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 reverted to parent from the client (this
324 happens often during iconify animation) */
325 if (detail
== NotifyInferior
)
329 /* This means focus moved from the root window to a client */
330 if (detail
== NotifyVirtual
)
332 /* This means focus moved from one client to another */
333 if (detail
== NotifyNonlinearVirtual
)
339 g_assert(e
->type
== FocusOut
);
341 /* These are ones we never want.. */
343 /* This means focus was taken by a keyboard/mouse grab. */
344 if (mode
== NotifyGrab
)
347 /* Focus left the root window revertedto state */
348 if (win
== RootWindow(ob_display
, ob_screen
))
351 /* These are the ones we want.. */
353 /* This means focus moved from a client to the root window */
354 if (detail
== NotifyVirtual
)
356 /* This means focus moved from one client to another */
357 if (detail
== NotifyNonlinearVirtual
)
365 static Bool
event_look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
367 return e
->type
== FocusIn
&& wanted_focusevent(e
, FALSE
);
370 static Bool
event_look_for_focusin_client(Display
*d
, XEvent
*e
, XPointer arg
)
372 return e
->type
== FocusIn
&& wanted_focusevent(e
, TRUE
);
375 static void print_focusevent(XEvent
*e
)
377 gint mode
= e
->xfocus
.mode
;
378 gint detail
= e
->xfocus
.detail
;
379 Window win
= e
->xany
.window
;
380 const gchar
*modestr
, *detailstr
;
383 case NotifyNormal
: modestr
="NotifyNormal"; break;
384 case NotifyGrab
: modestr
="NotifyGrab"; break;
385 case NotifyUngrab
: modestr
="NotifyUngrab"; break;
386 case NotifyWhileGrabbed
: modestr
="NotifyWhileGrabbed"; break;
389 case NotifyAncestor
: detailstr
="NotifyAncestor"; break;
390 case NotifyVirtual
: detailstr
="NotifyVirtual"; break;
391 case NotifyInferior
: detailstr
="NotifyInferior"; break;
392 case NotifyNonlinear
: detailstr
="NotifyNonlinear"; break;
393 case NotifyNonlinearVirtual
: detailstr
="NotifyNonlinearVirtual"; break;
394 case NotifyPointer
: detailstr
="NotifyPointer"; break;
395 case NotifyPointerRoot
: detailstr
="NotifyPointerRoot"; break;
396 case NotifyDetailNone
: detailstr
="NotifyDetailNone"; break;
399 if (mode
== NotifyGrab
|| mode
== NotifyUngrab
)
404 ob_debug_type(OB_DEBUG_FOCUS
, "Focus%s 0x%x mode=%s detail=%s\n",
405 (e
->xfocus
.type
== FocusIn
? "In" : "Out"),
411 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
416 if (!wanted_focusevent(e
, FALSE
))
421 if (!wanted_focusevent(e
, FALSE
))
428 static void event_process(const XEvent
*ec
, gpointer data
)
431 ObClient
*client
= NULL
;
433 ObDockApp
*dockapp
= NULL
;
434 ObWindow
*obwin
= NULL
;
435 GSList
*timewinclients
= NULL
;
437 ObEventData
*ed
= data
;
439 /* make a copy we can mangle */
443 window
= event_get_window(e
);
444 if (e
->type
!= PropertyNotify
||
445 !(timewinclients
= propwin_get_clients(window
,
446 OB_PROPWIN_USER_TIME
)))
447 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
448 switch (obwin
->type
) {
450 dock
= WINDOW_AS_DOCK(obwin
);
453 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
456 client
= WINDOW_AS_CLIENT(obwin
);
459 case Window_Internal
:
460 /* not to be used for events */
461 g_assert_not_reached();
466 event_set_curtime(e
);
468 if (event_ignore(e
, client
)) {
475 /* deal with it in the kernel */
477 if (menu_frame_visible
&&
478 (e
->type
== EnterNotify
|| e
->type
== LeaveNotify
))
480 /* crossing events for menu */
481 event_handle_menu(e
);
482 } else if (e
->type
== FocusIn
) {
483 if (e
->xfocus
.detail
== NotifyPointerRoot
||
484 e
->xfocus
.detail
== NotifyDetailNone
||
485 e
->xfocus
.detail
== NotifyInferior
)
489 ob_debug_type(OB_DEBUG_FOCUS
, "Focus went to pointer root/none or"
490 " the frame window\n");
492 /* If another FocusIn is in the queue then don't fallback yet. This
493 fixes the fun case of:
494 window map -> send focusin
495 window unmap -> get focusout
496 window map -> send focusin
497 get first focus out -> fall back to something (new window
498 hasn't received focus yet, so something else) -> send focusin
499 which means the "something else" is the last thing to get a
500 focusin sent to it, so the new window doesn't end up with focus.
502 But if the other focus in is something like PointerRoot then we
503 still want to fall back.
505 if (XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin_client
,
508 XPutBackEvent(ob_display
, &ce
);
509 ob_debug_type(OB_DEBUG_FOCUS
,
510 " but another FocusIn is coming\n");
512 /* Focus has been reverted.
514 FocusOut events come after UnmapNotify, so we don't need to
515 worry about focusing an invalid window
518 if (!focus_left_screen
)
519 focus_fallback(TRUE
);
524 ob_debug_type(OB_DEBUG_FOCUS
,
525 "Focus went to a window that is already gone\n");
527 /* If you send focus to a window and then it disappears, you can
528 get the FocusIn for it, after it is unmanaged.
529 Just wait for the next FocusOut/FocusIn pair. */
531 else if (client
!= focus_client
) {
532 focus_left_screen
= FALSE
;
533 frame_adjust_focus(client
->frame
, TRUE
);
534 focus_set_client(client
);
535 client_calc_layer(client
);
536 client_bring_helper_windows(client
);
538 } else if (e
->type
== FocusOut
) {
539 gboolean nomove
= FALSE
;
543 frame_adjust_focus(client
->frame
, FALSE
);
544 /* focus_set_client(NULL) has already been called in this
545 section or by focus_fallback */
546 client_calc_layer(client
);
549 /* Look for the followup FocusIn */
550 if (!XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin
, NULL
)) {
551 /* There is no FocusIn, this means focus went to a window that
552 is not being managed, or a window on another screen. */
556 xerror_set_ignore(TRUE
);
557 if (XGetInputFocus(ob_display
, &win
, &i
) != 0 &&
558 XGetGeometry(ob_display
, win
, &root
, &i
,&i
,&u
,&u
,&u
,&u
) != 0 &&
559 root
!= RootWindow(ob_display
, ob_screen
))
561 ob_debug_type(OB_DEBUG_FOCUS
,
562 "Focus went to another screen !\n");
563 focus_left_screen
= TRUE
;
566 ob_debug_type(OB_DEBUG_FOCUS
,
567 "Focus went to a black hole !\n");
568 xerror_set_ignore(FALSE
);
569 /* nothing is focused */
570 focus_set_client(NULL
);
572 /* Focus moved, so process the FocusIn event */
573 ObEventData ed
= { .ignored
= FALSE
};
574 event_process(&ce
, &ed
);
576 /* The FocusIn was ignored, this means it was on a window
577 that isn't a client. */
578 ob_debug_type(OB_DEBUG_FOCUS
,
579 "Focus went to an unmanaged window 0x%x !\n",
581 focus_fallback(TRUE
);
584 } else if (timewinclients
)
585 event_handle_user_time_window_clients(timewinclients
, e
);
587 event_handle_client(client
, e
);
589 event_handle_dockapp(dockapp
, e
);
591 event_handle_dock(dock
, e
);
592 else if (window
== RootWindow(ob_display
, ob_screen
))
593 event_handle_root(e
);
594 else if (e
->type
== MapRequest
)
595 client_manage(window
);
596 else if (e
->type
== ClientMessage
) {
597 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
598 windows that are not managed yet. */
599 if (e
->xclient
.message_type
== prop_atoms
.net_request_frame_extents
) {
600 /* Pretend to manage the client, getting information used to
601 determine its decorations */
602 ObClient
*c
= client_fake_manage(e
->xclient
.window
);
605 /* set the frame extents on the window */
606 vals
[0] = c
->frame
->size
.left
;
607 vals
[1] = c
->frame
->size
.right
;
608 vals
[2] = c
->frame
->size
.top
;
609 vals
[3] = c
->frame
->size
.bottom
;
610 PROP_SETA32(e
->xclient
.window
, net_frame_extents
,
613 /* Free the pretend client */
614 client_fake_unmanage(c
);
617 else if (e
->type
== ConfigureRequest
) {
618 /* unhandled configure requests must be used to configure the
622 xwc
.x
= e
->xconfigurerequest
.x
;
623 xwc
.y
= e
->xconfigurerequest
.y
;
624 xwc
.width
= e
->xconfigurerequest
.width
;
625 xwc
.height
= e
->xconfigurerequest
.height
;
626 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
627 xwc
.sibling
= e
->xconfigurerequest
.above
;
628 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
630 /* we are not to be held responsible if someone sends us an
632 xerror_set_ignore(TRUE
);
633 XConfigureWindow(ob_display
, window
,
634 e
->xconfigurerequest
.value_mask
, &xwc
);
635 xerror_set_ignore(FALSE
);
638 else if (extensions_sync
&&
639 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
641 XSyncAlarmNotifyEvent
*se
= (XSyncAlarmNotifyEvent
*)e
;
642 if (se
->alarm
== moveresize_alarm
&& moveresize_in_progress
)
647 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
648 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
649 e
->type
== KeyRelease
)
651 event_handle_user_input(client
, e
);
654 /* if something happens and it's not from an XEvent, then we don't know
656 event_curtime
= CurrentTime
;
659 static void event_handle_root(XEvent
*e
)
665 ob_debug("Another WM has requested to replace us. Exiting.\n");
670 if (e
->xclient
.format
!= 32) break;
672 msgtype
= e
->xclient
.message_type
;
673 if (msgtype
== prop_atoms
.net_current_desktop
) {
674 guint d
= e
->xclient
.data
.l
[0];
675 if (d
< screen_num_desktops
) {
676 event_curtime
= e
->xclient
.data
.l
[1];
677 if (event_curtime
== 0)
678 ob_debug_type(OB_DEBUG_APP_BUGS
,
679 "_NET_CURRENT_DESKTOP message is missing "
681 screen_set_desktop(d
, TRUE
);
683 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
684 guint d
= e
->xclient
.data
.l
[0];
685 if (d
> 0 && d
<= 1000)
686 screen_set_num_desktops(d
);
687 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
688 screen_show_desktop(e
->xclient
.data
.l
[0] != 0, NULL
);
689 } else if (msgtype
== prop_atoms
.ob_control
) {
690 if (e
->xclient
.data
.l
[0] == 1)
692 else if (e
->xclient
.data
.l
[0] == 2)
697 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
)
698 screen_update_desktop_names();
699 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
700 screen_update_layout();
702 case ConfigureNotify
:
704 XRRUpdateConfiguration(e
);
713 void event_enter_client(ObClient
*client
)
715 g_assert(config_focus_follow
);
717 if (client_enter_focusable(client
) && client_can_focus(client
)) {
718 if (config_focus_delay
) {
719 ObFocusDelayData
*data
;
721 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
723 data
= g_new(ObFocusDelayData
, 1);
724 data
->client
= client
;
725 data
->time
= event_curtime
;
727 ob_main_loop_timeout_add(ob_main_loop
,
730 data
, focus_delay_cmp
, focus_delay_dest
);
732 ObFocusDelayData data
;
733 data
.client
= client
;
734 data
.time
= event_curtime
;
735 focus_delay_func(&data
);
740 static void event_handle_user_time_window_clients(GSList
*l
, XEvent
*e
)
742 g_assert(e
->type
== PropertyNotify
);
743 if (e
->xproperty
.atom
== prop_atoms
.net_wm_user_time
) {
744 for (; l
; l
= g_slist_next(l
))
745 client_update_user_time(l
->data
);
749 static void event_handle_client(ObClient
*client
, XEvent
*e
)
754 static gint px
= -1, py
= -1;
759 /* save where the press occured for the first button pressed */
761 pb
= e
->xbutton
.button
;
766 /* Wheel buttons don't draw because they are an instant click, so it
767 is a waste of resources to go drawing it.
768 if the user is doing an intereactive thing, or has a menu open then
769 the mouse is grabbed (possibly) and if we get these events we don't
770 want to deal with them
772 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5) &&
773 !keyboard_interactively_grabbed() &&
776 /* use where the press occured */
777 con
= frame_context(client
, e
->xbutton
.window
, px
, py
);
778 con
= mouse_button_frame_context(con
, e
->xbutton
.button
,
781 if (e
->type
== ButtonRelease
&& e
->xbutton
.button
== pb
)
782 pb
= 0, px
= py
= -1;
785 case OB_FRAME_CONTEXT_MAXIMIZE
:
786 client
->frame
->max_press
= (e
->type
== ButtonPress
);
787 framerender_frame(client
->frame
);
789 case OB_FRAME_CONTEXT_CLOSE
:
790 client
->frame
->close_press
= (e
->type
== ButtonPress
);
791 framerender_frame(client
->frame
);
793 case OB_FRAME_CONTEXT_ICONIFY
:
794 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
795 framerender_frame(client
->frame
);
797 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
798 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
799 framerender_frame(client
->frame
);
801 case OB_FRAME_CONTEXT_SHADE
:
802 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
803 framerender_frame(client
->frame
);
806 /* nothing changes with clicks for any other contexts */
812 con
= frame_context(client
, e
->xmotion
.window
,
813 e
->xmotion
.x
, e
->xmotion
.y
);
815 case OB_FRAME_CONTEXT_TITLEBAR
:
816 case OB_FRAME_CONTEXT_TLCORNER
:
817 case OB_FRAME_CONTEXT_TRCORNER
:
818 /* we've left the button area inside the titlebar */
819 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
820 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
821 client
->frame
->close_hover
)
823 client
->frame
->max_hover
= FALSE
;
824 client
->frame
->desk_hover
= FALSE
;
825 client
->frame
->shade_hover
= FALSE
;
826 client
->frame
->iconify_hover
= FALSE
;
827 client
->frame
->close_hover
= FALSE
;
828 frame_adjust_state(client
->frame
);
831 case OB_FRAME_CONTEXT_MAXIMIZE
:
832 if (!client
->frame
->max_hover
) {
833 client
->frame
->max_hover
= TRUE
;
834 frame_adjust_state(client
->frame
);
837 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
838 if (!client
->frame
->desk_hover
) {
839 client
->frame
->desk_hover
= TRUE
;
840 frame_adjust_state(client
->frame
);
843 case OB_FRAME_CONTEXT_SHADE
:
844 if (!client
->frame
->shade_hover
) {
845 client
->frame
->shade_hover
= TRUE
;
846 frame_adjust_state(client
->frame
);
849 case OB_FRAME_CONTEXT_ICONIFY
:
850 if (!client
->frame
->iconify_hover
) {
851 client
->frame
->iconify_hover
= TRUE
;
852 frame_adjust_state(client
->frame
);
855 case OB_FRAME_CONTEXT_CLOSE
:
856 if (!client
->frame
->close_hover
) {
857 client
->frame
->close_hover
= TRUE
;
858 frame_adjust_state(client
->frame
);
866 con
= frame_context(client
, e
->xcrossing
.window
,
867 e
->xcrossing
.x
, e
->xcrossing
.y
);
869 case OB_FRAME_CONTEXT_TITLEBAR
:
870 case OB_FRAME_CONTEXT_TLCORNER
:
871 case OB_FRAME_CONTEXT_TRCORNER
:
872 /* we've left the button area inside the titlebar */
873 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
874 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
875 client
->frame
->close_hover
)
877 client
->frame
->max_hover
= FALSE
;
878 client
->frame
->desk_hover
= FALSE
;
879 client
->frame
->shade_hover
= FALSE
;
880 client
->frame
->iconify_hover
= FALSE
;
881 client
->frame
->close_hover
= FALSE
;
882 frame_adjust_state(client
->frame
);
885 case OB_FRAME_CONTEXT_MAXIMIZE
:
886 client
->frame
->max_hover
= FALSE
;
887 frame_adjust_state(client
->frame
);
889 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
890 client
->frame
->desk_hover
= FALSE
;
891 frame_adjust_state(client
->frame
);
893 case OB_FRAME_CONTEXT_SHADE
:
894 client
->frame
->shade_hover
= FALSE
;
895 frame_adjust_state(client
->frame
);
897 case OB_FRAME_CONTEXT_ICONIFY
:
898 client
->frame
->iconify_hover
= FALSE
;
899 frame_adjust_state(client
->frame
);
901 case OB_FRAME_CONTEXT_CLOSE
:
902 client
->frame
->close_hover
= FALSE
;
903 frame_adjust_state(client
->frame
);
905 case OB_FRAME_CONTEXT_FRAME
:
906 /* When the mouse leaves an animating window, don't use the
907 corresponding enter events. Pretend like the animating window
908 doesn't even exist..! */
909 if (frame_iconify_animating(client
->frame
))
910 event_ignore_all_queued_enters();
912 ob_debug_type(OB_DEBUG_FOCUS
,
913 "%sNotify mode %d detail %d on %lx\n",
914 (e
->type
== EnterNotify
? "Enter" : "Leave"),
916 e
->xcrossing
.detail
, (client
?client
->window
:0));
917 if (keyboard_interactively_grabbed())
919 if (config_focus_follow
&& config_focus_delay
&&
920 /* leave inferior events can happen when the mouse goes onto
921 the window's border and then into the window before the
923 e
->xcrossing
.detail
!= NotifyInferior
)
925 ob_main_loop_timeout_remove_data(ob_main_loop
,
936 con
= frame_context(client
, e
->xcrossing
.window
,
937 e
->xcrossing
.x
, e
->xcrossing
.y
);
939 case OB_FRAME_CONTEXT_MAXIMIZE
:
940 client
->frame
->max_hover
= TRUE
;
941 frame_adjust_state(client
->frame
);
943 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
944 client
->frame
->desk_hover
= TRUE
;
945 frame_adjust_state(client
->frame
);
947 case OB_FRAME_CONTEXT_SHADE
:
948 client
->frame
->shade_hover
= TRUE
;
949 frame_adjust_state(client
->frame
);
951 case OB_FRAME_CONTEXT_ICONIFY
:
952 client
->frame
->iconify_hover
= TRUE
;
953 frame_adjust_state(client
->frame
);
955 case OB_FRAME_CONTEXT_CLOSE
:
956 client
->frame
->close_hover
= TRUE
;
957 frame_adjust_state(client
->frame
);
959 case OB_FRAME_CONTEXT_FRAME
:
960 if (keyboard_interactively_grabbed())
962 if (e
->xcrossing
.mode
== NotifyGrab
||
963 e
->xcrossing
.mode
== NotifyUngrab
||
964 /*ignore enters when we're already in the window */
965 e
->xcrossing
.detail
== NotifyInferior
||
966 is_enter_focus_event_ignored(e
))
968 ob_debug_type(OB_DEBUG_FOCUS
,
969 "%sNotify mode %d detail %d on %lx IGNORED\n",
970 (e
->type
== EnterNotify
? "Enter" : "Leave"),
972 e
->xcrossing
.detail
, client
?client
->window
:0);
975 ob_debug_type(OB_DEBUG_FOCUS
,
976 "%sNotify mode %d detail %d on %lx, "
978 (e
->type
== EnterNotify
? "Enter" : "Leave"),
980 e
->xcrossing
.detail
, (client
?client
->window
:0));
981 if (config_focus_follow
)
982 event_enter_client(client
);
990 case ConfigureRequest
:
992 /* dont compress these unless you're going to watch for property
993 notifies in between (these can change what the configure would
995 also you can't compress stacking events
999 gboolean move
= FALSE
;
1000 gboolean resize
= FALSE
;
1002 /* get the current area */
1003 RECT_TO_DIMS(client
->area
, x
, y
, w
, h
);
1005 ob_debug("ConfigureRequest desktop %d wmstate %d visibile %d\n",
1006 screen_desktop
, client
->wmstate
, client
->frame
->visible
);
1008 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
1009 if (client
->border_width
!= e
->xconfigurerequest
.border_width
) {
1010 client
->border_width
= e
->xconfigurerequest
.border_width
;
1012 /* if the border width is changing then that is the same
1013 as requesting a resize, but we don't actually change
1014 the client's border, so it will change their root
1015 coordiantes (since they include the border width) and
1016 we need to a notify then */
1021 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
1022 ObClient
*sibling
= NULL
;
1024 /* get the sibling */
1025 if (e
->xconfigurerequest
.value_mask
& CWSibling
) {
1027 win
= g_hash_table_lookup(window_map
,
1028 &e
->xconfigurerequest
.above
);
1029 if (WINDOW_IS_CLIENT(win
) && WINDOW_AS_CLIENT(win
) != client
)
1030 sibling
= WINDOW_AS_CLIENT(win
);
1033 /* activate it rather than just focus it */
1034 stacking_restack_request(client
, sibling
,
1035 e
->xconfigurerequest
.detail
, TRUE
);
1037 /* if a stacking change moves the window without resizing */
1041 if (e
->xconfigurerequest
.value_mask
& CWX
||
1042 e
->xconfigurerequest
.value_mask
& CWY
||
1043 e
->xconfigurerequest
.value_mask
& CWWidth
||
1044 e
->xconfigurerequest
.value_mask
& CWHeight
)
1046 if (e
->xconfigurerequest
.value_mask
& CWX
) {
1047 /* don't allow clients to move shaded windows (fvwm does this)
1049 if (!client
->shaded
)
1050 x
= e
->xconfigurerequest
.x
;
1053 if (e
->xconfigurerequest
.value_mask
& CWY
) {
1054 /* don't allow clients to move shaded windows (fvwm does this)
1056 if (!client
->shaded
)
1057 y
= e
->xconfigurerequest
.y
;
1061 if (e
->xconfigurerequest
.value_mask
& CWWidth
) {
1062 w
= e
->xconfigurerequest
.width
;
1065 /* if x was not given, then use gravity to figure out the new
1066 x. the reference point should not be moved */
1067 if (!(e
->xconfigurerequest
.value_mask
& CWX
))
1068 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1070 if (e
->xconfigurerequest
.value_mask
& CWHeight
) {
1071 h
= e
->xconfigurerequest
.height
;
1074 /* if y was not given, then use gravity to figure out the new
1075 y. the reference point should not be moved */
1076 if (!(e
->xconfigurerequest
.value_mask
& CWY
))
1077 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1081 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
1082 "move %d resize %d\n",
1083 e
->xconfigurerequest
.value_mask
& CWX
, x
,
1084 e
->xconfigurerequest
.value_mask
& CWY
, y
,
1085 e
->xconfigurerequest
.value_mask
& CWWidth
, w
,
1086 e
->xconfigurerequest
.value_mask
& CWHeight
, h
,
1089 /* check for broken apps moving to their root position
1091 XXX remove this some day...that would be nice. right now all
1092 kde apps do this when they try activate themselves on another
1093 desktop. eg. open amarok window on desktop 1, switch to desktop
1094 2, click amarok tray icon. it will move by its decoration size.
1096 if (move
&& !resize
&&
1097 x
!= client
->area
.x
&&
1098 x
== (client
->frame
->area
.x
+ client
->frame
->size
.left
-
1099 (gint
)client
->border_width
) &&
1100 y
!= client
->area
.y
&&
1101 y
== (client
->frame
->area
.y
+ client
->frame
->size
.top
-
1102 (gint
)client
->border_width
))
1104 ob_debug_type(OB_DEBUG_APP_BUGS
,
1105 "Application %s is trying to move via "
1106 "ConfigureRequest to it's root window position "
1107 "but it is not using StaticGravity\n",
1113 /* they still requested a move, so don't change whether a
1114 notify is sent or not */
1117 if (move
|| resize
) {
1120 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1121 client_try_configure(client
, &x
, &y
, &w
, &h
, &lw
, &lh
, FALSE
);
1122 /* if they requested something that moves the window, or if
1123 the window is actually being changed then configure it and
1124 send a configure notify to them */
1125 if (move
|| !RECT_EQUAL_DIMS(client
->area
, x
, y
, w
, h
)) {
1126 ob_debug("Doing configure\n");
1127 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1130 /* ignore enter events caused by these like ob actions do */
1131 event_ignore_all_queued_enters();
1136 if (client
->ignore_unmaps
) {
1137 client
->ignore_unmaps
--;
1140 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1141 "ignores left %d\n",
1142 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
1143 client
->ignore_unmaps
);
1144 client_unmanage(client
);
1147 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
1148 client_unmanage(client
);
1150 case ReparentNotify
:
1151 /* this is when the client is first taken captive in the frame */
1152 if (e
->xreparent
.parent
== client
->frame
->plate
) break;
1155 This event is quite rare and is usually handled in unmapHandler.
1156 However, if the window is unmapped when the reparent event occurs,
1157 the window manager never sees it because an unmap event is not sent
1158 to an already unmapped window.
1161 /* we don't want the reparent event, put it back on the stack for the
1162 X server to deal with after we unmanage the window */
1163 XPutBackEvent(ob_display
, e
);
1165 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
1166 client_unmanage(client
);
1169 ob_debug("MapRequest for 0x%lx\n", client
->window
);
1170 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
1171 does, we don't want it!
1172 it can happen now when the window is on
1173 another desktop, but we still don't
1175 client_activate(client
, FALSE
, TRUE
);
1178 /* validate cuz we query stuff off the client here */
1179 if (!client_validate(client
)) break;
1181 if (e
->xclient
.format
!= 32) return;
1183 msgtype
= e
->xclient
.message_type
;
1184 if (msgtype
== prop_atoms
.wm_change_state
) {
1185 /* compress changes into a single change */
1186 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1188 /* XXX: it would be nice to compress ALL messages of a
1189 type, not just messages in a row without other
1190 message types between. */
1191 if (ce
.xclient
.message_type
!= msgtype
) {
1192 XPutBackEvent(ob_display
, &ce
);
1195 e
->xclient
= ce
.xclient
;
1197 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1198 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
1199 /* compress changes into a single change */
1200 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1202 /* XXX: it would be nice to compress ALL messages of a
1203 type, not just messages in a row without other
1204 message types between. */
1205 if (ce
.xclient
.message_type
!= msgtype
) {
1206 XPutBackEvent(ob_display
, &ce
);
1209 e
->xclient
= ce
.xclient
;
1211 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1212 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1213 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1215 } else if (msgtype
== prop_atoms
.net_wm_state
) {
1216 /* can't compress these */
1217 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1218 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1219 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1220 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1221 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1223 client_set_state(client
, e
->xclient
.data
.l
[0],
1224 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1226 /* ignore enter events caused by these like ob actions do */
1227 event_ignore_all_queued_enters();
1228 } else if (msgtype
== prop_atoms
.net_close_window
) {
1229 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1230 client_close(client
);
1231 } else if (msgtype
== prop_atoms
.net_active_window
) {
1232 ob_debug("net_active_window for 0x%lx source=%s\n",
1234 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1235 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1236 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1237 /* XXX make use of data.l[2] !? */
1238 if (e
->xclient
.data
.l
[0] == 1 || e
->xclient
.data
.l
[0] == 2) {
1239 event_curtime
= e
->xclient
.data
.l
[1];
1240 if (event_curtime
== 0)
1241 ob_debug_type(OB_DEBUG_APP_BUGS
,
1242 "_NET_ACTIVE_WINDOW message for window %s is"
1243 " missing a timestamp\n", client
->title
);
1245 ob_debug_type(OB_DEBUG_APP_BUGS
,
1246 "_NET_ACTIVE_WINDOW message for window %s is "
1247 "missing source indication\n");
1248 client_activate(client
, FALSE
,
1249 (e
->xclient
.data
.l
[0] == 0 ||
1250 e
->xclient
.data
.l
[0] == 2));
1251 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1252 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1253 client
->window
, e
->xclient
.data
.l
[2]);
1254 if ((Atom
)e
->xclient
.data
.l
[2] ==
1255 prop_atoms
.net_wm_moveresize_size_topleft
||
1256 (Atom
)e
->xclient
.data
.l
[2] ==
1257 prop_atoms
.net_wm_moveresize_size_top
||
1258 (Atom
)e
->xclient
.data
.l
[2] ==
1259 prop_atoms
.net_wm_moveresize_size_topright
||
1260 (Atom
)e
->xclient
.data
.l
[2] ==
1261 prop_atoms
.net_wm_moveresize_size_right
||
1262 (Atom
)e
->xclient
.data
.l
[2] ==
1263 prop_atoms
.net_wm_moveresize_size_right
||
1264 (Atom
)e
->xclient
.data
.l
[2] ==
1265 prop_atoms
.net_wm_moveresize_size_bottomright
||
1266 (Atom
)e
->xclient
.data
.l
[2] ==
1267 prop_atoms
.net_wm_moveresize_size_bottom
||
1268 (Atom
)e
->xclient
.data
.l
[2] ==
1269 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1270 (Atom
)e
->xclient
.data
.l
[2] ==
1271 prop_atoms
.net_wm_moveresize_size_left
||
1272 (Atom
)e
->xclient
.data
.l
[2] ==
1273 prop_atoms
.net_wm_moveresize_move
||
1274 (Atom
)e
->xclient
.data
.l
[2] ==
1275 prop_atoms
.net_wm_moveresize_size_keyboard
||
1276 (Atom
)e
->xclient
.data
.l
[2] ==
1277 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1279 moveresize_start(client
, e
->xclient
.data
.l
[0],
1280 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1281 e
->xclient
.data
.l
[2]);
1283 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1284 prop_atoms
.net_wm_moveresize_cancel
)
1285 moveresize_end(TRUE
);
1286 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1287 gint ograv
, x
, y
, w
, h
;
1289 ograv
= client
->gravity
;
1291 if (e
->xclient
.data
.l
[0] & 0xff)
1292 client
->gravity
= e
->xclient
.data
.l
[0] & 0xff;
1294 if (e
->xclient
.data
.l
[0] & 1 << 8)
1295 x
= e
->xclient
.data
.l
[1];
1298 if (e
->xclient
.data
.l
[0] & 1 << 9)
1299 y
= e
->xclient
.data
.l
[2];
1303 if (e
->xclient
.data
.l
[0] & 1 << 10) {
1304 w
= e
->xclient
.data
.l
[3];
1306 /* if x was not given, then use gravity to figure out the new
1307 x. the reference point should not be moved */
1308 if (!(e
->xclient
.data
.l
[0] & 1 << 8))
1309 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1312 w
= client
->area
.width
;
1314 if (e
->xclient
.data
.l
[0] & 1 << 11) {
1315 h
= e
->xclient
.data
.l
[4];
1317 /* if y was not given, then use gravity to figure out the new
1318 y. the reference point should not be moved */
1319 if (!(e
->xclient
.data
.l
[0] & 1 << 9))
1320 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1323 h
= client
->area
.height
;
1325 ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)\n",
1326 e
->xclient
.data
.l
[0] & 1 << 8, x
,
1327 e
->xclient
.data
.l
[0] & 1 << 9, y
,
1330 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1332 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1334 client
->gravity
= ograv
;
1336 /* ignore enter events caused by these like ob actions do */
1337 event_ignore_all_queued_enters();
1338 } else if (msgtype
== prop_atoms
.net_restack_window
) {
1339 if (e
->xclient
.data
.l
[0] != 2) {
1340 ob_debug_type(OB_DEBUG_APP_BUGS
,
1341 "_NET_RESTACK_WINDOW sent for window %s with "
1342 "invalid source indication %ld\n",
1343 client
->title
, e
->xclient
.data
.l
[0]);
1345 ObClient
*sibling
= NULL
;
1346 if (e
->xclient
.data
.l
[1]) {
1347 ObWindow
*win
= g_hash_table_lookup
1348 (window_map
, &e
->xclient
.data
.l
[1]);
1349 if (WINDOW_IS_CLIENT(win
) &&
1350 WINDOW_AS_CLIENT(win
) != client
)
1352 sibling
= WINDOW_AS_CLIENT(win
);
1354 if (sibling
== NULL
)
1355 ob_debug_type(OB_DEBUG_APP_BUGS
,
1356 "_NET_RESTACK_WINDOW sent for window %s "
1357 "with invalid sibling 0x%x\n",
1358 client
->title
, e
->xclient
.data
.l
[1]);
1360 if (e
->xclient
.data
.l
[2] == Below
||
1361 e
->xclient
.data
.l
[2] == BottomIf
||
1362 e
->xclient
.data
.l
[2] == Above
||
1363 e
->xclient
.data
.l
[2] == TopIf
||
1364 e
->xclient
.data
.l
[2] == Opposite
)
1366 /* just raise, don't activate */
1367 stacking_restack_request(client
, sibling
,
1368 e
->xclient
.data
.l
[2], FALSE
);
1369 /* send a synthetic ConfigureNotify, cuz this is supposed
1370 to be like a ConfigureRequest. */
1371 client_reconfigure(client
);
1373 ob_debug_type(OB_DEBUG_APP_BUGS
,
1374 "_NET_RESTACK_WINDOW sent for window %s "
1375 "with invalid detail %d\n",
1376 client
->title
, e
->xclient
.data
.l
[2]);
1380 case PropertyNotify
:
1381 /* validate cuz we query stuff off the client here */
1382 if (!client_validate(client
)) break;
1384 /* compress changes to a single property into a single change */
1385 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1389 /* XXX: it would be nice to compress ALL changes to a property,
1390 not just changes in a row without other props between. */
1392 a
= ce
.xproperty
.atom
;
1393 b
= e
->xproperty
.atom
;
1397 if ((a
== prop_atoms
.net_wm_name
||
1398 a
== prop_atoms
.wm_name
||
1399 a
== prop_atoms
.net_wm_icon_name
||
1400 a
== prop_atoms
.wm_icon_name
)
1402 (b
== prop_atoms
.net_wm_name
||
1403 b
== prop_atoms
.wm_name
||
1404 b
== prop_atoms
.net_wm_icon_name
||
1405 b
== prop_atoms
.wm_icon_name
)) {
1408 if (a
== prop_atoms
.net_wm_icon
&&
1409 b
== prop_atoms
.net_wm_icon
)
1412 XPutBackEvent(ob_display
, &ce
);
1416 msgtype
= e
->xproperty
.atom
;
1417 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1418 client_update_normal_hints(client
);
1419 /* normal hints can make a window non-resizable */
1420 client_setup_decor_and_functions(client
);
1421 } else if (msgtype
== XA_WM_HINTS
) {
1422 client_update_wmhints(client
);
1423 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1424 client_update_transient_for(client
);
1425 client_get_type_and_transientness(client
);
1426 /* type may have changed, so update the layer */
1427 client_calc_layer(client
);
1428 client_setup_decor_and_functions(client
);
1429 } else if (msgtype
== prop_atoms
.net_wm_name
||
1430 msgtype
== prop_atoms
.wm_name
||
1431 msgtype
== prop_atoms
.net_wm_icon_name
||
1432 msgtype
== prop_atoms
.wm_icon_name
) {
1433 client_update_title(client
);
1434 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1435 client_update_protocols(client
);
1436 client_setup_decor_and_functions(client
);
1438 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1439 client_update_strut(client
);
1441 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1442 client_update_icons(client
);
1444 else if (msgtype
== prop_atoms
.net_wm_icon_geometry
) {
1445 client_update_icon_geometry(client
);
1447 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1448 client_update_user_time(client
);
1450 else if (msgtype
== prop_atoms
.net_wm_user_time_window
) {
1451 client_update_user_time_window(client
);
1454 else if (msgtype
== prop_atoms
.net_wm_sync_request_counter
) {
1455 client_update_sync_request_counter(client
);
1458 case ColormapNotify
:
1459 client_update_colormap(client
, e
->xcolormap
.colormap
);
1464 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1465 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1466 frame_adjust_shape(client
->frame
);
1472 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1476 if (e
->xbutton
.button
== 1)
1477 stacking_raise(DOCK_AS_WINDOW(s
));
1478 else if (e
->xbutton
.button
== 2)
1479 stacking_lower(DOCK_AS_WINDOW(s
));
1490 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1494 dock_app_drag(app
, &e
->xmotion
);
1497 if (app
->ignore_unmaps
) {
1498 app
->ignore_unmaps
--;
1501 dock_remove(app
, TRUE
);
1504 dock_remove(app
, FALSE
);
1506 case ReparentNotify
:
1507 dock_remove(app
, FALSE
);
1509 case ConfigureNotify
:
1510 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1515 static ObMenuFrame
* find_active_menu()
1518 ObMenuFrame
*ret
= NULL
;
1520 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1529 static ObMenuFrame
* find_active_or_last_menu()
1531 ObMenuFrame
*ret
= NULL
;
1533 ret
= find_active_menu();
1534 if (!ret
&& menu_frame_visible
)
1535 ret
= menu_frame_visible
->data
;
1539 static gboolean
event_handle_menu_keyboard(XEvent
*ev
)
1541 guint keycode
, state
;
1544 gboolean ret
= TRUE
;
1546 keycode
= ev
->xkey
.keycode
;
1547 state
= ev
->xkey
.state
;
1548 unikey
= translate_unichar(keycode
);
1550 frame
= find_active_or_last_menu();
1554 else if (keycode
== ob_keycode(OB_KEY_ESCAPE
) && state
== 0) {
1555 /* Escape goes to the parent menu or closes the last one */
1557 menu_frame_select(frame
, NULL
, TRUE
);
1559 menu_frame_hide_all();
1562 else if (keycode
== ob_keycode(OB_KEY_RETURN
) && (state
== 0 ||
1563 state
== ControlMask
))
1565 /* Enter runs the active item or goes into the submenu.
1566 Control-Enter runs it without closing the menu. */
1568 menu_frame_select_next(frame
->child
);
1570 menu_entry_frame_execute(frame
->selected
, state
, ev
->xkey
.time
);
1573 else if (keycode
== ob_keycode(OB_KEY_LEFT
) && ev
->xkey
.state
== 0) {
1574 /* Left goes to the parent menu */
1575 menu_frame_select(frame
, NULL
, TRUE
);
1578 else if (keycode
== ob_keycode(OB_KEY_RIGHT
) && ev
->xkey
.state
== 0) {
1579 /* Right goes to the selected submenu */
1580 if (frame
->child
) menu_frame_select_next(frame
->child
);
1583 else if (keycode
== ob_keycode(OB_KEY_UP
) && state
== 0) {
1584 menu_frame_select_previous(frame
);
1587 else if (keycode
== ob_keycode(OB_KEY_DOWN
) && state
== 0) {
1588 menu_frame_select_next(frame
);
1591 /* keyboard accelerator shortcuts. (allow controlmask) */
1592 else if ((ev
->xkey
.state
& ~ControlMask
) == 0 &&
1593 /* was it a valid key? */
1595 /* don't bother if the menu is empty. */
1600 ObMenuEntryFrame
*found
= NULL
;
1601 guint num_found
= 0;
1603 /* start after the selected one */
1604 start
= frame
->entries
;
1605 if (frame
->selected
) {
1606 for (it
= start
; frame
->selected
!= it
->data
; it
= g_list_next(it
))
1607 g_assert(it
!= NULL
); /* nothing was selected? */
1608 /* next with wraparound */
1609 start
= g_list_next(it
);
1610 if (start
== NULL
) start
= frame
->entries
;
1615 ObMenuEntryFrame
*e
= it
->data
;
1616 gunichar entrykey
= 0;
1618 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1619 entrykey
= e
->entry
->data
.normal
.shortcut
;
1620 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1621 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1623 if (unikey
== entrykey
) {
1624 if (found
== NULL
) found
= e
;
1628 /* next with wraparound */
1629 it
= g_list_next(it
);
1630 if (it
== NULL
) it
= frame
->entries
;
1631 } while (it
!= start
);
1634 if (found
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
1637 menu_frame_select(frame
, found
, TRUE
);
1638 usleep(50000); /* highlight the item for a short bit so the
1639 user can see what happened */
1640 menu_entry_frame_execute(found
, state
, ev
->xkey
.time
);
1642 menu_frame_select(frame
, found
, TRUE
);
1644 menu_frame_select_next(frame
->child
);
1655 static gboolean
event_handle_menu(XEvent
*ev
)
1658 ObMenuEntryFrame
*e
;
1659 gboolean ret
= TRUE
;
1663 if ((ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5)
1666 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1667 ev
->xbutton
.y_root
)))
1668 menu_entry_frame_execute(e
, ev
->xbutton
.state
,
1671 menu_frame_hide_all();
1675 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1676 if (e
->ignore_enters
)
1679 menu_frame_select(e
->frame
, e
, FALSE
);
1683 /*ignore leaves when we're already in the window */
1684 if (ev
->xcrossing
.detail
== NotifyInferior
)
1687 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1688 (f
= find_active_menu()) && f
->selected
== e
&&
1689 e
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1691 menu_frame_select(e
->frame
, NULL
, FALSE
);
1695 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1696 ev
->xmotion
.y_root
)))
1697 menu_frame_select(e
->frame
, e
, FALSE
);
1700 ret
= event_handle_menu_keyboard(ev
);
1706 static void event_handle_user_input(ObClient
*client
, XEvent
*e
)
1708 g_assert(e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
1709 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
1710 e
->type
== KeyRelease
);
1712 if (menu_frame_visible
) {
1713 if (event_handle_menu(e
))
1714 /* don't use the event if the menu used it, but if the menu
1715 didn't use it and it's a keypress that is bound, it will
1716 close the menu and be used */
1720 /* if the keyboard interactive action uses the event then dont
1721 use it for bindings. likewise is moveresize uses the event. */
1722 if (!keyboard_process_interactive_grab(e
, &client
) &&
1723 !(moveresize_in_progress
&& moveresize_event(e
)))
1725 if (moveresize_in_progress
)
1726 /* make further actions work on the client being
1728 client
= moveresize_client
;
1730 menu_can_hide
= FALSE
;
1731 ob_main_loop_timeout_add(ob_main_loop
,
1732 config_menu_hide_delay
* 1000,
1733 menu_hide_delay_func
,
1734 NULL
, g_direct_equal
, NULL
);
1736 if (e
->type
== ButtonPress
||
1737 e
->type
== ButtonRelease
||
1738 e
->type
== MotionNotify
)
1740 /* the frame may not be "visible" but they can still click on it
1741 in the case where it is animating before disappearing */
1742 if (!client
|| !frame_iconify_animating(client
->frame
))
1743 mouse_event(client
, e
);
1744 } else if (e
->type
== KeyPress
) {
1745 keyboard_event((focus_cycle_target
? focus_cycle_target
:
1746 (client
? client
: focus_client
)), e
);
1751 static gboolean
menu_hide_delay_func(gpointer data
)
1753 menu_can_hide
= TRUE
;
1754 return FALSE
; /* no repeat */
1757 static void focus_delay_dest(gpointer data
)
1762 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
1764 const ObFocusDelayData
*f1
= d1
;
1765 return f1
->client
== d2
;
1768 static gboolean
focus_delay_func(gpointer data
)
1770 ObFocusDelayData
*d
= data
;
1771 Time old
= event_curtime
;
1773 event_curtime
= d
->time
;
1774 if (focus_client
!= d
->client
) {
1775 if (client_focus(d
->client
) && config_focus_raise
)
1776 stacking_raise(CLIENT_AS_WINDOW(d
->client
));
1778 event_curtime
= old
;
1779 return FALSE
; /* no repeat */
1782 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1784 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1788 void event_halt_focus_delay()
1790 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1793 static Bool
event_look_for_enters(Display
*d
, XEvent
*e
, XPointer arg
)
1795 if (e
->type
== EnterNotify
&&
1796 /* these types aren't used for focusing */
1797 !(e
->xcrossing
.mode
== NotifyGrab
||
1798 e
->xcrossing
.mode
== NotifyUngrab
||
1799 e
->xcrossing
.detail
== NotifyInferior
))
1803 /* found an enter for that leave, ignore it if it's going to
1805 win
= g_hash_table_lookup(window_map
, &e
->xany
.window
);
1806 if (win
&& WINDOW_IS_CLIENT(win
))
1807 ++ignore_enter_focus
;
1809 return False
; /* don't disrupt the queue order, just count them */
1812 void event_ignore_all_queued_enters()
1816 XSync(ob_display
, FALSE
);
1818 /* count the events without disrupting them */
1819 ignore_enter_focus
= 0;
1820 XCheckIfEvent(ob_display
, &e
, event_look_for_enters
, NULL
);
1823 static gboolean
is_enter_focus_event_ignored(XEvent
*e
)
1825 g_assert(e
->type
== EnterNotify
&&
1826 !(e
->xcrossing
.mode
== NotifyGrab
||
1827 e
->xcrossing
.mode
== NotifyUngrab
||
1828 e
->xcrossing
.detail
== NotifyInferior
));
1830 ob_debug_type(OB_DEBUG_FOCUS
, "# enters ignored: %d\n",
1831 ignore_enter_focus
);
1833 if (ignore_enter_focus
) {
1834 --ignore_enter_focus
;
1840 gboolean
event_time_after(Time t1
, Time t2
)
1842 g_assert(t1
!= CurrentTime
);
1843 g_assert(t2
!= CurrentTime
);
1846 Timestamp values wrap around (after about 49.7 days). The server, given
1847 its current time is represented by timestamp T, always interprets
1848 timestamps from clients by treating half of the timestamp space as being
1849 later in time than T.
1850 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
1853 /* TIME_HALF is half of the number space of a Time type variable */
1854 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
1856 if (t2
>= TIME_HALF
)
1857 /* t2 is in the second half so t1 might wrap around and be smaller than
1859 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
1861 /* t2 is in the first half so t1 has to come after it */
1862 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);