46
46
#include <termios.h>
47
47
#include <fcntl.h>
48
48
#include <sys/time.h>
49
+ #include <signal.h>
49
50
#include <X11/Xlib.h>
50
51
#include <X11/Xutil.h>
51
52
@@ -108,7 +109,6 @@ static void drv_X11_color(RGBA c, int brightness)
108
109
error ("%s: XAllocColor(%02x%02x%02x) failed!" , Name , c .R , c .G , c .B );
109
110
}
110
111
XSetForeground (dp , gc , xc .pixel );
111
- XSetBackground (dp , gc , xc .pixel );
112
112
113
113
}
114
114
@@ -160,7 +160,7 @@ static int drv_X11_brightness(int brightness)
160
160
XSetWindowBackground (dp , w , xc .pixel );
161
161
162
162
/* redraw every LCD pixel */
163
- drv_X11_blit (0 , 0 , LROWS , LCOLS );
163
+ drv_X11_blit (0 , 0 , DROWS , DCOLS );
164
164
165
165
/* remember new brightness */
166
166
Brightness = brightness ;
@@ -225,6 +225,7 @@ static void drv_X11_expose(const int x, const int y, const int width, const int
225
225
RGBA col ;
226
226
RGBA lastCol = { 0 , 0 , 0 , 0 };
227
227
int hasLastCol = 0 ;
228
+ int brightness = drv_X11_brightness (-1 );
228
229
229
230
x0 = x - pixel ;
230
231
x1 = x + pixel + width ;
@@ -243,7 +244,7 @@ static void drv_X11_expose(const int x, const int y, const int width, const int
243
244
if (hasLastCol ) {
244
245
/* if the color of this pixel is different to the last pixels draw the old ones */
245
246
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 );
247
248
XFillRectangles (dp , w , gc , rect , nrect );
248
249
nrect = 0 ;
249
250
lastCol = col ;
@@ -255,15 +256,15 @@ static void drv_X11_expose(const int x, const int y, const int width, const int
255
256
nrect ++ ;
256
257
} else {
257
258
/* 1st shot: no old color */
258
- drv_X11_color (col , 255 );
259
+ drv_X11_color (col , brightness );
259
260
XFillRectangle (dp , w , gc , xc , yc , pixel , pixel );
260
261
lastCol = col ;
261
262
hasLastCol = 1 ;
262
263
}
263
264
}
264
265
}
265
266
/* draw the last block of rectangles */
266
- drv_X11_color (lastCol , 255 );
267
+ drv_X11_color (lastCol , brightness );
267
268
XFillRectangles (dp , w , gc , rect , nrect );
268
269
269
270
/* Keypad on the right side */
@@ -317,7 +318,9 @@ static void drv_X11_timer( __attribute__ ((unused))
317
318
int yoffset = border + (DROWS / YRES ) * rgap ;
318
319
static int btn = 0 ;
319
320
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 )
321
324
return ;
322
325
323
326
switch (ev .type ) {
@@ -372,9 +375,12 @@ static void drv_X11_timer( __attribute__ ((unused))
372
375
case ClientMessage :
373
376
if ((Atom ) (ev .xclient .data .l [0 ]) == wmDeleteMessage ) {
374
377
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
+ }
376
382
} 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 ],
378
384
ev .xclient .data .l [1 ], ev .xclient .data .l [2 ], ev .xclient .data .l [3 ], ev .xclient .data .l [4 ]);
379
385
}
380
386
@@ -503,7 +509,7 @@ static int drv_X11_start(const char *section)
503
509
504
510
XSetWMProperties (dp , w , NULL , NULL , NULL , 0 , & sh , NULL , NULL );
505
511
wmDeleteMessage = XInternAtom (dp , "WM_DELETE_WINDOW" , False );
506
- /* XSetWMProtocols(dp, w, &wmDeleteMessage, 1); *to be tested* */
512
+ XSetWMProtocols (dp , w , & wmDeleteMessage , 1 );
507
513
508
514
drv_X11_color (BR_COL , 255 );
509
515
XSetWindowBackground (dp , w , xc .pixel );
0 commit comments