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.
32 #include "menuframe.h"
38 #include "framerender.h"
40 #include "moveresize.h"
43 #include "extensions.h"
44 #include "translate.h"
47 #include <X11/Xatom.h>
50 #ifdef HAVE_SYS_SELECT_H
51 # include <sys/select.h>
57 # include <unistd.h> /* for usleep() */
60 # include <X11/XKBlib.h>
64 #include <X11/ICE/ICElib.h>
78 static void event_process(const XEvent
*e
, gpointer data
);
79 static void event_handle_root(XEvent
*e
);
80 static gboolean
event_handle_menu_keyboard(XEvent
*e
);
81 static gboolean
event_handle_menu(XEvent
*e
);
82 static void event_handle_dock(ObDock
*s
, XEvent
*e
);
83 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
);
84 static void event_handle_client(ObClient
*c
, XEvent
*e
);
85 static void event_handle_user_time_window_clients(GSList
*l
, XEvent
*e
);
86 static void event_handle_user_input(ObClient
*client
, XEvent
*e
);
88 static void focus_delay_dest(gpointer data
);
89 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
);
90 static gboolean
focus_delay_func(gpointer data
);
91 static void focus_delay_client_dest(ObClient
*client
, gpointer data
);
93 static gboolean
menu_hide_delay_func(gpointer data
);
95 /* The time for the current event being processed */
96 Time event_curtime
= CurrentTime
;
98 static guint ignore_enter_focus
= 0;
99 static gboolean menu_can_hide
;
100 static gboolean focus_left_screen
= FALSE
;
103 static void ice_handler(gint fd
, gpointer conn
)
106 IceProcessMessages(conn
, NULL
, &b
);
109 static void ice_watch(IceConn conn
, IcePointer data
, Bool opening
,
110 IcePointer
*watch_data
)
115 fd
= IceConnectionNumber(conn
);
116 ob_main_loop_fd_add(ob_main_loop
, fd
, ice_handler
, conn
, NULL
);
118 ob_main_loop_fd_remove(ob_main_loop
, fd
);
124 void event_startup(gboolean reconfig
)
126 if (reconfig
) return;
128 ob_main_loop_x_add(ob_main_loop
, event_process
, NULL
, NULL
);
131 IceAddConnectionWatch(ice_watch
, NULL
);
134 client_add_destructor(focus_delay_client_dest
, NULL
);
137 void event_shutdown(gboolean reconfig
)
139 if (reconfig
) return;
142 IceRemoveConnectionWatch(ice_watch
, NULL
);
145 client_remove_destructor(focus_delay_client_dest
);
148 static Window
event_get_window(XEvent
*e
)
155 window
= RootWindow(ob_display
, ob_screen
);
158 window
= e
->xmap
.window
;
161 window
= e
->xunmap
.window
;
164 window
= e
->xdestroywindow
.window
;
166 case ConfigureRequest
:
167 window
= e
->xconfigurerequest
.window
;
169 case ConfigureNotify
:
170 window
= e
->xconfigure
.window
;
174 if (extensions_xkb
&& e
->type
== extensions_xkb_event_basep
) {
175 switch (((XkbAnyEvent
*)e
)->xkb_type
) {
177 window
= ((XkbBellNotifyEvent
*)e
)->window
;
184 if (extensions_sync
&&
185 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
190 window
= e
->xany
.window
;
195 static void event_set_curtime(XEvent
*e
)
197 Time t
= CurrentTime
;
199 /* grab the lasttime and hack up the state */
215 t
= e
->xproperty
.time
;
219 t
= e
->xcrossing
.time
;
223 if (extensions_sync
&&
224 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
226 t
= ((XSyncAlarmNotifyEvent
*)e
)->time
;
229 /* if more event types are anticipated, get their timestamp
237 static void event_hack_mods(XEvent
*e
)
240 XkbStateRec xkb_state
;
246 e
->xbutton
.state
= modkeys_only_modifier_masks(e
->xbutton
.state
);
249 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
252 e
->xkey
.state
= modkeys_only_modifier_masks(e
->xkey
.state
);
254 if (XkbGetState(ob_display
, XkbUseCoreKbd
, &xkb_state
) == Success
) {
255 e
->xkey
.state
= xkb_state
.compat_state
;
259 /* remove from the state the mask of the modifier key being released,
260 if it is a modifier key being released that is */
261 e
->xkey
.state
&= ~modkeys_keycode_to_mask(e
->xkey
.keycode
);
264 e
->xmotion
.state
= modkeys_only_modifier_masks(e
->xmotion
.state
);
265 /* compress events */
268 while (XCheckTypedWindowEvent(ob_display
, e
->xmotion
.window
,
270 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
271 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
278 static gboolean
wanted_focusevent(XEvent
*e
, gboolean in_client_only
)
280 gint mode
= e
->xfocus
.mode
;
281 gint detail
= e
->xfocus
.detail
;
282 Window win
= e
->xany
.window
;
284 if (e
->type
== FocusIn
) {
285 /* These are ones we never want.. */
287 /* This means focus was given by a keyboard/mouse grab. */
288 if (mode
== NotifyGrab
)
290 /* This means focus was given back from a keyboard/mouse grab. */
291 if (mode
== NotifyUngrab
)
294 /* These are the ones we want.. */
296 if (win
== RootWindow(ob_display
, ob_screen
) && !in_client_only
) {
297 /* This means focus reverted off of a client */
298 if (detail
== NotifyPointerRoot
|| detail
== NotifyDetailNone
||
299 detail
== NotifyInferior
)
305 /* This means focus moved from the root window to a client */
306 if (detail
== NotifyVirtual
)
308 /* This means focus moved from one client to another */
309 if (detail
== NotifyNonlinearVirtual
)
311 /* This means focus moved to the frame window */
312 if (detail
== NotifyInferior
&& !in_client_only
)
318 g_assert(e
->type
== FocusOut
);
320 /* These are ones we never want.. */
322 /* This means focus was taken by a keyboard/mouse grab. */
323 if (mode
== NotifyGrab
)
326 /* Focus left the root window revertedto state */
327 if (win
== RootWindow(ob_display
, ob_screen
))
330 /* These are the ones we want.. */
332 /* This means focus moved from a client to the root window */
333 if (detail
== NotifyVirtual
)
335 /* This means focus moved from one client to another */
336 if (detail
== NotifyNonlinearVirtual
)
338 /* This means focus had moved to our frame window and now moved off */
339 if (detail
== NotifyNonlinear
)
347 static Bool
look_for_focusin(Display
*d
, XEvent
*e
, XPointer arg
)
349 return e
->type
== FocusIn
&& wanted_focusevent(e
, FALSE
);
352 static Bool
look_for_focusin_client(Display
*d
, XEvent
*e
, XPointer arg
)
354 return e
->type
== FocusIn
&& wanted_focusevent(e
, TRUE
);
357 static void print_focusevent(XEvent
*e
)
359 gint mode
= e
->xfocus
.mode
;
360 gint detail
= e
->xfocus
.detail
;
361 Window win
= e
->xany
.window
;
362 const gchar
*modestr
, *detailstr
;
365 case NotifyNormal
: modestr
="NotifyNormal"; break;
366 case NotifyGrab
: modestr
="NotifyGrab"; break;
367 case NotifyUngrab
: modestr
="NotifyUngrab"; break;
368 case NotifyWhileGrabbed
: modestr
="NotifyWhileGrabbed"; break;
371 case NotifyAncestor
: detailstr
="NotifyAncestor"; break;
372 case NotifyVirtual
: detailstr
="NotifyVirtual"; break;
373 case NotifyInferior
: detailstr
="NotifyInferior"; break;
374 case NotifyNonlinear
: detailstr
="NotifyNonlinear"; break;
375 case NotifyNonlinearVirtual
: detailstr
="NotifyNonlinearVirtual"; break;
376 case NotifyPointer
: detailstr
="NotifyPointer"; break;
377 case NotifyPointerRoot
: detailstr
="NotifyPointerRoot"; break;
378 case NotifyDetailNone
: detailstr
="NotifyDetailNone"; break;
383 ob_debug_type(OB_DEBUG_FOCUS
, "Focus%s 0x%x mode=%s detail=%s\n",
384 (e
->xfocus
.type
== FocusIn
? "In" : "Out"),
390 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
395 if (!wanted_focusevent(e
, FALSE
))
400 if (!wanted_focusevent(e
, FALSE
))
407 static void event_process(const XEvent
*ec
, gpointer data
)
410 ObClient
*client
= NULL
;
412 ObDockApp
*dockapp
= NULL
;
413 ObWindow
*obwin
= NULL
;
414 GSList
*timewinclients
= NULL
;
416 ObEventData
*ed
= data
;
418 /* make a copy we can mangle */
422 window
= event_get_window(e
);
423 if (e
->type
!= PropertyNotify
||
424 !(timewinclients
= propwin_get_clients(window
,
425 OB_PROPWIN_USER_TIME
)))
426 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
427 switch (obwin
->type
) {
429 dock
= WINDOW_AS_DOCK(obwin
);
432 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
435 client
= WINDOW_AS_CLIENT(obwin
);
438 case Window_Internal
:
439 /* not to be used for events */
440 g_assert_not_reached();
445 event_set_curtime(e
);
447 if (event_ignore(e
, client
)) {
454 /* deal with it in the kernel */
456 if (menu_frame_visible
&&
457 (e
->type
== EnterNotify
|| e
->type
== LeaveNotify
))
459 /* crossing events for menu */
460 event_handle_menu(e
);
461 } else if (e
->type
== FocusIn
) {
462 if (e
->xfocus
.detail
== NotifyPointerRoot
||
463 e
->xfocus
.detail
== NotifyDetailNone
||
464 e
->xfocus
.detail
== NotifyInferior
)
467 ob_debug_type(OB_DEBUG_FOCUS
,
468 "Focus went to pointer root/none or to our frame "
471 /* If another FocusIn is in the queue then don't fallback yet. This
472 fixes the fun case of:
473 window map -> send focusin
474 window unmap -> get focusout
475 window map -> send focusin
476 get first focus out -> fall back to something (new window
477 hasn't received focus yet, so something else) -> send focusin
478 which means the "something else" is the last thing to get a
479 focusin sent to it, so the new window doesn't end up with focus.
481 But if the other focus in is something like PointerRoot then we
482 still want to fall back.
484 if (XCheckIfEvent(ob_display
, &ce
, look_for_focusin_client
, NULL
)){
485 XPutBackEvent(ob_display
, &ce
);
486 ob_debug_type(OB_DEBUG_FOCUS
,
487 " but another FocusIn is coming\n");
489 /* Focus has been reverted to the root window, nothing, or to
492 FocusOut events come after UnmapNotify, so we don't need to
493 worry about focusing an invalid window
496 /* In this case we know focus is in our screen */
497 if (e
->xfocus
.detail
== NotifyInferior
)
498 focus_left_screen
= FALSE
;
500 if (!focus_left_screen
)
501 focus_fallback(TRUE
);
503 } else if (client
&& client
!= focus_client
) {
504 focus_left_screen
= FALSE
;
505 frame_adjust_focus(client
->frame
, TRUE
);
506 focus_set_client(client
);
507 client_calc_layer(client
);
508 client_bring_helper_windows(client
);
510 } else if (e
->type
== FocusOut
) {
511 gboolean nomove
= FALSE
;
514 /* Look for the followup FocusIn */
515 if (!XCheckIfEvent(ob_display
, &ce
, look_for_focusin
, NULL
)) {
516 /* There is no FocusIn, this means focus went to a window that
517 is not being managed, or a window on another screen. */
521 xerror_set_ignore(TRUE
);
522 if (XGetInputFocus(ob_display
, &win
, &i
) != 0 &&
523 XGetGeometry(ob_display
, win
, &root
, &i
,&i
,&u
,&u
,&u
,&u
) != 0 &&
524 root
!= RootWindow(ob_display
, ob_screen
))
526 ob_debug_type(OB_DEBUG_FOCUS
,
527 "Focus went to another screen !\n");
528 focus_left_screen
= TRUE
;
531 ob_debug_type(OB_DEBUG_FOCUS
,
532 "Focus went to a black hole !\n");
533 xerror_set_ignore(FALSE
);
534 /* nothing is focused */
535 focus_set_client(NULL
);
536 } else if (ce
.xany
.window
== e
->xany
.window
) {
537 ob_debug_type(OB_DEBUG_FOCUS
, "Focus didn't go anywhere\n");
538 /* If focus didn't actually move anywhere, there is nothing to do*/
541 /* Focus did move, so process the FocusIn event */
542 ObEventData ed
= { .ignored
= FALSE
};
543 event_process(&ce
, &ed
);
545 /* The FocusIn was ignored, this means it was on a window
546 that isn't a client. */
547 ob_debug_type(OB_DEBUG_FOCUS
,
548 "Focus went to an unmanaged window 0x%x !\n",
550 focus_fallback(TRUE
);
554 if (client
&& !nomove
) {
555 frame_adjust_focus(client
->frame
, FALSE
);
556 /* focus_set_client has already been called for sure */
557 client_calc_layer(client
);
559 } else if (timewinclients
)
560 event_handle_user_time_window_clients(timewinclients
, e
);
562 event_handle_client(client
, e
);
564 event_handle_dockapp(dockapp
, e
);
566 event_handle_dock(dock
, e
);
567 else if (window
== RootWindow(ob_display
, ob_screen
))
568 event_handle_root(e
);
569 else if (e
->type
== MapRequest
)
570 client_manage(window
);
571 else if (e
->type
== ClientMessage
) {
572 /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for
573 windows that are not managed yet. */
574 if (e
->xclient
.message_type
== prop_atoms
.net_request_frame_extents
) {
575 /* Pretend to manage the client, getting information used to
576 determine its decorations */
577 ObClient
*c
= client_fake_manage(e
->xclient
.window
);
580 /* adjust the decorations so we know the sizes */
581 frame_adjust_area(c
->frame
, FALSE
, TRUE
, TRUE
);
583 /* set the frame extents on the window */
584 vals
[0] = c
->frame
->size
.left
;
585 vals
[1] = c
->frame
->size
.right
;
586 vals
[2] = c
->frame
->size
.top
;
587 vals
[3] = c
->frame
->size
.bottom
;
588 PROP_SETA32(e
->xclient
.window
, net_frame_extents
,
591 /* Free the pretend client */
592 client_fake_unmanage(c
);
595 else if (e
->type
== ConfigureRequest
) {
596 /* unhandled config5Aure requests must be used to configure the
600 xwc
.x
= e
->xconfigurerequest
.x
;
601 xwc
.y
= e
->xconfigurerequest
.y
;
602 xwc
.width
= e
->xconfigurerequest
.width
;
603 xwc
.height
= e
->xconfigurerequest
.height
;
604 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
605 xwc
.sibling
= e
->xconfigurerequest
.above
;
606 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
608 /* we are not to be held responsible if someone sends us an
610 xerror_set_ignore(TRUE
);
611 XConfigureWindow(ob_display
, window
,
612 e
->xconfigurerequest
.value_mask
, &xwc
);
613 xerror_set_ignore(FALSE
);
616 else if (extensions_sync
&&
617 e
->type
== extensions_sync_event_basep
+ XSyncAlarmNotify
)
619 XSyncAlarmNotifyEvent
*se
= (XSyncAlarmNotifyEvent
*)e
;
620 if (se
->alarm
== moveresize_alarm
&& moveresize_in_progress
)
625 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
626 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
627 e
->type
== KeyRelease
)
629 event_handle_user_input(client
, e
);
632 /* if something happens and it's not from an XEvent, then we don't know
634 event_curtime
= CurrentTime
;
637 static void event_handle_root(XEvent
*e
)
643 ob_debug("Another WM has requested to replace us. Exiting.\n");
648 if (e
->xclient
.format
!= 32) break;
650 msgtype
= e
->xclient
.message_type
;
651 if (msgtype
== prop_atoms
.net_current_desktop
) {
652 guint d
= e
->xclient
.data
.l
[0];
653 if (d
< screen_num_desktops
) {
654 event_curtime
= e
->xclient
.data
.l
[1];
655 if (event_curtime
== 0)
656 ob_debug_type(OB_DEBUG_APP_BUGS
,
657 "_NET_CURRENT_DESKTOP message is missing "
659 screen_set_desktop(d
, TRUE
);
661 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
662 guint d
= e
->xclient
.data
.l
[0];
664 screen_set_num_desktops(d
);
665 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
666 screen_show_desktop(e
->xclient
.data
.l
[0] != 0, TRUE
);
667 } else if (msgtype
== prop_atoms
.openbox_control
) {
668 if (e
->xclient
.data
.l
[0] == 1)
670 else if (e
->xclient
.data
.l
[0] == 2)
675 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
)
676 screen_update_desktop_names();
677 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
678 screen_update_layout();
680 case ConfigureNotify
:
682 XRRUpdateConfiguration(e
);
691 void event_enter_client(ObClient
*client
)
693 g_assert(config_focus_follow
);
695 if (client_enter_focusable(client
) && client_can_focus(client
)) {
696 if (config_focus_delay
) {
697 ObFocusDelayData
*data
;
699 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
701 data
= g_new(ObFocusDelayData
, 1);
702 data
->client
= client
;
703 data
->time
= event_curtime
;
705 ob_main_loop_timeout_add(ob_main_loop
,
708 data
, focus_delay_cmp
, focus_delay_dest
);
710 ObFocusDelayData data
;
711 data
.client
= client
;
712 data
.time
= event_curtime
;
713 focus_delay_func(&data
);
718 static void event_handle_user_time_window_clients(GSList
*l
, XEvent
*e
)
720 g_assert(e
->type
== PropertyNotify
);
721 if (e
->xproperty
.atom
== prop_atoms
.net_wm_user_time
) {
722 for (; l
; l
= g_slist_next(l
))
723 client_update_user_time(l
->data
);
727 static void event_handle_client(ObClient
*client
, XEvent
*e
)
732 static gint px
= -1, py
= -1;
737 /* save where the press occured for the first button pressed */
739 pb
= e
->xbutton
.button
;
744 /* Wheel buttons don't draw because they are an instant click, so it
745 is a waste of resources to go drawing it.
746 if the user is doing an intereactive thing, or has a menu open then
747 the mouse is grabbed (possibly) and if we get these events we don't
748 want to deal with them
750 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5) &&
751 !keyboard_interactively_grabbed() &&
754 /* use where the press occured */
755 con
= frame_context(client
, e
->xbutton
.window
, px
, py
);
756 con
= mouse_button_frame_context(con
, e
->xbutton
.button
);
758 if (e
->type
== ButtonRelease
&& e
->xbutton
.button
== pb
)
759 pb
= 0, px
= py
= -1;
762 case OB_FRAME_CONTEXT_MAXIMIZE
:
763 client
->frame
->max_press
= (e
->type
== ButtonPress
);
764 framerender_frame(client
->frame
);
766 case OB_FRAME_CONTEXT_CLOSE
:
767 client
->frame
->close_press
= (e
->type
== ButtonPress
);
768 framerender_frame(client
->frame
);
770 case OB_FRAME_CONTEXT_ICONIFY
:
771 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
772 framerender_frame(client
->frame
);
774 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
775 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
776 framerender_frame(client
->frame
);
778 case OB_FRAME_CONTEXT_SHADE
:
779 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
780 framerender_frame(client
->frame
);
783 /* nothing changes with clicks for any other contexts */
789 con
= frame_context(client
, e
->xmotion
.window
,
790 e
->xmotion
.x
, e
->xmotion
.y
);
792 case OB_FRAME_CONTEXT_TITLEBAR
:
793 /* we've left the button area inside the titlebar */
794 if (client
->frame
->max_hover
|| client
->frame
->desk_hover
||
795 client
->frame
->shade_hover
|| client
->frame
->iconify_hover
||
796 client
->frame
->close_hover
)
798 client
->frame
->max_hover
= FALSE
;
799 client
->frame
->desk_hover
= FALSE
;
800 client
->frame
->shade_hover
= FALSE
;
801 client
->frame
->iconify_hover
= FALSE
;
802 client
->frame
->close_hover
= FALSE
;
803 frame_adjust_state(client
->frame
);
806 case OB_FRAME_CONTEXT_MAXIMIZE
:
807 if (!client
->frame
->max_hover
) {
808 client
->frame
->max_hover
= TRUE
;
809 frame_adjust_state(client
->frame
);
812 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
813 if (!client
->frame
->desk_hover
) {
814 client
->frame
->desk_hover
= TRUE
;
815 frame_adjust_state(client
->frame
);
818 case OB_FRAME_CONTEXT_SHADE
:
819 if (!client
->frame
->shade_hover
) {
820 client
->frame
->shade_hover
= TRUE
;
821 frame_adjust_state(client
->frame
);
824 case OB_FRAME_CONTEXT_ICONIFY
:
825 if (!client
->frame
->iconify_hover
) {
826 client
->frame
->iconify_hover
= TRUE
;
827 frame_adjust_state(client
->frame
);
830 case OB_FRAME_CONTEXT_CLOSE
:
831 if (!client
->frame
->close_hover
) {
832 client
->frame
->close_hover
= TRUE
;
833 frame_adjust_state(client
->frame
);
841 con
= frame_context(client
, e
->xcrossing
.window
,
842 e
->xcrossing
.x
, e
->xcrossing
.y
);
844 case OB_FRAME_CONTEXT_MAXIMIZE
:
845 client
->frame
->max_hover
= FALSE
;
846 frame_adjust_state(client
->frame
);
848 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
849 client
->frame
->desk_hover
= FALSE
;
850 frame_adjust_state(client
->frame
);
852 case OB_FRAME_CONTEXT_SHADE
:
853 client
->frame
->shade_hover
= FALSE
;
854 frame_adjust_state(client
->frame
);
856 case OB_FRAME_CONTEXT_ICONIFY
:
857 client
->frame
->iconify_hover
= FALSE
;
858 frame_adjust_state(client
->frame
);
860 case OB_FRAME_CONTEXT_CLOSE
:
861 client
->frame
->close_hover
= FALSE
;
862 frame_adjust_state(client
->frame
);
864 case OB_FRAME_CONTEXT_FRAME
:
865 /* When the mouse leaves an animating window, don't use the
866 corresponding enter events. Pretend like the animating window
867 doesn't even exist..! */
868 if (frame_iconify_animating(client
->frame
))
869 event_ignore_queued_enters();
871 ob_debug_type(OB_DEBUG_FOCUS
,
872 "%sNotify mode %d detail %d on %lx\n",
873 (e
->type
== EnterNotify
? "Enter" : "Leave"),
875 e
->xcrossing
.detail
, (client
?client
->window
:0));
876 if (keyboard_interactively_grabbed())
878 if (config_focus_follow
&& config_focus_delay
&&
879 /* leave inferior events can happen when the mouse goes onto
880 the window's border and then into the window before the
882 e
->xcrossing
.detail
!= NotifyInferior
)
884 ob_main_loop_timeout_remove_data(ob_main_loop
,
895 gboolean nofocus
= FALSE
;
897 if (ignore_enter_focus
) {
898 ignore_enter_focus
--;
902 con
= frame_context(client
, e
->xcrossing
.window
,
903 e
->xcrossing
.x
, e
->xcrossing
.y
);
905 case OB_FRAME_CONTEXT_MAXIMIZE
:
906 client
->frame
->max_hover
= TRUE
;
907 frame_adjust_state(client
->frame
);
909 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
910 client
->frame
->desk_hover
= TRUE
;
911 frame_adjust_state(client
->frame
);
913 case OB_FRAME_CONTEXT_SHADE
:
914 client
->frame
->shade_hover
= TRUE
;
915 frame_adjust_state(client
->frame
);
917 case OB_FRAME_CONTEXT_ICONIFY
:
918 client
->frame
->iconify_hover
= TRUE
;
919 frame_adjust_state(client
->frame
);
921 case OB_FRAME_CONTEXT_CLOSE
:
922 client
->frame
->close_hover
= TRUE
;
923 frame_adjust_state(client
->frame
);
925 case OB_FRAME_CONTEXT_FRAME
:
926 if (keyboard_interactively_grabbed())
928 if (e
->xcrossing
.mode
== NotifyGrab
||
929 e
->xcrossing
.mode
== NotifyUngrab
||
930 /*ignore enters when we're already in the window */
931 e
->xcrossing
.detail
== NotifyInferior
)
933 ob_debug_type(OB_DEBUG_FOCUS
,
934 "%sNotify mode %d detail %d on %lx IGNORED\n",
935 (e
->type
== EnterNotify
? "Enter" : "Leave"),
937 e
->xcrossing
.detail
, client
?client
->window
:0);
939 ob_debug_type(OB_DEBUG_FOCUS
,
940 "%sNotify mode %d detail %d on %lx, "
941 "focusing window: %d\n",
942 (e
->type
== EnterNotify
? "Enter" : "Leave"),
944 e
->xcrossing
.detail
, (client
?client
->window
:0),
946 if (!nofocus
&& config_focus_follow
)
947 event_enter_client(client
);
955 case ConfigureRequest
:
956 /* dont compress these unless you're going to watch for property
957 notifies in between (these can change what the configure would
959 also you can't compress stacking events
962 ob_debug("ConfigureRequest desktop %d wmstate %d vis %d\n",
963 screen_desktop
, client
->wmstate
, client
->frame
->visible
);
965 /* don't allow clients to move shaded windows (fvwm does this) */
966 if (client
->shaded
) {
967 e
->xconfigurerequest
.value_mask
&= ~CWX
;
968 e
->xconfigurerequest
.value_mask
&= ~CWY
;
971 /* resize, then move, as specified in the EWMH section 7.7 */
972 if (e
->xconfigurerequest
.value_mask
& (CWWidth
| CWHeight
|
977 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
978 client
->border_width
= e
->xconfigurerequest
.border_width
;
980 x
= (e
->xconfigurerequest
.value_mask
& CWX
) ?
981 e
->xconfigurerequest
.x
: client
->area
.x
;
982 y
= (e
->xconfigurerequest
.value_mask
& CWY
) ?
983 e
->xconfigurerequest
.y
: client
->area
.y
;
984 w
= (e
->xconfigurerequest
.value_mask
& CWWidth
) ?
985 e
->xconfigurerequest
.width
: client
->area
.width
;
986 h
= (e
->xconfigurerequest
.value_mask
& CWHeight
) ?
987 e
->xconfigurerequest
.height
: client
->area
.height
;
989 ob_debug("ConfigureRequest x %d %d y %d %d\n",
990 e
->xconfigurerequest
.value_mask
& CWX
, x
,
991 e
->xconfigurerequest
.value_mask
& CWY
, y
);
993 /* check for broken apps moving to their root position
995 XXX remove this some day...that would be nice. right now all
996 kde apps do this when they try activate themselves on another
997 desktop. eg. open amarok window on desktop 1, switch to desktop
998 2, click amarok tray icon. it will move by its decoration size.
1000 if (x
!= client
->area
.x
&&
1001 x
== (client
->frame
->area
.x
+ client
->frame
->size
.left
-
1002 (gint
)client
->border_width
) &&
1003 y
!= client
->area
.y
&&
1004 y
== (client
->frame
->area
.y
+ client
->frame
->size
.top
-
1005 (gint
)client
->border_width
))
1007 ob_debug_type(OB_DEBUG_APP_BUGS
,
1008 "Application %s is trying to move via "
1009 "ConfigureRequest to it's root window position "
1010 "but it is not using StaticGravity\n",
1017 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1018 client_configure_full(client
, x
, y
, w
, h
, FALSE
, TRUE
, TRUE
);
1021 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
1022 ObClient
*sibling
= NULL
;
1024 /* get the sibling */
1025 if (e
->xconfigurerequest
.value_mask
& CWSibling
) {
1027 win
= g_hash_table_lookup(window_map
,
1028 &e
->xconfigurerequest
.above
);
1029 if (WINDOW_IS_CLIENT(win
) && WINDOW_AS_CLIENT(win
) != client
)
1030 sibling
= WINDOW_AS_CLIENT(win
);
1033 /* activate it rather than just focus it */
1034 stacking_restack_request(client
, sibling
,
1035 e
->xconfigurerequest
.detail
, TRUE
);
1039 if (client
->ignore_unmaps
) {
1040 client
->ignore_unmaps
--;
1043 ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
1044 "ignores left %d\n",
1045 client
->window
, e
->xunmap
.event
, e
->xunmap
.from_configure
,
1046 client
->ignore_unmaps
);
1047 client_unmanage(client
);
1050 ob_debug("DestroyNotify for window 0x%x\n", client
->window
);
1051 client_unmanage(client
);
1053 case ReparentNotify
:
1054 /* this is when the client is first taken captive in the frame */
1055 if (e
->xreparent
.parent
== client
->frame
->plate
) break;
1058 This event is quite rare and is usually handled in unmapHandler.
1059 However, if the window is unmapped when the reparent event occurs,
1060 the window manager never sees it because an unmap event is not sent
1061 to an already unmapped window.
1064 /* we don't want the reparent event, put it back on the stack for the
1065 X server to deal with after we unmanage the window */
1066 XPutBackEvent(ob_display
, e
);
1068 ob_debug("ReparentNotify for window 0x%x\n", client
->window
);
1069 client_unmanage(client
);
1072 ob_debug("MapRequest for 0x%lx\n", client
->window
);
1073 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
1074 does, we don't want it!
1075 it can happen now when the window is on
1076 another desktop, but we still don't
1078 client_activate(client
, FALSE
, TRUE
);
1081 /* validate cuz we query stuff off the client here */
1082 if (!client_validate(client
)) break;
1084 if (e
->xclient
.format
!= 32) return;
1086 msgtype
= e
->xclient
.message_type
;
1087 if (msgtype
== prop_atoms
.wm_change_state
) {
1088 /* compress changes into a single change */
1089 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1091 /* XXX: it would be nice to compress ALL messages of a
1092 type, not just messages in a row without other
1093 message types between. */
1094 if (ce
.xclient
.message_type
!= msgtype
) {
1095 XPutBackEvent(ob_display
, &ce
);
1098 e
->xclient
= ce
.xclient
;
1100 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
1101 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
1102 /* compress changes into a single change */
1103 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1105 /* XXX: it would be nice to compress ALL messages of a
1106 type, not just messages in a row without other
1107 message types between. */
1108 if (ce
.xclient
.message_type
!= msgtype
) {
1109 XPutBackEvent(ob_display
, &ce
);
1112 e
->xclient
= ce
.xclient
;
1114 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
1115 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
1116 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
1118 } else if (msgtype
== prop_atoms
.net_wm_state
) {
1119 /* can't compress these */
1120 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
1121 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
1122 e
->xclient
.data
.l
[0] == 1 ? "Add" :
1123 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1124 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
1126 client_set_state(client
, e
->xclient
.data
.l
[0],
1127 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
1128 } else if (msgtype
== prop_atoms
.net_close_window
) {
1129 ob_debug("net_close_window for 0x%lx\n", client
->window
);
1130 client_close(client
);
1131 } else if (msgtype
== prop_atoms
.net_active_window
) {
1132 ob_debug("net_active_window for 0x%lx source=%s\n",
1134 (e
->xclient
.data
.l
[0] == 0 ? "unknown" :
1135 (e
->xclient
.data
.l
[0] == 1 ? "application" :
1136 (e
->xclient
.data
.l
[0] == 2 ? "user" : "INVALID"))));
1137 /* XXX make use of data.l[2] !? */
1138 event_curtime
= e
->xclient
.data
.l
[1];
1139 if (event_curtime
== 0)
1140 ob_debug_type(OB_DEBUG_APP_BUGS
,
1141 "_NET_ACTIVE_WINDOW message for window %s is "
1142 "missing a timestamp\n", client
->title
);
1143 client_activate(client
, FALSE
,
1144 (e
->xclient
.data
.l
[0] == 0 ||
1145 e
->xclient
.data
.l
[0] == 2));
1146 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
1147 ob_debug("net_wm_moveresize for 0x%lx direction %d\n",
1148 client
->window
, e
->xclient
.data
.l
[2]);
1149 if ((Atom
)e
->xclient
.data
.l
[2] ==
1150 prop_atoms
.net_wm_moveresize_size_topleft
||
1151 (Atom
)e
->xclient
.data
.l
[2] ==
1152 prop_atoms
.net_wm_moveresize_size_top
||
1153 (Atom
)e
->xclient
.data
.l
[2] ==
1154 prop_atoms
.net_wm_moveresize_size_topright
||
1155 (Atom
)e
->xclient
.data
.l
[2] ==
1156 prop_atoms
.net_wm_moveresize_size_right
||
1157 (Atom
)e
->xclient
.data
.l
[2] ==
1158 prop_atoms
.net_wm_moveresize_size_right
||
1159 (Atom
)e
->xclient
.data
.l
[2] ==
1160 prop_atoms
.net_wm_moveresize_size_bottomright
||
1161 (Atom
)e
->xclient
.data
.l
[2] ==
1162 prop_atoms
.net_wm_moveresize_size_bottom
||
1163 (Atom
)e
->xclient
.data
.l
[2] ==
1164 prop_atoms
.net_wm_moveresize_size_bottomleft
||
1165 (Atom
)e
->xclient
.data
.l
[2] ==
1166 prop_atoms
.net_wm_moveresize_size_left
||
1167 (Atom
)e
->xclient
.data
.l
[2] ==
1168 prop_atoms
.net_wm_moveresize_move
||
1169 (Atom
)e
->xclient
.data
.l
[2] ==
1170 prop_atoms
.net_wm_moveresize_size_keyboard
||
1171 (Atom
)e
->xclient
.data
.l
[2] ==
1172 prop_atoms
.net_wm_moveresize_move_keyboard
) {
1174 moveresize_start(client
, e
->xclient
.data
.l
[0],
1175 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
1176 e
->xclient
.data
.l
[2]);
1178 else if ((Atom
)e
->xclient
.data
.l
[2] ==
1179 prop_atoms
.net_wm_moveresize_cancel
)
1180 moveresize_end(TRUE
);
1181 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
1182 gint grav
, x
, y
, w
, h
;
1184 if (e
->xclient
.data
.l
[0] & 0xff)
1185 grav
= e
->xclient
.data
.l
[0] & 0xff;
1187 grav
= client
->gravity
;
1189 if (e
->xclient
.data
.l
[0] & 1 << 8)
1190 x
= e
->xclient
.data
.l
[1];
1193 if (e
->xclient
.data
.l
[0] & 1 << 9)
1194 y
= e
->xclient
.data
.l
[2];
1197 if (e
->xclient
.data
.l
[0] & 1 << 10)
1198 w
= e
->xclient
.data
.l
[3];
1200 w
= client
->area
.width
;
1201 if (e
->xclient
.data
.l
[0] & 1 << 11)
1202 h
= e
->xclient
.data
.l
[4];
1204 h
= client
->area
.height
;
1206 ob_debug("MOVERESIZE x %d %d y %d %d\n",
1207 e
->xclient
.data
.l
[0] & 1 << 8, x
,
1208 e
->xclient
.data
.l
[0] & 1 << 9, y
);
1209 client_convert_gravity(client
, grav
, &x
, &y
, w
, h
);
1210 client_find_onscreen(client
, &x
, &y
, w
, h
, FALSE
);
1211 client_configure(client
, x
, y
, w
, h
, FALSE
, TRUE
);
1212 } else if (msgtype
== prop_atoms
.net_restack_window
) {
1213 if (e
->xclient
.data
.l
[0] != 2) {
1214 ob_debug_type(OB_DEBUG_APP_BUGS
,
1215 "_NET_RESTACK_WINDOW sent for window %s with "
1216 "invalid source indication %ld\n",
1217 client
->title
, e
->xclient
.data
.l
[0]);
1219 ObClient
*sibling
= NULL
;
1220 if (e
->xclient
.data
.l
[1]) {
1221 ObWindow
*win
= g_hash_table_lookup(window_map
,
1222 &e
->xclient
.data
.l
[1]);
1223 if (WINDOW_IS_CLIENT(win
) &&
1224 WINDOW_AS_CLIENT(win
) != client
)
1226 sibling
= WINDOW_AS_CLIENT(win
);
1228 if (sibling
== NULL
)
1229 ob_debug_type(OB_DEBUG_APP_BUGS
,
1230 "_NET_RESTACK_WINDOW sent for window %s "
1231 "with invalid sibling 0x%x\n",
1232 client
->title
, e
->xclient
.data
.l
[1]);
1234 if (e
->xclient
.data
.l
[2] == Below
||
1235 e
->xclient
.data
.l
[2] == BottomIf
||
1236 e
->xclient
.data
.l
[2] == Above
||
1237 e
->xclient
.data
.l
[2] == TopIf
||
1238 e
->xclient
.data
.l
[2] == Opposite
)
1240 /* just raise, don't activate */
1241 stacking_restack_request(client
, sibling
,
1242 e
->xclient
.data
.l
[2], FALSE
);
1244 ob_debug_type(OB_DEBUG_APP_BUGS
,
1245 "_NET_RESTACK_WINDOW sent for window %s "
1246 "with invalid detail %d\n",
1247 client
->title
, e
->xclient
.data
.l
[2]);
1251 case PropertyNotify
:
1252 /* validate cuz we query stuff off the client here */
1253 if (!client_validate(client
)) break;
1255 /* compress changes to a single property into a single change */
1256 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
1260 /* XXX: it would be nice to compress ALL changes to a property,
1261 not just changes in a row without other props between. */
1263 a
= ce
.xproperty
.atom
;
1264 b
= e
->xproperty
.atom
;
1268 if ((a
== prop_atoms
.net_wm_name
||
1269 a
== prop_atoms
.wm_name
||
1270 a
== prop_atoms
.net_wm_icon_name
||
1271 a
== prop_atoms
.wm_icon_name
)
1273 (b
== prop_atoms
.net_wm_name
||
1274 b
== prop_atoms
.wm_name
||
1275 b
== prop_atoms
.net_wm_icon_name
||
1276 b
== prop_atoms
.wm_icon_name
)) {
1279 if (a
== prop_atoms
.net_wm_icon
&&
1280 b
== prop_atoms
.net_wm_icon
)
1283 XPutBackEvent(ob_display
, &ce
);
1287 msgtype
= e
->xproperty
.atom
;
1288 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1289 client_update_normal_hints(client
);
1290 /* normal hints can make a window non-resizable */
1291 client_setup_decor_and_functions(client
);
1292 } else if (msgtype
== XA_WM_HINTS
) {
1293 client_update_wmhints(client
);
1294 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1295 client_update_transient_for(client
);
1296 client_get_type_and_transientness(client
);
1297 /* type may have changed, so update the layer */
1298 client_calc_layer(client
);
1299 client_setup_decor_and_functions(client
);
1300 } else if (msgtype
== prop_atoms
.net_wm_name
||
1301 msgtype
== prop_atoms
.wm_name
||
1302 msgtype
== prop_atoms
.net_wm_icon_name
||
1303 msgtype
== prop_atoms
.wm_icon_name
) {
1304 client_update_title(client
);
1305 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1306 client_update_protocols(client
);
1307 client_setup_decor_and_functions(client
);
1309 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1310 client_update_strut(client
);
1312 else if (msgtype
== prop_atoms
.net_wm_icon
) {
1313 client_update_icons(client
);
1315 else if (msgtype
== prop_atoms
.net_wm_icon_geometry
) {
1316 client_update_icon_geometry(client
);
1318 else if (msgtype
== prop_atoms
.net_wm_user_time
) {
1319 client_update_user_time(client
);
1321 else if (msgtype
== prop_atoms
.net_wm_user_time_window
) {
1322 client_update_user_time_window(client
);
1325 else if (msgtype
== prop_atoms
.net_wm_sync_request_counter
) {
1326 client_update_sync_request_counter(client
);
1329 case ColormapNotify
:
1330 client_update_colormap(client
, e
->xcolormap
.colormap
);
1335 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1336 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1337 frame_adjust_shape(client
->frame
);
1343 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1347 if (e
->xbutton
.button
== 1)
1348 stacking_raise(DOCK_AS_WINDOW(s
));
1349 else if (e
->xbutton
.button
== 2)
1350 stacking_lower(DOCK_AS_WINDOW(s
));
1361 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1365 dock_app_drag(app
, &e
->xmotion
);
1368 if (app
->ignore_unmaps
) {
1369 app
->ignore_unmaps
--;
1372 dock_remove(app
, TRUE
);
1375 dock_remove(app
, FALSE
);
1377 case ReparentNotify
:
1378 dock_remove(app
, FALSE
);
1380 case ConfigureNotify
:
1381 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1386 static ObMenuFrame
* find_active_menu()
1389 ObMenuFrame
*ret
= NULL
;
1391 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1400 static ObMenuFrame
* find_active_or_last_menu()
1402 ObMenuFrame
*ret
= NULL
;
1404 ret
= find_active_menu();
1405 if (!ret
&& menu_frame_visible
)
1406 ret
= menu_frame_visible
->data
;
1410 static gboolean
event_handle_menu_keyboard(XEvent
*ev
)
1412 guint keycode
, state
;
1415 gboolean ret
= TRUE
;
1417 keycode
= ev
->xkey
.keycode
;
1418 state
= ev
->xkey
.state
;
1419 unikey
= translate_unichar(keycode
);
1421 frame
= find_active_or_last_menu();
1425 else if (keycode
== ob_keycode(OB_KEY_ESCAPE
) && state
== 0) {
1426 /* Escape closes the active menu */
1427 menu_frame_hide(frame
);
1430 else if (keycode
== ob_keycode(OB_KEY_RETURN
) && (state
== 0 ||
1431 state
== ControlMask
))
1433 /* Enter runs the active item or goes into the submenu.
1434 Control-Enter runs it without closing the menu. */
1436 menu_frame_select_next(frame
->child
);
1438 menu_entry_frame_execute(frame
->selected
, state
, ev
->xkey
.time
);
1441 else if (keycode
== ob_keycode(OB_KEY_LEFT
) && ev
->xkey
.state
== 0) {
1442 /* Left goes to the parent menu */
1443 menu_frame_select(frame
, NULL
, TRUE
);
1446 else if (keycode
== ob_keycode(OB_KEY_RIGHT
) && ev
->xkey
.state
== 0) {
1447 /* Right goes to the selected submenu */
1448 if (frame
->child
) menu_frame_select_next(frame
->child
);
1451 else if (keycode
== ob_keycode(OB_KEY_UP
) && state
== 0) {
1452 menu_frame_select_previous(frame
);
1455 else if (keycode
== ob_keycode(OB_KEY_DOWN
) && state
== 0) {
1456 menu_frame_select_next(frame
);
1459 /* keyboard accelerator shortcuts. */
1460 else if (ev
->xkey
.state
== 0 &&
1461 /* was it a valid key? */
1463 /* don't bother if the menu is empty. */
1468 ObMenuEntryFrame
*found
= NULL
;
1469 guint num_found
= 0;
1471 /* start after the selected one */
1472 start
= frame
->entries
;
1473 if (frame
->selected
) {
1474 for (it
= start
; frame
->selected
!= it
->data
; it
= g_list_next(it
))
1475 g_assert(it
!= NULL
); /* nothing was selected? */
1476 /* next with wraparound */
1477 start
= g_list_next(it
);
1478 if (start
== NULL
) start
= frame
->entries
;
1483 ObMenuEntryFrame
*e
= it
->data
;
1484 gunichar entrykey
= 0;
1486 if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
1487 entrykey
= e
->entry
->data
.normal
.shortcut
;
1488 else if (e
->entry
->type
== OB_MENU_ENTRY_TYPE_SUBMENU
)
1489 entrykey
= e
->entry
->data
.submenu
.submenu
->shortcut
;
1491 if (unikey
== entrykey
) {
1492 if (found
== NULL
) found
= e
;
1496 /* next with wraparound */
1497 it
= g_list_next(it
);
1498 if (it
== NULL
) it
= frame
->entries
;
1499 } while (it
!= start
);
1502 if (found
->entry
->type
== OB_MENU_ENTRY_TYPE_NORMAL
&&
1505 menu_frame_select(frame
, found
, TRUE
);
1506 usleep(50000); /* highlight the item for a short bit so the
1507 user can see what happened */
1508 menu_entry_frame_execute(found
, state
, ev
->xkey
.time
);
1510 menu_frame_select(frame
, found
, TRUE
);
1512 menu_frame_select_next(frame
->child
);
1523 static gboolean
event_handle_menu(XEvent
*ev
)
1526 ObMenuEntryFrame
*e
;
1527 gboolean ret
= TRUE
;
1531 if ((ev
->xbutton
.button
< 4 || ev
->xbutton
.button
> 5)
1534 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1535 ev
->xbutton
.y_root
)))
1536 menu_entry_frame_execute(e
, ev
->xbutton
.state
,
1539 menu_frame_hide_all();
1543 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
))) {
1544 if (e
->ignore_enters
)
1547 menu_frame_select(e
->frame
, e
, FALSE
);
1551 if ((e
= g_hash_table_lookup(menu_frame_map
, &ev
->xcrossing
.window
)) &&
1552 (f
= find_active_menu()) && f
->selected
== e
&&
1553 e
->entry
->type
!= OB_MENU_ENTRY_TYPE_SUBMENU
)
1555 menu_frame_select(e
->frame
, NULL
, FALSE
);
1558 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1559 ev
->xmotion
.y_root
)))
1560 menu_frame_select(e
->frame
, e
, FALSE
);
1563 ret
= event_handle_menu_keyboard(ev
);
1569 static void event_handle_user_input(ObClient
*client
, XEvent
*e
)
1571 g_assert(e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
1572 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
1573 e
->type
== KeyRelease
);
1575 if (menu_frame_visible
) {
1576 if (event_handle_menu(e
))
1577 /* don't use the event if the menu used it, but if the menu
1578 didn't use it and it's a keypress that is bound, it will
1579 close the menu and be used */
1583 /* if the keyboard interactive action uses the event then dont
1584 use it for bindings. likewise is moveresize uses the event. */
1585 if (!keyboard_process_interactive_grab(e
, &client
) &&
1586 !(moveresize_in_progress
&& moveresize_event(e
)))
1588 if (moveresize_in_progress
)
1589 /* make further actions work on the client being
1591 client
= moveresize_client
;
1593 menu_can_hide
= FALSE
;
1594 ob_main_loop_timeout_add(ob_main_loop
,
1595 config_menu_hide_delay
* 1000,
1596 menu_hide_delay_func
,
1597 NULL
, g_direct_equal
, NULL
);
1599 if (e
->type
== ButtonPress
||
1600 e
->type
== ButtonRelease
||
1601 e
->type
== MotionNotify
)
1603 /* the frame may not be "visible" but they can still click on it
1604 in the case where it is animating before disappearing */
1605 if (!client
|| !frame_iconify_animating(client
->frame
))
1606 mouse_event(client
, e
);
1607 } else if (e
->type
== KeyPress
) {
1608 keyboard_event((focus_cycle_target
? focus_cycle_target
:
1609 (client
? client
: focus_client
)), e
);
1614 static gboolean
menu_hide_delay_func(gpointer data
)
1616 menu_can_hide
= TRUE
;
1617 return FALSE
; /* no repeat */
1620 static void focus_delay_dest(gpointer data
)
1625 static gboolean
focus_delay_cmp(gconstpointer d1
, gconstpointer d2
)
1627 const ObFocusDelayData
*f1
= d1
;
1628 return f1
->client
== d2
;
1631 static gboolean
focus_delay_func(gpointer data
)
1633 ObFocusDelayData
*d
= data
;
1634 Time old
= event_curtime
;
1636 event_curtime
= d
->time
;
1637 if (focus_client
!= d
->client
) {
1638 if (client_focus(d
->client
) && config_focus_raise
)
1639 stacking_raise(CLIENT_AS_WINDOW(d
->client
));
1641 event_curtime
= old
;
1642 return FALSE
; /* no repeat */
1645 static void focus_delay_client_dest(ObClient
*client
, gpointer data
)
1647 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1651 void event_halt_focus_delay()
1653 ob_main_loop_timeout_remove(ob_main_loop
, focus_delay_func
);
1656 void event_ignore_queued_enters()
1658 GSList
*saved
= NULL
, *it
;
1661 XSync(ob_display
, FALSE
);
1663 /* count the events */
1665 e
= g_new(XEvent
, 1);
1666 if (XCheckTypedEvent(ob_display
, EnterNotify
, e
)) {
1669 win
= g_hash_table_lookup(window_map
, &e
->xany
.window
);
1670 if (win
&& WINDOW_IS_CLIENT(win
))
1671 ++ignore_enter_focus
;
1673 saved
= g_slist_append(saved
, e
);
1679 /* put the events back */
1680 for (it
= saved
; it
; it
= g_slist_next(it
)) {
1681 XPutBackEvent(ob_display
, it
->data
);
1684 g_slist_free(saved
);
1687 gboolean
event_time_after(Time t1
, Time t2
)
1689 g_assert(t1
!= CurrentTime
);
1690 g_assert(t2
!= CurrentTime
);
1693 Timestamp values wrap around (after about 49.7 days). The server, given
1694 its current time is represented by timestamp T, always interprets
1695 timestamps from clients by treating half of the timestamp space as being
1696 later in time than T.
1697 - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
1700 /* TIME_HALF is half of the number space of a Time type variable */
1701 #define TIME_HALF (Time)(1 << (sizeof(Time)*8-1))
1703 if (t2
>= TIME_HALF
)
1704 /* t2 is in the second half so t1 might wrap around and be smaller than
1706 return t1
>= t2
|| t1
< (t2
+ TIME_HALF
);
1708 /* t2 is in the first half so t1 has to come after it */
1709 return t1
>= t2
&& t1
< (t2
+ TIME_HALF
);