1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 event.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
33 #include "menuframe.h"
39 #include "framerender.h"
41 #include "focus_cycle.h"
42 #include "moveresize.h"
45 #include "extensions.h"
46 #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>
82 gulong start
; /* inclusive */
83 gulong end
; /* inclusive */
86 static void event_process(const XEvent
*e
, gpointer data
);
87 static void event_handle_root(XEvent
*e
);
88 static gboolean
event_handle_menu_keyboard(XEvent
*e
);
89 static gboolean
event_handle_menu(XEvent
*e
);
90 static void event_handle_dock(ObDock
*s
, XEvent
*e
);
91 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
);
92 static void event_handle_client(ObClient
*c
, XEvent
*e
);
93 static void event_handle_user_time_window_clients(GSList
*l
, XEvent
*e
);
94 static void event_handle_user_input(ObClient
*client
, XEvent
*e
);
95 static gboolean
is_enter_focus_event_ignored(XEvent
*e
);
97 static void focus_delay_dest(gpointer data
);
98 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
);
99 static gboolean
focus_delay_func(gpointer data
);
100 static void focus_delay_client_dest(ObClient
*client
, gpointer data
);
102 /* The time for the current event being processed */
103 Time event_curtime
= CurrentTime
;
105 static gboolean focus_left_screen
= FALSE
;
106 /*! A list of ObSerialRanges which are to be ignored for mouse enter events */
107 static GSList
*ignore_serials
= NULL
;
110 static void ice_handler(gint fd
, gpointer conn
)
113 IceProcessMessages(conn
, NULL
, &b
);
116 static void ice_watch(IceConn conn
, IcePointer data
, Bool opening
,
117 IcePointer
*watch_data
)
122 fd
= IceConnectionNumber(conn
);
123 ob_main_loop_fd_add(ob_main_loop
, fd
, ice_handler
, conn
, NULL
);
125 ob_main_loop_fd_remove(ob_main_loop
, fd
);
131 void event_startup(gboolean reconfig
)
133 if (reconfig
) return;
135 ob_main_loop_x_add(ob_main_loop
, event_process
, NULL
, NULL
);
138 IceAddConnectionWatch(ice_watch
, NULL
);
141 client_add_destroy_notify(focus_delay_client_dest
, NULL
);
144 void event_shutdown(gboolean reconfig
)
146 if (reconfig
) return;
149 IceRemoveConnectionWatch(ice_watch
, NULL
);
152 client_remove_destroy_notify(focus_delay_client_dest
);
155 static Window
event_get_window(XEvent
*e
)
162 window
= RootWindow(ob_display
, ob_screen
);
165 window
= e
->xmap
.window
;
168 window
= e
->xunmap
.window
;
171 window
= e
->xdestroywindow
.window
;
173 case ConfigureRequest
:
174 window
= e
->xconfigurerequest
.window
;
176 case ConfigureNotify
:
177 window
= e
->xconfigure
.window
;
181 if (extensions_xkb
&& e
->type
== extensions_xkb_event_basep
) {
182 switch (((XkbAnyEvent
*)e
)->xkb_type
) {
184 window
= ((XkbBellNotifyEvent
*)e
)->window
;
191 if (extensions_sync
&&
192 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
197 window
= e
->xany
.window
;
202 static void event_set_curtime(XEvent
*e
)
204 Time t
= CurrentTime
;
206 /* grab the lasttime and hack up the state */
222 t
= e
->xproperty
.time
;
226 t
= e
->xcrossing
.time
;
230 if (extensions_sync
&&
231 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
233 t
= ((XSyncAlarmNotifyEvent
*)e
)->time
;
236 /* if more event types are anticipated, get their timestamp
244 static void event_hack_mods(XEvent
*e
)
247 XkbStateRec xkb_state
;
253 e
->xbutton
.state
= modkeys_only_modifier_masks(e
->xbutton
.state
);
256 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
259 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
261 if (XkbGetState(ob_display
, XkbUseCoreKbd
, &xkb_state
) == Success
) {
262 e
->xkey
.state
= xkb_state
.compat_state
;
266 /* remove from the state the mask of the modifier key being released,
267 if it is a modifier key being released that is */
268 e
->xkey
.state
&= ~modkeys_keycode_to_mask(e
->xkey
.keycode
);
271 e
->xmotion
.state
= modkeys_only_modifier_masks(e
->xmotion
.state
);
272 /* compress events */
275 while (XCheckTypedWindowEvent(ob_display
, e
->xmotion
.window
,
277 e
->xmotion
.x
= ce
.xmotion
.x
;
278 e
->xmotion
.y
= ce
.xmotion
.y
;
279 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
280 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
287 static gboolean
wanted_focusevent(XEvent
*e
, gboolean in_client_only
)
289 gint mode
= e
->xfocus
.mode
;
290 gint detail
= e
->xfocus
.detail
;
291 Window win
= e
->xany
.window
;
293 if (e
->type
== FocusIn
) {
294 /* These are ones we never want.. */
296 /* This means focus was given by a keyboard/mouse grab. */
297 if (mode
== NotifyGrab
)
299 /* This means focus was given back from a keyboard/mouse grab. */
300 if (mode
== NotifyUngrab
)
303 /* These are the ones we want.. */
305 if (win
== RootWindow(ob_display
, ob_screen
)) {
306 /* If looking for a focus in on a client, then always return
307 FALSE for focus in's to the root window */
310 /* This means focus reverted off of a client */
311 else if (detail
== NotifyPointerRoot
||
312 detail
== NotifyDetailNone
||
313 detail
== NotifyInferior
||
314 /* This means focus got here from another screen */
315 detail
== NotifyNonlinear
)
321 /* It was on a client, was it a valid one?
322 It's possible to get a FocusIn event for a client that was managed
325 if (in_client_only
) {
326 ObWindow
*w
= g_hash_table_lookup(window_map
, &e
->xfocus
.window
);
327 if (!w
|| !WINDOW_IS_CLIENT(w
))
331 /* This means focus reverted to parent from the client (this
332 happens often during iconify animation) */
333 if (detail
== NotifyInferior
)
337 /* This means focus moved from the root window to a client */
338 if (detail
== NotifyVirtual
)
340 /* This means focus moved from one client to another */
341 if (detail
== NotifyNonlinearVirtual
)
347 g_assert(e
->type
== FocusOut
);
349 /* These are ones we never want.. */
351 /* This means focus was taken by a keyboard/mouse grab. */
352 if (mode
== NotifyGrab
)
354 /* This means focus was grabbed on a window and it was released. */
355 if (mode
== NotifyUngrab
)
358 /* Focus left the root window revertedto state */
359 if (win
== RootWindow(ob_display
, ob_screen
))
362 /* These are the ones we want.. */
364 /* This means focus moved from a client to the root window */
365 if (detail
== NotifyVirtual
)
367 /* This means focus moved from one client to another */
368 if (detail
== NotifyNonlinearVirtual
)
376 static Bool
event_look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
378 return e
->type
== FocusIn
&& wanted_focusevent(e
, FALSE
);
381 static Bool
event_look_for_focusin_client(Display
*d
, XEvent
*e
, XPointer arg
)
383 return e
->type
== FocusIn
&& wanted_focusevent(e
, TRUE
);
386 static void print_focusevent(XEvent
*e
)
388 gint mode
= e
->xfocus
.mode
;
389 gint detail
= e
->xfocus
.detail
;
390 Window win
= e
->xany
.window
;
391 const gchar
*modestr
, *detailstr
;
394 case NotifyNormal
: modestr
="NotifyNormal"; break;
395 case NotifyGrab
: modestr
="NotifyGrab"; break;
396 case NotifyUngrab
: modestr
="NotifyUngrab"; break;
397 case NotifyWhileGrabbed
: modestr
="NotifyWhileGrabbed"; break;
400 case NotifyAncestor
: detailstr
="NotifyAncestor"; break;
401 case NotifyVirtual
: detailstr
="NotifyVirtual"; break;
402 case NotifyInferior
: detailstr
="NotifyInferior"; break;
403 case NotifyNonlinear
: detailstr
="NotifyNonlinear"; break;
404 case NotifyNonlinearVirtual
: detailstr
="NotifyNonlinearVirtual"; break;
405 case NotifyPointer
: detailstr
="NotifyPointer"; break;
406 case NotifyPointerRoot
: detailstr
="NotifyPointerRoot"; break;
407 case NotifyDetailNone
: detailstr
="NotifyDetailNone"; break;
410 if (mode
== NotifyGrab
|| mode
== NotifyUngrab
)
415 ob_debug_type(OB_DEBUG_FOCUS
, "Focus%s 0x%x mode=%s detail=%s\n",
416 (e
->xfocus
.type
== FocusIn
? "In" : "Out"),
422 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
427 if (!wanted_focusevent(e
, FALSE
))
432 if (!wanted_focusevent(e
, FALSE
))
439 static void event_process(const XEvent
*ec
, gpointer data
)
442 ObClient
*client
= NULL
;
444 ObDockApp
*dockapp
= NULL
;
445 ObWindow
*obwin
= NULL
;
446 GSList
*timewinclients
= NULL
;
448 ObEventData
*ed
= data
;
450 /* make a copy we can mangle */
454 window
= event_get_window(e
);
455 if (e
->type
!= PropertyNotify
||
456 !(timewinclients
= propwin_get_clients(window
,
457 OB_PROPWIN_USER_TIME
)))
458 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
459 switch (obwin
->type
) {
461 dock
= WINDOW_AS_DOCK(obwin
);
464 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
467 client
= WINDOW_AS_CLIENT(obwin
);
470 case Window_Internal
:
471 /* not to be used for events */
472 g_assert_not_reached();
477 event_set_curtime(e
);
479 if (event_ignore(e
, client
)) {
486 /* deal with it in the kernel */
488 if (menu_frame_visible
&&
489 (e
->type
== EnterNotify
|| e
->type
== LeaveNotify
))
491 /* crossing events for menu */
492 event_handle_menu(e
);
493 } else if (e
->type
== FocusIn
) {
495 e
->xfocus
.detail
== NotifyInferior
)
497 ob_debug_type(OB_DEBUG_FOCUS
,
498 "Focus went to the frame window");
500 focus_left_screen
= FALSE
;
502 focus_fallback(FALSE
, FALSE
);
504 /* We don't get a FocusOut for this case, because it's just moving
505 from our Inferior up to us. This happens when iconifying a
506 window with RevertToParent focus */
507 frame_adjust_focus(client
->frame
, FALSE
);
508 /* focus_set_client(NULL) has already been called */
509 client_calc_layer(client
);
511 if (e
->xfocus
.detail
== NotifyPointerRoot
||
512 e
->xfocus
.detail
== NotifyDetailNone
||
513 e
->xfocus
.detail
== NotifyInferior
||
514 e
->xfocus
.detail
== NotifyNonlinear
)
518 ob_debug_type(OB_DEBUG_FOCUS
,
519 "Focus went to root or pointer root/none\n");
521 if (e
->xfocus
.detail
== NotifyInferior
||
522 e
->xfocus
.detail
== NotifyNonlinear
)
524 focus_left_screen
= FALSE
;
527 /* If another FocusIn is in the queue then don't fallback yet. This
528 fixes the fun case of:
529 window map -> send focusin
530 window unmap -> get focusout
531 window map -> send focusin
532 get first focus out -> fall back to something (new window
533 hasn't received focus yet, so something else) -> send focusin
534 which means the "something else" is the last thing to get a
535 focusin sent to it, so the new window doesn't end up with focus.
537 But if the other focus in is something like PointerRoot then we
538 still want to fall back.
540 if (XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin_client
,
543 XPutBackEvent(ob_display
, &ce
);
544 ob_debug_type(OB_DEBUG_FOCUS
,
545 " but another FocusIn is coming\n");
547 /* Focus has been reverted.
549 FocusOut events come after UnmapNotify, so we don't need to
550 worry about focusing an invalid window
553 if (!focus_left_screen
)
554 focus_fallback(FALSE
, FALSE
);
559 ob_debug_type(OB_DEBUG_FOCUS
,
560 "Focus went to a window that is already gone\n");
562 /* If you send focus to a window and then it disappears, you can
563 get the FocusIn for it, after it is unmanaged.
564 Just wait for the next FocusOut/FocusIn pair, but make note that
565 the window that was focused no longer is. */
566 focus_set_client(NULL
);
568 else if (client
!= focus_client
) {
569 focus_left_screen
= FALSE
;
570 frame_adjust_focus(client
->frame
, TRUE
);
571 focus_set_client(client
);
572 client_calc_layer(client
);
573 client_bring_helper_windows(client
);
575 } else if (e
->type
== FocusOut
) {
578 /* Look for the followup FocusIn */
579 if (!XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin
, NULL
)) {
580 /* There is no FocusIn, this means focus went to a window that
581 is not being managed, or a window on another screen. */
585 xerror_set_ignore(TRUE
);
586 if (XGetInputFocus(ob_display
, &win
, &i
) != 0 &&
587 XGetGeometry(ob_display
, win
, &root
, &i
,&i
,&u
,&u
,&u
,&u
) != 0 &&
588 root
!= RootWindow(ob_display
, ob_screen
))
590 ob_debug_type(OB_DEBUG_FOCUS
,
591 "Focus went to another screen !\n");
592 focus_left_screen
= TRUE
;
595 ob_debug_type(OB_DEBUG_FOCUS
,
596 "Focus went to a black hole !\n");
597 xerror_set_ignore(FALSE
);
598 /* nothing is focused */
599 focus_set_client(NULL
);
601 /* Focus moved, so process the FocusIn event */
602 ObEventData ed
= { .ignored
= FALSE
};
603 event_process(&ce
, &ed
);
605 /* The FocusIn was ignored, this means it was on a window
606 that isn't a client. */
607 ob_debug_type(OB_DEBUG_FOCUS
,
608 "Focus went to an unmanaged window 0x%x !\n",
610 focus_fallback(TRUE
, FALSE
);
614 if (client
&& client
!= focus_client
) {
615 frame_adjust_focus(client
->frame
, FALSE
);
616 /* focus_set_client(NULL) has already been called in this
617 section or by focus_fallback */
618 client_calc_layer(client
);
620 } else if (timewinclients
)
621 event_handle_user_time_window_clients(timewinclients
, e
);
623 event_handle_client(client
, e
);
625 event_handle_dockapp(dockapp
, e
);
627 event_handle_dock(dock
, e
);
628 else if (window
== RootWindow(ob_display
, ob_screen
))
629 event_handle_root(e
);
630 else if (e
->type
== MapRequest
)
631 client_manage(window
);
632 else if (e
->type
== ClientMessage
) {
633 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
634 windows that are not managed yet. */
635 if (e
->xclient
.message_type
== prop_atoms
.net_request_frame_extents
) {
636 /* Pretend to manage the client, getting information used to
637 determine its decorations */
638 ObClient
*c
= client_fake_manage(e
->xclient
.window
);
641 /* set the frame extents on the window */
642 vals
[0] = c
->frame
->size
.left
;
643 vals
[1] = c
->frame
->size
.right
;
644 vals
[2] = c
->frame
->size
.top
;
645 vals
[3] = c
->frame
->size
.bottom
;
646 PROP_SETA32(e
->xclient
.window
, net_frame_extents
,
649 /* Free the pretend client */
650 client_fake_unmanage(c
);
653 else if (e
->type
== ConfigureRequest
) {
654 /* unhandled configure requests must be used to configure the
658 xwc
.x
= e
->xconfigurerequest
.x
;
659 xwc
.y
= e
->xconfigurerequest
.y
;
660 xwc
.width
= e
->xconfigurerequest
.width
;
661 xwc
.height
= e
->xconfigurerequest
.height
;
662 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
663 xwc
.sibling
= e
->xconfigurerequest
.above
;
664 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
666 /* we are not to be held responsible if someone sends us an
668 xerror_set_ignore(TRUE
);
669 XConfigureWindow(ob_display
, window
,
670 e
->xconfigurerequest
.value_mask
, &xwc
);
671 xerror_set_ignore(FALSE
);
674 else if (extensions_sync
&&
675 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
677 XSyncAlarmNotifyEvent
*se
= (XSyncAlarmNotifyEvent
*)e
;
678 if (se
->alarm
== moveresize_alarm
&& moveresize_in_progress
)
683 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
684 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
685 e
->type
== KeyRelease
)
687 event_handle_user_input(client
, e
);
690 /* if something happens and it's not from an XEvent, then we don't know
692 event_curtime
= CurrentTime
;
695 static void event_handle_root(XEvent
*e
)
701 ob_debug("Another WM has requested to replace us. Exiting.\n");
706 if (e
->xclient
.format
!= 32) break;
708 msgtype
= e
->xclient
.message_type
;
709 if (msgtype
== prop_atoms
.net_current_desktop
) {
710 guint d
= e
->xclient
.data
.l
[0];
711 if (d
< screen_num_desktops
) {
712 event_curtime
= e
->xclient
.data
.l
[1];
713 if (event_curtime
== 0)
714 ob_debug_type(OB_DEBUG_APP_BUGS
,
715 "_NET_CURRENT_DESKTOP message is missing "
717 screen_set_desktop(d
, TRUE
);
719 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
720 guint d
= e
->xclient
.data
.l
[0];
721 if (d
> 0 && d
<= 1000)
722 screen_set_num_desktops(d
);
723 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
724 screen_show_desktop(e
->xclient
.data
.l
[0] != 0, NULL
);
725 } else if (msgtype
== prop_atoms
.ob_control
) {
726 if (e
->xclient
.data
.l
[0] == 1)
728 else if (e
->xclient
.data
.l
[0] == 2)
733 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
)
734 screen_update_desktop_names();
735 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
736 screen_update_layout();
738 case ConfigureNotify
:
740 XRRUpdateConfiguration(e
);
749 void event_enter_client(ObClient
*client
)
751 g_assert(config_focus_follow
);
753 if (client_enter_focusable(client
) && client_can_focus(client
)) {
754 if (config_focus_delay
) {
755 ObFocusDelayData
*data
;
757 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
759 data
= g_new(ObFocusDelayData
, 1);
760 data
->client
= client
;
761 data
->time
= event_curtime
;
763 ob_main_loop_timeout_add(ob_main_loop
,
766 data
, focus_delay_cmp
, focus_delay_dest
);
768 ObFocusDelayData data
;
769 data
.client
= client
;
770 data
.time
= event_curtime
;
771 focus_delay_func(&data
);
776 static void event_handle_user_time_window_clients(GSList
*l
, XEvent
*e
)
778 g_assert(e
->type
== PropertyNotify
);
779 if (e
->xproperty
.atom
== prop_atoms
.net_wm_user_time
) {
780 for (; l
; l
= g_slist_next(l
))
781 client_update_user_time(l
->data
);
785 static void event_handle_client(ObClient
*client
, XEvent
*e
)
790 static gint px
= -1, py
= -1;
795 /* save where the press occured for the first button pressed */
797 pb
= e
->xbutton
.button
;
802 /* Wheel buttons don't draw because they are an instant click, so it
803 is a waste of resources to go drawing it.
804 if the user is doing an intereactive thing, or has a menu open then
805 the mouse is grabbed (possibly) and if we get these events we don't
806 want to deal with them
808 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5) &&
809 !keyboard_interactively_grabbed() &&
812 /* use where the press occured */
813 con
= frame_context(client
, e
->xbutton
.window
, px
, py
);
814 con
= mouse_button_frame_context(con
, e
->xbutton
.button
,
817 if (e
->type
== ButtonRelease
&& e
->xbutton
.button
== pb
)
818 pb
= 0, px
= py
= -1;
821 case OB_FRAME_CONTEXT_MAXIMIZE
:
822 client
->frame
->max_press
= (e
->type
== ButtonPress
);
823 framerender_frame(client
->frame
);
825 case OB_FRAME_CONTEXT_CLOSE
:
826 client
->frame
->close_press
= (e
->type
== ButtonPress
);
827 framerender_frame(client
->frame
);
829 case OB_FRAME_CONTEXT_ICONIFY
:
830 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
831 framerender_frame(client
->frame
);
833 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
834 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
835 framerender_frame(client
->frame
);
837 case OB_FRAME_CONTEXT_SHADE
:
838 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
839 framerender_frame(client
->frame
);
842 /* nothing changes with clicks for any other contexts */
848 /* when there is a grab on the pointer, we won't get enter/leave
849 notifies, but we still get motion events */
850 if (grab_on_pointer()) break;
852 con
= frame_context(client
, e
->xmotion
.window
,
853 e
->xmotion
.x
, e
->xmotion
.y
);
855 case OB_FRAME_CONTEXT_TITLEBAR
:
856 case OB_FRAME_CONTEXT_TLCORNER
:
857 case OB_FRAME_CONTEXT_TRCORNER
:
858 /* we've left the button area inside the titlebar */
859 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
860 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
861 client
->frame
->close_hover
)
863 client
->frame
->max_hover
= FALSE
;
864 client
->frame
->desk_hover
= FALSE
;
865 client
->frame
->shade_hover
= FALSE
;
866 client
->frame
->iconify_hover
= FALSE
;
867 client
->frame
->close_hover
= FALSE
;
868 frame_adjust_state(client
->frame
);
871 case OB_FRAME_CONTEXT_MAXIMIZE
:
872 if (!client
->frame
->max_hover
) {
873 client
->frame
->max_hover
= TRUE
;
874 frame_adjust_state(client
->frame
);
877 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
878 if (!client
->frame
->desk_hover
) {
879 client
->frame
->desk_hover
= TRUE
;
880 frame_adjust_state(client
->frame
);
883 case OB_FRAME_CONTEXT_SHADE
:
884 if (!client
->frame
->shade_hover
) {
885 client
->frame
->shade_hover
= TRUE
;
886 frame_adjust_state(client
->frame
);
889 case OB_FRAME_CONTEXT_ICONIFY
:
890 if (!client
->frame
->iconify_hover
) {
891 client
->frame
->iconify_hover
= TRUE
;
892 frame_adjust_state(client
->frame
);
895 case OB_FRAME_CONTEXT_CLOSE
:
896 if (!client
->frame
->close_hover
) {
897 client
->frame
->close_hover
= TRUE
;
898 frame_adjust_state(client
->frame
);
906 con
= frame_context(client
, e
->xcrossing
.window
,
907 e
->xcrossing
.x
, e
->xcrossing
.y
);
909 case OB_FRAME_CONTEXT_TITLEBAR
:
910 case OB_FRAME_CONTEXT_TLCORNER
:
911 case OB_FRAME_CONTEXT_TRCORNER
:
912 /* we've left the button area inside the titlebar */
913 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
914 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
915 client
->frame
->close_hover
)
917 client
->frame
->max_hover
= FALSE
;
918 client
->frame
->desk_hover
= FALSE
;
919 client
->frame
->shade_hover
= FALSE
;
920 client
->frame
->iconify_hover
= FALSE
;
921 client
->frame
->close_hover
= FALSE
;
922 frame_adjust_state(client
->frame
);
925 case OB_FRAME_CONTEXT_MAXIMIZE
:
926 client
->frame
->max_hover
= FALSE
;
927 frame_adjust_state(client
->frame
);
929 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
930 client
->frame
->desk_hover
= FALSE
;
931 frame_adjust_state(client
->frame
);
933 case OB_FRAME_CONTEXT_SHADE
:
934 client
->frame
->shade_hover
= FALSE
;
935 frame_adjust_state(client
->frame
);
937 case OB_FRAME_CONTEXT_ICONIFY
:
938 client
->frame
->iconify_hover
= FALSE
;
939 frame_adjust_state(client
->frame
);
941 case OB_FRAME_CONTEXT_CLOSE
:
942 client
->frame
->close_hover
= FALSE
;
943 frame_adjust_state(client
->frame
);
945 case OB_FRAME_CONTEXT_FRAME
:
946 /* When the mouse leaves an animating window, don't use the
947 corresponding enter events. Pretend like the animating window
948 doesn't even exist..! */
949 if (frame_iconify_animating(client
->frame
))
950 event_end_ignore_all_enters(event_start_ignore_all_enters());
952 ob_debug_type(OB_DEBUG_FOCUS
,
953 "%sNotify mode %d detail %d on %lx\n",
954 (e
->type
== EnterNotify
? "Enter" : "Leave"),
956 e
->xcrossing
.detail
, (client
?client
->window
:0));
957 if (keyboard_interactively_grabbed())
959 if (config_focus_follow
&& config_focus_delay
&&
960 /* leave inferior events can happen when the mouse goes onto
961 the window's border and then into the window before the
963 e
->xcrossing
.detail
!= NotifyInferior
)
965 ob_main_loop_timeout_remove_data(ob_main_loop
,
976 con
= frame_context(client
, e
->xcrossing
.window
,
977 e
->xcrossing
.x
, e
->xcrossing
.y
);
979 case OB_FRAME_CONTEXT_MAXIMIZE
:
980 client
->frame
->max_hover
= TRUE
;
981 frame_adjust_state(client
->frame
);
983 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
984 client
->frame
->desk_hover
= TRUE
;
985 frame_adjust_state(client
->frame
);
987 case OB_FRAME_CONTEXT_SHADE
:
988 client
->frame
->shade_hover
= TRUE
;
989 frame_adjust_state(client
->frame
);
991 case OB_FRAME_CONTEXT_ICONIFY
:
992 client
->frame
->iconify_hover
= TRUE
;
993 frame_adjust_state(client
->frame
);
995 case OB_FRAME_CONTEXT_CLOSE
:
996 client
->frame
->close_hover
= TRUE
;
997 frame_adjust_state(client
->frame
);
999 case OB_FRAME_CONTEXT_FRAME
:
1000 if (keyboard_interactively_grabbed())
1002 if (e
->xcrossing
.mode
== NotifyGrab
||
1003 e
->xcrossing
.mode
== NotifyUngrab
||
1004 /*ignore enters when we're already in the window */
1005 e
->xcrossing
.detail
== NotifyInferior
||
1006 is_enter_focus_event_ignored(e
))
1008 ob_debug_type(OB_DEBUG_FOCUS
,
1009 "%sNotify mode %d detail %d on %lx IGNORED\n",
1010 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1012 e
->xcrossing
.detail
, client
?client
->window
:0);
1015 ob_debug_type(OB_DEBUG_FOCUS
,
1016 "%sNotify mode %d detail %d on %lx, "
1017 "focusing window\n",
1018 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1020 e
->xcrossing
.detail
, (client
?client
->window
:0));
1021 if (config_focus_follow
)
1022 event_enter_client(client
);
1030 case ConfigureRequest
:
1032 /* dont compress these unless you're going to watch for property
1033 notifies in between (these can change what the configure would
1035 also you can't compress stacking events
1039 gboolean move
= FALSE
;
1040 gboolean resize
= FALSE
;
1042 /* get the current area */
1043 RECT_TO_DIMS(client
->area
, x
, y
, w
, h
);
1045 ob_debug("ConfigureRequest for \"%s\" desktop %d wmstate %d "
1047 " x %d y %d w %d h %d b %d\n",
1049 screen_desktop
, client
->wmstate
, client
->frame
->visible
,
1050 x
, y
, w
, h
, client
->border_width
);
1052 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
1053 if (client
->border_width
!= e
->xconfigurerequest
.border_width
) {
1054 client
->border_width
= e
->xconfigurerequest
.border_width
;
1056 /* if the border width is changing then that is the same
1057 as requesting a resize, but we don't actually change
1058 the client's border, so it will change their root
1059 coordiantes (since they include the border width) and
1060 we need to a notify then */
1065 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
1066 ObClient
*sibling
= NULL
;
1067 gulong ignore_start
;
1069 /* get the sibling */
1070 if (e
->xconfigurerequest
.value_mask
& CWSibling
) {
1072 win
= g_hash_table_lookup(window_map
,
1073 &e
->xconfigurerequest
.above
);
1074 if (WINDOW_IS_CLIENT(win
) && WINDOW_AS_CLIENT(win
) != client
)
1075 sibling
= WINDOW_AS_CLIENT(win
);
1078 /* activate it rather than just focus it */
1079 if (!config_focus_under_mouse
)
1080 ignore_start
= event_start_ignore_all_enters();
1081 stacking_restack_request(client
, sibling
,
1082 e
->xconfigurerequest
.detail
,
1084 if (!config_focus_under_mouse
)
1085 event_end_ignore_all_enters(ignore_start
);
1087 /* if a stacking change moves the window without resizing */
1091 if ((e
->xconfigurerequest
.value_mask
& CWX
) ||
1092 (e
->xconfigurerequest
.value_mask
& CWY
) ||
1093 (e
->xconfigurerequest
.value_mask
& CWWidth
) ||
1094 (e
->xconfigurerequest
.value_mask
& CWHeight
))
1096 if (e
->xconfigurerequest
.value_mask
& CWX
) {
1097 /* don't allow clients to move shaded windows (fvwm does this)
1099 if (!client
->shaded
)
1100 x
= e
->xconfigurerequest
.x
;
1103 if (e
->xconfigurerequest
.value_mask
& CWY
) {
1104 /* don't allow clients to move shaded windows (fvwm does this)
1106 if (!client
->shaded
)
1107 y
= e
->xconfigurerequest
.y
;
1111 if (e
->xconfigurerequest
.value_mask
& CWWidth
) {
1112 w
= e
->xconfigurerequest
.width
;
1115 if (e
->xconfigurerequest
.value_mask
& CWHeight
) {
1116 h
= e
->xconfigurerequest
.height
;
1121 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
1122 "move %d resize %d\n",
1123 e
->xconfigurerequest
.value_mask
& CWX
, x
,
1124 e
->xconfigurerequest
.value_mask
& CWY
, y
,
1125 e
->xconfigurerequest
.value_mask
& CWWidth
, w
,
1126 e
->xconfigurerequest
.value_mask
& CWHeight
, h
,
1129 /* check for broken apps moving to their root position
1131 XXX remove this some day...that would be nice. right now all
1132 kde apps do this when they try activate themselves on another
1133 desktop. eg. open amarok window on desktop 1, switch to desktop
1134 2, click amarok tray icon. it will move by its decoration size.
1136 if (x
!= client
->area
.x
&&
1137 x
== (client
->frame
->area
.x
+ client
->frame
->size
.left
-
1138 (gint
)client
->border_width
) &&
1139 y
!= client
->area
.y
&&
1140 y
== (client
->frame
->area
.y
+ client
->frame
->size
.top
-
1141 (gint
)client
->border_width
) &&
1142 w
== client
->area
.width
&&
1143 h
== client
->area
.height
)
1145 ob_debug_type(OB_DEBUG_APP_BUGS
,
1146 "Application %s is trying to move via "
1147 "ConfigureRequest to it's root window position "
1148 "but it is not using StaticGravity\n",
1154 /* they still requested a move, so don't change whether a
1155 notify is sent or not */
1158 if (move
|| resize
) {
1161 client_try_configure(client
, &x
, &y
, &w
, &h
, &lw
, &lh
, FALSE
);
1163 /* if x was not given, then use gravity to figure out the new
1164 x. the reference point should not be moved */
1165 if ((e
->xconfigurerequest
.value_mask
& CWWidth
&&
1166 !(e
->xconfigurerequest
.value_mask
& CWX
)))
1167 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1168 /* if y was not given, then use gravity to figure out the new
1169 y. the reference point should not be moved */
1170 if ((e
->xconfigurerequest
.value_mask
& CWHeight
&&
1171 !(e
->xconfigurerequest
.value_mask
& CWY
)))
1172 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1174 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1176 /* if they requested something that moves the window, or if
1177 the window is actually being changed then configure it and
1178 send a configure notify to them */
1179 if (move
|| !RECT_EQUAL_DIMS(client
->area
, x
, y
, w
, h
)) {
1180 gulong ignore_start
;
1182 ob_debug("Granting ConfigureRequest x %d y %d w %d h %d\n",
1184 ignore_start
= event_start_ignore_all_enters();
1185 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1186 event_end_ignore_all_enters(ignore_start
);
1192 if (client
->ignore_unmaps
) {
1193 client
->ignore_unmaps
--;
1196 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1197 "ignores left %d\n",
1198 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
1199 client
->ignore_unmaps
);
1200 client_unmanage(client
);
1203 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
1204 client_unmanage(client
);
1206 case ReparentNotify
:
1207 /* this is when the client is first taken captive in the frame */
1208 if (e
->xreparent
.parent
== client
->frame
->window
) break;
1211 This event is quite rare and is usually handled in unmapHandler.
1212 However, if the window is unmapped when the reparent event occurs,
1213 the window manager never sees it because an unmap event is not sent
1214 to an already unmapped window.
1217 /* we don't want the reparent event, put it back on the stack for the
1218 X server to deal with after we unmanage the window */
1219 XPutBackEvent(ob_display
, e
);
1221 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
1222 client_unmanage(client
);
1225 ob_debug("MapRequest for 0x%lx\n", client
->window
);
1226 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
1227 does, we don't want it!
1228 it can happen now when the window is on
1229 another desktop, but we still don't
1231 client_activate(client
, FALSE
, TRUE
);
1234 /* validate cuz we query stuff off the client here */
1235 if (!client_validate(client
)) break;
1237 if (e
->xclient
.format
!= 32) return;
1239 msgtype
= e
->xclient
.message_type
;
1240 if (msgtype
== prop_atoms
.wm_change_state
) {
1241 /* compress changes into a single change */
1242 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1244 /* XXX: it would be nice to compress ALL messages of a
1245 type, not just messages in a row without other
1246 message types between. */
1247 if (ce
.xclient
.message_type
!= msgtype
) {
1248 XPutBackEvent(ob_display
, &ce
);
1251 e
->xclient
= ce
.xclient
;
1253 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1254 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
1255 /* compress changes into a single change */
1256 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1258 /* XXX: it would be nice to compress ALL messages of a
1259 type, not just messages in a row without other
1260 message types between. */
1261 if (ce
.xclient
.message_type
!= msgtype
) {
1262 XPutBackEvent(ob_display
, &ce
);
1265 e
->xclient
= ce
.xclient
;
1267 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1268 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1269 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1271 } else if (msgtype
== prop_atoms
.net_wm_state
) {
1272 gulong ignore_start
;
1274 /* can't compress these */
1275 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1276 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1277 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1278 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1279 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1282 /* ignore enter events caused by these like ob actions do */
1283 if (!config_focus_under_mouse
)
1284 ignore_start
= event_start_ignore_all_enters();
1285 client_set_state(client
, e
->xclient
.data
.l
[0],
1286 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1287 if (!config_focus_under_mouse
)
1288 event_end_ignore_all_enters(ignore_start
);
1289 } else if (msgtype
== prop_atoms
.net_close_window
) {
1290 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1291 client_close(client
);
1292 } else if (msgtype
== prop_atoms
.net_active_window
) {
1293 ob_debug("net_active_window for 0x%lx source=%s\n",
1295 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1296 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1297 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1298 /* XXX make use of data.l[2] !? */
1299 if (e
->xclient
.data
.l
[0] == 1 || e
->xclient
.data
.l
[0] == 2) {
1300 event_curtime
= e
->xclient
.data
.l
[1];
1301 if (event_curtime
== 0)
1302 ob_debug_type(OB_DEBUG_APP_BUGS
,
1303 "_NET_ACTIVE_WINDOW message for window %s is"
1304 " missing a timestamp\n", client
->title
);
1306 ob_debug_type(OB_DEBUG_APP_BUGS
,
1307 "_NET_ACTIVE_WINDOW message for window %s is "
1308 "missing source indication\n");
1309 client_activate(client
, FALSE
,
1310 (e
->xclient
.data
.l
[0] == 0 ||
1311 e
->xclient
.data
.l
[0] == 2));
1312 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1313 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1314 client
->window
, e
->xclient
.data
.l
[2]);
1315 if ((Atom
)e
->xclient
.data
.l
[2] ==
1316 prop_atoms
.net_wm_moveresize_size_topleft
||
1317 (Atom
)e
->xclient
.data
.l
[2] ==
1318 prop_atoms
.net_wm_moveresize_size_top
||
1319 (Atom
)e
->xclient
.data
.l
[2] ==
1320 prop_atoms
.net_wm_moveresize_size_topright
||
1321 (Atom
)e
->xclient
.data
.l
[2] ==
1322 prop_atoms
.net_wm_moveresize_size_right
||
1323 (Atom
)e
->xclient
.data
.l
[2] ==
1324 prop_atoms
.net_wm_moveresize_size_right
||
1325 (Atom
)e
->xclient
.data
.l
[2] ==
1326 prop_atoms
.net_wm_moveresize_size_bottomright
||
1327 (Atom
)e
->xclient
.data
.l
[2] ==
1328 prop_atoms
.net_wm_moveresize_size_bottom
||
1329 (Atom
)e
->xclient
.data
.l
[2] ==
1330 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1331 (Atom
)e
->xclient
.data
.l
[2] ==
1332 prop_atoms
.net_wm_moveresize_size_left
||
1333 (Atom
)e
->xclient
.data
.l
[2] ==
1334 prop_atoms
.net_wm_moveresize_move
||
1335 (Atom
)e
->xclient
.data
.l
[2] ==
1336 prop_atoms
.net_wm_moveresize_size_keyboard
||
1337 (Atom
)e
->xclient
.data
.l
[2] ==
1338 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1340 moveresize_start(client
, e
->xclient
.data
.l
[0],
1341 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1342 e
->xclient
.data
.l
[2]);
1344 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1345 prop_atoms
.net_wm_moveresize_cancel
)
1346 moveresize_end(TRUE
);
1347 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1348 gint ograv
, x
, y
, w
, h
;
1349 gulong ignore_start
;
1351 ograv
= client
->gravity
;
1353 if (e
->xclient
.data
.l
[0] & 0xff)
1354 client
->gravity
= e
->xclient
.data
.l
[0] & 0xff;
1356 if (e
->xclient
.data
.l
[0] & 1 << 8)
1357 x
= e
->xclient
.data
.l
[1];
1360 if (e
->xclient
.data
.l
[0] & 1 << 9)
1361 y
= e
->xclient
.data
.l
[2];
1365 if (e
->xclient
.data
.l
[0] & 1 << 10) {
1366 w
= e
->xclient
.data
.l
[3];
1368 /* if x was not given, then use gravity to figure out the new
1369 x. the reference point should not be moved */
1370 if (!(e
->xclient
.data
.l
[0] & 1 << 8))
1371 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1374 w
= client
->area
.width
;
1376 if (e
->xclient
.data
.l
[0] & 1 << 11) {
1377 h
= e
->xclient
.data
.l
[4];
1379 /* if y was not given, then use gravity to figure out the new
1380 y. the reference point should not be moved */
1381 if (!(e
->xclient
.data
.l
[0] & 1 << 9))
1382 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1385 h
= client
->area
.height
;
1387 ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)\n",
1388 e
->xclient
.data
.l
[0] & 1 << 8, x
,
1389 e
->xclient
.data
.l
[0] & 1 << 9, y
,
1392 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1394 /* ignore enter events caused by these like ob actions do */
1395 ignore_start
= event_start_ignore_all_enters();
1396 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1397 event_end_ignore_all_enters(ignore_start
);
1399 client
->gravity
= ograv
;
1400 } else if (msgtype
== prop_atoms
.net_restack_window
) {
1401 if (e
->xclient
.data
.l
[0] != 2) {
1402 ob_debug_type(OB_DEBUG_APP_BUGS
,
1403 "_NET_RESTACK_WINDOW sent for window %s with "
1404 "invalid source indication %ld\n",
1405 client
->title
, e
->xclient
.data
.l
[0]);
1407 ObClient
*sibling
= NULL
;
1408 if (e
->xclient
.data
.l
[1]) {
1409 ObWindow
*win
= g_hash_table_lookup
1410 (window_map
, &e
->xclient
.data
.l
[1]);
1411 if (WINDOW_IS_CLIENT(win
) &&
1412 WINDOW_AS_CLIENT(win
) != client
)
1414 sibling
= WINDOW_AS_CLIENT(win
);
1416 if (sibling
== NULL
)
1417 ob_debug_type(OB_DEBUG_APP_BUGS
,
1418 "_NET_RESTACK_WINDOW sent for window %s "
1419 "with invalid sibling 0x%x\n",
1420 client
->title
, e
->xclient
.data
.l
[1]);
1422 if (e
->xclient
.data
.l
[2] == Below
||
1423 e
->xclient
.data
.l
[2] == BottomIf
||
1424 e
->xclient
.data
.l
[2] == Above
||
1425 e
->xclient
.data
.l
[2] == TopIf
||
1426 e
->xclient
.data
.l
[2] == Opposite
)
1428 gulong ignore_start
;
1430 if (!config_focus_under_mouse
)
1431 ignore_start
= event_start_ignore_all_enters();
1432 /* just raise, don't activate */
1433 stacking_restack_request(client
, sibling
,
1434 e
->xclient
.data
.l
[2], FALSE
);
1435 if (!config_focus_under_mouse
)
1436 event_end_ignore_all_enters(ignore_start
);
1438 /* send a synthetic ConfigureNotify, cuz this is supposed
1439 to be like a ConfigureRequest. */
1440 client_reconfigure(client
);
1442 ob_debug_type(OB_DEBUG_APP_BUGS
,
1443 "_NET_RESTACK_WINDOW sent for window %s "
1444 "with invalid detail %d\n",
1445 client
->title
, e
->xclient
.data
.l
[2]);
1449 case PropertyNotify
:
1450 /* validate cuz we query stuff off the client here */
1451 if (!client_validate(client
)) break;
1453 /* compress changes to a single property into a single change */
1454 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1458 /* XXX: it would be nice to compress ALL changes to a property,
1459 not just changes in a row without other props between. */
1461 a
= ce
.xproperty
.atom
;
1462 b
= e
->xproperty
.atom
;
1466 if ((a
== prop_atoms
.net_wm_name
||
1467 a
== prop_atoms
.wm_name
||
1468 a
== prop_atoms
.net_wm_icon_name
||
1469 a
== prop_atoms
.wm_icon_name
)
1471 (b
== prop_atoms
.net_wm_name
||
1472 b
== prop_atoms
.wm_name
||
1473 b
== prop_atoms
.net_wm_icon_name
||
1474 b
== prop_atoms
.wm_icon_name
)) {
1477 if (a
== prop_atoms
.net_wm_icon
&&
1478 b
== prop_atoms
.net_wm_icon
)
1481 XPutBackEvent(ob_display
, &ce
);
1485 msgtype
= e
->xproperty
.atom
;
1486 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1487 client_update_normal_hints(client
);
1488 /* normal hints can make a window non-resizable */
1489 client_setup_decor_and_functions(client
, TRUE
);
1490 } else if (msgtype
== XA_WM_HINTS
) {
1491 client_update_wmhints(client
);
1492 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1493 client_update_transient_for(client
);
1494 client_get_type_and_transientness(client
);
1495 /* type may have changed, so update the layer */
1496 client_calc_layer(client
);
1497 client_setup_decor_and_functions(client
, TRUE
);
1498 } else if (msgtype
== prop_atoms
.net_wm_name
||
1499 msgtype
== prop_atoms
.wm_name
||
1500 msgtype
== prop_atoms
.net_wm_icon_name
||
1501 msgtype
== prop_atoms
.wm_icon_name
) {
1502 client_update_title(client
);
1503 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1504 client_update_protocols(client
);
1505 client_setup_decor_and_functions(client
, TRUE
);
1507 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1508 client_update_strut(client
);
1510 else if (msgtype
== prop_atoms
.net_wm_strut_partial
) {
1511 client_update_strut(client
);
1513 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1514 client_update_icons(client
);
1516 else if (msgtype
== prop_atoms
.net_wm_icon_geometry
) {
1517 client_update_icon_geometry(client
);
1519 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1520 client_update_user_time(client
);
1522 else if (msgtype
== prop_atoms
.net_wm_user_time_window
) {
1523 client_update_user_time_window(client
);
1526 else if (msgtype
== prop_atoms
.net_wm_sync_request_counter
) {
1527 client_update_sync_request_counter(client
);
1531 case ColormapNotify
:
1532 client_update_colormap(client
, e
->xcolormap
.colormap
);
1537 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1538 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1539 frame_adjust_shape(client
->frame
);
1545 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1549 if (e
->xbutton
.button
== 1)
1550 stacking_raise(DOCK_AS_WINDOW(s
));
1551 else if (e
->xbutton
.button
== 2)
1552 stacking_lower(DOCK_AS_WINDOW(s
));
1558 /* don't hide when moving into a dock app */
1559 if (e
->xcrossing
.detail
!= NotifyInferior
)
1565 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1569 dock_app_drag(app
, &e
->xmotion
);
1572 if (app
->ignore_unmaps
) {
1573 app
->ignore_unmaps
--;
1576 dock_remove(app
, TRUE
);
1579 dock_remove(app
, FALSE
);
1581 case ReparentNotify
:
1582 dock_remove(app
, FALSE
);
1584 case ConfigureNotify
:
1585 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1590 static ObMenuFrame
* find_active_menu()
1593 ObMenuFrame
*ret
= NULL
;
1595 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1604 static ObMenuFrame
* find_active_or_last_menu()
1606 ObMenuFrame
*ret
= NULL
;
1608 ret
= find_active_menu();
1609 if (!ret
&& menu_frame_visible
)
1610 ret
= menu_frame_visible
->data
;
1614 static gboolean
event_handle_menu_keyboard(XEvent
*ev
)
1616 guint keycode
, state
;
1619 gboolean ret
= TRUE
;
1621 keycode
= ev
->xkey
.keycode
;
1622 state
= ev
->xkey
.state
;
1623 unikey
= translate_unichar(keycode
);
1625 frame
= find_active_or_last_menu();
1629 else if (keycode
== ob_keycode(OB_KEY_ESCAPE
) && state
== 0)
1630 menu_frame_hide_all();
1632 else if (keycode
== ob_keycode(OB_KEY_RETURN
) && (state
== 0 ||
1633 state
== ControlMask
))
1635 /* Enter runs the active item or goes into the submenu.
1636 Control-Enter runs it without closing the menu. */
1638 menu_frame_select_next(frame
->child
);
1639 else if (frame
->selected
)
1640 menu_entry_frame_execute(frame
->selected
, state
, ev
->xkey
.time
);
1643 else if (keycode
== ob_keycode(OB_KEY_LEFT
) && ev
->xkey
.state
== 0) {
1644 /* Left goes to the parent menu */
1645 menu_frame_select(frame
, NULL
, TRUE
);
1648 else if (keycode
== ob_keycode(OB_KEY_RIGHT
) && ev
->xkey
.state
== 0) {
1649 /* Right goes to the selected submenu */
1650 if (frame
->child
) menu_frame_select_next(frame
->child
);
1653 else if (keycode
== ob_keycode(OB_KEY_UP
) && state
== 0) {
1654 menu_frame_select_previous(frame
);
1657 else if (keycode
== ob_keycode(OB_KEY_DOWN
) && state
== 0) {
1658 menu_frame_select_next(frame
);
1661 /* keyboard accelerator shortcuts. (allow controlmask) */
1662 else if ((ev
->xkey
.state
& ~ControlMask
) == 0 &&
1663 /* was it a valid key? */
1665 /* don't bother if the menu is empty. */
1670 ObMenuEntryFrame
*found
= NULL
;
1671 guint num_found
= 0;
1673 /* start after the selected one */
1674 start
= frame
->entries
;
1675 if (frame
->selected
) {
1676 for (it
= start
; frame
->selected
!= it
->data
; it
= g_list_next(it
))
1677 g_assert(it
!= NULL
); /* nothing was selected? */
1678 /* next with wraparound */
1679 start
= g_list_next(it
);
1680 if (start
== NULL
) start
= frame
->entries
;
1685 ObMenuEntryFrame
*e
= it
->data
;
1686 gunichar entrykey
= 0;
1688 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1689 entrykey
= e
->entry
->data
.normal
.shortcut
;
1690 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1691 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1693 if (unikey
== entrykey
) {
1694 if (found
== NULL
) found
= e
;
1698 /* next with wraparound */
1699 it
= g_list_next(it
);
1700 if (it
== NULL
) it
= frame
->entries
;
1701 } while (it
!= start
);
1704 if (found
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
1707 menu_frame_select(frame
, found
, TRUE
);
1708 usleep(50000); /* highlight the item for a short bit so the
1709 user can see what happened */
1710 menu_entry_frame_execute(found
, state
, ev
->xkey
.time
);
1712 menu_frame_select(frame
, found
, TRUE
);
1714 menu_frame_select_next(frame
->child
);
1725 static gboolean
event_handle_menu(XEvent
*ev
)
1728 ObMenuEntryFrame
*e
;
1729 gboolean ret
= TRUE
;
1733 if (menu_hide_delay_reached() &&
1734 (ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5))
1736 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1737 ev
->xbutton
.y_root
)))
1739 menu_frame_select(e
->frame
, e
, TRUE
);
1740 menu_entry_frame_execute(e
, ev
->xbutton
.state
,
1744 menu_frame_hide_all();
1748 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1749 if (e
->ignore_enters
)
1751 else if (!(f
= find_active_menu()) ||
1753 f
->parent
== e
->frame
||
1754 f
->child
== e
->frame
)
1755 menu_frame_select(e
->frame
, e
, FALSE
);
1759 /*ignore leaves when we're already in the window */
1760 if (ev
->xcrossing
.detail
== NotifyInferior
)
1763 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1764 (f
= find_active_menu()) && f
->selected
== e
&&
1765 e
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1767 menu_frame_select(e
->frame
, NULL
, FALSE
);
1771 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1772 ev
->xmotion
.y_root
)))
1773 if (!(f
= find_active_menu()) ||
1775 f
->parent
== e
->frame
||
1776 f
->child
== e
->frame
)
1777 menu_frame_select(e
->frame
, e
, FALSE
);
1780 ret
= event_handle_menu_keyboard(ev
);
1786 static void event_handle_user_input(ObClient
*client
, XEvent
*e
)
1788 g_assert(e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
1789 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
1790 e
->type
== KeyRelease
);
1792 if (menu_frame_visible
) {
1793 if (event_handle_menu(e
))
1794 /* don't use the event if the menu used it, but if the menu
1795 didn't use it and it's a keypress that is bound, it will
1796 close the menu and be used */
1800 /* if the keyboard interactive action uses the event then dont
1801 use it for bindings. likewise is moveresize uses the event. */
1802 if (!keyboard_process_interactive_grab(e
, &client
) &&
1803 !(moveresize_in_progress
&& moveresize_event(e
)))
1805 if (moveresize_in_progress
)
1806 /* make further actions work on the client being
1808 client
= moveresize_client
;
1810 if (e
->type
== ButtonPress
||
1811 e
->type
== ButtonRelease
||
1812 e
->type
== MotionNotify
)
1814 /* the frame may not be "visible" but they can still click on it
1815 in the case where it is animating before disappearing */
1816 if (!client
|| !frame_iconify_animating(client
->frame
))
1817 mouse_event(client
, e
);
1818 } else if (e
->type
== KeyPress
) {
1819 keyboard_event((focus_cycle_target
? focus_cycle_target
:
1820 (client
? client
: focus_client
)), e
);
1825 static void focus_delay_dest(gpointer data
)
1830 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
1832 const ObFocusDelayData
*f1
= d1
;
1833 return f1
->client
== d2
;
1836 static gboolean
focus_delay_func(gpointer data
)
1838 ObFocusDelayData
*d
= data
;
1839 Time old
= event_curtime
;
1841 event_curtime
= d
->time
;
1842 if (focus_client
!= d
->client
) {
1843 if (client_focus(d
->client
) && config_focus_raise
)
1844 stacking_raise(CLIENT_AS_WINDOW(d
->client
));
1846 event_curtime
= old
;
1847 return FALSE
; /* no repeat */
1850 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1852 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1856 void event_halt_focus_delay()
1858 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1861 gulong
event_start_ignore_all_enters()
1863 XSync(ob_display
, FALSE
);
1864 return LastKnownRequestProcessed(ob_display
);
1867 void event_end_ignore_all_enters(gulong start
)
1871 g_assert(start
!= 0);
1872 XSync(ob_display
, FALSE
);
1874 r
= g_new(ObSerialRange
, 1);
1876 r
->end
= LastKnownRequestProcessed(ob_display
);
1877 ignore_serials
= g_slist_prepend(ignore_serials
, r
);
1878 ob_debug("ignoring serials %u-%u\n", r
->start
, r
->end
);
1880 /* increment the serial so we don't ignore events we weren't meant to */
1881 XSync(ob_display
, FALSE
);
1882 ob_debug("now last serial %u\n", LastKnownRequestProcessed(ob_display
));
1885 static gboolean
is_enter_focus_event_ignored(XEvent
*e
)
1889 g_assert(e
->type
== EnterNotify
&&
1890 !(e
->xcrossing
.mode
== NotifyGrab
||
1891 e
->xcrossing
.mode
== NotifyUngrab
||
1892 e
->xcrossing
.detail
== NotifyInferior
));
1894 ob_debug("checking serial %u\n", e
->xany
.serial
);
1895 for (it
= ignore_serials
; it
; it
= next
) {
1896 ObSerialRange
*r
= it
->data
;
1898 next
= g_slist_next(it
);
1900 /* XXX wraparound... */
1901 ob_debug(" ignore range %u-%u\n", r
->start
, r
->end
);
1902 if ((glong
)(e
->xany
.serial
- r
->end
) > 0) {
1904 ignore_serials
= g_slist_delete_link(ignore_serials
, it
);
1907 else if ((glong
)(e
->xany
.serial
- r
->start
) >= 0)
1913 void event_cancel_all_key_grabs()
1915 if (keyboard_interactively_grabbed())
1916 keyboard_interactive_cancel();
1917 else if (menu_frame_visible
)
1918 menu_frame_hide_all();
1919 else if (grab_on_keyboard())
1922 /* If we don't have the keyboard grabbed, then ungrab it with
1923 XUngrabKeyboard, so that there is not a passive grab left
1924 on from the KeyPress. If the grab is left on, and focus
1925 moves during that time, it will be NotifyWhileGrabbed, and
1926 applications like to ignore those! */
1927 if (!keyboard_interactively_grabbed())
1928 XUngrabKeyboard(ob_display
, CurrentTime
);
1932 gboolean
event_time_after(Time t1
, Time t2
)
1934 g_assert(t1
!= CurrentTime
);
1935 g_assert(t2
!= CurrentTime
);
1938 Timestamp values wrap around (after about 49.7 days). The server, given
1939 its current time is represented by timestamp T, always interprets
1940 timestamps from clients by treating half of the timestamp space as being
1941 later in time than T.
1942 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
1945 /* TIME_HALF is half of the number space of a Time type variable */
1946 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
1948 if (t2
>= TIME_HALF
)
1949 /* t2 is in the second half so t1 might wrap around and be smaller than
1951 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
1953 /* t2 is in the first half so t1 has to come after it */
1954 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);