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];
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
);
777 if (e
->type
== ButtonRelease
&& e
->xbutton
.button
== pb
)
778 pb
= 0, px
= py
= -1;
781 case OB_FRAME_CONTEXT_MAXIMIZE
:
782 client
->frame
->max_press
= (e
->type
== ButtonPress
);
783 framerender_frame(client
->frame
);
785 case OB_FRAME_CONTEXT_CLOSE
:
786 client
->frame
->close_press
= (e
->type
== ButtonPress
);
787 framerender_frame(client
->frame
);
789 case OB_FRAME_CONTEXT_ICONIFY
:
790 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
791 framerender_frame(client
->frame
);
793 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
794 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
795 framerender_frame(client
->frame
);
797 case OB_FRAME_CONTEXT_SHADE
:
798 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
799 framerender_frame(client
->frame
);
802 /* nothing changes with clicks for any other contexts */
808 con
= frame_context(client
, e
->xmotion
.window
,
809 e
->xmotion
.x
, e
->xmotion
.y
);
811 case OB_FRAME_CONTEXT_TITLEBAR
:
812 /* we've left the button area inside the titlebar */
813 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
814 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
815 client
->frame
->close_hover
)
817 client
->frame
->max_hover
= FALSE
;
818 client
->frame
->desk_hover
= FALSE
;
819 client
->frame
->shade_hover
= FALSE
;
820 client
->frame
->iconify_hover
= FALSE
;
821 client
->frame
->close_hover
= FALSE
;
822 frame_adjust_state(client
->frame
);
825 case OB_FRAME_CONTEXT_MAXIMIZE
:
826 if (!client
->frame
->max_hover
) {
827 client
->frame
->max_hover
= TRUE
;
828 frame_adjust_state(client
->frame
);
831 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
832 if (!client
->frame
->desk_hover
) {
833 client
->frame
->desk_hover
= TRUE
;
834 frame_adjust_state(client
->frame
);
837 case OB_FRAME_CONTEXT_SHADE
:
838 if (!client
->frame
->shade_hover
) {
839 client
->frame
->shade_hover
= TRUE
;
840 frame_adjust_state(client
->frame
);
843 case OB_FRAME_CONTEXT_ICONIFY
:
844 if (!client
->frame
->iconify_hover
) {
845 client
->frame
->iconify_hover
= TRUE
;
846 frame_adjust_state(client
->frame
);
849 case OB_FRAME_CONTEXT_CLOSE
:
850 if (!client
->frame
->close_hover
) {
851 client
->frame
->close_hover
= TRUE
;
852 frame_adjust_state(client
->frame
);
860 con
= frame_context(client
, e
->xcrossing
.window
,
861 e
->xcrossing
.x
, e
->xcrossing
.y
);
863 case OB_FRAME_CONTEXT_MAXIMIZE
:
864 client
->frame
->max_hover
= FALSE
;
865 frame_adjust_state(client
->frame
);
867 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
868 client
->frame
->desk_hover
= FALSE
;
869 frame_adjust_state(client
->frame
);
871 case OB_FRAME_CONTEXT_SHADE
:
872 client
->frame
->shade_hover
= FALSE
;
873 frame_adjust_state(client
->frame
);
875 case OB_FRAME_CONTEXT_ICONIFY
:
876 client
->frame
->iconify_hover
= FALSE
;
877 frame_adjust_state(client
->frame
);
879 case OB_FRAME_CONTEXT_CLOSE
:
880 client
->frame
->close_hover
= FALSE
;
881 frame_adjust_state(client
->frame
);
883 case OB_FRAME_CONTEXT_FRAME
:
884 /* When the mouse leaves an animating window, don't use the
885 corresponding enter events. Pretend like the animating window
886 doesn't even exist..! */
887 if (frame_iconify_animating(client
->frame
))
888 event_ignore_all_queued_enters();
890 ob_debug_type(OB_DEBUG_FOCUS
,
891 "%sNotify mode %d detail %d on %lx\n",
892 (e
->type
== EnterNotify
? "Enter" : "Leave"),
894 e
->xcrossing
.detail
, (client
?client
->window
:0));
895 if (keyboard_interactively_grabbed())
897 if (config_focus_follow
&& config_focus_delay
&&
898 /* leave inferior events can happen when the mouse goes onto
899 the window's border and then into the window before the
901 e
->xcrossing
.detail
!= NotifyInferior
)
903 ob_main_loop_timeout_remove_data(ob_main_loop
,
914 con
= frame_context(client
, e
->xcrossing
.window
,
915 e
->xcrossing
.x
, e
->xcrossing
.y
);
917 case OB_FRAME_CONTEXT_MAXIMIZE
:
918 client
->frame
->max_hover
= TRUE
;
919 frame_adjust_state(client
->frame
);
921 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
922 client
->frame
->desk_hover
= TRUE
;
923 frame_adjust_state(client
->frame
);
925 case OB_FRAME_CONTEXT_SHADE
:
926 client
->frame
->shade_hover
= TRUE
;
927 frame_adjust_state(client
->frame
);
929 case OB_FRAME_CONTEXT_ICONIFY
:
930 client
->frame
->iconify_hover
= TRUE
;
931 frame_adjust_state(client
->frame
);
933 case OB_FRAME_CONTEXT_CLOSE
:
934 client
->frame
->close_hover
= TRUE
;
935 frame_adjust_state(client
->frame
);
937 case OB_FRAME_CONTEXT_FRAME
:
938 if (keyboard_interactively_grabbed())
940 if (e
->xcrossing
.mode
== NotifyGrab
||
941 e
->xcrossing
.mode
== NotifyUngrab
||
942 /*ignore enters when we're already in the window */
943 e
->xcrossing
.detail
== NotifyInferior
||
944 is_enter_focus_event_ignored(e
))
946 ob_debug_type(OB_DEBUG_FOCUS
,
947 "%sNotify mode %d detail %d on %lx IGNORED\n",
948 (e
->type
== EnterNotify
? "Enter" : "Leave"),
950 e
->xcrossing
.detail
, client
?client
->window
:0);
953 ob_debug_type(OB_DEBUG_FOCUS
,
954 "%sNotify mode %d detail %d on %lx, "
956 (e
->type
== EnterNotify
? "Enter" : "Leave"),
958 e
->xcrossing
.detail
, (client
?client
->window
:0));
959 if (config_focus_follow
)
960 event_enter_client(client
);
968 case ConfigureRequest
:
970 /* dont compress these unless you're going to watch for property
971 notifies in between (these can change what the configure would
973 also you can't compress stacking events
978 /* if nothing is changed, then a configurenotify is needed */
979 gboolean config
= TRUE
;
983 w
= client
->area
.width
;
984 h
= client
->area
.height
;
986 ob_debug("ConfigureRequest desktop %d wmstate %d visibile %d\n",
987 screen_desktop
, client
->wmstate
, client
->frame
->visible
);
989 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
990 if (client
->border_width
!= e
->xconfigurerequest
.border_width
) {
991 client
->border_width
= e
->xconfigurerequest
.border_width
;
992 /* if only the border width is changing, then it's not needed*/
997 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
998 ObClient
*sibling
= NULL
;
1000 /* get the sibling */
1001 if (e
->xconfigurerequest
.value_mask
& CWSibling
) {
1003 win
= g_hash_table_lookup(window_map
,
1004 &e
->xconfigurerequest
.above
);
1005 if (WINDOW_IS_CLIENT(win
) && WINDOW_AS_CLIENT(win
) != client
)
1006 sibling
= WINDOW_AS_CLIENT(win
);
1009 /* activate it rather than just focus it */
1010 stacking_restack_request(client
, sibling
,
1011 e
->xconfigurerequest
.detail
, TRUE
);
1013 /* if a stacking change is requested then it is needed */
1017 /* don't allow clients to move shaded windows (fvwm does this) */
1018 if (client
->shaded
&& (e
->xconfigurerequest
.value_mask
& CWX
||
1019 e
->xconfigurerequest
.value_mask
& CWY
))
1021 e
->xconfigurerequest
.value_mask
&= ~CWX
;
1022 e
->xconfigurerequest
.value_mask
&= ~CWY
;
1024 /* if the client tried to move and we aren't letting it then a
1025 synthetic event is needed */
1029 if (e
->xconfigurerequest
.value_mask
& CWX
||
1030 e
->xconfigurerequest
.value_mask
& CWY
||
1031 e
->xconfigurerequest
.value_mask
& CWWidth
||
1032 e
->xconfigurerequest
.value_mask
& CWHeight
)
1034 if (e
->xconfigurerequest
.value_mask
& CWX
)
1035 x
= e
->xconfigurerequest
.x
;
1036 if (e
->xconfigurerequest
.value_mask
& CWY
)
1037 y
= e
->xconfigurerequest
.y
;
1038 if (e
->xconfigurerequest
.value_mask
& CWWidth
)
1039 w
= e
->xconfigurerequest
.width
;
1040 if (e
->xconfigurerequest
.value_mask
& CWHeight
)
1041 h
= e
->xconfigurerequest
.height
;
1043 /* if a new position or size is requested, then a configure is
1048 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d\n",
1049 e
->xconfigurerequest
.value_mask
& CWX
, x
,
1050 e
->xconfigurerequest
.value_mask
& CWY
, y
,
1051 e
->xconfigurerequest
.value_mask
& CWWidth
, w
,
1052 e
->xconfigurerequest
.value_mask
& CWHeight
, h
);
1054 /* check for broken apps moving to their root position
1056 XXX remove this some day...that would be nice. right now all
1057 kde apps do this when they try activate themselves on another
1058 desktop. eg. open amarok window on desktop 1, switch to desktop
1059 2, click amarok tray icon. it will move by its decoration size.
1061 if (x
!= client
->area
.x
&&
1062 x
== (client
->frame
->area
.x
+ client
->frame
->size
.left
-
1063 (gint
)client
->border_width
) &&
1064 y
!= client
->area
.y
&&
1065 y
== (client
->frame
->area
.y
+ client
->frame
->size
.top
-
1066 (gint
)client
->border_width
))
1068 ob_debug_type(OB_DEBUG_APP_BUGS
,
1069 "Application %s is trying to move via "
1070 "ConfigureRequest to it's root window position "
1071 "but it is not using StaticGravity\n",
1079 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1080 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1082 /* ignore enter events caused by these like ob actions do */
1083 event_ignore_all_queued_enters();
1088 if (client
->ignore_unmaps
) {
1089 client
->ignore_unmaps
--;
1092 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1093 "ignores left %d\n",
1094 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
1095 client
->ignore_unmaps
);
1096 client_unmanage(client
);
1099 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
1100 client_unmanage(client
);
1102 case ReparentNotify
:
1103 /* this is when the client is first taken captive in the frame */
1104 if (e
->xreparent
.parent
== client
->frame
->plate
) break;
1107 This event is quite rare and is usually handled in unmapHandler.
1108 However, if the window is unmapped when the reparent event occurs,
1109 the window manager never sees it because an unmap event is not sent
1110 to an already unmapped window.
1113 /* we don't want the reparent event, put it back on the stack for the
1114 X server to deal with after we unmanage the window */
1115 XPutBackEvent(ob_display
, e
);
1117 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
1118 client_unmanage(client
);
1121 ob_debug("MapRequest for 0x%lx\n", client
->window
);
1122 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
1123 does, we don't want it!
1124 it can happen now when the window is on
1125 another desktop, but we still don't
1127 client_activate(client
, FALSE
, TRUE
);
1130 /* validate cuz we query stuff off the client here */
1131 if (!client_validate(client
)) break;
1133 if (e
->xclient
.format
!= 32) return;
1135 msgtype
= e
->xclient
.message_type
;
1136 if (msgtype
== prop_atoms
.wm_change_state
) {
1137 /* compress changes into a single change */
1138 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1140 /* XXX: it would be nice to compress ALL messages of a
1141 type, not just messages in a row without other
1142 message types between. */
1143 if (ce
.xclient
.message_type
!= msgtype
) {
1144 XPutBackEvent(ob_display
, &ce
);
1147 e
->xclient
= ce
.xclient
;
1149 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1150 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
1151 /* compress changes into a single change */
1152 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1154 /* XXX: it would be nice to compress ALL messages of a
1155 type, not just messages in a row without other
1156 message types between. */
1157 if (ce
.xclient
.message_type
!= msgtype
) {
1158 XPutBackEvent(ob_display
, &ce
);
1161 e
->xclient
= ce
.xclient
;
1163 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1164 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1165 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1167 } else if (msgtype
== prop_atoms
.net_wm_state
) {
1168 /* can't compress these */
1169 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1170 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1171 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1172 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1173 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1175 client_set_state(client
, e
->xclient
.data
.l
[0],
1176 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1178 /* ignore enter events caused by these like ob actions do */
1179 event_ignore_all_queued_enters();
1180 } else if (msgtype
== prop_atoms
.net_close_window
) {
1181 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1182 client_close(client
);
1183 } else if (msgtype
== prop_atoms
.net_active_window
) {
1184 ob_debug("net_active_window for 0x%lx source=%s\n",
1186 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1187 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1188 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1189 /* XXX make use of data.l[2] !? */
1190 event_curtime
= e
->xclient
.data
.l
[1];
1191 if (event_curtime
== 0)
1192 ob_debug_type(OB_DEBUG_APP_BUGS
,
1193 "_NET_ACTIVE_WINDOW message for window %s is "
1194 "missing a timestamp\n", client
->title
);
1195 client_activate(client
, FALSE
,
1196 (e
->xclient
.data
.l
[0] == 0 ||
1197 e
->xclient
.data
.l
[0] == 2));
1198 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1199 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1200 client
->window
, e
->xclient
.data
.l
[2]);
1201 if ((Atom
)e
->xclient
.data
.l
[2] ==
1202 prop_atoms
.net_wm_moveresize_size_topleft
||
1203 (Atom
)e
->xclient
.data
.l
[2] ==
1204 prop_atoms
.net_wm_moveresize_size_top
||
1205 (Atom
)e
->xclient
.data
.l
[2] ==
1206 prop_atoms
.net_wm_moveresize_size_topright
||
1207 (Atom
)e
->xclient
.data
.l
[2] ==
1208 prop_atoms
.net_wm_moveresize_size_right
||
1209 (Atom
)e
->xclient
.data
.l
[2] ==
1210 prop_atoms
.net_wm_moveresize_size_right
||
1211 (Atom
)e
->xclient
.data
.l
[2] ==
1212 prop_atoms
.net_wm_moveresize_size_bottomright
||
1213 (Atom
)e
->xclient
.data
.l
[2] ==
1214 prop_atoms
.net_wm_moveresize_size_bottom
||
1215 (Atom
)e
->xclient
.data
.l
[2] ==
1216 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1217 (Atom
)e
->xclient
.data
.l
[2] ==
1218 prop_atoms
.net_wm_moveresize_size_left
||
1219 (Atom
)e
->xclient
.data
.l
[2] ==
1220 prop_atoms
.net_wm_moveresize_move
||
1221 (Atom
)e
->xclient
.data
.l
[2] ==
1222 prop_atoms
.net_wm_moveresize_size_keyboard
||
1223 (Atom
)e
->xclient
.data
.l
[2] ==
1224 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1226 moveresize_start(client
, e
->xclient
.data
.l
[0],
1227 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1228 e
->xclient
.data
.l
[2]);
1230 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1231 prop_atoms
.net_wm_moveresize_cancel
)
1232 moveresize_end(TRUE
);
1233 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1234 gint grav
, x
, y
, w
, h
;
1236 if (e
->xclient
.data
.l
[0] & 0xff)
1237 grav
= e
->xclient
.data
.l
[0] & 0xff;
1239 grav
= client
->gravity
;
1241 if (e
->xclient
.data
.l
[0] & 1 << 8)
1242 x
= e
->xclient
.data
.l
[1];
1245 if (e
->xclient
.data
.l
[0] & 1 << 9)
1246 y
= e
->xclient
.data
.l
[2];
1249 if (e
->xclient
.data
.l
[0] & 1 << 10)
1250 w
= e
->xclient
.data
.l
[3];
1252 w
= client
->area
.width
;
1253 if (e
->xclient
.data
.l
[0] & 1 << 11)
1254 h
= e
->xclient
.data
.l
[4];
1256 h
= client
->area
.height
;
1258 ob_debug("MOVERESIZE x %d %d y %d %d\n",
1259 e
->xclient
.data
.l
[0] & 1 << 8, x
,
1260 e
->xclient
.data
.l
[0] & 1 << 9, y
);
1261 client_convert_gravity(client
, grav
, &x
, &y
, w
, h
);
1262 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1264 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1266 /* ignore enter events caused by these like ob actions do */
1267 event_ignore_all_queued_enters();
1268 } else if (msgtype
== prop_atoms
.net_restack_window
) {
1269 if (e
->xclient
.data
.l
[0] != 2) {
1270 ob_debug_type(OB_DEBUG_APP_BUGS
,
1271 "_NET_RESTACK_WINDOW sent for window %s with "
1272 "invalid source indication %ld\n",
1273 client
->title
, e
->xclient
.data
.l
[0]);
1275 ObClient
*sibling
= NULL
;
1276 if (e
->xclient
.data
.l
[1]) {
1277 ObWindow
*win
= g_hash_table_lookup
1278 (window_map
, &e
->xclient
.data
.l
[1]);
1279 if (WINDOW_IS_CLIENT(win
) &&
1280 WINDOW_AS_CLIENT(win
) != client
)
1282 sibling
= WINDOW_AS_CLIENT(win
);
1284 if (sibling
== NULL
)
1285 ob_debug_type(OB_DEBUG_APP_BUGS
,
1286 "_NET_RESTACK_WINDOW sent for window %s "
1287 "with invalid sibling 0x%x\n",
1288 client
->title
, e
->xclient
.data
.l
[1]);
1290 if (e
->xclient
.data
.l
[2] == Below
||
1291 e
->xclient
.data
.l
[2] == BottomIf
||
1292 e
->xclient
.data
.l
[2] == Above
||
1293 e
->xclient
.data
.l
[2] == TopIf
||
1294 e
->xclient
.data
.l
[2] == Opposite
)
1296 /* just raise, don't activate */
1297 stacking_restack_request(client
, sibling
,
1298 e
->xclient
.data
.l
[2], FALSE
);
1299 /* send a synthetic ConfigureNotify, cuz this is supposed
1300 to be like a ConfigureRequest. */
1301 client_reconfigure(client
);
1303 ob_debug_type(OB_DEBUG_APP_BUGS
,
1304 "_NET_RESTACK_WINDOW sent for window %s "
1305 "with invalid detail %d\n",
1306 client
->title
, e
->xclient
.data
.l
[2]);
1310 case PropertyNotify
:
1311 /* validate cuz we query stuff off the client here */
1312 if (!client_validate(client
)) break;
1314 /* compress changes to a single property into a single change */
1315 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1319 /* XXX: it would be nice to compress ALL changes to a property,
1320 not just changes in a row without other props between. */
1322 a
= ce
.xproperty
.atom
;
1323 b
= e
->xproperty
.atom
;
1327 if ((a
== prop_atoms
.net_wm_name
||
1328 a
== prop_atoms
.wm_name
||
1329 a
== prop_atoms
.net_wm_icon_name
||
1330 a
== prop_atoms
.wm_icon_name
)
1332 (b
== prop_atoms
.net_wm_name
||
1333 b
== prop_atoms
.wm_name
||
1334 b
== prop_atoms
.net_wm_icon_name
||
1335 b
== prop_atoms
.wm_icon_name
)) {
1338 if (a
== prop_atoms
.net_wm_icon
&&
1339 b
== prop_atoms
.net_wm_icon
)
1342 XPutBackEvent(ob_display
, &ce
);
1346 msgtype
= e
->xproperty
.atom
;
1347 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1348 client_update_normal_hints(client
);
1349 /* normal hints can make a window non-resizable */
1350 client_setup_decor_and_functions(client
);
1351 } else if (msgtype
== XA_WM_HINTS
) {
1352 client_update_wmhints(client
);
1353 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1354 client_update_transient_for(client
);
1355 client_get_type_and_transientness(client
);
1356 /* type may have changed, so update the layer */
1357 client_calc_layer(client
);
1358 client_setup_decor_and_functions(client
);
1359 } else if (msgtype
== prop_atoms
.net_wm_name
||
1360 msgtype
== prop_atoms
.wm_name
||
1361 msgtype
== prop_atoms
.net_wm_icon_name
||
1362 msgtype
== prop_atoms
.wm_icon_name
) {
1363 client_update_title(client
);
1364 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1365 client_update_protocols(client
);
1366 client_setup_decor_and_functions(client
);
1368 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1369 client_update_strut(client
);
1371 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1372 client_update_icons(client
);
1374 else if (msgtype
== prop_atoms
.net_wm_icon_geometry
) {
1375 client_update_icon_geometry(client
);
1377 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1378 client_update_user_time(client
);
1380 else if (msgtype
== prop_atoms
.net_wm_user_time_window
) {
1381 client_update_user_time_window(client
);
1384 else if (msgtype
== prop_atoms
.net_wm_sync_request_counter
) {
1385 client_update_sync_request_counter(client
);
1388 case ColormapNotify
:
1389 client_update_colormap(client
, e
->xcolormap
.colormap
);
1394 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1395 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1396 frame_adjust_shape(client
->frame
);
1402 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1406 if (e
->xbutton
.button
== 1)
1407 stacking_raise(DOCK_AS_WINDOW(s
));
1408 else if (e
->xbutton
.button
== 2)
1409 stacking_lower(DOCK_AS_WINDOW(s
));
1420 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1424 dock_app_drag(app
, &e
->xmotion
);
1427 if (app
->ignore_unmaps
) {
1428 app
->ignore_unmaps
--;
1431 dock_remove(app
, TRUE
);
1434 dock_remove(app
, FALSE
);
1436 case ReparentNotify
:
1437 dock_remove(app
, FALSE
);
1439 case ConfigureNotify
:
1440 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1445 static ObMenuFrame
* find_active_menu()
1448 ObMenuFrame
*ret
= NULL
;
1450 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1459 static ObMenuFrame
* find_active_or_last_menu()
1461 ObMenuFrame
*ret
= NULL
;
1463 ret
= find_active_menu();
1464 if (!ret
&& menu_frame_visible
)
1465 ret
= menu_frame_visible
->data
;
1469 static gboolean
event_handle_menu_keyboard(XEvent
*ev
)
1471 guint keycode
, state
;
1474 gboolean ret
= TRUE
;
1476 keycode
= ev
->xkey
.keycode
;
1477 state
= ev
->xkey
.state
;
1478 unikey
= translate_unichar(keycode
);
1480 frame
= find_active_or_last_menu();
1484 else if (keycode
== ob_keycode(OB_KEY_ESCAPE
) && state
== 0) {
1485 /* Escape closes the active menu */
1486 menu_frame_hide(frame
);
1489 else if (keycode
== ob_keycode(OB_KEY_RETURN
) && (state
== 0 ||
1490 state
== ControlMask
))
1492 /* Enter runs the active item or goes into the submenu.
1493 Control-Enter runs it without closing the menu. */
1495 menu_frame_select_next(frame
->child
);
1497 menu_entry_frame_execute(frame
->selected
, state
, ev
->xkey
.time
);
1500 else if (keycode
== ob_keycode(OB_KEY_LEFT
) && ev
->xkey
.state
== 0) {
1501 /* Left goes to the parent menu */
1502 menu_frame_select(frame
, NULL
, TRUE
);
1505 else if (keycode
== ob_keycode(OB_KEY_RIGHT
) && ev
->xkey
.state
== 0) {
1506 /* Right goes to the selected submenu */
1507 if (frame
->child
) menu_frame_select_next(frame
->child
);
1510 else if (keycode
== ob_keycode(OB_KEY_UP
) && state
== 0) {
1511 menu_frame_select_previous(frame
);
1514 else if (keycode
== ob_keycode(OB_KEY_DOWN
) && state
== 0) {
1515 menu_frame_select_next(frame
);
1518 /* keyboard accelerator shortcuts. */
1519 else if (ev
->xkey
.state
== 0 &&
1520 /* was it a valid key? */
1522 /* don't bother if the menu is empty. */
1527 ObMenuEntryFrame
*found
= NULL
;
1528 guint num_found
= 0;
1530 /* start after the selected one */
1531 start
= frame
->entries
;
1532 if (frame
->selected
) {
1533 for (it
= start
; frame
->selected
!= it
->data
; it
= g_list_next(it
))
1534 g_assert(it
!= NULL
); /* nothing was selected? */
1535 /* next with wraparound */
1536 start
= g_list_next(it
);
1537 if (start
== NULL
) start
= frame
->entries
;
1542 ObMenuEntryFrame
*e
= it
->data
;
1543 gunichar entrykey
= 0;
1545 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1546 entrykey
= e
->entry
->data
.normal
.shortcut
;
1547 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1548 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1550 if (unikey
== entrykey
) {
1551 if (found
== NULL
) found
= e
;
1555 /* next with wraparound */
1556 it
= g_list_next(it
);
1557 if (it
== NULL
) it
= frame
->entries
;
1558 } while (it
!= start
);
1561 if (found
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
1564 menu_frame_select(frame
, found
, TRUE
);
1565 usleep(50000); /* highlight the item for a short bit so the
1566 user can see what happened */
1567 menu_entry_frame_execute(found
, state
, ev
->xkey
.time
);
1569 menu_frame_select(frame
, found
, TRUE
);
1571 menu_frame_select_next(frame
->child
);
1582 static gboolean
event_handle_menu(XEvent
*ev
)
1585 ObMenuEntryFrame
*e
;
1586 gboolean ret
= TRUE
;
1590 if ((ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5)
1593 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1594 ev
->xbutton
.y_root
)))
1595 menu_entry_frame_execute(e
, ev
->xbutton
.state
,
1598 menu_frame_hide_all();
1602 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1603 if (e
->ignore_enters
)
1606 menu_frame_select(e
->frame
, e
, FALSE
);
1610 /*ignore leaves when we're already in the window */
1611 if (ev
->xcrossing
.detail
== NotifyInferior
)
1614 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1615 (f
= find_active_menu()) && f
->selected
== e
&&
1616 e
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1618 menu_frame_select(e
->frame
, NULL
, FALSE
);
1622 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1623 ev
->xmotion
.y_root
)))
1624 menu_frame_select(e
->frame
, e
, FALSE
);
1627 ret
= event_handle_menu_keyboard(ev
);
1633 static void event_handle_user_input(ObClient
*client
, XEvent
*e
)
1635 g_assert(e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
1636 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
1637 e
->type
== KeyRelease
);
1639 if (menu_frame_visible
) {
1640 if (event_handle_menu(e
))
1641 /* don't use the event if the menu used it, but if the menu
1642 didn't use it and it's a keypress that is bound, it will
1643 close the menu and be used */
1647 /* if the keyboard interactive action uses the event then dont
1648 use it for bindings. likewise is moveresize uses the event. */
1649 if (!keyboard_process_interactive_grab(e
, &client
) &&
1650 !(moveresize_in_progress
&& moveresize_event(e
)))
1652 if (moveresize_in_progress
)
1653 /* make further actions work on the client being
1655 client
= moveresize_client
;
1657 menu_can_hide
= FALSE
;
1658 ob_main_loop_timeout_add(ob_main_loop
,
1659 config_menu_hide_delay
* 1000,
1660 menu_hide_delay_func
,
1661 NULL
, g_direct_equal
, NULL
);
1663 if (e
->type
== ButtonPress
||
1664 e
->type
== ButtonRelease
||
1665 e
->type
== MotionNotify
)
1667 /* the frame may not be "visible" but they can still click on it
1668 in the case where it is animating before disappearing */
1669 if (!client
|| !frame_iconify_animating(client
->frame
))
1670 mouse_event(client
, e
);
1671 } else if (e
->type
== KeyPress
) {
1672 keyboard_event((focus_cycle_target
? focus_cycle_target
:
1673 (client
? client
: focus_client
)), e
);
1678 static gboolean
menu_hide_delay_func(gpointer data
)
1680 menu_can_hide
= TRUE
;
1681 return FALSE
; /* no repeat */
1684 static void focus_delay_dest(gpointer data
)
1689 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
1691 const ObFocusDelayData
*f1
= d1
;
1692 return f1
->client
== d2
;
1695 static gboolean
focus_delay_func(gpointer data
)
1697 ObFocusDelayData
*d
= data
;
1698 Time old
= event_curtime
;
1700 event_curtime
= d
->time
;
1701 if (focus_client
!= d
->client
) {
1702 if (client_focus(d
->client
) && config_focus_raise
)
1703 stacking_raise(CLIENT_AS_WINDOW(d
->client
));
1705 event_curtime
= old
;
1706 return FALSE
; /* no repeat */
1709 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1711 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1715 void event_halt_focus_delay()
1717 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1720 static Bool
event_look_for_enters(Display
*d
, XEvent
*e
, XPointer arg
)
1722 if (e
->type
== EnterNotify
&&
1723 /* these types aren't used for focusing */
1724 !(e
->xcrossing
.mode
== NotifyGrab
||
1725 e
->xcrossing
.mode
== NotifyUngrab
||
1726 e
->xcrossing
.detail
== NotifyInferior
))
1730 /* found an enter for that leave, ignore it if it's going to
1732 win
= g_hash_table_lookup(window_map
, &e
->xany
.window
);
1733 if (win
&& WINDOW_IS_CLIENT(win
))
1734 ++ignore_enter_focus
;
1736 return False
; /* don't disrupt the queue order, just count them */
1739 void event_ignore_all_queued_enters()
1743 XSync(ob_display
, FALSE
);
1745 /* count the events without disrupting them */
1746 ignore_enter_focus
= 0;
1747 XCheckIfEvent(ob_display
, &e
, event_look_for_enters
, NULL
);
1750 static gboolean
is_enter_focus_event_ignored(XEvent
*e
)
1752 g_assert(e
->type
== EnterNotify
&&
1753 !(e
->xcrossing
.mode
== NotifyGrab
||
1754 e
->xcrossing
.mode
== NotifyUngrab
||
1755 e
->xcrossing
.detail
== NotifyInferior
));
1757 ob_debug_type(OB_DEBUG_FOCUS
, "# enters ignored: %d\n",
1758 ignore_enter_focus
);
1760 if (ignore_enter_focus
) {
1761 --ignore_enter_focus
;
1767 gboolean
event_time_after(Time t1
, Time t2
)
1769 g_assert(t1
!= CurrentTime
);
1770 g_assert(t2
!= CurrentTime
);
1773 Timestamp values wrap around (after about 49.7 days). The server, given
1774 its current time is represented by timestamp T, always interprets
1775 timestamps from clients by treating half of the timestamp space as being
1776 later in time than T.
1777 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
1780 /* TIME_HALF is half of the number space of a Time type variable */
1781 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
1783 if (t2
>= TIME_HALF
)
1784 /* t2 is in the second half so t1 might wrap around and be smaller than
1786 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
1788 /* t2 is in the first half so t1 has to come after it */
1789 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);