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_destroy(gpointer data
);
83 static gboolean
focus_delay_func(gpointer data
);
84 static void focus_delay_client_dest(ObClient
*client
, gpointer data
);
86 static gboolean
menu_hide_delay_func(gpointer data
);
88 /* The time for the current event being processed */
89 Time event_curtime
= CurrentTime
;
91 /*! The value of the mask for the NumLock modifier */
93 /*! The value of the mask for the ScrollLock modifier */
95 /*! The key codes for the modifier keys */
96 static XModifierKeymap
*modmap
;
97 /*! Table of the constant modifier masks */
98 static const gint mask_table
[] = {
99 ShiftMask
, LockMask
, ControlMask
, Mod1Mask
,
100 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
102 static gint mask_table_size
;
104 static guint ignore_enter_focus
= 0;
106 static gboolean menu_can_hide
;
108 static ObFocusDelayData focus_delay_data
= { .client
= NULL
,
109 .time
= CurrentTime
};
114 static void ice_handler(gint fd
, gpointer conn
)
117 IceProcessMessages(conn
, NULL
, &b
);
120 static void ice_watch(IceConn conn
, IcePointer data
, Bool opening
,
121 IcePointer
*watch_data
)
126 fd
= IceConnectionNumber(conn
);
127 ob_main_loop_fd_add(ob_main_loop
, fd
, ice_handler
, conn
, NULL
);
129 ob_main_loop_fd_remove(ob_main_loop
, fd
);
135 void event_startup(gboolean reconfig
)
137 if (reconfig
) return;
139 mask_table_size
= sizeof(mask_table
) / sizeof(mask_table
[0]);
141 /* get lock masks that are defined by the display (not constant) */
142 modmap
= XGetModifierMapping(ob_display
);
144 if (modmap
&& modmap
->max_keypermod
> 0) {
146 const size_t size
= mask_table_size
* modmap
->max_keypermod
;
147 /* get the values of the keyboard lock modifiers
148 Note: Caps lock is not retrieved the same way as Scroll and Num
149 lock since it doesn't need to be. */
150 const KeyCode num_lock
= XKeysymToKeycode(ob_display
, XK_Num_Lock
);
151 const KeyCode scroll_lock
= XKeysymToKeycode(ob_display
,
154 for (cnt
= 0; cnt
< size
; ++cnt
) {
155 if (! modmap
->modifiermap
[cnt
]) continue;
157 if (num_lock
== modmap
->modifiermap
[cnt
])
158 NumLockMask
= mask_table
[cnt
/ modmap
->max_keypermod
];
159 if (scroll_lock
== modmap
->modifiermap
[cnt
])
160 ScrollLockMask
= mask_table
[cnt
/ modmap
->max_keypermod
];
164 ob_main_loop_x_add(ob_main_loop
, event_process
, NULL
, NULL
);
167 IceAddConnectionWatch(ice_watch
, NULL
);
170 client_add_destructor(focus_delay_client_dest
, NULL
);
171 client_add_destructor(event_client_dest
, NULL
);
174 void event_shutdown(gboolean reconfig
)
176 if (reconfig
) return;
179 IceRemoveConnectionWatch(ice_watch
, NULL
);
182 client_remove_destructor(focus_delay_client_dest
);
183 client_remove_destructor(event_client_dest
);
184 XFreeModifiermap(modmap
);
187 static Window
event_get_window(XEvent
*e
)
194 window
= RootWindow(ob_display
, ob_screen
);
197 window
= e
->xmap
.window
;
200 window
= e
->xunmap
.window
;
203 window
= e
->xdestroywindow
.window
;
205 case ConfigureRequest
:
206 window
= e
->xconfigurerequest
.window
;
208 case ConfigureNotify
:
209 window
= e
->xconfigure
.window
;
213 if (extensions_xkb
&& e
->type
== extensions_xkb_event_basep
) {
214 switch (((XkbAnyEvent
*)e
)->xkb_type
) {
216 window
= ((XkbBellNotifyEvent
*)e
)->window
;
222 window
= e
->xany
.window
;
227 static void event_set_curtime(XEvent
*e
)
229 Time t
= CurrentTime
;
231 /* grab the lasttime and hack up the state */
247 t
= e
->xproperty
.time
;
251 t
= e
->xcrossing
.time
;
254 /* if more event types are anticipated, get their timestamp
262 #define STRIP_MODS(s) \
263 s &= ~(LockMask | NumLockMask | ScrollLockMask), \
264 /* kill off the Button1Mask etc, only want the modifiers */ \
265 s &= (ControlMask | ShiftMask | Mod1Mask | \
266 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask) \
268 static void event_hack_mods(XEvent *e)
271 XkbStateRec xkb_state
;
279 STRIP_MODS(e
->xbutton
.state
);
282 STRIP_MODS(e
->xkey
.state
);
285 STRIP_MODS(e
->xkey
.state
);
286 /* remove from the state the mask of the modifier being released, if
287 it is a modifier key being released (this is a little ugly..) */
289 if (XkbGetState(ob_display
, XkbUseCoreKbd
, &xkb_state
) == Success
) {
290 e
->xkey
.state
= xkb_state
.compat_state
;
294 kp
= modmap
->modifiermap
;
295 for (i
= 0; i
< mask_table_size
; ++i
) {
296 for (k
= 0; k
< modmap
->max_keypermod
; ++k
) {
297 if (*kp
== e
->xkey
.keycode
) { /* found the keycode */
298 /* remove the mask for it */
299 e
->xkey
.state
&= ~mask_table
[i
];
300 /* cause the first loop to break; */
302 break; /* get outta here! */
309 STRIP_MODS(e
->xmotion
.state
);
310 /* compress events */
313 while (XCheckTypedWindowEvent(ob_display
, e
->xmotion
.window
,
315 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
316 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
323 static gboolean
wanted_focusevent(XEvent
*e
)
325 gint mode
= e
->xfocus
.mode
;
326 gint detail
= e
->xfocus
.detail
;
327 Window win
= e
->xany
.window
;
329 if (e
->type
== FocusIn
) {
331 /* These are ones we never want.. */
333 /* This means focus was given by a keyboard/mouse grab. */
334 if (mode
== NotifyGrab
)
336 /* This means focus was given back from a keyboard/mouse grab. */
337 if (mode
== NotifyUngrab
)
340 /* These are the ones we want.. */
342 if (win
== RootWindow(ob_display
, ob_screen
)) {
343 /* This means focus reverted off of a client */
344 if (detail
== NotifyPointerRoot
|| detail
== NotifyDetailNone
||
345 detail
== NotifyInferior
)
351 /* This means focus moved from the root window to a client */
352 if (detail
== NotifyVirtual
)
354 /* This means focus moved from one client to another */
355 if (detail
== NotifyNonlinearVirtual
)
358 /* This means focus reverted off of a client */
359 if (detail
== NotifyInferior
)
365 g_assert(e
->type
== FocusOut
);
368 /* These are ones we never want.. */
370 /* This means focus was taken by a keyboard/mouse grab. */
371 if (mode
== NotifyGrab
)
374 /* Focus left the root window revertedto state */
375 if (win
== RootWindow(ob_display
, ob_screen
))
378 /* These are the ones we want.. */
380 /* This means focus moved from a client to the root window */
381 if (detail
== NotifyVirtual
)
383 /* This means focus moved from one client to another */
384 if (detail
== NotifyNonlinearVirtual
)
392 static Bool
look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
394 return e
->type
== FocusIn
&& wanted_focusevent(e
);
397 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
402 return keyboard_interactively_grabbed();
405 /* I don't think this should ever happen with our event masks, but
406 if it does, we don't want it. */
409 if (!wanted_focusevent(e
))
416 static void event_process(const XEvent
*ec
, gpointer data
)
419 ObGroup
*group
= NULL
;
420 ObClient
*client
= NULL
;
422 ObDockApp
*dockapp
= NULL
;
423 ObWindow
*obwin
= NULL
;
425 ObEventData
*ed
= data
;
427 /* make a copy we can mangle */
431 window
= event_get_window(e
);
432 if (!(e
->type
== PropertyNotify
&&
433 (group
= g_hash_table_lookup(group_map
, &window
))))
434 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
435 switch (obwin
->type
) {
437 dock
= WINDOW_AS_DOCK(obwin
);
440 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
443 client
= WINDOW_AS_CLIENT(obwin
);
446 case Window_Internal
:
447 /* not to be used for events */
448 g_assert_not_reached();
453 if (e
->type
== FocusIn
|| e
->type
== FocusOut
) {
454 gint mode
= e
->xfocus
.mode
;
455 gint detail
= e
->xfocus
.detail
;
456 Window window
= e
->xfocus
.window
;
457 if (detail
== NotifyVirtual
) {
458 ob_debug_type(OB_DEBUG_FOCUS
,
459 "FOCUS %s NOTIFY VIRTUAL window 0x%x\n",
460 (e
->type
== FocusIn
? "IN" : "OUT"), window
);
463 else if (detail
== NotifyNonlinearVirtual
) {
464 ob_debug_type(OB_DEBUG_FOCUS
,
465 "FOCUS %s NOTIFY NONLINVIRTUAL window 0x%x\n",
466 (e
->type
== FocusIn
? "IN" : "OUT"), window
);
470 ob_debug_type(OB_DEBUG_FOCUS
,
471 "UNKNOWN FOCUS %s (d %d, m %d) window 0x%x\n",
472 (e
->type
== FocusIn
? "IN" : "OUT"),
473 detail
, mode
, window
);
476 event_set_curtime(e
);
478 if (event_ignore(e
, client
)) {
485 /* deal with it in the kernel */
487 if (menu_frame_visible
&&
488 (e
->type
== EnterNotify
|| e
->type
== LeaveNotify
))
490 /* crossing events for menu */
491 event_handle_menu(e
);
493 event_handle_group(group
, e
);
495 event_handle_client(client
, e
);
497 event_handle_dockapp(dockapp
, e
);
499 event_handle_dock(dock
, e
);
500 else if (window
== RootWindow(ob_display
, ob_screen
))
501 event_handle_root(e
);
502 else if (e
->type
== MapRequest
)
503 client_manage(window
);
504 else if (e
->type
== ConfigureRequest
) {
505 /* unhandled configure requests must be used to configure the
509 xwc
.x
= e
->xconfigurerequest
.x
;
510 xwc
.y
= e
->xconfigurerequest
.y
;
511 xwc
.width
= e
->xconfigurerequest
.width
;
512 xwc
.height
= e
->xconfigurerequest
.height
;
513 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
514 xwc
.sibling
= e
->xconfigurerequest
.above
;
515 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
517 /* we are not to be held responsible if someone sends us an
519 xerror_set_ignore(TRUE
);
520 XConfigureWindow(ob_display
, window
,
521 e
->xconfigurerequest
.value_mask
, &xwc
);
522 xerror_set_ignore(FALSE
);
525 /* user input (action-bound) events */
526 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
527 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
528 e
->type
== KeyRelease
)
530 if (menu_frame_visible
)
531 event_handle_menu(e
);
533 if (!keyboard_process_interactive_grab(e
, &client
)) {
534 if (moveresize_in_progress
) {
537 /* make further actions work on the client being
539 client
= moveresize_client
;
542 menu_can_hide
= FALSE
;
543 ob_main_loop_timeout_add(ob_main_loop
,
544 config_menu_hide_delay
* 1000,
545 menu_hide_delay_func
,
548 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
549 e
->type
== MotionNotify
)
550 mouse_event(client
, e
);
551 else if (e
->type
== KeyPress
) {
552 keyboard_event((focus_cycle_target
? focus_cycle_target
:
553 (focus_hilite
? focus_hilite
: client
)),
559 /* if something happens and it's not from an XEvent, then we don't know
561 event_curtime
= CurrentTime
;
564 static void event_handle_root(XEvent
*e
)
570 ob_debug("Another WM has requested to replace us. Exiting.\n");
575 if (e
->xclient
.format
!= 32) break;
577 msgtype
= e
->xclient
.message_type
;
578 if (msgtype
== prop_atoms
.net_current_desktop
) {
579 guint d
= e
->xclient
.data
.l
[0];
580 if (d
< screen_num_desktops
) {
581 event_curtime
= e
->xclient
.data
.l
[1];
582 ob_debug("SWITCH DESKTOP TIME: %d\n", event_curtime
);
583 screen_set_desktop(d
);
585 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
586 guint d
= e
->xclient
.data
.l
[0];
588 screen_set_num_desktops(d
);
589 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
590 screen_show_desktop(e
->xclient
.data
.l
[0] != 0);
591 } else if (msgtype
== prop_atoms
.ob_control
) {
592 if (e
->xclient
.data
.l
[0] == 1)
594 else if (e
->xclient
.data
.l
[0] == 2)
599 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
)
600 screen_update_desktop_names();
601 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
602 screen_update_layout();
604 case ConfigureNotify
:
606 XRRUpdateConfiguration(e
);
615 static void event_handle_group(ObGroup
*group
, XEvent
*e
)
619 g_assert(e
->type
== PropertyNotify
);
621 for (it
= group
->members
; it
; it
= g_slist_next(it
))
622 event_handle_client(it
->data
, e
);
625 void event_enter_client(ObClient
*client
)
627 g_assert(config_focus_follow
);
629 if (client_normal(client
) && client_can_focus(client
)) {
630 if (config_focus_delay
) {
631 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
633 focus_delay_data
.client
= client
;
634 focus_delay_data
.time
= event_curtime
;
636 ob_main_loop_timeout_add(ob_main_loop
,
639 NULL
, focus_delay_destroy
);
641 focus_delay_func(NULL
);
645 static void event_handle_client(ObClient
*client
, XEvent
*e
)
653 case VisibilityNotify
:
654 client
->frame
->obscured
= e
->xvisibility
.state
!= VisibilityUnobscured
;
658 /* Wheel buttons don't draw because they are an instant click, so it
659 is a waste of resources to go drawing it. */
660 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5)) {
661 con
= frame_context(client
, e
->xbutton
.window
);
662 con
= mouse_button_frame_context(con
, e
->xbutton
.button
);
664 case OB_FRAME_CONTEXT_MAXIMIZE
:
665 client
->frame
->max_press
= (e
->type
== ButtonPress
);
666 framerender_frame(client
->frame
);
668 case OB_FRAME_CONTEXT_CLOSE
:
669 client
->frame
->close_press
= (e
->type
== ButtonPress
);
670 framerender_frame(client
->frame
);
672 case OB_FRAME_CONTEXT_ICONIFY
:
673 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
674 framerender_frame(client
->frame
);
676 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
677 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
678 framerender_frame(client
->frame
);
680 case OB_FRAME_CONTEXT_SHADE
:
681 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
682 framerender_frame(client
->frame
);
685 /* nothing changes with clicks for any other contexts */
691 if (client
!= focus_client
) {
692 focus_set_client(client
);
693 frame_adjust_focus(client
->frame
, TRUE
);
694 client_calc_layer(client
);
698 /* Look for the followup FocusIn */
699 if (!XCheckIfEvent(ob_display
, &ce
, look_for_focusin
, NULL
)) {
700 /* There is no FocusIn, this means focus went to a window that
701 is not being managed, or a window on another screen. */
702 ob_debug_type(OB_DEBUG_FOCUS
, "Focus went to a black hole !\n");
703 } else if (ce
.xany
.window
== e
->xany
.window
) {
704 /* If focus didn't actually move anywhere, there is nothing to do*/
706 } else if (ce
.xfocus
.detail
== NotifyPointerRoot
||
707 ce
.xfocus
.detail
== NotifyDetailNone
) {
708 ob_debug_type(OB_DEBUG_FOCUS
, "Focus went to root\n");
709 /* Focus has been reverted to the root window or nothing, so fall
710 back to something other than the window which just had it. */
711 focus_fallback(FALSE
);
712 } else if (ce
.xfocus
.detail
== NotifyInferior
) {
713 ob_debug_type(OB_DEBUG_FOCUS
, "Focus went to parent\n");
714 /* Focus has been reverted to parent, which is our frame window,
715 or the root window, so fall back to something other than the
716 window which had it. */
717 focus_fallback(FALSE
);
719 /* Focus did move, so process the FocusIn event */
720 ObEventData ed
= { .ignored
= FALSE
};
721 event_process(&ce
, &ed
);
723 /* The FocusIn was ignored, this means it was on a window
724 that isn't a client. */
725 ob_debug_type(OB_DEBUG_FOCUS
,
726 "Focus went to an unmanaged window 0x%x !\n",
728 focus_fallback(TRUE
);
732 /* This client is no longer focused, so show that */
734 frame_adjust_focus(client
->frame
, FALSE
);
735 client_calc_layer(client
);
738 con
= frame_context(client
, e
->xcrossing
.window
);
740 case OB_FRAME_CONTEXT_MAXIMIZE
:
741 client
->frame
->max_hover
= FALSE
;
742 frame_adjust_state(client
->frame
);
744 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
745 client
->frame
->desk_hover
= FALSE
;
746 frame_adjust_state(client
->frame
);
748 case OB_FRAME_CONTEXT_SHADE
:
749 client
->frame
->shade_hover
= FALSE
;
750 frame_adjust_state(client
->frame
);
752 case OB_FRAME_CONTEXT_ICONIFY
:
753 client
->frame
->iconify_hover
= FALSE
;
754 frame_adjust_state(client
->frame
);
756 case OB_FRAME_CONTEXT_CLOSE
:
757 client
->frame
->close_hover
= FALSE
;
758 frame_adjust_state(client
->frame
);
760 case OB_FRAME_CONTEXT_FRAME
:
761 if (config_focus_follow
&& config_focus_delay
)
762 ob_main_loop_timeout_remove_data(ob_main_loop
,
772 gboolean nofocus
= FALSE
;
774 if (ignore_enter_focus
) {
775 ignore_enter_focus
--;
779 con
= frame_context(client
, e
->xcrossing
.window
);
781 case OB_FRAME_CONTEXT_MAXIMIZE
:
782 client
->frame
->max_hover
= TRUE
;
783 frame_adjust_state(client
->frame
);
785 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
786 client
->frame
->desk_hover
= TRUE
;
787 frame_adjust_state(client
->frame
);
789 case OB_FRAME_CONTEXT_SHADE
:
790 client
->frame
->shade_hover
= TRUE
;
791 frame_adjust_state(client
->frame
);
793 case OB_FRAME_CONTEXT_ICONIFY
:
794 client
->frame
->iconify_hover
= TRUE
;
795 frame_adjust_state(client
->frame
);
797 case OB_FRAME_CONTEXT_CLOSE
:
798 client
->frame
->close_hover
= TRUE
;
799 frame_adjust_state(client
->frame
);
801 case OB_FRAME_CONTEXT_FRAME
:
802 if (e
->xcrossing
.mode
== NotifyGrab
||
803 e
->xcrossing
.mode
== NotifyUngrab
)
805 ob_debug_type(OB_DEBUG_FOCUS
,
806 "%sNotify mode %d detail %d on %lx IGNORED\n",
807 (e
->type
== EnterNotify
? "Enter" : "Leave"),
809 e
->xcrossing
.detail
, client
?client
->window
:0);
811 ob_debug_type(OB_DEBUG_FOCUS
,
812 "%sNotify mode %d detail %d on %lx, "
813 "focusing window: %d\n",
814 (e
->type
== EnterNotify
? "Enter" : "Leave"),
816 e
->xcrossing
.detail
, (client
?client
->window
:0),
818 if (!nofocus
&& config_focus_follow
)
819 event_enter_client(client
);
827 case ConfigureRequest
:
829 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
830 ConfigureRequest
, &ce
)) {
832 /* XXX if this causes bad things.. we can compress config req's
833 with the same mask. */
834 e
->xconfigurerequest
.value_mask
|=
835 ce
.xconfigurerequest
.value_mask
;
836 if (ce
.xconfigurerequest
.value_mask
& CWX
)
837 e
->xconfigurerequest
.x
= ce
.xconfigurerequest
.x
;
838 if (ce
.xconfigurerequest
.value_mask
& CWY
)
839 e
->xconfigurerequest
.y
= ce
.xconfigurerequest
.y
;
840 if (ce
.xconfigurerequest
.value_mask
& CWWidth
)
841 e
->xconfigurerequest
.width
= ce
.xconfigurerequest
.width
;
842 if (ce
.xconfigurerequest
.value_mask
& CWHeight
)
843 e
->xconfigurerequest
.height
= ce
.xconfigurerequest
.height
;
844 if (ce
.xconfigurerequest
.value_mask
& CWBorderWidth
)
845 e
->xconfigurerequest
.border_width
=
846 ce
.xconfigurerequest
.border_width
;
847 if (ce
.xconfigurerequest
.value_mask
& CWStackMode
)
848 e
->xconfigurerequest
.detail
= ce
.xconfigurerequest
.detail
;
851 /* if we are iconic (or shaded (fvwm does this)) ignore the event */
852 if (client
->iconic
|| client
->shaded
) return;
854 /* resize, then move, as specified in the EWMH section 7.7 */
855 if (e
->xconfigurerequest
.value_mask
& (CWWidth
| CWHeight
|
861 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
862 client
->border_width
= e
->xconfigurerequest
.border_width
;
864 x
= (e
->xconfigurerequest
.value_mask
& CWX
) ?
865 e
->xconfigurerequest
.x
: client
->area
.x
;
866 y
= (e
->xconfigurerequest
.value_mask
& CWY
) ?
867 e
->xconfigurerequest
.y
: client
->area
.y
;
868 w
= (e
->xconfigurerequest
.value_mask
& CWWidth
) ?
869 e
->xconfigurerequest
.width
: client
->area
.width
;
870 h
= (e
->xconfigurerequest
.value_mask
& CWHeight
) ?
871 e
->xconfigurerequest
.height
: client
->area
.height
;
877 client
->frame
->size
.left
+ client
->frame
->size
.right
;
879 client
->frame
->size
.top
+ client
->frame
->size
.bottom
;
880 /* make this rude for size-only changes but not for position
882 gboolean moving
= ((e
->xconfigurerequest
.value_mask
& CWX
) ||
883 (e
->xconfigurerequest
.value_mask
& CWY
));
885 client_find_onscreen(client
, &newx
, &newy
, fw
, fh
,
887 if (e
->xconfigurerequest
.value_mask
& CWX
)
889 if (e
->xconfigurerequest
.value_mask
& CWY
)
893 switch (client
->gravity
) {
894 case NorthEastGravity
:
896 corner
= OB_CORNER_TOPRIGHT
;
898 case SouthWestGravity
:
900 corner
= OB_CORNER_BOTTOMLEFT
;
902 case SouthEastGravity
:
903 corner
= OB_CORNER_BOTTOMRIGHT
;
905 default: /* NorthWest, Static, etc */
906 corner
= OB_CORNER_TOPLEFT
;
909 client_configure_full(client
, corner
, x
, y
, w
, h
, FALSE
, TRUE
,
913 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
914 switch (e
->xconfigurerequest
.detail
) {
917 /* Apps are so rude. And this is totally disconnected from
918 activation/focus. Bleh. */
919 /*client_lower(client);*/
925 /* Apps are so rude. And this is totally disconnected from
926 activation/focus. Bleh. */
927 /*client_raise(client);*/
933 if (client
->ignore_unmaps
) {
934 client
->ignore_unmaps
--;
937 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
939 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
940 client
->ignore_unmaps
);
941 client_unmanage(client
);
944 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
945 client_unmanage(client
);
948 /* this is when the client is first taken captive in the frame */
949 if (e
->xreparent
.parent
== client
->frame
->plate
) break;
952 This event is quite rare and is usually handled in unmapHandler.
953 However, if the window is unmapped when the reparent event occurs,
954 the window manager never sees it because an unmap event is not sent
955 to an already unmapped window.
958 /* we don't want the reparent event, put it back on the stack for the
959 X server to deal with after we unmanage the window */
960 XPutBackEvent(ob_display
, e
);
962 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
963 client_unmanage(client
);
966 ob_debug("MapRequest for 0x%lx\n", client
->window
);
967 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
968 does, we don't want it!
969 it can happen now when the window is on
970 another desktop, but we still don't
972 client_activate(client
, FALSE
, TRUE
);
975 /* validate cuz we query stuff off the client here */
976 if (!client_validate(client
)) break;
978 if (e
->xclient
.format
!= 32) return;
980 msgtype
= e
->xclient
.message_type
;
981 if (msgtype
== prop_atoms
.wm_change_state
) {
982 /* compress changes into a single change */
983 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
985 /* XXX: it would be nice to compress ALL messages of a
986 type, not just messages in a row without other
987 message types between. */
988 if (ce
.xclient
.message_type
!= msgtype
) {
989 XPutBackEvent(ob_display
, &ce
);
992 e
->xclient
= ce
.xclient
;
994 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
995 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
996 /* compress changes into a single change */
997 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
999 /* XXX: it would be nice to compress ALL messages of a
1000 type, not just messages in a row without other
1001 message types between. */
1002 if (ce
.xclient
.message_type
!= msgtype
) {
1003 XPutBackEvent(ob_display
, &ce
);
1006 e
->xclient
= ce
.xclient
;
1008 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1009 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1010 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1012 } else if (msgtype
== prop_atoms
.net_wm_state
) {
1013 /* can't compress these */
1014 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1015 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1016 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1017 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1018 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1020 client_set_state(client
, e
->xclient
.data
.l
[0],
1021 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1022 } else if (msgtype
== prop_atoms
.net_close_window
) {
1023 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1024 client_close(client
);
1025 } else if (msgtype
== prop_atoms
.net_active_window
) {
1026 ob_debug("net_active_window for 0x%lx source=%s\n",
1028 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1029 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1030 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1031 /* XXX make use of data.l[2] ! */
1032 event_curtime
= e
->xclient
.data
.l
[1];
1033 client_activate(client
, FALSE
,
1034 (e
->xclient
.data
.l
[0] == 0 ||
1035 e
->xclient
.data
.l
[0] == 2));
1036 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1037 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1038 client
->window
, e
->xclient
.data
.l
[2]);
1039 if ((Atom
)e
->xclient
.data
.l
[2] ==
1040 prop_atoms
.net_wm_moveresize_size_topleft
||
1041 (Atom
)e
->xclient
.data
.l
[2] ==
1042 prop_atoms
.net_wm_moveresize_size_top
||
1043 (Atom
)e
->xclient
.data
.l
[2] ==
1044 prop_atoms
.net_wm_moveresize_size_topright
||
1045 (Atom
)e
->xclient
.data
.l
[2] ==
1046 prop_atoms
.net_wm_moveresize_size_right
||
1047 (Atom
)e
->xclient
.data
.l
[2] ==
1048 prop_atoms
.net_wm_moveresize_size_right
||
1049 (Atom
)e
->xclient
.data
.l
[2] ==
1050 prop_atoms
.net_wm_moveresize_size_bottomright
||
1051 (Atom
)e
->xclient
.data
.l
[2] ==
1052 prop_atoms
.net_wm_moveresize_size_bottom
||
1053 (Atom
)e
->xclient
.data
.l
[2] ==
1054 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1055 (Atom
)e
->xclient
.data
.l
[2] ==
1056 prop_atoms
.net_wm_moveresize_size_left
||
1057 (Atom
)e
->xclient
.data
.l
[2] ==
1058 prop_atoms
.net_wm_moveresize_move
||
1059 (Atom
)e
->xclient
.data
.l
[2] ==
1060 prop_atoms
.net_wm_moveresize_size_keyboard
||
1061 (Atom
)e
->xclient
.data
.l
[2] ==
1062 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1064 moveresize_start(client
, e
->xclient
.data
.l
[0],
1065 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1066 e
->xclient
.data
.l
[2]);
1068 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1069 prop_atoms
.net_wm_moveresize_cancel
)
1070 moveresize_end(TRUE
);
1071 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1072 gint oldg
= client
->gravity
;
1073 gint tmpg
, x
, y
, w
, h
;
1075 if (e
->xclient
.data
.l
[0] & 0xff)
1076 tmpg
= e
->xclient
.data
.l
[0] & 0xff;
1080 if (e
->xclient
.data
.l
[0] & 1 << 8)
1081 x
= e
->xclient
.data
.l
[1];
1084 if (e
->xclient
.data
.l
[0] & 1 << 9)
1085 y
= e
->xclient
.data
.l
[2];
1088 if (e
->xclient
.data
.l
[0] & 1 << 10)
1089 w
= e
->xclient
.data
.l
[3];
1091 w
= client
->area
.width
;
1092 if (e
->xclient
.data
.l
[0] & 1 << 11)
1093 h
= e
->xclient
.data
.l
[4];
1095 h
= client
->area
.height
;
1096 client
->gravity
= tmpg
;
1102 client
->frame
->size
.left
+ client
->frame
->size
.right
;
1104 client
->frame
->size
.top
+ client
->frame
->size
.bottom
;
1105 client_find_onscreen(client
, &newx
, &newy
, fw
, fh
,
1106 client_normal(client
));
1107 if (e
->xclient
.data
.l
[0] & 1 << 8)
1109 if (e
->xclient
.data
.l
[0] & 1 << 9)
1113 client_configure(client
, OB_CORNER_TOPLEFT
,
1114 x
, y
, w
, h
, FALSE
, TRUE
);
1116 client
->gravity
= oldg
;
1119 case PropertyNotify
:
1120 /* validate cuz we query stuff off the client here */
1121 if (!client_validate(client
)) break;
1123 /* compress changes to a single property into a single change */
1124 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1128 /* XXX: it would be nice to compress ALL changes to a property,
1129 not just changes in a row without other props between. */
1131 a
= ce
.xproperty
.atom
;
1132 b
= e
->xproperty
.atom
;
1136 if ((a
== prop_atoms
.net_wm_name
||
1137 a
== prop_atoms
.wm_name
||
1138 a
== prop_atoms
.net_wm_icon_name
||
1139 a
== prop_atoms
.wm_icon_name
)
1141 (b
== prop_atoms
.net_wm_name
||
1142 b
== prop_atoms
.wm_name
||
1143 b
== prop_atoms
.net_wm_icon_name
||
1144 b
== prop_atoms
.wm_icon_name
)) {
1147 if (a
== prop_atoms
.net_wm_icon
&&
1148 b
== prop_atoms
.net_wm_icon
)
1151 XPutBackEvent(ob_display
, &ce
);
1155 msgtype
= e
->xproperty
.atom
;
1156 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1157 client_update_normal_hints(client
);
1158 /* normal hints can make a window non-resizable */
1159 client_setup_decor_and_functions(client
);
1160 } else if (msgtype
== XA_WM_HINTS
) {
1161 client_update_wmhints(client
);
1162 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1163 client_update_transient_for(client
);
1164 client_get_type(client
);
1165 /* type may have changed, so update the layer */
1166 client_calc_layer(client
);
1167 client_setup_decor_and_functions(client
);
1168 } else if (msgtype
== prop_atoms
.net_wm_name
||
1169 msgtype
== prop_atoms
.wm_name
||
1170 msgtype
== prop_atoms
.net_wm_icon_name
||
1171 msgtype
== prop_atoms
.wm_icon_name
) {
1172 client_update_title(client
);
1173 } else if (msgtype
== prop_atoms
.wm_class
) {
1174 client_update_class(client
);
1175 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1176 client_update_protocols(client
);
1177 client_setup_decor_and_functions(client
);
1179 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1180 client_update_strut(client
);
1182 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1183 client_update_icons(client
);
1185 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1186 client_update_user_time(client
);
1188 else if (msgtype
== prop_atoms
.sm_client_id
) {
1189 client_update_sm_client_id(client
);
1194 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1195 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1196 frame_adjust_shape(client
->frame
);
1202 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1206 if (e
->xbutton
.button
== 1)
1207 stacking_raise(DOCK_AS_WINDOW(s
));
1208 else if (e
->xbutton
.button
== 2)
1209 stacking_lower(DOCK_AS_WINDOW(s
));
1220 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1224 dock_app_drag(app
, &e
->xmotion
);
1227 if (app
->ignore_unmaps
) {
1228 app
->ignore_unmaps
--;
1231 dock_remove(app
, TRUE
);
1234 dock_remove(app
, FALSE
);
1236 case ReparentNotify
:
1237 dock_remove(app
, FALSE
);
1239 case ConfigureNotify
:
1240 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1245 ObMenuFrame
* find_active_menu()
1248 ObMenuFrame
*ret
= NULL
;
1250 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1259 ObMenuFrame
* find_active_or_last_menu()
1261 ObMenuFrame
*ret
= NULL
;
1263 ret
= find_active_menu();
1264 if (!ret
&& menu_frame_visible
)
1265 ret
= menu_frame_visible
->data
;
1269 static void event_handle_menu(XEvent
*ev
)
1272 ObMenuEntryFrame
*e
;
1276 if (menu_can_hide
) {
1277 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1278 ev
->xbutton
.y_root
)))
1279 menu_entry_frame_execute(e
, ev
->xbutton
.state
,
1282 menu_frame_hide_all();
1286 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1287 if (e
->ignore_enters
)
1290 menu_frame_select(e
->frame
, e
);
1294 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1295 (f
= find_active_menu()) && f
->selected
== e
&&
1296 e
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1298 menu_frame_select(e
->frame
, NULL
);
1301 if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_ESCAPE
))
1302 menu_frame_hide_all();
1303 else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_RETURN
)) {
1305 if ((f
= find_active_menu()))
1306 menu_entry_frame_execute(f
->selected
, ev
->xkey
.state
,
1308 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
)) {
1310 if ((f
= find_active_or_last_menu()) && f
->parent
)
1311 menu_frame_select(f
, NULL
);
1312 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
)) {
1314 if ((f
= find_active_or_last_menu()) && f
->child
)
1315 menu_frame_select_next(f
->child
);
1316 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_UP
)) {
1318 if ((f
= find_active_or_last_menu()))
1319 menu_frame_select_previous(f
);
1320 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
)) {
1322 if ((f
= find_active_or_last_menu()))
1323 menu_frame_select_next(f
);
1329 static gboolean
menu_hide_delay_func(gpointer data
)
1331 menu_can_hide
= TRUE
;
1332 return FALSE
; /* no repeat */
1335 static void focus_delay_destroy(gpointer data
)
1337 focus_delay_data
.client
= NULL
;
1338 focus_delay_data
.time
= CurrentTime
;
1341 static gboolean
focus_delay_func(gpointer data
)
1343 Time old
= event_curtime
;
1344 event_curtime
= focus_delay_data
.time
;
1345 if (focus_client
!= focus_delay_data
.client
) {
1346 if (client_focus(focus_delay_data
.client
) && config_focus_raise
)
1347 client_raise(focus_delay_data
.client
);
1349 event_curtime
= old
;
1350 return FALSE
; /* no repeat */
1353 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1355 if (focus_delay_data
.client
== client
)
1356 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1359 static void event_client_dest(ObClient
*client
, gpointer data
)
1361 if (client
== focus_hilite
)
1362 focus_hilite
= NULL
;
1365 void event_halt_focus_delay()
1367 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1370 void event_ignore_queued_enters()
1372 GSList
*saved
= NULL
, *it
;
1375 XSync(ob_display
, FALSE
);
1377 /* count the events */
1379 e
= g_new(XEvent
, 1);
1380 if (XCheckTypedEvent(ob_display
, EnterNotify
, e
)) {
1383 win
= g_hash_table_lookup(window_map
, &e
->xany
.window
);
1384 if (win
&& WINDOW_IS_CLIENT(win
))
1385 ++ignore_enter_focus
;
1387 saved
= g_slist_append(saved
, e
);
1393 /* put the events back */
1394 for (it
= saved
; it
; it
= g_slist_next(it
)) {
1395 XPutBackEvent(ob_display
, it
->data
);
1398 g_slist_free(saved
);
1401 gboolean
event_time_after(Time t1
, Time t2
)
1403 g_assert(t1
!= CurrentTime
);
1404 g_assert(t2
!= CurrentTime
);
1407 Timestamp values wrap around (after about 49.7 days). The server, given
1408 its current time is represented by timestamp T, always interprets
1409 timestamps from clients by treating half of the timestamp space as being
1410 later in time than T.
1411 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
1414 /* TIME_HALF is half of the number space of a Time type variable */
1415 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
1417 if (t2
>= TIME_HALF
)
1418 /* t2 is in the second half so t1 might wrap around and be smaller than
1420 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
1422 /* t2 is in the first half so t1 has to come after it */
1423 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);