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
= ce
.xmotion
.x
;
274 e
->xmotion
.y
= ce
.xmotion
.y
;
275 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
276 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
283 static gboolean
wanted_focusevent(XEvent
*e
, gboolean in_client_only
)
285 gint mode
= e
->xfocus
.mode
;
286 gint detail
= e
->xfocus
.detail
;
287 Window win
= e
->xany
.window
;
289 if (e
->type
== FocusIn
) {
290 /* These are ones we never want.. */
292 /* This means focus was given by a keyboard/mouse grab. */
293 if (mode
== NotifyGrab
)
295 /* This means focus was given back from a keyboard/mouse grab. */
296 if (mode
== NotifyUngrab
)
299 /* These are the ones we want.. */
301 if (win
== RootWindow(ob_display
, ob_screen
)) {
302 /* If looking for a focus in on a client, then always return
303 FALSE for focus in's to the root window */
306 /* This means focus reverted off of a client */
307 else if (detail
== NotifyPointerRoot
||
308 detail
== NotifyDetailNone
||
309 detail
== NotifyInferior
||
310 /* This means focus got here from another screen */
311 detail
== NotifyNonlinear
)
317 /* It was on a client, was it a valid one?
318 It's possible to get a FocusIn event for a client that was managed
321 if (in_client_only
) {
322 ObWindow
*w
= g_hash_table_lookup(window_map
, &e
->xfocus
.window
);
323 if (!w
|| !WINDOW_IS_CLIENT(w
))
327 /* This means focus reverted to parent from the client (this
328 happens often during iconify animation) */
329 if (detail
== NotifyInferior
)
333 /* This means focus moved from the root window to a client */
334 if (detail
== NotifyVirtual
)
336 /* This means focus moved from one client to another */
337 if (detail
== NotifyNonlinearVirtual
)
343 g_assert(e
->type
== FocusOut
);
345 /* These are ones we never want.. */
347 /* This means focus was taken by a keyboard/mouse grab. */
348 if (mode
== NotifyGrab
)
350 /* This means focus was grabbed on a window and it was released. */
351 if (mode
== NotifyUngrab
)
354 /* Focus left the root window revertedto state */
355 if (win
== RootWindow(ob_display
, ob_screen
))
358 /* These are the ones we want.. */
360 /* This means focus moved from a client to the root window */
361 if (detail
== NotifyVirtual
)
363 /* This means focus moved from one client to another */
364 if (detail
== NotifyNonlinearVirtual
)
372 static Bool
event_look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
374 return e
->type
== FocusIn
&& wanted_focusevent(e
, FALSE
);
377 static Bool
event_look_for_focusin_client(Display
*d
, XEvent
*e
, XPointer arg
)
379 return e
->type
== FocusIn
&& wanted_focusevent(e
, TRUE
);
382 static void print_focusevent(XEvent
*e
)
384 gint mode
= e
->xfocus
.mode
;
385 gint detail
= e
->xfocus
.detail
;
386 Window win
= e
->xany
.window
;
387 const gchar
*modestr
, *detailstr
;
390 case NotifyNormal
: modestr
="NotifyNormal"; break;
391 case NotifyGrab
: modestr
="NotifyGrab"; break;
392 case NotifyUngrab
: modestr
="NotifyUngrab"; break;
393 case NotifyWhileGrabbed
: modestr
="NotifyWhileGrabbed"; break;
396 case NotifyAncestor
: detailstr
="NotifyAncestor"; break;
397 case NotifyVirtual
: detailstr
="NotifyVirtual"; break;
398 case NotifyInferior
: detailstr
="NotifyInferior"; break;
399 case NotifyNonlinear
: detailstr
="NotifyNonlinear"; break;
400 case NotifyNonlinearVirtual
: detailstr
="NotifyNonlinearVirtual"; break;
401 case NotifyPointer
: detailstr
="NotifyPointer"; break;
402 case NotifyPointerRoot
: detailstr
="NotifyPointerRoot"; break;
403 case NotifyDetailNone
: detailstr
="NotifyDetailNone"; break;
406 if (mode
== NotifyGrab
|| mode
== NotifyUngrab
)
411 ob_debug_type(OB_DEBUG_FOCUS
, "Focus%s 0x%x mode=%s detail=%s\n",
412 (e
->xfocus
.type
== FocusIn
? "In" : "Out"),
418 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
423 if (!wanted_focusevent(e
, FALSE
))
428 if (!wanted_focusevent(e
, FALSE
))
435 static void event_process(const XEvent
*ec
, gpointer data
)
438 ObClient
*client
= NULL
;
440 ObDockApp
*dockapp
= NULL
;
441 ObWindow
*obwin
= NULL
;
442 GSList
*timewinclients
= NULL
;
444 ObEventData
*ed
= data
;
446 /* make a copy we can mangle */
450 window
= event_get_window(e
);
451 if (e
->type
!= PropertyNotify
||
452 !(timewinclients
= propwin_get_clients(window
,
453 OB_PROPWIN_USER_TIME
)))
454 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
455 switch (obwin
->type
) {
457 dock
= WINDOW_AS_DOCK(obwin
);
460 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
463 client
= WINDOW_AS_CLIENT(obwin
);
466 case Window_Internal
:
467 /* not to be used for events */
468 g_assert_not_reached();
473 event_set_curtime(e
);
475 if (event_ignore(e
, client
)) {
482 /* deal with it in the kernel */
484 if (menu_frame_visible
&&
485 (e
->type
== EnterNotify
|| e
->type
== LeaveNotify
))
487 /* crossing events for menu */
488 event_handle_menu(e
);
489 } else if (e
->type
== FocusIn
) {
490 if (e
->xfocus
.detail
== NotifyPointerRoot
||
491 e
->xfocus
.detail
== NotifyDetailNone
||
492 e
->xfocus
.detail
== NotifyInferior
||
493 e
->xfocus
.detail
== NotifyNonlinear
)
497 ob_debug_type(OB_DEBUG_FOCUS
, "Focus went to root, "
498 "pointer root/none or "
499 "the frame window\n");
501 if (e
->xfocus
.detail
== NotifyInferior
||
502 e
->xfocus
.detail
== NotifyNonlinear
)
504 focus_left_screen
= FALSE
;
507 /* If another FocusIn is in the queue then don't fallback yet. This
508 fixes the fun case of:
509 window map -> send focusin
510 window unmap -> get focusout
511 window map -> send focusin
512 get first focus out -> fall back to something (new window
513 hasn't received focus yet, so something else) -> send focusin
514 which means the "something else" is the last thing to get a
515 focusin sent to it, so the new window doesn't end up with focus.
517 But if the other focus in is something like PointerRoot then we
518 still want to fall back.
520 if (XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin_client
,
523 XPutBackEvent(ob_display
, &ce
);
524 ob_debug_type(OB_DEBUG_FOCUS
,
525 " but another FocusIn is coming\n");
527 /* Focus has been reverted.
529 FocusOut events come after UnmapNotify, so we don't need to
530 worry about focusing an invalid window
533 if (!focus_left_screen
)
534 focus_fallback(FALSE
, FALSE
);
539 ob_debug_type(OB_DEBUG_FOCUS
,
540 "Focus went to a window that is already gone\n");
542 /* If you send focus to a window and then it disappears, you can
543 get the FocusIn for it, after it is unmanaged.
544 Just wait for the next FocusOut/FocusIn pair. */
546 else if (client
!= focus_client
) {
547 focus_left_screen
= FALSE
;
548 frame_adjust_focus(client
->frame
, TRUE
);
549 focus_set_client(client
);
550 client_calc_layer(client
);
551 client_bring_helper_windows(client
);
553 } else if (e
->type
== FocusOut
) {
556 /* Look for the followup FocusIn */
557 if (!XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin
, NULL
)) {
558 /* There is no FocusIn, this means focus went to a window that
559 is not being managed, or a window on another screen. */
563 xerror_set_ignore(TRUE
);
564 if (XGetInputFocus(ob_display
, &win
, &i
) != 0 &&
565 XGetGeometry(ob_display
, win
, &root
, &i
,&i
,&u
,&u
,&u
,&u
) != 0 &&
566 root
!= RootWindow(ob_display
, ob_screen
))
568 ob_debug_type(OB_DEBUG_FOCUS
,
569 "Focus went to another screen !\n");
570 focus_left_screen
= TRUE
;
573 ob_debug_type(OB_DEBUG_FOCUS
,
574 "Focus went to a black hole !\n");
575 xerror_set_ignore(FALSE
);
576 /* nothing is focused */
577 focus_set_client(NULL
);
579 /* Focus moved, so process the FocusIn event */
580 ObEventData ed
= { .ignored
= FALSE
};
581 event_process(&ce
, &ed
);
583 /* The FocusIn was ignored, this means it was on a window
584 that isn't a client. */
585 ob_debug_type(OB_DEBUG_FOCUS
,
586 "Focus went to an unmanaged window 0x%x !\n",
588 focus_fallback(TRUE
, FALSE
);
592 if (client
&& client
!= focus_client
) {
593 frame_adjust_focus(client
->frame
, FALSE
);
594 /* focus_set_client(NULL) has already been called in this
595 section or by focus_fallback */
596 client_calc_layer(client
);
598 } else if (timewinclients
)
599 event_handle_user_time_window_clients(timewinclients
, e
);
601 event_handle_client(client
, e
);
603 event_handle_dockapp(dockapp
, e
);
605 event_handle_dock(dock
, e
);
606 else if (window
== RootWindow(ob_display
, ob_screen
))
607 event_handle_root(e
);
608 else if (e
->type
== MapRequest
)
609 client_manage(window
);
610 else if (e
->type
== ClientMessage
) {
611 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
612 windows that are not managed yet. */
613 if (e
->xclient
.message_type
== prop_atoms
.net_request_frame_extents
) {
614 /* Pretend to manage the client, getting information used to
615 determine its decorations */
616 ObClient
*c
= client_fake_manage(e
->xclient
.window
);
619 /* set the frame extents on the window */
620 vals
[0] = c
->frame
->size
.left
;
621 vals
[1] = c
->frame
->size
.right
;
622 vals
[2] = c
->frame
->size
.top
;
623 vals
[3] = c
->frame
->size
.bottom
;
624 PROP_SETA32(e
->xclient
.window
, net_frame_extents
,
627 /* Free the pretend client */
628 client_fake_unmanage(c
);
631 else if (e
->type
== ConfigureRequest
) {
632 /* unhandled configure requests must be used to configure the
636 xwc
.x
= e
->xconfigurerequest
.x
;
637 xwc
.y
= e
->xconfigurerequest
.y
;
638 xwc
.width
= e
->xconfigurerequest
.width
;
639 xwc
.height
= e
->xconfigurerequest
.height
;
640 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
641 xwc
.sibling
= e
->xconfigurerequest
.above
;
642 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
644 /* we are not to be held responsible if someone sends us an
646 xerror_set_ignore(TRUE
);
647 XConfigureWindow(ob_display
, window
,
648 e
->xconfigurerequest
.value_mask
, &xwc
);
649 xerror_set_ignore(FALSE
);
652 else if (extensions_sync
&&
653 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
655 XSyncAlarmNotifyEvent
*se
= (XSyncAlarmNotifyEvent
*)e
;
656 if (se
->alarm
== moveresize_alarm
&& moveresize_in_progress
)
661 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
662 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
663 e
->type
== KeyRelease
)
665 event_handle_user_input(client
, e
);
668 /* if something happens and it's not from an XEvent, then we don't know
670 event_curtime
= CurrentTime
;
673 static void event_handle_root(XEvent
*e
)
679 ob_debug("Another WM has requested to replace us. Exiting.\n");
684 if (e
->xclient
.format
!= 32) break;
686 msgtype
= e
->xclient
.message_type
;
687 if (msgtype
== prop_atoms
.net_current_desktop
) {
688 guint d
= e
->xclient
.data
.l
[0];
689 if (d
< screen_num_desktops
) {
690 event_curtime
= e
->xclient
.data
.l
[1];
691 if (event_curtime
== 0)
692 ob_debug_type(OB_DEBUG_APP_BUGS
,
693 "_NET_CURRENT_DESKTOP message is missing "
695 screen_set_desktop(d
, TRUE
);
697 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
698 guint d
= e
->xclient
.data
.l
[0];
699 if (d
> 0 && d
<= 1000)
700 screen_set_num_desktops(d
);
701 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
702 screen_show_desktop(e
->xclient
.data
.l
[0] != 0, NULL
);
703 } else if (msgtype
== prop_atoms
.ob_control
) {
704 if (e
->xclient
.data
.l
[0] == 1)
706 else if (e
->xclient
.data
.l
[0] == 2)
711 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
)
712 screen_update_desktop_names();
713 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
714 screen_update_layout();
716 case ConfigureNotify
:
718 XRRUpdateConfiguration(e
);
727 void event_enter_client(ObClient
*client
)
729 g_assert(config_focus_follow
);
731 if (client_enter_focusable(client
) && client_can_focus(client
)) {
732 if (config_focus_delay
) {
733 ObFocusDelayData
*data
;
735 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
737 data
= g_new(ObFocusDelayData
, 1);
738 data
->client
= client
;
739 data
->time
= event_curtime
;
741 ob_main_loop_timeout_add(ob_main_loop
,
744 data
, focus_delay_cmp
, focus_delay_dest
);
746 ObFocusDelayData data
;
747 data
.client
= client
;
748 data
.time
= event_curtime
;
749 focus_delay_func(&data
);
754 static void event_handle_user_time_window_clients(GSList
*l
, XEvent
*e
)
756 g_assert(e
->type
== PropertyNotify
);
757 if (e
->xproperty
.atom
== prop_atoms
.net_wm_user_time
) {
758 for (; l
; l
= g_slist_next(l
))
759 client_update_user_time(l
->data
);
763 static void event_handle_client(ObClient
*client
, XEvent
*e
)
768 static gint px
= -1, py
= -1;
773 /* save where the press occured for the first button pressed */
775 pb
= e
->xbutton
.button
;
780 /* Wheel buttons don't draw because they are an instant click, so it
781 is a waste of resources to go drawing it.
782 if the user is doing an intereactive thing, or has a menu open then
783 the mouse is grabbed (possibly) and if we get these events we don't
784 want to deal with them
786 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5) &&
787 !keyboard_interactively_grabbed() &&
790 /* use where the press occured */
791 con
= frame_context(client
, e
->xbutton
.window
, px
, py
);
792 con
= mouse_button_frame_context(con
, e
->xbutton
.button
,
795 if (e
->type
== ButtonRelease
&& e
->xbutton
.button
== pb
)
796 pb
= 0, px
= py
= -1;
799 case OB_FRAME_CONTEXT_MAXIMIZE
:
800 client
->frame
->max_press
= (e
->type
== ButtonPress
);
801 framerender_frame(client
->frame
);
803 case OB_FRAME_CONTEXT_CLOSE
:
804 client
->frame
->close_press
= (e
->type
== ButtonPress
);
805 framerender_frame(client
->frame
);
807 case OB_FRAME_CONTEXT_ICONIFY
:
808 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
809 framerender_frame(client
->frame
);
811 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
812 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
813 framerender_frame(client
->frame
);
815 case OB_FRAME_CONTEXT_SHADE
:
816 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
817 framerender_frame(client
->frame
);
820 /* nothing changes with clicks for any other contexts */
826 /* when there is a grab on the pointer, we won't get enter/leave
827 notifies, but we still get motion events */
828 if (grab_on_pointer()) break;
830 con
= frame_context(client
, e
->xmotion
.window
,
831 e
->xmotion
.x
, e
->xmotion
.y
);
833 case OB_FRAME_CONTEXT_TITLEBAR
:
834 case OB_FRAME_CONTEXT_TLCORNER
:
835 case OB_FRAME_CONTEXT_TRCORNER
:
836 /* we've left the button area inside the titlebar */
837 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
838 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
839 client
->frame
->close_hover
)
841 client
->frame
->max_hover
= FALSE
;
842 client
->frame
->desk_hover
= FALSE
;
843 client
->frame
->shade_hover
= FALSE
;
844 client
->frame
->iconify_hover
= FALSE
;
845 client
->frame
->close_hover
= FALSE
;
846 frame_adjust_state(client
->frame
);
849 case OB_FRAME_CONTEXT_MAXIMIZE
:
850 if (!client
->frame
->max_hover
) {
851 client
->frame
->max_hover
= TRUE
;
852 frame_adjust_state(client
->frame
);
855 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
856 if (!client
->frame
->desk_hover
) {
857 client
->frame
->desk_hover
= TRUE
;
858 frame_adjust_state(client
->frame
);
861 case OB_FRAME_CONTEXT_SHADE
:
862 if (!client
->frame
->shade_hover
) {
863 client
->frame
->shade_hover
= TRUE
;
864 frame_adjust_state(client
->frame
);
867 case OB_FRAME_CONTEXT_ICONIFY
:
868 if (!client
->frame
->iconify_hover
) {
869 client
->frame
->iconify_hover
= TRUE
;
870 frame_adjust_state(client
->frame
);
873 case OB_FRAME_CONTEXT_CLOSE
:
874 if (!client
->frame
->close_hover
) {
875 client
->frame
->close_hover
= TRUE
;
876 frame_adjust_state(client
->frame
);
884 con
= frame_context(client
, e
->xcrossing
.window
,
885 e
->xcrossing
.x
, e
->xcrossing
.y
);
887 case OB_FRAME_CONTEXT_TITLEBAR
:
888 case OB_FRAME_CONTEXT_TLCORNER
:
889 case OB_FRAME_CONTEXT_TRCORNER
:
890 /* we've left the button area inside the titlebar */
891 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
892 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
893 client
->frame
->close_hover
)
895 client
->frame
->max_hover
= FALSE
;
896 client
->frame
->desk_hover
= FALSE
;
897 client
->frame
->shade_hover
= FALSE
;
898 client
->frame
->iconify_hover
= FALSE
;
899 client
->frame
->close_hover
= FALSE
;
900 frame_adjust_state(client
->frame
);
903 case OB_FRAME_CONTEXT_MAXIMIZE
:
904 client
->frame
->max_hover
= FALSE
;
905 frame_adjust_state(client
->frame
);
907 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
908 client
->frame
->desk_hover
= FALSE
;
909 frame_adjust_state(client
->frame
);
911 case OB_FRAME_CONTEXT_SHADE
:
912 client
->frame
->shade_hover
= FALSE
;
913 frame_adjust_state(client
->frame
);
915 case OB_FRAME_CONTEXT_ICONIFY
:
916 client
->frame
->iconify_hover
= FALSE
;
917 frame_adjust_state(client
->frame
);
919 case OB_FRAME_CONTEXT_CLOSE
:
920 client
->frame
->close_hover
= FALSE
;
921 frame_adjust_state(client
->frame
);
923 case OB_FRAME_CONTEXT_FRAME
:
924 /* When the mouse leaves an animating window, don't use the
925 corresponding enter events. Pretend like the animating window
926 doesn't even exist..! */
927 if (frame_iconify_animating(client
->frame
))
928 event_ignore_all_queued_enters();
930 ob_debug_type(OB_DEBUG_FOCUS
,
931 "%sNotify mode %d detail %d on %lx\n",
932 (e
->type
== EnterNotify
? "Enter" : "Leave"),
934 e
->xcrossing
.detail
, (client
?client
->window
:0));
935 if (keyboard_interactively_grabbed())
937 if (config_focus_follow
&& config_focus_delay
&&
938 /* leave inferior events can happen when the mouse goes onto
939 the window's border and then into the window before the
941 e
->xcrossing
.detail
!= NotifyInferior
)
943 ob_main_loop_timeout_remove_data(ob_main_loop
,
954 con
= frame_context(client
, e
->xcrossing
.window
,
955 e
->xcrossing
.x
, e
->xcrossing
.y
);
957 case OB_FRAME_CONTEXT_MAXIMIZE
:
958 client
->frame
->max_hover
= TRUE
;
959 frame_adjust_state(client
->frame
);
961 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
962 client
->frame
->desk_hover
= TRUE
;
963 frame_adjust_state(client
->frame
);
965 case OB_FRAME_CONTEXT_SHADE
:
966 client
->frame
->shade_hover
= TRUE
;
967 frame_adjust_state(client
->frame
);
969 case OB_FRAME_CONTEXT_ICONIFY
:
970 client
->frame
->iconify_hover
= TRUE
;
971 frame_adjust_state(client
->frame
);
973 case OB_FRAME_CONTEXT_CLOSE
:
974 client
->frame
->close_hover
= TRUE
;
975 frame_adjust_state(client
->frame
);
977 case OB_FRAME_CONTEXT_FRAME
:
978 if (keyboard_interactively_grabbed())
980 if (e
->xcrossing
.mode
== NotifyGrab
||
981 e
->xcrossing
.mode
== NotifyUngrab
||
982 /*ignore enters when we're already in the window */
983 e
->xcrossing
.detail
== NotifyInferior
||
984 is_enter_focus_event_ignored(e
))
986 ob_debug_type(OB_DEBUG_FOCUS
,
987 "%sNotify mode %d detail %d on %lx IGNORED\n",
988 (e
->type
== EnterNotify
? "Enter" : "Leave"),
990 e
->xcrossing
.detail
, client
?client
->window
:0);
993 ob_debug_type(OB_DEBUG_FOCUS
,
994 "%sNotify mode %d detail %d on %lx, "
996 (e
->type
== EnterNotify
? "Enter" : "Leave"),
998 e
->xcrossing
.detail
, (client
?client
->window
:0));
999 if (config_focus_follow
)
1000 event_enter_client(client
);
1008 case ConfigureRequest
:
1010 /* dont compress these unless you're going to watch for property
1011 notifies in between (these can change what the configure would
1013 also you can't compress stacking events
1017 gboolean move
= FALSE
;
1018 gboolean resize
= FALSE
;
1020 /* get the current area */
1021 RECT_TO_DIMS(client
->area
, x
, y
, w
, h
);
1023 ob_debug("ConfigureRequest for \"%s\" desktop %d wmstate %d "
1025 " x %d y %d w %d h %d b %d\n",
1027 screen_desktop
, client
->wmstate
, client
->frame
->visible
,
1028 x
, y
, w
, h
, client
->border_width
);
1030 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
1031 if (client
->border_width
!= e
->xconfigurerequest
.border_width
) {
1032 client
->border_width
= e
->xconfigurerequest
.border_width
;
1034 /* if the border width is changing then that is the same
1035 as requesting a resize, but we don't actually change
1036 the client's border, so it will change their root
1037 coordiantes (since they include the border width) and
1038 we need to a notify then */
1043 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
1044 ObClient
*sibling
= NULL
;
1046 /* get the sibling */
1047 if (e
->xconfigurerequest
.value_mask
& CWSibling
) {
1049 win
= g_hash_table_lookup(window_map
,
1050 &e
->xconfigurerequest
.above
);
1051 if (WINDOW_IS_CLIENT(win
) && WINDOW_AS_CLIENT(win
) != client
)
1052 sibling
= WINDOW_AS_CLIENT(win
);
1055 /* activate it rather than just focus it */
1056 stacking_restack_request(client
, sibling
,
1057 e
->xconfigurerequest
.detail
, TRUE
);
1059 /* if a stacking change moves the window without resizing */
1063 if ((e
->xconfigurerequest
.value_mask
& CWX
) ||
1064 (e
->xconfigurerequest
.value_mask
& CWY
) ||
1065 (e
->xconfigurerequest
.value_mask
& CWWidth
) ||
1066 (e
->xconfigurerequest
.value_mask
& CWHeight
))
1068 if (e
->xconfigurerequest
.value_mask
& CWX
) {
1069 /* don't allow clients to move shaded windows (fvwm does this)
1071 if (!client
->shaded
)
1072 x
= e
->xconfigurerequest
.x
;
1075 if (e
->xconfigurerequest
.value_mask
& CWY
) {
1076 /* don't allow clients to move shaded windows (fvwm does this)
1078 if (!client
->shaded
)
1079 y
= e
->xconfigurerequest
.y
;
1083 if (e
->xconfigurerequest
.value_mask
& CWWidth
) {
1084 w
= e
->xconfigurerequest
.width
;
1087 if (e
->xconfigurerequest
.value_mask
& CWHeight
) {
1088 h
= e
->xconfigurerequest
.height
;
1093 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
1094 "move %d resize %d\n",
1095 e
->xconfigurerequest
.value_mask
& CWX
, x
,
1096 e
->xconfigurerequest
.value_mask
& CWY
, y
,
1097 e
->xconfigurerequest
.value_mask
& CWWidth
, w
,
1098 e
->xconfigurerequest
.value_mask
& CWHeight
, h
,
1101 /* check for broken apps moving to their root position
1103 XXX remove this some day...that would be nice. right now all
1104 kde apps do this when they try activate themselves on another
1105 desktop. eg. open amarok window on desktop 1, switch to desktop
1106 2, click amarok tray icon. it will move by its decoration size.
1108 if (x
!= client
->area
.x
&&
1109 x
== (client
->frame
->area
.x
+ client
->frame
->size
.left
-
1110 (gint
)client
->border_width
) &&
1111 y
!= client
->area
.y
&&
1112 y
== (client
->frame
->area
.y
+ client
->frame
->size
.top
-
1113 (gint
)client
->border_width
) &&
1114 w
== client
->area
.width
&&
1115 h
== client
->area
.height
)
1117 ob_debug_type(OB_DEBUG_APP_BUGS
,
1118 "Application %s is trying to move via "
1119 "ConfigureRequest to it's root window position "
1120 "but it is not using StaticGravity\n",
1126 /* they still requested a move, so don't change whether a
1127 notify is sent or not */
1130 if (move
|| resize
) {
1133 client_try_configure(client
, &x
, &y
, &w
, &h
, &lw
, &lh
, FALSE
);
1135 /* if x was not given, then use gravity to figure out the new
1136 x. the reference point should not be moved */
1137 if ((e
->xconfigurerequest
.value_mask
& CWWidth
&&
1138 !(e
->xconfigurerequest
.value_mask
& CWX
)))
1139 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1140 /* if y was not given, then use gravity to figure out the new
1141 y. the reference point should not be moved */
1142 if ((e
->xconfigurerequest
.value_mask
& CWHeight
&&
1143 !(e
->xconfigurerequest
.value_mask
& CWY
)))
1144 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1146 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1148 /* if they requested something that moves the window, or if
1149 the window is actually being changed then configure it and
1150 send a configure notify to them */
1151 if (move
|| !RECT_EQUAL_DIMS(client
->area
, x
, y
, w
, h
)) {
1152 ob_debug("Granting ConfigureRequest x %d y %d w %d h %d\n",
1154 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1157 /* ignore enter events caused by these like ob actions do */
1158 event_ignore_all_queued_enters();
1163 if (client
->ignore_unmaps
) {
1164 client
->ignore_unmaps
--;
1167 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1168 "ignores left %d\n",
1169 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
1170 client
->ignore_unmaps
);
1171 client_unmanage(client
);
1174 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
1175 client_unmanage(client
);
1177 case ReparentNotify
:
1178 /* this is when the client is first taken captive in the frame */
1179 if (e
->xreparent
.parent
== client
->frame
->window
) break;
1182 This event is quite rare and is usually handled in unmapHandler.
1183 However, if the window is unmapped when the reparent event occurs,
1184 the window manager never sees it because an unmap event is not sent
1185 to an already unmapped window.
1188 /* we don't want the reparent event, put it back on the stack for the
1189 X server to deal with after we unmanage the window */
1190 XPutBackEvent(ob_display
, e
);
1192 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
1193 client_unmanage(client
);
1196 ob_debug("MapRequest for 0x%lx\n", client
->window
);
1197 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
1198 does, we don't want it!
1199 it can happen now when the window is on
1200 another desktop, but we still don't
1202 client_activate(client
, FALSE
, TRUE
);
1205 /* validate cuz we query stuff off the client here */
1206 if (!client_validate(client
)) break;
1208 if (e
->xclient
.format
!= 32) return;
1210 msgtype
= e
->xclient
.message_type
;
1211 if (msgtype
== prop_atoms
.wm_change_state
) {
1212 /* compress changes into a single change */
1213 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1215 /* XXX: it would be nice to compress ALL messages of a
1216 type, not just messages in a row without other
1217 message types between. */
1218 if (ce
.xclient
.message_type
!= msgtype
) {
1219 XPutBackEvent(ob_display
, &ce
);
1222 e
->xclient
= ce
.xclient
;
1224 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1225 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
1226 /* compress changes into a single change */
1227 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1229 /* XXX: it would be nice to compress ALL messages of a
1230 type, not just messages in a row without other
1231 message types between. */
1232 if (ce
.xclient
.message_type
!= msgtype
) {
1233 XPutBackEvent(ob_display
, &ce
);
1236 e
->xclient
= ce
.xclient
;
1238 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1239 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1240 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1242 } else if (msgtype
== prop_atoms
.net_wm_state
) {
1243 /* can't compress these */
1244 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1245 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1246 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1247 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1248 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1250 client_set_state(client
, e
->xclient
.data
.l
[0],
1251 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1253 /* ignore enter events caused by these like ob actions do */
1254 event_ignore_all_queued_enters();
1255 } else if (msgtype
== prop_atoms
.net_close_window
) {
1256 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1257 client_close(client
);
1258 } else if (msgtype
== prop_atoms
.net_active_window
) {
1259 ob_debug("net_active_window for 0x%lx source=%s\n",
1261 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1262 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1263 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1264 /* XXX make use of data.l[2] !? */
1265 if (e
->xclient
.data
.l
[0] == 1 || e
->xclient
.data
.l
[0] == 2) {
1266 event_curtime
= e
->xclient
.data
.l
[1];
1267 if (event_curtime
== 0)
1268 ob_debug_type(OB_DEBUG_APP_BUGS
,
1269 "_NET_ACTIVE_WINDOW message for window %s is"
1270 " missing a timestamp\n", client
->title
);
1272 ob_debug_type(OB_DEBUG_APP_BUGS
,
1273 "_NET_ACTIVE_WINDOW message for window %s is "
1274 "missing source indication\n");
1275 client_activate(client
, FALSE
,
1276 (e
->xclient
.data
.l
[0] == 0 ||
1277 e
->xclient
.data
.l
[0] == 2));
1278 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1279 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1280 client
->window
, e
->xclient
.data
.l
[2]);
1281 if ((Atom
)e
->xclient
.data
.l
[2] ==
1282 prop_atoms
.net_wm_moveresize_size_topleft
||
1283 (Atom
)e
->xclient
.data
.l
[2] ==
1284 prop_atoms
.net_wm_moveresize_size_top
||
1285 (Atom
)e
->xclient
.data
.l
[2] ==
1286 prop_atoms
.net_wm_moveresize_size_topright
||
1287 (Atom
)e
->xclient
.data
.l
[2] ==
1288 prop_atoms
.net_wm_moveresize_size_right
||
1289 (Atom
)e
->xclient
.data
.l
[2] ==
1290 prop_atoms
.net_wm_moveresize_size_right
||
1291 (Atom
)e
->xclient
.data
.l
[2] ==
1292 prop_atoms
.net_wm_moveresize_size_bottomright
||
1293 (Atom
)e
->xclient
.data
.l
[2] ==
1294 prop_atoms
.net_wm_moveresize_size_bottom
||
1295 (Atom
)e
->xclient
.data
.l
[2] ==
1296 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1297 (Atom
)e
->xclient
.data
.l
[2] ==
1298 prop_atoms
.net_wm_moveresize_size_left
||
1299 (Atom
)e
->xclient
.data
.l
[2] ==
1300 prop_atoms
.net_wm_moveresize_move
||
1301 (Atom
)e
->xclient
.data
.l
[2] ==
1302 prop_atoms
.net_wm_moveresize_size_keyboard
||
1303 (Atom
)e
->xclient
.data
.l
[2] ==
1304 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1306 moveresize_start(client
, e
->xclient
.data
.l
[0],
1307 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1308 e
->xclient
.data
.l
[2]);
1310 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1311 prop_atoms
.net_wm_moveresize_cancel
)
1312 moveresize_end(TRUE
);
1313 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1314 gint ograv
, x
, y
, w
, h
;
1316 ograv
= client
->gravity
;
1318 if (e
->xclient
.data
.l
[0] & 0xff)
1319 client
->gravity
= e
->xclient
.data
.l
[0] & 0xff;
1321 if (e
->xclient
.data
.l
[0] & 1 << 8)
1322 x
= e
->xclient
.data
.l
[1];
1325 if (e
->xclient
.data
.l
[0] & 1 << 9)
1326 y
= e
->xclient
.data
.l
[2];
1330 if (e
->xclient
.data
.l
[0] & 1 << 10) {
1331 w
= e
->xclient
.data
.l
[3];
1333 /* if x was not given, then use gravity to figure out the new
1334 x. the reference point should not be moved */
1335 if (!(e
->xclient
.data
.l
[0] & 1 << 8))
1336 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1339 w
= client
->area
.width
;
1341 if (e
->xclient
.data
.l
[0] & 1 << 11) {
1342 h
= e
->xclient
.data
.l
[4];
1344 /* if y was not given, then use gravity to figure out the new
1345 y. the reference point should not be moved */
1346 if (!(e
->xclient
.data
.l
[0] & 1 << 9))
1347 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1350 h
= client
->area
.height
;
1352 ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)\n",
1353 e
->xclient
.data
.l
[0] & 1 << 8, x
,
1354 e
->xclient
.data
.l
[0] & 1 << 9, y
,
1357 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1359 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1361 client
->gravity
= ograv
;
1363 /* ignore enter events caused by these like ob actions do */
1364 event_ignore_all_queued_enters();
1365 } else if (msgtype
== prop_atoms
.net_restack_window
) {
1366 if (e
->xclient
.data
.l
[0] != 2) {
1367 ob_debug_type(OB_DEBUG_APP_BUGS
,
1368 "_NET_RESTACK_WINDOW sent for window %s with "
1369 "invalid source indication %ld\n",
1370 client
->title
, e
->xclient
.data
.l
[0]);
1372 ObClient
*sibling
= NULL
;
1373 if (e
->xclient
.data
.l
[1]) {
1374 ObWindow
*win
= g_hash_table_lookup
1375 (window_map
, &e
->xclient
.data
.l
[1]);
1376 if (WINDOW_IS_CLIENT(win
) &&
1377 WINDOW_AS_CLIENT(win
) != client
)
1379 sibling
= WINDOW_AS_CLIENT(win
);
1381 if (sibling
== NULL
)
1382 ob_debug_type(OB_DEBUG_APP_BUGS
,
1383 "_NET_RESTACK_WINDOW sent for window %s "
1384 "with invalid sibling 0x%x\n",
1385 client
->title
, e
->xclient
.data
.l
[1]);
1387 if (e
->xclient
.data
.l
[2] == Below
||
1388 e
->xclient
.data
.l
[2] == BottomIf
||
1389 e
->xclient
.data
.l
[2] == Above
||
1390 e
->xclient
.data
.l
[2] == TopIf
||
1391 e
->xclient
.data
.l
[2] == Opposite
)
1393 /* just raise, don't activate */
1394 stacking_restack_request(client
, sibling
,
1395 e
->xclient
.data
.l
[2], FALSE
);
1396 /* send a synthetic ConfigureNotify, cuz this is supposed
1397 to be like a ConfigureRequest. */
1398 client_reconfigure(client
);
1400 ob_debug_type(OB_DEBUG_APP_BUGS
,
1401 "_NET_RESTACK_WINDOW sent for window %s "
1402 "with invalid detail %d\n",
1403 client
->title
, e
->xclient
.data
.l
[2]);
1407 case PropertyNotify
:
1408 /* validate cuz we query stuff off the client here */
1409 if (!client_validate(client
)) break;
1411 /* compress changes to a single property into a single change */
1412 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1416 /* XXX: it would be nice to compress ALL changes to a property,
1417 not just changes in a row without other props between. */
1419 a
= ce
.xproperty
.atom
;
1420 b
= e
->xproperty
.atom
;
1424 if ((a
== prop_atoms
.net_wm_name
||
1425 a
== prop_atoms
.wm_name
||
1426 a
== prop_atoms
.net_wm_icon_name
||
1427 a
== prop_atoms
.wm_icon_name
)
1429 (b
== prop_atoms
.net_wm_name
||
1430 b
== prop_atoms
.wm_name
||
1431 b
== prop_atoms
.net_wm_icon_name
||
1432 b
== prop_atoms
.wm_icon_name
)) {
1435 if (a
== prop_atoms
.net_wm_icon
&&
1436 b
== prop_atoms
.net_wm_icon
)
1439 XPutBackEvent(ob_display
, &ce
);
1443 msgtype
= e
->xproperty
.atom
;
1444 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1445 client_update_normal_hints(client
);
1446 /* normal hints can make a window non-resizable */
1447 client_setup_decor_and_functions(client
, TRUE
);
1448 } else if (msgtype
== XA_WM_HINTS
) {
1449 client_update_wmhints(client
);
1450 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1451 client_update_transient_for(client
);
1452 client_get_type_and_transientness(client
);
1453 /* type may have changed, so update the layer */
1454 client_calc_layer(client
);
1455 client_setup_decor_and_functions(client
, TRUE
);
1456 } else if (msgtype
== prop_atoms
.net_wm_name
||
1457 msgtype
== prop_atoms
.wm_name
||
1458 msgtype
== prop_atoms
.net_wm_icon_name
||
1459 msgtype
== prop_atoms
.wm_icon_name
) {
1460 client_update_title(client
);
1461 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1462 client_update_protocols(client
);
1463 client_setup_decor_and_functions(client
, TRUE
);
1465 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1466 client_update_strut(client
);
1468 else if (msgtype
== prop_atoms
.net_wm_strut_partial
) {
1469 client_update_strut(client
);
1471 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1472 client_update_icons(client
);
1474 else if (msgtype
== prop_atoms
.net_wm_icon_geometry
) {
1475 client_update_icon_geometry(client
);
1477 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1478 client_update_user_time(client
);
1480 else if (msgtype
== prop_atoms
.net_wm_user_time_window
) {
1481 client_update_user_time_window(client
);
1484 else if (msgtype
== prop_atoms
.net_wm_sync_request_counter
) {
1485 client_update_sync_request_counter(client
);
1489 case ColormapNotify
:
1490 client_update_colormap(client
, e
->xcolormap
.colormap
);
1495 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1496 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1497 frame_adjust_shape(client
->frame
);
1503 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1507 if (e
->xbutton
.button
== 1)
1508 stacking_raise(DOCK_AS_WINDOW(s
));
1509 else if (e
->xbutton
.button
== 2)
1510 stacking_lower(DOCK_AS_WINDOW(s
));
1516 /* don't hide when moving into a dock app */
1517 if (e
->xcrossing
.detail
!= NotifyInferior
)
1523 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1527 dock_app_drag(app
, &e
->xmotion
);
1530 if (app
->ignore_unmaps
) {
1531 app
->ignore_unmaps
--;
1534 dock_remove(app
, TRUE
);
1537 dock_remove(app
, FALSE
);
1539 case ReparentNotify
:
1540 dock_remove(app
, FALSE
);
1542 case ConfigureNotify
:
1543 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1548 static ObMenuFrame
* find_active_menu()
1551 ObMenuFrame
*ret
= NULL
;
1553 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1562 static ObMenuFrame
* find_active_or_last_menu()
1564 ObMenuFrame
*ret
= NULL
;
1566 ret
= find_active_menu();
1567 if (!ret
&& menu_frame_visible
)
1568 ret
= menu_frame_visible
->data
;
1572 static gboolean
event_handle_menu_keyboard(XEvent
*ev
)
1574 guint keycode
, state
;
1577 gboolean ret
= TRUE
;
1579 keycode
= ev
->xkey
.keycode
;
1580 state
= ev
->xkey
.state
;
1581 unikey
= translate_unichar(keycode
);
1583 frame
= find_active_or_last_menu();
1587 else if (keycode
== ob_keycode(OB_KEY_ESCAPE
) && state
== 0)
1588 menu_frame_hide_all();
1590 else if (keycode
== ob_keycode(OB_KEY_RETURN
) && (state
== 0 ||
1591 state
== ControlMask
))
1593 /* Enter runs the active item or goes into the submenu.
1594 Control-Enter runs it without closing the menu. */
1596 menu_frame_select_next(frame
->child
);
1597 else if (frame
->selected
)
1598 menu_entry_frame_execute(frame
->selected
, state
, ev
->xkey
.time
);
1601 else if (keycode
== ob_keycode(OB_KEY_LEFT
) && ev
->xkey
.state
== 0) {
1602 /* Left goes to the parent menu */
1603 menu_frame_select(frame
, NULL
, TRUE
);
1606 else if (keycode
== ob_keycode(OB_KEY_RIGHT
) && ev
->xkey
.state
== 0) {
1607 /* Right goes to the selected submenu */
1608 if (frame
->child
) menu_frame_select_next(frame
->child
);
1611 else if (keycode
== ob_keycode(OB_KEY_UP
) && state
== 0) {
1612 menu_frame_select_previous(frame
);
1615 else if (keycode
== ob_keycode(OB_KEY_DOWN
) && state
== 0) {
1616 menu_frame_select_next(frame
);
1619 /* keyboard accelerator shortcuts. (allow controlmask) */
1620 else if ((ev
->xkey
.state
& ~ControlMask
) == 0 &&
1621 /* was it a valid key? */
1623 /* don't bother if the menu is empty. */
1628 ObMenuEntryFrame
*found
= NULL
;
1629 guint num_found
= 0;
1631 /* start after the selected one */
1632 start
= frame
->entries
;
1633 if (frame
->selected
) {
1634 for (it
= start
; frame
->selected
!= it
->data
; it
= g_list_next(it
))
1635 g_assert(it
!= NULL
); /* nothing was selected? */
1636 /* next with wraparound */
1637 start
= g_list_next(it
);
1638 if (start
== NULL
) start
= frame
->entries
;
1643 ObMenuEntryFrame
*e
= it
->data
;
1644 gunichar entrykey
= 0;
1646 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1647 entrykey
= e
->entry
->data
.normal
.shortcut
;
1648 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1649 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1651 if (unikey
== entrykey
) {
1652 if (found
== NULL
) found
= e
;
1656 /* next with wraparound */
1657 it
= g_list_next(it
);
1658 if (it
== NULL
) it
= frame
->entries
;
1659 } while (it
!= start
);
1662 if (found
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
1665 menu_frame_select(frame
, found
, TRUE
);
1666 usleep(50000); /* highlight the item for a short bit so the
1667 user can see what happened */
1668 menu_entry_frame_execute(found
, state
, ev
->xkey
.time
);
1670 menu_frame_select(frame
, found
, TRUE
);
1672 menu_frame_select_next(frame
->child
);
1683 static gboolean
event_handle_menu(XEvent
*ev
)
1686 ObMenuEntryFrame
*e
;
1687 gboolean ret
= TRUE
;
1691 if ((ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5)
1694 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1695 ev
->xbutton
.y_root
)))
1697 menu_frame_select(e
->frame
, e
, TRUE
);
1698 menu_entry_frame_execute(e
, ev
->xbutton
.state
,
1702 menu_frame_hide_all();
1706 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1707 if (e
->ignore_enters
)
1709 else if (!(f
= find_active_menu()) ||
1711 f
->parent
== e
->frame
||
1712 f
->child
== e
->frame
)
1713 menu_frame_select(e
->frame
, e
, FALSE
);
1717 /*ignore leaves when we're already in the window */
1718 if (ev
->xcrossing
.detail
== NotifyInferior
)
1721 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1722 (f
= find_active_menu()) && f
->selected
== e
&&
1723 e
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1725 menu_frame_select(e
->frame
, NULL
, FALSE
);
1729 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1730 ev
->xmotion
.y_root
)))
1731 if (!(f
= find_active_menu()) ||
1733 f
->parent
== e
->frame
||
1734 f
->child
== e
->frame
)
1735 menu_frame_select(e
->frame
, e
, FALSE
);
1738 ret
= event_handle_menu_keyboard(ev
);
1744 static void event_handle_user_input(ObClient
*client
, XEvent
*e
)
1746 g_assert(e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
1747 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
1748 e
->type
== KeyRelease
);
1750 if (menu_frame_visible
) {
1751 if (event_handle_menu(e
))
1752 /* don't use the event if the menu used it, but if the menu
1753 didn't use it and it's a keypress that is bound, it will
1754 close the menu and be used */
1758 /* if the keyboard interactive action uses the event then dont
1759 use it for bindings. likewise is moveresize uses the event. */
1760 if (!keyboard_process_interactive_grab(e
, &client
) &&
1761 !(moveresize_in_progress
&& moveresize_event(e
)))
1763 if (moveresize_in_progress
)
1764 /* make further actions work on the client being
1766 client
= moveresize_client
;
1768 menu_can_hide
= FALSE
;
1769 ob_main_loop_timeout_add(ob_main_loop
,
1770 config_menu_hide_delay
* 1000,
1771 menu_hide_delay_func
,
1772 NULL
, g_direct_equal
, NULL
);
1774 if (e
->type
== ButtonPress
||
1775 e
->type
== ButtonRelease
||
1776 e
->type
== MotionNotify
)
1778 /* the frame may not be "visible" but they can still click on it
1779 in the case where it is animating before disappearing */
1780 if (!client
|| !frame_iconify_animating(client
->frame
))
1781 mouse_event(client
, e
);
1782 } else if (e
->type
== KeyPress
) {
1783 keyboard_event((focus_cycle_target
? focus_cycle_target
:
1784 (client
? client
: focus_client
)), e
);
1789 static gboolean
menu_hide_delay_func(gpointer data
)
1791 menu_can_hide
= TRUE
;
1792 return FALSE
; /* no repeat */
1795 static void focus_delay_dest(gpointer data
)
1800 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
1802 const ObFocusDelayData
*f1
= d1
;
1803 return f1
->client
== d2
;
1806 static gboolean
focus_delay_func(gpointer data
)
1808 ObFocusDelayData
*d
= data
;
1809 Time old
= event_curtime
;
1811 event_curtime
= d
->time
;
1812 if (focus_client
!= d
->client
) {
1813 if (client_focus(d
->client
) && config_focus_raise
)
1814 stacking_raise(CLIENT_AS_WINDOW(d
->client
));
1816 event_curtime
= old
;
1817 return FALSE
; /* no repeat */
1820 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1822 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1826 void event_halt_focus_delay()
1828 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1831 static Bool
event_look_for_enters(Display
*d
, XEvent
*e
, XPointer arg
)
1833 if (e
->type
== EnterNotify
&&
1834 /* these types aren't used for focusing */
1835 !(e
->xcrossing
.mode
== NotifyGrab
||
1836 e
->xcrossing
.mode
== NotifyUngrab
||
1837 e
->xcrossing
.detail
== NotifyInferior
))
1841 /* found an enter for that leave, ignore it if it's going to
1843 win
= g_hash_table_lookup(window_map
, &e
->xany
.window
);
1844 if (win
&& WINDOW_IS_CLIENT(win
))
1845 ++ignore_enter_focus
;
1847 return False
; /* don't disrupt the queue order, just count them */
1850 void event_ignore_all_queued_enters()
1854 XSync(ob_display
, FALSE
);
1856 /* count the events without disrupting them */
1857 ignore_enter_focus
= 0;
1858 XCheckIfEvent(ob_display
, &e
, event_look_for_enters
, NULL
);
1861 static gboolean
is_enter_focus_event_ignored(XEvent
*e
)
1863 g_assert(e
->type
== EnterNotify
&&
1864 !(e
->xcrossing
.mode
== NotifyGrab
||
1865 e
->xcrossing
.mode
== NotifyUngrab
||
1866 e
->xcrossing
.detail
== NotifyInferior
));
1868 ob_debug_type(OB_DEBUG_FOCUS
, "# enters ignored: %d\n",
1869 ignore_enter_focus
);
1871 if (ignore_enter_focus
) {
1872 --ignore_enter_focus
;
1878 void event_cancel_all_key_grabs()
1880 if (keyboard_interactively_grabbed())
1881 keyboard_interactive_cancel();
1882 else if (menu_frame_visible
)
1883 menu_frame_hide_all();
1884 else if (grab_on_keyboard())
1887 /* If we don't have the keyboard grabbed, then ungrab it with
1888 XUngrabKeyboard, so that there is not a passive grab left
1889 on from the KeyPress. If the grab is left on, and focus
1890 moves during that time, it will be NotifyWhileGrabbed, and
1891 applications like to ignore those! */
1892 if (!keyboard_interactively_grabbed())
1893 XUngrabKeyboard(ob_display
, CurrentTime
);
1897 gboolean
event_time_after(Time t1
, Time t2
)
1899 g_assert(t1
!= CurrentTime
);
1900 g_assert(t2
!= CurrentTime
);
1903 Timestamp values wrap around (after about 49.7 days). The server, given
1904 its current time is represented by timestamp T, always interprets
1905 timestamps from clients by treating half of the timestamp space as being
1906 later in time than T.
1907 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
1910 /* TIME_HALF is half of the number space of a Time type variable */
1911 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
1913 if (t2
>= TIME_HALF
)
1914 /* t2 is in the second half so t1 might wrap around and be smaller than
1916 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
1918 /* t2 is in the first half so t1 has to come after it */
1919 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);