Bläddra i källkod

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

Dalton Nell 9 år sedan
förälder
incheckning
edd9784e85
8 ändrade filer med 67 tillägg och 34 borttagningar
  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 Visa fil

@@ -61,13 +61,16 @@ Options
61 61
     -t=INT, --tolerance=INT        How far in pixels the mouse can move after clicking and still be detected
62 62
                                    as a normal click. Setting to zero will disable window selections.
63 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 66
     -g=FLOAT, --gracetime=FLOAT    Set the amount of time before slop will check for keyboard cancellations
66 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 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 74
     -v, --version                  prints version.
72 75
 
73 76
 Examples
@@ -79,4 +82,7 @@ Examples
79 82
 
80 83
     $ # Disable window selections. Useful for selecting individual pixels.
81 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 Visa fil

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

+ 14
- 5
options.cpp Visa fil

@@ -3,7 +3,8 @@
3 3
 slop::Options* options = new slop::Options();
4 4
 
5 5
 slop::Options::Options() {
6
-    m_version = "v2.0.8";
6
+    m_version = "v2.0.9";
7
+    m_highlight = false;
7 8
     m_borderSize = 10;
8 9
     m_padding = 0;
9 10
     m_xdisplay = ":0";
@@ -31,13 +32,16 @@ void slop::Options::printHelp() {
31 32
     printf( "    -t=INT, --tolerance=INT        How far in pixels the mouse can move after clicking and still be detected\n" );
32 33
     printf( "                                   as a normal click. Setting to zero will disable window selections.\n" );
33 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 37
     printf( "    -g=FLOAT, --gracetime=FLOAT    Set the amount of time before slop will check for keyboard cancellations\n" );
36 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 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 45
     printf( "    -v, --version                  prints version.\n" );
42 46
     printf( "\n" );
43 47
     printf( "Examples\n" );
@@ -49,6 +53,9 @@ void slop::Options::printHelp() {
49 53
     printf( "\n" );
50 54
     printf( "    $ # Disable window selections. Useful for selecting individual pixels.\n" );
51 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 61
 int slop::Options::parseOptions( int argc, char** argv ) {
@@ -109,6 +116,8 @@ int slop::Options::parseOptions( int argc, char** argv ) {
109 116
             m_keyboard = false;
110 117
         } else if ( matches( arg, "-nd", "--nodecorations" ) ) {
111 118
             m_decorations = false;
119
+        } else if ( matches( arg, "-hi", "--highlight" ) ) {
120
+            m_highlight = true;
112 121
         } else if ( matches( arg, "-h", "--help" ) ) {
113 122
             printHelp();
114 123
             return 2;

+ 1
- 0
options.hpp Visa fil

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

+ 35
- 23
rectangle.cpp Visa fil

@@ -18,19 +18,24 @@ slop::Rectangle::~Rectangle() {
18 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 22
     m_x = std::min( sx, ex );
23 23
     m_y = std::min( sy, ey );
24 24
     m_width = std::max( sx, ex ) - m_x;
25 25
     m_height = std::max( sy, ey ) - m_y;
26 26
     m_border = border;
27 27
     m_window = None;
28
+    m_highlight = highlight;
28 29
 
29 30
     // If we don't have a border, we don't exist, so just die.
30 31
     if ( m_border == 0 ) {
31 32
         return;
32 33
     }
33 34
 
35
+    if ( m_highlight ) {
36
+        m_border = 0;
37
+    }
38
+
34 39
     // This sets up m_color
35 40
     int err = convertColor( r, g, b );
36 41
     if ( err ) {
@@ -60,19 +65,25 @@ slop::Rectangle::Rectangle( int sx, int sy, int ex, int ey, int border, float r,
60 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 68
     XClassHint classhints;
70 69
     char name[] = "slop";
71 70
     classhints.res_name = name;
72 71
     classhints.res_class = name;
73 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 87
     XMapWindow( xengine->m_display, m_window );
77 88
 }
78 89
 
@@ -89,24 +100,25 @@ void slop::Rectangle::setGeo( int sx, int sy, int ex, int ey ) {
89 100
     m_y = y;
90 101
     m_width = w;
91 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 104
     // Change the window size
98 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 122
     XMoveWindow( xengine->m_display, m_window, m_x-m_border, m_y-m_border );
111 123
 }
112 124
 

+ 2
- 1
rectangle.hpp Visa fil

@@ -21,7 +21,7 @@ namespace slop {
21 21
 
22 22
 class Rectangle {
23 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 25
             ~Rectangle();
26 26
     void    setPos( int x, int y );
27 27
     void    setDim( int w, int h );
@@ -33,6 +33,7 @@ public:
33 33
     int     m_width;
34 34
     int     m_height;
35 35
     int     m_border;
36
+    bool    m_highlight;
36 37
 private:
37 38
     int     convertColor( float r, float g, float b );
38 39
     void    constrain( int w, int h );

+ 1
- 1
x.cpp Visa fil

@@ -107,7 +107,7 @@ int slop::XEngine::grabKeyboard() {
107 107
     int err = XGrabKeyboard( m_display, m_root, False, GrabModeAsync, GrabModeAsync, CurrentTime );
108 108
     if ( err != GrabSuccess ) {
109 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 111
         fprintf( stderr, "         slop should still run properly though.\n" );
112 112
         return 1;
113 113
     }

+ 1
- 0
x.hpp Visa fil

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