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 Ben Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
32 #include "menuframe.h"
36 #include "framerender.h"
38 #include "moveresize.h"
41 #include "extensions.h"
44 #include <X11/keysym.h>
45 #include <X11/Xatom.h>
48 #ifdef HAVE_SYS_SELECT_H
49 # include <sys/select.h>
55 # include <X11/XKBlib.h>
59 #include <X11/ICE/ICElib.h>
73 static void event_process(const XEvent
*e
, gpointer data
);
74 static void event_client_dest(ObClient
*client
, gpointer data
);
75 static void event_handle_root(XEvent
*e
);
76 static void event_handle_menu(XEvent
*e
);
77 static void event_handle_dock(ObDock
*s
, XEvent
*e
);
78 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
);
79 static void event_handle_client(ObClient
*c
, XEvent
*e
);
80 static void event_handle_group(ObGroup
*g
, XEvent
*e
);
82 static void focus_delay_dest(gpointer data
);
83 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
);
84 static gboolean
focus_delay_func(gpointer data
);
85 static void focus_delay_client_dest(ObClient
*client
, gpointer data
);
87 static gboolean
menu_hide_delay_func(gpointer data
);
89 /* The time for the current event being processed */
90 Time event_curtime
= CurrentTime
;
92 /*! The value of the mask for the NumLock modifier */
94 /*! The value of the mask for the ScrollLock modifier */
96 /*! The key codes for the modifier keys */
97 static XModifierKeymap
*modmap
;
98 /*! Table of the constant modifier masks */
99 static const gint mask_table
[] = {
100 ShiftMask
, LockMask
, ControlMask
, Mod1Mask
,
101 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
103 static gint mask_table_size
;
105 static guint ignore_enter_focus
= 0;
107 static gboolean menu_can_hide
;
110 static void ice_handler(gint fd
, gpointer conn
)
113 IceProcessMessages(conn
, NULL
, &b
);
116 static void ice_watch(IceConn conn
, IcePointer data
, Bool opening
,
117 IcePointer
*watch_data
)
122 fd
= IceConnectionNumber(conn
);
123 ob_main_loop_fd_add(ob_main_loop
, fd
, ice_handler
, conn
, NULL
);
125 ob_main_loop_fd_remove(ob_main_loop
, fd
);
131 void event_startup(gboolean reconfig
)
133 if (reconfig
) return;
135 mask_table_size
= sizeof(mask_table
) / sizeof(mask_table
[0]);
137 /* get lock masks that are defined by the display (not constant) */
138 modmap
= XGetModifierMapping(ob_display
);
140 if (modmap
&& modmap
->max_keypermod
> 0) {
142 const size_t size
= mask_table_size
* modmap
->max_keypermod
;
143 /* get the values of the keyboard lock modifiers
144 Note: Caps lock is not retrieved the same way as Scroll and Num
145 lock since it doesn't need to be. */
146 const KeyCode num_lock
= XKeysymToKeycode(ob_display
, XK_Num_Lock
);
147 const KeyCode scroll_lock
= XKeysymToKeycode(ob_display
,
150 for (cnt
= 0; cnt
< size
; ++cnt
) {
151 if (! modmap
->modifiermap
[cnt
]) continue;
153 if (num_lock
== modmap
->modifiermap
[cnt
])
154 NumLockMask
= mask_table
[cnt
/ modmap
->max_keypermod
];
155 if (scroll_lock
== modmap
->modifiermap
[cnt
])
156 ScrollLockMask
= mask_table
[cnt
/ modmap
->max_keypermod
];
160 ob_main_loop_x_add(ob_main_loop
, event_process
, NULL
, NULL
);
163 IceAddConnectionWatch(ice_watch
, NULL
);
166 client_add_destructor(focus_delay_client_dest
, NULL
);
167 client_add_destructor(event_client_dest
, NULL
);
170 void event_shutdown(gboolean reconfig
)
172 if (reconfig
) return;
175 IceRemoveConnectionWatch(ice_watch
, NULL
);
178 client_remove_destructor(focus_delay_client_dest
);
179 client_remove_destructor(event_client_dest
);
180 XFreeModifiermap(modmap
);
183 static Window
event_get_window(XEvent
*e
)
190 window
= RootWindow(ob_display
, ob_screen
);
193 window
= e
->xmap
.window
;
196 window
= e
->xunmap
.window
;
199 window
= e
->xdestroywindow
.window
;
201 case ConfigureRequest
:
202 window
= e
->xconfigurerequest
.window
;
204 case ConfigureNotify
:
205 window
= e
->xconfigure
.window
;
209 if (extensions_xkb
&& e
->type
== extensions_xkb_event_basep
) {
210 switch (((XkbAnyEvent
*)e
)->xkb_type
) {
212 window
= ((XkbBellNotifyEvent
*)e
)->window
;
218 window
= e
->xany
.window
;
223 static void event_set_curtime(XEvent
*e
)
225 Time t
= CurrentTime
;
227 /* grab the lasttime and hack up the state */
243 t
= e
->xproperty
.time
;
247 t
= e
->xcrossing
.time
;
250 /* if more event types are anticipated, get their timestamp
258 #define STRIP_MODS(s) \
259 s &= ~(LockMask | NumLockMask | ScrollLockMask), \
260 /* kill off the Button1Mask etc, only want the modifiers */ \
261 s &= (ControlMask | ShiftMask | Mod1Mask | \
262 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask) \
264 static void event_hack_mods(XEvent *e)
267 XkbStateRec xkb_state
;
275 STRIP_MODS(e
->xbutton
.state
);
278 STRIP_MODS(e
->xkey
.state
);
281 STRIP_MODS(e
->xkey
.state
);
282 /* remove from the state the mask of the modifier being released, if
283 it is a modifier key being released (this is a little ugly..) */
285 if (XkbGetState(ob_display
, XkbUseCoreKbd
, &xkb_state
) == Success
) {
286 e
->xkey
.state
= xkb_state
.compat_state
;
290 kp
= modmap
->modifiermap
;
291 for (i
= 0; i
< mask_table_size
; ++i
) {
292 for (k
= 0; k
< modmap
->max_keypermod
; ++k
) {
293 if (*kp
== e
->xkey
.keycode
) { /* found the keycode */
294 /* remove the mask for it */
295 e
->xkey
.state
&= ~mask_table
[i
];
296 /* cause the first loop to break; */
298 break; /* get outta here! */
305 STRIP_MODS(e
->xmotion
.state
);
306 /* compress events */
309 while (XCheckTypedWindowEvent(ob_display
, e
->xmotion
.window
,
311 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
312 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
319 static gboolean
wanted_focusevent(XEvent
*e
)
321 gint mode
= e
->xfocus
.mode
;
322 gint detail
= e
->xfocus
.detail
;
323 Window win
= e
->xany
.window
;
325 if (e
->type
== FocusIn
) {
327 /* These are ones we never want.. */
329 /* This means focus was given by a keyboard/mouse grab. */
330 if (mode
== NotifyGrab
)
332 /* This means focus was given back from a keyboard/mouse grab. */
333 if (mode
== NotifyUngrab
)
336 /* These are the ones we want.. */
338 if (win
== RootWindow(ob_display
, ob_screen
)) {
339 /* This means focus reverted off of a client */
340 if (detail
== NotifyPointerRoot
|| detail
== NotifyDetailNone
||
341 detail
== NotifyInferior
)
347 /* This means focus moved from the root window to a client */
348 if (detail
== NotifyVirtual
)
350 /* This means focus moved from one client to another */
351 if (detail
== NotifyNonlinearVirtual
)
354 /* This means focus reverted off of a client */
355 if (detail
== NotifyInferior
)
361 g_assert(e
->type
== FocusOut
);
364 /* These are ones we never want.. */
366 /* This means focus was taken by a keyboard/mouse grab. */
367 if (mode
== NotifyGrab
)
370 /* Focus left the root window revertedto state */
371 if (win
== RootWindow(ob_display
, ob_screen
))
374 /* These are the ones we want.. */
376 /* This means focus moved from a client to the root window */
377 if (detail
== NotifyVirtual
)
379 /* This means focus moved from one client to another */
380 if (detail
== NotifyNonlinearVirtual
)
388 static Bool
look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
390 return e
->type
== FocusIn
&& wanted_focusevent(e
);
393 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
398 return keyboard_interactively_grabbed();
401 if (!wanted_focusevent(e
)) {
402 ob_debug_type(OB_DEBUG_FOCUS
, "focus event ignored\n");
405 ob_debug_type(OB_DEBUG_FOCUS
, "focus event used;\n");
411 static void event_process(const XEvent
*ec
, gpointer data
)
414 ObGroup
*group
= NULL
;
415 ObClient
*client
= NULL
;
417 ObDockApp
*dockapp
= NULL
;
418 ObWindow
*obwin
= NULL
;
420 ObEventData
*ed
= data
;
422 /* make a copy we can mangle */
426 window
= event_get_window(e
);
427 if (!(e
->type
== PropertyNotify
&&
428 (group
= g_hash_table_lookup(group_map
, &window
))))
429 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
430 switch (obwin
->type
) {
432 dock
= WINDOW_AS_DOCK(obwin
);
435 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
438 client
= WINDOW_AS_CLIENT(obwin
);
441 case Window_Internal
:
442 /* not to be used for events */
443 g_assert_not_reached();
448 if (e
->type
== FocusIn
|| e
->type
== FocusOut
) {
449 gint mode
= e
->xfocus
.mode
;
450 gint detail
= e
->xfocus
.detail
;
451 Window window
= e
->xfocus
.window
;
452 if (detail
== NotifyVirtual
) {
453 ob_debug_type(OB_DEBUG_FOCUS
,
454 "FOCUS %s NOTIFY VIRTUAL window 0x%x\n",
455 (e
->type
== FocusIn
? "IN" : "OUT"), window
);
458 else if (detail
== NotifyNonlinearVirtual
) {
459 ob_debug_type(OB_DEBUG_FOCUS
,
460 "FOCUS %s NOTIFY NONLINVIRTUAL window 0x%x\n",
461 (e
->type
== FocusIn
? "IN" : "OUT"), window
);
465 ob_debug_type(OB_DEBUG_FOCUS
,
466 "UNKNOWN FOCUS %s (d %d, m %d) window 0x%x\n",
467 (e
->type
== FocusIn
? "IN" : "OUT"),
468 detail
, mode
, window
);
471 event_set_curtime(e
);
473 if (event_ignore(e
, client
)) {
480 /* deal with it in the kernel */
482 if (menu_frame_visible
&&
483 (e
->type
== EnterNotify
|| e
->type
== LeaveNotify
))
485 /* crossing events for menu */
486 event_handle_menu(e
);
487 } else if (e
->type
== FocusIn
) {
488 if (e
->xfocus
.detail
== NotifyPointerRoot
||
489 e
->xfocus
.detail
== NotifyDetailNone
) {
490 ob_debug_type(OB_DEBUG_FOCUS
, "Focus went to root\n");
491 /* Focus has been reverted to the root window or nothing, so fall
492 back to something other than the window which just had it. */
493 focus_fallback(FALSE
);
494 } else if (e
->xfocus
.detail
== NotifyInferior
) {
495 ob_debug_type(OB_DEBUG_FOCUS
, "Focus went to parent\n");
496 /* Focus has been reverted to parent, which is our frame window,
497 or the root window, so fall back to something other than the
498 window which had it. */
499 focus_fallback(FALSE
);
500 } else if (client
&& client
!= focus_client
) {
501 focus_set_client(client
);
502 frame_adjust_focus(client
->frame
, TRUE
);
503 client_calc_layer(client
);
505 } else if (e
->type
== FocusOut
) {
506 gboolean nomove
= FALSE
;
509 ob_debug_type(OB_DEBUG_FOCUS
, "FocusOut Event\n");
511 /* Look for the followup FocusIn */
512 if (!XCheckIfEvent(ob_display
, &ce
, look_for_focusin
, NULL
)) {
513 /* There is no FocusIn, this means focus went to a window that
514 is not being managed, or a window on another screen. */
515 ob_debug_type(OB_DEBUG_FOCUS
, "Focus went to a black hole !\n");
516 } else if (ce
.xany
.window
== e
->xany
.window
) {
517 /* If focus didn't actually move anywhere, there is nothing to do*/
520 /* Focus did move, so process the FocusIn event */
521 ObEventData ed
= { .ignored
= FALSE
};
522 event_process(&ce
, &ed
);
524 /* The FocusIn was ignored, this means it was on a window
525 that isn't a client. */
526 ob_debug_type(OB_DEBUG_FOCUS
,
527 "Focus went to an unmanaged window 0x%x !\n",
529 focus_fallback(TRUE
);
533 if (client
&& !nomove
) {
534 /* This client is no longer focused, so show that */
536 frame_adjust_focus(client
->frame
, FALSE
);
537 client_calc_layer(client
);
540 event_handle_group(group
, e
);
542 event_handle_client(client
, e
);
544 event_handle_dockapp(dockapp
, e
);
546 event_handle_dock(dock
, e
);
547 else if (window
== RootWindow(ob_display
, ob_screen
))
548 event_handle_root(e
);
549 else if (e
->type
== MapRequest
)
550 client_manage(window
);
551 else if (e
->type
== ConfigureRequest
) {
552 /* unhandled configure requests must be used to configure the
556 xwc
.x
= e
->xconfigurerequest
.x
;
557 xwc
.y
= e
->xconfigurerequest
.y
;
558 xwc
.width
= e
->xconfigurerequest
.width
;
559 xwc
.height
= e
->xconfigurerequest
.height
;
560 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
561 xwc
.sibling
= e
->xconfigurerequest
.above
;
562 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
564 /* we are not to be held responsible if someone sends us an
566 xerror_set_ignore(TRUE
);
567 XConfigureWindow(ob_display
, window
,
568 e
->xconfigurerequest
.value_mask
, &xwc
);
569 xerror_set_ignore(FALSE
);
572 /* user input (action-bound) events */
573 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
574 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
575 e
->type
== KeyRelease
)
577 if (menu_frame_visible
)
578 event_handle_menu(e
);
580 if (!keyboard_process_interactive_grab(e
, &client
)) {
581 if (moveresize_in_progress
) {
584 /* make further actions work on the client being
586 client
= moveresize_client
;
589 menu_can_hide
= FALSE
;
590 ob_main_loop_timeout_add(ob_main_loop
,
591 config_menu_hide_delay
* 1000,
592 menu_hide_delay_func
,
593 NULL
, g_direct_equal
, NULL
);
595 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
596 e
->type
== MotionNotify
)
597 mouse_event(client
, e
);
598 else if (e
->type
== KeyPress
) {
599 keyboard_event((focus_cycle_target
? focus_cycle_target
:
600 (focus_hilite
? focus_hilite
: client
)),
606 /* if something happens and it's not from an XEvent, then we don't know
608 event_curtime
= CurrentTime
;
611 static void event_handle_root(XEvent
*e
)
617 ob_debug("Another WM has requested to replace us. Exiting.\n");
622 if (e
->xclient
.format
!= 32) break;
624 msgtype
= e
->xclient
.message_type
;
625 if (msgtype
== prop_atoms
.net_current_desktop
) {
626 guint d
= e
->xclient
.data
.l
[0];
627 if (d
< screen_num_desktops
) {
628 event_curtime
= e
->xclient
.data
.l
[1];
629 ob_debug("SWITCH DESKTOP TIME: %d\n", event_curtime
);
630 screen_set_desktop(d
);
632 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
633 guint d
= e
->xclient
.data
.l
[0];
635 screen_set_num_desktops(d
);
636 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
637 screen_show_desktop(e
->xclient
.data
.l
[0] != 0);
638 } else if (msgtype
== prop_atoms
.ob_control
) {
639 if (e
->xclient
.data
.l
[0] == 1)
641 else if (e
->xclient
.data
.l
[0] == 2)
646 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
)
647 screen_update_desktop_names();
648 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
649 screen_update_layout();
651 case ConfigureNotify
:
653 XRRUpdateConfiguration(e
);
662 static void event_handle_group(ObGroup
*group
, XEvent
*e
)
666 g_assert(e
->type
== PropertyNotify
);
668 for (it
= group
->members
; it
; it
= g_slist_next(it
))
669 event_handle_client(it
->data
, e
);
672 void event_enter_client(ObClient
*client
)
674 g_assert(config_focus_follow
);
676 if (client_normal(client
) && client_can_focus(client
)) {
677 if (config_focus_delay
) {
678 ObFocusDelayData
*data
;
680 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
682 data
= g_new(ObFocusDelayData
, 1);
683 data
->client
= client
;
684 data
->time
= event_curtime
;
686 ob_main_loop_timeout_add(ob_main_loop
,
689 data
, focus_delay_cmp
, focus_delay_dest
);
691 ObFocusDelayData data
;
692 data
.client
= client
;
693 data
.time
= event_curtime
;
694 focus_delay_func(&data
);
699 static void event_handle_client(ObClient
*client
, XEvent
*e
)
707 case VisibilityNotify
:
708 client
->frame
->obscured
= e
->xvisibility
.state
!= VisibilityUnobscured
;
712 /* Wheel buttons don't draw because they are an instant click, so it
713 is a waste of resources to go drawing it. */
714 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5)) {
715 con
= frame_context(client
, e
->xbutton
.window
);
716 con
= mouse_button_frame_context(con
, e
->xbutton
.button
);
718 case OB_FRAME_CONTEXT_MAXIMIZE
:
719 client
->frame
->max_press
= (e
->type
== ButtonPress
);
720 framerender_frame(client
->frame
);
722 case OB_FRAME_CONTEXT_CLOSE
:
723 client
->frame
->close_press
= (e
->type
== ButtonPress
);
724 framerender_frame(client
->frame
);
726 case OB_FRAME_CONTEXT_ICONIFY
:
727 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
728 framerender_frame(client
->frame
);
730 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
731 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
732 framerender_frame(client
->frame
);
734 case OB_FRAME_CONTEXT_SHADE
:
735 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
736 framerender_frame(client
->frame
);
739 /* nothing changes with clicks for any other contexts */
745 con
= frame_context(client
, e
->xcrossing
.window
);
747 case OB_FRAME_CONTEXT_MAXIMIZE
:
748 client
->frame
->max_hover
= FALSE
;
749 frame_adjust_state(client
->frame
);
751 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
752 client
->frame
->desk_hover
= FALSE
;
753 frame_adjust_state(client
->frame
);
755 case OB_FRAME_CONTEXT_SHADE
:
756 client
->frame
->shade_hover
= FALSE
;
757 frame_adjust_state(client
->frame
);
759 case OB_FRAME_CONTEXT_ICONIFY
:
760 client
->frame
->iconify_hover
= FALSE
;
761 frame_adjust_state(client
->frame
);
763 case OB_FRAME_CONTEXT_CLOSE
:
764 client
->frame
->close_hover
= FALSE
;
765 frame_adjust_state(client
->frame
);
767 case OB_FRAME_CONTEXT_FRAME
:
768 if (config_focus_follow
&& config_focus_delay
)
769 ob_main_loop_timeout_remove_data(ob_main_loop
,
779 gboolean nofocus
= FALSE
;
781 if (ignore_enter_focus
) {
782 ignore_enter_focus
--;
786 con
= frame_context(client
, e
->xcrossing
.window
);
788 case OB_FRAME_CONTEXT_MAXIMIZE
:
789 client
->frame
->max_hover
= TRUE
;
790 frame_adjust_state(client
->frame
);
792 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
793 client
->frame
->desk_hover
= TRUE
;
794 frame_adjust_state(client
->frame
);
796 case OB_FRAME_CONTEXT_SHADE
:
797 client
->frame
->shade_hover
= TRUE
;
798 frame_adjust_state(client
->frame
);
800 case OB_FRAME_CONTEXT_ICONIFY
:
801 client
->frame
->iconify_hover
= TRUE
;
802 frame_adjust_state(client
->frame
);
804 case OB_FRAME_CONTEXT_CLOSE
:
805 client
->frame
->close_hover
= TRUE
;
806 frame_adjust_state(client
->frame
);
808 case OB_FRAME_CONTEXT_FRAME
:
809 if (e
->xcrossing
.mode
== NotifyGrab
||
810 e
->xcrossing
.mode
== NotifyUngrab
)
812 ob_debug_type(OB_DEBUG_FOCUS
,
813 "%sNotify mode %d detail %d on %lx IGNORED\n",
814 (e
->type
== EnterNotify
? "Enter" : "Leave"),
816 e
->xcrossing
.detail
, client
?client
->window
:0);
818 ob_debug_type(OB_DEBUG_FOCUS
,
819 "%sNotify mode %d detail %d on %lx, "
820 "focusing window: %d\n",
821 (e
->type
== EnterNotify
? "Enter" : "Leave"),
823 e
->xcrossing
.detail
, (client
?client
->window
:0),
825 if (!nofocus
&& config_focus_follow
)
826 event_enter_client(client
);
834 case ConfigureRequest
:
836 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
837 ConfigureRequest
, &ce
)) {
839 /* XXX if this causes bad things.. we can compress config req's
840 with the same mask. */
841 e
->xconfigurerequest
.value_mask
|=
842 ce
.xconfigurerequest
.value_mask
;
843 if (ce
.xconfigurerequest
.value_mask
& CWX
)
844 e
->xconfigurerequest
.x
= ce
.xconfigurerequest
.x
;
845 if (ce
.xconfigurerequest
.value_mask
& CWY
)
846 e
->xconfigurerequest
.y
= ce
.xconfigurerequest
.y
;
847 if (ce
.xconfigurerequest
.value_mask
& CWWidth
)
848 e
->xconfigurerequest
.width
= ce
.xconfigurerequest
.width
;
849 if (ce
.xconfigurerequest
.value_mask
& CWHeight
)
850 e
->xconfigurerequest
.height
= ce
.xconfigurerequest
.height
;
851 if (ce
.xconfigurerequest
.value_mask
& CWBorderWidth
)
852 e
->xconfigurerequest
.border_width
=
853 ce
.xconfigurerequest
.border_width
;
854 if (ce
.xconfigurerequest
.value_mask
& CWStackMode
)
855 e
->xconfigurerequest
.detail
= ce
.xconfigurerequest
.detail
;
858 /* if we are iconic (or shaded (fvwm does this)) ignore the event */
859 if (client
->iconic
|| client
->shaded
) return;
861 /* resize, then move, as specified in the EWMH section 7.7 */
862 if (e
->xconfigurerequest
.value_mask
& (CWWidth
| CWHeight
|
868 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
869 client
->border_width
= e
->xconfigurerequest
.border_width
;
871 x
= (e
->xconfigurerequest
.value_mask
& CWX
) ?
872 e
->xconfigurerequest
.x
: client
->area
.x
;
873 y
= (e
->xconfigurerequest
.value_mask
& CWY
) ?
874 e
->xconfigurerequest
.y
: client
->area
.y
;
875 w
= (e
->xconfigurerequest
.value_mask
& CWWidth
) ?
876 e
->xconfigurerequest
.width
: client
->area
.width
;
877 h
= (e
->xconfigurerequest
.value_mask
& CWHeight
) ?
878 e
->xconfigurerequest
.height
: client
->area
.height
;
884 client
->frame
->size
.left
+ client
->frame
->size
.right
;
886 client
->frame
->size
.top
+ client
->frame
->size
.bottom
;
887 /* make this rude for size-only changes but not for position
889 gboolean moving
= ((e
->xconfigurerequest
.value_mask
& CWX
) ||
890 (e
->xconfigurerequest
.value_mask
& CWY
));
892 client_find_onscreen(client
, &newx
, &newy
, fw
, fh
,
894 if (e
->xconfigurerequest
.value_mask
& CWX
)
896 if (e
->xconfigurerequest
.value_mask
& CWY
)
900 switch (client
->gravity
) {
901 case NorthEastGravity
:
903 corner
= OB_CORNER_TOPRIGHT
;
905 case SouthWestGravity
:
907 corner
= OB_CORNER_BOTTOMLEFT
;
909 case SouthEastGravity
:
910 corner
= OB_CORNER_BOTTOMRIGHT
;
912 default: /* NorthWest, Static, etc */
913 corner
= OB_CORNER_TOPLEFT
;
916 client_configure_full(client
, corner
, x
, y
, w
, h
, FALSE
, TRUE
,
920 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
921 switch (e
->xconfigurerequest
.detail
) {
924 /* Apps are so rude. And this is totally disconnected from
925 activation/focus. Bleh. */
926 /*client_lower(client);*/
932 /* Apps are so rude. And this is totally disconnected from
933 activation/focus. Bleh. */
934 /*client_raise(client);*/
940 if (client
->ignore_unmaps
) {
941 client
->ignore_unmaps
--;
944 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
946 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
947 client
->ignore_unmaps
);
948 client_unmanage(client
);
951 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
952 client_unmanage(client
);
955 /* this is when the client is first taken captive in the frame */
956 if (e
->xreparent
.parent
== client
->frame
->plate
) break;
959 This event is quite rare and is usually handled in unmapHandler.
960 However, if the window is unmapped when the reparent event occurs,
961 the window manager never sees it because an unmap event is not sent
962 to an already unmapped window.
965 /* we don't want the reparent event, put it back on the stack for the
966 X server to deal with after we unmanage the window */
967 XPutBackEvent(ob_display
, e
);
969 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
970 client_unmanage(client
);
973 ob_debug("MapRequest for 0x%lx\n", client
->window
);
974 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
975 does, we don't want it!
976 it can happen now when the window is on
977 another desktop, but we still don't
979 client_activate(client
, FALSE
, TRUE
);
982 /* validate cuz we query stuff off the client here */
983 if (!client_validate(client
)) break;
985 if (e
->xclient
.format
!= 32) return;
987 msgtype
= e
->xclient
.message_type
;
988 if (msgtype
== prop_atoms
.wm_change_state
) {
989 /* compress changes into a single change */
990 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
992 /* XXX: it would be nice to compress ALL messages of a
993 type, not just messages in a row without other
994 message types between. */
995 if (ce
.xclient
.message_type
!= msgtype
) {
996 XPutBackEvent(ob_display
, &ce
);
999 e
->xclient
= ce
.xclient
;
1001 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1002 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
1003 /* compress changes into a single change */
1004 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1006 /* XXX: it would be nice to compress ALL messages of a
1007 type, not just messages in a row without other
1008 message types between. */
1009 if (ce
.xclient
.message_type
!= msgtype
) {
1010 XPutBackEvent(ob_display
, &ce
);
1013 e
->xclient
= ce
.xclient
;
1015 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1016 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1017 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1019 } else if (msgtype
== prop_atoms
.net_wm_state
) {
1020 /* can't compress these */
1021 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1022 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1023 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1024 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1025 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1027 client_set_state(client
, e
->xclient
.data
.l
[0],
1028 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1029 } else if (msgtype
== prop_atoms
.net_close_window
) {
1030 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1031 client_close(client
);
1032 } else if (msgtype
== prop_atoms
.net_active_window
) {
1033 ob_debug("net_active_window for 0x%lx source=%s\n",
1035 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1036 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1037 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1038 /* XXX make use of data.l[2] ! */
1039 event_curtime
= e
->xclient
.data
.l
[1];
1040 client_activate(client
, FALSE
,
1041 (e
->xclient
.data
.l
[0] == 0 ||
1042 e
->xclient
.data
.l
[0] == 2));
1043 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1044 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1045 client
->window
, e
->xclient
.data
.l
[2]);
1046 if ((Atom
)e
->xclient
.data
.l
[2] ==
1047 prop_atoms
.net_wm_moveresize_size_topleft
||
1048 (Atom
)e
->xclient
.data
.l
[2] ==
1049 prop_atoms
.net_wm_moveresize_size_top
||
1050 (Atom
)e
->xclient
.data
.l
[2] ==
1051 prop_atoms
.net_wm_moveresize_size_topright
||
1052 (Atom
)e
->xclient
.data
.l
[2] ==
1053 prop_atoms
.net_wm_moveresize_size_right
||
1054 (Atom
)e
->xclient
.data
.l
[2] ==
1055 prop_atoms
.net_wm_moveresize_size_right
||
1056 (Atom
)e
->xclient
.data
.l
[2] ==
1057 prop_atoms
.net_wm_moveresize_size_bottomright
||
1058 (Atom
)e
->xclient
.data
.l
[2] ==
1059 prop_atoms
.net_wm_moveresize_size_bottom
||
1060 (Atom
)e
->xclient
.data
.l
[2] ==
1061 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1062 (Atom
)e
->xclient
.data
.l
[2] ==
1063 prop_atoms
.net_wm_moveresize_size_left
||
1064 (Atom
)e
->xclient
.data
.l
[2] ==
1065 prop_atoms
.net_wm_moveresize_move
||
1066 (Atom
)e
->xclient
.data
.l
[2] ==
1067 prop_atoms
.net_wm_moveresize_size_keyboard
||
1068 (Atom
)e
->xclient
.data
.l
[2] ==
1069 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1071 moveresize_start(client
, e
->xclient
.data
.l
[0],
1072 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1073 e
->xclient
.data
.l
[2]);
1075 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1076 prop_atoms
.net_wm_moveresize_cancel
)
1077 moveresize_end(TRUE
);
1078 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1079 gint oldg
= client
->gravity
;
1080 gint tmpg
, x
, y
, w
, h
;
1082 if (e
->xclient
.data
.l
[0] & 0xff)
1083 tmpg
= e
->xclient
.data
.l
[0] & 0xff;
1087 if (e
->xclient
.data
.l
[0] & 1 << 8)
1088 x
= e
->xclient
.data
.l
[1];
1091 if (e
->xclient
.data
.l
[0] & 1 << 9)
1092 y
= e
->xclient
.data
.l
[2];
1095 if (e
->xclient
.data
.l
[0] & 1 << 10)
1096 w
= e
->xclient
.data
.l
[3];
1098 w
= client
->area
.width
;
1099 if (e
->xclient
.data
.l
[0] & 1 << 11)
1100 h
= e
->xclient
.data
.l
[4];
1102 h
= client
->area
.height
;
1103 client
->gravity
= tmpg
;
1109 client
->frame
->size
.left
+ client
->frame
->size
.right
;
1111 client
->frame
->size
.top
+ client
->frame
->size
.bottom
;
1112 client_find_onscreen(client
, &newx
, &newy
, fw
, fh
,
1113 client_normal(client
));
1114 if (e
->xclient
.data
.l
[0] & 1 << 8)
1116 if (e
->xclient
.data
.l
[0] & 1 << 9)
1120 client_configure(client
, OB_CORNER_TOPLEFT
,
1121 x
, y
, w
, h
, FALSE
, TRUE
);
1123 client
->gravity
= oldg
;
1126 case PropertyNotify
:
1127 /* validate cuz we query stuff off the client here */
1128 if (!client_validate(client
)) break;
1130 /* compress changes to a single property into a single change */
1131 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1135 /* XXX: it would be nice to compress ALL changes to a property,
1136 not just changes in a row without other props between. */
1138 a
= ce
.xproperty
.atom
;
1139 b
= e
->xproperty
.atom
;
1143 if ((a
== prop_atoms
.net_wm_name
||
1144 a
== prop_atoms
.wm_name
||
1145 a
== prop_atoms
.net_wm_icon_name
||
1146 a
== prop_atoms
.wm_icon_name
)
1148 (b
== prop_atoms
.net_wm_name
||
1149 b
== prop_atoms
.wm_name
||
1150 b
== prop_atoms
.net_wm_icon_name
||
1151 b
== prop_atoms
.wm_icon_name
)) {
1154 if (a
== prop_atoms
.net_wm_icon
&&
1155 b
== prop_atoms
.net_wm_icon
)
1158 XPutBackEvent(ob_display
, &ce
);
1162 msgtype
= e
->xproperty
.atom
;
1163 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1164 client_update_normal_hints(client
);
1165 /* normal hints can make a window non-resizable */
1166 client_setup_decor_and_functions(client
);
1167 } else if (msgtype
== XA_WM_HINTS
) {
1168 client_update_wmhints(client
);
1169 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1170 client_update_transient_for(client
);
1171 client_get_type(client
);
1172 /* type may have changed, so update the layer */
1173 client_calc_layer(client
);
1174 client_setup_decor_and_functions(client
);
1175 } else if (msgtype
== prop_atoms
.net_wm_name
||
1176 msgtype
== prop_atoms
.wm_name
||
1177 msgtype
== prop_atoms
.net_wm_icon_name
||
1178 msgtype
== prop_atoms
.wm_icon_name
) {
1179 client_update_title(client
);
1180 } else if (msgtype
== prop_atoms
.wm_class
) {
1181 client_update_class(client
);
1182 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1183 client_update_protocols(client
);
1184 client_setup_decor_and_functions(client
);
1186 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1187 client_update_strut(client
);
1189 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1190 client_update_icons(client
);
1192 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1193 client_update_user_time(client
);
1195 else if (msgtype
== prop_atoms
.sm_client_id
) {
1196 client_update_sm_client_id(client
);
1201 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1202 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1203 frame_adjust_shape(client
->frame
);
1209 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1213 if (e
->xbutton
.button
== 1)
1214 stacking_raise(DOCK_AS_WINDOW(s
));
1215 else if (e
->xbutton
.button
== 2)
1216 stacking_lower(DOCK_AS_WINDOW(s
));
1227 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1231 dock_app_drag(app
, &e
->xmotion
);
1234 if (app
->ignore_unmaps
) {
1235 app
->ignore_unmaps
--;
1238 dock_remove(app
, TRUE
);
1241 dock_remove(app
, FALSE
);
1243 case ReparentNotify
:
1244 dock_remove(app
, FALSE
);
1246 case ConfigureNotify
:
1247 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1252 ObMenuFrame
* find_active_menu()
1255 ObMenuFrame
*ret
= NULL
;
1257 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1266 ObMenuFrame
* find_active_or_last_menu()
1268 ObMenuFrame
*ret
= NULL
;
1270 ret
= find_active_menu();
1271 if (!ret
&& menu_frame_visible
)
1272 ret
= menu_frame_visible
->data
;
1276 static void event_handle_menu(XEvent
*ev
)
1279 ObMenuEntryFrame
*e
;
1283 if (menu_can_hide
) {
1284 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1285 ev
->xbutton
.y_root
)))
1286 menu_entry_frame_execute(e
, ev
->xbutton
.state
,
1289 menu_frame_hide_all();
1293 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1294 if (e
->ignore_enters
)
1297 menu_frame_select(e
->frame
, e
);
1301 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1302 (f
= find_active_menu()) && f
->selected
== e
&&
1303 e
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1305 menu_frame_select(e
->frame
, NULL
);
1308 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1309 ev
->xmotion
.y_root
)))
1310 menu_frame_select(e
->frame
, e
);
1313 if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_ESCAPE
))
1314 menu_frame_hide_all();
1315 else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_RETURN
)) {
1317 if ((f
= find_active_menu()))
1318 menu_entry_frame_execute(f
->selected
, ev
->xkey
.state
,
1320 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
)) {
1322 if ((f
= find_active_or_last_menu()) && f
->parent
)
1323 menu_frame_select(f
, NULL
);
1324 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
)) {
1326 if ((f
= find_active_or_last_menu()) && f
->child
)
1327 menu_frame_select_next(f
->child
);
1328 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_UP
)) {
1330 if ((f
= find_active_or_last_menu()))
1331 menu_frame_select_previous(f
);
1332 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
)) {
1334 if ((f
= find_active_or_last_menu()))
1335 menu_frame_select_next(f
);
1341 static gboolean
menu_hide_delay_func(gpointer data
)
1343 menu_can_hide
= TRUE
;
1344 return FALSE
; /* no repeat */
1347 static void focus_delay_dest(gpointer data
)
1352 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
1354 const ObFocusDelayData
*f1
= d1
, *f2
= d2
;
1355 return f1
->client
== f2
->client
;
1358 static gboolean
focus_delay_func(gpointer data
)
1360 ObFocusDelayData
*d
= data
;
1361 Time old
= event_curtime
;
1363 event_curtime
= d
->time
;
1364 if (focus_client
!= d
->client
) {
1365 if (client_focus(d
->client
) && config_focus_raise
)
1366 client_raise(d
->client
);
1368 event_curtime
= old
;
1369 return FALSE
; /* no repeat */
1372 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1374 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1378 static void event_client_dest(ObClient
*client
, gpointer data
)
1380 if (client
== focus_hilite
)
1381 focus_hilite
= NULL
;
1384 void event_halt_focus_delay()
1386 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1389 void event_ignore_queued_enters()
1391 GSList
*saved
= NULL
, *it
;
1394 XSync(ob_display
, FALSE
);
1396 /* count the events */
1398 e
= g_new(XEvent
, 1);
1399 if (XCheckTypedEvent(ob_display
, EnterNotify
, e
)) {
1402 win
= g_hash_table_lookup(window_map
, &e
->xany
.window
);
1403 if (win
&& WINDOW_IS_CLIENT(win
))
1404 ++ignore_enter_focus
;
1406 saved
= g_slist_append(saved
, e
);
1412 /* put the events back */
1413 for (it
= saved
; it
; it
= g_slist_next(it
)) {
1414 XPutBackEvent(ob_display
, it
->data
);
1417 g_slist_free(saved
);
1420 gboolean
event_time_after(Time t1
, Time t2
)
1422 g_assert(t1
!= CurrentTime
);
1423 g_assert(t2
!= CurrentTime
);
1426 Timestamp values wrap around (after about 49.7 days). The server, given
1427 its current time is represented by timestamp T, always interprets
1428 timestamps from clients by treating half of the timestamp space as being
1429 later in time than T.
1430 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
1433 /* TIME_HALF is half of the number space of a Time type variable */
1434 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
1436 if (t2
>= TIME_HALF
)
1437 /* t2 is in the second half so t1 might wrap around and be smaller than
1439 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
1441 /* t2 is in the first half so t1 has to come after it */
1442 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);