11 #include "menuframe.h"
15 #include "framerender.h"
17 #include "moveresize.h"
19 #include "extensions.h"
23 #include <X11/keysym.h>
24 #include <X11/Xatom.h>
27 #ifdef HAVE_SYS_SELECT_H
28 # include <sys/select.h>
35 #include <X11/ICE/ICElib.h>
38 static void event_process(const XEvent
*e
, gpointer data
);
39 static void event_handle_root(XEvent
*e
);
40 static void event_handle_menu(XEvent
*e
);
41 static void event_handle_dock(ObDock
*s
, XEvent
*e
);
42 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
);
43 static void event_handle_client(ObClient
*c
, XEvent
*e
);
45 static gboolean
focus_delay_func(gpointer data
);
46 static void focus_delay_client_dest(gpointer data
);
48 #define INVALID_FOCUSIN(e) ((e)->xfocus.detail == NotifyInferior || \
49 (e)->xfocus.detail == NotifyAncestor || \
50 (e)->xfocus.detail > NotifyNonlinearVirtual)
51 #define INVALID_FOCUSOUT(e) ((e)->xfocus.mode == NotifyGrab || \
52 (e)->xfocus.detail == NotifyInferior || \
53 (e)->xfocus.detail == NotifyAncestor || \
54 (e)->xfocus.detail > NotifyNonlinearVirtual)
56 Time event_lasttime
= 0;
58 /*! The value of the mask for the NumLock modifier */
59 unsigned int NumLockMask
;
60 /*! The value of the mask for the ScrollLock modifier */
61 unsigned int ScrollLockMask
;
62 /*! The key codes for the modifier keys */
63 static XModifierKeymap
*modmap
;
64 /*! Table of the constant modifier masks */
65 static const int mask_table
[] = {
66 ShiftMask
, LockMask
, ControlMask
, Mod1Mask
,
67 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
69 static int mask_table_size
;
71 static ObClient
*focus_delay_client
;
74 static void ice_handler(int fd
, gpointer conn
)
77 IceProcessMessages(conn
, NULL
, &b
);
80 static void ice_watch(IceConn conn
, IcePointer data
, Bool opening
,
81 IcePointer
*watch_data
)
86 fd
= IceConnectionNumber(conn
);
87 ob_main_loop_fd_add(ob_main_loop
, fd
, ice_handler
, conn
, NULL
);
89 ob_main_loop_fd_remove(ob_main_loop
, fd
);
95 void event_startup(gboolean reconfig
)
99 mask_table_size
= sizeof(mask_table
) / sizeof(mask_table
[0]);
101 /* get lock masks that are defined by the display (not constant) */
102 modmap
= XGetModifierMapping(ob_display
);
104 if (modmap
&& modmap
->max_keypermod
> 0) {
106 const size_t size
= mask_table_size
* modmap
->max_keypermod
;
107 /* get the values of the keyboard lock modifiers
108 Note: Caps lock is not retrieved the same way as Scroll and Num
109 lock since it doesn't need to be. */
110 const KeyCode num_lock
= XKeysymToKeycode(ob_display
, XK_Num_Lock
);
111 const KeyCode scroll_lock
= XKeysymToKeycode(ob_display
,
114 for (cnt
= 0; cnt
< size
; ++cnt
) {
115 if (! modmap
->modifiermap
[cnt
]) continue;
117 if (num_lock
== modmap
->modifiermap
[cnt
])
118 NumLockMask
= mask_table
[cnt
/ modmap
->max_keypermod
];
119 if (scroll_lock
== modmap
->modifiermap
[cnt
])
120 ScrollLockMask
= mask_table
[cnt
/ modmap
->max_keypermod
];
124 ob_main_loop_x_add(ob_main_loop
, event_process
, NULL
, NULL
);
127 IceAddConnectionWatch(ice_watch
, NULL
);
130 client_add_destructor(focus_delay_client_dest
);
133 void event_shutdown(gboolean reconfig
)
135 if (reconfig
) return;
137 client_remove_destructor(focus_delay_client_dest
);
138 XFreeModifiermap(modmap
);
141 static Window
event_get_window(XEvent
*e
)
148 window
= RootWindow(ob_display
, ob_screen
);
151 window
= e
->xmap
.window
;
154 window
= e
->xunmap
.window
;
157 window
= e
->xdestroywindow
.window
;
159 case ConfigureRequest
:
160 window
= e
->xconfigurerequest
.window
;
162 case ConfigureNotify
:
163 window
= e
->xconfigure
.window
;
167 if (extensions_xkb
&& e
->type
== extensions_xkb_event_basep
) {
168 switch (((XkbAnyEvent
*)e
)->xkb_type
) {
170 window
= ((XkbBellNotifyEvent
*)e
)->window
;
176 window
= e
->xany
.window
;
181 static void event_set_lasttime(XEvent
*e
)
185 /* grab the lasttime and hack up the state */
201 t
= e
->xproperty
.time
;
205 t
= e
->xcrossing
.time
;
208 /* if more event types are anticipated, get their timestamp
213 if (t
> event_lasttime
)
217 #define STRIP_MODS(s) \
218 s &= ~(LockMask | NumLockMask | ScrollLockMask), \
219 /* kill off the Button1Mask etc, only want the modifiers */ \
220 s &= (ControlMask | ShiftMask | Mod1Mask | \
221 Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask) \
223 static void event_hack_mods(XEvent *e)
231 STRIP_MODS(e
->xbutton
.state
);
234 STRIP_MODS(e
->xkey
.state
);
237 STRIP_MODS(e
->xkey
.state
);
238 /* remove from the state the mask of the modifier being released, if
239 it is a modifier key being released (this is a little ugly..) */
240 kp
= modmap
->modifiermap
;
241 for (i
= 0; i
< mask_table_size
; ++i
) {
242 for (k
= 0; k
< modmap
->max_keypermod
; ++k
) {
243 if (*kp
== e
->xkey
.keycode
) { /* found the keycode */
244 /* remove the mask for it */
245 e
->xkey
.state
&= ~mask_table
[i
];
246 /* cause the first loop to break; */
248 break; /* get outta here! */
255 STRIP_MODS(e
->xmotion
.state
);
256 /* compress events */
259 while (XCheckTypedWindowEvent(ob_display
, e
->xmotion
.window
,
261 e
->xmotion
.x_root
= ce
.xmotion
.x_root
;
262 e
->xmotion
.y_root
= ce
.xmotion
.y_root
;
269 static gboolean
event_ignore(XEvent
*e
, ObClient
*client
)
273 /* NotifyAncestor is not ignored in FocusIn like it is in FocusOut
274 because of RevertToPointerRoot. If the focus ends up reverting to
275 pointer root on a workspace change, then the FocusIn event that we
276 want will be of type NotifyAncestor. This situation does not occur
277 for FocusOut, so it is safely ignored there.
279 if (INVALID_FOCUSIN(e
) ||
282 ob_debug("FocusIn on %lx mode %d detail %d IGNORED\n",
283 e
->xfocus
.window
, e
->xfocus
.mode
, e
->xfocus
.detail
);
285 /* says a client was not found for the event (or a valid FocusIn
288 e
->xfocus
.window
= None
;
293 ob_debug("FocusIn on %lx mode %d detail %d\n", e
->xfocus
.window
,
294 e
->xfocus
.mode
, e
->xfocus
.detail
);
298 if (INVALID_FOCUSOUT(e
)) {
300 ob_debug("FocusOut on %lx mode %d detail %d IGNORED\n",
301 e
->xfocus
.window
, e
->xfocus
.mode
, e
->xfocus
.detail
);
307 ob_debug("FocusOut on %lx mode %d detail %d\n",
308 e
->xfocus
.window
, e
->xfocus
.mode
, e
->xfocus
.detail
);
313 gboolean fallback
= TRUE
;
316 if (!XCheckTypedWindowEvent(ob_display
, e
->xfocus
.window
,
318 if (!XCheckTypedEvent(ob_display
, FocusIn
, &fe
))
320 if (fe
.type
== FocusOut
) {
322 ob_debug("found pending FocusOut\n");
324 if (!INVALID_FOCUSOUT(&fe
)) {
325 /* if there is a VALID FocusOut still coming, don't
326 fallback focus yet, we'll deal with it then */
327 XPutBackEvent(ob_display
, &fe
);
333 ob_debug("found pending FocusIn\n");
335 /* is the focused window getting a FocusOut/In back to
338 if (fe
.xfocus
.window
== e
->xfocus
.window
&&
339 !event_ignore(&fe
, client
)) {
341 if focus_client is not set, then we can't do
342 this. we need the FocusIn. This happens in the
343 case when the set_focus_client(NULL) in the
344 focus_fallback function fires and then
345 focus_fallback picks the currently focused
346 window (such as on a SendToDesktop-esque action.
350 ob_debug("focused window got an Out/In back to "
351 "itself IGNORED both\n");
355 event_process(&fe
, NULL
);
357 ob_debug("focused window got an Out/In back to "
358 "itself but focus_client was null "
359 "IGNORED just the Out\n");
365 /* once all the FocusOut's have been dealt with, if there
366 is a FocusIn still left and it is valid, then use it */
367 event_process(&fe
, NULL
);
368 /* secret magic way of event_process telling us that no
369 client was found for the FocusIn event. ^_^ */
370 if (fe
.xfocus
.window
!= None
) {
378 ob_debug("no valid FocusIn and no FocusOut events found, "
381 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
387 /* NotifyUngrab occurs when a mouse button is released and the event is
388 caused, like when lowering a window */
389 /* NotifyVirtual occurs when ungrabbing the pointer */
390 if (e
->xcrossing
.mode
== NotifyGrab
||
391 e
->xcrossing
.detail
== NotifyInferior
||
392 (e
->xcrossing
.mode
== NotifyUngrab
&&
393 e
->xcrossing
.detail
== NotifyVirtual
)) {
395 ob_debug("%sNotify mode %d detail %d on %lx IGNORED\n",
396 (e
->type
== EnterNotify
? "Enter" : "Leave"),
398 e
->xcrossing
.detail
, client
?client
->window
:0);
403 ob_debug("%sNotify mode %d detail %d on %lx\n",
404 (e
->type
== EnterNotify
? "Enter" : "Leave"),
406 e
->xcrossing
.detail
, client
?client
->window
:0);
413 static void event_process(const XEvent
*ec
, gpointer data
)
416 ObClient
*client
= NULL
;
418 ObDockApp
*dockapp
= NULL
;
419 ObWindow
*obwin
= NULL
;
422 /* make a copy we can mangle */
426 window
= event_get_window(e
);
427 if ((obwin
= g_hash_table_lookup(window_map
, &window
))) {
428 switch (obwin
->type
) {
430 dock
= WINDOW_AS_DOCK(obwin
);
433 dockapp
= WINDOW_AS_DOCKAPP(obwin
);
436 client
= WINDOW_AS_CLIENT(obwin
);
439 case Window_Internal
:
440 /* not to be used for events */
441 g_assert_not_reached();
446 event_set_lasttime(e
);
448 if (event_ignore(e
, client
))
451 /* deal with it in the kernel */
453 event_handle_client(client
, e
);
455 event_handle_dockapp(dockapp
, e
);
457 event_handle_dock(dock
, e
);
458 else if (window
== RootWindow(ob_display
, ob_screen
))
459 event_handle_root(e
);
460 else if (e
->type
== MapRequest
)
461 client_manage(window
);
462 else if (e
->type
== ConfigureRequest
) {
463 /* unhandled configure requests must be used to configure the
467 xwc
.x
= e
->xconfigurerequest
.x
;
468 xwc
.y
= e
->xconfigurerequest
.y
;
469 xwc
.width
= e
->xconfigurerequest
.width
;
470 xwc
.height
= e
->xconfigurerequest
.height
;
471 xwc
.border_width
= e
->xconfigurerequest
.border_width
;
472 xwc
.sibling
= e
->xconfigurerequest
.above
;
473 xwc
.stack_mode
= e
->xconfigurerequest
.detail
;
475 /* we are not to be held responsible if someone sends us an
477 xerror_set_ignore(TRUE
);
478 XConfigureWindow(ob_display
, window
,
479 e
->xconfigurerequest
.value_mask
, &xwc
);
480 xerror_set_ignore(FALSE
);
483 /* user input (action-bound) events */
484 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
485 e
->type
== MotionNotify
|| e
->type
== KeyPress
||
486 e
->type
== KeyRelease
)
488 if (menu_frame_visible
)
489 event_handle_menu(e
);
490 else if (moveresize_in_progress
)
493 ObFrameContext context
;
495 context
= frame_context(client
, e
->xany
.window
);
497 if (!keyboard_process_interactive_grab(e
, &client
, &context
)) {
498 if (e
->type
== ButtonPress
|| e
->type
== ButtonRelease
||
499 e
->type
== MotionNotify
)
500 mouse_event(client
, context
, e
);
501 else if (e
->type
== KeyPress
)
502 /* when in the middle of a focus cycling action, this
503 causes the window which appears to be focused to be
504 the one on which the actions will be executed */
505 keyboard_event((focus_cycle_target
?
506 focus_cycle_target
: client
), e
);
512 static void event_handle_root(XEvent
*e
)
518 ob_debug("Another WM has requested to replace us. Exiting.\n");
523 if (e
->xclient
.format
!= 32) break;
525 msgtype
= e
->xclient
.message_type
;
526 if (msgtype
== prop_atoms
.net_current_desktop
) {
527 unsigned int d
= e
->xclient
.data
.l
[0];
528 if (d
< screen_num_desktops
)
529 screen_set_desktop(d
);
530 } else if (msgtype
== prop_atoms
.net_number_of_desktops
) {
531 unsigned int d
= e
->xclient
.data
.l
[0];
533 screen_set_num_desktops(d
);
534 } else if (msgtype
== prop_atoms
.net_showing_desktop
) {
535 screen_show_desktop(e
->xclient
.data
.l
[0] != 0);
539 if (e
->xproperty
.atom
== prop_atoms
.net_desktop_names
)
540 screen_update_desktop_names();
541 else if (e
->xproperty
.atom
== prop_atoms
.net_desktop_layout
)
542 screen_update_layout();
544 case ConfigureNotify
:
546 XRRUpdateConfiguration(e
);
553 if (extensions_vidmode
&& e
->type
== extensions_vidmode_event_basep
) {
554 ob_debug("VIDMODE EVENT\n");
560 static void event_handle_client(ObClient
*client
, XEvent
*e
)
568 case VisibilityNotify
:
569 client
->frame
->obscured
= e
->xvisibility
.state
!= VisibilityUnobscured
;
573 /* Wheel buttons don't draw because they are an instant click, so it
574 is a waste of resources to go drawing it. */
575 if (!(e
->xbutton
.button
== 4 || e
->xbutton
.button
== 5)) {
576 switch (frame_context(client
, e
->xbutton
.window
)) {
577 case OB_FRAME_CONTEXT_MAXIMIZE
:
578 client
->frame
->max_press
= (e
->type
== ButtonPress
);
579 framerender_frame(client
->frame
);
581 case OB_FRAME_CONTEXT_CLOSE
:
582 client
->frame
->close_press
= (e
->type
== ButtonPress
);
583 framerender_frame(client
->frame
);
585 case OB_FRAME_CONTEXT_ICONIFY
:
586 client
->frame
->iconify_press
= (e
->type
== ButtonPress
);
587 framerender_frame(client
->frame
);
589 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
590 client
->frame
->desk_press
= (e
->type
== ButtonPress
);
591 framerender_frame(client
->frame
);
593 case OB_FRAME_CONTEXT_SHADE
:
594 client
->frame
->shade_press
= (e
->type
== ButtonPress
);
595 framerender_frame(client
->frame
);
598 /* nothing changes with clicks for any other contexts */
605 ob_debug("FocusIn on client for %lx\n", client
->window
);
607 if (client
!= focus_client
) {
608 focus_set_client(client
);
609 frame_adjust_focus(client
->frame
, TRUE
);
614 ob_debug("FocusOut on client for %lx\n", client
->window
);
616 /* are we a fullscreen window or a transient of one? (checks layer)
617 if we are then we need to be iconified since we are losing focus
619 if (client
->layer
== OB_STACKING_LAYER_FULLSCREEN
&& !client
->iconic
&&
620 !client_search_focus_tree_full(client
))
621 /* iconify fullscreen windows when they and their transients
623 client_iconify(client
, TRUE
, TRUE
);
624 frame_adjust_focus(client
->frame
, FALSE
);
627 con
= frame_context(client
, e
->xcrossing
.window
);
629 case OB_FRAME_CONTEXT_MAXIMIZE
:
630 client
->frame
->max_hover
= FALSE
;
631 frame_adjust_state(client
->frame
);
633 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
634 client
->frame
->desk_hover
= FALSE
;
635 frame_adjust_state(client
->frame
);
637 case OB_FRAME_CONTEXT_SHADE
:
638 client
->frame
->shade_hover
= FALSE
;
639 frame_adjust_state(client
->frame
);
641 case OB_FRAME_CONTEXT_ICONIFY
:
642 client
->frame
->iconify_hover
= FALSE
;
643 frame_adjust_state(client
->frame
);
645 case OB_FRAME_CONTEXT_CLOSE
:
646 client
->frame
->close_hover
= FALSE
;
647 frame_adjust_state(client
->frame
);
649 case OB_FRAME_CONTEXT_FRAME
:
650 /* XXX if doing a 'reconfigure' make sure you kill this timer,
651 maybe all timers.. */
652 if (config_focus_delay
&& client
== focus_delay_client
) {
653 ob_main_loop_timeout_remove_data(ob_main_loop
,
656 focus_delay_client
= NULL
;
663 con
= frame_context(client
, e
->xcrossing
.window
);
665 case OB_FRAME_CONTEXT_MAXIMIZE
:
666 client
->frame
->max_hover
= TRUE
;
667 frame_adjust_state(client
->frame
);
669 case OB_FRAME_CONTEXT_ALLDESKTOPS
:
670 client
->frame
->desk_hover
= TRUE
;
671 frame_adjust_state(client
->frame
);
673 case OB_FRAME_CONTEXT_SHADE
:
674 client
->frame
->shade_hover
= TRUE
;
675 frame_adjust_state(client
->frame
);
677 case OB_FRAME_CONTEXT_ICONIFY
:
678 client
->frame
->iconify_hover
= TRUE
;
679 frame_adjust_state(client
->frame
);
681 case OB_FRAME_CONTEXT_CLOSE
:
682 client
->frame
->close_hover
= TRUE
;
683 frame_adjust_state(client
->frame
);
685 case OB_FRAME_CONTEXT_FRAME
:
686 if (client_normal(client
)) {
687 if (ob_state() == OB_STATE_STARTING
) {
688 /* move it to the top of the focus order */
689 guint desktop
= client
->desktop
;
690 if (desktop
== DESKTOP_ALL
) desktop
= screen_desktop
;
691 focus_order
[desktop
] = g_list_remove(focus_order
[desktop
],
693 focus_order
[desktop
] = g_list_prepend(focus_order
[desktop
],
695 } else if (config_focus_follow
) {
697 ob_debug("EnterNotify on %lx, focusing window\n",
700 if (config_focus_delay
) {
701 ob_main_loop_timeout_add(ob_main_loop
,
705 focus_delay_client
= client
;
707 client_focus(client
);
715 case ConfigureRequest
:
717 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
718 ConfigureRequest
, &ce
)) {
720 /* XXX if this causes bad things.. we can compress config req's
721 with the same mask. */
722 e
->xconfigurerequest
.value_mask
|=
723 ce
.xconfigurerequest
.value_mask
;
724 if (ce
.xconfigurerequest
.value_mask
& CWX
)
725 e
->xconfigurerequest
.x
= ce
.xconfigurerequest
.x
;
726 if (ce
.xconfigurerequest
.value_mask
& CWY
)
727 e
->xconfigurerequest
.y
= ce
.xconfigurerequest
.y
;
728 if (ce
.xconfigurerequest
.value_mask
& CWWidth
)
729 e
->xconfigurerequest
.width
= ce
.xconfigurerequest
.width
;
730 if (ce
.xconfigurerequest
.value_mask
& CWHeight
)
731 e
->xconfigurerequest
.height
= ce
.xconfigurerequest
.height
;
732 if (ce
.xconfigurerequest
.value_mask
& CWBorderWidth
)
733 e
->xconfigurerequest
.border_width
=
734 ce
.xconfigurerequest
.border_width
;
735 if (ce
.xconfigurerequest
.value_mask
& CWStackMode
)
736 e
->xconfigurerequest
.detail
= ce
.xconfigurerequest
.detail
;
739 /* if we are iconic (or shaded (fvwm does this)) ignore the event */
740 if (client
->iconic
|| client
->shaded
) return;
742 /* resize, then move, as specified in the EWMH section 7.7 */
743 if (e
->xconfigurerequest
.value_mask
& (CWWidth
| CWHeight
|
749 if (e
->xconfigurerequest
.value_mask
& CWBorderWidth
)
750 client
->border_width
= e
->xconfigurerequest
.border_width
;
752 x
= (e
->xconfigurerequest
.value_mask
& CWX
) ?
753 e
->xconfigurerequest
.x
: client
->area
.x
;
754 y
= (e
->xconfigurerequest
.value_mask
& CWY
) ?
755 e
->xconfigurerequest
.y
: client
->area
.y
;
756 w
= (e
->xconfigurerequest
.value_mask
& CWWidth
) ?
757 e
->xconfigurerequest
.width
: client
->area
.width
;
758 h
= (e
->xconfigurerequest
.value_mask
& CWHeight
) ?
759 e
->xconfigurerequest
.height
: client
->area
.height
;
765 client
->frame
->size
.left
+ client
->frame
->size
.right
;
767 client
->frame
->size
.top
+ client
->frame
->size
.bottom
;
768 client_find_onscreen(client
, &newx
, &newy
, fw
, fh
,
769 client_normal(client
));
770 if (e
->xconfigurerequest
.value_mask
& CWX
)
772 if (e
->xconfigurerequest
.value_mask
& CWY
)
776 switch (client
->gravity
) {
777 case NorthEastGravity
:
779 corner
= OB_CORNER_TOPRIGHT
;
781 case SouthWestGravity
:
783 corner
= OB_CORNER_BOTTOMLEFT
;
785 case SouthEastGravity
:
786 corner
= OB_CORNER_BOTTOMRIGHT
;
788 default: /* NorthWest, Static, etc */
789 corner
= OB_CORNER_TOPLEFT
;
792 client_configure_full(client
, corner
, x
, y
, w
, h
, FALSE
, TRUE
,
796 if (e
->xconfigurerequest
.value_mask
& CWStackMode
) {
797 switch (e
->xconfigurerequest
.detail
) {
800 stacking_lower(CLIENT_AS_WINDOW(client
));
806 stacking_raise(CLIENT_AS_WINDOW(client
));
812 if (client
->ignore_unmaps
) {
813 client
->ignore_unmaps
--;
816 client_unmanage(client
);
819 client_unmanage(client
);
822 /* this is when the client is first taken captive in the frame */
823 if (e
->xreparent
.parent
== client
->frame
->plate
) break;
826 This event is quite rare and is usually handled in unmapHandler.
827 However, if the window is unmapped when the reparent event occurs,
828 the window manager never sees it because an unmap event is not sent
829 to an already unmapped window.
832 /* we don't want the reparent event, put it back on the stack for the
833 X server to deal with after we unmanage the window */
834 XPutBackEvent(ob_display
, e
);
836 client_unmanage(client
);
839 ob_debug("MapRequest for 0x%lx\n", client
->window
);
840 if (!client
->iconic
) break; /* this normally doesn't happen, but if it
841 does, we don't want it! */
842 if (screen_showing_desktop
)
843 screen_show_desktop(FALSE
);
844 client_iconify(client
, FALSE
, TRUE
);
845 if (!client
->frame
->visible
)
846 /* if its not visible still, then don't mess with it */
849 client_shade(client
, FALSE
);
850 client_focus(client
);
851 stacking_raise(CLIENT_AS_WINDOW(client
));
854 /* validate cuz we query stuff off the client here */
855 if (!client_validate(client
)) break;
857 if (e
->xclient
.format
!= 32) return;
859 msgtype
= e
->xclient
.message_type
;
860 if (msgtype
== prop_atoms
.wm_change_state
) {
861 /* compress changes into a single change */
862 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
864 /* XXX: it would be nice to compress ALL messages of a
865 type, not just messages in a row without other
866 message types between. */
867 if (ce
.xclient
.message_type
!= msgtype
) {
868 XPutBackEvent(ob_display
, &ce
);
871 e
->xclient
= ce
.xclient
;
873 client_set_wm_state(client
, e
->xclient
.data
.l
[0]);
874 } else if (msgtype
== prop_atoms
.net_wm_desktop
) {
875 /* compress changes into a single change */
876 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
878 /* XXX: it would be nice to compress ALL messages of a
879 type, not just messages in a row without other
880 message types between. */
881 if (ce
.xclient
.message_type
!= msgtype
) {
882 XPutBackEvent(ob_display
, &ce
);
885 e
->xclient
= ce
.xclient
;
887 if ((unsigned)e
->xclient
.data
.l
[0] < screen_num_desktops
||
888 (unsigned)e
->xclient
.data
.l
[0] == DESKTOP_ALL
)
889 client_set_desktop(client
, (unsigned)e
->xclient
.data
.l
[0],
891 } else if (msgtype
== prop_atoms
.net_wm_state
) {
892 /* can't compress these */
893 ob_debug("net_wm_state %s %ld %ld for 0x%lx\n",
894 (e
->xclient
.data
.l
[0] == 0 ? "Remove" :
895 e
->xclient
.data
.l
[0] == 1 ? "Add" :
896 e
->xclient
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
897 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2],
899 client_set_state(client
, e
->xclient
.data
.l
[0],
900 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[2]);
901 } else if (msgtype
== prop_atoms
.net_close_window
) {
902 ob_debug("net_close_window for 0x%lx\n", client
->window
);
903 client_close(client
);
904 } else if (msgtype
== prop_atoms
.net_active_window
) {
905 ob_debug("net_active_window for 0x%lx\n", client
->window
);
906 client_activate(client
, FALSE
);
907 } else if (msgtype
== prop_atoms
.net_wm_moveresize
) {
908 ob_debug("net_wm_moveresize for 0x%lx\n", client
->window
);
909 if ((Atom
)e
->xclient
.data
.l
[2] ==
910 prop_atoms
.net_wm_moveresize_size_topleft
||
911 (Atom
)e
->xclient
.data
.l
[2] ==
912 prop_atoms
.net_wm_moveresize_size_top
||
913 (Atom
)e
->xclient
.data
.l
[2] ==
914 prop_atoms
.net_wm_moveresize_size_topright
||
915 (Atom
)e
->xclient
.data
.l
[2] ==
916 prop_atoms
.net_wm_moveresize_size_right
||
917 (Atom
)e
->xclient
.data
.l
[2] ==
918 prop_atoms
.net_wm_moveresize_size_right
||
919 (Atom
)e
->xclient
.data
.l
[2] ==
920 prop_atoms
.net_wm_moveresize_size_bottomright
||
921 (Atom
)e
->xclient
.data
.l
[2] ==
922 prop_atoms
.net_wm_moveresize_size_bottom
||
923 (Atom
)e
->xclient
.data
.l
[2] ==
924 prop_atoms
.net_wm_moveresize_size_bottomleft
||
925 (Atom
)e
->xclient
.data
.l
[2] ==
926 prop_atoms
.net_wm_moveresize_size_left
||
927 (Atom
)e
->xclient
.data
.l
[2] ==
928 prop_atoms
.net_wm_moveresize_move
||
929 (Atom
)e
->xclient
.data
.l
[2] ==
930 prop_atoms
.net_wm_moveresize_size_keyboard
||
931 (Atom
)e
->xclient
.data
.l
[2] ==
932 prop_atoms
.net_wm_moveresize_move_keyboard
) {
934 moveresize_start(client
, e
->xclient
.data
.l
[0],
935 e
->xclient
.data
.l
[1], e
->xclient
.data
.l
[3],
936 e
->xclient
.data
.l
[2]);
938 } else if (msgtype
== prop_atoms
.net_moveresize_window
) {
939 int oldg
= client
->gravity
;
940 int tmpg
, x
, y
, w
, h
;
942 if (e
->xclient
.data
.l
[0] & 0xff)
943 tmpg
= e
->xclient
.data
.l
[0] & 0xff;
947 if (e
->xclient
.data
.l
[0] & 1 << 8)
948 x
= e
->xclient
.data
.l
[1];
951 if (e
->xclient
.data
.l
[0] & 1 << 9)
952 y
= e
->xclient
.data
.l
[2];
955 if (e
->xclient
.data
.l
[0] & 1 << 10)
956 w
= e
->xclient
.data
.l
[3];
958 w
= client
->area
.width
;
959 if (e
->xclient
.data
.l
[0] & 1 << 11)
960 h
= e
->xclient
.data
.l
[4];
962 h
= client
->area
.height
;
963 client
->gravity
= tmpg
;
969 client
->frame
->size
.left
+ client
->frame
->size
.right
;
971 client
->frame
->size
.top
+ client
->frame
->size
.bottom
;
972 client_find_onscreen(client
, &newx
, &newy
, fw
, fh
,
973 client_normal(client
));
974 if (e
->xclient
.data
.l
[0] & 1 << 8)
976 if (e
->xclient
.data
.l
[0] & 1 << 9)
980 client_configure(client
, OB_CORNER_TOPLEFT
,
981 x
, y
, w
, h
, FALSE
, TRUE
);
983 client
->gravity
= oldg
;
987 /* validate cuz we query stuff off the client here */
988 if (!client_validate(client
)) break;
990 /* compress changes to a single property into a single change */
991 while (XCheckTypedWindowEvent(ob_display
, client
->window
,
995 /* XXX: it would be nice to compress ALL changes to a property,
996 not just changes in a row without other props between. */
998 a
= ce
.xproperty
.atom
;
999 b
= e
->xproperty
.atom
;
1003 if ((a
== prop_atoms
.net_wm_name
||
1004 a
== prop_atoms
.wm_name
||
1005 a
== prop_atoms
.net_wm_icon_name
||
1006 a
== prop_atoms
.wm_icon_name
)
1008 (b
== prop_atoms
.net_wm_name
||
1009 b
== prop_atoms
.wm_name
||
1010 b
== prop_atoms
.net_wm_icon_name
||
1011 b
== prop_atoms
.wm_icon_name
)) {
1014 if ((a
== prop_atoms
.net_wm_icon
||
1015 a
== prop_atoms
.kwm_win_icon
)
1017 (b
== prop_atoms
.net_wm_icon
||
1018 b
== prop_atoms
.kwm_win_icon
))
1021 XPutBackEvent(ob_display
, &ce
);
1025 msgtype
= e
->xproperty
.atom
;
1026 if (msgtype
== XA_WM_NORMAL_HINTS
) {
1027 client_update_normal_hints(client
);
1028 /* normal hints can make a window non-resizable */
1029 client_setup_decor_and_functions(client
);
1030 } else if (msgtype
== XA_WM_HINTS
) {
1031 client_update_wmhints(client
);
1032 } else if (msgtype
== XA_WM_TRANSIENT_FOR
) {
1033 client_update_transient_for(client
);
1034 client_get_type(client
);
1035 /* type may have changed, so update the layer */
1036 client_calc_layer(client
);
1037 client_setup_decor_and_functions(client
);
1038 } else if (msgtype
== prop_atoms
.net_wm_name
||
1039 msgtype
== prop_atoms
.wm_name
||
1040 msgtype
== prop_atoms
.net_wm_icon_name
||
1041 msgtype
== prop_atoms
.wm_icon_name
) {
1042 client_update_title(client
);
1043 } else if (msgtype
== prop_atoms
.wm_class
) {
1044 client_update_class(client
);
1045 } else if (msgtype
== prop_atoms
.wm_protocols
) {
1046 client_update_protocols(client
);
1047 client_setup_decor_and_functions(client
);
1049 else if (msgtype
== prop_atoms
.net_wm_strut
) {
1050 client_update_strut(client
);
1052 else if (msgtype
== prop_atoms
.net_wm_icon
||
1053 msgtype
== prop_atoms
.kwm_win_icon
) {
1054 client_update_icons(client
);
1059 if (extensions_shape
&& e
->type
== extensions_shape_event_basep
) {
1060 client
->shaped
= ((XShapeEvent
*)e
)->shaped
;
1061 frame_adjust_shape(client
->frame
);
1067 static void event_handle_dock(ObDock
*s
, XEvent
*e
)
1071 stacking_raise(DOCK_AS_WINDOW(s
));
1082 static void event_handle_dockapp(ObDockApp
*app
, XEvent
*e
)
1086 dock_app_drag(app
, &e
->xmotion
);
1089 if (app
->ignore_unmaps
) {
1090 app
->ignore_unmaps
--;
1093 dock_remove(app
, TRUE
);
1096 dock_remove(app
, FALSE
);
1098 case ReparentNotify
:
1099 dock_remove(app
, FALSE
);
1101 case ConfigureNotify
:
1102 dock_app_configure(app
, e
->xconfigure
.width
, e
->xconfigure
.height
);
1107 ObMenuFrame
* find_active_menu()
1112 for (it
= menu_frame_visible
; it
; it
= g_list_next(it
)) {
1117 return it
? it
->data
: NULL
;
1120 static void event_handle_menu(XEvent
*ev
)
1123 ObMenuEntryFrame
*e
;
1127 if (!(f
= menu_frame_under(ev
->xbutton
.x_root
,
1128 ev
->xbutton
.y_root
)))
1129 menu_frame_hide_all();
1131 if ((e
= menu_entry_frame_under(ev
->xbutton
.x_root
,
1132 ev
->xbutton
.y_root
)))
1133 menu_entry_frame_execute(e
, ev
->xbutton
.state
);
1137 if ((f
= menu_frame_under(ev
->xmotion
.x_root
,
1138 ev
->xmotion
.y_root
))) {
1139 menu_frame_move_on_screen(f
);
1140 if ((e
= menu_entry_frame_under(ev
->xmotion
.x_root
,
1141 ev
->xmotion
.y_root
)))
1142 menu_frame_select(f
, e
);
1146 if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_ESCAPE
))
1147 menu_frame_hide_all();
1148 else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_RETURN
)) {
1150 if ((f
= find_active_menu()))
1151 menu_entry_frame_execute(f
->selected
, ev
->xkey
.state
);
1152 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_LEFT
)) {
1154 if ((f
= find_active_menu()) && f
->parent
)
1155 menu_frame_select(f
, NULL
);
1156 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_RIGHT
)) {
1158 if ((f
= find_active_menu()) && f
->child
)
1159 menu_frame_select_next(f
->child
);
1160 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_UP
)) {
1162 if ((f
= find_active_menu()))
1163 menu_frame_select_previous(f
);
1164 } else if (ev
->xkey
.keycode
== ob_keycode(OB_KEY_DOWN
)) {
1166 if ((f
= find_active_menu()))
1167 menu_frame_select_next(f
);
1173 static gboolean
focus_delay_func(gpointer data
)
1175 client_focus(focus_delay_client
);
1176 return FALSE
; /* no repeat */
1179 static void focus_delay_client_dest(gpointer data
)
1182 if (c
== focus_delay_client
) {
1183 ob_main_loop_timeout_remove_data(ob_main_loop
, focus_delay_func
,
1184 focus_delay_client
);
1185 focus_delay_client
= NULL
;