32 |
extern BOOL sendmotion; |
extern BOOL sendmotion; |
33 |
extern BOOL fullscreen; |
extern BOOL fullscreen; |
34 |
extern BOOL grab_keyboard; |
extern BOOL grab_keyboard; |
35 |
|
extern char title[]; |
36 |
|
BOOL enable_compose = False; |
37 |
|
|
38 |
Display *display = NULL; |
Display *display; |
39 |
static int x_socket; |
static int x_socket; |
40 |
|
static Screen *screen; |
41 |
static Window wnd; |
static Window wnd; |
42 |
static GC gc; |
static GC gc; |
43 |
static Visual *visual; |
static Visual *visual; |
44 |
static int depth; |
static int depth; |
45 |
static int bpp; |
static int bpp; |
46 |
|
static XIM IM; |
47 |
|
static XIC IC; |
48 |
|
static Cursor current_cursor; |
49 |
|
|
50 |
/* endianness */ |
/* endianness */ |
51 |
static BOOL host_be; |
static BOOL host_be; |
63 |
} |
} |
64 |
|
|
65 |
/* colour maps */ |
/* colour maps */ |
|
static BOOL owncolmap; |
|
66 |
static Colormap xcolmap; |
static Colormap xcolmap; |
|
static uint32 white; |
|
67 |
static uint32 *colmap; |
static uint32 *colmap; |
|
static XIM IM = NULL; |
|
|
static XIC IC = NULL; |
|
|
|
|
|
/* Compose support */ |
|
|
BOOL enable_compose = False; |
|
68 |
|
|
69 |
#define TRANSLATE(col) ( owncolmap ? col : translate_colour(colmap[col]) ) |
#define SET_FOREGROUND(col) XSetForeground(display, gc, translate_colour(colmap[col])); |
70 |
#define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); |
#define SET_BACKGROUND(col) XSetBackground(display, gc, translate_colour(colmap[col])); |
|
#define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); |
|
71 |
|
|
72 |
static int rop2_map[] = { |
static int rop2_map[] = { |
73 |
GXclear, /* 0 */ |
GXclear, /* 0 */ |
185 |
return colour; |
return colour; |
186 |
} |
} |
187 |
|
|
188 |
static unsigned long |
BOOL |
189 |
init_inputmethod(void) |
get_key_state(int keysym) |
190 |
{ |
{ |
191 |
unsigned long filtered_events = 0; |
int keysymMask = 0, modifierpos, key; |
192 |
|
Window wDummy1, wDummy2; |
193 |
|
int iDummy3, iDummy4, iDummy5, iDummy6; |
194 |
|
unsigned int current_state; |
195 |
|
int offset; |
196 |
|
|
197 |
IM = XOpenIM(display, NULL, NULL, NULL); |
XModifierKeymap *map = XGetModifierMapping(display); |
198 |
if (IM == NULL) |
KeyCode keycode = XKeysymToKeycode(display, keysym); |
|
{ |
|
|
error("Failed to open input method\n"); |
|
|
} |
|
199 |
|
|
200 |
if (IM != NULL) |
if (keycode == NoSymbol) |
201 |
|
return False; |
202 |
|
|
203 |
|
for (modifierpos = 0; modifierpos < 8; modifierpos++) |
204 |
{ |
{ |
205 |
/* Must be done after XCreateWindow */ |
offset = map->max_keypermod * modifierpos; |
|
IC = XCreateIC(IM, XNInputStyle, |
|
|
(XIMPreeditNothing | XIMStatusNothing), |
|
|
XNClientWindow, wnd, XNFocusWindow, wnd, NULL); |
|
206 |
|
|
207 |
if (IC == NULL) |
for (key = 0; key < map->max_keypermod; key++) |
208 |
{ |
{ |
209 |
error("Failed to create input context\n"); |
if (map->modifiermap[offset + key] == keycode) |
210 |
XCloseIM(IM); |
keysymMask = 1 << modifierpos; |
|
IM = NULL; |
|
211 |
} |
} |
212 |
} |
} |
213 |
|
|
214 |
/* For correct Multi_key/Compose processing, I guess. |
XQueryPointer(display, DefaultRootWindow(display), &wDummy1, |
215 |
It seems to work alright anyway, though. */ |
&wDummy2, &iDummy3, &iDummy4, &iDummy5, &iDummy6, ¤t_state); |
|
if (IC != NULL) |
|
|
{ |
|
|
if (XGetICValues(IC, XNFilterEvents, &filtered_events, NULL) != NULL) |
|
|
{ |
|
|
error("Failed to obtain XNFilterEvents value from IC\n"); |
|
|
filtered_events = 0; |
|
|
} |
|
|
} |
|
|
return filtered_events; |
|
|
} |
|
216 |
|
|
217 |
static void |
XFreeModifiermap(map); |
218 |
close_inputmethod(void) |
|
219 |
{ |
return (current_state & keysymMask) ? True : False; |
|
if (IC != NULL) |
|
|
{ |
|
|
XDestroyIC(IC); |
|
|
if (IM != NULL) |
|
|
{ |
|
|
XCloseIM(IM); |
|
|
IM = NULL; |
|
|
} |
|
|
} |
|
220 |
} |
} |
221 |
|
|
222 |
BOOL |
BOOL |
223 |
ui_init() |
ui_init() |
224 |
{ |
{ |
225 |
Screen *screen; |
XPixmapFormatValues *pfm; |
226 |
|
uint16 test; |
227 |
|
int i; |
228 |
|
|
229 |
display = XOpenDisplay(NULL); |
display = XOpenDisplay(NULL); |
230 |
if (display == NULL) |
if (display == NULL) |
231 |
{ |
{ |
232 |
error("Failed to open display\n"); |
error("Failed to open display\n"); |
233 |
return False; |
return False; |
234 |
} |
} |
|
if (fullscreen) |
|
|
{ |
|
|
screen = DefaultScreenOfDisplay(display); |
|
|
width = WidthOfScreen(screen); |
|
|
height = HeightOfScreen(screen); |
|
|
} |
|
|
return True; |
|
|
} |
|
|
|
|
|
BOOL |
|
|
ui_create_window(char *title) |
|
|
{ |
|
|
XSetWindowAttributes attribs; |
|
|
XClassHint *classhints; |
|
|
XSizeHints *sizehints; |
|
|
unsigned long input_mask; |
|
|
XPixmapFormatValues *pfm; |
|
|
Screen *screen; |
|
|
uint16 test; |
|
|
int i; |
|
|
XEvent xevent; |
|
235 |
|
|
236 |
x_socket = ConnectionNumber(display); |
x_socket = ConnectionNumber(display); |
237 |
screen = DefaultScreenOfDisplay(display); |
screen = DefaultScreenOfDisplay(display); |
260 |
return False; |
return False; |
261 |
} |
} |
262 |
|
|
263 |
if (depth <= 8) |
xcolmap = DefaultColormapOfScreen(screen); |
264 |
owncolmap = True; |
gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL); |
265 |
else |
|
266 |
xcolmap = DefaultColormapOfScreen(screen); |
if (DoesBackingStore(screen) != Always) |
267 |
|
ownbackstore = True; |
268 |
|
|
269 |
test = 1; |
test = 1; |
270 |
host_be = !(BOOL) (*(uint8 *) (&test)); |
host_be = !(BOOL) (*(uint8 *) (&test)); |
271 |
xserver_be = (ImageByteOrder(display) == MSBFirst); |
xserver_be = (ImageByteOrder(display) == MSBFirst); |
272 |
|
|
|
white = WhitePixelOfScreen(screen); |
|
|
attribs.background_pixel = BlackPixelOfScreen(screen); |
|
|
attribs.backing_store = DoesBackingStore(screen); |
|
|
|
|
|
if (attribs.backing_store == NotUseful) |
|
|
ownbackstore = True; |
|
|
|
|
273 |
if (fullscreen) |
if (fullscreen) |
274 |
{ |
{ |
|
attribs.override_redirect = True; |
|
275 |
width = WidthOfScreen(screen); |
width = WidthOfScreen(screen); |
276 |
height = HeightOfScreen(screen); |
height = HeightOfScreen(screen); |
277 |
} |
} |
278 |
else |
|
279 |
|
/* make sure width is a multiple of 4 */ |
280 |
|
width = (width + 3) & ~3; |
281 |
|
|
282 |
|
if (ownbackstore) |
283 |
{ |
{ |
284 |
attribs.override_redirect = False; |
backstore = XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth); |
285 |
|
|
286 |
|
/* clear to prevent rubbish being exposed at startup */ |
287 |
|
XSetForeground(display, gc, BlackPixelOfScreen(screen)); |
288 |
|
XFillRectangle(display, backstore, gc, 0, 0, width, height); |
289 |
} |
} |
290 |
|
|
291 |
width = (width + 3) & ~3; /* make width a multiple of 32 bits */ |
if (enable_compose) |
292 |
|
IM = XOpenIM(display, NULL, NULL, NULL); |
293 |
|
|
294 |
|
xkeymap_init(); |
295 |
|
return True; |
296 |
|
} |
297 |
|
|
298 |
|
void |
299 |
|
ui_deinit() |
300 |
|
{ |
301 |
|
if (IM != NULL) |
302 |
|
XCloseIM(IM); |
303 |
|
|
304 |
|
if (ownbackstore) |
305 |
|
XFreePixmap(display, backstore); |
306 |
|
|
307 |
|
XFreeGC(display, gc); |
308 |
|
XCloseDisplay(display); |
309 |
|
display = NULL; |
310 |
|
} |
311 |
|
|
312 |
|
BOOL |
313 |
|
ui_create_window() |
314 |
|
{ |
315 |
|
XSetWindowAttributes attribs; |
316 |
|
XClassHint *classhints; |
317 |
|
XSizeHints *sizehints; |
318 |
|
int wndwidth, wndheight; |
319 |
|
long input_mask, ic_input_mask; |
320 |
|
XEvent xevent; |
321 |
|
|
322 |
wnd = XCreateWindow(display, RootWindowOfScreen(screen), |
wndwidth = fullscreen ? WidthOfScreen(screen) : width; |
323 |
0, 0, width, height, 0, CopyFromParent, |
wndheight = fullscreen ? HeightOfScreen(screen) : height; |
324 |
InputOutput, CopyFromParent, |
|
325 |
CWBackingStore | CWBackPixel | CWOverrideRedirect, &attribs); |
attribs.background_pixel = BlackPixelOfScreen(screen); |
326 |
|
attribs.backing_store = ownbackstore ? NotUseful : Always; |
327 |
|
attribs.override_redirect = fullscreen; |
328 |
|
|
329 |
|
wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, wndwidth, wndheight, |
330 |
|
0, CopyFromParent, InputOutput, CopyFromParent, |
331 |
|
CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs); |
332 |
|
|
333 |
XStoreName(display, wnd, title); |
XStoreName(display, wnd, title); |
334 |
|
|
350 |
XFree(sizehints); |
XFree(sizehints); |
351 |
} |
} |
352 |
|
|
|
xkeymap_init2(); |
|
|
|
|
353 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
354 |
VisibilityChangeMask | FocusChangeMask; |
StructureNotifyMask | FocusChangeMask; |
355 |
|
|
356 |
if (grab_keyboard) |
if (grab_keyboard) |
357 |
input_mask |= EnterWindowMask | LeaveWindowMask; |
input_mask |= EnterWindowMask | LeaveWindowMask; |
358 |
if (sendmotion) |
if (sendmotion) |
359 |
input_mask |= PointerMotionMask; |
input_mask |= PointerMotionMask; |
|
|
|
360 |
if (ownbackstore) |
if (ownbackstore) |
361 |
input_mask |= ExposureMask; |
input_mask |= ExposureMask; |
362 |
|
|
363 |
if (enable_compose) |
if (IM != NULL) |
364 |
input_mask |= init_inputmethod(); |
{ |
365 |
|
IC = XCreateIC(IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), |
366 |
XSelectInput(display, wnd, input_mask); |
XNClientWindow, wnd, XNFocusWindow, wnd, NULL); |
|
|
|
|
gc = XCreateGC(display, wnd, 0, NULL); |
|
367 |
|
|
368 |
if (ownbackstore) |
if ((IC != NULL) && (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL)) |
369 |
backstore = XCreatePixmap(display, wnd, width, height, depth); |
input_mask |= ic_input_mask; |
370 |
|
} |
371 |
|
|
372 |
|
XSelectInput(display, wnd, input_mask); |
373 |
XMapWindow(display, wnd); |
XMapWindow(display, wnd); |
374 |
|
|
375 |
/* Wait for VisibilityNotify Event */ |
/* wait for MapNotify */ |
376 |
for (;;) { |
do { |
377 |
XNextEvent(display, &xevent); |
XMaskEvent(display, StructureNotifyMask, &xevent); |
378 |
if (xevent.type == VisibilityNotify) |
} while (xevent.type != MapNotify); |
|
break; |
|
|
} |
|
379 |
|
|
380 |
/* clear the window so that cached data is not viewed upon start... */ |
if (fullscreen) |
381 |
XSetBackground(display, gc, 0); |
XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); |
|
XSetForeground(display, gc, 0); |
|
|
FILL_RECTANGLE(0, 0, width, height); |
|
382 |
|
|
383 |
return True; |
return True; |
384 |
} |
} |
386 |
void |
void |
387 |
ui_destroy_window() |
ui_destroy_window() |
388 |
{ |
{ |
389 |
if (ownbackstore) |
if (IC != NULL) |
390 |
XFreePixmap(display, backstore); |
XDestroyIC(IC); |
391 |
|
|
392 |
XFreeGC(display, gc); |
XDestroyWindow(display, wnd); |
393 |
|
} |
394 |
|
|
395 |
close_inputmethod(); |
void |
396 |
|
xwin_toggle_fullscreen() |
397 |
|
{ |
398 |
|
Pixmap contents = 0; |
399 |
|
|
400 |
XDestroyWindow(display, wnd); |
if (!ownbackstore) |
401 |
XCloseDisplay(display); |
{ |
402 |
display = NULL; |
/* need to save contents of window */ |
403 |
|
contents = XCreatePixmap(display, wnd, width, height, depth); |
404 |
|
XCopyArea(display, wnd, contents, gc, 0, 0, width, height, 0, 0); |
405 |
|
} |
406 |
|
|
407 |
|
ui_destroy_window(); |
408 |
|
fullscreen = !fullscreen; |
409 |
|
ui_create_window(); |
410 |
|
|
411 |
|
XDefineCursor(display, wnd, current_cursor); |
412 |
|
|
413 |
|
if (!ownbackstore) |
414 |
|
{ |
415 |
|
XCopyArea(display, contents, wnd, gc, 0, 0, width, height, 0, 0); |
416 |
|
XFreePixmap(display, contents); |
417 |
|
} |
418 |
} |
} |
419 |
|
|
420 |
|
/* Process all events in Xlib queue */ |
421 |
static void |
static void |
422 |
xwin_process_events() |
xwin_process_events() |
423 |
{ |
{ |
424 |
XEvent xevent; |
XEvent xevent; |
|
|
|
425 |
KeySym keysym; |
KeySym keysym; |
426 |
uint16 button, flags; |
uint16 button, flags; |
427 |
uint32 ev_time; |
uint32 ev_time; |
430 |
char str[256]; |
char str[256]; |
431 |
Status status; |
Status status; |
432 |
|
|
433 |
/* Refresh keyboard mapping if it has changed. This is important for |
while (XPending(display) > 0) |
|
Xvnc, since it allocates keycodes dynamically */ |
|
|
if (XCheckTypedEvent(display, MappingNotify, &xevent)) |
|
434 |
{ |
{ |
435 |
if (xevent.xmapping.request == MappingKeyboard |
XNextEvent(display, &xevent); |
|
|| xevent.xmapping.request == MappingModifier) |
|
|
XRefreshKeyboardMapping(&xevent.xmapping); |
|
|
} |
|
436 |
|
|
437 |
while (XCheckMaskEvent(display, ~0, &xevent)) |
if ((IC != NULL) && (XFilterEvent(&xevent, None) == True)) |
|
{ |
|
|
if (enable_compose && (XFilterEvent(&xevent, None) == True)) |
|
438 |
{ |
{ |
439 |
DEBUG_KBD(("Filtering event\n")); |
DEBUG_KBD(("Filtering event\n")); |
440 |
continue; |
continue; |
462 |
else |
else |
463 |
{ |
{ |
464 |
/* Plain old XLookupString */ |
/* Plain old XLookupString */ |
465 |
DEBUG_KBD(("No input context, using XLookupString\n")); |
DEBUG_KBD(("\nNo input context, using XLookupString\n")); |
466 |
XLookupString((XKeyEvent *) & xevent, |
XLookupString((XKeyEvent *) & xevent, |
467 |
str, sizeof(str), &keysym, NULL); |
str, sizeof(str), &keysym, NULL); |
468 |
} |
} |
469 |
|
|
470 |
ksname = get_ksname(keysym); |
ksname = get_ksname(keysym); |
471 |
DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); |
DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); |
472 |
|
|
473 |
if (inhibit_key(keysym)) |
if (handle_special_keys(keysym, ev_time, True)) |
|
{ |
|
|
DEBUG_KBD(("Inhibiting key\n")); |
|
474 |
break; |
break; |
|
} |
|
475 |
|
|
476 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
477 |
xevent.xkey.keycode, xevent.xkey.state); |
xevent.xkey.keycode, xevent.xkey.state); |
478 |
|
|
|
ensure_remote_modifiers(ev_time, tr); |
|
|
|
|
479 |
if (tr.scancode == 0) |
if (tr.scancode == 0) |
480 |
break; |
break; |
481 |
|
|
482 |
|
ensure_remote_modifiers(ev_time, tr); |
483 |
|
|
484 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
485 |
break; |
break; |
486 |
case KeyRelease: |
case KeyRelease: |
491 |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
492 |
ksname)); |
ksname)); |
493 |
|
|
494 |
if (inhibit_key(keysym)) |
if (handle_special_keys(keysym, ev_time, False)) |
495 |
break; |
break; |
496 |
|
|
497 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
521 |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
522 |
break; |
break; |
523 |
|
|
|
case FocusIn: |
|
|
/* fall through */ |
|
524 |
case EnterNotify: |
case EnterNotify: |
525 |
if (grab_keyboard) |
if (grab_keyboard) |
526 |
XGrabKeyboard(display, wnd, True, |
XGrabKeyboard(display, wnd, True, |
527 |
GrabModeAsync, GrabModeAsync, CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
528 |
break; |
break; |
529 |
|
|
|
case FocusOut: |
|
|
/* reset keys */ |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
|
|
/* fall through */ |
|
530 |
case LeaveNotify: |
case LeaveNotify: |
531 |
if (grab_keyboard) |
if (grab_keyboard) |
532 |
XUngrabKeyboard(display, CurrentTime); |
XUngrabKeyboard(display, CurrentTime); |
533 |
break; |
break; |
534 |
|
|
535 |
|
case FocusIn: |
536 |
|
reset_modifier_keys(); |
537 |
|
break; |
538 |
|
|
539 |
case Expose: |
case Expose: |
540 |
XCopyArea(display, backstore, wnd, gc, |
XCopyArea(display, backstore, wnd, gc, |
541 |
xevent.xexpose.x, xevent.xexpose.y, |
xevent.xexpose.x, xevent.xexpose.y, |
543 |
xevent.xexpose.height, |
xevent.xexpose.height, |
544 |
xevent.xexpose.x, xevent.xexpose.y); |
xevent.xexpose.x, xevent.xexpose.y); |
545 |
break; |
break; |
546 |
|
|
547 |
|
case MappingNotify: |
548 |
|
/* Refresh keyboard mapping if it has changed. This is important for |
549 |
|
Xvnc, since it allocates keycodes dynamically */ |
550 |
|
if (xevent.xmapping.request == MappingKeyboard |
551 |
|
|| xevent.xmapping.request == MappingModifier) |
552 |
|
XRefreshKeyboardMapping(&xevent.xmapping); |
553 |
|
break; |
554 |
|
|
555 |
} |
} |
556 |
} |
} |
557 |
} |
} |
566 |
|
|
567 |
while (True) |
while (True) |
568 |
{ |
{ |
569 |
|
/* Process any events already waiting */ |
570 |
|
xwin_process_events(); |
571 |
|
|
572 |
FD_ZERO(&rfds); |
FD_ZERO(&rfds); |
573 |
FD_SET(rdp_socket, &rfds); |
FD_SET(rdp_socket, &rfds); |
574 |
if (display != NULL) |
FD_SET(x_socket, &rfds); |
|
{ |
|
|
FD_SET(x_socket, &rfds); |
|
|
XFlush(display); |
|
|
} |
|
575 |
|
|
576 |
switch (select(n, &rfds, NULL, NULL, NULL)) |
switch (select(n, &rfds, NULL, NULL, NULL)) |
577 |
{ |
{ |
582 |
continue; |
continue; |
583 |
} |
} |
584 |
|
|
|
if (FD_ISSET(x_socket, &rfds)) |
|
|
xwin_process_events(); |
|
|
|
|
585 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
586 |
return; |
return; |
587 |
} |
} |
600 |
Pixmap bitmap; |
Pixmap bitmap; |
601 |
uint8 *tdata; |
uint8 *tdata; |
602 |
|
|
603 |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
tdata = translate_image(width, height, data); |
604 |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
605 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
606 |
(char *) tdata, width, height, 8, 0); |
(char *) tdata, width, height, 8, 0); |
608 |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
609 |
|
|
610 |
XFree(image); |
XFree(image); |
611 |
if (!owncolmap) |
xfree(tdata); |
|
xfree(tdata); |
|
612 |
return (HBITMAP) bitmap; |
return (HBITMAP) bitmap; |
613 |
} |
} |
614 |
|
|
618 |
XImage *image; |
XImage *image; |
619 |
uint8 *tdata; |
uint8 *tdata; |
620 |
|
|
621 |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
tdata = translate_image(width, height, data); |
622 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
623 |
(char *) tdata, width, height, 8, 0); |
(char *) tdata, width, height, 8, 0); |
624 |
|
|
633 |
} |
} |
634 |
|
|
635 |
XFree(image); |
XFree(image); |
636 |
if (!owncolmap) |
xfree(tdata); |
|
xfree(tdata); |
|
637 |
} |
} |
638 |
|
|
639 |
void |
void |
748 |
void |
void |
749 |
ui_set_cursor(HCURSOR cursor) |
ui_set_cursor(HCURSOR cursor) |
750 |
{ |
{ |
751 |
XDefineCursor(display, wnd, (Cursor) cursor); |
current_cursor = (Cursor) cursor; |
752 |
|
XDefineCursor(display, wnd, current_cursor); |
753 |
} |
} |
754 |
|
|
755 |
void |
void |
769 |
{ |
{ |
770 |
COLOURENTRY *entry; |
COLOURENTRY *entry; |
771 |
int i, ncolours = colours->ncolours; |
int i, ncolours = colours->ncolours; |
772 |
|
uint32 *map = xmalloc(sizeof(*colmap) * ncolours); |
773 |
|
XColor xentry; |
774 |
|
XColor xc_cache[256]; |
775 |
|
uint32 colour; |
776 |
|
int colLookup = 256; |
777 |
|
for (i = 0; i < ncolours; i++) |
778 |
|
{ |
779 |
|
entry = &colours->colours[i]; |
780 |
|
MAKE_XCOLOR(&xentry, entry); |
781 |
|
|
782 |
|
if (XAllocColor(display, xcolmap, &xentry) == 0) |
783 |
|
{ |
784 |
|
/* Allocation failed, find closest match. */ |
785 |
|
int j = 256; |
786 |
|
int nMinDist = 3 * 256 * 256; |
787 |
|
long nDist = nMinDist; |
788 |
|
|
789 |
|
/* only get the colors once */ |
790 |
|
while( colLookup-- ){ |
791 |
|
xc_cache[colLookup].pixel = colLookup; |
792 |
|
xc_cache[colLookup].red = xc_cache[colLookup].green = xc_cache[colLookup].blue = 0; |
793 |
|
xc_cache[colLookup].flags = 0; |
794 |
|
XQueryColor(display, DefaultColormap(display, DefaultScreen(display)), &xc_cache[colLookup]); |
795 |
|
} |
796 |
|
colLookup = 0; |
797 |
|
|
798 |
if (owncolmap) |
/* approximate the pixel */ |
799 |
{ |
while( j-- ){ |
800 |
XColor *xcolours, *xentry; |
if( xc_cache[j].flags ){ |
801 |
Colormap map; |
nDist = |
802 |
|
((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) * |
803 |
xcolours = xmalloc(sizeof(XColor) * ncolours); |
((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) + |
804 |
for (i = 0; i < ncolours; i++) |
((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) * |
805 |
{ |
((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) + |
806 |
entry = &colours->colours[i]; |
((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8)) * |
807 |
xentry = &xcolours[i]; |
((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8)); |
808 |
xentry->pixel = i; |
} |
809 |
MAKE_XCOLOR(xentry, entry); |
if( nDist < nMinDist ){ |
810 |
|
nMinDist = nDist; |
811 |
|
xentry.pixel = j; |
812 |
|
} |
813 |
|
} |
814 |
} |
} |
815 |
|
colour = xentry.pixel; |
816 |
|
|
817 |
map = XCreateColormap(display, wnd, visual, AllocAll); |
/* update our cache */ |
818 |
XStoreColors(display, map, xcolours, ncolours); |
if( xentry.pixel < 256 ){ |
819 |
|
xc_cache[xentry.pixel].red = xentry.red; |
820 |
xfree(xcolours); |
xc_cache[xentry.pixel].green = xentry.green; |
821 |
return (HCOLOURMAP) map; |
xc_cache[xentry.pixel].blue = xentry.blue; |
|
} |
|
|
else |
|
|
{ |
|
|
uint32 *map = xmalloc(sizeof(*colmap) * ncolours); |
|
|
XColor xentry; |
|
|
uint32 colour; |
|
|
|
|
|
for (i = 0; i < ncolours; i++) |
|
|
{ |
|
|
entry = &colours->colours[i]; |
|
|
MAKE_XCOLOR(&xentry, entry); |
|
822 |
|
|
|
if (XAllocColor(display, xcolmap, &xentry) != 0) |
|
|
colour = xentry.pixel; |
|
|
else |
|
|
colour = white; |
|
|
|
|
|
/* byte swap here to make translate_image faster */ |
|
|
map[i] = translate_colour(colour); |
|
823 |
} |
} |
824 |
|
|
825 |
return map; |
|
826 |
|
/* byte swap here to make translate_image faster */ |
827 |
|
map[i] = translate_colour(colour); |
828 |
} |
} |
829 |
|
|
830 |
|
return map; |
831 |
} |
} |
832 |
|
|
833 |
void |
void |
834 |
ui_destroy_colourmap(HCOLOURMAP map) |
ui_destroy_colourmap(HCOLOURMAP map) |
835 |
{ |
{ |
836 |
if (owncolmap) |
xfree(map); |
|
XFreeColormap(display, (Colormap) map); |
|
|
else |
|
|
xfree(map); |
|
837 |
} |
} |
838 |
|
|
839 |
void |
void |
840 |
ui_set_colourmap(HCOLOURMAP map) |
ui_set_colourmap(HCOLOURMAP map) |
841 |
{ |
{ |
842 |
if (owncolmap) |
colmap = map; |
|
XSetWindowColormap(display, wnd, (Colormap) map); |
|
|
else |
|
|
colmap = map; |
|
843 |
} |
} |
844 |
|
|
845 |
void |
void |