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 |
BOOL enable_compose = False; |
BOOL enable_compose = False; |
35 |
|
BOOL focused; |
36 |
|
BOOL mouse_in_wnd; |
37 |
|
|
38 |
Display *display; |
Display *display; |
39 |
static int x_socket; |
static int x_socket; |
56 |
static BOOL ownbackstore; |
static BOOL ownbackstore; |
57 |
static Pixmap backstore; |
static Pixmap backstore; |
58 |
|
|
59 |
|
/* MWM decorations */ |
60 |
|
#define MWM_HINTS_DECORATIONS (1L << 1) |
61 |
|
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 |
62 |
|
typedef struct |
63 |
|
{ |
64 |
|
unsigned long flags; |
65 |
|
unsigned long functions; |
66 |
|
unsigned long decorations; |
67 |
|
long inputMode; |
68 |
|
unsigned long status; |
69 |
|
} |
70 |
|
PropMotifWmHints; |
71 |
|
|
72 |
|
|
73 |
#define FILL_RECTANGLE(x,y,cx,cy)\ |
#define FILL_RECTANGLE(x,y,cx,cy)\ |
74 |
{ \ |
{ \ |
75 |
XFillRectangle(display, wnd, gc, x, y, cx, cy); \ |
XFillRectangle(display, wnd, gc, x, y, cx, cy); \ |
106 |
#define SET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); } |
#define SET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); } |
107 |
#define RESET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); } |
#define RESET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); } |
108 |
|
|
109 |
|
void |
110 |
|
mwm_hide_decorations(void) |
111 |
|
{ |
112 |
|
PropMotifWmHints motif_hints; |
113 |
|
Atom hintsatom; |
114 |
|
|
115 |
|
/* setup the property */ |
116 |
|
motif_hints.flags = MWM_HINTS_DECORATIONS; |
117 |
|
motif_hints.decorations = 0; |
118 |
|
|
119 |
|
/* get the atom for the property */ |
120 |
|
hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False); |
121 |
|
if (!hintsatom) |
122 |
|
{ |
123 |
|
error("Failed to get atom _MOTIF_WM_HINTS\n"); |
124 |
|
return; |
125 |
|
} |
126 |
|
|
127 |
|
XChangeProperty(display, wnd, hintsatom, hintsatom, 32, PropModeReplace, |
128 |
|
(unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); |
129 |
|
} |
130 |
|
|
131 |
static void |
static void |
132 |
translate8(uint8 * data, uint8 * out, uint8 * end) |
translate8(uint8 * data, uint8 * out, uint8 * end) |
133 |
{ |
{ |
223 |
} |
} |
224 |
|
|
225 |
BOOL |
BOOL |
226 |
get_key_state(uint32 keysym, unsigned int state) |
get_key_state(unsigned int state, uint32 keysym) |
227 |
{ |
{ |
228 |
int modifierpos, key, keysymMask = 0; |
int modifierpos, key, keysymMask = 0; |
229 |
int offset; |
int offset; |
257 |
display = XOpenDisplay(NULL); |
display = XOpenDisplay(NULL); |
258 |
if (display == NULL) |
if (display == NULL) |
259 |
{ |
{ |
260 |
error("Failed to open display\n"); |
error("Failed to open display: %s\n", XDisplayName(NULL)); |
261 |
return False; |
return False; |
262 |
} |
} |
263 |
|
|
365 |
|
|
366 |
XStoreName(display, wnd, title); |
XStoreName(display, wnd, title); |
367 |
|
|
368 |
|
if (hide_decorations) |
369 |
|
mwm_hide_decorations(); |
370 |
|
|
371 |
classhints = XAllocClassHint(); |
classhints = XAllocClassHint(); |
372 |
if (classhints != NULL) |
if (classhints != NULL) |
373 |
{ |
{ |
393 |
input_mask |= PointerMotionMask; |
input_mask |= PointerMotionMask; |
394 |
if (ownbackstore) |
if (ownbackstore) |
395 |
input_mask |= ExposureMask; |
input_mask |= ExposureMask; |
396 |
|
if (fullscreen || grab_keyboard) |
397 |
|
input_mask |= EnterWindowMask; |
398 |
|
if (grab_keyboard) |
399 |
|
input_mask |= LeaveWindowMask; |
400 |
|
|
401 |
if (IM != NULL) |
if (IM != NULL) |
402 |
{ |
{ |
418 |
} |
} |
419 |
while (xevent.type != VisibilityNotify); |
while (xevent.type != VisibilityNotify); |
420 |
|
|
421 |
if (fullscreen) |
focused = False; |
422 |
XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); |
mouse_in_wnd = False; |
423 |
|
|
424 |
return True; |
return True; |
425 |
} |
} |
509 |
str, sizeof(str), &keysym, NULL); |
str, sizeof(str), &keysym, NULL); |
510 |
} |
} |
511 |
|
|
512 |
DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym))); |
DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, |
513 |
|
get_ksname(keysym))); |
514 |
|
|
515 |
ev_time = time(NULL); |
ev_time = time(NULL); |
516 |
if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True)) |
if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True)) |
566 |
break; |
break; |
567 |
|
|
568 |
case FocusIn: |
case FocusIn: |
569 |
XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state); |
if (xevent.xfocus.mode == NotifyGrab) |
570 |
|
break; |
571 |
|
focused = True; |
572 |
|
XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, |
573 |
|
&dummy, &dummy, &state); |
574 |
reset_modifier_keys(state); |
reset_modifier_keys(state); |
575 |
if (grab_keyboard) |
if (grab_keyboard && mouse_in_wnd) |
576 |
XGrabKeyboard(display, wnd, True, |
XGrabKeyboard(display, wnd, True, |
577 |
GrabModeAsync, GrabModeAsync, CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
578 |
break; |
break; |
579 |
|
|
580 |
case FocusOut: |
case FocusOut: |
581 |
|
if (xevent.xfocus.mode == NotifyUngrab) |
582 |
|
break; |
583 |
|
focused = False; |
584 |
if (xevent.xfocus.mode == NotifyWhileGrabbed) |
if (xevent.xfocus.mode == NotifyWhileGrabbed) |
585 |
XUngrabKeyboard(display, CurrentTime); |
XUngrabKeyboard(display, CurrentTime); |
586 |
break; |
break; |
587 |
|
|
588 |
|
case EnterNotify: |
589 |
|
/* we only register for this event when in fullscreen mode */ |
590 |
|
/* or grab_keyboard */ |
591 |
|
mouse_in_wnd = True; |
592 |
|
if (fullscreen) |
593 |
|
{ |
594 |
|
XSetInputFocus(display, wnd, RevertToPointerRoot, |
595 |
|
CurrentTime); |
596 |
|
break; |
597 |
|
} |
598 |
|
if (focused) |
599 |
|
XGrabKeyboard(display, wnd, True, |
600 |
|
GrabModeAsync, GrabModeAsync, CurrentTime); |
601 |
|
break; |
602 |
|
|
603 |
|
case LeaveNotify: |
604 |
|
/* we only register for this event when grab_keyboard */ |
605 |
|
mouse_in_wnd = False; |
606 |
|
XUngrabKeyboard(display, CurrentTime); |
607 |
|
break; |
608 |
|
|
609 |
case Expose: |
case Expose: |
610 |
XCopyArea(display, backstore, wnd, gc, |
XCopyArea(display, backstore, wnd, gc, |
611 |
xevent.xexpose.x, xevent.xexpose.y, |
xevent.xexpose.x, xevent.xexpose.y, |