1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 event.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
33 #include "menuframe.h"
37 #include "focus_cycle.h"
38 #include "moveresize.h"
42 #include "obt/display.h"
44 #include "obt/keyboard.h"
47 #include <X11/Xatom.h>
50 #ifdef HAVE_SYS_SELECT_H
51 # include <sys/select.h>
57 # include <unistd.h> /* for usleep() */
60 # include <X11/XKBlib.h>
64 #include <X11/ICE/ICElib.h>
81 gulong start
; /* inclusive */
82 gulong end
; /* inclusive */
85 static void event_process(const XEvent
*e
, gpointer data
);
86 static void event_handle_root(XEvent
*e
);
87 static gboolean
event_handle_menu_input(XEvent
*e
);
88 static void event_handle_menu(ObMenuFrame
*frame
, XEvent
*e
);
89 static gboolean
event_handle_prompt(ObPrompt
*p
, XEvent
*e
);
90 static void event_handle_dock(ObDock
*s
, XEvent
*e
);
91 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
);
92 static void event_handle_client(ObClient
*c
, XEvent
*e
);
93 static gboolean
event_handle_user_input(ObClient
*client
, XEvent
*e
);
94 static gboolean
is_enter_focus_event_ignored(gulong serial
);
95 static void event_ignore_enter_range(gulong start
, gulong end
);
97 static void focus_delay_dest(gpointer data
);
98 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
);
99 static gboolean
focus_delay_func(gpointer data
);
100 static gboolean
unfocus_delay_func(gpointer data
);
101 static void focus_delay_client_dest(ObClient
*client
, gpointer data
);
103 Time event_curtime
= CurrentTime
;
104 Time event_last_user_time
= CurrentTime
;
105 /*! The serial of the current X event */
107 static gulong event_curserial
;
108 static gboolean focus_left_screen
= FALSE
;
109 /*! A list of ObSerialRanges which are to be ignored for mouse enter events */
110 static GSList
*ignore_serials
= NULL
;
113 static void ice_handler(gint fd
, gpointer conn
)
116 IceProcessMessages(conn
, NULL
, &b
);
119 static void ice_watch(IceConn conn
, IcePointer data
, Bool opening
,
120 IcePointer
*watch_data
)
125 fd
= IceConnectionNumber(conn
);
126 obt_main_loop_fd_add(ob_main_loop
, fd
, ice_handler
, conn
, NULL
);
128 obt_main_loop_fd_remove(ob_main_loop
, fd
);
134 void event_startup(gboolean reconfig
)
136 if (reconfig
) return;
138 obt_main_loop_x_add(ob_main_loop
, event_process
, NULL
, NULL
);
141 IceAddConnectionWatch(ice_watch
, NULL
);
144 client_add_destroy_notify(focus_delay_client_dest
, NULL
);
147 void event_shutdown(gboolean reconfig
)
149 if (reconfig
) return;
152 IceRemoveConnectionWatch(ice_watch
, NULL
);
155 client_remove_destroy_notify(focus_delay_client_dest
);
158 static Window
event_get_window(XEvent
*e
)
165 window
= obt_root(ob_screen
);
168 window
= e
->xcreatewindow
.window
;
171 window
= e
->xmaprequest
.window
;
174 window
= e
->xmap
.window
;
177 window
= e
->xunmap
.window
;
180 window
= e
->xdestroywindow
.window
;
182 case ConfigureRequest
:
183 window
= e
->xconfigurerequest
.window
;
185 case ConfigureNotify
:
186 window
= e
->xconfigure
.window
;
190 if (obt_display_extension_xkb
&&
191 e
->type
== obt_display_extension_xkb_basep
)
193 switch (((XkbAnyEvent
*)e
)->xkb_type
) {
195 window
= ((XkbBellNotifyEvent
*)e
)->window
;
202 if (obt_display_extension_sync
&&
203 e
->type
== obt_display_extension_sync_basep
+ XSyncAlarmNotify
)
208 window
= e
->xany
.window
;
213 static void event_set_curtime(XEvent
*e
)
215 Time t
= CurrentTime
;
217 /* grab the lasttime and hack up the state */
233 t
= e
->xproperty
.time
;
237 t
= e
->xcrossing
.time
;
241 if (obt_display_extension_sync
&&
242 e
->type
== obt_display_extension_sync_basep
+ XSyncAlarmNotify
)
244 t
= ((XSyncAlarmNotifyEvent
*)e
)->time
;
247 /* if more event types are anticipated, get their timestamp
252 /* watch that if we get an event earlier than the last specified user_time,
253 which can happen if the clock goes backwards, we erase the last
254 specified user_time */
255 if (t
&& event_last_user_time
&& event_time_after(event_last_user_time
, t
))
256 event_last_user_time
= CurrentTime
;
261 static void event_hack_mods(XEvent
*e
)
264 XkbStateRec xkb_state
;
270 e
->xbutton
.state
= obt_keyboard_only_modmasks(e
->xbutton
.state
);
273 e
->xkey
.state
= obt_keyboard_only_modmasks(e
->xkey
.state
);
277 /* If XKB is present, then the modifiers are all strange from its
278 magic. Our X core protocol stuff won't work, so we use this to
279 find what the modifier state is instead. */
280 if (XkbGetState(obt_display
, XkbUseCoreKbd
, &xkb_state
) == Success
)
282 obt_keyboard_only_modmasks(xkb_state
.compat_state
);
286 e
->xkey
.state
= obt_keyboard_only_modmasks(e
->xkey
.state
);
287 /* remove from the state the mask of the modifier key being
288 released, if it is a modifier key being released that is */
289 e
->xkey
.state
&= ~obt_keyboard_keycode_to_modmask(e
->xkey
.keycode
);
293 e
->xmotion
.state
= obt_keyboard_only_modmasks(e
->xmotion
.state
);
294 /* compress events */
297 while (XCheckTypedWindowEvent(obt_display
, e
->xmotion
.window
,
299 e
->xmotion
.x
= ce
.xmotion
.x
;
300 e
->xmotion
.y
= ce
.xmotion
.y
;
301 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
302 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
309 static gboolean
wanted_focusevent(XEvent
*e
, gboolean in_client_only
)
311 gint mode
= e
->xfocus
.mode
;
312 gint detail
= e
->xfocus
.detail
;
313 Window win
= e
->xany
.window
;
315 if (e
->type
== FocusIn
) {
316 /* These are ones we never want.. */
318 /* This means focus was given by a keyboard/mouse grab. */
319 if (mode
== NotifyGrab
)
321 /* This means focus was given back from a keyboard/mouse grab. */
322 if (mode
== NotifyUngrab
)
325 /* These are the ones we want.. */
327 if (win
== obt_root(ob_screen
)) {
328 /* If looking for a focus in on a client, then always return
329 FALSE for focus in's to the root window */
332 /* This means focus reverted off of a client */
333 else if (detail
== NotifyPointerRoot
||
334 detail
== NotifyDetailNone
||
335 detail
== NotifyInferior
||
336 /* This means focus got here from another screen */
337 detail
== NotifyNonlinear
)
343 /* It was on a client, was it a valid one?
344 It's possible to get a FocusIn event for a client that was managed
347 if (in_client_only
) {
348 ObWindow
*w
= window_find(e
->xfocus
.window
);
349 if (!w
|| !WINDOW_IS_CLIENT(w
))
353 /* This means focus reverted to parent from the client (this
354 happens often during iconify animation) */
355 if (detail
== NotifyInferior
)
359 /* This means focus moved from the root window to a client */
360 if (detail
== NotifyVirtual
)
362 /* This means focus moved from one client to another */
363 if (detail
== NotifyNonlinearVirtual
)
369 g_assert(e
->type
== FocusOut
);
371 /* These are ones we never want.. */
373 /* This means focus was taken by a keyboard/mouse grab. */
374 if (mode
== NotifyGrab
)
376 /* This means focus was grabbed on a window and it was released. */
377 if (mode
== NotifyUngrab
)
380 /* Focus left the root window revertedto state */
381 if (win
== obt_root(ob_screen
))
384 /* These are the ones we want.. */
386 /* This means focus moved from a client to the root window */
387 if (detail
== NotifyVirtual
)
389 /* This means focus moved from one client to another */
390 if (detail
== NotifyNonlinearVirtual
)
398 static Bool
event_look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
400 return e
->type
== FocusIn
&& wanted_focusevent(e
, FALSE
);
403 static Bool
event_look_for_focusin_client(Display
*d
, XEvent
*e
, XPointer arg
)
405 return e
->type
== FocusIn
&& wanted_focusevent(e
, TRUE
);
408 static void print_focusevent(XEvent
*e
)
410 gint mode
= e
->xfocus
.mode
;
411 gint detail
= e
->xfocus
.detail
;
412 Window win
= e
->xany
.window
;
413 const gchar
*modestr
, *detailstr
;
416 case NotifyNormal
: modestr
="NotifyNormal"; break;
417 case NotifyGrab
: modestr
="NotifyGrab"; break;
418 case NotifyUngrab
: modestr
="NotifyUngrab"; break;
419 case NotifyWhileGrabbed
: modestr
="NotifyWhileGrabbed"; break;
420 default: g_assert_not_reached();
423 case NotifyAncestor
: detailstr
="NotifyAncestor"; break;
424 case NotifyVirtual
: detailstr
="NotifyVirtual"; break;
425 case NotifyInferior
: detailstr
="NotifyInferior"; break;
426 case NotifyNonlinear
: detailstr
="NotifyNonlinear"; break;
427 case NotifyNonlinearVirtual
: detailstr
="NotifyNonlinearVirtual"; break;
428 case NotifyPointer
: detailstr
="NotifyPointer"; break;
429 case NotifyPointerRoot
: detailstr
="NotifyPointerRoot"; break;
430 case NotifyDetailNone
: detailstr
="NotifyDetailNone"; break;
431 default: g_assert_not_reached();
434 if (mode
== NotifyGrab
|| mode
== NotifyUngrab
)
439 ob_debug_type(OB_DEBUG_FOCUS
, "Focus%s 0x%x mode=%s detail=%s",
440 (e
->xfocus
.type
== FocusIn
? "In" : "Out"),
446 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
451 if (!wanted_focusevent(e
, FALSE
))
456 if (!wanted_focusevent(e
, FALSE
))
463 static void event_process(const XEvent
*ec
, gpointer data
)
466 ObEventData
*ed
= data
;
469 ObClient
*client
= NULL
;
471 ObDockApp
*dockapp
= NULL
;
472 ObWindow
*obwin
= NULL
;
473 ObMenuFrame
*menu
= NULL
;
474 ObPrompt
*prompt
= NULL
;
477 /* make a copy we can mangle */
481 window
= event_get_window(e
);
482 if (window
== obt_root(ob_screen
))
483 /* don't do any lookups, waste of cpu */;
484 else if ((obwin
= window_find(window
))) {
485 switch (obwin
->type
) {
486 case OB_WINDOW_CLASS_DOCK
:
487 dock
= WINDOW_AS_DOCK(obwin
);
489 case OB_WINDOW_CLASS_CLIENT
:
490 client
= WINDOW_AS_CLIENT(obwin
);
491 /* events on clients can be events on prompt windows too */
492 prompt
= client
->prompt
;
494 case OB_WINDOW_CLASS_MENUFRAME
:
495 menu
= WINDOW_AS_MENUFRAME(obwin
);
497 case OB_WINDOW_CLASS_INTERNAL
:
498 /* we don't do anything with events directly on these windows */
500 case OB_WINDOW_CLASS_PROMPT
:
501 prompt
= WINDOW_AS_PROMPT(obwin
);
506 dockapp
= dock_find_dockapp(window
);
508 event_set_curtime(e
);
509 event_curserial
= e
->xany
.serial
;
511 if (event_ignore(e
, client
)) {
518 /* deal with it in the kernel */
520 if (e
->type
== FocusIn
) {
522 e
->xfocus
.detail
== NotifyInferior
)
524 ob_debug_type(OB_DEBUG_FOCUS
,
525 "Focus went to the frame window");
527 focus_left_screen
= FALSE
;
529 focus_fallback(FALSE
, config_focus_under_mouse
, TRUE
, TRUE
);
531 /* We don't get a FocusOut for this case, because it's just moving
532 from our Inferior up to us. This happens when iconifying a
533 window with RevertToParent focus */
534 frame_adjust_focus(client
->frame
, FALSE
);
535 /* focus_set_client(NULL) has already been called */
537 else if (e
->xfocus
.detail
== NotifyPointerRoot
||
538 e
->xfocus
.detail
== NotifyDetailNone
||
539 e
->xfocus
.detail
== NotifyInferior
||
540 e
->xfocus
.detail
== NotifyNonlinear
)
544 ob_debug_type(OB_DEBUG_FOCUS
,
545 "Focus went to root or pointer root/none");
547 if (e
->xfocus
.detail
== NotifyInferior
||
548 e
->xfocus
.detail
== NotifyNonlinear
)
550 focus_left_screen
= FALSE
;
553 /* If another FocusIn is in the queue then don't fallback yet. This
554 fixes the fun case of:
555 window map -> send focusin
556 window unmap -> get focusout
557 window map -> send focusin
558 get first focus out -> fall back to something (new window
559 hasn't received focus yet, so something else) -> send focusin
560 which means the "something else" is the last thing to get a
561 focusin sent to it, so the new window doesn't end up with focus.
563 But if the other focus in is something like PointerRoot then we
564 still want to fall back.
566 if (XCheckIfEvent(obt_display
, &ce
, event_look_for_focusin_client
,
569 XPutBackEvent(obt_display
, &ce
);
570 ob_debug_type(OB_DEBUG_FOCUS
,
571 " but another FocusIn is coming");
573 /* Focus has been reverted.
575 FocusOut events come after UnmapNotify, so we don't need to
576 worry about focusing an invalid window
579 if (!focus_left_screen
)
580 focus_fallback(FALSE
, config_focus_under_mouse
,
586 ob_debug_type(OB_DEBUG_FOCUS
,
587 "Focus went to a window that is already gone");
589 /* If you send focus to a window and then it disappears, you can
590 get the FocusIn for it, after it is unmanaged.
591 Just wait for the next FocusOut/FocusIn pair, but make note that
592 the window that was focused no longer is. */
593 focus_set_client(NULL
);
595 else if (client
!= focus_client
) {
596 focus_left_screen
= FALSE
;
597 frame_adjust_focus(client
->frame
, TRUE
);
598 focus_set_client(client
);
599 client_calc_layer(client
);
600 client_bring_helper_windows(client
);
602 } else if (e
->type
== FocusOut
) {
605 /* Look for the followup FocusIn */
606 if (!XCheckIfEvent(obt_display
, &ce
, event_look_for_focusin
, NULL
)) {
607 /* There is no FocusIn, this means focus went to a window that
608 is not being managed, or a window on another screen. */
612 obt_display_ignore_errors(TRUE
);
613 if (XGetInputFocus(obt_display
, &win
, &i
) &&
614 XGetGeometry(obt_display
, win
, &root
, &i
,&i
,&u
,&u
,&u
,&u
) &&
615 root
!= obt_root(ob_screen
))
617 ob_debug_type(OB_DEBUG_FOCUS
,
618 "Focus went to another screen !");
619 focus_left_screen
= TRUE
;
622 ob_debug_type(OB_DEBUG_FOCUS
,
623 "Focus went to a black hole !");
624 obt_display_ignore_errors(FALSE
);
625 /* nothing is focused */
626 focus_set_client(NULL
);
628 /* Focus moved, so process the FocusIn event */
629 ObEventData ed
= { .ignored
= FALSE
};
630 event_process(&ce
, &ed
);
632 /* The FocusIn was ignored, this means it was on a window
633 that isn't a client. */
634 ob_debug_type(OB_DEBUG_FOCUS
,
635 "Focus went to an unmanaged window 0x%x !",
637 focus_fallback(TRUE
, config_focus_under_mouse
, TRUE
, TRUE
);
641 if (client
&& client
!= focus_client
) {
642 frame_adjust_focus(client
->frame
, FALSE
);
643 /* focus_set_client(NULL) has already been called in this
644 section or by focus_fallback */
648 event_handle_client(client
, e
);
650 event_handle_dockapp(dockapp
, e
);
652 event_handle_dock(dock
, e
);
654 event_handle_menu(menu
, e
);
655 else if (window
== obt_root(ob_screen
))
656 event_handle_root(e
);
657 else if (e
->type
== MapRequest
)
658 window_manage(window
);
659 else if (e
->type
== MappingNotify
) {
660 /* keyboard layout changes for modifier mapping changes. reload the
661 modifier map, and rebind all the key bindings as appropriate */
662 ob_debug("Keyboard map changed. Reloading keyboard bindings.");
663 ob_set_state(OB_STATE_RECONFIGURING
);
664 obt_keyboard_reload();
666 ob_set_state(OB_STATE_RUNNING
);
668 else if (e
->type
== ClientMessage
) {
669 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
670 windows that are not managed yet. */
671 if (e
->xclient
.message_type
==
672 OBT_PROP_ATOM(NET_REQUEST_FRAME_EXTENTS
))
674 /* Pretend to manage the client, getting information used to
675 determine its decorations */
676 ObClient
*c
= client_fake_manage(e
->xclient
.window
);
679 /* set the frame extents on the window */
680 vals
[0] = c
->frame
->size
.left
;
681 vals
[1] = c
->frame
->size
.right
;
682 vals
[2] = c
->frame
->size
.top
;
683 vals
[3] = c
->frame
->size
.bottom
;
684 OBT_PROP_SETA32(e
->xclient
.window
, NET_FRAME_EXTENTS
,
687 /* Free the pretend client */
688 client_fake_unmanage(c
);
691 else if (e
->type
== ConfigureRequest
) {
692 /* unhandled configure requests must be used to configure the
696 xwc
.x
= e
->xconfigurerequest
.x
;
697 xwc
.y
= e
->xconfigurerequest
.y
;
698 xwc
.width
= e
->xconfigurerequest
.width
;
699 xwc
.height
= e
->xconfigurerequest
.height
;
700 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
701 xwc
.sibling
= e
->xconfigurerequest
.above
;
702 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
704 /* we are not to be held responsible if someone sends us an
706 obt_display_ignore_errors(TRUE
);
707 XConfigureWindow(obt_display
, window
,
708 e
->xconfigurerequest
.value_mask
, &xwc
);
709 obt_display_ignore_errors(FALSE
);
712 else if (obt_display_extension_sync
&&
713 e
->type
== obt_display_extension_sync_basep
+ XSyncAlarmNotify
)
715 XSyncAlarmNotifyEvent
*se
= (XSyncAlarmNotifyEvent
*)e
;
716 if (se
->alarm
== moveresize_alarm
&& moveresize_in_progress
)
721 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
) {
722 /* If the button press was on some non-root window, or was physically
723 on the root window, then process it */
724 if (window
!= obt_root(ob_screen
) ||
725 e
->xbutton
.subwindow
== None
)
727 used
= event_handle_user_input(client
, e
);
729 /* Otherwise only process it if it was physically on an openbox
734 if ((w
= window_find(e
->xbutton
.subwindow
)) &&
735 WINDOW_IS_INTERNAL(w
))
737 used
= event_handle_user_input(client
, e
);
741 else if (e
->type
== KeyPress
|| e
->type
== KeyRelease
||
742 e
->type
== MotionNotify
)
743 used
= event_handle_user_input(client
, e
);
746 used
= event_handle_prompt(prompt
, e
);
748 /* if something happens and it's not from an XEvent, then we don't know
750 event_curtime
= CurrentTime
;
754 static void event_handle_root(XEvent
*e
)
760 ob_debug("Another WM has requested to replace us. Exiting.");
765 if (e
->xclient
.format
!= 32) break;
767 msgtype
= e
->xclient
.message_type
;
768 if (msgtype
== OBT_PROP_ATOM(NET_CURRENT_DESKTOP
)) {
769 guint d
= e
->xclient
.data
.l
[0];
770 if (d
< screen_num_desktops
) {
771 event_curtime
= e
->xclient
.data
.l
[1];
772 if (event_curtime
== 0)
773 ob_debug_type(OB_DEBUG_APP_BUGS
,
774 "_NET_CURRENT_DESKTOP message is missing "
776 screen_set_desktop(d
, TRUE
);
778 } else if (msgtype
== OBT_PROP_ATOM(NET_NUMBER_OF_DESKTOPS
)) {
779 guint d
= e
->xclient
.data
.l
[0];
780 if (d
> 0 && d
<= 1000)
781 screen_set_num_desktops(d
);
782 } else if (msgtype
== OBT_PROP_ATOM(NET_SHOWING_DESKTOP
)) {
783 screen_show_desktop(e
->xclient
.data
.l
[0] != 0, NULL
);
784 } else if (msgtype
== OBT_PROP_ATOM(OB_CONTROL
)) {
785 ob_debug("OB_CONTROL: %d", e
->xclient
.data
.l
[0]);
786 if (e
->xclient
.data
.l
[0] == 1)
788 else if (e
->xclient
.data
.l
[0] == 2)
790 else if (e
->xclient
.data
.l
[0] == 3)
792 } else if (msgtype
== OBT_PROP_ATOM(WM_PROTOCOLS
)) {
793 if ((Atom
)e
->xclient
.data
.l
[0] == OBT_PROP_ATOM(NET_WM_PING
))
794 ping_got_pong(e
->xclient
.data
.l
[1]);
798 if (e
->xproperty
.atom
== OBT_PROP_ATOM(NET_DESKTOP_NAMES
)) {
799 ob_debug("UPDATE DESKTOP NAMES");
800 screen_update_desktop_names();
802 else if (e
->xproperty
.atom
== OBT_PROP_ATOM(NET_DESKTOP_LAYOUT
))
803 screen_update_layout();
805 case ConfigureNotify
:
807 XRRUpdateConfiguration(e
);
816 void event_enter_client(ObClient
*client
)
818 g_assert(config_focus_follow
);
820 if (is_enter_focus_event_ignored(event_curserial
)) {
821 ob_debug_type(OB_DEBUG_FOCUS
, "Ignoring enter event with serial %lu\n"
822 "on client 0x%x", event_curserial
, client
->window
);
826 if (client_enter_focusable(client
) && client_can_focus(client
)) {
827 if (config_focus_delay
) {
828 ObFocusDelayData
*data
;
830 obt_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
832 data
= g_new(ObFocusDelayData
, 1);
833 data
->client
= client
;
834 data
->time
= event_curtime
;
835 data
->serial
= event_curserial
;
837 obt_main_loop_timeout_add(ob_main_loop
,
838 config_focus_delay
* 1000,
840 data
, focus_delay_cmp
, focus_delay_dest
);
842 ObFocusDelayData data
;
843 data
.client
= client
;
844 data
.time
= event_curtime
;
845 data
.serial
= event_curserial
;
846 focus_delay_func(&data
);
851 void event_leave_client(ObClient
*client
)
853 g_assert(config_focus_follow
);
855 if (is_enter_focus_event_ignored(event_curserial
)) {
856 ob_debug_type(OB_DEBUG_FOCUS
, "Ignoring leave event with serial %lu\n"
857 "on client 0x%x", event_curserial
, client
->window
);
861 if (client
== focus_client
) {
862 if (config_focus_delay
) {
863 ObFocusDelayData
*data
;
865 obt_main_loop_timeout_remove(ob_main_loop
, unfocus_delay_func
);
867 data
= g_new(ObFocusDelayData
, 1);
868 data
->client
= client
;
869 data
->time
= event_curtime
;
870 data
->serial
= event_curserial
;
872 obt_main_loop_timeout_add(ob_main_loop
,
873 config_focus_delay
* 1000,
875 data
, focus_delay_cmp
, focus_delay_dest
);
877 ObFocusDelayData data
;
878 data
.client
= client
;
879 data
.time
= event_curtime
;
880 data
.serial
= event_curserial
;
881 unfocus_delay_func(&data
);
886 static gboolean
*context_to_button(ObFrame
*f
, ObFrameContext con
, gboolean press
)
890 case OB_FRAME_CONTEXT_MAXIMIZE
:
891 return &f
->max_press
;
892 case OB_FRAME_CONTEXT_CLOSE
:
893 return &f
->close_press
;
894 case OB_FRAME_CONTEXT_ICONIFY
:
895 return &f
->iconify_press
;
896 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
897 return &f
->desk_press
;
898 case OB_FRAME_CONTEXT_SHADE
:
899 return &f
->shade_press
;
905 case OB_FRAME_CONTEXT_MAXIMIZE
:
906 return &f
->max_hover
;
907 case OB_FRAME_CONTEXT_CLOSE
:
908 return &f
->close_hover
;
909 case OB_FRAME_CONTEXT_ICONIFY
:
910 return &f
->iconify_hover
;
911 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
912 return &f
->desk_hover
;
913 case OB_FRAME_CONTEXT_SHADE
:
914 return &f
->shade_hover
;
921 static void compress_client_message_event(XEvent
*e
, XEvent
*ce
, Window window
,
924 /* compress changes into a single change */
925 while (XCheckTypedWindowEvent(obt_display
, window
, e
->type
, ce
)) {
926 /* XXX: it would be nice to compress ALL messages of a
927 type, not just messages in a row without other
928 message types between. */
929 if (ce
->xclient
.message_type
!= msgtype
) {
930 XPutBackEvent(obt_display
, ce
);
933 e
->xclient
= ce
->xclient
;
937 static void event_handle_client(ObClient
*client
, XEvent
*e
)
943 static gint px
= -1, py
= -1;
945 static ObFrameContext pcon
= OB_FRAME_CONTEXT_NONE
;
949 /* save where the press occured for the first button pressed */
951 pb
= e
->xbutton
.button
;
955 pcon
= frame_context(client
, e
->xbutton
.window
, px
, py
);
956 pcon
= mouse_button_frame_context(pcon
, e
->xbutton
.button
,
960 /* Wheel buttons don't draw because they are an instant click, so it
961 is a waste of resources to go drawing it.
962 if the user is doing an interactive thing, or has a menu open then
963 the mouse is grabbed (possibly) and if we get these events we don't
964 want to deal with them
966 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5) &&
969 /* use where the press occured */
970 con
= frame_context(client
, e
->xbutton
.window
, px
, py
);
971 con
= mouse_button_frame_context(con
, e
->xbutton
.button
,
974 /* button presses on CLIENT_CONTEXTs are not accompanied by a
975 release because they are Replayed to the client */
976 if ((e
->type
== ButtonRelease
|| CLIENT_CONTEXT(con
, client
)) &&
977 e
->xbutton
.button
== pb
)
978 pb
= 0, px
= py
= -1, pcon
= OB_FRAME_CONTEXT_NONE
;
980 but
= context_to_button(client
->frame
, con
, TRUE
);
982 *but
= (e
->type
== ButtonPress
);
983 frame_adjust_state(client
->frame
);
988 /* when there is a grab on the pointer, we won't get enter/leave
989 notifies, but we still get motion events */
990 if (grab_on_pointer()) break;
992 con
= frame_context(client
, e
->xmotion
.window
,
993 e
->xmotion
.x
, e
->xmotion
.y
);
995 case OB_FRAME_CONTEXT_TITLEBAR
:
996 case OB_FRAME_CONTEXT_TLCORNER
:
997 case OB_FRAME_CONTEXT_TRCORNER
:
998 /* we've left the button area inside the titlebar */
999 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
1000 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
1001 client
->frame
->close_hover
)
1003 client
->frame
->max_hover
=
1004 client
->frame
->desk_hover
=
1005 client
->frame
->shade_hover
=
1006 client
->frame
->iconify_hover
=
1007 client
->frame
->close_hover
= FALSE
;
1008 frame_adjust_state(client
->frame
);
1012 but
= context_to_button(client
->frame
, con
, FALSE
);
1013 if (but
&& !*but
&& !pb
) {
1015 frame_adjust_state(client
->frame
);
1021 con
= frame_context(client
, e
->xcrossing
.window
,
1022 e
->xcrossing
.x
, e
->xcrossing
.y
);
1024 case OB_FRAME_CONTEXT_TITLEBAR
:
1025 case OB_FRAME_CONTEXT_TLCORNER
:
1026 case OB_FRAME_CONTEXT_TRCORNER
:
1027 /* we've left the button area inside the titlebar */
1028 client
->frame
->max_hover
=
1029 client
->frame
->desk_hover
=
1030 client
->frame
->shade_hover
=
1031 client
->frame
->iconify_hover
=
1032 client
->frame
->close_hover
= FALSE
;
1033 if (e
->xcrossing
.mode
== NotifyGrab
) {
1034 client
->frame
->max_press
=
1035 client
->frame
->desk_press
=
1036 client
->frame
->shade_press
=
1037 client
->frame
->iconify_press
=
1038 client
->frame
->close_press
= FALSE
;
1041 case OB_FRAME_CONTEXT_FRAME
:
1042 /* When the mouse leaves an animating window, don't use the
1043 corresponding enter events. Pretend like the animating window
1044 doesn't even exist..! */
1045 if (frame_iconify_animating(client
->frame
))
1046 event_end_ignore_all_enters(event_start_ignore_all_enters());
1048 ob_debug_type(OB_DEBUG_FOCUS
,
1049 "%sNotify mode %d detail %d on %lx",
1050 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1052 e
->xcrossing
.detail
, (client
?client
->window
:0));
1053 if (grab_on_keyboard())
1055 if (config_focus_follow
&&
1056 /* leave inferior events can happen when the mouse goes onto
1057 the window's border and then into the window before the
1059 e
->xcrossing
.detail
!= NotifyInferior
)
1061 if (config_focus_delay
)
1062 obt_main_loop_timeout_remove_data(ob_main_loop
,
1065 if (config_unfocus_leave
)
1066 event_leave_client(client
);
1070 but
= context_to_button(client
->frame
, con
, FALSE
);
1073 if (e
->xcrossing
.mode
== NotifyGrab
) {
1074 but
= context_to_button(client
->frame
, con
, TRUE
);
1077 frame_adjust_state(client
->frame
);
1084 con
= frame_context(client
, e
->xcrossing
.window
,
1085 e
->xcrossing
.x
, e
->xcrossing
.y
);
1087 case OB_FRAME_CONTEXT_FRAME
:
1088 if (grab_on_keyboard())
1090 if (e
->xcrossing
.mode
== NotifyGrab
||
1091 e
->xcrossing
.mode
== NotifyUngrab
||
1092 /*ignore enters when we're already in the window */
1093 e
->xcrossing
.detail
== NotifyInferior
)
1095 ob_debug_type(OB_DEBUG_FOCUS
,
1096 "%sNotify mode %d detail %d serial %lu on %lx "
1098 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1100 e
->xcrossing
.detail
,
1101 e
->xcrossing
.serial
,
1102 client
?client
->window
:0);
1105 ob_debug_type(OB_DEBUG_FOCUS
,
1106 "%sNotify mode %d detail %d serial %lu on %lx, "
1108 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1110 e
->xcrossing
.detail
,
1111 e
->xcrossing
.serial
,
1112 (client
?client
->window
:0));
1113 if (config_focus_follow
) {
1114 if (config_focus_delay
)
1115 obt_main_loop_timeout_remove_data(ob_main_loop
,
1118 event_enter_client(client
);
1123 but
= context_to_button(client
->frame
, con
, FALSE
);
1126 if (e
->xcrossing
.mode
== NotifyUngrab
) {
1127 but
= context_to_button(client
->frame
, con
, TRUE
);
1128 *but
= (con
== pcon
);
1130 frame_adjust_state(client
->frame
);
1136 case ConfigureRequest
:
1138 /* dont compress these unless you're going to watch for property
1139 notifies in between (these can change what the configure would
1141 also you can't compress stacking events
1145 gboolean move
= FALSE
;
1146 gboolean resize
= FALSE
;
1148 /* get the current area */
1149 RECT_TO_DIMS(client
->area
, x
, y
, w
, h
);
1151 ob_debug("ConfigureRequest for \"%s\" desktop %d wmstate %d "
1154 screen_desktop
, client
->wmstate
, client
->frame
->visible
);
1155 ob_debug(" x %d y %d w %d h %d b %d",
1156 x
, y
, w
, h
, client
->border_width
);
1158 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
1159 if (client
->border_width
!= e
->xconfigurerequest
.border_width
) {
1160 client
->border_width
= e
->xconfigurerequest
.border_width
;
1162 /* if the border width is changing then that is the same
1163 as requesting a resize, but we don't actually change
1164 the client's border, so it will change their root
1165 coordinates (since they include the border width) and
1166 we need to a notify then */
1170 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
1171 ObClient
*sibling
= NULL
;
1172 gulong ignore_start
;
1175 /* get the sibling */
1176 if (e
->xconfigurerequest
.value_mask
& CWSibling
) {
1178 win
= window_find(e
->xconfigurerequest
.above
);
1179 if (win
&& WINDOW_IS_CLIENT(win
) &&
1180 WINDOW_AS_CLIENT(win
) != client
)
1182 sibling
= WINDOW_AS_CLIENT(win
);
1185 /* an invalid sibling was specified so don't restack at
1186 all, it won't make sense no matter what we do */
1191 if (!config_focus_under_mouse
)
1192 ignore_start
= event_start_ignore_all_enters();
1193 stacking_restack_request(client
, sibling
,
1194 e
->xconfigurerequest
.detail
);
1195 if (!config_focus_under_mouse
)
1196 event_end_ignore_all_enters(ignore_start
);
1199 /* a stacking change moves the window without resizing */
1203 if ((e
->xconfigurerequest
.value_mask
& CWX
) ||
1204 (e
->xconfigurerequest
.value_mask
& CWY
) ||
1205 (e
->xconfigurerequest
.value_mask
& CWWidth
) ||
1206 (e
->xconfigurerequest
.value_mask
& CWHeight
))
1208 /* don't allow clients to move shaded windows (fvwm does this)
1210 if (e
->xconfigurerequest
.value_mask
& CWX
) {
1211 if (!client
->shaded
)
1212 x
= e
->xconfigurerequest
.x
;
1215 if (e
->xconfigurerequest
.value_mask
& CWY
) {
1216 if (!client
->shaded
)
1217 y
= e
->xconfigurerequest
.y
;
1221 if (e
->xconfigurerequest
.value_mask
& CWWidth
) {
1222 w
= e
->xconfigurerequest
.width
;
1225 if (e
->xconfigurerequest
.value_mask
& CWHeight
) {
1226 h
= e
->xconfigurerequest
.height
;
1231 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
1232 "move %d resize %d",
1233 e
->xconfigurerequest
.value_mask
& CWX
, x
,
1234 e
->xconfigurerequest
.value_mask
& CWY
, y
,
1235 e
->xconfigurerequest
.value_mask
& CWWidth
, w
,
1236 e
->xconfigurerequest
.value_mask
& CWHeight
, h
,
1239 /* check for broken apps moving to their root position
1241 XXX remove this some day...that would be nice. right now all
1242 kde apps do this when they try activate themselves on another
1243 desktop. eg. open amarok window on desktop 1, switch to desktop
1244 2, click amarok tray icon. it will move by its decoration size.
1246 if (x
!= client
->area
.x
&&
1247 x
== (client
->frame
->area
.x
+ client
->frame
->size
.left
-
1248 (gint
)client
->border_width
) &&
1249 y
!= client
->area
.y
&&
1250 y
== (client
->frame
->area
.y
+ client
->frame
->size
.top
-
1251 (gint
)client
->border_width
) &&
1252 w
== client
->area
.width
&&
1253 h
== client
->area
.height
)
1255 ob_debug_type(OB_DEBUG_APP_BUGS
,
1256 "Application %s is trying to move via "
1257 "ConfigureRequest to it's root window position "
1258 "but it is not using StaticGravity",
1264 /* they still requested a move, so don't change whether a
1265 notify is sent or not */
1271 client_try_configure(client
, &x
, &y
, &w
, &h
, &lw
, &lh
, FALSE
);
1273 /* if x was not given, then use gravity to figure out the new
1274 x. the reference point should not be moved */
1275 if ((e
->xconfigurerequest
.value_mask
& CWWidth
&&
1276 !(e
->xconfigurerequest
.value_mask
& CWX
)))
1277 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1279 if ((e
->xconfigurerequest
.value_mask
& CWHeight
&&
1280 !(e
->xconfigurerequest
.value_mask
& CWY
)))
1281 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1283 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1285 ob_debug("Granting ConfigureRequest x %d y %d w %d h %d",
1287 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
, TRUE
);
1292 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1294 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
1295 client
->ignore_unmaps
);
1296 if (client
->ignore_unmaps
) {
1297 client
->ignore_unmaps
--;
1300 client_unmanage(client
);
1303 ob_debug("DestroyNotify for window 0x%x", client
->window
);
1304 client_unmanage(client
);
1306 case ReparentNotify
:
1307 /* this is when the client is first taken captive in the frame */
1308 if (e
->xreparent
.parent
== client
->frame
->window
) break;
1311 This event is quite rare and is usually handled in unmapHandler.
1312 However, if the window is unmapped when the reparent event occurs,
1313 the window manager never sees it because an unmap event is not sent
1314 to an already unmapped window.
1317 /* we don't want the reparent event, put it back on the stack for the
1318 X server to deal with after we unmanage the window */
1319 XPutBackEvent(obt_display
, e
);
1321 ob_debug("ReparentNotify for window 0x%x", client
->window
);
1322 client_unmanage(client
);
1325 ob_debug("MapRequest for 0x%lx", client
->window
);
1326 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
1327 does, we don't want it!
1328 it can happen now when the window is on
1329 another desktop, but we still don't
1331 client_activate(client
, FALSE
, FALSE
, TRUE
, TRUE
, TRUE
);
1334 /* validate cuz we query stuff off the client here */
1335 if (!client_validate(client
)) break;
1337 if (e
->xclient
.format
!= 32) return;
1339 msgtype
= e
->xclient
.message_type
;
1340 if (msgtype
== OBT_PROP_ATOM(WM_CHANGE_STATE
)) {
1341 compress_client_message_event(e
, &ce
, client
->window
, msgtype
);
1342 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1343 } else if (msgtype
== OBT_PROP_ATOM(NET_WM_DESKTOP
)) {
1344 compress_client_message_event(e
, &ce
, client
->window
, msgtype
);
1345 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1346 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1347 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1349 } else if (msgtype
== OBT_PROP_ATOM(NET_WM_STATE
)) {
1350 gulong ignore_start
;
1352 /* can't compress these */
1353 ob_debug("net_wm_state %s %ld %ld for 0x%lx",
1354 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1355 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1356 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1357 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1360 /* ignore enter events caused by these like ob actions do */
1361 if (!config_focus_under_mouse
)
1362 ignore_start
= event_start_ignore_all_enters();
1363 client_set_state(client
, e
->xclient
.data
.l
[0],
1364 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1365 if (!config_focus_under_mouse
)
1366 event_end_ignore_all_enters(ignore_start
);
1367 } else if (msgtype
== OBT_PROP_ATOM(NET_CLOSE_WINDOW
)) {
1368 ob_debug("net_close_window for 0x%lx", client
->window
);
1369 client_close(client
);
1370 } else if (msgtype
== OBT_PROP_ATOM(NET_ACTIVE_WINDOW
)) {
1371 ob_debug("net_active_window for 0x%lx source=%s",
1373 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1374 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1375 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1376 /* XXX make use of data.l[2] !? */
1377 if (e
->xclient
.data
.l
[0] == 1 || e
->xclient
.data
.l
[0] == 2) {
1378 event_curtime
= e
->xclient
.data
.l
[1];
1379 if (e
->xclient
.data
.l
[1] == 0)
1380 ob_debug_type(OB_DEBUG_APP_BUGS
,
1381 "_NET_ACTIVE_WINDOW message for window %s is"
1382 " missing a timestamp", client
->title
);
1384 ob_debug_type(OB_DEBUG_APP_BUGS
,
1385 "_NET_ACTIVE_WINDOW message for window %s is "
1386 "missing source indication", client
->title
);
1387 client_activate(client
, FALSE
, FALSE
, TRUE
, TRUE
,
1388 (e
->xclient
.data
.l
[0] == 0 ||
1389 e
->xclient
.data
.l
[0] == 2));
1390 } else if (msgtype
== OBT_PROP_ATOM(NET_WM_MOVERESIZE
)) {
1391 ob_debug("net_wm_moveresize for 0x%lx direction %d",
1392 client
->window
, e
->xclient
.data
.l
[2]);
1393 if ((Atom
)e
->xclient
.data
.l
[2] ==
1394 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT
) ||
1395 (Atom
)e
->xclient
.data
.l
[2] ==
1396 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP
) ||
1397 (Atom
)e
->xclient
.data
.l
[2] ==
1398 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT
) ||
1399 (Atom
)e
->xclient
.data
.l
[2] ==
1400 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT
) ||
1401 (Atom
)e
->xclient
.data
.l
[2] ==
1402 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT
) ||
1403 (Atom
)e
->xclient
.data
.l
[2] ==
1404 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
) ||
1405 (Atom
)e
->xclient
.data
.l
[2] ==
1406 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM
) ||
1407 (Atom
)e
->xclient
.data
.l
[2] ==
1408 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
) ||
1409 (Atom
)e
->xclient
.data
.l
[2] ==
1410 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT
) ||
1411 (Atom
)e
->xclient
.data
.l
[2] ==
1412 OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE
) ||
1413 (Atom
)e
->xclient
.data
.l
[2] ==
1414 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD
) ||
1415 (Atom
)e
->xclient
.data
.l
[2] ==
1416 OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD
))
1418 moveresize_start(client
, e
->xclient
.data
.l
[0],
1419 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1420 e
->xclient
.data
.l
[2]);
1422 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1423 OBT_PROP_ATOM(NET_WM_MOVERESIZE_CANCEL
))
1424 moveresize_end(TRUE
);
1425 } else if (msgtype
== OBT_PROP_ATOM(NET_MOVERESIZE_WINDOW
)) {
1426 gint ograv
, x
, y
, w
, h
;
1428 ograv
= client
->gravity
;
1430 if (e
->xclient
.data
.l
[0] & 0xff)
1431 client
->gravity
= e
->xclient
.data
.l
[0] & 0xff;
1433 if (e
->xclient
.data
.l
[0] & 1 << 8)
1434 x
= e
->xclient
.data
.l
[1];
1437 if (e
->xclient
.data
.l
[0] & 1 << 9)
1438 y
= e
->xclient
.data
.l
[2];
1442 if (e
->xclient
.data
.l
[0] & 1 << 10) {
1443 w
= e
->xclient
.data
.l
[3];
1445 /* if x was not given, then use gravity to figure out the new
1446 x. the reference point should not be moved */
1447 if (!(e
->xclient
.data
.l
[0] & 1 << 8))
1448 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1451 w
= client
->area
.width
;
1453 if (e
->xclient
.data
.l
[0] & 1 << 11) {
1454 h
= e
->xclient
.data
.l
[4];
1457 if (!(e
->xclient
.data
.l
[0] & 1 << 9))
1458 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1461 h
= client
->area
.height
;
1463 ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)",
1464 e
->xclient
.data
.l
[0] & 1 << 8, x
,
1465 e
->xclient
.data
.l
[0] & 1 << 9, y
,
1468 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1470 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
1472 client
->gravity
= ograv
;
1473 } else if (msgtype
== OBT_PROP_ATOM(NET_RESTACK_WINDOW
)) {
1474 if (e
->xclient
.data
.l
[0] != 2) {
1475 ob_debug_type(OB_DEBUG_APP_BUGS
,
1476 "_NET_RESTACK_WINDOW sent for window %s with "
1477 "invalid source indication %ld",
1478 client
->title
, e
->xclient
.data
.l
[0]);
1480 ObClient
*sibling
= NULL
;
1481 if (e
->xclient
.data
.l
[1]) {
1482 ObWindow
*win
= window_find(e
->xclient
.data
.l
[1]);
1483 if (WINDOW_IS_CLIENT(win
) &&
1484 WINDOW_AS_CLIENT(win
) != client
)
1486 sibling
= WINDOW_AS_CLIENT(win
);
1488 if (sibling
== NULL
)
1489 ob_debug_type(OB_DEBUG_APP_BUGS
,
1490 "_NET_RESTACK_WINDOW sent for window %s "
1491 "with invalid sibling 0x%x",
1492 client
->title
, e
->xclient
.data
.l
[1]);
1494 if (e
->xclient
.data
.l
[2] == Below
||
1495 e
->xclient
.data
.l
[2] == BottomIf
||
1496 e
->xclient
.data
.l
[2] == Above
||
1497 e
->xclient
.data
.l
[2] == TopIf
||
1498 e
->xclient
.data
.l
[2] == Opposite
)
1500 gulong ignore_start
;
1502 if (!config_focus_under_mouse
)
1503 ignore_start
= event_start_ignore_all_enters();
1504 /* just raise, don't activate */
1505 stacking_restack_request(client
, sibling
,
1506 e
->xclient
.data
.l
[2]);
1507 if (!config_focus_under_mouse
)
1508 event_end_ignore_all_enters(ignore_start
);
1510 /* send a synthetic ConfigureNotify, cuz this is supposed
1511 to be like a ConfigureRequest. */
1512 client_reconfigure(client
, TRUE
);
1514 ob_debug_type(OB_DEBUG_APP_BUGS
,
1515 "_NET_RESTACK_WINDOW sent for window %s "
1516 "with invalid detail %d",
1517 client
->title
, e
->xclient
.data
.l
[2]);
1521 case PropertyNotify
:
1522 /* validate cuz we query stuff off the client here */
1523 if (!client_validate(client
)) break;
1525 /* compress changes to a single property into a single change */
1526 while (XCheckTypedWindowEvent(obt_display
, client
->window
,
1530 /* XXX: it would be nice to compress ALL changes to a property,
1531 not just changes in a row without other props between. */
1533 a
= ce
.xproperty
.atom
;
1534 b
= e
->xproperty
.atom
;
1538 if ((a
== OBT_PROP_ATOM(NET_WM_NAME
) ||
1539 a
== OBT_PROP_ATOM(WM_NAME
) ||
1540 a
== OBT_PROP_ATOM(NET_WM_ICON_NAME
) ||
1541 a
== OBT_PROP_ATOM(WM_ICON_NAME
))
1543 (b
== OBT_PROP_ATOM(NET_WM_NAME
) ||
1544 b
== OBT_PROP_ATOM(WM_NAME
) ||
1545 b
== OBT_PROP_ATOM(NET_WM_ICON_NAME
) ||
1546 b
== OBT_PROP_ATOM(WM_ICON_NAME
))) {
1549 if (a
== OBT_PROP_ATOM(NET_WM_ICON
) &&
1550 b
== OBT_PROP_ATOM(NET_WM_ICON
))
1553 XPutBackEvent(obt_display
, &ce
);
1557 msgtype
= e
->xproperty
.atom
;
1558 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1559 int x
, y
, w
, h
, lw
, lh
;
1561 ob_debug("Update NORMAL hints");
1562 client_update_normal_hints(client
);
1563 /* normal hints can make a window non-resizable */
1564 client_setup_decor_and_functions(client
, FALSE
);
1568 w
= client
->area
.width
;
1569 h
= client
->area
.height
;
1571 /* apply the new normal hints */
1572 client_try_configure(client
, &x
, &y
, &w
, &h
, &lw
, &lh
, FALSE
);
1573 /* make sure the window is visible, and if the window is resized
1574 off-screen due to the normal hints changing then this will push
1575 it back onto the screen. */
1576 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1578 /* make sure the client's sizes are within its bounds, but don't
1579 make it reply with a configurenotify unless something changed.
1580 emacs will update its normal hints every time it receives a
1582 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
1583 } else if (msgtype
== OBT_PROP_ATOM(MOTIF_WM_HINTS
)) {
1584 client_get_mwm_hints(client
);
1585 /* This can override some mwm hints */
1586 client_get_type_and_transientness(client
);
1588 /* Apply the changes to the window */
1589 client_setup_decor_and_functions(client
, TRUE
);
1590 } else if (msgtype
== XA_WM_HINTS
) {
1591 client_update_wmhints(client
);
1592 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1593 client_update_transient_for(client
);
1594 client_get_type_and_transientness(client
);
1595 /* type may have changed, so update the layer */
1596 client_calc_layer(client
);
1597 client_setup_decor_and_functions(client
, TRUE
);
1598 } else if (msgtype
== OBT_PROP_ATOM(NET_WM_NAME
) ||
1599 msgtype
== OBT_PROP_ATOM(WM_NAME
) ||
1600 msgtype
== OBT_PROP_ATOM(NET_WM_ICON_NAME
) ||
1601 msgtype
== OBT_PROP_ATOM(WM_ICON_NAME
)) {
1602 client_update_title(client
);
1603 } else if (msgtype
== OBT_PROP_ATOM(WM_PROTOCOLS
)) {
1604 client_update_protocols(client
);
1605 client_setup_decor_and_functions(client
, TRUE
);
1607 else if (msgtype
== OBT_PROP_ATOM(NET_WM_STRUT
) ||
1608 msgtype
== OBT_PROP_ATOM(NET_WM_STRUT_PARTIAL
)) {
1609 client_update_strut(client
);
1611 else if (msgtype
== OBT_PROP_ATOM(NET_WM_ICON
)) {
1612 client_update_icons(client
);
1614 else if (msgtype
== OBT_PROP_ATOM(NET_WM_ICON_GEOMETRY
)) {
1615 client_update_icon_geometry(client
);
1617 else if (msgtype
== OBT_PROP_ATOM(NET_WM_USER_TIME
)) {
1619 if (client
== focus_client
&&
1620 OBT_PROP_GET32(client
->window
, NET_WM_USER_TIME
, CARDINAL
, &t
)
1621 && t
&& !event_time_after(t
, e
->xproperty
.time
) &&
1622 (!event_last_user_time
||
1623 event_time_after(t
, event_last_user_time
)))
1625 event_last_user_time
= t
;
1629 else if (msgtype
== OBT_PROP_ATOM(NET_WM_SYNC_REQUEST_COUNTER
)) {
1630 client_update_sync_request_counter(client
);
1634 case ColormapNotify
:
1635 client_update_colormap(client
, e
->xcolormap
.colormap
);
1642 if (obt_display_extension_shape
&&
1643 e
->type
== obt_display_extension_shape_basep
)
1645 switch (((XShapeEvent
*)e
)->kind
) {
1648 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1649 kind
= ShapeBounding
;
1652 client
->shaped_input
= ((XShapeEvent
*)e
)->shaped
;
1656 g_assert_not_reached();
1658 frame_adjust_shape_kind(client
->frame
, kind
);
1665 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1669 if (e
->xbutton
.button
== 1)
1670 stacking_raise(DOCK_AS_WINDOW(s
));
1671 else if (e
->xbutton
.button
== 2)
1672 stacking_lower(DOCK_AS_WINDOW(s
));
1678 /* don't hide when moving into a dock app */
1679 if (e
->xcrossing
.detail
!= NotifyInferior
)
1685 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1689 dock_app_drag(app
, &e
->xmotion
);
1692 if (app
->ignore_unmaps
) {
1693 app
->ignore_unmaps
--;
1696 dock_unmanage(app
, TRUE
);
1699 case ReparentNotify
:
1700 dock_unmanage(app
, FALSE
);
1702 case ConfigureNotify
:
1703 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1708 static ObMenuFrame
* find_active_menu(void)
1711 ObMenuFrame
*ret
= NULL
;
1713 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1722 static ObMenuFrame
* find_active_or_last_menu(void)
1724 ObMenuFrame
*ret
= NULL
;
1726 ret
= find_active_menu();
1727 if (!ret
&& menu_frame_visible
)
1728 ret
= menu_frame_visible
->data
;
1732 static gboolean
event_handle_prompt(ObPrompt
*p
, XEvent
*e
)
1738 return prompt_mouse_event(p
, e
);
1741 return prompt_key_event(p
, e
);
1747 static gboolean
event_handle_menu_input(XEvent
*ev
)
1749 gboolean ret
= FALSE
;
1751 if (ev
->type
== ButtonRelease
|| ev
->type
== ButtonPress
) {
1752 ObMenuEntryFrame
*e
;
1754 if (menu_hide_delay_reached() &&
1755 (ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5))
1757 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1758 ev
->xbutton
.y_root
)))
1760 if (ev
->type
== ButtonPress
&& e
->frame
->child
)
1761 menu_frame_select(e
->frame
->child
, NULL
, TRUE
);
1762 menu_frame_select(e
->frame
, e
, TRUE
);
1763 if (ev
->type
== ButtonRelease
)
1764 menu_entry_frame_execute(e
, ev
->xbutton
.state
);
1766 else if (ev
->type
== ButtonRelease
)
1767 menu_frame_hide_all();
1771 else if (ev
->type
== MotionNotify
) {
1773 ObMenuEntryFrame
*e
;
1775 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1776 ev
->xmotion
.y_root
)))
1777 if (!(f
= find_active_menu()) ||
1779 f
->parent
== e
->frame
||
1780 f
->child
== e
->frame
)
1781 menu_frame_select(e
->frame
, e
, FALSE
);
1783 else if (ev
->type
== KeyPress
|| ev
->type
== KeyRelease
) {
1784 guint keycode
, state
;
1788 keycode
= ev
->xkey
.keycode
;
1789 state
= ev
->xkey
.state
;
1790 unikey
= obt_keyboard_keycode_to_unichar(keycode
);
1792 frame
= find_active_or_last_menu();
1794 g_assert_not_reached(); /* there is no active menu */
1796 /* Allow control while going thru the menu */
1797 else if (ev
->type
== KeyPress
&& (state
& ~ControlMask
) == 0) {
1798 frame
->got_press
= TRUE
;
1800 if (ob_keycode_match(keycode
, OB_KEY_ESCAPE
)) {
1801 menu_frame_hide_all();
1805 else if (ob_keycode_match(keycode
, OB_KEY_LEFT
)) {
1806 /* Left goes to the parent menu */
1807 if (frame
->parent
) {
1808 /* remove focus from the child */
1809 menu_frame_select(frame
, NULL
, TRUE
);
1810 /* and put it in the parent */
1811 menu_frame_select(frame
->parent
, frame
->parent
->selected
,
1817 else if (ob_keycode_match(keycode
, OB_KEY_RIGHT
)) {
1818 /* Right goes to the selected submenu */
1819 if (frame
->child
) menu_frame_select_next(frame
->child
);
1823 else if (ob_keycode_match(keycode
, OB_KEY_UP
)) {
1824 menu_frame_select_previous(frame
);
1828 else if (ob_keycode_match(keycode
, OB_KEY_DOWN
)) {
1829 menu_frame_select_next(frame
);
1834 /* Use KeyRelease events for running things so that the key release
1835 doesn't get sent to the focused application.
1837 Allow ControlMask only, and don't bother if the menu is empty */
1838 else if (ev
->type
== KeyRelease
&& (state
& ~ControlMask
) == 0 &&
1839 frame
->entries
&& frame
->got_press
)
1841 if (ob_keycode_match(keycode
, OB_KEY_RETURN
)) {
1842 /* Enter runs the active item or goes into the submenu.
1843 Control-Enter runs it without closing the menu. */
1845 menu_frame_select_next(frame
->child
);
1846 else if (frame
->selected
)
1847 menu_entry_frame_execute(frame
->selected
, state
);
1852 /* keyboard accelerator shortcuts. (if it was a valid key) */
1853 else if (unikey
!= 0) {
1856 ObMenuEntryFrame
*found
= NULL
;
1857 guint num_found
= 0;
1859 /* start after the selected one */
1860 start
= frame
->entries
;
1861 if (frame
->selected
) {
1862 for (it
= start
; frame
->selected
!= it
->data
;
1863 it
= g_list_next(it
))
1864 g_assert(it
!= NULL
); /* nothing was selected? */
1865 /* next with wraparound */
1866 start
= g_list_next(it
);
1867 if (start
== NULL
) start
= frame
->entries
;
1872 ObMenuEntryFrame
*e
= it
->data
;
1873 gunichar entrykey
= 0;
1875 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1876 entrykey
= e
->entry
->data
.normal
.shortcut
;
1877 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1878 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1880 if (unikey
== entrykey
) {
1881 if (found
== NULL
) found
= e
;
1885 /* next with wraparound */
1886 it
= g_list_next(it
);
1887 if (it
== NULL
) it
= frame
->entries
;
1888 } while (it
!= start
);
1891 if (found
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
1894 menu_frame_select(frame
, found
, TRUE
);
1895 usleep(50000); /* highlight the item for a short bit so
1896 the user can see what happened */
1897 menu_entry_frame_execute(found
, state
);
1899 menu_frame_select(frame
, found
, TRUE
);
1901 menu_frame_select_next(frame
->child
);
1913 static Bool
event_look_for_menu_enter(Display
*d
, XEvent
*ev
, XPointer arg
)
1915 ObMenuFrame
*f
= (ObMenuFrame
*)arg
;
1916 ObMenuEntryFrame
*e
;
1917 return ev
->type
== EnterNotify
&&
1918 (e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1919 !e
->ignore_enters
&& e
->frame
== f
;
1922 static void event_handle_menu(ObMenuFrame
*frame
, XEvent
*ev
)
1925 ObMenuEntryFrame
*e
;
1929 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1930 if (e
->ignore_enters
)
1932 else if (!(f
= find_active_menu()) ||
1934 f
->parent
== e
->frame
||
1935 f
->child
== e
->frame
)
1936 menu_frame_select(e
->frame
, e
, FALSE
);
1940 /*ignore leaves when we're already in the window */
1941 if (ev
->xcrossing
.detail
== NotifyInferior
)
1944 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)))
1948 /* check if an EnterNotify event is coming, and if not, then select
1949 nothing in the menu */
1950 if (XCheckIfEvent(obt_display
, &ce
, event_look_for_menu_enter
,
1951 (XPointer
)e
->frame
))
1952 XPutBackEvent(obt_display
, &ce
);
1954 menu_frame_select(e
->frame
, NULL
, FALSE
);
1960 static gboolean
event_handle_user_input(ObClient
*client
, XEvent
*e
)
1962 g_assert(e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
1963 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
1964 e
->type
== KeyRelease
);
1966 if (menu_frame_visible
) {
1967 if (event_handle_menu_input(e
))
1968 /* don't use the event if the menu used it, but if the menu
1969 didn't use it and it's a keypress that is bound, it will
1970 close the menu and be used */
1974 /* if the keyboard interactive action uses the event then dont
1975 use it for bindings. likewise is moveresize uses the event. */
1976 if (actions_interactive_input_event(e
) || moveresize_event(e
))
1979 if (moveresize_in_progress
)
1980 /* make further actions work on the client being
1982 client
= moveresize_client
;
1984 if (e
->type
== ButtonPress
||
1985 e
->type
== ButtonRelease
||
1986 e
->type
== MotionNotify
)
1988 /* the frame may not be "visible" but they can still click on it
1989 in the case where it is animating before disappearing */
1990 if (!client
|| !frame_iconify_animating(client
->frame
))
1991 return mouse_event(client
, e
);
1993 return keyboard_event((focus_cycle_target
? focus_cycle_target
:
1994 (client
? client
: focus_client
)), e
);
1999 static void focus_delay_dest(gpointer data
)
2004 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
2006 const ObFocusDelayData
*f1
= d1
;
2007 return f1
->client
== d2
;
2010 static gboolean
focus_delay_func(gpointer data
)
2012 ObFocusDelayData
*d
= data
;
2013 Time old
= event_curtime
;
2015 event_curtime
= d
->time
;
2016 event_curserial
= d
->serial
;
2017 if (client_focus(d
->client
) && config_focus_raise
)
2018 stacking_raise(CLIENT_AS_WINDOW(d
->client
));
2019 event_curtime
= old
;
2020 return FALSE
; /* no repeat */
2023 static gboolean
unfocus_delay_func(gpointer data
)
2025 ObFocusDelayData
*d
= data
;
2026 Time old
= event_curtime
;
2028 event_curtime
= d
->time
;
2029 event_curserial
= d
->serial
;
2031 event_curtime
= old
;
2032 return FALSE
; /* no repeat */
2035 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
2037 obt_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
2039 obt_main_loop_timeout_remove_data(ob_main_loop
, unfocus_delay_func
,
2043 void event_halt_focus_delay(void)
2045 /* ignore all enter events up till the event which caused this to occur */
2046 if (event_curserial
) event_ignore_enter_range(1, event_curserial
);
2047 obt_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
2048 obt_main_loop_timeout_remove(ob_main_loop
, unfocus_delay_func
);
2051 gulong
event_start_ignore_all_enters(void)
2053 return NextRequest(obt_display
);
2056 static void event_ignore_enter_range(gulong start
, gulong end
)
2060 g_assert(start
!= 0);
2063 r
= g_new(ObSerialRange
, 1);
2066 ignore_serials
= g_slist_prepend(ignore_serials
, r
);
2068 ob_debug_type(OB_DEBUG_FOCUS
, "ignoring enters from %lu until %lu",
2071 /* increment the serial so we don't ignore events we weren't meant to */
2072 OBT_PROP_ERASE(screen_support_win
, MOTIF_WM_HINTS
);
2075 void event_end_ignore_all_enters(gulong start
)
2077 /* Use (NextRequest-1) so that we ignore up to the current serial only.
2078 Inside event_ignore_enter_range, we increment the serial by one, but if
2079 we ignore that serial too, then any enter events generated by mouse
2080 movement will be ignored until we create some further network traffic.
2081 Instead ignore up to NextRequest-1, then when we increment the serial,
2082 we will be *past* the range of ignored serials */
2083 event_ignore_enter_range(start
, NextRequest(obt_display
)-1);
2086 static gboolean
is_enter_focus_event_ignored(gulong serial
)
2090 for (it
= ignore_serials
; it
; it
= next
) {
2091 ObSerialRange
*r
= it
->data
;
2093 next
= g_slist_next(it
);
2095 if ((glong
)(serial
- r
->end
) > 0) {
2097 ignore_serials
= g_slist_delete_link(ignore_serials
, it
);
2100 else if ((glong
)(serial
- r
->start
) >= 0)
2106 void event_cancel_all_key_grabs(void)
2108 if (actions_interactive_act_running()) {
2109 actions_interactive_cancel_act();
2110 ob_debug("KILLED interactive action");
2112 else if (menu_frame_visible
) {
2113 menu_frame_hide_all();
2114 ob_debug("KILLED open menus");
2116 else if (moveresize_in_progress
) {
2117 moveresize_end(TRUE
);
2118 ob_debug("KILLED interactive moveresize");
2120 else if (grab_on_keyboard()) {
2122 ob_debug("KILLED active grab on keyboard");
2125 ungrab_passive_key();
2127 XSync(obt_display
, FALSE
);
2130 gboolean
event_time_after(guint32 t1
, guint32 t2
)
2132 g_assert(t1
!= CurrentTime
);
2133 g_assert(t2
!= CurrentTime
);
2136 Timestamp values wrap around (after about 49.7 days). The server, given
2137 its current time is represented by timestamp T, always interprets
2138 timestamps from clients by treating half of the timestamp space as being
2139 later in time than T.
2140 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
2143 /* TIME_HALF is not half of the number space of a Time type variable.
2144 * Rather, it is half the number space of a timestamp value, which is
2145 * always 32 bits. */
2146 #define TIME_HALF (guint32)(1 << 31)
2148 if (t2
>= TIME_HALF
)
2149 /* t2 is in the second half so t1 might wrap around and be smaller than
2151 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
2153 /* t2 is in the first half so t1 has to come after it */
2154 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);
2157 Time
event_get_server_time(void)
2159 /* Generate a timestamp */
2162 XChangeProperty(obt_display
, screen_support_win
,
2163 OBT_PROP_ATOM(WM_CLASS
), OBT_PROP_ATOM(STRING
),
2164 8, PropModeAppend
, NULL
, 0);
2165 XWindowEvent(obt_display
, screen_support_win
, PropertyChangeMask
, &event
);
2166 return event
.xproperty
.time
;