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>
67 static void event_process(const XEvent
*e
, gpointer data
);
68 static void event_client_dest(ObClient
*client
, gpointer data
);
69 static void event_handle_root(XEvent
*e
);
70 static void event_handle_menu(XEvent
*e
);
71 static void event_handle_dock(ObDock
*s
, XEvent
*e
);
72 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
);
73 static void event_handle_client(ObClient
*c
, XEvent
*e
);
74 static void event_handle_group(ObGroup
*g
, XEvent
*e
);
76 static gboolean
focus_delay_func(gpointer data
);
77 static void focus_delay_client_dest(ObClient
*client
, gpointer data
);
79 static gboolean
menu_hide_delay_func(gpointer data
);
81 /* The time for the current event being processed */
82 Time event_curtime
= CurrentTime
;
84 /*! The value of the mask for the NumLock modifier */
86 /*! The value of the mask for the ScrollLock modifier */
88 /*! The key codes for the modifier keys */
89 static XModifierKeymap
*modmap
;
90 /*! Table of the constant modifier masks */
91 static const gint mask_table
[] = {
92 ShiftMask
, LockMask
, ControlMask
, Mod1Mask
,
93 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
95 static gint mask_table_size
;
97 static guint ignore_enter_focus
= 0;
99 static gboolean menu_can_hide
;
102 static void ice_handler(gint fd
, gpointer conn
)
105 IceProcessMessages(conn
, NULL
, &b
);
108 static void ice_watch(IceConn conn
, IcePointer data
, Bool opening
,
109 IcePointer
*watch_data
)
114 fd
= IceConnectionNumber(conn
);
115 ob_main_loop_fd_add(ob_main_loop
, fd
, ice_handler
, conn
, NULL
);
117 ob_main_loop_fd_remove(ob_main_loop
, fd
);
123 void event_startup(gboolean reconfig
)
125 if (reconfig
) return;
127 mask_table_size
= sizeof(mask_table
) / sizeof(mask_table
[0]);
129 /* get lock masks that are defined by the display (not constant) */
130 modmap
= XGetModifierMapping(ob_display
);
132 if (modmap
&& modmap
->max_keypermod
> 0) {
134 const size_t size
= mask_table_size
* modmap
->max_keypermod
;
135 /* get the values of the keyboard lock modifiers
136 Note: Caps lock is not retrieved the same way as Scroll and Num
137 lock since it doesn't need to be. */
138 const KeyCode num_lock
= XKeysymToKeycode(ob_display
, XK_Num_Lock
);
139 const KeyCode scroll_lock
= XKeysymToKeycode(ob_display
,
142 for (cnt
= 0; cnt
< size
; ++cnt
) {
143 if (! modmap
->modifiermap
[cnt
]) continue;
145 if (num_lock
== modmap
->modifiermap
[cnt
])
146 NumLockMask
= mask_table
[cnt
/ modmap
->max_keypermod
];
147 if (scroll_lock
== modmap
->modifiermap
[cnt
])
148 ScrollLockMask
= mask_table
[cnt
/ modmap
->max_keypermod
];
152 ob_main_loop_x_add(ob_main_loop
, event_process
, NULL
, NULL
);
155 IceAddConnectionWatch(ice_watch
, NULL
);
158 client_add_destructor(focus_delay_client_dest
, NULL
);
159 client_add_destructor(event_client_dest
, NULL
);
162 void event_shutdown(gboolean reconfig
)
164 if (reconfig
) return;
167 IceRemoveConnectionWatch(ice_watch
, NULL
);
170 client_remove_destructor(focus_delay_client_dest
);
171 client_remove_destructor(event_client_dest
);
172 XFreeModifiermap(modmap
);
175 static Window
event_get_window(XEvent
*e
)
182 window
= RootWindow(ob_display
, ob_screen
);
185 window
= e
->xmap
.window
;
188 window
= e
->xunmap
.window
;
191 window
= e
->xdestroywindow
.window
;
193 case ConfigureRequest
:
194 window
= e
->xconfigurerequest
.window
;
196 case ConfigureNotify
:
197 window
= e
->xconfigure
.window
;
201 if (extensions_xkb
&& e
->type
== extensions_xkb_event_basep
) {
202 switch (((XkbAnyEvent
*)e
)->xkb_type
) {
204 window
= ((XkbBellNotifyEvent
*)e
)->window
;
210 window
= e
->xany
.window
;
215 static void event_set_curtime(XEvent
*e
)
217 Time t
= CurrentTime
;
219 /* grab the lasttime and hack up the state */
235 t
= e
->xproperty
.time
;
239 t
= e
->xcrossing
.time
;
242 /* if more event types are anticipated, get their timestamp
250 #define STRIP_MODS(s) \
251 s &= ~(LockMask | NumLockMask | ScrollLockMask), \
252 /* kill off the Button1Mask etc, only want the modifiers */ \
253 s &= (ControlMask | ShiftMask | Mod1Mask | \
254 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask) \
256 static void event_hack_mods(XEvent *e)
259 XkbStateRec xkb_state
;
267 STRIP_MODS(e
->xbutton
.state
);
270 STRIP_MODS(e
->xkey
.state
);
273 STRIP_MODS(e
->xkey
.state
);
274 /* remove from the state the mask of the modifier being released, if
275 it is a modifier key being released (this is a little ugly..) */
277 if (XkbGetState(ob_display
, XkbUseCoreKbd
, &xkb_state
) == Success
) {
278 e
->xkey
.state
= xkb_state
.compat_state
;
282 kp
= modmap
->modifiermap
;
283 for (i
= 0; i
< mask_table_size
; ++i
) {
284 for (k
= 0; k
< modmap
->max_keypermod
; ++k
) {
285 if (*kp
== e
->xkey
.keycode
) { /* found the keycode */
286 /* remove the mask for it */
287 e
->xkey
.state
&= ~mask_table
[i
];
288 /* cause the first loop to break; */
290 break; /* get outta here! */
297 STRIP_MODS(e
->xmotion
.state
);
298 /* compress events */
301 while (XCheckTypedWindowEvent(ob_display
, e
->xmotion
.window
,
303 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
304 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
311 static gboolean
wanted_focusevent(XEvent
*e
)
313 gint mode
= e
->xfocus
.mode
;
314 gint detail
= e
->xfocus
.detail
;
315 Window win
= e
->xany
.window
;
317 if (e
->type
== FocusIn
) {
319 /* These are ones we never want.. */
321 /* This means focus was given by a keyboard/mouse grab. */
322 if (mode
== NotifyGrab
)
324 /* This means focus was given back from a keyboard/mouse grab. */
325 if (mode
== NotifyUngrab
)
328 /* These are the ones we want.. */
330 if (win
== RootWindow(ob_display
, ob_screen
)) {
331 /* This means focus reverted off of a client */
332 if (detail
== NotifyPointerRoot
|| detail
== NotifyDetailNone
||
333 detail
== NotifyInferior
)
339 /* This means focus moved from the root window to a client */
340 if (detail
== NotifyVirtual
)
342 /* This means focus moved from one client to another */
343 if (detail
== NotifyNonlinearVirtual
)
346 /* This means focus reverted off of a client */
347 if (detail
== NotifyInferior
)
353 g_assert(e
->type
== FocusOut
);
356 /* These are ones we never want.. */
358 /* This means focus was taken by a keyboard/mouse grab. */
359 if (mode
== NotifyGrab
)
362 /* Focus left the root window revertedto state */
363 if (win
== RootWindow(ob_display
, ob_screen
))
366 /* These are the ones we want.. */
368 /* This means focus moved from a client to the root window */
369 if (detail
== NotifyVirtual
)
371 /* This means focus moved from one client to another */
372 if (detail
== NotifyNonlinearVirtual
)
380 static Bool
look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
382 return e
->type
== FocusIn
&& wanted_focusevent(e
);
385 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
390 if (e
->xcrossing
.detail
== NotifyInferior
)
395 /* I don't think this should ever happen with our event masks, but
396 if it does, we don't want it. */
399 if (!wanted_focusevent(e
))
406 static void event_process(const XEvent
*ec
, gpointer data
)
409 ObGroup
*group
= NULL
;
410 ObClient
*client
= NULL
;
412 ObDockApp
*dockapp
= NULL
;
413 ObWindow
*obwin
= NULL
;
415 ObEventData
*ed
= data
;
417 /* make a copy we can mangle */
421 window
= event_get_window(e
);
422 if (!(e
->type
== PropertyNotify
&&
423 (group
= g_hash_table_lookup(group_map
, &window
))))
424 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
425 switch (obwin
->type
) {
427 dock
= WINDOW_AS_DOCK(obwin
);
430 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
433 client
= WINDOW_AS_CLIENT(obwin
);
436 case Window_Internal
:
437 /* not to be used for events */
438 g_assert_not_reached();
443 if (e
->type
== FocusIn
|| e
->type
== FocusOut
) {
444 gint mode
= e
->xfocus
.mode
;
445 gint detail
= e
->xfocus
.detail
;
446 Window window
= e
->xfocus
.window
;
447 if (detail
== NotifyVirtual
) {
448 ob_debug_type(OB_DEBUG_FOCUS
,
449 "FOCUS %s NOTIFY VIRTUAL window 0x%x\n",
450 (e
->type
== FocusIn
? "IN" : "OUT"), window
);
453 else if (detail
== NotifyNonlinearVirtual
) {
454 ob_debug_type(OB_DEBUG_FOCUS
,
455 "FOCUS %s NOTIFY NONLINVIRTUAL window 0x%x\n",
456 (e
->type
== FocusIn
? "IN" : "OUT"), window
);
460 ob_debug_type(OB_DEBUG_FOCUS
,
461 "UNKNOWN FOCUS %s (d %d, m %d) window 0x%x\n",
462 (e
->type
== FocusIn
? "IN" : "OUT"),
463 detail
, mode
, window
);
466 event_set_curtime(e
);
468 if (event_ignore(e
, client
)) {
475 /* deal with it in the kernel */
477 event_handle_group(group
, e
);
479 event_handle_client(client
, e
);
481 event_handle_dockapp(dockapp
, e
);
483 event_handle_dock(dock
, e
);
484 else if (window
== RootWindow(ob_display
, ob_screen
))
485 event_handle_root(e
);
486 else if (e
->type
== MapRequest
)
487 client_manage(window
);
488 else if (e
->type
== ConfigureRequest
) {
489 /* unhandled configure requests must be used to configure the
493 xwc
.x
= e
->xconfigurerequest
.x
;
494 xwc
.y
= e
->xconfigurerequest
.y
;
495 xwc
.width
= e
->xconfigurerequest
.width
;
496 xwc
.height
= e
->xconfigurerequest
.height
;
497 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
498 xwc
.sibling
= e
->xconfigurerequest
.above
;
499 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
501 /* we are not to be held responsible if someone sends us an
503 xerror_set_ignore(TRUE
);
504 XConfigureWindow(ob_display
, window
,
505 e
->xconfigurerequest
.value_mask
, &xwc
);
506 xerror_set_ignore(FALSE
);
509 /* user input (action-bound) events */
510 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
511 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
512 e
->type
== KeyRelease
)
514 if (menu_frame_visible
)
515 event_handle_menu(e
);
517 if (!keyboard_process_interactive_grab(e
, &client
)) {
518 if (moveresize_in_progress
) {
521 /* make further actions work on the client being
523 client
= moveresize_client
;
526 menu_can_hide
= FALSE
;
527 ob_main_loop_timeout_add(ob_main_loop
,
528 config_menu_hide_delay
* 1000,
529 menu_hide_delay_func
,
532 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
533 e
->type
== MotionNotify
)
534 mouse_event(client
, e
);
535 else if (e
->type
== KeyPress
) {
536 keyboard_event((focus_cycle_target
? focus_cycle_target
:
537 (focus_hilite
? focus_hilite
: client
)),
543 /* if something happens and it's not from an XEvent, then we don't know
545 event_curtime
= CurrentTime
;
548 static void event_handle_root(XEvent
*e
)
554 ob_debug("Another WM has requested to replace us. Exiting.\n");
559 if (e
->xclient
.format
!= 32) break;
561 msgtype
= e
->xclient
.message_type
;
562 if (msgtype
== prop_atoms
.net_current_desktop
) {
563 guint d
= e
->xclient
.data
.l
[0];
564 if (d
< screen_num_desktops
) {
565 event_curtime
= e
->xclient
.data
.l
[1];
566 ob_debug("SWITCH DESKTOP TIME: %d\n", event_curtime
);
567 screen_set_desktop(d
);
569 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
570 guint d
= e
->xclient
.data
.l
[0];
572 screen_set_num_desktops(d
);
573 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
574 screen_show_desktop(e
->xclient
.data
.l
[0] != 0);
575 } else if (msgtype
== prop_atoms
.ob_control
) {
576 if (e
->xclient
.data
.l
[0] == 1)
578 else if (e
->xclient
.data
.l
[0] == 2)
583 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
)
584 screen_update_desktop_names();
585 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
586 screen_update_layout();
588 case ConfigureNotify
:
590 XRRUpdateConfiguration(e
);
599 static void event_handle_group(ObGroup
*group
, XEvent
*e
)
603 g_assert(e
->type
== PropertyNotify
);
605 for (it
= group
->members
; it
; it
= g_slist_next(it
))
606 event_handle_client(it
->data
, e
);
609 void event_enter_client(ObClient
*client
)
611 g_assert(config_focus_follow
);
613 if (client_normal(client
) && client_can_focus(client
)) {
614 if (config_focus_delay
) {
615 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
616 ob_main_loop_timeout_add(ob_main_loop
,
621 focus_delay_func(client
);
625 static void event_handle_client(ObClient
*client
, XEvent
*e
)
633 case VisibilityNotify
:
634 client
->frame
->obscured
= e
->xvisibility
.state
!= VisibilityUnobscured
;
638 /* Wheel buttons don't draw because they are an instant click, so it
639 is a waste of resources to go drawing it. */
640 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5)) {
641 con
= frame_context(client
, e
->xbutton
.window
);
642 con
= mouse_button_frame_context(con
, e
->xbutton
.button
);
644 case OB_FRAME_CONTEXT_MAXIMIZE
:
645 client
->frame
->max_press
= (e
->type
== ButtonPress
);
646 framerender_frame(client
->frame
);
648 case OB_FRAME_CONTEXT_CLOSE
:
649 client
->frame
->close_press
= (e
->type
== ButtonPress
);
650 framerender_frame(client
->frame
);
652 case OB_FRAME_CONTEXT_ICONIFY
:
653 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
654 framerender_frame(client
->frame
);
656 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
657 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
658 framerender_frame(client
->frame
);
660 case OB_FRAME_CONTEXT_SHADE
:
661 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
662 framerender_frame(client
->frame
);
665 /* nothing changes with clicks for any other contexts */
671 if (client
!= focus_client
) {
672 focus_set_client(client
);
673 frame_adjust_focus(client
->frame
, TRUE
);
674 client_calc_layer(client
);
678 /* Look for the followup FocusIn */
679 if (!XCheckIfEvent(ob_display
, &ce
, look_for_focusin
, NULL
)) {
680 /* There is no FocusIn, this means focus went to a window that
681 is not being managed, or a window on another screen. */
682 ob_debug_type(OB_DEBUG_FOCUS
, "Focus went to a black hole !\n");
683 } else if (ce
.xany
.window
== e
->xany
.window
) {
684 /* If focus didn't actually move anywhere, there is nothing to do*/
686 } else if (ce
.xfocus
.detail
== NotifyPointerRoot
||
687 ce
.xfocus
.detail
== NotifyDetailNone
) {
688 ob_debug_type(OB_DEBUG_FOCUS
, "Focus went to root\n");
689 /* Focus has been reverted to the root window or nothing, so fall
690 back to something other than the window which just had it. */
691 focus_fallback(FALSE
);
692 } else if (ce
.xfocus
.detail
== NotifyInferior
) {
693 ob_debug_type(OB_DEBUG_FOCUS
, "Focus went to parent\n");
694 /* Focus has been reverted to parent, which is our frame window,
695 or the root window, so fall back to something other than the
696 window which had it. */
697 focus_fallback(FALSE
);
699 /* Focus did move, so process the FocusIn event */
700 ObEventData ed
= { .ignored
= FALSE
};
701 event_process(&ce
, &ed
);
703 /* The FocusIn was ignored, this means it was on a window
704 that isn't a client. */
705 ob_debug_type(OB_DEBUG_FOCUS
,
706 "Focus went to an unmanaged window 0x%x !\n",
708 focus_fallback(TRUE
);
712 /* This client is no longer focused, so show that */
714 frame_adjust_focus(client
->frame
, FALSE
);
715 client_calc_layer(client
);
718 con
= frame_context(client
, e
->xcrossing
.window
);
720 case OB_FRAME_CONTEXT_MAXIMIZE
:
721 client
->frame
->max_hover
= FALSE
;
722 frame_adjust_state(client
->frame
);
724 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
725 client
->frame
->desk_hover
= FALSE
;
726 frame_adjust_state(client
->frame
);
728 case OB_FRAME_CONTEXT_SHADE
:
729 client
->frame
->shade_hover
= FALSE
;
730 frame_adjust_state(client
->frame
);
732 case OB_FRAME_CONTEXT_ICONIFY
:
733 client
->frame
->iconify_hover
= FALSE
;
734 frame_adjust_state(client
->frame
);
736 case OB_FRAME_CONTEXT_CLOSE
:
737 client
->frame
->close_hover
= FALSE
;
738 frame_adjust_state(client
->frame
);
740 case OB_FRAME_CONTEXT_FRAME
:
741 if (config_focus_follow
&& config_focus_delay
)
742 ob_main_loop_timeout_remove_data(ob_main_loop
,
752 gboolean nofocus
= FALSE
;
754 if (ignore_enter_focus
) {
755 ignore_enter_focus
--;
759 con
= frame_context(client
, e
->xcrossing
.window
);
761 case OB_FRAME_CONTEXT_MAXIMIZE
:
762 client
->frame
->max_hover
= TRUE
;
763 frame_adjust_state(client
->frame
);
765 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
766 client
->frame
->desk_hover
= TRUE
;
767 frame_adjust_state(client
->frame
);
769 case OB_FRAME_CONTEXT_SHADE
:
770 client
->frame
->shade_hover
= TRUE
;
771 frame_adjust_state(client
->frame
);
773 case OB_FRAME_CONTEXT_ICONIFY
:
774 client
->frame
->iconify_hover
= TRUE
;
775 frame_adjust_state(client
->frame
);
777 case OB_FRAME_CONTEXT_CLOSE
:
778 client
->frame
->close_hover
= TRUE
;
779 frame_adjust_state(client
->frame
);
781 case OB_FRAME_CONTEXT_FRAME
:
782 if (e
->xcrossing
.mode
== NotifyGrab
||
783 e
->xcrossing
.mode
== NotifyUngrab
)
785 ob_debug_type(OB_DEBUG_FOCUS
,
786 "%sNotify mode %d detail %d on %lx IGNORED\n",
787 (e
->type
== EnterNotify
? "Enter" : "Leave"),
789 e
->xcrossing
.detail
, client
?client
->window
:0);
791 ob_debug_type(OB_DEBUG_FOCUS
,
792 "%sNotify mode %d detail %d on %lx, "
793 "focusing window: %d\n",
794 (e
->type
== EnterNotify
? "Enter" : "Leave"),
796 e
->xcrossing
.detail
, (client
?client
->window
:0),
798 if (!nofocus
&& config_focus_follow
)
799 event_enter_client(client
);
807 case ConfigureRequest
:
809 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
810 ConfigureRequest
, &ce
)) {
812 /* XXX if this causes bad things.. we can compress config req's
813 with the same mask. */
814 e
->xconfigurerequest
.value_mask
|=
815 ce
.xconfigurerequest
.value_mask
;
816 if (ce
.xconfigurerequest
.value_mask
& CWX
)
817 e
->xconfigurerequest
.x
= ce
.xconfigurerequest
.x
;
818 if (ce
.xconfigurerequest
.value_mask
& CWY
)
819 e
->xconfigurerequest
.y
= ce
.xconfigurerequest
.y
;
820 if (ce
.xconfigurerequest
.value_mask
& CWWidth
)
821 e
->xconfigurerequest
.width
= ce
.xconfigurerequest
.width
;
822 if (ce
.xconfigurerequest
.value_mask
& CWHeight
)
823 e
->xconfigurerequest
.height
= ce
.xconfigurerequest
.height
;
824 if (ce
.xconfigurerequest
.value_mask
& CWBorderWidth
)
825 e
->xconfigurerequest
.border_width
=
826 ce
.xconfigurerequest
.border_width
;
827 if (ce
.xconfigurerequest
.value_mask
& CWStackMode
)
828 e
->xconfigurerequest
.detail
= ce
.xconfigurerequest
.detail
;
831 /* if we are iconic (or shaded (fvwm does this)) ignore the event */
832 if (client
->iconic
|| client
->shaded
) return;
834 /* resize, then move, as specified in the EWMH section 7.7 */
835 if (e
->xconfigurerequest
.value_mask
& (CWWidth
| CWHeight
|
841 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
842 client
->border_width
= e
->xconfigurerequest
.border_width
;
844 x
= (e
->xconfigurerequest
.value_mask
& CWX
) ?
845 e
->xconfigurerequest
.x
: client
->area
.x
;
846 y
= (e
->xconfigurerequest
.value_mask
& CWY
) ?
847 e
->xconfigurerequest
.y
: client
->area
.y
;
848 w
= (e
->xconfigurerequest
.value_mask
& CWWidth
) ?
849 e
->xconfigurerequest
.width
: client
->area
.width
;
850 h
= (e
->xconfigurerequest
.value_mask
& CWHeight
) ?
851 e
->xconfigurerequest
.height
: client
->area
.height
;
857 client
->frame
->size
.left
+ client
->frame
->size
.right
;
859 client
->frame
->size
.top
+ client
->frame
->size
.bottom
;
860 /* make this rude for size-only changes but not for position
862 gboolean moving
= ((e
->xconfigurerequest
.value_mask
& CWX
) ||
863 (e
->xconfigurerequest
.value_mask
& CWY
));
865 client_find_onscreen(client
, &newx
, &newy
, fw
, fh
,
867 if (e
->xconfigurerequest
.value_mask
& CWX
)
869 if (e
->xconfigurerequest
.value_mask
& CWY
)
873 switch (client
->gravity
) {
874 case NorthEastGravity
:
876 corner
= OB_CORNER_TOPRIGHT
;
878 case SouthWestGravity
:
880 corner
= OB_CORNER_BOTTOMLEFT
;
882 case SouthEastGravity
:
883 corner
= OB_CORNER_BOTTOMRIGHT
;
885 default: /* NorthWest, Static, etc */
886 corner
= OB_CORNER_TOPLEFT
;
889 client_configure_full(client
, corner
, x
, y
, w
, h
, FALSE
, TRUE
,
893 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
894 switch (e
->xconfigurerequest
.detail
) {
897 /* Apps are so rude. And this is totally disconnected from
898 activation/focus. Bleh. */
899 /*client_lower(client);*/
905 /* Apps are so rude. And this is totally disconnected from
906 activation/focus. Bleh. */
907 /*client_raise(client);*/
913 if (client
->ignore_unmaps
) {
914 client
->ignore_unmaps
--;
917 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
919 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
920 client
->ignore_unmaps
);
921 client_unmanage(client
);
924 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
925 client_unmanage(client
);
928 /* this is when the client is first taken captive in the frame */
929 if (e
->xreparent
.parent
== client
->frame
->plate
) break;
932 This event is quite rare and is usually handled in unmapHandler.
933 However, if the window is unmapped when the reparent event occurs,
934 the window manager never sees it because an unmap event is not sent
935 to an already unmapped window.
938 /* we don't want the reparent event, put it back on the stack for the
939 X server to deal with after we unmanage the window */
940 XPutBackEvent(ob_display
, e
);
942 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
943 client_unmanage(client
);
946 ob_debug("MapRequest for 0x%lx\n", client
->window
);
947 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
948 does, we don't want it!
949 it can happen now when the window is on
950 another desktop, but we still don't
952 client_activate(client
, FALSE
, TRUE
);
955 /* validate cuz we query stuff off the client here */
956 if (!client_validate(client
)) break;
958 if (e
->xclient
.format
!= 32) return;
960 msgtype
= e
->xclient
.message_type
;
961 if (msgtype
== prop_atoms
.wm_change_state
) {
962 /* compress changes into a single change */
963 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
965 /* XXX: it would be nice to compress ALL messages of a
966 type, not just messages in a row without other
967 message types between. */
968 if (ce
.xclient
.message_type
!= msgtype
) {
969 XPutBackEvent(ob_display
, &ce
);
972 e
->xclient
= ce
.xclient
;
974 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
975 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
976 /* compress changes into a single change */
977 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
979 /* XXX: it would be nice to compress ALL messages of a
980 type, not just messages in a row without other
981 message types between. */
982 if (ce
.xclient
.message_type
!= msgtype
) {
983 XPutBackEvent(ob_display
, &ce
);
986 e
->xclient
= ce
.xclient
;
988 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
989 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
990 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
992 } else if (msgtype
== prop_atoms
.net_wm_state
) {
993 /* can't compress these */
994 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
995 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
996 e
->xclient
.data
.l
[0] == 1 ? "Add" :
997 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
998 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1000 client_set_state(client
, e
->xclient
.data
.l
[0],
1001 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1002 } else if (msgtype
== prop_atoms
.net_close_window
) {
1003 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1004 client_close(client
);
1005 } else if (msgtype
== prop_atoms
.net_active_window
) {
1006 ob_debug("net_active_window for 0x%lx source=%s\n",
1008 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1009 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1010 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1011 /* XXX make use of data.l[2] ! */
1012 event_curtime
= e
->xclient
.data
.l
[1];
1013 client_activate(client
, FALSE
,
1014 (e
->xclient
.data
.l
[0] == 0 ||
1015 e
->xclient
.data
.l
[0] == 2));
1016 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1017 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1018 client
->window
, e
->xclient
.data
.l
[2]);
1019 if ((Atom
)e
->xclient
.data
.l
[2] ==
1020 prop_atoms
.net_wm_moveresize_size_topleft
||
1021 (Atom
)e
->xclient
.data
.l
[2] ==
1022 prop_atoms
.net_wm_moveresize_size_top
||
1023 (Atom
)e
->xclient
.data
.l
[2] ==
1024 prop_atoms
.net_wm_moveresize_size_topright
||
1025 (Atom
)e
->xclient
.data
.l
[2] ==
1026 prop_atoms
.net_wm_moveresize_size_right
||
1027 (Atom
)e
->xclient
.data
.l
[2] ==
1028 prop_atoms
.net_wm_moveresize_size_right
||
1029 (Atom
)e
->xclient
.data
.l
[2] ==
1030 prop_atoms
.net_wm_moveresize_size_bottomright
||
1031 (Atom
)e
->xclient
.data
.l
[2] ==
1032 prop_atoms
.net_wm_moveresize_size_bottom
||
1033 (Atom
)e
->xclient
.data
.l
[2] ==
1034 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1035 (Atom
)e
->xclient
.data
.l
[2] ==
1036 prop_atoms
.net_wm_moveresize_size_left
||
1037 (Atom
)e
->xclient
.data
.l
[2] ==
1038 prop_atoms
.net_wm_moveresize_move
||
1039 (Atom
)e
->xclient
.data
.l
[2] ==
1040 prop_atoms
.net_wm_moveresize_size_keyboard
||
1041 (Atom
)e
->xclient
.data
.l
[2] ==
1042 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1044 moveresize_start(client
, e
->xclient
.data
.l
[0],
1045 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1046 e
->xclient
.data
.l
[2]);
1048 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1049 prop_atoms
.net_wm_moveresize_cancel
)
1050 moveresize_end(TRUE
);
1051 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1052 gint oldg
= client
->gravity
;
1053 gint tmpg
, x
, y
, w
, h
;
1055 if (e
->xclient
.data
.l
[0] & 0xff)
1056 tmpg
= e
->xclient
.data
.l
[0] & 0xff;
1060 if (e
->xclient
.data
.l
[0] & 1 << 8)
1061 x
= e
->xclient
.data
.l
[1];
1064 if (e
->xclient
.data
.l
[0] & 1 << 9)
1065 y
= e
->xclient
.data
.l
[2];
1068 if (e
->xclient
.data
.l
[0] & 1 << 10)
1069 w
= e
->xclient
.data
.l
[3];
1071 w
= client
->area
.width
;
1072 if (e
->xclient
.data
.l
[0] & 1 << 11)
1073 h
= e
->xclient
.data
.l
[4];
1075 h
= client
->area
.height
;
1076 client
->gravity
= tmpg
;
1082 client
->frame
->size
.left
+ client
->frame
->size
.right
;
1084 client
->frame
->size
.top
+ client
->frame
->size
.bottom
;
1085 client_find_onscreen(client
, &newx
, &newy
, fw
, fh
,
1086 client_normal(client
));
1087 if (e
->xclient
.data
.l
[0] & 1 << 8)
1089 if (e
->xclient
.data
.l
[0] & 1 << 9)
1093 client_configure(client
, OB_CORNER_TOPLEFT
,
1094 x
, y
, w
, h
, FALSE
, TRUE
);
1096 client
->gravity
= oldg
;
1099 case PropertyNotify
:
1100 /* validate cuz we query stuff off the client here */
1101 if (!client_validate(client
)) break;
1103 /* compress changes to a single property into a single change */
1104 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1108 /* XXX: it would be nice to compress ALL changes to a property,
1109 not just changes in a row without other props between. */
1111 a
= ce
.xproperty
.atom
;
1112 b
= e
->xproperty
.atom
;
1116 if ((a
== prop_atoms
.net_wm_name
||
1117 a
== prop_atoms
.wm_name
||
1118 a
== prop_atoms
.net_wm_icon_name
||
1119 a
== prop_atoms
.wm_icon_name
)
1121 (b
== prop_atoms
.net_wm_name
||
1122 b
== prop_atoms
.wm_name
||
1123 b
== prop_atoms
.net_wm_icon_name
||
1124 b
== prop_atoms
.wm_icon_name
)) {
1127 if (a
== prop_atoms
.net_wm_icon
&&
1128 b
== prop_atoms
.net_wm_icon
)
1131 XPutBackEvent(ob_display
, &ce
);
1135 msgtype
= e
->xproperty
.atom
;
1136 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1137 client_update_normal_hints(client
);
1138 /* normal hints can make a window non-resizable */
1139 client_setup_decor_and_functions(client
);
1140 } else if (msgtype
== XA_WM_HINTS
) {
1141 client_update_wmhints(client
);
1142 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1143 client_update_transient_for(client
);
1144 client_get_type(client
);
1145 /* type may have changed, so update the layer */
1146 client_calc_layer(client
);
1147 client_setup_decor_and_functions(client
);
1148 } else if (msgtype
== prop_atoms
.net_wm_name
||
1149 msgtype
== prop_atoms
.wm_name
||
1150 msgtype
== prop_atoms
.net_wm_icon_name
||
1151 msgtype
== prop_atoms
.wm_icon_name
) {
1152 client_update_title(client
);
1153 } else if (msgtype
== prop_atoms
.wm_class
) {
1154 client_update_class(client
);
1155 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1156 client_update_protocols(client
);
1157 client_setup_decor_and_functions(client
);
1159 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1160 client_update_strut(client
);
1162 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1163 client_update_icons(client
);
1165 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1166 client_update_user_time(client
);
1168 else if (msgtype
== prop_atoms
.sm_client_id
) {
1169 client_update_sm_client_id(client
);
1174 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1175 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1176 frame_adjust_shape(client
->frame
);
1182 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1186 if (e
->xbutton
.button
== 1)
1187 stacking_raise(DOCK_AS_WINDOW(s
));
1188 else if (e
->xbutton
.button
== 2)
1189 stacking_lower(DOCK_AS_WINDOW(s
));
1200 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1204 dock_app_drag(app
, &e
->xmotion
);
1207 if (app
->ignore_unmaps
) {
1208 app
->ignore_unmaps
--;
1211 dock_remove(app
, TRUE
);
1214 dock_remove(app
, FALSE
);
1216 case ReparentNotify
:
1217 dock_remove(app
, FALSE
);
1219 case ConfigureNotify
:
1220 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1225 ObMenuFrame
* find_active_menu()
1228 ObMenuFrame
*ret
= NULL
;
1230 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1239 ObMenuFrame
* find_active_or_last_menu()
1241 ObMenuFrame
*ret
= NULL
;
1243 ret
= find_active_menu();
1244 if (!ret
&& menu_frame_visible
)
1245 ret
= menu_frame_visible
->data
;
1249 static void event_handle_menu(XEvent
*ev
)
1252 ObMenuEntryFrame
*e
;
1256 if (menu_can_hide
) {
1257 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1258 ev
->xbutton
.y_root
)))
1259 menu_entry_frame_execute(e
, ev
->xbutton
.state
,
1262 menu_frame_hide_all();
1266 if ((f
= menu_frame_under(ev
->xmotion
.x_root
,
1267 ev
->xmotion
.y_root
))) {
1268 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1269 ev
->xmotion
.y_root
))) {
1270 /* XXX menu_frame_entry_move_on_screen(f); */
1271 menu_frame_select(f
, e
);
1277 a
= find_active_menu();
1279 a
->selected
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1281 menu_frame_select(a
, NULL
);
1286 if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_ESCAPE
))
1287 menu_frame_hide_all();
1288 else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_RETURN
)) {
1290 if ((f
= find_active_menu()))
1291 menu_entry_frame_execute(f
->selected
, ev
->xkey
.state
,
1293 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
)) {
1295 if ((f
= find_active_or_last_menu()) && f
->parent
)
1296 menu_frame_select(f
, NULL
);
1297 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
)) {
1299 if ((f
= find_active_or_last_menu()) && f
->child
)
1300 menu_frame_select_next(f
->child
);
1301 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_UP
)) {
1303 if ((f
= find_active_or_last_menu()))
1304 menu_frame_select_previous(f
);
1305 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
)) {
1307 if ((f
= find_active_or_last_menu()))
1308 menu_frame_select_next(f
);
1314 static gboolean
menu_hide_delay_func(gpointer data
)
1316 menu_can_hide
= TRUE
;
1317 return FALSE
; /* no repeat */
1320 static gboolean
focus_delay_func(gpointer data
)
1324 if (focus_client
!= c
) {
1325 if (client_focus(c
) && config_focus_raise
)
1328 return FALSE
; /* no repeat */
1331 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1333 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1337 static void event_client_dest(ObClient
*client
, gpointer data
)
1339 if (client
== focus_hilite
)
1340 focus_hilite
= NULL
;
1343 void event_halt_focus_delay()
1345 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1348 void event_ignore_queued_enters()
1350 GSList
*saved
= NULL
, *it
;
1353 XSync(ob_display
, FALSE
);
1355 /* count the events */
1357 e
= g_new(XEvent
, 1);
1358 if (XCheckTypedEvent(ob_display
, EnterNotify
, e
)) {
1361 win
= g_hash_table_lookup(window_map
, &e
->xany
.window
);
1362 if (win
&& WINDOW_IS_CLIENT(win
))
1363 ++ignore_enter_focus
;
1365 saved
= g_slist_append(saved
, e
);
1371 /* put the events back */
1372 for (it
= saved
; it
; it
= g_slist_next(it
)) {
1373 XPutBackEvent(ob_display
, it
->data
);
1376 g_slist_free(saved
);
1379 gboolean
event_time_after(Time t1
, Time t2
)
1381 g_assert(t1
!= CurrentTime
);
1382 g_assert(t2
!= CurrentTime
);
1385 Timestamp values wrap around (after about 49.7 days). The server, given
1386 its current time is represented by timestamp T, always interprets
1387 timestamps from clients by treating half of the timestamp space as being
1388 later in time than T.
1389 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
1392 /* TIME_HALF is half of the number space of a Time type variable */
1393 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
1395 if (t2
>= TIME_HALF
)
1396 /* t2 is in the second half so t1 might wrap around and be smaller than
1398 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
1400 /* t2 is in the first half so t1 has to come after it */
1401 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);