Skip to content

Commit edd9784

Browse files
committed
Added highlight feature, and now events fall through slop windows.
1 parent a31494b commit edd9784

File tree

8 files changed

+67
-34
lines changed

8 files changed

+67
-34
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@ Options
6161
-t=INT, --tolerance=INT How far in pixels the mouse can move after clicking and still be detected
6262
as a normal click. Setting to zero will disable window selections.
6363
-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.
6566
-g=FLOAT, --gracetime=FLOAT Set the amount of time before slop will check for keyboard cancellations
6667
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.
7071
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.
7174
-v, --version prints version.
7275
7376
Examples
@@ -79,4 +82,7 @@ Examples
7982
8083
$ # Disable window selections. Useful for selecting individual pixels.
8184
$ slop -t=0
85+
86+
$ # Classic Windows XP selection.
87+
$ slop -hi -c=0.2,0.4,0.5,0.4
8288
```

main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ int main( int argc, char** argv ) {
100100
float g = options->m_green;
101101
float b = options->m_blue;
102102
float a = options->m_alpha;
103+
bool highlight = options->m_highlight;
103104
bool keyboard = options->m_keyboard;
104105
bool decorations = options->m_decorations;
105106
timespec start, time;
@@ -170,6 +171,7 @@ int main( int argc, char** argv ) {
170171
t.m_x + t.m_width,
171172
t.m_y + t.m_height,
172173
borderSize,
174+
highlight,
173175
r, g, b, a );
174176
} else {
175177
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 ) {
208210
xengine->m_mousex + 1,
209211
xengine->m_mousey + 1,
210212
borderSize,
213+
highlight,
211214
r, g, b, a );
212215
}
213216
// If the user has let go of the mouse button, we'll just

options.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
slop::Options* options = new slop::Options();
44

55
slop::Options::Options() {
6-
m_version = "v2.0.8";
6+
m_version = "v2.0.9";
7+
m_highlight = false;
78
m_borderSize = 10;
89
m_padding = 0;
910
m_xdisplay = ":0";
@@ -31,13 +32,16 @@ void slop::Options::printHelp() {
3132
printf( " -t=INT, --tolerance=INT How far in pixels the mouse can move after clicking and still be detected\n" );
3233
printf( " as a normal click. Setting to zero will disable window selections.\n" );
3334
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" );
3537
printf( " -g=FLOAT, --gracetime=FLOAT Set the amount of time before slop will check for keyboard cancellations\n" );
3638
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" );
4042
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" );
4145
printf( " -v, --version prints version.\n" );
4246
printf( "\n" );
4347
printf( "Examples\n" );
@@ -49,6 +53,9 @@ void slop::Options::printHelp() {
4953
printf( "\n" );
5054
printf( " $ # Disable window selections. Useful for selecting individual pixels.\n" );
5155
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" );
5259
}
5360

5461
int slop::Options::parseOptions( int argc, char** argv ) {
@@ -109,6 +116,8 @@ int slop::Options::parseOptions( int argc, char** argv ) {
109116
m_keyboard = false;
110117
} else if ( matches( arg, "-nd", "--nodecorations" ) ) {
111118
m_decorations = false;
119+
} else if ( matches( arg, "-hi", "--highlight" ) ) {
120+
m_highlight = true;
112121
} else if ( matches( arg, "-h", "--help" ) ) {
113122
printHelp();
114123
return 2;

options.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Options {
2626
float m_gracetime;
2727
bool m_keyboard;
2828
bool m_decorations;
29+
bool m_highlight;
2930
private:
3031
int parseInt( std::string arg, int* returnInt );
3132
int parseFloat( std::string arg, float* returnFloat );

rectangle.cpp

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,24 @@ slop::Rectangle::~Rectangle() {
1818
usleep( 10000 );
1919
}
2020

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 ) {
2222
m_x = std::min( sx, ex );
2323
m_y = std::min( sy, ey );
2424
m_width = std::max( sx, ex ) - m_x;
2525
m_height = std::max( sy, ey ) - m_y;
2626
m_border = border;
2727
m_window = None;
28+
m_highlight = highlight;
2829

2930
// If we don't have a border, we don't exist, so just die.
3031
if ( m_border == 0 ) {
3132
return;
3233
}
3334

35+
if ( m_highlight ) {
36+
m_border = 0;
37+
}
38+
3439
// This sets up m_color
3540
int err = convertColor( r, g, b );
3641
if ( err ) {
@@ -60,19 +65,25 @@ slop::Rectangle::Rectangle( int sx, int sy, int ex, int ey, int border, float r,
6065
XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&cardinal_alpha, 1 );
6166
}
6267

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-
6968
XClassHint classhints;
7069
char name[] = "slop";
7170
classhints.res_name = name;
7271
classhints.res_class = name;
7372
XSetClassHint( xengine->m_display, m_window, &classhints );
7473

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);
7687
XMapWindow( xengine->m_display, m_window );
7788
}
7889

@@ -89,24 +100,25 @@ void slop::Rectangle::setGeo( int sx, int sy, int ex, int ey ) {
89100
m_y = y;
90101
m_width = w;
91102
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-
}
96103

97104
// Change the window size
98105
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+
}
110122
XMoveWindow( xengine->m_display, m_window, m_x-m_border, m_y-m_border );
111123
}
112124

rectangle.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace slop {
2121

2222
class Rectangle {
2323
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 );
2525
~Rectangle();
2626
void setPos( int x, int y );
2727
void setDim( int w, int h );
@@ -33,6 +33,7 @@ class Rectangle {
3333
int m_width;
3434
int m_height;
3535
int m_border;
36+
bool m_highlight;
3637
private:
3738
int convertColor( float r, float g, float b );
3839
void constrain( int w, int h );

x.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ int slop::XEngine::grabKeyboard() {
107107
int err = XGrabKeyboard( m_display, m_root, False, GrabModeAsync, GrabModeAsync, CurrentTime );
108108
if ( err != GrabSuccess ) {
109109
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" );
111111
fprintf( stderr, " slop should still run properly though.\n" );
112112
return 1;
113113
}

x.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <X11/cursorfont.h>
1010
#include <X11/extensions/shape.h>
1111

12+
#include <cstring>
1213
#include <cstdlib>
1314
#include <cmath>
1415
#include <cstdio>

0 commit comments

Comments
 (0)