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.
34 #include "menuframe.h"
40 #include "focus_cycle.h"
41 #include "moveresize.h"
44 #include "extensions.h"
45 #include "translate.h"
49 #include <X11/Xatom.h>
52 #ifdef HAVE_SYS_SELECT_H
53 # include <sys/select.h>
59 # include <unistd.h> /* for usleep() */
62 # include <X11/XKBlib.h>
66 #include <X11/ICE/ICElib.h>
83 gulong start
; /* inclusive */
84 gulong end
; /* inclusive */
87 static void event_process(const XEvent
*e
, gpointer data
);
88 static void event_handle_root(XEvent
*e
);
89 static gboolean
event_handle_menu_keyboard(XEvent
*e
);
90 static gboolean
event_handle_menu(XEvent
*e
);
91 static void event_handle_dock(ObDock
*s
, XEvent
*e
);
92 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
);
93 static void event_handle_client(ObClient
*c
, XEvent
*e
);
94 static void event_handle_user_input(ObClient
*client
, XEvent
*e
);
95 static gboolean
is_enter_focus_event_ignored(XEvent
*e
);
96 static void event_ignore_enter_range(gulong start
, gulong end
);
98 static void focus_delay_dest(gpointer data
);
99 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
);
100 static gboolean
focus_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 ob_main_loop_fd_add(ob_main_loop
, fd
, ice_handler
, conn
, NULL
);
128 ob_main_loop_fd_remove(ob_main_loop
, fd
);
134 void event_startup(gboolean reconfig
)
136 if (reconfig
) return;
138 ob_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
= RootWindow(ob_display
, ob_screen
);
168 window
= e
->xmap
.window
;
171 window
= e
->xunmap
.window
;
174 window
= e
->xdestroywindow
.window
;
176 case ConfigureRequest
:
177 window
= e
->xconfigurerequest
.window
;
179 case ConfigureNotify
:
180 window
= e
->xconfigure
.window
;
184 if (extensions_xkb
&& e
->type
== extensions_xkb_event_basep
) {
185 switch (((XkbAnyEvent
*)e
)->xkb_type
) {
187 window
= ((XkbBellNotifyEvent
*)e
)->window
;
194 if (extensions_sync
&&
195 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
200 window
= e
->xany
.window
;
205 static void event_set_curtime(XEvent
*e
)
207 Time t
= CurrentTime
;
209 /* grab the lasttime and hack up the state */
225 t
= e
->xproperty
.time
;
229 t
= e
->xcrossing
.time
;
233 if (extensions_sync
&&
234 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
236 t
= ((XSyncAlarmNotifyEvent
*)e
)->time
;
239 /* if more event types are anticipated, get their timestamp
244 /* watch that if we get an event earlier than the last specified user_time,
245 which can happen if the clock goes backwards, we erase the last
246 specified user_time */
247 if (t
&& event_last_user_time
&& event_time_after(event_last_user_time
, t
))
248 event_last_user_time
= CurrentTime
;
253 static void event_hack_mods(XEvent
*e
)
256 XkbStateRec xkb_state
;
262 e
->xbutton
.state
= modkeys_only_modifier_masks(e
->xbutton
.state
);
265 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
269 /* If XKB is present, then the modifiers are all strange from its
270 magic. Our X core protocol stuff won't work, so we use this to
271 find what the modifier state is instead. */
272 if (XkbGetState(ob_display
, XkbUseCoreKbd
, &xkb_state
) == Success
)
273 e
->xkey
.state
= xkb_state
.compat_state
;
277 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
278 /* remove from the state the mask of the modifier key being
279 released, if it is a modifier key being released that is */
280 e
->xkey
.state
&= ~modkeys_keycode_to_mask(e
->xkey
.keycode
);
284 e
->xmotion
.state
= modkeys_only_modifier_masks(e
->xmotion
.state
);
285 /* compress events */
288 while (XCheckTypedWindowEvent(ob_display
, e
->xmotion
.window
,
290 e
->xmotion
.x
= ce
.xmotion
.x
;
291 e
->xmotion
.y
= ce
.xmotion
.y
;
292 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
293 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
300 static gboolean
wanted_focusevent(XEvent
*e
, gboolean in_client_only
)
302 gint mode
= e
->xfocus
.mode
;
303 gint detail
= e
->xfocus
.detail
;
304 Window win
= e
->xany
.window
;
306 if (e
->type
== FocusIn
) {
307 /* These are ones we never want.. */
309 /* This means focus was given by a keyboard/mouse grab. */
310 if (mode
== NotifyGrab
)
312 /* This means focus was given back from a keyboard/mouse grab. */
313 if (mode
== NotifyUngrab
)
316 /* These are the ones we want.. */
318 if (win
== RootWindow(ob_display
, ob_screen
)) {
319 /* If looking for a focus in on a client, then always return
320 FALSE for focus in's to the root window */
323 /* This means focus reverted off of a client */
324 else if (detail
== NotifyPointerRoot
||
325 detail
== NotifyDetailNone
||
326 detail
== NotifyInferior
||
327 /* This means focus got here from another screen */
328 detail
== NotifyNonlinear
)
334 /* It was on a client, was it a valid one?
335 It's possible to get a FocusIn event for a client that was managed
338 if (in_client_only
) {
339 ObWindow
*w
= g_hash_table_lookup(window_map
, &e
->xfocus
.window
);
340 if (!w
|| !WINDOW_IS_CLIENT(w
))
344 /* This means focus reverted to parent from the client (this
345 happens often during iconify animation) */
346 if (detail
== NotifyInferior
)
350 /* This means focus moved from the root window to a client */
351 if (detail
== NotifyVirtual
)
353 /* This means focus moved from one client to another */
354 if (detail
== NotifyNonlinearVirtual
)
360 g_assert(e
->type
== FocusOut
);
362 /* These are ones we never want.. */
364 /* This means focus was taken by a keyboard/mouse grab. */
365 if (mode
== NotifyGrab
)
367 /* This means focus was grabbed on a window and it was released. */
368 if (mode
== NotifyUngrab
)
371 /* Focus left the root window revertedto state */
372 if (win
== RootWindow(ob_display
, ob_screen
))
375 /* These are the ones we want.. */
377 /* This means focus moved from a client to the root window */
378 if (detail
== NotifyVirtual
)
380 /* This means focus moved from one client to another */
381 if (detail
== NotifyNonlinearVirtual
)
389 static Bool
event_look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
391 return e
->type
== FocusIn
&& wanted_focusevent(e
, FALSE
);
394 static Bool
event_look_for_focusin_client(Display
*d
, XEvent
*e
, XPointer arg
)
396 return e
->type
== FocusIn
&& wanted_focusevent(e
, TRUE
);
399 static void print_focusevent(XEvent
*e
)
401 gint mode
= e
->xfocus
.mode
;
402 gint detail
= e
->xfocus
.detail
;
403 Window win
= e
->xany
.window
;
404 const gchar
*modestr
, *detailstr
;
407 case NotifyNormal
: modestr
="NotifyNormal"; break;
408 case NotifyGrab
: modestr
="NotifyGrab"; break;
409 case NotifyUngrab
: modestr
="NotifyUngrab"; break;
410 case NotifyWhileGrabbed
: modestr
="NotifyWhileGrabbed"; break;
413 case NotifyAncestor
: detailstr
="NotifyAncestor"; break;
414 case NotifyVirtual
: detailstr
="NotifyVirtual"; break;
415 case NotifyInferior
: detailstr
="NotifyInferior"; break;
416 case NotifyNonlinear
: detailstr
="NotifyNonlinear"; break;
417 case NotifyNonlinearVirtual
: detailstr
="NotifyNonlinearVirtual"; break;
418 case NotifyPointer
: detailstr
="NotifyPointer"; break;
419 case NotifyPointerRoot
: detailstr
="NotifyPointerRoot"; break;
420 case NotifyDetailNone
: detailstr
="NotifyDetailNone"; break;
423 if (mode
== NotifyGrab
|| mode
== NotifyUngrab
)
428 ob_debug_type(OB_DEBUG_FOCUS
, "Focus%s 0x%x mode=%s detail=%s\n",
429 (e
->xfocus
.type
== FocusIn
? "In" : "Out"),
435 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
440 if (!wanted_focusevent(e
, FALSE
))
445 if (!wanted_focusevent(e
, FALSE
))
452 static void event_process(const XEvent
*ec
, gpointer data
)
455 ObClient
*client
= NULL
;
457 ObDockApp
*dockapp
= NULL
;
458 ObWindow
*obwin
= NULL
;
460 ObEventData
*ed
= data
;
462 /* make a copy we can mangle */
466 window
= event_get_window(e
);
467 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
468 switch (obwin
->type
) {
470 dock
= WINDOW_AS_DOCK(obwin
);
473 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
476 client
= WINDOW_AS_CLIENT(obwin
);
479 /* not to be used for events */
480 g_assert_not_reached();
482 case Window_Internal
:
483 /* we don't do anything with events directly on these windows */
488 event_set_curtime(e
);
489 event_curserial
= e
->xany
.serial
;
491 if (event_ignore(e
, client
)) {
498 /* deal with it in the kernel */
500 if (menu_frame_visible
&&
501 (e
->type
== EnterNotify
|| e
->type
== LeaveNotify
))
503 /* crossing events for menu */
504 event_handle_menu(e
);
505 } else if (e
->type
== FocusIn
) {
507 e
->xfocus
.detail
== NotifyInferior
)
509 ob_debug_type(OB_DEBUG_FOCUS
,
510 "Focus went to the frame window");
512 focus_left_screen
= FALSE
;
514 focus_fallback(FALSE
, config_focus_under_mouse
, TRUE
, TRUE
);
516 /* We don't get a FocusOut for this case, because it's just moving
517 from our Inferior up to us. This happens when iconifying a
518 window with RevertToParent focus */
519 frame_adjust_focus(client
->frame
, FALSE
);
520 /* focus_set_client(NULL) has already been called */
521 client_calc_layer(client
);
523 else if (e
->xfocus
.detail
== NotifyPointerRoot
||
524 e
->xfocus
.detail
== NotifyDetailNone
||
525 e
->xfocus
.detail
== NotifyInferior
||
526 e
->xfocus
.detail
== NotifyNonlinear
)
530 ob_debug_type(OB_DEBUG_FOCUS
,
531 "Focus went to root or pointer root/none\n");
533 if (e
->xfocus
.detail
== NotifyInferior
||
534 e
->xfocus
.detail
== NotifyNonlinear
)
536 focus_left_screen
= FALSE
;
539 /* If another FocusIn is in the queue then don't fallback yet. This
540 fixes the fun case of:
541 window map -> send focusin
542 window unmap -> get focusout
543 window map -> send focusin
544 get first focus out -> fall back to something (new window
545 hasn't received focus yet, so something else) -> send focusin
546 which means the "something else" is the last thing to get a
547 focusin sent to it, so the new window doesn't end up with focus.
549 But if the other focus in is something like PointerRoot then we
550 still want to fall back.
552 if (XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin_client
,
555 XPutBackEvent(ob_display
, &ce
);
556 ob_debug_type(OB_DEBUG_FOCUS
,
557 " but another FocusIn is coming\n");
559 /* Focus has been reverted.
561 FocusOut events come after UnmapNotify, so we don't need to
562 worry about focusing an invalid window
565 if (!focus_left_screen
)
566 focus_fallback(FALSE
, config_focus_under_mouse
,
572 ob_debug_type(OB_DEBUG_FOCUS
,
573 "Focus went to a window that is already gone\n");
575 /* If you send focus to a window and then it disappears, you can
576 get the FocusIn for it, after it is unmanaged.
577 Just wait for the next FocusOut/FocusIn pair, but make note that
578 the window that was focused no longer is. */
579 focus_set_client(NULL
);
581 else if (client
!= focus_client
) {
582 focus_left_screen
= FALSE
;
583 frame_adjust_focus(client
->frame
, TRUE
);
584 focus_set_client(client
);
585 client_calc_layer(client
);
586 client_bring_helper_windows(client
);
588 } else if (e
->type
== FocusOut
) {
591 /* Look for the followup FocusIn */
592 if (!XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin
, NULL
)) {
593 /* There is no FocusIn, this means focus went to a window that
594 is not being managed, or a window on another screen. */
598 xerror_set_ignore(TRUE
);
599 if (XGetInputFocus(ob_display
, &win
, &i
) != 0 &&
600 XGetGeometry(ob_display
, win
, &root
, &i
,&i
,&u
,&u
,&u
,&u
) != 0 &&
601 root
!= RootWindow(ob_display
, ob_screen
))
603 ob_debug_type(OB_DEBUG_FOCUS
,
604 "Focus went to another screen !\n");
605 focus_left_screen
= TRUE
;
608 ob_debug_type(OB_DEBUG_FOCUS
,
609 "Focus went to a black hole !\n");
610 xerror_set_ignore(FALSE
);
611 /* nothing is focused */
612 focus_set_client(NULL
);
614 /* Focus moved, so process the FocusIn event */
615 ObEventData ed
= { .ignored
= FALSE
};
616 event_process(&ce
, &ed
);
618 /* The FocusIn was ignored, this means it was on a window
619 that isn't a client. */
620 ob_debug_type(OB_DEBUG_FOCUS
,
621 "Focus went to an unmanaged window 0x%x !\n",
623 focus_fallback(TRUE
, config_focus_under_mouse
, TRUE
, TRUE
);
627 if (client
&& client
!= focus_client
) {
628 frame_adjust_focus(client
->frame
, FALSE
);
629 /* focus_set_client(NULL) has already been called in this
630 section or by focus_fallback */
631 client_calc_layer(client
);
635 event_handle_client(client
, e
);
637 event_handle_dockapp(dockapp
, e
);
639 event_handle_dock(dock
, e
);
640 else if (window
== RootWindow(ob_display
, ob_screen
))
641 event_handle_root(e
);
642 else if (e
->type
== MapRequest
)
643 client_manage(window
);
644 else if (e
->type
== MappingNotify
) {
645 /* keyboard layout changes for modifier mapping changes. reload the
646 modifier map, and rebind all the key bindings as appropriate */
647 ob_debug("Kepboard map changed. Reloading keyboard bindings.\n");
648 modkeys_shutdown(TRUE
);
649 modkeys_startup(TRUE
);
652 else if (e
->type
== ClientMessage
) {
653 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
654 windows that are not managed yet. */
655 if (e
->xclient
.message_type
== prop_atoms
.net_request_frame_extents
) {
656 /* Pretend to manage the client, getting information used to
657 determine its decorations */
658 ObClient
*c
= client_fake_manage(e
->xclient
.window
);
661 /* set the frame extents on the window */
662 vals
[0] = c
->frame
->size
.left
;
663 vals
[1] = c
->frame
->size
.right
;
664 vals
[2] = c
->frame
->size
.top
;
665 vals
[3] = c
->frame
->size
.bottom
;
666 PROP_SETA32(e
->xclient
.window
, net_frame_extents
,
669 /* Free the pretend client */
670 client_fake_unmanage(c
);
673 else if (e
->type
== ConfigureRequest
) {
674 /* unhandled configure requests must be used to configure the
678 xwc
.x
= e
->xconfigurerequest
.x
;
679 xwc
.y
= e
->xconfigurerequest
.y
;
680 xwc
.width
= e
->xconfigurerequest
.width
;
681 xwc
.height
= e
->xconfigurerequest
.height
;
682 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
683 xwc
.sibling
= e
->xconfigurerequest
.above
;
684 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
686 /* we are not to be held responsible if someone sends us an
688 xerror_set_ignore(TRUE
);
689 XConfigureWindow(ob_display
, window
,
690 e
->xconfigurerequest
.value_mask
, &xwc
);
691 xerror_set_ignore(FALSE
);
694 else if (extensions_sync
&&
695 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
697 XSyncAlarmNotifyEvent
*se
= (XSyncAlarmNotifyEvent
*)e
;
698 if (se
->alarm
== moveresize_alarm
&& moveresize_in_progress
)
703 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
) {
704 /* If the button press was on some non-root window, or was physically
705 on the root window, the process it */
706 if (window
!= RootWindow(ob_display
, ob_screen
) ||
707 e
->xbutton
.subwindow
== None
)
709 event_handle_user_input(client
, e
);
711 /* Otherwise only process it if it was physically on an openbox
716 if ((w
= g_hash_table_lookup(window_map
, &e
->xbutton
.subwindow
)) &&
717 WINDOW_IS_INTERNAL(w
))
719 event_handle_user_input(client
, e
);
723 else if (e
->type
== KeyPress
|| e
->type
== KeyRelease
||
724 e
->type
== MotionNotify
)
725 event_handle_user_input(client
, e
);
727 /* if something happens and it's not from an XEvent, then we don't know
729 event_curtime
= CurrentTime
;
733 static void event_handle_root(XEvent
*e
)
739 ob_debug("Another WM has requested to replace us. Exiting.\n");
744 if (e
->xclient
.format
!= 32) break;
746 msgtype
= e
->xclient
.message_type
;
747 if (msgtype
== prop_atoms
.net_current_desktop
) {
748 guint d
= e
->xclient
.data
.l
[0];
749 if (d
< screen_num_desktops
) {
750 event_curtime
= e
->xclient
.data
.l
[1];
751 if (event_curtime
== 0)
752 ob_debug_type(OB_DEBUG_APP_BUGS
,
753 "_NET_CURRENT_DESKTOP message is missing "
755 screen_set_desktop(d
, TRUE
);
757 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
758 guint d
= e
->xclient
.data
.l
[0];
759 if (d
> 0 && d
<= 1000)
760 screen_set_num_desktops(d
);
761 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
762 screen_show_desktop(e
->xclient
.data
.l
[0] != 0, NULL
);
763 } else if (msgtype
== prop_atoms
.ob_control
) {
764 ob_debug("OB_CONTROL: %d\n", e
->xclient
.data
.l
[0]);
765 if (e
->xclient
.data
.l
[0] == 1)
767 else if (e
->xclient
.data
.l
[0] == 2)
769 else if (e
->xclient
.data
.l
[0] == 3)
771 } else if (msgtype
== prop_atoms
.wm_protocols
) {
772 if (e
->xclient
.data
.l
[0] == prop_atoms
.net_wm_ping
)
773 ping_got_pong(e
->xclient
.data
.l
[1]);
777 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
) {
778 ob_debug("UPDATE DESKTOP NAMES\n");
779 screen_update_desktop_names();
781 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
782 screen_update_layout();
784 case ConfigureNotify
:
786 XRRUpdateConfiguration(e
);
795 void event_enter_client(ObClient
*client
)
797 g_assert(config_focus_follow
);
799 if (client_enter_focusable(client
) && client_can_focus(client
)) {
800 if (config_focus_delay
) {
801 ObFocusDelayData
*data
;
803 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
805 data
= g_new(ObFocusDelayData
, 1);
806 data
->client
= client
;
807 data
->time
= event_curtime
;
808 data
->serial
= event_curserial
;
810 ob_main_loop_timeout_add(ob_main_loop
,
811 config_focus_delay
* 1000,
813 data
, focus_delay_cmp
, focus_delay_dest
);
815 ObFocusDelayData data
;
816 data
.client
= client
;
817 data
.time
= event_curtime
;
818 data
.serial
= event_curserial
;
819 focus_delay_func(&data
);
824 static void event_handle_client(ObClient
*client
, XEvent
*e
)
829 static gint px
= -1, py
= -1;
834 /* save where the press occured for the first button pressed */
836 pb
= e
->xbutton
.button
;
841 /* Wheel buttons don't draw because they are an instant click, so it
842 is a waste of resources to go drawing it.
843 if the user is doing an intereactive thing, or has a menu open then
844 the mouse is grabbed (possibly) and if we get these events we don't
845 want to deal with them
847 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5) &&
850 /* use where the press occured */
851 con
= frame_context(client
, e
->xbutton
.window
, px
, py
);
852 con
= mouse_button_frame_context(con
, e
->xbutton
.button
,
855 if (e
->type
== ButtonRelease
&& e
->xbutton
.button
== pb
)
856 pb
= 0, px
= py
= -1;
859 case OB_FRAME_CONTEXT_MAXIMIZE
:
860 client
->frame
->max_press
= (e
->type
== ButtonPress
);
861 frame_adjust_state(client
->frame
);
863 case OB_FRAME_CONTEXT_CLOSE
:
864 client
->frame
->close_press
= (e
->type
== ButtonPress
);
865 frame_adjust_state(client
->frame
);
867 case OB_FRAME_CONTEXT_ICONIFY
:
868 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
869 frame_adjust_state(client
->frame
);
871 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
872 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
873 frame_adjust_state(client
->frame
);
875 case OB_FRAME_CONTEXT_SHADE
:
876 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
877 frame_adjust_state(client
->frame
);
880 /* nothing changes with clicks for any other contexts */
886 /* when there is a grab on the pointer, we won't get enter/leave
887 notifies, but we still get motion events */
888 if (grab_on_pointer()) break;
890 con
= frame_context(client
, e
->xmotion
.window
,
891 e
->xmotion
.x
, e
->xmotion
.y
);
893 case OB_FRAME_CONTEXT_TITLEBAR
:
894 case OB_FRAME_CONTEXT_TLCORNER
:
895 case OB_FRAME_CONTEXT_TRCORNER
:
896 /* we've left the button area inside the titlebar */
897 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
898 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
899 client
->frame
->close_hover
)
901 client
->frame
->max_hover
= FALSE
;
902 client
->frame
->desk_hover
= FALSE
;
903 client
->frame
->shade_hover
= FALSE
;
904 client
->frame
->iconify_hover
= FALSE
;
905 client
->frame
->close_hover
= FALSE
;
906 frame_adjust_state(client
->frame
);
909 case OB_FRAME_CONTEXT_MAXIMIZE
:
910 if (!client
->frame
->max_hover
) {
911 client
->frame
->max_hover
= TRUE
;
912 frame_adjust_state(client
->frame
);
915 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
916 if (!client
->frame
->desk_hover
) {
917 client
->frame
->desk_hover
= TRUE
;
918 frame_adjust_state(client
->frame
);
921 case OB_FRAME_CONTEXT_SHADE
:
922 if (!client
->frame
->shade_hover
) {
923 client
->frame
->shade_hover
= TRUE
;
924 frame_adjust_state(client
->frame
);
927 case OB_FRAME_CONTEXT_ICONIFY
:
928 if (!client
->frame
->iconify_hover
) {
929 client
->frame
->iconify_hover
= TRUE
;
930 frame_adjust_state(client
->frame
);
933 case OB_FRAME_CONTEXT_CLOSE
:
934 if (!client
->frame
->close_hover
) {
935 client
->frame
->close_hover
= TRUE
;
936 frame_adjust_state(client
->frame
);
944 con
= frame_context(client
, e
->xcrossing
.window
,
945 e
->xcrossing
.x
, e
->xcrossing
.y
);
947 case OB_FRAME_CONTEXT_TITLEBAR
:
948 case OB_FRAME_CONTEXT_TLCORNER
:
949 case OB_FRAME_CONTEXT_TRCORNER
:
950 /* we've left the button area inside the titlebar */
951 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
952 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
953 client
->frame
->close_hover
)
955 client
->frame
->max_hover
= FALSE
;
956 client
->frame
->desk_hover
= FALSE
;
957 client
->frame
->shade_hover
= FALSE
;
958 client
->frame
->iconify_hover
= FALSE
;
959 client
->frame
->close_hover
= FALSE
;
960 frame_adjust_state(client
->frame
);
963 case OB_FRAME_CONTEXT_MAXIMIZE
:
964 client
->frame
->max_hover
= FALSE
;
965 frame_adjust_state(client
->frame
);
967 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
968 client
->frame
->desk_hover
= FALSE
;
969 frame_adjust_state(client
->frame
);
971 case OB_FRAME_CONTEXT_SHADE
:
972 client
->frame
->shade_hover
= FALSE
;
973 frame_adjust_state(client
->frame
);
975 case OB_FRAME_CONTEXT_ICONIFY
:
976 client
->frame
->iconify_hover
= FALSE
;
977 frame_adjust_state(client
->frame
);
979 case OB_FRAME_CONTEXT_CLOSE
:
980 client
->frame
->close_hover
= FALSE
;
981 frame_adjust_state(client
->frame
);
983 case OB_FRAME_CONTEXT_FRAME
:
984 /* When the mouse leaves an animating window, don't use the
985 corresponding enter events. Pretend like the animating window
986 doesn't even exist..! */
987 if (frame_iconify_animating(client
->frame
))
988 event_end_ignore_all_enters(event_start_ignore_all_enters());
990 ob_debug_type(OB_DEBUG_FOCUS
,
991 "%sNotify mode %d detail %d on %lx\n",
992 (e
->type
== EnterNotify
? "Enter" : "Leave"),
994 e
->xcrossing
.detail
, (client
?client
->window
:0));
995 if (grab_on_keyboard())
997 if (config_focus_follow
&& config_focus_delay
&&
998 /* leave inferior events can happen when the mouse goes onto
999 the window's border and then into the window before the
1001 e
->xcrossing
.detail
!= NotifyInferior
)
1003 ob_main_loop_timeout_remove_data(ob_main_loop
,
1014 con
= frame_context(client
, e
->xcrossing
.window
,
1015 e
->xcrossing
.x
, e
->xcrossing
.y
);
1017 case OB_FRAME_CONTEXT_MAXIMIZE
:
1018 client
->frame
->max_hover
= TRUE
;
1019 frame_adjust_state(client
->frame
);
1021 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
1022 client
->frame
->desk_hover
= TRUE
;
1023 frame_adjust_state(client
->frame
);
1025 case OB_FRAME_CONTEXT_SHADE
:
1026 client
->frame
->shade_hover
= TRUE
;
1027 frame_adjust_state(client
->frame
);
1029 case OB_FRAME_CONTEXT_ICONIFY
:
1030 client
->frame
->iconify_hover
= TRUE
;
1031 frame_adjust_state(client
->frame
);
1033 case OB_FRAME_CONTEXT_CLOSE
:
1034 client
->frame
->close_hover
= TRUE
;
1035 frame_adjust_state(client
->frame
);
1037 case OB_FRAME_CONTEXT_FRAME
:
1038 if (grab_on_keyboard())
1040 if (e
->xcrossing
.mode
== NotifyGrab
||
1041 e
->xcrossing
.mode
== NotifyUngrab
||
1042 /*ignore enters when we're already in the window */
1043 e
->xcrossing
.detail
== NotifyInferior
||
1044 is_enter_focus_event_ignored(e
))
1046 ob_debug_type(OB_DEBUG_FOCUS
,
1047 "%sNotify mode %d detail %d serial %lu on %lx "
1049 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1051 e
->xcrossing
.detail
,
1052 e
->xcrossing
.serial
,
1053 client
?client
->window
:0);
1056 ob_debug_type(OB_DEBUG_FOCUS
,
1057 "%sNotify mode %d detail %d serial %lu on %lx, "
1058 "focusing window\n",
1059 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1061 e
->xcrossing
.detail
,
1062 e
->xcrossing
.serial
,
1063 (client
?client
->window
:0));
1064 if (config_focus_follow
)
1065 event_enter_client(client
);
1073 case ConfigureRequest
:
1075 /* dont compress these unless you're going to watch for property
1076 notifies in between (these can change what the configure would
1078 also you can't compress stacking events
1082 gboolean move
= FALSE
;
1083 gboolean resize
= FALSE
;
1085 /* get the current area */
1086 RECT_TO_DIMS(client
->area
, x
, y
, w
, h
);
1088 ob_debug("ConfigureRequest for \"%s\" desktop %d wmstate %d "
1090 " x %d y %d w %d h %d b %d\n",
1092 screen_desktop
, client
->wmstate
, client
->frame
->visible
,
1093 x
, y
, w
, h
, client
->border_width
);
1095 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
1096 if (client
->border_width
!= e
->xconfigurerequest
.border_width
) {
1097 client
->border_width
= e
->xconfigurerequest
.border_width
;
1099 /* if the border width is changing then that is the same
1100 as requesting a resize, but we don't actually change
1101 the client's border, so it will change their root
1102 coordiantes (since they include the border width) and
1103 we need to a notify then */
1108 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
1109 ObClient
*sibling
= NULL
;
1110 gulong ignore_start
;
1113 /* get the sibling */
1114 if (e
->xconfigurerequest
.value_mask
& CWSibling
) {
1116 win
= g_hash_table_lookup(window_map
,
1117 &e
->xconfigurerequest
.above
);
1118 if (win
&& WINDOW_IS_CLIENT(win
) &&
1119 WINDOW_AS_CLIENT(win
) != client
)
1121 sibling
= WINDOW_AS_CLIENT(win
);
1124 /* an invalid sibling was specified so don't restack at
1125 all, it won't make sense no matter what we do */
1130 if (!config_focus_under_mouse
)
1131 ignore_start
= event_start_ignore_all_enters();
1132 stacking_restack_request(client
, sibling
,
1133 e
->xconfigurerequest
.detail
);
1134 if (!config_focus_under_mouse
)
1135 event_end_ignore_all_enters(ignore_start
);
1138 /* a stacking change moves the window without resizing */
1142 if ((e
->xconfigurerequest
.value_mask
& CWX
) ||
1143 (e
->xconfigurerequest
.value_mask
& CWY
) ||
1144 (e
->xconfigurerequest
.value_mask
& CWWidth
) ||
1145 (e
->xconfigurerequest
.value_mask
& CWHeight
))
1147 if (e
->xconfigurerequest
.value_mask
& CWX
) {
1148 /* don't allow clients to move shaded windows (fvwm does this)
1150 if (!client
->shaded
)
1151 x
= e
->xconfigurerequest
.x
;
1154 if (e
->xconfigurerequest
.value_mask
& CWY
) {
1155 /* don't allow clients to move shaded windows (fvwm does this)
1157 if (!client
->shaded
)
1158 y
= e
->xconfigurerequest
.y
;
1162 if (e
->xconfigurerequest
.value_mask
& CWWidth
) {
1163 w
= e
->xconfigurerequest
.width
;
1166 if (e
->xconfigurerequest
.value_mask
& CWHeight
) {
1167 h
= e
->xconfigurerequest
.height
;
1172 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
1173 "move %d resize %d\n",
1174 e
->xconfigurerequest
.value_mask
& CWX
, x
,
1175 e
->xconfigurerequest
.value_mask
& CWY
, y
,
1176 e
->xconfigurerequest
.value_mask
& CWWidth
, w
,
1177 e
->xconfigurerequest
.value_mask
& CWHeight
, h
,
1180 /* check for broken apps moving to their root position
1182 XXX remove this some day...that would be nice. right now all
1183 kde apps do this when they try activate themselves on another
1184 desktop. eg. open amarok window on desktop 1, switch to desktop
1185 2, click amarok tray icon. it will move by its decoration size.
1187 if (x
!= client
->area
.x
&&
1188 x
== (client
->frame
->area
.x
+ client
->frame
->size
.left
-
1189 (gint
)client
->border_width
) &&
1190 y
!= client
->area
.y
&&
1191 y
== (client
->frame
->area
.y
+ client
->frame
->size
.top
-
1192 (gint
)client
->border_width
) &&
1193 w
== client
->area
.width
&&
1194 h
== client
->area
.height
)
1196 ob_debug_type(OB_DEBUG_APP_BUGS
,
1197 "Application %s is trying to move via "
1198 "ConfigureRequest to it's root window position "
1199 "but it is not using StaticGravity\n",
1205 /* they still requested a move, so don't change whether a
1206 notify is sent or not */
1212 client_try_configure(client
, &x
, &y
, &w
, &h
, &lw
, &lh
, FALSE
);
1214 /* if x was not given, then use gravity to figure out the new
1215 x. the reference point should not be moved */
1216 if ((e
->xconfigurerequest
.value_mask
& CWWidth
&&
1217 !(e
->xconfigurerequest
.value_mask
& CWX
)))
1218 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1219 /* if y was not given, then use gravity to figure out the new
1220 y. the reference point should not be moved */
1221 if ((e
->xconfigurerequest
.value_mask
& CWHeight
&&
1222 !(e
->xconfigurerequest
.value_mask
& CWY
)))
1223 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1225 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1227 ob_debug("Granting ConfigureRequest x %d y %d w %d h %d\n",
1229 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
, TRUE
);
1234 if (client
->ignore_unmaps
) {
1235 client
->ignore_unmaps
--;
1238 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1239 "ignores left %d\n",
1240 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
1241 client
->ignore_unmaps
);
1242 client_unmanage(client
);
1245 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
1246 client_unmanage(client
);
1248 case ReparentNotify
:
1249 /* this is when the client is first taken captive in the frame */
1250 if (e
->xreparent
.parent
== client
->frame
->window
) break;
1253 This event is quite rare and is usually handled in unmapHandler.
1254 However, if the window is unmapped when the reparent event occurs,
1255 the window manager never sees it because an unmap event is not sent
1256 to an already unmapped window.
1259 /* we don't want the reparent event, put it back on the stack for the
1260 X server to deal with after we unmanage the window */
1261 XPutBackEvent(ob_display
, e
);
1263 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
1264 client_unmanage(client
);
1267 ob_debug("MapRequest for 0x%lx\n", client
->window
);
1268 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
1269 does, we don't want it!
1270 it can happen now when the window is on
1271 another desktop, but we still don't
1273 client_activate(client
, FALSE
, TRUE
, TRUE
, TRUE
);
1276 /* validate cuz we query stuff off the client here */
1277 if (!client_validate(client
)) break;
1279 if (e
->xclient
.format
!= 32) return;
1281 msgtype
= e
->xclient
.message_type
;
1282 if (msgtype
== prop_atoms
.wm_change_state
) {
1283 /* compress changes into a single change */
1284 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1286 /* XXX: it would be nice to compress ALL messages of a
1287 type, not just messages in a row without other
1288 message types between. */
1289 if (ce
.xclient
.message_type
!= msgtype
) {
1290 XPutBackEvent(ob_display
, &ce
);
1293 e
->xclient
= ce
.xclient
;
1295 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1296 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
1297 /* compress changes into a single change */
1298 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1300 /* XXX: it would be nice to compress ALL messages of a
1301 type, not just messages in a row without other
1302 message types between. */
1303 if (ce
.xclient
.message_type
!= msgtype
) {
1304 XPutBackEvent(ob_display
, &ce
);
1307 e
->xclient
= ce
.xclient
;
1309 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1310 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1311 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1313 } else if (msgtype
== prop_atoms
.net_wm_state
) {
1314 gulong ignore_start
;
1316 /* can't compress these */
1317 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1318 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1319 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1320 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1321 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1324 /* ignore enter events caused by these like ob actions do */
1325 if (!config_focus_under_mouse
)
1326 ignore_start
= event_start_ignore_all_enters();
1327 client_set_state(client
, e
->xclient
.data
.l
[0],
1328 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1329 if (!config_focus_under_mouse
)
1330 event_end_ignore_all_enters(ignore_start
);
1331 } else if (msgtype
== prop_atoms
.net_close_window
) {
1332 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1333 client_close(client
);
1334 } else if (msgtype
== prop_atoms
.net_active_window
) {
1335 ob_debug("net_active_window for 0x%lx source=%s\n",
1337 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1338 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1339 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1340 /* XXX make use of data.l[2] !? */
1341 if (e
->xclient
.data
.l
[0] == 1 || e
->xclient
.data
.l
[0] == 2) {
1342 /* don't use the user's timestamp for client_focus, cuz if it's
1343 an old broken timestamp (happens all the time) then focus
1344 won't move even though we're trying to move it
1345 event_curtime = e->xclient.data.l[1];*/
1346 if (e
->xclient
.data
.l
[1] == 0)
1347 ob_debug_type(OB_DEBUG_APP_BUGS
,
1348 "_NET_ACTIVE_WINDOW message for window %s is"
1349 " missing a timestamp\n", client
->title
);
1351 ob_debug_type(OB_DEBUG_APP_BUGS
,
1352 "_NET_ACTIVE_WINDOW message for window %s is "
1353 "missing source indication\n");
1354 client_activate(client
, FALSE
, TRUE
, TRUE
,
1355 (e
->xclient
.data
.l
[0] == 0 ||
1356 e
->xclient
.data
.l
[0] == 2));
1357 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1358 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1359 client
->window
, e
->xclient
.data
.l
[2]);
1360 if ((Atom
)e
->xclient
.data
.l
[2] ==
1361 prop_atoms
.net_wm_moveresize_size_topleft
||
1362 (Atom
)e
->xclient
.data
.l
[2] ==
1363 prop_atoms
.net_wm_moveresize_size_top
||
1364 (Atom
)e
->xclient
.data
.l
[2] ==
1365 prop_atoms
.net_wm_moveresize_size_topright
||
1366 (Atom
)e
->xclient
.data
.l
[2] ==
1367 prop_atoms
.net_wm_moveresize_size_right
||
1368 (Atom
)e
->xclient
.data
.l
[2] ==
1369 prop_atoms
.net_wm_moveresize_size_right
||
1370 (Atom
)e
->xclient
.data
.l
[2] ==
1371 prop_atoms
.net_wm_moveresize_size_bottomright
||
1372 (Atom
)e
->xclient
.data
.l
[2] ==
1373 prop_atoms
.net_wm_moveresize_size_bottom
||
1374 (Atom
)e
->xclient
.data
.l
[2] ==
1375 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1376 (Atom
)e
->xclient
.data
.l
[2] ==
1377 prop_atoms
.net_wm_moveresize_size_left
||
1378 (Atom
)e
->xclient
.data
.l
[2] ==
1379 prop_atoms
.net_wm_moveresize_move
||
1380 (Atom
)e
->xclient
.data
.l
[2] ==
1381 prop_atoms
.net_wm_moveresize_size_keyboard
||
1382 (Atom
)e
->xclient
.data
.l
[2] ==
1383 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1385 moveresize_start(client
, e
->xclient
.data
.l
[0],
1386 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1387 e
->xclient
.data
.l
[2]);
1389 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1390 prop_atoms
.net_wm_moveresize_cancel
)
1391 moveresize_end(TRUE
);
1392 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1393 gint ograv
, x
, y
, w
, h
;
1395 ograv
= client
->gravity
;
1397 if (e
->xclient
.data
.l
[0] & 0xff)
1398 client
->gravity
= e
->xclient
.data
.l
[0] & 0xff;
1400 if (e
->xclient
.data
.l
[0] & 1 << 8)
1401 x
= e
->xclient
.data
.l
[1];
1404 if (e
->xclient
.data
.l
[0] & 1 << 9)
1405 y
= e
->xclient
.data
.l
[2];
1409 if (e
->xclient
.data
.l
[0] & 1 << 10) {
1410 w
= e
->xclient
.data
.l
[3];
1412 /* if x was not given, then use gravity to figure out the new
1413 x. the reference point should not be moved */
1414 if (!(e
->xclient
.data
.l
[0] & 1 << 8))
1415 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1418 w
= client
->area
.width
;
1420 if (e
->xclient
.data
.l
[0] & 1 << 11) {
1421 h
= e
->xclient
.data
.l
[4];
1423 /* if y was not given, then use gravity to figure out the new
1424 y. the reference point should not be moved */
1425 if (!(e
->xclient
.data
.l
[0] & 1 << 9))
1426 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1429 h
= client
->area
.height
;
1431 ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)\n",
1432 e
->xclient
.data
.l
[0] & 1 << 8, x
,
1433 e
->xclient
.data
.l
[0] & 1 << 9, y
,
1436 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1438 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
1440 client
->gravity
= ograv
;
1441 } else if (msgtype
== prop_atoms
.net_restack_window
) {
1442 if (e
->xclient
.data
.l
[0] != 2) {
1443 ob_debug_type(OB_DEBUG_APP_BUGS
,
1444 "_NET_RESTACK_WINDOW sent for window %s with "
1445 "invalid source indication %ld\n",
1446 client
->title
, e
->xclient
.data
.l
[0]);
1448 ObClient
*sibling
= NULL
;
1449 if (e
->xclient
.data
.l
[1]) {
1450 ObWindow
*win
= g_hash_table_lookup
1451 (window_map
, &e
->xclient
.data
.l
[1]);
1452 if (WINDOW_IS_CLIENT(win
) &&
1453 WINDOW_AS_CLIENT(win
) != client
)
1455 sibling
= WINDOW_AS_CLIENT(win
);
1457 if (sibling
== NULL
)
1458 ob_debug_type(OB_DEBUG_APP_BUGS
,
1459 "_NET_RESTACK_WINDOW sent for window %s "
1460 "with invalid sibling 0x%x\n",
1461 client
->title
, e
->xclient
.data
.l
[1]);
1463 if (e
->xclient
.data
.l
[2] == Below
||
1464 e
->xclient
.data
.l
[2] == BottomIf
||
1465 e
->xclient
.data
.l
[2] == Above
||
1466 e
->xclient
.data
.l
[2] == TopIf
||
1467 e
->xclient
.data
.l
[2] == Opposite
)
1469 gulong ignore_start
;
1471 if (!config_focus_under_mouse
)
1472 ignore_start
= event_start_ignore_all_enters();
1473 /* just raise, don't activate */
1474 stacking_restack_request(client
, sibling
,
1475 e
->xclient
.data
.l
[2]);
1476 if (!config_focus_under_mouse
)
1477 event_end_ignore_all_enters(ignore_start
);
1479 /* send a synthetic ConfigureNotify, cuz this is supposed
1480 to be like a ConfigureRequest. */
1481 client_reconfigure(client
, TRUE
);
1483 ob_debug_type(OB_DEBUG_APP_BUGS
,
1484 "_NET_RESTACK_WINDOW sent for window %s "
1485 "with invalid detail %d\n",
1486 client
->title
, e
->xclient
.data
.l
[2]);
1490 case PropertyNotify
:
1491 /* validate cuz we query stuff off the client here */
1492 if (!client_validate(client
)) break;
1494 /* compress changes to a single property into a single change */
1495 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1499 /* XXX: it would be nice to compress ALL changes to a property,
1500 not just changes in a row without other props between. */
1502 a
= ce
.xproperty
.atom
;
1503 b
= e
->xproperty
.atom
;
1507 if ((a
== prop_atoms
.net_wm_name
||
1508 a
== prop_atoms
.wm_name
||
1509 a
== prop_atoms
.net_wm_icon_name
||
1510 a
== prop_atoms
.wm_icon_name
)
1512 (b
== prop_atoms
.net_wm_name
||
1513 b
== prop_atoms
.wm_name
||
1514 b
== prop_atoms
.net_wm_icon_name
||
1515 b
== prop_atoms
.wm_icon_name
)) {
1518 if (a
== prop_atoms
.net_wm_icon
&&
1519 b
== prop_atoms
.net_wm_icon
)
1522 XPutBackEvent(ob_display
, &ce
);
1526 msgtype
= e
->xproperty
.atom
;
1527 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1528 ob_debug("Update NORMAL hints\n");
1529 client_update_normal_hints(client
);
1530 /* normal hints can make a window non-resizable */
1531 client_setup_decor_and_functions(client
, FALSE
);
1533 /* make sure the client's sizes are within its bounds, but only
1534 reconfigure the window if it needs to. emacs will update its
1535 normal hints every time it receives a conigurenotify */
1536 client_reconfigure(client
, FALSE
);
1537 } else if (msgtype
== XA_WM_HINTS
) {
1538 client_update_wmhints(client
);
1539 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1540 client_update_transient_for(client
);
1541 client_get_type_and_transientness(client
);
1542 /* type may have changed, so update the layer */
1543 client_calc_layer(client
);
1544 client_setup_decor_and_functions(client
, TRUE
);
1545 } else if (msgtype
== prop_atoms
.net_wm_name
||
1546 msgtype
== prop_atoms
.wm_name
||
1547 msgtype
== prop_atoms
.net_wm_icon_name
||
1548 msgtype
== prop_atoms
.wm_icon_name
) {
1549 client_update_title(client
);
1550 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1551 client_update_protocols(client
);
1552 client_setup_decor_and_functions(client
, TRUE
);
1554 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1555 client_update_strut(client
);
1557 else if (msgtype
== prop_atoms
.net_wm_strut_partial
) {
1558 client_update_strut(client
);
1560 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1561 client_update_icons(client
);
1563 else if (msgtype
== prop_atoms
.net_wm_icon_geometry
) {
1564 client_update_icon_geometry(client
);
1566 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1568 if (client
== focus_client
&&
1569 PROP_GET32(client
->window
, net_wm_user_time
, cardinal
, &t
) &&
1570 t
&& !event_time_after(t
, e
->xproperty
.time
) &&
1571 (!event_last_user_time
||
1572 event_time_after(t
, event_last_user_time
)))
1574 event_last_user_time
= t
;
1578 else if (msgtype
== prop_atoms
.net_wm_sync_request_counter
) {
1579 client_update_sync_request_counter(client
);
1583 case ColormapNotify
:
1584 client_update_colormap(client
, e
->xcolormap
.colormap
);
1589 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1590 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1591 frame_adjust_shape(client
->frame
);
1597 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1601 if (e
->xbutton
.button
== 1)
1602 stacking_raise(DOCK_AS_WINDOW(s
));
1603 else if (e
->xbutton
.button
== 2)
1604 stacking_lower(DOCK_AS_WINDOW(s
));
1610 /* don't hide when moving into a dock app */
1611 if (e
->xcrossing
.detail
!= NotifyInferior
)
1617 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1621 dock_app_drag(app
, &e
->xmotion
);
1624 if (app
->ignore_unmaps
) {
1625 app
->ignore_unmaps
--;
1628 dock_remove(app
, TRUE
);
1631 dock_remove(app
, FALSE
);
1633 case ReparentNotify
:
1634 dock_remove(app
, FALSE
);
1636 case ConfigureNotify
:
1637 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1642 static ObMenuFrame
* find_active_menu(void)
1645 ObMenuFrame
*ret
= NULL
;
1647 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1656 static ObMenuFrame
* find_active_or_last_menu(void)
1658 ObMenuFrame
*ret
= NULL
;
1660 ret
= find_active_menu();
1661 if (!ret
&& menu_frame_visible
)
1662 ret
= menu_frame_visible
->data
;
1666 static gboolean
event_handle_menu_keyboard(XEvent
*ev
)
1668 guint keycode
, state
;
1671 gboolean ret
= FALSE
;
1673 keycode
= ev
->xkey
.keycode
;
1674 state
= ev
->xkey
.state
;
1675 unikey
= translate_unichar(keycode
);
1677 frame
= find_active_or_last_menu();
1679 g_assert_not_reached(); /* there is no active menu */
1681 /* Allow control while going thru the menu */
1682 else if (ev
->type
== KeyPress
&& (state
& ~ControlMask
) == 0) {
1683 frame
->got_press
= TRUE
;
1685 if (keycode
== ob_keycode(OB_KEY_ESCAPE
)) {
1686 menu_frame_hide_all();
1690 else if (keycode
== ob_keycode(OB_KEY_LEFT
)) {
1691 /* Left goes to the parent menu */
1692 menu_frame_select(frame
, NULL
, TRUE
);
1696 else if (keycode
== ob_keycode(OB_KEY_RIGHT
)) {
1697 /* Right goes to the selected submenu */
1698 if (frame
->child
) menu_frame_select_next(frame
->child
);
1702 else if (keycode
== ob_keycode(OB_KEY_UP
)) {
1703 menu_frame_select_previous(frame
);
1707 else if (keycode
== ob_keycode(OB_KEY_DOWN
)) {
1708 menu_frame_select_next(frame
);
1713 /* Use KeyRelease events for running things so that the key release doesn't
1714 get sent to the focused application.
1716 Allow ControlMask only, and don't bother if the menu is empty */
1717 else if (ev
->type
== KeyRelease
&& (state
& ~ControlMask
) == 0 &&
1718 frame
->entries
&& frame
->got_press
)
1720 if (keycode
== ob_keycode(OB_KEY_RETURN
)) {
1721 /* Enter runs the active item or goes into the submenu.
1722 Control-Enter runs it without closing the menu. */
1724 menu_frame_select_next(frame
->child
);
1725 else if (frame
->selected
)
1726 menu_entry_frame_execute(frame
->selected
, state
);
1731 /* keyboard accelerator shortcuts. (if it was a valid key) */
1732 else if (unikey
!= 0) {
1735 ObMenuEntryFrame
*found
= NULL
;
1736 guint num_found
= 0;
1738 /* start after the selected one */
1739 start
= frame
->entries
;
1740 if (frame
->selected
) {
1741 for (it
= start
; frame
->selected
!= it
->data
;
1742 it
= g_list_next(it
))
1743 g_assert(it
!= NULL
); /* nothing was selected? */
1744 /* next with wraparound */
1745 start
= g_list_next(it
);
1746 if (start
== NULL
) start
= frame
->entries
;
1751 ObMenuEntryFrame
*e
= it
->data
;
1752 gunichar entrykey
= 0;
1754 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1755 entrykey
= e
->entry
->data
.normal
.shortcut
;
1756 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1757 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1759 if (unikey
== entrykey
) {
1760 if (found
== NULL
) found
= e
;
1764 /* next with wraparound */
1765 it
= g_list_next(it
);
1766 if (it
== NULL
) it
= frame
->entries
;
1767 } while (it
!= start
);
1770 if (found
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
1773 menu_frame_select(frame
, found
, TRUE
);
1774 usleep(50000); /* highlight the item for a short bit so the
1775 user can see what happened */
1776 menu_entry_frame_execute(found
, state
);
1778 menu_frame_select(frame
, found
, TRUE
);
1780 menu_frame_select_next(frame
->child
);
1791 static gboolean
event_handle_menu(XEvent
*ev
)
1794 ObMenuEntryFrame
*e
;
1795 gboolean ret
= TRUE
;
1799 if (menu_hide_delay_reached() &&
1800 (ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5))
1802 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1803 ev
->xbutton
.y_root
)))
1805 menu_frame_select(e
->frame
, e
, TRUE
);
1806 menu_entry_frame_execute(e
, ev
->xbutton
.state
);
1809 menu_frame_hide_all();
1813 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1814 if (e
->ignore_enters
)
1816 else if (!(f
= find_active_menu()) ||
1818 f
->parent
== e
->frame
||
1819 f
->child
== e
->frame
)
1820 menu_frame_select(e
->frame
, e
, FALSE
);
1824 /*ignore leaves when we're already in the window */
1825 if (ev
->xcrossing
.detail
== NotifyInferior
)
1828 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1829 (f
= find_active_menu()) && f
->selected
== e
&&
1830 e
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1832 menu_frame_select(e
->frame
, NULL
, FALSE
);
1836 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1837 ev
->xmotion
.y_root
)))
1838 if (!(f
= find_active_menu()) ||
1840 f
->parent
== e
->frame
||
1841 f
->child
== e
->frame
)
1842 menu_frame_select(e
->frame
, e
, FALSE
);
1846 ret
= event_handle_menu_keyboard(ev
);
1852 static void event_handle_user_input(ObClient
*client
, XEvent
*e
)
1854 g_assert(e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
1855 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
1856 e
->type
== KeyRelease
);
1858 if (menu_frame_visible
) {
1859 if (event_handle_menu(e
))
1860 /* don't use the event if the menu used it, but if the menu
1861 didn't use it and it's a keypress that is bound, it will
1862 close the menu and be used */
1866 /* if the keyboard interactive action uses the event then dont
1867 use it for bindings. likewise is moveresize uses the event. */
1868 if (!actions_interactive_input_event(e
) && !moveresize_event(e
)) {
1869 if (moveresize_in_progress
)
1870 /* make further actions work on the client being
1872 client
= moveresize_client
;
1874 if (e
->type
== ButtonPress
||
1875 e
->type
== ButtonRelease
||
1876 e
->type
== MotionNotify
)
1878 /* the frame may not be "visible" but they can still click on it
1879 in the case where it is animating before disappearing */
1880 if (!client
|| !frame_iconify_animating(client
->frame
))
1881 mouse_event(client
, e
);
1883 keyboard_event((focus_cycle_target
? focus_cycle_target
:
1884 (client
? client
: focus_client
)), e
);
1888 static void focus_delay_dest(gpointer data
)
1893 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
1895 const ObFocusDelayData
*f1
= d1
;
1896 return f1
->client
== d2
;
1899 static gboolean
focus_delay_func(gpointer data
)
1901 ObFocusDelayData
*d
= data
;
1902 Time old
= event_curtime
;
1904 /* don't move focus and kill the menu or the move/resize */
1905 if (menu_frame_visible
|| moveresize_in_progress
) return FALSE
;
1907 event_curtime
= d
->time
;
1908 event_curserial
= d
->serial
;
1909 if (client_focus(d
->client
) && config_focus_raise
)
1910 stacking_raise(CLIENT_AS_WINDOW(d
->client
));
1911 event_curtime
= old
;
1912 return FALSE
; /* no repeat */
1915 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1917 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1921 void event_halt_focus_delay(void)
1923 /* ignore all enter events up till the event which caused this to occur */
1924 if (event_curserial
) event_ignore_enter_range(1, event_curserial
);
1925 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1928 gulong
event_start_ignore_all_enters(void)
1930 XSync(ob_display
, FALSE
);
1931 return LastKnownRequestProcessed(ob_display
);
1934 static void event_ignore_enter_range(gulong start
, gulong end
)
1938 g_assert(start
!= 0);
1941 r
= g_new(ObSerialRange
, 1);
1944 ignore_serials
= g_slist_prepend(ignore_serials
, r
);
1946 ob_debug_type(OB_DEBUG_FOCUS
, "ignoring enters from %lu until %lu\n",
1949 /* increment the serial so we don't ignore events we weren't meant to */
1950 XSync(ob_display
, FALSE
);
1953 void event_end_ignore_all_enters(gulong start
)
1955 XSync(ob_display
, FALSE
);
1956 event_ignore_enter_range(start
, LastKnownRequestProcessed(ob_display
));
1959 static gboolean
is_enter_focus_event_ignored(XEvent
*e
)
1963 g_assert(e
->type
== EnterNotify
&&
1964 !(e
->xcrossing
.mode
== NotifyGrab
||
1965 e
->xcrossing
.mode
== NotifyUngrab
||
1966 e
->xcrossing
.detail
== NotifyInferior
));
1968 for (it
= ignore_serials
; it
; it
= next
) {
1969 ObSerialRange
*r
= it
->data
;
1971 next
= g_slist_next(it
);
1973 if ((glong
)(e
->xany
.serial
- r
->end
) > 0) {
1975 ignore_serials
= g_slist_delete_link(ignore_serials
, it
);
1978 else if ((glong
)(e
->xany
.serial
- r
->start
) >= 0)
1984 void event_cancel_all_key_grabs(void)
1986 if (actions_interactive_act_running()) {
1987 actions_interactive_cancel_act();
1988 ob_debug("KILLED interactive action\n");
1990 else if (menu_frame_visible
) {
1991 menu_frame_hide_all();
1992 ob_debug("KILLED open menus\n");
1994 else if (moveresize_in_progress
) {
1995 moveresize_end(TRUE
);
1996 ob_debug("KILLED interactive moveresize\n");
1998 else if (grab_on_keyboard()) {
2000 ob_debug("KILLED active grab on keyboard\n");
2003 ungrab_passive_key();
2005 XSync(ob_display
, FALSE
);
2008 gboolean
event_time_after(Time t1
, Time t2
)
2010 g_assert(t1
!= CurrentTime
);
2011 g_assert(t2
!= CurrentTime
);
2014 Timestamp values wrap around (after about 49.7 days). The server, given
2015 its current time is represented by timestamp T, always interprets
2016 timestamps from clients by treating half of the timestamp space as being
2017 later in time than T.
2018 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
2021 /* TIME_HALF is half of the number space of a Time type variable */
2022 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
2024 if (t2
>= TIME_HALF
)
2025 /* t2 is in the second half so t1 might wrap around and be smaller than
2027 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
2029 /* t2 is in the first half so t1 has to come after it */
2030 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);
2033 Time
event_get_server_time(void)
2035 /* Generate a timestamp */
2038 XChangeProperty(ob_display
, screen_support_win
,
2039 prop_atoms
.wm_class
, prop_atoms
.string
,
2040 8, PropModeAppend
, NULL
, 0);
2041 XWindowEvent(ob_display
, screen_support_win
, PropertyChangeMask
, &event
);
2042 return event
.xproperty
.time
;