@@ -91,25 +91,44 @@ static Window w, rw;
91
91
static Visual * vi ;
92
92
static GC gc ;
93
93
static Colormap cm ;
94
- static XColor xc ;
95
94
static Pixmap pm ;
96
95
97
96
98
97
/****************************************/
99
98
/*** hardware dependant functions ***/
100
99
/****************************************/
101
100
102
- static void drv_X11_color (RGBA c , int brightness )
101
+ static XColor drv_X11_color (RGBA c , int brightness )
103
102
{
103
+ static XColor col [64 ];
104
+ static unsigned char alloced [64 ] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
105
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
106
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
107
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
108
+ };
109
+ XColor xc ;
110
+ int key ;
111
+
104
112
xc .red = brightness * c .R ;
105
113
xc .green = brightness * c .G ;
106
114
xc .blue = brightness * c .B ;
107
- xc .flags = DoRed | DoGreen | DoBlue ;
108
- if (XAllocColor (dp , cm , & xc ) == False ) {
109
- error ("%s: XAllocColor(%02x%02x%02x) failed!" , Name , c .R , c .G , c .B );
115
+ /* 16bits per color, compressed to 6 bits (2 each color) */
116
+ key = (xc .red & 0xc000 ) >> 10 | (xc .green & 0xc000 ) >> 12 | (xc .blue & 0xc000 ) >> 14 ;
117
+ /* todo: support more than 64 colors: check if allocated color is exactly the requested */
118
+ if (alloced [key ]) {
119
+ xc = col [key ];
120
+ } else {
121
+ xc .flags = DoRed | DoGreen | DoBlue ;
122
+ if (XAllocColor (dp , cm , & xc ) == False ) {
123
+ error ("%s: XAllocColor(%02x%02x%02x) failed!" , Name , c .R , c .G , c .B );
124
+ }
125
+ col [key ] = xc ;
126
+ alloced [key ] = 1 ;
110
127
}
128
+
111
129
XSetForeground (dp , gc , xc .pixel );
112
130
131
+ return (xc );
113
132
}
114
133
115
134
@@ -135,6 +154,7 @@ static void drv_X11_blit(const int row, const int col, const int height, const i
135
154
static int drv_X11_brightness (int brightness )
136
155
{
137
156
static int Brightness = 255 ;
157
+ int i ;
138
158
139
159
/* -1 is used to query the current brightness */
140
160
if (brightness == -1 )
@@ -156,11 +176,14 @@ static int drv_X11_brightness(int brightness)
156
176
BL_COL .B = BP_COL .B * dim ;
157
177
158
178
/* set new background */
159
- drv_X11_color (BR_COL , brightness );
160
- XSetWindowBackground (dp , w , xc .pixel );
179
+ XSetWindowBackground (dp , w , drv_X11_color (BR_COL , brightness ).pixel );
161
180
162
181
/* redraw every LCD pixel */
163
- drv_X11_blit (0 , 0 , DROWS , DCOLS );
182
+ XClearWindow (dp , w );
183
+ for (i = 0 ; i < DROWS * DCOLS ; i ++ ) {
184
+ drv_X11_FB [i ] = NO_COL ;
185
+ }
186
+ drv_X11_blit (0 , 0 , LROWS , LCOLS );
164
187
165
188
/* remember new brightness */
166
189
Brightness = brightness ;
@@ -319,8 +342,8 @@ static void drv_X11_timer( __attribute__ ((unused))
319
342
static int btn = 0 ;
320
343
321
344
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 )
345
+ /* there is no ClientMessageMask, so this will be checked separately */
346
+ && XCheckTypedWindowEvent (dp , w , ClientMessage , & ev ) == 0 )
324
347
return ;
325
348
326
349
switch (ev .type ) {
@@ -375,10 +398,10 @@ static void drv_X11_timer( __attribute__ ((unused))
375
398
case ClientMessage :
376
399
if ((Atom ) (ev .xclient .data .l [0 ]) == wmDeleteMessage ) {
377
400
info ("%s: Window closed by WindowManager, quit." , Name );
378
- if (raise (SIGTERM ) != 0 ) {
379
- error ("%s: Error raising SIGTERM: exit!" , Name );
380
- exit (1 );
381
- }
401
+ if (raise (SIGTERM ) != 0 ) {
402
+ error ("%s: Error raising SIGTERM: exit!" , Name );
403
+ exit (1 );
404
+ }
382
405
} else {
383
406
debug ("%s: Got XClient message 0x%lx %lx %lx %lx %lx" , Name , ev .xclient .data .l [0 ],
384
407
ev .xclient .data .l [1 ], ev .xclient .data .l [2 ], ev .xclient .data .l [3 ], ev .xclient .data .l [4 ]);
@@ -511,8 +534,7 @@ static int drv_X11_start(const char *section)
511
534
wmDeleteMessage = XInternAtom (dp , "WM_DELETE_WINDOW" , False );
512
535
XSetWMProtocols (dp , w , & wmDeleteMessage , 1 );
513
536
514
- drv_X11_color (BR_COL , 255 );
515
- XSetWindowBackground (dp , w , xc .pixel );
537
+ XSetWindowBackground (dp , w , drv_X11_color (BR_COL , 255 ).pixel );
516
538
XClearWindow (dp , w );
517
539
518
540
/* set brightness (after first background painting) */
0 commit comments