Browse Source

Added transparency suppport.

Dalton Nell 9 years ago
parent
commit
a31494baa5
6 changed files with 33 additions and 17 deletions
  1. 6
    3
      README.md
  2. 3
    2
      main.cpp
  3. 12
    9
      options.cpp
  4. 2
    1
      options.hpp
  5. 8
    1
      rectangle.cpp
  6. 2
    1
      rectangle.hpp

+ 6
- 3
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
64
+    -c=COLOR, --color=COLOR        Set selection rectangle color, COLOR is in format FLOAT,FLOAT,FLOAT,FLOAT
65
     -g=FLOAT, --gracetime=FLOAT    Set the amount of time before slop will check for keyboard cancellations
65
     -g=FLOAT, --gracetime=FLOAT    Set the amount of time before slop will check for keyboard cancellations
66
                                    in seconds.
66
                                    in seconds.
67
     -nd, --nodecorations           attempts to remove decorations from window selections.
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.
70
+                                   widths or heights.
68
     -v, --version                  prints version.
71
     -v, --version                  prints version.
69
 
72
 
70
 Examples
73
 Examples
71
-    $ # Gray, thick border for maximum visiblity.
72
-    $ slop -b=20 -c=0.5,0.5,0.5
74
+    $ # Gray, thick, transparent border for maximum visiblity.
75
+    $ slop -b=20 -c=0.5,0.5,0.5,0.8
73
 
76
 
74
     $ # Remove window decorations.
77
     $ # Remove window decorations.
75
     $ slop -nd
78
     $ slop -nd

+ 3
- 2
main.cpp View File

99
     float r = options->m_red;
99
     float r = options->m_red;
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
     bool keyboard = options->m_keyboard;
103
     bool keyboard = options->m_keyboard;
103
     bool decorations = options->m_decorations;
104
     bool decorations = options->m_decorations;
104
     timespec start, time;
105
     timespec start, time;
169
                                                          t.m_x + t.m_width,
170
                                                          t.m_x + t.m_width,
170
                                                          t.m_y + t.m_height,
171
                                                          t.m_y + t.m_height,
171
                                                          borderSize,
172
                                                          borderSize,
172
-                                                         r, g, b );
173
+                                                         r, g, b, a );
173
                     } else {
174
                     } else {
174
                         selection->setGeo( t.m_x, t.m_y, t.m_x + t.m_width, t.m_y + t.m_height );
175
                         selection->setGeo( t.m_x, t.m_y, t.m_x + t.m_width, t.m_y + t.m_height );
175
                     }
176
                     }
207
                                                      xengine->m_mousex + 1,
208
                                                      xengine->m_mousex + 1,
208
                                                      xengine->m_mousey + 1,
209
                                                      xengine->m_mousey + 1,
209
                                                      borderSize,
210
                                                      borderSize,
210
-                                                     r, g, b );
211
+                                                     r, g, b, a );
211
                 }
212
                 }
212
                 // If the user has let go of the mouse button, we'll just
213
                 // If the user has let go of the mouse button, we'll just
213
                 // continue to the next state.
214
                 // continue to the next state.

+ 12
- 9
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.7";
6
+    m_version = "v2.0.8";
7
     m_borderSize = 10;
7
     m_borderSize = 10;
8
     m_padding = 0;
8
     m_padding = 0;
9
     m_xdisplay = ":0";
9
     m_xdisplay = ":0";
11
     m_red = 0;
11
     m_red = 0;
12
     m_green = 0;
12
     m_green = 0;
13
     m_blue = 0;
13
     m_blue = 0;
14
+    m_alpha = 1;
14
     m_gracetime = 0.4;
15
     m_gracetime = 0.4;
15
     m_keyboard = true;
16
     m_keyboard = true;
16
     m_decorations = true;
17
     m_decorations = true;
30
     printf( "    -t=INT, --tolerance=INT        How far in pixels the mouse can move after clicking and still be detected\n" );
31
     printf( "    -t=INT, --tolerance=INT        How far in pixels the mouse can move after clicking and still be detected\n" );
31
     printf( "                                   as a normal click. Setting to zero will disable window selections.\n" );
32
     printf( "                                   as a normal click. Setting to zero will disable window selections.\n" );
32
     printf( "    -x=STRING, --xdisplay=STRING   Set x display (STRING must be hostname:number.screen_number format)\n" );
33
     printf( "    -x=STRING, --xdisplay=STRING   Set x display (STRING must be hostname:number.screen_number format)\n" );
33
-    printf( "    -c=COLOR, --color=COLOR        Set selection rectangle color, COLOR is in format FLOAT,FLOAT,FLOAT\n" );
34
+    printf( "    -c=COLOR, --color=COLOR        Set selection rectangle color, COLOR is in format FLOAT,FLOAT,FLOAT,FLOAT\n" );
34
     printf( "    -g=FLOAT, --gracetime=FLOAT    Set the amount of time before slop will check for keyboard cancellations\n" );
35
     printf( "    -g=FLOAT, --gracetime=FLOAT    Set the amount of time before slop will check for keyboard cancellations\n" );
35
     printf( "                                   in seconds.\n" );
36
     printf( "                                   in seconds.\n" );
36
     printf( "    -nd, --nodecorations           attempts to remove decorations from window selections.\n" );
37
     printf( "    -nd, --nodecorations           attempts to remove decorations from window selections.\n" );
40
     printf( "    -v, --version                  prints version.\n" );
41
     printf( "    -v, --version                  prints version.\n" );
41
     printf( "\n" );
42
     printf( "\n" );
42
     printf( "Examples\n" );
43
     printf( "Examples\n" );
43
-    printf( "    $ # Gray, thick border for maximum visiblity.\n" );
44
-    printf( "    $ slop -b=20 -c=0.5,0.5,0.5\n" );
44
+    printf( "    $ # Gray, thick, transparent border for maximum visiblity.\n" );
45
+    printf( "    $ slop -b=20 -c=0.5,0.5,0.5,0.8\n" );
45
     printf( "\n" );
46
     printf( "\n" );
46
     printf( "    $ # Remove window decorations.\n" );
47
     printf( "    $ # Remove window decorations.\n" );
47
     printf( "    $ slop -nd\n" );
48
     printf( "    $ slop -nd\n" );
79
                 return 1;
80
                 return 1;
80
             }
81
             }
81
         } else if ( matches( arg, "-c=", "--color=" ) ) {
82
         } else if ( matches( arg, "-c=", "--color=" ) ) {
82
-            int err = parseColor( arg, &m_red, &m_green, &m_blue );
83
+            int err = parseColor( arg, &m_red, &m_green, &m_blue, &m_alpha );
83
             if ( err ) {
84
             if ( err ) {
84
                 return 1;
85
                 return 1;
85
             }
86
             }
211
     return 0;
212
     return 0;
212
 }
213
 }
213
 
214
 
214
-int slop::Options::parseColor( std::string arg, float* r, float* g, float* b ) {
215
+int slop::Options::parseColor( std::string arg, float* r, float* g, float* b, float* a ) {
215
     std::string copy = arg;
216
     std::string copy = arg;
216
     int find = copy.find( "=" );
217
     int find = copy.find( "=" );
217
     while( find != copy.npos ) {
218
     while( find != copy.npos ) {
221
 
222
 
222
     // Just in case we error out, grab the actual argument name into x.
223
     // Just in case we error out, grab the actual argument name into x.
223
     char* x = new char[ arg.size() ];
224
     char* x = new char[ arg.size() ];
224
-    int num = sscanf( copy.c_str(), "%s %f %f %f", x, r, g, b );
225
-    if ( num != 4 ) {
225
+    // Just in case we didn't include an alpha value
226
+    *a = 1;
227
+    int num = sscanf( copy.c_str(), "%s %f %f %f %f", x, r, g, b, a );
228
+    if ( num != 4 && num != 5 ) {
226
         fprintf( stderr, "Error parsing command arguments near %s\n", arg.c_str() );
229
         fprintf( stderr, "Error parsing command arguments near %s\n", arg.c_str() );
227
         fprintf( stderr, "Usage: %s=COLOR\n", x );
230
         fprintf( stderr, "Usage: %s=COLOR\n", x );
228
-        fprintf( stderr, "Example: %s=0,0,0 or %s=0.7,0.2,1\n", x, x );
231
+        fprintf( stderr, "Example: %s=0,0,0 or %s=0.7,0.2,1,0.5 or %s=1,1,1,0.8\n", x, x, x );
229
         fprintf( stderr, "Try -h or --help for help.\n" );
232
         fprintf( stderr, "Try -h or --help for help.\n" );
230
         delete[] x;
233
         delete[] x;
231
         return 1;
234
         return 1;

+ 2
- 1
options.hpp View File

21
     float       m_red;
21
     float       m_red;
22
     float       m_green;
22
     float       m_green;
23
     float       m_blue;
23
     float       m_blue;
24
+    float       m_alpha;
24
     std::string m_xdisplay;
25
     std::string m_xdisplay;
25
     float       m_gracetime;
26
     float       m_gracetime;
26
     bool        m_keyboard;
27
     bool        m_keyboard;
30
     int         parseFloat( std::string arg, float* returnFloat );
31
     int         parseFloat( std::string arg, float* returnFloat );
31
     int         parseString( std::string arg, std::string* returnString );
32
     int         parseString( std::string arg, std::string* returnString );
32
     int         parseGeometry( std::string arg, int* x, int* y, int* w, int* h );
33
     int         parseGeometry( std::string arg, int* x, int* y, int* w, int* h );
33
-    int         parseColor( std::string arg, float* r, float* g, float* b );
34
+    int         parseColor( std::string arg, float* r, float* g, float* b, float* a );
34
     bool        matches( std::string arg, std::string shorthand, std::string longhand );
35
     bool        matches( std::string arg, std::string shorthand, std::string longhand );
35
 };
36
 };
36
 
37
 

+ 8
- 1
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 ) {
21
+slop::Rectangle::Rectangle( int sx, int sy, int ex, int ey, int border, 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;
40
     // Set up the window so it's our color 
40
     // Set up the window so it's our color 
41
     attributes.background_pixmap = None;
41
     attributes.background_pixmap = None;
42
     attributes.background_pixel = m_color.pixel;
42
     attributes.background_pixel = m_color.pixel;
43
+    attributes.border_pixel = m_color.pixel;
43
     // Not actually sure what this does, but it keeps the window from bugging out :u.
44
     // Not actually sure what this does, but it keeps the window from bugging out :u.
44
     attributes.override_redirect = True;
45
     attributes.override_redirect = True;
45
     // We must use our color map, because that's where our color is allocated.
46
     // We must use our color map, because that's where our color is allocated.
53
                               0, CopyFromParent, InputOutput,
54
                               0, CopyFromParent, InputOutput,
54
                               CopyFromParent, valueMask, &attributes );
55
                               CopyFromParent, valueMask, &attributes );
55
 
56
 
57
+    if ( a < 1 ) {
58
+        unsigned int cardinal_alpha = (unsigned int) (a * (unsigned int)-1) ;
59
+        XChangeProperty( xengine->m_display, m_window, XInternAtom( xengine->m_display, "_NET_WM_WINDOW_OPACITY", 0),
60
+                         XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&cardinal_alpha, 1 );
61
+    }
62
+
56
     // Now punch a hole into it so it looks like a selection rectangle!
63
     // Now punch a hole into it so it looks like a selection rectangle!
57
     XRectangle rect;
64
     XRectangle rect;
58
     rect.x = rect.y = m_border;
65
     rect.x = rect.y = m_border;

+ 2
- 1
rectangle.hpp View File

9
 
9
 
10
 #include <X11/Xlib.h>
10
 #include <X11/Xlib.h>
11
 #include <X11/extensions/shape.h>
11
 #include <X11/extensions/shape.h>
12
+#include <X11/Xatom.h>
12
 
13
 
13
 #include <cstdlib>
14
 #include <cstdlib>
14
 #include <cmath>
15
 #include <cmath>
20
 
21
 
21
 class Rectangle {
22
 class Rectangle {
22
 public:
23
 public:
23
-            Rectangle( int sx, int sy, int ex, int ey, int border, float r, float g, float b );
24
+            Rectangle( int sx, int sy, int ex, int ey, int border, float r, float g, float b, float a );
24
             ~Rectangle();
25
             ~Rectangle();
25
     void    setPos( int x, int y );
26
     void    setPos( int x, int y );
26
     void    setDim( int w, int h );
27
     void    setDim( int w, int h );