Selaa lähdekoodia

Added quiet option

naelstrof 7 vuotta sitten
vanhempi
commit
a4da810654
6 muutettua tiedostoa jossa 27 lisäystä ja 16 poistoa
  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 Näytä tiedosto

@@ -44,6 +44,9 @@ Sets the level of aggressiveness when trying to remove window decroations. `0' i
44 44
 .TP
45 45
 .BR \-l ", " \-\-highlight
46 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 50
 .SH EXAMPLES
48 51
 To emulate a windows XP selection, you can use something like this:
49 52
 .PP

BIN
slop.1.gz Näytä tiedosto


+ 11
- 5
src/main.cpp Näytä tiedosto

@@ -108,12 +108,14 @@ void printHelp() {
108 108
 	std::cout << "                                Set the selection rectangle's color. Supports\n";
109 109
 	std::cout << "                                  RGB or RGBA values.\n";
110 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 112
 	std::cout << "                                  avoid window decorations. Setting this to\n";
113 113
     std::cout << "                                  1 will enable a light attempt to\n";
114 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 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 119
 	std::cout << "  -l, --highlight               Instead of outlining selections, slop\n";
118 120
 	std::cout << "                                  highlights it. This is only useful when\n";
119 121
 	std::cout << "                                  --color is set to a transparent color.\n";
@@ -151,7 +153,9 @@ void printHelp() {
151 153
 int app( int argc, char** argv ) {
152 154
     // Options just validates all of our input from argv
153 155
     Options options( argc, argv );
154
-    bool help;
156
+    bool quiet = false;
157
+    options.getBool( "quiet", 'q', quiet );
158
+    bool help = false;
155 159
     if ( options.getBool( "help", 'h', help ) ) {
156 160
         printHelp();
157 161
         return 0;
@@ -174,13 +178,15 @@ int app( int argc, char** argv ) {
174 178
 
175 179
     // Finally we do the real selection.
176 180
     bool cancelled = false;
177
-    selection = SlopSelect(parsedOptions, &cancelled);
181
+    selection = SlopSelect(parsedOptions, &cancelled, quiet);
178 182
     
179 183
     // Here we're done with the parsed option data.
180 184
     delete parsedOptions;
181 185
     // We know if we cancelled or not
182 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 190
         return 1;
185 191
     }
186 192
     // If we recieved a format option, we output the specified output.

+ 4
- 4
src/options.hpp Näytä tiedosto

@@ -28,10 +28,10 @@
28 28
 #include <vector>
29 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 35
 static unsigned int maxFloatingValues = 0;
36 36
 
37 37
 class Options {

+ 8
- 6
src/slop.cpp Näytä tiedosto

@@ -31,7 +31,7 @@ SlopSelection::SlopSelection( float x, float y, float w, float h, int id ) {
31 31
 SlopSelection GLSlopSelect( SlopOptions* options, bool* cancelled, SlopWindow* window );
32 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 35
     SlopSelection returnval(0,0,0,0,0);
36 36
     bool deleteOptions = false;
37 37
     if ( !options ) {
@@ -59,11 +59,13 @@ SlopSelection SlopSelect( SlopOptions* options, bool* cancelled ) {
59 59
     }
60 60
     if ( !success ) {
61 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 70
         returnval = XShapeSlopSelect( options, cancelled );
69 71
     } else {

+ 1
- 1
src/slop.hpp Näytä tiedosto

@@ -64,6 +64,6 @@ public:
64 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 69
 #endif // N_SLOP_H_