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 |
31 |
extern BOOL grab_keyboard; |
extern BOOL grab_keyboard; |
32 |
extern char title[]; |
extern char title[]; |
33 |
BOOL enable_compose = False; |
BOOL enable_compose = False; |
34 |
|
BOOL focused; |
35 |
|
BOOL mouse_in_wnd; |
36 |
|
|
37 |
Display *display; |
Display *display; |
38 |
static int x_socket; |
static int x_socket; |
186 |
} |
} |
187 |
|
|
188 |
BOOL |
BOOL |
189 |
get_key_state(uint32 keysym, unsigned int state) |
get_key_state(unsigned int state, uint32 keysym) |
190 |
{ |
{ |
191 |
int modifierpos, key, keysymMask = 0; |
int modifierpos, key, keysymMask = 0; |
192 |
int offset; |
int offset; |
220 |
display = XOpenDisplay(NULL); |
display = XOpenDisplay(NULL); |
221 |
if (display == NULL) |
if (display == NULL) |
222 |
{ |
{ |
223 |
error("Failed to open display\n"); |
error("Failed to open display: %s\n", XDisplayName(NULL)); |
224 |
return False; |
return False; |
225 |
} |
} |
226 |
|
|
347 |
} |
} |
348 |
|
|
349 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
350 |
StructureNotifyMask | FocusChangeMask; |
VisibilityChangeMask | FocusChangeMask; |
351 |
|
|
352 |
if (sendmotion) |
if (sendmotion) |
353 |
input_mask |= PointerMotionMask; |
input_mask |= PointerMotionMask; |
354 |
if (ownbackstore) |
if (ownbackstore) |
355 |
input_mask |= ExposureMask; |
input_mask |= ExposureMask; |
356 |
|
if (fullscreen || grab_keyboard) |
357 |
|
input_mask |= EnterWindowMask; |
358 |
|
if (grab_keyboard) |
359 |
|
input_mask |= LeaveWindowMask; |
360 |
|
|
361 |
if (IM != NULL) |
if (IM != NULL) |
362 |
{ |
{ |
371 |
XSelectInput(display, wnd, input_mask); |
XSelectInput(display, wnd, input_mask); |
372 |
XMapWindow(display, wnd); |
XMapWindow(display, wnd); |
373 |
|
|
374 |
/* wait for MapNotify */ |
/* wait for VisibilityNotify */ |
375 |
do |
do |
376 |
{ |
{ |
377 |
XMaskEvent(display, StructureNotifyMask, &xevent); |
XMaskEvent(display, VisibilityChangeMask, &xevent); |
378 |
} |
} |
379 |
while (xevent.type != MapNotify); |
while (xevent.type != VisibilityNotify); |
380 |
|
|
381 |
if (fullscreen) |
focused = False; |
382 |
XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); |
mouse_in_wnd = False; |
383 |
|
|
384 |
return True; |
return True; |
385 |
} |
} |
469 |
str, sizeof(str), &keysym, NULL); |
str, sizeof(str), &keysym, NULL); |
470 |
} |
} |
471 |
|
|
472 |
DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym))); |
DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, |
473 |
|
get_ksname(keysym))); |
474 |
|
|
475 |
ev_time = time(NULL); |
ev_time = time(NULL); |
476 |
if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True)) |
if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True)) |
526 |
break; |
break; |
527 |
|
|
528 |
case FocusIn: |
case FocusIn: |
529 |
XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state); |
if (xevent.xfocus.mode == NotifyGrab) |
530 |
|
break; |
531 |
|
focused = True; |
532 |
|
XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, |
533 |
|
&dummy, &dummy, &state); |
534 |
reset_modifier_keys(state); |
reset_modifier_keys(state); |
535 |
if (grab_keyboard) |
if (grab_keyboard && mouse_in_wnd) |
536 |
XGrabKeyboard(display, wnd, True, |
XGrabKeyboard(display, wnd, True, |
537 |
GrabModeAsync, GrabModeAsync, CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
538 |
break; |
break; |
539 |
|
|
540 |
case FocusOut: |
case FocusOut: |
541 |
|
if (xevent.xfocus.mode == NotifyUngrab) |
542 |
|
break; |
543 |
|
focused = False; |
544 |
if (xevent.xfocus.mode == NotifyWhileGrabbed) |
if (xevent.xfocus.mode == NotifyWhileGrabbed) |
545 |
XUngrabKeyboard(display, CurrentTime); |
XUngrabKeyboard(display, CurrentTime); |
546 |
break; |
break; |
547 |
|
|
548 |
|
case EnterNotify: |
549 |
|
/* we only register for this event when in fullscreen mode */ |
550 |
|
/* or grab_keyboard */ |
551 |
|
mouse_in_wnd = True; |
552 |
|
if (fullscreen) |
553 |
|
{ |
554 |
|
XSetInputFocus(display, wnd, RevertToPointerRoot, |
555 |
|
CurrentTime); |
556 |
|
break; |
557 |
|
} |
558 |
|
if (focused) |
559 |
|
XGrabKeyboard(display, wnd, True, |
560 |
|
GrabModeAsync, GrabModeAsync, CurrentTime); |
561 |
|
break; |
562 |
|
|
563 |
|
case LeaveNotify: |
564 |
|
/* we only register for this event when grab_keyboard */ |
565 |
|
mouse_in_wnd = False; |
566 |
|
XUngrabKeyboard(display, CurrentTime); |
567 |
|
break; |
568 |
|
|
569 |
case Expose: |
case Expose: |
570 |
XCopyArea(display, backstore, wnd, gc, |
XCopyArea(display, backstore, wnd, gc, |
571 |
xevent.xexpose.x, xevent.xexpose.y, |
xevent.xexpose.x, xevent.xexpose.y, |