Przeglądaj źródła

added help printing

naelstrof 7 lat temu
rodzic
commit
e157484d65
4 zmienionych plików z 89 dodań i 6 usunięć
  1. 81
    0
      src/main.cpp
  2. 4
    4
      src/options.hpp
  3. 3
    2
      src/slop.cpp
  4. 1
    0
      src/slop.hpp

+ 81
- 0
src/main.cpp Wyświetl plik

@@ -30,6 +30,7 @@ SlopOptions* getOptions( Options& options ) {
30 30
     options.getFloat("tolerance", 't', foo->tolerance);
31 31
     glm::vec4 color = glm::vec4( foo->r, foo->g, foo->b, foo->a );
32 32
     options.getColor("color", 'c', color);
33
+    options.getString( "xdisplay", 'x', foo->xdisplay );
33 34
     foo->r = color.r;
34 35
     foo->g = color.g;
35 36
     foo->b = color.b;
@@ -71,9 +72,89 @@ std::string formatOutput( std::string input, SlopSelection selection ) {
71 72
     return output.str();
72 73
 }
73 74
 
75
+void printHelp() {
76
+    std::cout << "slop v5.3.21\n";
77
+    std::cout << "\n";
78
+    std::cout << "Copyright (C) 2017 Dalton Nell, Slop Contributors\n";
79
+    std::cout << "(https://github.com/naelstrof/slop/graphs/contributors)\n";
80
+    std::cout << "Usage: slop [options]\n";
81
+    std::cout << "\n";
82
+    std::cout << "slop (Select Operation) is an application that queries for a selection from the\n";
83
+    std::cout << "user and prints the region to stdout.\n";
84
+    std::cout << "\n";
85
+    std::cout << "-h, --help                    Print help and exit\n";
86
+    std::cout << "-v, --version                 Print version and exit\n";
87
+    std::cout << "Options\n";
88
+    std::cout << "  -x, --xdisplay=hostname:number.screen_number\n";
89
+    std::cout << "                                Sets the x display.\n";
90
+	std::cout << "  -k, --nokeyboard              Disables the ability to cancel selections with\n";
91
+	std::cout << "                                  the keyboard.  (default=off)\n";
92
+	std::cout << "  -b, --bordersize=FLOAT        Set the selection rectangle's thickness.\n";
93
+	std::cout << "                                  (default=`1')\n";
94
+	std::cout << "  -p, --padding=FLOAT           Set the padding size of the selection. Can be\n";
95
+	std::cout << "                                  negative.  (default=`0')\n";
96
+	std::cout << "  -t, --tolerance=FLOAT         How far in pixels the mouse can move after\n";
97
+	std::cout << "                                  clicking and still be detected as a normal\n";
98
+	std::cout << "                                  click instead of a click and drag. Setting\n";
99
+	std::cout << "                                  this to 0 will disable window selections.\n";
100
+	std::cout << "                                  Alternatively setting it to 999999 would.\n";
101
+	std::cout << "                                  only allow for window selections.\n";
102
+	std::cout << "                                  (default=`2')\n";
103
+	std::cout << "  -c, --color=FLOAT,FLOAT,FLOAT,FLOAT\n";
104
+	std::cout << "                                Set the selection rectangle's color. Supports\n";
105
+	std::cout << "                                  RGB or RGBA values.\n";
106
+	std::cout << "                                  (default=`0.5,0.5,0.5,1')\n";
107
+	std::cout << "  -n, --nodecorations           Attempt to select child windows in order to\n";
108
+	std::cout << "                                  avoid window decorations.  (default=off)\n";
109
+	std::cout << "  -l, --highlight               Instead of outlining selections, slop\n";
110
+	std::cout << "                                  highlights it. This is only useful when\n";
111
+	std::cout << "                                  --color is set to a transparent color.\n";
112
+	std::cout << "                                  (default=off)\n";
113
+	std::cout << "      --shader=STRING           Sets the shader to load and use from\n";
114
+	std::cout << "                                  ~/.config/slop/ or /usr/share/.\n";
115
+	std::cout << "                                  (default=`simple')\n";
116
+	std::cout << "  -f, --format=STRING           Set the output format string. Format specifiers\n";
117
+	std::cout << "                                  are %x, %y, %w, %h, %i, %g, and %c.\n";
118
+	std::cout << "                                  (default=`X=%x\nY=%y\nW=%w\nH=%h\nG=%g\nID=%i\nCancel=%c\n')\n";
119
+	std::cout << "Examples\n";
120
+	std::cout << "    $ # Gray, thick, transparent border for maximum visiblity.\n";
121
+	std::cout << "    $ slop -b 20 -c 0.5,0.5,0.5,0.8\n";
122
+	std::cout << "\n";
123
+	std::cout << "    $ # Remove window decorations.\n";
124
+	std::cout << "    $ slop --nodecorations\n";
125
+	std::cout << "\n";
126
+	std::cout << "    $ # Disable window selections. Useful for selecting individual pixels.\n";
127
+	std::cout << "    $ slop -t 0\n";
128
+	std::cout << "\n";
129
+	std::cout << "    $ # Classic Windows XP selection.\n";
130
+	std::cout << "    $ slop -l -c 0.3,0.4,0.6,0.4\n";
131
+	std::cout << "\n";
132
+	std::cout << "    $ # Wiggle wiggle!\n";
133
+	std::cout << "    $ slop --opengl --shader wiggle\n";
134
+	std::cout << "\n";
135
+	std::cout << "    $ # Change output format to use safer parsing\n";
136
+	std::cout << "    $ slopoutput=$(slop -f \"%x %y %w %h\")\n";
137
+	std::cout << "    $ X=$(echo $slopoutput | awk '{print $1}')\n";
138
+	std::cout << "    $ Y=$(echo $slopoutput | awk '{print $2}')\n";
139
+	std::cout << "    $ W=$(echo $slopoutput | awk '{print $3}')\n";
140
+	std::cout << "    $ H=$(echo $slopoutput | awk '{print $4}')\n";
141
+	std::cout << "\n";
142
+	std::cout << "Tips\n";
143
+	std::cout << "    * If you don't like a selection: you can cancel it by right-clicking\n";
144
+	std::cout << "regardless of which options are enabled or disabled for slop.\n";
145
+	std::cout << "    * If slop doesn't seem to select a window accurately, the problem could be\n";
146
+	std::cout << "because of decorations getting in the way. Try enabling the --nodecorations\n";
147
+	std::cout << "flag.\n";
148
+}
149
+
74 150
 int app( int argc, char** argv ) {
75 151
     // Options just validates all of our input from argv
76 152
     Options options( argc, argv );
153
+    bool help;
154
+    if ( options.getBool( "help", 'h', help ) ) {
155
+        printHelp();
156
+        return 0;
157
+    }
77 158
     // We then parse the options into something slop can understand.
78 159
     SlopOptions* parsedOptions = getOptions( options );
79 160
 

+ 4
- 4
src/options.hpp Wyświetl plik

@@ -28,11 +28,11 @@
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" };
32
-static char validCharArguments[] = { 'b', 'p', 'c', 's', 'h', 'f', 't', 'n', 'k' };
31
+static std::string validStringArguments[] = { "bordersize", "padding", "color", "shader", "highlight", "format", "tolerance", "nodecorations", "nokeyboard", "help", "xdisplay" };
32
+static char validCharArguments[] = { 'b', 'p', 'c', 's', 'h', 'f', 't', 'n', 'k', 'h', 'x' };
33 33
 // 0 for flag, 1 for how many arguments to eat up
34
-static unsigned int isFlagArgument[] = { false, false, false, false, true, false, false, true, true };
35
-static unsigned int validArgumentCount = 9;
34
+static unsigned int isFlagArgument[] = { false, false, false, false, true, false, false, true, true, true, false};
35
+static unsigned int validArgumentCount = 11;
36 36
 static unsigned int maxFloatingValues = 0;
37 37
 
38 38
 class Options {

+ 3
- 2
src/slop.cpp Wyświetl plik

@@ -9,10 +9,11 @@ Resource* resource;
9 9
 SlopOptions::SlopOptions() {
10 10
     borderSize = 1;
11 11
     nodecorations = false;
12
-    tolerance = 4;
12
+    tolerance = 2;
13 13
     padding = 0;
14 14
     shader = "textured";
15 15
     highlight = false;
16
+    xdisplay = ":0";
16 17
     r = 0.5;
17 18
     g = 0.5;
18 19
     b = 0.5;
@@ -76,7 +77,7 @@ SlopSelection SlopSelect( SlopOptions* options, bool* cancelled ) {
76 77
     }
77 78
     resource = new Resource();
78 79
     // Set up x11 temporarily
79
-    x11 = new X11(":0");
80
+    x11 = new X11(options->xdisplay);
80 81
     mouse = new Mouse( x11, options->nodecorations );
81 82
     keyboard = new Keyboard( x11 );
82 83
 

+ 1
- 0
src/slop.hpp Wyświetl plik

@@ -47,6 +47,7 @@ public:
47 47
     float g;
48 48
     float b;
49 49
     float a;
50
+    std::string xdisplay;
50 51
 };
51 52
 
52 53
 class SlopSelection {