]> Dogcows Code - chaz/openbox/blob - openbox/event.c
Merge branch 'backport' into work
[chaz/openbox] / openbox / event.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 event.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "event.h"
21 #include "debug.h"
22 #include "window.h"
23 #include "openbox.h"
24 #include "dock.h"
25 #include "actions.h"
26 #include "client.h"
27 #include "config.h"
28 #include "screen.h"
29 #include "frame.h"
30 #include "grab.h"
31 #include "menu.h"
32 #include "prompt.h"
33 #include "menuframe.h"
34 #include "keyboard.h"
35 #include "mouse.h"
36 #include "hooks.h"
37 #include "focus.h"
38 #include "focus_cycle.h"
39 #include "moveresize.h"
40 #include "group.h"
41 #include "stacking.h"
42 #include "ping.h"
43 #include "obt/display.h"
44 #include "obt/prop.h"
45 #include "obt/keyboard.h"
46
47 #include <X11/Xlib.h>
48 #include <X11/Xatom.h>
49 #include <glib.h>
50
51 #ifdef HAVE_SYS_SELECT_H
52 # include <sys/select.h>
53 #endif
54 #ifdef HAVE_SIGNAL_H
55 # include <signal.h>
56 #endif
57 #ifdef HAVE_UNISTD_H
58 # include <unistd.h> /* for usleep() */
59 #endif
60 #ifdef XKB
61 # include <X11/XKBlib.h>
62 #endif
63
64 #ifdef USE_SM
65 #include <X11/ICE/ICElib.h>
66 #endif
67
68 typedef struct
69 {
70 gboolean ignored;
71 } ObEventData;
72
73 typedef struct
74 {
75 ObClient *client;
76 Time time;
77 gulong serial;
78 } ObFocusDelayData;
79
80 typedef struct
81 {
82 gulong start; /* inclusive */
83 gulong end; /* inclusive */
84 } ObSerialRange;
85
86 static void event_process(const XEvent *e, gpointer data);
87 static void event_handle_root(XEvent *e);
88 static gboolean event_handle_menu_input(XEvent *e);
89 static void event_handle_menu(ObMenuFrame *frame, XEvent *e);
90 static gboolean event_handle_prompt(ObPrompt *p, XEvent *e);
91 static void event_handle_dock(ObDock *s, XEvent *e);
92 static void event_handle_dockapp(ObDockApp *app, XEvent *e);
93 static void event_handle_client(ObClient *c, XEvent *e);
94 static void event_handle_user_input(ObClient *client, XEvent *e);
95 static gboolean is_enter_focus_event_ignored(gulong serial);
96 static void event_ignore_enter_range(gulong start, gulong end);
97
98 static void focus_delay_dest(gpointer data);
99 static gboolean focus_delay_cmp(gconstpointer d1, gconstpointer d2);
100 static gboolean focus_delay_func(gpointer data);
101 static void focus_delay_client_dest(ObClient *client, gpointer data);
102
103 Time event_curtime = CurrentTime;
104 Time event_last_user_time = CurrentTime;
105 /*! The serial of the current X event */
106
107 static gulong event_curserial;
108 static gboolean focus_left_screen = FALSE;
109 /*! A list of ObSerialRanges which are to be ignored for mouse enter events */
110 static GSList *ignore_serials = NULL;
111
112 #ifdef USE_SM
113 static void ice_handler(gint fd, gpointer conn)
114 {
115 Bool b;
116 IceProcessMessages(conn, NULL, &b);
117 }
118
119 static void ice_watch(IceConn conn, IcePointer data, Bool opening,
120 IcePointer *watch_data)
121 {
122 static gint fd = -1;
123
124 if (opening) {
125 fd = IceConnectionNumber(conn);
126 obt_main_loop_fd_add(ob_main_loop, fd, ice_handler, conn, NULL);
127 } else {
128 obt_main_loop_fd_remove(ob_main_loop, fd);
129 fd = -1;
130 }
131 }
132 #endif
133
134 void event_startup(gboolean reconfig)
135 {
136 if (reconfig) return;
137
138 obt_main_loop_x_add(ob_main_loop, event_process, NULL, NULL);
139
140 #ifdef USE_SM
141 IceAddConnectionWatch(ice_watch, NULL);
142 #endif
143
144 client_add_destroy_notify(focus_delay_client_dest, NULL);
145 }
146
147 void event_shutdown(gboolean reconfig)
148 {
149 if (reconfig) return;
150
151 #ifdef USE_SM
152 IceRemoveConnectionWatch(ice_watch, NULL);
153 #endif
154
155 client_remove_destroy_notify(focus_delay_client_dest);
156 }
157
158 static Window event_get_window(XEvent *e)
159 {
160 Window window;
161
162 /* pick a window */
163 switch (e->type) {
164 case SelectionClear:
165 window = obt_root(ob_screen);
166 break;
167 case CreateNotify:
168 window = e->xcreatewindow.window;
169 break;
170 case MapRequest:
171 window = e->xmaprequest.window;
172 break;
173 case MapNotify:
174 window = e->xmap.window;
175 break;
176 case UnmapNotify:
177 window = e->xunmap.window;
178 break;
179 case DestroyNotify:
180 window = e->xdestroywindow.window;
181 break;
182 case ConfigureRequest:
183 window = e->xconfigurerequest.window;
184 break;
185 case ConfigureNotify:
186 window = e->xconfigure.window;
187 break;
188 default:
189 #ifdef XKB
190 if (obt_display_extension_xkb &&
191 e->type == obt_display_extension_xkb_basep)
192 {
193 switch (((XkbAnyEvent*)e)->xkb_type) {
194 case XkbBellNotify:
195 window = ((XkbBellNotifyEvent*)e)->window;
196 default:
197 window = None;
198 }
199 } else
200 #endif
201 #ifdef SYNC
202 if (obt_display_extension_sync &&
203 e->type == obt_display_extension_sync_basep + XSyncAlarmNotify)
204 {
205 window = None;
206 } else
207 #endif
208 window = e->xany.window;
209 }
210 return window;
211 }
212
213 static void event_set_curtime(XEvent *e)
214 {
215 Time t = CurrentTime;
216
217 /* grab the lasttime and hack up the state */
218 switch (e->type) {
219 case ButtonPress:
220 case ButtonRelease:
221 t = e->xbutton.time;
222 break;
223 case KeyPress:
224 t = e->xkey.time;
225 break;
226 case KeyRelease:
227 t = e->xkey.time;
228 break;
229 case MotionNotify:
230 t = e->xmotion.time;
231 break;
232 case PropertyNotify:
233 t = e->xproperty.time;
234 break;
235 case EnterNotify:
236 case LeaveNotify:
237 t = e->xcrossing.time;
238 break;
239 default:
240 #ifdef SYNC
241 if (obt_display_extension_sync &&
242 e->type == obt_display_extension_sync_basep + XSyncAlarmNotify)
243 {
244 t = ((XSyncAlarmNotifyEvent*)e)->time;
245 }
246 #endif
247 /* if more event types are anticipated, get their timestamp
248 explicitly */
249 break;
250 }
251
252 /* watch that if we get an event earlier than the last specified user_time,
253 which can happen if the clock goes backwards, we erase the last
254 specified user_time */
255 if (t && event_last_user_time && event_time_after(event_last_user_time, t))
256 event_last_user_time = CurrentTime;
257
258 event_curtime = t;
259 }
260
261 static void event_hack_mods(XEvent *e)
262 {
263 #ifdef XKB
264 XkbStateRec xkb_state;
265 #endif
266
267 switch (e->type) {
268 case ButtonPress:
269 case ButtonRelease:
270 e->xbutton.state = obt_keyboard_only_modmasks(e->xbutton.state);
271 break;
272 case KeyPress:
273 e->xkey.state = obt_keyboard_only_modmasks(e->xkey.state);
274 break;
275 case KeyRelease:
276 #ifdef XKB
277 /* If XKB is present, then the modifiers are all strange from its
278 magic. Our X core protocol stuff won't work, so we use this to
279 find what the modifier state is instead. */
280 if (XkbGetState(obt_display, XkbUseCoreKbd, &xkb_state) == Success)
281 e->xkey.state =
282 obt_keyboard_only_modmasks(xkb_state.compat_state);
283 else
284 #endif
285 {
286 e->xkey.state = obt_keyboard_only_modmasks(e->xkey.state);
287 /* remove from the state the mask of the modifier key being
288 released, if it is a modifier key being released that is */
289 e->xkey.state &= ~obt_keyboard_keycode_to_modmask(e->xkey.keycode);
290 }
291 break;
292 case MotionNotify:
293 e->xmotion.state = obt_keyboard_only_modmasks(e->xmotion.state);
294 /* compress events */
295 {
296 XEvent ce;
297 while (XCheckTypedWindowEvent(obt_display, e->xmotion.window,
298 e->type, &ce)) {
299 e->xmotion.x = ce.xmotion.x;
300 e->xmotion.y = ce.xmotion.y;
301 e->xmotion.x_root = ce.xmotion.x_root;
302 e->xmotion.y_root = ce.xmotion.y_root;
303 }
304 }
305 break;
306 }
307 }
308
309 static gboolean wanted_focusevent(XEvent *e, gboolean in_client_only)
310 {
311 gint mode = e->xfocus.mode;
312 gint detail = e->xfocus.detail;
313 Window win = e->xany.window;
314
315 if (e->type == FocusIn) {
316 /* These are ones we never want.. */
317
318 /* This means focus was given by a keyboard/mouse grab. */
319 if (mode == NotifyGrab)
320 return FALSE;
321 /* This means focus was given back from a keyboard/mouse grab. */
322 if (mode == NotifyUngrab)
323 return FALSE;
324
325 /* These are the ones we want.. */
326
327 if (win == obt_root(ob_screen)) {
328 /* If looking for a focus in on a client, then always return
329 FALSE for focus in's to the root window */
330 if (in_client_only)
331 return FALSE;
332 /* This means focus reverted off of a client */
333 else if (detail == NotifyPointerRoot ||
334 detail == NotifyDetailNone ||
335 detail == NotifyInferior ||
336 /* This means focus got here from another screen */
337 detail == NotifyNonlinear)
338 return TRUE;
339 else
340 return FALSE;
341 }
342
343 /* It was on a client, was it a valid one?
344 It's possible to get a FocusIn event for a client that was managed
345 but has disappeared.
346 */
347 if (in_client_only) {
348 ObWindow *w = window_find(e->xfocus.window);
349 if (!w || !WINDOW_IS_CLIENT(w))
350 return FALSE;
351 }
352 else {
353 /* This means focus reverted to parent from the client (this
354 happens often during iconify animation) */
355 if (detail == NotifyInferior)
356 return TRUE;
357 }
358
359 /* This means focus moved from the root window to a client */
360 if (detail == NotifyVirtual)
361 return TRUE;
362 /* This means focus moved from one client to another */
363 if (detail == NotifyNonlinearVirtual)
364 return TRUE;
365
366 /* Otherwise.. */
367 return FALSE;
368 } else {
369 g_assert(e->type == FocusOut);
370
371 /* These are ones we never want.. */
372
373 /* This means focus was taken by a keyboard/mouse grab. */
374 if (mode == NotifyGrab)
375 return FALSE;
376 /* This means focus was grabbed on a window and it was released. */
377 if (mode == NotifyUngrab)
378 return FALSE;
379
380 /* Focus left the root window revertedto state */
381 if (win == obt_root(ob_screen))
382 return FALSE;
383
384 /* These are the ones we want.. */
385
386 /* This means focus moved from a client to the root window */
387 if (detail == NotifyVirtual)
388 return TRUE;
389 /* This means focus moved from one client to another */
390 if (detail == NotifyNonlinearVirtual)
391 return TRUE;
392
393 /* Otherwise.. */
394 return FALSE;
395 }
396 }
397
398 static Bool event_look_for_focusin(Display *d, XEvent *e, XPointer arg)
399 {
400 return e->type == FocusIn && wanted_focusevent(e, FALSE);
401 }
402
403 static Bool event_look_for_focusin_client(Display *d, XEvent *e, XPointer arg)
404 {
405 return e->type == FocusIn && wanted_focusevent(e, TRUE);
406 }
407
408 static void print_focusevent(XEvent *e)
409 {
410 gint mode = e->xfocus.mode;
411 gint detail = e->xfocus.detail;
412 Window win = e->xany.window;
413 const gchar *modestr, *detailstr;
414
415 switch (mode) {
416 case NotifyNormal: modestr="NotifyNormal"; break;
417 case NotifyGrab: modestr="NotifyGrab"; break;
418 case NotifyUngrab: modestr="NotifyUngrab"; break;
419 case NotifyWhileGrabbed: modestr="NotifyWhileGrabbed"; break;
420 }
421 switch (detail) {
422 case NotifyAncestor: detailstr="NotifyAncestor"; break;
423 case NotifyVirtual: detailstr="NotifyVirtual"; break;
424 case NotifyInferior: detailstr="NotifyInferior"; break;
425 case NotifyNonlinear: detailstr="NotifyNonlinear"; break;
426 case NotifyNonlinearVirtual: detailstr="NotifyNonlinearVirtual"; break;
427 case NotifyPointer: detailstr="NotifyPointer"; break;
428 case NotifyPointerRoot: detailstr="NotifyPointerRoot"; break;
429 case NotifyDetailNone: detailstr="NotifyDetailNone"; break;
430 }
431
432 if (mode == NotifyGrab || mode == NotifyUngrab)
433 return;
434
435 g_assert(modestr);
436 g_assert(detailstr);
437 ob_debug_type(OB_DEBUG_FOCUS, "Focus%s 0x%x mode=%s detail=%s",
438 (e->xfocus.type == FocusIn ? "In" : "Out"),
439 win,
440 modestr, detailstr);
441
442 }
443
444 static gboolean event_ignore(XEvent *e, ObClient *client)
445 {
446 switch(e->type) {
447 case FocusIn:
448 print_focusevent(e);
449 if (!wanted_focusevent(e, FALSE))
450 return TRUE;
451 break;
452 case FocusOut:
453 print_focusevent(e);
454 if (!wanted_focusevent(e, FALSE))
455 return TRUE;
456 break;
457 }
458 return FALSE;
459 }
460
461 static void event_process(const XEvent *ec, gpointer data)
462 {
463 XEvent ee, *e;
464 ObEventData *ed = data;
465
466 Window window;
467 ObClient *client = NULL;
468 ObDock *dock = NULL;
469 ObDockApp *dockapp = NULL;
470 ObWindow *obwin = NULL;
471 ObMenuFrame *menu = NULL;
472 ObPrompt *prompt = NULL;
473
474 /* make a copy we can mangle */
475 ee = *ec;
476 e = &ee;
477
478 window = event_get_window(e);
479 if (window == obt_root(ob_screen))
480 /* don't do any lookups, waste of cpu */;
481 else if ((obwin = window_find(window))) {
482 switch (obwin->type) {
483 case OB_WINDOW_CLASS_DOCK:
484 dock = WINDOW_AS_DOCK(obwin);
485 break;
486 case OB_WINDOW_CLASS_CLIENT:
487 client = WINDOW_AS_CLIENT(obwin);
488 /* events on clients can be events on prompt windows too */
489 prompt = client->prompt;
490 break;
491 case OB_WINDOW_CLASS_MENUFRAME:
492 menu = WINDOW_AS_MENUFRAME(obwin);
493 break;
494 case OB_WINDOW_CLASS_INTERNAL:
495 /* we don't do anything with events directly on these windows */
496 break;
497 case OB_WINDOW_CLASS_PROMPT:
498 prompt = WINDOW_AS_PROMPT(obwin);
499 break;
500 }
501 }
502 else
503 dockapp = dock_find_dockapp(window);
504
505 event_set_curtime(e);
506 event_curserial = e->xany.serial;
507 event_hack_mods(e);
508 if (event_ignore(e, client)) {
509 if (ed)
510 ed->ignored = TRUE;
511 return;
512 } else if (ed)
513 ed->ignored = FALSE;
514
515 /* deal with it in the kernel */
516
517 if (e->type == FocusIn) {
518 if (client &&
519 e->xfocus.detail == NotifyInferior)
520 {
521 ob_debug_type(OB_DEBUG_FOCUS,
522 "Focus went to the frame window");
523
524 focus_left_screen = FALSE;
525
526 focus_fallback(FALSE, config_focus_under_mouse, TRUE, TRUE);
527
528 /* We don't get a FocusOut for this case, because it's just moving
529 from our Inferior up to us. This happens when iconifying a
530 window with RevertToParent focus */
531 frame_adjust_focus(client->frame, FALSE);
532 /* focus_set_client(NULL) has already been called */
533 }
534 else if (e->xfocus.detail == NotifyPointerRoot ||
535 e->xfocus.detail == NotifyDetailNone ||
536 e->xfocus.detail == NotifyInferior ||
537 e->xfocus.detail == NotifyNonlinear)
538 {
539 XEvent ce;
540
541 ob_debug_type(OB_DEBUG_FOCUS,
542 "Focus went to root or pointer root/none");
543
544 if (e->xfocus.detail == NotifyInferior ||
545 e->xfocus.detail == NotifyNonlinear)
546 {
547 focus_left_screen = FALSE;
548 }
549
550 /* If another FocusIn is in the queue then don't fallback yet. This
551 fixes the fun case of:
552 window map -> send focusin
553 window unmap -> get focusout
554 window map -> send focusin
555 get first focus out -> fall back to something (new window
556 hasn't received focus yet, so something else) -> send focusin
557 which means the "something else" is the last thing to get a
558 focusin sent to it, so the new window doesn't end up with focus.
559
560 But if the other focus in is something like PointerRoot then we
561 still want to fall back.
562 */
563 if (XCheckIfEvent(obt_display, &ce, event_look_for_focusin_client,
564 NULL))
565 {
566 XPutBackEvent(obt_display, &ce);
567 ob_debug_type(OB_DEBUG_FOCUS,
568 " but another FocusIn is coming");
569 } else {
570 /* Focus has been reverted.
571
572 FocusOut events come after UnmapNotify, so we don't need to
573 worry about focusing an invalid window
574 */
575
576 if (!focus_left_screen)
577 focus_fallback(FALSE, config_focus_under_mouse,
578 TRUE, TRUE);
579 }
580 }
581 else if (!client)
582 {
583 ob_debug_type(OB_DEBUG_FOCUS,
584 "Focus went to a window that is already gone");
585
586 /* If you send focus to a window and then it disappears, you can
587 get the FocusIn for it, after it is unmanaged.
588 Just wait for the next FocusOut/FocusIn pair, but make note that
589 the window that was focused no longer is. */
590 focus_set_client(NULL);
591 }
592 else if (client != focus_client) {
593 focus_left_screen = FALSE;
594 frame_adjust_focus(client->frame, TRUE);
595 focus_set_client(client);
596 client_calc_layer(client);
597 client_bring_helper_windows(client);
598 }
599 } else if (e->type == FocusOut) {
600 XEvent ce;
601
602 /* Look for the followup FocusIn */
603 if (!XCheckIfEvent(obt_display, &ce, event_look_for_focusin, NULL)) {
604 /* There is no FocusIn, this means focus went to a window that
605 is not being managed, or a window on another screen. */
606 Window win, root;
607 gint i;
608 guint u;
609 obt_display_ignore_errors(TRUE);
610 if (XGetInputFocus(obt_display, &win, &i) &&
611 XGetGeometry(obt_display, win, &root, &i,&i,&u,&u,&u,&u) &&
612 root != obt_root(ob_screen))
613 {
614 ob_debug_type(OB_DEBUG_FOCUS,
615 "Focus went to another screen !");
616 focus_left_screen = TRUE;
617 }
618 else
619 ob_debug_type(OB_DEBUG_FOCUS,
620 "Focus went to a black hole !");
621 obt_display_ignore_errors(FALSE);
622 /* nothing is focused */
623 focus_set_client(NULL);
624 } else {
625 /* Focus moved, so process the FocusIn event */
626 ObEventData ed = { .ignored = FALSE };
627 event_process(&ce, &ed);
628 if (ed.ignored) {
629 /* The FocusIn was ignored, this means it was on a window
630 that isn't a client. */
631 ob_debug_type(OB_DEBUG_FOCUS,
632 "Focus went to an unmanaged window 0x%x !",
633 ce.xfocus.window);
634 focus_fallback(TRUE, config_focus_under_mouse, TRUE, TRUE);
635 }
636 }
637
638 if (client && client != focus_client) {
639 frame_adjust_focus(client->frame, FALSE);
640 /* focus_set_client(NULL) has already been called in this
641 section or by focus_fallback */
642 }
643 }
644 else if (client)
645 event_handle_client(client, e);
646 else if (dockapp)
647 event_handle_dockapp(dockapp, e);
648 else if (dock)
649 event_handle_dock(dock, e);
650 else if (menu)
651 event_handle_menu(menu, e);
652 else if (window == obt_root(ob_screen))
653 event_handle_root(e);
654 else if (e->type == MapRequest)
655 window_manage(window);
656 else if (e->type == MappingNotify) {
657 /* keyboard layout changes for modifier mapping changes. reload the
658 modifier map, and rebind all the key bindings as appropriate */
659 ob_debug("Keyboard map changed. Reloading keyboard bindings.");
660 ob_set_state(OB_STATE_RECONFIGURING);
661 obt_keyboard_reload();
662 keyboard_rebind();
663 ob_set_state(OB_STATE_RUNNING);
664 }
665 else if (e->type == ClientMessage) {
666 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
667 windows that are not managed yet. */
668 if (e->xclient.message_type ==
669 OBT_PROP_ATOM(NET_REQUEST_FRAME_EXTENTS))
670 {
671 /* Pretend to manage the client, getting information used to
672 determine its decorations */
673 ObClient *c = client_fake_manage(e->xclient.window);
674 gulong vals[4];
675
676 /* set the frame extents on the window */
677 vals[0] = c->frame->size.left;
678 vals[1] = c->frame->size.right;
679 vals[2] = c->frame->size.top;
680 vals[3] = c->frame->size.bottom;
681 OBT_PROP_SETA32(e->xclient.window, NET_FRAME_EXTENTS,
682 CARDINAL, vals, 4);
683
684 /* Free the pretend client */
685 client_fake_unmanage(c);
686 }
687 }
688 else if (e->type == ConfigureRequest) {
689 /* unhandled configure requests must be used to configure the
690 window directly */
691 XWindowChanges xwc;
692
693 xwc.x = e->xconfigurerequest.x;
694 xwc.y = e->xconfigurerequest.y;
695 xwc.width = e->xconfigurerequest.width;
696 xwc.height = e->xconfigurerequest.height;
697 xwc.border_width = e->xconfigurerequest.border_width;
698 xwc.sibling = e->xconfigurerequest.above;
699 xwc.stack_mode = e->xconfigurerequest.detail;
700
701 /* we are not to be held responsible if someone sends us an
702 invalid request! */
703 obt_display_ignore_errors(TRUE);
704 XConfigureWindow(obt_display, window,
705 e->xconfigurerequest.value_mask, &xwc);
706 obt_display_ignore_errors(FALSE);
707 }
708 #ifdef SYNC
709 else if (obt_display_extension_sync &&
710 e->type == obt_display_extension_sync_basep + XSyncAlarmNotify)
711 {
712 XSyncAlarmNotifyEvent *se = (XSyncAlarmNotifyEvent*)e;
713 if (se->alarm == moveresize_alarm && moveresize_in_progress)
714 moveresize_event(e);
715 }
716 #endif
717
718 if (prompt && event_handle_prompt(prompt, e))
719 ;
720 else if (e->type == ButtonPress || e->type == ButtonRelease) {
721 /* If the button press was on some non-root window, or was physically
722 on the root window, then process it */
723 if (window != obt_root(ob_screen) ||
724 e->xbutton.subwindow == None)
725 {
726 event_handle_user_input(client, e);
727 }
728 /* Otherwise only process it if it was physically on an openbox
729 internal window */
730 else {
731 ObWindow *w;
732
733 if ((w = window_find(e->xbutton.subwindow)) &&
734 WINDOW_IS_INTERNAL(w))
735 {
736 event_handle_user_input(client, e);
737 }
738 }
739 }
740 else if (e->type == KeyPress || e->type == KeyRelease ||
741 e->type == MotionNotify)
742 event_handle_user_input(client, e);
743
744 XFlush(obt_display);
745
746 /* run all the hooks at once */
747 hooks_run_queue();
748
749 /* if something happens and it's not from an XEvent, then we don't know
750 the time */
751 event_curtime = CurrentTime;
752 event_curserial = 0;
753 }
754
755 static void event_handle_root(XEvent *e)
756 {
757 Atom msgtype;
758
759 switch(e->type) {
760 case SelectionClear:
761 ob_debug("Another WM has requested to replace us. Exiting.");
762 ob_exit_replace();
763 break;
764
765 case ClientMessage:
766 if (e->xclient.format != 32) break;
767
768 msgtype = e->xclient.message_type;
769 if (msgtype == OBT_PROP_ATOM(NET_CURRENT_DESKTOP)) {
770 guint d = e->xclient.data.l[0];
771 if (d < screen_num_desktops) {
772 event_curtime = e->xclient.data.l[1];
773 if (event_curtime == 0)
774 ob_debug_type(OB_DEBUG_APP_BUGS,
775 "_NET_CURRENT_DESKTOP message is missing "
776 "a timestamp");
777 screen_set_desktop(d, TRUE);
778 }
779 } else if (msgtype == OBT_PROP_ATOM(NET_NUMBER_OF_DESKTOPS)) {
780 guint d = e->xclient.data.l[0];
781 if (d > 0 && d <= 1000)
782 screen_set_num_desktops(d);
783 } else if (msgtype == OBT_PROP_ATOM(NET_SHOWING_DESKTOP)) {
784 screen_show_desktop(e->xclient.data.l[0] != 0, NULL);
785 } else if (msgtype == OBT_PROP_ATOM(OB_CONTROL)) {
786 ob_debug("OB_CONTROL: %d", e->xclient.data.l[0]);
787 if (e->xclient.data.l[0] == 1)
788 ob_reconfigure();
789 else if (e->xclient.data.l[0] == 2)
790 ob_restart();
791 else if (e->xclient.data.l[0] == 3)
792 ob_exit(0);
793 } else if (msgtype == OBT_PROP_ATOM(WM_PROTOCOLS)) {
794 if ((Atom)e->xclient.data.l[0] == OBT_PROP_ATOM(NET_WM_PING))
795 ping_got_pong(e->xclient.data.l[1]);
796 }
797 break;
798 case PropertyNotify:
799 if (e->xproperty.atom == OBT_PROP_ATOM(NET_DESKTOP_NAMES)) {
800 ob_debug("UPDATE DESKTOP NAMES");
801 screen_update_desktop_names();
802 }
803 else if (e->xproperty.atom == OBT_PROP_ATOM(NET_DESKTOP_LAYOUT))
804 screen_update_layout();
805 break;
806 case ConfigureNotify:
807 #ifdef XRANDR
808 XRRUpdateConfiguration(e);
809 #endif
810 screen_resize();
811 break;
812 default:
813 ;
814 }
815 }
816
817 void event_enter_client(ObClient *client)
818 {
819 g_assert(config_focus_follow);
820
821 if (is_enter_focus_event_ignored(event_curserial)) {
822 ob_debug_type(OB_DEBUG_FOCUS, "Ignoring enter event with serial %lu\n"
823 "on client 0x%x", event_curserial, client->window);
824 return;
825 }
826
827 if (client_enter_focusable(client) && client_can_focus(client)) {
828 if (config_focus_delay) {
829 ObFocusDelayData *data;
830
831 obt_main_loop_timeout_remove(ob_main_loop, focus_delay_func);
832
833 data = g_new(ObFocusDelayData, 1);
834 data->client = client;
835 data->time = event_curtime;
836 data->serial = event_curserial;
837
838 obt_main_loop_timeout_add(ob_main_loop,
839 config_focus_delay * 1000,
840 focus_delay_func,
841 data, focus_delay_cmp, focus_delay_dest);
842 } else {
843 ObFocusDelayData data;
844 data.client = client;
845 data.time = event_curtime;
846 data.serial = event_curserial;
847 focus_delay_func(&data);
848 }
849 }
850 }
851
852 static gboolean *context_to_button(ObFrame *f, ObFrameContext con, gboolean press)
853 {
854 if (press) {
855 switch (con) {
856 case OB_FRAME_CONTEXT_MAXIMIZE:
857 return &f->max_press;
858 case OB_FRAME_CONTEXT_CLOSE:
859 return &f->close_press;
860 case OB_FRAME_CONTEXT_ICONIFY:
861 return &f->iconify_press;
862 case OB_FRAME_CONTEXT_ALLDESKTOPS:
863 return &f->desk_press;
864 case OB_FRAME_CONTEXT_SHADE:
865 return &f->shade_press;
866 default:
867 return NULL;
868 }
869 } else {
870 switch (con) {
871 case OB_FRAME_CONTEXT_MAXIMIZE:
872 return &f->max_hover;
873 case OB_FRAME_CONTEXT_CLOSE:
874 return &f->close_hover;
875 case OB_FRAME_CONTEXT_ICONIFY:
876 return &f->iconify_hover;
877 case OB_FRAME_CONTEXT_ALLDESKTOPS:
878 return &f->desk_hover;
879 case OB_FRAME_CONTEXT_SHADE:
880 return &f->shade_hover;
881 default:
882 return NULL;
883 }
884 }
885 }
886
887 static void compress_client_message_event(XEvent *e, XEvent *ce, Window window,
888 Atom msgtype)
889 {
890 /* compress changes into a single change */
891 while (XCheckTypedWindowEvent(obt_display, window, e->type, ce)) {
892 /* XXX: it would be nice to compress ALL messages of a
893 type, not just messages in a row without other
894 message types between. */
895 if (ce->xclient.message_type != msgtype) {
896 XPutBackEvent(obt_display, ce);
897 break;
898 }
899 e->xclient = ce->xclient;
900 }
901 }
902
903 static void event_handle_client(ObClient *client, XEvent *e)
904 {
905 XEvent ce;
906 Atom msgtype;
907 ObFrameContext con;
908 gboolean *but;
909 static gint px = -1, py = -1;
910 static guint pb = 0;
911 static ObFrameContext pcon = OB_FRAME_CONTEXT_NONE;
912
913 switch (e->type) {
914 case ButtonPress:
915 /* save where the press occured for the first button pressed */
916 if (!pb) {
917 pb = e->xbutton.button;
918 px = e->xbutton.x;
919 py = e->xbutton.y;
920
921 pcon = frame_context(client, e->xbutton.window, px, py);
922 pcon = mouse_button_frame_context(pcon, e->xbutton.button,
923 e->xbutton.state);
924 }
925 case ButtonRelease:
926 /* Wheel buttons don't draw because they are an instant click, so it
927 is a waste of resources to go drawing it.
928 if the user is doing an interactive thing, or has a menu open then
929 the mouse is grabbed (possibly) and if we get these events we don't
930 want to deal with them
931 */
932 if (!(e->xbutton.button == 4 || e->xbutton.button == 5) &&
933 !grab_on_keyboard())
934 {
935 /* use where the press occured */
936 con = frame_context(client, e->xbutton.window, px, py);
937 con = mouse_button_frame_context(con, e->xbutton.button,
938 e->xbutton.state);
939
940 /* button presses on CLIENT_CONTEXTs are not accompanied by a
941 release because they are Replayed to the client */
942 if ((e->type == ButtonRelease || CLIENT_CONTEXT(con, client)) &&
943 e->xbutton.button == pb)
944 pb = 0, px = py = -1, pcon = OB_FRAME_CONTEXT_NONE;
945
946 but = context_to_button(client->frame, con, TRUE);
947 if (but) {
948 *but = (e->type == ButtonPress);
949 frame_adjust_state(client->frame);
950 }
951 }
952 break;
953 case MotionNotify:
954 /* when there is a grab on the pointer, we won't get enter/leave
955 notifies, but we still get motion events */
956 if (grab_on_pointer()) break;
957
958 con = frame_context(client, e->xmotion.window,
959 e->xmotion.x, e->xmotion.y);
960 switch (con) {
961 case OB_FRAME_CONTEXT_TITLEBAR:
962 case OB_FRAME_CONTEXT_TLCORNER:
963 case OB_FRAME_CONTEXT_TRCORNER:
964 /* we've left the button area inside the titlebar */
965 if (client->frame->max_hover || client->frame->desk_hover ||
966 client->frame->shade_hover || client->frame->iconify_hover ||
967 client->frame->close_hover)
968 {
969 client->frame->max_hover =
970 client->frame->desk_hover =
971 client->frame->shade_hover =
972 client->frame->iconify_hover =
973 client->frame->close_hover = FALSE;
974 frame_adjust_state(client->frame);
975 }
976 break;
977 default:
978 but = context_to_button(client->frame, con, FALSE);
979 if (but && !*but && !pb) {
980 *but = TRUE;
981 frame_adjust_state(client->frame);
982 }
983 break;
984 }
985 break;
986 case LeaveNotify:
987 con = frame_context(client, e->xcrossing.window,
988 e->xcrossing.x, e->xcrossing.y);
989 switch (con) {
990 case OB_FRAME_CONTEXT_TITLEBAR:
991 case OB_FRAME_CONTEXT_TLCORNER:
992 case OB_FRAME_CONTEXT_TRCORNER:
993 /* we've left the button area inside the titlebar */
994 client->frame->max_hover =
995 client->frame->desk_hover =
996 client->frame->shade_hover =
997 client->frame->iconify_hover =
998 client->frame->close_hover = FALSE;
999 if (e->xcrossing.mode == NotifyGrab) {
1000 client->frame->max_press =
1001 client->frame->desk_press =
1002 client->frame->shade_press =
1003 client->frame->iconify_press =
1004 client->frame->close_press = FALSE;
1005 }
1006 break;
1007 case OB_FRAME_CONTEXT_FRAME:
1008 /* When the mouse leaves an animating window, don't use the
1009 corresponding enter events. Pretend like the animating window
1010 doesn't even exist..! */
1011 if (frame_iconify_animating(client->frame))
1012 event_end_ignore_all_enters(event_start_ignore_all_enters());
1013
1014 ob_debug_type(OB_DEBUG_FOCUS,
1015 "%sNotify mode %d detail %d on %lx",
1016 (e->type == EnterNotify ? "Enter" : "Leave"),
1017 e->xcrossing.mode,
1018 e->xcrossing.detail, (client?client->window:0));
1019 if (grab_on_keyboard())
1020 break;
1021 if (config_focus_follow && config_focus_delay &&
1022 /* leave inferior events can happen when the mouse goes onto
1023 the window's border and then into the window before the
1024 delay is up */
1025 e->xcrossing.detail != NotifyInferior)
1026 {
1027 obt_main_loop_timeout_remove_data(ob_main_loop,
1028 focus_delay_func,
1029 client, FALSE);
1030 }
1031 break;
1032 default:
1033 but = context_to_button(client->frame, con, FALSE);
1034 if (but) {
1035 *but = FALSE;
1036 if (e->xcrossing.mode == NotifyGrab) {
1037 but = context_to_button(client->frame, con, TRUE);
1038 *but = FALSE;
1039 }
1040 frame_adjust_state(client->frame);
1041 }
1042 break;
1043 }
1044 break;
1045 case EnterNotify:
1046 {
1047 con = frame_context(client, e->xcrossing.window,
1048 e->xcrossing.x, e->xcrossing.y);
1049 switch (con) {
1050 case OB_FRAME_CONTEXT_FRAME:
1051 if (grab_on_keyboard())
1052 break;
1053 if (e->xcrossing.mode == NotifyGrab ||
1054 e->xcrossing.mode == NotifyUngrab ||
1055 /*ignore enters when we're already in the window */
1056 e->xcrossing.detail == NotifyInferior)
1057 {
1058 ob_debug_type(OB_DEBUG_FOCUS,
1059 "%sNotify mode %d detail %d serial %lu on %lx "
1060 "IGNORED",
1061 (e->type == EnterNotify ? "Enter" : "Leave"),
1062 e->xcrossing.mode,
1063 e->xcrossing.detail,
1064 e->xcrossing.serial,
1065 client?client->window:0);
1066 }
1067 else {
1068 ob_debug_type(OB_DEBUG_FOCUS,
1069 "%sNotify mode %d detail %d serial %lu on %lx, "
1070 "focusing window",
1071 (e->type == EnterNotify ? "Enter" : "Leave"),
1072 e->xcrossing.mode,
1073 e->xcrossing.detail,
1074 e->xcrossing.serial,
1075 (client?client->window:0));
1076 if (config_focus_follow)
1077 event_enter_client(client);
1078 }
1079 break;
1080 default:
1081 but = context_to_button(client->frame, con, FALSE);
1082 if (but) {
1083 *but = TRUE;
1084 if (e->xcrossing.mode == NotifyUngrab) {
1085 but = context_to_button(client->frame, con, TRUE);
1086 *but = (con == pcon);
1087 }
1088 frame_adjust_state(client->frame);
1089 }
1090 break;
1091 }
1092 break;
1093 }
1094 case ConfigureRequest:
1095 {
1096 /* dont compress these unless you're going to watch for property
1097 notifies in between (these can change what the configure would
1098 do to the window).
1099 also you can't compress stacking events
1100 */
1101
1102 gint x, y, w, h;
1103 gboolean move = FALSE;
1104 gboolean resize = FALSE;
1105
1106 /* get the current area */
1107 RECT_TO_DIMS(client->area, x, y, w, h);
1108
1109 ob_debug("ConfigureRequest for \"%s\" desktop %d wmstate %d "
1110 "visible %d",
1111 client->title,
1112 screen_desktop, client->wmstate, client->frame->visible);
1113 ob_debug(" x %d y %d w %d h %d b %d",
1114 x, y, w, h, client->border_width);
1115
1116 if (e->xconfigurerequest.value_mask & CWBorderWidth)
1117 if (client->border_width != e->xconfigurerequest.border_width) {
1118 client->border_width = e->xconfigurerequest.border_width;
1119
1120 /* if the border width is changing then that is the same
1121 as requesting a resize, but we don't actually change
1122 the client's border, so it will change their root
1123 coordinates (since they include the border width) and
1124 we need to a notify then */
1125 move = TRUE;
1126 }
1127
1128 if (e->xconfigurerequest.value_mask & CWStackMode) {
1129 ObClient *sibling = NULL;
1130 gulong ignore_start;
1131 gboolean ok = TRUE;
1132
1133 /* get the sibling */
1134 if (e->xconfigurerequest.value_mask & CWSibling) {
1135 ObWindow *win;
1136 win = window_find(e->xconfigurerequest.above);
1137 if (win && WINDOW_IS_CLIENT(win) &&
1138 WINDOW_AS_CLIENT(win) != client)
1139 {
1140 sibling = WINDOW_AS_CLIENT(win);
1141 }
1142 else
1143 /* an invalid sibling was specified so don't restack at
1144 all, it won't make sense no matter what we do */
1145 ok = FALSE;
1146 }
1147
1148 if (ok) {
1149 if (!config_focus_under_mouse)
1150 ignore_start = event_start_ignore_all_enters();
1151 stacking_restack_request(client, sibling,
1152 e->xconfigurerequest.detail);
1153 if (!config_focus_under_mouse)
1154 event_end_ignore_all_enters(ignore_start);
1155 }
1156
1157 /* a stacking change moves the window without resizing */
1158 move = TRUE;
1159 }
1160
1161 if ((e->xconfigurerequest.value_mask & CWX) ||
1162 (e->xconfigurerequest.value_mask & CWY) ||
1163 (e->xconfigurerequest.value_mask & CWWidth) ||
1164 (e->xconfigurerequest.value_mask & CWHeight))
1165 {
1166 /* don't allow clients to move shaded windows (fvwm does this)
1167 */
1168 if (e->xconfigurerequest.value_mask & CWX) {
1169 if (!client->shaded)
1170 x = e->xconfigurerequest.x;
1171 move = TRUE;
1172 }
1173 if (e->xconfigurerequest.value_mask & CWY) {
1174 if (!client->shaded)
1175 y = e->xconfigurerequest.y;
1176 move = TRUE;
1177 }
1178
1179 if (e->xconfigurerequest.value_mask & CWWidth) {
1180 w = e->xconfigurerequest.width;
1181 resize = TRUE;
1182 }
1183 if (e->xconfigurerequest.value_mask & CWHeight) {
1184 h = e->xconfigurerequest.height;
1185 resize = TRUE;
1186 }
1187 }
1188
1189 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
1190 "move %d resize %d",
1191 e->xconfigurerequest.value_mask & CWX, x,
1192 e->xconfigurerequest.value_mask & CWY, y,
1193 e->xconfigurerequest.value_mask & CWWidth, w,
1194 e->xconfigurerequest.value_mask & CWHeight, h,
1195 move, resize);
1196
1197 /* check for broken apps moving to their root position
1198
1199 XXX remove this some day...that would be nice. right now all
1200 kde apps do this when they try activate themselves on another
1201 desktop. eg. open amarok window on desktop 1, switch to desktop
1202 2, click amarok tray icon. it will move by its decoration size.
1203 */
1204 if (x != client->area.x &&
1205 x == (client->frame->area.x + client->frame->size.left -
1206 (gint)client->border_width) &&
1207 y != client->area.y &&
1208 y == (client->frame->area.y + client->frame->size.top -
1209 (gint)client->border_width) &&
1210 w == client->area.width &&
1211 h == client->area.height)
1212 {
1213 ob_debug_type(OB_DEBUG_APP_BUGS,
1214 "Application %s is trying to move via "
1215 "ConfigureRequest to it's root window position "
1216 "but it is not using StaticGravity",
1217 client->title);
1218 /* don't move it */
1219 x = client->area.x;
1220 y = client->area.y;
1221
1222 /* they still requested a move, so don't change whether a
1223 notify is sent or not */
1224 }
1225
1226 {
1227 gint lw, lh;
1228
1229 client_try_configure(client, &x, &y, &w, &h, &lw, &lh, FALSE);
1230
1231 /* if x was not given, then use gravity to figure out the new
1232 x. the reference point should not be moved */
1233 if ((e->xconfigurerequest.value_mask & CWWidth &&
1234 !(e->xconfigurerequest.value_mask & CWX)))
1235 client_gravity_resize_w(client, &x, client->area.width, w);
1236 /* same for y */
1237 if ((e->xconfigurerequest.value_mask & CWHeight &&
1238 !(e->xconfigurerequest.value_mask & CWY)))
1239 client_gravity_resize_h(client, &y, client->area.height,h);
1240
1241 client_find_onscreen(client, &x, &y, w, h, FALSE);
1242
1243 ob_debug("Granting ConfigureRequest x %d y %d w %d h %d",
1244 x, y, w, h);
1245 client_configure(client, x, y, w, h, FALSE, TRUE, TRUE);
1246 }
1247 break;
1248 }
1249 case UnmapNotify:
1250 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1251 "ignores left %d",
1252 client->window, e->xunmap.event, e->xunmap.from_configure,
1253 client->ignore_unmaps);
1254 if (client->ignore_unmaps) {
1255 client->ignore_unmaps--;
1256 break;
1257 }
1258 client_unmanage(client);
1259 break;
1260 case DestroyNotify:
1261 ob_debug("DestroyNotify for window 0x%x", client->window);
1262 client_unmanage(client);
1263 break;
1264 case ReparentNotify:
1265 /* this is when the client is first taken captive in the frame */
1266 if (e->xreparent.parent == client->frame->window) break;
1267
1268 /*
1269 This event is quite rare and is usually handled in unmapHandler.
1270 However, if the window is unmapped when the reparent event occurs,
1271 the window manager never sees it because an unmap event is not sent
1272 to an already unmapped window.
1273 */
1274
1275 /* we don't want the reparent event, put it back on the stack for the
1276 X server to deal with after we unmanage the window */
1277 XPutBackEvent(obt_display, e);
1278
1279 ob_debug("ReparentNotify for window 0x%x", client->window);
1280 client_unmanage(client);
1281 break;
1282 case MapRequest:
1283 ob_debug("MapRequest for 0x%lx", client->window);
1284 if (!client->iconic) break; /* this normally doesn't happen, but if it
1285 does, we don't want it!
1286 it can happen now when the window is on
1287 another desktop, but we still don't
1288 want it! */
1289 client_activate(client, FALSE, TRUE, TRUE, TRUE);
1290 break;
1291 case ClientMessage:
1292 /* validate cuz we query stuff off the client here */
1293 if (!client_validate(client)) break;
1294
1295 if (e->xclient.format != 32) return;
1296
1297 msgtype = e->xclient.message_type;
1298 if (msgtype == OBT_PROP_ATOM(WM_CHANGE_STATE)) {
1299 compress_client_message_event(e, &ce, client->window, msgtype);
1300 client_set_wm_state(client, e->xclient.data.l[0]);
1301 } else if (msgtype == OBT_PROP_ATOM(NET_WM_DESKTOP)) {
1302 compress_client_message_event(e, &ce, client->window, msgtype);
1303 if ((unsigned)e->xclient.data.l[0] < screen_num_desktops ||
1304 (unsigned)e->xclient.data.l[0] == DESKTOP_ALL)
1305 client_set_desktop(client, (unsigned)e->xclient.data.l[0],
1306 FALSE, FALSE);
1307 } else if (msgtype == OBT_PROP_ATOM(NET_WM_STATE)) {
1308 gulong ignore_start;
1309
1310 /* can't compress these */
1311 ob_debug("net_wm_state %s %ld %ld for 0x%lx",
1312 (e->xclient.data.l[0] == 0 ? "Remove" :
1313 e->xclient.data.l[0] == 1 ? "Add" :
1314 e->xclient.data.l[0] == 2 ? "Toggle" : "INVALID"),
1315 e->xclient.data.l[1], e->xclient.data.l[2],
1316 client->window);
1317
1318 /* ignore enter events caused by these like ob actions do */
1319 if (!config_focus_under_mouse)
1320 ignore_start = event_start_ignore_all_enters();
1321 client_set_state(client, e->xclient.data.l[0],
1322 e->xclient.data.l[1], e->xclient.data.l[2]);
1323 if (!config_focus_under_mouse)
1324 event_end_ignore_all_enters(ignore_start);
1325 } else if (msgtype == OBT_PROP_ATOM(NET_CLOSE_WINDOW)) {
1326 ob_debug("net_close_window for 0x%lx", client->window);
1327 client_close(client);
1328 } else if (msgtype == OBT_PROP_ATOM(NET_ACTIVE_WINDOW)) {
1329 ob_debug("net_active_window for 0x%lx source=%s",
1330 client->window,
1331 (e->xclient.data.l[0] == 0 ? "unknown" :
1332 (e->xclient.data.l[0] == 1 ? "application" :
1333 (e->xclient.data.l[0] == 2 ? "user" : "INVALID"))));
1334 /* XXX make use of data.l[2] !? */
1335 if (e->xclient.data.l[0] == 1 || e->xclient.data.l[0] == 2) {
1336 /* don't use the user's timestamp for client_focus, cuz if it's
1337 an old broken timestamp (happens all the time) then focus
1338 won't move even though we're trying to move it
1339 event_curtime = e->xclient.data.l[1];*/
1340 if (e->xclient.data.l[1] == 0)
1341 ob_debug_type(OB_DEBUG_APP_BUGS,
1342 "_NET_ACTIVE_WINDOW message for window %s is"
1343 " missing a timestamp", client->title);
1344 } else
1345 ob_debug_type(OB_DEBUG_APP_BUGS,
1346 "_NET_ACTIVE_WINDOW message for window %s is "
1347 "missing source indication", client->title);
1348 client_activate(client, TRUE, TRUE, TRUE,
1349 (e->xclient.data.l[0] == 0 ||
1350 e->xclient.data.l[0] == 2));
1351 } else if (msgtype == OBT_PROP_ATOM(NET_WM_MOVERESIZE)) {
1352 ob_debug("net_wm_moveresize for 0x%lx direction %d",
1353 client->window, e->xclient.data.l[2]);
1354 if ((Atom)e->xclient.data.l[2] ==
1355 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT) ||
1356 (Atom)e->xclient.data.l[2] ==
1357 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP) ||
1358 (Atom)e->xclient.data.l[2] ==
1359 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT) ||
1360 (Atom)e->xclient.data.l[2] ==
1361 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT) ||
1362 (Atom)e->xclient.data.l[2] ==
1363 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT) ||
1364 (Atom)e->xclient.data.l[2] ==
1365 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT) ||
1366 (Atom)e->xclient.data.l[2] ==
1367 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM) ||
1368 (Atom)e->xclient.data.l[2] ==
1369 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT) ||
1370 (Atom)e->xclient.data.l[2] ==
1371 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT) ||
1372 (Atom)e->xclient.data.l[2] ==
1373 OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE) ||
1374 (Atom)e->xclient.data.l[2] ==
1375 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD) ||
1376 (Atom)e->xclient.data.l[2] ==
1377 OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD))
1378 {
1379 moveresize_start(client, e->xclient.data.l[0],
1380 e->xclient.data.l[1], e->xclient.data.l[3],
1381 e->xclient.data.l[2]);
1382 }
1383 else if ((Atom)e->xclient.data.l[2] ==
1384 OBT_PROP_ATOM(NET_WM_MOVERESIZE_CANCEL))
1385 moveresize_end(TRUE);
1386 } else if (msgtype == OBT_PROP_ATOM(NET_MOVERESIZE_WINDOW)) {
1387 gint ograv, x, y, w, h;
1388
1389 ograv = client->gravity;
1390
1391 if (e->xclient.data.l[0] & 0xff)
1392 client->gravity = e->xclient.data.l[0] & 0xff;
1393
1394 if (e->xclient.data.l[0] & 1 << 8)
1395 x = e->xclient.data.l[1];
1396 else
1397 x = client->area.x;
1398 if (e->xclient.data.l[0] & 1 << 9)
1399 y = e->xclient.data.l[2];
1400 else
1401 y = client->area.y;
1402
1403 if (e->xclient.data.l[0] & 1 << 10) {
1404 w = e->xclient.data.l[3];
1405
1406 /* if x was not given, then use gravity to figure out the new
1407 x. the reference point should not be moved */
1408 if (!(e->xclient.data.l[0] & 1 << 8))
1409 client_gravity_resize_w(client, &x, client->area.width, w);
1410 }
1411 else
1412 w = client->area.width;
1413
1414 if (e->xclient.data.l[0] & 1 << 11) {
1415 h = e->xclient.data.l[4];
1416
1417 /* same for y */
1418 if (!(e->xclient.data.l[0] & 1 << 9))
1419 client_gravity_resize_h(client, &y, client->area.height,h);
1420 }
1421 else
1422 h = client->area.height;
1423
1424 ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)",
1425 e->xclient.data.l[0] & 1 << 8, x,
1426 e->xclient.data.l[0] & 1 << 9, y,
1427 client->gravity);
1428
1429 client_find_onscreen(client, &x, &y, w, h, FALSE);
1430
1431 client_configure(client, x, y, w, h, FALSE, TRUE, FALSE);
1432
1433 client->gravity = ograv;
1434 } else if (msgtype == OBT_PROP_ATOM(NET_RESTACK_WINDOW)) {
1435 if (e->xclient.data.l[0] != 2) {
1436 ob_debug_type(OB_DEBUG_APP_BUGS,
1437 "_NET_RESTACK_WINDOW sent for window %s with "
1438 "invalid source indication %ld",
1439 client->title, e->xclient.data.l[0]);
1440 } else {
1441 ObClient *sibling = NULL;
1442 if (e->xclient.data.l[1]) {
1443 ObWindow *win = window_find(e->xclient.data.l[1]);
1444 if (WINDOW_IS_CLIENT(win) &&
1445 WINDOW_AS_CLIENT(win) != client)
1446 {
1447 sibling = WINDOW_AS_CLIENT(win);
1448 }
1449 if (sibling == NULL)
1450 ob_debug_type(OB_DEBUG_APP_BUGS,
1451 "_NET_RESTACK_WINDOW sent for window %s "
1452 "with invalid sibling 0x%x",
1453 client->title, e->xclient.data.l[1]);
1454 }
1455 if (e->xclient.data.l[2] == Below ||
1456 e->xclient.data.l[2] == BottomIf ||
1457 e->xclient.data.l[2] == Above ||
1458 e->xclient.data.l[2] == TopIf ||
1459 e->xclient.data.l[2] == Opposite)
1460 {
1461 gulong ignore_start;
1462
1463 if (!config_focus_under_mouse)
1464 ignore_start = event_start_ignore_all_enters();
1465 /* just raise, don't activate */
1466 stacking_restack_request(client, sibling,
1467 e->xclient.data.l[2]);
1468 if (!config_focus_under_mouse)
1469 event_end_ignore_all_enters(ignore_start);
1470
1471 /* send a synthetic ConfigureNotify, cuz this is supposed
1472 to be like a ConfigureRequest. */
1473 client_reconfigure(client, TRUE);
1474 } else
1475 ob_debug_type(OB_DEBUG_APP_BUGS,
1476 "_NET_RESTACK_WINDOW sent for window %s "
1477 "with invalid detail %d",
1478 client->title, e->xclient.data.l[2]);
1479 }
1480 }
1481 break;
1482 case PropertyNotify:
1483 /* validate cuz we query stuff off the client here */
1484 if (!client_validate(client)) break;
1485
1486 /* compress changes to a single property into a single change */
1487 while (XCheckTypedWindowEvent(obt_display, client->window,
1488 e->type, &ce)) {
1489 Atom a, b;
1490
1491 /* XXX: it would be nice to compress ALL changes to a property,
1492 not just changes in a row without other props between. */
1493
1494 a = ce.xproperty.atom;
1495 b = e->xproperty.atom;
1496
1497 if (a == b)
1498 continue;
1499 if ((a == OBT_PROP_ATOM(NET_WM_NAME) ||
1500 a == OBT_PROP_ATOM(WM_NAME) ||
1501 a == OBT_PROP_ATOM(NET_WM_ICON_NAME) ||
1502 a == OBT_PROP_ATOM(WM_ICON_NAME))
1503 &&
1504 (b == OBT_PROP_ATOM(NET_WM_NAME) ||
1505 b == OBT_PROP_ATOM(WM_NAME) ||
1506 b == OBT_PROP_ATOM(NET_WM_ICON_NAME) ||
1507 b == OBT_PROP_ATOM(WM_ICON_NAME))) {
1508 continue;
1509 }
1510 if (a == OBT_PROP_ATOM(NET_WM_ICON) &&
1511 b == OBT_PROP_ATOM(NET_WM_ICON))
1512 continue;
1513
1514 XPutBackEvent(obt_display, &ce);
1515 break;
1516 }
1517
1518 msgtype = e->xproperty.atom;
1519 if (msgtype == XA_WM_NORMAL_HINTS) {
1520 ob_debug("Update NORMAL hints");
1521 client_update_normal_hints(client);
1522 /* normal hints can make a window non-resizable */
1523 client_setup_decor_and_functions(client, FALSE);
1524
1525 /* make sure the client's sizes are within its bounds, but only
1526 reconfigure the window if it needs to. emacs will update its
1527 normal hints every time it receives a conigurenotify */
1528 client_reconfigure(client, FALSE);
1529 } else if (msgtype == OBT_PROP_ATOM(MOTIF_WM_HINTS)) {
1530 client_get_mwm_hints(client);
1531 /* This can override some mwm hints */
1532 client_get_type_and_transientness(client);
1533
1534 /* Apply the changes to the window */
1535 client_setup_decor_and_functions(client, TRUE);
1536 } else if (msgtype == XA_WM_HINTS) {
1537 client_update_wmhints(client);
1538 } else if (msgtype == XA_WM_TRANSIENT_FOR) {
1539 client_update_transient_for(client);
1540 client_get_type_and_transientness(client);
1541 /* type may have changed, so update the layer */
1542 client_calc_layer(client);
1543 client_setup_decor_and_functions(client, TRUE);
1544 } else if (msgtype == OBT_PROP_ATOM(NET_WM_NAME) ||
1545 msgtype == OBT_PROP_ATOM(WM_NAME) ||
1546 msgtype == OBT_PROP_ATOM(NET_WM_ICON_NAME) ||
1547 msgtype == OBT_PROP_ATOM(WM_ICON_NAME)) {
1548 client_update_title(client);
1549 } else if (msgtype == OBT_PROP_ATOM(WM_PROTOCOLS)) {
1550 client_update_protocols(client);
1551 client_setup_decor_and_functions(client, TRUE);
1552 }
1553 else if (msgtype == OBT_PROP_ATOM(NET_WM_STRUT) ||
1554 msgtype == OBT_PROP_ATOM(NET_WM_STRUT_PARTIAL)) {
1555 client_update_strut(client);
1556 }
1557 else if (msgtype == OBT_PROP_ATOM(NET_WM_ICON)) {
1558 client_update_icons(client);
1559 }
1560 else if (msgtype == OBT_PROP_ATOM(NET_WM_ICON_GEOMETRY)) {
1561 client_update_icon_geometry(client);
1562 }
1563 else if (msgtype == OBT_PROP_ATOM(NET_WM_USER_TIME)) {
1564 guint32 t;
1565 if (client == focus_client &&
1566 OBT_PROP_GET32(client->window, NET_WM_USER_TIME, CARDINAL, &t)
1567 && t && !event_time_after(t, e->xproperty.time) &&
1568 (!event_last_user_time ||
1569 event_time_after(t, event_last_user_time)))
1570 {
1571 event_last_user_time = t;
1572 }
1573 }
1574 #ifdef SYNC
1575 else if (msgtype == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST_COUNTER)) {
1576 client_update_sync_request_counter(client);
1577 }
1578 #endif
1579 break;
1580 case ColormapNotify:
1581 client_update_colormap(client, e->xcolormap.colormap);
1582 break;
1583 default:
1584 ;
1585 #ifdef SHAPE
1586 {
1587 int kind;
1588 if (obt_display_extension_shape &&
1589 e->type == obt_display_extension_shape_basep)
1590 {
1591 switch (((XShapeEvent*)e)->kind) {
1592 case ShapeBounding:
1593 case ShapeClip:
1594 client->shaped = ((XShapeEvent*)e)->shaped;
1595 kind = ShapeBounding;
1596 break;
1597 case ShapeInput:
1598 client->shaped_input = ((XShapeEvent*)e)->shaped;
1599 kind = ShapeInput;
1600 break;
1601 }
1602 frame_adjust_shape_kind(client->frame, kind);
1603 }
1604 }
1605 #endif
1606 }
1607 }
1608
1609 static void event_handle_dock(ObDock *s, XEvent *e)
1610 {
1611 switch (e->type) {
1612 case ButtonPress:
1613 if (e->xbutton.button == 1)
1614 stacking_raise(DOCK_AS_WINDOW(s));
1615 else if (e->xbutton.button == 2)
1616 stacking_lower(DOCK_AS_WINDOW(s));
1617 break;
1618 case EnterNotify:
1619 dock_hide(FALSE);
1620 break;
1621 case LeaveNotify:
1622 /* don't hide when moving into a dock app */
1623 if (e->xcrossing.detail != NotifyInferior)
1624 dock_hide(TRUE);
1625 break;
1626 }
1627 }
1628
1629 static void event_handle_dockapp(ObDockApp *app, XEvent *e)
1630 {
1631 switch (e->type) {
1632 case MotionNotify:
1633 dock_app_drag(app, &e->xmotion);
1634 break;
1635 case UnmapNotify:
1636 if (app->ignore_unmaps) {
1637 app->ignore_unmaps--;
1638 break;
1639 }
1640 dock_unmanage(app, TRUE);
1641 break;
1642 case DestroyNotify:
1643 case ReparentNotify:
1644 dock_unmanage(app, FALSE);
1645 break;
1646 case ConfigureNotify:
1647 dock_app_configure(app, e->xconfigure.width, e->xconfigure.height);
1648 break;
1649 }
1650 }
1651
1652 static ObMenuFrame* find_active_menu(void)
1653 {
1654 GList *it;
1655 ObMenuFrame *ret = NULL;
1656
1657 for (it = menu_frame_visible; it; it = g_list_next(it)) {
1658 ret = it->data;
1659 if (ret->selected)
1660 break;
1661 ret = NULL;
1662 }
1663 return ret;
1664 }
1665
1666 static ObMenuFrame* find_active_or_last_menu(void)
1667 {
1668 ObMenuFrame *ret = NULL;
1669
1670 ret = find_active_menu();
1671 if (!ret && menu_frame_visible)
1672 ret = menu_frame_visible->data;
1673 return ret;
1674 }
1675
1676 static gboolean event_handle_prompt(ObPrompt *p, XEvent *e)
1677 {
1678 switch (e->type) {
1679 case ButtonPress:
1680 case ButtonRelease:
1681 case MotionNotify:
1682 return prompt_mouse_event(p, e);
1683 break;
1684 case KeyPress:
1685 return prompt_key_event(p, e);
1686 break;
1687 }
1688 return FALSE;
1689 }
1690
1691 static gboolean event_handle_menu_input(XEvent *ev)
1692 {
1693 gboolean ret = FALSE;
1694
1695 if (ev->type == ButtonRelease || ev->type == ButtonPress) {
1696 ObMenuEntryFrame *e;
1697
1698 if (menu_hide_delay_reached() &&
1699 (ev->xbutton.button < 4 || ev->xbutton.button > 5))
1700 {
1701 if ((e = menu_entry_frame_under(ev->xbutton.x_root,
1702 ev->xbutton.y_root)))
1703 {
1704 if (ev->type == ButtonPress && e->frame->child)
1705 menu_frame_select(e->frame->child, NULL, TRUE);
1706 menu_frame_select(e->frame, e, TRUE);
1707 if (ev->type == ButtonRelease)
1708 menu_entry_frame_execute(e, ev->xbutton.state);
1709 }
1710 else if (ev->type == ButtonRelease)
1711 menu_frame_hide_all();
1712 }
1713 ret = TRUE;
1714 }
1715 else if (ev->type == MotionNotify) {
1716 ObMenuFrame *f;
1717 ObMenuEntryFrame *e;
1718
1719 if ((e = menu_entry_frame_under(ev->xmotion.x_root,
1720 ev->xmotion.y_root)))
1721 if (!(f = find_active_menu()) ||
1722 f == e->frame ||
1723 f->parent == e->frame ||
1724 f->child == e->frame)
1725 menu_frame_select(e->frame, e, FALSE);
1726 }
1727 else if (ev->type == KeyPress || ev->type == KeyRelease) {
1728 guint keycode, state;
1729 gunichar unikey;
1730 ObMenuFrame *frame;
1731
1732 keycode = ev->xkey.keycode;
1733 state = ev->xkey.state;
1734 unikey = obt_keyboard_keycode_to_unichar(keycode);
1735
1736 frame = find_active_or_last_menu();
1737 if (frame == NULL)
1738 g_assert_not_reached(); /* there is no active menu */
1739
1740 /* Allow control while going thru the menu */
1741 else if (ev->type == KeyPress && (state & ~ControlMask) == 0) {
1742 frame->got_press = TRUE;
1743
1744 if (keycode == ob_keycode(OB_KEY_ESCAPE)) {
1745 menu_frame_hide_all();
1746 ret = TRUE;
1747 }
1748
1749 else if (keycode == ob_keycode(OB_KEY_LEFT)) {
1750 /* Left goes to the parent menu */
1751 if (frame->parent)
1752 menu_frame_select(frame, NULL, TRUE);
1753 ret = TRUE;
1754 }
1755
1756 else if (keycode == ob_keycode(OB_KEY_RIGHT)) {
1757 /* Right goes to the selected submenu */
1758 if (frame->child) menu_frame_select_next(frame->child);
1759 ret = TRUE;
1760 }
1761
1762 else if (keycode == ob_keycode(OB_KEY_UP)) {
1763 menu_frame_select_previous(frame);
1764 ret = TRUE;
1765 }
1766
1767 else if (keycode == ob_keycode(OB_KEY_DOWN)) {
1768 menu_frame_select_next(frame);
1769 ret = TRUE;
1770 }
1771 }
1772
1773 /* Use KeyRelease events for running things so that the key release
1774 doesn't get sent to the focused application.
1775
1776 Allow ControlMask only, and don't bother if the menu is empty */
1777 else if (ev->type == KeyRelease && (state & ~ControlMask) == 0 &&
1778 frame->entries && frame->got_press)
1779 {
1780 if (keycode == ob_keycode(OB_KEY_RETURN)) {
1781 /* Enter runs the active item or goes into the submenu.
1782 Control-Enter runs it without closing the menu. */
1783 if (frame->child)
1784 menu_frame_select_next(frame->child);
1785 else if (frame->selected)
1786 menu_entry_frame_execute(frame->selected, state);
1787
1788 ret = TRUE;
1789 }
1790
1791 /* keyboard accelerator shortcuts. (if it was a valid key) */
1792 else if (unikey != 0) {
1793 GList *start;
1794 GList *it;
1795 ObMenuEntryFrame *found = NULL;
1796 guint num_found = 0;
1797
1798 /* start after the selected one */
1799 start = frame->entries;
1800 if (frame->selected) {
1801 for (it = start; frame->selected != it->data;
1802 it = g_list_next(it))
1803 g_assert(it != NULL); /* nothing was selected? */
1804 /* next with wraparound */
1805 start = g_list_next(it);
1806 if (start == NULL) start = frame->entries;
1807 }
1808
1809 it = start;
1810 do {
1811 ObMenuEntryFrame *e = it->data;
1812 gunichar entrykey = 0;
1813
1814 if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL)
1815 entrykey = e->entry->data.normal.shortcut;
1816 else if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
1817 entrykey = e->entry->data.submenu.submenu->shortcut;
1818
1819 if (unikey == entrykey) {
1820 if (found == NULL) found = e;
1821 ++num_found;
1822 }
1823
1824 /* next with wraparound */
1825 it = g_list_next(it);
1826 if (it == NULL) it = frame->entries;
1827 } while (it != start);
1828
1829 if (found) {
1830 if (found->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
1831 num_found == 1)
1832 {
1833 menu_frame_select(frame, found, TRUE);
1834 usleep(50000); /* highlight the item for a short bit so
1835 the user can see what happened */
1836 menu_entry_frame_execute(found, state);
1837 } else {
1838 menu_frame_select(frame, found, TRUE);
1839 if (num_found == 1)
1840 menu_frame_select_next(frame->child);
1841 }
1842
1843 ret = TRUE;
1844 }
1845 }
1846 }
1847 }
1848
1849 return ret;
1850 }
1851
1852 static void event_handle_menu(ObMenuFrame *frame, XEvent *ev)
1853 {
1854 ObMenuFrame *f;
1855 ObMenuEntryFrame *e;
1856
1857 switch (ev->type) {
1858 case EnterNotify:
1859 if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window))) {
1860 if (e->ignore_enters)
1861 --e->ignore_enters;
1862 else if (!(f = find_active_menu()) ||
1863 f == e->frame ||
1864 f->parent == e->frame ||
1865 f->child == e->frame)
1866 menu_frame_select(e->frame, e, FALSE);
1867 }
1868 break;
1869 case LeaveNotify:
1870 /*ignore leaves when we're already in the window */
1871 if (ev->xcrossing.detail == NotifyInferior)
1872 break;
1873
1874 if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window)) &&
1875 (f = find_active_menu()) && f->selected == e &&
1876 e->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU)
1877 {
1878 menu_frame_select(e->frame, NULL, FALSE);
1879 }
1880 break;
1881 }
1882 }
1883
1884 static void event_handle_user_input(ObClient *client, XEvent *e)
1885 {
1886 g_assert(e->type == ButtonPress || e->type == ButtonRelease ||
1887 e->type == MotionNotify || e->type == KeyPress ||
1888 e->type == KeyRelease);
1889
1890 if (menu_frame_visible) {
1891 if (event_handle_menu_input(e))
1892 /* don't use the event if the menu used it, but if the menu
1893 didn't use it and it's a keypress that is bound, it will
1894 close the menu and be used */
1895 return;
1896 }
1897
1898 /* if the keyboard interactive action uses the event then dont
1899 use it for bindings. likewise is moveresize uses the event. */
1900 if (!actions_interactive_input_event(e) && !moveresize_event(e)) {
1901 if (moveresize_in_progress)
1902 /* make further actions work on the client being
1903 moved/resized */
1904 client = moveresize_client;
1905
1906 if (e->type == ButtonPress ||
1907 e->type == ButtonRelease ||
1908 e->type == MotionNotify)
1909 {
1910 /* the frame may not be "visible" but they can still click on it
1911 in the case where it is animating before disappearing */
1912 if (!client || !frame_iconify_animating(client->frame))
1913 mouse_event(client, e);
1914 } else
1915 keyboard_event(event_target_client(client), e);
1916 }
1917 }
1918
1919 ObClient* event_target_client(ObClient *client)
1920 {
1921 return (focus_cycle_target ? focus_cycle_target :
1922 (client ? client : focus_client));
1923 }
1924
1925 static void focus_delay_dest(gpointer data)
1926 {
1927 g_free(data);
1928 }
1929
1930 static gboolean focus_delay_cmp(gconstpointer d1, gconstpointer d2)
1931 {
1932 const ObFocusDelayData *f1 = d1;
1933 return f1->client == d2;
1934 }
1935
1936 static gboolean focus_delay_func(gpointer data)
1937 {
1938 ObFocusDelayData *d = data;
1939 Time old = event_curtime;
1940
1941 /* don't move focus and kill the menu or the move/resize */
1942 if (menu_frame_visible || moveresize_in_progress) return FALSE;
1943
1944 event_curtime = d->time;
1945 event_curserial = d->serial;
1946 if (client_focus(d->client) && config_focus_raise)
1947 stacking_raise(CLIENT_AS_WINDOW(d->client));
1948 event_curtime = old;
1949 return FALSE; /* no repeat */
1950 }
1951
1952 static void focus_delay_client_dest(ObClient *client, gpointer data)
1953 {
1954 obt_main_loop_timeout_remove_data(ob_main_loop, focus_delay_func,
1955 client, FALSE);
1956 }
1957
1958 void event_halt_focus_delay(void)
1959 {
1960 /* ignore all enter events up till the event which caused this to occur */
1961 if (event_curserial) event_ignore_enter_range(1, event_curserial);
1962 obt_main_loop_timeout_remove(ob_main_loop, focus_delay_func);
1963 }
1964
1965 gulong event_start_ignore_all_enters(void)
1966 {
1967 return NextRequest(obt_display);
1968 }
1969
1970 static void event_ignore_enter_range(gulong start, gulong end)
1971 {
1972 ObSerialRange *r;
1973
1974 g_assert(start != 0);
1975 g_assert(end != 0);
1976
1977 r = g_new(ObSerialRange, 1);
1978 r->start = start;
1979 r->end = end;
1980 ignore_serials = g_slist_prepend(ignore_serials, r);
1981
1982 ob_debug_type(OB_DEBUG_FOCUS, "ignoring enters from %lu until %lu",
1983 r->start, r->end);
1984
1985 /* increment the serial so we don't ignore events we weren't meant to */
1986 OBT_PROP_ERASE(screen_support_win, MOTIF_WM_HINTS);
1987 }
1988
1989 void event_end_ignore_all_enters(gulong start)
1990 {
1991 /* Use (NextRequest-1) so that we ignore up to the current serial only.
1992 Inside event_ignore_enter_range, we increment the serial by one, but if
1993 we ignore that serial too, then any enter events generated by mouse
1994 movement will be ignored until we create some further network traffic.
1995 Instead ignore up to NextRequest-1, then when we increment the serial,
1996 we will be *past* the range of ignored serials */
1997 event_ignore_enter_range(start, NextRequest(obt_display)-1);
1998 }
1999
2000 static gboolean is_enter_focus_event_ignored(gulong serial)
2001 {
2002 GSList *it, *next;
2003
2004 for (it = ignore_serials; it; it = next) {
2005 ObSerialRange *r = it->data;
2006
2007 next = g_slist_next(it);
2008
2009 if ((glong)(serial - r->end) > 0) {
2010 /* past the end */
2011 ignore_serials = g_slist_delete_link(ignore_serials, it);
2012 g_free(r);
2013 }
2014 else if ((glong)(serial - r->start) >= 0)
2015 return TRUE;
2016 }
2017 return FALSE;
2018 }
2019
2020 void event_cancel_all_key_grabs(void)
2021 {
2022 if (actions_interactive_act_running()) {
2023 actions_interactive_cancel_act();
2024 ob_debug("KILLED interactive action");
2025 }
2026 else if (menu_frame_visible) {
2027 menu_frame_hide_all();
2028 ob_debug("KILLED open menus");
2029 }
2030 else if (moveresize_in_progress) {
2031 moveresize_end(TRUE);
2032 ob_debug("KILLED interactive moveresize");
2033 }
2034 else if (grab_on_keyboard()) {
2035 ungrab_keyboard();
2036 ob_debug("KILLED active grab on keyboard");
2037 }
2038 else
2039 ungrab_passive_key();
2040
2041 XSync(obt_display, FALSE);
2042 }
2043
2044 gboolean event_time_after(guint32 t1, guint32 t2)
2045 {
2046 g_assert(t1 != CurrentTime);
2047 g_assert(t2 != CurrentTime);
2048
2049 /*
2050 Timestamp values wrap around (after about 49.7 days). The server, given
2051 its current time is represented by timestamp T, always interprets
2052 timestamps from clients by treating half of the timestamp space as being
2053 later in time than T.
2054 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
2055 */
2056
2057 /* TIME_HALF is not half of the number space of a Time type variable.
2058 * Rather, it is half the number space of a timestamp value, which is
2059 * always 32 bits. */
2060 #define TIME_HALF (guint32)(1 << 31)
2061
2062 if (t2 >= TIME_HALF)
2063 /* t2 is in the second half so t1 might wrap around and be smaller than
2064 t2 */
2065 return t1 >= t2 || t1 < (t2 + TIME_HALF);
2066 else
2067 /* t2 is in the first half so t1 has to come after it */
2068 return t1 >= t2 && t1 < (t2 + TIME_HALF);
2069 }
2070
2071 Time event_get_server_time(void)
2072 {
2073 /* Generate a timestamp */
2074 XEvent event;
2075
2076 XChangeProperty(obt_display, screen_support_win,
2077 OBT_PROP_ATOM(WM_CLASS), OBT_PROP_ATOM(STRING),
2078 8, PropModeAppend, NULL, 0);
2079 XWindowEvent(obt_display, screen_support_win, PropertyChangeMask, &event);
2080 return event.xproperty.time;
2081 }
This page took 0.123835 seconds and 4 git commands to generate.