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.
33 #include "menuframe.h"
39 #include "framerender.h"
41 #include "focus_cycle.h"
42 #include "moveresize.h"
45 #include "extensions.h"
46 #include "translate.h"
49 #include <X11/Xatom.h>
52 #ifdef HAVE_SYS_SELECT_H
53 # include <sys/select.h>
59 # include <unistd.h> /* for usleep() */
62 # include <X11/XKBlib.h>
66 #include <X11/ICE/ICElib.h>
80 static void event_process(const XEvent *e, gpointer data);
81 static void event_handle_root(XEvent *e);
82 static gboolean event_handle_menu_keyboard(XEvent *e);
83 static gboolean event_handle_menu(XEvent *e);
84 static void event_handle_dock(ObDock *s, XEvent *e);
85 static void event_handle_dockapp(ObDockApp *app, XEvent *e);
86 static void event_handle_client(ObClient *c, XEvent *e);
87 static void event_handle_user_time_window_clients(GSList *l, XEvent *e);
88 static void event_handle_user_input(ObClient *client, XEvent *e);
89 static gboolean is_enter_focus_event_ignored(XEvent *e);
91 static void focus_delay_dest(gpointer data);
92 static gboolean focus_delay_cmp(gconstpointer d1, gconstpointer d2);
93 static gboolean focus_delay_func(gpointer data);
94 static void focus_delay_client_dest(ObClient *client, gpointer data);
96 static gboolean menu_hide_delay_func(gpointer data);
98 /* The time for the current event being processed */
99 Time event_curtime = CurrentTime;
101 static guint ignore_enter_focus = 0;
102 static gboolean menu_can_hide;
103 static gboolean focus_left_screen = FALSE;
106 static void ice_handler(gint fd, gpointer conn)
109 IceProcessMessages(conn, NULL, &b);
112 static void ice_watch(IceConn conn, IcePointer data, Bool opening,
113 IcePointer *watch_data)
118 fd = IceConnectionNumber(conn);
119 ob_main_loop_fd_add(ob_main_loop, fd, ice_handler, conn, NULL);
121 ob_main_loop_fd_remove(ob_main_loop, fd);
127 void event_startup(gboolean reconfig)
129 if (reconfig) return;
131 ob_main_loop_x_add(ob_main_loop, event_process, NULL, NULL);
134 IceAddConnectionWatch(ice_watch, NULL);
137 client_add_destroy_notify(focus_delay_client_dest, NULL);
140 void event_shutdown(gboolean reconfig)
142 if (reconfig) return;
145 IceRemoveConnectionWatch(ice_watch, NULL);
148 client_remove_destroy_notify(focus_delay_client_dest);
151 static Window event_get_window(XEvent *e)
158 window = RootWindow(ob_display, ob_screen);
161 window = e->xmap.window;
164 window = e->xunmap.window;
167 window = e->xdestroywindow.window;
169 case ConfigureRequest:
170 window = e->xconfigurerequest.window;
172 case ConfigureNotify:
173 window = e->xconfigure.window;
177 if (extensions_xkb && e->type == extensions_xkb_event_basep) {
178 switch (((XkbAnyEvent*)e)->xkb_type) {
180 window = ((XkbBellNotifyEvent*)e)->window;
187 if (extensions_sync &&
188 e->type == extensions_sync_event_basep + XSyncAlarmNotify)
193 window = e->xany.window;
198 static void event_set_curtime(XEvent *e)
200 Time t = CurrentTime;
202 /* grab the lasttime and hack up the state */
218 t = e->xproperty.time;
222 t = e->xcrossing.time;
226 if (extensions_sync &&
227 e->type == extensions_sync_event_basep + XSyncAlarmNotify)
229 t = ((XSyncAlarmNotifyEvent*)e)->time;
232 /* if more event types are anticipated, get their timestamp
240 static void event_hack_mods(XEvent *e)
243 XkbStateRec xkb_state;
249 e->xbutton.state = modkeys_only_modifier_masks(e->xbutton.state);
252 e->xkey.state = modkeys_only_modifier_masks(e->xkey.state);
255 e->xkey.state = modkeys_only_modifier_masks(e->xkey.state);
257 if (XkbGetState(ob_display, XkbUseCoreKbd, &xkb_state) == Success) {
258 e->xkey.state = xkb_state.compat_state;
262 /* remove from the state the mask of the modifier key being released,
263 if it is a modifier key being released that is */
264 e->xkey.state &= ~modkeys_keycode_to_mask(e->xkey.keycode);
267 e->xmotion.state = modkeys_only_modifier_masks(e->xmotion.state);
272 static gboolean wanted_focusevent(XEvent *e, gboolean in_client_only)
274 gint mode = e->xfocus.mode;
275 gint detail = e->xfocus.detail;
276 Window win = e->xany.window;
278 if (e->type == FocusIn) {
279 /* These are ones we never want.. */
281 /* This means focus was given by a keyboard/mouse grab. */
282 if (mode == NotifyGrab)
284 /* This means focus was given back from a keyboard/mouse grab. */
285 if (mode == NotifyUngrab)
288 /* These are the ones we want.. */
290 if (win == RootWindow(ob_display, ob_screen)) {
291 /* If looking for a focus in on a client, then always return
292 FALSE for focus in's to the root window */
295 /* This means focus reverted off of a client */
296 else if (detail == NotifyPointerRoot ||
297 detail == NotifyDetailNone ||
298 detail == NotifyInferior)
304 /* It was on a client, was it a valid one?
305 It's possible to get a FocusIn event for a client that was managed
308 if (in_client_only) {
309 ObWindow *w = g_hash_table_lookup(window_map, &e->xfocus.window);
310 if (!w || !WINDOW_IS_CLIENT(w))
314 /* This means focus moved from the root window to a client */
315 if (detail == NotifyVirtual)
317 /* This means focus moved from one client to another */
318 if (detail == NotifyNonlinearVirtual)
324 g_assert(e->type == FocusOut);
326 /* These are ones we never want.. */
328 /* This means focus was taken by a keyboard/mouse grab. */
329 if (mode == NotifyGrab)
332 /* Focus left the root window revertedto state */
333 if (win == RootWindow(ob_display, ob_screen))
336 /* These are the ones we want.. */
338 /* This means focus moved from a client to the root window */
339 if (detail == NotifyVirtual)
341 /* This means focus moved from one client to another */
342 if (detail == NotifyNonlinearVirtual)
350 static Bool event_look_for_focusin(Display *d, XEvent *e, XPointer arg)
352 return e->type == FocusIn && wanted_focusevent(e, FALSE);
355 static Bool event_look_for_focusin_client(Display *d, XEvent *e, XPointer arg)
357 return e->type == FocusIn && wanted_focusevent(e, TRUE);
360 static void print_focusevent(XEvent *e)
362 gint mode = e->xfocus.mode;
363 gint detail = e->xfocus.detail;
364 Window win = e->xany.window;
365 const gchar *modestr, *detailstr;
368 case NotifyNormal: modestr="NotifyNormal"; break;
369 case NotifyGrab: modestr="NotifyGrab"; break;
370 case NotifyUngrab: modestr="NotifyUngrab"; break;
371 case NotifyWhileGrabbed: modestr="NotifyWhileGrabbed"; break;
374 case NotifyAncestor: detailstr="NotifyAncestor"; break;
375 case NotifyVirtual: detailstr="NotifyVirtual"; break;
376 case NotifyInferior: detailstr="NotifyInferior"; break;
377 case NotifyNonlinear: detailstr="NotifyNonlinear"; break;
378 case NotifyNonlinearVirtual: detailstr="NotifyNonlinearVirtual"; break;
379 case NotifyPointer: detailstr="NotifyPointer"; break;
380 case NotifyPointerRoot: detailstr="NotifyPointerRoot"; break;
381 case NotifyDetailNone: detailstr="NotifyDetailNone"; break;
384 if (mode == NotifyGrab || mode == NotifyUngrab)
389 ob_debug_type(OB_DEBUG_FOCUS, "Focus%s 0x%x mode=%s detail=%s\n",
390 (e->xfocus.type == FocusIn ? "In" : "Out"),
396 static gboolean event_ignore(XEvent *e, ObClient *client)
401 if (!wanted_focusevent(e, FALSE))
406 if (!wanted_focusevent(e, FALSE))
413 static void event_process(const XEvent *ec, gpointer data)
416 ObClient *client = NULL;
418 ObDockApp *dockapp = NULL;
419 ObWindow *obwin = NULL;
420 GSList *timewinclients = NULL;
422 ObEventData *ed = data;
424 /* make a copy we can mangle */
428 window = event_get_window(e);
429 if (e->type != PropertyNotify ||
430 !(timewinclients = propwin_get_clients(window,
431 OB_PROPWIN_USER_TIME)))
432 if ((obwin = g_hash_table_lookup(window_map, &window))) {
433 switch (obwin->type) {
435 dock = WINDOW_AS_DOCK(obwin);
438 dockapp = WINDOW_AS_DOCKAPP(obwin);
441 client = WINDOW_AS_CLIENT(obwin);
444 case Window_Internal:
445 /* not to be used for events */
446 g_assert_not_reached();
451 event_set_curtime(e);
453 if (event_ignore(e, client)) {
460 /* deal with it in the kernel */
462 if (menu_frame_visible &&
463 (e->type == EnterNotify || e->type == LeaveNotify))
465 /* crossing events for menu */
466 event_handle_menu(e);
467 } else if (e->type == FocusIn) {
468 if (e->xfocus.detail == NotifyPointerRoot ||
469 e->xfocus.detail == NotifyDetailNone ||
470 e->xfocus.detail == NotifyInferior)
474 ob_debug_type(OB_DEBUG_FOCUS, "Focus went to pointer root/none\n");
476 /* If another FocusIn is in the queue then don't fallback yet. This
477 fixes the fun case of:
478 window map -> send focusin
479 window unmap -> get focusout
480 window map -> send focusin
481 get first focus out -> fall back to something (new window
482 hasn't received focus yet, so something else) -> send focusin
483 which means the "something else" is the last thing to get a
484 focusin sent to it, so the new window doesn't end up with focus.
486 But if the other focus in is something like PointerRoot then we
487 still want to fall back.
489 if (XCheckIfEvent(ob_display, &ce, event_look_for_focusin_client,
492 XPutBackEvent(ob_display, &ce);
493 ob_debug_type(OB_DEBUG_FOCUS,
494 " but another FocusIn is coming\n");
496 /* Focus has been reverted to the root window or nothing.
498 FocusOut events come after UnmapNotify, so we don't need to
499 worry about focusing an invalid window
502 if (!focus_left_screen)
503 focus_fallback(TRUE);
508 ob_debug_type(OB_DEBUG_FOCUS,
509 "Focus went to a window that is already gone\n");
511 /* If you send focus to a window and then it disappears, you can
512 get the FocusIn for it, after it is unmanaged.
513 Just wait for the next FocusOut/FocusIn pair. */
515 else if (client != focus_client) {
516 focus_left_screen = FALSE;
517 frame_adjust_focus(client->frame, TRUE);
518 focus_set_client(client);
519 client_calc_layer(client);
520 client_bring_helper_windows(client);
522 } else if (e->type == FocusOut) {
523 gboolean nomove = FALSE;
526 /* Look for the followup FocusIn */
527 if (!XCheckIfEvent(ob_display, &ce, event_look_for_focusin, NULL)) {
528 /* There is no FocusIn, this means focus went to a window that
529 is not being managed, or a window on another screen. */
533 xerror_set_ignore(TRUE);
534 if (XGetInputFocus(ob_display, &win, &i) != 0 &&
535 XGetGeometry(ob_display, win, &root, &i,&i,&u,&u,&u,&u) != 0 &&
536 root != RootWindow(ob_display, ob_screen))
538 ob_debug_type(OB_DEBUG_FOCUS,
539 "Focus went to another screen !\n");
540 focus_left_screen = TRUE;
543 ob_debug_type(OB_DEBUG_FOCUS,
544 "Focus went to a black hole !\n");
545 xerror_set_ignore(FALSE);
546 /* nothing is focused */
547 focus_set_client(NULL);
548 } else if (ce.xany.window == e->xany.window) {
549 ob_debug_type(OB_DEBUG_FOCUS, "Focus didn't go anywhere\n");
550 /* If focus didn't actually move anywhere, there is nothing to do*/
553 /* Focus did move, so process the FocusIn event */
554 ObEventData ed = { .ignored = FALSE };
555 event_process(&ce, &ed);
557 /* The FocusIn was ignored, this means it was on a window
558 that isn't a client. */
559 ob_debug_type(OB_DEBUG_FOCUS,
560 "Focus went to an unmanaged window 0x%x !\n",
562 focus_fallback(TRUE);
566 if (client && !nomove) {
567 frame_adjust_focus(client->frame, FALSE);
568 if (client == focus_client)
569 focus_set_client(NULL);
570 client_calc_layer(client);
572 } else if (timewinclients)
573 event_handle_user_time_window_clients(timewinclients, e);
575 event_handle_client(client, e);
577 event_handle_dockapp(dockapp, e);
579 event_handle_dock(dock, e);
580 else if (window == RootWindow(ob_display, ob_screen))
581 event_handle_root(e);
582 else if (e->type == MapRequest)
583 client_manage(window);
584 else if (e->type == ClientMessage) {
585 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
586 windows that are not managed yet. */
587 if (e->xclient.message_type == prop_atoms.net_request_frame_extents) {
588 /* Pretend to manage the client, getting information used to
589 determine its decorations */
590 ObClient *c = client_fake_manage(e->xclient.window);
593 /* set the frame extents on the window */
594 vals[0] = c->frame->size.left;
595 vals[1] = c->frame->size.right;
596 vals[2] = c->frame->size.top;
597 vals[3] = c->frame->size.bottom;
598 PROP_SETA32(e->xclient.window, net_frame_extents,
601 /* Free the pretend client */
602 client_fake_unmanage(c);
605 else if (e->type == ConfigureRequest) {
606 /* unhandled configure requests must be used to configure the
610 xwc.x = e->xconfigurerequest.x;
611 xwc.y = e->xconfigurerequest.y;
612 xwc.width = e->xconfigurerequest.width;
613 xwc.height = e->xconfigurerequest.height;
614 xwc.border_width = e->xconfigurerequest.border_width;
615 xwc.sibling = e->xconfigurerequest.above;
616 xwc.stack_mode = e->xconfigurerequest.detail;
618 /* we are not to be held responsible if someone sends us an
620 xerror_set_ignore(TRUE);
621 XConfigureWindow(ob_display, window,
622 e->xconfigurerequest.value_mask, &xwc);
623 xerror_set_ignore(FALSE);
626 else if (extensions_sync &&
627 e->type == extensions_sync_event_basep + XSyncAlarmNotify)
629 XSyncAlarmNotifyEvent *se = (XSyncAlarmNotifyEvent*)e;
630 if (se->alarm == moveresize_alarm && moveresize_in_progress)
635 if (e->type == ButtonPress || e->type == ButtonRelease ||
636 e->type == MotionNotify || e->type == KeyPress ||
637 e->type == KeyRelease)
639 event_handle_user_input(client, e);
642 /* if something happens and it's not from an XEvent, then we don't know
644 event_curtime = CurrentTime;
647 static void event_handle_root(XEvent *e)
653 ob_debug("Another WM has requested to replace us. Exiting.\n");
658 if (e->xclient.format != 32) break;
660 msgtype = e->xclient.message_type;
661 if (msgtype == prop_atoms.net_current_desktop) {
662 guint d = e->xclient.data.l[0];
663 if (d < screen_num_desktops) {
664 event_curtime = e->xclient.data.l[1];
665 if (event_curtime == 0)
666 ob_debug_type(OB_DEBUG_APP_BUGS,
667 "_NET_CURRENT_DESKTOP message is missing "
669 screen_set_desktop(d, TRUE);
671 } else if (msgtype == prop_atoms.net_number_of_desktops) {
672 guint d = e->xclient.data.l[0];
674 screen_set_num_desktops(d);
675 } else if (msgtype == prop_atoms.net_showing_desktop) {
676 screen_show_desktop(e->xclient.data.l[0] != 0, NULL);
677 } else if (msgtype == prop_atoms.ob_control) {
678 if (e->xclient.data.l[0] == 1)
680 else if (e->xclient.data.l[0] == 2)
685 if (e->xproperty.atom == prop_atoms.net_desktop_names)
686 screen_update_desktop_names();
687 else if (e->xproperty.atom == prop_atoms.net_desktop_layout)
688 screen_update_layout();
690 case ConfigureNotify:
692 XRRUpdateConfiguration(e);
701 void event_enter_client(ObClient *client)
703 g_assert(config_focus_follow);
705 if (client_enter_focusable(client) && client_can_focus(client)) {
706 if (config_focus_delay) {
707 ObFocusDelayData *data;
709 ob_main_loop_timeout_remove(ob_main_loop, focus_delay_func);
711 data = g_new(ObFocusDelayData, 1);
712 data->client = client;
713 data->time = event_curtime;
715 ob_main_loop_timeout_add(ob_main_loop,
718 data, focus_delay_cmp, focus_delay_dest);
720 ObFocusDelayData data;
721 data.client = client;
722 data.time = event_curtime;
723 focus_delay_func(&data);
728 static void event_handle_user_time_window_clients(GSList *l, XEvent *e)
730 g_assert(e->type == PropertyNotify);
731 if (e->xproperty.atom == prop_atoms.net_wm_user_time) {
732 for (; l; l = g_slist_next(l))
733 client_update_user_time(l->data);
737 static void event_handle_client(ObClient *client, XEvent *e)
742 static gint px = -1, py = -1;
747 /* save where the press occured for the first button pressed */
749 pb = e->xbutton.button;
754 /* Wheel buttons don't draw because they are an instant click, so it
755 is a waste of resources to go drawing it.
756 if the user is doing an intereactive thing, or has a menu open then
757 the mouse is grabbed (possibly) and if we get these events we don't
758 want to deal with them
760 if (!(e->xbutton.button == 4 || e->xbutton.button == 5) &&
761 !keyboard_interactively_grabbed() &&
764 /* use where the press occured */
765 con = frame_context(client, e->xbutton.window, px, py);
766 con = mouse_button_frame_context(con, e->xbutton.button,
769 if (e->type == ButtonRelease && e->xbutton.button == pb)
770 pb = 0, px = py = -1;
773 case OB_FRAME_CONTEXT_MAXIMIZE:
774 client->frame->max_press = (e->type == ButtonPress);
775 framerender_frame(client->frame);
777 case OB_FRAME_CONTEXT_CLOSE:
778 client->frame->close_press = (e->type == ButtonPress);
779 framerender_frame(client->frame);
781 case OB_FRAME_CONTEXT_ICONIFY:
782 client->frame->iconify_press = (e->type == ButtonPress);
783 framerender_frame(client->frame);
785 case OB_FRAME_CONTEXT_ALLDESKTOPS:
786 client->frame->desk_press = (e->type == ButtonPress);
787 framerender_frame(client->frame);
789 case OB_FRAME_CONTEXT_SHADE:
790 client->frame->shade_press = (e->type == ButtonPress);
791 framerender_frame(client->frame);
794 /* nothing changes with clicks for any other contexts */
800 con = frame_context(client, e->xmotion.window,
801 e->xmotion.x, e->xmotion.y);
803 case OB_FRAME_CONTEXT_TITLEBAR:
804 case OB_FRAME_CONTEXT_TLCORNER:
805 case OB_FRAME_CONTEXT_TRCORNER:
806 /* we've left the button area inside the titlebar */
807 if (client->frame->max_hover || client->frame->desk_hover ||
808 client->frame->shade_hover || client->frame->iconify_hover ||
809 client->frame->close_hover)
811 client->frame->max_hover = FALSE;
812 client->frame->desk_hover = FALSE;
813 client->frame->shade_hover = FALSE;
814 client->frame->iconify_hover = FALSE;
815 client->frame->close_hover = FALSE;
816 frame_adjust_state(client->frame);
819 case OB_FRAME_CONTEXT_MAXIMIZE:
820 if (!client->frame->max_hover) {
821 client->frame->max_hover = TRUE;
822 frame_adjust_state(client->frame);
825 case OB_FRAME_CONTEXT_ALLDESKTOPS:
826 if (!client->frame->desk_hover) {
827 client->frame->desk_hover = TRUE;
828 frame_adjust_state(client->frame);
831 case OB_FRAME_CONTEXT_SHADE:
832 if (!client->frame->shade_hover) {
833 client->frame->shade_hover = TRUE;
834 frame_adjust_state(client->frame);
837 case OB_FRAME_CONTEXT_ICONIFY:
838 if (!client->frame->iconify_hover) {
839 client->frame->iconify_hover = TRUE;
840 frame_adjust_state(client->frame);
843 case OB_FRAME_CONTEXT_CLOSE:
844 if (!client->frame->close_hover) {
845 client->frame->close_hover = TRUE;
846 frame_adjust_state(client->frame);
854 con = frame_context(client, e->xcrossing.window,
855 e->xcrossing.x, e->xcrossing.y);
857 case OB_FRAME_CONTEXT_TITLEBAR:
858 case OB_FRAME_CONTEXT_TLCORNER:
859 case OB_FRAME_CONTEXT_TRCORNER:
860 /* we've left the button area inside the titlebar */
861 if (client->frame->max_hover || client->frame->desk_hover ||
862 client->frame->shade_hover || client->frame->iconify_hover ||
863 client->frame->close_hover)
865 client->frame->max_hover = FALSE;
866 client->frame->desk_hover = FALSE;
867 client->frame->shade_hover = FALSE;
868 client->frame->iconify_hover = FALSE;
869 client->frame->close_hover = FALSE;
870 frame_adjust_state(client->frame);
873 case OB_FRAME_CONTEXT_MAXIMIZE:
874 client->frame->max_hover = FALSE;
875 frame_adjust_state(client->frame);
877 case OB_FRAME_CONTEXT_ALLDESKTOPS:
878 client->frame->desk_hover = FALSE;
879 frame_adjust_state(client->frame);
881 case OB_FRAME_CONTEXT_SHADE:
882 client->frame->shade_hover = FALSE;
883 frame_adjust_state(client->frame);
885 case OB_FRAME_CONTEXT_ICONIFY:
886 client->frame->iconify_hover = FALSE;
887 frame_adjust_state(client->frame);
889 case OB_FRAME_CONTEXT_CLOSE:
890 client->frame->close_hover = FALSE;
891 frame_adjust_state(client->frame);
893 case OB_FRAME_CONTEXT_FRAME:
894 /* When the mouse leaves an animating window, don't use the
895 corresponding enter events. Pretend like the animating window
896 doesn't even exist..! */
897 if (frame_iconify_animating(client->frame))
898 event_ignore_all_queued_enters();
900 ob_debug_type(OB_DEBUG_FOCUS,
901 "%sNotify mode %d detail %d on %lx\n",
902 (e->type == EnterNotify ? "Enter" : "Leave"),
904 e->xcrossing.detail, (client?client->window:0));
905 if (keyboard_interactively_grabbed())
907 if (config_focus_follow && config_focus_delay &&
908 /* leave inferior events can happen when the mouse goes onto
909 the window's border and then into the window before the
911 e->xcrossing.detail != NotifyInferior)
913 ob_main_loop_timeout_remove_data(ob_main_loop,
924 con = frame_context(client, e->xcrossing.window,
925 e->xcrossing.x, e->xcrossing.y);
927 case OB_FRAME_CONTEXT_MAXIMIZE:
928 client->frame->max_hover = TRUE;
929 frame_adjust_state(client->frame);
931 case OB_FRAME_CONTEXT_ALLDESKTOPS:
932 client->frame->desk_hover = TRUE;
933 frame_adjust_state(client->frame);
935 case OB_FRAME_CONTEXT_SHADE:
936 client->frame->shade_hover = TRUE;
937 frame_adjust_state(client->frame);
939 case OB_FRAME_CONTEXT_ICONIFY:
940 client->frame->iconify_hover = TRUE;
941 frame_adjust_state(client->frame);
943 case OB_FRAME_CONTEXT_CLOSE:
944 client->frame->close_hover = TRUE;
945 frame_adjust_state(client->frame);
947 case OB_FRAME_CONTEXT_FRAME:
948 if (keyboard_interactively_grabbed())
950 if (e->xcrossing.mode == NotifyGrab ||
951 e->xcrossing.mode == NotifyUngrab ||
952 /*ignore enters when we're already in the window */
953 e->xcrossing.detail == NotifyInferior ||
954 is_enter_focus_event_ignored(e))
956 ob_debug_type(OB_DEBUG_FOCUS,
957 "%sNotify mode %d detail %d on %lx IGNORED\n",
958 (e->type == EnterNotify ? "Enter" : "Leave"),
960 e->xcrossing.detail, client?client->window:0);
963 ob_debug_type(OB_DEBUG_FOCUS,
964 "%sNotify mode %d detail %d on %lx, "
966 (e->type == EnterNotify ? "Enter" : "Leave"),
968 e->xcrossing.detail, (client?client->window:0));
969 if (config_focus_follow)
970 event_enter_client(client);
978 case ConfigureRequest:
980 /* dont compress these unless you're going to watch for property
981 notifies in between (these can change what the configure would
983 also you can't compress stacking events
987 gboolean move = FALSE;
988 gboolean resize = FALSE;
990 /* get the current area */
991 RECT_TO_DIMS(client->area, x, y, w, h);
993 ob_debug("ConfigureRequest desktop %d wmstate %d visibile %d\n",
994 screen_desktop, client->wmstate, client->frame->visible);
996 if (e->xconfigurerequest.value_mask & CWBorderWidth)
997 if (client->border_width != e->xconfigurerequest.border_width) {
998 client->border_width = e->xconfigurerequest.border_width;
1000 /* if the border width is changing then that is the same
1001 as requesting a resize, but we don't actually change
1002 the client's border, so it will change their root
1003 coordiantes (since they include the border width) and
1004 we need to a notify then */
1009 if (e->xconfigurerequest.value_mask & CWStackMode) {
1010 ObClient *sibling = NULL;
1012 /* get the sibling */
1013 if (e->xconfigurerequest.value_mask & CWSibling) {
1015 win = g_hash_table_lookup(window_map,
1016 &e->xconfigurerequest.above);
1017 if (WINDOW_IS_CLIENT(win) && WINDOW_AS_CLIENT(win) != client)
1018 sibling = WINDOW_AS_CLIENT(win);
1021 /* activate it rather than just focus it */
1022 stacking_restack_request(client, sibling,
1023 e->xconfigurerequest.detail, TRUE);
1025 /* if a stacking change moves the window without resizing */
1029 /* don't allow clients to move shaded windows (fvwm does this) */
1030 if (client->shaded && (e->xconfigurerequest.value_mask & CWX ||
1031 e->xconfigurerequest.value_mask & CWY))
1033 e->xconfigurerequest.value_mask &= ~CWX;
1034 e->xconfigurerequest.value_mask &= ~CWY;
1036 /* if the client tried to move and we aren't letting it then a
1037 synthetic event is needed */
1041 if (e->xconfigurerequest.value_mask & CWX ||
1042 e->xconfigurerequest.value_mask & CWY ||
1043 e->xconfigurerequest.value_mask & CWWidth ||
1044 e->xconfigurerequest.value_mask & CWHeight)
1046 if (e->xconfigurerequest.value_mask & CWX) {
1047 x = e->xconfigurerequest.x;
1050 if (e->xconfigurerequest.value_mask & CWY) {
1051 y = e->xconfigurerequest.y;
1054 if (e->xconfigurerequest.value_mask & CWWidth) {
1055 w = e->xconfigurerequest.width;
1058 if (e->xconfigurerequest.value_mask & CWHeight) {
1059 h = e->xconfigurerequest.height;
1064 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
1065 "move %d resize %d\n",
1066 e->xconfigurerequest.value_mask & CWX, x,
1067 e->xconfigurerequest.value_mask & CWY, y,
1068 e->xconfigurerequest.value_mask & CWWidth, w,
1069 e->xconfigurerequest.value_mask & CWHeight, h,
1072 /* check for broken apps moving to their root position
1074 XXX remove this some day...that would be nice. right now all
1075 kde apps do this when they try activate themselves on another
1076 desktop. eg. open amarok window on desktop 1, switch to desktop
1077 2, click amarok tray icon. it will move by its decoration size.
1079 if (move && !resize &&
1080 x != client->area.x &&
1081 x == (client->frame->area.x + client->frame->size.left -
1082 (gint)client->border_width) &&
1083 y != client->area.y &&
1084 y == (client->frame->area.y + client->frame->size.top -
1085 (gint)client->border_width))
1087 ob_debug_type(OB_DEBUG_APP_BUGS,
1088 "Application %s is trying to move via "
1089 "ConfigureRequest to it's root window position "
1090 "but it is not using StaticGravity\n",
1096 /* they still requested a move, so don't change whether a
1097 notify is sent or not */
1100 if (move || resize) {
1103 client_find_onscreen(client, &x, &y, w, h, FALSE);
1104 client_try_configure(client, &x, &y, &w, &h, &lw, &lh, FALSE);
1105 /* if they requested something that moves the window, or if
1106 the window is actually being changed then configure it and
1107 send a configure notify to them */
1108 if (move || !RECT_EQUAL_DIMS(client->area, x, y, w, h)) {
1109 ob_debug("Doing configure\n");
1110 client_configure(client, x, y, w, h, FALSE, TRUE);
1113 /* ignore enter events caused by these like ob actions do */
1114 event_ignore_all_queued_enters();
1119 if (client->ignore_unmaps) {
1120 client->ignore_unmaps--;
1123 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1124 "ignores left %d\n",
1125 client->window, e->xunmap.event, e->xunmap.from_configure,
1126 client->ignore_unmaps);
1127 client_unmanage(client);
1130 ob_debug("DestroyNotify for window 0x%x\n", client->window);
1131 client_unmanage(client);
1133 case ReparentNotify:
1134 /* this is when the client is first taken captive in the frame */
1135 if (e->xreparent.parent == client->frame->plate) break;
1138 This event is quite rare and is usually handled in unmapHandler.
1139 However, if the window is unmapped when the reparent event occurs,
1140 the window manager never sees it because an unmap event is not sent
1141 to an already unmapped window.
1144 /* we don't want the reparent event, put it back on the stack for the
1145 X server to deal with after we unmanage the window */
1146 XPutBackEvent(ob_display, e);
1148 ob_debug("ReparentNotify for window 0x%x\n", client->window);
1149 client_unmanage(client);
1152 ob_debug("MapRequest for 0x%lx\n", client->window);
1153 if (!client->iconic) break; /* this normally doesn't happen, but if it
1154 does, we don't want it!
1155 it can happen now when the window is on
1156 another desktop, but we still don't
1158 client_activate(client, FALSE, TRUE);
1161 /* validate cuz we query stuff off the client here */
1162 if (!client_validate(client)) break;
1164 if (e->xclient.format != 32) return;
1166 msgtype = e->xclient.message_type;
1167 if (msgtype == prop_atoms.wm_change_state) {
1168 /* compress changes into a single change */
1169 while (XCheckTypedWindowEvent(ob_display, client->window,
1171 /* XXX: it would be nice to compress ALL messages of a
1172 type, not just messages in a row without other
1173 message types between. */
1174 if (ce.xclient.message_type != msgtype) {
1175 XPutBackEvent(ob_display, &ce);
1178 e->xclient = ce.xclient;
1180 client_set_wm_state(client, e->xclient.data.l[0]);
1181 } else if (msgtype == prop_atoms.net_wm_desktop) {
1182 /* compress changes into a single change */
1183 while (XCheckTypedWindowEvent(ob_display, client->window,
1185 /* XXX: it would be nice to compress ALL messages of a
1186 type, not just messages in a row without other
1187 message types between. */
1188 if (ce.xclient.message_type != msgtype) {
1189 XPutBackEvent(ob_display, &ce);
1192 e->xclient = ce.xclient;
1194 if ((unsigned)e->xclient.data.l[0] < screen_num_desktops ||
1195 (unsigned)e->xclient.data.l[0] == DESKTOP_ALL)
1196 client_set_desktop(client, (unsigned)e->xclient.data.l[0],
1198 } else if (msgtype == prop_atoms.net_wm_state) {
1199 /* can't compress these */
1200 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1201 (e->xclient.data.l[0] == 0 ? "Remove" :
1202 e->xclient.data.l[0] == 1 ? "Add" :
1203 e->xclient.data.l[0] == 2 ? "Toggle" : "INVALID"),
1204 e->xclient.data.l[1], e->xclient.data.l[2],
1206 client_set_state(client, e->xclient.data.l[0],
1207 e->xclient.data.l[1], e->xclient.data.l[2]);
1209 /* ignore enter events caused by these like ob actions do */
1210 event_ignore_all_queued_enters();
1211 } else if (msgtype == prop_atoms.net_close_window) {
1212 ob_debug("net_close_window for 0x%lx\n", client->window);
1213 client_close(client);
1214 } else if (msgtype == prop_atoms.net_active_window) {
1215 ob_debug("net_active_window for 0x%lx source=%s\n",
1217 (e->xclient.data.l[0] == 0 ? "unknown" :
1218 (e->xclient.data.l[0] == 1 ? "application" :
1219 (e->xclient.data.l[0] == 2 ? "user" : "INVALID"))));
1220 /* XXX make use of data.l[2] !? */
1221 if (e->xclient.data.l[0] == 1 || e->xclient.data.l[0] == 2) {
1222 event_curtime = e->xclient.data.l[1];
1223 if (event_curtime == 0)
1224 ob_debug_type(OB_DEBUG_APP_BUGS,
1225 "_NET_ACTIVE_WINDOW message for window %s is"
1226 " missing a timestamp\n", client->title);
1228 ob_debug_type(OB_DEBUG_APP_BUGS,
1229 "_NET_ACTIVE_WINDOW message for window %s is "
1230 "missing source indication\n");
1231 client_activate(client, FALSE,
1232 (e->xclient.data.l[0] == 0 ||
1233 e->xclient.data.l[0] == 2));
1234 } else if (msgtype == prop_atoms.net_wm_moveresize) {
1235 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1236 client->window, e->xclient.data.l[2]);
1237 if ((Atom)e->xclient.data.l[2] ==
1238 prop_atoms.net_wm_moveresize_size_topleft ||
1239 (Atom)e->xclient.data.l[2] ==
1240 prop_atoms.net_wm_moveresize_size_top ||
1241 (Atom)e->xclient.data.l[2] ==
1242 prop_atoms.net_wm_moveresize_size_topright ||
1243 (Atom)e->xclient.data.l[2] ==
1244 prop_atoms.net_wm_moveresize_size_right ||
1245 (Atom)e->xclient.data.l[2] ==
1246 prop_atoms.net_wm_moveresize_size_right ||
1247 (Atom)e->xclient.data.l[2] ==
1248 prop_atoms.net_wm_moveresize_size_bottomright ||
1249 (Atom)e->xclient.data.l[2] ==
1250 prop_atoms.net_wm_moveresize_size_bottom ||
1251 (Atom)e->xclient.data.l[2] ==
1252 prop_atoms.net_wm_moveresize_size_bottomleft ||
1253 (Atom)e->xclient.data.l[2] ==
1254 prop_atoms.net_wm_moveresize_size_left ||
1255 (Atom)e->xclient.data.l[2] ==
1256 prop_atoms.net_wm_moveresize_move ||
1257 (Atom)e->xclient.data.l[2] ==
1258 prop_atoms.net_wm_moveresize_size_keyboard ||
1259 (Atom)e->xclient.data.l[2] ==
1260 prop_atoms.net_wm_moveresize_move_keyboard) {
1262 moveresize_start(client, e->xclient.data.l[0],
1263 e->xclient.data.l[1], e->xclient.data.l[3],
1264 e->xclient.data.l[2]);
1266 else if ((Atom)e->xclient.data.l[2] ==
1267 prop_atoms.net_wm_moveresize_cancel)
1268 moveresize_end(TRUE);
1269 } else if (msgtype == prop_atoms.net_moveresize_window) {
1270 gint grav, x, y, w, h;
1272 if (e->xclient.data.l[0] & 0xff)
1273 grav = e->xclient.data.l[0] & 0xff;
1275 grav = client->gravity;
1277 if (e->xclient.data.l[0] & 1 << 8)
1278 x = e->xclient.data.l[1];
1281 if (e->xclient.data.l[0] & 1 << 9)
1282 y = e->xclient.data.l[2];
1285 if (e->xclient.data.l[0] & 1 << 10)
1286 w = e->xclient.data.l[3];
1288 w = client->area.width;
1289 if (e->xclient.data.l[0] & 1 << 11)
1290 h = e->xclient.data.l[4];
1292 h = client->area.height;
1294 ob_debug("MOVERESIZE x %d %d y %d %d\n",
1295 e->xclient.data.l[0] & 1 << 8, x,
1296 e->xclient.data.l[0] & 1 << 9, y);
1297 client_convert_gravity(client, grav, &x, &y, w, h);
1298 client_find_onscreen(client, &x, &y, w, h, FALSE);
1300 client_configure(client, x, y, w, h, FALSE, TRUE);
1302 /* ignore enter events caused by these like ob actions do */
1303 event_ignore_all_queued_enters();
1304 } else if (msgtype == prop_atoms.net_restack_window) {
1305 if (e->xclient.data.l[0] != 2) {
1306 ob_debug_type(OB_DEBUG_APP_BUGS,
1307 "_NET_RESTACK_WINDOW sent for window %s with "
1308 "invalid source indication %ld\n",
1309 client->title, e->xclient.data.l[0]);
1311 ObClient *sibling = NULL;
1312 if (e->xclient.data.l[1]) {
1313 ObWindow *win = g_hash_table_lookup
1314 (window_map, &e->xclient.data.l[1]);
1315 if (WINDOW_IS_CLIENT(win) &&
1316 WINDOW_AS_CLIENT(win) != client)
1318 sibling = WINDOW_AS_CLIENT(win);
1320 if (sibling == NULL)
1321 ob_debug_type(OB_DEBUG_APP_BUGS,
1322 "_NET_RESTACK_WINDOW sent for window %s "
1323 "with invalid sibling 0x%x\n",
1324 client->title, e->xclient.data.l[1]);
1326 if (e->xclient.data.l[2] == Below ||
1327 e->xclient.data.l[2] == BottomIf ||
1328 e->xclient.data.l[2] == Above ||
1329 e->xclient.data.l[2] == TopIf ||
1330 e->xclient.data.l[2] == Opposite)
1332 /* just raise, don't activate */
1333 stacking_restack_request(client, sibling,
1334 e->xclient.data.l[2], FALSE);
1335 /* send a synthetic ConfigureNotify, cuz this is supposed
1336 to be like a ConfigureRequest. */
1337 client_reconfigure(client);
1339 ob_debug_type(OB_DEBUG_APP_BUGS,
1340 "_NET_RESTACK_WINDOW sent for window %s "
1341 "with invalid detail %d\n",
1342 client->title, e->xclient.data.l[2]);
1346 case PropertyNotify:
1347 /* validate cuz we query stuff off the client here */
1348 if (!client_validate(client)) break;
1350 /* compress changes to a single property into a single change */
1351 while (XCheckTypedWindowEvent(ob_display, client->window,
1355 /* XXX: it would be nice to compress ALL changes to a property,
1356 not just changes in a row without other props between. */
1358 a = ce.xproperty.atom;
1359 b = e->xproperty.atom;
1363 if ((a == prop_atoms.net_wm_name ||
1364 a == prop_atoms.wm_name ||
1365 a == prop_atoms.net_wm_icon_name ||
1366 a == prop_atoms.wm_icon_name)
1368 (b == prop_atoms.net_wm_name ||
1369 b == prop_atoms.wm_name ||
1370 b == prop_atoms.net_wm_icon_name ||
1371 b == prop_atoms.wm_icon_name)) {
1374 if (a == prop_atoms.net_wm_icon &&
1375 b == prop_atoms.net_wm_icon)
1378 XPutBackEvent(ob_display, &ce);
1382 msgtype = e->xproperty.atom;
1383 if (msgtype == XA_WM_NORMAL_HINTS) {
1384 client_update_normal_hints(client);
1385 /* normal hints can make a window non-resizable */
1386 client_setup_decor_and_functions(client);
1387 } else if (msgtype == XA_WM_HINTS) {
1388 client_update_wmhints(client);
1389 } else if (msgtype == XA_WM_TRANSIENT_FOR) {
1390 client_update_transient_for(client);
1391 client_get_type_and_transientness(client);
1392 /* type may have changed, so update the layer */
1393 client_calc_layer(client);
1394 client_setup_decor_and_functions(client);
1395 } else if (msgtype == prop_atoms.net_wm_name ||
1396 msgtype == prop_atoms.wm_name ||
1397 msgtype == prop_atoms.net_wm_icon_name ||
1398 msgtype == prop_atoms.wm_icon_name) {
1399 client_update_title(client);
1400 } else if (msgtype == prop_atoms.wm_protocols) {
1401 client_update_protocols(client);
1402 client_setup_decor_and_functions(client);
1404 else if (msgtype == prop_atoms.net_wm_strut) {
1405 client_update_strut(client);
1407 else if (msgtype == prop_atoms.net_wm_icon) {
1408 client_update_icons(client);
1410 else if (msgtype == prop_atoms.net_wm_icon_geometry) {
1411 client_update_icon_geometry(client);
1413 else if (msgtype == prop_atoms.net_wm_user_time) {
1414 client_update_user_time(client);
1416 else if (msgtype == prop_atoms.net_wm_user_time_window) {
1417 client_update_user_time_window(client);
1420 else if (msgtype == prop_atoms.net_wm_sync_request_counter) {
1421 client_update_sync_request_counter(client);
1424 case ColormapNotify:
1425 client_update_colormap(client, e->xcolormap.colormap);
1430 if (extensions_shape && e->type == extensions_shape_event_basep) {
1431 client->shaped = ((XShapeEvent*)e)->shaped;
1432 frame_adjust_shape(client->frame);
1438 static void event_handle_dock(ObDock *s, XEvent *e)
1442 if (e->xbutton.button == 1)
1443 stacking_raise(DOCK_AS_WINDOW(s));
1444 else if (e->xbutton.button == 2)
1445 stacking_lower(DOCK_AS_WINDOW(s));
1456 static void event_handle_dockapp(ObDockApp *app, XEvent *e)
1460 dock_app_drag(app, &e->xmotion);
1463 if (app->ignore_unmaps) {
1464 app->ignore_unmaps--;
1467 dock_remove(app, TRUE);
1470 dock_remove(app, FALSE);
1472 case ReparentNotify:
1473 dock_remove(app, FALSE);
1475 case ConfigureNotify:
1476 dock_app_configure(app, e->xconfigure.width, e->xconfigure.height);
1481 static ObMenuFrame* find_active_menu()
1484 ObMenuFrame *ret = NULL;
1486 for (it = menu_frame_visible; it; it = g_list_next(it)) {
1495 static ObMenuFrame* find_active_or_last_menu()
1497 ObMenuFrame *ret = NULL;
1499 ret = find_active_menu();
1500 if (!ret && menu_frame_visible)
1501 ret = menu_frame_visible->data;
1505 static gboolean event_handle_menu_keyboard(XEvent *ev)
1507 guint keycode, state;
1510 gboolean ret = TRUE;
1512 keycode = ev->xkey.keycode;
1513 state = ev->xkey.state;
1514 unikey = translate_unichar(keycode);
1516 frame = find_active_or_last_menu();
1520 else if (keycode == ob_keycode(OB_KEY_ESCAPE) && state == 0) {
1521 /* Escape goes to the parent menu or closes the last one */
1523 menu_frame_select(frame, NULL, TRUE);
1525 menu_frame_hide_all();
1528 else if (keycode == ob_keycode(OB_KEY_RETURN) && (state == 0 ||
1529 state == ControlMask))
1531 /* Enter runs the active item or goes into the submenu.
1532 Control-Enter runs it without closing the menu. */
1534 menu_frame_select_next(frame->child);
1536 menu_entry_frame_execute(frame->selected, state, ev->xkey.time);
1539 else if (keycode == ob_keycode(OB_KEY_LEFT) && ev->xkey.state == 0) {
1540 /* Left goes to the parent menu */
1541 menu_frame_select(frame, NULL, TRUE);
1544 else if (keycode == ob_keycode(OB_KEY_RIGHT) && ev->xkey.state == 0) {
1545 /* Right goes to the selected submenu */
1546 if (frame->child) menu_frame_select_next(frame->child);
1549 else if (keycode == ob_keycode(OB_KEY_UP) && state == 0) {
1550 menu_frame_select_previous(frame);
1553 else if (keycode == ob_keycode(OB_KEY_DOWN) && state == 0) {
1554 menu_frame_select_next(frame);
1557 /* keyboard accelerator shortcuts. */
1558 else if (ev->xkey.state == 0 &&
1559 /* was it a valid key? */
1561 /* don't bother if the menu is empty. */
1566 ObMenuEntryFrame *found = NULL;
1567 guint num_found = 0;
1569 /* start after the selected one */
1570 start = frame->entries;
1571 if (frame->selected) {
1572 for (it = start; frame->selected != it->data; it = g_list_next(it))
1573 g_assert(it != NULL); /* nothing was selected? */
1574 /* next with wraparound */
1575 start = g_list_next(it);
1576 if (start == NULL) start = frame->entries;
1581 ObMenuEntryFrame *e = it->data;
1582 gunichar entrykey = 0;
1584 if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL)
1585 entrykey = e->entry->data.normal.shortcut;
1586 else if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
1587 entrykey = e->entry->data.submenu.submenu->shortcut;
1589 if (unikey == entrykey) {
1590 if (found == NULL) found = e;
1594 /* next with wraparound */
1595 it = g_list_next(it);
1596 if (it == NULL) it = frame->entries;
1597 } while (it != start);
1600 if (found->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
1603 menu_frame_select(frame, found, TRUE);
1604 usleep(50000); /* highlight the item for a short bit so the
1605 user can see what happened */
1606 menu_entry_frame_execute(found, state, ev->xkey.time);
1608 menu_frame_select(frame, found, TRUE);
1610 menu_frame_select_next(frame->child);
1621 static gboolean event_handle_menu(XEvent *ev)
1624 ObMenuEntryFrame *e;
1625 gboolean ret = TRUE;
1629 if ((ev->xbutton.button < 4 || ev->xbutton.button > 5)
1632 if ((e = menu_entry_frame_under(ev->xbutton.x_root,
1633 ev->xbutton.y_root)))
1634 menu_entry_frame_execute(e, ev->xbutton.state,
1637 menu_frame_hide_all();
1641 if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window))) {
1642 if (e->ignore_enters)
1645 menu_frame_select(e->frame, e, FALSE);
1649 /*ignore leaves when we're already in the window */
1650 if (ev->xcrossing.detail == NotifyInferior)
1653 if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window)) &&
1654 (f = find_active_menu()) && f->selected == e &&
1655 e->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU)
1657 menu_frame_select(e->frame, NULL, FALSE);
1661 if ((e = menu_entry_frame_under(ev->xmotion.x_root,
1662 ev->xmotion.y_root)))
1663 menu_frame_select(e->frame, e, FALSE);
1666 ret = event_handle_menu_keyboard(ev);
1672 static void event_handle_user_input(ObClient *client, XEvent *e)
1674 g_assert(e->type == ButtonPress || e->type == ButtonRelease ||
1675 e->type == MotionNotify || e->type == KeyPress ||
1676 e->type == KeyRelease);
1678 if (menu_frame_visible) {
1679 if (event_handle_menu(e))
1680 /* don't use the event if the menu used it, but if the menu
1681 didn't use it and it's a keypress that is bound, it will
1682 close the menu and be used */
1686 /* if the keyboard interactive action uses the event then dont
1687 use it for bindings. likewise is moveresize uses the event. */
1688 if (!keyboard_process_interactive_grab(e, &client) &&
1689 !(moveresize_in_progress && moveresize_event(e)))
1691 if (moveresize_in_progress)
1692 /* make further actions work on the client being
1694 client = moveresize_client;
1696 menu_can_hide = FALSE;
1697 ob_main_loop_timeout_add(ob_main_loop,
1698 config_menu_hide_delay * 1000,
1699 menu_hide_delay_func,
1700 NULL, g_direct_equal, NULL);
1702 if (e->type == ButtonPress ||
1703 e->type == ButtonRelease ||
1704 e->type == MotionNotify)
1706 /* the frame may not be "visible" but they can still click on it
1707 in the case where it is animating before disappearing */
1708 if (!client || !frame_iconify_animating(client->frame))
1709 mouse_event(client, e);
1710 } else if (e->type == KeyPress) {
1711 keyboard_event((focus_cycle_target ? focus_cycle_target :
1712 (client ? client : focus_client)), e);
1717 static gboolean menu_hide_delay_func(gpointer data)
1719 menu_can_hide = TRUE;
1720 return FALSE; /* no repeat */
1723 static void focus_delay_dest(gpointer data)
1728 static gboolean focus_delay_cmp(gconstpointer d1, gconstpointer d2)
1730 const ObFocusDelayData *f1 = d1;
1731 return f1->client == d2;
1734 static gboolean focus_delay_func(gpointer data)
1736 ObFocusDelayData *d = data;
1737 Time old = event_curtime;
1739 event_curtime = d->time;
1740 if (focus_client != d->client) {
1741 if (client_focus(d->client) && config_focus_raise)
1742 stacking_raise(CLIENT_AS_WINDOW(d->client));
1744 event_curtime = old;
1745 return FALSE; /* no repeat */
1748 static void focus_delay_client_dest(ObClient *client, gpointer data)
1750 ob_main_loop_timeout_remove_data(ob_main_loop, focus_delay_func,
1754 void event_halt_focus_delay()
1756 ob_main_loop_timeout_remove(ob_main_loop, focus_delay_func);
1759 static Bool event_look_for_enters(Display *d, XEvent *e, XPointer arg)
1761 if (e->type == EnterNotify &&
1762 /* these types aren't used for focusing */
1763 !(e->xcrossing.mode == NotifyGrab ||
1764 e->xcrossing.mode == NotifyUngrab ||
1765 e->xcrossing.detail == NotifyInferior))
1769 /* found an enter for that leave, ignore it if it's going to
1771 win = g_hash_table_lookup(window_map, &e->xany.window);
1772 if (win && WINDOW_IS_CLIENT(win))
1773 ++ignore_enter_focus;
1775 return False; /* don't disrupt the queue order, just count them */
1778 void event_ignore_all_queued_enters()
1782 XSync(ob_display, FALSE);
1784 /* count the events without disrupting them */
1785 ignore_enter_focus = 0;
1786 XCheckIfEvent(ob_display, &e, event_look_for_enters, NULL);
1789 static gboolean is_enter_focus_event_ignored(XEvent *e)
1791 g_assert(e->type == EnterNotify &&
1792 !(e->xcrossing.mode == NotifyGrab ||
1793 e->xcrossing.mode == NotifyUngrab ||
1794 e->xcrossing.detail == NotifyInferior));
1796 ob_debug_type(OB_DEBUG_FOCUS, "# enters ignored: %d\n",
1797 ignore_enter_focus);
1799 if (ignore_enter_focus) {
1800 --ignore_enter_focus;
1806 gboolean event_time_after(Time t1, Time t2)
1808 g_assert(t1 != CurrentTime);
1809 g_assert(t2 != CurrentTime);
1812 Timestamp values wrap around (after about 49.7 days). The server, given
1813 its current time is represented by timestamp T, always interprets
1814 timestamps from clients by treating half of the timestamp space as being
1815 later in time than T.
1816 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
1819 /* TIME_HALF is half of the number space of a Time type variable */
1820 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
1822 if (t2 >= TIME_HALF)
1823 /* t2 is in the second half so t1 might wrap around and be smaller than
1825 return t1 >= t2 || t1 < (t2 + TIME_HALF);
1827 /* t2 is in the first half so t1 has to come after it */
1828 return t1 >= t2 && t1 < (t2 + TIME_HALF);