Browse Source

Added highlight feature, and now events fall through slop windows.

Dalton Nell 10 years ago
parent
commit
edd9784e85
8 changed files with 67 additions and 34 deletions
  1. 10
    4
      README.md
  2. 3
    0
      main.cpp
  3. 14
    5
      options.cpp
  4. 1
    0
      options.hpp
  5. 35
    23
      rectangle.cpp
  6. 2
    1
      rectangle.hpp
  7. 1
    1
      x.cpp
  8. 1
    0
      x.hpp

+ 10
- 4
README.md View File

61
     -t=INT, --tolerance=INT        How far in pixels the mouse can move after clicking and still be detected
61
     -t=INT, --tolerance=INT        How far in pixels the mouse can move after clicking and still be detected
62
                                    as a normal click. Setting to zero will disable window selections.
62
                                    as a normal click. Setting to zero will disable window selections.
63
     -x=STRING, --xdisplay=STRING   Set x display (STRING must be hostname:number.screen_number format)
63
     -x=STRING, --xdisplay=STRING   Set x display (STRING must be hostname:number.screen_number format)
64
-    -c=COLOR, --color=COLOR        Set selection rectangle color, COLOR is in format FLOAT,FLOAT,FLOAT,FLOAT
64
+    -c=COLOR, --color=COLOR        Set selection rectangle color, COLOR is in format FLOAT,FLOAT,FLOAT,FLOAT.
65
+                                   takes RGBA or RGB.
65
     -g=FLOAT, --gracetime=FLOAT    Set the amount of time before slop will check for keyboard cancellations
66
     -g=FLOAT, --gracetime=FLOAT    Set the amount of time before slop will check for keyboard cancellations
66
                                    in seconds.
67
                                    in seconds.
67
-    -nd, --nodecorations           attempts to remove decorations from window selections.
68
-    -min=INT, --minimumsize=INT    sets the minimum output of width or height values, useful to avoid outputting 0
69
-    -max=INT, --maximumsize=INT    sets the maximum output of width or height values.
68
+    -nd, --nodecorations           Attempts to remove decorations from window selections.
69
+    -min=INT, --minimumsize=INT    Sets the minimum output of width or height values, useful to avoid outputting 0
70
+    -max=INT, --maximumsize=INT    Sets the maximum output of width or height values.
70
                                    widths or heights.
71
                                    widths or heights.
72
+    -hi, --highlight               Instead of outlining the selection, slop highlights it. Only useful when
73
+                                   used with a --color with an alpha under 1.
71
     -v, --version                  prints version.
74
     -v, --version                  prints version.
72
 
75
 
73
 Examples
76
 Examples
79
 
82
 
80
     $ # Disable window selections. Useful for selecting individual pixels.
83
     $ # Disable window selections. Useful for selecting individual pixels.
81
     $ slop -t=0
84
     $ slop -t=0
85
+
86
+    $ # Classic Windows XP selection.
87
+    $ slop -hi -c=0.2,0.4,0.5,0.4
82
 ```
88
 ```

+ 3
- 0
main.cpp View File

100
     float g = options->m_green;
100
     float g = options->m_green;
101
     float b = options->m_blue;
101
     float b = options->m_blue;
102
     float a = options->m_alpha;
102
     float a = options->m_alpha;
103
+    bool highlight = options->m_highlight;
103
     bool keyboard = options->m_keyboard;
104
     bool keyboard = options->m_keyboard;
104
     bool decorations = options->m_decorations;
105
     bool decorations = options->m_decorations;
105
     timespec start, time;
106
     timespec start, time;
170
                                                          t.m_x + t.m_width,
171
                                                          t.m_x + t.m_width,
171
                                                          t.m_y + t.m_height,
172
                                                          t.m_y + t.m_height,
172
                                                          borderSize,
173
                                                          borderSize,
174
+                                                         highlight,
173
                                                          r, g, b, a );
175
                                                          r, g, b, a );
174
                     } else {
176
                     } else {
175
                         selection->setGeo( t.m_x, t.m_y, t.m_x + t.m_width, t.m_y + t.m_height );
177
                         selection->setGeo( t.m_x, t.m_y, t.m_x + t.m_width, t.m_y + t.m_height );
208
                                                      xengine->m_mousex + 1,
210
                                                      xengine->m_mousex + 1,
209
                                                      xengine->m_mousey + 1,
211
                                                      xengine->m_mousey + 1,
210
                                                      borderSize,
212
                                                      borderSize,
213
+                                                     highlight,
211
                                                      r, g, b, a );
214
                                                      r, g, b, a );
212
                 }
215
                 }
213
                 // If the user has let go of the mouse button, we'll just
216
                 // If the user has let go of the mouse button, we'll just

+ 14
- 5
options.cpp View File

3
 slop::Options* options = new slop::Options();
3
 slop::Options* options = new slop::Options();
4
 
4
 
5
 slop::Options::Options() {
5
 slop::Options::Options() {
6
-    m_version = "v2.0.8";
6
+    m_version = "v2.0.9";
7
+    m_highlight = false;
7
     m_borderSize = 10;
8
     m_borderSize = 10;
8
     m_padding = 0;
9
     m_padding = 0;
9
     m_xdisplay = ":0";
10
     m_xdisplay = ":0";
31
     printf( "    -t=INT, --tolerance=INT        How far in pixels the mouse can move after clicking and still be detected\n" );
32
     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( "                                   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( "    -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,FLOAT\n" );
35
+    printf( "    -c=COLOR, --color=COLOR        Set selection rectangle color, COLOR is in format FLOAT,FLOAT,FLOAT,FLOAT.\n" );
36
+    printf( "                                   takes RGBA or RGB.\n" );
35
     printf( "    -g=FLOAT, --gracetime=FLOAT    Set the amount of time before slop will check for keyboard cancellations\n" );
37
     printf( "    -g=FLOAT, --gracetime=FLOAT    Set the amount of time before slop will check for keyboard cancellations\n" );
36
     printf( "                                   in seconds.\n" );
38
     printf( "                                   in seconds.\n" );
37
-    printf( "    -nd, --nodecorations           attempts to remove decorations from window selections.\n" );
38
-    printf( "    -min=INT, --minimumsize=INT    sets the minimum output of width or height values, useful to avoid outputting 0\n" );
39
-    printf( "    -max=INT, --maximumsize=INT    sets the maximum output of width or height values.\n" );
39
+    printf( "    -nd, --nodecorations           Attempts to remove decorations from window selections.\n" );
40
+    printf( "    -min=INT, --minimumsize=INT    Sets the minimum output of width or height values, useful to avoid outputting 0\n" );
41
+    printf( "    -max=INT, --maximumsize=INT    Sets the maximum output of width or height values.\n" );
40
     printf( "                                   widths or heights.\n" );
42
     printf( "                                   widths or heights.\n" );
43
+    printf( "    -hi, --highlight               Instead of outlining the selection, slop highlights it. Only useful when\n" );
44
+    printf( "                                   used with a --color with an alpha under 1.\n" );
41
     printf( "    -v, --version                  prints version.\n" );
45
     printf( "    -v, --version                  prints version.\n" );
42
     printf( "\n" );
46
     printf( "\n" );
43
     printf( "Examples\n" );
47
     printf( "Examples\n" );
49
     printf( "\n" );
53
     printf( "\n" );
50
     printf( "    $ # Disable window selections. Useful for selecting individual pixels.\n" );
54
     printf( "    $ # Disable window selections. Useful for selecting individual pixels.\n" );
51
     printf( "    $ slop -t=0\n" );
55
     printf( "    $ slop -t=0\n" );
56
+    printf( "\n" );
57
+    printf( "    $ # Classic Windows XP selection.\n" );
58
+    printf( "    $ slop -hi -c=0.2,0.4,0.5,0.4\n" );
52
 }
59
 }
53
 
60
 
54
 int slop::Options::parseOptions( int argc, char** argv ) {
61
 int slop::Options::parseOptions( int argc, char** argv ) {
109
             m_keyboard = false;
116
             m_keyboard = false;
110
         } else if ( matches( arg, "-nd", "--nodecorations" ) ) {
117
         } else if ( matches( arg, "-nd", "--nodecorations" ) ) {
111
             m_decorations = false;
118
             m_decorations = false;
119
+        } else if ( matches( arg, "-hi", "--highlight" ) ) {
120
+            m_highlight = true;
112
         } else if ( matches( arg, "-h", "--help" ) ) {
121
         } else if ( matches( arg, "-h", "--help" ) ) {
113
             printHelp();
122
             printHelp();
114
             return 2;
123
             return 2;

+ 1
- 0
options.hpp View File

26
     float       m_gracetime;
26
     float       m_gracetime;
27
     bool        m_keyboard;
27
     bool        m_keyboard;
28
     bool        m_decorations;
28
     bool        m_decorations;
29
+    bool        m_highlight;
29
 private:
30
 private:
30
     int         parseInt( std::string arg, int* returnInt );
31
     int         parseInt( std::string arg, int* returnInt );
31
     int         parseFloat( std::string arg, float* returnFloat );
32
     int         parseFloat( std::string arg, float* returnFloat );

+ 35
- 23
rectangle.cpp View File

18
     usleep( 10000 );
18
     usleep( 10000 );
19
 }
19
 }
20
 
20
 
21
-slop::Rectangle::Rectangle( int sx, int sy, int ex, int ey, int border, float r, float g, float b, float a ) {
21
+slop::Rectangle::Rectangle( int sx, int sy, int ex, int ey, int border, bool highlight, float r, float g, float b, float a ) {
22
     m_x = std::min( sx, ex );
22
     m_x = std::min( sx, ex );
23
     m_y = std::min( sy, ey );
23
     m_y = std::min( sy, ey );
24
     m_width = std::max( sx, ex ) - m_x;
24
     m_width = std::max( sx, ex ) - m_x;
25
     m_height = std::max( sy, ey ) - m_y;
25
     m_height = std::max( sy, ey ) - m_y;
26
     m_border = border;
26
     m_border = border;
27
     m_window = None;
27
     m_window = None;
28
+    m_highlight = highlight;
28
 
29
 
29
     // If we don't have a border, we don't exist, so just die.
30
     // If we don't have a border, we don't exist, so just die.
30
     if ( m_border == 0 ) {
31
     if ( m_border == 0 ) {
31
         return;
32
         return;
32
     }
33
     }
33
 
34
 
35
+    if ( m_highlight ) {
36
+        m_border = 0;
37
+    }
38
+
34
     // This sets up m_color
39
     // This sets up m_color
35
     int err = convertColor( r, g, b );
40
     int err = convertColor( r, g, b );
36
     if ( err ) {
41
     if ( err ) {
60
                          XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&cardinal_alpha, 1 );
65
                          XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&cardinal_alpha, 1 );
61
     }
66
     }
62
 
67
 
63
-    // Now punch a hole into it so it looks like a selection rectangle!
64
-    XRectangle rect;
65
-    rect.x = rect.y = m_border;
66
-    rect.width = m_width;
67
-    rect.height = m_height;
68
-
69
     XClassHint classhints;
68
     XClassHint classhints;
70
     char name[] = "slop";
69
     char name[] = "slop";
71
     classhints.res_name = name;
70
     classhints.res_name = name;
72
     classhints.res_class = name;
71
     classhints.res_class = name;
73
     XSetClassHint( xengine->m_display, m_window, &classhints );
72
     XSetClassHint( xengine->m_display, m_window, &classhints );
74
 
73
 
75
-    XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSubtract, 0);
74
+    // Now punch a hole into it so it looks like a selection rectangle, but only if we're not highlighting.
75
+    if ( !m_highlight ) {
76
+        XRectangle rect;
77
+        rect.x = rect.y = m_border;
78
+        rect.width = m_width;
79
+        rect.height = m_height;
80
+
81
+        XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSubtract, 0);
82
+    }
83
+    // Make it so all input falls through
84
+    XRectangle rect;
85
+    rect.x = rect.y = rect.width = rect.height = 0;
86
+    XShapeCombineRectangles( xengine->m_display, m_window, ShapeInput, 0, 0, &rect, 1, ShapeSet, 0);
76
     XMapWindow( xengine->m_display, m_window );
87
     XMapWindow( xengine->m_display, m_window );
77
 }
88
 }
78
 
89
 
89
     m_y = y;
100
     m_y = y;
90
     m_width = w;
101
     m_width = w;
91
     m_height = h;
102
     m_height = h;
92
-    // If we don't have a border, we don't exist, so just die.
93
-    if ( m_border == 0 ) {
94
-        return;
95
-    }
96
 
103
 
97
     // Change the window size
104
     // Change the window size
98
     XResizeWindow( xengine->m_display, m_window, m_width+m_border*2, m_height+m_border*2 );
105
     XResizeWindow( xengine->m_display, m_window, m_width+m_border*2, m_height+m_border*2 );
99
-    // Fill up our old hole
100
-    XRectangle rect;
101
-    rect.x = rect.y = 0;
102
-    rect.width = m_width+m_border*2;
103
-    rect.height = m_height+m_border*2;
104
-    XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSet, 0);
105
-    // Then punch out another.
106
-    rect.x = rect.y = m_border;
107
-    rect.width = m_width;
108
-    rect.height = m_height;
109
-    XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSubtract, 0);
106
+    if ( m_border > 0 ) {
107
+        // Fill up our old hole
108
+        XRectangle rect;
109
+        rect.x = rect.y = 0;
110
+        rect.width = m_width+m_border*2;
111
+        rect.height = m_height+m_border*2;
112
+        XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSet, 0);
113
+        // Then punch out another.
114
+        rect.x = rect.y = m_border;
115
+        rect.width = m_width;
116
+        rect.height = m_height;
117
+        XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSubtract, 0);
118
+        // Then make it so all input falls through.
119
+        rect.x = rect.y = rect.width = rect.height = 0;
120
+        XShapeCombineRectangles( xengine->m_display, m_window, ShapeInput, 0, 0, &rect, 1, ShapeSet, 0);
121
+    }
110
     XMoveWindow( xengine->m_display, m_window, m_x-m_border, m_y-m_border );
122
     XMoveWindow( xengine->m_display, m_window, m_x-m_border, m_y-m_border );
111
 }
123
 }
112
 
124
 

+ 2
- 1
rectangle.hpp View File

21
 
21
 
22
 class Rectangle {
22
 class Rectangle {
23
 public:
23
 public:
24
-            Rectangle( int sx, int sy, int ex, int ey, int border, float r, float g, float b, float a );
24
+            Rectangle( int sx, int sy, int ex, int ey, int border, bool highlight, float r, float g, float b, float a );
25
             ~Rectangle();
25
             ~Rectangle();
26
     void    setPos( int x, int y );
26
     void    setPos( int x, int y );
27
     void    setDim( int w, int h );
27
     void    setDim( int w, int h );
33
     int     m_width;
33
     int     m_width;
34
     int     m_height;
34
     int     m_height;
35
     int     m_border;
35
     int     m_border;
36
+    bool    m_highlight;
36
 private:
37
 private:
37
     int     convertColor( float r, float g, float b );
38
     int     convertColor( float r, float g, float b );
38
     void    constrain( int w, int h );
39
     void    constrain( int w, int h );

+ 1
- 1
x.cpp View File

107
     int err = XGrabKeyboard( m_display, m_root, False, GrabModeAsync, GrabModeAsync, CurrentTime );
107
     int err = XGrabKeyboard( m_display, m_root, False, GrabModeAsync, GrabModeAsync, CurrentTime );
108
     if ( err != GrabSuccess ) {
108
     if ( err != GrabSuccess ) {
109
         fprintf( stderr, "Warning: Failed to grab X keyboard.\n" );
109
         fprintf( stderr, "Warning: Failed to grab X keyboard.\n" );
110
-        fprintf( stderr, "         This happens when something's already grabbed your keybaord.\n" );
110
+        fprintf( stderr, "         This happens when something has already grabbed your keybaord.\n" );
111
         fprintf( stderr, "         slop should still run properly though.\n" );
111
         fprintf( stderr, "         slop should still run properly though.\n" );
112
         return 1;
112
         return 1;
113
     }
113
     }

+ 1
- 0
x.hpp View File

9
 #include <X11/cursorfont.h>
9
 #include <X11/cursorfont.h>
10
 #include <X11/extensions/shape.h>
10
 #include <X11/extensions/shape.h>
11
 
11
 
12
+#include <cstring>
12
 #include <cstdlib>
13
 #include <cstdlib>
13
 #include <cmath>
14
 #include <cmath>
14
 #include <cstdio>
15
 #include <cstdio>