|
@@ -8,6 +8,15 @@ slop::Rectangle::~Rectangle() {
|
8
|
8
|
if ( m_window == None ) {
|
9
|
9
|
return;
|
10
|
10
|
}
|
|
11
|
+ // Try to erase the window before destroying it.
|
|
12
|
+ XRectangle rect;
|
|
13
|
+ rect.x = 0;
|
|
14
|
+ rect.y = 0;
|
|
15
|
+ rect.width = 0;
|
|
16
|
+ rect.height = 0;
|
|
17
|
+ XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSet, 0);
|
|
18
|
+ // Sleep for 0.1 seconds in hope that the rectangle was erased.
|
|
19
|
+ usleep( 10000 );
|
11
|
20
|
// Free up our color.
|
12
|
21
|
XFreeColors( xengine->m_display, xengine->m_colormap, &m_color.pixel, 1, 0 );
|
13
|
22
|
XDestroyWindow( xengine->m_display, m_window );
|
|
@@ -36,30 +45,24 @@ slop::Rectangle::Rectangle( int sx, int sy, int ex, int ey, int border, bool hig
|
36
|
45
|
m_border = 0;
|
37
|
46
|
}
|
38
|
47
|
|
39
|
|
- // This sets up m_color
|
40
|
|
- int err = convertColor( r, g, b );
|
41
|
|
- if ( err ) {
|
42
|
|
- fprintf( stderr, "Couldn't allocate color of value %f,%f,%f!\n", r, g, b );
|
43
|
|
- }
|
|
48
|
+ m_color = convertColor( r, g, b );
|
44
|
49
|
XSetWindowAttributes attributes;
|
45
|
50
|
// Set up the window so it's our color
|
46
|
|
- attributes.background_pixmap = None;
|
47
|
51
|
attributes.background_pixel = m_color.pixel;
|
48
|
|
- attributes.border_pixel = m_color.pixel;
|
49
|
|
- // Not actually sure what this does, but it keeps the window from bugging out :u.
|
|
52
|
+ // Disable window decorations.
|
50
|
53
|
attributes.override_redirect = True;
|
51
|
|
- // We must use our color map, because that's where our color is allocated.
|
52
|
|
- attributes.colormap = xengine->m_colormap;
|
53
|
54
|
// Make sure we know when we've been successfully destroyed later!
|
54
|
55
|
attributes.event_mask = StructureNotifyMask;
|
55
|
|
- unsigned long valueMask = CWBackPixmap | CWBackPixel | CWOverrideRedirect | CWColormap | CWEventMask;
|
|
56
|
+ unsigned long valueMask = CWBackPixel | CWOverrideRedirect | CWEventMask;
|
56
|
57
|
|
57
|
58
|
// Create the window
|
58
|
|
- m_window = XCreateWindow( xengine->m_display, xengine->m_root, m_x-m_border, m_y-m_border, m_width+m_border*2, m_height+m_border*2,
|
|
59
|
+ m_window = XCreateWindow( xengine->m_display, xengine->m_root, 0, 0, WidthOfScreen( xengine->m_screen ), HeightOfScreen( xengine->m_screen ),
|
59
|
60
|
0, CopyFromParent, InputOutput,
|
60
|
61
|
CopyFromParent, valueMask, &attributes );
|
61
|
62
|
|
|
63
|
+
|
62
|
64
|
if ( a < 1 ) {
|
|
65
|
+ // Change the window opacity
|
63
|
66
|
unsigned int cardinal_alpha = (unsigned int) (a * (unsigned int)-1) ;
|
64
|
67
|
XChangeProperty( xengine->m_display, m_window, XInternAtom( xengine->m_display, "_NET_WM_WINDOW_OPACITY", 0),
|
65
|
68
|
XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&cardinal_alpha, 1 );
|
|
@@ -73,12 +76,35 @@ slop::Rectangle::Rectangle( int sx, int sy, int ex, int ey, int border, bool hig
|
73
|
76
|
|
74
|
77
|
// Now punch a hole into it so it looks like a selection rectangle, but only if we're not highlighting.
|
75
|
78
|
if ( !m_highlight ) {
|
|
79
|
+ XRectangle rects[4];
|
|
80
|
+ // Left
|
|
81
|
+ rects[0].x = m_x-m_border;
|
|
82
|
+ rects[0].y = m_y-m_border;
|
|
83
|
+ rects[0].width = m_border;
|
|
84
|
+ rects[0].height = m_height+m_border*2;
|
|
85
|
+ // Top
|
|
86
|
+ rects[1].x = m_x;
|
|
87
|
+ rects[1].y = m_y-m_border;
|
|
88
|
+ rects[1].width = m_width+m_border;
|
|
89
|
+ rects[1].height = m_border;
|
|
90
|
+ // Right
|
|
91
|
+ rects[2].x = m_x+m_width;
|
|
92
|
+ rects[2].y = m_y-m_border;
|
|
93
|
+ rects[2].width = m_border;
|
|
94
|
+ rects[2].height = m_height+m_border*2;
|
|
95
|
+ // Bottom
|
|
96
|
+ rects[3].x = m_x;
|
|
97
|
+ rects[3].y = m_y+m_height;
|
|
98
|
+ rects[3].width = m_width+m_border;
|
|
99
|
+ rects[3].height = m_border;
|
|
100
|
+ XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, rects, 4, ShapeSet, 0);
|
|
101
|
+ } else {
|
76
|
102
|
XRectangle rect;
|
77
|
|
- rect.x = rect.y = m_border;
|
|
103
|
+ rect.x = m_x;
|
|
104
|
+ rect.y = m_y;
|
78
|
105
|
rect.width = m_width;
|
79
|
106
|
rect.height = m_height;
|
80
|
|
-
|
81
|
|
- XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSubtract, 0);
|
|
107
|
+ XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSet, 0);
|
82
|
108
|
}
|
83
|
109
|
// Make it so all input falls through
|
84
|
110
|
XRectangle rect;
|
|
@@ -92,37 +118,46 @@ void slop::Rectangle::setGeo( int sx, int sy, int ex, int ey ) {
|
92
|
118
|
int y = std::min( sy, ey );
|
93
|
119
|
int w = std::max( sx, ex ) - x;
|
94
|
120
|
int h = std::max( sy, ey ) - y;
|
95
|
|
- if ( m_x == x && m_y == y && m_width == w && m_height == h ) {
|
96
|
|
- return;
|
97
|
|
- }
|
98
|
121
|
|
|
122
|
+ // Only resize or move if we have to, because they're oddly expensive.
|
99
|
123
|
m_x = x;
|
100
|
124
|
m_y = y;
|
101
|
125
|
m_width = w;
|
102
|
126
|
m_height = h;
|
103
|
|
-
|
104
|
|
- // Change the window size
|
105
|
|
- XResizeWindow( xengine->m_display, m_window, m_width+m_border*2, m_height+m_border*2 );
|
106
|
127
|
if ( m_border > 0 ) {
|
107
|
|
- // Fill up our old hole
|
|
128
|
+ XRectangle rects[4];
|
|
129
|
+ // Left
|
|
130
|
+ rects[0].x = m_x-m_border;
|
|
131
|
+ rects[0].y = m_y-m_border;
|
|
132
|
+ rects[0].width = m_border;
|
|
133
|
+ rects[0].height = m_height+m_border*2;
|
|
134
|
+ // Top
|
|
135
|
+ rects[1].x = m_x;
|
|
136
|
+ rects[1].y = m_y-m_border;
|
|
137
|
+ rects[1].width = m_width+m_border;
|
|
138
|
+ rects[1].height = m_border;
|
|
139
|
+ // Right
|
|
140
|
+ rects[2].x = m_x+m_width;
|
|
141
|
+ rects[2].y = m_y-m_border;
|
|
142
|
+ rects[2].width = m_border;
|
|
143
|
+ rects[2].height = m_height+m_border*2;
|
|
144
|
+ // Bottom
|
|
145
|
+ rects[3].x = m_x;
|
|
146
|
+ rects[3].y = m_y+m_height;
|
|
147
|
+ rects[3].width = m_width+m_border;
|
|
148
|
+ rects[3].height = m_border;
|
|
149
|
+ XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, rects, 4, ShapeSet, 0);
|
|
150
|
+ } else {
|
108
|
151
|
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;
|
|
152
|
+ rect.x = m_x;
|
|
153
|
+ rect.y = m_y;
|
115
|
154
|
rect.width = m_width;
|
116
|
155
|
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);
|
|
156
|
+ XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSet, 0);
|
121
|
157
|
}
|
122
|
|
- XMoveWindow( xengine->m_display, m_window, m_x-m_border, m_y-m_border );
|
123
|
158
|
}
|
124
|
159
|
|
125
|
|
-int slop::Rectangle::convertColor( float r, float g, float b ) {
|
|
160
|
+XColor slop::Rectangle::convertColor( float r, float g, float b ) {
|
126
|
161
|
// Convert float colors to shorts.
|
127
|
162
|
short red = short( floor( r * 65535.f ) );
|
128
|
163
|
short green = short( floor( g * 65535.f ) );
|
|
@@ -133,8 +168,7 @@ int slop::Rectangle::convertColor( float r, float g, float b ) {
|
133
|
168
|
color.blue = blue;
|
134
|
169
|
int err = XAllocColor( xengine->m_display, xengine->m_colormap, &color );
|
135
|
170
|
if ( err == BadColor ) {
|
136
|
|
- return err;
|
|
171
|
+ fprintf( stderr, "Couldn't allocate color of value %f,%f,%f!\n", r, g, b );
|
137
|
172
|
}
|
138
|
|
- m_color = color;
|
139
|
|
- return 0;
|
|
173
|
+ return color;
|
140
|
174
|
}
|