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
) {
491 e
->xfocus
.detail
== NotifyInferior
)
493 ob_debug_type(OB_DEBUG_FOCUS
,
494 "Focus went to the frame window");
496 focus_left_screen
= FALSE
;
498 focus_fallback(FALSE
, FALSE
);
500 /* We don't get a FocusOut for this case, because it's just moving
501 from our Inferior up to us. This happens when iconifying a
502 window with RevertToParent focus */
503 frame_adjust_focus(client
->frame
, FALSE
);
504 /* focus_set_client(NULL) has already been called */
505 client_calc_layer(client
);
507 if (e
->xfocus
.detail
== NotifyPointerRoot
||
508 e
->xfocus
.detail
== NotifyDetailNone
||
509 e
->xfocus
.detail
== NotifyInferior
||
510 e
->xfocus
.detail
== NotifyNonlinear
)
514 ob_debug_type(OB_DEBUG_FOCUS
,
515 "Focus went to root or pointer root/none\n");
517 if (e
->xfocus
.detail
== NotifyInferior
||
518 e
->xfocus
.detail
== NotifyNonlinear
)
520 focus_left_screen
= FALSE
;
523 /* If another FocusIn is in the queue then don't fallback yet. This
524 fixes the fun case of:
525 window map -> send focusin
526 window unmap -> get focusout
527 window map -> send focusin
528 get first focus out -> fall back to something (new window
529 hasn't received focus yet, so something else) -> send focusin
530 which means the "something else" is the last thing to get a
531 focusin sent to it, so the new window doesn't end up with focus.
533 But if the other focus in is something like PointerRoot then we
534 still want to fall back.
536 if (XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin_client
,
539 XPutBackEvent(ob_display
, &ce
);
540 ob_debug_type(OB_DEBUG_FOCUS
,
541 " but another FocusIn is coming\n");
543 /* Focus has been reverted.
545 FocusOut events come after UnmapNotify, so we don't need to
546 worry about focusing an invalid window
549 if (!focus_left_screen
)
550 focus_fallback(FALSE
, FALSE
);
555 ob_debug_type(OB_DEBUG_FOCUS
,
556 "Focus went to a window that is already gone\n");
558 /* If you send focus to a window and then it disappears, you can
559 get the FocusIn for it, after it is unmanaged.
560 Just wait for the next FocusOut/FocusIn pair, but make note that
561 the window that was focused no longer is. */
562 focus_set_client(NULL
);
564 else if (client
!= focus_client
) {
565 focus_left_screen
= FALSE
;
566 frame_adjust_focus(client
->frame
, TRUE
);
567 focus_set_client(client
);
568 client_calc_layer(client
);
569 client_bring_helper_windows(client
);
571 } else if (e
->type
== FocusOut
) {
574 /* Look for the followup FocusIn */
575 if (!XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin
, NULL
)) {
576 /* There is no FocusIn, this means focus went to a window that
577 is not being managed, or a window on another screen. */
581 xerror_set_ignore(TRUE
);
582 if (XGetInputFocus(ob_display
, &win
, &i
) != 0 &&
583 XGetGeometry(ob_display
, win
, &root
, &i
,&i
,&u
,&u
,&u
,&u
) != 0 &&
584 root
!= RootWindow(ob_display
, ob_screen
))
586 ob_debug_type(OB_DEBUG_FOCUS
,
587 "Focus went to another screen !\n");
588 focus_left_screen
= TRUE
;
591 ob_debug_type(OB_DEBUG_FOCUS
,
592 "Focus went to a black hole !\n");
593 xerror_set_ignore(FALSE
);
594 /* nothing is focused */
595 focus_set_client(NULL
);
597 /* Focus moved, so process the FocusIn event */
598 ObEventData ed
= { .ignored
= FALSE
};
599 event_process(&ce
, &ed
);
601 /* The FocusIn was ignored, this means it was on a window
602 that isn't a client. */
603 ob_debug_type(OB_DEBUG_FOCUS
,
604 "Focus went to an unmanaged window 0x%x !\n",
606 focus_fallback(TRUE
, FALSE
);
610 if (client
&& client
!= focus_client
) {
611 frame_adjust_focus(client
->frame
, FALSE
);
612 /* focus_set_client(NULL) has already been called in this
613 section or by focus_fallback */
614 client_calc_layer(client
);
616 } else if (timewinclients
)
617 event_handle_user_time_window_clients(timewinclients
, e
);
619 event_handle_client(client
, e
);
621 event_handle_dockapp(dockapp
, e
);
623 event_handle_dock(dock
, e
);
624 else if (window
== RootWindow(ob_display
, ob_screen
))
625 event_handle_root(e
);
626 else if (e
->type
== MapRequest
)
627 client_manage(window
);
628 else if (e
->type
== ClientMessage
) {
629 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
630 windows that are not managed yet. */
631 if (e
->xclient
.message_type
== prop_atoms
.net_request_frame_extents
) {
632 /* Pretend to manage the client, getting information used to
633 determine its decorations */
634 ObClient
*c
= client_fake_manage(e
->xclient
.window
);
637 /* set the frame extents on the window */
638 vals
[0] = c
->frame
->size
.left
;
639 vals
[1] = c
->frame
->size
.right
;
640 vals
[2] = c
->frame
->size
.top
;
641 vals
[3] = c
->frame
->size
.bottom
;
642 PROP_SETA32(e
->xclient
.window
, net_frame_extents
,
645 /* Free the pretend client */
646 client_fake_unmanage(c
);
649 else if (e
->type
== ConfigureRequest
) {
650 /* unhandled configure requests must be used to configure the
654 xwc
.x
= e
->xconfigurerequest
.x
;
655 xwc
.y
= e
->xconfigurerequest
.y
;
656 xwc
.width
= e
->xconfigurerequest
.width
;
657 xwc
.height
= e
->xconfigurerequest
.height
;
658 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
659 xwc
.sibling
= e
->xconfigurerequest
.above
;
660 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
662 /* we are not to be held responsible if someone sends us an
664 xerror_set_ignore(TRUE
);
665 XConfigureWindow(ob_display
, window
,
666 e
->xconfigurerequest
.value_mask
, &xwc
);
667 xerror_set_ignore(FALSE
);
670 else if (extensions_sync
&&
671 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
673 XSyncAlarmNotifyEvent
*se
= (XSyncAlarmNotifyEvent
*)e
;
674 if (se
->alarm
== moveresize_alarm
&& moveresize_in_progress
)
679 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
680 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
681 e
->type
== KeyRelease
)
683 event_handle_user_input(client
, e
);
686 /* if something happens and it's not from an XEvent, then we don't know
688 event_curtime
= CurrentTime
;
691 static void event_handle_root(XEvent
*e
)
697 ob_debug("Another WM has requested to replace us. Exiting.\n");
702 if (e
->xclient
.format
!= 32) break;
704 msgtype
= e
->xclient
.message_type
;
705 if (msgtype
== prop_atoms
.net_current_desktop
) {
706 guint d
= e
->xclient
.data
.l
[0];
707 if (d
< screen_num_desktops
) {
708 event_curtime
= e
->xclient
.data
.l
[1];
709 if (event_curtime
== 0)
710 ob_debug_type(OB_DEBUG_APP_BUGS
,
711 "_NET_CURRENT_DESKTOP message is missing "
713 screen_set_desktop(d
, TRUE
);
715 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
716 guint d
= e
->xclient
.data
.l
[0];
717 if (d
> 0 && d
<= 1000)
718 screen_set_num_desktops(d
);
719 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
720 screen_show_desktop(e
->xclient
.data
.l
[0] != 0, NULL
);
721 } else if (msgtype
== prop_atoms
.ob_control
) {
722 if (e
->xclient
.data
.l
[0] == 1)
724 else if (e
->xclient
.data
.l
[0] == 2)
729 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
)
730 screen_update_desktop_names();
731 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
732 screen_update_layout();
734 case ConfigureNotify
:
736 XRRUpdateConfiguration(e
);
745 void event_enter_client(ObClient
*client
)
747 g_assert(config_focus_follow
);
749 if (client_enter_focusable(client
) && client_can_focus(client
)) {
750 if (config_focus_delay
) {
751 ObFocusDelayData
*data
;
753 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
755 data
= g_new(ObFocusDelayData
, 1);
756 data
->client
= client
;
757 data
->time
= event_curtime
;
759 ob_main_loop_timeout_add(ob_main_loop
,
762 data
, focus_delay_cmp
, focus_delay_dest
);
764 ObFocusDelayData data
;
765 data
.client
= client
;
766 data
.time
= event_curtime
;
767 focus_delay_func(&data
);
772 static void event_handle_user_time_window_clients(GSList
*l
, XEvent
*e
)
774 g_assert(e
->type
== PropertyNotify
);
775 if (e
->xproperty
.atom
== prop_atoms
.net_wm_user_time
) {
776 for (; l
; l
= g_slist_next(l
))
777 client_update_user_time(l
->data
);
781 static void event_handle_client(ObClient
*client
, XEvent
*e
)
786 static gint px
= -1, py
= -1;
791 /* save where the press occured for the first button pressed */
793 pb
= e
->xbutton
.button
;
798 /* Wheel buttons don't draw because they are an instant click, so it
799 is a waste of resources to go drawing it.
800 if the user is doing an intereactive thing, or has a menu open then
801 the mouse is grabbed (possibly) and if we get these events we don't
802 want to deal with them
804 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5) &&
805 !keyboard_interactively_grabbed() &&
808 /* use where the press occured */
809 con
= frame_context(client
, e
->xbutton
.window
, px
, py
);
810 con
= mouse_button_frame_context(con
, e
->xbutton
.button
,
813 if (e
->type
== ButtonRelease
&& e
->xbutton
.button
== pb
)
814 pb
= 0, px
= py
= -1;
817 case OB_FRAME_CONTEXT_MAXIMIZE
:
818 client
->frame
->max_press
= (e
->type
== ButtonPress
);
819 framerender_frame(client
->frame
);
821 case OB_FRAME_CONTEXT_CLOSE
:
822 client
->frame
->close_press
= (e
->type
== ButtonPress
);
823 framerender_frame(client
->frame
);
825 case OB_FRAME_CONTEXT_ICONIFY
:
826 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
827 framerender_frame(client
->frame
);
829 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
830 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
831 framerender_frame(client
->frame
);
833 case OB_FRAME_CONTEXT_SHADE
:
834 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
835 framerender_frame(client
->frame
);
838 /* nothing changes with clicks for any other contexts */
844 /* when there is a grab on the pointer, we won't get enter/leave
845 notifies, but we still get motion events */
846 if (grab_on_pointer()) break;
848 con
= frame_context(client
, e
->xmotion
.window
,
849 e
->xmotion
.x
, e
->xmotion
.y
);
851 case OB_FRAME_CONTEXT_TITLEBAR
:
852 case OB_FRAME_CONTEXT_TLCORNER
:
853 case OB_FRAME_CONTEXT_TRCORNER
:
854 /* we've left the button area inside the titlebar */
855 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
856 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
857 client
->frame
->close_hover
)
859 client
->frame
->max_hover
= FALSE
;
860 client
->frame
->desk_hover
= FALSE
;
861 client
->frame
->shade_hover
= FALSE
;
862 client
->frame
->iconify_hover
= FALSE
;
863 client
->frame
->close_hover
= FALSE
;
864 frame_adjust_state(client
->frame
);
867 case OB_FRAME_CONTEXT_MAXIMIZE
:
868 if (!client
->frame
->max_hover
) {
869 client
->frame
->max_hover
= TRUE
;
870 frame_adjust_state(client
->frame
);
873 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
874 if (!client
->frame
->desk_hover
) {
875 client
->frame
->desk_hover
= TRUE
;
876 frame_adjust_state(client
->frame
);
879 case OB_FRAME_CONTEXT_SHADE
:
880 if (!client
->frame
->shade_hover
) {
881 client
->frame
->shade_hover
= TRUE
;
882 frame_adjust_state(client
->frame
);
885 case OB_FRAME_CONTEXT_ICONIFY
:
886 if (!client
->frame
->iconify_hover
) {
887 client
->frame
->iconify_hover
= TRUE
;
888 frame_adjust_state(client
->frame
);
891 case OB_FRAME_CONTEXT_CLOSE
:
892 if (!client
->frame
->close_hover
) {
893 client
->frame
->close_hover
= TRUE
;
894 frame_adjust_state(client
->frame
);
902 con
= frame_context(client
, e
->xcrossing
.window
,
903 e
->xcrossing
.x
, e
->xcrossing
.y
);
905 case OB_FRAME_CONTEXT_TITLEBAR
:
906 case OB_FRAME_CONTEXT_TLCORNER
:
907 case OB_FRAME_CONTEXT_TRCORNER
:
908 /* we've left the button area inside the titlebar */
909 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
910 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
911 client
->frame
->close_hover
)
913 client
->frame
->max_hover
= FALSE
;
914 client
->frame
->desk_hover
= FALSE
;
915 client
->frame
->shade_hover
= FALSE
;
916 client
->frame
->iconify_hover
= FALSE
;
917 client
->frame
->close_hover
= FALSE
;
918 frame_adjust_state(client
->frame
);
921 case OB_FRAME_CONTEXT_MAXIMIZE
:
922 client
->frame
->max_hover
= FALSE
;
923 frame_adjust_state(client
->frame
);
925 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
926 client
->frame
->desk_hover
= FALSE
;
927 frame_adjust_state(client
->frame
);
929 case OB_FRAME_CONTEXT_SHADE
:
930 client
->frame
->shade_hover
= FALSE
;
931 frame_adjust_state(client
->frame
);
933 case OB_FRAME_CONTEXT_ICONIFY
:
934 client
->frame
->iconify_hover
= FALSE
;
935 frame_adjust_state(client
->frame
);
937 case OB_FRAME_CONTEXT_CLOSE
:
938 client
->frame
->close_hover
= FALSE
;
939 frame_adjust_state(client
->frame
);
941 case OB_FRAME_CONTEXT_FRAME
:
942 /* When the mouse leaves an animating window, don't use the
943 corresponding enter events. Pretend like the animating window
944 doesn't even exist..! */
945 if (frame_iconify_animating(client
->frame
))
946 event_ignore_all_queued_enters();
948 ob_debug_type(OB_DEBUG_FOCUS
,
949 "%sNotify mode %d detail %d on %lx\n",
950 (e
->type
== EnterNotify
? "Enter" : "Leave"),
952 e
->xcrossing
.detail
, (client
?client
->window
:0));
953 if (keyboard_interactively_grabbed())
955 if (config_focus_follow
&& config_focus_delay
&&
956 /* leave inferior events can happen when the mouse goes onto
957 the window's border and then into the window before the
959 e
->xcrossing
.detail
!= NotifyInferior
)
961 ob_main_loop_timeout_remove_data(ob_main_loop
,
972 con
= frame_context(client
, e
->xcrossing
.window
,
973 e
->xcrossing
.x
, e
->xcrossing
.y
);
975 case OB_FRAME_CONTEXT_MAXIMIZE
:
976 client
->frame
->max_hover
= TRUE
;
977 frame_adjust_state(client
->frame
);
979 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
980 client
->frame
->desk_hover
= TRUE
;
981 frame_adjust_state(client
->frame
);
983 case OB_FRAME_CONTEXT_SHADE
:
984 client
->frame
->shade_hover
= TRUE
;
985 frame_adjust_state(client
->frame
);
987 case OB_FRAME_CONTEXT_ICONIFY
:
988 client
->frame
->iconify_hover
= TRUE
;
989 frame_adjust_state(client
->frame
);
991 case OB_FRAME_CONTEXT_CLOSE
:
992 client
->frame
->close_hover
= TRUE
;
993 frame_adjust_state(client
->frame
);
995 case OB_FRAME_CONTEXT_FRAME
:
996 if (keyboard_interactively_grabbed())
998 if (e
->xcrossing
.mode
== NotifyGrab
||
999 e
->xcrossing
.mode
== NotifyUngrab
||
1000 /*ignore enters when we're already in the window */
1001 e
->xcrossing
.detail
== NotifyInferior
||
1002 is_enter_focus_event_ignored(e
))
1004 ob_debug_type(OB_DEBUG_FOCUS
,
1005 "%sNotify mode %d detail %d on %lx IGNORED\n",
1006 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1008 e
->xcrossing
.detail
, client
?client
->window
:0);
1011 ob_debug_type(OB_DEBUG_FOCUS
,
1012 "%sNotify mode %d detail %d on %lx, "
1013 "focusing window\n",
1014 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1016 e
->xcrossing
.detail
, (client
?client
->window
:0));
1017 if (config_focus_follow
)
1018 event_enter_client(client
);
1026 case ConfigureRequest
:
1028 /* dont compress these unless you're going to watch for property
1029 notifies in between (these can change what the configure would
1031 also you can't compress stacking events
1035 gboolean move
= FALSE
;
1036 gboolean resize
= FALSE
;
1038 /* get the current area */
1039 RECT_TO_DIMS(client
->area
, x
, y
, w
, h
);
1041 ob_debug("ConfigureRequest for \"%s\" desktop %d wmstate %d "
1043 " x %d y %d w %d h %d b %d\n",
1045 screen_desktop
, client
->wmstate
, client
->frame
->visible
,
1046 x
, y
, w
, h
, client
->border_width
);
1048 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
1049 if (client
->border_width
!= e
->xconfigurerequest
.border_width
) {
1050 client
->border_width
= e
->xconfigurerequest
.border_width
;
1052 /* if the border width is changing then that is the same
1053 as requesting a resize, but we don't actually change
1054 the client's border, so it will change their root
1055 coordiantes (since they include the border width) and
1056 we need to a notify then */
1061 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
1062 ObClient
*sibling
= NULL
;
1064 /* get the sibling */
1065 if (e
->xconfigurerequest
.value_mask
& CWSibling
) {
1067 win
= g_hash_table_lookup(window_map
,
1068 &e
->xconfigurerequest
.above
);
1069 if (WINDOW_IS_CLIENT(win
) && WINDOW_AS_CLIENT(win
) != client
)
1070 sibling
= WINDOW_AS_CLIENT(win
);
1073 /* activate it rather than just focus it */
1074 stacking_restack_request(client
, sibling
,
1075 e
->xconfigurerequest
.detail
, TRUE
);
1077 /* if a stacking change moves the window without resizing */
1081 if ((e
->xconfigurerequest
.value_mask
& CWX
) ||
1082 (e
->xconfigurerequest
.value_mask
& CWY
) ||
1083 (e
->xconfigurerequest
.value_mask
& CWWidth
) ||
1084 (e
->xconfigurerequest
.value_mask
& CWHeight
))
1086 if (e
->xconfigurerequest
.value_mask
& CWX
) {
1087 /* don't allow clients to move shaded windows (fvwm does this)
1089 if (!client
->shaded
)
1090 x
= e
->xconfigurerequest
.x
;
1093 if (e
->xconfigurerequest
.value_mask
& CWY
) {
1094 /* don't allow clients to move shaded windows (fvwm does this)
1096 if (!client
->shaded
)
1097 y
= e
->xconfigurerequest
.y
;
1101 if (e
->xconfigurerequest
.value_mask
& CWWidth
) {
1102 w
= e
->xconfigurerequest
.width
;
1105 if (e
->xconfigurerequest
.value_mask
& CWHeight
) {
1106 h
= e
->xconfigurerequest
.height
;
1111 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
1112 "move %d resize %d\n",
1113 e
->xconfigurerequest
.value_mask
& CWX
, x
,
1114 e
->xconfigurerequest
.value_mask
& CWY
, y
,
1115 e
->xconfigurerequest
.value_mask
& CWWidth
, w
,
1116 e
->xconfigurerequest
.value_mask
& CWHeight
, h
,
1119 /* check for broken apps moving to their root position
1121 XXX remove this some day...that would be nice. right now all
1122 kde apps do this when they try activate themselves on another
1123 desktop. eg. open amarok window on desktop 1, switch to desktop
1124 2, click amarok tray icon. it will move by its decoration size.
1126 if (x
!= client
->area
.x
&&
1127 x
== (client
->frame
->area
.x
+ client
->frame
->size
.left
-
1128 (gint
)client
->border_width
) &&
1129 y
!= client
->area
.y
&&
1130 y
== (client
->frame
->area
.y
+ client
->frame
->size
.top
-
1131 (gint
)client
->border_width
) &&
1132 w
== client
->area
.width
&&
1133 h
== client
->area
.height
)
1135 ob_debug_type(OB_DEBUG_APP_BUGS
,
1136 "Application %s is trying to move via "
1137 "ConfigureRequest to it's root window position "
1138 "but it is not using StaticGravity\n",
1144 /* they still requested a move, so don't change whether a
1145 notify is sent or not */
1148 if (move
|| resize
) {
1151 client_try_configure(client
, &x
, &y
, &w
, &h
, &lw
, &lh
, FALSE
);
1153 /* if x was not given, then use gravity to figure out the new
1154 x. the reference point should not be moved */
1155 if ((e
->xconfigurerequest
.value_mask
& CWWidth
&&
1156 !(e
->xconfigurerequest
.value_mask
& CWX
)))
1157 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1158 /* if y was not given, then use gravity to figure out the new
1159 y. the reference point should not be moved */
1160 if ((e
->xconfigurerequest
.value_mask
& CWHeight
&&
1161 !(e
->xconfigurerequest
.value_mask
& CWY
)))
1162 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1164 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1166 /* if they requested something that moves the window, or if
1167 the window is actually being changed then configure it and
1168 send a configure notify to them */
1169 if (move
|| !RECT_EQUAL_DIMS(client
->area
, x
, y
, w
, h
)) {
1170 ob_debug("Granting ConfigureRequest x %d y %d w %d h %d\n",
1172 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1175 /* ignore enter events caused by these like ob actions do */
1176 event_ignore_all_queued_enters();
1181 if (client
->ignore_unmaps
) {
1182 client
->ignore_unmaps
--;
1185 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1186 "ignores left %d\n",
1187 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
1188 client
->ignore_unmaps
);
1189 client_unmanage(client
);
1192 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
1193 client_unmanage(client
);
1195 case ReparentNotify
:
1196 /* this is when the client is first taken captive in the frame */
1197 if (e
->xreparent
.parent
== client
->frame
->window
) break;
1200 This event is quite rare and is usually handled in unmapHandler.
1201 However, if the window is unmapped when the reparent event occurs,
1202 the window manager never sees it because an unmap event is not sent
1203 to an already unmapped window.
1206 /* we don't want the reparent event, put it back on the stack for the
1207 X server to deal with after we unmanage the window */
1208 XPutBackEvent(ob_display
, e
);
1210 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
1211 client_unmanage(client
);
1214 ob_debug("MapRequest for 0x%lx\n", client
->window
);
1215 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
1216 does, we don't want it!
1217 it can happen now when the window is on
1218 another desktop, but we still don't
1220 client_activate(client
, FALSE
, TRUE
);
1223 /* validate cuz we query stuff off the client here */
1224 if (!client_validate(client
)) break;
1226 if (e
->xclient
.format
!= 32) return;
1228 msgtype
= e
->xclient
.message_type
;
1229 if (msgtype
== prop_atoms
.wm_change_state
) {
1230 /* compress changes into a single change */
1231 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1233 /* XXX: it would be nice to compress ALL messages of a
1234 type, not just messages in a row without other
1235 message types between. */
1236 if (ce
.xclient
.message_type
!= msgtype
) {
1237 XPutBackEvent(ob_display
, &ce
);
1240 e
->xclient
= ce
.xclient
;
1242 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1243 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
1244 /* compress changes into a single change */
1245 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1247 /* XXX: it would be nice to compress ALL messages of a
1248 type, not just messages in a row without other
1249 message types between. */
1250 if (ce
.xclient
.message_type
!= msgtype
) {
1251 XPutBackEvent(ob_display
, &ce
);
1254 e
->xclient
= ce
.xclient
;
1256 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1257 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1258 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1260 } else if (msgtype
== prop_atoms
.net_wm_state
) {
1261 /* can't compress these */
1262 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1263 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1264 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1265 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1266 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1268 client_set_state(client
, e
->xclient
.data
.l
[0],
1269 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1271 /* ignore enter events caused by these like ob actions do */
1272 event_ignore_all_queued_enters();
1273 } else if (msgtype
== prop_atoms
.net_close_window
) {
1274 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1275 client_close(client
);
1276 } else if (msgtype
== prop_atoms
.net_active_window
) {
1277 ob_debug("net_active_window for 0x%lx source=%s\n",
1279 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1280 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1281 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1282 /* XXX make use of data.l[2] !? */
1283 if (e
->xclient
.data
.l
[0] == 1 || e
->xclient
.data
.l
[0] == 2) {
1284 event_curtime
= e
->xclient
.data
.l
[1];
1285 if (event_curtime
== 0)
1286 ob_debug_type(OB_DEBUG_APP_BUGS
,
1287 "_NET_ACTIVE_WINDOW message for window %s is"
1288 " missing a timestamp\n", client
->title
);
1290 ob_debug_type(OB_DEBUG_APP_BUGS
,
1291 "_NET_ACTIVE_WINDOW message for window %s is "
1292 "missing source indication\n");
1293 client_activate(client
, FALSE
,
1294 (e
->xclient
.data
.l
[0] == 0 ||
1295 e
->xclient
.data
.l
[0] == 2));
1296 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1297 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1298 client
->window
, e
->xclient
.data
.l
[2]);
1299 if ((Atom
)e
->xclient
.data
.l
[2] ==
1300 prop_atoms
.net_wm_moveresize_size_topleft
||
1301 (Atom
)e
->xclient
.data
.l
[2] ==
1302 prop_atoms
.net_wm_moveresize_size_top
||
1303 (Atom
)e
->xclient
.data
.l
[2] ==
1304 prop_atoms
.net_wm_moveresize_size_topright
||
1305 (Atom
)e
->xclient
.data
.l
[2] ==
1306 prop_atoms
.net_wm_moveresize_size_right
||
1307 (Atom
)e
->xclient
.data
.l
[2] ==
1308 prop_atoms
.net_wm_moveresize_size_right
||
1309 (Atom
)e
->xclient
.data
.l
[2] ==
1310 prop_atoms
.net_wm_moveresize_size_bottomright
||
1311 (Atom
)e
->xclient
.data
.l
[2] ==
1312 prop_atoms
.net_wm_moveresize_size_bottom
||
1313 (Atom
)e
->xclient
.data
.l
[2] ==
1314 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1315 (Atom
)e
->xclient
.data
.l
[2] ==
1316 prop_atoms
.net_wm_moveresize_size_left
||
1317 (Atom
)e
->xclient
.data
.l
[2] ==
1318 prop_atoms
.net_wm_moveresize_move
||
1319 (Atom
)e
->xclient
.data
.l
[2] ==
1320 prop_atoms
.net_wm_moveresize_size_keyboard
||
1321 (Atom
)e
->xclient
.data
.l
[2] ==
1322 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1324 moveresize_start(client
, e
->xclient
.data
.l
[0],
1325 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1326 e
->xclient
.data
.l
[2]);
1328 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1329 prop_atoms
.net_wm_moveresize_cancel
)
1330 moveresize_end(TRUE
);
1331 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1332 gint ograv
, x
, y
, w
, h
;
1334 ograv
= client
->gravity
;
1336 if (e
->xclient
.data
.l
[0] & 0xff)
1337 client
->gravity
= e
->xclient
.data
.l
[0] & 0xff;
1339 if (e
->xclient
.data
.l
[0] & 1 << 8)
1340 x
= e
->xclient
.data
.l
[1];
1343 if (e
->xclient
.data
.l
[0] & 1 << 9)
1344 y
= e
->xclient
.data
.l
[2];
1348 if (e
->xclient
.data
.l
[0] & 1 << 10) {
1349 w
= e
->xclient
.data
.l
[3];
1351 /* if x was not given, then use gravity to figure out the new
1352 x. the reference point should not be moved */
1353 if (!(e
->xclient
.data
.l
[0] & 1 << 8))
1354 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1357 w
= client
->area
.width
;
1359 if (e
->xclient
.data
.l
[0] & 1 << 11) {
1360 h
= e
->xclient
.data
.l
[4];
1362 /* if y was not given, then use gravity to figure out the new
1363 y. the reference point should not be moved */
1364 if (!(e
->xclient
.data
.l
[0] & 1 << 9))
1365 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1368 h
= client
->area
.height
;
1370 ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)\n",
1371 e
->xclient
.data
.l
[0] & 1 << 8, x
,
1372 e
->xclient
.data
.l
[0] & 1 << 9, y
,
1375 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1377 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1379 client
->gravity
= ograv
;
1381 /* ignore enter events caused by these like ob actions do */
1382 event_ignore_all_queued_enters();
1383 } else if (msgtype
== prop_atoms
.net_restack_window
) {
1384 if (e
->xclient
.data
.l
[0] != 2) {
1385 ob_debug_type(OB_DEBUG_APP_BUGS
,
1386 "_NET_RESTACK_WINDOW sent for window %s with "
1387 "invalid source indication %ld\n",
1388 client
->title
, e
->xclient
.data
.l
[0]);
1390 ObClient
*sibling
= NULL
;
1391 if (e
->xclient
.data
.l
[1]) {
1392 ObWindow
*win
= g_hash_table_lookup
1393 (window_map
, &e
->xclient
.data
.l
[1]);
1394 if (WINDOW_IS_CLIENT(win
) &&
1395 WINDOW_AS_CLIENT(win
) != client
)
1397 sibling
= WINDOW_AS_CLIENT(win
);
1399 if (sibling
== NULL
)
1400 ob_debug_type(OB_DEBUG_APP_BUGS
,
1401 "_NET_RESTACK_WINDOW sent for window %s "
1402 "with invalid sibling 0x%x\n",
1403 client
->title
, e
->xclient
.data
.l
[1]);
1405 if (e
->xclient
.data
.l
[2] == Below
||
1406 e
->xclient
.data
.l
[2] == BottomIf
||
1407 e
->xclient
.data
.l
[2] == Above
||
1408 e
->xclient
.data
.l
[2] == TopIf
||
1409 e
->xclient
.data
.l
[2] == Opposite
)
1411 /* just raise, don't activate */
1412 stacking_restack_request(client
, sibling
,
1413 e
->xclient
.data
.l
[2], FALSE
);
1414 /* send a synthetic ConfigureNotify, cuz this is supposed
1415 to be like a ConfigureRequest. */
1416 client_reconfigure(client
);
1418 ob_debug_type(OB_DEBUG_APP_BUGS
,
1419 "_NET_RESTACK_WINDOW sent for window %s "
1420 "with invalid detail %d\n",
1421 client
->title
, e
->xclient
.data
.l
[2]);
1425 case PropertyNotify
:
1426 /* validate cuz we query stuff off the client here */
1427 if (!client_validate(client
)) break;
1429 /* compress changes to a single property into a single change */
1430 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1434 /* XXX: it would be nice to compress ALL changes to a property,
1435 not just changes in a row without other props between. */
1437 a
= ce
.xproperty
.atom
;
1438 b
= e
->xproperty
.atom
;
1442 if ((a
== prop_atoms
.net_wm_name
||
1443 a
== prop_atoms
.wm_name
||
1444 a
== prop_atoms
.net_wm_icon_name
||
1445 a
== prop_atoms
.wm_icon_name
)
1447 (b
== prop_atoms
.net_wm_name
||
1448 b
== prop_atoms
.wm_name
||
1449 b
== prop_atoms
.net_wm_icon_name
||
1450 b
== prop_atoms
.wm_icon_name
)) {
1453 if (a
== prop_atoms
.net_wm_icon
&&
1454 b
== prop_atoms
.net_wm_icon
)
1457 XPutBackEvent(ob_display
, &ce
);
1461 msgtype
= e
->xproperty
.atom
;
1462 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1463 client_update_normal_hints(client
);
1464 /* normal hints can make a window non-resizable */
1465 client_setup_decor_and_functions(client
, TRUE
);
1466 } else if (msgtype
== XA_WM_HINTS
) {
1467 client_update_wmhints(client
);
1468 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1469 client_update_transient_for(client
);
1470 client_get_type_and_transientness(client
);
1471 /* type may have changed, so update the layer */
1472 client_calc_layer(client
);
1473 client_setup_decor_and_functions(client
, TRUE
);
1474 } else if (msgtype
== prop_atoms
.net_wm_name
||
1475 msgtype
== prop_atoms
.wm_name
||
1476 msgtype
== prop_atoms
.net_wm_icon_name
||
1477 msgtype
== prop_atoms
.wm_icon_name
) {
1478 client_update_title(client
);
1479 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1480 client_update_protocols(client
);
1481 client_setup_decor_and_functions(client
, TRUE
);
1483 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1484 client_update_strut(client
);
1486 else if (msgtype
== prop_atoms
.net_wm_strut_partial
) {
1487 client_update_strut(client
);
1489 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1490 client_update_icons(client
);
1492 else if (msgtype
== prop_atoms
.net_wm_icon_geometry
) {
1493 client_update_icon_geometry(client
);
1495 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1496 client_update_user_time(client
);
1498 else if (msgtype
== prop_atoms
.net_wm_user_time_window
) {
1499 client_update_user_time_window(client
);
1502 else if (msgtype
== prop_atoms
.net_wm_sync_request_counter
) {
1503 client_update_sync_request_counter(client
);
1507 case ColormapNotify
:
1508 client_update_colormap(client
, e
->xcolormap
.colormap
);
1513 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1514 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1515 frame_adjust_shape(client
->frame
);
1521 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1525 if (e
->xbutton
.button
== 1)
1526 stacking_raise(DOCK_AS_WINDOW(s
));
1527 else if (e
->xbutton
.button
== 2)
1528 stacking_lower(DOCK_AS_WINDOW(s
));
1534 /* don't hide when moving into a dock app */
1535 if (e
->xcrossing
.detail
!= NotifyInferior
)
1541 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1545 dock_app_drag(app
, &e
->xmotion
);
1548 if (app
->ignore_unmaps
) {
1549 app
->ignore_unmaps
--;
1552 dock_remove(app
, TRUE
);
1555 dock_remove(app
, FALSE
);
1557 case ReparentNotify
:
1558 dock_remove(app
, FALSE
);
1560 case ConfigureNotify
:
1561 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1566 static ObMenuFrame
* find_active_menu()
1569 ObMenuFrame
*ret
= NULL
;
1571 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1580 static ObMenuFrame
* find_active_or_last_menu()
1582 ObMenuFrame
*ret
= NULL
;
1584 ret
= find_active_menu();
1585 if (!ret
&& menu_frame_visible
)
1586 ret
= menu_frame_visible
->data
;
1590 static gboolean
event_handle_menu_keyboard(XEvent
*ev
)
1592 guint keycode
, state
;
1595 gboolean ret
= TRUE
;
1597 keycode
= ev
->xkey
.keycode
;
1598 state
= ev
->xkey
.state
;
1599 unikey
= translate_unichar(keycode
);
1601 frame
= find_active_or_last_menu();
1605 else if (keycode
== ob_keycode(OB_KEY_ESCAPE
) && state
== 0)
1606 menu_frame_hide_all();
1608 else if (keycode
== ob_keycode(OB_KEY_RETURN
) && (state
== 0 ||
1609 state
== ControlMask
))
1611 /* Enter runs the active item or goes into the submenu.
1612 Control-Enter runs it without closing the menu. */
1614 menu_frame_select_next(frame
->child
);
1615 else if (frame
->selected
)
1616 menu_entry_frame_execute(frame
->selected
, state
, ev
->xkey
.time
);
1619 else if (keycode
== ob_keycode(OB_KEY_LEFT
) && ev
->xkey
.state
== 0) {
1620 /* Left goes to the parent menu */
1621 menu_frame_select(frame
, NULL
, TRUE
);
1624 else if (keycode
== ob_keycode(OB_KEY_RIGHT
) && ev
->xkey
.state
== 0) {
1625 /* Right goes to the selected submenu */
1626 if (frame
->child
) menu_frame_select_next(frame
->child
);
1629 else if (keycode
== ob_keycode(OB_KEY_UP
) && state
== 0) {
1630 menu_frame_select_previous(frame
);
1633 else if (keycode
== ob_keycode(OB_KEY_DOWN
) && state
== 0) {
1634 menu_frame_select_next(frame
);
1637 /* keyboard accelerator shortcuts. (allow controlmask) */
1638 else if ((ev
->xkey
.state
& ~ControlMask
) == 0 &&
1639 /* was it a valid key? */
1641 /* don't bother if the menu is empty. */
1646 ObMenuEntryFrame
*found
= NULL
;
1647 guint num_found
= 0;
1649 /* start after the selected one */
1650 start
= frame
->entries
;
1651 if (frame
->selected
) {
1652 for (it
= start
; frame
->selected
!= it
->data
; it
= g_list_next(it
))
1653 g_assert(it
!= NULL
); /* nothing was selected? */
1654 /* next with wraparound */
1655 start
= g_list_next(it
);
1656 if (start
== NULL
) start
= frame
->entries
;
1661 ObMenuEntryFrame
*e
= it
->data
;
1662 gunichar entrykey
= 0;
1664 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1665 entrykey
= e
->entry
->data
.normal
.shortcut
;
1666 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1667 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1669 if (unikey
== entrykey
) {
1670 if (found
== NULL
) found
= e
;
1674 /* next with wraparound */
1675 it
= g_list_next(it
);
1676 if (it
== NULL
) it
= frame
->entries
;
1677 } while (it
!= start
);
1680 if (found
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
1683 menu_frame_select(frame
, found
, TRUE
);
1684 usleep(50000); /* highlight the item for a short bit so the
1685 user can see what happened */
1686 menu_entry_frame_execute(found
, state
, ev
->xkey
.time
);
1688 menu_frame_select(frame
, found
, TRUE
);
1690 menu_frame_select_next(frame
->child
);
1701 static gboolean
event_handle_menu(XEvent
*ev
)
1704 ObMenuEntryFrame
*e
;
1705 gboolean ret
= TRUE
;
1709 if ((ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5)
1712 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1713 ev
->xbutton
.y_root
)))
1715 menu_frame_select(e
->frame
, e
, TRUE
);
1716 menu_entry_frame_execute(e
, ev
->xbutton
.state
,
1720 menu_frame_hide_all();
1724 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1725 if (e
->ignore_enters
)
1727 else if (!(f
= find_active_menu()) ||
1729 f
->parent
== e
->frame
||
1730 f
->child
== e
->frame
)
1731 menu_frame_select(e
->frame
, e
, FALSE
);
1735 /*ignore leaves when we're already in the window */
1736 if (ev
->xcrossing
.detail
== NotifyInferior
)
1739 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1740 (f
= find_active_menu()) && f
->selected
== e
&&
1741 e
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1743 menu_frame_select(e
->frame
, NULL
, FALSE
);
1747 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1748 ev
->xmotion
.y_root
)))
1749 if (!(f
= find_active_menu()) ||
1751 f
->parent
== e
->frame
||
1752 f
->child
== e
->frame
)
1753 menu_frame_select(e
->frame
, e
, FALSE
);
1756 ret
= event_handle_menu_keyboard(ev
);
1762 static void event_handle_user_input(ObClient
*client
, XEvent
*e
)
1764 g_assert(e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
1765 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
1766 e
->type
== KeyRelease
);
1768 if (menu_frame_visible
) {
1769 if (event_handle_menu(e
))
1770 /* don't use the event if the menu used it, but if the menu
1771 didn't use it and it's a keypress that is bound, it will
1772 close the menu and be used */
1776 /* if the keyboard interactive action uses the event then dont
1777 use it for bindings. likewise is moveresize uses the event. */
1778 if (!keyboard_process_interactive_grab(e
, &client
) &&
1779 !(moveresize_in_progress
&& moveresize_event(e
)))
1781 if (moveresize_in_progress
)
1782 /* make further actions work on the client being
1784 client
= moveresize_client
;
1786 menu_can_hide
= FALSE
;
1787 ob_main_loop_timeout_add(ob_main_loop
,
1788 config_menu_hide_delay
* 1000,
1789 menu_hide_delay_func
,
1790 NULL
, g_direct_equal
, NULL
);
1792 if (e
->type
== ButtonPress
||
1793 e
->type
== ButtonRelease
||
1794 e
->type
== MotionNotify
)
1796 /* the frame may not be "visible" but they can still click on it
1797 in the case where it is animating before disappearing */
1798 if (!client
|| !frame_iconify_animating(client
->frame
))
1799 mouse_event(client
, e
);
1800 } else if (e
->type
== KeyPress
) {
1801 keyboard_event((focus_cycle_target
? focus_cycle_target
:
1802 (client
? client
: focus_client
)), e
);
1807 static gboolean
menu_hide_delay_func(gpointer data
)
1809 menu_can_hide
= TRUE
;
1810 return FALSE
; /* no repeat */
1813 static void focus_delay_dest(gpointer data
)
1818 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
1820 const ObFocusDelayData
*f1
= d1
;
1821 return f1
->client
== d2
;
1824 static gboolean
focus_delay_func(gpointer data
)
1826 ObFocusDelayData
*d
= data
;
1827 Time old
= event_curtime
;
1829 event_curtime
= d
->time
;
1830 if (focus_client
!= d
->client
) {
1831 if (client_focus(d
->client
) && config_focus_raise
)
1832 stacking_raise(CLIENT_AS_WINDOW(d
->client
));
1834 event_curtime
= old
;
1835 return FALSE
; /* no repeat */
1838 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1840 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1844 void event_halt_focus_delay()
1846 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1849 static Bool
event_look_for_enters(Display
*d
, XEvent
*e
, XPointer arg
)
1851 if (e
->type
== EnterNotify
&&
1852 /* these types aren't used for focusing */
1853 !(e
->xcrossing
.mode
== NotifyGrab
||
1854 e
->xcrossing
.mode
== NotifyUngrab
||
1855 e
->xcrossing
.detail
== NotifyInferior
))
1859 /* found an enter for that leave, ignore it if it's going to
1861 win
= g_hash_table_lookup(window_map
, &e
->xany
.window
);
1862 if (win
&& WINDOW_IS_CLIENT(win
))
1863 ++ignore_enter_focus
;
1865 return False
; /* don't disrupt the queue order, just count them */
1868 void event_ignore_all_queued_enters()
1872 XSync(ob_display
, FALSE
);
1874 /* count the events without disrupting them */
1875 ignore_enter_focus
= 0;
1876 XCheckIfEvent(ob_display
, &e
, event_look_for_enters
, NULL
);
1879 static gboolean
is_enter_focus_event_ignored(XEvent
*e
)
1881 g_assert(e
->type
== EnterNotify
&&
1882 !(e
->xcrossing
.mode
== NotifyGrab
||
1883 e
->xcrossing
.mode
== NotifyUngrab
||
1884 e
->xcrossing
.detail
== NotifyInferior
));
1886 ob_debug_type(OB_DEBUG_FOCUS
, "# enters ignored: %d\n",
1887 ignore_enter_focus
);
1889 if (ignore_enter_focus
) {
1890 --ignore_enter_focus
;
1896 void event_cancel_all_key_grabs()
1898 if (keyboard_interactively_grabbed())
1899 keyboard_interactive_cancel();
1900 else if (menu_frame_visible
)
1901 menu_frame_hide_all();
1902 else if (grab_on_keyboard())
1905 /* If we don't have the keyboard grabbed, then ungrab it with
1906 XUngrabKeyboard, so that there is not a passive grab left
1907 on from the KeyPress. If the grab is left on, and focus
1908 moves during that time, it will be NotifyWhileGrabbed, and
1909 applications like to ignore those! */
1910 if (!keyboard_interactively_grabbed())
1911 XUngrabKeyboard(ob_display
, CurrentTime
);
1915 gboolean
event_time_after(Time t1
, Time t2
)
1917 g_assert(t1
!= CurrentTime
);
1918 g_assert(t2
!= CurrentTime
);
1921 Timestamp values wrap around (after about 49.7 days). The server, given
1922 its current time is represented by timestamp T, always interprets
1923 timestamps from clients by treating half of the timestamp space as being
1924 later in time than T.
1925 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
1928 /* TIME_HALF is half of the number space of a Time type variable */
1929 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
1931 if (t2
>= TIME_HALF
)
1932 /* t2 is in the second half so t1 might wrap around and be smaller than
1934 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
1936 /* t2 is in the first half so t1 has to come after it */
1937 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);