1 /* event.c- event loop and handling
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
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 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <sys/select.h>
26 #include <sys/inotify.h>
37 #include <X11/Xutil.h>
39 # include <X11/extensions/shape.h>
46 #include <X11/extensions/Xrandr.h>
49 #ifdef KEEP_XKB_LOCK_STATUS
50 #include <X11/XKBlib.h>
51 #endif /* KEEP_XKB_LOCK_STATUS */
53 #include "WindowMaker.h"
59 #include "application.h"
62 #include "workspace.h"
65 #include "properties.h"
70 /******** Global Variables **********/
71 extern XContext wWinContext
;
72 extern XContext wVEdgeContext
;
74 extern Cursor wCursor
[WCUR_LAST
];
76 extern WShortKey wKeyBindings
[WKBD_LAST
];
77 extern int wScreenCount
;
78 extern Time LastTimestamp
;
79 extern Time LastFocusChange
;
81 extern WPreferences wPreferences
;
83 #define MOD_MASK wPreferences.modifier_mask
85 extern Atom _XA_WM_COLORMAP_NOTIFY
;
87 extern Atom _XA_WM_CHANGE_STATE
;
88 extern Atom _XA_WM_DELETE_WINDOW
;
89 extern Atom _XA_GNUSTEP_WM_ATTR
;
90 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
91 extern Atom _XA_GNUSTEP_TITLEBAR_STATE
;
92 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
93 extern Atom _XA_WINDOWMAKER_COMMAND
;
94 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS
;
97 extern Bool wShapeSupported
;
98 extern int wShapeEventBase
;
101 #ifdef KEEP_XKB_LOCK_STATUS
102 extern int wXkbEventBase
;
106 extern Bool has_randr
;
107 extern int randr_event_base
;
111 /*extern char WDelayedActionSet;*/
113 /************ Local stuff ***********/
115 static void saveTimestamp(XEvent
*event
);
116 static void handleColormapNotify(XEvent
*event
);
117 static void handleMapNotify(XEvent
*event
);
118 static void handleUnmapNotify(XEvent
*event
);
119 static void handleButtonPress(XEvent
*event
);
120 static void handleExpose(XEvent
*event
);
121 static void handleDestroyNotify(XEvent
*event
);
122 static void handleConfigureRequest(XEvent
*event
);
123 static void handleMapRequest(XEvent
*event
);
124 static void handlePropertyNotify(XEvent
*event
);
125 static void handleEnterNotify(XEvent
*event
);
126 static void handleLeaveNotify(XEvent
*event
);
127 static void handleExtensions(XEvent
*event
);
128 static void handleClientMessage(XEvent
*event
);
129 static void handleKeyPress(XEvent
*event
);
130 static void handleFocusIn(XEvent
*event
);
131 static void handleMotionNotify(XEvent
*event
);
132 static void handleVisibilityNotify(XEvent
*event
);
133 static void handle_inotify_events(int fd
, int wd
);
134 static void wdelete_death_handler(WMagicNumber id
);
138 static void handleShapeNotify(XEvent
*event
);
141 #ifdef KEEP_XKB_LOCK_STATUS
142 static void handleXkbIndicatorStateNotify(XEvent
*event
);
145 /* called from the signal handler */
146 void NotifyDeadProcess(pid_t pid
, unsigned char status
);
148 /* real dead process handler */
149 static void handleDeadProcess(void *foo
);
151 typedef struct DeadProcesses
{
153 unsigned char exit_status
;
156 /* stack of dead processes */
157 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
158 static int deadProcessPtr
= 0;
160 typedef struct DeathHandler
{
161 WDeathHandler
*callback
;
166 static WMArray
*deathHandlers
= NULL
;
168 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
170 DeathHandler
*handler
;
172 handler
= malloc(sizeof(DeathHandler
));
177 handler
->callback
= callback
;
178 handler
->client_data
= cdata
;
181 deathHandlers
= WMCreateArrayWithDestructor(8, wfree
);
183 WMAddToArray(deathHandlers
, handler
);
188 static void wdelete_death_handler(WMagicNumber id
)
190 DeathHandler
*handler
= (DeathHandler
*) id
;
192 if (!handler
|| !deathHandlers
)
195 /* array destructor will call wfree(handler) */
196 WMRemoveFromArray(deathHandlers
, handler
);
199 void DispatchEvent(XEvent
* event
)
202 handleDeadProcess(NULL
);
204 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
205 WCHANGE_STATE(WSTATE_EXITING
);
206 /* received SIGTERM */
208 * WMHandleEvent() can't be called from anything
209 * executed inside here, or we can get in a infinite
212 Shutdown(WSExitMode
);
214 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
215 WCHANGE_STATE(WSTATE_RESTARTING
);
217 Shutdown(WSRestartPreparationMode
);
218 /* received SIGHUP */
220 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
221 WCHANGE_STATE(WSTATE_NORMAL
);
222 wDefaultsCheckDomains(NULL
);
225 /* for the case that all that is wanted to be dispatched is
230 saveTimestamp(event
);
231 switch (event
->type
) {
233 handleMapRequest(event
);
237 handleKeyPress(event
);
241 handleMotionNotify(event
);
244 case ConfigureRequest
:
245 handleConfigureRequest(event
);
249 handleDestroyNotify(event
);
253 handleMapNotify(event
);
257 handleUnmapNotify(event
);
261 handleButtonPress(event
);
269 handlePropertyNotify(event
);
273 handleEnterNotify(event
);
277 handleLeaveNotify(event
);
281 handleClientMessage(event
);
285 handleColormapNotify(event
);
289 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
290 XRefreshKeyboardMapping(&event
->xmapping
);
294 handleFocusIn(event
);
297 case VisibilityNotify
:
298 handleVisibilityNotify(event
);
301 case ConfigureNotify
:
302 if (event
->xconfigure
.window
== DefaultRootWindow(dpy
)) {
304 XRRUpdateConfiguration(event
);
310 handleExtensions(event
);
317 *----------------------------------------------------------------------
318 * handle_inotify_events-
319 * Check for inotify events
322 * After reading events for the given file descriptor (fd) and
323 * watch descriptor (wd)
326 * Calls wDefaultsCheckDomains if config database is updated
327 *----------------------------------------------------------------------
329 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
330 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
331 static void handle_inotify_events(int fd
, int wd
)
333 extern void wDefaultsCheckDomains(void *);
334 ssize_t eventQLength
, i
= 0;
335 char buff
[BUFF_SIZE
] = { 0 };
336 /* Check config only once per read of the event queue */
340 * Read off the queued events
341 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
342 * not occur; the block is on Xevents, but a config file change will normally
343 * occur as a result of an Xevent - so the event queue should never have more than
344 * a few entries before a read().
346 eventQLength
= read(fd
, buff
, BUFF_SIZE
);
348 /* check what events occured */
349 /* Should really check wd here too, but for now we only have one watch! */
350 while (i
< eventQLength
) {
351 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
354 * see inotify.h for event types.
356 if (pevent
->mask
& IN_DELETE_SELF
) {
357 wwarning(_("the defaults database has been deleted!"
358 " Restart Window Maker to create the database" " with the default settings"));
361 if (pevent
->mask
& IN_UNMOUNT
) {
362 wwarning(_("the unit containing the defaults database has"
363 " been unmounted. Setting --static mode." " Any changes will not be saved."));
365 wPreferences
.flags
.noupdates
= 1;
367 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
368 wwarning(_("Inotify: Reading config files in defaults database."));
369 wDefaultsCheckDomains(NULL
);
372 /* move to next event in the buffer */
373 i
+= sizeof(struct inotify_event
) + pevent
->len
;
376 #endif /* HAVE_INOTIFY */
379 *----------------------------------------------------------------------
381 * Processes X and internal events indefinitely.
387 * The LastTimestamp global variable is updated.
388 * Calls inotifyGetEvents if defaults database changes.
389 *----------------------------------------------------------------------
395 extern int inotifyFD
;
396 extern int inotifyWD
;
401 if (inotifyFD
< 0 || inotifyWD
< 0)
407 WMNextEvent(dpy
, &event
); /* Blocks here */
408 WMHandleEvent(&event
);
414 FD_SET(inotifyFD
, &rfds
);
416 /* check for available read data from inotify - don't block! */
417 retVal
= select(inotifyFD
+ 1, &rfds
, NULL
, NULL
, &time
);
419 if (retVal
< 0) { /* an error has occured */
420 wwarning(_("select failed. The inotify instance will be closed."
421 " Changes to the defaults database will require"
422 " a restart to take effect."));
426 if (FD_ISSET(inotifyFD
, &rfds
))
427 handle_inotify_events(inotifyFD
, inotifyWD
);
434 *----------------------------------------------------------------------
435 * ProcessPendingEvents --
436 * Processes the events that are currently pending (at the time
437 * this function is called) in the display's queue.
440 * After the pending events that were present at the function call
444 * Many -- whatever handling events may involve.
446 *----------------------------------------------------------------------
448 void ProcessPendingEvents(void)
455 /* Take a snapshot of the event count in the queue */
456 count
= XPending(dpy
);
458 while (count
> 0 && XPending(dpy
)) {
459 WMNextEvent(dpy
, &event
);
460 WMHandleEvent(&event
);
465 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
467 if ((scr
->last_click_time
> 0) &&
468 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
469 && (event
->xbutton
.button
== scr
->last_click_button
)
470 && (event
->xbutton
.window
== scr
->last_click_window
)) {
472 scr
->flags
.next_click_is_not_double
= 1;
473 scr
->last_click_time
= 0;
474 scr
->last_click_window
= event
->xbutton
.window
;
481 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
483 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
484 wwarning("stack overflow: too many dead processes");
487 /* stack the process to be handled later,
488 * as this is called from the signal handler */
489 deadProcesses
[deadProcessPtr
].pid
= pid
;
490 deadProcesses
[deadProcessPtr
].exit_status
= status
;
494 static void handleDeadProcess(void *foo
)
499 for (i
= 0; i
< deadProcessPtr
; i
++) {
500 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
503 if (!deathHandlers
) {
508 /* get the pids on the queue and call handlers */
509 while (deadProcessPtr
> 0) {
512 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
513 tmp
= WMGetFromArray(deathHandlers
, i
);
517 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
518 (*tmp
->callback
) (tmp
->pid
,
519 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
520 wdelete_death_handler(tmp
);
526 static void saveTimestamp(XEvent
* event
)
529 * Never save CurrentTime as LastTimestamp because CurrentTime
530 * it's not a real timestamp (it's the 0L constant)
533 switch (event
->type
) {
536 LastTimestamp
= event
->xbutton
.time
;
540 LastTimestamp
= event
->xkey
.time
;
543 LastTimestamp
= event
->xmotion
.time
;
546 LastTimestamp
= event
->xproperty
.time
;
550 LastTimestamp
= event
->xcrossing
.time
;
553 LastTimestamp
= event
->xselectionclear
.time
;
555 case SelectionRequest
:
556 LastTimestamp
= event
->xselectionrequest
.time
;
558 case SelectionNotify
:
559 LastTimestamp
= event
->xselection
.time
;
561 wXDNDProcessSelection(event
);
567 static int matchWindow(const void *item
, const void *cdata
)
569 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
572 static void handleExtensions(XEvent
* event
)
574 #ifdef KEEP_XKB_LOCK_STATUS
576 xkbevent
= (XkbEvent
*) event
;
577 #endif /*KEEP_XKB_LOCK_STATUS */
579 if (wShapeSupported
&& event
->type
== (wShapeEventBase
+ ShapeNotify
)) {
580 handleShapeNotify(event
);
583 #ifdef KEEP_XKB_LOCK_STATUS
584 if (wPreferences
.modelock
&& (xkbevent
->type
== wXkbEventBase
)) {
585 handleXkbIndicatorStateNotify(event
);
587 #endif /*KEEP_XKB_LOCK_STATUS */
589 if (has_randr
&& event
->type
== (randr_event_base
+ RRScreenChangeNotify
)) {
590 /* From xrandr man page: "Clients must call back into Xlib using
591 * XRRUpdateConfiguration when screen configuration change notify
592 * events are generated */
593 XRRUpdateConfiguration(event
);
594 WCHANGE_STATE(WSTATE_RESTARTING
);
595 Shutdown(WSRestartPreparationMode
);
601 static void handleMapRequest(XEvent
* ev
)
605 Window window
= ev
->xmaprequest
.window
;
607 if ((wwin
= wWindowFor(window
))) {
608 if (wwin
->flags
.shaded
) {
609 wUnshadeWindow(wwin
);
611 /* deiconify window */
612 if (wwin
->flags
.miniaturized
) {
613 wDeiconifyWindow(wwin
);
614 } else if (wwin
->flags
.hidden
) {
615 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
616 /* go to the last workspace that the user worked on the app */
618 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
620 wUnhideApplication(wapp
, False
, False
);
625 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
627 wwin
= wManageWindow(scr
, window
);
630 * This is to let the Dock know that the application it launched
631 * has already been mapped (eg: it has finished launching).
632 * It is not necessary for normally docked apps, but is needed for
633 * apps that were forcedly docked (like with dockit).
635 if (scr
->last_dock
) {
636 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
637 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
639 wDockTrackWindowLaunch(scr
->last_dock
, window
);
643 wClientSetState(wwin
, NormalState
, None
);
644 if (wwin
->flags
.maximized
) {
645 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
647 if (wwin
->flags
.shaded
) {
648 wwin
->flags
.shaded
= 0;
649 wwin
->flags
.skip_next_animation
= 1;
652 if (wwin
->flags
.miniaturized
) {
653 wwin
->flags
.miniaturized
= 0;
654 wwin
->flags
.skip_next_animation
= 1;
655 wIconifyWindow(wwin
);
657 if (wwin
->flags
.fullscreen
) {
658 wwin
->flags
.fullscreen
= 0;
659 wFullscreenWindow(wwin
);
661 if (wwin
->flags
.hidden
) {
662 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
664 wwin
->flags
.hidden
= 0;
665 wwin
->flags
.skip_next_animation
= 1;
667 wHideApplication(wapp
);
673 static void handleDestroyNotify(XEvent
* event
)
677 Window window
= event
->xdestroywindow
.window
;
678 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
681 wwin
= wWindowFor(window
);
683 wUnmanageWindow(wwin
, False
, True
);
687 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
688 WFakeGroupLeader
*fPtr
;
690 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
691 if (fPtr
->retainCount
> 0) {
693 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
694 XDestroyWindow(dpy
, fPtr
->leader
);
699 fPtr
->origLeader
= None
;
703 app
= wApplicationOf(window
);
705 if (window
== app
->main_window
) {
707 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
709 if (wwin
->main_window
== window
) {
710 wwin
->main_window
= None
;
715 wApplicationDestroy(app
);
719 static void handleExpose(XEvent
* event
)
721 WObjDescriptor
*desc
;
724 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
726 if (XFindContext(dpy
, event
->xexpose
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
730 if (desc
->handle_expose
) {
731 (*desc
->handle_expose
) (desc
, event
);
735 static void executeButtonAction(WScreen
* scr
, XEvent
* event
, int action
)
738 case WA_SELECT_WINDOWS
:
739 wUnselectWindows(scr
);
740 wSelectWindows(scr
, event
);
742 case WA_OPEN_APPMENU
:
743 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
745 if (scr
->root_menu
) {
746 if (scr
->root_menu
->brother
->flags
.mapped
)
747 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
749 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
752 case WA_OPEN_WINLISTMENU
:
753 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
754 if (scr
->switch_menu
) {
755 if (scr
->switch_menu
->brother
->flags
.mapped
)
756 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
758 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
767 static void handleButtonPress(XEvent
* event
)
769 WObjDescriptor
*desc
;
772 scr
= wScreenForRootWindow(event
->xbutton
.root
);
778 if (event
->xbutton
.window
== scr
->root_win
) {
779 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
780 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
781 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
782 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
783 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
784 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
785 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
786 wWorkspaceRelativeChange(scr
, 1);
787 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
788 wWorkspaceRelativeChange(scr
, -1);
793 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
794 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
799 if (desc
->parent_type
== WCLASS_WINDOW
) {
802 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
803 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
805 /* if (wPreferences.focus_mode == WKF_CLICK) { */
806 if (wPreferences
.ignore_focus_click
) {
807 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
809 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
813 } else if (desc
->parent_type
== WCLASS_APPICON
814 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
815 if (event
->xbutton
.state
& MOD_MASK
) {
817 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
822 if (desc
->handle_mousedown
!= NULL
) {
823 (*desc
->handle_mousedown
) (desc
, event
);
826 /* save double-click information */
827 if (scr
->flags
.next_click_is_not_double
) {
828 scr
->flags
.next_click_is_not_double
= 0;
830 scr
->last_click_time
= event
->xbutton
.time
;
831 scr
->last_click_button
= event
->xbutton
.button
;
832 scr
->last_click_window
= event
->xbutton
.window
;
836 static void handleMapNotify(XEvent
* event
)
840 wwin
= wWindowFor(event
->xmap
.event
);
841 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
842 if (wwin
->flags
.miniaturized
) {
843 wDeiconifyWindow(wwin
);
847 wClientSetState(wwin
, NormalState
, None
);
853 static void handleUnmapNotify(XEvent
* event
)
857 Bool withdraw
= False
;
859 /* only process windows with StructureNotify selected
860 * (ignore SubstructureNotify) */
861 wwin
= wWindowFor(event
->xunmap
.window
);
865 /* whether the event is a Withdrawal request */
866 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
869 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
872 if (!wwin
->flags
.mapped
&& !withdraw
873 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
874 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
878 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
879 wwin
->flags
.mapped
= 0;
881 /* check if the window was destroyed */
882 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
885 Bool reparented
= False
;
887 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
890 /* withdraw window */
891 wwin
->flags
.mapped
= 0;
893 wClientSetState(wwin
, WithdrawnState
, None
);
895 /* if the window was reparented, do not reparent it back to the
897 wUnmanageWindow(wwin
, !reparented
, False
);
902 static void handleConfigureRequest(XEvent
* event
)
906 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
908 * Configure request for unmapped window
910 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
912 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
916 static void handlePropertyNotify(XEvent
* event
)
924 wwin
= wWindowFor(event
->xproperty
.window
);
926 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
929 wClientCheckProperty(wwin
, &event
->xproperty
);
931 wapp
= wApplicationOf(event
->xproperty
.window
);
933 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
937 static void handleClientMessage(XEvent
* event
)
940 WObjDescriptor
*desc
;
942 /* handle transition from Normal to Iconic state */
943 if (event
->xclient
.message_type
== _XA_WM_CHANGE_STATE
944 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
946 wwin
= wWindowFor(event
->xclient
.window
);
949 if (!wwin
->flags
.miniaturized
)
950 wIconifyWindow(wwin
);
951 } else if (event
->xclient
.message_type
== _XA_WM_COLORMAP_NOTIFY
&& event
->xclient
.format
== 32) {
952 WScreen
*scr
= wScreenSearchForRootWindow(event
->xclient
.window
);
957 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
958 wColormapAllowClientInstallation(scr
, True
);
959 } else { /* stopping */
960 wColormapAllowClientInstallation(scr
, False
);
962 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_COMMAND
) {
967 len
= sizeof(event
->xclient
.data
.b
) + 1;
968 command
= wmalloc(len
);
969 memset(command
, 0, len
);
970 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
972 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
973 wwarning(_("Got Reconfigure command"));
974 wDefaultsCheckDomains(NULL
);
976 wwarning(_("Got unknown command %s"), command
);
981 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
984 wapp
= wApplicationOf(event
->xclient
.window
);
986 switch (event
->xclient
.data
.l
[0]) {
987 case WMFHideOtherApplications
:
988 wHideOtherApplications(wapp
->main_window_desc
);
992 case WMFHideApplication
:
993 wHideApplication(wapp
);
999 wwin
= wWindowFor(event
->xclient
.window
);
1001 switch (event
->xclient
.data
.l
[0]) {
1002 case WMFHideOtherApplications
:
1003 wHideOtherApplications(wwin
);
1006 case WMFHideApplication
:
1007 wHideApplication(wApplicationOf(wwin
->main_window
));
1012 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_WM_ATTR
) {
1013 wwin
= wWindowFor(event
->xclient
.window
);
1016 switch (event
->xclient
.data
.l
[0]) {
1017 case GSWindowLevelAttr
:
1019 int level
= (int)event
->xclient
.data
.l
[1];
1021 if (WINDOW_LEVEL(wwin
) != level
) {
1022 ChangeStackingLevel(wwin
->frame
->core
, level
);
1027 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_TITLEBAR_STATE
) {
1028 wwin
= wWindowFor(event
->xclient
.window
);
1031 switch (event
->xclient
.data
.l
[0]) {
1032 case WMTitleBarNormal
:
1033 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1035 case WMTitleBarMain
:
1036 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1039 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1042 } else if (event
->xclient
.message_type
== _XA_WM_IGNORE_FOCUS_EVENTS
) {
1043 WScreen
*scr
= wScreenSearchForRootWindow(event
->xclient
.window
);
1046 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1047 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1050 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1055 * Non-standard thing, but needed by OffiX DND.
1056 * For when the icon frame gets a ClientMessage
1057 * that should have gone to the icon_window.
1059 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1060 struct WIcon
*icon
= NULL
;
1062 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1063 icon
= (WIcon
*) desc
->parent
;
1064 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1065 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1067 if (icon
&& (wwin
= icon
->owner
)) {
1068 if (wwin
->client_win
!= event
->xclient
.window
) {
1069 event
->xclient
.window
= wwin
->client_win
;
1070 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1077 static void raiseWindow(WScreen
* scr
)
1081 scr
->autoRaiseTimer
= NULL
;
1083 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1087 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1088 wRaiseFrame(wwin
->frame
->core
);
1089 /* this is needed or a race condition will occur */
1094 static void handleEnterNotify(XEvent
* event
)
1097 WObjDescriptor
*desc
= NULL
;
1099 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1101 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1102 /* already left the window... */
1104 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1109 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1110 if (desc
->handle_enternotify
)
1111 (*desc
->handle_enternotify
) (desc
, event
);
1114 /* enter to window */
1115 wwin
= wWindowFor(event
->xcrossing
.window
);
1117 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1118 wColormapInstallForWindow(scr
, NULL
);
1120 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1121 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1122 scr
->autoRaiseTimer
= NULL
;
1125 /* set auto raise timer even if in focus-follows-mouse mode
1126 * and the event is for the frame window, even if the window
1127 * has focus already. useful if you move the pointer from a focused
1128 * window to the root window and back pretty fast
1130 * set focus if in focus-follows-mouse mode and the event
1131 * is for the frame window and window doesn't have focus yet */
1132 if (wPreferences
.focus_mode
== WKF_SLOPPY
1133 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1135 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1136 wSetFocusTo(scr
, wwin
);
1138 if (scr
->autoRaiseTimer
)
1139 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1140 scr
->autoRaiseTimer
= NULL
;
1142 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1143 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1145 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1148 /* Install colormap for window, if the colormap installation mode
1149 * is colormap_follows_mouse */
1150 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1151 if (wwin
->client_win
== event
->xcrossing
.window
)
1152 wColormapInstallForWindow(scr
, wwin
);
1154 wColormapInstallForWindow(scr
, NULL
);
1158 if (event
->xcrossing
.window
== event
->xcrossing
.root
1159 && event
->xcrossing
.detail
== NotifyNormal
1160 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1162 wSetFocusTo(scr
, scr
->focused_window
);
1165 wBalloonEnteredObject(scr
, desc
);
1169 static void handleLeaveNotify(XEvent
* event
)
1171 WObjDescriptor
*desc
= NULL
;
1173 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1174 if (desc
->handle_leavenotify
)
1175 (*desc
->handle_leavenotify
) (desc
, event
);
1180 static void handleShapeNotify(XEvent
* event
)
1182 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1189 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1190 if (ev
.xshape
.kind
== ShapeBounding
) {
1191 if (ev
.xshape
.shaped
== shev
->shaped
) {
1194 XPutBackEvent(dpy
, &ev
.xevent
);
1200 wwin
= wWindowFor(shev
->window
);
1201 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1204 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1206 wwin
->flags
.shaped
= 0;
1207 wWindowClearShape(wwin
);
1209 } else if (shev
->shaped
) {
1211 wwin
->flags
.shaped
= 1;
1212 wWindowSetShape(wwin
);
1217 #ifdef KEEP_XKB_LOCK_STATUS
1218 /* please help ]d if you know what to do */
1219 static void handleXkbIndicatorStateNotify(XEvent
*event
)
1223 XkbStateRec staterec
;
1226 for (i
= 0; i
< wScreenCount
; i
++) {
1227 scr
= wScreenWithNumber(i
);
1228 wwin
= scr
->focused_window
;
1229 if (wwin
&& wwin
->flags
.focused
) {
1230 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1231 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1232 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1233 wwin
->frame
->languagemode
= staterec
.group
;
1235 #ifdef XKB_BUTTON_HINT
1236 if (wwin
->frame
->titlebar
) {
1237 wFrameWindowPaint(wwin
->frame
);
1243 #endif /*KEEP_XKB_LOCK_STATUS */
1245 static void handleColormapNotify(XEvent
* event
)
1249 Bool reinstall
= False
;
1251 wwin
= wWindowFor(event
->xcolormap
.window
);
1255 scr
= wwin
->screen_ptr
;
1259 if (event
->xcolormap
.new) {
1260 XWindowAttributes attr
;
1262 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1264 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1265 scr
->current_colormap
= attr
.colormap
;
1268 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1269 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1271 /* some bastard app (like XV) removed our colormap */
1273 * can't enforce or things like xscreensaver wont work
1276 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1277 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1279 /* someone has put our colormap back */
1283 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1284 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1286 if (reinstall
&& scr
->current_colormap
!= None
) {
1287 if (!scr
->flags
.colormap_stuff_blocked
)
1288 XInstallColormap(dpy
, scr
->current_colormap
);
1292 static void handleFocusIn(XEvent
* event
)
1297 * For applications that like stealing the focus.
1299 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1300 saveTimestamp(event
);
1301 if (event
->xfocus
.mode
== NotifyUngrab
1302 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1306 wwin
= wWindowFor(event
->xfocus
.window
);
1307 if (wwin
&& !wwin
->flags
.focused
) {
1308 if (wwin
->flags
.mapped
)
1309 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1311 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1313 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1315 wSetFocusTo(scr
, NULL
);
1319 static WWindow
*windowUnderPointer(WScreen
* scr
)
1325 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1326 return wWindowFor(win
);
1330 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1332 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1338 static void handleKeyPress(XEvent
* event
)
1340 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1341 WWindow
*wwin
= scr
->focused_window
;
1345 #ifdef KEEP_XKB_LOCK_STATUS
1346 XkbStateRec staterec
;
1347 #endif /*KEEP_XKB_LOCK_STATUS */
1349 /* ignore CapsLock */
1350 modifiers
= event
->xkey
.state
& ValidModMask
;
1352 for (i
= 0; i
< WKBD_LAST
; i
++) {
1353 if (wKeyBindings
[i
].keycode
== 0)
1356 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1357 || */ wKeyBindings
[i
].modifier
==
1366 if (!wRootMenuPerformShortcut(event
)) {
1367 static int dontLoop
= 0;
1369 if (dontLoop
> 10) {
1370 wwarning("problem with key event processing code");
1374 /* if the focused window is an internal window, try redispatching
1375 * the event to the managed window, as it can be a WINGs window */
1376 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1377 /* client_leader contains the WINGs toplevel */
1378 event
->xany
.window
= wwin
->client_leader
;
1379 WMHandleEvent(event
);
1385 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1386 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1391 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1392 if (!CheckFullScreenWindowFocused(scr
)) {
1393 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1394 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1398 case WKBD_WINDOWLIST
:
1399 if (!CheckFullScreenWindowFocused(scr
)) {
1400 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1401 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1406 case WKBD_WINDOWMENU
:
1407 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1408 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1410 case WKBD_MINIMIZEALL
:
1411 CloseWindowMenu(scr
);
1414 case WKBD_MINIATURIZE
:
1415 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1416 && !WFLAGP(wwin
, no_miniaturizable
)) {
1417 CloseWindowMenu(scr
);
1419 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1420 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, event
->xbutton
.time
);
1422 wIconifyWindow(wwin
);
1427 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1428 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1429 CloseWindowMenu(scr
);
1431 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1432 wHideApplication(wapp
);
1436 case WKBD_HIDE_OTHERS
:
1437 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1438 CloseWindowMenu(scr
);
1440 wHideOtherApplications(wwin
);
1444 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1445 CloseWindowMenu(scr
);
1447 if (wwin
->flags
.maximized
== (MAX_VERTICAL
| MAX_HORIZONTAL
))
1448 wUnmaximizeWindow(wwin
);
1450 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1453 case WKBD_VMAXIMIZE
:
1454 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1455 CloseWindowMenu(scr
);
1457 if (wwin
->flags
.maximized
== MAX_VERTICAL
)
1458 wUnmaximizeWindow(wwin
);
1460 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1463 case WKBD_HMAXIMIZE
:
1464 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1465 CloseWindowMenu(scr
);
1467 if (wwin
->flags
.maximized
== MAX_HORIZONTAL
)
1468 wUnmaximizeWindow(wwin
);
1470 wMaximizeWindow(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1473 case WKBD_LHMAXIMIZE
:
1474 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1475 CloseWindowMenu(scr
);
1477 if (wwin
->flags
.maximized
== (MAX_VERTICAL
| MAX_LEFTHALF
))
1478 wUnmaximizeWindow(wwin
);
1480 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1483 case WKBD_RHMAXIMIZE
:
1484 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1485 CloseWindowMenu(scr
);
1487 if (wwin
->flags
.maximized
== (MAX_VERTICAL
| MAX_RIGHTHALF
))
1488 wUnmaximizeWindow(wwin
);
1490 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1494 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1495 CloseWindowMenu(scr
);
1497 if (wwin
->flags
.maximized
== MAX_MAXIMUS
)
1498 wUnmaximizeWindow(wwin
);
1500 wMaximizeWindow(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1504 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1505 CloseWindowMenu(scr
);
1507 wRaiseFrame(wwin
->frame
->core
);
1511 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1512 CloseWindowMenu(scr
);
1514 wLowerFrame(wwin
->frame
->core
);
1517 case WKBD_RAISELOWER
:
1518 /* raise or lower the window under the pointer, not the
1521 wwin
= windowUnderPointer(scr
);
1523 wRaiseLowerFrame(wwin
->frame
->core
);
1526 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1527 if (wwin
->flags
.shaded
)
1528 wUnshadeWindow(wwin
);
1533 case WKBD_MOVERESIZE
:
1534 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1535 CloseWindowMenu(scr
);
1537 wKeyboardMoveResizeWindow(wwin
);
1541 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1542 CloseWindowMenu(scr
);
1543 if (wwin
->protocols
.DELETE_WINDOW
)
1544 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, event
->xkey
.time
);
1548 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1549 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1552 case WKBD_FOCUSNEXT
:
1553 StartWindozeCycle(wwin
, event
, True
, False
);
1556 case WKBD_FOCUSPREV
:
1557 StartWindozeCycle(wwin
, event
, False
, False
);
1560 case WKBD_GROUPNEXT
:
1561 StartWindozeCycle(wwin
, event
, True
, True
);
1564 case WKBD_GROUPPREV
:
1565 StartWindozeCycle(wwin
, event
, False
, True
);
1568 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1569 widx
= command
- WKBD_WORKSPACE1
;
1570 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1571 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1572 wWorkspaceChange(scr
, i
);
1575 case WKBD_NEXTWORKSPACE
:
1576 wWorkspaceRelativeChange(scr
, 1);
1578 case WKBD_PREVWORKSPACE
:
1579 wWorkspaceRelativeChange(scr
, -1);
1593 widx
= command
- WKBD_WINDOW1
;
1595 if (scr
->shortcutWindows
[widx
]) {
1596 WMArray
*list
= scr
->shortcutWindows
[widx
];
1598 int count
= WMGetArrayItemCount(list
);
1600 WMArrayIterator iter
;
1603 wUnselectWindows(scr
);
1604 cw
= scr
->current_workspace
;
1606 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1608 wWindowChangeWorkspace(wwin
, cw
);
1610 wMakeWindowVisible(wwin
);
1613 wSelectWindow(wwin
, True
);
1616 /* rotate the order of windows, to create a cycling effect */
1617 twin
= WMGetFromArray(list
, 0);
1618 WMDeleteFromArray(list
, 0);
1619 WMAddToArray(list
, twin
);
1621 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1622 if (scr
->shortcutWindows
[widx
]) {
1623 WMFreeArray(scr
->shortcutWindows
[widx
]);
1624 scr
->shortcutWindows
[widx
] = NULL
;
1627 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1628 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1629 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1630 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1632 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1633 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1636 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1639 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1642 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1644 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1645 if (scr
->shortcutWindows
[widx
]) {
1646 WMFreeArray(scr
->shortcutWindows
[widx
]);
1648 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1655 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1656 (void) RelaunchWindow(wwin
);
1660 case WKBD_SWITCH_SCREEN
:
1661 if (wScreenCount
> 1) {
1665 /* find index of this screen */
1666 for (i
= 0; i
< wScreenCount
; i
++) {
1667 if (wScreenWithNumber(i
) == scr
)
1671 if (i
>= wScreenCount
) {
1674 scr2
= wScreenWithNumber(i
);
1677 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1678 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1683 case WKBD_NEXTWSLAYER
:
1684 case WKBD_PREVWSLAYER
:
1688 row
= scr
->current_workspace
/ 10;
1689 column
= scr
->current_workspace
% 10;
1691 if (command
== WKBD_NEXTWSLAYER
) {
1692 if ((row
+ 1) * 10 < scr
->workspace_count
)
1693 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1696 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1700 case WKBD_CLIPRAISELOWER
:
1701 if (!wPreferences
.flags
.noclip
)
1702 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1704 case WKBD_DOCKRAISELOWER
:
1705 if (!wPreferences
.flags
.nodock
)
1706 wDockRaiseLower(scr
->dock
);
1708 #ifdef KEEP_XKB_LOCK_STATUS
1710 if (wPreferences
.modelock
) {
1712 wwin
= scr
->focused_window
;
1714 if (wwin
&& wwin
->flags
.mapped
1715 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1716 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1717 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1719 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1720 wwin
->frame
->last_languagemode
= staterec
.group
;
1721 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1726 #endif /* KEEP_XKB_LOCK_STATUS */
1730 static void handleMotionNotify(XEvent
* event
)
1732 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1734 if (wPreferences
.scrollable_menus
) {
1735 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1736 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1738 if (scr
->flags
.jump_back_pending
||
1739 p
.x
<= (rect
.pos
.x
+ 1) ||
1740 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1741 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1744 menu
= wMenuUnderPointer(scr
);
1746 wMenuScroll(menu
, event
);
1751 static void handleVisibilityNotify(XEvent
* event
)
1755 wwin
= wWindowFor(event
->xvisibility
.window
);
1758 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);