|
@@ -14,24 +14,18 @@ slop::Rectangle::~Rectangle() {
|
14
|
14
|
XEvent event;
|
15
|
15
|
// Block until the window is actually completely removed.
|
16
|
16
|
XIfEvent( xengine->m_display, &event, &isDestroyNotify, (XPointer)&m_window );
|
|
17
|
+ // Sleep for 0.1 seconds in hope that the screen actually cleared the window.
|
|
18
|
+ usleep( 10000 );
|
17
|
19
|
}
|
18
|
20
|
|
19
|
|
-slop::Rectangle::Rectangle( int x, int y, int width, int height, int border, int padding, int minimumwidth, int minimumheight, float r, float g, float b ) {
|
20
|
|
- m_xoffset = 0;
|
21
|
|
- m_yoffset = 0;
|
22
|
|
- m_x = x;
|
23
|
|
- m_y = y;
|
24
|
|
- m_width = width;
|
25
|
|
- m_height = height;
|
26
|
|
- m_minimumwidth = minimumwidth;
|
27
|
|
- m_minimumheight = minimumheight;
|
|
21
|
+slop::Rectangle::Rectangle( int sx, int sy, int ex, int ey, int border, float r, float g, float b ) {
|
|
22
|
+ m_x = std::min( sx, ex );
|
|
23
|
+ m_y = std::min( sy, ey );
|
|
24
|
+ m_width = std::max( sx, ex ) - m_x;
|
|
25
|
+ m_height = std::max( sy, ey ) - m_y;
|
28
|
26
|
m_border = border;
|
29
|
|
- m_padding = padding;
|
30
|
27
|
m_window = None;
|
31
|
28
|
|
32
|
|
- // Convert the width, height, x, and y to coordinates that don't have negative values.
|
33
|
|
- // (also adjust for padding and border size.)
|
34
|
|
- constrain( width, height );
|
35
|
29
|
// If we don't have a border, we don't exist, so just die.
|
36
|
30
|
if ( m_border == 0 ) {
|
37
|
31
|
return;
|
|
@@ -54,8 +48,8 @@ slop::Rectangle::Rectangle( int x, int y, int width, int height, int border, int
|
54
|
48
|
attributes.event_mask = StructureNotifyMask;
|
55
|
49
|
unsigned long valueMask = CWBackPixmap | CWBackPixel | CWOverrideRedirect | CWColormap | CWEventMask;
|
56
|
50
|
|
57
|
|
- // Create the window offset by our generated offsets (see constrain( float, float ))
|
58
|
|
- m_window = XCreateWindow( xengine->m_display, xengine->m_root, m_x+m_xoffset-m_border, m_y+m_yoffset-m_border, m_width+m_border*2, m_height+m_border*2,
|
|
51
|
+ // Create the window
|
|
52
|
+ 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
|
53
|
0, CopyFromParent, InputOutput,
|
60
|
54
|
CopyFromParent, valueMask, &attributes );
|
61
|
55
|
|
|
@@ -75,63 +69,27 @@ slop::Rectangle::Rectangle( int x, int y, int width, int height, int border, int
|
75
|
69
|
XMapWindow( xengine->m_display, m_window );
|
76
|
70
|
}
|
77
|
71
|
|
78
|
|
-void slop::Rectangle::setPos( int x, int y ) {
|
79
|
|
- if ( m_x == x && m_y == y ) {
|
80
|
|
- return;
|
81
|
|
- }
|
82
|
|
- m_x = x;
|
83
|
|
- m_y = y;
|
84
|
|
- // If we don't have a border, we don't exist, so just die.
|
85
|
|
- if ( m_border == 0 ) {
|
86
|
|
- return;
|
87
|
|
- }
|
88
|
|
- XMoveWindow( xengine->m_display, m_window, m_x+m_xoffset-m_border, m_y+m_yoffset-m_border );
|
89
|
|
-}
|
90
|
|
-
|
91
|
|
-void slop::Rectangle::setDim( int w, int h ) {
|
92
|
|
- if ( m_width == w && m_height == h ) {
|
93
|
|
- return;
|
94
|
|
- }
|
95
|
|
-
|
96
|
|
- constrain( w, h );
|
97
|
|
- // If we don't have a border, we don't exist, so just die.
|
98
|
|
- if ( m_border == 0 ) {
|
99
|
|
- return;
|
100
|
|
- }
|
101
|
|
-
|
102
|
|
- // Change the window size and location to our generated offsets (see constrain( float, float ))
|
103
|
|
- XResizeWindow( xengine->m_display, m_window, m_width+m_border*2, m_height+m_border*2 );
|
104
|
|
- XMoveWindow( xengine->m_display, m_window, m_x+m_xoffset-m_border, m_y+m_yoffset-m_border );
|
105
|
|
- // Regenerate our hole
|
106
|
|
- XRectangle rect;
|
107
|
|
- rect.x = rect.y = 0;
|
108
|
|
- rect.width = m_width+m_border*2;
|
109
|
|
- rect.height = m_height+m_border*2;
|
110
|
|
- XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSet, 0);
|
111
|
|
- // Then punch out another.
|
112
|
|
- rect.x = rect.y = m_border;
|
113
|
|
- rect.width = m_width;
|
114
|
|
- rect.height = m_height;
|
115
|
|
- XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSubtract, 0);
|
116
|
|
-}
|
117
|
|
-
|
118
|
|
-void slop::Rectangle::setGeo( int x, int y, int w, int h ) {
|
|
72
|
+void slop::Rectangle::setGeo( int sx, int sy, int ex, int ey ) {
|
|
73
|
+ int x = std::min( sx, ex );
|
|
74
|
+ int y = std::min( sy, ey );
|
|
75
|
+ int w = std::max( sx, ex ) - x;
|
|
76
|
+ int h = std::max( sy, ey ) - y;
|
119
|
77
|
if ( m_x == x && m_y == y && m_width == w && m_height == h ) {
|
120
|
78
|
return;
|
121
|
79
|
}
|
122
|
80
|
|
123
|
81
|
m_x = x;
|
124
|
82
|
m_y = y;
|
125
|
|
- constrain( w, h );
|
|
83
|
+ m_width = w;
|
|
84
|
+ m_height = h;
|
126
|
85
|
// If we don't have a border, we don't exist, so just die.
|
127
|
86
|
if ( m_border == 0 ) {
|
128
|
87
|
return;
|
129
|
88
|
}
|
130
|
89
|
|
131
|
|
- // Change the window size and location to our generated offsets (see constrain( float, float ))
|
|
90
|
+ // Change the window size
|
132
|
91
|
XResizeWindow( xengine->m_display, m_window, m_width+m_border*2, m_height+m_border*2 );
|
133
|
|
- XMoveWindow( xengine->m_display, m_window, m_x+m_xoffset-m_border, m_y+m_yoffset-m_border );
|
134
|
|
- // Regenerate our hole
|
|
92
|
+ // Fill up our old hole
|
135
|
93
|
XRectangle rect;
|
136
|
94
|
rect.x = rect.y = 0;
|
137
|
95
|
rect.width = m_width+m_border*2;
|
|
@@ -142,44 +100,7 @@ void slop::Rectangle::setGeo( int x, int y, int w, int h ) {
|
142
|
100
|
rect.width = m_width;
|
143
|
101
|
rect.height = m_height;
|
144
|
102
|
XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSubtract, 0);
|
145
|
|
-}
|
146
|
|
-
|
147
|
|
-// Keeps our rectangle's sizes all positive, so Xlib doesn't throw an exception.
|
148
|
|
-// It also keeps our values in absolute coordinates which is nice.
|
149
|
|
-void slop::Rectangle::constrain( int w, int h ) {
|
150
|
|
- int pad = m_padding;
|
151
|
|
- if ( pad < 0 && std::abs( w ) < std::abs( pad ) * 2 ) {
|
152
|
|
- pad = 0;
|
153
|
|
- }
|
154
|
|
- if ( w < 0 ) {
|
155
|
|
- m_flippedx = true;
|
156
|
|
- m_xoffset = w - pad;
|
157
|
|
- m_width = -w + pad * 2;
|
158
|
|
- } else {
|
159
|
|
- m_flippedx = false;
|
160
|
|
- m_xoffset = -pad;
|
161
|
|
- m_width = w + pad * 2;
|
162
|
|
- }
|
163
|
|
-
|
164
|
|
- pad = m_padding;
|
165
|
|
- if ( pad < 0 && std::abs( h ) < std::abs( pad ) * 2 ) {
|
166
|
|
- pad = 0;
|
167
|
|
- }
|
168
|
|
- if ( h < 0 ) {
|
169
|
|
- m_flippedy = true;
|
170
|
|
- m_yoffset = h - pad;
|
171
|
|
- m_height = -h + pad * 2;
|
172
|
|
- } else {
|
173
|
|
- m_flippedy = false;
|
174
|
|
- m_yoffset = -pad;
|
175
|
|
- m_height = h + pad * 2;
|
176
|
|
- }
|
177
|
|
- if ( m_width < m_minimumwidth ) {
|
178
|
|
- m_width = m_minimumwidth;
|
179
|
|
- }
|
180
|
|
- if ( m_height < m_minimumheight ) {
|
181
|
|
- m_height = m_minimumheight;
|
182
|
|
- }
|
|
103
|
+ XMoveWindow( xengine->m_display, m_window, m_x-m_border, m_y-m_border );
|
183
|
104
|
}
|
184
|
105
|
|
185
|
106
|
int slop::Rectangle::convertColor( float r, float g, float b ) {
|