1 |
/* |
/* |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
User interface services - X Window System |
User interface services - X Window System |
4 |
Copyright (C) Matthew Chapman 1999-2001 |
Copyright (C) Matthew Chapman 1999-2002 |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
7 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
29 |
extern BOOL sendmotion; |
extern BOOL sendmotion; |
30 |
extern BOOL fullscreen; |
extern BOOL fullscreen; |
31 |
extern BOOL grab_keyboard; |
extern BOOL grab_keyboard; |
32 |
|
extern BOOL hide_decorations; |
33 |
extern char title[]; |
extern char title[]; |
34 |
|
extern int server_bpp; |
35 |
|
extern int win_button_size; |
36 |
BOOL enable_compose = False; |
BOOL enable_compose = False; |
37 |
|
BOOL focused; |
38 |
|
BOOL mouse_in_wnd; |
39 |
|
|
40 |
Display *display; |
Display *display; |
41 |
static int x_socket; |
static int x_socket; |
47 |
static int bpp; |
static int bpp; |
48 |
static XIM IM; |
static XIM IM; |
49 |
static XIC IC; |
static XIC IC; |
50 |
|
static XModifierKeymap *mod_map; |
51 |
static Cursor current_cursor; |
static Cursor current_cursor; |
52 |
|
static Atom protocol_atom, kill_atom; |
53 |
|
|
54 |
/* endianness */ |
/* endianness */ |
55 |
static BOOL host_be; |
static BOOL host_be; |
59 |
static BOOL ownbackstore; |
static BOOL ownbackstore; |
60 |
static Pixmap backstore; |
static Pixmap backstore; |
61 |
|
|
62 |
|
/* MWM decorations */ |
63 |
|
#define MWM_HINTS_DECORATIONS (1L << 1) |
64 |
|
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 |
65 |
|
typedef struct |
66 |
|
{ |
67 |
|
uint32 flags; |
68 |
|
uint32 functions; |
69 |
|
uint32 decorations; |
70 |
|
sint32 inputMode; |
71 |
|
uint32 status; |
72 |
|
} |
73 |
|
PropMotifWmHints; |
74 |
|
|
75 |
|
typedef struct |
76 |
|
{ |
77 |
|
uint32 red; |
78 |
|
uint32 green; |
79 |
|
uint32 blue; |
80 |
|
} |
81 |
|
PixelColour; |
82 |
|
|
83 |
#define FILL_RECTANGLE(x,y,cx,cy)\ |
#define FILL_RECTANGLE(x,y,cx,cy)\ |
84 |
{ \ |
{ \ |
85 |
XFillRectangle(display, wnd, gc, x, y, cx, cy); \ |
XFillRectangle(display, wnd, gc, x, y, cx, cy); \ |
87 |
XFillRectangle(display, backstore, gc, x, y, cx, cy); \ |
XFillRectangle(display, backstore, gc, x, y, cx, cy); \ |
88 |
} |
} |
89 |
|
|
90 |
|
#define FILL_RECTANGLE_BACKSTORE(x,y,cx,cy)\ |
91 |
|
{ \ |
92 |
|
XFillRectangle(display, ownbackstore ? backstore : wnd, gc, x, y, cx, cy); \ |
93 |
|
} |
94 |
|
|
95 |
/* colour maps */ |
/* colour maps */ |
96 |
|
BOOL owncolmap = False; |
97 |
static Colormap xcolmap; |
static Colormap xcolmap; |
98 |
static uint32 *colmap; |
static uint32 *colmap; |
99 |
|
|
100 |
#define SET_FOREGROUND(col) XSetForeground(display, gc, translate_colour(colmap[col])); |
#define TRANSLATE(col) ( server_bpp != 8 ? translate_colour(col) : owncolmap ? col : translate_colour(colmap[col]) ) |
101 |
#define SET_BACKGROUND(col) XSetBackground(display, gc, translate_colour(colmap[col])); |
#define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); |
102 |
|
#define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); |
103 |
|
|
104 |
static int rop2_map[] = { |
static int rop2_map[] = { |
105 |
GXclear, /* 0 */ |
GXclear, /* 0 */ |
124 |
#define RESET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); } |
#define RESET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); } |
125 |
|
|
126 |
static void |
static void |
127 |
translate8(uint8 * data, uint8 * out, uint8 * end) |
mwm_hide_decorations(void) |
128 |
|
{ |
129 |
|
PropMotifWmHints motif_hints; |
130 |
|
Atom hintsatom; |
131 |
|
|
132 |
|
/* setup the property */ |
133 |
|
motif_hints.flags = MWM_HINTS_DECORATIONS; |
134 |
|
motif_hints.decorations = 0; |
135 |
|
|
136 |
|
/* get the atom for the property */ |
137 |
|
hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False); |
138 |
|
if (!hintsatom) |
139 |
|
{ |
140 |
|
warning("Failed to get atom _MOTIF_WM_HINTS: probably your window manager does not support MWM hints\n"); |
141 |
|
return; |
142 |
|
} |
143 |
|
|
144 |
|
XChangeProperty(display, wnd, hintsatom, hintsatom, 32, PropModeReplace, |
145 |
|
(unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); |
146 |
|
} |
147 |
|
|
148 |
|
static PixelColour |
149 |
|
split_colour15(uint32 colour) |
150 |
|
{ |
151 |
|
PixelColour rv; |
152 |
|
rv.red = (colour & 0x7c00) >> 10; |
153 |
|
rv.red = (rv.red * 0xff) / 0x1f; |
154 |
|
rv.green = (colour & 0x03e0) >> 5; |
155 |
|
rv.green = (rv.green * 0xff) / 0x1f; |
156 |
|
rv.blue = (colour & 0x1f); |
157 |
|
rv.blue = (rv.blue * 0xff) / 0x1f; |
158 |
|
return rv; |
159 |
|
} |
160 |
|
|
161 |
|
static PixelColour |
162 |
|
split_colour16(uint32 colour) |
163 |
|
{ |
164 |
|
PixelColour rv; |
165 |
|
rv.red = (colour & 0xf800) >> 11; |
166 |
|
rv.red = (rv.red * 0xff) / 0x1f; |
167 |
|
rv.green = (colour & 0x07e0) >> 5; |
168 |
|
rv.green = (rv.green * 0xff) / 0x3f; |
169 |
|
rv.blue = (colour & 0x001f); |
170 |
|
rv.blue = (rv.blue * 0xff) / 0x1f; |
171 |
|
return rv; |
172 |
|
} |
173 |
|
|
174 |
|
static PixelColour |
175 |
|
split_colour24(uint32 colour) |
176 |
|
{ |
177 |
|
PixelColour rv; |
178 |
|
rv.blue = (colour & 0xff0000) >> 16; |
179 |
|
rv.green = (colour & 0xff00) >> 8; |
180 |
|
rv.red = (colour & 0xff); |
181 |
|
return rv; |
182 |
|
} |
183 |
|
|
184 |
|
static uint32 |
185 |
|
make_colour16(PixelColour pc) |
186 |
|
{ |
187 |
|
pc.red = (pc.red * 0x1f) / 0xff; |
188 |
|
pc.green = (pc.green * 0x3f) / 0xff; |
189 |
|
pc.blue = (pc.blue * 0x1f) / 0xff; |
190 |
|
return (pc.red << 11) | (pc.green << 5) | pc.blue; |
191 |
|
} |
192 |
|
|
193 |
|
static uint32 |
194 |
|
make_colour24(PixelColour pc) |
195 |
|
{ |
196 |
|
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
197 |
|
} |
198 |
|
|
199 |
|
static uint32 |
200 |
|
make_colour32(PixelColour pc) |
201 |
|
{ |
202 |
|
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
203 |
|
} |
204 |
|
|
205 |
|
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
206 |
|
#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } |
207 |
|
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
208 |
|
x = (x << 16) | (x >> 16); } |
209 |
|
|
210 |
|
static uint32 |
211 |
|
translate_colour(uint32 colour) |
212 |
|
{ |
213 |
|
switch (server_bpp) |
214 |
|
{ |
215 |
|
case 15: |
216 |
|
switch (bpp) |
217 |
|
{ |
218 |
|
case 16: |
219 |
|
colour = make_colour16(split_colour15(colour)); |
220 |
|
break; |
221 |
|
case 24: |
222 |
|
colour = make_colour24(split_colour15(colour)); |
223 |
|
break; |
224 |
|
case 32: |
225 |
|
colour = make_colour32(split_colour15(colour)); |
226 |
|
break; |
227 |
|
} |
228 |
|
break; |
229 |
|
case 16: |
230 |
|
switch (bpp) |
231 |
|
{ |
232 |
|
case 16: |
233 |
|
break; |
234 |
|
case 24: |
235 |
|
colour = make_colour24(split_colour16(colour)); |
236 |
|
break; |
237 |
|
case 32: |
238 |
|
colour = make_colour32(split_colour16(colour)); |
239 |
|
break; |
240 |
|
} |
241 |
|
break; |
242 |
|
case 24: |
243 |
|
switch (bpp) |
244 |
|
{ |
245 |
|
case 16: |
246 |
|
colour = make_colour16(split_colour24(colour)); |
247 |
|
break; |
248 |
|
case 24: |
249 |
|
break; |
250 |
|
case 32: |
251 |
|
colour = make_colour32(split_colour24(colour)); |
252 |
|
break; |
253 |
|
} |
254 |
|
break; |
255 |
|
} |
256 |
|
switch (bpp) |
257 |
|
{ |
258 |
|
case 16: |
259 |
|
if (host_be != xserver_be) |
260 |
|
BSWAP16(colour); |
261 |
|
break; |
262 |
|
|
263 |
|
case 24: |
264 |
|
if (xserver_be) |
265 |
|
BSWAP24(colour); |
266 |
|
break; |
267 |
|
|
268 |
|
case 32: |
269 |
|
if (host_be != xserver_be) |
270 |
|
BSWAP32(colour); |
271 |
|
break; |
272 |
|
} |
273 |
|
|
274 |
|
return colour; |
275 |
|
} |
276 |
|
|
277 |
|
static void |
278 |
|
translate8to8(uint8 * data, uint8 * out, uint8 * end) |
279 |
{ |
{ |
280 |
while (out < end) |
while (out < end) |
281 |
*(out++) = (uint8) colmap[*(data++)]; |
*(out++) = (uint8) colmap[*(data++)]; |
282 |
} |
} |
283 |
|
|
284 |
static void |
static void |
285 |
translate16(uint8 * data, uint16 * out, uint16 * end) |
translate8to16(uint8 * data, uint16 * out, uint16 * end) |
286 |
{ |
{ |
287 |
while (out < end) |
while (out < end) |
288 |
*(out++) = (uint16) colmap[*(data++)]; |
*(out++) = (uint16) colmap[*(data++)]; |
290 |
|
|
291 |
/* little endian - conversion happens when colourmap is built */ |
/* little endian - conversion happens when colourmap is built */ |
292 |
static void |
static void |
293 |
translate24(uint8 * data, uint8 * out, uint8 * end) |
translate8to24(uint8 * data, uint8 * out, uint8 * end) |
294 |
{ |
{ |
295 |
uint32 value; |
uint32 value; |
296 |
|
|
304 |
} |
} |
305 |
|
|
306 |
static void |
static void |
307 |
translate32(uint8 * data, uint32 * out, uint32 * end) |
translate8to32(uint8 * data, uint32 * out, uint32 * end) |
308 |
{ |
{ |
309 |
while (out < end) |
while (out < end) |
310 |
*(out++) = colmap[*(data++)]; |
*(out++) = colmap[*(data++)]; |
311 |
} |
} |
312 |
|
|
313 |
static uint8 * |
/* todo the remaining translate function might need some big endian check ?? */ |
314 |
translate_image(int width, int height, uint8 * data) |
|
315 |
|
static void |
316 |
|
translate15to16(uint16 * data, uint16 * out, uint16 * end) |
317 |
{ |
{ |
318 |
int size = width * height * bpp / 8; |
while (out < end) |
319 |
uint8 *out = xmalloc(size); |
*(out++) = (uint16) make_colour16(split_colour15(*(data++))); |
320 |
uint8 *end = out + size; |
} |
321 |
|
|
322 |
switch (bpp) |
static void |
323 |
|
translate15to24(uint16 * data, uint8 * out, uint8 * end) |
324 |
|
{ |
325 |
|
uint32 value; |
326 |
|
|
327 |
|
while (out < end) |
328 |
{ |
{ |
329 |
case 8: |
value = make_colour24(split_colour15(*(data++))); |
330 |
translate8(data, out, end); |
*(out++) = value; |
331 |
break; |
*(out++) = value >> 8; |
332 |
|
*(out++) = value >> 16; |
333 |
|
} |
334 |
|
} |
335 |
|
|
336 |
case 16: |
static void |
337 |
translate16(data, (uint16 *) out, (uint16 *) end); |
translate15to32(uint16 * data, uint32 * out, uint32 * end) |
338 |
break; |
{ |
339 |
|
while (out < end) |
340 |
|
*(out++) = make_colour32(split_colour15(*(data++))); |
341 |
|
} |
342 |
|
|
343 |
case 24: |
static void |
344 |
translate24(data, out, end); |
translate16to16(uint16 * data, uint16 * out, uint16 * end) |
345 |
break; |
{ |
346 |
|
while (out < end) |
347 |
|
*(out++) = (uint16) (*(data++)); |
348 |
|
} |
349 |
|
|
350 |
case 32: |
|
351 |
translate32(data, (uint32 *) out, (uint32 *) end); |
static void |
352 |
break; |
translate16to24(uint16 * data, uint8 * out, uint8 * end) |
353 |
|
{ |
354 |
|
uint32 value; |
355 |
|
|
356 |
|
while (out < end) |
357 |
|
{ |
358 |
|
value = make_colour24(split_colour16(*(data++))); |
359 |
|
*(out++) = value; |
360 |
|
*(out++) = value >> 8; |
361 |
|
*(out++) = value >> 16; |
362 |
} |
} |
363 |
|
} |
364 |
|
|
365 |
return out; |
static void |
366 |
|
translate16to32(uint16 * data, uint32 * out, uint32 * end) |
367 |
|
{ |
368 |
|
while (out < end) |
369 |
|
*(out++) = make_colour32(split_colour16(*(data++))); |
370 |
} |
} |
371 |
|
|
372 |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
static void |
373 |
#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } |
translate24to16(uint8 * data, uint16 * out, uint16 * end) |
374 |
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
{ |
375 |
x = (x << 16) | (x >> 16); } |
uint32 pixel = 0; |
376 |
|
while (out < end) |
377 |
|
{ |
378 |
|
pixel = *(data++) << 16; |
379 |
|
pixel |= *(data++) << 8; |
380 |
|
pixel |= *(data++); |
381 |
|
*(out++) = (uint16) make_colour16(split_colour24(pixel)); |
382 |
|
} |
383 |
|
} |
384 |
|
|
385 |
static uint32 |
static void |
386 |
translate_colour(uint32 colour) |
translate24to24(uint8 * data, uint8 * out, uint8 * end) |
387 |
{ |
{ |
388 |
switch (bpp) |
while (out < end) |
389 |
{ |
{ |
390 |
case 16: |
*(out++) = (*(data++)); |
391 |
if (host_be != xserver_be) |
} |
392 |
BSWAP16(colour); |
} |
393 |
break; |
|
394 |
|
static void |
395 |
|
translate24to32(uint8 * data, uint32 * out, uint32 * end) |
396 |
|
{ |
397 |
|
uint32 pixel = 0; |
398 |
|
while (out < end) |
399 |
|
{ |
400 |
|
memcpy(&pixel, data, 3); |
401 |
|
data += 3; |
402 |
|
*(out++) = pixel; |
403 |
|
} |
404 |
|
} |
405 |
|
|
406 |
|
static uint8 * |
407 |
|
translate_image(int width, int height, uint8 * data) |
408 |
|
{ |
409 |
|
int size = width * height * bpp / 8; |
410 |
|
uint8 *out = xmalloc(size); |
411 |
|
uint8 *end = out + size; |
412 |
|
|
413 |
|
switch (server_bpp) |
414 |
|
{ |
415 |
case 24: |
case 24: |
416 |
if (xserver_be) |
switch (bpp) |
417 |
BSWAP24(colour); |
{ |
418 |
|
case 32: |
419 |
|
translate24to32(data, (uint32 *) out, (uint32 *) end); |
420 |
|
break; |
421 |
|
case 24: |
422 |
|
translate24to24(data, out, end); |
423 |
|
break; |
424 |
|
case 16: |
425 |
|
translate24to16(data, (uint16 *) out, (uint16 *) end); |
426 |
|
break; |
427 |
|
} |
428 |
break; |
break; |
429 |
|
case 16: |
430 |
case 32: |
switch (bpp) |
431 |
if (host_be != xserver_be) |
{ |
432 |
BSWAP32(colour); |
case 32: |
433 |
|
translate16to32((uint16 *) data, (uint32 *) out, |
434 |
|
(uint32 *) end); |
435 |
|
break; |
436 |
|
case 24: |
437 |
|
translate16to24((uint16 *) data, out, end); |
438 |
|
break; |
439 |
|
case 16: |
440 |
|
translate16to16((uint16 *) data, (uint16 *) out, |
441 |
|
(uint16 *) end); |
442 |
|
break; |
443 |
|
} |
444 |
|
break; |
445 |
|
case 15: |
446 |
|
switch (bpp) |
447 |
|
{ |
448 |
|
case 32: |
449 |
|
translate15to32((uint16 *) data, (uint32 *) out, |
450 |
|
(uint32 *) end); |
451 |
|
break; |
452 |
|
case 24: |
453 |
|
translate15to24((uint16 *) data, out, end); |
454 |
|
break; |
455 |
|
case 16: |
456 |
|
translate15to16((uint16 *) data, (uint16 *) out, |
457 |
|
(uint16 *) end); |
458 |
|
break; |
459 |
|
} |
460 |
|
break; |
461 |
|
case 8: |
462 |
|
switch (bpp) |
463 |
|
{ |
464 |
|
case 8: |
465 |
|
translate8to8(data, out, end); |
466 |
|
break; |
467 |
|
case 16: |
468 |
|
translate8to16(data, (uint16 *) out, (uint16 *) end); |
469 |
|
break; |
470 |
|
case 24: |
471 |
|
translate8to24(data, out, end); |
472 |
|
break; |
473 |
|
case 32: |
474 |
|
translate8to32(data, (uint32 *) out, (uint32 *) end); |
475 |
|
break; |
476 |
|
} |
477 |
break; |
break; |
478 |
} |
} |
479 |
|
return out; |
|
return colour; |
|
480 |
} |
} |
481 |
|
|
482 |
BOOL |
BOOL |
483 |
get_key_state(int keysym) |
get_key_state(unsigned int state, uint32 keysym) |
484 |
{ |
{ |
485 |
int keysymMask = 0, modifierpos, key; |
int modifierpos, key, keysymMask = 0; |
|
Window wDummy1, wDummy2; |
|
|
int iDummy3, iDummy4, iDummy5, iDummy6; |
|
|
unsigned int current_state; |
|
486 |
int offset; |
int offset; |
487 |
|
|
|
XModifierKeymap *map = XGetModifierMapping(display); |
|
488 |
KeyCode keycode = XKeysymToKeycode(display, keysym); |
KeyCode keycode = XKeysymToKeycode(display, keysym); |
489 |
|
|
490 |
if (keycode == NoSymbol) |
if (keycode == NoSymbol) |
492 |
|
|
493 |
for (modifierpos = 0; modifierpos < 8; modifierpos++) |
for (modifierpos = 0; modifierpos < 8; modifierpos++) |
494 |
{ |
{ |
495 |
offset = map->max_keypermod * modifierpos; |
offset = mod_map->max_keypermod * modifierpos; |
496 |
|
|
497 |
for (key = 0; key < map->max_keypermod; key++) |
for (key = 0; key < mod_map->max_keypermod; key++) |
498 |
{ |
{ |
499 |
if (map->modifiermap[offset + key] == keycode) |
if (mod_map->modifiermap[offset + key] == keycode) |
500 |
keysymMask = 1 << modifierpos; |
keysymMask |= 1 << modifierpos; |
501 |
} |
} |
502 |
} |
} |
503 |
|
|
504 |
XQueryPointer(display, DefaultRootWindow(display), &wDummy1, |
return (state & keysymMask) ? True : False; |
|
&wDummy2, &iDummy3, &iDummy4, &iDummy5, &iDummy6, ¤t_state); |
|
|
|
|
|
XFreeModifiermap(map); |
|
|
|
|
|
return (current_state & keysymMask) ? True : False; |
|
505 |
} |
} |
506 |
|
|
507 |
BOOL |
BOOL |
514 |
display = XOpenDisplay(NULL); |
display = XOpenDisplay(NULL); |
515 |
if (display == NULL) |
if (display == NULL) |
516 |
{ |
{ |
517 |
error("Failed to open display\n"); |
error("Failed to open display: %s\n", XDisplayName(NULL)); |
518 |
return False; |
return False; |
519 |
} |
} |
520 |
|
|
545 |
return False; |
return False; |
546 |
} |
} |
547 |
|
|
548 |
xcolmap = DefaultColormapOfScreen(screen); |
if (owncolmap != True) |
549 |
|
{ |
550 |
|
xcolmap = DefaultColormapOfScreen(screen); |
551 |
|
if (depth <= 8) |
552 |
|
warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n"); |
553 |
|
} |
554 |
|
|
555 |
gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL); |
gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL); |
556 |
|
|
557 |
if (DoesBackingStore(screen) != Always) |
if (DoesBackingStore(screen) != Always) |
561 |
host_be = !(BOOL) (*(uint8 *) (&test)); |
host_be = !(BOOL) (*(uint8 *) (&test)); |
562 |
xserver_be = (ImageByteOrder(display) == MSBFirst); |
xserver_be = (ImageByteOrder(display) == MSBFirst); |
563 |
|
|
564 |
|
if ((width == 0) || (height == 0)) |
565 |
|
{ |
566 |
|
/* Fetch geometry from _NET_WORKAREA */ |
567 |
|
uint32 x, y, cx, cy; |
568 |
|
|
569 |
|
if (get_current_workarea(&x, &y, &cx, &cy) == 0) |
570 |
|
{ |
571 |
|
width = cx; |
572 |
|
height = cy; |
573 |
|
} |
574 |
|
else |
575 |
|
{ |
576 |
|
warning("Failed to get workarea: probably your window manager does not support extended hints\n"); |
577 |
|
width = 800; |
578 |
|
height = 600; |
579 |
|
} |
580 |
|
} |
581 |
|
|
582 |
if (fullscreen) |
if (fullscreen) |
583 |
{ |
{ |
584 |
width = WidthOfScreen(screen); |
width = WidthOfScreen(screen); |
590 |
|
|
591 |
if (ownbackstore) |
if (ownbackstore) |
592 |
{ |
{ |
593 |
backstore = XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth); |
backstore = |
594 |
|
XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth); |
595 |
|
|
596 |
/* clear to prevent rubbish being exposed at startup */ |
/* clear to prevent rubbish being exposed at startup */ |
597 |
XSetForeground(display, gc, BlackPixelOfScreen(screen)); |
XSetForeground(display, gc, BlackPixelOfScreen(screen)); |
598 |
XFillRectangle(display, backstore, gc, 0, 0, width, height); |
XFillRectangle(display, backstore, gc, 0, 0, width, height); |
599 |
} |
} |
600 |
|
|
601 |
|
mod_map = XGetModifierMapping(display); |
602 |
|
|
603 |
if (enable_compose) |
if (enable_compose) |
604 |
IM = XOpenIM(display, NULL, NULL, NULL); |
IM = XOpenIM(display, NULL, NULL, NULL); |
605 |
|
|
606 |
xkeymap_init(); |
xkeymap_init(); |
607 |
|
|
608 |
|
/* todo take this out when high colour is done */ |
609 |
|
printf("server bpp %d client bpp %d depth %d\n", server_bpp, bpp, depth); |
610 |
|
|
611 |
return True; |
return True; |
612 |
} |
} |
613 |
|
|
617 |
if (IM != NULL) |
if (IM != NULL) |
618 |
XCloseIM(IM); |
XCloseIM(IM); |
619 |
|
|
620 |
|
XFreeModifiermap(mod_map); |
621 |
|
|
622 |
if (ownbackstore) |
if (ownbackstore) |
623 |
XFreePixmap(display, backstore); |
XFreePixmap(display, backstore); |
624 |
|
|
637 |
long input_mask, ic_input_mask; |
long input_mask, ic_input_mask; |
638 |
XEvent xevent; |
XEvent xevent; |
639 |
|
|
640 |
wndwidth = fullscreen ? WidthOfScreen(screen) : width; |
wndwidth = fullscreen ? WidthOfScreen(screen) : width; |
641 |
wndheight = fullscreen ? HeightOfScreen(screen) : height; |
wndheight = fullscreen ? HeightOfScreen(screen) : height; |
642 |
|
|
643 |
attribs.background_pixel = BlackPixelOfScreen(screen); |
attribs.background_pixel = BlackPixelOfScreen(screen); |
650 |
|
|
651 |
XStoreName(display, wnd, title); |
XStoreName(display, wnd, title); |
652 |
|
|
653 |
|
if (hide_decorations) |
654 |
|
mwm_hide_decorations(); |
655 |
|
|
656 |
classhints = XAllocClassHint(); |
classhints = XAllocClassHint(); |
657 |
if (classhints != NULL) |
if (classhints != NULL) |
658 |
{ |
{ |
672 |
} |
} |
673 |
|
|
674 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
675 |
StructureNotifyMask | FocusChangeMask; |
VisibilityChangeMask | FocusChangeMask; |
676 |
|
|
|
if (grab_keyboard) |
|
|
input_mask |= EnterWindowMask | LeaveWindowMask; |
|
677 |
if (sendmotion) |
if (sendmotion) |
678 |
input_mask |= PointerMotionMask; |
input_mask |= PointerMotionMask; |
679 |
if (ownbackstore) |
if (ownbackstore) |
680 |
input_mask |= ExposureMask; |
input_mask |= ExposureMask; |
681 |
|
if (fullscreen || grab_keyboard) |
682 |
|
input_mask |= EnterWindowMask; |
683 |
|
if (grab_keyboard) |
684 |
|
input_mask |= LeaveWindowMask; |
685 |
|
|
686 |
if (IM != NULL) |
if (IM != NULL) |
687 |
{ |
{ |
688 |
IC = XCreateIC(IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), |
IC = XCreateIC(IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), |
689 |
XNClientWindow, wnd, XNFocusWindow, wnd, NULL); |
XNClientWindow, wnd, XNFocusWindow, wnd, NULL); |
690 |
|
|
691 |
if ((IC != NULL) && (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL)) |
if ((IC != NULL) |
692 |
|
&& (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL)) |
693 |
input_mask |= ic_input_mask; |
input_mask |= ic_input_mask; |
694 |
} |
} |
695 |
|
|
696 |
XSelectInput(display, wnd, input_mask); |
XSelectInput(display, wnd, input_mask); |
697 |
XMapWindow(display, wnd); |
XMapWindow(display, wnd); |
698 |
|
|
699 |
/* wait for MapNotify */ |
/* wait for VisibilityNotify */ |
700 |
do { |
do |
701 |
XMaskEvent(display, StructureNotifyMask, &xevent); |
{ |
702 |
} while (xevent.type != MapNotify); |
XMaskEvent(display, VisibilityChangeMask, &xevent); |
703 |
|
} |
704 |
|
while (xevent.type != VisibilityNotify); |
705 |
|
|
706 |
if (fullscreen) |
focused = False; |
707 |
XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); |
mouse_in_wnd = False; |
708 |
|
|
709 |
|
/* handle the WM_DELETE_WINDOW protocol */ |
710 |
|
protocol_atom = XInternAtom(display, "WM_PROTOCOLS", True); |
711 |
|
kill_atom = XInternAtom(display, "WM_DELETE_WINDOW", True); |
712 |
|
XSetWMProtocols(display, wnd, &kill_atom, 1); |
713 |
|
|
714 |
return True; |
return True; |
715 |
} |
} |
748 |
} |
} |
749 |
} |
} |
750 |
|
|
751 |
/* Process all events in Xlib queue */ |
/* Process all events in Xlib queue |
752 |
static void |
Returns 0 after user quit, 1 otherwise */ |
753 |
|
static int |
754 |
xwin_process_events(void) |
xwin_process_events(void) |
755 |
{ |
{ |
756 |
XEvent xevent; |
XEvent xevent; |
758 |
uint16 button, flags; |
uint16 button, flags; |
759 |
uint32 ev_time; |
uint32 ev_time; |
760 |
key_translation tr; |
key_translation tr; |
|
char *ksname = NULL; |
|
761 |
char str[256]; |
char str[256]; |
762 |
Status status; |
Status status; |
763 |
|
unsigned int state; |
764 |
|
Window wdummy; |
765 |
|
int dummy; |
766 |
|
|
767 |
while (XPending(display) > 0) |
while (XPending(display) > 0) |
768 |
{ |
{ |
774 |
continue; |
continue; |
775 |
} |
} |
776 |
|
|
|
ev_time = time(NULL); |
|
777 |
flags = 0; |
flags = 0; |
778 |
|
|
779 |
switch (xevent.type) |
switch (xevent.type) |
780 |
{ |
{ |
781 |
|
case ClientMessage: |
782 |
|
/* the window manager told us to quit */ |
783 |
|
if ((xevent.xclient.message_type == protocol_atom) |
784 |
|
&& (xevent.xclient.data.l[0] == kill_atom)) |
785 |
|
/* Quit */ |
786 |
|
return 0; |
787 |
|
break; |
788 |
|
|
789 |
case KeyPress: |
case KeyPress: |
790 |
if (IC != NULL) |
if (IC != NULL) |
791 |
/* Multi_key compatible version */ |
/* Multi_key compatible version */ |
808 |
str, sizeof(str), &keysym, NULL); |
str, sizeof(str), &keysym, NULL); |
809 |
} |
} |
810 |
|
|
811 |
ksname = get_ksname(keysym); |
DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, |
812 |
DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); |
get_ksname(keysym))); |
813 |
|
|
814 |
if (handle_special_keys(keysym, ev_time, True)) |
ev_time = time(NULL); |
815 |
|
if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True)) |
816 |
break; |
break; |
817 |
|
|
818 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
825 |
|
|
826 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
827 |
break; |
break; |
828 |
|
|
829 |
case KeyRelease: |
case KeyRelease: |
830 |
XLookupString((XKeyEvent *) & xevent, str, |
XLookupString((XKeyEvent *) & xevent, str, |
831 |
sizeof(str), &keysym, NULL); |
sizeof(str), &keysym, NULL); |
832 |
|
|
|
ksname = get_ksname(keysym); |
|
833 |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
834 |
ksname)); |
get_ksname(keysym))); |
835 |
|
|
836 |
if (handle_special_keys(keysym, ev_time, False)) |
ev_time = time(NULL); |
837 |
|
if (handle_special_keys(keysym, xevent.xkey.state, ev_time, False)) |
838 |
break; |
break; |
839 |
|
|
840 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
855 |
if (button == 0) |
if (button == 0) |
856 |
break; |
break; |
857 |
|
|
858 |
rdp_send_input(ev_time, RDP_INPUT_MOUSE, |
/* If win_button_size is nonzero, enable single app mode */ |
859 |
|
if (xevent.xbutton.y < win_button_size) |
860 |
|
{ |
861 |
|
if (xevent.xbutton.x >= width - win_button_size) |
862 |
|
{ |
863 |
|
/* The close button, do nothing */ |
864 |
|
; |
865 |
|
} |
866 |
|
else if (xevent.xbutton.x >= width - win_button_size * 2) |
867 |
|
{ |
868 |
|
/* The maximize/restore button. Do not send to |
869 |
|
server. It might be a good idea to change the |
870 |
|
cursor or give some other visible indication |
871 |
|
that rdesktop inhibited this click */ |
872 |
|
break; |
873 |
|
} |
874 |
|
else if (xevent.xbutton.x >= width - win_button_size * 3) |
875 |
|
{ |
876 |
|
/* The minimize button. Iconify window. */ |
877 |
|
XIconifyWindow(display, wnd, |
878 |
|
DefaultScreen(display)); |
879 |
|
break; |
880 |
|
} |
881 |
|
} |
882 |
|
|
883 |
|
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
884 |
flags | button, xevent.xbutton.x, xevent.xbutton.y); |
flags | button, xevent.xbutton.x, xevent.xbutton.y); |
885 |
break; |
break; |
886 |
|
|
887 |
case MotionNotify: |
case MotionNotify: |
888 |
rdp_send_input(ev_time, RDP_INPUT_MOUSE, |
if (fullscreen && !focused) |
889 |
|
XSetInputFocus(display, wnd, RevertToPointerRoot, |
890 |
|
CurrentTime); |
891 |
|
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
892 |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
893 |
break; |
break; |
894 |
|
|
895 |
case EnterNotify: |
case FocusIn: |
896 |
if (grab_keyboard) |
if (xevent.xfocus.mode == NotifyGrab) |
897 |
|
break; |
898 |
|
focused = True; |
899 |
|
XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, |
900 |
|
&dummy, &dummy, &state); |
901 |
|
reset_modifier_keys(state); |
902 |
|
if (grab_keyboard && mouse_in_wnd) |
903 |
XGrabKeyboard(display, wnd, True, |
XGrabKeyboard(display, wnd, True, |
904 |
GrabModeAsync, GrabModeAsync, CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
905 |
break; |
break; |
906 |
|
|
907 |
case LeaveNotify: |
case FocusOut: |
908 |
if (grab_keyboard) |
if (xevent.xfocus.mode == NotifyUngrab) |
909 |
|
break; |
910 |
|
focused = False; |
911 |
|
if (xevent.xfocus.mode == NotifyWhileGrabbed) |
912 |
XUngrabKeyboard(display, CurrentTime); |
XUngrabKeyboard(display, CurrentTime); |
913 |
break; |
break; |
914 |
|
|
915 |
case FocusIn: |
case EnterNotify: |
916 |
reset_modifier_keys(); |
/* we only register for this event when in fullscreen mode */ |
917 |
|
/* or grab_keyboard */ |
918 |
|
mouse_in_wnd = True; |
919 |
|
if (fullscreen) |
920 |
|
{ |
921 |
|
XSetInputFocus(display, wnd, RevertToPointerRoot, |
922 |
|
CurrentTime); |
923 |
|
break; |
924 |
|
} |
925 |
|
if (focused) |
926 |
|
XGrabKeyboard(display, wnd, True, |
927 |
|
GrabModeAsync, GrabModeAsync, CurrentTime); |
928 |
|
break; |
929 |
|
|
930 |
|
case LeaveNotify: |
931 |
|
/* we only register for this event when grab_keyboard */ |
932 |
|
mouse_in_wnd = False; |
933 |
|
XUngrabKeyboard(display, CurrentTime); |
934 |
break; |
break; |
935 |
|
|
936 |
case Expose: |
case Expose: |
947 |
if (xevent.xmapping.request == MappingKeyboard |
if (xevent.xmapping.request == MappingKeyboard |
948 |
|| xevent.xmapping.request == MappingModifier) |
|| xevent.xmapping.request == MappingModifier) |
949 |
XRefreshKeyboardMapping(&xevent.xmapping); |
XRefreshKeyboardMapping(&xevent.xmapping); |
950 |
|
|
951 |
|
if (xevent.xmapping.request == MappingModifier) |
952 |
|
{ |
953 |
|
XFreeModifiermap(mod_map); |
954 |
|
mod_map = XGetModifierMapping(display); |
955 |
|
} |
956 |
break; |
break; |
957 |
|
|
958 |
} |
} |
959 |
} |
} |
960 |
|
/* Keep going */ |
961 |
|
return 1; |
962 |
} |
} |
963 |
|
|
964 |
void |
/* Returns 0 after user quit, 1 otherwise */ |
965 |
|
int |
966 |
ui_select(int rdp_socket) |
ui_select(int rdp_socket) |
967 |
{ |
{ |
968 |
int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1; |
int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1; |
973 |
while (True) |
while (True) |
974 |
{ |
{ |
975 |
/* Process any events already waiting */ |
/* Process any events already waiting */ |
976 |
xwin_process_events(); |
if (!xwin_process_events()) |
977 |
|
/* User quit */ |
978 |
|
return 0; |
979 |
|
|
980 |
FD_ZERO(&rfds); |
FD_ZERO(&rfds); |
981 |
FD_SET(rdp_socket, &rfds); |
FD_SET(rdp_socket, &rfds); |
991 |
} |
} |
992 |
|
|
993 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
994 |
return; |
return 1; |
995 |
} |
} |
996 |
} |
} |
997 |
|
|
1008 |
Pixmap bitmap; |
Pixmap bitmap; |
1009 |
uint8 *tdata; |
uint8 *tdata; |
1010 |
|
|
1011 |
tdata = translate_image(width, height, data); |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
1012 |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
1013 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
1014 |
(char *) tdata, width, height, 8, 0); |
(char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0); |
1015 |
|
|
1016 |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
1017 |
|
|
1018 |
XFree(image); |
XFree(image); |
1019 |
xfree(tdata); |
if (!owncolmap) |
1020 |
|
xfree(tdata); |
1021 |
return (HBITMAP) bitmap; |
return (HBITMAP) bitmap; |
1022 |
} |
} |
1023 |
|
|
1026 |
{ |
{ |
1027 |
XImage *image; |
XImage *image; |
1028 |
uint8 *tdata; |
uint8 *tdata; |
1029 |
|
tdata = (owncolmap ? data : translate_image(width, height, data)); |
|
tdata = translate_image(width, height, data); |
|
1030 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
1031 |
(char *) tdata, width, height, 8, 0); |
(char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0); |
1032 |
|
|
1033 |
if (ownbackstore) |
if (ownbackstore) |
1034 |
{ |
{ |
1041 |
} |
} |
1042 |
|
|
1043 |
XFree(image); |
XFree(image); |
1044 |
xfree(tdata); |
if (!owncolmap) |
1045 |
|
xfree(tdata); |
1046 |
} |
} |
1047 |
|
|
1048 |
void |
void |
1173 |
(xc)->blue = ((c)->blue << 8) | (c)->blue; \ |
(xc)->blue = ((c)->blue << 8) | (c)->blue; \ |
1174 |
(xc)->flags = DoRed | DoGreen | DoBlue; |
(xc)->flags = DoRed | DoGreen | DoBlue; |
1175 |
|
|
1176 |
|
|
1177 |
HCOLOURMAP |
HCOLOURMAP |
1178 |
ui_create_colourmap(COLOURMAP * colours) |
ui_create_colourmap(COLOURMAP * colours) |
1179 |
{ |
{ |
1180 |
COLOURENTRY *entry; |
COLOURENTRY *entry; |
1181 |
int i, ncolours = colours->ncolours; |
int i, ncolours = colours->ncolours; |
1182 |
uint32 *map = xmalloc(sizeof(*colmap) * ncolours); |
if (!owncolmap) |
|
XColor xentry; |
|
|
XColor xc_cache[256]; |
|
|
uint32 colour; |
|
|
int colLookup = 256; |
|
|
for (i = 0; i < ncolours; i++) |
|
1183 |
{ |
{ |
1184 |
entry = &colours->colours[i]; |
uint32 *map = xmalloc(sizeof(*colmap) * ncolours); |
1185 |
MAKE_XCOLOR(&xentry, entry); |
XColor xentry; |
1186 |
|
XColor xc_cache[256]; |
1187 |
if (XAllocColor(display, xcolmap, &xentry) == 0) |
uint32 colour; |
1188 |
|
int colLookup = 256; |
1189 |
|
for (i = 0; i < ncolours; i++) |
1190 |
{ |
{ |
1191 |
/* Allocation failed, find closest match. */ |
entry = &colours->colours[i]; |
1192 |
int j = 256; |
MAKE_XCOLOR(&xentry, entry); |
1193 |
int nMinDist = 3 * 256 * 256; |
|
1194 |
long nDist = nMinDist; |
if (XAllocColor(display, xcolmap, &xentry) == 0) |
1195 |
|
{ |
1196 |
/* only get the colors once */ |
/* Allocation failed, find closest match. */ |
1197 |
while( colLookup-- ){ |
int j = 256; |
1198 |
xc_cache[colLookup].pixel = colLookup; |
int nMinDist = 3 * 256 * 256; |
1199 |
xc_cache[colLookup].red = xc_cache[colLookup].green = xc_cache[colLookup].blue = 0; |
long nDist = nMinDist; |
|
xc_cache[colLookup].flags = 0; |
|
|
XQueryColor(display, DefaultColormap(display, DefaultScreen(display)), &xc_cache[colLookup]); |
|
|
} |
|
|
colLookup = 0; |
|
1200 |
|
|
1201 |
/* approximate the pixel */ |
/* only get the colors once */ |
1202 |
while( j-- ){ |
while (colLookup--) |
1203 |
if( xc_cache[j].flags ){ |
{ |
1204 |
nDist = |
xc_cache[colLookup].pixel = colLookup; |
1205 |
((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) * |
xc_cache[colLookup].red = xc_cache[colLookup].green = |
1206 |
((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) + |
xc_cache[colLookup].blue = 0; |
1207 |
((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) * |
xc_cache[colLookup].flags = 0; |
1208 |
((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) + |
XQueryColor(display, |
1209 |
((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8)) * |
DefaultColormap(display, |
1210 |
((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8)); |
DefaultScreen(display)), |
1211 |
|
&xc_cache[colLookup]); |
1212 |
} |
} |
1213 |
if( nDist < nMinDist ){ |
colLookup = 0; |
1214 |
nMinDist = nDist; |
|
1215 |
xentry.pixel = j; |
/* approximate the pixel */ |
1216 |
|
while (j--) |
1217 |
|
{ |
1218 |
|
if (xc_cache[j].flags) |
1219 |
|
{ |
1220 |
|
nDist = ((long) (xc_cache[j].red >> 8) - |
1221 |
|
(long) (xentry.red >> 8)) * |
1222 |
|
((long) (xc_cache[j].red >> 8) - |
1223 |
|
(long) (xentry.red >> 8)) + |
1224 |
|
((long) (xc_cache[j].green >> 8) - |
1225 |
|
(long) (xentry.green >> 8)) * |
1226 |
|
((long) (xc_cache[j].green >> 8) - |
1227 |
|
(long) (xentry.green >> 8)) + |
1228 |
|
((long) (xc_cache[j].blue >> 8) - |
1229 |
|
(long) (xentry.blue >> 8)) * |
1230 |
|
((long) (xc_cache[j].blue >> 8) - |
1231 |
|
(long) (xentry.blue >> 8)); |
1232 |
|
} |
1233 |
|
if (nDist < nMinDist) |
1234 |
|
{ |
1235 |
|
nMinDist = nDist; |
1236 |
|
xentry.pixel = j; |
1237 |
|
} |
1238 |
} |
} |
1239 |
} |
} |
1240 |
} |
colour = xentry.pixel; |
|
colour = xentry.pixel; |
|
1241 |
|
|
1242 |
/* update our cache */ |
/* update our cache */ |
1243 |
if( xentry.pixel < 256 ){ |
if (xentry.pixel < 256) |
1244 |
xc_cache[xentry.pixel].red = xentry.red; |
{ |
1245 |
xc_cache[xentry.pixel].green = xentry.green; |
xc_cache[xentry.pixel].red = xentry.red; |
1246 |
xc_cache[xentry.pixel].blue = xentry.blue; |
xc_cache[xentry.pixel].green = xentry.green; |
1247 |
|
xc_cache[xentry.pixel].blue = xentry.blue; |
1248 |
|
|
1249 |
} |
} |
1250 |
|
|
1251 |
|
|
1252 |
/* byte swap here to make translate_image faster */ |
/* byte swap here to make translate_image faster */ |
1253 |
map[i] = translate_colour(colour); |
map[i] = translate_colour(colour); |
1254 |
|
} |
1255 |
|
return map; |
1256 |
} |
} |
1257 |
|
else |
1258 |
|
{ |
1259 |
|
XColor *xcolours, *xentry; |
1260 |
|
Colormap map; |
1261 |
|
|
1262 |
|
xcolours = xmalloc(sizeof(XColor) * ncolours); |
1263 |
|
for (i = 0; i < ncolours; i++) |
1264 |
|
{ |
1265 |
|
entry = &colours->colours[i]; |
1266 |
|
xentry = &xcolours[i]; |
1267 |
|
xentry->pixel = i; |
1268 |
|
MAKE_XCOLOR(xentry, entry); |
1269 |
|
} |
1270 |
|
|
1271 |
|
map = XCreateColormap(display, wnd, visual, AllocAll); |
1272 |
|
XStoreColors(display, map, xcolours, ncolours); |
1273 |
|
|
1274 |
return map; |
xfree(xcolours); |
1275 |
|
return (HCOLOURMAP) map; |
1276 |
|
} |
1277 |
} |
} |
1278 |
|
|
1279 |
void |
void |
1280 |
ui_destroy_colourmap(HCOLOURMAP map) |
ui_destroy_colourmap(HCOLOURMAP map) |
1281 |
{ |
{ |
1282 |
xfree(map); |
if (!owncolmap) |
1283 |
|
xfree(map); |
1284 |
|
else |
1285 |
|
XFreeColormap(display, (Colormap) map); |
1286 |
} |
} |
1287 |
|
|
1288 |
void |
void |
1289 |
ui_set_colourmap(HCOLOURMAP map) |
ui_set_colourmap(HCOLOURMAP map) |
1290 |
{ |
{ |
1291 |
colmap = map; |
if (!owncolmap) |
1292 |
|
colmap = map; |
1293 |
|
else |
1294 |
|
XSetWindowColormap(display, wnd, (Colormap) map); |
1295 |
} |
} |
1296 |
|
|
1297 |
void |
void |
1454 |
FILL_RECTANGLE(x, y, cx, cy); |
FILL_RECTANGLE(x, y, cx, cy); |
1455 |
} |
} |
1456 |
|
|
1457 |
|
/* warning, this function only draws on wnd or backstore, not both */ |
1458 |
void |
void |
1459 |
ui_draw_glyph(int mixmode, |
ui_draw_glyph(int mixmode, |
1460 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
1469 |
XSetStipple(display, gc, (Pixmap) glyph); |
XSetStipple(display, gc, (Pixmap) glyph); |
1470 |
XSetTSOrigin(display, gc, x, y); |
XSetTSOrigin(display, gc, x, y); |
1471 |
|
|
1472 |
FILL_RECTANGLE(x, y, cx, cy); |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
1473 |
|
|
1474 |
XSetFillStyle(display, gc, FillSolid); |
XSetFillStyle(display, gc, FillSolid); |
1475 |
} |
} |
1498 |
}\ |
}\ |
1499 |
if (glyph != NULL)\ |
if (glyph != NULL)\ |
1500 |
{\ |
{\ |
1501 |
ui_draw_glyph (mixmode, x + (short) glyph->offset,\ |
ui_draw_glyph (mixmode, x + glyph->offset,\ |
1502 |
y + (short) glyph->baseline,\ |
y + glyph->baseline,\ |
1503 |
glyph->width, glyph->height,\ |
glyph->width, glyph->height,\ |
1504 |
glyph->pixmap, 0, 0, bgcolour, fgcolour);\ |
glyph->pixmap, 0, 0, bgcolour, fgcolour);\ |
1505 |
if (flags & TEXT2_IMPLICIT_X)\ |
if (flags & TEXT2_IMPLICIT_X)\ |
1521 |
|
|
1522 |
if (boxcx > 1) |
if (boxcx > 1) |
1523 |
{ |
{ |
1524 |
FILL_RECTANGLE(boxx, boxy, boxcx, boxcy); |
FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy); |
1525 |
} |
} |
1526 |
else if (mixmode == MIX_OPAQUE) |
else if (mixmode == MIX_OPAQUE) |
1527 |
{ |
{ |
1528 |
FILL_RECTANGLE(clipx, clipy, clipcx, clipcy); |
FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy); |
1529 |
} |
} |
1530 |
|
|
1531 |
/* Paint text, character by character */ |
/* Paint text, character by character */ |
1539 |
else |
else |
1540 |
{ |
{ |
1541 |
error("this shouldn't be happening\n"); |
error("this shouldn't be happening\n"); |
1542 |
break; |
exit(1); |
1543 |
} |
} |
1544 |
/* this will move pointer from start to first character after FF command */ |
/* this will move pointer from start to first character after FF command */ |
1545 |
length -= i + 3; |
length -= i + 3; |
1559 |
else |
else |
1560 |
x += text[i + 2]; |
x += text[i + 2]; |
1561 |
} |
} |
|
if (i + 2 < length) |
|
|
i += 3; |
|
|
else |
|
|
i += 2; |
|
|
length -= i; |
|
|
/* this will move pointer from start to first character after FE command */ |
|
|
text = &(text[i]); |
|
|
i = 0; |
|
1562 |
for (j = 0; j < entry->size; j++) |
for (j = 0; j < entry->size; j++) |
1563 |
DO_GLYPH(((uint8 *) (entry->data)), j); |
DO_GLYPH(((uint8 *) (entry->data)), j); |
1564 |
} |
} |
1565 |
|
if (i + 2 < length) |
1566 |
|
i += 3; |
1567 |
|
else |
1568 |
|
i += 2; |
1569 |
|
length -= i; |
1570 |
|
/* this will move pointer from start to first character after FE command */ |
1571 |
|
text = &(text[i]); |
1572 |
|
i = 0; |
1573 |
break; |
break; |
1574 |
|
|
1575 |
default: |
default: |
1578 |
break; |
break; |
1579 |
} |
} |
1580 |
} |
} |
1581 |
|
if (ownbackstore) |
1582 |
|
{ |
1583 |
|
if (boxcx > 1) |
1584 |
|
XCopyArea(display, backstore, wnd, gc, boxx, |
1585 |
|
boxy, boxcx, boxcy, boxx, boxy); |
1586 |
|
else |
1587 |
|
XCopyArea(display, backstore, wnd, gc, clipx, |
1588 |
|
clipy, clipcx, clipcy, clipx, clipy); |
1589 |
|
} |
1590 |
} |
} |
1591 |
|
|
1592 |
void |
void |