Browse Source

added options to disable keyboard grabbing

naelstrof 11 years ago
parent
commit
20c8794fe0
3 changed files with 17 additions and 9 deletions
  1. 10
    7
      main.cpp
  2. 6
    2
      options.cpp
  3. 1
    0
      options.hpp

+ 10
- 7
main.cpp View File

@@ -20,6 +20,7 @@ int main( int argc, char** argv ) {
20 20
     float r = options->m_red;
21 21
     float g = options->m_green;
22 22
     float b = options->m_blue;
23
+    bool keyboard = options->m_keyboard;
23 24
     timespec start, time;
24 25
     int cx = 0;
25 26
     int cy = 0;
@@ -42,13 +43,15 @@ int main( int argc, char** argv ) {
42 43
         printf( "H=0\n" );
43 44
         return err;
44 45
     }
45
-    err = xengine->grabKeyboard();
46
-    if ( err ) {
47
-        printf( "X=0\n" );
48
-        printf( "Y=0\n" );
49
-        printf( "W=0\n" );
50
-        printf( "H=0\n" );
51
-        return err;
46
+    if ( keyboard ) {
47
+        err = xengine->grabKeyboard();
48
+        if ( err ) {
49
+            printf( "X=0\n" );
50
+            printf( "Y=0\n" );
51
+            printf( "W=0\n" );
52
+            printf( "H=0\n" );
53
+            return err;
54
+        }
52 55
     }
53 56
     clock_gettime( CLOCK_REALTIME, &start );
54 57
     while ( running ) {

+ 6
- 2
options.cpp View File

@@ -11,14 +11,16 @@ slop::Options::Options() {
11 11
     m_green = 0;
12 12
     m_blue = 0;
13 13
     m_gracetime = 0.1;
14
+    m_keyboard = true;
14 15
 }
15 16
 
16 17
 void slop::Options::printHelp() {
17 18
     printf( "Usage: slop [options]\n" );
18
-    printf( "Print user selected region to stdout.\n" );
19
+    printf( "Print user selected region to stdout. Pressing keys or right-clicking cancels selection.\n" );
19 20
     printf( "\n" );
20 21
     printf( "options\n" );
21 22
     printf( "    -h, --help                     show this message.\n" );
23
+    printf( "    -nk, --nokeyboard              don't try to grab the keyboard. This may fix problems with certain window managers.\n" );
22 24
     printf( "    -b=INT, --bordersize=INT       set selection rectangle border size.\n" );
23 25
     printf( "    -p=INT, --m_padding=INT        set m_padding size for selection.\n" );
24 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.\n" );
@@ -73,7 +75,9 @@ int slop::Options::parseOptions( int argc, char** argv ) {
73 75
             if ( err ) {
74 76
                 return 1;
75 77
             }
76
-        } else if ( arg == "-h" || arg == "--help" ) {
78
+        } else if ( matches( arg, "-nk", "--nokeyboard" ) ) {
79
+            m_keyboard = false;
80
+        } else if ( matches( arg, "-h", "--help" ) ) {
77 81
             printHelp();
78 82
             return 2;
79 83
         } else {

+ 1
- 0
options.hpp View File

@@ -19,6 +19,7 @@ public:
19 19
     float       m_blue;
20 20
     std::string m_xdisplay;
21 21
     float       m_gracetime;
22
+    bool        m_keyboard;
22 23
 private:
23 24
     int         parseInt( std::string arg, int* returnInt );
24 25
     int         parseFloat( std::string arg, float* returnFloat );