1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 event.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
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.
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.
17 See the COPYING file for a copy of the GNU General Public License.
32 #include "menuframe.h"
38 #include "framerender.h"
40 #include "moveresize.h"
43 #include "extensions.h"
44 #include "translate.h"
47 #include <X11/Xatom.h>
50 #ifdef HAVE_SYS_SELECT_H
51 # include <sys/select.h>
57 # include <unistd.h> /* for usleep() */
60 # include <X11/XKBlib.h>
64 #include <X11/ICE/ICElib.h>
78 static void event_process(const XEvent *e, gpointer data);
79 static void event_handle_root(XEvent *e);
80 static gboolean event_handle_menu_keyboard(XEvent *e);
81 static gboolean event_handle_menu(XEvent *e);
82 static void event_handle_dock(ObDock *s, XEvent *e);
83 static void event_handle_dockapp(ObDockApp *app, XEvent *e);
84 static void event_handle_client(ObClient *c, XEvent *e);
85 static void event_handle_user_time_window_clients(GSList *l, XEvent *e);
86 static void event_handle_user_input(ObClient *client, XEvent *e);
88 static void focus_delay_dest(gpointer data);
89 static gboolean focus_delay_cmp(gconstpointer d1, gconstpointer d2);
90 static gboolean focus_delay_func(gpointer data);
91 static void focus_delay_client_dest(ObClient *client, gpointer data);
93 static gboolean menu_hide_delay_func(gpointer data);
95 /* The time for the current event being processed */
96 Time event_curtime = CurrentTime;
98 static guint ignore_enter_focus = 0;
99 static gboolean menu_can_hide;
100 static gboolean focus_left_screen = FALSE;
103 static void ice_handler(gint fd, gpointer conn)
106 IceProcessMessages(conn, NULL, &b);
109 static void ice_watch(IceConn conn, IcePointer data, Bool opening,
110 IcePointer *watch_data)
115 fd = IceConnectionNumber(conn);
116 ob_main_loop_fd_add(ob_main_loop, fd, ice_handler, conn, NULL);
118 ob_main_loop_fd_remove(ob_main_loop, fd);
124 void event_startup(gboolean reconfig)
126 if (reconfig) return;
128 ob_main_loop_x_add(ob_main_loop, event_process, NULL, NULL);
131 IceAddConnectionWatch(ice_watch, NULL);
134 client_add_destroy_notify(focus_delay_client_dest, NULL);
137 void event_shutdown(gboolean reconfig)
139 if (reconfig) return;
142 IceRemoveConnectionWatch(ice_watch, NULL);
145 client_remove_destroy_notify(focus_delay_client_dest);
148 static Window event_get_window(XEvent *e)
155 window = RootWindow(ob_display, ob_screen);
158 window = e->xmap.window;
161 window = e->xunmap.window;
164 window = e->xdestroywindow.window;
166 case ConfigureRequest:
167 window = e->xconfigurerequest.window;
169 case ConfigureNotify:
170 window = e->xconfigure.window;
174 if (extensions_xkb && e->type == extensions_xkb_event_basep) {
175 switch (((XkbAnyEvent*)e)->xkb_type) {
177 window = ((XkbBellNotifyEvent*)e)->window;
184 if (extensions_sync &&
185 e->type == extensions_sync_event_basep + XSyncAlarmNotify)
190 window = e->xany.window;
195 static void event_set_curtime(XEvent *e)
197 Time t = CurrentTime;
199 /* grab the lasttime and hack up the state */
215 t = e->xproperty.time;
219 t = e->xcrossing.time;
223 if (extensions_sync &&
224 e->type == extensions_sync_event_basep + XSyncAlarmNotify)
226 t = ((XSyncAlarmNotifyEvent*)e)->time;
229 /* if more event types are anticipated, get their timestamp
237 static void event_hack_mods(XEvent *e)
240 XkbStateRec xkb_state;
246 e->xbutton.state = modkeys_only_modifier_masks(e->xbutton.state);
249 e->xkey.state = modkeys_only_modifier_masks(e->xkey.state);
252 e->xkey.state = modkeys_only_modifier_masks(e->xkey.state);
254 if (XkbGetState(ob_display, XkbUseCoreKbd, &xkb_state) == Success) {
255 e->xkey.state = xkb_state.compat_state;
259 /* remove from the state the mask of the modifier key being released,
260 if it is a modifier key being released that is */
261 e->xkey.state &= ~modkeys_keycode_to_mask(e->xkey.keycode);
264 e->xmotion.state = modkeys_only_modifier_masks(e->xmotion.state);
265 /* compress events */
268 while (XCheckTypedWindowEvent(ob_display, e->xmotion.window,
270 e->xmotion.x_root = ce.xmotion.x_root;
271 e->xmotion.y_root = ce.xmotion.y_root;
278 static gboolean wanted_focusevent(XEvent *e, gboolean in_client_only)
280 gint mode = e->xfocus.mode;
281 gint detail = e->xfocus.detail;
282 Window win = e->xany.window;
284 if (e->type == FocusIn) {
285 /* These are ones we never want.. */
287 /* This means focus was given by a keyboard/mouse grab. */
288 if (mode == NotifyGrab)
290 /* This means focus was given back from a keyboard/mouse grab. */
291 if (mode == NotifyUngrab)
294 /* These are the ones we want.. */
296 if (win == RootWindow(ob_display, ob_screen)) {
297 /* If looking for a focus in on a client, then always return
298 FALSE for focus in's to the root window */
301 /* This means focus reverted off of a client */
302 else if (detail == NotifyPointerRoot ||
303 detail == NotifyDetailNone ||
304 detail == NotifyInferior)
310 /* This means focus moved to the frame window */
311 if (detail == NotifyInferior && !in_client_only)
314 /* It was on a client, was it a valid one?
315 It's possible to get a FocusIn event for a client that was managed
316 but has disappeared. Don't even parse those FocusIn events.
319 ObWindow *w = g_hash_table_lookup(window_map, &e->xfocus.window);
320 if (!w || !WINDOW_IS_CLIENT(w))
324 /* This means focus moved from the root window to a client */
325 if (detail == NotifyVirtual)
327 /* This means focus moved from one client to another */
328 if (detail == NotifyNonlinearVirtual)
334 g_assert(e->type == FocusOut);
336 /* These are ones we never want.. */
338 /* This means focus was taken by a keyboard/mouse grab. */
339 if (mode == NotifyGrab)
342 /* Focus left the root window revertedto state */
343 if (win == RootWindow(ob_display, ob_screen))
346 /* These are the ones we want.. */
348 /* This means focus moved from a client to the root window */
349 if (detail == NotifyVirtual)
351 /* This means focus moved from one client to another */
352 if (detail == NotifyNonlinearVirtual)
354 /* This means focus had moved to our frame window and now moved off */
355 if (detail == NotifyNonlinear)
363 static Bool event_look_for_focusin(Display *d, XEvent *e, XPointer arg)
365 return e->type == FocusIn && wanted_focusevent(e, FALSE);
368 Bool event_look_for_focusin_client(Display *d, XEvent *e, XPointer arg)
370 return e->type == FocusIn && wanted_focusevent(e, TRUE);
373 static void print_focusevent(XEvent *e)
375 gint mode = e->xfocus.mode;
376 gint detail = e->xfocus.detail;
377 Window win = e->xany.window;
378 const gchar *modestr, *detailstr;
381 case NotifyNormal: modestr="NotifyNormal"; break;
382 case NotifyGrab: modestr="NotifyGrab"; break;
383 case NotifyUngrab: modestr="NotifyUngrab"; break;
384 case NotifyWhileGrabbed: modestr="NotifyWhileGrabbed"; break;
387 case NotifyAncestor: detailstr="NotifyAncestor"; break;
388 case NotifyVirtual: detailstr="NotifyVirtual"; break;
389 case NotifyInferior: detailstr="NotifyInferior"; break;
390 case NotifyNonlinear: detailstr="NotifyNonlinear"; break;
391 case NotifyNonlinearVirtual: detailstr="NotifyNonlinearVirtual"; break;
392 case NotifyPointer: detailstr="NotifyPointer"; break;
393 case NotifyPointerRoot: detailstr="NotifyPointerRoot"; break;
394 case NotifyDetailNone: detailstr="NotifyDetailNone"; break;
399 ob_debug_type(OB_DEBUG_FOCUS, "Focus%s 0x%x mode=%s detail=%s\n",
400 (e->xfocus.type == FocusIn ? "In" : "Out"),
406 static gboolean event_ignore(XEvent *e, ObClient *client)
411 if (!wanted_focusevent(e, FALSE))
416 if (!wanted_focusevent(e, FALSE))
423 static void event_process(const XEvent *ec, gpointer data)
426 ObClient *client = NULL;
428 ObDockApp *dockapp = NULL;
429 ObWindow *obwin = NULL;
430 GSList *timewinclients = NULL;
432 ObEventData *ed = data;
434 /* make a copy we can mangle */
438 window = event_get_window(e);
439 if (e->type != PropertyNotify ||
440 !(timewinclients = propwin_get_clients(window,
441 OB_PROPWIN_USER_TIME)))
442 if ((obwin = g_hash_table_lookup(window_map, &window))) {
443 switch (obwin->type) {
445 dock = WINDOW_AS_DOCK(obwin);
448 dockapp = WINDOW_AS_DOCKAPP(obwin);
451 client = WINDOW_AS_CLIENT(obwin);
454 case Window_Internal:
455 /* not to be used for events */
456 g_assert_not_reached();
461 event_set_curtime(e);
463 if (event_ignore(e, client)) {
470 /* deal with it in the kernel */
472 if (menu_frame_visible &&
473 (e->type == EnterNotify || e->type == LeaveNotify))
475 /* crossing events for menu */
476 event_handle_menu(e);
477 } else if (e->type == FocusIn) {
478 if (e->xfocus.detail == NotifyPointerRoot ||
479 e->xfocus.detail == NotifyDetailNone ||
480 e->xfocus.detail == NotifyInferior)
484 ob_debug_type(OB_DEBUG_FOCUS,
485 "Focus went to pointer root/none or to our frame "
488 /* If another FocusIn is in the queue then don't fallback yet. This
489 fixes the fun case of:
490 window map -> send focusin
491 window unmap -> get focusout
492 window map -> send focusin
493 get first focus out -> fall back to something (new window
494 hasn't received focus yet, so something else) -> send focusin
495 which means the "something else" is the last thing to get a
496 focusin sent to it, so the new window doesn't end up with focus.
498 But if the other focus in is something like PointerRoot then we
499 still want to fall back.
501 if (XCheckIfEvent(ob_display, &ce, event_look_for_focusin_client,
504 XPutBackEvent(ob_display, &ce);
505 ob_debug_type(OB_DEBUG_FOCUS,
506 " but another FocusIn is coming\n");
508 /* Focus has been reverted to the root window, nothing, or to
511 FocusOut events come after UnmapNotify, so we don't need to
512 worry about focusing an invalid window
515 /* In this case we know focus is in our screen */
516 if (e->xfocus.detail == NotifyInferior)
517 focus_left_screen = FALSE;
519 if (!focus_left_screen)
520 focus_fallback(TRUE);
523 else if (client != focus_client) {
524 focus_left_screen = FALSE;
525 frame_adjust_focus(client->frame, TRUE);
526 focus_set_client(client);
527 client_calc_layer(client);
528 client_bring_helper_windows(client);
530 } else if (e->type == FocusOut) {
531 gboolean nomove = FALSE;
534 /* Look for the followup FocusIn */
535 if (!XCheckIfEvent(ob_display, &ce, event_look_for_focusin, NULL)) {
536 /* There is no FocusIn, this means focus went to a window that
537 is not being managed, or a window on another screen. */
541 xerror_set_ignore(TRUE);
542 if (XGetInputFocus(ob_display, &win, &i) != 0 &&
543 XGetGeometry(ob_display, win, &root, &i,&i,&u,&u,&u,&u) != 0 &&
544 root != RootWindow(ob_display, ob_screen))
546 ob_debug_type(OB_DEBUG_FOCUS,
547 "Focus went to another screen !\n");
548 focus_left_screen = TRUE;
551 ob_debug_type(OB_DEBUG_FOCUS,
552 "Focus went to a black hole !\n");
553 xerror_set_ignore(FALSE);
554 /* nothing is focused */
555 focus_set_client(NULL);
556 } else if (ce.xany.window == e->xany.window) {
557 ob_debug_type(OB_DEBUG_FOCUS, "Focus didn't go anywhere\n");
558 /* If focus didn't actually move anywhere, there is nothing to do*/
561 /* Focus did move, so process the FocusIn event */
562 ObEventData ed = { .ignored = FALSE };
563 event_process(&ce, &ed);
565 /* The FocusIn was ignored, this means it was on a window
566 that isn't a client. */
567 ob_debug_type(OB_DEBUG_FOCUS,
568 "Focus went to an unmanaged window 0x%x !\n",
570 focus_fallback(TRUE);
574 if (client && !nomove) {
575 frame_adjust_focus(client->frame, FALSE);
576 focus_set_client(NULL);
577 /* focus_set_client has already been called for sure */
578 client_calc_layer(client);
580 } else if (timewinclients)
581 event_handle_user_time_window_clients(timewinclients, e);
583 event_handle_client(client, e);
585 event_handle_dockapp(dockapp, e);
587 event_handle_dock(dock, e);
588 else if (window == RootWindow(ob_display, ob_screen))
589 event_handle_root(e);
590 else if (e->type == MapRequest)
591 client_manage(window);
592 else if (e->type == ClientMessage) {
593 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
594 windows that are not managed yet. */
595 if (e->xclient.message_type == prop_atoms.net_request_frame_extents) {
596 /* Pretend to manage the client, getting information used to
597 determine its decorations */
598 ObClient *c = client_fake_manage(e->xclient.window);
601 /* set the frame extents on the window */
602 vals[0] = c->frame->size.left;
603 vals[1] = c->frame->size.right;
604 vals[2] = c->frame->size.top;
605 vals[3] = c->frame->size.bottom;
606 PROP_SETA32(e->xclient.window, net_frame_extents,
609 /* Free the pretend client */
610 client_fake_unmanage(c);
613 else if (e->type == ConfigureRequest) {
614 /* unhandled configure requests must be used to configure the
618 xwc.x = e->xconfigurerequest.x;
619 xwc.y = e->xconfigurerequest.y;
620 xwc.width = e->xconfigurerequest.width;
621 xwc.height = e->xconfigurerequest.height;
622 xwc.border_width = e->xconfigurerequest.border_width;
623 xwc.sibling = e->xconfigurerequest.above;
624 xwc.stack_mode = e->xconfigurerequest.detail;
626 /* we are not to be held responsible if someone sends us an
628 xerror_set_ignore(TRUE);
629 XConfigureWindow(ob_display, window,
630 e->xconfigurerequest.value_mask, &xwc);
631 xerror_set_ignore(FALSE);
634 else if (extensions_sync &&
635 e->type == extensions_sync_event_basep + XSyncAlarmNotify)
637 XSyncAlarmNotifyEvent *se = (XSyncAlarmNotifyEvent*)e;
638 if (se->alarm == moveresize_alarm && moveresize_in_progress)
643 if (e->type == ButtonPress || e->type == ButtonRelease ||
644 e->type == MotionNotify || e->type == KeyPress ||
645 e->type == KeyRelease)
647 event_handle_user_input(client, e);
650 /* if something happens and it's not from an XEvent, then we don't know
652 event_curtime = CurrentTime;
655 static void event_handle_root(XEvent *e)
661 ob_debug("Another WM has requested to replace us. Exiting.\n");
666 if (e->xclient.format != 32) break;
668 msgtype = e->xclient.message_type;
669 if (msgtype == prop_atoms.net_current_desktop) {
670 guint d = e->xclient.data.l[0];
671 if (d < screen_num_desktops) {
672 event_curtime = e->xclient.data.l[1];
673 if (event_curtime == 0)
674 ob_debug_type(OB_DEBUG_APP_BUGS,
675 "_NET_CURRENT_DESKTOP message is missing "
677 screen_set_desktop(d, TRUE);
679 } else if (msgtype == prop_atoms.net_number_of_desktops) {
680 guint d = e->xclient.data.l[0];
682 screen_set_num_desktops(d);
683 } else if (msgtype == prop_atoms.net_showing_desktop) {
684 screen_show_desktop(e->xclient.data.l[0] != 0, NULL);
685 } else if (msgtype == prop_atoms.ob_control) {
686 if (e->xclient.data.l[0] == 1)
688 else if (e->xclient.data.l[0] == 2)
693 if (e->xproperty.atom == prop_atoms.net_desktop_names)
694 screen_update_desktop_names();
695 else if (e->xproperty.atom == prop_atoms.net_desktop_layout)
696 screen_update_layout();
698 case ConfigureNotify:
700 XRRUpdateConfiguration(e);
709 void event_enter_client(ObClient *client)
711 g_assert(config_focus_follow);
713 if (client_enter_focusable(client) && client_can_focus(client)) {
714 if (config_focus_delay) {
715 ObFocusDelayData *data;
717 ob_main_loop_timeout_remove(ob_main_loop, focus_delay_func);
719 data = g_new(ObFocusDelayData, 1);
720 data->client = client;
721 data->time = event_curtime;
723 ob_main_loop_timeout_add(ob_main_loop,
726 data, focus_delay_cmp, focus_delay_dest);
728 ObFocusDelayData data;
729 data.client = client;
730 data.time = event_curtime;
731 focus_delay_func(&data);
736 static void event_handle_user_time_window_clients(GSList *l, XEvent *e)
738 g_assert(e->type == PropertyNotify);
739 if (e->xproperty.atom == prop_atoms.net_wm_user_time) {
740 for (; l; l = g_slist_next(l))
741 client_update_user_time(l->data);
745 static void event_handle_client(ObClient *client, XEvent *e)
750 static gint px = -1, py = -1;
755 /* save where the press occured for the first button pressed */
757 pb = e->xbutton.button;
762 /* Wheel buttons don't draw because they are an instant click, so it
763 is a waste of resources to go drawing it.
764 if the user is doing an intereactive thing, or has a menu open then
765 the mouse is grabbed (possibly) and if we get these events we don't
766 want to deal with them
768 if (!(e->xbutton.button == 4 || e->xbutton.button == 5) &&
769 !keyboard_interactively_grabbed() &&
772 /* use where the press occured */
773 con = frame_context(client, e->xbutton.window, px, py);
774 con = mouse_button_frame_context(con, e->xbutton.button);
776 if (e->type == ButtonRelease && e->xbutton.button == pb)
777 pb = 0, px = py = -1;
780 case OB_FRAME_CONTEXT_MAXIMIZE:
781 client->frame->max_press = (e->type == ButtonPress);
782 framerender_frame(client->frame);
784 case OB_FRAME_CONTEXT_CLOSE:
785 client->frame->close_press = (e->type == ButtonPress);
786 framerender_frame(client->frame);
788 case OB_FRAME_CONTEXT_ICONIFY:
789 client->frame->iconify_press = (e->type == ButtonPress);
790 framerender_frame(client->frame);
792 case OB_FRAME_CONTEXT_ALLDESKTOPS:
793 client->frame->desk_press = (e->type == ButtonPress);
794 framerender_frame(client->frame);
796 case OB_FRAME_CONTEXT_SHADE:
797 client->frame->shade_press = (e->type == ButtonPress);
798 framerender_frame(client->frame);
801 /* nothing changes with clicks for any other contexts */
807 con = frame_context(client, e->xmotion.window,
808 e->xmotion.x, e->xmotion.y);
810 case OB_FRAME_CONTEXT_TITLEBAR:
811 /* we've left the button area inside the titlebar */
812 if (client->frame->max_hover || client->frame->desk_hover ||
813 client->frame->shade_hover || client->frame->iconify_hover ||
814 client->frame->close_hover)
816 client->frame->max_hover = FALSE;
817 client->frame->desk_hover = FALSE;
818 client->frame->shade_hover = FALSE;
819 client->frame->iconify_hover = FALSE;
820 client->frame->close_hover = FALSE;
821 frame_adjust_state(client->frame);
824 case OB_FRAME_CONTEXT_MAXIMIZE:
825 if (!client->frame->max_hover) {
826 client->frame->max_hover = TRUE;
827 frame_adjust_state(client->frame);
830 case OB_FRAME_CONTEXT_ALLDESKTOPS:
831 if (!client->frame->desk_hover) {
832 client->frame->desk_hover = TRUE;
833 frame_adjust_state(client->frame);
836 case OB_FRAME_CONTEXT_SHADE:
837 if (!client->frame->shade_hover) {
838 client->frame->shade_hover = TRUE;
839 frame_adjust_state(client->frame);
842 case OB_FRAME_CONTEXT_ICONIFY:
843 if (!client->frame->iconify_hover) {
844 client->frame->iconify_hover = TRUE;
845 frame_adjust_state(client->frame);
848 case OB_FRAME_CONTEXT_CLOSE:
849 if (!client->frame->close_hover) {
850 client->frame->close_hover = TRUE;
851 frame_adjust_state(client->frame);
859 con = frame_context(client, e->xcrossing.window,
860 e->xcrossing.x, e->xcrossing.y);
862 case OB_FRAME_CONTEXT_MAXIMIZE:
863 client->frame->max_hover = FALSE;
864 frame_adjust_state(client->frame);
866 case OB_FRAME_CONTEXT_ALLDESKTOPS:
867 client->frame->desk_hover = FALSE;
868 frame_adjust_state(client->frame);
870 case OB_FRAME_CONTEXT_SHADE:
871 client->frame->shade_hover = FALSE;
872 frame_adjust_state(client->frame);
874 case OB_FRAME_CONTEXT_ICONIFY:
875 client->frame->iconify_hover = FALSE;
876 frame_adjust_state(client->frame);
878 case OB_FRAME_CONTEXT_CLOSE:
879 client->frame->close_hover = FALSE;
880 frame_adjust_state(client->frame);
882 case OB_FRAME_CONTEXT_FRAME:
883 /* When the mouse leaves an animating window, don't use the
884 corresponding enter events. Pretend like the animating window
885 doesn't even exist..! */
886 if (frame_iconify_animating(client->frame))
887 event_ignore_queued_enters();
889 ob_debug_type(OB_DEBUG_FOCUS,
890 "%sNotify mode %d detail %d on %lx\n",
891 (e->type == EnterNotify ? "Enter" : "Leave"),
893 e->xcrossing.detail, (client?client->window:0));
894 if (keyboard_interactively_grabbed())
896 if (config_focus_follow && config_focus_delay &&
897 /* leave inferior events can happen when the mouse goes onto
898 the window's border and then into the window before the
900 e->xcrossing.detail != NotifyInferior)
902 ob_main_loop_timeout_remove_data(ob_main_loop,
913 gboolean nofocus = FALSE;
915 if (ignore_enter_focus) {
916 ignore_enter_focus--;
920 con = frame_context(client, e->xcrossing.window,
921 e->xcrossing.x, e->xcrossing.y);
923 case OB_FRAME_CONTEXT_MAXIMIZE:
924 client->frame->max_hover = TRUE;
925 frame_adjust_state(client->frame);
927 case OB_FRAME_CONTEXT_ALLDESKTOPS:
928 client->frame->desk_hover = TRUE;
929 frame_adjust_state(client->frame);
931 case OB_FRAME_CONTEXT_SHADE:
932 client->frame->shade_hover = TRUE;
933 frame_adjust_state(client->frame);
935 case OB_FRAME_CONTEXT_ICONIFY:
936 client->frame->iconify_hover = TRUE;
937 frame_adjust_state(client->frame);
939 case OB_FRAME_CONTEXT_CLOSE:
940 client->frame->close_hover = TRUE;
941 frame_adjust_state(client->frame);
943 case OB_FRAME_CONTEXT_FRAME:
944 if (keyboard_interactively_grabbed())
946 if (e->xcrossing.mode == NotifyGrab ||
947 e->xcrossing.mode == NotifyUngrab ||
948 /*ignore enters when we're already in the window */
949 e->xcrossing.detail == NotifyInferior)
951 ob_debug_type(OB_DEBUG_FOCUS,
952 "%sNotify mode %d detail %d on %lx IGNORED\n",
953 (e->type == EnterNotify ? "Enter" : "Leave"),
955 e->xcrossing.detail, client?client->window:0);
957 ob_debug_type(OB_DEBUG_FOCUS,
958 "%sNotify mode %d detail %d on %lx, "
959 "focusing window: %d\n",
960 (e->type == EnterNotify ? "Enter" : "Leave"),
962 e->xcrossing.detail, (client?client->window:0),
964 if (!nofocus && config_focus_follow)
965 event_enter_client(client);
973 case ConfigureRequest:
975 /* dont compress these unless you're going to watch for property
976 notifies in between (these can change what the configure would
978 also you can't compress stacking events
983 /* if nothing is changed, then a configurenotify is needed */
984 gboolean config = TRUE;
988 w = client->area.width;
989 h = client->area.height;
991 ob_debug("ConfigureRequest desktop %d wmstate %d visibile %d\n",
992 screen_desktop, client->wmstate, client->frame->visible);
994 if (e->xconfigurerequest.value_mask & CWBorderWidth)
995 if (client->border_width != e->xconfigurerequest.border_width) {
996 client->border_width = e->xconfigurerequest.border_width;
997 /* if only the border width is changing, then it's not needed*/
1002 if (e->xconfigurerequest.value_mask & CWStackMode) {
1003 ObClient *sibling = NULL;
1005 /* get the sibling */
1006 if (e->xconfigurerequest.value_mask & CWSibling) {
1008 win = g_hash_table_lookup(window_map,
1009 &e->xconfigurerequest.above);
1010 if (WINDOW_IS_CLIENT(win) && WINDOW_AS_CLIENT(win) != client)
1011 sibling = WINDOW_AS_CLIENT(win);
1014 /* activate it rather than just focus it */
1015 stacking_restack_request(client, sibling,
1016 e->xconfigurerequest.detail, TRUE);
1018 /* if a stacking change is requested then it is needed */
1022 /* don't allow clients to move shaded windows (fvwm does this) */
1023 if (client->shaded && (e->xconfigurerequest.value_mask & CWX ||
1024 e->xconfigurerequest.value_mask & CWY))
1026 e->xconfigurerequest.value_mask &= ~CWX;
1027 e->xconfigurerequest.value_mask &= ~CWY;
1029 /* if the client tried to move and we aren't letting it then a
1030 synthetic event is needed */
1034 if (e->xconfigurerequest.value_mask & CWX ||
1035 e->xconfigurerequest.value_mask & CWY ||
1036 e->xconfigurerequest.value_mask & CWWidth ||
1037 e->xconfigurerequest.value_mask & CWHeight)
1039 if (e->xconfigurerequest.value_mask & CWX)
1040 x = e->xconfigurerequest.x;
1041 if (e->xconfigurerequest.value_mask & CWY)
1042 y = e->xconfigurerequest.y;
1043 if (e->xconfigurerequest.value_mask & CWWidth)
1044 w = e->xconfigurerequest.width;
1045 if (e->xconfigurerequest.value_mask & CWHeight)
1046 h = e->xconfigurerequest.height;
1048 /* if a new position or size is requested, then a configure is
1053 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d\n",
1054 e->xconfigurerequest.value_mask & CWX, x,
1055 e->xconfigurerequest.value_mask & CWY, y,
1056 e->xconfigurerequest.value_mask & CWWidth, w,
1057 e->xconfigurerequest.value_mask & CWHeight, h);
1059 /* check for broken apps moving to their root position
1061 XXX remove this some day...that would be nice. right now all
1062 kde apps do this when they try activate themselves on another
1063 desktop. eg. open amarok window on desktop 1, switch to desktop
1064 2, click amarok tray icon. it will move by its decoration size.
1066 if (x != client->area.x &&
1067 x == (client->frame->area.x + client->frame->size.left -
1068 (gint)client->border_width) &&
1069 y != client->area.y &&
1070 y == (client->frame->area.y + client->frame->size.top -
1071 (gint)client->border_width))
1073 ob_debug_type(OB_DEBUG_APP_BUGS,
1074 "Application %s is trying to move via "
1075 "ConfigureRequest to it's root window position "
1076 "but it is not using StaticGravity\n",
1084 client_find_onscreen(client, &x, &y, w, h, FALSE);
1085 client_configure_full(client, x, y, w, h, FALSE, TRUE);
1090 if (client->ignore_unmaps) {
1091 client->ignore_unmaps--;
1094 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1095 "ignores left %d\n",
1096 client->window, e->xunmap.event, e->xunmap.from_configure,
1097 client->ignore_unmaps);
1098 client_unmanage(client);
1101 ob_debug("DestroyNotify for window 0x%x\n", client->window);
1102 client_unmanage(client);
1104 case ReparentNotify:
1105 /* this is when the client is first taken captive in the frame */
1106 if (e->xreparent.parent == client->frame->plate) break;
1109 This event is quite rare and is usually handled in unmapHandler.
1110 However, if the window is unmapped when the reparent event occurs,
1111 the window manager never sees it because an unmap event is not sent
1112 to an already unmapped window.
1115 /* we don't want the reparent event, put it back on the stack for the
1116 X server to deal with after we unmanage the window */
1117 XPutBackEvent(ob_display, e);
1119 ob_debug("ReparentNotify for window 0x%x\n", client->window);
1120 client_unmanage(client);
1123 ob_debug("MapRequest for 0x%lx\n", client->window);
1124 if (!client->iconic) break; /* this normally doesn't happen, but if it
1125 does, we don't want it!
1126 it can happen now when the window is on
1127 another desktop, but we still don't
1129 client_activate(client, FALSE, TRUE);
1132 /* validate cuz we query stuff off the client here */
1133 if (!client_validate(client)) break;
1135 if (e->xclient.format != 32) return;
1137 msgtype = e->xclient.message_type;
1138 if (msgtype == prop_atoms.wm_change_state) {
1139 /* compress changes into a single change */
1140 while (XCheckTypedWindowEvent(ob_display, client->window,
1142 /* XXX: it would be nice to compress ALL messages of a
1143 type, not just messages in a row without other
1144 message types between. */
1145 if (ce.xclient.message_type != msgtype) {
1146 XPutBackEvent(ob_display, &ce);
1149 e->xclient = ce.xclient;
1151 client_set_wm_state(client, e->xclient.data.l[0]);
1152 } else if (msgtype == prop_atoms.net_wm_desktop) {
1153 /* compress changes into a single change */
1154 while (XCheckTypedWindowEvent(ob_display, client->window,
1156 /* XXX: it would be nice to compress ALL messages of a
1157 type, not just messages in a row without other
1158 message types between. */
1159 if (ce.xclient.message_type != msgtype) {
1160 XPutBackEvent(ob_display, &ce);
1163 e->xclient = ce.xclient;
1165 if ((unsigned)e->xclient.data.l[0] < screen_num_desktops ||
1166 (unsigned)e->xclient.data.l[0] == DESKTOP_ALL)
1167 client_set_desktop(client, (unsigned)e->xclient.data.l[0],
1169 } else if (msgtype == prop_atoms.net_wm_state) {
1170 /* can't compress these */
1171 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1172 (e->xclient.data.l[0] == 0 ? "Remove" :
1173 e->xclient.data.l[0] == 1 ? "Add" :
1174 e->xclient.data.l[0] == 2 ? "Toggle" : "INVALID"),
1175 e->xclient.data.l[1], e->xclient.data.l[2],
1177 client_set_state(client, e->xclient.data.l[0],
1178 e->xclient.data.l[1], e->xclient.data.l[2]);
1179 } else if (msgtype == prop_atoms.net_close_window) {
1180 ob_debug("net_close_window for 0x%lx\n", client->window);
1181 client_close(client);
1182 } else if (msgtype == prop_atoms.net_active_window) {
1183 ob_debug("net_active_window for 0x%lx source=%s\n",
1185 (e->xclient.data.l[0] == 0 ? "unknown" :
1186 (e->xclient.data.l[0] == 1 ? "application" :
1187 (e->xclient.data.l[0] == 2 ? "user" : "INVALID"))));
1188 /* XXX make use of data.l[2] !? */
1189 event_curtime = e->xclient.data.l[1];
1190 if (event_curtime == 0)
1191 ob_debug_type(OB_DEBUG_APP_BUGS,
1192 "_NET_ACTIVE_WINDOW message for window %s is "
1193 "missing a timestamp\n", client->title);
1194 client_activate(client, FALSE,
1195 (e->xclient.data.l[0] == 0 ||
1196 e->xclient.data.l[0] == 2));
1197 } else if (msgtype == prop_atoms.net_wm_moveresize) {
1198 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1199 client->window, e->xclient.data.l[2]);
1200 if ((Atom)e->xclient.data.l[2] ==
1201 prop_atoms.net_wm_moveresize_size_topleft ||
1202 (Atom)e->xclient.data.l[2] ==
1203 prop_atoms.net_wm_moveresize_size_top ||
1204 (Atom)e->xclient.data.l[2] ==
1205 prop_atoms.net_wm_moveresize_size_topright ||
1206 (Atom)e->xclient.data.l[2] ==
1207 prop_atoms.net_wm_moveresize_size_right ||
1208 (Atom)e->xclient.data.l[2] ==
1209 prop_atoms.net_wm_moveresize_size_right ||
1210 (Atom)e->xclient.data.l[2] ==
1211 prop_atoms.net_wm_moveresize_size_bottomright ||
1212 (Atom)e->xclient.data.l[2] ==
1213 prop_atoms.net_wm_moveresize_size_bottom ||
1214 (Atom)e->xclient.data.l[2] ==
1215 prop_atoms.net_wm_moveresize_size_bottomleft ||
1216 (Atom)e->xclient.data.l[2] ==
1217 prop_atoms.net_wm_moveresize_size_left ||
1218 (Atom)e->xclient.data.l[2] ==
1219 prop_atoms.net_wm_moveresize_move ||
1220 (Atom)e->xclient.data.l[2] ==
1221 prop_atoms.net_wm_moveresize_size_keyboard ||
1222 (Atom)e->xclient.data.l[2] ==
1223 prop_atoms.net_wm_moveresize_move_keyboard) {
1225 moveresize_start(client, e->xclient.data.l[0],
1226 e->xclient.data.l[1], e->xclient.data.l[3],
1227 e->xclient.data.l[2]);
1229 else if ((Atom)e->xclient.data.l[2] ==
1230 prop_atoms.net_wm_moveresize_cancel)
1231 moveresize_end(TRUE);
1232 } else if (msgtype == prop_atoms.net_moveresize_window) {
1233 gint grav, x, y, w, h;
1235 if (e->xclient.data.l[0] & 0xff)
1236 grav = e->xclient.data.l[0] & 0xff;
1238 grav = client->gravity;
1240 if (e->xclient.data.l[0] & 1 << 8)
1241 x = e->xclient.data.l[1];
1244 if (e->xclient.data.l[0] & 1 << 9)
1245 y = e->xclient.data.l[2];
1248 if (e->xclient.data.l[0] & 1 << 10)
1249 w = e->xclient.data.l[3];
1251 w = client->area.width;
1252 if (e->xclient.data.l[0] & 1 << 11)
1253 h = e->xclient.data.l[4];
1255 h = client->area.height;
1257 ob_debug("MOVERESIZE x %d %d y %d %d\n",
1258 e->xclient.data.l[0] & 1 << 8, x,
1259 e->xclient.data.l[0] & 1 << 9, y);
1260 client_convert_gravity(client, grav, &x, &y, w, h);
1261 client_find_onscreen(client, &x, &y, w, h, FALSE);
1262 client_configure(client, x, y, w, h, FALSE, TRUE);
1263 } else if (msgtype == prop_atoms.net_restack_window) {
1264 if (e->xclient.data.l[0] != 2) {
1265 ob_debug_type(OB_DEBUG_APP_BUGS,
1266 "_NET_RESTACK_WINDOW sent for window %s with "
1267 "invalid source indication %ld\n",
1268 client->title, e->xclient.data.l[0]);
1270 ObClient *sibling = NULL;
1271 if (e->xclient.data.l[1]) {
1272 ObWindow *win = g_hash_table_lookup(window_map,
1273 &e->xclient.data.l[1]);
1274 if (WINDOW_IS_CLIENT(win) &&
1275 WINDOW_AS_CLIENT(win) != client)
1277 sibling = WINDOW_AS_CLIENT(win);
1279 if (sibling == NULL)
1280 ob_debug_type(OB_DEBUG_APP_BUGS,
1281 "_NET_RESTACK_WINDOW sent for window %s "
1282 "with invalid sibling 0x%x\n",
1283 client->title, e->xclient.data.l[1]);
1285 if (e->xclient.data.l[2] == Below ||
1286 e->xclient.data.l[2] == BottomIf ||
1287 e->xclient.data.l[2] == Above ||
1288 e->xclient.data.l[2] == TopIf ||
1289 e->xclient.data.l[2] == Opposite)
1291 /* just raise, don't activate */
1292 stacking_restack_request(client, sibling,
1293 e->xclient.data.l[2], FALSE);
1294 /* send a synthetic ConfigureNotify, cuz this is supposed
1295 to be like a ConfigureRequest. */
1296 client_configure_full(client, client->area.x,
1299 client->area.height,
1302 ob_debug_type(OB_DEBUG_APP_BUGS,
1303 "_NET_RESTACK_WINDOW sent for window %s "
1304 "with invalid detail %d\n",
1305 client->title, e->xclient.data.l[2]);
1309 case PropertyNotify:
1310 /* validate cuz we query stuff off the client here */
1311 if (!client_validate(client)) break;
1313 /* compress changes to a single property into a single change */
1314 while (XCheckTypedWindowEvent(ob_display, client->window,
1318 /* XXX: it would be nice to compress ALL changes to a property,
1319 not just changes in a row without other props between. */
1321 a = ce.xproperty.atom;
1322 b = e->xproperty.atom;
1326 if ((a == prop_atoms.net_wm_name ||
1327 a == prop_atoms.wm_name ||
1328 a == prop_atoms.net_wm_icon_name ||
1329 a == prop_atoms.wm_icon_name)
1331 (b == prop_atoms.net_wm_name ||
1332 b == prop_atoms.wm_name ||
1333 b == prop_atoms.net_wm_icon_name ||
1334 b == prop_atoms.wm_icon_name)) {
1337 if (a == prop_atoms.net_wm_icon &&
1338 b == prop_atoms.net_wm_icon)
1341 XPutBackEvent(ob_display, &ce);
1345 msgtype = e->xproperty.atom;
1346 if (msgtype == XA_WM_NORMAL_HINTS) {
1347 client_update_normal_hints(client);
1348 /* normal hints can make a window non-resizable */
1349 client_setup_decor_and_functions(client);
1350 } else if (msgtype == XA_WM_HINTS) {
1351 client_update_wmhints(client);
1352 } else if (msgtype == XA_WM_TRANSIENT_FOR) {
1353 client_update_transient_for(client);
1354 client_get_type_and_transientness(client);
1355 /* type may have changed, so update the layer */
1356 client_calc_layer(client);
1357 client_setup_decor_and_functions(client);
1358 } else if (msgtype == prop_atoms.net_wm_name ||
1359 msgtype == prop_atoms.wm_name ||
1360 msgtype == prop_atoms.net_wm_icon_name ||
1361 msgtype == prop_atoms.wm_icon_name) {
1362 client_update_title(client);
1363 } else if (msgtype == prop_atoms.wm_protocols) {
1364 client_update_protocols(client);
1365 client_setup_decor_and_functions(client);
1367 else if (msgtype == prop_atoms.net_wm_strut) {
1368 client_update_strut(client);
1370 else if (msgtype == prop_atoms.net_wm_icon) {
1371 client_update_icons(client);
1373 else if (msgtype == prop_atoms.net_wm_icon_geometry) {
1374 client_update_icon_geometry(client);
1376 else if (msgtype == prop_atoms.net_wm_user_time) {
1377 client_update_user_time(client);
1379 else if (msgtype == prop_atoms.net_wm_user_time_window) {
1380 client_update_user_time_window(client);
1383 else if (msgtype == prop_atoms.net_wm_sync_request_counter) {
1384 client_update_sync_request_counter(client);
1387 case ColormapNotify:
1388 client_update_colormap(client, e->xcolormap.colormap);
1393 if (extensions_shape && e->type == extensions_shape_event_basep) {
1394 client->shaped = ((XShapeEvent*)e)->shaped;
1395 frame_adjust_shape(client->frame);
1401 static void event_handle_dock(ObDock *s, XEvent *e)
1405 if (e->xbutton.button == 1)
1406 stacking_raise(DOCK_AS_WINDOW(s));
1407 else if (e->xbutton.button == 2)
1408 stacking_lower(DOCK_AS_WINDOW(s));
1419 static void event_handle_dockapp(ObDockApp *app, XEvent *e)
1423 dock_app_drag(app, &e->xmotion);
1426 if (app->ignore_unmaps) {
1427 app->ignore_unmaps--;
1430 dock_remove(app, TRUE);
1433 dock_remove(app, FALSE);
1435 case ReparentNotify:
1436 dock_remove(app, FALSE);
1438 case ConfigureNotify:
1439 dock_app_configure(app, e->xconfigure.width, e->xconfigure.height);
1444 static ObMenuFrame* find_active_menu()
1447 ObMenuFrame *ret = NULL;
1449 for (it = menu_frame_visible; it; it = g_list_next(it)) {
1458 static ObMenuFrame* find_active_or_last_menu()
1460 ObMenuFrame *ret = NULL;
1462 ret = find_active_menu();
1463 if (!ret && menu_frame_visible)
1464 ret = menu_frame_visible->data;
1468 static gboolean event_handle_menu_keyboard(XEvent *ev)
1470 guint keycode, state;
1473 gboolean ret = TRUE;
1475 keycode = ev->xkey.keycode;
1476 state = ev->xkey.state;
1477 unikey = translate_unichar(keycode);
1479 frame = find_active_or_last_menu();
1483 else if (keycode == ob_keycode(OB_KEY_ESCAPE) && state == 0) {
1484 /* Escape closes the active menu */
1485 menu_frame_hide(frame);
1488 else if (keycode == ob_keycode(OB_KEY_RETURN) && (state == 0 ||
1489 state == ControlMask))
1491 /* Enter runs the active item or goes into the submenu.
1492 Control-Enter runs it without closing the menu. */
1494 menu_frame_select_next(frame->child);
1496 menu_entry_frame_execute(frame->selected, state, ev->xkey.time);
1499 else if (keycode == ob_keycode(OB_KEY_LEFT) && ev->xkey.state == 0) {
1500 /* Left goes to the parent menu */
1501 menu_frame_select(frame, NULL, TRUE);
1504 else if (keycode == ob_keycode(OB_KEY_RIGHT) && ev->xkey.state == 0) {
1505 /* Right goes to the selected submenu */
1506 if (frame->child) menu_frame_select_next(frame->child);
1509 else if (keycode == ob_keycode(OB_KEY_UP) && state == 0) {
1510 menu_frame_select_previous(frame);
1513 else if (keycode == ob_keycode(OB_KEY_DOWN) && state == 0) {
1514 menu_frame_select_next(frame);
1517 /* keyboard accelerator shortcuts. */
1518 else if (ev->xkey.state == 0 &&
1519 /* was it a valid key? */
1521 /* don't bother if the menu is empty. */
1526 ObMenuEntryFrame *found = NULL;
1527 guint num_found = 0;
1529 /* start after the selected one */
1530 start = frame->entries;
1531 if (frame->selected) {
1532 for (it = start; frame->selected != it->data; it = g_list_next(it))
1533 g_assert(it != NULL); /* nothing was selected? */
1534 /* next with wraparound */
1535 start = g_list_next(it);
1536 if (start == NULL) start = frame->entries;
1541 ObMenuEntryFrame *e = it->data;
1542 gunichar entrykey = 0;
1544 if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL)
1545 entrykey = e->entry->data.normal.shortcut;
1546 else if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
1547 entrykey = e->entry->data.submenu.submenu->shortcut;
1549 if (unikey == entrykey) {
1550 if (found == NULL) found = e;
1554 /* next with wraparound */
1555 it = g_list_next(it);
1556 if (it == NULL) it = frame->entries;
1557 } while (it != start);
1560 if (found->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
1563 menu_frame_select(frame, found, TRUE);
1564 usleep(50000); /* highlight the item for a short bit so the
1565 user can see what happened */
1566 menu_entry_frame_execute(found, state, ev->xkey.time);
1568 menu_frame_select(frame, found, TRUE);
1570 menu_frame_select_next(frame->child);
1581 static gboolean event_handle_menu(XEvent *ev)
1584 ObMenuEntryFrame *e;
1585 gboolean ret = TRUE;
1589 if ((ev->xbutton.button < 4 || ev->xbutton.button > 5)
1592 if ((e = menu_entry_frame_under(ev->xbutton.x_root,
1593 ev->xbutton.y_root)))
1594 menu_entry_frame_execute(e, ev->xbutton.state,
1597 menu_frame_hide_all();
1601 if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window))) {
1602 if (e->ignore_enters)
1605 menu_frame_select(e->frame, e, FALSE);
1609 if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window)) &&
1610 (f = find_active_menu()) && f->selected == e &&
1611 e->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU)
1613 menu_frame_select(e->frame, NULL, FALSE);
1617 if ((e = menu_entry_frame_under(ev->xmotion.x_root,
1618 ev->xmotion.y_root)))
1619 menu_frame_select(e->frame, e, FALSE);
1622 ret = event_handle_menu_keyboard(ev);
1628 static void event_handle_user_input(ObClient *client, XEvent *e)
1630 g_assert(e->type == ButtonPress || e->type == ButtonRelease ||
1631 e->type == MotionNotify || e->type == KeyPress ||
1632 e->type == KeyRelease);
1634 if (menu_frame_visible) {
1635 if (event_handle_menu(e))
1636 /* don't use the event if the menu used it, but if the menu
1637 didn't use it and it's a keypress that is bound, it will
1638 close the menu and be used */
1642 /* if the keyboard interactive action uses the event then dont
1643 use it for bindings. likewise is moveresize uses the event. */
1644 if (!keyboard_process_interactive_grab(e, &client) &&
1645 !(moveresize_in_progress && moveresize_event(e)))
1647 if (moveresize_in_progress)
1648 /* make further actions work on the client being
1650 client = moveresize_client;
1652 menu_can_hide = FALSE;
1653 ob_main_loop_timeout_add(ob_main_loop,
1654 config_menu_hide_delay * 1000,
1655 menu_hide_delay_func,
1656 NULL, g_direct_equal, NULL);
1658 if (e->type == ButtonPress ||
1659 e->type == ButtonRelease ||
1660 e->type == MotionNotify)
1662 /* the frame may not be "visible" but they can still click on it
1663 in the case where it is animating before disappearing */
1664 if (!client || !frame_iconify_animating(client->frame))
1665 mouse_event(client, e);
1666 } else if (e->type == KeyPress) {
1667 keyboard_event((focus_cycle_target ? focus_cycle_target :
1668 (client ? client : focus_client)), e);
1673 static gboolean menu_hide_delay_func(gpointer data)
1675 menu_can_hide = TRUE;
1676 return FALSE; /* no repeat */
1679 static void focus_delay_dest(gpointer data)
1684 static gboolean focus_delay_cmp(gconstpointer d1, gconstpointer d2)
1686 const ObFocusDelayData *f1 = d1;
1687 return f1->client == d2;
1690 static gboolean focus_delay_func(gpointer data)
1692 ObFocusDelayData *d = data;
1693 Time old = event_curtime;
1695 event_curtime = d->time;
1696 if (focus_client != d->client) {
1697 if (client_focus(d->client) && config_focus_raise)
1698 stacking_raise(CLIENT_AS_WINDOW(d->client));
1700 event_curtime = old;
1701 return FALSE; /* no repeat */
1704 static void focus_delay_client_dest(ObClient *client, gpointer data)
1706 ob_main_loop_timeout_remove_data(ob_main_loop, focus_delay_func,
1710 void event_halt_focus_delay()
1712 ob_main_loop_timeout_remove(ob_main_loop, focus_delay_func);
1715 void event_ignore_queued_enters()
1717 GSList *saved = NULL, *it;
1720 XSync(ob_display, FALSE);
1722 /* count the events */
1724 e = g_new(XEvent, 1);
1725 if (XCheckTypedEvent(ob_display, EnterNotify, e)) {
1728 win = g_hash_table_lookup(window_map, &e->xany.window);
1729 if (win && WINDOW_IS_CLIENT(win))
1730 ++ignore_enter_focus;
1732 saved = g_slist_append(saved, e);
1738 /* put the events back */
1739 for (it = saved; it; it = g_slist_next(it)) {
1740 XPutBackEvent(ob_display, it->data);
1743 g_slist_free(saved);
1746 gboolean event_time_after(Time t1, Time t2)
1748 g_assert(t1 != CurrentTime);
1749 g_assert(t2 != CurrentTime);
1752 Timestamp values wrap around (after about 49.7 days). The server, given
1753 its current time is represented by timestamp T, always interprets
1754 timestamps from clients by treating half of the timestamp space as being
1755 later in time than T.
1756 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
1759 /* TIME_HALF is half of the number space of a Time type variable */
1760 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
1762 if (t2 >= TIME_HALF)
1763 /* t2 is in the second half so t1 might wrap around and be smaller than
1765 return t1 >= t2 || t1 < (t2 + TIME_HALF);
1767 /* t2 is in the first half so t1 has to come after it */
1768 return t1 >= t2 && t1 < (t2 + TIME_HALF);