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.
35 #include "menuframe.h"
41 #include "focus_cycle.h"
42 #include "moveresize.h"
45 #include "extensions.h"
46 #include "translate.h"
50 #include <X11/Xatom.h>
53 #ifdef HAVE_SYS_SELECT_H
54 # include <sys/select.h>
60 # include <unistd.h> /* for usleep() */
63 # include <X11/XKBlib.h>
67 #include <X11/ICE/ICElib.h>
84 gulong start
; /* inclusive */
85 gulong end
; /* inclusive */
88 static void event_process(const XEvent
*e
, gpointer data
);
89 static void event_handle_root(XEvent
*e
);
90 static gboolean
event_handle_menu_keyboard(XEvent
*e
);
91 static gboolean
event_handle_menu(XEvent
*e
);
92 static void event_handle_dock(ObDock
*s
, XEvent
*e
);
93 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
);
94 static void event_handle_client(ObClient
*c
, XEvent
*e
);
95 static void event_handle_user_input(ObClient
*client
, XEvent
*e
);
96 static gboolean
is_enter_focus_event_ignored(gulong serial
);
97 static void event_ignore_enter_range(gulong start
, gulong end
);
99 static void focus_delay_dest(gpointer data
);
100 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
);
101 static gboolean
focus_delay_func(gpointer data
);
102 static void focus_delay_client_dest(ObClient
*client
, gpointer data
);
104 Time event_curtime
= CurrentTime
;
105 Time event_last_user_time
= CurrentTime
;
106 /*! The serial of the current X event */
108 static gulong event_curserial
;
109 static gboolean focus_left_screen
= FALSE
;
110 /*! A list of ObSerialRanges which are to be ignored for mouse enter events */
111 static GSList
*ignore_serials
= NULL
;
114 static void ice_handler(gint fd
, gpointer conn
)
117 IceProcessMessages(conn
, NULL
, &b
);
120 static void ice_watch(IceConn conn
, IcePointer data
, Bool opening
,
121 IcePointer
*watch_data
)
126 fd
= IceConnectionNumber(conn
);
127 ob_main_loop_fd_add(ob_main_loop
, fd
, ice_handler
, conn
, NULL
);
129 ob_main_loop_fd_remove(ob_main_loop
, fd
);
135 void event_startup(gboolean reconfig
)
137 if (reconfig
) return;
139 ob_main_loop_x_add(ob_main_loop
, event_process
, NULL
, NULL
);
142 IceAddConnectionWatch(ice_watch
, NULL
);
145 client_add_destroy_notify(focus_delay_client_dest
, NULL
);
148 void event_shutdown(gboolean reconfig
)
150 if (reconfig
) return;
153 IceRemoveConnectionWatch(ice_watch
, NULL
);
156 client_remove_destroy_notify(focus_delay_client_dest
);
159 static Window
event_get_window(XEvent
*e
)
166 window
= RootWindow(ob_display
, ob_screen
);
169 window
= e
->xmap
.window
;
172 window
= e
->xunmap
.window
;
175 window
= e
->xdestroywindow
.window
;
177 case ConfigureRequest
:
178 window
= e
->xconfigurerequest
.window
;
180 case ConfigureNotify
:
181 window
= e
->xconfigure
.window
;
185 if (extensions_xkb
&& e
->type
== extensions_xkb_event_basep
) {
186 switch (((XkbAnyEvent
*)e
)->xkb_type
) {
188 window
= ((XkbBellNotifyEvent
*)e
)->window
;
195 if (extensions_sync
&&
196 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
201 window
= e
->xany
.window
;
206 static void event_set_curtime(XEvent
*e
)
208 Time t
= CurrentTime
;
210 /* grab the lasttime and hack up the state */
226 t
= e
->xproperty
.time
;
230 t
= e
->xcrossing
.time
;
234 if (extensions_sync
&&
235 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
237 t
= ((XSyncAlarmNotifyEvent
*)e
)->time
;
240 /* if more event types are anticipated, get their timestamp
245 /* watch that if we get an event earlier than the last specified user_time,
246 which can happen if the clock goes backwards, we erase the last
247 specified user_time */
248 if (t
&& event_last_user_time
&& event_time_after(event_last_user_time
, t
))
249 event_last_user_time
= CurrentTime
;
254 static void event_hack_mods(XEvent
*e
)
257 XkbStateRec xkb_state
;
263 e
->xbutton
.state
= modkeys_only_modifier_masks(e
->xbutton
.state
);
266 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
270 /* If XKB is present, then the modifiers are all strange from its
271 magic. Our X core protocol stuff won't work, so we use this to
272 find what the modifier state is instead. */
273 if (XkbGetState(ob_display
, XkbUseCoreKbd
, &xkb_state
) == Success
)
275 modkeys_only_modifier_masks(xkb_state
.compat_state
);
279 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
280 /* remove from the state the mask of the modifier key being
281 released, if it is a modifier key being released that is */
282 e
->xkey
.state
&= ~modkeys_keycode_to_mask(e
->xkey
.keycode
);
286 e
->xmotion
.state
= modkeys_only_modifier_masks(e
->xmotion
.state
);
287 /* compress events */
290 while (XCheckTypedWindowEvent(ob_display
, e
->xmotion
.window
,
292 e
->xmotion
.x
= ce
.xmotion
.x
;
293 e
->xmotion
.y
= ce
.xmotion
.y
;
294 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
295 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
302 static gboolean
wanted_focusevent(XEvent
*e
, gboolean in_client_only
)
304 gint mode
= e
->xfocus
.mode
;
305 gint detail
= e
->xfocus
.detail
;
306 Window win
= e
->xany
.window
;
308 if (e
->type
== FocusIn
) {
309 /* These are ones we never want.. */
311 /* This means focus was given by a keyboard/mouse grab. */
312 if (mode
== NotifyGrab
)
314 /* This means focus was given back from a keyboard/mouse grab. */
315 if (mode
== NotifyUngrab
)
318 /* These are the ones we want.. */
320 if (win
== RootWindow(ob_display
, ob_screen
)) {
321 /* If looking for a focus in on a client, then always return
322 FALSE for focus in's to the root window */
325 /* This means focus reverted off of a client */
326 else if (detail
== NotifyPointerRoot
||
327 detail
== NotifyDetailNone
||
328 detail
== NotifyInferior
||
329 /* This means focus got here from another screen */
330 detail
== NotifyNonlinear
)
336 /* It was on a client, was it a valid one?
337 It's possible to get a FocusIn event for a client that was managed
340 if (in_client_only
) {
341 ObWindow
*w
= g_hash_table_lookup(window_map
, &e
->xfocus
.window
);
342 if (!w
|| !WINDOW_IS_CLIENT(w
))
346 /* This means focus reverted to parent from the client (this
347 happens often during iconify animation) */
348 if (detail
== NotifyInferior
)
352 /* This means focus moved from the root window to a client */
353 if (detail
== NotifyVirtual
)
355 /* This means focus moved from one client to another */
356 if (detail
== NotifyNonlinearVirtual
)
362 g_assert(e
->type
== FocusOut
);
364 /* These are ones we never want.. */
366 /* This means focus was taken by a keyboard/mouse grab. */
367 if (mode
== NotifyGrab
)
369 /* This means focus was grabbed on a window and it was released. */
370 if (mode
== NotifyUngrab
)
373 /* Focus left the root window revertedto state */
374 if (win
== RootWindow(ob_display
, ob_screen
))
377 /* These are the ones we want.. */
379 /* This means focus moved from a client to the root window */
380 if (detail
== NotifyVirtual
)
382 /* This means focus moved from one client to another */
383 if (detail
== NotifyNonlinearVirtual
)
391 static Bool
event_look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
393 return e
->type
== FocusIn
&& wanted_focusevent(e
, FALSE
);
396 static Bool
event_look_for_focusin_client(Display
*d
, XEvent
*e
, XPointer arg
)
398 return e
->type
== FocusIn
&& wanted_focusevent(e
, TRUE
);
401 static void print_focusevent(XEvent
*e
)
403 gint mode
= e
->xfocus
.mode
;
404 gint detail
= e
->xfocus
.detail
;
405 Window win
= e
->xany
.window
;
406 const gchar
*modestr
, *detailstr
;
409 case NotifyNormal
: modestr
="NotifyNormal"; break;
410 case NotifyGrab
: modestr
="NotifyGrab"; break;
411 case NotifyUngrab
: modestr
="NotifyUngrab"; break;
412 case NotifyWhileGrabbed
: modestr
="NotifyWhileGrabbed"; break;
415 case NotifyAncestor
: detailstr
="NotifyAncestor"; break;
416 case NotifyVirtual
: detailstr
="NotifyVirtual"; break;
417 case NotifyInferior
: detailstr
="NotifyInferior"; break;
418 case NotifyNonlinear
: detailstr
="NotifyNonlinear"; break;
419 case NotifyNonlinearVirtual
: detailstr
="NotifyNonlinearVirtual"; break;
420 case NotifyPointer
: detailstr
="NotifyPointer"; break;
421 case NotifyPointerRoot
: detailstr
="NotifyPointerRoot"; break;
422 case NotifyDetailNone
: detailstr
="NotifyDetailNone"; break;
425 if (mode
== NotifyGrab
|| mode
== NotifyUngrab
)
430 ob_debug_type(OB_DEBUG_FOCUS
, "Focus%s 0x%x mode=%s detail=%s\n",
431 (e
->xfocus
.type
== FocusIn
? "In" : "Out"),
437 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
442 if (!wanted_focusevent(e
, FALSE
))
447 if (!wanted_focusevent(e
, FALSE
))
454 static void event_process(const XEvent
*ec
, gpointer data
)
457 ObClient
*client
= NULL
;
459 ObDockApp
*dockapp
= NULL
;
460 ObWindow
*obwin
= NULL
;
462 ObEventData
*ed
= data
;
463 ObPrompt
*prompt
= NULL
;
465 /* make a copy we can mangle */
469 window
= event_get_window(e
);
470 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
471 switch (obwin
->type
) {
473 dock
= WINDOW_AS_DOCK(obwin
);
476 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
479 client
= WINDOW_AS_CLIENT(obwin
);
482 /* not to be used for events */
483 g_assert_not_reached();
485 case Window_Internal
:
486 /* we don't do anything with events directly on these windows */
489 prompt
= WINDOW_AS_PROMPT(obwin
);
494 event_set_curtime(e
);
495 event_curserial
= e
->xany
.serial
;
497 if (event_ignore(e
, client
)) {
504 /* deal with it in the kernel */
506 if (menu_frame_visible
&&
507 (e
->type
== EnterNotify
|| e
->type
== LeaveNotify
))
509 /* crossing events for menu */
510 event_handle_menu(e
);
511 } else if (e
->type
== FocusIn
) {
513 e
->xfocus
.detail
== NotifyInferior
)
515 ob_debug_type(OB_DEBUG_FOCUS
,
516 "Focus went to the frame window");
518 focus_left_screen
= FALSE
;
520 focus_fallback(FALSE
, config_focus_under_mouse
, TRUE
, TRUE
);
522 /* We don't get a FocusOut for this case, because it's just moving
523 from our Inferior up to us. This happens when iconifying a
524 window with RevertToParent focus */
525 frame_adjust_focus(client
->frame
, FALSE
);
526 /* focus_set_client(NULL) has already been called */
528 else if (e
->xfocus
.detail
== NotifyPointerRoot
||
529 e
->xfocus
.detail
== NotifyDetailNone
||
530 e
->xfocus
.detail
== NotifyInferior
||
531 e
->xfocus
.detail
== NotifyNonlinear
)
535 ob_debug_type(OB_DEBUG_FOCUS
,
536 "Focus went to root or pointer root/none\n");
538 if (e
->xfocus
.detail
== NotifyInferior
||
539 e
->xfocus
.detail
== NotifyNonlinear
)
541 focus_left_screen
= FALSE
;
544 /* If another FocusIn is in the queue then don't fallback yet. This
545 fixes the fun case of:
546 window map -> send focusin
547 window unmap -> get focusout
548 window map -> send focusin
549 get first focus out -> fall back to something (new window
550 hasn't received focus yet, so something else) -> send focusin
551 which means the "something else" is the last thing to get a
552 focusin sent to it, so the new window doesn't end up with focus.
554 But if the other focus in is something like PointerRoot then we
555 still want to fall back.
557 if (XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin_client
,
560 XPutBackEvent(ob_display
, &ce
);
561 ob_debug_type(OB_DEBUG_FOCUS
,
562 " but another FocusIn is coming\n");
564 /* Focus has been reverted.
566 FocusOut events come after UnmapNotify, so we don't need to
567 worry about focusing an invalid window
570 if (!focus_left_screen
)
571 focus_fallback(FALSE
, config_focus_under_mouse
,
577 ob_debug_type(OB_DEBUG_FOCUS
,
578 "Focus went to a window that is already gone\n");
580 /* If you send focus to a window and then it disappears, you can
581 get the FocusIn for it, after it is unmanaged.
582 Just wait for the next FocusOut/FocusIn pair, but make note that
583 the window that was focused no longer is. */
584 focus_set_client(NULL
);
586 else if (client
!= focus_client
) {
587 focus_left_screen
= FALSE
;
588 frame_adjust_focus(client
->frame
, TRUE
);
589 focus_set_client(client
);
590 client_calc_layer(client
);
591 client_bring_helper_windows(client
);
593 } else if (e
->type
== FocusOut
) {
596 /* Look for the followup FocusIn */
597 if (!XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin
, NULL
)) {
598 /* There is no FocusIn, this means focus went to a window that
599 is not being managed, or a window on another screen. */
603 xerror_set_ignore(TRUE
);
604 if (XGetInputFocus(ob_display
, &win
, &i
) != 0 &&
605 XGetGeometry(ob_display
, win
, &root
, &i
,&i
,&u
,&u
,&u
,&u
) != 0 &&
606 root
!= RootWindow(ob_display
, ob_screen
))
608 ob_debug_type(OB_DEBUG_FOCUS
,
609 "Focus went to another screen !\n");
610 focus_left_screen
= TRUE
;
613 ob_debug_type(OB_DEBUG_FOCUS
,
614 "Focus went to a black hole !\n");
615 xerror_set_ignore(FALSE
);
616 /* nothing is focused */
617 focus_set_client(NULL
);
619 /* Focus moved, so process the FocusIn event */
620 ObEventData ed
= { .ignored
= FALSE
};
621 event_process(&ce
, &ed
);
623 /* The FocusIn was ignored, this means it was on a window
624 that isn't a client. */
625 ob_debug_type(OB_DEBUG_FOCUS
,
626 "Focus went to an unmanaged window 0x%x !\n",
628 focus_fallback(TRUE
, config_focus_under_mouse
, TRUE
, TRUE
);
632 if (client
&& client
!= focus_client
) {
633 frame_adjust_focus(client
->frame
, FALSE
);
634 /* focus_set_client(NULL) has already been called in this
635 section or by focus_fallback */
639 event_handle_client(client
, e
);
641 event_handle_dockapp(dockapp
, e
);
643 event_handle_dock(dock
, e
);
644 else if (window
== RootWindow(ob_display
, ob_screen
))
645 event_handle_root(e
);
646 else if (e
->type
== MapRequest
)
647 client_manage(window
, NULL
);
648 else if (e
->type
== MappingNotify
) {
649 /* keyboard layout changes for modifier mapping changes. reload the
650 modifier map, and rebind all the key bindings as appropriate */
651 ob_debug("Kepboard map changed. Reloading keyboard bindings.\n");
652 modkeys_shutdown(TRUE
);
653 modkeys_startup(TRUE
);
656 else if (e
->type
== ClientMessage
) {
657 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
658 windows that are not managed yet. */
659 if (e
->xclient
.message_type
== prop_atoms
.net_request_frame_extents
) {
660 /* Pretend to manage the client, getting information used to
661 determine its decorations */
662 ObClient
*c
= client_fake_manage(e
->xclient
.window
);
665 /* set the frame extents on the window */
666 vals
[0] = c
->frame
->size
.left
;
667 vals
[1] = c
->frame
->size
.right
;
668 vals
[2] = c
->frame
->size
.top
;
669 vals
[3] = c
->frame
->size
.bottom
;
670 PROP_SETA32(e
->xclient
.window
, net_frame_extents
,
673 /* Free the pretend client */
674 client_fake_unmanage(c
);
677 else if (e
->type
== ConfigureRequest
) {
678 /* unhandled configure requests must be used to configure the
682 xwc
.x
= e
->xconfigurerequest
.x
;
683 xwc
.y
= e
->xconfigurerequest
.y
;
684 xwc
.width
= e
->xconfigurerequest
.width
;
685 xwc
.height
= e
->xconfigurerequest
.height
;
686 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
687 xwc
.sibling
= e
->xconfigurerequest
.above
;
688 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
690 /* we are not to be held responsible if someone sends us an
692 xerror_set_ignore(TRUE
);
693 XConfigureWindow(ob_display
, window
,
694 e
->xconfigurerequest
.value_mask
, &xwc
);
695 xerror_set_ignore(FALSE
);
698 else if (extensions_sync
&&
699 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
701 XSyncAlarmNotifyEvent
*se
= (XSyncAlarmNotifyEvent
*)e
;
702 if (se
->alarm
== moveresize_alarm
&& moveresize_in_progress
)
707 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
) {
708 /* If the button press was on some non-root window, or was physically
709 on the root window, then process it */
710 if (window
!= RootWindow(ob_display
, ob_screen
) ||
711 e
->xbutton
.subwindow
== None
)
713 event_handle_user_input(client
, e
);
715 /* Otherwise only process it if it was physically on an openbox
720 if ((w
= g_hash_table_lookup(window_map
, &e
->xbutton
.subwindow
)) &&
721 WINDOW_IS_INTERNAL(w
))
723 event_handle_user_input(client
, e
);
727 else if (e
->type
== KeyPress
|| e
->type
== KeyRelease
||
728 e
->type
== MotionNotify
)
729 event_handle_user_input(client
, e
);
731 /* if something happens and it's not from an XEvent, then we don't know
733 event_curtime
= CurrentTime
;
737 static void event_handle_root(XEvent
*e
)
743 ob_debug("Another WM has requested to replace us. Exiting.\n");
748 if (e
->xclient
.format
!= 32) break;
750 msgtype
= e
->xclient
.message_type
;
751 if (msgtype
== prop_atoms
.net_current_desktop
) {
752 guint d
= e
->xclient
.data
.l
[0];
753 if (d
< screen_num_desktops
) {
754 event_curtime
= e
->xclient
.data
.l
[1];
755 if (event_curtime
== 0)
756 ob_debug_type(OB_DEBUG_APP_BUGS
,
757 "_NET_CURRENT_DESKTOP message is missing "
759 screen_set_desktop(d
, TRUE
);
761 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
762 guint d
= e
->xclient
.data
.l
[0];
763 if (d
> 0 && d
<= 1000)
764 screen_set_num_desktops(d
);
765 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
766 screen_show_desktop(e
->xclient
.data
.l
[0] != 0, NULL
);
767 } else if (msgtype
== prop_atoms
.ob_control
) {
768 ob_debug("OB_CONTROL: %d\n", e
->xclient
.data
.l
[0]);
769 if (e
->xclient
.data
.l
[0] == 1)
771 else if (e
->xclient
.data
.l
[0] == 2)
773 else if (e
->xclient
.data
.l
[0] == 3)
775 } else if (msgtype
== prop_atoms
.wm_protocols
) {
776 if ((Atom
)e
->xclient
.data
.l
[0] == prop_atoms
.net_wm_ping
)
777 ping_got_pong(e
->xclient
.data
.l
[1]);
781 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
) {
782 ob_debug("UPDATE DESKTOP NAMES\n");
783 screen_update_desktop_names();
785 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
786 screen_update_layout();
788 case ConfigureNotify
:
790 XRRUpdateConfiguration(e
);
799 void event_enter_client(ObClient
*client
)
801 g_assert(config_focus_follow
);
803 if (is_enter_focus_event_ignored(event_curserial
)) {
804 ob_debug_type(OB_DEBUG_FOCUS
, "Ignoring enter event with serial %lu\n"
805 "on client 0x%x", event_curserial
, client
->window
);
809 if (client_enter_focusable(client
) && client_can_focus(client
)) {
810 if (config_focus_delay
) {
811 ObFocusDelayData
*data
;
813 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
815 data
= g_new(ObFocusDelayData
, 1);
816 data
->client
= client
;
817 data
->time
= event_curtime
;
818 data
->serial
= event_curserial
;
820 ob_main_loop_timeout_add(ob_main_loop
,
821 config_focus_delay
* 1000,
823 data
, focus_delay_cmp
, focus_delay_dest
);
825 ObFocusDelayData data
;
826 data
.client
= client
;
827 data
.time
= event_curtime
;
828 data
.serial
= event_curserial
;
829 focus_delay_func(&data
);
834 static void event_handle_client(ObClient
*client
, XEvent
*e
)
839 static gint px
= -1, py
= -1;
844 /* save where the press occured for the first button pressed */
846 pb
= e
->xbutton
.button
;
851 /* Wheel buttons don't draw because they are an instant click, so it
852 is a waste of resources to go drawing it.
853 if the user is doing an intereactive thing, or has a menu open then
854 the mouse is grabbed (possibly) and if we get these events we don't
855 want to deal with them
857 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5) &&
860 /* use where the press occured */
861 con
= frame_context(client
, e
->xbutton
.window
, px
, py
);
862 con
= mouse_button_frame_context(con
, e
->xbutton
.button
,
865 if (e
->type
== ButtonRelease
&& e
->xbutton
.button
== pb
)
866 pb
= 0, px
= py
= -1;
869 case OB_FRAME_CONTEXT_MAXIMIZE
:
870 client
->frame
->max_press
= (e
->type
== ButtonPress
);
871 frame_adjust_state(client
->frame
);
873 case OB_FRAME_CONTEXT_CLOSE
:
874 client
->frame
->close_press
= (e
->type
== ButtonPress
);
875 frame_adjust_state(client
->frame
);
877 case OB_FRAME_CONTEXT_ICONIFY
:
878 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
879 frame_adjust_state(client
->frame
);
881 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
882 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
883 frame_adjust_state(client
->frame
);
885 case OB_FRAME_CONTEXT_SHADE
:
886 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
887 frame_adjust_state(client
->frame
);
890 /* nothing changes with clicks for any other contexts */
896 /* when there is a grab on the pointer, we won't get enter/leave
897 notifies, but we still get motion events */
898 if (grab_on_pointer()) break;
900 con
= frame_context(client
, e
->xmotion
.window
,
901 e
->xmotion
.x
, e
->xmotion
.y
);
903 case OB_FRAME_CONTEXT_TITLEBAR
:
904 case OB_FRAME_CONTEXT_TLCORNER
:
905 case OB_FRAME_CONTEXT_TRCORNER
:
906 /* we've left the button area inside the titlebar */
907 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
908 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
909 client
->frame
->close_hover
)
911 client
->frame
->max_hover
= FALSE
;
912 client
->frame
->desk_hover
= FALSE
;
913 client
->frame
->shade_hover
= FALSE
;
914 client
->frame
->iconify_hover
= FALSE
;
915 client
->frame
->close_hover
= FALSE
;
916 frame_adjust_state(client
->frame
);
919 case OB_FRAME_CONTEXT_MAXIMIZE
:
920 if (!client
->frame
->max_hover
) {
921 client
->frame
->max_hover
= TRUE
;
922 frame_adjust_state(client
->frame
);
925 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
926 if (!client
->frame
->desk_hover
) {
927 client
->frame
->desk_hover
= TRUE
;
928 frame_adjust_state(client
->frame
);
931 case OB_FRAME_CONTEXT_SHADE
:
932 if (!client
->frame
->shade_hover
) {
933 client
->frame
->shade_hover
= TRUE
;
934 frame_adjust_state(client
->frame
);
937 case OB_FRAME_CONTEXT_ICONIFY
:
938 if (!client
->frame
->iconify_hover
) {
939 client
->frame
->iconify_hover
= TRUE
;
940 frame_adjust_state(client
->frame
);
943 case OB_FRAME_CONTEXT_CLOSE
:
944 if (!client
->frame
->close_hover
) {
945 client
->frame
->close_hover
= TRUE
;
946 frame_adjust_state(client
->frame
);
954 con
= frame_context(client
, e
->xcrossing
.window
,
955 e
->xcrossing
.x
, e
->xcrossing
.y
);
957 case OB_FRAME_CONTEXT_TITLEBAR
:
958 case OB_FRAME_CONTEXT_TLCORNER
:
959 case OB_FRAME_CONTEXT_TRCORNER
:
960 /* we've left the button area inside the titlebar */
961 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
962 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
963 client
->frame
->close_hover
)
965 client
->frame
->max_hover
= FALSE
;
966 client
->frame
->desk_hover
= FALSE
;
967 client
->frame
->shade_hover
= FALSE
;
968 client
->frame
->iconify_hover
= FALSE
;
969 client
->frame
->close_hover
= FALSE
;
970 frame_adjust_state(client
->frame
);
973 case OB_FRAME_CONTEXT_MAXIMIZE
:
974 client
->frame
->max_hover
= FALSE
;
975 frame_adjust_state(client
->frame
);
977 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
978 client
->frame
->desk_hover
= FALSE
;
979 frame_adjust_state(client
->frame
);
981 case OB_FRAME_CONTEXT_SHADE
:
982 client
->frame
->shade_hover
= FALSE
;
983 frame_adjust_state(client
->frame
);
985 case OB_FRAME_CONTEXT_ICONIFY
:
986 client
->frame
->iconify_hover
= FALSE
;
987 frame_adjust_state(client
->frame
);
989 case OB_FRAME_CONTEXT_CLOSE
:
990 client
->frame
->close_hover
= FALSE
;
991 frame_adjust_state(client
->frame
);
993 case OB_FRAME_CONTEXT_FRAME
:
994 /* When the mouse leaves an animating window, don't use the
995 corresponding enter events. Pretend like the animating window
996 doesn't even exist..! */
997 if (frame_iconify_animating(client
->frame
))
998 event_end_ignore_all_enters(event_start_ignore_all_enters());
1000 ob_debug_type(OB_DEBUG_FOCUS
,
1001 "%sNotify mode %d detail %d on %lx\n",
1002 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1004 e
->xcrossing
.detail
, (client
?client
->window
:0));
1005 if (grab_on_keyboard())
1007 if (config_focus_follow
&& config_focus_delay
&&
1008 /* leave inferior events can happen when the mouse goes onto
1009 the window's border and then into the window before the
1011 e
->xcrossing
.detail
!= NotifyInferior
)
1013 ob_main_loop_timeout_remove_data(ob_main_loop
,
1024 con
= frame_context(client
, e
->xcrossing
.window
,
1025 e
->xcrossing
.x
, e
->xcrossing
.y
);
1027 case OB_FRAME_CONTEXT_MAXIMIZE
:
1028 client
->frame
->max_hover
= TRUE
;
1029 frame_adjust_state(client
->frame
);
1031 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
1032 client
->frame
->desk_hover
= TRUE
;
1033 frame_adjust_state(client
->frame
);
1035 case OB_FRAME_CONTEXT_SHADE
:
1036 client
->frame
->shade_hover
= TRUE
;
1037 frame_adjust_state(client
->frame
);
1039 case OB_FRAME_CONTEXT_ICONIFY
:
1040 client
->frame
->iconify_hover
= TRUE
;
1041 frame_adjust_state(client
->frame
);
1043 case OB_FRAME_CONTEXT_CLOSE
:
1044 client
->frame
->close_hover
= TRUE
;
1045 frame_adjust_state(client
->frame
);
1047 case OB_FRAME_CONTEXT_FRAME
:
1048 if (grab_on_keyboard())
1050 if (e
->xcrossing
.mode
== NotifyGrab
||
1051 e
->xcrossing
.mode
== NotifyUngrab
||
1052 /*ignore enters when we're already in the window */
1053 e
->xcrossing
.detail
== NotifyInferior
)
1055 ob_debug_type(OB_DEBUG_FOCUS
,
1056 "%sNotify mode %d detail %d serial %lu on %lx "
1058 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1060 e
->xcrossing
.detail
,
1061 e
->xcrossing
.serial
,
1062 client
?client
->window
:0);
1065 ob_debug_type(OB_DEBUG_FOCUS
,
1066 "%sNotify mode %d detail %d serial %lu on %lx, "
1067 "focusing window\n",
1068 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1070 e
->xcrossing
.detail
,
1071 e
->xcrossing
.serial
,
1072 (client
?client
->window
:0));
1073 if (config_focus_follow
)
1074 event_enter_client(client
);
1082 case ConfigureRequest
:
1084 /* dont compress these unless you're going to watch for property
1085 notifies in between (these can change what the configure would
1087 also you can't compress stacking events
1091 gboolean move
= FALSE
;
1092 gboolean resize
= FALSE
;
1094 /* get the current area */
1095 RECT_TO_DIMS(client
->area
, x
, y
, w
, h
);
1097 ob_debug("ConfigureRequest for \"%s\" desktop %d wmstate %d "
1099 " x %d y %d w %d h %d b %d\n",
1101 screen_desktop
, client
->wmstate
, client
->frame
->visible
,
1102 x
, y
, w
, h
, client
->border_width
);
1104 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
1105 if (client
->border_width
!= e
->xconfigurerequest
.border_width
) {
1106 client
->border_width
= e
->xconfigurerequest
.border_width
;
1108 /* if the border width is changing then that is the same
1109 as requesting a resize, but we don't actually change
1110 the client's border, so it will change their root
1111 coordiantes (since they include the border width) and
1112 we need to a notify then */
1117 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
1118 ObClient
*sibling
= NULL
;
1119 gulong ignore_start
;
1122 /* get the sibling */
1123 if (e
->xconfigurerequest
.value_mask
& CWSibling
) {
1125 win
= g_hash_table_lookup(window_map
,
1126 &e
->xconfigurerequest
.above
);
1127 if (win
&& WINDOW_IS_CLIENT(win
) &&
1128 WINDOW_AS_CLIENT(win
) != client
)
1130 sibling
= WINDOW_AS_CLIENT(win
);
1133 /* an invalid sibling was specified so don't restack at
1134 all, it won't make sense no matter what we do */
1139 if (!config_focus_under_mouse
)
1140 ignore_start
= event_start_ignore_all_enters();
1141 stacking_restack_request(client
, sibling
,
1142 e
->xconfigurerequest
.detail
);
1143 if (!config_focus_under_mouse
)
1144 event_end_ignore_all_enters(ignore_start
);
1147 /* a stacking change moves the window without resizing */
1151 if ((e
->xconfigurerequest
.value_mask
& CWX
) ||
1152 (e
->xconfigurerequest
.value_mask
& CWY
) ||
1153 (e
->xconfigurerequest
.value_mask
& CWWidth
) ||
1154 (e
->xconfigurerequest
.value_mask
& CWHeight
))
1156 if (e
->xconfigurerequest
.value_mask
& CWX
) {
1157 /* don't allow clients to move shaded windows (fvwm does this)
1159 if (!client
->shaded
)
1160 x
= e
->xconfigurerequest
.x
;
1163 if (e
->xconfigurerequest
.value_mask
& CWY
) {
1164 /* don't allow clients to move shaded windows (fvwm does this)
1166 if (!client
->shaded
)
1167 y
= e
->xconfigurerequest
.y
;
1171 if (e
->xconfigurerequest
.value_mask
& CWWidth
) {
1172 w
= e
->xconfigurerequest
.width
;
1175 if (e
->xconfigurerequest
.value_mask
& CWHeight
) {
1176 h
= e
->xconfigurerequest
.height
;
1181 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
1182 "move %d resize %d\n",
1183 e
->xconfigurerequest
.value_mask
& CWX
, x
,
1184 e
->xconfigurerequest
.value_mask
& CWY
, y
,
1185 e
->xconfigurerequest
.value_mask
& CWWidth
, w
,
1186 e
->xconfigurerequest
.value_mask
& CWHeight
, h
,
1189 /* check for broken apps moving to their root position
1191 XXX remove this some day...that would be nice. right now all
1192 kde apps do this when they try activate themselves on another
1193 desktop. eg. open amarok window on desktop 1, switch to desktop
1194 2, click amarok tray icon. it will move by its decoration size.
1196 if (x
!= client
->area
.x
&&
1197 x
== (client
->frame
->area
.x
+ client
->frame
->size
.left
-
1198 (gint
)client
->border_width
) &&
1199 y
!= client
->area
.y
&&
1200 y
== (client
->frame
->area
.y
+ client
->frame
->size
.top
-
1201 (gint
)client
->border_width
) &&
1202 w
== client
->area
.width
&&
1203 h
== client
->area
.height
)
1205 ob_debug_type(OB_DEBUG_APP_BUGS
,
1206 "Application %s is trying to move via "
1207 "ConfigureRequest to it's root window position "
1208 "but it is not using StaticGravity\n",
1214 /* they still requested a move, so don't change whether a
1215 notify is sent or not */
1221 client_try_configure(client
, &x
, &y
, &w
, &h
, &lw
, &lh
, FALSE
);
1223 /* if x was not given, then use gravity to figure out the new
1224 x. the reference point should not be moved */
1225 if ((e
->xconfigurerequest
.value_mask
& CWWidth
&&
1226 !(e
->xconfigurerequest
.value_mask
& CWX
)))
1227 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1228 /* if y was not given, then use gravity to figure out the new
1229 y. the reference point should not be moved */
1230 if ((e
->xconfigurerequest
.value_mask
& CWHeight
&&
1231 !(e
->xconfigurerequest
.value_mask
& CWY
)))
1232 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1234 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1236 ob_debug("Granting ConfigureRequest x %d y %d w %d h %d\n",
1238 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
, TRUE
);
1243 if (client
->ignore_unmaps
) {
1244 client
->ignore_unmaps
--;
1247 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1248 "ignores left %d\n",
1249 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
1250 client
->ignore_unmaps
);
1251 client_unmanage(client
);
1254 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
1255 client_unmanage(client
);
1257 case ReparentNotify
:
1258 /* this is when the client is first taken captive in the frame */
1259 if (e
->xreparent
.parent
== client
->frame
->window
) break;
1262 This event is quite rare and is usually handled in unmapHandler.
1263 However, if the window is unmapped when the reparent event occurs,
1264 the window manager never sees it because an unmap event is not sent
1265 to an already unmapped window.
1268 /* we don't want the reparent event, put it back on the stack for the
1269 X server to deal with after we unmanage the window */
1270 XPutBackEvent(ob_display
, e
);
1272 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
1273 client_unmanage(client
);
1276 ob_debug("MapRequest for 0x%lx\n", client
->window
);
1277 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
1278 does, we don't want it!
1279 it can happen now when the window is on
1280 another desktop, but we still don't
1282 client_activate(client
, FALSE
, TRUE
, TRUE
, TRUE
);
1285 /* validate cuz we query stuff off the client here */
1286 if (!client_validate(client
)) break;
1288 if (e
->xclient
.format
!= 32) return;
1290 msgtype
= e
->xclient
.message_type
;
1291 if (msgtype
== prop_atoms
.wm_change_state
) {
1292 /* compress changes into a single change */
1293 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1295 /* XXX: it would be nice to compress ALL messages of a
1296 type, not just messages in a row without other
1297 message types between. */
1298 if (ce
.xclient
.message_type
!= msgtype
) {
1299 XPutBackEvent(ob_display
, &ce
);
1302 e
->xclient
= ce
.xclient
;
1304 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1305 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
1306 /* compress changes into a single change */
1307 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1309 /* XXX: it would be nice to compress ALL messages of a
1310 type, not just messages in a row without other
1311 message types between. */
1312 if (ce
.xclient
.message_type
!= msgtype
) {
1313 XPutBackEvent(ob_display
, &ce
);
1316 e
->xclient
= ce
.xclient
;
1318 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1319 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1320 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1322 } else if (msgtype
== prop_atoms
.net_wm_state
) {
1323 gulong ignore_start
;
1325 /* can't compress these */
1326 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1327 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1328 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1329 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1330 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1333 /* ignore enter events caused by these like ob actions do */
1334 if (!config_focus_under_mouse
)
1335 ignore_start
= event_start_ignore_all_enters();
1336 client_set_state(client
, e
->xclient
.data
.l
[0],
1337 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1338 if (!config_focus_under_mouse
)
1339 event_end_ignore_all_enters(ignore_start
);
1340 } else if (msgtype
== prop_atoms
.net_close_window
) {
1341 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1342 client_close(client
);
1343 } else if (msgtype
== prop_atoms
.net_active_window
) {
1344 ob_debug("net_active_window for 0x%lx source=%s\n",
1346 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1347 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1348 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1349 /* XXX make use of data.l[2] !? */
1350 if (e
->xclient
.data
.l
[0] == 1 || e
->xclient
.data
.l
[0] == 2) {
1351 /* don't use the user's timestamp for client_focus, cuz if it's
1352 an old broken timestamp (happens all the time) then focus
1353 won't move even though we're trying to move it
1354 event_curtime = e->xclient.data.l[1];*/
1355 if (e
->xclient
.data
.l
[1] == 0)
1356 ob_debug_type(OB_DEBUG_APP_BUGS
,
1357 "_NET_ACTIVE_WINDOW message for window %s is"
1358 " missing a timestamp\n", client
->title
);
1360 ob_debug_type(OB_DEBUG_APP_BUGS
,
1361 "_NET_ACTIVE_WINDOW message for window %s is "
1362 "missing source indication\n");
1363 client_activate(client
, TRUE
, TRUE
, TRUE
,
1364 (e
->xclient
.data
.l
[0] == 0 ||
1365 e
->xclient
.data
.l
[0] == 2));
1366 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1367 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1368 client
->window
, e
->xclient
.data
.l
[2]);
1369 if ((Atom
)e
->xclient
.data
.l
[2] ==
1370 prop_atoms
.net_wm_moveresize_size_topleft
||
1371 (Atom
)e
->xclient
.data
.l
[2] ==
1372 prop_atoms
.net_wm_moveresize_size_top
||
1373 (Atom
)e
->xclient
.data
.l
[2] ==
1374 prop_atoms
.net_wm_moveresize_size_topright
||
1375 (Atom
)e
->xclient
.data
.l
[2] ==
1376 prop_atoms
.net_wm_moveresize_size_right
||
1377 (Atom
)e
->xclient
.data
.l
[2] ==
1378 prop_atoms
.net_wm_moveresize_size_right
||
1379 (Atom
)e
->xclient
.data
.l
[2] ==
1380 prop_atoms
.net_wm_moveresize_size_bottomright
||
1381 (Atom
)e
->xclient
.data
.l
[2] ==
1382 prop_atoms
.net_wm_moveresize_size_bottom
||
1383 (Atom
)e
->xclient
.data
.l
[2] ==
1384 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1385 (Atom
)e
->xclient
.data
.l
[2] ==
1386 prop_atoms
.net_wm_moveresize_size_left
||
1387 (Atom
)e
->xclient
.data
.l
[2] ==
1388 prop_atoms
.net_wm_moveresize_move
||
1389 (Atom
)e
->xclient
.data
.l
[2] ==
1390 prop_atoms
.net_wm_moveresize_size_keyboard
||
1391 (Atom
)e
->xclient
.data
.l
[2] ==
1392 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1394 moveresize_start(client
, e
->xclient
.data
.l
[0],
1395 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1396 e
->xclient
.data
.l
[2]);
1398 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1399 prop_atoms
.net_wm_moveresize_cancel
)
1400 moveresize_end(TRUE
);
1401 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1402 gint ograv
, x
, y
, w
, h
;
1404 ograv
= client
->gravity
;
1406 if (e
->xclient
.data
.l
[0] & 0xff)
1407 client
->gravity
= e
->xclient
.data
.l
[0] & 0xff;
1409 if (e
->xclient
.data
.l
[0] & 1 << 8)
1410 x
= e
->xclient
.data
.l
[1];
1413 if (e
->xclient
.data
.l
[0] & 1 << 9)
1414 y
= e
->xclient
.data
.l
[2];
1418 if (e
->xclient
.data
.l
[0] & 1 << 10) {
1419 w
= e
->xclient
.data
.l
[3];
1421 /* if x was not given, then use gravity to figure out the new
1422 x. the reference point should not be moved */
1423 if (!(e
->xclient
.data
.l
[0] & 1 << 8))
1424 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1427 w
= client
->area
.width
;
1429 if (e
->xclient
.data
.l
[0] & 1 << 11) {
1430 h
= e
->xclient
.data
.l
[4];
1432 /* if y was not given, then use gravity to figure out the new
1433 y. the reference point should not be moved */
1434 if (!(e
->xclient
.data
.l
[0] & 1 << 9))
1435 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1438 h
= client
->area
.height
;
1440 ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)\n",
1441 e
->xclient
.data
.l
[0] & 1 << 8, x
,
1442 e
->xclient
.data
.l
[0] & 1 << 9, y
,
1445 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1447 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
1449 client
->gravity
= ograv
;
1450 } else if (msgtype
== prop_atoms
.net_restack_window
) {
1451 if (e
->xclient
.data
.l
[0] != 2) {
1452 ob_debug_type(OB_DEBUG_APP_BUGS
,
1453 "_NET_RESTACK_WINDOW sent for window %s with "
1454 "invalid source indication %ld\n",
1455 client
->title
, e
->xclient
.data
.l
[0]);
1457 ObClient
*sibling
= NULL
;
1458 if (e
->xclient
.data
.l
[1]) {
1459 ObWindow
*win
= g_hash_table_lookup
1460 (window_map
, &e
->xclient
.data
.l
[1]);
1461 if (WINDOW_IS_CLIENT(win
) &&
1462 WINDOW_AS_CLIENT(win
) != client
)
1464 sibling
= WINDOW_AS_CLIENT(win
);
1466 if (sibling
== NULL
)
1467 ob_debug_type(OB_DEBUG_APP_BUGS
,
1468 "_NET_RESTACK_WINDOW sent for window %s "
1469 "with invalid sibling 0x%x\n",
1470 client
->title
, e
->xclient
.data
.l
[1]);
1472 if (e
->xclient
.data
.l
[2] == Below
||
1473 e
->xclient
.data
.l
[2] == BottomIf
||
1474 e
->xclient
.data
.l
[2] == Above
||
1475 e
->xclient
.data
.l
[2] == TopIf
||
1476 e
->xclient
.data
.l
[2] == Opposite
)
1478 gulong ignore_start
;
1480 if (!config_focus_under_mouse
)
1481 ignore_start
= event_start_ignore_all_enters();
1482 /* just raise, don't activate */
1483 stacking_restack_request(client
, sibling
,
1484 e
->xclient
.data
.l
[2]);
1485 if (!config_focus_under_mouse
)
1486 event_end_ignore_all_enters(ignore_start
);
1488 /* send a synthetic ConfigureNotify, cuz this is supposed
1489 to be like a ConfigureRequest. */
1490 client_reconfigure(client
, TRUE
);
1492 ob_debug_type(OB_DEBUG_APP_BUGS
,
1493 "_NET_RESTACK_WINDOW sent for window %s "
1494 "with invalid detail %d\n",
1495 client
->title
, e
->xclient
.data
.l
[2]);
1499 case PropertyNotify
:
1500 /* validate cuz we query stuff off the client here */
1501 if (!client_validate(client
)) break;
1503 /* compress changes to a single property into a single change */
1504 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1508 /* XXX: it would be nice to compress ALL changes to a property,
1509 not just changes in a row without other props between. */
1511 a
= ce
.xproperty
.atom
;
1512 b
= e
->xproperty
.atom
;
1516 if ((a
== prop_atoms
.net_wm_name
||
1517 a
== prop_atoms
.wm_name
||
1518 a
== prop_atoms
.net_wm_icon_name
||
1519 a
== prop_atoms
.wm_icon_name
)
1521 (b
== prop_atoms
.net_wm_name
||
1522 b
== prop_atoms
.wm_name
||
1523 b
== prop_atoms
.net_wm_icon_name
||
1524 b
== prop_atoms
.wm_icon_name
)) {
1527 if (a
== prop_atoms
.net_wm_icon
&&
1528 b
== prop_atoms
.net_wm_icon
)
1531 XPutBackEvent(ob_display
, &ce
);
1535 msgtype
= e
->xproperty
.atom
;
1536 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1537 ob_debug("Update NORMAL hints\n");
1538 client_update_normal_hints(client
);
1539 /* normal hints can make a window non-resizable */
1540 client_setup_decor_and_functions(client
, FALSE
);
1542 /* make sure the client's sizes are within its bounds, but only
1543 reconfigure the window if it needs to. emacs will update its
1544 normal hints every time it receives a conigurenotify */
1545 client_reconfigure(client
, FALSE
);
1546 } else if (msgtype
== XA_WM_HINTS
) {
1547 client_update_wmhints(client
);
1548 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1549 client_update_transient_for(client
);
1550 client_get_type_and_transientness(client
);
1551 /* type may have changed, so update the layer */
1552 client_calc_layer(client
);
1553 client_setup_decor_and_functions(client
, TRUE
);
1554 } else if (msgtype
== prop_atoms
.net_wm_name
||
1555 msgtype
== prop_atoms
.wm_name
||
1556 msgtype
== prop_atoms
.net_wm_icon_name
||
1557 msgtype
== prop_atoms
.wm_icon_name
) {
1558 client_update_title(client
);
1559 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1560 client_update_protocols(client
);
1561 client_setup_decor_and_functions(client
, TRUE
);
1563 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1564 client_update_strut(client
);
1566 else if (msgtype
== prop_atoms
.net_wm_strut_partial
) {
1567 client_update_strut(client
);
1569 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1570 client_update_icons(client
);
1572 else if (msgtype
== prop_atoms
.net_wm_icon_geometry
) {
1573 client_update_icon_geometry(client
);
1575 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1577 if (client
== focus_client
&&
1578 PROP_GET32(client
->window
, net_wm_user_time
, cardinal
, &t
) &&
1579 t
&& !event_time_after(t
, e
->xproperty
.time
) &&
1580 (!event_last_user_time
||
1581 event_time_after(t
, event_last_user_time
)))
1583 event_last_user_time
= t
;
1587 else if (msgtype
== prop_atoms
.net_wm_sync_request_counter
) {
1588 client_update_sync_request_counter(client
);
1592 case ColormapNotify
:
1593 client_update_colormap(client
, e
->xcolormap
.colormap
);
1598 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1599 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1600 frame_adjust_shape(client
->frame
);
1606 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1610 if (e
->xbutton
.button
== 1)
1611 stacking_raise(DOCK_AS_WINDOW(s
));
1612 else if (e
->xbutton
.button
== 2)
1613 stacking_lower(DOCK_AS_WINDOW(s
));
1619 /* don't hide when moving into a dock app */
1620 if (e
->xcrossing
.detail
!= NotifyInferior
)
1626 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1630 dock_app_drag(app
, &e
->xmotion
);
1633 if (app
->ignore_unmaps
) {
1634 app
->ignore_unmaps
--;
1637 dock_remove(app
, TRUE
);
1640 dock_remove(app
, FALSE
);
1642 case ReparentNotify
:
1643 dock_remove(app
, FALSE
);
1645 case ConfigureNotify
:
1646 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1651 static ObMenuFrame
* find_active_menu(void)
1654 ObMenuFrame
*ret
= NULL
;
1656 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1665 static ObMenuFrame
* find_active_or_last_menu(void)
1667 ObMenuFrame
*ret
= NULL
;
1669 ret
= find_active_menu();
1670 if (!ret
&& menu_frame_visible
)
1671 ret
= menu_frame_visible
->data
;
1675 static gboolean
event_handle_menu_keyboard(XEvent
*ev
)
1677 guint keycode
, state
;
1680 gboolean ret
= FALSE
;
1682 keycode
= ev
->xkey
.keycode
;
1683 state
= ev
->xkey
.state
;
1684 unikey
= translate_unichar(keycode
);
1686 frame
= find_active_or_last_menu();
1688 g_assert_not_reached(); /* there is no active menu */
1690 /* Allow control while going thru the menu */
1691 else if (ev
->type
== KeyPress
&& (state
& ~ControlMask
) == 0) {
1692 frame
->got_press
= TRUE
;
1694 if (keycode
== ob_keycode(OB_KEY_ESCAPE
)) {
1695 menu_frame_hide_all();
1699 else if (keycode
== ob_keycode(OB_KEY_LEFT
)) {
1700 /* Left goes to the parent menu */
1701 menu_frame_select(frame
, NULL
, TRUE
);
1705 else if (keycode
== ob_keycode(OB_KEY_RIGHT
)) {
1706 /* Right goes to the selected submenu */
1707 if (frame
->child
) menu_frame_select_next(frame
->child
);
1711 else if (keycode
== ob_keycode(OB_KEY_UP
)) {
1712 menu_frame_select_previous(frame
);
1716 else if (keycode
== ob_keycode(OB_KEY_DOWN
)) {
1717 menu_frame_select_next(frame
);
1722 /* Use KeyRelease events for running things so that the key release doesn't
1723 get sent to the focused application.
1725 Allow ControlMask only, and don't bother if the menu is empty */
1726 else if (ev
->type
== KeyRelease
&& (state
& ~ControlMask
) == 0 &&
1727 frame
->entries
&& frame
->got_press
)
1729 if (keycode
== ob_keycode(OB_KEY_RETURN
)) {
1730 /* Enter runs the active item or goes into the submenu.
1731 Control-Enter runs it without closing the menu. */
1733 menu_frame_select_next(frame
->child
);
1734 else if (frame
->selected
)
1735 menu_entry_frame_execute(frame
->selected
, state
);
1740 /* keyboard accelerator shortcuts. (if it was a valid key) */
1741 else if (unikey
!= 0) {
1744 ObMenuEntryFrame
*found
= NULL
;
1745 guint num_found
= 0;
1747 /* start after the selected one */
1748 start
= frame
->entries
;
1749 if (frame
->selected
) {
1750 for (it
= start
; frame
->selected
!= it
->data
;
1751 it
= g_list_next(it
))
1752 g_assert(it
!= NULL
); /* nothing was selected? */
1753 /* next with wraparound */
1754 start
= g_list_next(it
);
1755 if (start
== NULL
) start
= frame
->entries
;
1760 ObMenuEntryFrame
*e
= it
->data
;
1761 gunichar entrykey
= 0;
1763 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1764 entrykey
= e
->entry
->data
.normal
.shortcut
;
1765 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1766 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1768 if (unikey
== entrykey
) {
1769 if (found
== NULL
) found
= e
;
1773 /* next with wraparound */
1774 it
= g_list_next(it
);
1775 if (it
== NULL
) it
= frame
->entries
;
1776 } while (it
!= start
);
1779 if (found
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
1782 menu_frame_select(frame
, found
, TRUE
);
1783 usleep(50000); /* highlight the item for a short bit so the
1784 user can see what happened */
1785 menu_entry_frame_execute(found
, state
);
1787 menu_frame_select(frame
, found
, TRUE
);
1789 menu_frame_select_next(frame
->child
);
1800 static gboolean
event_handle_menu(XEvent
*ev
)
1803 ObMenuEntryFrame
*e
;
1804 gboolean ret
= TRUE
;
1808 if (menu_hide_delay_reached() &&
1809 (ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5))
1811 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1812 ev
->xbutton
.y_root
)))
1814 menu_frame_select(e
->frame
, e
, TRUE
);
1815 menu_entry_frame_execute(e
, ev
->xbutton
.state
);
1818 menu_frame_hide_all();
1822 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1823 if (e
->ignore_enters
)
1825 else if (!(f
= find_active_menu()) ||
1827 f
->parent
== e
->frame
||
1828 f
->child
== e
->frame
)
1829 menu_frame_select(e
->frame
, e
, FALSE
);
1833 /*ignore leaves when we're already in the window */
1834 if (ev
->xcrossing
.detail
== NotifyInferior
)
1837 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1838 (f
= find_active_menu()) && f
->selected
== e
&&
1839 e
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1841 menu_frame_select(e
->frame
, NULL
, FALSE
);
1845 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1846 ev
->xmotion
.y_root
)))
1847 if (!(f
= find_active_menu()) ||
1849 f
->parent
== e
->frame
||
1850 f
->child
== e
->frame
)
1851 menu_frame_select(e
->frame
, e
, FALSE
);
1855 ret
= event_handle_menu_keyboard(ev
);
1861 static void event_handle_user_input(ObClient
*client
, XEvent
*e
)
1863 g_assert(e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
1864 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
1865 e
->type
== KeyRelease
);
1867 if (menu_frame_visible
) {
1868 if (event_handle_menu(e
))
1869 /* don't use the event if the menu used it, but if the menu
1870 didn't use it and it's a keypress that is bound, it will
1871 close the menu and be used */
1875 /* if the keyboard interactive action uses the event then dont
1876 use it for bindings. likewise is moveresize uses the event. */
1877 if (!actions_interactive_input_event(e
) && !moveresize_event(e
)) {
1878 if (moveresize_in_progress
)
1879 /* make further actions work on the client being
1881 client
= moveresize_client
;
1883 if (e
->type
== ButtonPress
||
1884 e
->type
== ButtonRelease
||
1885 e
->type
== MotionNotify
)
1887 /* the frame may not be "visible" but they can still click on it
1888 in the case where it is animating before disappearing */
1889 if (!client
|| !frame_iconify_animating(client
->frame
))
1890 mouse_event(client
, e
);
1892 keyboard_event((focus_cycle_target
? focus_cycle_target
:
1893 (client
? client
: focus_client
)), e
);
1897 static void focus_delay_dest(gpointer data
)
1902 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
1904 const ObFocusDelayData
*f1
= d1
;
1905 return f1
->client
== d2
;
1908 static gboolean
focus_delay_func(gpointer data
)
1910 ObFocusDelayData
*d
= data
;
1911 Time old
= event_curtime
;
1913 /* don't move focus and kill the menu or the move/resize */
1914 if (menu_frame_visible
|| moveresize_in_progress
) return FALSE
;
1916 event_curtime
= d
->time
;
1917 event_curserial
= d
->serial
;
1918 if (client_focus(d
->client
) && config_focus_raise
)
1919 stacking_raise(CLIENT_AS_WINDOW(d
->client
));
1920 event_curtime
= old
;
1921 return FALSE
; /* no repeat */
1924 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1926 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1930 void event_halt_focus_delay(void)
1932 /* ignore all enter events up till the event which caused this to occur */
1933 if (event_curserial
) event_ignore_enter_range(1, event_curserial
);
1934 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1937 gulong
event_start_ignore_all_enters(void)
1939 return NextRequest(ob_display
);
1942 static void event_ignore_enter_range(gulong start
, gulong end
)
1946 g_assert(start
!= 0);
1949 r
= g_new(ObSerialRange
, 1);
1952 ignore_serials
= g_slist_prepend(ignore_serials
, r
);
1954 ob_debug_type(OB_DEBUG_FOCUS
, "ignoring enters from %lu until %lu\n",
1957 /* increment the serial so we don't ignore events we weren't meant to */
1958 PROP_ERASE(screen_support_win
, motif_wm_hints
);
1961 void event_end_ignore_all_enters(gulong start
)
1963 /* Use (NextRequest-1) so that we ignore up to the current serial only.
1964 Inside event_ignore_enter_range, we increment the serial by one, but if
1965 we ignore that serial too, then any enter events generated by mouse
1966 movement will be ignored until we create some further network traffic.
1967 Instead ignore up to NextRequest-1, then when we increment the serial,
1968 we will be *past* the range of ignored serials */
1969 event_ignore_enter_range(start
, NextRequest(ob_display
)-1);
1972 static gboolean
is_enter_focus_event_ignored(gulong serial
)
1976 for (it
= ignore_serials
; it
; it
= next
) {
1977 ObSerialRange
*r
= it
->data
;
1979 next
= g_slist_next(it
);
1981 if ((glong
)(serial
- r
->end
) > 0) {
1983 ignore_serials
= g_slist_delete_link(ignore_serials
, it
);
1986 else if ((glong
)(serial
- r
->start
) >= 0)
1992 void event_cancel_all_key_grabs(void)
1994 if (actions_interactive_act_running()) {
1995 actions_interactive_cancel_act();
1996 ob_debug("KILLED interactive action\n");
1998 else if (menu_frame_visible
) {
1999 menu_frame_hide_all();
2000 ob_debug("KILLED open menus\n");
2002 else if (moveresize_in_progress
) {
2003 moveresize_end(TRUE
);
2004 ob_debug("KILLED interactive moveresize\n");
2006 else if (grab_on_keyboard()) {
2008 ob_debug("KILLED active grab on keyboard\n");
2011 ungrab_passive_key();
2013 XSync(ob_display
, FALSE
);
2016 gboolean
event_time_after(Time t1
, Time t2
)
2018 g_assert(t1
!= CurrentTime
);
2019 g_assert(t2
!= CurrentTime
);
2022 Timestamp values wrap around (after about 49.7 days). The server, given
2023 its current time is represented by timestamp T, always interprets
2024 timestamps from clients by treating half of the timestamp space as being
2025 later in time than T.
2026 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
2029 /* TIME_HALF is half of the number space of a Time type variable */
2030 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
2032 if (t2
>= TIME_HALF
)
2033 /* t2 is in the second half so t1 might wrap around and be smaller than
2035 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
2037 /* t2 is in the first half so t1 has to come after it */
2038 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);
2041 Time
event_get_server_time(void)
2043 /* Generate a timestamp */
2046 XChangeProperty(ob_display
, screen_support_win
,
2047 prop_atoms
.wm_class
, prop_atoms
.string
,
2048 8, PropModeAppend
, NULL
, 0);
2049 XWindowEvent(ob_display
, screen_support_win
, PropertyChangeMask
, &event
);
2050 return event
.xproperty
.time
;