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
);
95 static void focus_delay_dest(gpointer data
);
96 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
);
97 static gboolean
focus_delay_func(gpointer data
);
98 static void focus_delay_client_dest(ObClient
*client
, gpointer data
);
100 Time event_curtime
= CurrentTime
;
101 Time event_last_user_time
= CurrentTime
;
103 static gboolean focus_left_screen
= FALSE
;
104 /*! A list of ObSerialRanges which are to be ignored for mouse enter events */
105 static GSList
*ignore_serials
= NULL
;
108 static void ice_handler(gint fd
, gpointer conn
)
111 IceProcessMessages(conn
, NULL
, &b
);
114 static void ice_watch(IceConn conn
, IcePointer data
, Bool opening
,
115 IcePointer
*watch_data
)
120 fd
= IceConnectionNumber(conn
);
121 ob_main_loop_fd_add(ob_main_loop
, fd
, ice_handler
, conn
, NULL
);
123 ob_main_loop_fd_remove(ob_main_loop
, fd
);
129 void event_startup(gboolean reconfig
)
131 if (reconfig
) return;
133 ob_main_loop_x_add(ob_main_loop
, event_process
, NULL
, NULL
);
136 IceAddConnectionWatch(ice_watch
, NULL
);
139 client_add_destroy_notify(focus_delay_client_dest
, NULL
);
142 void event_shutdown(gboolean reconfig
)
144 if (reconfig
) return;
147 IceRemoveConnectionWatch(ice_watch
, NULL
);
150 client_remove_destroy_notify(focus_delay_client_dest
);
153 static Window
event_get_window(XEvent
*e
)
160 window
= RootWindow(ob_display
, ob_screen
);
163 window
= e
->xmap
.window
;
166 window
= e
->xunmap
.window
;
169 window
= e
->xdestroywindow
.window
;
171 case ConfigureRequest
:
172 window
= e
->xconfigurerequest
.window
;
174 case ConfigureNotify
:
175 window
= e
->xconfigure
.window
;
179 if (extensions_xkb
&& e
->type
== extensions_xkb_event_basep
) {
180 switch (((XkbAnyEvent
*)e
)->xkb_type
) {
182 window
= ((XkbBellNotifyEvent
*)e
)->window
;
189 if (extensions_sync
&&
190 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
195 window
= e
->xany
.window
;
200 static void event_set_curtime(XEvent
*e
)
202 Time t
= CurrentTime
;
204 /* grab the lasttime and hack up the state */
220 t
= e
->xproperty
.time
;
224 t
= e
->xcrossing
.time
;
228 if (extensions_sync
&&
229 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
231 t
= ((XSyncAlarmNotifyEvent
*)e
)->time
;
234 /* if more event types are anticipated, get their timestamp
239 /* watch that if we get an event earlier than the last specified user_time,
240 which can happen if the clock goes backwards, we erase the last
241 specified user_time */
242 if (t
&& event_last_user_time
&& event_time_after(event_last_user_time
, t
))
243 event_last_user_time
= CurrentTime
;
248 static void event_hack_mods(XEvent
*e
)
253 e
->xbutton
.state
= modkeys_only_modifier_masks(e
->xbutton
.state
);
256 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
259 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
260 /* remove from the state the mask of the modifier key being released,
261 if it is a modifier key being released that is */
262 e
->xkey
.state
&= ~modkeys_keycode_to_mask(e
->xkey
.keycode
);
265 e
->xmotion
.state
= modkeys_only_modifier_masks(e
->xmotion
.state
);
266 /* compress events */
269 while (XCheckTypedWindowEvent(ob_display
, e
->xmotion
.window
,
271 e
->xmotion
.x
= ce
.xmotion
.x
;
272 e
->xmotion
.y
= ce
.xmotion
.y
;
273 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
274 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
281 static gboolean
wanted_focusevent(XEvent
*e
, gboolean in_client_only
)
283 gint mode
= e
->xfocus
.mode
;
284 gint detail
= e
->xfocus
.detail
;
285 Window win
= e
->xany
.window
;
287 if (e
->type
== FocusIn
) {
288 /* These are ones we never want.. */
290 /* This means focus was given by a keyboard/mouse grab. */
291 if (mode
== NotifyGrab
)
293 /* This means focus was given back from a keyboard/mouse grab. */
294 if (mode
== NotifyUngrab
)
297 /* These are the ones we want.. */
299 if (win
== RootWindow(ob_display
, ob_screen
)) {
300 /* If looking for a focus in on a client, then always return
301 FALSE for focus in's to the root window */
304 /* This means focus reverted off of a client */
305 else if (detail
== NotifyPointerRoot
||
306 detail
== NotifyDetailNone
||
307 detail
== NotifyInferior
||
308 /* This means focus got here from another screen */
309 detail
== NotifyNonlinear
)
315 /* It was on a client, was it a valid one?
316 It's possible to get a FocusIn event for a client that was managed
319 if (in_client_only
) {
320 ObWindow
*w
= g_hash_table_lookup(window_map
, &e
->xfocus
.window
);
321 if (!w
|| !WINDOW_IS_CLIENT(w
))
325 /* This means focus reverted to parent from the client (this
326 happens often during iconify animation) */
327 if (detail
== NotifyInferior
)
331 /* This means focus moved from the root window to a client */
332 if (detail
== NotifyVirtual
)
334 /* This means focus moved from one client to another */
335 if (detail
== NotifyNonlinearVirtual
)
341 g_assert(e
->type
== FocusOut
);
343 /* These are ones we never want.. */
345 /* This means focus was taken by a keyboard/mouse grab. */
346 if (mode
== NotifyGrab
)
348 /* This means focus was grabbed on a window and it was released. */
349 if (mode
== NotifyUngrab
)
352 /* Focus left the root window revertedto state */
353 if (win
== RootWindow(ob_display
, ob_screen
))
356 /* These are the ones we want.. */
358 /* This means focus moved from a client to the root window */
359 if (detail
== NotifyVirtual
)
361 /* This means focus moved from one client to another */
362 if (detail
== NotifyNonlinearVirtual
)
370 static Bool
event_look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
372 return e
->type
== FocusIn
&& wanted_focusevent(e
, FALSE
);
375 static Bool
event_look_for_focusin_client(Display
*d
, XEvent
*e
, XPointer arg
)
377 return e
->type
== FocusIn
&& wanted_focusevent(e
, TRUE
);
380 static void print_focusevent(XEvent
*e
)
382 gint mode
= e
->xfocus
.mode
;
383 gint detail
= e
->xfocus
.detail
;
384 Window win
= e
->xany
.window
;
385 const gchar
*modestr
, *detailstr
;
388 case NotifyNormal
: modestr
="NotifyNormal"; break;
389 case NotifyGrab
: modestr
="NotifyGrab"; break;
390 case NotifyUngrab
: modestr
="NotifyUngrab"; break;
391 case NotifyWhileGrabbed
: modestr
="NotifyWhileGrabbed"; break;
394 case NotifyAncestor
: detailstr
="NotifyAncestor"; break;
395 case NotifyVirtual
: detailstr
="NotifyVirtual"; break;
396 case NotifyInferior
: detailstr
="NotifyInferior"; break;
397 case NotifyNonlinear
: detailstr
="NotifyNonlinear"; break;
398 case NotifyNonlinearVirtual
: detailstr
="NotifyNonlinearVirtual"; break;
399 case NotifyPointer
: detailstr
="NotifyPointer"; break;
400 case NotifyPointerRoot
: detailstr
="NotifyPointerRoot"; break;
401 case NotifyDetailNone
: detailstr
="NotifyDetailNone"; break;
404 if (mode
== NotifyGrab
|| mode
== NotifyUngrab
)
409 ob_debug_type(OB_DEBUG_FOCUS
, "Focus%s 0x%x mode=%s detail=%s\n",
410 (e
->xfocus
.type
== FocusIn
? "In" : "Out"),
416 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
421 if (!wanted_focusevent(e
, FALSE
))
426 if (!wanted_focusevent(e
, FALSE
))
433 static void event_process(const XEvent
*ec
, gpointer data
)
436 ObClient
*client
= NULL
;
438 ObDockApp
*dockapp
= NULL
;
439 ObWindow
*obwin
= NULL
;
441 ObEventData
*ed
= data
;
443 /* make a copy we can mangle */
447 window
= event_get_window(e
);
448 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
449 switch (obwin
->type
) {
451 dock
= WINDOW_AS_DOCK(obwin
);
454 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
457 client
= WINDOW_AS_CLIENT(obwin
);
460 case Window_Internal
:
461 /* not to be used for events */
462 g_assert_not_reached();
467 event_set_curtime(e
);
469 if (event_ignore(e
, client
)) {
476 /* deal with it in the kernel */
478 if (menu_frame_visible
&&
479 (e
->type
== EnterNotify
|| e
->type
== LeaveNotify
))
481 /* crossing events for menu */
482 event_handle_menu(e
);
483 } else if (e
->type
== FocusIn
) {
485 e
->xfocus
.detail
== NotifyInferior
)
487 ob_debug_type(OB_DEBUG_FOCUS
,
488 "Focus went to the frame window");
490 focus_left_screen
= FALSE
;
492 focus_fallback(FALSE
, config_focus_under_mouse
, TRUE
);
494 /* We don't get a FocusOut for this case, because it's just moving
495 from our Inferior up to us. This happens when iconifying a
496 window with RevertToParent focus */
497 frame_adjust_focus(client
->frame
, FALSE
);
498 /* focus_set_client(NULL) has already been called */
499 client_calc_layer(client
);
501 if (e
->xfocus
.detail
== NotifyPointerRoot
||
502 e
->xfocus
.detail
== NotifyDetailNone
||
503 e
->xfocus
.detail
== NotifyInferior
||
504 e
->xfocus
.detail
== NotifyNonlinear
)
508 ob_debug_type(OB_DEBUG_FOCUS
,
509 "Focus went to root or pointer root/none\n");
511 if (e
->xfocus
.detail
== NotifyInferior
||
512 e
->xfocus
.detail
== NotifyNonlinear
)
514 focus_left_screen
= FALSE
;
517 /* If another FocusIn is in the queue then don't fallback yet. This
518 fixes the fun case of:
519 window map -> send focusin
520 window unmap -> get focusout
521 window map -> send focusin
522 get first focus out -> fall back to something (new window
523 hasn't received focus yet, so something else) -> send focusin
524 which means the "something else" is the last thing to get a
525 focusin sent to it, so the new window doesn't end up with focus.
527 But if the other focus in is something like PointerRoot then we
528 still want to fall back.
530 if (XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin_client
,
533 XPutBackEvent(ob_display
, &ce
);
534 ob_debug_type(OB_DEBUG_FOCUS
,
535 " but another FocusIn is coming\n");
537 /* Focus has been reverted.
539 FocusOut events come after UnmapNotify, so we don't need to
540 worry about focusing an invalid window
543 if (!focus_left_screen
)
544 focus_fallback(FALSE
, config_focus_under_mouse
, TRUE
);
549 ob_debug_type(OB_DEBUG_FOCUS
,
550 "Focus went to a window that is already gone\n");
552 /* If you send focus to a window and then it disappears, you can
553 get the FocusIn for it, after it is unmanaged.
554 Just wait for the next FocusOut/FocusIn pair, but make note that
555 the window that was focused no longer is. */
556 focus_set_client(NULL
);
558 else if (client
!= focus_client
) {
559 focus_left_screen
= FALSE
;
560 frame_adjust_focus(client
->frame
, TRUE
);
561 focus_set_client(client
);
562 client_calc_layer(client
);
563 client_bring_helper_windows(client
);
565 } else if (e
->type
== FocusOut
) {
568 /* Look for the followup FocusIn */
569 if (!XCheckIfEvent(ob_display
, &ce
, event_look_for_focusin
, NULL
)) {
570 /* There is no FocusIn, this means focus went to a window that
571 is not being managed, or a window on another screen. */
575 xerror_set_ignore(TRUE
);
576 if (XGetInputFocus(ob_display
, &win
, &i
) != 0 &&
577 XGetGeometry(ob_display
, win
, &root
, &i
,&i
,&u
,&u
,&u
,&u
) != 0 &&
578 root
!= RootWindow(ob_display
, ob_screen
))
580 ob_debug_type(OB_DEBUG_FOCUS
,
581 "Focus went to another screen !\n");
582 focus_left_screen
= TRUE
;
585 ob_debug_type(OB_DEBUG_FOCUS
,
586 "Focus went to a black hole !\n");
587 xerror_set_ignore(FALSE
);
588 /* nothing is focused */
589 focus_set_client(NULL
);
591 /* Focus moved, so process the FocusIn event */
592 ObEventData ed
= { .ignored
= FALSE
};
593 event_process(&ce
, &ed
);
595 /* The FocusIn was ignored, this means it was on a window
596 that isn't a client. */
597 ob_debug_type(OB_DEBUG_FOCUS
,
598 "Focus went to an unmanaged window 0x%x !\n",
600 focus_fallback(TRUE
, config_focus_under_mouse
, TRUE
);
604 if (client
&& client
!= focus_client
) {
605 frame_adjust_focus(client
->frame
, FALSE
);
606 /* focus_set_client(NULL) has already been called in this
607 section or by focus_fallback */
608 client_calc_layer(client
);
612 event_handle_client(client
, e
);
614 event_handle_dockapp(dockapp
, e
);
616 event_handle_dock(dock
, e
);
617 else if (window
== RootWindow(ob_display
, ob_screen
))
618 event_handle_root(e
);
619 else if (e
->type
== MapRequest
)
620 client_manage(window
);
621 else if (e
->type
== ClientMessage
) {
622 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
623 windows that are not managed yet. */
624 if (e
->xclient
.message_type
== prop_atoms
.net_request_frame_extents
) {
625 /* Pretend to manage the client, getting information used to
626 determine its decorations */
627 ObClient
*c
= client_fake_manage(e
->xclient
.window
);
630 /* set the frame extents on the window */
631 vals
[0] = c
->frame
->size
.left
;
632 vals
[1] = c
->frame
->size
.right
;
633 vals
[2] = c
->frame
->size
.top
;
634 vals
[3] = c
->frame
->size
.bottom
;
635 PROP_SETA32(e
->xclient
.window
, net_frame_extents
,
638 /* Free the pretend client */
639 client_fake_unmanage(c
);
642 else if (e
->type
== ConfigureRequest
) {
643 /* unhandled configure requests must be used to configure the
647 xwc
.x
= e
->xconfigurerequest
.x
;
648 xwc
.y
= e
->xconfigurerequest
.y
;
649 xwc
.width
= e
->xconfigurerequest
.width
;
650 xwc
.height
= e
->xconfigurerequest
.height
;
651 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
652 xwc
.sibling
= e
->xconfigurerequest
.above
;
653 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
655 /* we are not to be held responsible if someone sends us an
657 xerror_set_ignore(TRUE
);
658 XConfigureWindow(ob_display
, window
,
659 e
->xconfigurerequest
.value_mask
, &xwc
);
660 xerror_set_ignore(FALSE
);
663 else if (extensions_sync
&&
664 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
666 XSyncAlarmNotifyEvent
*se
= (XSyncAlarmNotifyEvent
*)e
;
667 if (se
->alarm
== moveresize_alarm
&& moveresize_in_progress
)
672 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
673 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
674 e
->type
== KeyRelease
)
676 event_handle_user_input(client
, e
);
679 /* if something happens and it's not from an XEvent, then we don't know
681 event_curtime
= CurrentTime
;
684 static void event_handle_root(XEvent
*e
)
690 ob_debug("Another WM has requested to replace us. Exiting.\n");
695 if (e
->xclient
.format
!= 32) break;
697 msgtype
= e
->xclient
.message_type
;
698 if (msgtype
== prop_atoms
.net_current_desktop
) {
699 guint d
= e
->xclient
.data
.l
[0];
700 if (d
< screen_num_desktops
) {
701 event_curtime
= e
->xclient
.data
.l
[1];
702 if (event_curtime
== 0)
703 ob_debug_type(OB_DEBUG_APP_BUGS
,
704 "_NET_CURRENT_DESKTOP message is missing "
706 screen_set_desktop(d
, TRUE
);
708 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
709 guint d
= e
->xclient
.data
.l
[0];
710 if (d
> 0 && d
<= 1000)
711 screen_set_num_desktops(d
);
712 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
713 screen_show_desktop(e
->xclient
.data
.l
[0] != 0, NULL
);
714 } else if (msgtype
== prop_atoms
.ob_control
) {
715 ob_debug("OB_CONTROL: %d\n", e
->xclient
.data
.l
[0]);
716 if (e
->xclient
.data
.l
[0] == 1)
718 else if (e
->xclient
.data
.l
[0] == 2)
723 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
) {
724 ob_debug("UPDATE DESKTOP NAMES\n");
725 screen_update_desktop_names();
727 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
728 screen_update_layout();
730 case ConfigureNotify
:
732 XRRUpdateConfiguration(e
);
741 void event_enter_client(ObClient
*client
)
743 g_assert(config_focus_follow
);
745 if (client_enter_focusable(client
) && client_can_focus(client
)) {
746 if (config_focus_delay
) {
747 ObFocusDelayData
*data
;
749 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
751 data
= g_new(ObFocusDelayData
, 1);
752 data
->client
= client
;
753 data
->time
= event_curtime
;
755 ob_main_loop_timeout_add(ob_main_loop
,
756 config_focus_delay
* 1000,
758 data
, focus_delay_cmp
, focus_delay_dest
);
760 ObFocusDelayData data
;
761 data
.client
= client
;
762 data
.time
= event_curtime
;
763 focus_delay_func(&data
);
768 static void event_handle_client(ObClient
*client
, XEvent
*e
)
773 static gint px
= -1, py
= -1;
778 /* save where the press occured for the first button pressed */
780 pb
= e
->xbutton
.button
;
785 /* Wheel buttons don't draw because they are an instant click, so it
786 is a waste of resources to go drawing it.
787 if the user is doing an intereactive thing, or has a menu open then
788 the mouse is grabbed (possibly) and if we get these events we don't
789 want to deal with them
791 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5) &&
794 /* use where the press occured */
795 con
= frame_context(client
, e
->xbutton
.window
, px
, py
);
796 con
= mouse_button_frame_context(con
, e
->xbutton
.button
,
799 if (e
->type
== ButtonRelease
&& e
->xbutton
.button
== pb
)
800 pb
= 0, px
= py
= -1;
803 case OB_FRAME_CONTEXT_MAXIMIZE
:
804 client
->frame
->max_press
= (e
->type
== ButtonPress
);
805 frame_adjust_state(client
->frame
);
807 case OB_FRAME_CONTEXT_CLOSE
:
808 client
->frame
->close_press
= (e
->type
== ButtonPress
);
809 frame_adjust_state(client
->frame
);
811 case OB_FRAME_CONTEXT_ICONIFY
:
812 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
813 frame_adjust_state(client
->frame
);
815 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
816 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
817 frame_adjust_state(client
->frame
);
819 case OB_FRAME_CONTEXT_SHADE
:
820 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
821 frame_adjust_state(client
->frame
);
824 /* nothing changes with clicks for any other contexts */
830 /* when there is a grab on the pointer, we won't get enter/leave
831 notifies, but we still get motion events */
832 if (grab_on_pointer()) break;
834 con
= frame_context(client
, e
->xmotion
.window
,
835 e
->xmotion
.x
, e
->xmotion
.y
);
837 case OB_FRAME_CONTEXT_TITLEBAR
:
838 case OB_FRAME_CONTEXT_TLCORNER
:
839 case OB_FRAME_CONTEXT_TRCORNER
:
840 /* we've left the button area inside the titlebar */
841 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
842 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
843 client
->frame
->close_hover
)
845 client
->frame
->max_hover
= FALSE
;
846 client
->frame
->desk_hover
= FALSE
;
847 client
->frame
->shade_hover
= FALSE
;
848 client
->frame
->iconify_hover
= FALSE
;
849 client
->frame
->close_hover
= FALSE
;
850 frame_adjust_state(client
->frame
);
853 case OB_FRAME_CONTEXT_MAXIMIZE
:
854 if (!client
->frame
->max_hover
) {
855 client
->frame
->max_hover
= TRUE
;
856 frame_adjust_state(client
->frame
);
859 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
860 if (!client
->frame
->desk_hover
) {
861 client
->frame
->desk_hover
= TRUE
;
862 frame_adjust_state(client
->frame
);
865 case OB_FRAME_CONTEXT_SHADE
:
866 if (!client
->frame
->shade_hover
) {
867 client
->frame
->shade_hover
= TRUE
;
868 frame_adjust_state(client
->frame
);
871 case OB_FRAME_CONTEXT_ICONIFY
:
872 if (!client
->frame
->iconify_hover
) {
873 client
->frame
->iconify_hover
= TRUE
;
874 frame_adjust_state(client
->frame
);
877 case OB_FRAME_CONTEXT_CLOSE
:
878 if (!client
->frame
->close_hover
) {
879 client
->frame
->close_hover
= TRUE
;
880 frame_adjust_state(client
->frame
);
888 con
= frame_context(client
, e
->xcrossing
.window
,
889 e
->xcrossing
.x
, e
->xcrossing
.y
);
891 case OB_FRAME_CONTEXT_TITLEBAR
:
892 case OB_FRAME_CONTEXT_TLCORNER
:
893 case OB_FRAME_CONTEXT_TRCORNER
:
894 /* we've left the button area inside the titlebar */
895 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
896 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
897 client
->frame
->close_hover
)
899 client
->frame
->max_hover
= FALSE
;
900 client
->frame
->desk_hover
= FALSE
;
901 client
->frame
->shade_hover
= FALSE
;
902 client
->frame
->iconify_hover
= FALSE
;
903 client
->frame
->close_hover
= FALSE
;
904 frame_adjust_state(client
->frame
);
907 case OB_FRAME_CONTEXT_MAXIMIZE
:
908 client
->frame
->max_hover
= FALSE
;
909 frame_adjust_state(client
->frame
);
911 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
912 client
->frame
->desk_hover
= FALSE
;
913 frame_adjust_state(client
->frame
);
915 case OB_FRAME_CONTEXT_SHADE
:
916 client
->frame
->shade_hover
= FALSE
;
917 frame_adjust_state(client
->frame
);
919 case OB_FRAME_CONTEXT_ICONIFY
:
920 client
->frame
->iconify_hover
= FALSE
;
921 frame_adjust_state(client
->frame
);
923 case OB_FRAME_CONTEXT_CLOSE
:
924 client
->frame
->close_hover
= FALSE
;
925 frame_adjust_state(client
->frame
);
927 case OB_FRAME_CONTEXT_FRAME
:
928 /* When the mouse leaves an animating window, don't use the
929 corresponding enter events. Pretend like the animating window
930 doesn't even exist..! */
931 if (frame_iconify_animating(client
->frame
))
932 event_end_ignore_all_enters(event_start_ignore_all_enters());
934 ob_debug_type(OB_DEBUG_FOCUS
,
935 "%sNotify mode %d detail %d on %lx\n",
936 (e
->type
== EnterNotify
? "Enter" : "Leave"),
938 e
->xcrossing
.detail
, (client
?client
->window
:0));
939 if (grab_on_keyboard())
941 if (config_focus_follow
&& config_focus_delay
&&
942 /* leave inferior events can happen when the mouse goes onto
943 the window's border and then into the window before the
945 e
->xcrossing
.detail
!= NotifyInferior
)
947 ob_main_loop_timeout_remove_data(ob_main_loop
,
958 con
= frame_context(client
, e
->xcrossing
.window
,
959 e
->xcrossing
.x
, e
->xcrossing
.y
);
961 case OB_FRAME_CONTEXT_MAXIMIZE
:
962 client
->frame
->max_hover
= TRUE
;
963 frame_adjust_state(client
->frame
);
965 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
966 client
->frame
->desk_hover
= TRUE
;
967 frame_adjust_state(client
->frame
);
969 case OB_FRAME_CONTEXT_SHADE
:
970 client
->frame
->shade_hover
= TRUE
;
971 frame_adjust_state(client
->frame
);
973 case OB_FRAME_CONTEXT_ICONIFY
:
974 client
->frame
->iconify_hover
= TRUE
;
975 frame_adjust_state(client
->frame
);
977 case OB_FRAME_CONTEXT_CLOSE
:
978 client
->frame
->close_hover
= TRUE
;
979 frame_adjust_state(client
->frame
);
981 case OB_FRAME_CONTEXT_FRAME
:
982 if (grab_on_keyboard())
984 if (e
->xcrossing
.mode
== NotifyGrab
||
985 e
->xcrossing
.mode
== NotifyUngrab
||
986 /*ignore enters when we're already in the window */
987 e
->xcrossing
.detail
== NotifyInferior
||
988 is_enter_focus_event_ignored(e
))
990 ob_debug_type(OB_DEBUG_FOCUS
,
991 "%sNotify mode %d detail %d on %lx IGNORED\n",
992 (e
->type
== EnterNotify
? "Enter" : "Leave"),
994 e
->xcrossing
.detail
, client
?client
->window
:0);
997 ob_debug_type(OB_DEBUG_FOCUS
,
998 "%sNotify mode %d detail %d on %lx, "
1000 (e
->type
== EnterNotify
? "Enter" : "Leave"),
1002 e
->xcrossing
.detail
, (client
?client
->window
:0));
1003 if (config_focus_follow
)
1004 event_enter_client(client
);
1012 case ConfigureRequest
:
1014 /* dont compress these unless you're going to watch for property
1015 notifies in between (these can change what the configure would
1017 also you can't compress stacking events
1021 gboolean move
= FALSE
;
1022 gboolean resize
= FALSE
;
1024 /* get the current area */
1025 RECT_TO_DIMS(client
->area
, x
, y
, w
, h
);
1027 ob_debug("ConfigureRequest for \"%s\" desktop %d wmstate %d "
1029 " x %d y %d w %d h %d b %d\n",
1031 screen_desktop
, client
->wmstate
, client
->frame
->visible
,
1032 x
, y
, w
, h
, client
->border_width
);
1034 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
1035 if (client
->border_width
!= e
->xconfigurerequest
.border_width
) {
1036 client
->border_width
= e
->xconfigurerequest
.border_width
;
1038 /* if the border width is changing then that is the same
1039 as requesting a resize, but we don't actually change
1040 the client's border, so it will change their root
1041 coordiantes (since they include the border width) and
1042 we need to a notify then */
1047 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
1048 ObClient
*sibling
= NULL
;
1049 gulong ignore_start
;
1052 /* get the sibling */
1053 if (e
->xconfigurerequest
.value_mask
& CWSibling
) {
1055 win
= g_hash_table_lookup(window_map
,
1056 &e
->xconfigurerequest
.above
);
1057 if (win
&& WINDOW_IS_CLIENT(win
) &&
1058 WINDOW_AS_CLIENT(win
) != client
)
1060 sibling
= WINDOW_AS_CLIENT(win
);
1063 /* an invalid sibling was specified so don't restack at
1064 all, it won't make sense no matter what we do */
1069 if (!config_focus_under_mouse
)
1070 ignore_start
= event_start_ignore_all_enters();
1071 stacking_restack_request(client
, sibling
,
1072 e
->xconfigurerequest
.detail
);
1073 if (!config_focus_under_mouse
)
1074 event_end_ignore_all_enters(ignore_start
);
1077 /* a stacking change moves the window without resizing */
1081 if ((e
->xconfigurerequest
.value_mask
& CWX
) ||
1082 (e
->xconfigurerequest
.value_mask
& CWY
) ||
1083 (e
->xconfigurerequest
.value_mask
& CWWidth
) ||
1084 (e
->xconfigurerequest
.value_mask
& CWHeight
))
1086 if (e
->xconfigurerequest
.value_mask
& CWX
) {
1087 /* don't allow clients to move shaded windows (fvwm does this)
1089 if (!client
->shaded
)
1090 x
= e
->xconfigurerequest
.x
;
1093 if (e
->xconfigurerequest
.value_mask
& CWY
) {
1094 /* don't allow clients to move shaded windows (fvwm does this)
1096 if (!client
->shaded
)
1097 y
= e
->xconfigurerequest
.y
;
1101 if (e
->xconfigurerequest
.value_mask
& CWWidth
) {
1102 w
= e
->xconfigurerequest
.width
;
1105 if (e
->xconfigurerequest
.value_mask
& CWHeight
) {
1106 h
= e
->xconfigurerequest
.height
;
1111 ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
1112 "move %d resize %d\n",
1113 e
->xconfigurerequest
.value_mask
& CWX
, x
,
1114 e
->xconfigurerequest
.value_mask
& CWY
, y
,
1115 e
->xconfigurerequest
.value_mask
& CWWidth
, w
,
1116 e
->xconfigurerequest
.value_mask
& CWHeight
, h
,
1119 /* check for broken apps moving to their root position
1121 XXX remove this some day...that would be nice. right now all
1122 kde apps do this when they try activate themselves on another
1123 desktop. eg. open amarok window on desktop 1, switch to desktop
1124 2, click amarok tray icon. it will move by its decoration size.
1126 if (x
!= client
->area
.x
&&
1127 x
== (client
->frame
->area
.x
+ client
->frame
->size
.left
-
1128 (gint
)client
->border_width
) &&
1129 y
!= client
->area
.y
&&
1130 y
== (client
->frame
->area
.y
+ client
->frame
->size
.top
-
1131 (gint
)client
->border_width
) &&
1132 w
== client
->area
.width
&&
1133 h
== client
->area
.height
)
1135 ob_debug_type(OB_DEBUG_APP_BUGS
,
1136 "Application %s is trying to move via "
1137 "ConfigureRequest to it's root window position "
1138 "but it is not using StaticGravity\n",
1144 /* they still requested a move, so don't change whether a
1145 notify is sent or not */
1151 client_try_configure(client
, &x
, &y
, &w
, &h
, &lw
, &lh
, FALSE
);
1153 /* if x was not given, then use gravity to figure out the new
1154 x. the reference point should not be moved */
1155 if ((e
->xconfigurerequest
.value_mask
& CWWidth
&&
1156 !(e
->xconfigurerequest
.value_mask
& CWX
)))
1157 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1158 /* if y was not given, then use gravity to figure out the new
1159 y. the reference point should not be moved */
1160 if ((e
->xconfigurerequest
.value_mask
& CWHeight
&&
1161 !(e
->xconfigurerequest
.value_mask
& CWY
)))
1162 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1164 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1166 ob_debug("Granting ConfigureRequest x %d y %d w %d h %d\n",
1168 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
, TRUE
);
1173 if (client
->ignore_unmaps
) {
1174 client
->ignore_unmaps
--;
1177 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1178 "ignores left %d\n",
1179 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
1180 client
->ignore_unmaps
);
1181 client_unmanage(client
);
1184 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
1185 client_unmanage(client
);
1187 case ReparentNotify
:
1188 /* this is when the client is first taken captive in the frame */
1189 if (e
->xreparent
.parent
== client
->frame
->window
) break;
1192 This event is quite rare and is usually handled in unmapHandler.
1193 However, if the window is unmapped when the reparent event occurs,
1194 the window manager never sees it because an unmap event is not sent
1195 to an already unmapped window.
1198 /* we don't want the reparent event, put it back on the stack for the
1199 X server to deal with after we unmanage the window */
1200 XPutBackEvent(ob_display
, e
);
1202 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
1203 client_unmanage(client
);
1206 ob_debug("MapRequest for 0x%lx\n", client
->window
);
1207 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
1208 does, we don't want it!
1209 it can happen now when the window is on
1210 another desktop, but we still don't
1212 client_activate(client
, FALSE
, TRUE
, TRUE
, TRUE
);
1215 /* validate cuz we query stuff off the client here */
1216 if (!client_validate(client
)) break;
1218 if (e
->xclient
.format
!= 32) return;
1220 msgtype
= e
->xclient
.message_type
;
1221 if (msgtype
== prop_atoms
.wm_change_state
) {
1222 /* compress changes into a single change */
1223 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1225 /* XXX: it would be nice to compress ALL messages of a
1226 type, not just messages in a row without other
1227 message types between. */
1228 if (ce
.xclient
.message_type
!= msgtype
) {
1229 XPutBackEvent(ob_display
, &ce
);
1232 e
->xclient
= ce
.xclient
;
1234 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1235 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
1236 /* compress changes into a single change */
1237 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1239 /* XXX: it would be nice to compress ALL messages of a
1240 type, not just messages in a row without other
1241 message types between. */
1242 if (ce
.xclient
.message_type
!= msgtype
) {
1243 XPutBackEvent(ob_display
, &ce
);
1246 e
->xclient
= ce
.xclient
;
1248 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1249 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1250 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1252 } else if (msgtype
== prop_atoms
.net_wm_state
) {
1253 gulong ignore_start
;
1255 /* can't compress these */
1256 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1257 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1258 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1259 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1260 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1263 /* ignore enter events caused by these like ob actions do */
1264 if (!config_focus_under_mouse
)
1265 ignore_start
= event_start_ignore_all_enters();
1266 client_set_state(client
, e
->xclient
.data
.l
[0],
1267 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1268 if (!config_focus_under_mouse
)
1269 event_end_ignore_all_enters(ignore_start
);
1270 } else if (msgtype
== prop_atoms
.net_close_window
) {
1271 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1272 client_close(client
);
1273 } else if (msgtype
== prop_atoms
.net_active_window
) {
1274 ob_debug("net_active_window for 0x%lx source=%s\n",
1276 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1277 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1278 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1279 /* XXX make use of data.l[2] !? */
1280 if (e
->xclient
.data
.l
[0] == 1 || e
->xclient
.data
.l
[0] == 2) {
1281 /* don't use the user's timestamp for client_focus, cuz if it's
1282 an old broken timestamp (happens all the time) then focus
1283 won't move even though we're trying to move it
1284 event_curtime = e->xclient.data.l[1];*/
1285 if (e
->xclient
.data
.l
[1] == 0)
1286 ob_debug_type(OB_DEBUG_APP_BUGS
,
1287 "_NET_ACTIVE_WINDOW message for window %s is"
1288 " missing a timestamp\n", client
->title
);
1290 ob_debug_type(OB_DEBUG_APP_BUGS
,
1291 "_NET_ACTIVE_WINDOW message for window %s is "
1292 "missing source indication\n");
1293 client_activate(client
, FALSE
, TRUE
, TRUE
,
1294 (e
->xclient
.data
.l
[0] == 0 ||
1295 e
->xclient
.data
.l
[0] == 2));
1296 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1297 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1298 client
->window
, e
->xclient
.data
.l
[2]);
1299 if ((Atom
)e
->xclient
.data
.l
[2] ==
1300 prop_atoms
.net_wm_moveresize_size_topleft
||
1301 (Atom
)e
->xclient
.data
.l
[2] ==
1302 prop_atoms
.net_wm_moveresize_size_top
||
1303 (Atom
)e
->xclient
.data
.l
[2] ==
1304 prop_atoms
.net_wm_moveresize_size_topright
||
1305 (Atom
)e
->xclient
.data
.l
[2] ==
1306 prop_atoms
.net_wm_moveresize_size_right
||
1307 (Atom
)e
->xclient
.data
.l
[2] ==
1308 prop_atoms
.net_wm_moveresize_size_right
||
1309 (Atom
)e
->xclient
.data
.l
[2] ==
1310 prop_atoms
.net_wm_moveresize_size_bottomright
||
1311 (Atom
)e
->xclient
.data
.l
[2] ==
1312 prop_atoms
.net_wm_moveresize_size_bottom
||
1313 (Atom
)e
->xclient
.data
.l
[2] ==
1314 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1315 (Atom
)e
->xclient
.data
.l
[2] ==
1316 prop_atoms
.net_wm_moveresize_size_left
||
1317 (Atom
)e
->xclient
.data
.l
[2] ==
1318 prop_atoms
.net_wm_moveresize_move
||
1319 (Atom
)e
->xclient
.data
.l
[2] ==
1320 prop_atoms
.net_wm_moveresize_size_keyboard
||
1321 (Atom
)e
->xclient
.data
.l
[2] ==
1322 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1324 moveresize_start(client
, e
->xclient
.data
.l
[0],
1325 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1326 e
->xclient
.data
.l
[2]);
1328 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1329 prop_atoms
.net_wm_moveresize_cancel
)
1330 moveresize_end(TRUE
);
1331 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1332 gint ograv
, x
, y
, w
, h
;
1334 ograv
= client
->gravity
;
1336 if (e
->xclient
.data
.l
[0] & 0xff)
1337 client
->gravity
= e
->xclient
.data
.l
[0] & 0xff;
1339 if (e
->xclient
.data
.l
[0] & 1 << 8)
1340 x
= e
->xclient
.data
.l
[1];
1343 if (e
->xclient
.data
.l
[0] & 1 << 9)
1344 y
= e
->xclient
.data
.l
[2];
1348 if (e
->xclient
.data
.l
[0] & 1 << 10) {
1349 w
= e
->xclient
.data
.l
[3];
1351 /* if x was not given, then use gravity to figure out the new
1352 x. the reference point should not be moved */
1353 if (!(e
->xclient
.data
.l
[0] & 1 << 8))
1354 client_gravity_resize_w(client
, &x
, client
->area
.width
, w
);
1357 w
= client
->area
.width
;
1359 if (e
->xclient
.data
.l
[0] & 1 << 11) {
1360 h
= e
->xclient
.data
.l
[4];
1362 /* if y was not given, then use gravity to figure out the new
1363 y. the reference point should not be moved */
1364 if (!(e
->xclient
.data
.l
[0] & 1 << 9))
1365 client_gravity_resize_h(client
, &y
, client
->area
.height
,h
);
1368 h
= client
->area
.height
;
1370 ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)\n",
1371 e
->xclient
.data
.l
[0] & 1 << 8, x
,
1372 e
->xclient
.data
.l
[0] & 1 << 9, y
,
1375 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1377 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
1379 client
->gravity
= ograv
;
1380 } else if (msgtype
== prop_atoms
.net_restack_window
) {
1381 if (e
->xclient
.data
.l
[0] != 2) {
1382 ob_debug_type(OB_DEBUG_APP_BUGS
,
1383 "_NET_RESTACK_WINDOW sent for window %s with "
1384 "invalid source indication %ld\n",
1385 client
->title
, e
->xclient
.data
.l
[0]);
1387 ObClient
*sibling
= NULL
;
1388 if (e
->xclient
.data
.l
[1]) {
1389 ObWindow
*win
= g_hash_table_lookup
1390 (window_map
, &e
->xclient
.data
.l
[1]);
1391 if (WINDOW_IS_CLIENT(win
) &&
1392 WINDOW_AS_CLIENT(win
) != client
)
1394 sibling
= WINDOW_AS_CLIENT(win
);
1396 if (sibling
== NULL
)
1397 ob_debug_type(OB_DEBUG_APP_BUGS
,
1398 "_NET_RESTACK_WINDOW sent for window %s "
1399 "with invalid sibling 0x%x\n",
1400 client
->title
, e
->xclient
.data
.l
[1]);
1402 if (e
->xclient
.data
.l
[2] == Below
||
1403 e
->xclient
.data
.l
[2] == BottomIf
||
1404 e
->xclient
.data
.l
[2] == Above
||
1405 e
->xclient
.data
.l
[2] == TopIf
||
1406 e
->xclient
.data
.l
[2] == Opposite
)
1408 gulong ignore_start
;
1410 if (!config_focus_under_mouse
)
1411 ignore_start
= event_start_ignore_all_enters();
1412 /* just raise, don't activate */
1413 stacking_restack_request(client
, sibling
,
1414 e
->xclient
.data
.l
[2]);
1415 if (!config_focus_under_mouse
)
1416 event_end_ignore_all_enters(ignore_start
);
1418 /* send a synthetic ConfigureNotify, cuz this is supposed
1419 to be like a ConfigureRequest. */
1420 client_reconfigure(client
, TRUE
);
1422 ob_debug_type(OB_DEBUG_APP_BUGS
,
1423 "_NET_RESTACK_WINDOW sent for window %s "
1424 "with invalid detail %d\n",
1425 client
->title
, e
->xclient
.data
.l
[2]);
1429 case PropertyNotify
:
1430 /* validate cuz we query stuff off the client here */
1431 if (!client_validate(client
)) break;
1433 /* compress changes to a single property into a single change */
1434 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1438 /* XXX: it would be nice to compress ALL changes to a property,
1439 not just changes in a row without other props between. */
1441 a
= ce
.xproperty
.atom
;
1442 b
= e
->xproperty
.atom
;
1446 if ((a
== prop_atoms
.net_wm_name
||
1447 a
== prop_atoms
.wm_name
||
1448 a
== prop_atoms
.net_wm_icon_name
||
1449 a
== prop_atoms
.wm_icon_name
)
1451 (b
== prop_atoms
.net_wm_name
||
1452 b
== prop_atoms
.wm_name
||
1453 b
== prop_atoms
.net_wm_icon_name
||
1454 b
== prop_atoms
.wm_icon_name
)) {
1457 if (a
== prop_atoms
.net_wm_icon
&&
1458 b
== prop_atoms
.net_wm_icon
)
1461 XPutBackEvent(ob_display
, &ce
);
1465 msgtype
= e
->xproperty
.atom
;
1466 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1467 ob_debug("Update NORMAL hints\n");
1468 client_update_normal_hints(client
);
1469 /* normal hints can make a window non-resizable */
1470 client_setup_decor_and_functions(client
, FALSE
);
1472 /* make sure the client's sizes are within its bounds, but only
1473 reconfigure the window if it needs to. emacs will update its
1474 normal hints every time it receives a conigurenotify */
1475 client_reconfigure(client
, FALSE
);
1476 } else if (msgtype
== XA_WM_HINTS
) {
1477 client_update_wmhints(client
);
1478 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1479 client_update_transient_for(client
);
1480 client_get_type_and_transientness(client
);
1481 /* type may have changed, so update the layer */
1482 client_calc_layer(client
);
1483 client_setup_decor_and_functions(client
, TRUE
);
1484 } else if (msgtype
== prop_atoms
.net_wm_name
||
1485 msgtype
== prop_atoms
.wm_name
||
1486 msgtype
== prop_atoms
.net_wm_icon_name
||
1487 msgtype
== prop_atoms
.wm_icon_name
) {
1488 client_update_title(client
);
1489 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1490 client_update_protocols(client
);
1491 client_setup_decor_and_functions(client
, TRUE
);
1493 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1494 client_update_strut(client
);
1496 else if (msgtype
== prop_atoms
.net_wm_strut_partial
) {
1497 client_update_strut(client
);
1499 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1500 client_update_icons(client
);
1502 else if (msgtype
== prop_atoms
.net_wm_icon_geometry
) {
1503 client_update_icon_geometry(client
);
1505 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1507 if (client
== focus_client
&&
1508 PROP_GET32(client
->window
, net_wm_user_time
, cardinal
, &t
) &&
1509 t
&& !event_time_after(t
, e
->xproperty
.time
) &&
1510 (!event_last_user_time
||
1511 event_time_after(t
, event_last_user_time
)))
1513 event_last_user_time
= t
;
1517 else if (msgtype
== prop_atoms
.net_wm_sync_request_counter
) {
1518 client_update_sync_request_counter(client
);
1522 case ColormapNotify
:
1523 client_update_colormap(client
, e
->xcolormap
.colormap
);
1528 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1529 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1530 frame_adjust_shape(client
->frame
);
1536 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1540 if (e
->xbutton
.button
== 1)
1541 stacking_raise(DOCK_AS_WINDOW(s
));
1542 else if (e
->xbutton
.button
== 2)
1543 stacking_lower(DOCK_AS_WINDOW(s
));
1549 /* don't hide when moving into a dock app */
1550 if (e
->xcrossing
.detail
!= NotifyInferior
)
1556 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1560 dock_app_drag(app
, &e
->xmotion
);
1563 if (app
->ignore_unmaps
) {
1564 app
->ignore_unmaps
--;
1567 dock_remove(app
, TRUE
);
1570 dock_remove(app
, FALSE
);
1572 case ReparentNotify
:
1573 dock_remove(app
, FALSE
);
1575 case ConfigureNotify
:
1576 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1581 static ObMenuFrame
* find_active_menu()
1584 ObMenuFrame
*ret
= NULL
;
1586 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1595 static ObMenuFrame
* find_active_or_last_menu()
1597 ObMenuFrame
*ret
= NULL
;
1599 ret
= find_active_menu();
1600 if (!ret
&& menu_frame_visible
)
1601 ret
= menu_frame_visible
->data
;
1605 static gboolean
event_handle_menu_keyboard(XEvent
*ev
)
1607 guint keycode
, state
;
1610 gboolean ret
= FALSE
;
1612 keycode
= ev
->xkey
.keycode
;
1613 state
= ev
->xkey
.state
;
1614 unikey
= translate_unichar(keycode
);
1616 frame
= find_active_or_last_menu();
1618 g_assert_not_reached(); /* there is no active menu */
1620 /* Allow control while going thru the menu */
1621 else if (ev
->type
== KeyPress
&& (state
& ~ControlMask
) == 0) {
1622 if (keycode
== ob_keycode(OB_KEY_ESCAPE
)) {
1623 menu_frame_hide_all();
1627 else if (keycode
== ob_keycode(OB_KEY_LEFT
)) {
1628 /* Left goes to the parent menu */
1629 menu_frame_select(frame
, NULL
, TRUE
);
1633 else if (keycode
== ob_keycode(OB_KEY_RIGHT
)) {
1634 /* Right goes to the selected submenu */
1635 if (frame
->child
) menu_frame_select_next(frame
->child
);
1639 else if (keycode
== ob_keycode(OB_KEY_UP
)) {
1640 menu_frame_select_previous(frame
);
1644 else if (keycode
== ob_keycode(OB_KEY_DOWN
)) {
1645 menu_frame_select_next(frame
);
1650 /* Use KeyRelease events for running things so that the key release doesn't
1651 get sent to the focused application.
1653 Allow ControlMask only, and don't bother if the menu is empty */
1654 else if (ev
->type
== KeyRelease
&& (state
& ~ControlMask
) == 0 &&
1657 if (keycode
== ob_keycode(OB_KEY_RETURN
)) {
1658 /* Enter runs the active item or goes into the submenu.
1659 Control-Enter runs it without closing the menu. */
1661 menu_frame_select_next(frame
->child
);
1662 else if (frame
->selected
)
1663 menu_entry_frame_execute(frame
->selected
, state
);
1668 /* keyboard accelerator shortcuts. (if it was a valid key) */
1669 else if (unikey
!= 0) {
1672 ObMenuEntryFrame
*found
= NULL
;
1673 guint num_found
= 0;
1675 /* start after the selected one */
1676 start
= frame
->entries
;
1677 if (frame
->selected
) {
1678 for (it
= start
; frame
->selected
!= it
->data
;
1679 it
= g_list_next(it
))
1680 g_assert(it
!= NULL
); /* nothing was selected? */
1681 /* next with wraparound */
1682 start
= g_list_next(it
);
1683 if (start
== NULL
) start
= frame
->entries
;
1688 ObMenuEntryFrame
*e
= it
->data
;
1689 gunichar entrykey
= 0;
1691 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1692 entrykey
= e
->entry
->data
.normal
.shortcut
;
1693 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1694 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1696 if (unikey
== entrykey
) {
1697 if (found
== NULL
) found
= e
;
1701 /* next with wraparound */
1702 it
= g_list_next(it
);
1703 if (it
== NULL
) it
= frame
->entries
;
1704 } while (it
!= start
);
1707 if (found
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
1710 menu_frame_select(frame
, found
, TRUE
);
1711 usleep(50000); /* highlight the item for a short bit so the
1712 user can see what happened */
1713 menu_entry_frame_execute(found
, state
);
1715 menu_frame_select(frame
, found
, TRUE
);
1717 menu_frame_select_next(frame
->child
);
1728 static gboolean
event_handle_menu(XEvent
*ev
)
1731 ObMenuEntryFrame
*e
;
1732 gboolean ret
= TRUE
;
1736 if (menu_hide_delay_reached() &&
1737 (ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5))
1739 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1740 ev
->xbutton
.y_root
)))
1742 menu_frame_select(e
->frame
, e
, TRUE
);
1743 menu_entry_frame_execute(e
, ev
->xbutton
.state
);
1746 menu_frame_hide_all();
1750 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1751 if (e
->ignore_enters
)
1753 else if (!(f
= find_active_menu()) ||
1755 f
->parent
== e
->frame
||
1756 f
->child
== e
->frame
)
1757 menu_frame_select(e
->frame
, e
, FALSE
);
1761 /*ignore leaves when we're already in the window */
1762 if (ev
->xcrossing
.detail
== NotifyInferior
)
1765 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1766 (f
= find_active_menu()) && f
->selected
== e
&&
1767 e
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1769 menu_frame_select(e
->frame
, NULL
, FALSE
);
1773 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1774 ev
->xmotion
.y_root
)))
1775 if (!(f
= find_active_menu()) ||
1777 f
->parent
== e
->frame
||
1778 f
->child
== e
->frame
)
1779 menu_frame_select(e
->frame
, e
, FALSE
);
1783 ret
= event_handle_menu_keyboard(ev
);
1789 static void event_handle_user_input(ObClient
*client
, XEvent
*e
)
1791 g_assert(e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
1792 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
1793 e
->type
== KeyRelease
);
1795 if (menu_frame_visible
) {
1796 if (event_handle_menu(e
))
1797 /* don't use the event if the menu used it, but if the menu
1798 didn't use it and it's a keypress that is bound, it will
1799 close the menu and be used */
1803 /* if the keyboard interactive action uses the event then dont
1804 use it for bindings. likewise is moveresize uses the event. */
1805 if (!actions_interactive_input_event(e
) && !moveresize_event(e
)) {
1806 if (moveresize_in_progress
)
1807 /* make further actions work on the client being
1809 client
= moveresize_client
;
1811 if (e
->type
== ButtonPress
||
1812 e
->type
== ButtonRelease
||
1813 e
->type
== MotionNotify
)
1815 /* the frame may not be "visible" but they can still click on it
1816 in the case where it is animating before disappearing */
1817 if (!client
|| !frame_iconify_animating(client
->frame
))
1818 mouse_event(client
, e
);
1820 keyboard_event((focus_cycle_target
? focus_cycle_target
:
1821 (client
? client
: focus_client
)), e
);
1825 static void focus_delay_dest(gpointer data
)
1830 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
1832 const ObFocusDelayData
*f1
= d1
;
1833 return f1
->client
== d2
;
1836 static gboolean
focus_delay_func(gpointer data
)
1838 ObFocusDelayData
*d
= data
;
1839 Time old
= event_curtime
;
1841 /* don't move focus and kill the menu or the move/resize */
1842 if (menu_frame_visible
|| moveresize_in_progress
) return FALSE
;
1844 event_curtime
= d
->time
;
1845 if (focus_client
!= d
->client
) {
1846 if (client_focus(d
->client
) && config_focus_raise
)
1847 stacking_raise(CLIENT_AS_WINDOW(d
->client
));
1849 event_curtime
= old
;
1850 return FALSE
; /* no repeat */
1853 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1855 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1859 void event_halt_focus_delay()
1861 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1864 gulong
event_start_ignore_all_enters()
1866 XSync(ob_display
, FALSE
);
1867 return LastKnownRequestProcessed(ob_display
);
1870 void event_end_ignore_all_enters(gulong start
)
1874 g_assert(start
!= 0);
1875 XSync(ob_display
, FALSE
);
1877 r
= g_new(ObSerialRange
, 1);
1879 r
->end
= LastKnownRequestProcessed(ob_display
);
1880 ignore_serials
= g_slist_prepend(ignore_serials
, r
);
1882 /* increment the serial so we don't ignore events we weren't meant to */
1883 XSync(ob_display
, FALSE
);
1886 static gboolean
is_enter_focus_event_ignored(XEvent
*e
)
1890 g_assert(e
->type
== EnterNotify
&&
1891 !(e
->xcrossing
.mode
== NotifyGrab
||
1892 e
->xcrossing
.mode
== NotifyUngrab
||
1893 e
->xcrossing
.detail
== NotifyInferior
));
1895 for (it
= ignore_serials
; it
; it
= next
) {
1896 ObSerialRange
*r
= it
->data
;
1898 next
= g_slist_next(it
);
1900 if ((glong
)(e
->xany
.serial
- r
->end
) > 0) {
1902 ignore_serials
= g_slist_delete_link(ignore_serials
, it
);
1905 else if ((glong
)(e
->xany
.serial
- r
->start
) >= 0)
1911 void event_cancel_all_key_grabs()
1913 if (actions_interactive_act_running()) {
1914 actions_interactive_cancel_act();
1915 ob_debug("KILLED interactive action\n");
1917 else if (menu_frame_visible
) {
1918 menu_frame_hide_all();
1919 ob_debug("KILLED open menus\n");
1921 else if (moveresize_in_progress
) {
1922 moveresize_end(TRUE
);
1923 ob_debug("KILLED interactive moveresize\n");
1925 else if (grab_on_keyboard()) {
1927 ob_debug("KILLED active grab on keyboard\n");
1930 ungrab_passive_key();
1933 gboolean
event_time_after(Time t1
, Time t2
)
1935 g_assert(t1
!= CurrentTime
);
1936 g_assert(t2
!= CurrentTime
);
1939 Timestamp values wrap around (after about 49.7 days). The server, given
1940 its current time is represented by timestamp T, always interprets
1941 timestamps from clients by treating half of the timestamp space as being
1942 later in time than T.
1943 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
1946 /* TIME_HALF is half of the number space of a Time type variable */
1947 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
1949 if (t2
>= TIME_HALF
)
1950 /* t2 is in the second half so t1 might wrap around and be smaller than
1952 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
1954 /* t2 is in the first half so t1 has to come after it */
1955 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);
1958 Time
event_get_server_time()
1960 /* Generate a timestamp */
1963 XChangeProperty(ob_display
, screen_support_win
,
1964 prop_atoms
.wm_class
, prop_atoms
.string
,
1965 8, PropModeAppend
, NULL
, 0);
1966 XWindowEvent(ob_display
, screen_support_win
, PropertyChangeMask
, &event
);
1967 return event
.xproperty
.time
;