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 "moveresize.h"
44 #include "extensions.h"
45 #include "translate.h"
48 #include <X11/Xatom.h>
51 #ifdef HAVE_SYS_SELECT_H
52 # include <sys/select.h>
58 # include <unistd.h> /* for usleep() */
61 # include <X11/XKBlib.h>
65 #include <X11/ICE/ICElib.h>
79 static void event_process(const XEvent
*e
, gpointer data
);
80 static void event_handle_root(XEvent
*e
);
81 static gboolean
event_handle_menu_keyboard(XEvent
*e
);
82 static gboolean
event_handle_menu(XEvent
*e
);
83 static void event_handle_dock(ObDock
*s
, XEvent
*e
);
84 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
);
85 static void event_handle_client(ObClient
*c
, XEvent
*e
);
86 static void event_handle_user_time_window_clients(GSList
*l
, XEvent
*e
);
87 static void event_handle_user_input(ObClient
*client
, XEvent
*e
);
89 static void focus_delay_dest(gpointer data
);
90 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
);
91 static gboolean
focus_delay_func(gpointer data
);
92 static void focus_delay_client_dest(ObClient
*client
, gpointer data
);
94 static gboolean
menu_hide_delay_func(gpointer data
);
96 /* The time for the current event being processed */
97 Time event_curtime
= CurrentTime
;
99 static guint ignore_enter_focus
= 0;
100 static gboolean menu_can_hide
;
101 static gboolean focus_left_screen
= FALSE
;
104 static void ice_handler(gint fd
, gpointer conn
)
107 IceProcessMessages(conn
, NULL
, &b
);
110 static void ice_watch(IceConn conn
, IcePointer data
, Bool opening
,
111 IcePointer
*watch_data
)
116 fd
= IceConnectionNumber(conn
);
117 ob_main_loop_fd_add(ob_main_loop
, fd
, ice_handler
, conn
, NULL
);
119 ob_main_loop_fd_remove(ob_main_loop
, fd
);
125 void event_startup(gboolean reconfig
)
127 if (reconfig
) return;
129 ob_main_loop_x_add(ob_main_loop
, event_process
, NULL
, NULL
);
132 IceAddConnectionWatch(ice_watch
, NULL
);
135 client_add_destroy_notify(focus_delay_client_dest
, NULL
);
138 void event_shutdown(gboolean reconfig
)
140 if (reconfig
) return;
143 IceRemoveConnectionWatch(ice_watch
, NULL
);
146 client_remove_destroy_notify(focus_delay_client_dest
);
149 static Window
event_get_window(XEvent
*e
)
156 window
= RootWindow(ob_display
, ob_screen
);
159 window
= e
->xmap
.window
;
162 window
= e
->xunmap
.window
;
165 window
= e
->xdestroywindow
.window
;
167 case ConfigureRequest
:
168 window
= e
->xconfigurerequest
.window
;
170 case ConfigureNotify
:
171 window
= e
->xconfigure
.window
;
175 if (extensions_xkb
&& e
->type
== extensions_xkb_event_basep
) {
176 switch (((XkbAnyEvent
*)e
)->xkb_type
) {
178 window
= ((XkbBellNotifyEvent
*)e
)->window
;
185 if (extensions_sync
&&
186 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
191 window
= e
->xany
.window
;
196 static void event_set_curtime(XEvent
*e
)
198 Time t
= CurrentTime
;
200 /* grab the lasttime and hack up the state */
216 t
= e
->xproperty
.time
;
220 t
= e
->xcrossing
.time
;
224 if (extensions_sync
&&
225 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
227 t
= ((XSyncAlarmNotifyEvent
*)e
)->time
;
230 /* if more event types are anticipated, get their timestamp
238 static void event_hack_mods(XEvent
*e
)
241 XkbStateRec xkb_state
;
247 e
->xbutton
.state
= modkeys_only_modifier_masks(e
->xbutton
.state
);
250 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
253 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
255 if (XkbGetState(ob_display
, XkbUseCoreKbd
, &xkb_state
) == Success
) {
256 e
->xkey
.state
= xkb_state
.compat_state
;
260 /* remove from the state the mask of the modifier key being released,
261 if it is a modifier key being released that is */
262 e
->xkey
.state
&= ~modkeys_keycode_to_mask(e
->xkey
.keycode
);
265 e
->xmotion
.state
= modkeys_only_modifier_masks(e
->xmotion
.state
);
266 /* compress events */
269 while (XCheckTypedWindowEvent(ob_display
, e
->xmotion
.window
,
271 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
272 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
279 static gboolean
wanted_focusevent(XEvent
*e
, gboolean in_client_only
)
281 gint mode
= e
->xfocus
.mode
;
282 gint detail
= e
->xfocus
.detail
;
283 Window win
= e
->xany
.window
;
285 if (e
->type
== FocusIn
) {
286 /* These are ones we never want.. */
288 /* This means focus was given by a keyboard/mouse grab. */
289 if (mode
== NotifyGrab
)
291 /* This means focus was given back from a keyboard/mouse grab. */
292 if (mode
== NotifyUngrab
)
295 /* These are the ones we want.. */
297 if (win
== RootWindow(ob_display
, ob_screen
)) {
298 /* If looking for a focus in on a client, then always return
299 FALSE for focus in's to the root window */
302 /* This means focus reverted off of a client */
303 else if (detail
== NotifyPointerRoot
||
304 detail
== NotifyDetailNone
||
305 detail
== NotifyInferior
)
311 /* It was on a client, was it a valid one?
312 It's possible to get a FocusIn event for a client that was managed
315 if (in_client_only
) {
316 ObWindow
*w
= g_hash_table_lookup(window_map
, &e
->xfocus
.window
);
317 if (!w
|| !WINDOW_IS_CLIENT(w
))
321 /* This means focus moved from the root window to a client */
322 if (detail
== NotifyVirtual
)
324 /* This means focus moved from one client to another */
325 if (detail
== NotifyNonlinearVirtual
)
331 g_assert(e
->type
== FocusOut
);
333 /* These are ones we never want.. */
335 /* This means focus was taken by a keyboard/mouse grab. */
336 if (mode
== NotifyGrab
)
339 /* Focus left the root window revertedto state */
340 if (win
== RootWindow(ob_display
, ob_screen
))
343 /* These are the ones we want.. */
345 /* This means focus moved from a client to the root window */
346 if (detail
== NotifyVirtual
)
348 /* This means focus moved from one client to another */
349 if (detail
== NotifyNonlinearVirtual
)
357 static Bool
event_look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
359 return e
->type
== FocusIn
&& wanted_focusevent(e
, FALSE
);
362 Bool
event_look_for_focusin_client(Display
*d
, XEvent
*e
, XPointer arg
)
364 return e
->type
== FocusIn
&& wanted_focusevent(e
, TRUE
);
367 static void print_focusevent(XEvent
*e
)
369 gint mode
= e
->xfocus
.mode
;
370 gint detail
= e
->xfocus
.detail
;
371 Window win
= e
->xany
.window
;
372 const gchar
*modestr
, *detailstr
;
375 case NotifyNormal
: modestr
="NotifyNormal"; break;
376 case NotifyGrab
: modestr
="NotifyGrab"; break;
377 case NotifyUngrab
: modestr
="NotifyUngrab"; break;
378 case NotifyWhileGrabbed
: modestr
="NotifyWhileGrabbed"; break;
381 case NotifyAncestor
: detailstr
="NotifyAncestor"; break;
382 case NotifyVirtual
: detailstr
="NotifyVirtual"; break;
383 case NotifyInferior
: detailstr
="NotifyInferior"; break;
384 case NotifyNonlinear
: detailstr
="NotifyNonlinear"; break;
385 case NotifyNonlinearVirtual
: detailstr
="NotifyNonlinearVirtual"; break;
386 case NotifyPointer
: detailstr
="NotifyPointer"; break;
387 case NotifyPointerRoot
: detailstr
="NotifyPointerRoot"; break;
388 case NotifyDetailNone
: detailstr
="NotifyDetailNone"; break;
391 if (mode
== NotifyGrab
|| mode
== NotifyUngrab
)
396 ob_debug_type(OB_DEBUG_FOCUS
, "Focus%s 0x%x mode=%s detail=%s\n",
397 (e
->xfocus
.type
== FocusIn
? "In" : "Out"),
403 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
408 if (!wanted_focusevent(e
, FALSE
))
413 if (!wanted_focusevent(e
, FALSE
))
420 static void event_process(const XEvent
*ec
, gpointer data
)
423 ObClient
*client
= NULL
;
425 ObDockApp
*dockapp
= NULL
;
426 ObWindow
*obwin
= NULL
;
427 GSList
*timewinclients
= NULL
;
429 ObEventData
*ed
= data
;
431 /* make a copy we can mangle */
435 window
= event_get_window(e
);
436 if (e
->type
!= PropertyNotify
||
437 !(timewinclients
= propwin_get_clients(window
,
438 OB_PROPWIN_USER_TIME
)))
439 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
440 switch (obwin
->type
) {
442 dock
= WINDOW_AS_DOCK(obwin
);
445 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
448 client
= WINDOW_AS_CLIENT(obwin
);
451 case Window_Internal
:
452 /* not to be used for events */
453 g_assert_not_reached();
458 event_set_curtime(e
);
460 if (event_ignore(e
, client
)) {
467 /* deal with it in the kernel */
469 if (menu_frame_visible
&&
470 (e
->type
== EnterNotify
|| e
->type
== LeaveNotify
))
472 /* crossing events for menu */
473 event_handle_menu(e
);
474 } else if (e
->type
== FocusIn
) {
475 if (e
->xfocus
.detail
== NotifyPointerRoot
||
476 e
->xfocus
.detail
== NotifyDetailNone
||
477 e
->xfocus
.detail
== NotifyInferior
)
481 ob_debug_type(OB_DEBUG_FOCUS
, "Focus went to pointer root/none\n");
483 /* If another FocusIn is in the queue then don't fallback yet. This
484 fixes the fun case of:
485 window map -> send focusin
486 window unmap -> get focusout
487 window map -> send focusin
488 get first focus out -> fall back to something (new window
489 hasn't received focus yet, so something else) -> send focusin
490 which means the "something else" is the last thing to get a
491 focusin sent to it, so the new window doesn't end up with focus.
493 But if the other focus in is something like PointerRoot then we
494 still want to fall back.
496 if (XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin_client
,
499 XPutBackEvent(ob_display
, &ce
);
500 ob_debug_type(OB_DEBUG_FOCUS
,
501 " but another FocusIn is coming\n");
503 /* Focus has been reverted to the root window or nothing.
505 FocusOut events come after UnmapNotify, so we don't need to
506 worry about focusing an invalid window
509 if (!focus_left_screen
)
510 focus_fallback(TRUE
);
515 ob_debug_type(OB_DEBUG_FOCUS
,
516 "Focus went to a window that is already gone\n");
518 /* If you send focus to a window and then it disappears, you can
519 get the FocusIn for it, after it is unmanaged.
520 Just wait for the next FocusOut/FocusIn pair. */
522 else if (client
!= focus_client
) {
523 focus_left_screen
= FALSE
;
524 frame_adjust_focus(client
->frame
, TRUE
);
525 focus_set_client(client
);
526 client_calc_layer(client
);
527 client_bring_helper_windows(client
);
529 } else if (e
->type
== FocusOut
) {
530 gboolean nomove
= FALSE
;
533 /* Look for the followup FocusIn */
534 if (!XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin
, NULL
)) {
535 /* There is no FocusIn, this means focus went to a window that
536 is not being managed, or a window on another screen. */
540 xerror_set_ignore(TRUE
);
541 if (XGetInputFocus(ob_display
, &win
, &i
) != 0 &&
542 XGetGeometry(ob_display
, win
, &root
, &i
,&i
,&u
,&u
,&u
,&u
) != 0 &&
543 root
!= RootWindow(ob_display
, ob_screen
))
545 ob_debug_type(OB_DEBUG_FOCUS
,
546 "Focus went to another screen !\n");
547 focus_left_screen
= TRUE
;
550 ob_debug_type(OB_DEBUG_FOCUS
,
551 "Focus went to a black hole !\n");
552 xerror_set_ignore(FALSE
);
553 /* nothing is focused */
554 focus_set_client(NULL
);
555 } else if (ce
.xany
.window
== e
->xany
.window
) {
556 ob_debug_type(OB_DEBUG_FOCUS
, "Focus didn't go anywhere\n");
557 /* If focus didn't actually move anywhere, there is nothing to do*/
560 /* Focus did move, so process the FocusIn event */
561 ObEventData ed
= { .ignored
= FALSE
};
562 event_process(&ce
, &ed
);
564 /* The FocusIn was ignored, this means it was on a window
565 that isn't a client. */
566 ob_debug_type(OB_DEBUG_FOCUS
,
567 "Focus went to an unmanaged window 0x%x !\n",
569 focus_fallback(TRUE
);
573 if (client
&& !nomove
) {
574 frame_adjust_focus(client
->frame
, FALSE
);
575 if (client
== focus_client
)
576 focus_set_client(NULL
);
577 client_calc_layer(client
);
579 } else if (timewinclients
)
580 event_handle_user_time_window_clients(timewinclients
, e
);
582 event_handle_client(client
, e
);
584 event_handle_dockapp(dockapp
, e
);
586 event_handle_dock(dock
, e
);
587 else if (window
== RootWindow(ob_display
, ob_screen
))
588 event_handle_root(e
);
589 else if (e
->type
== MapRequest
)
590 client_manage(window
);
591 else if (e
->type
== ClientMessage
) {
592 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
593 windows that are not managed yet. */
594 if (e
->xclient
.message_type
== prop_atoms
.net_request_frame_extents
) {
595 /* Pretend to manage the client, getting information used to
596 determine its decorations */
597 ObClient
*c
= client_fake_manage(e
->xclient
.window
);
600 /* set the frame extents on the window */
601 vals
[0] = c
->frame
->size
.left
;
602 vals
[1] = c
->frame
->size
.right
;
603 vals
[2] = c
->frame
->size
.top
;
604 vals
[3] = c
->frame
->size
.bottom
;
605 PROP_SETA32(e
->xclient
.window
, net_frame_extents
,
608 /* Free the pretend client */
609 client_fake_unmanage(c
);
612 else if (e
->type
== ConfigureRequest
) {
613 /* unhandled configure requests must be used to configure the
617 xwc
.x
= e
->xconfigurerequest
.x
;
618 xwc
.y
= e
->xconfigurerequest
.y
;
619 xwc
.width
= e
->xconfigurerequest
.width
;
620 xwc
.height
= e
->xconfigurerequest
.height
;
621 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
622 xwc
.sibling
= e
->xconfigurerequest
.above
;
623 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
625 /* we are not to be held responsible if someone sends us an
627 xerror_set_ignore(TRUE
);
628 XConfigureWindow(ob_display
, window
,
629 e
->xconfigurerequest
.value_mask
, &xwc
);
630 xerror_set_ignore(FALSE
);
633 else if (extensions_sync
&&
634 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
636 XSyncAlarmNotifyEvent
*se
= (XSyncAlarmNotifyEvent
*)e
;
637 if (se
->alarm
== moveresize_alarm
&& moveresize_in_progress
)
642 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
643 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
644 e
->type
== KeyRelease
)
646 event_handle_user_input(client
, e
);
649 /* if something happens and it's not from an XEvent, then we don't know
651 event_curtime
= CurrentTime
;
654 static void event_handle_root(XEvent
*e
)
660 ob_debug("Another WM has requested to replace us. Exiting.\n");
665 if (e
->xclient
.format
!= 32) break;
667 msgtype
= e
->xclient
.message_type
;
668 if (msgtype
== prop_atoms
.net_current_desktop
) {
669 guint d
= e
->xclient
.data
.l
[0];
670 if (d
< screen_num_desktops
) {
671 event_curtime
= e
->xclient
.data
.l
[1];
672 if (event_curtime
== 0)
673 ob_debug_type(OB_DEBUG_APP_BUGS
,
674 "_NET_CURRENT_DESKTOP message is missing "
676 screen_set_desktop(d
, TRUE
);
678 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
679 guint d
= e
->xclient
.data
.l
[0];
681 screen_set_num_desktops(d
);
682 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
683 screen_show_desktop(e
->xclient
.data
.l
[0] != 0, NULL
);
684 } else if (msgtype
== prop_atoms
.ob_control
) {
685 if (e
->xclient
.data
.l
[0] == 1)
687 else if (e
->xclient
.data
.l
[0] == 2)
692 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
)
693 screen_update_desktop_names();
694 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
695 screen_update_layout();
697 case ConfigureNotify
:
699 XRRUpdateConfiguration(e
);
708 void event_enter_client(ObClient
*client
)
710 g_assert(config_focus_follow
);
712 if (client_enter_focusable(client
) && client_can_focus(client
)) {
713 if (config_focus_delay
) {
714 ObFocusDelayData
*data
;
716 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
718 data
= g_new(ObFocusDelayData
, 1);
719 data
->client
= client
;
720 data
->time
= event_curtime
;
722 ob_main_loop_timeout_add(ob_main_loop
,
725 data
, focus_delay_cmp
, focus_delay_dest
);
727 ObFocusDelayData data
;
728 data
.client
= client
;
729 data
.time
= event_curtime
;
730 focus_delay_func(&data
);
735 static void event_handle_user_time_window_clients(GSList
*l
, XEvent
*e
)
737 g_assert(e
->type
== PropertyNotify
);
738 if (e
->xproperty
.atom
== prop_atoms
.net_wm_user_time
) {
739 for (; l
; l
= g_slist_next(l
))
740 client_update_user_time(l
->data
);
744 static void event_handle_client(ObClient
*client
, XEvent
*e
)
749 static gint px
= -1, py
= -1;
754 /* save where the press occured for the first button pressed */
756 pb
= e
->xbutton
.button
;
761 /* Wheel buttons don't draw because they are an instant click, so it
762 is a waste of resources to go drawing it.
763 if the user is doing an intereactive thing, or has a menu open then
764 the mouse is grabbed (possibly) and if we get these events we don't
765 want to deal with them
767 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5) &&
768 !keyboard_interactively_grabbed() &&
771 /* use where the press occured */
772 con
= frame_context(client
, e
->xbutton
.window
, px
, py
);
773 con
= mouse_button_frame_context(con
, e
->xbutton
.button
);
775 if (e
->type
== ButtonRelease
&& e
->xbutton
.button
== pb
)
776 pb
= 0, px
= py
= -1;
779 case OB_FRAME_CONTEXT_MAXIMIZE
:
780 client
->frame
->max_press
= (e
->type
== ButtonPress
);
781 framerender_frame(client
->frame
);
783 case OB_FRAME_CONTEXT_CLOSE
:
784 client
->frame
->close_press
= (e
->type
== ButtonPress
);
785 framerender_frame(client
->frame
);
787 case OB_FRAME_CONTEXT_ICONIFY
:
788 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
789 framerender_frame(client
->frame
);
791 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
792 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
793 framerender_frame(client
->frame
);
795 case OB_FRAME_CONTEXT_SHADE
:
796 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
797 framerender_frame(client
->frame
);
800 /* nothing changes with clicks for any other contexts */
806 con
= frame_context(client
, e
->xmotion
.window
,
807 e
->xmotion
.x
, e
->xmotion
.y
);
809 case OB_FRAME_CONTEXT_TITLEBAR
:
810 /* we've left the button area inside the titlebar */
811 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
812 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
813 client
->frame
->close_hover
)
815 client
->frame
->max_hover
= FALSE
;
816 client
->frame
->desk_hover
= FALSE
;
817 client
->frame
->shade_hover
= FALSE
;
818 client
->frame
->iconify_hover
= FALSE
;
819 client
->frame
->close_hover
= FALSE
;
820 frame_adjust_state(client
->frame
);
823 case OB_FRAME_CONTEXT_MAXIMIZE
:
824 if (!client
->frame
->max_hover
) {
825 client
->frame
->max_hover
= TRUE
;
826 frame_adjust_state(client
->frame
);
829 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
830 if (!client
->frame
->desk_hover
) {
831 client
->frame
->desk_hover
= TRUE
;
832 frame_adjust_state(client
->frame
);
835 case OB_FRAME_CONTEXT_SHADE
:
836 if (!client
->frame
->shade_hover
) {
837 client
->frame
->shade_hover
= TRUE
;
838 frame_adjust_state(client
->frame
);
841 case OB_FRAME_CONTEXT_ICONIFY
:
842 if (!client
->frame
->iconify_hover
) {
843 client
->frame
->iconify_hover
= TRUE
;
844 frame_adjust_state(client
->frame
);
847 case OB_FRAME_CONTEXT_CLOSE
:
848 if (!client
->frame
->close_hover
) {
849 client
->frame
->close_hover
= TRUE
;
850 frame_adjust_state(client
->frame
);
858 con
= frame_context(client
, e
->xcrossing
.window
,
859 e
->xcrossing
.x
, e
->xcrossing
.y
);
861 case OB_FRAME_CONTEXT_MAXIMIZE
:
862 client
->frame
->max_hover
= FALSE
;
863 frame_adjust_state(client
->frame
);
865 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
866 client
->frame
->desk_hover
= FALSE
;
867 frame_adjust_state(client
->frame
);
869 case OB_FRAME_CONTEXT_SHADE
:
870 client
->frame
->shade_hover
= FALSE
;
871 frame_adjust_state(client
->frame
);
873 case OB_FRAME_CONTEXT_ICONIFY
:
874 client
->frame
->iconify_hover
= FALSE
;
875 frame_adjust_state(client
->frame
);
877 case OB_FRAME_CONTEXT_CLOSE
:
878 client
->frame
->close_hover
= FALSE
;
879 frame_adjust_state(client
->frame
);
881 case OB_FRAME_CONTEXT_FRAME
:
882 /* When the mouse leaves an animating window, don't use the
883 corresponding enter events. Pretend like the animating window
884 doesn't even exist..! */
885 if (frame_iconify_animating(client
->frame
))
886 event_ignore_queued_enters();
888 ob_debug_type(OB_DEBUG_FOCUS
,
889 "%sNotify mode %d detail %d on %lx\n",
890 (e
->type
== EnterNotify
? "Enter" : "Leave"),
892 e
->xcrossing
.detail
, (client
?client
->window
:0));
893 if (keyboard_interactively_grabbed())
895 if (config_focus_follow
&& config_focus_delay
&&
896 /* leave inferior events can happen when the mouse goes onto
897 the window's border and then into the window before the
899 e
->xcrossing
.detail
!= NotifyInferior
)
901 ob_main_loop_timeout_remove_data(ob_main_loop
,
912 gboolean nofocus
= FALSE
;
914 if (ignore_enter_focus
) {
915 ignore_enter_focus
--;
919 con
= frame_context(client
, e
->xcrossing
.window
,
920 e
->xcrossing
.x
, e
->xcrossing
.y
);
922 case OB_FRAME_CONTEXT_MAXIMIZE
:
923 client
->frame
->max_hover
= TRUE
;
924 frame_adjust_state(client
->frame
);
926 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
927 client
->frame
->desk_hover
= TRUE
;
928 frame_adjust_state(client
->frame
);
930 case OB_FRAME_CONTEXT_SHADE
:
931 client
->frame
->shade_hover
= TRUE
;
932 frame_adjust_state(client
->frame
);
934 case OB_FRAME_CONTEXT_ICONIFY
:
935 client
->frame
->iconify_hover
= TRUE
;
936 frame_adjust_state(client
->frame
);
938 case OB_FRAME_CONTEXT_CLOSE
:
939 client
->frame
->close_hover
= TRUE
;
940 frame_adjust_state(client
->frame
);
942 case OB_FRAME_CONTEXT_FRAME
:
943 if (keyboard_interactively_grabbed())
945 if (e
->xcrossing
.mode
== NotifyGrab
||
946 e
->xcrossing
.mode
== NotifyUngrab
||
947 /*ignore enters when we're already in the window */
948 e
->xcrossing
.detail
== NotifyInferior
)
950 ob_debug_type(OB_DEBUG_FOCUS
,
951 "%sNotify mode %d detail %d on %lx IGNORED\n",
952 (e
->type
== EnterNotify
? "Enter" : "Leave"),
954 e
->xcrossing
.detail
, client
?client
->window
:0);
956 ob_debug_type(OB_DEBUG_FOCUS
,
957 "%sNotify mode %d detail %d on %lx, "
958 "focusing window: %d\n",
959 (e
->type
== EnterNotify
? "Enter" : "Leave"),
961 e
->xcrossing
.detail
, (client
?client
->window
:0),
963 if (!nofocus
&& config_focus_follow
)
964 event_enter_client(client
);
972 case ConfigureRequest
:
974 /* dont compress these unless you're going to watch for property
975 notifies in between (these can change what the configure would
977 also you can't compress stacking events
982 /* if nothing is changed, then a configurenotify is needed */
983 gboolean config
= TRUE
;
987 w
= client
->area
.width
;
988 h
= client
->area
.height
;
990 ob_debug("ConfigureRequest desktop %d wmstate %d visibile %d\n",
991 screen_desktop
, client
->wmstate
, client
->frame
->visible
);
993 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
994 if (client
->border_width
!= e
->xconfigurerequest
.border_width
) {
995 client
->border_width
= e
->xconfigurerequest
.border_width
;
996 /* if only the border width is changing, then it's not needed*/
1001 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
1002 ObClient
*sibling
= NULL
;
1004 /* get the sibling */
1005 if (e
->xconfigurerequest
.value_mask
& CWSibling
) {
1007 win
= g_hash_table_lookup(window_map
,
1008 &e
->xconfigurerequest
.above
);
1009 if (WINDOW_IS_CLIENT(win
) && WINDOW_AS_CLIENT(win
) != client
)
1010 sibling
= WINDOW_AS_CLIENT(win
);
1013 /* activate it rather than just focus it */
1014 stacking_restack_request(client
, sibling
,
1015 e
->xconfigurerequest
.detail
, TRUE
);
1017 /* if a stacking change is requested then it is needed */
1021 /* don't allow clients to move shaded windows (fvwm does this) */
1022 if (client
->shaded
&& (e
->xconfigurerequest
.value_mask
& CWX
||
1023 e
->xconfigurerequest
.value_mask
& CWY
))
1025 e
->xconfigurerequest
.value_mask
&= ~CWX
;
1026 e
->xconfigurerequest
.value_mask
&= ~CWY
;
1028 /* if the client tried to move and we aren't letting it then a
1029 synthetic event is needed */
1033 if (e
->xconfigurerequest
.value_mask
& CWX
||
1034 e
->xconfigurerequest
.value_mask
& CWY
||
1035 e
->xconfigurerequest
.value_mask
& CWWidth
||
1036 e
->xconfigurerequest
.value_mask
& CWHeight
)
1038 if (e
->xconfigurerequest
.value_mask
& CWX
)
1039 x
= e
->xconfigurerequest
.x
;
1040 if (e
->xconfigurerequest
.value_mask
& CWY
)
1041 y
= e
->xconfigurerequest
.y
;
1042 if (e
->xconfigurerequest
.value_mask
& CWWidth
)
1043 w
= e
->xconfigurerequest
.width
;
1044 if (e
->xconfigurerequest
.value_mask
& CWHeight
)
1045 h
= e
->xconfigurerequest
.height
;
1047 /* if a new position or size is requested, then a configure is
1052 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d\n",
1053 e
->xconfigurerequest
.value_mask
& CWX
, x
,
1054 e
->xconfigurerequest
.value_mask
& CWY
, y
,
1055 e
->xconfigurerequest
.value_mask
& CWWidth
, w
,
1056 e
->xconfigurerequest
.value_mask
& CWHeight
, h
);
1058 /* check for broken apps moving to their root position
1060 XXX remove this some day...that would be nice. right now all
1061 kde apps do this when they try activate themselves on another
1062 desktop. eg. open amarok window on desktop 1, switch to desktop
1063 2, click amarok tray icon. it will move by its decoration size.
1065 if (x
!= client
->area
.x
&&
1066 x
== (client
->frame
->area
.x
+ client
->frame
->size
.left
-
1067 (gint
)client
->border_width
) &&
1068 y
!= client
->area
.y
&&
1069 y
== (client
->frame
->area
.y
+ client
->frame
->size
.top
-
1070 (gint
)client
->border_width
))
1072 ob_debug_type(OB_DEBUG_APP_BUGS
,
1073 "Application %s is trying to move via "
1074 "ConfigureRequest to it's root window position "
1075 "but it is not using StaticGravity\n",
1083 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1084 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1086 /* ignore enter events caused by these like ob actions do */
1087 event_ignore_queued_enters();
1092 if (client
->ignore_unmaps
) {
1093 client
->ignore_unmaps
--;
1096 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1097 "ignores left %d\n",
1098 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
1099 client
->ignore_unmaps
);
1100 client_unmanage(client
);
1103 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
1104 client_unmanage(client
);
1106 case ReparentNotify
:
1107 /* this is when the client is first taken captive in the frame */
1108 if (e
->xreparent
.parent
== client
->frame
->plate
) break;
1111 This event is quite rare and is usually handled in unmapHandler.
1112 However, if the window is unmapped when the reparent event occurs,
1113 the window manager never sees it because an unmap event is not sent
1114 to an already unmapped window.
1117 /* we don't want the reparent event, put it back on the stack for the
1118 X server to deal with after we unmanage the window */
1119 XPutBackEvent(ob_display
, e
);
1121 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
1122 client_unmanage(client
);
1125 ob_debug("MapRequest for 0x%lx\n", client
->window
);
1126 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
1127 does, we don't want it!
1128 it can happen now when the window is on
1129 another desktop, but we still don't
1131 client_activate(client
, FALSE
, TRUE
);
1134 /* validate cuz we query stuff off the client here */
1135 if (!client_validate(client
)) break;
1137 if (e
->xclient
.format
!= 32) return;
1139 msgtype
= e
->xclient
.message_type
;
1140 if (msgtype
== prop_atoms
.wm_change_state
) {
1141 /* compress changes into a single change */
1142 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1144 /* XXX: it would be nice to compress ALL messages of a
1145 type, not just messages in a row without other
1146 message types between. */
1147 if (ce
.xclient
.message_type
!= msgtype
) {
1148 XPutBackEvent(ob_display
, &ce
);
1151 e
->xclient
= ce
.xclient
;
1153 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1154 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
1155 /* compress changes into a single change */
1156 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1158 /* XXX: it would be nice to compress ALL messages of a
1159 type, not just messages in a row without other
1160 message types between. */
1161 if (ce
.xclient
.message_type
!= msgtype
) {
1162 XPutBackEvent(ob_display
, &ce
);
1165 e
->xclient
= ce
.xclient
;
1167 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1168 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1169 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1171 } else if (msgtype
== prop_atoms
.net_wm_state
) {
1172 /* can't compress these */
1173 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1174 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1175 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1176 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1177 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1179 client_set_state(client
, e
->xclient
.data
.l
[0],
1180 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1182 /* ignore enter events caused by these like ob actions do */
1183 event_ignore_queued_enters();
1184 } else if (msgtype
== prop_atoms
.net_close_window
) {
1185 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1186 client_close(client
);
1187 } else if (msgtype
== prop_atoms
.net_active_window
) {
1188 ob_debug("net_active_window for 0x%lx source=%s\n",
1190 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1191 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1192 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1193 /* XXX make use of data.l[2] !? */
1194 event_curtime
= e
->xclient
.data
.l
[1];
1195 if (event_curtime
== 0)
1196 ob_debug_type(OB_DEBUG_APP_BUGS
,
1197 "_NET_ACTIVE_WINDOW message for window %s is "
1198 "missing a timestamp\n", client
->title
);
1199 client_activate(client
, FALSE
,
1200 (e
->xclient
.data
.l
[0] == 0 ||
1201 e
->xclient
.data
.l
[0] == 2));
1202 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1203 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1204 client
->window
, e
->xclient
.data
.l
[2]);
1205 if ((Atom
)e
->xclient
.data
.l
[2] ==
1206 prop_atoms
.net_wm_moveresize_size_topleft
||
1207 (Atom
)e
->xclient
.data
.l
[2] ==
1208 prop_atoms
.net_wm_moveresize_size_top
||
1209 (Atom
)e
->xclient
.data
.l
[2] ==
1210 prop_atoms
.net_wm_moveresize_size_topright
||
1211 (Atom
)e
->xclient
.data
.l
[2] ==
1212 prop_atoms
.net_wm_moveresize_size_right
||
1213 (Atom
)e
->xclient
.data
.l
[2] ==
1214 prop_atoms
.net_wm_moveresize_size_right
||
1215 (Atom
)e
->xclient
.data
.l
[2] ==
1216 prop_atoms
.net_wm_moveresize_size_bottomright
||
1217 (Atom
)e
->xclient
.data
.l
[2] ==
1218 prop_atoms
.net_wm_moveresize_size_bottom
||
1219 (Atom
)e
->xclient
.data
.l
[2] ==
1220 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1221 (Atom
)e
->xclient
.data
.l
[2] ==
1222 prop_atoms
.net_wm_moveresize_size_left
||
1223 (Atom
)e
->xclient
.data
.l
[2] ==
1224 prop_atoms
.net_wm_moveresize_move
||
1225 (Atom
)e
->xclient
.data
.l
[2] ==
1226 prop_atoms
.net_wm_moveresize_size_keyboard
||
1227 (Atom
)e
->xclient
.data
.l
[2] ==
1228 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1230 moveresize_start(client
, e
->xclient
.data
.l
[0],
1231 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1232 e
->xclient
.data
.l
[2]);
1234 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1235 prop_atoms
.net_wm_moveresize_cancel
)
1236 moveresize_end(TRUE
);
1237 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1238 gint grav
, x
, y
, w
, h
;
1240 if (e
->xclient
.data
.l
[0] & 0xff)
1241 grav
= e
->xclient
.data
.l
[0] & 0xff;
1243 grav
= client
->gravity
;
1245 if (e
->xclient
.data
.l
[0] & 1 << 8)
1246 x
= e
->xclient
.data
.l
[1];
1249 if (e
->xclient
.data
.l
[0] & 1 << 9)
1250 y
= e
->xclient
.data
.l
[2];
1253 if (e
->xclient
.data
.l
[0] & 1 << 10)
1254 w
= e
->xclient
.data
.l
[3];
1256 w
= client
->area
.width
;
1257 if (e
->xclient
.data
.l
[0] & 1 << 11)
1258 h
= e
->xclient
.data
.l
[4];
1260 h
= client
->area
.height
;
1262 ob_debug("MOVERESIZE x %d %d y %d %d\n",
1263 e
->xclient
.data
.l
[0] & 1 << 8, x
,
1264 e
->xclient
.data
.l
[0] & 1 << 9, y
);
1265 client_convert_gravity(client
, grav
, &x
, &y
, w
, h
);
1266 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1268 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1270 /* ignore enter events caused by these like ob actions do */
1271 event_ignore_queued_enters();
1272 } else if (msgtype
== prop_atoms
.net_restack_window
) {
1273 if (e
->xclient
.data
.l
[0] != 2) {
1274 ob_debug_type(OB_DEBUG_APP_BUGS
,
1275 "_NET_RESTACK_WINDOW sent for window %s with "
1276 "invalid source indication %ld\n",
1277 client
->title
, e
->xclient
.data
.l
[0]);
1279 ObClient
*sibling
= NULL
;
1280 if (e
->xclient
.data
.l
[1]) {
1281 ObWindow
*win
= g_hash_table_lookup(window_map
,
1282 &e
->xclient
.data
.l
[1]);
1283 if (WINDOW_IS_CLIENT(win
) &&
1284 WINDOW_AS_CLIENT(win
) != client
)
1286 sibling
= WINDOW_AS_CLIENT(win
);
1288 if (sibling
== NULL
)
1289 ob_debug_type(OB_DEBUG_APP_BUGS
,
1290 "_NET_RESTACK_WINDOW sent for window %s "
1291 "with invalid sibling 0x%x\n",
1292 client
->title
, e
->xclient
.data
.l
[1]);
1294 if (e
->xclient
.data
.l
[2] == Below
||
1295 e
->xclient
.data
.l
[2] == BottomIf
||
1296 e
->xclient
.data
.l
[2] == Above
||
1297 e
->xclient
.data
.l
[2] == TopIf
||
1298 e
->xclient
.data
.l
[2] == Opposite
)
1300 /* just raise, don't activate */
1301 stacking_restack_request(client
, sibling
,
1302 e
->xclient
.data
.l
[2], FALSE
);
1303 /* send a synthetic ConfigureNotify, cuz this is supposed
1304 to be like a ConfigureRequest. */
1305 client_reconfigure(client
);
1307 ob_debug_type(OB_DEBUG_APP_BUGS
,
1308 "_NET_RESTACK_WINDOW sent for window %s "
1309 "with invalid detail %d\n",
1310 client
->title
, e
->xclient
.data
.l
[2]);
1314 case PropertyNotify
:
1315 /* validate cuz we query stuff off the client here */
1316 if (!client_validate(client
)) break;
1318 /* compress changes to a single property into a single change */
1319 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1323 /* XXX: it would be nice to compress ALL changes to a property,
1324 not just changes in a row without other props between. */
1326 a
= ce
.xproperty
.atom
;
1327 b
= e
->xproperty
.atom
;
1331 if ((a
== prop_atoms
.net_wm_name
||
1332 a
== prop_atoms
.wm_name
||
1333 a
== prop_atoms
.net_wm_icon_name
||
1334 a
== prop_atoms
.wm_icon_name
)
1336 (b
== prop_atoms
.net_wm_name
||
1337 b
== prop_atoms
.wm_name
||
1338 b
== prop_atoms
.net_wm_icon_name
||
1339 b
== prop_atoms
.wm_icon_name
)) {
1342 if (a
== prop_atoms
.net_wm_icon
&&
1343 b
== prop_atoms
.net_wm_icon
)
1346 XPutBackEvent(ob_display
, &ce
);
1350 msgtype
= e
->xproperty
.atom
;
1351 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1352 client_update_normal_hints(client
);
1353 /* normal hints can make a window non-resizable */
1354 client_setup_decor_and_functions(client
);
1355 } else if (msgtype
== XA_WM_HINTS
) {
1356 client_update_wmhints(client
);
1357 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1358 client_update_transient_for(client
);
1359 client_get_type_and_transientness(client
);
1360 /* type may have changed, so update the layer */
1361 client_calc_layer(client
);
1362 client_setup_decor_and_functions(client
);
1363 } else if (msgtype
== prop_atoms
.net_wm_name
||
1364 msgtype
== prop_atoms
.wm_name
||
1365 msgtype
== prop_atoms
.net_wm_icon_name
||
1366 msgtype
== prop_atoms
.wm_icon_name
) {
1367 client_update_title(client
);
1368 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1369 client_update_protocols(client
);
1370 client_setup_decor_and_functions(client
);
1372 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1373 client_update_strut(client
);
1375 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1376 client_update_icons(client
);
1378 else if (msgtype
== prop_atoms
.net_wm_icon_geometry
) {
1379 client_update_icon_geometry(client
);
1381 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1382 client_update_user_time(client
);
1384 else if (msgtype
== prop_atoms
.net_wm_user_time_window
) {
1385 client_update_user_time_window(client
);
1388 else if (msgtype
== prop_atoms
.net_wm_sync_request_counter
) {
1389 client_update_sync_request_counter(client
);
1392 case ColormapNotify
:
1393 client_update_colormap(client
, e
->xcolormap
.colormap
);
1398 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1399 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1400 frame_adjust_shape(client
->frame
);
1406 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1410 if (e
->xbutton
.button
== 1)
1411 stacking_raise(DOCK_AS_WINDOW(s
));
1412 else if (e
->xbutton
.button
== 2)
1413 stacking_lower(DOCK_AS_WINDOW(s
));
1424 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1428 dock_app_drag(app
, &e
->xmotion
);
1431 if (app
->ignore_unmaps
) {
1432 app
->ignore_unmaps
--;
1435 dock_remove(app
, TRUE
);
1438 dock_remove(app
, FALSE
);
1440 case ReparentNotify
:
1441 dock_remove(app
, FALSE
);
1443 case ConfigureNotify
:
1444 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1449 static ObMenuFrame
* find_active_menu()
1452 ObMenuFrame
*ret
= NULL
;
1454 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1463 static ObMenuFrame
* find_active_or_last_menu()
1465 ObMenuFrame
*ret
= NULL
;
1467 ret
= find_active_menu();
1468 if (!ret
&& menu_frame_visible
)
1469 ret
= menu_frame_visible
->data
;
1473 static gboolean
event_handle_menu_keyboard(XEvent
*ev
)
1475 guint keycode
, state
;
1478 gboolean ret
= TRUE
;
1480 keycode
= ev
->xkey
.keycode
;
1481 state
= ev
->xkey
.state
;
1482 unikey
= translate_unichar(keycode
);
1484 frame
= find_active_or_last_menu();
1488 else if (keycode
== ob_keycode(OB_KEY_ESCAPE
) && state
== 0) {
1489 /* Escape closes the active menu */
1490 menu_frame_hide(frame
);
1493 else if (keycode
== ob_keycode(OB_KEY_RETURN
) && (state
== 0 ||
1494 state
== ControlMask
))
1496 /* Enter runs the active item or goes into the submenu.
1497 Control-Enter runs it without closing the menu. */
1499 menu_frame_select_next(frame
->child
);
1501 menu_entry_frame_execute(frame
->selected
, state
, ev
->xkey
.time
);
1504 else if (keycode
== ob_keycode(OB_KEY_LEFT
) && ev
->xkey
.state
== 0) {
1505 /* Left goes to the parent menu */
1506 menu_frame_select(frame
, NULL
, TRUE
);
1509 else if (keycode
== ob_keycode(OB_KEY_RIGHT
) && ev
->xkey
.state
== 0) {
1510 /* Right goes to the selected submenu */
1511 if (frame
->child
) menu_frame_select_next(frame
->child
);
1514 else if (keycode
== ob_keycode(OB_KEY_UP
) && state
== 0) {
1515 menu_frame_select_previous(frame
);
1518 else if (keycode
== ob_keycode(OB_KEY_DOWN
) && state
== 0) {
1519 menu_frame_select_next(frame
);
1522 /* keyboard accelerator shortcuts. */
1523 else if (ev
->xkey
.state
== 0 &&
1524 /* was it a valid key? */
1526 /* don't bother if the menu is empty. */
1531 ObMenuEntryFrame
*found
= NULL
;
1532 guint num_found
= 0;
1534 /* start after the selected one */
1535 start
= frame
->entries
;
1536 if (frame
->selected
) {
1537 for (it
= start
; frame
->selected
!= it
->data
; it
= g_list_next(it
))
1538 g_assert(it
!= NULL
); /* nothing was selected? */
1539 /* next with wraparound */
1540 start
= g_list_next(it
);
1541 if (start
== NULL
) start
= frame
->entries
;
1546 ObMenuEntryFrame
*e
= it
->data
;
1547 gunichar entrykey
= 0;
1549 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1550 entrykey
= e
->entry
->data
.normal
.shortcut
;
1551 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1552 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1554 if (unikey
== entrykey
) {
1555 if (found
== NULL
) found
= e
;
1559 /* next with wraparound */
1560 it
= g_list_next(it
);
1561 if (it
== NULL
) it
= frame
->entries
;
1562 } while (it
!= start
);
1565 if (found
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
1568 menu_frame_select(frame
, found
, TRUE
);
1569 usleep(50000); /* highlight the item for a short bit so the
1570 user can see what happened */
1571 menu_entry_frame_execute(found
, state
, ev
->xkey
.time
);
1573 menu_frame_select(frame
, found
, TRUE
);
1575 menu_frame_select_next(frame
->child
);
1586 static gboolean
event_handle_menu(XEvent
*ev
)
1589 ObMenuEntryFrame
*e
;
1590 gboolean ret
= TRUE
;
1594 if ((ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5)
1597 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1598 ev
->xbutton
.y_root
)))
1599 menu_entry_frame_execute(e
, ev
->xbutton
.state
,
1602 menu_frame_hide_all();
1606 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1607 if (e
->ignore_enters
)
1610 menu_frame_select(e
->frame
, e
, FALSE
);
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 void event_ignore_queued_enters()
1722 GSList
*saved
= NULL
, *it
;
1726 XSync(ob_display
, FALSE
);
1728 /* count the events */
1730 e
= g_new(XEvent
, 1);
1731 if (XCheckTypedEvent(ob_display
, EnterNotify
, e
)) {
1734 win
= g_hash_table_lookup(window_map
, &e
->xany
.window
);
1735 /* check to make sure we're not ignoring the same event multiple
1737 if (win
&& WINDOW_IS_CLIENT(win
) && i
>= ignore_enter_focus
)
1738 ++ignore_enter_focus
;
1740 saved
= g_slist_append(saved
, e
);
1747 /* put the events back */
1748 for (it
= saved
; it
; it
= g_slist_next(it
)) {
1749 XPutBackEvent(ob_display
, it
->data
);
1752 g_slist_free(saved
);
1755 gboolean
event_time_after(Time t1
, Time t2
)
1757 g_assert(t1
!= CurrentTime
);
1758 g_assert(t2
!= CurrentTime
);
1761 Timestamp values wrap around (after about 49.7 days). The server, given
1762 its current time is represented by timestamp T, always interprets
1763 timestamps from clients by treating half of the timestamp space as being
1764 later in time than T.
1765 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
1768 /* TIME_HALF is half of the number space of a Time type variable */
1769 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
1771 if (t2
>= TIME_HALF
)
1772 /* t2 is in the second half so t1 might wrap around and be smaller than
1774 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
1776 /* t2 is in the first half so t1 has to come after it */
1777 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);