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
);
268 /* compress events */
271 while (XCheckTypedWindowEvent(ob_display
, e
->xmotion
.window
,
273 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
274 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
281 static gboolean
wanted_focusevent(XEvent
*e
, gboolean in_client_only
)
283 gint mode
= e
->xfocus
.mode
;
284 gint detail
= e
->xfocus
.detail
;
285 Window win
= e
->xany
.window
;
287 if (e
->type
== FocusIn
) {
288 /* These are ones we never want.. */
290 /* This means focus was given by a keyboard/mouse grab. */
291 if (mode
== NotifyGrab
)
293 /* This means focus was given back from a keyboard/mouse grab. */
294 if (mode
== NotifyUngrab
)
297 /* These are the ones we want.. */
299 if (win
== RootWindow(ob_display
, ob_screen
)) {
300 /* If looking for a focus in on a client, then always return
301 FALSE for focus in's to the root window */
304 /* This means focus reverted off of a client */
305 else if (detail
== NotifyPointerRoot
||
306 detail
== NotifyDetailNone
||
307 detail
== NotifyInferior
)
313 /* It was on a client, was it a valid one?
314 It's possible to get a FocusIn event for a client that was managed
317 if (in_client_only
) {
318 ObWindow
*w
= g_hash_table_lookup(window_map
, &e
->xfocus
.window
);
319 if (!w
|| !WINDOW_IS_CLIENT(w
))
323 /* This means focus moved from the root window to a client */
324 if (detail
== NotifyVirtual
)
326 /* This means focus moved from one client to another */
327 if (detail
== NotifyNonlinearVirtual
)
333 g_assert(e
->type
== FocusOut
);
335 /* These are ones we never want.. */
337 /* This means focus was taken by a keyboard/mouse grab. */
338 if (mode
== NotifyGrab
)
341 /* Focus left the root window revertedto state */
342 if (win
== RootWindow(ob_display
, ob_screen
))
345 /* These are the ones we want.. */
347 /* This means focus moved from a client to the root window */
348 if (detail
== NotifyVirtual
)
350 /* This means focus moved from one client to another */
351 if (detail
== NotifyNonlinearVirtual
)
359 static Bool
event_look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
361 return e
->type
== FocusIn
&& wanted_focusevent(e
, FALSE
);
364 static Bool
event_look_for_focusin_client(Display
*d
, XEvent
*e
, XPointer arg
)
366 return e
->type
== FocusIn
&& wanted_focusevent(e
, TRUE
);
369 static void print_focusevent(XEvent
*e
)
371 gint mode
= e
->xfocus
.mode
;
372 gint detail
= e
->xfocus
.detail
;
373 Window win
= e
->xany
.window
;
374 const gchar
*modestr
, *detailstr
;
377 case NotifyNormal
: modestr
="NotifyNormal"; break;
378 case NotifyGrab
: modestr
="NotifyGrab"; break;
379 case NotifyUngrab
: modestr
="NotifyUngrab"; break;
380 case NotifyWhileGrabbed
: modestr
="NotifyWhileGrabbed"; break;
383 case NotifyAncestor
: detailstr
="NotifyAncestor"; break;
384 case NotifyVirtual
: detailstr
="NotifyVirtual"; break;
385 case NotifyInferior
: detailstr
="NotifyInferior"; break;
386 case NotifyNonlinear
: detailstr
="NotifyNonlinear"; break;
387 case NotifyNonlinearVirtual
: detailstr
="NotifyNonlinearVirtual"; break;
388 case NotifyPointer
: detailstr
="NotifyPointer"; break;
389 case NotifyPointerRoot
: detailstr
="NotifyPointerRoot"; break;
390 case NotifyDetailNone
: detailstr
="NotifyDetailNone"; break;
393 if (mode
== NotifyGrab
|| mode
== NotifyUngrab
)
398 ob_debug_type(OB_DEBUG_FOCUS
, "Focus%s 0x%x mode=%s detail=%s\n",
399 (e
->xfocus
.type
== FocusIn
? "In" : "Out"),
405 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
410 if (!wanted_focusevent(e
, FALSE
))
415 if (!wanted_focusevent(e
, FALSE
))
422 static void event_process(const XEvent
*ec
, gpointer data
)
425 ObClient
*client
= NULL
;
427 ObDockApp
*dockapp
= NULL
;
428 ObWindow
*obwin
= NULL
;
429 GSList
*timewinclients
= NULL
;
431 ObEventData
*ed
= data
;
433 /* make a copy we can mangle */
437 window
= event_get_window(e
);
438 if (e
->type
!= PropertyNotify
||
439 !(timewinclients
= propwin_get_clients(window
,
440 OB_PROPWIN_USER_TIME
)))
441 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
442 switch (obwin
->type
) {
444 dock
= WINDOW_AS_DOCK(obwin
);
447 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
450 client
= WINDOW_AS_CLIENT(obwin
);
453 case Window_Internal
:
454 /* not to be used for events */
455 g_assert_not_reached();
460 event_set_curtime(e
);
462 if (event_ignore(e
, client
)) {
469 /* deal with it in the kernel */
471 if (menu_frame_visible
&&
472 (e
->type
== EnterNotify
|| e
->type
== LeaveNotify
))
474 /* crossing events for menu */
475 event_handle_menu(e
);
476 } else if (e
->type
== FocusIn
) {
477 if (e
->xfocus
.detail
== NotifyPointerRoot
||
478 e
->xfocus
.detail
== NotifyDetailNone
||
479 e
->xfocus
.detail
== NotifyInferior
)
483 ob_debug_type(OB_DEBUG_FOCUS
, "Focus went to pointer root/none\n");
485 /* If another FocusIn is in the queue then don't fallback yet. This
486 fixes the fun case of:
487 window map -> send focusin
488 window unmap -> get focusout
489 window map -> send focusin
490 get first focus out -> fall back to something (new window
491 hasn't received focus yet, so something else) -> send focusin
492 which means the "something else" is the last thing to get a
493 focusin sent to it, so the new window doesn't end up with focus.
495 But if the other focus in is something like PointerRoot then we
496 still want to fall back.
498 if (XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin_client
,
501 XPutBackEvent(ob_display
, &ce
);
502 ob_debug_type(OB_DEBUG_FOCUS
,
503 " but another FocusIn is coming\n");
505 /* Focus has been reverted to the root window or nothing.
507 FocusOut events come after UnmapNotify, so we don't need to
508 worry about focusing an invalid window
511 if (!focus_left_screen
)
512 focus_fallback(TRUE
);
517 ob_debug_type(OB_DEBUG_FOCUS
,
518 "Focus went to a window that is already gone\n");
520 /* If you send focus to a window and then it disappears, you can
521 get the FocusIn for it, after it is unmanaged.
522 Just wait for the next FocusOut/FocusIn pair. */
524 else if (client
!= focus_client
) {
525 focus_left_screen
= FALSE
;
526 frame_adjust_focus(client
->frame
, TRUE
);
527 focus_set_client(client
);
528 client_calc_layer(client
);
529 client_bring_helper_windows(client
);
531 } else if (e
->type
== FocusOut
) {
532 gboolean nomove
= FALSE
;
535 /* Look for the followup FocusIn */
536 if (!XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin
, NULL
)) {
537 /* There is no FocusIn, this means focus went to a window that
538 is not being managed, or a window on another screen. */
542 xerror_set_ignore(TRUE
);
543 if (XGetInputFocus(ob_display
, &win
, &i
) != 0 &&
544 XGetGeometry(ob_display
, win
, &root
, &i
,&i
,&u
,&u
,&u
,&u
) != 0 &&
545 root
!= RootWindow(ob_display
, ob_screen
))
547 ob_debug_type(OB_DEBUG_FOCUS
,
548 "Focus went to another screen !\n");
549 focus_left_screen
= TRUE
;
552 ob_debug_type(OB_DEBUG_FOCUS
,
553 "Focus went to a black hole !\n");
554 xerror_set_ignore(FALSE
);
555 /* nothing is focused */
556 focus_set_client(NULL
);
557 } else if (ce
.xany
.window
== e
->xany
.window
) {
558 ob_debug_type(OB_DEBUG_FOCUS
, "Focus didn't go anywhere\n");
559 /* If focus didn't actually move anywhere, there is nothing to do*/
562 /* Focus did move, so process the FocusIn event */
563 ObEventData ed
= { .ignored
= FALSE
};
564 event_process(&ce
, &ed
);
566 /* The FocusIn was ignored, this means it was on a window
567 that isn't a client. */
568 ob_debug_type(OB_DEBUG_FOCUS
,
569 "Focus went to an unmanaged window 0x%x !\n",
571 focus_fallback(TRUE
);
575 if (client
&& !nomove
) {
576 frame_adjust_focus(client
->frame
, FALSE
);
577 if (client
== focus_client
)
578 focus_set_client(NULL
);
579 client_calc_layer(client
);
581 } else if (timewinclients
)
582 event_handle_user_time_window_clients(timewinclients
, e
);
584 event_handle_client(client
, e
);
586 event_handle_dockapp(dockapp
, e
);
588 event_handle_dock(dock
, e
);
589 else if (window
== RootWindow(ob_display
, ob_screen
))
590 event_handle_root(e
);
591 else if (e
->type
== MapRequest
)
592 client_manage(window
);
593 else if (e
->type
== ClientMessage
) {
594 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
595 windows that are not managed yet. */
596 if (e
->xclient
.message_type
== prop_atoms
.net_request_frame_extents
) {
597 /* Pretend to manage the client, getting information used to
598 determine its decorations */
599 ObClient
*c
= client_fake_manage(e
->xclient
.window
);
602 /* set the frame extents on the window */
603 vals
[0] = c
->frame
->size
.left
;
604 vals
[1] = c
->frame
->size
.right
;
605 vals
[2] = c
->frame
->size
.top
;
606 vals
[3] = c
->frame
->size
.bottom
;
607 PROP_SETA32(e
->xclient
.window
, net_frame_extents
,
610 /* Free the pretend client */
611 client_fake_unmanage(c
);
614 else if (e
->type
== ConfigureRequest
) {
615 /* unhandled configure requests must be used to configure the
619 xwc
.x
= e
->xconfigurerequest
.x
;
620 xwc
.y
= e
->xconfigurerequest
.y
;
621 xwc
.width
= e
->xconfigurerequest
.width
;
622 xwc
.height
= e
->xconfigurerequest
.height
;
623 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
624 xwc
.sibling
= e
->xconfigurerequest
.above
;
625 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
627 /* we are not to be held responsible if someone sends us an
629 xerror_set_ignore(TRUE
);
630 XConfigureWindow(ob_display
, window
,
631 e
->xconfigurerequest
.value_mask
, &xwc
);
632 xerror_set_ignore(FALSE
);
635 else if (extensions_sync
&&
636 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
638 XSyncAlarmNotifyEvent
*se
= (XSyncAlarmNotifyEvent
*)e
;
639 if (se
->alarm
== moveresize_alarm
&& moveresize_in_progress
)
644 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
645 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
646 e
->type
== KeyRelease
)
648 event_handle_user_input(client
, e
);
651 /* if something happens and it's not from an XEvent, then we don't know
653 event_curtime
= CurrentTime
;
656 static void event_handle_root(XEvent
*e
)
662 ob_debug("Another WM has requested to replace us. Exiting.\n");
667 if (e
->xclient
.format
!= 32) break;
669 msgtype
= e
->xclient
.message_type
;
670 if (msgtype
== prop_atoms
.net_current_desktop
) {
671 guint d
= e
->xclient
.data
.l
[0];
672 if (d
< screen_num_desktops
) {
673 event_curtime
= e
->xclient
.data
.l
[1];
674 if (event_curtime
== 0)
675 ob_debug_type(OB_DEBUG_APP_BUGS
,
676 "_NET_CURRENT_DESKTOP message is missing "
678 screen_set_desktop(d
, TRUE
);
680 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
681 guint d
= e
->xclient
.data
.l
[0];
682 if (d
> 0 && d
<= 1000)
683 screen_set_num_desktops(d
);
684 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
685 screen_show_desktop(e
->xclient
.data
.l
[0] != 0, NULL
);
686 } else if (msgtype
== prop_atoms
.ob_control
) {
687 if (e
->xclient
.data
.l
[0] == 1)
689 else if (e
->xclient
.data
.l
[0] == 2)
694 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
)
695 screen_update_desktop_names();
696 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
697 screen_update_layout();
699 case ConfigureNotify
:
701 XRRUpdateConfiguration(e
);
710 void event_enter_client(ObClient
*client
)
712 g_assert(config_focus_follow
);
714 if (client_enter_focusable(client
) && client_can_focus(client
)) {
715 if (config_focus_delay
) {
716 ObFocusDelayData
*data
;
718 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
720 data
= g_new(ObFocusDelayData
, 1);
721 data
->client
= client
;
722 data
->time
= event_curtime
;
724 ob_main_loop_timeout_add(ob_main_loop
,
727 data
, focus_delay_cmp
, focus_delay_dest
);
729 ObFocusDelayData data
;
730 data
.client
= client
;
731 data
.time
= event_curtime
;
732 focus_delay_func(&data
);
737 static void event_handle_user_time_window_clients(GSList
*l
, XEvent
*e
)
739 g_assert(e
->type
== PropertyNotify
);
740 if (e
->xproperty
.atom
== prop_atoms
.net_wm_user_time
) {
741 for (; l
; l
= g_slist_next(l
))
742 client_update_user_time(l
->data
);
746 static void event_handle_client(ObClient
*client
, XEvent
*e
)
751 static gint px
= -1, py
= -1;
756 /* save where the press occured for the first button pressed */
758 pb
= e
->xbutton
.button
;
763 /* Wheel buttons don't draw because they are an instant click, so it
764 is a waste of resources to go drawing it.
765 if the user is doing an intereactive thing, or has a menu open then
766 the mouse is grabbed (possibly) and if we get these events we don't
767 want to deal with them
769 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5) &&
770 !keyboard_interactively_grabbed() &&
773 /* use where the press occured */
774 con
= frame_context(client
, e
->xbutton
.window
, px
, py
);
775 con
= mouse_button_frame_context(con
, e
->xbutton
.button
,
778 if (e
->type
== ButtonRelease
&& e
->xbutton
.button
== pb
)
779 pb
= 0, px
= py
= -1;
782 case OB_FRAME_CONTEXT_MAXIMIZE
:
783 client
->frame
->max_press
= (e
->type
== ButtonPress
);
784 framerender_frame(client
->frame
);
786 case OB_FRAME_CONTEXT_CLOSE
:
787 client
->frame
->close_press
= (e
->type
== ButtonPress
);
788 framerender_frame(client
->frame
);
790 case OB_FRAME_CONTEXT_ICONIFY
:
791 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
792 framerender_frame(client
->frame
);
794 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
795 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
796 framerender_frame(client
->frame
);
798 case OB_FRAME_CONTEXT_SHADE
:
799 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
800 framerender_frame(client
->frame
);
803 /* nothing changes with clicks for any other contexts */
809 con
= frame_context(client
, e
->xmotion
.window
,
810 e
->xmotion
.x
, e
->xmotion
.y
);
812 case OB_FRAME_CONTEXT_TITLEBAR
:
813 case OB_FRAME_CONTEXT_TLCORNER
:
814 case OB_FRAME_CONTEXT_TRCORNER
:
815 /* we've left the button area inside the titlebar */
816 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
817 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
818 client
->frame
->close_hover
)
820 client
->frame
->max_hover
= FALSE
;
821 client
->frame
->desk_hover
= FALSE
;
822 client
->frame
->shade_hover
= FALSE
;
823 client
->frame
->iconify_hover
= FALSE
;
824 client
->frame
->close_hover
= FALSE
;
825 frame_adjust_state(client
->frame
);
828 case OB_FRAME_CONTEXT_MAXIMIZE
:
829 if (!client
->frame
->max_hover
) {
830 client
->frame
->max_hover
= TRUE
;
831 frame_adjust_state(client
->frame
);
834 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
835 if (!client
->frame
->desk_hover
) {
836 client
->frame
->desk_hover
= TRUE
;
837 frame_adjust_state(client
->frame
);
840 case OB_FRAME_CONTEXT_SHADE
:
841 if (!client
->frame
->shade_hover
) {
842 client
->frame
->shade_hover
= TRUE
;
843 frame_adjust_state(client
->frame
);
846 case OB_FRAME_CONTEXT_ICONIFY
:
847 if (!client
->frame
->iconify_hover
) {
848 client
->frame
->iconify_hover
= TRUE
;
849 frame_adjust_state(client
->frame
);
852 case OB_FRAME_CONTEXT_CLOSE
:
853 if (!client
->frame
->close_hover
) {
854 client
->frame
->close_hover
= TRUE
;
855 frame_adjust_state(client
->frame
);
863 con
= frame_context(client
, e
->xcrossing
.window
,
864 e
->xcrossing
.x
, e
->xcrossing
.y
);
866 case OB_FRAME_CONTEXT_TITLEBAR
:
867 case OB_FRAME_CONTEXT_TLCORNER
:
868 case OB_FRAME_CONTEXT_TRCORNER
:
869 /* we've left the button area inside the titlebar */
870 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
871 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
872 client
->frame
->close_hover
)
874 client
->frame
->max_hover
= FALSE
;
875 client
->frame
->desk_hover
= FALSE
;
876 client
->frame
->shade_hover
= FALSE
;
877 client
->frame
->iconify_hover
= FALSE
;
878 client
->frame
->close_hover
= FALSE
;
879 frame_adjust_state(client
->frame
);
882 case OB_FRAME_CONTEXT_MAXIMIZE
:
883 client
->frame
->max_hover
= FALSE
;
884 frame_adjust_state(client
->frame
);
886 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
887 client
->frame
->desk_hover
= FALSE
;
888 frame_adjust_state(client
->frame
);
890 case OB_FRAME_CONTEXT_SHADE
:
891 client
->frame
->shade_hover
= FALSE
;
892 frame_adjust_state(client
->frame
);
894 case OB_FRAME_CONTEXT_ICONIFY
:
895 client
->frame
->iconify_hover
= FALSE
;
896 frame_adjust_state(client
->frame
);
898 case OB_FRAME_CONTEXT_CLOSE
:
899 client
->frame
->close_hover
= FALSE
;
900 frame_adjust_state(client
->frame
);
902 case OB_FRAME_CONTEXT_FRAME
:
903 /* When the mouse leaves an animating window, don't use the
904 corresponding enter events. Pretend like the animating window
905 doesn't even exist..! */
906 if (frame_iconify_animating(client
->frame
))
907 event_ignore_all_queued_enters();
909 ob_debug_type(OB_DEBUG_FOCUS
,
910 "%sNotify mode %d detail %d on %lx\n",
911 (e
->type
== EnterNotify
? "Enter" : "Leave"),
913 e
->xcrossing
.detail
, (client
?client
->window
:0));
914 if (keyboard_interactively_grabbed())
916 if (config_focus_follow
&& config_focus_delay
&&
917 /* leave inferior events can happen when the mouse goes onto
918 the window's border and then into the window before the
920 e
->xcrossing
.detail
!= NotifyInferior
)
922 ob_main_loop_timeout_remove_data(ob_main_loop
,
933 con
= frame_context(client
, e
->xcrossing
.window
,
934 e
->xcrossing
.x
, e
->xcrossing
.y
);
936 case OB_FRAME_CONTEXT_MAXIMIZE
:
937 client
->frame
->max_hover
= TRUE
;
938 frame_adjust_state(client
->frame
);
940 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
941 client
->frame
->desk_hover
= TRUE
;
942 frame_adjust_state(client
->frame
);
944 case OB_FRAME_CONTEXT_SHADE
:
945 client
->frame
->shade_hover
= TRUE
;
946 frame_adjust_state(client
->frame
);
948 case OB_FRAME_CONTEXT_ICONIFY
:
949 client
->frame
->iconify_hover
= TRUE
;
950 frame_adjust_state(client
->frame
);
952 case OB_FRAME_CONTEXT_CLOSE
:
953 client
->frame
->close_hover
= TRUE
;
954 frame_adjust_state(client
->frame
);
956 case OB_FRAME_CONTEXT_FRAME
:
957 if (keyboard_interactively_grabbed())
959 if (e
->xcrossing
.mode
== NotifyGrab
||
960 e
->xcrossing
.mode
== NotifyUngrab
||
961 /*ignore enters when we're already in the window */
962 e
->xcrossing
.detail
== NotifyInferior
||
963 is_enter_focus_event_ignored(e
))
965 ob_debug_type(OB_DEBUG_FOCUS
,
966 "%sNotify mode %d detail %d on %lx IGNORED\n",
967 (e
->type
== EnterNotify
? "Enter" : "Leave"),
969 e
->xcrossing
.detail
, client
?client
->window
:0);
972 ob_debug_type(OB_DEBUG_FOCUS
,
973 "%sNotify mode %d detail %d on %lx, "
975 (e
->type
== EnterNotify
? "Enter" : "Leave"),
977 e
->xcrossing
.detail
, (client
?client
->window
:0));
978 if (config_focus_follow
)
979 event_enter_client(client
);
987 case ConfigureRequest
:
989 /* dont compress these unless you're going to watch for property
990 notifies in between (these can change what the configure would
992 also you can't compress stacking events
996 gboolean move
= FALSE
;
997 gboolean resize
= FALSE
;
999 /* get the current area */
1000 RECT_TO_DIMS(client
->area
, x
, y
, w
, h
);
1002 ob_debug("ConfigureRequest desktop %d wmstate %d visibile %d\n",
1003 screen_desktop
, client
->wmstate
, client
->frame
->visible
);
1005 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
1006 if (client
->border_width
!= e
->xconfigurerequest
.border_width
) {
1007 client
->border_width
= e
->xconfigurerequest
.border_width
;
1009 /* if the border width is changing then that is the same
1010 as requesting a resize, but we don't actually change
1011 the client's border, so it will change their root
1012 coordiantes (since they include the border width) and
1013 we need to a notify then */
1018 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
1019 ObClient
*sibling
= NULL
;
1021 /* get the sibling */
1022 if (e
->xconfigurerequest
.value_mask
& CWSibling
) {
1024 win
= g_hash_table_lookup(window_map
,
1025 &e
->xconfigurerequest
.above
);
1026 if (WINDOW_IS_CLIENT(win
) && WINDOW_AS_CLIENT(win
) != client
)
1027 sibling
= WINDOW_AS_CLIENT(win
);
1030 /* activate it rather than just focus it */
1031 stacking_restack_request(client
, sibling
,
1032 e
->xconfigurerequest
.detail
, TRUE
);
1034 /* if a stacking change moves the window without resizing */
1038 if (e
->xconfigurerequest
.value_mask
& CWX
||
1039 e
->xconfigurerequest
.value_mask
& CWY
||
1040 e
->xconfigurerequest
.value_mask
& CWWidth
||
1041 e
->xconfigurerequest
.value_mask
& CWHeight
)
1043 if (e
->xconfigurerequest
.value_mask
& CWX
) {
1044 /* don't allow clients to move shaded windows (fvwm does this)
1046 if (!client
->shaded
)
1047 x
= e
->xconfigurerequest
.x
;
1050 if (e
->xconfigurerequest
.value_mask
& CWY
) {
1051 /* don't allow clients to move shaded windows (fvwm does this)
1053 if (!client
->shaded
)
1054 y
= e
->xconfigurerequest
.y
;
1058 if (e
->xconfigurerequest
.value_mask
& CWWidth
) {
1059 w
= e
->xconfigurerequest
.width
;
1062 /* if x was not given, then use gravity to figure out the new
1063 x. the reference point should not be moved */
1064 if (!(e
->xconfigurerequest
.value_mask
& CWX
))
1065 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1067 if (e
->xconfigurerequest
.value_mask
& CWHeight
) {
1068 h
= e
->xconfigurerequest
.height
;
1071 /* if y was not given, then use gravity to figure out the new
1072 y. the reference point should not be moved */
1073 if (!(e
->xconfigurerequest
.value_mask
& CWY
))
1074 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1078 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
1079 "move %d resize %d\n",
1080 e
->xconfigurerequest
.value_mask
& CWX
, x
,
1081 e
->xconfigurerequest
.value_mask
& CWY
, y
,
1082 e
->xconfigurerequest
.value_mask
& CWWidth
, w
,
1083 e
->xconfigurerequest
.value_mask
& CWHeight
, h
,
1086 /* check for broken apps moving to their root position
1088 XXX remove this some day...that would be nice. right now all
1089 kde apps do this when they try activate themselves on another
1090 desktop. eg. open amarok window on desktop 1, switch to desktop
1091 2, click amarok tray icon. it will move by its decoration size.
1093 if (move
&& !resize
&&
1094 x
!= client
->area
.x
&&
1095 x
== (client
->frame
->area
.x
+ client
->frame
->size
.left
-
1096 (gint
)client
->border_width
) &&
1097 y
!= client
->area
.y
&&
1098 y
== (client
->frame
->area
.y
+ client
->frame
->size
.top
-
1099 (gint
)client
->border_width
))
1101 ob_debug_type(OB_DEBUG_APP_BUGS
,
1102 "Application %s is trying to move via "
1103 "ConfigureRequest to it's root window position "
1104 "but it is not using StaticGravity\n",
1110 /* they still requested a move, so don't change whether a
1111 notify is sent or not */
1114 if (move
|| resize
) {
1117 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1118 client_try_configure(client
, &x
, &y
, &w
, &h
, &lw
, &lh
, FALSE
);
1119 /* if they requested something that moves the window, or if
1120 the window is actually being changed then configure it and
1121 send a configure notify to them */
1122 if (move
|| !RECT_EQUAL_DIMS(client
->area
, x
, y
, w
, h
)) {
1123 ob_debug("Doing configure\n");
1124 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1127 /* ignore enter events caused by these like ob actions do */
1128 event_ignore_all_queued_enters();
1133 if (client
->ignore_unmaps
) {
1134 client
->ignore_unmaps
--;
1137 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1138 "ignores left %d\n",
1139 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
1140 client
->ignore_unmaps
);
1141 client_unmanage(client
);
1144 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
1145 client_unmanage(client
);
1147 case ReparentNotify
:
1148 /* this is when the client is first taken captive in the frame */
1149 if (e
->xreparent
.parent
== client
->frame
->plate
) break;
1152 This event is quite rare and is usually handled in unmapHandler.
1153 However, if the window is unmapped when the reparent event occurs,
1154 the window manager never sees it because an unmap event is not sent
1155 to an already unmapped window.
1158 /* we don't want the reparent event, put it back on the stack for the
1159 X server to deal with after we unmanage the window */
1160 XPutBackEvent(ob_display
, e
);
1162 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
1163 client_unmanage(client
);
1166 ob_debug("MapRequest for 0x%lx\n", client
->window
);
1167 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
1168 does, we don't want it!
1169 it can happen now when the window is on
1170 another desktop, but we still don't
1172 client_activate(client
, FALSE
, TRUE
);
1175 /* validate cuz we query stuff off the client here */
1176 if (!client_validate(client
)) break;
1178 if (e
->xclient
.format
!= 32) return;
1180 msgtype
= e
->xclient
.message_type
;
1181 if (msgtype
== prop_atoms
.wm_change_state
) {
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 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1195 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
1196 /* compress changes into a single change */
1197 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1199 /* XXX: it would be nice to compress ALL messages of a
1200 type, not just messages in a row without other
1201 message types between. */
1202 if (ce
.xclient
.message_type
!= msgtype
) {
1203 XPutBackEvent(ob_display
, &ce
);
1206 e
->xclient
= ce
.xclient
;
1208 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1209 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1210 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1212 } else if (msgtype
== prop_atoms
.net_wm_state
) {
1213 /* can't compress these */
1214 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1215 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1216 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1217 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1218 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1220 client_set_state(client
, e
->xclient
.data
.l
[0],
1221 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1223 /* ignore enter events caused by these like ob actions do */
1224 event_ignore_all_queued_enters();
1225 } else if (msgtype
== prop_atoms
.net_close_window
) {
1226 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1227 client_close(client
);
1228 } else if (msgtype
== prop_atoms
.net_active_window
) {
1229 ob_debug("net_active_window for 0x%lx source=%s\n",
1231 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1232 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1233 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1234 /* XXX make use of data.l[2] !? */
1235 if (e
->xclient
.data
.l
[0] == 1 || e
->xclient
.data
.l
[0] == 2) {
1236 event_curtime
= e
->xclient
.data
.l
[1];
1237 if (event_curtime
== 0)
1238 ob_debug_type(OB_DEBUG_APP_BUGS
,
1239 "_NET_ACTIVE_WINDOW message for window %s is"
1240 " missing a timestamp\n", client
->title
);
1242 ob_debug_type(OB_DEBUG_APP_BUGS
,
1243 "_NET_ACTIVE_WINDOW message for window %s is "
1244 "missing source indication\n");
1245 client_activate(client
, FALSE
,
1246 (e
->xclient
.data
.l
[0] == 0 ||
1247 e
->xclient
.data
.l
[0] == 2));
1248 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1249 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1250 client
->window
, e
->xclient
.data
.l
[2]);
1251 if ((Atom
)e
->xclient
.data
.l
[2] ==
1252 prop_atoms
.net_wm_moveresize_size_topleft
||
1253 (Atom
)e
->xclient
.data
.l
[2] ==
1254 prop_atoms
.net_wm_moveresize_size_top
||
1255 (Atom
)e
->xclient
.data
.l
[2] ==
1256 prop_atoms
.net_wm_moveresize_size_topright
||
1257 (Atom
)e
->xclient
.data
.l
[2] ==
1258 prop_atoms
.net_wm_moveresize_size_right
||
1259 (Atom
)e
->xclient
.data
.l
[2] ==
1260 prop_atoms
.net_wm_moveresize_size_right
||
1261 (Atom
)e
->xclient
.data
.l
[2] ==
1262 prop_atoms
.net_wm_moveresize_size_bottomright
||
1263 (Atom
)e
->xclient
.data
.l
[2] ==
1264 prop_atoms
.net_wm_moveresize_size_bottom
||
1265 (Atom
)e
->xclient
.data
.l
[2] ==
1266 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1267 (Atom
)e
->xclient
.data
.l
[2] ==
1268 prop_atoms
.net_wm_moveresize_size_left
||
1269 (Atom
)e
->xclient
.data
.l
[2] ==
1270 prop_atoms
.net_wm_moveresize_move
||
1271 (Atom
)e
->xclient
.data
.l
[2] ==
1272 prop_atoms
.net_wm_moveresize_size_keyboard
||
1273 (Atom
)e
->xclient
.data
.l
[2] ==
1274 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1276 moveresize_start(client
, e
->xclient
.data
.l
[0],
1277 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1278 e
->xclient
.data
.l
[2]);
1280 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1281 prop_atoms
.net_wm_moveresize_cancel
)
1282 moveresize_end(TRUE
);
1283 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1284 gint ograv
, x
, y
, w
, h
;
1286 ograv
= client
->gravity
;
1288 if (e
->xclient
.data
.l
[0] & 0xff)
1289 client
->gravity
= e
->xclient
.data
.l
[0] & 0xff;
1291 if (e
->xclient
.data
.l
[0] & 1 << 8)
1292 x
= e
->xclient
.data
.l
[1];
1295 if (e
->xclient
.data
.l
[0] & 1 << 9)
1296 y
= e
->xclient
.data
.l
[2];
1300 if (e
->xclient
.data
.l
[0] & 1 << 10) {
1301 w
= e
->xclient
.data
.l
[3];
1303 /* if x was not given, then use gravity to figure out the new
1304 x. the reference point should not be moved */
1305 if (!(e
->xclient
.data
.l
[0] & 1 << 8))
1306 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1309 w
= client
->area
.width
;
1311 if (e
->xclient
.data
.l
[0] & 1 << 11) {
1312 h
= e
->xclient
.data
.l
[4];
1314 /* if y was not given, then use gravity to figure out the new
1315 y. the reference point should not be moved */
1316 if (!(e
->xclient
.data
.l
[0] & 1 << 9))
1317 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1320 h
= client
->area
.height
;
1322 ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)\n",
1323 e
->xclient
.data
.l
[0] & 1 << 8, x
,
1324 e
->xclient
.data
.l
[0] & 1 << 9, y
,
1327 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1329 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1331 client
->gravity
= ograv
;
1333 /* ignore enter events caused by these like ob actions do */
1334 event_ignore_all_queued_enters();
1335 } else if (msgtype
== prop_atoms
.net_restack_window
) {
1336 if (e
->xclient
.data
.l
[0] != 2) {
1337 ob_debug_type(OB_DEBUG_APP_BUGS
,
1338 "_NET_RESTACK_WINDOW sent for window %s with "
1339 "invalid source indication %ld\n",
1340 client
->title
, e
->xclient
.data
.l
[0]);
1342 ObClient
*sibling
= NULL
;
1343 if (e
->xclient
.data
.l
[1]) {
1344 ObWindow
*win
= g_hash_table_lookup
1345 (window_map
, &e
->xclient
.data
.l
[1]);
1346 if (WINDOW_IS_CLIENT(win
) &&
1347 WINDOW_AS_CLIENT(win
) != client
)
1349 sibling
= WINDOW_AS_CLIENT(win
);
1351 if (sibling
== NULL
)
1352 ob_debug_type(OB_DEBUG_APP_BUGS
,
1353 "_NET_RESTACK_WINDOW sent for window %s "
1354 "with invalid sibling 0x%x\n",
1355 client
->title
, e
->xclient
.data
.l
[1]);
1357 if (e
->xclient
.data
.l
[2] == Below
||
1358 e
->xclient
.data
.l
[2] == BottomIf
||
1359 e
->xclient
.data
.l
[2] == Above
||
1360 e
->xclient
.data
.l
[2] == TopIf
||
1361 e
->xclient
.data
.l
[2] == Opposite
)
1363 /* just raise, don't activate */
1364 stacking_restack_request(client
, sibling
,
1365 e
->xclient
.data
.l
[2], FALSE
);
1366 /* send a synthetic ConfigureNotify, cuz this is supposed
1367 to be like a ConfigureRequest. */
1368 client_reconfigure(client
);
1370 ob_debug_type(OB_DEBUG_APP_BUGS
,
1371 "_NET_RESTACK_WINDOW sent for window %s "
1372 "with invalid detail %d\n",
1373 client
->title
, e
->xclient
.data
.l
[2]);
1377 case PropertyNotify
:
1378 /* validate cuz we query stuff off the client here */
1379 if (!client_validate(client
)) break;
1381 /* compress changes to a single property into a single change */
1382 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1386 /* XXX: it would be nice to compress ALL changes to a property,
1387 not just changes in a row without other props between. */
1389 a
= ce
.xproperty
.atom
;
1390 b
= e
->xproperty
.atom
;
1394 if ((a
== prop_atoms
.net_wm_name
||
1395 a
== prop_atoms
.wm_name
||
1396 a
== prop_atoms
.net_wm_icon_name
||
1397 a
== prop_atoms
.wm_icon_name
)
1399 (b
== prop_atoms
.net_wm_name
||
1400 b
== prop_atoms
.wm_name
||
1401 b
== prop_atoms
.net_wm_icon_name
||
1402 b
== prop_atoms
.wm_icon_name
)) {
1405 if (a
== prop_atoms
.net_wm_icon
&&
1406 b
== prop_atoms
.net_wm_icon
)
1409 XPutBackEvent(ob_display
, &ce
);
1413 msgtype
= e
->xproperty
.atom
;
1414 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1415 client_update_normal_hints(client
);
1416 /* normal hints can make a window non-resizable */
1417 client_setup_decor_and_functions(client
);
1418 } else if (msgtype
== XA_WM_HINTS
) {
1419 client_update_wmhints(client
);
1420 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1421 client_update_transient_for(client
);
1422 client_get_type_and_transientness(client
);
1423 /* type may have changed, so update the layer */
1424 client_calc_layer(client
);
1425 client_setup_decor_and_functions(client
);
1426 } else if (msgtype
== prop_atoms
.net_wm_name
||
1427 msgtype
== prop_atoms
.wm_name
||
1428 msgtype
== prop_atoms
.net_wm_icon_name
||
1429 msgtype
== prop_atoms
.wm_icon_name
) {
1430 client_update_title(client
);
1431 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1432 client_update_protocols(client
);
1433 client_setup_decor_and_functions(client
);
1435 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1436 client_update_strut(client
);
1438 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1439 client_update_icons(client
);
1441 else if (msgtype
== prop_atoms
.net_wm_icon_geometry
) {
1442 client_update_icon_geometry(client
);
1444 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1445 client_update_user_time(client
);
1447 else if (msgtype
== prop_atoms
.net_wm_user_time_window
) {
1448 client_update_user_time_window(client
);
1451 else if (msgtype
== prop_atoms
.net_wm_sync_request_counter
) {
1452 client_update_sync_request_counter(client
);
1455 case ColormapNotify
:
1456 client_update_colormap(client
, e
->xcolormap
.colormap
);
1461 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1462 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1463 frame_adjust_shape(client
->frame
);
1469 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1473 if (e
->xbutton
.button
== 1)
1474 stacking_raise(DOCK_AS_WINDOW(s
));
1475 else if (e
->xbutton
.button
== 2)
1476 stacking_lower(DOCK_AS_WINDOW(s
));
1487 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1491 dock_app_drag(app
, &e
->xmotion
);
1494 if (app
->ignore_unmaps
) {
1495 app
->ignore_unmaps
--;
1498 dock_remove(app
, TRUE
);
1501 dock_remove(app
, FALSE
);
1503 case ReparentNotify
:
1504 dock_remove(app
, FALSE
);
1506 case ConfigureNotify
:
1507 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1512 static ObMenuFrame
* find_active_menu()
1515 ObMenuFrame
*ret
= NULL
;
1517 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1526 static ObMenuFrame
* find_active_or_last_menu()
1528 ObMenuFrame
*ret
= NULL
;
1530 ret
= find_active_menu();
1531 if (!ret
&& menu_frame_visible
)
1532 ret
= menu_frame_visible
->data
;
1536 static gboolean
event_handle_menu_keyboard(XEvent
*ev
)
1538 guint keycode
, state
;
1541 gboolean ret
= TRUE
;
1543 keycode
= ev
->xkey
.keycode
;
1544 state
= ev
->xkey
.state
;
1545 unikey
= translate_unichar(keycode
);
1547 frame
= find_active_or_last_menu();
1551 else if (keycode
== ob_keycode(OB_KEY_ESCAPE
) && state
== 0) {
1552 /* Escape goes to the parent menu or closes the last one */
1554 menu_frame_select(frame
, NULL
, TRUE
);
1556 menu_frame_hide_all();
1559 else if (keycode
== ob_keycode(OB_KEY_RETURN
) && (state
== 0 ||
1560 state
== ControlMask
))
1562 /* Enter runs the active item or goes into the submenu.
1563 Control-Enter runs it without closing the menu. */
1565 menu_frame_select_next(frame
->child
);
1567 menu_entry_frame_execute(frame
->selected
, state
, ev
->xkey
.time
);
1570 else if (keycode
== ob_keycode(OB_KEY_LEFT
) && ev
->xkey
.state
== 0) {
1571 /* Left goes to the parent menu */
1572 menu_frame_select(frame
, NULL
, TRUE
);
1575 else if (keycode
== ob_keycode(OB_KEY_RIGHT
) && ev
->xkey
.state
== 0) {
1576 /* Right goes to the selected submenu */
1577 if (frame
->child
) menu_frame_select_next(frame
->child
);
1580 else if (keycode
== ob_keycode(OB_KEY_UP
) && state
== 0) {
1581 menu_frame_select_previous(frame
);
1584 else if (keycode
== ob_keycode(OB_KEY_DOWN
) && state
== 0) {
1585 menu_frame_select_next(frame
);
1588 /* keyboard accelerator shortcuts. */
1589 else if (ev
->xkey
.state
== 0 &&
1590 /* was it a valid key? */
1592 /* don't bother if the menu is empty. */
1597 ObMenuEntryFrame
*found
= NULL
;
1598 guint num_found
= 0;
1600 /* start after the selected one */
1601 start
= frame
->entries
;
1602 if (frame
->selected
) {
1603 for (it
= start
; frame
->selected
!= it
->data
; it
= g_list_next(it
))
1604 g_assert(it
!= NULL
); /* nothing was selected? */
1605 /* next with wraparound */
1606 start
= g_list_next(it
);
1607 if (start
== NULL
) start
= frame
->entries
;
1612 ObMenuEntryFrame
*e
= it
->data
;
1613 gunichar entrykey
= 0;
1615 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1616 entrykey
= e
->entry
->data
.normal
.shortcut
;
1617 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1618 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1620 if (unikey
== entrykey
) {
1621 if (found
== NULL
) found
= e
;
1625 /* next with wraparound */
1626 it
= g_list_next(it
);
1627 if (it
== NULL
) it
= frame
->entries
;
1628 } while (it
!= start
);
1631 if (found
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
1634 menu_frame_select(frame
, found
, TRUE
);
1635 usleep(50000); /* highlight the item for a short bit so the
1636 user can see what happened */
1637 menu_entry_frame_execute(found
, state
, ev
->xkey
.time
);
1639 menu_frame_select(frame
, found
, TRUE
);
1641 menu_frame_select_next(frame
->child
);
1652 static gboolean
event_handle_menu(XEvent
*ev
)
1655 ObMenuEntryFrame
*e
;
1656 gboolean ret
= TRUE
;
1660 if ((ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5)
1663 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1664 ev
->xbutton
.y_root
)))
1665 menu_entry_frame_execute(e
, ev
->xbutton
.state
,
1668 menu_frame_hide_all();
1672 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1673 if (e
->ignore_enters
)
1676 menu_frame_select(e
->frame
, e
, FALSE
);
1680 /*ignore leaves when we're already in the window */
1681 if (ev
->xcrossing
.detail
== NotifyInferior
)
1684 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1685 (f
= find_active_menu()) && f
->selected
== e
&&
1686 e
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1688 menu_frame_select(e
->frame
, NULL
, FALSE
);
1692 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1693 ev
->xmotion
.y_root
)))
1694 menu_frame_select(e
->frame
, e
, FALSE
);
1697 ret
= event_handle_menu_keyboard(ev
);
1703 static void event_handle_user_input(ObClient
*client
, XEvent
*e
)
1705 g_assert(e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
1706 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
1707 e
->type
== KeyRelease
);
1709 if (menu_frame_visible
) {
1710 if (event_handle_menu(e
))
1711 /* don't use the event if the menu used it, but if the menu
1712 didn't use it and it's a keypress that is bound, it will
1713 close the menu and be used */
1717 /* if the keyboard interactive action uses the event then dont
1718 use it for bindings. likewise is moveresize uses the event. */
1719 if (!keyboard_process_interactive_grab(e
, &client
) &&
1720 !(moveresize_in_progress
&& moveresize_event(e
)))
1722 if (moveresize_in_progress
)
1723 /* make further actions work on the client being
1725 client
= moveresize_client
;
1727 menu_can_hide
= FALSE
;
1728 ob_main_loop_timeout_add(ob_main_loop
,
1729 config_menu_hide_delay
* 1000,
1730 menu_hide_delay_func
,
1731 NULL
, g_direct_equal
, NULL
);
1733 if (e
->type
== ButtonPress
||
1734 e
->type
== ButtonRelease
||
1735 e
->type
== MotionNotify
)
1737 /* the frame may not be "visible" but they can still click on it
1738 in the case where it is animating before disappearing */
1739 if (!client
|| !frame_iconify_animating(client
->frame
))
1740 mouse_event(client
, e
);
1741 } else if (e
->type
== KeyPress
) {
1742 keyboard_event((focus_cycle_target
? focus_cycle_target
:
1743 (client
? client
: focus_client
)), e
);
1748 static gboolean
menu_hide_delay_func(gpointer data
)
1750 menu_can_hide
= TRUE
;
1751 return FALSE
; /* no repeat */
1754 static void focus_delay_dest(gpointer data
)
1759 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
1761 const ObFocusDelayData
*f1
= d1
;
1762 return f1
->client
== d2
;
1765 static gboolean
focus_delay_func(gpointer data
)
1767 ObFocusDelayData
*d
= data
;
1768 Time old
= event_curtime
;
1770 event_curtime
= d
->time
;
1771 if (focus_client
!= d
->client
) {
1772 if (client_focus(d
->client
) && config_focus_raise
)
1773 stacking_raise(CLIENT_AS_WINDOW(d
->client
));
1775 event_curtime
= old
;
1776 return FALSE
; /* no repeat */
1779 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1781 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1785 void event_halt_focus_delay()
1787 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1790 static Bool
event_look_for_enters(Display
*d
, XEvent
*e
, XPointer arg
)
1792 if (e
->type
== EnterNotify
&&
1793 /* these types aren't used for focusing */
1794 !(e
->xcrossing
.mode
== NotifyGrab
||
1795 e
->xcrossing
.mode
== NotifyUngrab
||
1796 e
->xcrossing
.detail
== NotifyInferior
))
1800 /* found an enter for that leave, ignore it if it's going to
1802 win
= g_hash_table_lookup(window_map
, &e
->xany
.window
);
1803 if (win
&& WINDOW_IS_CLIENT(win
))
1804 ++ignore_enter_focus
;
1806 return False
; /* don't disrupt the queue order, just count them */
1809 void event_ignore_all_queued_enters()
1813 XSync(ob_display
, FALSE
);
1815 /* count the events without disrupting them */
1816 ignore_enter_focus
= 0;
1817 XCheckIfEvent(ob_display
, &e
, event_look_for_enters
, NULL
);
1820 static gboolean
is_enter_focus_event_ignored(XEvent
*e
)
1822 g_assert(e
->type
== EnterNotify
&&
1823 !(e
->xcrossing
.mode
== NotifyGrab
||
1824 e
->xcrossing
.mode
== NotifyUngrab
||
1825 e
->xcrossing
.detail
== NotifyInferior
));
1827 ob_debug_type(OB_DEBUG_FOCUS
, "# enters ignored: %d\n",
1828 ignore_enter_focus
);
1830 if (ignore_enter_focus
) {
1831 --ignore_enter_focus
;
1837 gboolean
event_time_after(Time t1
, Time t2
)
1839 g_assert(t1
!= CurrentTime
);
1840 g_assert(t2
!= CurrentTime
);
1843 Timestamp values wrap around (after about 49.7 days). The server, given
1844 its current time is represented by timestamp T, always interprets
1845 timestamps from clients by treating half of the timestamp space as being
1846 later in time than T.
1847 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
1850 /* TIME_HALF is half of the number space of a Time type variable */
1851 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
1853 if (t2
>= TIME_HALF
)
1854 /* t2 is in the second half so t1 might wrap around and be smaller than
1856 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
1858 /* t2 is in the first half so t1 has to come after it */
1859 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);