31 |
extern BOOL grab_keyboard; |
extern BOOL grab_keyboard; |
32 |
extern BOOL hide_decorations; |
extern BOOL hide_decorations; |
33 |
extern char title[]; |
extern char title[]; |
34 |
|
extern int server_bpp; |
35 |
BOOL enable_compose = False; |
BOOL enable_compose = False; |
36 |
BOOL focused; |
BOOL focused; |
37 |
BOOL mouse_in_wnd; |
BOOL mouse_in_wnd; |
63 |
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 |
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 |
64 |
typedef struct |
typedef struct |
65 |
{ |
{ |
66 |
unsigned long flags; |
uint32 flags; |
67 |
unsigned long functions; |
uint32 functions; |
68 |
unsigned long decorations; |
uint32 decorations; |
69 |
long inputMode; |
sint32 inputMode; |
70 |
unsigned long status; |
uint32 status; |
71 |
} |
} |
72 |
PropMotifWmHints; |
PropMotifWmHints; |
73 |
|
|
89 |
static Colormap xcolmap; |
static Colormap xcolmap; |
90 |
static uint32 *colmap; |
static uint32 *colmap; |
91 |
|
|
92 |
#define TRANSLATE(col) ( owncolmap ? col : translate_colour(colmap[col]) ) |
#define TRANSLATE(col) ( server_bpp != 8 ? translate_colour(col) : owncolmap ? col : translate_colour(colmap[col]) ) |
93 |
#define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); |
#define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); |
94 |
#define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); |
#define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); |
95 |
|
|
137 |
(unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); |
(unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); |
138 |
} |
} |
139 |
|
|
140 |
|
uint32 |
141 |
|
colour16to24(uint32 colour) |
142 |
|
{ |
143 |
|
int r; |
144 |
|
int g; |
145 |
|
int b; |
146 |
|
r = (colour & 0xf800) >> 11; |
147 |
|
r = (r * 0xff) / 0x1f; |
148 |
|
g = (colour & 0x07e0) >> 5; |
149 |
|
g = (g * 0xff) / 0x3f; |
150 |
|
b = (colour & 0x001f); |
151 |
|
b = (b * 0xff) / 0x1f; |
152 |
|
return (r << 16) | (g << 8) | b; |
153 |
|
} |
154 |
|
|
155 |
|
uint32 |
156 |
|
colour16to32(uint32 colour) |
157 |
|
{ |
158 |
|
return colour16to24(colour); |
159 |
|
} |
160 |
|
|
161 |
|
uint32 |
162 |
|
colour24to32(uint32 colour) |
163 |
|
{ |
164 |
|
return colour; |
165 |
|
} |
166 |
|
|
167 |
|
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
168 |
|
#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } |
169 |
|
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
170 |
|
x = (x << 16) | (x >> 16); } |
171 |
|
|
172 |
|
static uint32 |
173 |
|
translate_colour(uint32 colour) |
174 |
|
{ |
175 |
|
switch (server_bpp) |
176 |
|
{ |
177 |
|
case 16: |
178 |
|
switch (bpp) |
179 |
|
{ |
180 |
|
case 16: |
181 |
|
break; |
182 |
|
case 24: |
183 |
|
colour = colour16to24(colour); |
184 |
|
break; |
185 |
|
case 32: |
186 |
|
colour = colour16to32(colour); |
187 |
|
break; |
188 |
|
} |
189 |
|
break; |
190 |
|
case 24: |
191 |
|
switch (bpp) |
192 |
|
{ |
193 |
|
case 24: |
194 |
|
break; |
195 |
|
case 32: |
196 |
|
colour = colour24to32(colour); |
197 |
|
break; |
198 |
|
} |
199 |
|
break; |
200 |
|
} |
201 |
|
switch (bpp) |
202 |
|
{ |
203 |
|
case 16: |
204 |
|
if (host_be != xserver_be) |
205 |
|
BSWAP16(colour); |
206 |
|
break; |
207 |
|
|
208 |
|
case 24: |
209 |
|
if (xserver_be) |
210 |
|
BSWAP24(colour); |
211 |
|
break; |
212 |
|
|
213 |
|
case 32: |
214 |
|
if (host_be != xserver_be) |
215 |
|
BSWAP32(colour); |
216 |
|
break; |
217 |
|
} |
218 |
|
|
219 |
|
return colour; |
220 |
|
} |
221 |
|
|
222 |
static void |
static void |
223 |
translate8(uint8 * data, uint8 * out, uint8 * end) |
translate8to8(uint8 * data, uint8 * out, uint8 * end) |
224 |
{ |
{ |
225 |
while (out < end) |
while (out < end) |
226 |
*(out++) = (uint8) colmap[*(data++)]; |
*(out++) = (uint8) colmap[*(data++)]; |
227 |
} |
} |
228 |
|
|
229 |
static void |
static void |
230 |
translate16(uint8 * data, uint16 * out, uint16 * end) |
translate8to16(uint8 * data, uint16 * out, uint16 * end) |
231 |
{ |
{ |
232 |
while (out < end) |
while (out < end) |
233 |
*(out++) = (uint16) colmap[*(data++)]; |
*(out++) = (uint16) colmap[*(data++)]; |
234 |
} |
} |
235 |
|
|
236 |
|
static void |
237 |
|
translate16to16(uint16 * data, uint16 * out, uint16 * end) |
238 |
|
{ |
239 |
|
while (out < end) |
240 |
|
*(out++) = (uint16) translate_colour(*(data++)); |
241 |
|
} |
242 |
|
|
243 |
/* little endian - conversion happens when colourmap is built */ |
/* little endian - conversion happens when colourmap is built */ |
244 |
static void |
static void |
245 |
translate24(uint8 * data, uint8 * out, uint8 * end) |
translate8to24(uint8 * data, uint8 * out, uint8 * end) |
246 |
{ |
{ |
247 |
uint32 value; |
uint32 value; |
248 |
|
|
256 |
} |
} |
257 |
|
|
258 |
static void |
static void |
259 |
translate32(uint8 * data, uint32 * out, uint32 * end) |
translate16to24(uint16 * data, uint8 * out, uint8 * end) |
260 |
|
{ |
261 |
|
uint32 value; |
262 |
|
|
263 |
|
while (out < end) |
264 |
|
{ |
265 |
|
value = translate_colour(*(data++)); |
266 |
|
*(out++) = value; |
267 |
|
*(out++) = value >> 8; |
268 |
|
*(out++) = value >> 16; |
269 |
|
} |
270 |
|
} |
271 |
|
|
272 |
|
static void |
273 |
|
translate8to32(uint8 * data, uint32 * out, uint32 * end) |
274 |
{ |
{ |
275 |
while (out < end) |
while (out < end) |
276 |
*(out++) = colmap[*(data++)]; |
*(out++) = colmap[*(data++)]; |
277 |
} |
} |
278 |
|
|
279 |
|
static void |
280 |
|
translate16to32(uint16 * data, uint32 * out, uint32 * end) |
281 |
|
{ |
282 |
|
while (out < end) |
283 |
|
*(out++) = translate_colour(*(data++)); |
284 |
|
} |
285 |
|
|
286 |
static uint8 * |
static uint8 * |
287 |
translate_image(int width, int height, uint8 * data) |
translate_image(int width, int height, uint8 * data) |
288 |
{ |
{ |
290 |
uint8 *out = xmalloc(size); |
uint8 *out = xmalloc(size); |
291 |
uint8 *end = out + size; |
uint8 *end = out + size; |
292 |
|
|
293 |
|
if (server_bpp == 16) |
294 |
|
{ |
295 |
|
if (bpp == 16) |
296 |
|
translate16to16((uint16 *) data, (uint16 *) out, (uint16 *) end); |
297 |
|
else if (bpp == 24) |
298 |
|
translate16to24((uint16 *) data, out, end); /* todo, check this one */ |
299 |
|
else if (bpp == 32) |
300 |
|
translate16to32((uint16 *) data, (uint32 *) out, (uint32 *) end); |
301 |
|
return out; |
302 |
|
} |
303 |
|
/* todo needs server_bpp == 24 */ |
304 |
switch (bpp) |
switch (bpp) |
305 |
{ |
{ |
306 |
case 8: |
case 8: |
307 |
translate8(data, out, end); |
translate8to8(data, out, end); |
308 |
break; |
break; |
309 |
|
|
310 |
case 16: |
case 16: |
311 |
translate16(data, (uint16 *) out, (uint16 *) end); |
translate8to16(data, (uint16 *) out, (uint16 *) end); |
312 |
break; |
break; |
313 |
|
|
314 |
case 24: |
case 24: |
315 |
translate24(data, out, end); |
translate8to24(data, out, end); |
316 |
break; |
break; |
317 |
|
|
318 |
case 32: |
case 32: |
319 |
translate32(data, (uint32 *) out, (uint32 *) end); |
translate8to32(data, (uint32 *) out, (uint32 *) end); |
320 |
break; |
break; |
321 |
} |
} |
322 |
|
|
323 |
return out; |
return out; |
324 |
} |
} |
325 |
|
|
|
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
|
|
#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } |
|
|
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
|
|
x = (x << 16) | (x >> 16); } |
|
|
|
|
|
static uint32 |
|
|
translate_colour(uint32 colour) |
|
|
{ |
|
|
switch (bpp) |
|
|
{ |
|
|
case 16: |
|
|
if (host_be != xserver_be) |
|
|
BSWAP16(colour); |
|
|
break; |
|
|
|
|
|
case 24: |
|
|
if (xserver_be) |
|
|
BSWAP24(colour); |
|
|
break; |
|
|
|
|
|
case 32: |
|
|
if (host_be != xserver_be) |
|
|
BSWAP32(colour); |
|
|
break; |
|
|
} |
|
|
|
|
|
return colour; |
|
|
} |
|
|
|
|
326 |
BOOL |
BOOL |
327 |
get_key_state(unsigned int state, uint32 keysym) |
get_key_state(unsigned int state, uint32 keysym) |
328 |
{ |
{ |
408 |
if ((width == 0) || (height == 0)) |
if ((width == 0) || (height == 0)) |
409 |
{ |
{ |
410 |
/* Fetch geometry from _NET_WORKAREA */ |
/* Fetch geometry from _NET_WORKAREA */ |
411 |
uint32 xpos, ypos; |
uint32 x, y, cx, cy; |
412 |
|
|
413 |
if (get_current_workarea(&xpos, &ypos, &width, &height) < 0) |
if (get_current_workarea(&x, &y, &cx, &cy) == 0) |
414 |
|
{ |
415 |
|
width = cx; |
416 |
|
height = cy; |
417 |
|
} |
418 |
|
else |
419 |
{ |
{ |
420 |
warning("Failed to get workarea: probably your window manager does not support extended hints\n"); |
warning("Failed to get workarea: probably your window manager does not support extended hints\n"); |
421 |
width = 800; |
width = 800; |
826 |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
827 |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
828 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
829 |
(char *) tdata, width, height, 8, 0); |
(char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0); |
830 |
|
|
831 |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
832 |
|
|
841 |
{ |
{ |
842 |
XImage *image; |
XImage *image; |
843 |
uint8 *tdata; |
uint8 *tdata; |
|
|
|
844 |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
845 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
846 |
(char *) tdata, width, height, 8, 0); |
(char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0); |
847 |
|
|
848 |
if (ownbackstore) |
if (ownbackstore) |
849 |
{ |
{ |
1313 |
}\ |
}\ |
1314 |
if (glyph != NULL)\ |
if (glyph != NULL)\ |
1315 |
{\ |
{\ |
1316 |
ui_draw_glyph (mixmode, x + (short) glyph->offset,\ |
ui_draw_glyph (mixmode, x + glyph->offset,\ |
1317 |
y + (short) glyph->baseline,\ |
y + glyph->baseline,\ |
1318 |
glyph->width, glyph->height,\ |
glyph->width, glyph->height,\ |
1319 |
glyph->pixmap, 0, 0, bgcolour, fgcolour);\ |
glyph->pixmap, 0, 0, bgcolour, fgcolour);\ |
1320 |
if (flags & TEXT2_IMPLICIT_X)\ |
if (flags & TEXT2_IMPLICIT_X)\ |