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() */
61 #include <X11/ICE/ICElib.h>
78 gulong start
; /* inclusive */
79 gulong end
; /* inclusive */
82 static void event_process(const XEvent
*e
, gpointer data
);
83 static void event_handle_root(XEvent
*e
);
84 static gboolean
event_handle_menu_input(XEvent
*e
);
85 static void event_handle_menu(ObMenuFrame
*frame
, XEvent
*e
);
86 static gboolean
event_handle_prompt(ObPrompt
*p
, XEvent
*e
);
87 static void event_handle_dock(ObDock
*s
, XEvent
*e
);
88 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
);
89 static void event_handle_client(ObClient
*c
, XEvent
*e
);
90 static gboolean
event_handle_user_input(ObClient
*client
, XEvent
*e
);
91 static gboolean
is_enter_focus_event_ignored(gulong serial
);
92 static void event_ignore_enter_range(gulong start
, gulong end
);
94 static void focus_delay_dest(gpointer data
);
95 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
);
96 static gboolean
focus_delay_func(gpointer data
);
97 static gboolean
unfocus_delay_func(gpointer data
);
98 static void focus_delay_client_dest(ObClient
*client
, gpointer data
);
100 Time event_curtime
= CurrentTime
;
101 Time event_last_user_time
= CurrentTime
;
102 /*! The serial of the current X event */
104 static gulong event_curserial
;
105 static gboolean focus_left_screen
= FALSE
;
106 /*! A list of ObSerialRanges which are to be ignored for mouse enter events */
107 static GSList
*ignore_serials
= NULL
;
110 static void ice_handler(gint fd
, gpointer conn
)
113 IceProcessMessages(conn
, NULL
, &b
);
116 static void ice_watch(IceConn conn
, IcePointer data
, Bool opening
,
117 IcePointer
*watch_data
)
122 fd
= IceConnectionNumber(conn
);
123 obt_main_loop_fd_add(ob_main_loop
, fd
, ice_handler
, conn
, NULL
);
125 obt_main_loop_fd_remove(ob_main_loop
, fd
);
131 void event_startup(gboolean reconfig
)
133 if (reconfig
) return;
135 obt_main_loop_x_add(ob_main_loop
, event_process
, NULL
, NULL
);
138 IceAddConnectionWatch(ice_watch
, NULL
);
141 client_add_destroy_notify(focus_delay_client_dest
, NULL
);
144 void event_shutdown(gboolean reconfig
)
146 if (reconfig
) return;
149 IceRemoveConnectionWatch(ice_watch
, NULL
);
152 client_remove_destroy_notify(focus_delay_client_dest
);
155 static Window
event_get_window(XEvent
*e
)
162 window
= obt_root(ob_screen
);
165 window
= e
->xcreatewindow
.window
;
168 window
= e
->xmaprequest
.window
;
171 window
= e
->xmap
.window
;
174 window
= e
->xunmap
.window
;
177 window
= e
->xdestroywindow
.window
;
179 case ConfigureRequest
:
180 window
= e
->xconfigurerequest
.window
;
182 case ConfigureNotify
:
183 window
= e
->xconfigure
.window
;
187 if (obt_display_extension_xkb
&&
188 e
->type
== obt_display_extension_xkb_basep
)
190 switch (((XkbAnyEvent
*)e
)->xkb_type
) {
192 window
= ((XkbBellNotifyEvent
*)e
)->window
;
199 if (obt_display_extension_sync
&&
200 e
->type
== obt_display_extension_sync_basep
+ XSyncAlarmNotify
)
205 window
= e
->xany
.window
;
210 static void event_set_curtime(XEvent
*e
)
212 Time t
= CurrentTime
;
214 /* grab the lasttime and hack up the state */
230 t
= e
->xproperty
.time
;
234 t
= e
->xcrossing
.time
;
238 if (obt_display_extension_sync
&&
239 e
->type
== obt_display_extension_sync_basep
+ XSyncAlarmNotify
)
241 t
= ((XSyncAlarmNotifyEvent
*)e
)->time
;
244 /* if more event types are anticipated, get their timestamp
249 /* watch that if we get an event earlier than the last specified user_time,
250 which can happen if the clock goes backwards, we erase the last
251 specified user_time */
252 if (t
&& event_last_user_time
&& event_time_after(event_last_user_time
, t
))
253 event_last_user_time
= CurrentTime
;
258 static void event_hack_mods(XEvent
*e
)
263 e
->xbutton
.state
= obt_keyboard_only_modmasks(e
->xbutton
.state
);
270 e
->xmotion
.state
= obt_keyboard_only_modmasks(e
->xmotion
.state
);
271 /* compress events */
274 while (XCheckTypedWindowEvent(obt_display
, e
->xmotion
.window
,
276 e
->xmotion
.x
= ce
.xmotion
.x
;
277 e
->xmotion
.y
= ce
.xmotion
.y
;
278 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
279 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
286 static gboolean
wanted_focusevent(XEvent
*e
, gboolean in_client_only
)
288 gint mode
= e
->xfocus
.mode
;
289 gint detail
= e
->xfocus
.detail
;
290 Window win
= e
->xany
.window
;
292 if (e
->type
== FocusIn
) {
293 /* These are ones we never want.. */
295 /* This means focus was given by a keyboard/mouse grab. */
296 if (mode
== NotifyGrab
)
298 /* This means focus was given back from a keyboard/mouse grab. */
299 if (mode
== NotifyUngrab
)
302 /* These are the ones we want.. */
304 if (win
== obt_root(ob_screen
)) {
305 /* If looking for a focus in on a client, then always return
306 FALSE for focus in's to the root window */
309 /* This means focus reverted off of a client */
310 else if (detail
== NotifyPointerRoot
||
311 detail
== NotifyDetailNone
||
312 detail
== NotifyInferior
||
313 /* This means focus got here from another screen */
314 detail
== NotifyNonlinear
)
320 /* It was on a client, was it a valid one?
321 It's possible to get a FocusIn event for a client that was managed
324 if (in_client_only
) {
325 ObWindow
*w
= window_find(e
->xfocus
.window
);
326 if (!w
|| !WINDOW_IS_CLIENT(w
))
330 /* This means focus reverted to parent from the client (this
331 happens often during iconify animation) */
332 if (detail
== NotifyInferior
)
336 /* This means focus moved from the root window to a client */
337 if (detail
== NotifyVirtual
)
339 /* This means focus moved from one client to another */
340 if (detail
== NotifyNonlinearVirtual
)
346 g_assert(e
->type
== FocusOut
);
348 /* These are ones we never want.. */
350 /* This means focus was taken by a keyboard/mouse grab. */
351 if (mode
== NotifyGrab
)
353 /* This means focus was grabbed on a window and it was released. */
354 if (mode
== NotifyUngrab
)
357 /* Focus left the root window revertedto state */
358 if (win
== obt_root(ob_screen
))
361 /* These are the ones we want.. */
363 /* This means focus moved from a client to the root window */
364 if (detail
== NotifyVirtual
)
366 /* This means focus moved from one client to another */
367 if (detail
== NotifyNonlinearVirtual
)
375 static Bool
event_look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
377 return e
->type
== FocusIn
&& wanted_focusevent(e
, FALSE
);
380 static Bool
event_look_for_focusin_client(Display
*d
, XEvent
*e
, XPointer arg
)
382 return e
->type
== FocusIn
&& wanted_focusevent(e
, TRUE
);
385 static void print_focusevent(XEvent
*e
)
387 gint mode
= e
->xfocus
.mode
;
388 gint detail
= e
->xfocus
.detail
;
389 Window win
= e
->xany
.window
;
390 const gchar
*modestr
, *detailstr
;
393 case NotifyNormal
: modestr
="NotifyNormal"; break;
394 case NotifyGrab
: modestr
="NotifyGrab"; break;
395 case NotifyUngrab
: modestr
="NotifyUngrab"; break;
396 case NotifyWhileGrabbed
: modestr
="NotifyWhileGrabbed"; break;
397 default: g_assert_not_reached();
400 case NotifyAncestor
: detailstr
="NotifyAncestor"; break;
401 case NotifyVirtual
: detailstr
="NotifyVirtual"; break;
402 case NotifyInferior
: detailstr
="NotifyInferior"; break;
403 case NotifyNonlinear
: detailstr
="NotifyNonlinear"; break;
404 case NotifyNonlinearVirtual
: detailstr
="NotifyNonlinearVirtual"; break;
405 case NotifyPointer
: detailstr
="NotifyPointer"; break;
406 case NotifyPointerRoot
: detailstr
="NotifyPointerRoot"; break;
407 case NotifyDetailNone
: detailstr
="NotifyDetailNone"; break;
408 default: g_assert_not_reached();
411 if (mode
== NotifyGrab
|| mode
== NotifyUngrab
)
416 ob_debug_type(OB_DEBUG_FOCUS
, "Focus%s 0x%x mode=%s detail=%s",
417 (e
->xfocus
.type
== FocusIn
? "In" : "Out"),
423 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
428 if (!wanted_focusevent(e
, FALSE
))
433 if (!wanted_focusevent(e
, FALSE
))
440 static void event_process(const XEvent
*ec
, gpointer data
)
443 ObEventData
*ed
= data
;
446 ObClient
*client
= NULL
;
448 ObDockApp
*dockapp
= NULL
;
449 ObWindow
*obwin
= NULL
;
450 ObMenuFrame
*menu
= NULL
;
451 ObPrompt
*prompt
= NULL
;
454 /* make a copy we can mangle */
458 window
= event_get_window(e
);
459 if (window
== obt_root(ob_screen
))
460 /* don't do any lookups, waste of cpu */;
461 else if ((obwin
= window_find(window
))) {
462 switch (obwin
->type
) {
463 case OB_WINDOW_CLASS_DOCK
:
464 dock
= WINDOW_AS_DOCK(obwin
);
466 case OB_WINDOW_CLASS_CLIENT
:
467 client
= WINDOW_AS_CLIENT(obwin
);
468 /* events on clients can be events on prompt windows too */
469 prompt
= client
->prompt
;
471 case OB_WINDOW_CLASS_MENUFRAME
:
472 menu
= WINDOW_AS_MENUFRAME(obwin
);
474 case OB_WINDOW_CLASS_INTERNAL
:
475 /* we don't do anything with events directly on these windows */
477 case OB_WINDOW_CLASS_PROMPT
:
478 prompt
= WINDOW_AS_PROMPT(obwin
);
483 dockapp
= dock_find_dockapp(window
);
485 event_set_curtime(e
);
486 event_curserial
= e
->xany
.serial
;
488 if (event_ignore(e
, client
)) {
495 /* deal with it in the kernel */
497 if (e
->type
== FocusIn
) {
499 e
->xfocus
.detail
== NotifyInferior
)
501 ob_debug_type(OB_DEBUG_FOCUS
,
502 "Focus went to the frame window");
504 focus_left_screen
= FALSE
;
506 focus_fallback(FALSE
, config_focus_under_mouse
, TRUE
, TRUE
);
508 /* We don't get a FocusOut for this case, because it's just moving
509 from our Inferior up to us. This happens when iconifying a
510 window with RevertToParent focus */
511 frame_adjust_focus(client
->frame
, FALSE
);
512 /* focus_set_client(NULL) has already been called */
514 else if (e
->xfocus
.detail
== NotifyPointerRoot
||
515 e
->xfocus
.detail
== NotifyDetailNone
||
516 e
->xfocus
.detail
== NotifyInferior
||
517 e
->xfocus
.detail
== NotifyNonlinear
)
521 ob_debug_type(OB_DEBUG_FOCUS
,
522 "Focus went to root or pointer root/none");
524 if (e
->xfocus
.detail
== NotifyInferior
||
525 e
->xfocus
.detail
== NotifyNonlinear
)
527 focus_left_screen
= FALSE
;
530 /* If another FocusIn is in the queue then don't fallback yet. This
531 fixes the fun case of:
532 window map -> send focusin
533 window unmap -> get focusout
534 window map -> send focusin
535 get first focus out -> fall back to something (new window
536 hasn't received focus yet, so something else) -> send focusin
537 which means the "something else" is the last thing to get a
538 focusin sent to it, so the new window doesn't end up with focus.
540 But if the other focus in is something like PointerRoot then we
541 still want to fall back.
543 if (XCheckIfEvent(obt_display
, &ce
, event_look_for_focusin_client
,
546 XPutBackEvent(obt_display
, &ce
);
547 ob_debug_type(OB_DEBUG_FOCUS
,
548 " but another FocusIn is coming");
550 /* Focus has been reverted.
552 FocusOut events come after UnmapNotify, so we don't need to
553 worry about focusing an invalid window
556 if (!focus_left_screen
)
557 focus_fallback(FALSE
, config_focus_under_mouse
,
563 ob_debug_type(OB_DEBUG_FOCUS
,
564 "Focus went to a window that is already gone");
566 /* If you send focus to a window and then it disappears, you can
567 get the FocusIn for it, after it is unmanaged.
568 Just wait for the next FocusOut/FocusIn pair, but make note that
569 the window that was focused no longer is. */
570 focus_set_client(NULL
);
572 else if (client
!= focus_client
) {
573 focus_left_screen
= FALSE
;
574 frame_adjust_focus(client
->frame
, TRUE
);
575 focus_set_client(client
);
576 client_calc_layer(client
);
577 client_bring_helper_windows(client
);
579 } else if (e
->type
== FocusOut
) {
582 /* Look for the followup FocusIn */
583 if (!XCheckIfEvent(obt_display
, &ce
, event_look_for_focusin
, NULL
)) {
584 /* There is no FocusIn, this means focus went to a window that
585 is not being managed, or a window on another screen. */
589 obt_display_ignore_errors(TRUE
);
590 if (XGetInputFocus(obt_display
, &win
, &i
) &&
591 XGetGeometry(obt_display
, win
, &root
, &i
,&i
,&u
,&u
,&u
,&u
) &&
592 root
!= obt_root(ob_screen
))
594 ob_debug_type(OB_DEBUG_FOCUS
,
595 "Focus went to another screen !");
596 focus_left_screen
= TRUE
;
599 ob_debug_type(OB_DEBUG_FOCUS
,
600 "Focus went to a black hole !");
601 obt_display_ignore_errors(FALSE
);
602 /* nothing is focused */
603 focus_set_client(NULL
);
605 /* Focus moved, so process the FocusIn event */
606 ObEventData ed
= { .ignored
= FALSE
};
607 event_process(&ce
, &ed
);
609 /* The FocusIn was ignored, this means it was on a window
610 that isn't a client. */
611 ob_debug_type(OB_DEBUG_FOCUS
,
612 "Focus went to an unmanaged window 0x%x !",
614 focus_fallback(TRUE
, config_focus_under_mouse
, TRUE
, TRUE
);
618 if (client
&& client
!= focus_client
) {
619 frame_adjust_focus(client
->frame
, FALSE
);
620 /* focus_set_client(NULL) has already been called in this
621 section or by focus_fallback */
625 event_handle_client(client
, e
);
627 event_handle_dockapp(dockapp
, e
);
629 event_handle_dock(dock
, e
);
631 event_handle_menu(menu
, e
);
632 else if (window
== obt_root(ob_screen
))
633 event_handle_root(e
);
634 else if (e
->type
== MapRequest
)
635 window_manage(window
);
636 else if (e
->type
== MappingNotify
) {
637 /* keyboard layout changes for modifier mapping changes. reload the
638 modifier map, and rebind all the key bindings as appropriate */
639 ob_debug("Keyboard map changed. Reloading keyboard bindings.");
640 ob_set_state(OB_STATE_RECONFIGURING
);
641 obt_keyboard_reload();
643 ob_set_state(OB_STATE_RUNNING
);
645 else if (e
->type
== ClientMessage
) {
646 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
647 windows that are not managed yet. */
648 if (e
->xclient
.message_type
==
649 OBT_PROP_ATOM(NET_REQUEST_FRAME_EXTENTS
))
651 /* Pretend to manage the client, getting information used to
652 determine its decorations */
653 ObClient
*c
= client_fake_manage(e
->xclient
.window
);
656 /* set the frame extents on the window */
657 vals
[0] = c
->frame
->size
.left
;
658 vals
[1] = c
->frame
->size
.right
;
659 vals
[2] = c
->frame
->size
.top
;
660 vals
[3] = c
->frame
->size
.bottom
;
661 OBT_PROP_SETA32(e
->xclient
.window
, NET_FRAME_EXTENTS
,
664 /* Free the pretend client */
665 client_fake_unmanage(c
);
668 else if (e
->type
== ConfigureRequest
) {
669 /* unhandled configure requests must be used to configure the
673 xwc
.x
= e
->xconfigurerequest
.x
;
674 xwc
.y
= e
->xconfigurerequest
.y
;
675 xwc
.width
= e
->xconfigurerequest
.width
;
676 xwc
.height
= e
->xconfigurerequest
.height
;
677 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
678 xwc
.sibling
= e
->xconfigurerequest
.above
;
679 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
681 /* we are not to be held responsible if someone sends us an
683 obt_display_ignore_errors(TRUE
);
684 XConfigureWindow(obt_display
, window
,
685 e
->xconfigurerequest
.value_mask
, &xwc
);
686 obt_display_ignore_errors(FALSE
);
689 else if (obt_display_extension_sync
&&
690 e
->type
== obt_display_extension_sync_basep
+ XSyncAlarmNotify
)
692 XSyncAlarmNotifyEvent
*se
= (XSyncAlarmNotifyEvent
*)e
;
693 if (se
->alarm
== moveresize_alarm
&& moveresize_in_progress
)
698 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
) {
700 static guint pressed
= 0;
701 static Window pressed_win
= None
;
703 /* If the button press was on some non-root window, or was physically
704 on the root window... */
705 if (window
!= obt_root(ob_screen
) ||
706 e
->xbutton
.subwindow
== None
||
707 /* ...or if it is related to the last button press we handled... */
708 pressed
== e
->xbutton
.button
||
709 /* ...or it if it was physically on an openbox
710 internal window... */
711 ((w
= window_find(e
->xbutton
.subwindow
)) &&
712 WINDOW_IS_INTERNAL(w
)))
713 /* ...then process the event, otherwise ignore it */
715 used
= event_handle_user_input(client
, e
);
717 if (e
->type
== ButtonPress
) {
718 pressed
= e
->xbutton
.button
;
719 pressed_win
= e
->xbutton
.subwindow
;
723 else if (e
->type
== KeyPress
|| e
->type
== KeyRelease
||
724 e
->type
== MotionNotify
)
725 used
= event_handle_user_input(client
, e
);
728 used
= event_handle_prompt(prompt
, e
);
730 /* if something happens and it's not from an XEvent, then we don't know
732 event_curtime
= CurrentTime
;
736 static void event_handle_root(XEvent
*e
)
742 ob_debug("Another WM has requested to replace us. Exiting.");
747 if (e
->xclient
.format
!= 32) break;
749 msgtype
= e
->xclient
.message_type
;
750 if (msgtype
== OBT_PROP_ATOM(NET_CURRENT_DESKTOP
)) {
751 guint d
= e
->xclient
.data
.l
[0];
752 if (d
< screen_num_desktops
) {
753 event_curtime
= e
->xclient
.data
.l
[1];
754 if (event_curtime
== 0)
755 ob_debug_type(OB_DEBUG_APP_BUGS
,
756 "_NET_CURRENT_DESKTOP message is missing "
758 screen_set_desktop(d
, TRUE
);
760 } else if (msgtype
== OBT_PROP_ATOM(NET_NUMBER_OF_DESKTOPS
)) {
761 guint d
= e
->xclient
.data
.l
[0];
762 if (d
> 0 && d
<= 1000)
763 screen_set_num_desktops(d
);
764 } else if (msgtype
== OBT_PROP_ATOM(NET_SHOWING_DESKTOP
)) {
765 screen_show_desktop(e
->xclient
.data
.l
[0] != 0, NULL
);
766 } else if (msgtype
== OBT_PROP_ATOM(OB_CONTROL
)) {
767 ob_debug("OB_CONTROL: %d", e
->xclient
.data
.l
[0]);
768 if (e
->xclient
.data
.l
[0] == 1)
770 else if (e
->xclient
.data
.l
[0] == 2)
772 else if (e
->xclient
.data
.l
[0] == 3)
774 } else if (msgtype
== OBT_PROP_ATOM(WM_PROTOCOLS
)) {
775 if ((Atom
)e
->xclient
.data
.l
[0] == OBT_PROP_ATOM(NET_WM_PING
))
776 ping_got_pong(e
->xclient
.data
.l
[1]);
780 if (e
->xproperty
.atom
== OBT_PROP_ATOM(NET_DESKTOP_NAMES
)) {
781 ob_debug("UPDATE DESKTOP NAMES");
782 screen_update_desktop_names();
784 else if (e
->xproperty
.atom
== OBT_PROP_ATOM(NET_DESKTOP_LAYOUT
))
785 screen_update_layout();
787 case ConfigureNotify
:
789 XRRUpdateConfiguration(e
);
798 void event_enter_client(ObClient
*client
)
800 g_assert(config_focus_follow
);
802 if (is_enter_focus_event_ignored(event_curserial
)) {
803 ob_debug_type(OB_DEBUG_FOCUS
, "Ignoring enter event with serial %lu\n"
804 "on client 0x%x", event_curserial
, client
->window
);
808 if (client_enter_focusable(client
) && client_can_focus(client
)) {
809 if (config_focus_delay
) {
810 ObFocusDelayData
*data
;
812 obt_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
814 data
= g_slice_new(ObFocusDelayData
);
815 data
->client
= client
;
816 data
->time
= event_curtime
;
817 data
->serial
= event_curserial
;
819 obt_main_loop_timeout_add(ob_main_loop
,
820 config_focus_delay
* 1000,
822 data
, focus_delay_cmp
, focus_delay_dest
);
824 ObFocusDelayData data
;
825 data
.client
= client
;
826 data
.time
= event_curtime
;
827 data
.serial
= event_curserial
;
828 focus_delay_func(&data
);
833 void event_leave_client(ObClient
*client
)
835 g_assert(config_focus_follow
);
837 if (is_enter_focus_event_ignored(event_curserial
)) {
838 ob_debug_type(OB_DEBUG_FOCUS
, "Ignoring leave event with serial %lu\n"
839 "on client 0x%x", event_curserial
, client
->window
);
843 if (client
== focus_client
) {
844 if (config_focus_delay
) {
845 ObFocusDelayData
*data
;
847 obt_main_loop_timeout_remove(ob_main_loop
, unfocus_delay_func
);
849 data
= g_slice_new(ObFocusDelayData
);
850 data
->client
= client
;
851 data
->time
= event_curtime
;
852 data
->serial
= event_curserial
;
854 obt_main_loop_timeout_add(ob_main_loop
,
855 config_focus_delay
* 1000,
857 data
, focus_delay_cmp
, focus_delay_dest
);
859 ObFocusDelayData data
;
860 data
.client
= client
;
861 data
.time
= event_curtime
;
862 data
.serial
= event_curserial
;
863 unfocus_delay_func(&data
);
868 static gboolean
*context_to_button(ObFrame
*f
, ObFrameContext con
, gboolean press
)
872 case OB_FRAME_CONTEXT_MAXIMIZE
:
873 return &f
->max_press
;
874 case OB_FRAME_CONTEXT_CLOSE
:
875 return &f
->close_press
;
876 case OB_FRAME_CONTEXT_ICONIFY
:
877 return &f
->iconify_press
;
878 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
879 return &f
->desk_press
;
880 case OB_FRAME_CONTEXT_SHADE
:
881 return &f
->shade_press
;
887 case OB_FRAME_CONTEXT_MAXIMIZE
:
888 return &f
->max_hover
;
889 case OB_FRAME_CONTEXT_CLOSE
:
890 return &f
->close_hover
;
891 case OB_FRAME_CONTEXT_ICONIFY
:
892 return &f
->iconify_hover
;
893 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
894 return &f
->desk_hover
;
895 case OB_FRAME_CONTEXT_SHADE
:
896 return &f
->shade_hover
;
903 static void compress_client_message_event(XEvent
*e
, XEvent
*ce
, Window window
,
906 /* compress changes into a single change */
907 while (XCheckTypedWindowEvent(obt_display
, window
, e
->type
, ce
)) {
908 /* XXX: it would be nice to compress ALL messages of a
909 type, not just messages in a row without other
910 message types between. */
911 if (ce
->xclient
.message_type
!= msgtype
) {
912 XPutBackEvent(obt_display
, ce
);
915 e
->xclient
= ce
->xclient
;
919 static void event_handle_client(ObClient
*client
, XEvent
*e
)
925 static gint px
= -1, py
= -1;
927 static ObFrameContext pcon
= OB_FRAME_CONTEXT_NONE
;
931 /* save where the press occured for the first button pressed */
933 pb
= e
->xbutton
.button
;
937 pcon
= frame_context(client
, e
->xbutton
.window
, px
, py
);
938 pcon
= mouse_button_frame_context(pcon
, e
->xbutton
.button
,
942 /* Wheel buttons don't draw because they are an instant click, so it
943 is a waste of resources to go drawing it.
944 if the user is doing an interactive thing, or has a menu open then
945 the mouse is grabbed (possibly) and if we get these events we don't
946 want to deal with them
948 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5) &&
951 /* use where the press occured */
952 con
= frame_context(client
, e
->xbutton
.window
, px
, py
);
953 con
= mouse_button_frame_context(con
, e
->xbutton
.button
,
956 /* button presses on CLIENT_CONTEXTs are not accompanied by a
957 release because they are Replayed to the client */
958 if ((e
->type
== ButtonRelease
|| CLIENT_CONTEXT(con
, client
)) &&
959 e
->xbutton
.button
== pb
)
960 pb
= 0, px
= py
= -1, pcon
= OB_FRAME_CONTEXT_NONE
;
962 but
= context_to_button(client
->frame
, con
, TRUE
);
964 *but
= (e
->type
== ButtonPress
);
965 frame_adjust_state(client
->frame
);
970 /* when there is a grab on the pointer, we won't get enter/leave
971 notifies, but we still get motion events */
972 if (grab_on_pointer()) break;
974 con
= frame_context(client
, e
->xmotion
.window
,
975 e
->xmotion
.x
, e
->xmotion
.y
);
977 case OB_FRAME_CONTEXT_TITLEBAR
:
978 case OB_FRAME_CONTEXT_TLCORNER
:
979 case OB_FRAME_CONTEXT_TRCORNER
:
980 /* we've left the button area inside the titlebar */
981 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
982 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
983 client
->frame
->close_hover
)
985 client
->frame
->max_hover
=
986 client
->frame
->desk_hover
=
987 client
->frame
->shade_hover
=
988 client
->frame
->iconify_hover
=
989 client
->frame
->close_hover
= FALSE
;
990 frame_adjust_state(client
->frame
);
994 but
= context_to_button(client
->frame
, con
, FALSE
);
995 if (but
&& !*but
&& !pb
) {
997 frame_adjust_state(client
->frame
);
1003 con
= frame_context(client
, e
->xcrossing
.window
,
1004 e
->xcrossing
.x
, e
->xcrossing
.y
);
1006 case OB_FRAME_CONTEXT_TITLEBAR
:
1007 case OB_FRAME_CONTEXT_TLCORNER
:
1008 case OB_FRAME_CONTEXT_TRCORNER
:
1009 /* we've left the button area inside the titlebar */
1010 client
->frame
->max_hover
=
1011 client
->frame
->desk_hover
=
1012 client
->frame
->shade_hover
=
1013 client
->frame
->iconify_hover
=
1014 client
->frame
->close_hover
= FALSE
;
1015 if (e
->xcrossing
.mode
== NotifyGrab
) {
1016 client
->frame
->max_press
=
1017 client
->frame
->desk_press
=
1018 client
->frame
->shade_press
=
1019 client
->frame
->iconify_press
=
1020 client
->frame
->close_press
= FALSE
;
1023 case OB_FRAME_CONTEXT_FRAME
:
1024 /* When the mouse leaves an animating window, don't use the
1025 corresponding enter events. Pretend like the animating window
1026 doesn't even exist..! */
1027 if (frame_iconify_animating(client
->frame
))
1028 event_end_ignore_all_enters(event_start_ignore_all_enters());
1030 ob_debug_type(OB_DEBUG_FOCUS
,
1031 "%sNotify mode %d detail %d on %lx",
1032 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1034 e
->xcrossing
.detail
, (client
?client
->window
:0));
1035 if (grab_on_keyboard())
1037 if (config_focus_follow
&&
1038 /* leave inferior events can happen when the mouse goes onto
1039 the window's border and then into the window before the
1041 e
->xcrossing
.detail
!= NotifyInferior
)
1043 if (config_focus_delay
)
1044 obt_main_loop_timeout_remove_data(ob_main_loop
,
1047 if (config_unfocus_leave
)
1048 event_leave_client(client
);
1052 but
= context_to_button(client
->frame
, con
, FALSE
);
1055 if (e
->xcrossing
.mode
== NotifyGrab
) {
1056 but
= context_to_button(client
->frame
, con
, TRUE
);
1059 frame_adjust_state(client
->frame
);
1066 con
= frame_context(client
, e
->xcrossing
.window
,
1067 e
->xcrossing
.x
, e
->xcrossing
.y
);
1069 case OB_FRAME_CONTEXT_FRAME
:
1070 if (grab_on_keyboard())
1072 if (e
->xcrossing
.mode
== NotifyGrab
||
1073 e
->xcrossing
.mode
== NotifyUngrab
||
1074 /*ignore enters when we're already in the window */
1075 e
->xcrossing
.detail
== NotifyInferior
)
1077 ob_debug_type(OB_DEBUG_FOCUS
,
1078 "%sNotify mode %d detail %d serial %lu on %lx "
1080 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1082 e
->xcrossing
.detail
,
1083 e
->xcrossing
.serial
,
1084 client
?client
->window
:0);
1087 ob_debug_type(OB_DEBUG_FOCUS
,
1088 "%sNotify mode %d detail %d serial %lu on %lx, "
1090 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1092 e
->xcrossing
.detail
,
1093 e
->xcrossing
.serial
,
1094 (client
?client
->window
:0));
1095 if (config_focus_follow
) {
1096 if (config_focus_delay
)
1097 obt_main_loop_timeout_remove_data(ob_main_loop
,
1100 event_enter_client(client
);
1105 but
= context_to_button(client
->frame
, con
, FALSE
);
1108 if (e
->xcrossing
.mode
== NotifyUngrab
) {
1109 but
= context_to_button(client
->frame
, con
, TRUE
);
1110 *but
= (con
== pcon
);
1112 frame_adjust_state(client
->frame
);
1118 case ConfigureRequest
:
1120 /* dont compress these unless you're going to watch for property
1121 notifies in between (these can change what the configure would
1123 also you can't compress stacking events
1127 gboolean move
= FALSE
;
1128 gboolean resize
= FALSE
;
1130 /* get the current area */
1131 RECT_TO_DIMS(client
->area
, x
, y
, w
, h
);
1133 ob_debug("ConfigureRequest for \"%s\" desktop %d wmstate %d "
1136 screen_desktop
, client
->wmstate
, client
->frame
->visible
);
1137 ob_debug(" x %d y %d w %d h %d b %d",
1138 x
, y
, w
, h
, client
->border_width
);
1140 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
1141 if (client
->border_width
!= e
->xconfigurerequest
.border_width
) {
1142 client
->border_width
= e
->xconfigurerequest
.border_width
;
1144 /* if the border width is changing then that is the same
1145 as requesting a resize, but we don't actually change
1146 the client's border, so it will change their root
1147 coordinates (since they include the border width) and
1148 we need to a notify then */
1152 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
1153 ObClient
*sibling
= NULL
;
1154 gulong ignore_start
;
1157 /* get the sibling */
1158 if (e
->xconfigurerequest
.value_mask
& CWSibling
) {
1160 win
= window_find(e
->xconfigurerequest
.above
);
1161 if (win
&& WINDOW_IS_CLIENT(win
) &&
1162 WINDOW_AS_CLIENT(win
) != client
)
1164 sibling
= WINDOW_AS_CLIENT(win
);
1167 /* an invalid sibling was specified so don't restack at
1168 all, it won't make sense no matter what we do */
1173 if (!config_focus_under_mouse
)
1174 ignore_start
= event_start_ignore_all_enters();
1175 stacking_restack_request(client
, sibling
,
1176 e
->xconfigurerequest
.detail
);
1177 if (!config_focus_under_mouse
)
1178 event_end_ignore_all_enters(ignore_start
);
1181 /* a stacking change moves the window without resizing */
1185 if ((e
->xconfigurerequest
.value_mask
& CWX
) ||
1186 (e
->xconfigurerequest
.value_mask
& CWY
) ||
1187 (e
->xconfigurerequest
.value_mask
& CWWidth
) ||
1188 (e
->xconfigurerequest
.value_mask
& CWHeight
))
1190 /* don't allow clients to move shaded windows (fvwm does this)
1192 if (e
->xconfigurerequest
.value_mask
& CWX
) {
1193 if (!client
->shaded
)
1194 x
= e
->xconfigurerequest
.x
;
1197 if (e
->xconfigurerequest
.value_mask
& CWY
) {
1198 if (!client
->shaded
)
1199 y
= e
->xconfigurerequest
.y
;
1203 if (e
->xconfigurerequest
.value_mask
& CWWidth
) {
1204 w
= e
->xconfigurerequest
.width
;
1207 if (e
->xconfigurerequest
.value_mask
& CWHeight
) {
1208 h
= e
->xconfigurerequest
.height
;
1213 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
1214 "move %d resize %d",
1215 e
->xconfigurerequest
.value_mask
& CWX
, x
,
1216 e
->xconfigurerequest
.value_mask
& CWY
, y
,
1217 e
->xconfigurerequest
.value_mask
& CWWidth
, w
,
1218 e
->xconfigurerequest
.value_mask
& CWHeight
, h
,
1221 /* check for broken apps moving to their root position
1223 XXX remove this some day...that would be nice. right now all
1224 kde apps do this when they try activate themselves on another
1225 desktop. eg. open amarok window on desktop 1, switch to desktop
1226 2, click amarok tray icon. it will move by its decoration size.
1228 if (x
!= client
->area
.x
&&
1229 x
== (client
->frame
->area
.x
+ client
->frame
->size
.left
-
1230 (gint
)client
->border_width
) &&
1231 y
!= client
->area
.y
&&
1232 y
== (client
->frame
->area
.y
+ client
->frame
->size
.top
-
1233 (gint
)client
->border_width
) &&
1234 w
== client
->area
.width
&&
1235 h
== client
->area
.height
)
1237 ob_debug_type(OB_DEBUG_APP_BUGS
,
1238 "Application %s is trying to move via "
1239 "ConfigureRequest to it's root window position "
1240 "but it is not using StaticGravity",
1246 /* they still requested a move, so don't change whether a
1247 notify is sent or not */
1253 client_try_configure(client
, &x
, &y
, &w
, &h
, &lw
, &lh
, FALSE
);
1255 /* if x was not given, then use gravity to figure out the new
1256 x. the reference point should not be moved */
1257 if ((e
->xconfigurerequest
.value_mask
& CWWidth
&&
1258 !(e
->xconfigurerequest
.value_mask
& CWX
)))
1259 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1261 if ((e
->xconfigurerequest
.value_mask
& CWHeight
&&
1262 !(e
->xconfigurerequest
.value_mask
& CWY
)))
1263 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1265 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1267 ob_debug("Granting ConfigureRequest x %d y %d w %d h %d",
1269 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
, TRUE
);
1274 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1276 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
1277 client
->ignore_unmaps
);
1278 if (client
->ignore_unmaps
) {
1279 client
->ignore_unmaps
--;
1282 client_unmanage(client
);
1285 ob_debug("DestroyNotify for window 0x%x", client
->window
);
1286 client_unmanage(client
);
1288 case ReparentNotify
:
1289 /* this is when the client is first taken captive in the frame */
1290 if (e
->xreparent
.parent
== client
->frame
->window
) break;
1293 This event is quite rare and is usually handled in unmapHandler.
1294 However, if the window is unmapped when the reparent event occurs,
1295 the window manager never sees it because an unmap event is not sent
1296 to an already unmapped window.
1299 /* we don't want the reparent event, put it back on the stack for the
1300 X server to deal with after we unmanage the window */
1301 XPutBackEvent(obt_display
, e
);
1303 ob_debug("ReparentNotify for window 0x%x", client
->window
);
1304 client_unmanage(client
);
1307 ob_debug("MapRequest for 0x%lx", client
->window
);
1308 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
1309 does, we don't want it!
1310 it can happen now when the window is on
1311 another desktop, but we still don't
1313 client_activate(client
, FALSE
, FALSE
, TRUE
, TRUE
, TRUE
);
1316 /* validate cuz we query stuff off the client here */
1317 if (!client_validate(client
)) break;
1319 if (e
->xclient
.format
!= 32) return;
1321 msgtype
= e
->xclient
.message_type
;
1322 if (msgtype
== OBT_PROP_ATOM(WM_CHANGE_STATE
)) {
1323 compress_client_message_event(e
, &ce
, client
->window
, msgtype
);
1324 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1325 } else if (msgtype
== OBT_PROP_ATOM(NET_WM_DESKTOP
)) {
1326 compress_client_message_event(e
, &ce
, client
->window
, msgtype
);
1327 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1328 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1329 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1331 } else if (msgtype
== OBT_PROP_ATOM(NET_WM_STATE
)) {
1332 gulong ignore_start
;
1334 /* can't compress these */
1335 ob_debug("net_wm_state %s %ld %ld for 0x%lx",
1336 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1337 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1338 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1339 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1342 /* ignore enter events caused by these like ob actions do */
1343 if (!config_focus_under_mouse
)
1344 ignore_start
= event_start_ignore_all_enters();
1345 client_set_state(client
, e
->xclient
.data
.l
[0],
1346 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1347 if (!config_focus_under_mouse
)
1348 event_end_ignore_all_enters(ignore_start
);
1349 } else if (msgtype
== OBT_PROP_ATOM(NET_CLOSE_WINDOW
)) {
1350 ob_debug("net_close_window for 0x%lx", client
->window
);
1351 client_close(client
);
1352 } else if (msgtype
== OBT_PROP_ATOM(NET_ACTIVE_WINDOW
)) {
1353 ob_debug("net_active_window for 0x%lx source=%s",
1355 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1356 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1357 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1358 /* XXX make use of data.l[2] !? */
1359 if (e
->xclient
.data
.l
[0] == 1 || e
->xclient
.data
.l
[0] == 2) {
1360 /* we can not trust the timestamp from applications.
1361 e.g. chromium passes a very old timestamp. openbox thinks
1362 the window will get focus and calls XSetInputFocus with the
1363 (old) timestamp, which doesn't end up moving focus at all.
1364 but the window is raised, not hilited, etc, as if it was
1365 really going to get focus.
1367 so do not use this timestamp in event_curtime, as this would
1368 be used in XSetInputFocus.
1370 /*event_curtime = e->xclient.data.l[1];*/
1371 if (e
->xclient
.data
.l
[1] == 0)
1372 ob_debug_type(OB_DEBUG_APP_BUGS
,
1373 "_NET_ACTIVE_WINDOW message for window %s is"
1374 " missing a timestamp", client
->title
);
1376 event_curtime
= event_get_server_time();
1378 ob_debug_type(OB_DEBUG_APP_BUGS
,
1379 "_NET_ACTIVE_WINDOW message for window %s is "
1380 "missing source indication", client
->title
);
1381 client_activate(client
, FALSE
, FALSE
, TRUE
, TRUE
,
1382 (e
->xclient
.data
.l
[0] == 0 ||
1383 e
->xclient
.data
.l
[0] == 2));
1384 } else if (msgtype
== OBT_PROP_ATOM(NET_WM_MOVERESIZE
)) {
1385 ob_debug("net_wm_moveresize for 0x%lx direction %d",
1386 client
->window
, e
->xclient
.data
.l
[2]);
1387 if ((Atom
)e
->xclient
.data
.l
[2] ==
1388 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT
) ||
1389 (Atom
)e
->xclient
.data
.l
[2] ==
1390 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP
) ||
1391 (Atom
)e
->xclient
.data
.l
[2] ==
1392 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT
) ||
1393 (Atom
)e
->xclient
.data
.l
[2] ==
1394 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT
) ||
1395 (Atom
)e
->xclient
.data
.l
[2] ==
1396 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT
) ||
1397 (Atom
)e
->xclient
.data
.l
[2] ==
1398 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
) ||
1399 (Atom
)e
->xclient
.data
.l
[2] ==
1400 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM
) ||
1401 (Atom
)e
->xclient
.data
.l
[2] ==
1402 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
) ||
1403 (Atom
)e
->xclient
.data
.l
[2] ==
1404 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT
) ||
1405 (Atom
)e
->xclient
.data
.l
[2] ==
1406 OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE
) ||
1407 (Atom
)e
->xclient
.data
.l
[2] ==
1408 OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD
) ||
1409 (Atom
)e
->xclient
.data
.l
[2] ==
1410 OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD
))
1412 moveresize_start(client
, e
->xclient
.data
.l
[0],
1413 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1414 e
->xclient
.data
.l
[2]);
1416 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1417 OBT_PROP_ATOM(NET_WM_MOVERESIZE_CANCEL
))
1418 moveresize_end(TRUE
);
1419 } else if (msgtype
== OBT_PROP_ATOM(NET_MOVERESIZE_WINDOW
)) {
1420 gint ograv
, x
, y
, w
, h
;
1422 ograv
= client
->gravity
;
1424 if (e
->xclient
.data
.l
[0] & 0xff)
1425 client
->gravity
= e
->xclient
.data
.l
[0] & 0xff;
1427 if (e
->xclient
.data
.l
[0] & 1 << 8)
1428 x
= e
->xclient
.data
.l
[1];
1431 if (e
->xclient
.data
.l
[0] & 1 << 9)
1432 y
= e
->xclient
.data
.l
[2];
1436 if (e
->xclient
.data
.l
[0] & 1 << 10) {
1437 w
= e
->xclient
.data
.l
[3];
1439 /* if x was not given, then use gravity to figure out the new
1440 x. the reference point should not be moved */
1441 if (!(e
->xclient
.data
.l
[0] & 1 << 8))
1442 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1445 w
= client
->area
.width
;
1447 if (e
->xclient
.data
.l
[0] & 1 << 11) {
1448 h
= e
->xclient
.data
.l
[4];
1451 if (!(e
->xclient
.data
.l
[0] & 1 << 9))
1452 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1455 h
= client
->area
.height
;
1457 ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)",
1458 e
->xclient
.data
.l
[0] & 1 << 8, x
,
1459 e
->xclient
.data
.l
[0] & 1 << 9, y
,
1462 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1464 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
1466 client
->gravity
= ograv
;
1467 } else if (msgtype
== OBT_PROP_ATOM(NET_RESTACK_WINDOW
)) {
1468 if (e
->xclient
.data
.l
[0] != 2) {
1469 ob_debug_type(OB_DEBUG_APP_BUGS
,
1470 "_NET_RESTACK_WINDOW sent for window %s with "
1471 "invalid source indication %ld",
1472 client
->title
, e
->xclient
.data
.l
[0]);
1474 ObClient
*sibling
= NULL
;
1475 if (e
->xclient
.data
.l
[1]) {
1476 ObWindow
*win
= window_find(e
->xclient
.data
.l
[1]);
1477 if (WINDOW_IS_CLIENT(win
) &&
1478 WINDOW_AS_CLIENT(win
) != client
)
1480 sibling
= WINDOW_AS_CLIENT(win
);
1482 if (sibling
== NULL
)
1483 ob_debug_type(OB_DEBUG_APP_BUGS
,
1484 "_NET_RESTACK_WINDOW sent for window %s "
1485 "with invalid sibling 0x%x",
1486 client
->title
, e
->xclient
.data
.l
[1]);
1488 if (e
->xclient
.data
.l
[2] == Below
||
1489 e
->xclient
.data
.l
[2] == BottomIf
||
1490 e
->xclient
.data
.l
[2] == Above
||
1491 e
->xclient
.data
.l
[2] == TopIf
||
1492 e
->xclient
.data
.l
[2] == Opposite
)
1494 gulong ignore_start
;
1496 if (!config_focus_under_mouse
)
1497 ignore_start
= event_start_ignore_all_enters();
1498 /* just raise, don't activate */
1499 stacking_restack_request(client
, sibling
,
1500 e
->xclient
.data
.l
[2]);
1501 if (!config_focus_under_mouse
)
1502 event_end_ignore_all_enters(ignore_start
);
1504 /* send a synthetic ConfigureNotify, cuz this is supposed
1505 to be like a ConfigureRequest. */
1506 client_reconfigure(client
, TRUE
);
1508 ob_debug_type(OB_DEBUG_APP_BUGS
,
1509 "_NET_RESTACK_WINDOW sent for window %s "
1510 "with invalid detail %d",
1511 client
->title
, e
->xclient
.data
.l
[2]);
1515 case PropertyNotify
:
1516 /* validate cuz we query stuff off the client here */
1517 if (!client_validate(client
)) break;
1519 /* compress changes to a single property into a single change */
1520 while (XCheckTypedWindowEvent(obt_display
, client
->window
,
1524 /* XXX: it would be nice to compress ALL changes to a property,
1525 not just changes in a row without other props between. */
1527 a
= ce
.xproperty
.atom
;
1528 b
= e
->xproperty
.atom
;
1532 if ((a
== OBT_PROP_ATOM(NET_WM_NAME
) ||
1533 a
== OBT_PROP_ATOM(WM_NAME
) ||
1534 a
== OBT_PROP_ATOM(NET_WM_ICON_NAME
) ||
1535 a
== OBT_PROP_ATOM(WM_ICON_NAME
))
1537 (b
== OBT_PROP_ATOM(NET_WM_NAME
) ||
1538 b
== OBT_PROP_ATOM(WM_NAME
) ||
1539 b
== OBT_PROP_ATOM(NET_WM_ICON_NAME
) ||
1540 b
== OBT_PROP_ATOM(WM_ICON_NAME
))) {
1543 if (a
== OBT_PROP_ATOM(NET_WM_ICON
) &&
1544 b
== OBT_PROP_ATOM(NET_WM_ICON
))
1547 XPutBackEvent(obt_display
, &ce
);
1551 msgtype
= e
->xproperty
.atom
;
1552 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1553 int x
, y
, w
, h
, lw
, lh
;
1555 ob_debug("Update NORMAL hints");
1556 client_update_normal_hints(client
);
1557 /* normal hints can make a window non-resizable */
1558 client_setup_decor_and_functions(client
, FALSE
);
1562 w
= client
->area
.width
;
1563 h
= client
->area
.height
;
1565 /* apply the new normal hints */
1566 client_try_configure(client
, &x
, &y
, &w
, &h
, &lw
, &lh
, FALSE
);
1567 /* make sure the window is visible, and if the window is resized
1568 off-screen due to the normal hints changing then this will push
1569 it back onto the screen. */
1570 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1572 /* make sure the client's sizes are within its bounds, but don't
1573 make it reply with a configurenotify unless something changed.
1574 emacs will update its normal hints every time it receives a
1576 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
1577 } else if (msgtype
== OBT_PROP_ATOM(MOTIF_WM_HINTS
)) {
1578 client_get_mwm_hints(client
);
1579 /* This can override some mwm hints */
1580 client_get_type_and_transientness(client
);
1582 /* Apply the changes to the window */
1583 client_setup_decor_and_functions(client
, TRUE
);
1584 } else if (msgtype
== XA_WM_HINTS
) {
1585 client_update_wmhints(client
);
1586 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1587 client_update_transient_for(client
);
1588 client_get_type_and_transientness(client
);
1589 /* type may have changed, so update the layer */
1590 client_calc_layer(client
);
1591 client_setup_decor_and_functions(client
, TRUE
);
1592 } else if (msgtype
== OBT_PROP_ATOM(NET_WM_NAME
) ||
1593 msgtype
== OBT_PROP_ATOM(WM_NAME
) ||
1594 msgtype
== OBT_PROP_ATOM(NET_WM_ICON_NAME
) ||
1595 msgtype
== OBT_PROP_ATOM(WM_ICON_NAME
)) {
1596 client_update_title(client
);
1597 } else if (msgtype
== OBT_PROP_ATOM(WM_PROTOCOLS
)) {
1598 client_update_protocols(client
);
1599 client_setup_decor_and_functions(client
, TRUE
);
1601 else if (msgtype
== OBT_PROP_ATOM(NET_WM_STRUT
) ||
1602 msgtype
== OBT_PROP_ATOM(NET_WM_STRUT_PARTIAL
)) {
1603 client_update_strut(client
);
1605 else if (msgtype
== OBT_PROP_ATOM(NET_WM_ICON
)) {
1606 client_update_icons(client
);
1608 else if (msgtype
== OBT_PROP_ATOM(NET_WM_ICON_GEOMETRY
)) {
1609 client_update_icon_geometry(client
);
1611 else if (msgtype
== OBT_PROP_ATOM(NET_WM_USER_TIME
)) {
1613 if (client
== focus_client
&&
1614 OBT_PROP_GET32(client
->window
, NET_WM_USER_TIME
, CARDINAL
, &t
)
1615 && t
&& !event_time_after(t
, e
->xproperty
.time
) &&
1616 (!event_last_user_time
||
1617 event_time_after(t
, event_last_user_time
)))
1619 event_last_user_time
= t
;
1623 else if (msgtype
== OBT_PROP_ATOM(NET_WM_SYNC_REQUEST_COUNTER
)) {
1624 client_update_sync_request_counter(client
);
1628 case ColormapNotify
:
1629 client_update_colormap(client
, e
->xcolormap
.colormap
);
1636 if (obt_display_extension_shape
&&
1637 e
->type
== obt_display_extension_shape_basep
)
1639 switch (((XShapeEvent
*)e
)->kind
) {
1642 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1643 kind
= ShapeBounding
;
1646 client
->shaped_input
= ((XShapeEvent
*)e
)->shaped
;
1650 g_assert_not_reached();
1652 frame_adjust_shape_kind(client
->frame
, kind
);
1659 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1663 if (e
->xbutton
.button
== 1)
1664 stacking_raise(DOCK_AS_WINDOW(s
));
1665 else if (e
->xbutton
.button
== 2)
1666 stacking_lower(DOCK_AS_WINDOW(s
));
1672 /* don't hide when moving into a dock app */
1673 if (e
->xcrossing
.detail
!= NotifyInferior
)
1679 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1683 dock_app_drag(app
, &e
->xmotion
);
1686 if (app
->ignore_unmaps
) {
1687 app
->ignore_unmaps
--;
1690 dock_unmanage(app
, TRUE
);
1693 case ReparentNotify
:
1694 dock_unmanage(app
, FALSE
);
1696 case ConfigureNotify
:
1697 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1702 static ObMenuFrame
* find_active_menu(void)
1705 ObMenuFrame
*ret
= NULL
;
1707 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1716 static ObMenuFrame
* find_active_or_last_menu(void)
1718 ObMenuFrame
*ret
= NULL
;
1720 ret
= find_active_menu();
1721 if (!ret
&& menu_frame_visible
)
1722 ret
= menu_frame_visible
->data
;
1726 static gboolean
event_handle_prompt(ObPrompt
*p
, XEvent
*e
)
1732 return prompt_mouse_event(p
, e
);
1735 return prompt_key_event(p
, e
);
1741 static gboolean
event_handle_menu_input(XEvent
*ev
)
1743 gboolean ret
= FALSE
;
1745 if (ev
->type
== ButtonRelease
|| ev
->type
== ButtonPress
) {
1746 ObMenuEntryFrame
*e
;
1748 if (menu_hide_delay_reached() &&
1749 (ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5))
1751 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1752 ev
->xbutton
.y_root
)))
1754 if (ev
->type
== ButtonPress
&& e
->frame
->child
)
1755 menu_frame_select(e
->frame
->child
, NULL
, TRUE
);
1756 menu_frame_select(e
->frame
, e
, TRUE
);
1757 if (ev
->type
== ButtonRelease
)
1758 menu_entry_frame_execute(e
, ev
->xbutton
.state
);
1760 else if (ev
->type
== ButtonRelease
)
1761 menu_frame_hide_all();
1765 else if (ev
->type
== MotionNotify
) {
1767 ObMenuEntryFrame
*e
;
1769 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1770 ev
->xmotion
.y_root
)))
1771 if (!(f
= find_active_menu()) ||
1773 f
->parent
== e
->frame
||
1774 f
->child
== e
->frame
)
1775 menu_frame_select(e
->frame
, e
, FALSE
);
1777 else if (ev
->type
== KeyPress
|| ev
->type
== KeyRelease
) {
1781 /* get the modifiers */
1782 mods
= obt_keyboard_only_modmasks(ev
->xkey
.state
);
1784 frame
= find_active_or_last_menu();
1786 g_assert_not_reached(); /* there is no active menu */
1788 /* Allow control while going thru the menu */
1789 else if (ev
->type
== KeyPress
&& (mods
& ~ControlMask
) == 0) {
1793 frame
->got_press
= TRUE
;
1794 frame
->press_keycode
= ev
->xkey
.keycode
;
1795 frame
->press_doexec
= FALSE
;
1797 sym
= obt_keyboard_keypress_to_keysym(ev
);
1799 if (sym
== XK_Escape
) {
1800 menu_frame_hide_all();
1804 else if (sym
== XK_Left
) {
1805 /* Left goes to the parent menu */
1806 if (frame
->parent
) {
1807 /* remove focus from the child */
1808 menu_frame_select(frame
, NULL
, TRUE
);
1809 /* and put it in the parent */
1810 menu_frame_select(frame
->parent
, frame
->parent
->selected
,
1816 else if (sym
== XK_Right
) {
1817 /* Right goes to the selected submenu */
1818 if (frame
->selected
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1820 /* make sure it is visible */
1821 menu_frame_select(frame
, frame
->selected
, TRUE
);
1822 menu_frame_select_next(frame
->child
);
1827 else if (sym
== XK_Up
) {
1828 menu_frame_select_previous(frame
);
1832 else if (sym
== XK_Down
) {
1833 menu_frame_select_next(frame
);
1837 else if (sym
== XK_Home
) {
1838 menu_frame_select_first(frame
);
1842 else if (sym
== XK_End
) {
1843 menu_frame_select_last(frame
);
1847 else if (sym
== XK_Return
) {
1848 frame
->press_doexec
= TRUE
;
1852 /* keyboard accelerator shortcuts. (if it was a valid key) */
1853 else if (frame
->entries
&&
1855 obt_keyboard_keypress_to_unichar(menu_frame_ic(frame
),
1860 ObMenuEntryFrame
*found
= NULL
;
1861 guint num_found
= 0;
1863 /* start after the selected one */
1864 start
= frame
->entries
;
1865 if (frame
->selected
) {
1866 for (it
= start
; frame
->selected
!= it
->data
;
1867 it
= g_list_next(it
))
1868 g_assert(it
!= NULL
); /* nothing was selected? */
1869 /* next with wraparound */
1870 start
= g_list_next(it
);
1871 if (start
== NULL
) start
= frame
->entries
;
1876 ObMenuEntryFrame
*e
= it
->data
;
1877 gunichar entrykey
= 0;
1879 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1880 entrykey
= e
->entry
->data
.normal
.shortcut
;
1881 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1882 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1884 if (unikey
== entrykey
) {
1885 if (found
== NULL
) found
= e
;
1889 /* next with wraparound */
1890 it
= g_list_next(it
);
1891 if (it
== NULL
) it
= frame
->entries
;
1892 } while (it
!= start
);
1895 menu_frame_select(frame
, found
, TRUE
);
1898 frame
->press_doexec
= TRUE
;
1904 /* Use KeyRelease events for running things so that the key release
1905 doesn't get sent to the focused application.
1907 Allow ControlMask only, and don't bother if the menu is empty */
1908 else if (ev
->type
== KeyRelease
&& (mods
& ~ControlMask
) == 0) {
1909 if (frame
->press_keycode
== ev
->xkey
.keycode
&&
1911 frame
->press_doexec
)
1914 menu_frame_select_next(frame
->child
);
1915 else if (frame
->selected
)
1916 menu_entry_frame_execute(frame
->selected
, ev
->xkey
.state
);
1924 static Bool
event_look_for_menu_enter(Display
*d
, XEvent
*ev
, XPointer arg
)
1926 ObMenuFrame
*f
= (ObMenuFrame
*)arg
;
1927 ObMenuEntryFrame
*e
;
1928 return ev
->type
== EnterNotify
&&
1929 (e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1930 !e
->ignore_enters
&& e
->frame
== f
;
1933 static void event_handle_menu(ObMenuFrame
*frame
, XEvent
*ev
)
1936 ObMenuEntryFrame
*e
;
1940 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1941 if (e
->ignore_enters
)
1943 else if (!(f
= find_active_menu()) ||
1945 f
->parent
== e
->frame
||
1946 f
->child
== e
->frame
)
1947 menu_frame_select(e
->frame
, e
, FALSE
);
1951 /*ignore leaves when we're already in the window */
1952 if (ev
->xcrossing
.detail
== NotifyInferior
)
1955 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)))
1959 /* check if an EnterNotify event is coming, and if not, then select
1960 nothing in the menu */
1961 if (XCheckIfEvent(obt_display
, &ce
, event_look_for_menu_enter
,
1962 (XPointer
)e
->frame
))
1963 XPutBackEvent(obt_display
, &ce
);
1965 menu_frame_select(e
->frame
, NULL
, FALSE
);
1971 static gboolean
event_handle_user_input(ObClient
*client
, XEvent
*e
)
1973 g_assert(e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
1974 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
1975 e
->type
== KeyRelease
);
1977 if (menu_frame_visible
) {
1978 if (event_handle_menu_input(e
))
1979 /* don't use the event if the menu used it, but if the menu
1980 didn't use it and it's a keypress that is bound, it will
1981 close the menu and be used */
1985 /* if the keyboard interactive action uses the event then dont
1986 use it for bindings. likewise is moveresize uses the event. */
1987 if (actions_interactive_input_event(e
) || moveresize_event(e
))
1990 if (moveresize_in_progress
)
1991 /* make further actions work on the client being
1993 client
= moveresize_client
;
1995 if (e
->type
== ButtonPress
||
1996 e
->type
== ButtonRelease
||
1997 e
->type
== MotionNotify
)
1999 /* the frame may not be "visible" but they can still click on it
2000 in the case where it is animating before disappearing */
2001 if (!client
|| !frame_iconify_animating(client
->frame
))
2002 return mouse_event(client
, e
);
2004 return keyboard_event((focus_cycle_target
? focus_cycle_target
:
2005 (client
? client
: focus_client
)), e
);
2010 static void focus_delay_dest(gpointer data
)
2012 g_slice_free(ObFocusDelayData
, data
);
2015 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
2017 const ObFocusDelayData
*f1
= d1
;
2018 return f1
->client
== d2
;
2021 static gboolean
focus_delay_func(gpointer data
)
2023 ObFocusDelayData
*d
= data
;
2024 Time old
= event_curtime
;
2026 event_curtime
= d
->time
;
2027 event_curserial
= d
->serial
;
2028 if (client_focus(d
->client
) && config_focus_raise
)
2029 stacking_raise(CLIENT_AS_WINDOW(d
->client
));
2030 event_curtime
= old
;
2031 return FALSE
; /* no repeat */
2034 static gboolean
unfocus_delay_func(gpointer data
)
2036 ObFocusDelayData
*d
= data
;
2037 Time old
= event_curtime
;
2039 event_curtime
= d
->time
;
2040 event_curserial
= d
->serial
;
2042 event_curtime
= old
;
2043 return FALSE
; /* no repeat */
2046 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
2048 obt_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
2050 obt_main_loop_timeout_remove_data(ob_main_loop
, unfocus_delay_func
,
2054 void event_halt_focus_delay(void)
2056 /* ignore all enter events up till the event which caused this to occur */
2057 if (event_curserial
) event_ignore_enter_range(1, event_curserial
);
2058 obt_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
2059 obt_main_loop_timeout_remove(ob_main_loop
, unfocus_delay_func
);
2062 gulong
event_start_ignore_all_enters(void)
2064 return NextRequest(obt_display
);
2067 static void event_ignore_enter_range(gulong start
, gulong end
)
2071 g_assert(start
!= 0);
2074 r
= g_slice_new(ObSerialRange
);
2077 ignore_serials
= g_slist_prepend(ignore_serials
, r
);
2079 ob_debug_type(OB_DEBUG_FOCUS
, "ignoring enters from %lu until %lu",
2082 /* increment the serial so we don't ignore events we weren't meant to */
2083 OBT_PROP_ERASE(screen_support_win
, MOTIF_WM_HINTS
);
2086 void event_end_ignore_all_enters(gulong start
)
2088 /* Use (NextRequest-1) so that we ignore up to the current serial only.
2089 Inside event_ignore_enter_range, we increment the serial by one, but if
2090 we ignore that serial too, then any enter events generated by mouse
2091 movement will be ignored until we create some further network traffic.
2092 Instead ignore up to NextRequest-1, then when we increment the serial,
2093 we will be *past* the range of ignored serials */
2094 event_ignore_enter_range(start
, NextRequest(obt_display
)-1);
2097 static gboolean
is_enter_focus_event_ignored(gulong serial
)
2101 for (it
= ignore_serials
; it
; it
= next
) {
2102 ObSerialRange
*r
= it
->data
;
2104 next
= g_slist_next(it
);
2106 if ((glong
)(serial
- r
->end
) > 0) {
2108 ignore_serials
= g_slist_delete_link(ignore_serials
, it
);
2109 g_slice_free(ObSerialRange
, r
);
2111 else if ((glong
)(serial
- r
->start
) >= 0)
2117 void event_cancel_all_key_grabs(void)
2119 if (actions_interactive_act_running()) {
2120 actions_interactive_cancel_act();
2121 ob_debug("KILLED interactive action");
2123 else if (menu_frame_visible
) {
2124 menu_frame_hide_all();
2125 ob_debug("KILLED open menus");
2127 else if (moveresize_in_progress
) {
2128 moveresize_end(TRUE
);
2129 ob_debug("KILLED interactive moveresize");
2131 else if (grab_on_keyboard()) {
2133 ob_debug("KILLED active grab on keyboard");
2136 ungrab_passive_key();
2138 XSync(obt_display
, FALSE
);
2141 gboolean
event_time_after(guint32 t1
, guint32 t2
)
2143 g_assert(t1
!= CurrentTime
);
2144 g_assert(t2
!= CurrentTime
);
2147 Timestamp values wrap around (after about 49.7 days). The server, given
2148 its current time is represented by timestamp T, always interprets
2149 timestamps from clients by treating half of the timestamp space as being
2150 later in time than T.
2151 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
2154 /* TIME_HALF is not half of the number space of a Time type variable.
2155 * Rather, it is half the number space of a timestamp value, which is
2156 * always 32 bits. */
2157 #define TIME_HALF (guint32)(1 << 31)
2159 if (t2
>= TIME_HALF
)
2160 /* t2 is in the second half so t1 might wrap around and be smaller than
2162 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
2164 /* t2 is in the first half so t1 has to come after it */
2165 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);
2168 Time
event_get_server_time(void)
2170 /* Generate a timestamp */
2173 XChangeProperty(obt_display
, screen_support_win
,
2174 OBT_PROP_ATOM(WM_CLASS
), OBT_PROP_ATOM(STRING
),
2175 8, PropModeAppend
, NULL
, 0);
2176 XWindowEvent(obt_display
, screen_support_win
, PropertyChangeMask
, &event
);
2177 return event
.xproperty
.time
;