|
@@ -10,6 +10,7 @@ slop::Options::Options() {
|
10
|
10
|
m_red = 0;
|
11
|
11
|
m_green = 0;
|
12
|
12
|
m_blue = 0;
|
|
13
|
+ m_gracetime = 0.1;
|
13
|
14
|
}
|
14
|
15
|
|
15
|
16
|
void slop::Options::printHelp() {
|
|
@@ -23,8 +24,9 @@ void slop::Options::printHelp() {
|
23
|
24
|
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.\n" );
|
24
|
25
|
printf( " -x=STRING, --xdisplay=STRING set x display (STRING must be hostname:number.screen_number format)\n" );
|
25
|
26
|
printf( " -c=COLOR, --color=COLOR set selection rectangle color, COLOR is in format FLOAT,FLOAT,FLOAT\n" );
|
|
27
|
+ printf( " -g=FLOAT, --gracetime=FLOAT set the amount of time before slop will check for keyboard cancellations in seconds.\n" );
|
26
|
28
|
printf( "examples\n" );
|
27
|
|
- printf( " slop -b=10 -x=:0 -p=-30 -t=4 -c=0.5,0.5,0.5\n" );
|
|
29
|
+ printf( " slop -b=10 -x=:0 -p=-30 -t=4 -c=0.5,0.5,0.5 -g=.2\n" );
|
28
|
30
|
}
|
29
|
31
|
|
30
|
32
|
int slop::Options::parseOptions( int argc, char** argv ) {
|
|
@@ -58,6 +60,14 @@ int slop::Options::parseOptions( int argc, char** argv ) {
|
58
|
60
|
if ( m_tolerance < 0 ) {
|
59
|
61
|
m_tolerance = 0;
|
60
|
62
|
}
|
|
63
|
+ } else if ( matches( arg, "-g=", "--gracetime=" ) ) {
|
|
64
|
+ int err = parseFloat( arg, &m_gracetime );
|
|
65
|
+ if ( err ) {
|
|
66
|
+ return 1;
|
|
67
|
+ }
|
|
68
|
+ if ( m_gracetime < 0 ) {
|
|
69
|
+ m_gracetime = 0;
|
|
70
|
+ }
|
61
|
71
|
} else if ( matches( arg, "-x=", "--xdisplay=" ) ) {
|
62
|
72
|
int err = parseString( arg, &m_xdisplay );
|
63
|
73
|
if ( err ) {
|
|
@@ -99,6 +109,27 @@ int slop::Options::parseInt( std::string arg, int* returnInt ) {
|
99
|
109
|
return 0;
|
100
|
110
|
}
|
101
|
111
|
|
|
112
|
+int slop::Options::parseFloat( std::string arg, float* returnFloat ) {
|
|
113
|
+ std::string copy = arg;
|
|
114
|
+ int find = copy.find( "=" );
|
|
115
|
+ if ( find != copy.npos ) {
|
|
116
|
+ copy.at( find ) = ' ';
|
|
117
|
+ }
|
|
118
|
+ // Just in case we error out, grab the actual argument name into x.
|
|
119
|
+ char* x = new char[ arg.size() ];
|
|
120
|
+ int num = sscanf( copy.c_str(), "%s %f", x, returnFloat );
|
|
121
|
+ if ( num != 2 ) {
|
|
122
|
+ fprintf( stderr, "Error parsing command arguments near %s\n", arg.c_str() );
|
|
123
|
+ fprintf( stderr, "Usage: %s=FLOAT\n", x );
|
|
124
|
+ fprintf( stderr, "Example: %s=3.14 or %s=-99\n", x, x );
|
|
125
|
+ fprintf( stderr, "Try -h or --help for help.\n" );
|
|
126
|
+ delete[] x;
|
|
127
|
+ return 1;
|
|
128
|
+ }
|
|
129
|
+ delete[] x;
|
|
130
|
+ return 0;
|
|
131
|
+}
|
|
132
|
+
|
102
|
133
|
bool slop::Options::matches( std::string arg, std::string shorthand, std::string longhand ) {
|
103
|
134
|
if ( arg.substr( 0, shorthand.size() ) == shorthand ||
|
104
|
135
|
arg.substr( 0, longhand.size() ) == longhand ) {
|