|
@@ -26,7 +26,7 @@ int slop::XEngineErrorHandler( Display* dpy, XErrorEvent* event ) {
|
26
|
26
|
// 31 = XGrabKeyboard's request code
|
27
|
27
|
if ( event->request_code == 31 && event->error_code == BadAccess ) {
|
28
|
28
|
fprintf( stderr, "_X Error \"BadAccess\" for XGrabKeyboard ignored...\n" );
|
29
|
|
- return 0;
|
|
29
|
+ return EXIT_SUCCESS;
|
30
|
30
|
}
|
31
|
31
|
// Everything else should be fatal as I don't like undefined behavior.
|
32
|
32
|
char buffer[1024];
|
|
@@ -39,21 +39,22 @@ int slop::XEngineErrorHandler( Display* dpy, XErrorEvent* event ) {
|
39
|
39
|
exit(1);
|
40
|
40
|
}
|
41
|
41
|
|
42
|
|
-int slop::XEngine::getWidth() {
|
|
42
|
+unsigned int slop::XEngine::getWidth() {
|
43
|
43
|
if ( !m_good ) {
|
44
|
44
|
return -1;
|
45
|
45
|
}
|
46
|
|
- return (int)WidthOfScreen( m_screen );
|
|
46
|
+ return WidthOfScreen( m_screen );
|
47
|
47
|
}
|
48
|
48
|
|
49
|
|
-int slop::XEngine::getHeight() {
|
|
49
|
+unsigned int slop::XEngine::getHeight() {
|
50
|
50
|
if ( !m_good ) {
|
51
|
51
|
return -1;
|
52
|
52
|
}
|
53
|
|
- return (int)HeightOfScreen( m_screen );
|
|
53
|
+ return HeightOfScreen( m_screen );
|
54
|
54
|
}
|
55
|
55
|
|
56
|
56
|
slop::XEngine::XEngine() {
|
|
57
|
+ m_keypressed = false;
|
57
|
58
|
m_display = NULL;
|
58
|
59
|
m_visual = NULL;
|
59
|
60
|
m_screen = NULL;
|
|
@@ -87,7 +88,7 @@ int slop::XEngine::init( std::string display ) {
|
87
|
88
|
m_display = XOpenDisplay( display.c_str() );
|
88
|
89
|
if ( !m_display ) {
|
89
|
90
|
fprintf( stderr, "Error: Failed to open X display %s\n", display.c_str() );
|
90
|
|
- return 1;
|
|
91
|
+ return EXIT_FAILURE;
|
91
|
92
|
}
|
92
|
93
|
m_screen = ScreenOfDisplay( m_display, DefaultScreen( m_display ) );
|
93
|
94
|
m_visual = DefaultVisual ( m_display, XScreenNumberOfScreen( m_screen ) );
|
|
@@ -98,7 +99,7 @@ int slop::XEngine::init( std::string display ) {
|
98
|
99
|
m_good = true;
|
99
|
100
|
XSetErrorHandler( slop::XEngineErrorHandler );
|
100
|
101
|
selectAllInputs( m_root, EnterWindowMask );
|
101
|
|
- return 0;
|
|
102
|
+ return EXIT_SUCCESS;
|
102
|
103
|
}
|
103
|
104
|
|
104
|
105
|
bool slop::XEngine::anyKeyPressed() {
|
|
@@ -121,24 +122,24 @@ bool slop::XEngine::anyKeyPressed() {
|
121
|
122
|
|
122
|
123
|
int slop::XEngine::grabKeyboard() {
|
123
|
124
|
if ( !m_good ) {
|
124
|
|
- return 1;
|
|
125
|
+ return EXIT_FAILURE;
|
125
|
126
|
}
|
126
|
127
|
int err = XGrabKeyboard( m_display, m_root, False, GrabModeAsync, GrabModeAsync, CurrentTime );
|
127
|
128
|
if ( err != GrabSuccess ) {
|
128
|
129
|
fprintf( stderr, "Warning: Failed to grab X keyboard.\n" );
|
129
|
130
|
fprintf( stderr, " This happens when something has already grabbed your keybaord.\n" );
|
130
|
131
|
fprintf( stderr, " slop should still run properly though.\n" );
|
131
|
|
- return 1;
|
|
132
|
+ return EXIT_FAILURE;
|
132
|
133
|
}
|
133
|
|
- return 0;
|
|
134
|
+ return EXIT_SUCCESS;
|
134
|
135
|
}
|
135
|
136
|
|
136
|
137
|
int slop::XEngine::releaseKeyboard() {
|
137
|
138
|
if ( !m_good ) {
|
138
|
|
- return 1;
|
|
139
|
+ return EXIT_FAILURE;
|
139
|
140
|
}
|
140
|
141
|
XUngrabKeyboard( m_display, CurrentTime );
|
141
|
|
- return 0;
|
|
142
|
+ return EXIT_SUCCESS;
|
142
|
143
|
}
|
143
|
144
|
|
144
|
145
|
void slop::XEngine::selectAllInputs( Window win, long event_mask) {
|
|
@@ -156,7 +157,7 @@ void slop::XEngine::selectAllInputs( Window win, long event_mask) {
|
156
|
157
|
// Grabs the cursor, be wary that setCursor changes the mouse masks.
|
157
|
158
|
int slop::XEngine::grabCursor( slop::CursorType type ) {
|
158
|
159
|
if ( !m_good ) {
|
159
|
|
- return 1;
|
|
160
|
+ return EXIT_FAILURE;
|
160
|
161
|
}
|
161
|
162
|
int xfontcursor = getCursor( type );
|
162
|
163
|
int err = XGrabPointer( m_display, m_root, True,
|
|
@@ -165,7 +166,7 @@ int slop::XEngine::grabCursor( slop::CursorType type ) {
|
165
|
166
|
if ( err != GrabSuccess ) {
|
166
|
167
|
fprintf( stderr, "Error: Failed to grab X cursor.\n" );
|
167
|
168
|
fprintf( stderr, " This can be caused by launching slop weirdly.\n" );
|
168
|
|
- return 1;
|
|
169
|
+ return EXIT_FAILURE;
|
169
|
170
|
}
|
170
|
171
|
// Quickly set the mouse position so we don't have to worry about x11 generating an event.
|
171
|
172
|
Window root, child;
|
|
@@ -183,15 +184,15 @@ int slop::XEngine::grabCursor( slop::CursorType type ) {
|
183
|
184
|
XQueryPointer( m_display, child, &root, &test, &mx, &my, &wx, &wy, &mask );
|
184
|
185
|
}
|
185
|
186
|
m_hoverWindow = child;
|
186
|
|
- return 0;
|
|
187
|
+ return EXIT_SUCCESS;
|
187
|
188
|
}
|
188
|
189
|
|
189
|
190
|
int slop::XEngine::releaseCursor() {
|
190
|
191
|
if ( !m_good ) {
|
191
|
|
- return 1;
|
|
192
|
+ return EXIT_FAILURE;
|
192
|
193
|
}
|
193
|
194
|
XUngrabPointer( m_display, CurrentTime );
|
194
|
|
- return 0;
|
|
195
|
+ return EXIT_SUCCESS;
|
195
|
196
|
}
|
196
|
197
|
|
197
|
198
|
void slop::XEngine::tick() {
|
|
@@ -255,7 +256,7 @@ Cursor slop::XEngine::getCursor( slop::CursorType type ) {
|
255
|
256
|
case Box: xfontcursor = 40; break;
|
256
|
257
|
}
|
257
|
258
|
Cursor newcursor = 0;
|
258
|
|
- if ( m_cursors.size() > xfontcursor ) {
|
|
259
|
+ if ( m_cursors.size() > (unsigned int)xfontcursor ) {
|
259
|
260
|
newcursor = m_cursors.at( xfontcursor );
|
260
|
261
|
}
|
261
|
262
|
if ( !newcursor ) {
|
|
@@ -278,11 +279,11 @@ void slop::XEngine::setCursor( slop::CursorType type ) {
|
278
|
279
|
}
|
279
|
280
|
|
280
|
281
|
void slop::WindowRectangle::applyPadding( int padding ) {
|
281
|
|
- if ( m_width + padding*2 >= 0 ) {
|
|
282
|
+ if ( (int)m_width + padding*2 >= 0 ) {
|
282
|
283
|
m_x -= padding;
|
283
|
284
|
m_width += padding*2;
|
284
|
285
|
}
|
285
|
|
- if ( m_height + padding*2 >= 0 ) {
|
|
286
|
+ if ( (int)m_height + padding*2 >= 0 ) {
|
286
|
287
|
m_y -= padding;
|
287
|
288
|
m_height += padding*2;
|
288
|
289
|
}
|
|
@@ -292,7 +293,7 @@ Window slop::WindowRectangle::getWindow() {
|
292
|
293
|
return m_window;
|
293
|
294
|
}
|
294
|
295
|
|
295
|
|
-void slop::WindowRectangle::applyMinMaxSize( int minimumsize, int maximumsize ) {
|
|
296
|
+void slop::WindowRectangle::applyMinMaxSize( unsigned int minimumsize, unsigned int maximumsize ) {
|
296
|
297
|
if ( minimumsize > maximumsize && maximumsize > 0 ) {
|
297
|
298
|
fprintf( stderr, "Error: minimumsize is greater than maximumsize.\n" );
|
298
|
299
|
exit( 1 );
|
|
@@ -328,7 +329,6 @@ void slop::WindowRectangle::setGeometry( Window win, bool decorations ) {
|
328
|
329
|
Window root, parent, test, junk;
|
329
|
330
|
Window* childlist;
|
330
|
331
|
unsigned int ujunk;
|
331
|
|
- unsigned int depth;
|
332
|
332
|
// Try to find the actual decorations.
|
333
|
333
|
test = win;
|
334
|
334
|
int status = XQueryTree( xengine->m_display, test, &root, &parent, &childlist, &ujunk);
|