Browse Source

Added quiet option

naelstrof 7 years ago
parent
commit
a4da810654
6 changed files with 27 additions and 16 deletions
  1. 3
    0
      slop.1
  2. BIN
      slop.1.gz
  3. 11
    5
      src/main.cpp
  4. 4
    4
      src/options.hpp
  5. 8
    6
      src/slop.cpp
  6. 1
    1
      src/slop.hpp

+ 3
- 0
slop.1 View File

44
 .TP
44
 .TP
45
 .BR \-l ", " \-\-highlight
45
 .BR \-l ", " \-\-highlight
46
 Instead of outlining a selection, slop will highlight it instead. This is particularly useful if the color is set to an opacity lower than 1.
46
 Instead of outlining a selection, slop will highlight it instead. This is particularly useful if the color is set to an opacity lower than 1.
47
+.TP
48
+.BR \-q ", " \-\-quiet
49
+Disable any unnecessary cerr output. Any warnings simply won't print.
47
 .SH EXAMPLES
50
 .SH EXAMPLES
48
 To emulate a windows XP selection, you can use something like this:
51
 To emulate a windows XP selection, you can use something like this:
49
 .PP
52
 .PP

BIN
slop.1.gz View File


+ 11
- 5
src/main.cpp View File

108
 	std::cout << "                                Set the selection rectangle's color. Supports\n";
108
 	std::cout << "                                Set the selection rectangle's color. Supports\n";
109
 	std::cout << "                                  RGB or RGBA values.\n";
109
 	std::cout << "                                  RGB or RGBA values.\n";
110
 	std::cout << "                                  (default=`0.5,0.5,0.5,1')\n";
110
 	std::cout << "                                  (default=`0.5,0.5,0.5,1')\n";
111
-	std::cout << "  -n, --nodecorations=INT           Attempt to select child windows in order to\n";
111
+	std::cout << "  -n, --nodecorations=INT       Attempt to select child windows in order to\n";
112
 	std::cout << "                                  avoid window decorations. Setting this to\n";
112
 	std::cout << "                                  avoid window decorations. Setting this to\n";
113
     std::cout << "                                  1 will enable a light attempt to\n";
113
     std::cout << "                                  1 will enable a light attempt to\n";
114
     std::cout << "                                  remove decorations. Setting this to 2 will\n";
114
     std::cout << "                                  remove decorations. Setting this to 2 will\n";
115
-    std::cout << "                                  enable an aggressive decoration removal.\n";
115
+    std::cout << "                                  enable aggressive decoration removal.\n";
116
     std::cout << "                                  (default=`0')\n";
116
     std::cout << "                                  (default=`0')\n";
117
+	std::cout << "  -q, --quiet                   Disable any unnecessary cerr output. Any\n";
118
+	std::cout << "                                  warnings simply won't print.\n";
117
 	std::cout << "  -l, --highlight               Instead of outlining selections, slop\n";
119
 	std::cout << "  -l, --highlight               Instead of outlining selections, slop\n";
118
 	std::cout << "                                  highlights it. This is only useful when\n";
120
 	std::cout << "                                  highlights it. This is only useful when\n";
119
 	std::cout << "                                  --color is set to a transparent color.\n";
121
 	std::cout << "                                  --color is set to a transparent color.\n";
151
 int app( int argc, char** argv ) {
153
 int app( int argc, char** argv ) {
152
     // Options just validates all of our input from argv
154
     // Options just validates all of our input from argv
153
     Options options( argc, argv );
155
     Options options( argc, argv );
154
-    bool help;
156
+    bool quiet = false;
157
+    options.getBool( "quiet", 'q', quiet );
158
+    bool help = false;
155
     if ( options.getBool( "help", 'h', help ) ) {
159
     if ( options.getBool( "help", 'h', help ) ) {
156
         printHelp();
160
         printHelp();
157
         return 0;
161
         return 0;
174
 
178
 
175
     // Finally we do the real selection.
179
     // Finally we do the real selection.
176
     bool cancelled = false;
180
     bool cancelled = false;
177
-    selection = SlopSelect(parsedOptions, &cancelled);
181
+    selection = SlopSelect(parsedOptions, &cancelled, quiet);
178
     
182
     
179
     // Here we're done with the parsed option data.
183
     // Here we're done with the parsed option data.
180
     delete parsedOptions;
184
     delete parsedOptions;
181
     // We know if we cancelled or not
185
     // We know if we cancelled or not
182
     if ( cancelled ) {
186
     if ( cancelled ) {
183
-        std::cerr << "Selection was cancelled by keystroke or right-click.\n";
187
+        if ( !quiet ) {
188
+            std::cerr << "Selection was cancelled by keystroke or right-click.\n";
189
+        }
184
         return 1;
190
         return 1;
185
     }
191
     }
186
     // If we recieved a format option, we output the specified output.
192
     // If we recieved a format option, we output the specified output.

+ 4
- 4
src/options.hpp View File

28
 #include <vector>
28
 #include <vector>
29
 #include <glm/glm.hpp>
29
 #include <glm/glm.hpp>
30
 
30
 
31
-static std::string validStringArguments[] = { "bordersize", "padding", "color", "shader", "highlight", "format", "tolerance", "nodecorations", "nokeyboard", "help", "xdisplay", "version" };
32
-static char validCharArguments[] = { 'b', 'p', 'c', 's', 'l', 'f', 't', 'n', 'k', 'h', 'x', 'v' };
33
-static unsigned int isFlagArgument[] = { false, false, false, false, true, false, false, false, true, true, false, true };
34
-static unsigned int validArgumentCount = 12;
31
+static std::string validStringArguments[] = { "bordersize", "padding", "color", "shader", "highlight", "format", "tolerance", "nodecorations", "nokeyboard", "help", "xdisplay", "version", "quiet" };
32
+static char validCharArguments[] = { 'b', 'p', 'c', 's', 'l', 'f', 't', 'n', 'k', 'h', 'x', 'v', 'q' };
33
+static unsigned int isFlagArgument[] = { false, false, false, false, true, false, false, false, true, true, false, true, true };
34
+static unsigned int validArgumentCount = 13;
35
 static unsigned int maxFloatingValues = 0;
35
 static unsigned int maxFloatingValues = 0;
36
 
36
 
37
 class Options {
37
 class Options {

+ 8
- 6
src/slop.cpp View File

31
 SlopSelection GLSlopSelect( SlopOptions* options, bool* cancelled, SlopWindow* window );
31
 SlopSelection GLSlopSelect( SlopOptions* options, bool* cancelled, SlopWindow* window );
32
 SlopSelection XShapeSlopSelect( SlopOptions* options, bool* cancelled);
32
 SlopSelection XShapeSlopSelect( SlopOptions* options, bool* cancelled);
33
 
33
 
34
-SlopSelection SlopSelect( SlopOptions* options, bool* cancelled ) {
34
+SlopSelection SlopSelect( SlopOptions* options, bool* cancelled, bool quiet) {
35
     SlopSelection returnval(0,0,0,0,0);
35
     SlopSelection returnval(0,0,0,0,0);
36
     bool deleteOptions = false;
36
     bool deleteOptions = false;
37
     if ( !options ) {
37
     if ( !options ) {
59
     }
59
     }
60
     if ( !success ) {
60
     if ( !success ) {
61
         // If we fail, we launch the XShape version of slop.
61
         // If we fail, we launch the XShape version of slop.
62
-        if ( errorstring.length() <= 0 ) {
63
-            errorstring += "Failed to launch OpenGL context, --shader parameter will be ignored.\n";
64
-            std::cerr << errorstring;
65
-        } else {
66
-            std::cerr << errorstring;
62
+        if ( !quiet ) {
63
+            if ( errorstring.length() <= 0 ) {
64
+                errorstring += "Failed to launch OpenGL context, --shader parameter will be ignored.\n";
65
+                std::cerr << errorstring;
66
+            } else {
67
+                std::cerr << errorstring;
68
+            }
67
         }
69
         }
68
         returnval = XShapeSlopSelect( options, cancelled );
70
         returnval = XShapeSlopSelect( options, cancelled );
69
     } else {
71
     } else {

+ 1
- 1
src/slop.hpp View File

64
     int id;
64
     int id;
65
 };
65
 };
66
 
66
 
67
-SlopSelection SlopSelect( SlopOptions* options = NULL, bool* cancelled = NULL );
67
+SlopSelection SlopSelect( SlopOptions* options = NULL, bool* cancelled = NULL, bool quiet = false );
68
 
68
 
69
 #endif // N_SLOP_H_
69
 #endif // N_SLOP_H_