소스 검색

Added transparency suppport.

Dalton Nell 9 년 전
부모
커밋
a31494baa5
6개의 변경된 파일33개의 추가작업 그리고 17개의 파일을 삭제
  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 파일 보기

@@ -61,15 +61,18 @@ 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
64
+    -c=COLOR, --color=COLOR        Set selection rectangle color, COLOR is in format FLOAT,FLOAT,FLOAT,FLOAT
65 65
     -g=FLOAT, --gracetime=FLOAT    Set the amount of time before slop will check for keyboard cancellations
66 66
                                    in seconds.
67 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 71
     -v, --version                  prints version.
69 72
 
70 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 77
     $ # Remove window decorations.
75 78
     $ slop -nd

+ 3
- 2
main.cpp 파일 보기

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

+ 12
- 9
options.cpp 파일 보기

@@ -3,7 +3,7 @@
3 3
 slop::Options* options = new slop::Options();
4 4
 
5 5
 slop::Options::Options() {
6
-    m_version = "v2.0.7";
6
+    m_version = "v2.0.8";
7 7
     m_borderSize = 10;
8 8
     m_padding = 0;
9 9
     m_xdisplay = ":0";
@@ -11,6 +11,7 @@ slop::Options::Options() {
11 11
     m_red = 0;
12 12
     m_green = 0;
13 13
     m_blue = 0;
14
+    m_alpha = 1;
14 15
     m_gracetime = 0.4;
15 16
     m_keyboard = true;
16 17
     m_decorations = true;
@@ -30,7 +31,7 @@ void slop::Options::printHelp() {
30 31
     printf( "    -t=INT, --tolerance=INT        How far in pixels the mouse can move after clicking and still be detected\n" );
31 32
     printf( "                                   as a normal click. Setting to zero will disable window selections.\n" );
32 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 35
     printf( "    -g=FLOAT, --gracetime=FLOAT    Set the amount of time before slop will check for keyboard cancellations\n" );
35 36
     printf( "                                   in seconds.\n" );
36 37
     printf( "    -nd, --nodecorations           attempts to remove decorations from window selections.\n" );
@@ -40,8 +41,8 @@ void slop::Options::printHelp() {
40 41
     printf( "    -v, --version                  prints version.\n" );
41 42
     printf( "\n" );
42 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 46
     printf( "\n" );
46 47
     printf( "    $ # Remove window decorations.\n" );
47 48
     printf( "    $ slop -nd\n" );
@@ -79,7 +80,7 @@ int slop::Options::parseOptions( int argc, char** argv ) {
79 80
                 return 1;
80 81
             }
81 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 84
             if ( err ) {
84 85
                 return 1;
85 86
             }
@@ -211,7 +212,7 @@ int slop::Options::parseString( std::string arg, std::string* returnString ) {
211 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 216
     std::string copy = arg;
216 217
     int find = copy.find( "=" );
217 218
     while( find != copy.npos ) {
@@ -221,11 +222,13 @@ int slop::Options::parseColor( std::string arg, float* r, float* g, float* b ) {
221 222
 
222 223
     // Just in case we error out, grab the actual argument name into x.
223 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 229
         fprintf( stderr, "Error parsing command arguments near %s\n", arg.c_str() );
227 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 232
         fprintf( stderr, "Try -h or --help for help.\n" );
230 233
         delete[] x;
231 234
         return 1;

+ 2
- 1
options.hpp 파일 보기

@@ -21,6 +21,7 @@ public:
21 21
     float       m_red;
22 22
     float       m_green;
23 23
     float       m_blue;
24
+    float       m_alpha;
24 25
     std::string m_xdisplay;
25 26
     float       m_gracetime;
26 27
     bool        m_keyboard;
@@ -30,7 +31,7 @@ private:
30 31
     int         parseFloat( std::string arg, float* returnFloat );
31 32
     int         parseString( std::string arg, std::string* returnString );
32 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 35
     bool        matches( std::string arg, std::string shorthand, std::string longhand );
35 36
 };
36 37
 

+ 8
- 1
rectangle.cpp 파일 보기

@@ -18,7 +18,7 @@ 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 ) {
21
+slop::Rectangle::Rectangle( int sx, int sy, int ex, int ey, int border, 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;
@@ -40,6 +40,7 @@ slop::Rectangle::Rectangle( int sx, int sy, int ex, int ey, int border, float r,
40 40
     // Set up the window so it's our color 
41 41
     attributes.background_pixmap = None;
42 42
     attributes.background_pixel = m_color.pixel;
43
+    attributes.border_pixel = m_color.pixel;
43 44
     // Not actually sure what this does, but it keeps the window from bugging out :u.
44 45
     attributes.override_redirect = True;
45 46
     // We must use our color map, because that's where our color is allocated.
@@ -53,6 +54,12 @@ slop::Rectangle::Rectangle( int sx, int sy, int ex, int ey, int border, float r,
53 54
                               0, CopyFromParent, InputOutput,
54 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 63
     // Now punch a hole into it so it looks like a selection rectangle!
57 64
     XRectangle rect;
58 65
     rect.x = rect.y = m_border;

+ 2
- 1
rectangle.hpp 파일 보기

@@ -9,6 +9,7 @@
9 9
 
10 10
 #include <X11/Xlib.h>
11 11
 #include <X11/extensions/shape.h>
12
+#include <X11/Xatom.h>
12 13
 
13 14
 #include <cstdlib>
14 15
 #include <cmath>
@@ -20,7 +21,7 @@ namespace slop {
20 21
 
21 22
 class Rectangle {
22 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 25
             ~Rectangle();
25 26
     void    setPos( int x, int y );
26 27
     void    setDim( int w, int h );