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"
36 #include "focus_cycle.h"
37 #include "moveresize.h"
41 #include "obt/display.h"
43 #include "obt/keyboard.h"
46 #include <X11/Xatom.h>
49 #ifdef HAVE_SYS_SELECT_H
50 # include <sys/select.h>
56 # include <unistd.h> /* for usleep() */
59 # include <X11/XKBlib.h>
63 #include <X11/ICE/ICElib.h>
80 gulong start; /* inclusive */
81 gulong end; /* inclusive */
84 static void event_process(const XEvent *e, gpointer data);
85 static void event_handle_root(XEvent *e);
86 static gboolean event_handle_menu_input(XEvent *e);
87 static void event_handle_menu(ObMenuFrame *frame, XEvent *e);
88 static void event_handle_dock(ObDock *s, XEvent *e);
89 static void event_handle_dockapp(ObDockApp *app, XEvent *e);
90 static void event_handle_client(ObClient *c, XEvent *e);
91 static void event_handle_user_input(ObClient *client, XEvent *e);
92 static gboolean is_enter_focus_event_ignored(gulong serial);
93 static void event_ignore_enter_range(gulong start, gulong end);
95 static void focus_delay_dest(gpointer data);
96 static gboolean focus_delay_cmp(gconstpointer d1, gconstpointer d2);
97 static gboolean focus_delay_func(gpointer data);
98 static void focus_delay_client_dest(ObClient *client, gpointer data);
100 Time event_curtime = CurrentTime;
101 Time event_last_user_time = CurrentTime;
102 /*! The serial of the current X event */
104 static gulong event_curserial;
105 static gboolean focus_left_screen = FALSE;
106 /*! A list of ObSerialRanges which are to be ignored for mouse enter events */
107 static GSList *ignore_serials = NULL;
110 static void ice_handler(gint fd, gpointer conn)
113 IceProcessMessages(conn, NULL, &b);
116 static void ice_watch(IceConn conn, IcePointer data, Bool opening,
117 IcePointer *watch_data)
122 fd = IceConnectionNumber(conn);
123 obt_main_loop_fd_add(ob_main_loop, fd, ice_handler, conn, NULL);
125 obt_main_loop_fd_remove(ob_main_loop, fd);
131 void event_startup(gboolean reconfig)
133 if (reconfig) return;
135 obt_main_loop_x_add(ob_main_loop, event_process, NULL, NULL);
138 IceAddConnectionWatch(ice_watch, NULL);
141 client_add_destroy_notify(focus_delay_client_dest, NULL);
144 void event_shutdown(gboolean reconfig)
146 if (reconfig) return;
149 IceRemoveConnectionWatch(ice_watch, NULL);
152 client_remove_destroy_notify(focus_delay_client_dest);
155 static Window event_get_window(XEvent *e)
162 window = obt_root(ob_screen);
165 window = e->xcreatewindow.window;
168 window = e->xmaprequest.window;
171 window = e->xmap.window;
174 window = e->xunmap.window;
177 window = e->xdestroywindow.window;
179 case ConfigureRequest:
180 window = e->xconfigurerequest.window;
182 case ConfigureNotify:
183 window = e->xconfigure.window;
187 if (obt_display_extension_xkb &&
188 e->type == obt_display_extension_xkb_basep)
190 switch (((XkbAnyEvent*)e)->xkb_type) {
192 window = ((XkbBellNotifyEvent*)e)->window;
199 if (obt_display_extension_sync &&
200 e->type == obt_display_extension_sync_basep + XSyncAlarmNotify)
205 window = e->xany.window;
210 static void event_set_curtime(XEvent *e)
212 Time t = CurrentTime;
214 /* grab the lasttime and hack up the state */
230 t = e->xproperty.time;
234 t = e->xcrossing.time;
238 if (obt_display_extension_sync &&
239 e->type == obt_display_extension_sync_basep + XSyncAlarmNotify)
241 t = ((XSyncAlarmNotifyEvent*)e)->time;
244 /* if more event types are anticipated, get their timestamp
249 /* watch that if we get an event earlier than the last specified user_time,
250 which can happen if the clock goes backwards, we erase the last
251 specified user_time */
252 if (t && event_last_user_time && event_time_after(event_last_user_time, t))
253 event_last_user_time = CurrentTime;
258 static void event_hack_mods(XEvent *e)
261 XkbStateRec xkb_state;
267 e->xbutton.state = obt_keyboard_only_modmasks(e->xbutton.state);
270 e->xkey.state = obt_keyboard_only_modmasks(e->xkey.state);
274 /* If XKB is present, then the modifiers are all strange from its
275 magic. Our X core protocol stuff won't work, so we use this to
276 find what the modifier state is instead. */
277 if (XkbGetState(obt_display, XkbUseCoreKbd, &xkb_state) == Success)
279 obt_keyboard_only_modmasks(xkb_state.compat_state);
283 e->xkey.state = obt_keyboard_only_modmasks(e->xkey.state);
284 /* remove from the state the mask of the modifier key being
285 released, if it is a modifier key being released that is */
286 e->xkey.state &= ~obt_keyboard_keycode_to_modmask(e->xkey.keycode);
290 e->xmotion.state = obt_keyboard_only_modmasks(e->xmotion.state);
291 /* compress events */
294 while (XCheckTypedWindowEvent(obt_display, e->xmotion.window,
296 e->xmotion.x = ce.xmotion.x;
297 e->xmotion.y = ce.xmotion.y;
298 e->xmotion.x_root = ce.xmotion.x_root;
299 e->xmotion.y_root = ce.xmotion.y_root;
306 static gboolean wanted_focusevent(XEvent *e, gboolean in_client_only)
308 gint mode = e->xfocus.mode;
309 gint detail = e->xfocus.detail;
310 Window win = e->xany.window;
312 if (e->type == FocusIn) {
313 /* These are ones we never want.. */
315 /* This means focus was given by a keyboard/mouse grab. */
316 if (mode == NotifyGrab)
318 /* This means focus was given back from a keyboard/mouse grab. */
319 if (mode == NotifyUngrab)
322 /* These are the ones we want.. */
324 if (win == obt_root(ob_screen)) {
325 /* If looking for a focus in on a client, then always return
326 FALSE for focus in's to the root window */
329 /* This means focus reverted off of a client */
330 else if (detail == NotifyPointerRoot ||
331 detail == NotifyDetailNone ||
332 detail == NotifyInferior ||
333 /* This means focus got here from another screen */
334 detail == NotifyNonlinear)
340 /* It was on a client, was it a valid one?
341 It's possible to get a FocusIn event for a client that was managed
344 if (in_client_only) {
345 ObWindow *w = window_find(e->xfocus.window);
346 if (!w || !WINDOW_IS_CLIENT(w))
350 /* This means focus reverted to parent from the client (this
351 happens often during iconify animation) */
352 if (detail == NotifyInferior)
356 /* This means focus moved from the root window to a client */
357 if (detail == NotifyVirtual)
359 /* This means focus moved from one client to another */
360 if (detail == NotifyNonlinearVirtual)
366 g_assert(e->type == FocusOut);
368 /* These are ones we never want.. */
370 /* This means focus was taken by a keyboard/mouse grab. */
371 if (mode == NotifyGrab)
373 /* This means focus was grabbed on a window and it was released. */
374 if (mode == NotifyUngrab)
377 /* Focus left the root window revertedto state */
378 if (win == obt_root(ob_screen))
381 /* These are the ones we want.. */
383 /* This means focus moved from a client to the root window */
384 if (detail == NotifyVirtual)
386 /* This means focus moved from one client to another */
387 if (detail == NotifyNonlinearVirtual)
395 static Bool event_look_for_focusin(Display *d, XEvent *e, XPointer arg)
397 return e->type == FocusIn && wanted_focusevent(e, FALSE);
400 static Bool event_look_for_focusin_client(Display *d, XEvent *e, XPointer arg)
402 return e->type == FocusIn && wanted_focusevent(e, TRUE);
405 static void print_focusevent(XEvent *e)
407 gint mode = e->xfocus.mode;
408 gint detail = e->xfocus.detail;
409 Window win = e->xany.window;
410 const gchar *modestr, *detailstr;
413 case NotifyNormal: modestr="NotifyNormal"; break;
414 case NotifyGrab: modestr="NotifyGrab"; break;
415 case NotifyUngrab: modestr="NotifyUngrab"; break;
416 case NotifyWhileGrabbed: modestr="NotifyWhileGrabbed"; break;
419 case NotifyAncestor: detailstr="NotifyAncestor"; break;
420 case NotifyVirtual: detailstr="NotifyVirtual"; break;
421 case NotifyInferior: detailstr="NotifyInferior"; break;
422 case NotifyNonlinear: detailstr="NotifyNonlinear"; break;
423 case NotifyNonlinearVirtual: detailstr="NotifyNonlinearVirtual"; break;
424 case NotifyPointer: detailstr="NotifyPointer"; break;
425 case NotifyPointerRoot: detailstr="NotifyPointerRoot"; break;
426 case NotifyDetailNone: detailstr="NotifyDetailNone"; break;
429 if (mode == NotifyGrab || mode == NotifyUngrab)
434 ob_debug_type(OB_DEBUG_FOCUS, "Focus%s 0x%x mode=%s detail=%s",
435 (e->xfocus.type == FocusIn ? "In" : "Out"),
441 static gboolean event_ignore(XEvent *e, ObClient *client)
446 if (!wanted_focusevent(e, FALSE))
451 if (!wanted_focusevent(e, FALSE))
458 static void event_process(const XEvent *ec, gpointer data)
461 ObEventData *ed = data;
464 ObClient *client = NULL;
466 ObDockApp *dockapp = NULL;
467 ObWindow *obwin = NULL;
468 ObMenuFrame *menu = NULL;
470 /* make a copy we can mangle */
474 window = event_get_window(e);
475 if (window == obt_root(ob_screen))
476 /* don't do any lookups, waste of cpu */;
477 else if ((obwin = window_find(window))) {
478 switch (obwin->type) {
479 case OB_WINDOW_CLASS_DOCK:
480 dock = WINDOW_AS_DOCK(obwin);
482 case OB_WINDOW_CLASS_CLIENT:
483 client = WINDOW_AS_CLIENT(obwin);
485 case OB_WINDOW_CLASS_MENUFRAME:
486 menu = WINDOW_AS_MENUFRAME(obwin);
488 case OB_WINDOW_CLASS_INTERNAL:
489 /* we don't do anything with events directly on these windows */
494 dockapp = dock_find_dockapp(window);
496 event_set_curtime(e);
497 event_curserial = e->xany.serial;
499 if (event_ignore(e, client)) {
506 /* deal with it in the kernel */
508 if (e->type == FocusIn) {
510 e->xfocus.detail == NotifyInferior)
512 ob_debug_type(OB_DEBUG_FOCUS,
513 "Focus went to the frame window");
515 focus_left_screen = FALSE;
517 focus_fallback(FALSE, config_focus_under_mouse, TRUE, TRUE);
519 /* We don't get a FocusOut for this case, because it's just moving
520 from our Inferior up to us. This happens when iconifying a
521 window with RevertToParent focus */
522 frame_adjust_focus(client->frame, FALSE);
523 /* focus_set_client(NULL) has already been called */
525 else if (e->xfocus.detail == NotifyPointerRoot ||
526 e->xfocus.detail == NotifyDetailNone ||
527 e->xfocus.detail == NotifyInferior ||
528 e->xfocus.detail == NotifyNonlinear)
532 ob_debug_type(OB_DEBUG_FOCUS,
533 "Focus went to root or pointer root/none");
535 if (e->xfocus.detail == NotifyInferior ||
536 e->xfocus.detail == NotifyNonlinear)
538 focus_left_screen = FALSE;
541 /* If another FocusIn is in the queue then don't fallback yet. This
542 fixes the fun case of:
543 window map -> send focusin
544 window unmap -> get focusout
545 window map -> send focusin
546 get first focus out -> fall back to something (new window
547 hasn't received focus yet, so something else) -> send focusin
548 which means the "something else" is the last thing to get a
549 focusin sent to it, so the new window doesn't end up with focus.
551 But if the other focus in is something like PointerRoot then we
552 still want to fall back.
554 if (XCheckIfEvent(obt_display, &ce, event_look_for_focusin_client,
557 XPutBackEvent(obt_display, &ce);
558 ob_debug_type(OB_DEBUG_FOCUS,
559 " but another FocusIn is coming");
561 /* Focus has been reverted.
563 FocusOut events come after UnmapNotify, so we don't need to
564 worry about focusing an invalid window
567 if (!focus_left_screen)
568 focus_fallback(FALSE, config_focus_under_mouse,
574 ob_debug_type(OB_DEBUG_FOCUS,
575 "Focus went to a window that is already gone");
577 /* If you send focus to a window and then it disappears, you can
578 get the FocusIn for it, after it is unmanaged.
579 Just wait for the next FocusOut/FocusIn pair, but make note that
580 the window that was focused no longer is. */
581 focus_set_client(NULL);
583 else if (client != focus_client) {
584 focus_left_screen = FALSE;
585 frame_adjust_focus(client->frame, TRUE);
586 focus_set_client(client);
587 client_calc_layer(client);
588 client_bring_helper_windows(client);
590 } else if (e->type == FocusOut) {
593 /* Look for the followup FocusIn */
594 if (!XCheckIfEvent(obt_display, &ce, event_look_for_focusin, NULL)) {
595 /* There is no FocusIn, this means focus went to a window that
596 is not being managed, or a window on another screen. */
600 obt_display_ignore_errors(TRUE);
601 if (XGetInputFocus(obt_display, &win, &i) &&
602 XGetGeometry(obt_display, win, &root, &i,&i,&u,&u,&u,&u) &&
603 root != obt_root(ob_screen))
605 ob_debug_type(OB_DEBUG_FOCUS,
606 "Focus went to another screen !");
607 focus_left_screen = TRUE;
610 ob_debug_type(OB_DEBUG_FOCUS,
611 "Focus went to a black hole !");
612 obt_display_ignore_errors(FALSE);
613 /* nothing is focused */
614 focus_set_client(NULL);
616 /* Focus moved, so process the FocusIn event */
617 ObEventData ed = { .ignored = FALSE };
618 event_process(&ce, &ed);
620 /* The FocusIn was ignored, this means it was on a window
621 that isn't a client. */
622 ob_debug_type(OB_DEBUG_FOCUS,
623 "Focus went to an unmanaged window 0x%x !",
625 focus_fallback(TRUE, config_focus_under_mouse, TRUE, TRUE);
629 if (client && client != focus_client) {
630 frame_adjust_focus(client->frame, FALSE);
631 /* focus_set_client(NULL) has already been called in this
632 section or by focus_fallback */
636 event_handle_client(client, e);
638 event_handle_dockapp(dockapp, e);
640 event_handle_dock(dock, e);
642 event_handle_menu(menu, e);
643 else if (window == obt_root(ob_screen))
644 event_handle_root(e);
645 else if (e->type == MapRequest)
646 window_manage(window);
647 else if (e->type == MappingNotify) {
648 /* keyboard layout changes for modifier mapping changes. reload the
649 modifier map, and rebind all the key bindings as appropriate */
650 ob_debug("Kepboard map changed. Reloading keyboard bindings.");
651 obt_keyboard_reload();
654 else if (e->type == ClientMessage) {
655 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
656 windows that are not managed yet. */
657 if (e->xclient.message_type ==
658 OBT_PROP_ATOM(NET_REQUEST_FRAME_EXTENTS))
660 /* Pretend to manage the client, getting information used to
661 determine its decorations */
662 ObClient *c = client_fake_manage(e->xclient.window);
665 /* set the frame extents on the window */
666 vals[0] = c->frame->size.left;
667 vals[1] = c->frame->size.right;
668 vals[2] = c->frame->size.top;
669 vals[3] = c->frame->size.bottom;
670 OBT_PROP_SETA32(e->xclient.window, NET_FRAME_EXTENTS,
673 /* Free the pretend client */
674 client_fake_unmanage(c);
677 else if (e->type == ConfigureRequest) {
678 /* unhandled configure requests must be used to configure the
682 xwc.x = e->xconfigurerequest.x;
683 xwc.y = e->xconfigurerequest.y;
684 xwc.width = e->xconfigurerequest.width;
685 xwc.height = e->xconfigurerequest.height;
686 xwc.border_width = e->xconfigurerequest.border_width;
687 xwc.sibling = e->xconfigurerequest.above;
688 xwc.stack_mode = e->xconfigurerequest.detail;
690 /* we are not to be held responsible if someone sends us an
692 obt_display_ignore_errors(TRUE);
693 XConfigureWindow(obt_display, window,
694 e->xconfigurerequest.value_mask, &xwc);
695 obt_display_ignore_errors(FALSE);
698 else if (obt_display_extension_sync &&
699 e->type == obt_display_extension_sync_basep + XSyncAlarmNotify)
701 XSyncAlarmNotifyEvent *se = (XSyncAlarmNotifyEvent*)e;
702 if (se->alarm == moveresize_alarm && moveresize_in_progress)
707 if (e->type == ButtonPress || e->type == ButtonRelease) {
708 /* If the button press was on some non-root window, or was physically
709 on the root window, then process it */
710 if (window != obt_root(ob_screen) ||
711 e->xbutton.subwindow == None)
713 event_handle_user_input(client, e);
715 /* Otherwise only process it if it was physically on an openbox
720 if ((w = window_find(e->xbutton.subwindow)) &&
721 WINDOW_IS_INTERNAL(w))
723 event_handle_user_input(client, e);
727 else if (e->type == KeyPress || e->type == KeyRelease ||
728 e->type == MotionNotify)
729 event_handle_user_input(client, e);
731 /* if something happens and it's not from an XEvent, then we don't know
733 event_curtime = CurrentTime;
737 static void event_handle_root(XEvent *e)
743 ob_debug("Another WM has requested to replace us. Exiting.");
748 if (e->xclient.format != 32) break;
750 msgtype = e->xclient.message_type;
751 if (msgtype == OBT_PROP_ATOM(NET_CURRENT_DESKTOP)) {
752 guint d = e->xclient.data.l[0];
753 if (d < screen_num_desktops) {
754 event_curtime = e->xclient.data.l[1];
755 if (event_curtime == 0)
756 ob_debug_type(OB_DEBUG_APP_BUGS,
757 "_NET_CURRENT_DESKTOP message is missing "
759 screen_set_desktop(d, TRUE);
761 } else if (msgtype == OBT_PROP_ATOM(NET_NUMBER_OF_DESKTOPS)) {
762 guint d = e->xclient.data.l[0];
763 if (d > 0 && d <= 1000)
764 screen_set_num_desktops(d);
765 } else if (msgtype == OBT_PROP_ATOM(NET_SHOWING_DESKTOP)) {
766 screen_show_desktop(e->xclient.data.l[0] != 0, NULL);
767 } else if (msgtype == OBT_PROP_ATOM(OB_CONTROL)) {
768 ob_debug("OB_CONTROL: %d", e->xclient.data.l[0]);
769 if (e->xclient.data.l[0] == 1)
771 else if (e->xclient.data.l[0] == 2)
773 else if (e->xclient.data.l[0] == 3)
775 } else if (msgtype == OBT_PROP_ATOM(WM_PROTOCOLS)) {
776 if ((Atom)e->xclient.data.l[0] == OBT_PROP_ATOM(NET_WM_PING))
777 ping_got_pong(e->xclient.data.l[1]);
781 if (e->xproperty.atom == OBT_PROP_ATOM(NET_DESKTOP_NAMES)) {
782 ob_debug("UPDATE DESKTOP NAMES");
783 screen_update_desktop_names();
785 else if (e->xproperty.atom == OBT_PROP_ATOM(NET_DESKTOP_LAYOUT))
786 screen_update_layout();
788 case ConfigureNotify:
790 XRRUpdateConfiguration(e);
799 void event_enter_client(ObClient *client)
801 g_assert(config_focus_follow);
803 if (is_enter_focus_event_ignored(event_curserial)) {
804 ob_debug_type(OB_DEBUG_FOCUS, "Ignoring enter event with serial %lu\n"
805 "on client 0x%x", event_curserial, client->window);
809 if (client_enter_focusable(client) && client_can_focus(client)) {
810 if (config_focus_delay) {
811 ObFocusDelayData *data;
813 obt_main_loop_timeout_remove(ob_main_loop, focus_delay_func);
815 data = g_new(ObFocusDelayData, 1);
816 data->client = client;
817 data->time = event_curtime;
818 data->serial = event_curserial;
820 obt_main_loop_timeout_add(ob_main_loop,
821 config_focus_delay * 1000,
823 data, focus_delay_cmp, focus_delay_dest);
825 ObFocusDelayData data;
826 data.client = client;
827 data.time = event_curtime;
828 data.serial = event_curserial;
829 focus_delay_func(&data);
834 static void event_handle_client(ObClient *client, XEvent *e)
839 static gint px = -1, py = -1;
844 /* save where the press occured for the first button pressed */
846 pb = e->xbutton.button;
851 /* Wheel buttons don't draw because they are an instant click, so it
852 is a waste of resources to go drawing it.
853 if the user is doing an intereactive thing, or has a menu open then
854 the mouse is grabbed (possibly) and if we get these events we don't
855 want to deal with them
857 if (!(e->xbutton.button == 4 || e->xbutton.button == 5) &&
860 /* use where the press occured */
861 con = frame_context(client, e->xbutton.window, px, py);
862 con = mouse_button_frame_context(con, e->xbutton.button,
865 if (e->type == ButtonRelease && e->xbutton.button == pb)
866 pb = 0, px = py = -1;
869 case OB_FRAME_CONTEXT_MAXIMIZE:
870 client->frame->max_press = (e->type == ButtonPress);
871 frame_adjust_state(client->frame);
873 case OB_FRAME_CONTEXT_CLOSE:
874 client->frame->close_press = (e->type == ButtonPress);
875 frame_adjust_state(client->frame);
877 case OB_FRAME_CONTEXT_ICONIFY:
878 client->frame->iconify_press = (e->type == ButtonPress);
879 frame_adjust_state(client->frame);
881 case OB_FRAME_CONTEXT_ALLDESKTOPS:
882 client->frame->desk_press = (e->type == ButtonPress);
883 frame_adjust_state(client->frame);
885 case OB_FRAME_CONTEXT_SHADE:
886 client->frame->shade_press = (e->type == ButtonPress);
887 frame_adjust_state(client->frame);
890 /* nothing changes with clicks for any other contexts */
896 /* when there is a grab on the pointer, we won't get enter/leave
897 notifies, but we still get motion events */
898 if (grab_on_pointer()) break;
900 con = frame_context(client, e->xmotion.window,
901 e->xmotion.x, e->xmotion.y);
903 case OB_FRAME_CONTEXT_TITLEBAR:
904 case OB_FRAME_CONTEXT_TLCORNER:
905 case OB_FRAME_CONTEXT_TRCORNER:
906 /* we've left the button area inside the titlebar */
907 if (client->frame->max_hover || client->frame->desk_hover ||
908 client->frame->shade_hover || client->frame->iconify_hover ||
909 client->frame->close_hover)
911 client->frame->max_hover = FALSE;
912 client->frame->desk_hover = FALSE;
913 client->frame->shade_hover = FALSE;
914 client->frame->iconify_hover = FALSE;
915 client->frame->close_hover = FALSE;
916 frame_adjust_state(client->frame);
919 case OB_FRAME_CONTEXT_MAXIMIZE:
920 if (!client->frame->max_hover) {
921 client->frame->max_hover = TRUE;
922 frame_adjust_state(client->frame);
925 case OB_FRAME_CONTEXT_ALLDESKTOPS:
926 if (!client->frame->desk_hover) {
927 client->frame->desk_hover = TRUE;
928 frame_adjust_state(client->frame);
931 case OB_FRAME_CONTEXT_SHADE:
932 if (!client->frame->shade_hover) {
933 client->frame->shade_hover = TRUE;
934 frame_adjust_state(client->frame);
937 case OB_FRAME_CONTEXT_ICONIFY:
938 if (!client->frame->iconify_hover) {
939 client->frame->iconify_hover = TRUE;
940 frame_adjust_state(client->frame);
943 case OB_FRAME_CONTEXT_CLOSE:
944 if (!client->frame->close_hover) {
945 client->frame->close_hover = TRUE;
946 frame_adjust_state(client->frame);
954 con = frame_context(client, e->xcrossing.window,
955 e->xcrossing.x, e->xcrossing.y);
957 case OB_FRAME_CONTEXT_TITLEBAR:
958 case OB_FRAME_CONTEXT_TLCORNER:
959 case OB_FRAME_CONTEXT_TRCORNER:
960 /* we've left the button area inside the titlebar */
961 if (client->frame->max_hover || client->frame->desk_hover ||
962 client->frame->shade_hover || client->frame->iconify_hover ||
963 client->frame->close_hover)
965 client->frame->max_hover = FALSE;
966 client->frame->desk_hover = FALSE;
967 client->frame->shade_hover = FALSE;
968 client->frame->iconify_hover = FALSE;
969 client->frame->close_hover = FALSE;
970 frame_adjust_state(client->frame);
973 case OB_FRAME_CONTEXT_MAXIMIZE:
974 client->frame->max_hover = FALSE;
975 frame_adjust_state(client->frame);
977 case OB_FRAME_CONTEXT_ALLDESKTOPS:
978 client->frame->desk_hover = FALSE;
979 frame_adjust_state(client->frame);
981 case OB_FRAME_CONTEXT_SHADE:
982 client->frame->shade_hover = FALSE;
983 frame_adjust_state(client->frame);
985 case OB_FRAME_CONTEXT_ICONIFY:
986 client->frame->iconify_hover = FALSE;
987 frame_adjust_state(client->frame);
989 case OB_FRAME_CONTEXT_CLOSE:
990 client->frame->close_hover = FALSE;
991 frame_adjust_state(client->frame);
993 case OB_FRAME_CONTEXT_FRAME:
994 /* When the mouse leaves an animating window, don't use the
995 corresponding enter events. Pretend like the animating window
996 doesn't even exist..! */
997 if (frame_iconify_animating(client->frame))
998 event_end_ignore_all_enters(event_start_ignore_all_enters());
1000 ob_debug_type(OB_DEBUG_FOCUS,
1001 "%sNotify mode %d detail %d on %lx",
1002 (e->type == EnterNotify ? "Enter" : "Leave"),
1004 e->xcrossing.detail, (client?client->window:0));
1005 if (grab_on_keyboard())
1007 if (config_focus_follow && config_focus_delay &&
1008 /* leave inferior events can happen when the mouse goes onto
1009 the window's border and then into the window before the
1011 e->xcrossing.detail != NotifyInferior)
1013 obt_main_loop_timeout_remove_data(ob_main_loop,
1024 con = frame_context(client, e->xcrossing.window,
1025 e->xcrossing.x, e->xcrossing.y);
1027 case OB_FRAME_CONTEXT_MAXIMIZE:
1028 client->frame->max_hover = TRUE;
1029 frame_adjust_state(client->frame);
1031 case OB_FRAME_CONTEXT_ALLDESKTOPS:
1032 client->frame->desk_hover = TRUE;
1033 frame_adjust_state(client->frame);
1035 case OB_FRAME_CONTEXT_SHADE:
1036 client->frame->shade_hover = TRUE;
1037 frame_adjust_state(client->frame);
1039 case OB_FRAME_CONTEXT_ICONIFY:
1040 client->frame->iconify_hover = TRUE;
1041 frame_adjust_state(client->frame);
1043 case OB_FRAME_CONTEXT_CLOSE:
1044 client->frame->close_hover = TRUE;
1045 frame_adjust_state(client->frame);
1047 case OB_FRAME_CONTEXT_FRAME:
1048 if (grab_on_keyboard())
1050 if (e->xcrossing.mode == NotifyGrab ||
1051 e->xcrossing.mode == NotifyUngrab ||
1052 /*ignore enters when we're already in the window */
1053 e->xcrossing.detail == NotifyInferior)
1055 ob_debug_type(OB_DEBUG_FOCUS,
1056 "%sNotify mode %d detail %d serial %lu on %lx "
1058 (e->type == EnterNotify ? "Enter" : "Leave"),
1060 e->xcrossing.detail,
1061 e->xcrossing.serial,
1062 client?client->window:0);
1065 ob_debug_type(OB_DEBUG_FOCUS,
1066 "%sNotify mode %d detail %d serial %lu on %lx, "
1068 (e->type == EnterNotify ? "Enter" : "Leave"),
1070 e->xcrossing.detail,
1071 e->xcrossing.serial,
1072 (client?client->window:0));
1073 if (config_focus_follow)
1074 event_enter_client(client);
1082 case ConfigureRequest:
1084 /* dont compress these unless you're going to watch for property
1085 notifies in between (these can change what the configure would
1087 also you can't compress stacking events
1091 gboolean move = FALSE;
1092 gboolean resize = FALSE;
1094 /* get the current area */
1095 RECT_TO_DIMS(client->area, x, y, w, h);
1097 ob_debug("ConfigureRequest for \"%s\" desktop %d wmstate %d "
1100 screen_desktop, client->wmstate, client->frame->visible);
1101 ob_debug(" x %d y %d w %d h %d b %d",
1102 x, y, w, h, client->border_width);
1104 if (e->xconfigurerequest.value_mask & CWBorderWidth)
1105 if (client->border_width != e->xconfigurerequest.border_width) {
1106 client->border_width = e->xconfigurerequest.border_width;
1108 /* if the border width is changing then that is the same
1109 as requesting a resize, but we don't actually change
1110 the client's border, so it will change their root
1111 coordiantes (since they include the border width) and
1112 we need to a notify then */
1117 if (e->xconfigurerequest.value_mask & CWStackMode) {
1118 ObClient *sibling = NULL;
1119 gulong ignore_start;
1122 /* get the sibling */
1123 if (e->xconfigurerequest.value_mask & CWSibling) {
1125 win = window_find(e->xconfigurerequest.above);
1126 if (win && WINDOW_IS_CLIENT(win) &&
1127 WINDOW_AS_CLIENT(win) != client)
1129 sibling = WINDOW_AS_CLIENT(win);
1132 /* an invalid sibling was specified so don't restack at
1133 all, it won't make sense no matter what we do */
1138 if (!config_focus_under_mouse)
1139 ignore_start = event_start_ignore_all_enters();
1140 stacking_restack_request(client, sibling,
1141 e->xconfigurerequest.detail);
1142 if (!config_focus_under_mouse)
1143 event_end_ignore_all_enters(ignore_start);
1146 /* a stacking change moves the window without resizing */
1150 if ((e->xconfigurerequest.value_mask & CWX) ||
1151 (e->xconfigurerequest.value_mask & CWY) ||
1152 (e->xconfigurerequest.value_mask & CWWidth) ||
1153 (e->xconfigurerequest.value_mask & CWHeight))
1155 if (e->xconfigurerequest.value_mask & CWX) {
1156 /* don't allow clients to move shaded windows (fvwm does this)
1158 if (!client->shaded)
1159 x = e->xconfigurerequest.x;
1162 if (e->xconfigurerequest.value_mask & CWY) {
1163 /* don't allow clients to move shaded windows (fvwm does this)
1165 if (!client->shaded)
1166 y = e->xconfigurerequest.y;
1170 if (e->xconfigurerequest.value_mask & CWWidth) {
1171 w = e->xconfigurerequest.width;
1174 if (e->xconfigurerequest.value_mask & CWHeight) {
1175 h = e->xconfigurerequest.height;
1180 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
1181 "move %d resize %d",
1182 e->xconfigurerequest.value_mask & CWX, x,
1183 e->xconfigurerequest.value_mask & CWY, y,
1184 e->xconfigurerequest.value_mask & CWWidth, w,
1185 e->xconfigurerequest.value_mask & CWHeight, h,
1188 /* check for broken apps moving to their root position
1190 XXX remove this some day...that would be nice. right now all
1191 kde apps do this when they try activate themselves on another
1192 desktop. eg. open amarok window on desktop 1, switch to desktop
1193 2, click amarok tray icon. it will move by its decoration size.
1195 if (x != client->area.x &&
1196 x == (client->frame->area.x + client->frame->size.left -
1197 (gint)client->border_width) &&
1198 y != client->area.y &&
1199 y == (client->frame->area.y + client->frame->size.top -
1200 (gint)client->border_width) &&
1201 w == client->area.width &&
1202 h == client->area.height)
1204 ob_debug_type(OB_DEBUG_APP_BUGS,
1205 "Application %s is trying to move via "
1206 "ConfigureRequest to it's root window position "
1207 "but it is not using StaticGravity",
1213 /* they still requested a move, so don't change whether a
1214 notify is sent or not */
1220 client_try_configure(client, &x, &y, &w, &h, &lw, &lh, FALSE);
1222 /* if x was not given, then use gravity to figure out the new
1223 x. the reference point should not be moved */
1224 if ((e->xconfigurerequest.value_mask & CWWidth &&
1225 !(e->xconfigurerequest.value_mask & CWX)))
1226 client_gravity_resize_w(client, &x, client->area.width, w);
1227 /* if y was not given, then use gravity to figure out the new
1228 y. the reference point should not be moved */
1229 if ((e->xconfigurerequest.value_mask & CWHeight &&
1230 !(e->xconfigurerequest.value_mask & CWY)))
1231 client_gravity_resize_h(client, &y, client->area.height,h);
1233 client_find_onscreen(client, &x, &y, w, h, FALSE);
1235 ob_debug("Granting ConfigureRequest x %d y %d w %d h %d",
1237 client_configure(client, x, y, w, h, FALSE, TRUE, TRUE);
1242 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1244 client->window, e->xunmap.event, e->xunmap.from_configure,
1245 client->ignore_unmaps);
1246 if (client->ignore_unmaps) {
1247 client->ignore_unmaps--;
1250 client_unmanage(client);
1253 ob_debug("DestroyNotify for window 0x%x", client->window);
1254 client_unmanage(client);
1256 case ReparentNotify:
1257 /* this is when the client is first taken captive in the frame */
1258 if (e->xreparent.parent == client->frame->window) break;
1261 This event is quite rare and is usually handled in unmapHandler.
1262 However, if the window is unmapped when the reparent event occurs,
1263 the window manager never sees it because an unmap event is not sent
1264 to an already unmapped window.
1267 /* we don't want the reparent event, put it back on the stack for the
1268 X server to deal with after we unmanage the window */
1269 XPutBackEvent(obt_display, e);
1271 ob_debug("ReparentNotify for window 0x%x", client->window);
1272 client_unmanage(client);
1275 ob_debug("MapRequest for 0x%lx", client->window);
1276 if (!client->iconic) break; /* this normally doesn't happen, but if it
1277 does, we don't want it!
1278 it can happen now when the window is on
1279 another desktop, but we still don't
1281 client_activate(client, FALSE, TRUE, TRUE, TRUE);
1284 /* validate cuz we query stuff off the client here */
1285 if (!client_validate(client)) break;
1287 if (e->xclient.format != 32) return;
1289 msgtype = e->xclient.message_type;
1290 if (msgtype == OBT_PROP_ATOM(WM_CHANGE_STATE)) {
1291 /* compress changes into a single change */
1292 while (XCheckTypedWindowEvent(obt_display, client->window,
1294 /* XXX: it would be nice to compress ALL messages of a
1295 type, not just messages in a row without other
1296 message types between. */
1297 if (ce.xclient.message_type != msgtype) {
1298 XPutBackEvent(obt_display, &ce);
1301 e->xclient = ce.xclient;
1303 client_set_wm_state(client, e->xclient.data.l[0]);
1304 } else if (msgtype == OBT_PROP_ATOM(NET_WM_DESKTOP)) {
1305 /* compress changes into a single change */
1306 while (XCheckTypedWindowEvent(obt_display, client->window,
1308 /* XXX: it would be nice to compress ALL messages of a
1309 type, not just messages in a row without other
1310 message types between. */
1311 if (ce.xclient.message_type != msgtype) {
1312 XPutBackEvent(obt_display, &ce);
1315 e->xclient = ce.xclient;
1317 if ((unsigned)e->xclient.data.l[0] < screen_num_desktops ||
1318 (unsigned)e->xclient.data.l[0] == DESKTOP_ALL)
1319 client_set_desktop(client, (unsigned)e->xclient.data.l[0],
1321 } else if (msgtype == OBT_PROP_ATOM(NET_WM_STATE)) {
1322 gulong ignore_start;
1324 /* can't compress these */
1325 ob_debug("net_wm_state %s %ld %ld for 0x%lx",
1326 (e->xclient.data.l[0] == 0 ? "Remove" :
1327 e->xclient.data.l[0] == 1 ? "Add" :
1328 e->xclient.data.l[0] == 2 ? "Toggle" : "INVALID"),
1329 e->xclient.data.l[1], e->xclient.data.l[2],
1332 /* ignore enter events caused by these like ob actions do */
1333 if (!config_focus_under_mouse)
1334 ignore_start = event_start_ignore_all_enters();
1335 client_set_state(client, e->xclient.data.l[0],
1336 e->xclient.data.l[1], e->xclient.data.l[2]);
1337 if (!config_focus_under_mouse)
1338 event_end_ignore_all_enters(ignore_start);
1339 } else if (msgtype == OBT_PROP_ATOM(NET_CLOSE_WINDOW)) {
1340 ob_debug("net_close_window for 0x%lx", client->window);
1341 client_close(client);
1342 } else if (msgtype == OBT_PROP_ATOM(NET_ACTIVE_WINDOW)) {
1343 ob_debug("net_active_window for 0x%lx source=%s",
1345 (e->xclient.data.l[0] == 0 ? "unknown" :
1346 (e->xclient.data.l[0] == 1 ? "application" :
1347 (e->xclient.data.l[0] == 2 ? "user" : "INVALID"))));
1348 /* XXX make use of data.l[2] !? */
1349 if (e->xclient.data.l[0] == 1 || e->xclient.data.l[0] == 2) {
1350 /* don't use the user's timestamp for client_focus, cuz if it's
1351 an old broken timestamp (happens all the time) then focus
1352 won't move even though we're trying to move it
1353 event_curtime = e->xclient.data.l[1];*/
1354 if (e->xclient.data.l[1] == 0)
1355 ob_debug_type(OB_DEBUG_APP_BUGS,
1356 "_NET_ACTIVE_WINDOW message for window %s is"
1357 " missing a timestamp", client->title);
1359 ob_debug_type(OB_DEBUG_APP_BUGS,
1360 "_NET_ACTIVE_WINDOW message for window %s is "
1361 "missing source indication");
1362 client_activate(client, FALSE, TRUE, TRUE,
1363 (e->xclient.data.l[0] == 0 ||
1364 e->xclient.data.l[0] == 2));
1365 } else if (msgtype == OBT_PROP_ATOM(NET_WM_MOVERESIZE)) {
1366 ob_debug("net_wm_moveresize for 0x%lx direction %d",
1367 client->window, e->xclient.data.l[2]);
1368 if ((Atom)e->xclient.data.l[2] ==
1369 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT) ||
1370 (Atom)e->xclient.data.l[2] ==
1371 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP) ||
1372 (Atom)e->xclient.data.l[2] ==
1373 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT) ||
1374 (Atom)e->xclient.data.l[2] ==
1375 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT) ||
1376 (Atom)e->xclient.data.l[2] ==
1377 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT) ||
1378 (Atom)e->xclient.data.l[2] ==
1379 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT) ||
1380 (Atom)e->xclient.data.l[2] ==
1381 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM) ||
1382 (Atom)e->xclient.data.l[2] ==
1383 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT) ||
1384 (Atom)e->xclient.data.l[2] ==
1385 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT) ||
1386 (Atom)e->xclient.data.l[2] ==
1387 OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE) ||
1388 (Atom)e->xclient.data.l[2] ==
1389 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD) ||
1390 (Atom)e->xclient.data.l[2] ==
1391 OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD))
1393 moveresize_start(client, e->xclient.data.l[0],
1394 e->xclient.data.l[1], e->xclient.data.l[3],
1395 e->xclient.data.l[2]);
1397 else if ((Atom)e->xclient.data.l[2] ==
1398 OBT_PROP_ATOM(NET_WM_MOVERESIZE_CANCEL))
1399 moveresize_end(TRUE);
1400 } else if (msgtype == OBT_PROP_ATOM(NET_MOVERESIZE_WINDOW)) {
1401 gint ograv, x, y, w, h;
1403 ograv = client->gravity;
1405 if (e->xclient.data.l[0] & 0xff)
1406 client->gravity = e->xclient.data.l[0] & 0xff;
1408 if (e->xclient.data.l[0] & 1 << 8)
1409 x = e->xclient.data.l[1];
1412 if (e->xclient.data.l[0] & 1 << 9)
1413 y = e->xclient.data.l[2];
1417 if (e->xclient.data.l[0] & 1 << 10) {
1418 w = e->xclient.data.l[3];
1420 /* if x was not given, then use gravity to figure out the new
1421 x. the reference point should not be moved */
1422 if (!(e->xclient.data.l[0] & 1 << 8))
1423 client_gravity_resize_w(client, &x, client->area.width, w);
1426 w = client->area.width;
1428 if (e->xclient.data.l[0] & 1 << 11) {
1429 h = e->xclient.data.l[4];
1431 /* if y was not given, then use gravity to figure out the new
1432 y. the reference point should not be moved */
1433 if (!(e->xclient.data.l[0] & 1 << 9))
1434 client_gravity_resize_h(client, &y, client->area.height,h);
1437 h = client->area.height;
1439 ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)",
1440 e->xclient.data.l[0] & 1 << 8, x,
1441 e->xclient.data.l[0] & 1 << 9, y,
1444 client_find_onscreen(client, &x, &y, w, h, FALSE);
1446 client_configure(client, x, y, w, h, FALSE, TRUE, FALSE);
1448 client->gravity = ograv;
1449 } else if (msgtype == OBT_PROP_ATOM(NET_RESTACK_WINDOW)) {
1450 if (e->xclient.data.l[0] != 2) {
1451 ob_debug_type(OB_DEBUG_APP_BUGS,
1452 "_NET_RESTACK_WINDOW sent for window %s with "
1453 "invalid source indication %ld",
1454 client->title, e->xclient.data.l[0]);
1456 ObClient *sibling = NULL;
1457 if (e->xclient.data.l[1]) {
1458 ObWindow *win = window_find(e->xclient.data.l[1]);
1459 if (WINDOW_IS_CLIENT(win) &&
1460 WINDOW_AS_CLIENT(win) != client)
1462 sibling = WINDOW_AS_CLIENT(win);
1464 if (sibling == NULL)
1465 ob_debug_type(OB_DEBUG_APP_BUGS,
1466 "_NET_RESTACK_WINDOW sent for window %s "
1467 "with invalid sibling 0x%x",
1468 client->title, e->xclient.data.l[1]);
1470 if (e->xclient.data.l[2] == Below ||
1471 e->xclient.data.l[2] == BottomIf ||
1472 e->xclient.data.l[2] == Above ||
1473 e->xclient.data.l[2] == TopIf ||
1474 e->xclient.data.l[2] == Opposite)
1476 gulong ignore_start;
1478 if (!config_focus_under_mouse)
1479 ignore_start = event_start_ignore_all_enters();
1480 /* just raise, don't activate */
1481 stacking_restack_request(client, sibling,
1482 e->xclient.data.l[2]);
1483 if (!config_focus_under_mouse)
1484 event_end_ignore_all_enters(ignore_start);
1486 /* send a synthetic ConfigureNotify, cuz this is supposed
1487 to be like a ConfigureRequest. */
1488 client_reconfigure(client, TRUE);
1490 ob_debug_type(OB_DEBUG_APP_BUGS,
1491 "_NET_RESTACK_WINDOW sent for window %s "
1492 "with invalid detail %d",
1493 client->title, e->xclient.data.l[2]);
1497 case PropertyNotify:
1498 /* validate cuz we query stuff off the client here */
1499 if (!client_validate(client)) break;
1501 /* compress changes to a single property into a single change */
1502 while (XCheckTypedWindowEvent(obt_display, client->window,
1506 /* XXX: it would be nice to compress ALL changes to a property,
1507 not just changes in a row without other props between. */
1509 a = ce.xproperty.atom;
1510 b = e->xproperty.atom;
1514 if ((a == OBT_PROP_ATOM(NET_WM_NAME) ||
1515 a == OBT_PROP_ATOM(WM_NAME) ||
1516 a == OBT_PROP_ATOM(NET_WM_ICON_NAME) ||
1517 a == OBT_PROP_ATOM(WM_ICON_NAME))
1519 (b == OBT_PROP_ATOM(NET_WM_NAME) ||
1520 b == OBT_PROP_ATOM(WM_NAME) ||
1521 b == OBT_PROP_ATOM(NET_WM_ICON_NAME) ||
1522 b == OBT_PROP_ATOM(WM_ICON_NAME))) {
1525 if (a == OBT_PROP_ATOM(NET_WM_ICON) &&
1526 b == OBT_PROP_ATOM(NET_WM_ICON))
1529 XPutBackEvent(obt_display, &ce);
1533 msgtype = e->xproperty.atom;
1534 if (msgtype == XA_WM_NORMAL_HINTS) {
1535 ob_debug("Update NORMAL hints");
1536 client_update_normal_hints(client);
1537 /* normal hints can make a window non-resizable */
1538 client_setup_decor_and_functions(client, FALSE);
1540 /* make sure the client's sizes are within its bounds, but only
1541 reconfigure the window if it needs to. emacs will update its
1542 normal hints every time it receives a conigurenotify */
1543 client_reconfigure(client, FALSE);
1544 } else if (msgtype == XA_WM_HINTS) {
1545 client_update_wmhints(client);
1546 } else if (msgtype == XA_WM_TRANSIENT_FOR) {
1547 client_update_transient_for(client);
1548 client_get_type_and_transientness(client);
1549 /* type may have changed, so update the layer */
1550 client_calc_layer(client);
1551 client_setup_decor_and_functions(client, TRUE);
1552 } else if (msgtype == OBT_PROP_ATOM(NET_WM_NAME) ||
1553 msgtype == OBT_PROP_ATOM(WM_NAME) ||
1554 msgtype == OBT_PROP_ATOM(NET_WM_ICON_NAME) ||
1555 msgtype == OBT_PROP_ATOM(WM_ICON_NAME)) {
1556 client_update_title(client);
1557 } else if (msgtype == OBT_PROP_ATOM(WM_PROTOCOLS)) {
1558 client_update_protocols(client);
1559 client_setup_decor_and_functions(client, TRUE);
1561 else if (msgtype == OBT_PROP_ATOM(NET_WM_STRUT)) {
1562 client_update_strut(client);
1564 else if (msgtype == OBT_PROP_ATOM(NET_WM_STRUT_PARTIAL)) {
1565 client_update_strut(client);
1567 else if (msgtype == OBT_PROP_ATOM(NET_WM_ICON)) {
1568 client_update_icons(client);
1570 else if (msgtype == OBT_PROP_ATOM(NET_WM_ICON_GEOMETRY)) {
1571 client_update_icon_geometry(client);
1573 else if (msgtype == OBT_PROP_ATOM(NET_WM_USER_TIME)) {
1575 if (client == focus_client &&
1576 OBT_PROP_GET32(client->window, NET_WM_USER_TIME, CARDINAL, &t)
1577 && t && !event_time_after(t, e->xproperty.time) &&
1578 (!event_last_user_time ||
1579 event_time_after(t, event_last_user_time)))
1581 event_last_user_time = t;
1585 else if (msgtype == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST_COUNTER)) {
1586 client_update_sync_request_counter(client);
1590 case ColormapNotify:
1591 client_update_colormap(client, e->xcolormap.colormap);
1596 if (obt_display_extension_shape &&
1597 e->type == obt_display_extension_shape_basep)
1599 client->shaped = ((XShapeEvent*)e)->shaped;
1600 frame_adjust_shape(client->frame);
1606 static void event_handle_dock(ObDock *s, XEvent *e)
1610 if (e->xbutton.button == 1)
1611 stacking_raise(DOCK_AS_WINDOW(s));
1612 else if (e->xbutton.button == 2)
1613 stacking_lower(DOCK_AS_WINDOW(s));
1619 /* don't hide when moving into a dock app */
1620 if (e->xcrossing.detail != NotifyInferior)
1626 static void event_handle_dockapp(ObDockApp *app, XEvent *e)
1630 dock_app_drag(app, &e->xmotion);
1633 if (app->ignore_unmaps) {
1634 app->ignore_unmaps--;
1637 dock_unmanage(app, TRUE);
1640 dock_unmanage(app, FALSE);
1642 case ReparentNotify:
1643 dock_unmanage(app, FALSE);
1645 case ConfigureNotify:
1646 dock_app_configure(app, e->xconfigure.width, e->xconfigure.height);
1651 static ObMenuFrame* find_active_menu(void)
1654 ObMenuFrame *ret = NULL;
1656 for (it = menu_frame_visible; it; it = g_list_next(it)) {
1665 static ObMenuFrame* find_active_or_last_menu(void)
1667 ObMenuFrame *ret = NULL;
1669 ret = find_active_menu();
1670 if (!ret && menu_frame_visible)
1671 ret = menu_frame_visible->data;
1675 static gboolean event_handle_menu_input(XEvent *ev)
1677 gboolean ret = FALSE;
1679 if (ev->type == ButtonRelease) {
1680 ObMenuEntryFrame *e;
1682 if (menu_hide_delay_reached() &&
1683 (ev->xbutton.button < 4 || ev->xbutton.button > 5))
1685 if ((e = menu_entry_frame_under(ev->xbutton.x_root,
1686 ev->xbutton.y_root)))
1688 menu_frame_select(e->frame, e, TRUE);
1689 menu_entry_frame_execute(e, ev->xbutton.state);
1692 menu_frame_hide_all();
1696 else if (ev->type == MotionNotify) {
1698 ObMenuEntryFrame *e;
1700 if ((e = menu_entry_frame_under(ev->xmotion.x_root,
1701 ev->xmotion.y_root)))
1702 if (!(f = find_active_menu()) ||
1704 f->parent == e->frame ||
1705 f->child == e->frame)
1706 menu_frame_select(e->frame, e, FALSE);
1708 else if (ev->type == KeyPress || ev->type == KeyRelease) {
1709 guint keycode, state;
1713 keycode = ev->xkey.keycode;
1714 state = ev->xkey.state;
1715 unikey = obt_keyboard_keycode_to_unichar(keycode);
1717 frame = find_active_or_last_menu();
1719 g_assert_not_reached(); /* there is no active menu */
1721 /* Allow control while going thru the menu */
1722 else if (ev->type == KeyPress && (state & ~ControlMask) == 0) {
1723 frame->got_press = TRUE;
1725 if (keycode == ob_keycode(OB_KEY_ESCAPE)) {
1726 menu_frame_hide_all();
1730 else if (keycode == ob_keycode(OB_KEY_LEFT)) {
1731 /* Left goes to the parent menu */
1732 menu_frame_select(frame, NULL, TRUE);
1736 else if (keycode == ob_keycode(OB_KEY_RIGHT)) {
1737 /* Right goes to the selected submenu */
1738 if (frame->child) menu_frame_select_next(frame->child);
1742 else if (keycode == ob_keycode(OB_KEY_UP)) {
1743 menu_frame_select_previous(frame);
1747 else if (keycode == ob_keycode(OB_KEY_DOWN)) {
1748 menu_frame_select_next(frame);
1753 /* Use KeyRelease events for running things so that the key release
1754 doesn't get sent to the focused application.
1756 Allow ControlMask only, and don't bother if the menu is empty */
1757 else if (ev->type == KeyRelease && (state & ~ControlMask) == 0 &&
1758 frame->entries && frame->got_press)
1760 if (keycode == ob_keycode(OB_KEY_RETURN)) {
1761 /* Enter runs the active item or goes into the submenu.
1762 Control-Enter runs it without closing the menu. */
1764 menu_frame_select_next(frame->child);
1765 else if (frame->selected)
1766 menu_entry_frame_execute(frame->selected, state);
1771 /* keyboard accelerator shortcuts. (if it was a valid key) */
1772 else if (unikey != 0) {
1775 ObMenuEntryFrame *found = NULL;
1776 guint num_found = 0;
1778 /* start after the selected one */
1779 start = frame->entries;
1780 if (frame->selected) {
1781 for (it = start; frame->selected != it->data;
1782 it = g_list_next(it))
1783 g_assert(it != NULL); /* nothing was selected? */
1784 /* next with wraparound */
1785 start = g_list_next(it);
1786 if (start == NULL) start = frame->entries;
1791 ObMenuEntryFrame *e = it->data;
1792 gunichar entrykey = 0;
1794 if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL)
1795 entrykey = e->entry->data.normal.shortcut;
1796 else if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
1797 entrykey = e->entry->data.submenu.submenu->shortcut;
1799 if (unikey == entrykey) {
1800 if (found == NULL) found = e;
1804 /* next with wraparound */
1805 it = g_list_next(it);
1806 if (it == NULL) it = frame->entries;
1807 } while (it != start);
1810 if (found->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
1813 menu_frame_select(frame, found, TRUE);
1814 usleep(50000); /* highlight the item for a short bit so
1815 the user can see what happened */
1816 menu_entry_frame_execute(found, state);
1818 menu_frame_select(frame, found, TRUE);
1820 menu_frame_select_next(frame->child);
1832 static void event_handle_menu(ObMenuFrame *frame, XEvent *ev)
1835 ObMenuEntryFrame *e;
1839 if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window))) {
1840 if (e->ignore_enters)
1842 else if (!(f = find_active_menu()) ||
1844 f->parent == e->frame ||
1845 f->child == e->frame)
1846 menu_frame_select(e->frame, e, FALSE);
1850 /*ignore leaves when we're already in the window */
1851 if (ev->xcrossing.detail == NotifyInferior)
1854 if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window)) &&
1855 (f = find_active_menu()) && f->selected == e &&
1856 e->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU)
1858 menu_frame_select(e->frame, NULL, FALSE);
1864 static void event_handle_user_input(ObClient *client, XEvent *e)
1866 g_assert(e->type == ButtonPress || e->type == ButtonRelease ||
1867 e->type == MotionNotify || e->type == KeyPress ||
1868 e->type == KeyRelease);
1870 if (menu_frame_visible) {
1871 if (event_handle_menu_input(e))
1872 /* don't use the event if the menu used it, but if the menu
1873 didn't use it and it's a keypress that is bound, it will
1874 close the menu and be used */
1878 /* if the keyboard interactive action uses the event then dont
1879 use it for bindings. likewise is moveresize uses the event. */
1880 if (!actions_interactive_input_event(e) && !moveresize_event(e)) {
1881 if (moveresize_in_progress)
1882 /* make further actions work on the client being
1884 client = moveresize_client;
1886 if (e->type == ButtonPress ||
1887 e->type == ButtonRelease ||
1888 e->type == MotionNotify)
1890 /* the frame may not be "visible" but they can still click on it
1891 in the case where it is animating before disappearing */
1892 if (!client || !frame_iconify_animating(client->frame))
1893 mouse_event(client, e);
1895 keyboard_event((focus_cycle_target ? focus_cycle_target :
1896 (client ? client : focus_client)), e);
1900 static void focus_delay_dest(gpointer data)
1905 static gboolean focus_delay_cmp(gconstpointer d1, gconstpointer d2)
1907 const ObFocusDelayData *f1 = d1;
1908 return f1->client == d2;
1911 static gboolean focus_delay_func(gpointer data)
1913 ObFocusDelayData *d = data;
1914 Time old = event_curtime;
1916 /* don't move focus and kill the menu or the move/resize */
1917 if (menu_frame_visible || moveresize_in_progress) return FALSE;
1919 event_curtime = d->time;
1920 event_curserial = d->serial;
1921 if (client_focus(d->client) && config_focus_raise)
1922 stacking_raise(CLIENT_AS_WINDOW(d->client));
1923 event_curtime = old;
1924 return FALSE; /* no repeat */
1927 static void focus_delay_client_dest(ObClient *client, gpointer data)
1929 obt_main_loop_timeout_remove_data(ob_main_loop, focus_delay_func,
1933 void event_halt_focus_delay(void)
1935 /* ignore all enter events up till the event which caused this to occur */
1936 if (event_curserial) event_ignore_enter_range(1, event_curserial);
1937 obt_main_loop_timeout_remove(ob_main_loop, focus_delay_func);
1940 gulong event_start_ignore_all_enters(void)
1942 return NextRequest(obt_display);
1945 static void event_ignore_enter_range(gulong start, gulong end)
1949 g_assert(start != 0);
1952 r = g_new(ObSerialRange, 1);
1955 ignore_serials = g_slist_prepend(ignore_serials, r);
1957 ob_debug_type(OB_DEBUG_FOCUS, "ignoring enters from %lu until %lu",
1960 /* increment the serial so we don't ignore events we weren't meant to */
1961 OBT_PROP_ERASE(screen_support_win, MOTIF_WM_HINTS);
1964 void event_end_ignore_all_enters(gulong start)
1966 /* Use (NextRequest-1) so that we ignore up to the current serial only.
1967 Inside event_ignore_enter_range, we increment the serial by one, but if
1968 we ignore that serial too, then any enter events generated by mouse
1969 movement will be ignored until we create some further network traffic.
1970 Instead ignore up to NextRequest-1, then when we increment the serial,
1971 we will be *past* the range of ignored serials */
1972 event_ignore_enter_range(start, NextRequest(obt_display)-1);
1975 static gboolean is_enter_focus_event_ignored(gulong serial)
1979 for (it = ignore_serials; it; it = next) {
1980 ObSerialRange *r = it->data;
1982 next = g_slist_next(it);
1984 if ((glong)(serial - r->end) > 0) {
1986 ignore_serials = g_slist_delete_link(ignore_serials, it);
1989 else if ((glong)(serial - r->start) >= 0)
1995 void event_cancel_all_key_grabs(void)
1997 if (actions_interactive_act_running()) {
1998 actions_interactive_cancel_act();
1999 ob_debug("KILLED interactive action");
2001 else if (menu_frame_visible) {
2002 menu_frame_hide_all();
2003 ob_debug("KILLED open menus");
2005 else if (moveresize_in_progress) {
2006 moveresize_end(TRUE);
2007 ob_debug("KILLED interactive moveresize");
2009 else if (grab_on_keyboard()) {
2011 ob_debug("KILLED active grab on keyboard");
2014 ungrab_passive_key();
2016 XSync(obt_display, FALSE);
2019 gboolean event_time_after(Time t1, Time t2)
2021 g_assert(t1 != CurrentTime);
2022 g_assert(t2 != CurrentTime);
2025 Timestamp values wrap around (after about 49.7 days). The server, given
2026 its current time is represented by timestamp T, always interprets
2027 timestamps from clients by treating half of the timestamp space as being
2028 later in time than T.
2029 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
2032 /* TIME_HALF is half of the number space of a Time type variable */
2033 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
2035 if (t2 >= TIME_HALF)
2036 /* t2 is in the second half so t1 might wrap around and be smaller than
2038 return t1 >= t2 || t1 < (t2 + TIME_HALF);
2040 /* t2 is in the first half so t1 has to come after it */
2041 return t1 >= t2 && t1 < (t2 + TIME_HALF);
2044 Time event_get_server_time(void)
2046 /* Generate a timestamp */
2049 XChangeProperty(obt_display, screen_support_win,
2050 OBT_PROP_ATOM(WM_CLASS), OBT_PROP_ATOM(STRING),
2051 8, PropModeAppend, NULL, 0);
2052 XWindowEvent(obt_display, screen_support_win, PropertyChangeMask, &event);
2053 return event.xproperty.time;