1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 event.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
32 #include "menuframe.h"
38 #include "framerender.h"
40 #include "moveresize.h"
43 #include "extensions.h"
44 #include "translate.h"
47 #include <X11/Xatom.h>
50 #ifdef HAVE_SYS_SELECT_H
51 # include <sys/select.h>
57 # include <unistd.h> /* for usleep() */
60 # include <X11/XKBlib.h>
64 #include <X11/ICE/ICElib.h>
78 static void event_process(const XEvent
*e
, gpointer data
);
79 static void event_handle_root(XEvent
*e
);
80 static gboolean
event_handle_menu_keyboard(XEvent
*e
);
81 static gboolean
event_handle_menu(XEvent
*e
);
82 static void event_handle_dock(ObDock
*s
, XEvent
*e
);
83 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
);
84 static void event_handle_client(ObClient
*c
, XEvent
*e
);
85 static void event_handle_user_time_window_clients(GSList
*l
, XEvent
*e
);
86 static void event_handle_user_input(ObClient
*client
, XEvent
*e
);
88 static void focus_delay_dest(gpointer data
);
89 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
);
90 static gboolean
focus_delay_func(gpointer data
);
91 static void focus_delay_client_dest(ObClient
*client
, gpointer data
);
93 static gboolean
menu_hide_delay_func(gpointer data
);
95 /* The time for the current event being processed */
96 Time event_curtime
= CurrentTime
;
98 static guint ignore_enter_focus
= 0;
99 static gboolean menu_can_hide
;
100 static gboolean focus_left_screen
= FALSE
;
103 static void ice_handler(gint fd
, gpointer conn
)
106 IceProcessMessages(conn
, NULL
, &b
);
109 static void ice_watch(IceConn conn
, IcePointer data
, Bool opening
,
110 IcePointer
*watch_data
)
115 fd
= IceConnectionNumber(conn
);
116 ob_main_loop_fd_add(ob_main_loop
, fd
, ice_handler
, conn
, NULL
);
118 ob_main_loop_fd_remove(ob_main_loop
, fd
);
124 void event_startup(gboolean reconfig
)
126 if (reconfig
) return;
128 ob_main_loop_x_add(ob_main_loop
, event_process
, NULL
, NULL
);
131 IceAddConnectionWatch(ice_watch
, NULL
);
134 client_add_destructor(focus_delay_client_dest
, NULL
);
137 void event_shutdown(gboolean reconfig
)
139 if (reconfig
) return;
142 IceRemoveConnectionWatch(ice_watch
, NULL
);
145 client_remove_destructor(focus_delay_client_dest
);
148 static Window
event_get_window(XEvent
*e
)
155 window
= RootWindow(ob_display
, ob_screen
);
158 window
= e
->xmap
.window
;
161 window
= e
->xunmap
.window
;
164 window
= e
->xdestroywindow
.window
;
166 case ConfigureRequest
:
167 window
= e
->xconfigurerequest
.window
;
169 case ConfigureNotify
:
170 window
= e
->xconfigure
.window
;
174 if (extensions_xkb
&& e
->type
== extensions_xkb_event_basep
) {
175 switch (((XkbAnyEvent
*)e
)->xkb_type
) {
177 window
= ((XkbBellNotifyEvent
*)e
)->window
;
184 if (extensions_sync
&&
185 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
190 window
= e
->xany
.window
;
195 static void event_set_curtime(XEvent
*e
)
197 Time t
= CurrentTime
;
199 /* grab the lasttime and hack up the state */
215 t
= e
->xproperty
.time
;
219 t
= e
->xcrossing
.time
;
223 if (extensions_sync
&&
224 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
226 t
= ((XSyncAlarmNotifyEvent
*)e
)->time
;
229 /* if more event types are anticipated, get their timestamp
237 static void event_hack_mods(XEvent
*e
)
240 XkbStateRec xkb_state
;
246 e
->xbutton
.state
= modkeys_only_modifier_masks(e
->xbutton
.state
);
249 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
252 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
254 if (XkbGetState(ob_display
, XkbUseCoreKbd
, &xkb_state
) == Success
) {
255 e
->xkey
.state
= xkb_state
.compat_state
;
259 /* remove from the state the mask of the modifier key being released,
260 if it is a modifier key being released that is */
261 e
->xkey
.state
&= ~modkeys_keycode_to_mask(e
->xkey
.keycode
);
264 e
->xmotion
.state
= modkeys_only_modifier_masks(e
->xmotion
.state
);
265 /* compress events */
268 while (XCheckTypedWindowEvent(ob_display
, e
->xmotion
.window
,
270 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
271 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
278 static gboolean
wanted_focusevent(XEvent
*e
, gboolean in_client_only
)
280 gint mode
= e
->xfocus
.mode
;
281 gint detail
= e
->xfocus
.detail
;
282 Window win
= e
->xany
.window
;
284 if (e
->type
== FocusIn
) {
285 /* These are ones we never want.. */
287 /* This means focus was given by a keyboard/mouse grab. */
288 if (mode
== NotifyGrab
)
290 /* This means focus was given back from a keyboard/mouse grab. */
291 if (mode
== NotifyUngrab
)
294 /* These are the ones we want.. */
296 if (win
== RootWindow(ob_display
, ob_screen
) && !in_client_only
) {
297 /* This means focus reverted off of a client */
298 if (detail
== NotifyPointerRoot
|| detail
== NotifyDetailNone
||
299 detail
== NotifyInferior
)
305 /* This means focus moved from the root window to a client */
306 if (detail
== NotifyVirtual
)
308 /* This means focus moved from one client to another */
309 if (detail
== NotifyNonlinearVirtual
)
311 /* This means focus moved to the frame window */
312 if (detail
== NotifyInferior
&& !in_client_only
)
318 g_assert(e
->type
== FocusOut
);
320 /* These are ones we never want.. */
322 /* This means focus was taken by a keyboard/mouse grab. */
323 if (mode
== NotifyGrab
)
326 /* Focus left the root window revertedto state */
327 if (win
== RootWindow(ob_display
, ob_screen
))
330 /* These are the ones we want.. */
332 /* This means focus moved from a client to the root window */
333 if (detail
== NotifyVirtual
)
335 /* This means focus moved from one client to another */
336 if (detail
== NotifyNonlinearVirtual
)
338 /* This means focus had moved to our frame window and now moved off */
339 if (detail
== NotifyNonlinear
)
347 static Bool
look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
349 return e
->type
== FocusIn
&& wanted_focusevent(e
, FALSE
);
352 static Bool
look_for_focusin_client(Display
*d
, XEvent
*e
, XPointer arg
)
354 return e
->type
== FocusIn
&& wanted_focusevent(e
, TRUE
);
357 static void print_focusevent(XEvent
*e
)
359 gint mode
= e
->xfocus
.mode
;
360 gint detail
= e
->xfocus
.detail
;
361 Window win
= e
->xany
.window
;
362 const gchar
*modestr
, *detailstr
;
365 case NotifyNormal
: modestr
="NotifyNormal"; break;
366 case NotifyGrab
: modestr
="NotifyGrab"; break;
367 case NotifyUngrab
: modestr
="NotifyUngrab"; break;
368 case NotifyWhileGrabbed
: modestr
="NotifyWhileGrabbed"; break;
371 case NotifyAncestor
: detailstr
="NotifyAncestor"; break;
372 case NotifyVirtual
: detailstr
="NotifyVirtual"; break;
373 case NotifyInferior
: detailstr
="NotifyInferior"; break;
374 case NotifyNonlinear
: detailstr
="NotifyNonlinear"; break;
375 case NotifyNonlinearVirtual
: detailstr
="NotifyNonlinearVirtual"; break;
376 case NotifyPointer
: detailstr
="NotifyPointer"; break;
377 case NotifyPointerRoot
: detailstr
="NotifyPointerRoot"; break;
378 case NotifyDetailNone
: detailstr
="NotifyDetailNone"; break;
383 ob_debug_type(OB_DEBUG_FOCUS
, "Focus%s 0x%x mode=%s detail=%s\n",
384 (e
->xfocus
.type
== FocusIn
? "In" : "Out"),
390 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
395 if (!wanted_focusevent(e
, FALSE
))
400 if (!wanted_focusevent(e
, FALSE
))
407 static void event_process(const XEvent
*ec
, gpointer data
)
410 ObClient
*client
= NULL
;
412 ObDockApp
*dockapp
= NULL
;
413 ObWindow
*obwin
= NULL
;
414 GSList
*timewinclients
= NULL
;
416 ObEventData
*ed
= data
;
418 /* make a copy we can mangle */
422 window
= event_get_window(e
);
423 if (e
->type
!= PropertyNotify
||
424 !(timewinclients
= propwin_get_clients(window
,
425 OB_PROPWIN_USER_TIME
)))
426 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
427 switch (obwin
->type
) {
429 dock
= WINDOW_AS_DOCK(obwin
);
432 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
435 client
= WINDOW_AS_CLIENT(obwin
);
438 case Window_Internal
:
439 /* not to be used for events */
440 g_assert_not_reached();
445 event_set_curtime(e
);
447 if (event_ignore(e
, client
)) {
454 /* deal with it in the kernel */
456 if (menu_frame_visible
&&
457 (e
->type
== EnterNotify
|| e
->type
== LeaveNotify
))
459 /* crossing events for menu */
460 event_handle_menu(e
);
461 } else if (e
->type
== FocusIn
) {
462 if (e
->xfocus
.detail
== NotifyPointerRoot
||
463 e
->xfocus
.detail
== NotifyDetailNone
||
464 e
->xfocus
.detail
== NotifyInferior
)
467 ob_debug_type(OB_DEBUG_FOCUS
,
468 "Focus went to pointer root/none or to our frame "
471 /* If another FocusIn is in the queue then don't fallback yet. This
472 fixes the fun case of:
473 window map -> send focusin
474 window unmap -> get focusout
475 window map -> send focusin
476 get first focus out -> fall back to something (new window
477 hasn't received focus yet, so something else) -> send focusin
478 which means the "something else" is the last thing to get a
479 focusin sent to it, so the new window doesn't end up with focus.
481 But if the other focus in is something like PointerRoot then we
482 still want to fall back.
484 if (XCheckIfEvent(ob_display
, &ce
, look_for_focusin_client
, NULL
)){
485 XPutBackEvent(ob_display
, &ce
);
486 ob_debug_type(OB_DEBUG_FOCUS
,
487 " but another FocusIn is coming\n");
489 /* Focus has been reverted to the root window, nothing, or to
492 FocusOut events come after UnmapNotify, so we don't need to
493 worry about focusing an invalid window
496 /* In this case we know focus is in our screen */
497 if (e
->xfocus
.detail
== NotifyInferior
)
498 focus_left_screen
= FALSE
;
500 if (!focus_left_screen
)
501 focus_fallback(TRUE
);
503 } else if (client
&& client
!= focus_client
) {
504 focus_left_screen
= FALSE
;
505 frame_adjust_focus(client
->frame
, TRUE
);
506 focus_set_client(client
);
507 client_calc_layer(client
);
508 client_bring_helper_windows(client
);
510 } else if (e
->type
== FocusOut
) {
511 gboolean nomove
= FALSE
;
514 /* Look for the followup FocusIn */
515 if (!XCheckIfEvent(ob_display
, &ce
, look_for_focusin
, NULL
)) {
516 /* There is no FocusIn, this means focus went to a window that
517 is not being managed, or a window on another screen. */
521 xerror_set_ignore(TRUE
);
522 if (XGetInputFocus(ob_display
, &win
, &i
) != 0 &&
523 XGetGeometry(ob_display
, win
, &root
, &i
,&i
,&u
,&u
,&u
,&u
) != 0 &&
524 root
!= RootWindow(ob_display
, ob_screen
))
526 ob_debug_type(OB_DEBUG_FOCUS
,
527 "Focus went to another screen !\n");
528 focus_left_screen
= TRUE
;
531 ob_debug_type(OB_DEBUG_FOCUS
,
532 "Focus went to a black hole !\n");
533 xerror_set_ignore(FALSE
);
534 /* nothing is focused */
535 focus_set_client(NULL
);
536 } else if (ce
.xany
.window
== e
->xany
.window
) {
537 ob_debug_type(OB_DEBUG_FOCUS
, "Focus didn't go anywhere\n");
538 /* If focus didn't actually move anywhere, there is nothing to do*/
541 /* Focus did move, so process the FocusIn event */
542 ObEventData ed
= { .ignored
= FALSE
};
543 event_process(&ce
, &ed
);
545 /* The FocusIn was ignored, this means it was on a window
546 that isn't a client. */
547 ob_debug_type(OB_DEBUG_FOCUS
,
548 "Focus went to an unmanaged window 0x%x !\n",
550 focus_fallback(TRUE
);
554 if (client
&& !nomove
) {
555 frame_adjust_focus(client
->frame
, FALSE
);
556 /* focus_set_client has already been called for sure */
557 client_calc_layer(client
);
559 } else if (timewinclients
)
560 event_handle_user_time_window_clients(timewinclients
, e
);
562 event_handle_client(client
, e
);
564 event_handle_dockapp(dockapp
, e
);
566 event_handle_dock(dock
, e
);
567 else if (window
== RootWindow(ob_display
, ob_screen
))
568 event_handle_root(e
);
569 else if (e
->type
== MapRequest
)
570 client_manage(window
);
571 else if (e
->type
== ClientMessage
) {
572 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
573 windows that are not managed yet. */
574 if (e
->xclient
.message_type
== prop_atoms
.net_request_frame_extents
) {
575 /* Pretend to manage the client, getting information used to
576 determine its decorations */
577 ObClient
*c
= client_fake_manage(e
->xclient
.window
);
580 /* set the frame extents on the window */
581 vals
[0] = c
->frame
->size
.left
;
582 vals
[1] = c
->frame
->size
.right
;
583 vals
[2] = c
->frame
->size
.top
;
584 vals
[3] = c
->frame
->size
.bottom
;
585 PROP_SETA32(e
->xclient
.window
, net_frame_extents
,
588 /* Free the pretend client */
589 client_fake_unmanage(c
);
592 else if (e
->type
== ConfigureRequest
) {
593 /* unhandled configure requests must be used to configure the
597 xwc
.x
= e
->xconfigurerequest
.x
;
598 xwc
.y
= e
->xconfigurerequest
.y
;
599 xwc
.width
= e
->xconfigurerequest
.width
;
600 xwc
.height
= e
->xconfigurerequest
.height
;
601 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
602 xwc
.sibling
= e
->xconfigurerequest
.above
;
603 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
605 /* we are not to be held responsible if someone sends us an
607 xerror_set_ignore(TRUE
);
608 XConfigureWindow(ob_display
, window
,
609 e
->xconfigurerequest
.value_mask
, &xwc
);
610 xerror_set_ignore(FALSE
);
613 else if (extensions_sync
&&
614 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
616 XSyncAlarmNotifyEvent
*se
= (XSyncAlarmNotifyEvent
*)e
;
617 if (se
->alarm
== moveresize_alarm
&& moveresize_in_progress
)
622 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
623 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
624 e
->type
== KeyRelease
)
626 event_handle_user_input(client
, e
);
629 /* if something happens and it's not from an XEvent, then we don't know
631 event_curtime
= CurrentTime
;
634 static void event_handle_root(XEvent
*e
)
640 ob_debug("Another WM has requested to replace us. Exiting.\n");
645 if (e
->xclient
.format
!= 32) break;
647 msgtype
= e
->xclient
.message_type
;
648 if (msgtype
== prop_atoms
.net_current_desktop
) {
649 guint d
= e
->xclient
.data
.l
[0];
650 if (d
< screen_num_desktops
) {
651 event_curtime
= e
->xclient
.data
.l
[1];
652 if (event_curtime
== 0)
653 ob_debug_type(OB_DEBUG_APP_BUGS
,
654 "_NET_CURRENT_DESKTOP message is missing "
656 screen_set_desktop(d
, TRUE
);
658 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
659 guint d
= e
->xclient
.data
.l
[0];
661 screen_set_num_desktops(d
);
662 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
663 screen_show_desktop(e
->xclient
.data
.l
[0] != 0, TRUE
);
664 } else if (msgtype
== prop_atoms
.openbox_control
) {
665 if (e
->xclient
.data
.l
[0] == 1)
667 else if (e
->xclient
.data
.l
[0] == 2)
672 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
)
673 screen_update_desktop_names();
674 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
675 screen_update_layout();
677 case ConfigureNotify
:
679 XRRUpdateConfiguration(e
);
688 void event_enter_client(ObClient
*client
)
690 g_assert(config_focus_follow
);
692 if (client_enter_focusable(client
) && client_can_focus(client
)) {
693 if (config_focus_delay
) {
694 ObFocusDelayData
*data
;
696 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
698 data
= g_new(ObFocusDelayData
, 1);
699 data
->client
= client
;
700 data
->time
= event_curtime
;
702 ob_main_loop_timeout_add(ob_main_loop
,
705 data
, focus_delay_cmp
, focus_delay_dest
);
707 ObFocusDelayData data
;
708 data
.client
= client
;
709 data
.time
= event_curtime
;
710 focus_delay_func(&data
);
715 static void event_handle_user_time_window_clients(GSList
*l
, XEvent
*e
)
717 g_assert(e
->type
== PropertyNotify
);
718 if (e
->xproperty
.atom
== prop_atoms
.net_wm_user_time
) {
719 for (; l
; l
= g_slist_next(l
))
720 client_update_user_time(l
->data
);
724 static void event_handle_client(ObClient
*client
, XEvent
*e
)
729 static gint px
= -1, py
= -1;
734 /* save where the press occured for the first button pressed */
736 pb
= e
->xbutton
.button
;
741 /* Wheel buttons don't draw because they are an instant click, so it
742 is a waste of resources to go drawing it.
743 if the user is doing an intereactive thing, or has a menu open then
744 the mouse is grabbed (possibly) and if we get these events we don't
745 want to deal with them
747 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5) &&
748 !keyboard_interactively_grabbed() &&
751 /* use where the press occured */
752 con
= frame_context(client
, e
->xbutton
.window
, px
, py
);
753 con
= mouse_button_frame_context(con
, e
->xbutton
.button
);
755 if (e
->type
== ButtonRelease
&& e
->xbutton
.button
== pb
)
756 pb
= 0, px
= py
= -1;
759 case OB_FRAME_CONTEXT_MAXIMIZE
:
760 client
->frame
->max_press
= (e
->type
== ButtonPress
);
761 framerender_frame(client
->frame
);
763 case OB_FRAME_CONTEXT_CLOSE
:
764 client
->frame
->close_press
= (e
->type
== ButtonPress
);
765 framerender_frame(client
->frame
);
767 case OB_FRAME_CONTEXT_ICONIFY
:
768 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
769 framerender_frame(client
->frame
);
771 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
772 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
773 framerender_frame(client
->frame
);
775 case OB_FRAME_CONTEXT_SHADE
:
776 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
777 framerender_frame(client
->frame
);
780 /* nothing changes with clicks for any other contexts */
786 con
= frame_context(client
, e
->xmotion
.window
,
787 e
->xmotion
.x
, e
->xmotion
.y
);
789 case OB_FRAME_CONTEXT_TITLEBAR
:
790 /* we've left the button area inside the titlebar */
791 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
792 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
793 client
->frame
->close_hover
)
795 client
->frame
->max_hover
= FALSE
;
796 client
->frame
->desk_hover
= FALSE
;
797 client
->frame
->shade_hover
= FALSE
;
798 client
->frame
->iconify_hover
= FALSE
;
799 client
->frame
->close_hover
= FALSE
;
800 frame_adjust_state(client
->frame
);
803 case OB_FRAME_CONTEXT_MAXIMIZE
:
804 if (!client
->frame
->max_hover
) {
805 client
->frame
->max_hover
= TRUE
;
806 frame_adjust_state(client
->frame
);
809 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
810 if (!client
->frame
->desk_hover
) {
811 client
->frame
->desk_hover
= TRUE
;
812 frame_adjust_state(client
->frame
);
815 case OB_FRAME_CONTEXT_SHADE
:
816 if (!client
->frame
->shade_hover
) {
817 client
->frame
->shade_hover
= TRUE
;
818 frame_adjust_state(client
->frame
);
821 case OB_FRAME_CONTEXT_ICONIFY
:
822 if (!client
->frame
->iconify_hover
) {
823 client
->frame
->iconify_hover
= TRUE
;
824 frame_adjust_state(client
->frame
);
827 case OB_FRAME_CONTEXT_CLOSE
:
828 if (!client
->frame
->close_hover
) {
829 client
->frame
->close_hover
= TRUE
;
830 frame_adjust_state(client
->frame
);
838 con
= frame_context(client
, e
->xcrossing
.window
,
839 e
->xcrossing
.x
, e
->xcrossing
.y
);
841 case OB_FRAME_CONTEXT_MAXIMIZE
:
842 client
->frame
->max_hover
= FALSE
;
843 frame_adjust_state(client
->frame
);
845 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
846 client
->frame
->desk_hover
= FALSE
;
847 frame_adjust_state(client
->frame
);
849 case OB_FRAME_CONTEXT_SHADE
:
850 client
->frame
->shade_hover
= FALSE
;
851 frame_adjust_state(client
->frame
);
853 case OB_FRAME_CONTEXT_ICONIFY
:
854 client
->frame
->iconify_hover
= FALSE
;
855 frame_adjust_state(client
->frame
);
857 case OB_FRAME_CONTEXT_CLOSE
:
858 client
->frame
->close_hover
= FALSE
;
859 frame_adjust_state(client
->frame
);
861 case OB_FRAME_CONTEXT_FRAME
:
862 /* When the mouse leaves an animating window, don't use the
863 corresponding enter events. Pretend like the animating window
864 doesn't even exist..! */
865 if (frame_iconify_animating(client
->frame
))
866 event_ignore_queued_enters();
868 ob_debug_type(OB_DEBUG_FOCUS
,
869 "%sNotify mode %d detail %d on %lx\n",
870 (e
->type
== EnterNotify
? "Enter" : "Leave"),
872 e
->xcrossing
.detail
, (client
?client
->window
:0));
873 if (keyboard_interactively_grabbed())
875 if (config_focus_follow
&& config_focus_delay
&&
876 /* leave inferior events can happen when the mouse goes onto
877 the window's border and then into the window before the
879 e
->xcrossing
.detail
!= NotifyInferior
)
881 ob_main_loop_timeout_remove_data(ob_main_loop
,
892 gboolean nofocus
= FALSE
;
894 if (ignore_enter_focus
) {
895 ignore_enter_focus
--;
899 con
= frame_context(client
, e
->xcrossing
.window
,
900 e
->xcrossing
.x
, e
->xcrossing
.y
);
902 case OB_FRAME_CONTEXT_MAXIMIZE
:
903 client
->frame
->max_hover
= TRUE
;
904 frame_adjust_state(client
->frame
);
906 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
907 client
->frame
->desk_hover
= TRUE
;
908 frame_adjust_state(client
->frame
);
910 case OB_FRAME_CONTEXT_SHADE
:
911 client
->frame
->shade_hover
= TRUE
;
912 frame_adjust_state(client
->frame
);
914 case OB_FRAME_CONTEXT_ICONIFY
:
915 client
->frame
->iconify_hover
= TRUE
;
916 frame_adjust_state(client
->frame
);
918 case OB_FRAME_CONTEXT_CLOSE
:
919 client
->frame
->close_hover
= TRUE
;
920 frame_adjust_state(client
->frame
);
922 case OB_FRAME_CONTEXT_FRAME
:
923 if (keyboard_interactively_grabbed())
925 if (e
->xcrossing
.mode
== NotifyGrab
||
926 e
->xcrossing
.mode
== NotifyUngrab
||
927 /*ignore enters when we're already in the window */
928 e
->xcrossing
.detail
== NotifyInferior
)
930 ob_debug_type(OB_DEBUG_FOCUS
,
931 "%sNotify mode %d detail %d on %lx IGNORED\n",
932 (e
->type
== EnterNotify
? "Enter" : "Leave"),
934 e
->xcrossing
.detail
, client
?client
->window
:0);
936 ob_debug_type(OB_DEBUG_FOCUS
,
937 "%sNotify mode %d detail %d on %lx, "
938 "focusing window: %d\n",
939 (e
->type
== EnterNotify
? "Enter" : "Leave"),
941 e
->xcrossing
.detail
, (client
?client
->window
:0),
943 if (!nofocus
&& config_focus_follow
)
944 event_enter_client(client
);
952 case ConfigureRequest
:
953 /* dont compress these unless you're going to watch for property
954 notifies in between (these can change what the configure would
956 also you can't compress stacking events
959 ob_debug("ConfigureRequest desktop %d wmstate %d vis %d\n",
960 screen_desktop
, client
->wmstate
, client
->frame
->visible
);
962 /* don't allow clients to move shaded windows (fvwm does this) */
963 if (client
->shaded
) {
964 e
->xconfigurerequest
.value_mask
&= ~CWX
;
965 e
->xconfigurerequest
.value_mask
&= ~CWY
;
968 /* resize, then move, as specified in the EWMH section 7.7 */
969 if (e
->xconfigurerequest
.value_mask
& (CWWidth
| CWHeight
|
974 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
975 client
->border_width
= e
->xconfigurerequest
.border_width
;
977 x
= (e
->xconfigurerequest
.value_mask
& CWX
) ?
978 e
->xconfigurerequest
.x
: client
->area
.x
;
979 y
= (e
->xconfigurerequest
.value_mask
& CWY
) ?
980 e
->xconfigurerequest
.y
: client
->area
.y
;
981 w
= (e
->xconfigurerequest
.value_mask
& CWWidth
) ?
982 e
->xconfigurerequest
.width
: client
->area
.width
;
983 h
= (e
->xconfigurerequest
.value_mask
& CWHeight
) ?
984 e
->xconfigurerequest
.height
: client
->area
.height
;
986 ob_debug("ConfigureRequest x %d %d y %d %d\n",
987 e
->xconfigurerequest
.value_mask
& CWX
, x
,
988 e
->xconfigurerequest
.value_mask
& CWY
, y
);
990 /* check for broken apps moving to their root position
992 XXX remove this some day...that would be nice. right now all
993 kde apps do this when they try activate themselves on another
994 desktop. eg. open amarok window on desktop 1, switch to desktop
995 2, click amarok tray icon. it will move by its decoration size.
997 if (x
!= client
->area
.x
&&
998 x
== (client
->frame
->area
.x
+ client
->frame
->size
.left
-
999 (gint
)client
->border_width
) &&
1000 y
!= client
->area
.y
&&
1001 y
== (client
->frame
->area
.y
+ client
->frame
->size
.top
-
1002 (gint
)client
->border_width
))
1004 ob_debug_type(OB_DEBUG_APP_BUGS
,
1005 "Application %s is trying to move via "
1006 "ConfigureRequest to it's root window position "
1007 "but it is not using StaticGravity\n",
1014 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1015 client_configure_full(client
, x
, y
, w
, h
, FALSE
, TRUE
, TRUE
);
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
);
1036 if (client
->ignore_unmaps
) {
1037 client
->ignore_unmaps
--;
1040 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1041 "ignores left %d\n",
1042 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
1043 client
->ignore_unmaps
);
1044 client_unmanage(client
);
1047 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
1048 client_unmanage(client
);
1050 case ReparentNotify
:
1051 /* this is when the client is first taken captive in the frame */
1052 if (e
->xreparent
.parent
== client
->frame
->plate
) break;
1055 This event is quite rare and is usually handled in unmapHandler.
1056 However, if the window is unmapped when the reparent event occurs,
1057 the window manager never sees it because an unmap event is not sent
1058 to an already unmapped window.
1061 /* we don't want the reparent event, put it back on the stack for the
1062 X server to deal with after we unmanage the window */
1063 XPutBackEvent(ob_display
, e
);
1065 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
1066 client_unmanage(client
);
1069 ob_debug("MapRequest for 0x%lx\n", client
->window
);
1070 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
1071 does, we don't want it!
1072 it can happen now when the window is on
1073 another desktop, but we still don't
1075 client_activate(client
, FALSE
, TRUE
);
1078 /* validate cuz we query stuff off the client here */
1079 if (!client_validate(client
)) break;
1081 if (e
->xclient
.format
!= 32) return;
1083 msgtype
= e
->xclient
.message_type
;
1084 if (msgtype
== prop_atoms
.wm_change_state
) {
1085 /* compress changes into a single change */
1086 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1088 /* XXX: it would be nice to compress ALL messages of a
1089 type, not just messages in a row without other
1090 message types between. */
1091 if (ce
.xclient
.message_type
!= msgtype
) {
1092 XPutBackEvent(ob_display
, &ce
);
1095 e
->xclient
= ce
.xclient
;
1097 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1098 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
1099 /* compress changes into a single change */
1100 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1102 /* XXX: it would be nice to compress ALL messages of a
1103 type, not just messages in a row without other
1104 message types between. */
1105 if (ce
.xclient
.message_type
!= msgtype
) {
1106 XPutBackEvent(ob_display
, &ce
);
1109 e
->xclient
= ce
.xclient
;
1111 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1112 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1113 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1115 } else if (msgtype
== prop_atoms
.net_wm_state
) {
1116 /* can't compress these */
1117 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1118 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1119 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1120 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1121 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1123 client_set_state(client
, e
->xclient
.data
.l
[0],
1124 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1125 } else if (msgtype
== prop_atoms
.net_close_window
) {
1126 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1127 client_close(client
);
1128 } else if (msgtype
== prop_atoms
.net_active_window
) {
1129 ob_debug("net_active_window for 0x%lx source=%s\n",
1131 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1132 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1133 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1134 /* XXX make use of data.l[2] !? */
1135 event_curtime
= e
->xclient
.data
.l
[1];
1136 if (event_curtime
== 0)
1137 ob_debug_type(OB_DEBUG_APP_BUGS
,
1138 "_NET_ACTIVE_WINDOW message for window %s is "
1139 "missing a timestamp\n", client
->title
);
1140 client_activate(client
, FALSE
,
1141 (e
->xclient
.data
.l
[0] == 0 ||
1142 e
->xclient
.data
.l
[0] == 2));
1143 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1144 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1145 client
->window
, e
->xclient
.data
.l
[2]);
1146 if ((Atom
)e
->xclient
.data
.l
[2] ==
1147 prop_atoms
.net_wm_moveresize_size_topleft
||
1148 (Atom
)e
->xclient
.data
.l
[2] ==
1149 prop_atoms
.net_wm_moveresize_size_top
||
1150 (Atom
)e
->xclient
.data
.l
[2] ==
1151 prop_atoms
.net_wm_moveresize_size_topright
||
1152 (Atom
)e
->xclient
.data
.l
[2] ==
1153 prop_atoms
.net_wm_moveresize_size_right
||
1154 (Atom
)e
->xclient
.data
.l
[2] ==
1155 prop_atoms
.net_wm_moveresize_size_right
||
1156 (Atom
)e
->xclient
.data
.l
[2] ==
1157 prop_atoms
.net_wm_moveresize_size_bottomright
||
1158 (Atom
)e
->xclient
.data
.l
[2] ==
1159 prop_atoms
.net_wm_moveresize_size_bottom
||
1160 (Atom
)e
->xclient
.data
.l
[2] ==
1161 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1162 (Atom
)e
->xclient
.data
.l
[2] ==
1163 prop_atoms
.net_wm_moveresize_size_left
||
1164 (Atom
)e
->xclient
.data
.l
[2] ==
1165 prop_atoms
.net_wm_moveresize_move
||
1166 (Atom
)e
->xclient
.data
.l
[2] ==
1167 prop_atoms
.net_wm_moveresize_size_keyboard
||
1168 (Atom
)e
->xclient
.data
.l
[2] ==
1169 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1171 moveresize_start(client
, e
->xclient
.data
.l
[0],
1172 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1173 e
->xclient
.data
.l
[2]);
1175 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1176 prop_atoms
.net_wm_moveresize_cancel
)
1177 moveresize_end(TRUE
);
1178 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1179 gint grav
, x
, y
, w
, h
;
1181 if (e
->xclient
.data
.l
[0] & 0xff)
1182 grav
= e
->xclient
.data
.l
[0] & 0xff;
1184 grav
= client
->gravity
;
1186 if (e
->xclient
.data
.l
[0] & 1 << 8)
1187 x
= e
->xclient
.data
.l
[1];
1190 if (e
->xclient
.data
.l
[0] & 1 << 9)
1191 y
= e
->xclient
.data
.l
[2];
1194 if (e
->xclient
.data
.l
[0] & 1 << 10)
1195 w
= e
->xclient
.data
.l
[3];
1197 w
= client
->area
.width
;
1198 if (e
->xclient
.data
.l
[0] & 1 << 11)
1199 h
= e
->xclient
.data
.l
[4];
1201 h
= client
->area
.height
;
1203 ob_debug("MOVERESIZE x %d %d y %d %d\n",
1204 e
->xclient
.data
.l
[0] & 1 << 8, x
,
1205 e
->xclient
.data
.l
[0] & 1 << 9, y
);
1206 client_convert_gravity(client
, grav
, &x
, &y
, w
, h
);
1207 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1208 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1209 } else if (msgtype
== prop_atoms
.net_restack_window
) {
1210 if (e
->xclient
.data
.l
[0] != 2) {
1211 ob_debug_type(OB_DEBUG_APP_BUGS
,
1212 "_NET_RESTACK_WINDOW sent for window %s with "
1213 "invalid source indication %ld\n",
1214 client
->title
, e
->xclient
.data
.l
[0]);
1216 ObClient
*sibling
= NULL
;
1217 if (e
->xclient
.data
.l
[1]) {
1218 ObWindow
*win
= g_hash_table_lookup(window_map
,
1219 &e
->xclient
.data
.l
[1]);
1220 if (WINDOW_IS_CLIENT(win
) &&
1221 WINDOW_AS_CLIENT(win
) != client
)
1223 sibling
= WINDOW_AS_CLIENT(win
);
1225 if (sibling
== NULL
)
1226 ob_debug_type(OB_DEBUG_APP_BUGS
,
1227 "_NET_RESTACK_WINDOW sent for window %s "
1228 "with invalid sibling 0x%x\n",
1229 client
->title
, e
->xclient
.data
.l
[1]);
1231 if (e
->xclient
.data
.l
[2] == Below
||
1232 e
->xclient
.data
.l
[2] == BottomIf
||
1233 e
->xclient
.data
.l
[2] == Above
||
1234 e
->xclient
.data
.l
[2] == TopIf
||
1235 e
->xclient
.data
.l
[2] == Opposite
)
1237 /* just raise, don't activate */
1238 stacking_restack_request(client
, sibling
,
1239 e
->xclient
.data
.l
[2], FALSE
);
1241 ob_debug_type(OB_DEBUG_APP_BUGS
,
1242 "_NET_RESTACK_WINDOW sent for window %s "
1243 "with invalid detail %d\n",
1244 client
->title
, e
->xclient
.data
.l
[2]);
1248 case PropertyNotify
:
1249 /* validate cuz we query stuff off the client here */
1250 if (!client_validate(client
)) break;
1252 /* compress changes to a single property into a single change */
1253 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1257 /* XXX: it would be nice to compress ALL changes to a property,
1258 not just changes in a row without other props between. */
1260 a
= ce
.xproperty
.atom
;
1261 b
= e
->xproperty
.atom
;
1265 if ((a
== prop_atoms
.net_wm_name
||
1266 a
== prop_atoms
.wm_name
||
1267 a
== prop_atoms
.net_wm_icon_name
||
1268 a
== prop_atoms
.wm_icon_name
)
1270 (b
== prop_atoms
.net_wm_name
||
1271 b
== prop_atoms
.wm_name
||
1272 b
== prop_atoms
.net_wm_icon_name
||
1273 b
== prop_atoms
.wm_icon_name
)) {
1276 if (a
== prop_atoms
.net_wm_icon
&&
1277 b
== prop_atoms
.net_wm_icon
)
1280 XPutBackEvent(ob_display
, &ce
);
1284 msgtype
= e
->xproperty
.atom
;
1285 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1286 client_update_normal_hints(client
);
1287 /* normal hints can make a window non-resizable */
1288 client_setup_decor_and_functions(client
);
1289 } else if (msgtype
== XA_WM_HINTS
) {
1290 client_update_wmhints(client
);
1291 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1292 client_update_transient_for(client
);
1293 client_get_type_and_transientness(client
);
1294 /* type may have changed, so update the layer */
1295 client_calc_layer(client
);
1296 client_setup_decor_and_functions(client
);
1297 } else if (msgtype
== prop_atoms
.net_wm_name
||
1298 msgtype
== prop_atoms
.wm_name
||
1299 msgtype
== prop_atoms
.net_wm_icon_name
||
1300 msgtype
== prop_atoms
.wm_icon_name
) {
1301 client_update_title(client
);
1302 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1303 client_update_protocols(client
);
1304 client_setup_decor_and_functions(client
);
1306 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1307 client_update_strut(client
);
1309 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1310 client_update_icons(client
);
1312 else if (msgtype
== prop_atoms
.net_wm_icon_geometry
) {
1313 client_update_icon_geometry(client
);
1315 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1316 client_update_user_time(client
);
1318 else if (msgtype
== prop_atoms
.net_wm_user_time_window
) {
1319 client_update_user_time_window(client
);
1322 else if (msgtype
== prop_atoms
.net_wm_sync_request_counter
) {
1323 client_update_sync_request_counter(client
);
1326 case ColormapNotify
:
1327 client_update_colormap(client
, e
->xcolormap
.colormap
);
1332 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1333 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1334 frame_adjust_shape(client
->frame
);
1340 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1344 if (e
->xbutton
.button
== 1)
1345 stacking_raise(DOCK_AS_WINDOW(s
));
1346 else if (e
->xbutton
.button
== 2)
1347 stacking_lower(DOCK_AS_WINDOW(s
));
1358 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1362 dock_app_drag(app
, &e
->xmotion
);
1365 if (app
->ignore_unmaps
) {
1366 app
->ignore_unmaps
--;
1369 dock_remove(app
, TRUE
);
1372 dock_remove(app
, FALSE
);
1374 case ReparentNotify
:
1375 dock_remove(app
, FALSE
);
1377 case ConfigureNotify
:
1378 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1383 static ObMenuFrame
* find_active_menu()
1386 ObMenuFrame
*ret
= NULL
;
1388 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1397 static ObMenuFrame
* find_active_or_last_menu()
1399 ObMenuFrame
*ret
= NULL
;
1401 ret
= find_active_menu();
1402 if (!ret
&& menu_frame_visible
)
1403 ret
= menu_frame_visible
->data
;
1407 static gboolean
event_handle_menu_keyboard(XEvent
*ev
)
1409 guint keycode
, state
;
1412 gboolean ret
= TRUE
;
1414 keycode
= ev
->xkey
.keycode
;
1415 state
= ev
->xkey
.state
;
1416 unikey
= translate_unichar(keycode
);
1418 frame
= find_active_or_last_menu();
1422 else if (keycode
== ob_keycode(OB_KEY_ESCAPE
) && state
== 0) {
1423 /* Escape closes the active menu */
1424 menu_frame_hide(frame
);
1427 else if (keycode
== ob_keycode(OB_KEY_RETURN
) && (state
== 0 ||
1428 state
== ControlMask
))
1430 /* Enter runs the active item or goes into the submenu.
1431 Control-Enter runs it without closing the menu. */
1433 menu_frame_select_next(frame
->child
);
1435 menu_entry_frame_execute(frame
->selected
, state
, ev
->xkey
.time
);
1438 else if (keycode
== ob_keycode(OB_KEY_LEFT
) && ev
->xkey
.state
== 0) {
1439 /* Left goes to the parent menu */
1440 menu_frame_select(frame
, NULL
, TRUE
);
1443 else if (keycode
== ob_keycode(OB_KEY_RIGHT
) && ev
->xkey
.state
== 0) {
1444 /* Right goes to the selected submenu */
1445 if (frame
->child
) menu_frame_select_next(frame
->child
);
1448 else if (keycode
== ob_keycode(OB_KEY_UP
) && state
== 0) {
1449 menu_frame_select_previous(frame
);
1452 else if (keycode
== ob_keycode(OB_KEY_DOWN
) && state
== 0) {
1453 menu_frame_select_next(frame
);
1456 /* keyboard accelerator shortcuts. */
1457 else if (ev
->xkey
.state
== 0 &&
1458 /* was it a valid key? */
1460 /* don't bother if the menu is empty. */
1465 ObMenuEntryFrame
*found
= NULL
;
1466 guint num_found
= 0;
1468 /* start after the selected one */
1469 start
= frame
->entries
;
1470 if (frame
->selected
) {
1471 for (it
= start
; frame
->selected
!= it
->data
; it
= g_list_next(it
))
1472 g_assert(it
!= NULL
); /* nothing was selected? */
1473 /* next with wraparound */
1474 start
= g_list_next(it
);
1475 if (start
== NULL
) start
= frame
->entries
;
1480 ObMenuEntryFrame
*e
= it
->data
;
1481 gunichar entrykey
= 0;
1483 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1484 entrykey
= e
->entry
->data
.normal
.shortcut
;
1485 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1486 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1488 if (unikey
== entrykey
) {
1489 if (found
== NULL
) found
= e
;
1493 /* next with wraparound */
1494 it
= g_list_next(it
);
1495 if (it
== NULL
) it
= frame
->entries
;
1496 } while (it
!= start
);
1499 if (found
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
1502 menu_frame_select(frame
, found
, TRUE
);
1503 usleep(50000); /* highlight the item for a short bit so the
1504 user can see what happened */
1505 menu_entry_frame_execute(found
, state
, ev
->xkey
.time
);
1507 menu_frame_select(frame
, found
, TRUE
);
1509 menu_frame_select_next(frame
->child
);
1520 static gboolean
event_handle_menu(XEvent
*ev
)
1523 ObMenuEntryFrame
*e
;
1524 gboolean ret
= TRUE
;
1528 if ((ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5)
1531 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1532 ev
->xbutton
.y_root
)))
1533 menu_entry_frame_execute(e
, ev
->xbutton
.state
,
1536 menu_frame_hide_all();
1540 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1541 if (e
->ignore_enters
)
1544 menu_frame_select(e
->frame
, e
, FALSE
);
1548 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1549 (f
= find_active_menu()) && f
->selected
== e
&&
1550 e
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1552 menu_frame_select(e
->frame
, NULL
, FALSE
);
1555 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1556 ev
->xmotion
.y_root
)))
1557 menu_frame_select(e
->frame
, e
, FALSE
);
1560 ret
= event_handle_menu_keyboard(ev
);
1566 static void event_handle_user_input(ObClient
*client
, XEvent
*e
)
1568 g_assert(e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
1569 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
1570 e
->type
== KeyRelease
);
1572 if (menu_frame_visible
) {
1573 if (event_handle_menu(e
))
1574 /* don't use the event if the menu used it, but if the menu
1575 didn't use it and it's a keypress that is bound, it will
1576 close the menu and be used */
1580 /* if the keyboard interactive action uses the event then dont
1581 use it for bindings. likewise is moveresize uses the event. */
1582 if (!keyboard_process_interactive_grab(e
, &client
) &&
1583 !(moveresize_in_progress
&& moveresize_event(e
)))
1585 if (moveresize_in_progress
)
1586 /* make further actions work on the client being
1588 client
= moveresize_client
;
1590 menu_can_hide
= FALSE
;
1591 ob_main_loop_timeout_add(ob_main_loop
,
1592 config_menu_hide_delay
* 1000,
1593 menu_hide_delay_func
,
1594 NULL
, g_direct_equal
, NULL
);
1596 if (e
->type
== ButtonPress
||
1597 e
->type
== ButtonRelease
||
1598 e
->type
== MotionNotify
)
1600 /* the frame may not be "visible" but they can still click on it
1601 in the case where it is animating before disappearing */
1602 if (!client
|| !frame_iconify_animating(client
->frame
))
1603 mouse_event(client
, e
);
1604 } else if (e
->type
== KeyPress
) {
1605 keyboard_event((focus_cycle_target
? focus_cycle_target
:
1606 (client
? client
: focus_client
)), e
);
1611 static gboolean
menu_hide_delay_func(gpointer data
)
1613 menu_can_hide
= TRUE
;
1614 return FALSE
; /* no repeat */
1617 static void focus_delay_dest(gpointer data
)
1622 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
1624 const ObFocusDelayData
*f1
= d1
;
1625 return f1
->client
== d2
;
1628 static gboolean
focus_delay_func(gpointer data
)
1630 ObFocusDelayData
*d
= data
;
1631 Time old
= event_curtime
;
1633 event_curtime
= d
->time
;
1634 if (focus_client
!= d
->client
) {
1635 if (client_focus(d
->client
) && config_focus_raise
)
1636 stacking_raise(CLIENT_AS_WINDOW(d
->client
));
1638 event_curtime
= old
;
1639 return FALSE
; /* no repeat */
1642 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1644 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1648 void event_halt_focus_delay()
1650 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1653 void event_ignore_queued_enters()
1655 GSList
*saved
= NULL
, *it
;
1658 XSync(ob_display
, FALSE
);
1660 /* count the events */
1662 e
= g_new(XEvent
, 1);
1663 if (XCheckTypedEvent(ob_display
, EnterNotify
, e
)) {
1666 win
= g_hash_table_lookup(window_map
, &e
->xany
.window
);
1667 if (win
&& WINDOW_IS_CLIENT(win
))
1668 ++ignore_enter_focus
;
1670 saved
= g_slist_append(saved
, e
);
1676 /* put the events back */
1677 for (it
= saved
; it
; it
= g_slist_next(it
)) {
1678 XPutBackEvent(ob_display
, it
->data
);
1681 g_slist_free(saved
);
1684 gboolean
event_time_after(Time t1
, Time t2
)
1686 g_assert(t1
!= CurrentTime
);
1687 g_assert(t2
!= CurrentTime
);
1690 Timestamp values wrap around (after about 49.7 days). The server, given
1691 its current time is represented by timestamp T, always interprets
1692 timestamps from clients by treating half of the timestamp space as being
1693 later in time than T.
1694 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
1697 /* TIME_HALF is half of the number space of a Time type variable */
1698 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
1700 if (t2
>= TIME_HALF
)
1701 /* t2 is in the second half so t1 might wrap around and be smaller than
1703 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
1705 /* t2 is in the first half so t1 has to come after it */
1706 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);