1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 event.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
34 #include "menuframe.h"
40 #include "focus_cycle.h"
41 #include "moveresize.h"
44 #include "extensions.h"
45 #include "translate.h"
48 #include <X11/Xatom.h>
51 #ifdef HAVE_SYS_SELECT_H
52 # include <sys/select.h>
58 # include <unistd.h> /* for usleep() */
61 # include <X11/XKBlib.h>
65 #include <X11/ICE/ICElib.h>
81 gulong start
; /* inclusive */
82 gulong end
; /* inclusive */
85 static void event_process(const XEvent
*e
, gpointer data
);
86 static void event_handle_root(XEvent
*e
);
87 static gboolean
event_handle_menu_keyboard(XEvent
*e
);
88 static gboolean
event_handle_menu(XEvent
*e
);
89 static void event_handle_dock(ObDock
*s
, XEvent
*e
);
90 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
);
91 static void event_handle_client(ObClient
*c
, XEvent
*e
);
92 static void event_handle_user_input(ObClient
*client
, XEvent
*e
);
93 static gboolean
is_enter_focus_event_ignored(XEvent
*e
);
94 static void event_ignore_enter_range(gulong start
, gulong end
);
96 static void focus_delay_dest(gpointer data
);
97 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
);
98 static gboolean
focus_delay_func(gpointer data
);
99 static void focus_delay_client_dest(ObClient
*client
, gpointer data
);
101 Time event_curtime
= CurrentTime
;
102 Time event_last_user_time
= CurrentTime
;
103 /*! The serial of the current X event */
104 gulong event_curserial
;
106 static gboolean focus_left_screen
= FALSE
;
107 /*! A list of ObSerialRanges which are to be ignored for mouse enter events */
108 static GSList
*ignore_serials
= NULL
;
111 static void ice_handler(gint fd
, gpointer conn
)
114 IceProcessMessages(conn
, NULL
, &b
);
117 static void ice_watch(IceConn conn
, IcePointer data
, Bool opening
,
118 IcePointer
*watch_data
)
123 fd
= IceConnectionNumber(conn
);
124 ob_main_loop_fd_add(ob_main_loop
, fd
, ice_handler
, conn
, NULL
);
126 ob_main_loop_fd_remove(ob_main_loop
, fd
);
132 void event_startup(gboolean reconfig
)
134 if (reconfig
) return;
136 ob_main_loop_x_add(ob_main_loop
, event_process
, NULL
, NULL
);
139 IceAddConnectionWatch(ice_watch
, NULL
);
142 client_add_destroy_notify(focus_delay_client_dest
, NULL
);
145 void event_shutdown(gboolean reconfig
)
147 if (reconfig
) return;
150 IceRemoveConnectionWatch(ice_watch
, NULL
);
153 client_remove_destroy_notify(focus_delay_client_dest
);
156 static Window
event_get_window(XEvent
*e
)
163 window
= RootWindow(ob_display
, ob_screen
);
166 window
= e
->xmap
.window
;
169 window
= e
->xunmap
.window
;
172 window
= e
->xdestroywindow
.window
;
174 case ConfigureRequest
:
175 window
= e
->xconfigurerequest
.window
;
177 case ConfigureNotify
:
178 window
= e
->xconfigure
.window
;
182 if (extensions_xkb
&& e
->type
== extensions_xkb_event_basep
) {
183 switch (((XkbAnyEvent
*)e
)->xkb_type
) {
185 window
= ((XkbBellNotifyEvent
*)e
)->window
;
192 if (extensions_sync
&&
193 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
198 window
= e
->xany
.window
;
203 static void event_set_curtime(XEvent
*e
)
205 Time t
= CurrentTime
;
207 /* grab the lasttime and hack up the state */
223 t
= e
->xproperty
.time
;
227 t
= e
->xcrossing
.time
;
231 if (extensions_sync
&&
232 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
234 t
= ((XSyncAlarmNotifyEvent
*)e
)->time
;
237 /* if more event types are anticipated, get their timestamp
242 /* watch that if we get an event earlier than the last specified user_time,
243 which can happen if the clock goes backwards, we erase the last
244 specified user_time */
245 if (t
&& event_last_user_time
&& event_time_after(event_last_user_time
, t
))
246 event_last_user_time
= CurrentTime
;
252 static void event_hack_mods(XEvent
*e
)
255 XkbStateRec xkb_state
;
261 e
->xbutton
.state
= modkeys_only_modifier_masks(e
->xbutton
.state
);
264 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
268 /* If XKB is present, then the modifiers are all strange from its
269 magic. Our X core protocol stuff won't work, so we use this to
270 find what the modifier state is instead. */
271 if (XkbGetState(ob_display
, XkbUseCoreKbd
, &xkb_state
) == Success
)
272 e
->xkey
.state
= xkb_state
.compat_state
;
276 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
277 /* remove from the state the mask of the modifier key being
278 released, if it is a modifier key being released that is */
279 e
->xkey
.state
&= ~modkeys_keycode_to_mask(e
->xkey
.keycode
);
283 e
->xmotion
.state
= modkeys_only_modifier_masks(e
->xmotion
.state
);
284 /* compress events */
287 while (XCheckTypedWindowEvent(ob_display
, e
->xmotion
.window
,
289 e
->xmotion
.x
= ce
.xmotion
.x
;
290 e
->xmotion
.y
= ce
.xmotion
.y
;
291 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
292 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
299 static gboolean
wanted_focusevent(XEvent
*e
, gboolean in_client_only
)
301 gint mode
= e
->xfocus
.mode
;
302 gint detail
= e
->xfocus
.detail
;
303 Window win
= e
->xany
.window
;
305 if (e
->type
== FocusIn
) {
306 /* These are ones we never want.. */
308 /* This means focus was given by a keyboard/mouse grab. */
309 if (mode
== NotifyGrab
)
311 /* This means focus was given back from a keyboard/mouse grab. */
312 if (mode
== NotifyUngrab
)
315 /* These are the ones we want.. */
317 if (win
== RootWindow(ob_display
, ob_screen
)) {
318 /* If looking for a focus in on a client, then always return
319 FALSE for focus in's to the root window */
322 /* This means focus reverted off of a client */
323 else if (detail
== NotifyPointerRoot
||
324 detail
== NotifyDetailNone
||
325 detail
== NotifyInferior
||
326 /* This means focus got here from another screen */
327 detail
== NotifyNonlinear
)
333 /* It was on a client, was it a valid one?
334 It's possible to get a FocusIn event for a client that was managed
337 if (in_client_only
) {
338 ObWindow
*w
= g_hash_table_lookup(window_map
, &e
->xfocus
.window
);
339 if (!w
|| !WINDOW_IS_CLIENT(w
))
343 /* This means focus reverted to parent from the client (this
344 happens often during iconify animation) */
345 if (detail
== NotifyInferior
)
349 /* This means focus moved from the root window to a client */
350 if (detail
== NotifyVirtual
)
352 /* This means focus moved from one client to another */
353 if (detail
== NotifyNonlinearVirtual
)
359 g_assert(e
->type
== FocusOut
);
361 /* These are ones we never want.. */
363 /* This means focus was taken by a keyboard/mouse grab. */
364 if (mode
== NotifyGrab
)
366 /* This means focus was grabbed on a window and it was released. */
367 if (mode
== NotifyUngrab
)
370 /* Focus left the root window revertedto state */
371 if (win
== RootWindow(ob_display
, ob_screen
))
374 /* These are the ones we want.. */
376 /* This means focus moved from a client to the root window */
377 if (detail
== NotifyVirtual
)
379 /* This means focus moved from one client to another */
380 if (detail
== NotifyNonlinearVirtual
)
388 static Bool
event_look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
390 return e
->type
== FocusIn
&& wanted_focusevent(e
, FALSE
);
393 static Bool
event_look_for_focusin_client(Display
*d
, XEvent
*e
, XPointer arg
)
395 return e
->type
== FocusIn
&& wanted_focusevent(e
, TRUE
);
398 static void print_focusevent(XEvent
*e
)
400 gint mode
= e
->xfocus
.mode
;
401 gint detail
= e
->xfocus
.detail
;
402 Window win
= e
->xany
.window
;
403 const gchar
*modestr
, *detailstr
;
406 case NotifyNormal
: modestr
="NotifyNormal"; break;
407 case NotifyGrab
: modestr
="NotifyGrab"; break;
408 case NotifyUngrab
: modestr
="NotifyUngrab"; break;
409 case NotifyWhileGrabbed
: modestr
="NotifyWhileGrabbed"; break;
412 case NotifyAncestor
: detailstr
="NotifyAncestor"; break;
413 case NotifyVirtual
: detailstr
="NotifyVirtual"; break;
414 case NotifyInferior
: detailstr
="NotifyInferior"; break;
415 case NotifyNonlinear
: detailstr
="NotifyNonlinear"; break;
416 case NotifyNonlinearVirtual
: detailstr
="NotifyNonlinearVirtual"; break;
417 case NotifyPointer
: detailstr
="NotifyPointer"; break;
418 case NotifyPointerRoot
: detailstr
="NotifyPointerRoot"; break;
419 case NotifyDetailNone
: detailstr
="NotifyDetailNone"; break;
422 if (mode
== NotifyGrab
|| mode
== NotifyUngrab
)
427 ob_debug_type(OB_DEBUG_FOCUS
, "Focus%s 0x%x mode=%s detail=%s\n",
428 (e
->xfocus
.type
== FocusIn
? "In" : "Out"),
434 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
439 if (!wanted_focusevent(e
, FALSE
))
444 if (!wanted_focusevent(e
, FALSE
))
451 static void event_process(const XEvent
*ec
, gpointer data
)
454 ObClient
*client
= NULL
;
456 ObDockApp
*dockapp
= NULL
;
457 ObWindow
*obwin
= NULL
;
459 ObEventData
*ed
= data
;
461 /* make a copy we can mangle */
465 window
= event_get_window(e
);
466 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
467 switch (obwin
->type
) {
469 dock
= WINDOW_AS_DOCK(obwin
);
472 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
475 client
= WINDOW_AS_CLIENT(obwin
);
478 case Window_Internal
:
479 /* not to be used for events */
480 g_assert_not_reached();
485 event_set_curtime(e
);
486 event_curserial
= e
->xany
.serial
;
488 if (event_ignore(e
, client
)) {
495 /* deal with it in the kernel */
497 if (menu_frame_visible
&&
498 (e
->type
== EnterNotify
|| e
->type
== LeaveNotify
))
500 /* crossing events for menu */
501 event_handle_menu(e
);
502 } else if (e
->type
== FocusIn
) {
504 e
->xfocus
.detail
== NotifyInferior
)
506 ob_debug_type(OB_DEBUG_FOCUS
,
507 "Focus went to the frame window");
509 focus_left_screen
= FALSE
;
511 focus_fallback(FALSE
, config_focus_under_mouse
, TRUE
, TRUE
);
513 /* We don't get a FocusOut for this case, because it's just moving
514 from our Inferior up to us. This happens when iconifying a
515 window with RevertToParent focus */
516 frame_adjust_focus(client
->frame
, FALSE
);
517 /* focus_set_client(NULL) has already been called */
518 client_calc_layer(client
);
520 else if (e
->xfocus
.detail
== NotifyPointerRoot
||
521 e
->xfocus
.detail
== NotifyDetailNone
||
522 e
->xfocus
.detail
== NotifyInferior
||
523 e
->xfocus
.detail
== NotifyNonlinear
)
527 ob_debug_type(OB_DEBUG_FOCUS
,
528 "Focus went to root or pointer root/none\n");
530 if (e
->xfocus
.detail
== NotifyInferior
||
531 e
->xfocus
.detail
== NotifyNonlinear
)
533 focus_left_screen
= FALSE
;
536 /* If another FocusIn is in the queue then don't fallback yet. This
537 fixes the fun case of:
538 window map -> send focusin
539 window unmap -> get focusout
540 window map -> send focusin
541 get first focus out -> fall back to something (new window
542 hasn't received focus yet, so something else) -> send focusin
543 which means the "something else" is the last thing to get a
544 focusin sent to it, so the new window doesn't end up with focus.
546 But if the other focus in is something like PointerRoot then we
547 still want to fall back.
549 if (XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin_client
,
552 XPutBackEvent(ob_display
, &ce
);
553 ob_debug_type(OB_DEBUG_FOCUS
,
554 " but another FocusIn is coming\n");
556 /* Focus has been reverted.
558 FocusOut events come after UnmapNotify, so we don't need to
559 worry about focusing an invalid window
562 if (!focus_left_screen
)
563 focus_fallback(FALSE
, config_focus_under_mouse
,
569 ob_debug_type(OB_DEBUG_FOCUS
,
570 "Focus went to a window that is already gone\n");
572 /* If you send focus to a window and then it disappears, you can
573 get the FocusIn for it, after it is unmanaged.
574 Just wait for the next FocusOut/FocusIn pair, but make note that
575 the window that was focused no longer is. */
576 focus_set_client(NULL
);
578 else if (client
!= focus_client
) {
579 focus_left_screen
= FALSE
;
580 frame_adjust_focus(client
->frame
, TRUE
);
581 focus_set_client(client
);
582 client_calc_layer(client
);
583 client_bring_helper_windows(client
);
585 } else if (e
->type
== FocusOut
) {
588 /* Look for the followup FocusIn */
589 if (!XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin
, NULL
)) {
590 /* There is no FocusIn, this means focus went to a window that
591 is not being managed, or a window on another screen. */
595 xerror_set_ignore(TRUE
);
596 if (XGetInputFocus(ob_display
, &win
, &i
) != 0 &&
597 XGetGeometry(ob_display
, win
, &root
, &i
,&i
,&u
,&u
,&u
,&u
) != 0 &&
598 root
!= RootWindow(ob_display
, ob_screen
))
600 ob_debug_type(OB_DEBUG_FOCUS
,
601 "Focus went to another screen !\n");
602 focus_left_screen
= TRUE
;
605 ob_debug_type(OB_DEBUG_FOCUS
,
606 "Focus went to a black hole !\n");
607 xerror_set_ignore(FALSE
);
608 /* nothing is focused */
609 focus_set_client(NULL
);
611 /* Focus moved, so process the FocusIn event */
612 ObEventData ed
= { .ignored
= FALSE
};
613 event_process(&ce
, &ed
);
615 /* The FocusIn was ignored, this means it was on a window
616 that isn't a client. */
617 ob_debug_type(OB_DEBUG_FOCUS
,
618 "Focus went to an unmanaged window 0x%x !\n",
620 focus_fallback(TRUE
, config_focus_under_mouse
, TRUE
, TRUE
);
624 if (client
&& client
!= focus_client
) {
625 frame_adjust_focus(client
->frame
, FALSE
);
626 /* focus_set_client(NULL) has already been called in this
627 section or by focus_fallback */
628 client_calc_layer(client
);
632 event_handle_client(client
, e
);
634 event_handle_dockapp(dockapp
, e
);
636 event_handle_dock(dock
, e
);
637 else if (window
== RootWindow(ob_display
, ob_screen
))
638 event_handle_root(e
);
639 else if (e
->type
== MapRequest
)
640 client_manage(window
);
641 else if (e
->type
== MappingNotify
) {
642 /* keyboard layout changes, reconfigure openbox. need to restart the
643 modkeys system, but also to reload the key bindings. */
646 else if (e
->type
== ClientMessage
) {
647 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
648 windows that are not managed yet. */
649 if (e
->xclient
.message_type
== prop_atoms
.net_request_frame_extents
) {
650 /* Pretend to manage the client, getting information used to
651 determine its decorations */
652 ObClient
*c
= client_fake_manage(e
->xclient
.window
);
655 /* set the frame extents on the window */
656 vals
[0] = c
->frame
->size
.left
;
657 vals
[1] = c
->frame
->size
.right
;
658 vals
[2] = c
->frame
->size
.top
;
659 vals
[3] = c
->frame
->size
.bottom
;
660 PROP_SETA32(e
->xclient
.window
, net_frame_extents
,
663 /* Free the pretend client */
664 client_fake_unmanage(c
);
667 else if (e
->type
== ConfigureRequest
) {
668 /* unhandled configure requests must be used to configure the
672 xwc
.x
= e
->xconfigurerequest
.x
;
673 xwc
.y
= e
->xconfigurerequest
.y
;
674 xwc
.width
= e
->xconfigurerequest
.width
;
675 xwc
.height
= e
->xconfigurerequest
.height
;
676 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
677 xwc
.sibling
= e
->xconfigurerequest
.above
;
678 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
680 /* we are not to be held responsible if someone sends us an
682 xerror_set_ignore(TRUE
);
683 XConfigureWindow(ob_display
, window
,
684 e
->xconfigurerequest
.value_mask
, &xwc
);
685 xerror_set_ignore(FALSE
);
688 else if (extensions_sync
&&
689 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
691 XSyncAlarmNotifyEvent
*se
= (XSyncAlarmNotifyEvent
*)e
;
692 if (se
->alarm
== moveresize_alarm
&& moveresize_in_progress
)
697 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
) {
698 /* If the button press was on some non-root window, or was physically
699 on the root window, the process it */
700 if (window
!= RootWindow(ob_display
, ob_screen
) ||
701 e
->xbutton
.subwindow
== None
)
703 event_handle_user_input(client
, e
);
705 /* Otherwise only process it if it was physically on an openbox
708 Window target
, parent
, root
, *children
;
709 unsigned int nchildren
;
712 /* Find the top level ancestor of the subwindow, besides the
714 target
= e
->xbutton
.subwindow
;
715 ob_debug("subwindow 0x%x\n", target
);
716 while (XQueryTree(ob_display
, target
, &root
, &parent
, &children
,
720 if (parent
== root
) {
721 ob_debug("parent is root\n");
726 ob_debug("toplevel 0x%x\n", target
);
728 w
= g_hash_table_lookup(window_map
, &target
);
729 ob_debug("w 0x%x\n", w
);
731 if ((w
= g_hash_table_lookup(window_map
, &target
)) &&
732 WINDOW_IS_INTERNAL(w
))
734 event_handle_user_input(client
, e
);
738 else if (e
->type
== KeyPress
|| e
->type
== KeyRelease
||
739 e
->type
== MotionNotify
)
740 event_handle_user_input(client
, e
);
742 /* if something happens and it's not from an XEvent, then we don't know
744 event_curtime
= CurrentTime
;
747 static void event_handle_root(XEvent
*e
)
753 ob_debug("Another WM has requested to replace us. Exiting.\n");
758 if (e
->xclient
.format
!= 32) break;
760 msgtype
= e
->xclient
.message_type
;
761 if (msgtype
== prop_atoms
.net_current_desktop
) {
762 guint d
= e
->xclient
.data
.l
[0];
763 if (d
< screen_num_desktops
) {
764 event_curtime
= e
->xclient
.data
.l
[1];
765 if (event_curtime
== 0)
766 ob_debug_type(OB_DEBUG_APP_BUGS
,
767 "_NET_CURRENT_DESKTOP message is missing "
769 screen_set_desktop(d
, TRUE
);
771 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
772 guint d
= e
->xclient
.data
.l
[0];
773 if (d
> 0 && d
<= 1000)
774 screen_set_num_desktops(d
);
775 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
776 screen_show_desktop(e
->xclient
.data
.l
[0] != 0, NULL
);
777 } else if (msgtype
== prop_atoms
.ob_control
) {
778 ob_debug("OB_CONTROL: %d\n", e
->xclient
.data
.l
[0]);
779 if (e
->xclient
.data
.l
[0] == 1)
781 else if (e
->xclient
.data
.l
[0] == 2)
783 else if (e
->xclient
.data
.l
[0] == 3)
788 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
) {
789 ob_debug("UPDATE DESKTOP NAMES\n");
790 screen_update_desktop_names();
792 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
793 screen_update_layout();
795 case ConfigureNotify
:
797 XRRUpdateConfiguration(e
);
806 void event_enter_client(ObClient
*client
)
808 g_assert(config_focus_follow
);
810 if (client_enter_focusable(client
) && client_can_focus(client
)) {
811 if (config_focus_delay
) {
812 ObFocusDelayData
*data
;
814 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
816 data
= g_new(ObFocusDelayData
, 1);
817 data
->client
= client
;
818 data
->time
= event_curtime
;
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 focus_delay_func(&data
);
833 static void event_handle_client(ObClient
*client
, XEvent
*e
)
838 static gint px
= -1, py
= -1;
843 /* save where the press occured for the first button pressed */
845 pb
= e
->xbutton
.button
;
850 /* Wheel buttons don't draw because they are an instant click, so it
851 is a waste of resources to go drawing it.
852 if the user is doing an intereactive thing, or has a menu open then
853 the mouse is grabbed (possibly) and if we get these events we don't
854 want to deal with them
856 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5) &&
859 /* use where the press occured */
860 con
= frame_context(client
, e
->xbutton
.window
, px
, py
);
861 con
= mouse_button_frame_context(con
, e
->xbutton
.button
,
864 if (e
->type
== ButtonRelease
&& e
->xbutton
.button
== pb
)
865 pb
= 0, px
= py
= -1;
868 case OB_FRAME_CONTEXT_MAXIMIZE
:
869 client
->frame
->max_press
= (e
->type
== ButtonPress
);
870 frame_adjust_state(client
->frame
);
872 case OB_FRAME_CONTEXT_CLOSE
:
873 client
->frame
->close_press
= (e
->type
== ButtonPress
);
874 frame_adjust_state(client
->frame
);
876 case OB_FRAME_CONTEXT_ICONIFY
:
877 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
878 frame_adjust_state(client
->frame
);
880 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
881 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
882 frame_adjust_state(client
->frame
);
884 case OB_FRAME_CONTEXT_SHADE
:
885 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
886 frame_adjust_state(client
->frame
);
889 /* nothing changes with clicks for any other contexts */
895 /* when there is a grab on the pointer, we won't get enter/leave
896 notifies, but we still get motion events */
897 if (grab_on_pointer()) break;
899 con
= frame_context(client
, e
->xmotion
.window
,
900 e
->xmotion
.x
, e
->xmotion
.y
);
902 case OB_FRAME_CONTEXT_TITLEBAR
:
903 case OB_FRAME_CONTEXT_TLCORNER
:
904 case OB_FRAME_CONTEXT_TRCORNER
:
905 /* we've left the button area inside the titlebar */
906 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
907 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
908 client
->frame
->close_hover
)
910 client
->frame
->max_hover
= FALSE
;
911 client
->frame
->desk_hover
= FALSE
;
912 client
->frame
->shade_hover
= FALSE
;
913 client
->frame
->iconify_hover
= FALSE
;
914 client
->frame
->close_hover
= FALSE
;
915 frame_adjust_state(client
->frame
);
918 case OB_FRAME_CONTEXT_MAXIMIZE
:
919 if (!client
->frame
->max_hover
) {
920 client
->frame
->max_hover
= TRUE
;
921 frame_adjust_state(client
->frame
);
924 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
925 if (!client
->frame
->desk_hover
) {
926 client
->frame
->desk_hover
= TRUE
;
927 frame_adjust_state(client
->frame
);
930 case OB_FRAME_CONTEXT_SHADE
:
931 if (!client
->frame
->shade_hover
) {
932 client
->frame
->shade_hover
= TRUE
;
933 frame_adjust_state(client
->frame
);
936 case OB_FRAME_CONTEXT_ICONIFY
:
937 if (!client
->frame
->iconify_hover
) {
938 client
->frame
->iconify_hover
= TRUE
;
939 frame_adjust_state(client
->frame
);
942 case OB_FRAME_CONTEXT_CLOSE
:
943 if (!client
->frame
->close_hover
) {
944 client
->frame
->close_hover
= TRUE
;
945 frame_adjust_state(client
->frame
);
953 con
= frame_context(client
, e
->xcrossing
.window
,
954 e
->xcrossing
.x
, e
->xcrossing
.y
);
956 case OB_FRAME_CONTEXT_TITLEBAR
:
957 case OB_FRAME_CONTEXT_TLCORNER
:
958 case OB_FRAME_CONTEXT_TRCORNER
:
959 /* we've left the button area inside the titlebar */
960 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
961 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
962 client
->frame
->close_hover
)
964 client
->frame
->max_hover
= FALSE
;
965 client
->frame
->desk_hover
= FALSE
;
966 client
->frame
->shade_hover
= FALSE
;
967 client
->frame
->iconify_hover
= FALSE
;
968 client
->frame
->close_hover
= FALSE
;
969 frame_adjust_state(client
->frame
);
972 case OB_FRAME_CONTEXT_MAXIMIZE
:
973 client
->frame
->max_hover
= FALSE
;
974 frame_adjust_state(client
->frame
);
976 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
977 client
->frame
->desk_hover
= FALSE
;
978 frame_adjust_state(client
->frame
);
980 case OB_FRAME_CONTEXT_SHADE
:
981 client
->frame
->shade_hover
= FALSE
;
982 frame_adjust_state(client
->frame
);
984 case OB_FRAME_CONTEXT_ICONIFY
:
985 client
->frame
->iconify_hover
= FALSE
;
986 frame_adjust_state(client
->frame
);
988 case OB_FRAME_CONTEXT_CLOSE
:
989 client
->frame
->close_hover
= FALSE
;
990 frame_adjust_state(client
->frame
);
992 case OB_FRAME_CONTEXT_FRAME
:
993 /* When the mouse leaves an animating window, don't use the
994 corresponding enter events. Pretend like the animating window
995 doesn't even exist..! */
996 if (frame_iconify_animating(client
->frame
))
997 event_end_ignore_all_enters(event_start_ignore_all_enters());
999 ob_debug_type(OB_DEBUG_FOCUS
,
1000 "%sNotify mode %d detail %d on %lx\n",
1001 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1003 e
->xcrossing
.detail
, (client
?client
->window
:0));
1004 if (grab_on_keyboard())
1006 if (config_focus_follow
&& config_focus_delay
&&
1007 /* leave inferior events can happen when the mouse goes onto
1008 the window's border and then into the window before the
1010 e
->xcrossing
.detail
!= NotifyInferior
)
1012 ob_main_loop_timeout_remove_data(ob_main_loop
,
1023 con
= frame_context(client
, e
->xcrossing
.window
,
1024 e
->xcrossing
.x
, e
->xcrossing
.y
);
1026 case OB_FRAME_CONTEXT_MAXIMIZE
:
1027 client
->frame
->max_hover
= TRUE
;
1028 frame_adjust_state(client
->frame
);
1030 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
1031 client
->frame
->desk_hover
= TRUE
;
1032 frame_adjust_state(client
->frame
);
1034 case OB_FRAME_CONTEXT_SHADE
:
1035 client
->frame
->shade_hover
= TRUE
;
1036 frame_adjust_state(client
->frame
);
1038 case OB_FRAME_CONTEXT_ICONIFY
:
1039 client
->frame
->iconify_hover
= TRUE
;
1040 frame_adjust_state(client
->frame
);
1042 case OB_FRAME_CONTEXT_CLOSE
:
1043 client
->frame
->close_hover
= TRUE
;
1044 frame_adjust_state(client
->frame
);
1046 case OB_FRAME_CONTEXT_FRAME
:
1047 if (grab_on_keyboard())
1049 if (e
->xcrossing
.mode
== NotifyGrab
||
1050 e
->xcrossing
.mode
== NotifyUngrab
||
1051 /*ignore enters when we're already in the window */
1052 e
->xcrossing
.detail
== NotifyInferior
||
1053 is_enter_focus_event_ignored(e
))
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
, FALSE
, 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 if (keycode
== ob_keycode(OB_KEY_ESCAPE
)) {
1693 menu_frame_hide_all();
1697 else if (keycode
== ob_keycode(OB_KEY_LEFT
)) {
1698 /* Left goes to the parent menu */
1699 menu_frame_select(frame
, NULL
, TRUE
);
1703 else if (keycode
== ob_keycode(OB_KEY_RIGHT
)) {
1704 /* Right goes to the selected submenu */
1705 if (frame
->child
) menu_frame_select_next(frame
->child
);
1709 else if (keycode
== ob_keycode(OB_KEY_UP
)) {
1710 menu_frame_select_previous(frame
);
1714 else if (keycode
== ob_keycode(OB_KEY_DOWN
)) {
1715 menu_frame_select_next(frame
);
1720 /* Use KeyRelease events for running things so that the key release doesn't
1721 get sent to the focused application.
1723 Allow ControlMask only, and don't bother if the menu is empty */
1724 else if (ev
->type
== KeyRelease
&& (state
& ~ControlMask
) == 0 &&
1727 if (keycode
== ob_keycode(OB_KEY_RETURN
)) {
1728 /* Enter runs the active item or goes into the submenu.
1729 Control-Enter runs it without closing the menu. */
1731 menu_frame_select_next(frame
->child
);
1732 else if (frame
->selected
)
1733 menu_entry_frame_execute(frame
->selected
, state
);
1738 /* keyboard accelerator shortcuts. (if it was a valid key) */
1739 else if (unikey
!= 0) {
1742 ObMenuEntryFrame
*found
= NULL
;
1743 guint num_found
= 0;
1745 /* start after the selected one */
1746 start
= frame
->entries
;
1747 if (frame
->selected
) {
1748 for (it
= start
; frame
->selected
!= it
->data
;
1749 it
= g_list_next(it
))
1750 g_assert(it
!= NULL
); /* nothing was selected? */
1751 /* next with wraparound */
1752 start
= g_list_next(it
);
1753 if (start
== NULL
) start
= frame
->entries
;
1758 ObMenuEntryFrame
*e
= it
->data
;
1759 gunichar entrykey
= 0;
1761 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1762 entrykey
= e
->entry
->data
.normal
.shortcut
;
1763 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1764 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1766 if (unikey
== entrykey
) {
1767 if (found
== NULL
) found
= e
;
1771 /* next with wraparound */
1772 it
= g_list_next(it
);
1773 if (it
== NULL
) it
= frame
->entries
;
1774 } while (it
!= start
);
1777 if (found
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
1780 menu_frame_select(frame
, found
, TRUE
);
1781 usleep(50000); /* highlight the item for a short bit so the
1782 user can see what happened */
1783 menu_entry_frame_execute(found
, state
);
1785 menu_frame_select(frame
, found
, TRUE
);
1787 menu_frame_select_next(frame
->child
);
1798 static gboolean
event_handle_menu(XEvent
*ev
)
1801 ObMenuEntryFrame
*e
;
1802 gboolean ret
= TRUE
;
1806 if (menu_hide_delay_reached() &&
1807 (ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5))
1809 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1810 ev
->xbutton
.y_root
)))
1812 menu_frame_select(e
->frame
, e
, TRUE
);
1813 menu_entry_frame_execute(e
, ev
->xbutton
.state
);
1816 menu_frame_hide_all();
1820 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1821 if (e
->ignore_enters
)
1823 else if (!(f
= find_active_menu()) ||
1825 f
->parent
== e
->frame
||
1826 f
->child
== e
->frame
)
1827 menu_frame_select(e
->frame
, e
, FALSE
);
1831 /*ignore leaves when we're already in the window */
1832 if (ev
->xcrossing
.detail
== NotifyInferior
)
1835 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1836 (f
= find_active_menu()) && f
->selected
== e
&&
1837 e
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1839 menu_frame_select(e
->frame
, NULL
, FALSE
);
1843 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1844 ev
->xmotion
.y_root
)))
1845 if (!(f
= find_active_menu()) ||
1847 f
->parent
== e
->frame
||
1848 f
->child
== e
->frame
)
1849 menu_frame_select(e
->frame
, e
, FALSE
);
1853 ret
= event_handle_menu_keyboard(ev
);
1859 static void event_handle_user_input(ObClient
*client
, XEvent
*e
)
1861 g_assert(e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
1862 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
1863 e
->type
== KeyRelease
);
1865 if (menu_frame_visible
) {
1866 if (event_handle_menu(e
))
1867 /* don't use the event if the menu used it, but if the menu
1868 didn't use it and it's a keypress that is bound, it will
1869 close the menu and be used */
1873 /* if the keyboard interactive action uses the event then dont
1874 use it for bindings. likewise is moveresize uses the event. */
1875 if (!actions_interactive_input_event(e
) && !moveresize_event(e
)) {
1876 if (moveresize_in_progress
)
1877 /* make further actions work on the client being
1879 client
= moveresize_client
;
1881 if (e
->type
== ButtonPress
||
1882 e
->type
== ButtonRelease
||
1883 e
->type
== MotionNotify
)
1885 /* the frame may not be "visible" but they can still click on it
1886 in the case where it is animating before disappearing */
1887 if (!client
|| !frame_iconify_animating(client
->frame
))
1888 mouse_event(client
, e
);
1890 keyboard_event((focus_cycle_target
? focus_cycle_target
:
1891 (client
? client
: focus_client
)), e
);
1895 static void focus_delay_dest(gpointer data
)
1900 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
1902 const ObFocusDelayData
*f1
= d1
;
1903 return f1
->client
== d2
;
1906 static gboolean
focus_delay_func(gpointer data
)
1908 ObFocusDelayData
*d
= data
;
1909 Time old
= event_curtime
;
1911 /* don't move focus and kill the menu or the move/resize */
1912 if (menu_frame_visible
|| moveresize_in_progress
) return FALSE
;
1914 event_curtime
= d
->time
;
1915 if (client_focus(d
->client
) && config_focus_raise
)
1916 stacking_raise(CLIENT_AS_WINDOW(d
->client
));
1917 event_curtime
= old
;
1918 return FALSE
; /* no repeat */
1921 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1923 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1927 void event_halt_focus_delay(gulong serial
)
1929 /* ignore all enter events up till the event which caused this to occur */
1930 if (event_curserial
) event_ignore_enter_range(1, event_curserial
);
1931 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1934 gulong
event_start_ignore_all_enters(void)
1936 /* increment the serial so we don't ignore events we weren't meant to */
1937 XSync(ob_display
, FALSE
);
1938 return LastKnownRequestProcessed(ob_display
);
1941 static void event_ignore_enter_range(gulong start
, gulong end
)
1945 g_assert(start
!= 0);
1948 r
= g_new(ObSerialRange
, 1);
1951 ignore_serials
= g_slist_prepend(ignore_serials
, r
);
1953 ob_debug_type(OB_DEBUG_FOCUS
, "ignoring enters from %lu until %lu\n",
1956 /* increment the serial so we don't ignore events we weren't meant to */
1957 XSync(ob_display
, FALSE
);
1960 void event_end_ignore_all_enters(gulong start
)
1962 event_ignore_enter_range(start
, LastKnownRequestProcessed(ob_display
));
1965 static gboolean
is_enter_focus_event_ignored(XEvent
*e
)
1969 g_assert(e
->type
== EnterNotify
&&
1970 !(e
->xcrossing
.mode
== NotifyGrab
||
1971 e
->xcrossing
.mode
== NotifyUngrab
||
1972 e
->xcrossing
.detail
== NotifyInferior
));
1974 for (it
= ignore_serials
; it
; it
= next
) {
1975 ObSerialRange
*r
= it
->data
;
1977 next
= g_slist_next(it
);
1979 if ((glong
)(e
->xany
.serial
- r
->end
) > 0) {
1981 ignore_serials
= g_slist_delete_link(ignore_serials
, it
);
1984 else if ((glong
)(e
->xany
.serial
- r
->start
) >= 0)
1990 void event_cancel_all_key_grabs(void)
1992 if (actions_interactive_act_running()) {
1993 actions_interactive_cancel_act();
1994 ob_debug("KILLED interactive action\n");
1996 else if (menu_frame_visible
) {
1997 menu_frame_hide_all();
1998 ob_debug("KILLED open menus\n");
2000 else if (moveresize_in_progress
) {
2001 moveresize_end(TRUE
);
2002 ob_debug("KILLED interactive moveresize\n");
2004 else if (grab_on_keyboard()) {
2006 ob_debug("KILLED active grab on keyboard\n");
2009 ungrab_passive_key();
2012 gboolean
event_time_after(Time t1
, Time t2
)
2014 g_assert(t1
!= CurrentTime
);
2015 g_assert(t2
!= CurrentTime
);
2018 Timestamp values wrap around (after about 49.7 days). The server, given
2019 its current time is represented by timestamp T, always interprets
2020 timestamps from clients by treating half of the timestamp space as being
2021 later in time than T.
2022 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
2025 /* TIME_HALF is half of the number space of a Time type variable */
2026 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
2028 if (t2
>= TIME_HALF
)
2029 /* t2 is in the second half so t1 might wrap around and be smaller than
2031 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
2033 /* t2 is in the first half so t1 has to come after it */
2034 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);
2037 Time
event_get_server_time(void)
2039 /* Generate a timestamp */
2042 XChangeProperty(ob_display
, screen_support_win
,
2043 prop_atoms
.wm_class
, prop_atoms
.string
,
2044 8, PropModeAppend
, NULL
, 0);
2045 XWindowEvent(ob_display
, screen_support_win
, PropertyChangeMask
, &event
);
2046 return event
.xproperty
.time
;