1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 event.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
35 #include "menuframe.h"
41 #include "focus_cycle.h"
42 #include "moveresize.h"
45 #include "extensions.h"
46 #include "translate.h"
50 #include <X11/Xatom.h>
53 #ifdef HAVE_SYS_SELECT_H
54 # include <sys/select.h>
60 # include <unistd.h> /* for usleep() */
63 # include <X11/XKBlib.h>
67 #include <X11/ICE/ICElib.h>
84 gulong start
; /* inclusive */
85 gulong end
; /* inclusive */
88 static void event_process(const XEvent
*e
, gpointer data
);
89 static void event_handle_root(XEvent
*e
);
90 static gboolean
event_handle_menu_keyboard(XEvent
*e
);
91 static gboolean
event_handle_menu(XEvent
*e
);
92 static gboolean
event_handle_prompt(ObPrompt
*p
, XEvent
*e
);
93 static void event_handle_dock(ObDock
*s
, XEvent
*e
);
94 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
);
95 static void event_handle_client(ObClient
*c
, XEvent
*e
);
96 static void event_handle_user_input(ObClient
*client
, XEvent
*e
);
97 static gboolean
is_enter_focus_event_ignored(gulong serial
);
98 static void event_ignore_enter_range(gulong start
, gulong end
);
100 static void focus_delay_dest(gpointer data
);
101 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
);
102 static gboolean
focus_delay_func(gpointer data
);
103 static void focus_delay_client_dest(ObClient
*client
, gpointer data
);
105 Time event_curtime
= CurrentTime
;
106 Time event_last_user_time
= CurrentTime
;
107 /*! The serial of the current X event */
109 static gulong event_curserial
;
110 static gboolean focus_left_screen
= FALSE
;
111 /*! A list of ObSerialRanges which are to be ignored for mouse enter events */
112 static GSList
*ignore_serials
= NULL
;
115 static void ice_handler(gint fd
, gpointer conn
)
118 IceProcessMessages(conn
, NULL
, &b
);
121 static void ice_watch(IceConn conn
, IcePointer data
, Bool opening
,
122 IcePointer
*watch_data
)
127 fd
= IceConnectionNumber(conn
);
128 ob_main_loop_fd_add(ob_main_loop
, fd
, ice_handler
, conn
, NULL
);
130 ob_main_loop_fd_remove(ob_main_loop
, fd
);
136 void event_startup(gboolean reconfig
)
138 if (reconfig
) return;
140 ob_main_loop_x_add(ob_main_loop
, event_process
, NULL
, NULL
);
143 IceAddConnectionWatch(ice_watch
, NULL
);
146 client_add_destroy_notify(focus_delay_client_dest
, NULL
);
149 void event_shutdown(gboolean reconfig
)
151 if (reconfig
) return;
154 IceRemoveConnectionWatch(ice_watch
, NULL
);
157 client_remove_destroy_notify(focus_delay_client_dest
);
160 static Window
event_get_window(XEvent
*e
)
167 window
= RootWindow(ob_display
, ob_screen
);
170 window
= e
->xmap
.window
;
173 window
= e
->xunmap
.window
;
176 window
= e
->xdestroywindow
.window
;
178 case ConfigureRequest
:
179 window
= e
->xconfigurerequest
.window
;
181 case ConfigureNotify
:
182 window
= e
->xconfigure
.window
;
186 if (extensions_xkb
&& e
->type
== extensions_xkb_event_basep
) {
187 switch (((XkbAnyEvent
*)e
)->xkb_type
) {
189 window
= ((XkbBellNotifyEvent
*)e
)->window
;
196 if (extensions_sync
&&
197 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
202 window
= e
->xany
.window
;
207 static void event_set_curtime(XEvent
*e
)
209 Time t
= CurrentTime
;
211 /* grab the lasttime and hack up the state */
227 t
= e
->xproperty
.time
;
231 t
= e
->xcrossing
.time
;
235 if (extensions_sync
&&
236 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
238 t
= ((XSyncAlarmNotifyEvent
*)e
)->time
;
241 /* if more event types are anticipated, get their timestamp
246 /* watch that if we get an event earlier than the last specified user_time,
247 which can happen if the clock goes backwards, we erase the last
248 specified user_time */
249 if (t
&& event_last_user_time
&& event_time_after(event_last_user_time
, t
))
250 event_last_user_time
= CurrentTime
;
255 static void event_hack_mods(XEvent
*e
)
258 XkbStateRec xkb_state
;
264 e
->xbutton
.state
= modkeys_only_modifier_masks(e
->xbutton
.state
);
267 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
271 /* If XKB is present, then the modifiers are all strange from its
272 magic. Our X core protocol stuff won't work, so we use this to
273 find what the modifier state is instead. */
274 if (XkbGetState(ob_display
, XkbUseCoreKbd
, &xkb_state
) == Success
)
276 modkeys_only_modifier_masks(xkb_state
.compat_state
);
280 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
281 /* remove from the state the mask of the modifier key being
282 released, if it is a modifier key being released that is */
283 e
->xkey
.state
&= ~modkeys_keycode_to_mask(e
->xkey
.keycode
);
287 e
->xmotion
.state
= modkeys_only_modifier_masks(e
->xmotion
.state
);
288 /* compress events */
291 while (XCheckTypedWindowEvent(ob_display
, e
->xmotion
.window
,
293 e
->xmotion
.x
= ce
.xmotion
.x
;
294 e
->xmotion
.y
= ce
.xmotion
.y
;
295 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
296 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
303 static gboolean
wanted_focusevent(XEvent
*e
, gboolean in_client_only
)
305 gint mode
= e
->xfocus
.mode
;
306 gint detail
= e
->xfocus
.detail
;
307 Window win
= e
->xany
.window
;
309 if (e
->type
== FocusIn
) {
310 /* These are ones we never want.. */
312 /* This means focus was given by a keyboard/mouse grab. */
313 if (mode
== NotifyGrab
)
315 /* This means focus was given back from a keyboard/mouse grab. */
316 if (mode
== NotifyUngrab
)
319 /* These are the ones we want.. */
321 if (win
== RootWindow(ob_display
, ob_screen
)) {
322 /* If looking for a focus in on a client, then always return
323 FALSE for focus in's to the root window */
326 /* This means focus reverted off of a client */
327 else if (detail
== NotifyPointerRoot
||
328 detail
== NotifyDetailNone
||
329 detail
== NotifyInferior
||
330 /* This means focus got here from another screen */
331 detail
== NotifyNonlinear
)
337 /* It was on a client, was it a valid one?
338 It's possible to get a FocusIn event for a client that was managed
341 if (in_client_only
) {
342 ObWindow
*w
= g_hash_table_lookup(window_map
, &e
->xfocus
.window
);
343 if (!w
|| !WINDOW_IS_CLIENT(w
))
347 /* This means focus reverted to parent from the client (this
348 happens often during iconify animation) */
349 if (detail
== NotifyInferior
)
353 /* This means focus moved from the root window to a client */
354 if (detail
== NotifyVirtual
)
356 /* This means focus moved from one client to another */
357 if (detail
== NotifyNonlinearVirtual
)
363 g_assert(e
->type
== FocusOut
);
365 /* These are ones we never want.. */
367 /* This means focus was taken by a keyboard/mouse grab. */
368 if (mode
== NotifyGrab
)
370 /* This means focus was grabbed on a window and it was released. */
371 if (mode
== NotifyUngrab
)
374 /* Focus left the root window revertedto state */
375 if (win
== RootWindow(ob_display
, ob_screen
))
378 /* These are the ones we want.. */
380 /* This means focus moved from a client to the root window */
381 if (detail
== NotifyVirtual
)
383 /* This means focus moved from one client to another */
384 if (detail
== NotifyNonlinearVirtual
)
392 static Bool
event_look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
394 return e
->type
== FocusIn
&& wanted_focusevent(e
, FALSE
);
397 static Bool
event_look_for_focusin_client(Display
*d
, XEvent
*e
, XPointer arg
)
399 return e
->type
== FocusIn
&& wanted_focusevent(e
, TRUE
);
402 static void print_focusevent(XEvent
*e
)
404 gint mode
= e
->xfocus
.mode
;
405 gint detail
= e
->xfocus
.detail
;
406 Window win
= e
->xany
.window
;
407 const gchar
*modestr
, *detailstr
;
410 case NotifyNormal
: modestr
="NotifyNormal"; break;
411 case NotifyGrab
: modestr
="NotifyGrab"; break;
412 case NotifyUngrab
: modestr
="NotifyUngrab"; break;
413 case NotifyWhileGrabbed
: modestr
="NotifyWhileGrabbed"; break;
416 case NotifyAncestor
: detailstr
="NotifyAncestor"; break;
417 case NotifyVirtual
: detailstr
="NotifyVirtual"; break;
418 case NotifyInferior
: detailstr
="NotifyInferior"; break;
419 case NotifyNonlinear
: detailstr
="NotifyNonlinear"; break;
420 case NotifyNonlinearVirtual
: detailstr
="NotifyNonlinearVirtual"; break;
421 case NotifyPointer
: detailstr
="NotifyPointer"; break;
422 case NotifyPointerRoot
: detailstr
="NotifyPointerRoot"; break;
423 case NotifyDetailNone
: detailstr
="NotifyDetailNone"; break;
426 if (mode
== NotifyGrab
|| mode
== NotifyUngrab
)
431 ob_debug_type(OB_DEBUG_FOCUS
, "Focus%s 0x%x mode=%s detail=%s\n",
432 (e
->xfocus
.type
== FocusIn
? "In" : "Out"),
438 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
443 if (!wanted_focusevent(e
, FALSE
))
448 if (!wanted_focusevent(e
, FALSE
))
455 static void event_process(const XEvent
*ec
, gpointer data
)
458 ObClient
*client
= NULL
;
460 ObDockApp
*dockapp
= NULL
;
461 ObWindow
*obwin
= NULL
;
463 ObEventData
*ed
= data
;
464 ObPrompt
*prompt
= NULL
;
466 /* make a copy we can mangle */
470 window
= event_get_window(e
);
471 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
472 switch (obwin
->type
) {
474 dock
= WINDOW_AS_DOCK(obwin
);
477 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
480 client
= WINDOW_AS_CLIENT(obwin
);
481 /* events on clients can be events on prompt windows too */
482 prompt
= client
->prompt
;
485 /* not to be used for events */
486 g_assert_not_reached();
488 case Window_Internal
:
489 /* we don't do anything with events directly on these windows */
492 prompt
= WINDOW_AS_PROMPT(obwin
);
497 event_set_curtime(e
);
498 event_curserial
= e
->xany
.serial
;
500 if (event_ignore(e
, client
)) {
507 /* deal with it in the kernel */
509 if (menu_frame_visible
&&
510 (e
->type
== EnterNotify
|| e
->type
== LeaveNotify
))
512 /* crossing events for menu */
513 event_handle_menu(e
);
514 } else if (e
->type
== FocusIn
) {
516 e
->xfocus
.detail
== NotifyInferior
)
518 ob_debug_type(OB_DEBUG_FOCUS
,
519 "Focus went to the frame window");
521 focus_left_screen
= FALSE
;
523 focus_fallback(FALSE
, config_focus_under_mouse
, TRUE
, TRUE
);
525 /* We don't get a FocusOut for this case, because it's just moving
526 from our Inferior up to us. This happens when iconifying a
527 window with RevertToParent focus */
528 frame_adjust_focus(client
->frame
, FALSE
);
529 /* focus_set_client(NULL) has already been called */
531 else if (e
->xfocus
.detail
== NotifyPointerRoot
||
532 e
->xfocus
.detail
== NotifyDetailNone
||
533 e
->xfocus
.detail
== NotifyInferior
||
534 e
->xfocus
.detail
== NotifyNonlinear
)
538 ob_debug_type(OB_DEBUG_FOCUS
,
539 "Focus went to root or pointer root/none\n");
541 if (e
->xfocus
.detail
== NotifyInferior
||
542 e
->xfocus
.detail
== NotifyNonlinear
)
544 focus_left_screen
= FALSE
;
547 /* If another FocusIn is in the queue then don't fallback yet. This
548 fixes the fun case of:
549 window map -> send focusin
550 window unmap -> get focusout
551 window map -> send focusin
552 get first focus out -> fall back to something (new window
553 hasn't received focus yet, so something else) -> send focusin
554 which means the "something else" is the last thing to get a
555 focusin sent to it, so the new window doesn't end up with focus.
557 But if the other focus in is something like PointerRoot then we
558 still want to fall back.
560 if (XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin_client
,
563 XPutBackEvent(ob_display
, &ce
);
564 ob_debug_type(OB_DEBUG_FOCUS
,
565 " but another FocusIn is coming\n");
567 /* Focus has been reverted.
569 FocusOut events come after UnmapNotify, so we don't need to
570 worry about focusing an invalid window
573 if (!focus_left_screen
)
574 focus_fallback(FALSE
, config_focus_under_mouse
,
580 ob_debug_type(OB_DEBUG_FOCUS
,
581 "Focus went to a window that is already gone\n");
583 /* If you send focus to a window and then it disappears, you can
584 get the FocusIn for it, after it is unmanaged.
585 Just wait for the next FocusOut/FocusIn pair, but make note that
586 the window that was focused no longer is. */
587 focus_set_client(NULL
);
589 else if (client
!= focus_client
) {
590 focus_left_screen
= FALSE
;
591 frame_adjust_focus(client
->frame
, TRUE
);
592 focus_set_client(client
);
593 client_calc_layer(client
);
594 client_bring_helper_windows(client
);
596 } else if (e
->type
== FocusOut
) {
599 /* Look for the followup FocusIn */
600 if (!XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin
, NULL
)) {
601 /* There is no FocusIn, this means focus went to a window that
602 is not being managed, or a window on another screen. */
606 xerror_set_ignore(TRUE
);
607 if (XGetInputFocus(ob_display
, &win
, &i
) != 0 &&
608 XGetGeometry(ob_display
, win
, &root
, &i
,&i
,&u
,&u
,&u
,&u
) != 0 &&
609 root
!= RootWindow(ob_display
, ob_screen
))
611 ob_debug_type(OB_DEBUG_FOCUS
,
612 "Focus went to another screen !\n");
613 focus_left_screen
= TRUE
;
616 ob_debug_type(OB_DEBUG_FOCUS
,
617 "Focus went to a black hole !\n");
618 xerror_set_ignore(FALSE
);
619 /* nothing is focused */
620 focus_set_client(NULL
);
622 /* Focus moved, so process the FocusIn event */
623 ObEventData ed
= { .ignored
= FALSE
};
624 event_process(&ce
, &ed
);
626 /* The FocusIn was ignored, this means it was on a window
627 that isn't a client. */
628 ob_debug_type(OB_DEBUG_FOCUS
,
629 "Focus went to an unmanaged window 0x%x !\n",
631 focus_fallback(TRUE
, config_focus_under_mouse
, TRUE
, TRUE
);
635 if (client
&& client
!= focus_client
) {
636 frame_adjust_focus(client
->frame
, FALSE
);
637 /* focus_set_client(NULL) has already been called in this
638 section or by focus_fallback */
642 event_handle_client(client
, e
);
644 event_handle_dockapp(dockapp
, e
);
646 event_handle_dock(dock
, e
);
647 else if (window
== RootWindow(ob_display
, ob_screen
))
648 event_handle_root(e
);
649 else if (e
->type
== MapRequest
)
650 client_manage(window
, NULL
);
651 else if (e
->type
== MappingNotify
) {
652 /* keyboard layout changes for modifier mapping changes. reload the
653 modifier map, and rebind all the key bindings as appropriate */
654 ob_debug("Kepboard map changed. Reloading keyboard bindings.\n");
655 modkeys_shutdown(TRUE
);
656 modkeys_startup(TRUE
);
659 else if (e
->type
== ClientMessage
) {
660 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
661 windows that are not managed yet. */
662 if (e
->xclient
.message_type
== prop_atoms
.net_request_frame_extents
) {
663 /* Pretend to manage the client, getting information used to
664 determine its decorations */
665 ObClient
*c
= client_fake_manage(e
->xclient
.window
);
668 /* set the frame extents on the window */
669 vals
[0] = c
->frame
->size
.left
;
670 vals
[1] = c
->frame
->size
.right
;
671 vals
[2] = c
->frame
->size
.top
;
672 vals
[3] = c
->frame
->size
.bottom
;
673 PROP_SETA32(e
->xclient
.window
, net_frame_extents
,
676 /* Free the pretend client */
677 client_fake_unmanage(c
);
680 else if (e
->type
== ConfigureRequest
) {
681 /* unhandled configure requests must be used to configure the
685 xwc
.x
= e
->xconfigurerequest
.x
;
686 xwc
.y
= e
->xconfigurerequest
.y
;
687 xwc
.width
= e
->xconfigurerequest
.width
;
688 xwc
.height
= e
->xconfigurerequest
.height
;
689 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
690 xwc
.sibling
= e
->xconfigurerequest
.above
;
691 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
693 /* we are not to be held responsible if someone sends us an
695 xerror_set_ignore(TRUE
);
696 XConfigureWindow(ob_display
, window
,
697 e
->xconfigurerequest
.value_mask
, &xwc
);
698 xerror_set_ignore(FALSE
);
701 else if (extensions_sync
&&
702 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
704 XSyncAlarmNotifyEvent
*se
= (XSyncAlarmNotifyEvent
*)e
;
705 if (se
->alarm
== moveresize_alarm
&& moveresize_in_progress
)
710 if (prompt
&& event_handle_prompt(prompt
, e
))
712 else if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
) {
713 /* If the button press was on some non-root window, or was physically
714 on the root window, then process it */
715 if (window
!= RootWindow(ob_display
, ob_screen
) ||
716 e
->xbutton
.subwindow
== None
)
718 event_handle_user_input(client
, e
);
720 /* Otherwise only process it if it was physically on an openbox
725 if ((w
= g_hash_table_lookup(window_map
, &e
->xbutton
.subwindow
)) &&
726 WINDOW_IS_INTERNAL(w
))
728 event_handle_user_input(client
, e
);
732 else if (e
->type
== KeyPress
|| e
->type
== KeyRelease
||
733 e
->type
== MotionNotify
)
734 event_handle_user_input(client
, e
);
736 /* if something happens and it's not from an XEvent, then we don't know
738 event_curtime
= CurrentTime
;
742 static void event_handle_root(XEvent
*e
)
748 ob_debug("Another WM has requested to replace us. Exiting.\n");
753 if (e
->xclient
.format
!= 32) break;
755 msgtype
= e
->xclient
.message_type
;
756 if (msgtype
== prop_atoms
.net_current_desktop
) {
757 guint d
= e
->xclient
.data
.l
[0];
758 if (d
< screen_num_desktops
) {
759 event_curtime
= e
->xclient
.data
.l
[1];
760 if (event_curtime
== 0)
761 ob_debug_type(OB_DEBUG_APP_BUGS
,
762 "_NET_CURRENT_DESKTOP message is missing "
764 screen_set_desktop(d
, TRUE
);
766 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
767 guint d
= e
->xclient
.data
.l
[0];
768 if (d
> 0 && d
<= 1000)
769 screen_set_num_desktops(d
);
770 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
771 screen_show_desktop(e
->xclient
.data
.l
[0] != 0, NULL
);
772 } else if (msgtype
== prop_atoms
.ob_control
) {
773 ob_debug("OB_CONTROL: %d\n", e
->xclient
.data
.l
[0]);
774 if (e
->xclient
.data
.l
[0] == 1)
776 else if (e
->xclient
.data
.l
[0] == 2)
778 else if (e
->xclient
.data
.l
[0] == 3)
780 } else if (msgtype
== prop_atoms
.wm_protocols
) {
781 if ((Atom
)e
->xclient
.data
.l
[0] == prop_atoms
.net_wm_ping
)
782 ping_got_pong(e
->xclient
.data
.l
[1]);
786 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
) {
787 ob_debug("UPDATE DESKTOP NAMES\n");
788 screen_update_desktop_names();
790 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
791 screen_update_layout();
793 case ConfigureNotify
:
795 XRRUpdateConfiguration(e
);
804 void event_enter_client(ObClient
*client
)
806 g_assert(config_focus_follow
);
808 if (is_enter_focus_event_ignored(event_curserial
)) {
809 ob_debug_type(OB_DEBUG_FOCUS
, "Ignoring enter event with serial %lu\n"
810 "on client 0x%x", event_curserial
, client
->window
);
814 if (client_enter_focusable(client
) && client_can_focus(client
)) {
815 if (config_focus_delay
) {
816 ObFocusDelayData
*data
;
818 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
820 data
= g_new(ObFocusDelayData
, 1);
821 data
->client
= client
;
822 data
->time
= event_curtime
;
823 data
->serial
= event_curserial
;
825 ob_main_loop_timeout_add(ob_main_loop
,
826 config_focus_delay
* 1000,
828 data
, focus_delay_cmp
, focus_delay_dest
);
830 ObFocusDelayData data
;
831 data
.client
= client
;
832 data
.time
= event_curtime
;
833 data
.serial
= event_curserial
;
834 focus_delay_func(&data
);
839 static void event_handle_client(ObClient
*client
, XEvent
*e
)
844 static gint px
= -1, py
= -1;
846 static ObFrameContext pcon
= OB_FRAME_CONTEXT_NONE
;
850 /* save where the press occured for the first button pressed */
852 pb
= e
->xbutton
.button
;
856 pcon
= frame_context(client
, e
->xbutton
.window
, px
, py
);
857 pcon
= mouse_button_frame_context(pcon
, e
->xbutton
.button
,
861 /* Wheel buttons don't draw because they are an instant click, so it
862 is a waste of resources to go drawing it.
863 if the user is doing an interactive thing, or has a menu open then
864 the mouse is grabbed (possibly) and if we get these events we don't
865 want to deal with them
867 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5) &&
870 /* use where the press occured */
871 con
= frame_context(client
, e
->xbutton
.window
, px
, py
);
872 con
= mouse_button_frame_context(con
, e
->xbutton
.button
,
875 /* button presses on CLIENT_CONTEXTs are not accompanied by a
876 release because they are Replayed to the client */
877 if ((e
->type
== ButtonRelease
|| CLIENT_CONTEXT(con
, client
)) &&
878 e
->xbutton
.button
== pb
)
879 pb
= 0, px
= py
= -1, pcon
= OB_FRAME_CONTEXT_NONE
;
882 case OB_FRAME_CONTEXT_MAXIMIZE
:
883 client
->frame
->max_press
= (e
->type
== ButtonPress
);
884 frame_adjust_state(client
->frame
);
886 case OB_FRAME_CONTEXT_CLOSE
:
887 client
->frame
->close_press
= (e
->type
== ButtonPress
);
888 frame_adjust_state(client
->frame
);
890 case OB_FRAME_CONTEXT_ICONIFY
:
891 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
892 frame_adjust_state(client
->frame
);
894 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
895 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
896 frame_adjust_state(client
->frame
);
898 case OB_FRAME_CONTEXT_SHADE
:
899 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
900 frame_adjust_state(client
->frame
);
903 /* nothing changes with clicks for any other contexts */
909 /* when there is a grab on the pointer, we won't get enter/leave
910 notifies, but we still get motion events */
911 if (grab_on_pointer()) break;
913 con
= frame_context(client
, e
->xmotion
.window
,
914 e
->xmotion
.x
, e
->xmotion
.y
);
916 case OB_FRAME_CONTEXT_TITLEBAR
:
917 case OB_FRAME_CONTEXT_TLCORNER
:
918 case OB_FRAME_CONTEXT_TRCORNER
:
919 /* we've left the button area inside the titlebar */
920 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
921 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
922 client
->frame
->close_hover
)
924 client
->frame
->max_hover
= FALSE
;
925 client
->frame
->desk_hover
= FALSE
;
926 client
->frame
->shade_hover
= FALSE
;
927 client
->frame
->iconify_hover
= FALSE
;
928 client
->frame
->close_hover
= FALSE
;
929 frame_adjust_state(client
->frame
);
932 case OB_FRAME_CONTEXT_MAXIMIZE
:
933 if (!client
->frame
->max_hover
&& !pb
) {
934 client
->frame
->max_hover
= TRUE
;
935 frame_adjust_state(client
->frame
);
938 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
939 if (!client
->frame
->desk_hover
&& !pb
) {
940 client
->frame
->desk_hover
= TRUE
;
941 frame_adjust_state(client
->frame
);
944 case OB_FRAME_CONTEXT_SHADE
:
945 if (!client
->frame
->shade_hover
&& !pb
) {
946 client
->frame
->shade_hover
= TRUE
;
947 frame_adjust_state(client
->frame
);
950 case OB_FRAME_CONTEXT_ICONIFY
:
951 if (!client
->frame
->iconify_hover
&& !pb
) {
952 client
->frame
->iconify_hover
= TRUE
;
953 frame_adjust_state(client
->frame
);
956 case OB_FRAME_CONTEXT_CLOSE
:
957 if (!client
->frame
->close_hover
&& !pb
) {
958 client
->frame
->close_hover
= TRUE
;
959 frame_adjust_state(client
->frame
);
967 con
= frame_context(client
, e
->xcrossing
.window
,
968 e
->xcrossing
.x
, e
->xcrossing
.y
);
970 case OB_FRAME_CONTEXT_TITLEBAR
:
971 case OB_FRAME_CONTEXT_TLCORNER
:
972 case OB_FRAME_CONTEXT_TRCORNER
:
973 /* we've left the button area inside the titlebar */
974 client
->frame
->max_hover
= FALSE
;
975 client
->frame
->desk_hover
= FALSE
;
976 client
->frame
->shade_hover
= FALSE
;
977 client
->frame
->iconify_hover
= FALSE
;
978 client
->frame
->close_hover
= FALSE
;
979 if (e
->xcrossing
.mode
== NotifyGrab
) {
980 client
->frame
->max_press
= FALSE
;
981 client
->frame
->desk_press
= FALSE
;
982 client
->frame
->shade_press
= FALSE
;
983 client
->frame
->iconify_press
= FALSE
;
984 client
->frame
->close_press
= FALSE
;
986 frame_adjust_state(client
->frame
);
988 case OB_FRAME_CONTEXT_MAXIMIZE
:
989 client
->frame
->max_hover
= FALSE
;
990 if (e
->xcrossing
.mode
== NotifyGrab
)
991 client
->frame
->max_press
= FALSE
;
992 frame_adjust_state(client
->frame
);
994 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
995 client
->frame
->desk_hover
= FALSE
;
996 if (e
->xcrossing
.mode
== NotifyGrab
)
997 client
->frame
->desk_press
= FALSE
;
998 frame_adjust_state(client
->frame
);
1000 case OB_FRAME_CONTEXT_SHADE
:
1001 client
->frame
->shade_hover
= FALSE
;
1002 if (e
->xcrossing
.mode
== NotifyGrab
)
1003 client
->frame
->shade_press
= FALSE
;
1004 frame_adjust_state(client
->frame
);
1006 case OB_FRAME_CONTEXT_ICONIFY
:
1007 client
->frame
->iconify_hover
= FALSE
;
1008 if (e
->xcrossing
.mode
== NotifyGrab
)
1009 client
->frame
->iconify_press
= FALSE
;
1010 frame_adjust_state(client
->frame
);
1012 case OB_FRAME_CONTEXT_CLOSE
:
1013 client
->frame
->close_hover
= FALSE
;
1014 if (e
->xcrossing
.mode
== NotifyGrab
)
1015 client
->frame
->close_press
= FALSE
;
1016 frame_adjust_state(client
->frame
);
1018 case OB_FRAME_CONTEXT_FRAME
:
1019 /* When the mouse leaves an animating window, don't use the
1020 corresponding enter events. Pretend like the animating window
1021 doesn't even exist..! */
1022 if (frame_iconify_animating(client
->frame
))
1023 event_end_ignore_all_enters(event_start_ignore_all_enters());
1025 ob_debug_type(OB_DEBUG_FOCUS
,
1026 "%sNotify mode %d detail %d on %lx\n",
1027 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1029 e
->xcrossing
.detail
, (client
?client
->window
:0));
1030 if (grab_on_keyboard())
1032 if (config_focus_follow
&& config_focus_delay
&&
1033 /* leave inferior events can happen when the mouse goes onto
1034 the window's border and then into the window before the
1036 e
->xcrossing
.detail
!= NotifyInferior
)
1038 ob_main_loop_timeout_remove_data(ob_main_loop
,
1049 con
= frame_context(client
, e
->xcrossing
.window
,
1050 e
->xcrossing
.x
, e
->xcrossing
.y
);
1052 case OB_FRAME_CONTEXT_MAXIMIZE
:
1053 client
->frame
->max_hover
= TRUE
;
1054 if (e
->xcrossing
.mode
== NotifyUngrab
)
1055 client
->frame
->max_press
= (con
== pcon
);
1056 frame_adjust_state(client
->frame
);
1058 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
1059 client
->frame
->desk_hover
= TRUE
;
1060 if (e
->xcrossing
.mode
== NotifyUngrab
)
1061 client
->frame
->desk_press
= (con
== pcon
);
1062 frame_adjust_state(client
->frame
);
1064 case OB_FRAME_CONTEXT_SHADE
:
1065 client
->frame
->shade_hover
= TRUE
;
1066 if (e
->xcrossing
.mode
== NotifyUngrab
)
1067 client
->frame
->shade_press
= (con
== pcon
);
1068 frame_adjust_state(client
->frame
);
1070 case OB_FRAME_CONTEXT_ICONIFY
:
1071 client
->frame
->iconify_hover
= TRUE
;
1072 if (e
->xcrossing
.mode
== NotifyUngrab
)
1073 client
->frame
->iconify_press
= (con
== pcon
);
1074 frame_adjust_state(client
->frame
);
1076 case OB_FRAME_CONTEXT_CLOSE
:
1077 client
->frame
->close_hover
= TRUE
;
1078 if (e
->xcrossing
.mode
== NotifyUngrab
)
1079 client
->frame
->close_press
= (con
== pcon
);
1080 frame_adjust_state(client
->frame
);
1082 case OB_FRAME_CONTEXT_FRAME
:
1083 if (grab_on_keyboard())
1085 if (e
->xcrossing
.mode
== NotifyGrab
||
1086 e
->xcrossing
.mode
== NotifyUngrab
||
1087 /*ignore enters when we're already in the window */
1088 e
->xcrossing
.detail
== NotifyInferior
)
1090 ob_debug_type(OB_DEBUG_FOCUS
,
1091 "%sNotify mode %d detail %d serial %lu on %lx "
1093 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1095 e
->xcrossing
.detail
,
1096 e
->xcrossing
.serial
,
1097 client
?client
->window
:0);
1100 ob_debug_type(OB_DEBUG_FOCUS
,
1101 "%sNotify mode %d detail %d serial %lu on %lx, "
1102 "focusing window\n",
1103 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1105 e
->xcrossing
.detail
,
1106 e
->xcrossing
.serial
,
1107 (client
?client
->window
:0));
1108 if (config_focus_follow
)
1109 event_enter_client(client
);
1117 case ConfigureRequest
:
1119 /* dont compress these unless you're going to watch for property
1120 notifies in between (these can change what the configure would
1122 also you can't compress stacking events
1126 gboolean move
= FALSE
;
1127 gboolean resize
= FALSE
;
1129 /* get the current area */
1130 RECT_TO_DIMS(client
->area
, x
, y
, w
, h
);
1132 ob_debug("ConfigureRequest for \"%s\" desktop %d wmstate %d "
1134 " x %d y %d w %d h %d b %d\n",
1136 screen_desktop
, client
->wmstate
, client
->frame
->visible
,
1137 x
, y
, w
, h
, client
->border_width
);
1139 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
1140 if (client
->border_width
!= e
->xconfigurerequest
.border_width
) {
1141 client
->border_width
= e
->xconfigurerequest
.border_width
;
1143 /* if the border width is changing then that is the same
1144 as requesting a resize, but we don't actually change
1145 the client's border, so it will change their root
1146 coordiantes (since they include the border width) and
1147 we need to a notify then */
1152 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
1153 ObClient
*sibling
= NULL
;
1154 gulong ignore_start
;
1157 /* get the sibling */
1158 if (e
->xconfigurerequest
.value_mask
& CWSibling
) {
1160 win
= g_hash_table_lookup(window_map
,
1161 &e
->xconfigurerequest
.above
);
1162 if (win
&& WINDOW_IS_CLIENT(win
) &&
1163 WINDOW_AS_CLIENT(win
) != client
)
1165 sibling
= WINDOW_AS_CLIENT(win
);
1168 /* an invalid sibling was specified so don't restack at
1169 all, it won't make sense no matter what we do */
1174 if (!config_focus_under_mouse
)
1175 ignore_start
= event_start_ignore_all_enters();
1176 stacking_restack_request(client
, sibling
,
1177 e
->xconfigurerequest
.detail
);
1178 if (!config_focus_under_mouse
)
1179 event_end_ignore_all_enters(ignore_start
);
1182 /* a stacking change moves the window without resizing */
1186 if ((e
->xconfigurerequest
.value_mask
& CWX
) ||
1187 (e
->xconfigurerequest
.value_mask
& CWY
) ||
1188 (e
->xconfigurerequest
.value_mask
& CWWidth
) ||
1189 (e
->xconfigurerequest
.value_mask
& CWHeight
))
1191 if (e
->xconfigurerequest
.value_mask
& CWX
) {
1192 /* don't allow clients to move shaded windows (fvwm does this)
1194 if (!client
->shaded
)
1195 x
= e
->xconfigurerequest
.x
;
1198 if (e
->xconfigurerequest
.value_mask
& CWY
) {
1199 /* don't allow clients to move shaded windows (fvwm does this)
1201 if (!client
->shaded
)
1202 y
= e
->xconfigurerequest
.y
;
1206 if (e
->xconfigurerequest
.value_mask
& CWWidth
) {
1207 w
= e
->xconfigurerequest
.width
;
1210 if (e
->xconfigurerequest
.value_mask
& CWHeight
) {
1211 h
= e
->xconfigurerequest
.height
;
1216 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
1217 "move %d resize %d\n",
1218 e
->xconfigurerequest
.value_mask
& CWX
, x
,
1219 e
->xconfigurerequest
.value_mask
& CWY
, y
,
1220 e
->xconfigurerequest
.value_mask
& CWWidth
, w
,
1221 e
->xconfigurerequest
.value_mask
& CWHeight
, h
,
1224 /* check for broken apps moving to their root position
1226 XXX remove this some day...that would be nice. right now all
1227 kde apps do this when they try activate themselves on another
1228 desktop. eg. open amarok window on desktop 1, switch to desktop
1229 2, click amarok tray icon. it will move by its decoration size.
1231 if (x
!= client
->area
.x
&&
1232 x
== (client
->frame
->area
.x
+ client
->frame
->size
.left
-
1233 (gint
)client
->border_width
) &&
1234 y
!= client
->area
.y
&&
1235 y
== (client
->frame
->area
.y
+ client
->frame
->size
.top
-
1236 (gint
)client
->border_width
) &&
1237 w
== client
->area
.width
&&
1238 h
== client
->area
.height
)
1240 ob_debug_type(OB_DEBUG_APP_BUGS
,
1241 "Application %s is trying to move via "
1242 "ConfigureRequest to it's root window position "
1243 "but it is not using StaticGravity\n",
1249 /* they still requested a move, so don't change whether a
1250 notify is sent or not */
1256 client_try_configure(client
, &x
, &y
, &w
, &h
, &lw
, &lh
, FALSE
);
1258 /* if x was not given, then use gravity to figure out the new
1259 x. the reference point should not be moved */
1260 if ((e
->xconfigurerequest
.value_mask
& CWWidth
&&
1261 !(e
->xconfigurerequest
.value_mask
& CWX
)))
1262 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1263 /* if y was not given, then use gravity to figure out the new
1264 y. the reference point should not be moved */
1265 if ((e
->xconfigurerequest
.value_mask
& CWHeight
&&
1266 !(e
->xconfigurerequest
.value_mask
& CWY
)))
1267 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1269 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1271 ob_debug("Granting ConfigureRequest x %d y %d w %d h %d\n",
1273 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
, TRUE
);
1278 if (client
->ignore_unmaps
) {
1279 client
->ignore_unmaps
--;
1282 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1283 "ignores left %d\n",
1284 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
1285 client
->ignore_unmaps
);
1286 client_unmanage(client
);
1289 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
1290 client_unmanage(client
);
1292 case ReparentNotify
:
1293 /* this is when the client is first taken captive in the frame */
1294 if (e
->xreparent
.parent
== client
->frame
->window
) break;
1297 This event is quite rare and is usually handled in unmapHandler.
1298 However, if the window is unmapped when the reparent event occurs,
1299 the window manager never sees it because an unmap event is not sent
1300 to an already unmapped window.
1303 /* we don't want the reparent event, put it back on the stack for the
1304 X server to deal with after we unmanage the window */
1305 XPutBackEvent(ob_display
, e
);
1307 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
1308 client_unmanage(client
);
1311 ob_debug("MapRequest for 0x%lx\n", client
->window
);
1312 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
1313 does, we don't want it!
1314 it can happen now when the window is on
1315 another desktop, but we still don't
1317 client_activate(client
, FALSE
, TRUE
, TRUE
, TRUE
);
1320 /* validate cuz we query stuff off the client here */
1321 if (!client_validate(client
)) break;
1323 if (e
->xclient
.format
!= 32) return;
1325 msgtype
= e
->xclient
.message_type
;
1326 if (msgtype
== prop_atoms
.wm_change_state
) {
1327 /* compress changes into a single change */
1328 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1330 /* XXX: it would be nice to compress ALL messages of a
1331 type, not just messages in a row without other
1332 message types between. */
1333 if (ce
.xclient
.message_type
!= msgtype
) {
1334 XPutBackEvent(ob_display
, &ce
);
1337 e
->xclient
= ce
.xclient
;
1339 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1340 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
1341 /* compress changes into a single change */
1342 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1344 /* XXX: it would be nice to compress ALL messages of a
1345 type, not just messages in a row without other
1346 message types between. */
1347 if (ce
.xclient
.message_type
!= msgtype
) {
1348 XPutBackEvent(ob_display
, &ce
);
1351 e
->xclient
= ce
.xclient
;
1353 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1354 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1355 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1357 } else if (msgtype
== prop_atoms
.net_wm_state
) {
1358 gulong ignore_start
;
1360 /* can't compress these */
1361 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1362 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1363 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1364 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1365 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1368 /* ignore enter events caused by these like ob actions do */
1369 if (!config_focus_under_mouse
)
1370 ignore_start
= event_start_ignore_all_enters();
1371 client_set_state(client
, e
->xclient
.data
.l
[0],
1372 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1373 if (!config_focus_under_mouse
)
1374 event_end_ignore_all_enters(ignore_start
);
1375 } else if (msgtype
== prop_atoms
.net_close_window
) {
1376 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1377 client_close(client
);
1378 } else if (msgtype
== prop_atoms
.net_active_window
) {
1379 ob_debug("net_active_window for 0x%lx source=%s\n",
1381 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1382 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1383 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1384 /* XXX make use of data.l[2] !? */
1385 if (e
->xclient
.data
.l
[0] == 1 || e
->xclient
.data
.l
[0] == 2) {
1386 /* don't use the user's timestamp for client_focus, cuz if it's
1387 an old broken timestamp (happens all the time) then focus
1388 won't move even though we're trying to move it
1389 event_curtime = e->xclient.data.l[1];*/
1390 if (e
->xclient
.data
.l
[1] == 0)
1391 ob_debug_type(OB_DEBUG_APP_BUGS
,
1392 "_NET_ACTIVE_WINDOW message for window %s is"
1393 " missing a timestamp\n", client
->title
);
1395 ob_debug_type(OB_DEBUG_APP_BUGS
,
1396 "_NET_ACTIVE_WINDOW message for window %s is "
1397 "missing source indication\n");
1398 client_activate(client
, TRUE
, TRUE
, TRUE
,
1399 (e
->xclient
.data
.l
[0] == 0 ||
1400 e
->xclient
.data
.l
[0] == 2));
1401 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1402 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1403 client
->window
, e
->xclient
.data
.l
[2]);
1404 if ((Atom
)e
->xclient
.data
.l
[2] ==
1405 prop_atoms
.net_wm_moveresize_size_topleft
||
1406 (Atom
)e
->xclient
.data
.l
[2] ==
1407 prop_atoms
.net_wm_moveresize_size_top
||
1408 (Atom
)e
->xclient
.data
.l
[2] ==
1409 prop_atoms
.net_wm_moveresize_size_topright
||
1410 (Atom
)e
->xclient
.data
.l
[2] ==
1411 prop_atoms
.net_wm_moveresize_size_right
||
1412 (Atom
)e
->xclient
.data
.l
[2] ==
1413 prop_atoms
.net_wm_moveresize_size_right
||
1414 (Atom
)e
->xclient
.data
.l
[2] ==
1415 prop_atoms
.net_wm_moveresize_size_bottomright
||
1416 (Atom
)e
->xclient
.data
.l
[2] ==
1417 prop_atoms
.net_wm_moveresize_size_bottom
||
1418 (Atom
)e
->xclient
.data
.l
[2] ==
1419 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1420 (Atom
)e
->xclient
.data
.l
[2] ==
1421 prop_atoms
.net_wm_moveresize_size_left
||
1422 (Atom
)e
->xclient
.data
.l
[2] ==
1423 prop_atoms
.net_wm_moveresize_move
||
1424 (Atom
)e
->xclient
.data
.l
[2] ==
1425 prop_atoms
.net_wm_moveresize_size_keyboard
||
1426 (Atom
)e
->xclient
.data
.l
[2] ==
1427 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1429 moveresize_start(client
, e
->xclient
.data
.l
[0],
1430 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1431 e
->xclient
.data
.l
[2]);
1433 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1434 prop_atoms
.net_wm_moveresize_cancel
)
1435 moveresize_end(TRUE
);
1436 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1437 gint ograv
, x
, y
, w
, h
;
1439 ograv
= client
->gravity
;
1441 if (e
->xclient
.data
.l
[0] & 0xff)
1442 client
->gravity
= e
->xclient
.data
.l
[0] & 0xff;
1444 if (e
->xclient
.data
.l
[0] & 1 << 8)
1445 x
= e
->xclient
.data
.l
[1];
1448 if (e
->xclient
.data
.l
[0] & 1 << 9)
1449 y
= e
->xclient
.data
.l
[2];
1453 if (e
->xclient
.data
.l
[0] & 1 << 10) {
1454 w
= e
->xclient
.data
.l
[3];
1456 /* if x was not given, then use gravity to figure out the new
1457 x. the reference point should not be moved */
1458 if (!(e
->xclient
.data
.l
[0] & 1 << 8))
1459 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1462 w
= client
->area
.width
;
1464 if (e
->xclient
.data
.l
[0] & 1 << 11) {
1465 h
= e
->xclient
.data
.l
[4];
1467 /* if y was not given, then use gravity to figure out the new
1468 y. the reference point should not be moved */
1469 if (!(e
->xclient
.data
.l
[0] & 1 << 9))
1470 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1473 h
= client
->area
.height
;
1475 ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)\n",
1476 e
->xclient
.data
.l
[0] & 1 << 8, x
,
1477 e
->xclient
.data
.l
[0] & 1 << 9, y
,
1480 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1482 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
1484 client
->gravity
= ograv
;
1485 } else if (msgtype
== prop_atoms
.net_restack_window
) {
1486 if (e
->xclient
.data
.l
[0] != 2) {
1487 ob_debug_type(OB_DEBUG_APP_BUGS
,
1488 "_NET_RESTACK_WINDOW sent for window %s with "
1489 "invalid source indication %ld\n",
1490 client
->title
, e
->xclient
.data
.l
[0]);
1492 ObClient
*sibling
= NULL
;
1493 if (e
->xclient
.data
.l
[1]) {
1494 ObWindow
*win
= g_hash_table_lookup
1495 (window_map
, &e
->xclient
.data
.l
[1]);
1496 if (WINDOW_IS_CLIENT(win
) &&
1497 WINDOW_AS_CLIENT(win
) != client
)
1499 sibling
= WINDOW_AS_CLIENT(win
);
1501 if (sibling
== NULL
)
1502 ob_debug_type(OB_DEBUG_APP_BUGS
,
1503 "_NET_RESTACK_WINDOW sent for window %s "
1504 "with invalid sibling 0x%x\n",
1505 client
->title
, e
->xclient
.data
.l
[1]);
1507 if (e
->xclient
.data
.l
[2] == Below
||
1508 e
->xclient
.data
.l
[2] == BottomIf
||
1509 e
->xclient
.data
.l
[2] == Above
||
1510 e
->xclient
.data
.l
[2] == TopIf
||
1511 e
->xclient
.data
.l
[2] == Opposite
)
1513 gulong ignore_start
;
1515 if (!config_focus_under_mouse
)
1516 ignore_start
= event_start_ignore_all_enters();
1517 /* just raise, don't activate */
1518 stacking_restack_request(client
, sibling
,
1519 e
->xclient
.data
.l
[2]);
1520 if (!config_focus_under_mouse
)
1521 event_end_ignore_all_enters(ignore_start
);
1523 /* send a synthetic ConfigureNotify, cuz this is supposed
1524 to be like a ConfigureRequest. */
1525 client_reconfigure(client
, TRUE
);
1527 ob_debug_type(OB_DEBUG_APP_BUGS
,
1528 "_NET_RESTACK_WINDOW sent for window %s "
1529 "with invalid detail %d\n",
1530 client
->title
, e
->xclient
.data
.l
[2]);
1534 case PropertyNotify
:
1535 /* validate cuz we query stuff off the client here */
1536 if (!client_validate(client
)) break;
1538 /* compress changes to a single property into a single change */
1539 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1543 /* XXX: it would be nice to compress ALL changes to a property,
1544 not just changes in a row without other props between. */
1546 a
= ce
.xproperty
.atom
;
1547 b
= e
->xproperty
.atom
;
1551 if ((a
== prop_atoms
.net_wm_name
||
1552 a
== prop_atoms
.wm_name
||
1553 a
== prop_atoms
.net_wm_icon_name
||
1554 a
== prop_atoms
.wm_icon_name
)
1556 (b
== prop_atoms
.net_wm_name
||
1557 b
== prop_atoms
.wm_name
||
1558 b
== prop_atoms
.net_wm_icon_name
||
1559 b
== prop_atoms
.wm_icon_name
)) {
1562 if (a
== prop_atoms
.net_wm_icon
&&
1563 b
== prop_atoms
.net_wm_icon
)
1566 XPutBackEvent(ob_display
, &ce
);
1570 msgtype
= e
->xproperty
.atom
;
1571 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1572 ob_debug("Update NORMAL hints\n");
1573 client_update_normal_hints(client
);
1574 /* normal hints can make a window non-resizable */
1575 client_setup_decor_and_functions(client
, FALSE
);
1577 /* make sure the client's sizes are within its bounds, but only
1578 reconfigure the window if it needs to. emacs will update its
1579 normal hints every time it receives a conigurenotify */
1580 client_reconfigure(client
, FALSE
);
1581 } else if (msgtype
== XA_WM_HINTS
) {
1582 client_update_wmhints(client
);
1583 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1584 client_update_transient_for(client
);
1585 client_get_type_and_transientness(client
);
1586 /* type may have changed, so update the layer */
1587 client_calc_layer(client
);
1588 client_setup_decor_and_functions(client
, TRUE
);
1589 } else if (msgtype
== prop_atoms
.net_wm_name
||
1590 msgtype
== prop_atoms
.wm_name
||
1591 msgtype
== prop_atoms
.net_wm_icon_name
||
1592 msgtype
== prop_atoms
.wm_icon_name
) {
1593 client_update_title(client
);
1594 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1595 client_update_protocols(client
);
1596 client_setup_decor_and_functions(client
, TRUE
);
1598 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1599 client_update_strut(client
);
1601 else if (msgtype
== prop_atoms
.net_wm_strut_partial
) {
1602 client_update_strut(client
);
1604 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1605 client_update_icons(client
);
1607 else if (msgtype
== prop_atoms
.net_wm_icon_geometry
) {
1608 client_update_icon_geometry(client
);
1610 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1612 if (client
== focus_client
&&
1613 PROP_GET32(client
->window
, net_wm_user_time
, cardinal
, &t
) &&
1614 t
&& !event_time_after(t
, e
->xproperty
.time
) &&
1615 (!event_last_user_time
||
1616 event_time_after(t
, event_last_user_time
)))
1618 event_last_user_time
= t
;
1622 else if (msgtype
== prop_atoms
.net_wm_sync_request_counter
) {
1623 client_update_sync_request_counter(client
);
1627 case ColormapNotify
:
1628 client_update_colormap(client
, e
->xcolormap
.colormap
);
1633 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1634 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1635 frame_adjust_shape(client
->frame
);
1641 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1645 if (e
->xbutton
.button
== 1)
1646 stacking_raise(DOCK_AS_WINDOW(s
));
1647 else if (e
->xbutton
.button
== 2)
1648 stacking_lower(DOCK_AS_WINDOW(s
));
1654 /* don't hide when moving into a dock app */
1655 if (e
->xcrossing
.detail
!= NotifyInferior
)
1661 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1665 dock_app_drag(app
, &e
->xmotion
);
1668 if (app
->ignore_unmaps
) {
1669 app
->ignore_unmaps
--;
1672 dock_remove(app
, TRUE
);
1675 dock_remove(app
, FALSE
);
1677 case ReparentNotify
:
1678 dock_remove(app
, FALSE
);
1680 case ConfigureNotify
:
1681 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1686 static ObMenuFrame
* find_active_menu(void)
1689 ObMenuFrame
*ret
= NULL
;
1691 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1700 static ObMenuFrame
* find_active_or_last_menu(void)
1702 ObMenuFrame
*ret
= NULL
;
1704 ret
= find_active_menu();
1705 if (!ret
&& menu_frame_visible
)
1706 ret
= menu_frame_visible
->data
;
1710 static gboolean
event_handle_prompt(ObPrompt
*p
, XEvent
*e
)
1716 return prompt_mouse_event(p
, e
);
1719 return prompt_key_event(p
, e
);
1725 static gboolean
event_handle_menu_keyboard(XEvent
*ev
)
1727 guint keycode
, state
;
1730 gboolean ret
= FALSE
;
1732 keycode
= ev
->xkey
.keycode
;
1733 state
= ev
->xkey
.state
;
1734 unikey
= translate_unichar(keycode
);
1736 frame
= find_active_or_last_menu();
1738 g_assert_not_reached(); /* there is no active menu */
1740 /* Allow control while going thru the menu */
1741 else if (ev
->type
== KeyPress
&& (state
& ~ControlMask
) == 0) {
1742 frame
->got_press
= TRUE
;
1744 if (keycode
== ob_keycode(OB_KEY_ESCAPE
)) {
1745 menu_frame_hide_all();
1749 else if (keycode
== ob_keycode(OB_KEY_LEFT
)) {
1750 /* Left goes to the parent menu */
1751 menu_frame_select(frame
, NULL
, TRUE
);
1755 else if (keycode
== ob_keycode(OB_KEY_RIGHT
)) {
1756 /* Right goes to the selected submenu */
1757 if (frame
->child
) menu_frame_select_next(frame
->child
);
1761 else if (keycode
== ob_keycode(OB_KEY_UP
)) {
1762 menu_frame_select_previous(frame
);
1766 else if (keycode
== ob_keycode(OB_KEY_DOWN
)) {
1767 menu_frame_select_next(frame
);
1772 /* Use KeyRelease events for running things so that the key release doesn't
1773 get sent to the focused application.
1775 Allow ControlMask only, and don't bother if the menu is empty */
1776 else if (ev
->type
== KeyRelease
&& (state
& ~ControlMask
) == 0 &&
1777 frame
->entries
&& frame
->got_press
)
1779 if (keycode
== ob_keycode(OB_KEY_RETURN
)) {
1780 /* Enter runs the active item or goes into the submenu.
1781 Control-Enter runs it without closing the menu. */
1783 menu_frame_select_next(frame
->child
);
1784 else if (frame
->selected
)
1785 menu_entry_frame_execute(frame
->selected
, state
);
1790 /* keyboard accelerator shortcuts. (if it was a valid key) */
1791 else if (unikey
!= 0) {
1794 ObMenuEntryFrame
*found
= NULL
;
1795 guint num_found
= 0;
1797 /* start after the selected one */
1798 start
= frame
->entries
;
1799 if (frame
->selected
) {
1800 for (it
= start
; frame
->selected
!= it
->data
;
1801 it
= g_list_next(it
))
1802 g_assert(it
!= NULL
); /* nothing was selected? */
1803 /* next with wraparound */
1804 start
= g_list_next(it
);
1805 if (start
== NULL
) start
= frame
->entries
;
1810 ObMenuEntryFrame
*e
= it
->data
;
1811 gunichar entrykey
= 0;
1813 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1814 entrykey
= e
->entry
->data
.normal
.shortcut
;
1815 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1816 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1818 if (unikey
== entrykey
) {
1819 if (found
== NULL
) found
= e
;
1823 /* next with wraparound */
1824 it
= g_list_next(it
);
1825 if (it
== NULL
) it
= frame
->entries
;
1826 } while (it
!= start
);
1829 if (found
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
1832 menu_frame_select(frame
, found
, TRUE
);
1833 usleep(50000); /* highlight the item for a short bit so the
1834 user can see what happened */
1835 menu_entry_frame_execute(found
, state
);
1837 menu_frame_select(frame
, found
, TRUE
);
1839 menu_frame_select_next(frame
->child
);
1850 static gboolean
event_handle_menu(XEvent
*ev
)
1853 ObMenuEntryFrame
*e
;
1854 gboolean ret
= TRUE
;
1858 if (menu_hide_delay_reached() &&
1859 (ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5))
1861 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1862 ev
->xbutton
.y_root
)))
1864 menu_frame_select(e
->frame
, e
, TRUE
);
1865 menu_entry_frame_execute(e
, ev
->xbutton
.state
);
1868 menu_frame_hide_all();
1872 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1873 if (e
->ignore_enters
)
1875 else if (!(f
= find_active_menu()) ||
1877 f
->parent
== e
->frame
||
1878 f
->child
== e
->frame
)
1879 menu_frame_select(e
->frame
, e
, FALSE
);
1883 /*ignore leaves when we're already in the window */
1884 if (ev
->xcrossing
.detail
== NotifyInferior
)
1887 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1888 (f
= find_active_menu()) && f
->selected
== e
&&
1889 e
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1891 menu_frame_select(e
->frame
, NULL
, FALSE
);
1895 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1896 ev
->xmotion
.y_root
)))
1897 if (!(f
= find_active_menu()) ||
1899 f
->parent
== e
->frame
||
1900 f
->child
== e
->frame
)
1901 menu_frame_select(e
->frame
, e
, FALSE
);
1905 ret
= event_handle_menu_keyboard(ev
);
1911 static void event_handle_user_input(ObClient
*client
, XEvent
*e
)
1913 g_assert(e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
1914 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
1915 e
->type
== KeyRelease
);
1917 if (menu_frame_visible
) {
1918 if (event_handle_menu(e
))
1919 /* don't use the event if the menu used it, but if the menu
1920 didn't use it and it's a keypress that is bound, it will
1921 close the menu and be used */
1925 /* if the keyboard interactive action uses the event then dont
1926 use it for bindings. likewise is moveresize uses the event. */
1927 if (!actions_interactive_input_event(e
) && !moveresize_event(e
)) {
1928 if (moveresize_in_progress
)
1929 /* make further actions work on the client being
1931 client
= moveresize_client
;
1933 if (e
->type
== ButtonPress
||
1934 e
->type
== ButtonRelease
||
1935 e
->type
== MotionNotify
)
1937 /* the frame may not be "visible" but they can still click on it
1938 in the case where it is animating before disappearing */
1939 if (!client
|| !frame_iconify_animating(client
->frame
))
1940 mouse_event(client
, e
);
1942 keyboard_event((focus_cycle_target
? focus_cycle_target
:
1943 (client
? client
: focus_client
)), e
);
1947 static void focus_delay_dest(gpointer data
)
1952 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
1954 const ObFocusDelayData
*f1
= d1
;
1955 return f1
->client
== d2
;
1958 static gboolean
focus_delay_func(gpointer data
)
1960 ObFocusDelayData
*d
= data
;
1961 Time old
= event_curtime
;
1963 /* don't move focus and kill the menu or the move/resize */
1964 if (menu_frame_visible
|| moveresize_in_progress
) return FALSE
;
1966 event_curtime
= d
->time
;
1967 event_curserial
= d
->serial
;
1968 if (client_focus(d
->client
) && config_focus_raise
)
1969 stacking_raise(CLIENT_AS_WINDOW(d
->client
));
1970 event_curtime
= old
;
1971 return FALSE
; /* no repeat */
1974 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1976 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1980 void event_halt_focus_delay(void)
1982 /* ignore all enter events up till the event which caused this to occur */
1983 if (event_curserial
) event_ignore_enter_range(1, event_curserial
);
1984 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1987 gulong
event_start_ignore_all_enters(void)
1989 return NextRequest(ob_display
);
1992 static void event_ignore_enter_range(gulong start
, gulong end
)
1996 g_assert(start
!= 0);
1999 r
= g_new(ObSerialRange
, 1);
2002 ignore_serials
= g_slist_prepend(ignore_serials
, r
);
2004 ob_debug_type(OB_DEBUG_FOCUS
, "ignoring enters from %lu until %lu\n",
2007 /* increment the serial so we don't ignore events we weren't meant to */
2008 PROP_ERASE(screen_support_win
, motif_wm_hints
);
2011 void event_end_ignore_all_enters(gulong start
)
2013 /* Use (NextRequest-1) so that we ignore up to the current serial only.
2014 Inside event_ignore_enter_range, we increment the serial by one, but if
2015 we ignore that serial too, then any enter events generated by mouse
2016 movement will be ignored until we create some further network traffic.
2017 Instead ignore up to NextRequest-1, then when we increment the serial,
2018 we will be *past* the range of ignored serials */
2019 event_ignore_enter_range(start
, NextRequest(ob_display
)-1);
2022 static gboolean
is_enter_focus_event_ignored(gulong serial
)
2026 for (it
= ignore_serials
; it
; it
= next
) {
2027 ObSerialRange
*r
= it
->data
;
2029 next
= g_slist_next(it
);
2031 if ((glong
)(serial
- r
->end
) > 0) {
2033 ignore_serials
= g_slist_delete_link(ignore_serials
, it
);
2036 else if ((glong
)(serial
- r
->start
) >= 0)
2042 void event_cancel_all_key_grabs(void)
2044 if (actions_interactive_act_running()) {
2045 actions_interactive_cancel_act();
2046 ob_debug("KILLED interactive action\n");
2048 else if (menu_frame_visible
) {
2049 menu_frame_hide_all();
2050 ob_debug("KILLED open menus\n");
2052 else if (moveresize_in_progress
) {
2053 moveresize_end(TRUE
);
2054 ob_debug("KILLED interactive moveresize\n");
2056 else if (grab_on_keyboard()) {
2058 ob_debug("KILLED active grab on keyboard\n");
2061 ungrab_passive_key();
2063 XSync(ob_display
, FALSE
);
2066 gboolean
event_time_after(Time t1
, Time t2
)
2068 g_assert(t1
!= CurrentTime
);
2069 g_assert(t2
!= CurrentTime
);
2072 Timestamp values wrap around (after about 49.7 days). The server, given
2073 its current time is represented by timestamp T, always interprets
2074 timestamps from clients by treating half of the timestamp space as being
2075 later in time than T.
2076 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
2079 /* TIME_HALF is half of the number space of a Time type variable */
2080 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
2082 if (t2
>= TIME_HALF
)
2083 /* t2 is in the second half so t1 might wrap around and be smaller than
2085 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
2087 /* t2 is in the first half so t1 has to come after it */
2088 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);
2091 Time
event_get_server_time(void)
2093 /* Generate a timestamp */
2096 XChangeProperty(ob_display
, screen_support_win
,
2097 prop_atoms
.wm_class
, prop_atoms
.string
,
2098 8, PropModeAppend
, NULL
, 0);
2099 XWindowEvent(ob_display
, screen_support_win
, PropertyChangeMask
, &event
);
2100 return event
.xproperty
.time
;