|
@@ -12,23 +12,43 @@ slop::Options::Options() {
|
12
|
12
|
m_blue = 0;
|
13
|
13
|
m_gracetime = 0.3;
|
14
|
14
|
m_keyboard = true;
|
|
15
|
+ m_decorations = true;
|
|
16
|
+ m_offsetx = 0;
|
|
17
|
+ m_offsety = 0;
|
|
18
|
+ m_offsetw = 0;
|
|
19
|
+ m_offseth = 0;
|
15
|
20
|
}
|
16
|
21
|
|
17
|
22
|
void slop::Options::printHelp() {
|
18
|
23
|
printf( "Usage: slop [options]\n" );
|
19
|
24
|
printf( "Print user selected region to stdout. Pressing keys or right-clicking cancels selection.\n" );
|
20
|
25
|
printf( "\n" );
|
21
|
|
- printf( "options\n" );
|
22
|
|
- printf( " -h, --help show this message.\n" );
|
23
|
|
- printf( " -nkb, --nokeyboard disables the ability to cancel selections with the keyboard.\n" );
|
24
|
|
- printf( " -b=INT, --bordersize=INT set selection rectangle border size.\n" );
|
25
|
|
- printf( " -p=INT, --padding=INT set padding size for selection.\n" );
|
26
|
|
- printf( " -t=INT, --tolerance=INT if you have a shaky mouse, increasing this value will make slop detect single clicks better. Rather than interpreting your shaky clicks as region selections. Setting to zero will disable window selections.\n" );
|
27
|
|
- printf( " -x=STRING, --xdisplay=STRING set x display (STRING must be hostname:number.screen_number format)\n" );
|
28
|
|
- printf( " -c=COLOR, --color=COLOR set selection rectangle color, COLOR is in format FLOAT,FLOAT,FLOAT\n" );
|
29
|
|
- printf( " -g=FLOAT, --gracetime=FLOAT set the amount of time before slop will check for keyboard cancellations in seconds.\n" );
|
30
|
|
- printf( "examples\n" );
|
31
|
|
- printf( " slop -b=10 -x=:0 -p=-30 -t=4 -c=0.5,0.5,0.5 -g=.3\n" );
|
|
26
|
+ printf( "Options\n" );
|
|
27
|
+ printf( " -h, --help Show this message.\n" );
|
|
28
|
+ printf( " -nkb, --nokeyboard Disables the ability to cancel selections with the keyboard.\n" );
|
|
29
|
+ printf( " -b=INT, --bordersize=INT Set selection rectangle border size.\n" );
|
|
30
|
+ printf( " -p=INT, --padding=INT Set padding size for selection.\n" );
|
|
31
|
+ printf( " -t=INT, --tolerance=INT How far in pixels the mouse can move after clicking and still be detected\n" );
|
|
32
|
+ printf( " as a normal click. Setting to zero will disable window selections.\n" );
|
|
33
|
+ printf( " -x=STRING, --xdisplay=STRING Set x display (STRING must be hostname:number.screen_number format)\n" );
|
|
34
|
+ printf( " -c=COLOR, --color=COLOR Set selection rectangle color, COLOR is in format FLOAT,FLOAT,FLOAT\n" );
|
|
35
|
+ printf( " -g=FLOAT, --gracetime=FLOAT Set the amount of time before slop will check for keyboard cancellations\n" );
|
|
36
|
+ printf( " in seconds.\n" );
|
|
37
|
+ printf( " -nd, --nodecorations attempts to remove decorations from window selections.\n" );
|
|
38
|
+ printf( " -o=GEOMETRY, --offset=GEOMETRY Offsets window selections, but only if --nodecorations is active and if the\n" );
|
|
39
|
+ printf( " window's decorations were successfully detected. Has a very specific use of\n" );
|
|
40
|
+ printf( " removing shadows from Gnome's window selections right now. GEOMETRY is in\n" );
|
|
41
|
+ printf( " format WxH+X+Y\n" );
|
|
42
|
+ printf( "\n" );
|
|
43
|
+ printf( "Examples\n" );
|
|
44
|
+ printf( " $ # gray, thick border for maximum visiblity.\n" );
|
|
45
|
+ printf( " $ slop -b=20 -c=0.5,0.5,0.5\n" );
|
|
46
|
+ printf( "\n" );
|
|
47
|
+ printf( " $ # Remove window decorations, but include the 28px titlebar. Useful to remove the arbitrarily sized shadows in Gnome where they are included in window geometry for whatever reason.\n" );
|
|
48
|
+ printf( " $ slop -nd -o=0x28+0-28\n" );
|
|
49
|
+ printf( "\n" );
|
|
50
|
+ printf( " $ # Disable window selections. Useful for selecting individual pixels.\n" );
|
|
51
|
+ printf( " $ slop -t=0\n" );
|
32
|
52
|
}
|
33
|
53
|
|
34
|
54
|
int slop::Options::parseOptions( int argc, char** argv ) {
|
|
@@ -44,6 +64,11 @@ int slop::Options::parseOptions( int argc, char** argv ) {
|
44
|
64
|
if ( m_borderSize < 0 ) {
|
45
|
65
|
m_borderSize = 0;
|
46
|
66
|
}
|
|
67
|
+ } else if ( matches( arg, "-o=", "--offset=" ) ) {
|
|
68
|
+ int err = parseGeometry( arg, &m_offsetx, &m_offsety, &m_offsetw, &m_offseth );
|
|
69
|
+ if ( err ) {
|
|
70
|
+ return 1;
|
|
71
|
+ }
|
47
|
72
|
} else if ( matches( arg, "-p=", "--padding=" ) ) {
|
48
|
73
|
int err = parseInt( arg, &m_padding );
|
49
|
74
|
if ( err ) {
|
|
@@ -77,6 +102,8 @@ int slop::Options::parseOptions( int argc, char** argv ) {
|
77
|
102
|
}
|
78
|
103
|
} else if ( matches( arg, "-nkb", "--nokeyboard" ) ) {
|
79
|
104
|
m_keyboard = false;
|
|
105
|
+ } else if ( matches( arg, "-nd", "--nodecorations" ) ) {
|
|
106
|
+ m_decorations = false;
|
80
|
107
|
} else if ( matches( arg, "-h", "--help" ) ) {
|
81
|
108
|
printHelp();
|
82
|
109
|
return 2;
|
|
@@ -195,3 +222,32 @@ int slop::Options::parseColor( std::string arg, float* r, float* g, float* b ) {
|
195
|
222
|
delete[] x;
|
196
|
223
|
return 0;
|
197
|
224
|
}
|
|
225
|
+
|
|
226
|
+int slop::Options::parseGeometry( std::string arg, int* x, int* y, int* w, int* h ) {
|
|
227
|
+ std::string copy = arg;
|
|
228
|
+ // Replace the first =, all x's and +'s with spaces.
|
|
229
|
+ int find = copy.find( "=" );
|
|
230
|
+ while( find != copy.npos ) {
|
|
231
|
+ copy.at( find ) = ' ';
|
|
232
|
+ find = copy.find( "x" );
|
|
233
|
+ }
|
|
234
|
+ find = copy.find( "+" );
|
|
235
|
+ while( find != copy.npos ) {
|
|
236
|
+ copy.at( find ) = ' ';
|
|
237
|
+ find = copy.find( "+" );
|
|
238
|
+ }
|
|
239
|
+
|
|
240
|
+ // Just in case we error out, grab the actual argument name into x.
|
|
241
|
+ char* foo = new char[ arg.size() ];
|
|
242
|
+ int num = sscanf( copy.c_str(), "%s %d %d %d %d", foo, w, h, x, y );
|
|
243
|
+ if ( num != 5 ) {
|
|
244
|
+ fprintf( stderr, "Error parsing command arguments near %s\n", arg.c_str() );
|
|
245
|
+ fprintf( stderr, "Usage: %s=GEOMETRY\n", foo );
|
|
246
|
+ fprintf( stderr, "Example: %s=1920x1080+0+0 or %s=256x256+100+-200\n", foo, foo );
|
|
247
|
+ fprintf( stderr, "Try -h or --help for help.\n" );
|
|
248
|
+ delete[] foo;
|
|
249
|
+ return 1;
|
|
250
|
+ }
|
|
251
|
+ delete[] foo;
|
|
252
|
+ return 0;
|
|
253
|
+}
|