34 |
extern BOOL grab_keyboard; |
extern BOOL grab_keyboard; |
35 |
extern char title[]; |
extern char title[]; |
36 |
|
|
37 |
Display *display = NULL; |
Display *display; |
38 |
static int x_socket; |
static int x_socket; |
39 |
|
static Screen *screen; |
40 |
static Window wnd; |
static Window wnd; |
41 |
static GC gc; |
static GC gc; |
42 |
static Visual *visual; |
static Visual *visual; |
63 |
/* colour maps */ |
/* colour maps */ |
64 |
static BOOL owncolmap; |
static BOOL owncolmap; |
65 |
static Colormap xcolmap; |
static Colormap xcolmap; |
|
static uint32 white; |
|
66 |
static uint32 *colmap; |
static uint32 *colmap; |
|
static XIM IM = NULL; |
|
|
static XIC IC = NULL; |
|
67 |
|
|
68 |
/* Compose support */ |
/* Compose support */ |
69 |
BOOL enable_compose = False; |
BOOL enable_compose = False; |
70 |
|
static XIM IM = NULL; |
71 |
|
static XIC IC = NULL; |
72 |
|
|
73 |
/* toggle fullscreen globals */ |
/* toggle fullscreen globals */ |
|
static XSetWindowAttributes attribs; |
|
74 |
static unsigned long input_mask; |
static unsigned long input_mask; |
75 |
|
|
76 |
#define TRANSLATE(col) ( owncolmap ? col : translate_colour(colmap[col]) ) |
#define TRANSLATE(col) ( owncolmap ? col : translate_colour(colmap[col]) ) |
246 |
} |
} |
247 |
} |
} |
248 |
|
|
249 |
static BOOL |
BOOL |
250 |
get_key_state(int keysym) |
get_key_state(int keysym) |
251 |
{ |
{ |
252 |
int keysymMask = 0, modifierpos, key; |
int keysymMask = 0, modifierpos, key; |
284 |
BOOL |
BOOL |
285 |
ui_init() |
ui_init() |
286 |
{ |
{ |
287 |
Screen *screen; |
XPixmapFormatValues *pfm; |
288 |
|
uint16 test; |
289 |
|
int i; |
290 |
|
|
291 |
display = XOpenDisplay(NULL); |
display = XOpenDisplay(NULL); |
292 |
if (display == NULL) |
if (display == NULL) |
293 |
{ |
{ |
294 |
error("Failed to open display\n"); |
error("Failed to open display\n"); |
295 |
return False; |
return False; |
296 |
} |
} |
297 |
|
|
298 |
|
x_socket = ConnectionNumber(display); |
299 |
|
screen = DefaultScreenOfDisplay(display); |
300 |
|
visual = DefaultVisualOfScreen(screen); |
301 |
|
depth = DefaultDepthOfScreen(screen); |
302 |
|
|
303 |
|
pfm = XListPixmapFormats(display, &i); |
304 |
|
if (pfm != NULL) |
305 |
|
{ |
306 |
|
/* Use maximum bpp for this depth - this is generally |
307 |
|
desirable, e.g. 24 bits->32 bits. */ |
308 |
|
while (i--) |
309 |
|
{ |
310 |
|
if ((pfm[i].depth == depth) && (pfm[i].bits_per_pixel > bpp)) |
311 |
|
{ |
312 |
|
bpp = pfm[i].bits_per_pixel; |
313 |
|
} |
314 |
|
} |
315 |
|
XFree(pfm); |
316 |
|
} |
317 |
|
|
318 |
|
if (bpp < 8) |
319 |
|
{ |
320 |
|
error("Less than 8 bpp not currently supported.\n"); |
321 |
|
XCloseDisplay(display); |
322 |
|
return False; |
323 |
|
} |
324 |
|
|
325 |
|
if (depth <= 8) |
326 |
|
owncolmap = True; |
327 |
|
else |
328 |
|
xcolmap = DefaultColormapOfScreen(screen); |
329 |
|
|
330 |
|
if (DoesBackingStore(screen) == NotUseful) |
331 |
|
ownbackstore = True; |
332 |
|
|
333 |
|
test = 1; |
334 |
|
host_be = !(BOOL) (*(uint8 *) (&test)); |
335 |
|
xserver_be = (ImageByteOrder(display) == MSBFirst); |
336 |
|
|
337 |
if (fullscreen) |
if (fullscreen) |
338 |
{ |
{ |
|
screen = DefaultScreenOfDisplay(display); |
|
339 |
width = WidthOfScreen(screen); |
width = WidthOfScreen(screen); |
340 |
height = HeightOfScreen(screen); |
height = HeightOfScreen(screen); |
341 |
} |
} |
342 |
|
|
343 |
|
xkeymap_init(); |
344 |
return True; |
return True; |
345 |
} |
} |
346 |
|
|
347 |
void |
BOOL |
348 |
ui_create_window_obj(int xpos, int ypos, int width, int height, int valuemask) |
ui_create_window() |
349 |
{ |
{ |
350 |
|
XSetWindowAttributes attribs; |
351 |
XClassHint *classhints; |
XClassHint *classhints; |
352 |
XSizeHints *sizehints; |
XSizeHints *sizehints; |
353 |
XEvent xevent; |
XEvent xevent; |
|
Screen *screen; |
|
|
|
|
|
screen = DefaultScreenOfDisplay(display); |
|
|
|
|
|
wnd = XCreateWindow(display, RootWindowOfScreen(screen), xpos, |
|
|
ypos, width, height, 0, CopyFromParent, |
|
|
InputOutput, CopyFromParent, valuemask, &attribs); |
|
354 |
|
|
355 |
|
attribs.background_pixel = BlackPixelOfScreen(screen); |
356 |
|
attribs.backing_store = ownbackstore ? NotUseful : Always; |
357 |
|
attribs.override_redirect = fullscreen; |
358 |
|
wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, width, height, |
359 |
|
0, CopyFromParent, InputOutput, CopyFromParent, |
360 |
|
CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs); |
361 |
|
|
362 |
XStoreName(display, wnd, title); |
XStoreName(display, wnd, title); |
363 |
|
|
379 |
XFree(sizehints); |
XFree(sizehints); |
380 |
} |
} |
381 |
|
|
382 |
|
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
383 |
|
VisibilityChangeMask | FocusChangeMask; |
384 |
|
|
385 |
|
if (grab_keyboard) |
386 |
|
input_mask |= EnterWindowMask | LeaveWindowMask; |
387 |
|
if (sendmotion) |
388 |
|
input_mask |= PointerMotionMask; |
389 |
|
if (ownbackstore) |
390 |
|
input_mask |= ExposureMask; |
391 |
if (enable_compose) |
if (enable_compose) |
392 |
input_mask |= init_inputmethod(); |
input_mask |= init_inputmethod(); |
393 |
|
|
414 |
FILL_RECTANGLE(0, 0, width, height); |
FILL_RECTANGLE(0, 0, width, height); |
415 |
/* make sure the window is focused */ |
/* make sure the window is focused */ |
416 |
XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); |
XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); |
|
} |
|
|
|
|
|
BOOL |
|
|
ui_create_window() |
|
|
{ |
|
|
XPixmapFormatValues *pfm; |
|
|
Screen *screen; |
|
|
uint16 test; |
|
|
int i; |
|
|
|
|
|
x_socket = ConnectionNumber(display); |
|
|
screen = DefaultScreenOfDisplay(display); |
|
|
visual = DefaultVisualOfScreen(screen); |
|
|
depth = DefaultDepthOfScreen(screen); |
|
|
|
|
|
pfm = XListPixmapFormats(display, &i); |
|
|
if (pfm != NULL) |
|
|
{ |
|
|
/* Use maximum bpp for this depth - this is generally |
|
|
desirable, e.g. 24 bits->32 bits. */ |
|
|
while (i--) |
|
|
{ |
|
|
if ((pfm[i].depth == depth) && (pfm[i].bits_per_pixel > bpp)) |
|
|
{ |
|
|
bpp = pfm[i].bits_per_pixel; |
|
|
} |
|
|
} |
|
|
XFree(pfm); |
|
|
} |
|
|
|
|
|
if (bpp < 8) |
|
|
{ |
|
|
error("Less than 8 bpp not currently supported.\n"); |
|
|
XCloseDisplay(display); |
|
|
return False; |
|
|
} |
|
|
|
|
|
if (depth <= 8) |
|
|
owncolmap = True; |
|
|
else |
|
|
xcolmap = DefaultColormapOfScreen(screen); |
|
|
|
|
|
test = 1; |
|
|
host_be = !(BOOL) (*(uint8 *) (&test)); |
|
|
xserver_be = (ImageByteOrder(display) == MSBFirst); |
|
|
|
|
|
white = WhitePixelOfScreen(screen); |
|
|
attribs.background_pixel = BlackPixelOfScreen(screen); |
|
|
attribs.backing_store = DoesBackingStore(screen); |
|
|
|
|
|
if (attribs.backing_store == NotUseful) |
|
|
ownbackstore = True; |
|
|
|
|
|
dpy_width = WidthOfScreen(screen); |
|
|
dpy_height = HeightOfScreen(screen); |
|
|
|
|
|
if (fullscreen) |
|
|
{ |
|
|
attribs.override_redirect = True; |
|
|
width = dpy_width; |
|
|
height = dpy_height; |
|
|
} |
|
|
else |
|
|
{ |
|
|
attribs.override_redirect = False; |
|
|
} |
|
|
|
|
|
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
|
|
VisibilityChangeMask | FocusChangeMask; |
|
|
|
|
|
if (grab_keyboard) |
|
|
input_mask |= EnterWindowMask | LeaveWindowMask; |
|
|
if (sendmotion) |
|
|
input_mask |= PointerMotionMask; |
|
|
|
|
|
if (ownbackstore) |
|
|
input_mask |= ExposureMask; |
|
|
|
|
|
if (fullscreen) |
|
|
ui_create_window_obj(0, 0, width, height, |
|
|
CWBackingStore | CWBackPixel | CWOverrideRedirect); |
|
|
else |
|
|
ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel); |
|
|
|
|
|
xkeymap_init2(); |
|
417 |
|
|
418 |
return True; |
return True; |
419 |
} |
} |
463 |
XFreePixmap(display, backstore); |
XFreePixmap(display, backstore); |
464 |
XFreeGC(display, gc); |
XFreeGC(display, gc); |
465 |
XDestroyWindow(display, wnd); |
XDestroyWindow(display, wnd); |
466 |
if (fullscreen) |
ui_create_window(); |
|
{ |
|
|
attribs.override_redirect = True; |
|
|
ui_create_window_obj(0, 0, dpy_width, dpy_height, |
|
|
CWBackingStore | CWBackPixel | CWOverrideRedirect); |
|
|
} |
|
|
else |
|
|
{ |
|
|
attribs.override_redirect = False; |
|
|
ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel); |
|
|
} |
|
467 |
ui_set_cursor(cache_get_cursor(0)); |
ui_set_cursor(cache_get_cursor(0)); |
468 |
ui_move_pointer(width / 2, height / 2); |
ui_move_pointer(width / 2, height / 2); |
469 |
reset_keys(); |
reset_keys(); |
474 |
XFreePixmap(display, pixmap); |
XFreePixmap(display, pixmap); |
475 |
} |
} |
476 |
|
|
477 |
|
/* Process all events in Xlib queue */ |
478 |
static void |
static void |
479 |
xwin_process_events() |
xwin_process_events() |
480 |
{ |
{ |
488 |
char str[256]; |
char str[256]; |
489 |
Status status; |
Status status; |
490 |
|
|
|
/* Refresh keyboard mapping if it has changed. This is important for |
|
|
Xvnc, since it allocates keycodes dynamically */ |
|
|
if (XCheckTypedEvent(display, MappingNotify, &xevent)) |
|
|
{ |
|
|
if (xevent.xmapping.request == MappingKeyboard |
|
|
|| xevent.xmapping.request == MappingModifier) |
|
|
XRefreshKeyboardMapping(&xevent.xmapping); |
|
|
} |
|
|
|
|
491 |
while (XCheckMaskEvent(display, ~0, &xevent)) |
while (XCheckMaskEvent(display, ~0, &xevent)) |
492 |
{ |
{ |
493 |
if (enable_compose && (XFilterEvent(&xevent, None) == True)) |
if (enable_compose && (XFilterEvent(&xevent, None) == True)) |
523 |
str, sizeof(str), &keysym, NULL); |
str, sizeof(str), &keysym, NULL); |
524 |
} |
} |
525 |
|
|
|
if (keysym == XK_Break) /* toggle full screen */ |
|
|
{ |
|
|
if (get_key_state(XK_Alt_L) || get_key_state(XK_Alt_R)) |
|
|
{ |
|
|
toggle_fullscreen(); |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
526 |
ksname = get_ksname(keysym); |
ksname = get_ksname(keysym); |
527 |
DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); |
DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname)); |
528 |
|
|
529 |
if (inhibit_key(keysym)) |
if (handle_special_keys(keysym, ev_time, True)) |
|
{ |
|
|
DEBUG_KBD(("Inhibiting key\n")); |
|
530 |
break; |
break; |
|
} |
|
531 |
|
|
532 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
533 |
xevent.xkey.keycode, xevent.xkey.state); |
xevent.xkey.keycode, xevent.xkey.state); |
547 |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, |
548 |
ksname)); |
ksname)); |
549 |
|
|
550 |
if (inhibit_key(keysym)) |
if (handle_special_keys(keysym, ev_time, False)) |
551 |
break; |
break; |
552 |
|
|
553 |
tr = xkeymap_translate_key(keysym, |
tr = xkeymap_translate_key(keysym, |
600 |
xevent.xexpose.height, |
xevent.xexpose.height, |
601 |
xevent.xexpose.x, xevent.xexpose.y); |
xevent.xexpose.x, xevent.xexpose.y); |
602 |
break; |
break; |
603 |
|
|
604 |
|
case MappingNotify: |
605 |
|
/* Refresh keyboard mapping if it has changed. This is important for |
606 |
|
Xvnc, since it allocates keycodes dynamically */ |
607 |
|
if (xevent.xmapping.request == MappingKeyboard |
608 |
|
|| xevent.xmapping.request == MappingModifier) |
609 |
|
XRefreshKeyboardMapping(&xevent.xmapping); |
610 |
|
break; |
611 |
|
|
612 |
} |
} |
613 |
} |
} |
614 |
} |
} |
623 |
|
|
624 |
while (True) |
while (True) |
625 |
{ |
{ |
626 |
|
/* Process any events already waiting */ |
627 |
|
XFlush(display); |
628 |
|
xwin_process_events(); |
629 |
|
|
630 |
FD_ZERO(&rfds); |
FD_ZERO(&rfds); |
631 |
FD_SET(rdp_socket, &rfds); |
FD_SET(rdp_socket, &rfds); |
632 |
if (display != NULL) |
FD_SET(x_socket, &rfds); |
|
{ |
|
|
FD_SET(x_socket, &rfds); |
|
|
XFlush(display); |
|
|
} |
|
633 |
|
|
634 |
switch (select(n, &rfds, NULL, NULL, NULL)) |
switch (select(n, &rfds, NULL, NULL, NULL)) |
635 |
{ |
{ |
640 |
continue; |
continue; |
641 |
} |
} |
642 |
|
|
|
if (FD_ISSET(x_socket, &rfds)) |
|
|
xwin_process_events(); |
|
|
|
|
643 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
644 |
return; |
return; |
645 |
} |
} |
863 |
if (XAllocColor(display, xcolmap, &xentry) != 0) |
if (XAllocColor(display, xcolmap, &xentry) != 0) |
864 |
colour = xentry.pixel; |
colour = xentry.pixel; |
865 |
else |
else |
866 |
colour = white; |
colour = WhitePixelOfScreen(screen); |
867 |
|
|
868 |
/* byte swap here to make translate_image faster */ |
/* byte swap here to make translate_image faster */ |
869 |
map[i] = translate_colour(colour); |
map[i] = translate_colour(colour); |