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
     float r = options->m_red;
20
     float r = options->m_red;
21
     float g = options->m_green;
21
     float g = options->m_green;
22
     float b = options->m_blue;
22
     float b = options->m_blue;
23
+    bool keyboard = options->m_keyboard;
23
     timespec start, time;
24
     timespec start, time;
24
     int cx = 0;
25
     int cx = 0;
25
     int cy = 0;
26
     int cy = 0;
42
         printf( "H=0\n" );
43
         printf( "H=0\n" );
43
         return err;
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
     clock_gettime( CLOCK_REALTIME, &start );
56
     clock_gettime( CLOCK_REALTIME, &start );
54
     while ( running ) {
57
     while ( running ) {

+ 6
- 2
options.cpp View File

11
     m_green = 0;
11
     m_green = 0;
12
     m_blue = 0;
12
     m_blue = 0;
13
     m_gracetime = 0.1;
13
     m_gracetime = 0.1;
14
+    m_keyboard = true;
14
 }
15
 }
15
 
16
 
16
 void slop::Options::printHelp() {
17
 void slop::Options::printHelp() {
17
     printf( "Usage: slop [options]\n" );
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
     printf( "\n" );
20
     printf( "\n" );
20
     printf( "options\n" );
21
     printf( "options\n" );
21
     printf( "    -h, --help                     show this message.\n" );
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
     printf( "    -b=INT, --bordersize=INT       set selection rectangle border size.\n" );
24
     printf( "    -b=INT, --bordersize=INT       set selection rectangle border size.\n" );
23
     printf( "    -p=INT, --m_padding=INT        set m_padding size for selection.\n" );
25
     printf( "    -p=INT, --m_padding=INT        set m_padding size for selection.\n" );
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" );
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
             if ( err ) {
75
             if ( err ) {
74
                 return 1;
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
             printHelp();
81
             printHelp();
78
             return 2;
82
             return 2;
79
         } else {
83
         } else {

+ 1
- 0
options.hpp View File

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