Skip to content

Commit ba89cd6

Browse files
author
volker
committed
Closing XWindow quits without error
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@972 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
1 parent acb916c commit ba89cd6

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

drv_X11.c

+15-9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <termios.h>
4747
#include <fcntl.h>
4848
#include <sys/time.h>
49+
#include <signal.h>
4950
#include <X11/Xlib.h>
5051
#include <X11/Xutil.h>
5152

@@ -108,7 +109,6 @@ static void drv_X11_color(RGBA c, int brightness)
108109
error("%s: XAllocColor(%02x%02x%02x) failed!", Name, c.R, c.G, c.B);
109110
}
110111
XSetForeground(dp, gc, xc.pixel);
111-
XSetBackground(dp, gc, xc.pixel);
112112

113113
}
114114

@@ -160,7 +160,7 @@ static int drv_X11_brightness(int brightness)
160160
XSetWindowBackground(dp, w, xc.pixel);
161161

162162
/* redraw every LCD pixel */
163-
drv_X11_blit(0, 0, LROWS, LCOLS);
163+
drv_X11_blit(0, 0, DROWS, DCOLS);
164164

165165
/* remember new brightness */
166166
Brightness = brightness;
@@ -225,6 +225,7 @@ static void drv_X11_expose(const int x, const int y, const int width, const int
225225
RGBA col;
226226
RGBA lastCol = { 0, 0, 0, 0 };
227227
int hasLastCol = 0;
228+
int brightness = drv_X11_brightness(-1);
228229

229230
x0 = x - pixel;
230231
x1 = x + pixel + width;
@@ -243,7 +244,7 @@ static void drv_X11_expose(const int x, const int y, const int width, const int
243244
if (hasLastCol) {
244245
/* if the color of this pixel is different to the last pixels draw the old ones */
245246
if (col.R != lastCol.R || col.G != lastCol.G || col.B != lastCol.B) {
246-
drv_X11_color(lastCol, 255);
247+
drv_X11_color(lastCol, brightness);
247248
XFillRectangles(dp, w, gc, rect, nrect);
248249
nrect = 0;
249250
lastCol = col;
@@ -255,15 +256,15 @@ static void drv_X11_expose(const int x, const int y, const int width, const int
255256
nrect++;
256257
} else {
257258
/* 1st shot: no old color */
258-
drv_X11_color(col, 255);
259+
drv_X11_color(col, brightness);
259260
XFillRectangle(dp, w, gc, xc, yc, pixel, pixel);
260261
lastCol = col;
261262
hasLastCol = 1;
262263
}
263264
}
264265
}
265266
/* draw the last block of rectangles */
266-
drv_X11_color(lastCol, 255);
267+
drv_X11_color(lastCol, brightness);
267268
XFillRectangles(dp, w, gc, rect, nrect);
268269

269270
/* Keypad on the right side */
@@ -317,7 +318,9 @@ static void drv_X11_timer( __attribute__ ((unused))
317318
int yoffset = border + (DROWS / YRES) * rgap;
318319
static int btn = 0;
319320

320-
if (XCheckWindowEvent(dp, w, ExposureMask | ButtonPressMask | ButtonReleaseMask, &ev) == 0)
321+
if (XCheckWindowEvent(dp, w, ExposureMask | ButtonPressMask | ButtonReleaseMask, &ev) == 0
322+
/* there is no ClientMessageMask, so this will be checked separately */
323+
&& XCheckTypedWindowEvent(dp, w, ClientMessage, &ev) == 0)
321324
return;
322325

323326
switch (ev.type) {
@@ -372,9 +375,12 @@ static void drv_X11_timer( __attribute__ ((unused))
372375
case ClientMessage:
373376
if ((Atom) (ev.xclient.data.l[0]) == wmDeleteMessage) {
374377
info("%s: Window closed by WindowManager, quit.", Name);
375-
exit(0);
378+
if (raise(SIGTERM) != 0) {
379+
error("%s: Error raising SIGTERM: exit!", Name);
380+
exit(1);
381+
}
376382
} else {
377-
debug("%s: Got client message 0x%lx %lx %lx %lx %lx", Name, ev.xclient.data.l[0],
383+
debug("%s: Got XClient message 0x%lx %lx %lx %lx %lx", Name, ev.xclient.data.l[0],
378384
ev.xclient.data.l[1], ev.xclient.data.l[2], ev.xclient.data.l[3], ev.xclient.data.l[4]);
379385
}
380386

@@ -503,7 +509,7 @@ static int drv_X11_start(const char *section)
503509

504510
XSetWMProperties(dp, w, NULL, NULL, NULL, 0, &sh, NULL, NULL);
505511
wmDeleteMessage = XInternAtom(dp, "WM_DELETE_WINDOW", False);
506-
/* XSetWMProtocols(dp, w, &wmDeleteMessage, 1); *to be tested* */
512+
XSetWMProtocols(dp, w, &wmDeleteMessage, 1);
507513

508514
drv_X11_color(BR_COL, 255);
509515
XSetWindowBackground(dp, w, xc.pixel);

0 commit comments

Comments
 (0)