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"
60 #include "application.h"
63 #include "workspace.h"
66 #include "properties.h"
77 #include "switchmenu.h"
79 /******** Global Variables **********/
80 extern WShortKey wKeyBindings
[WKBD_LAST
];
82 #define MOD_MASK wPreferences.modifier_mask
84 /************ Local stuff ***********/
86 static void saveTimestamp(XEvent
*event
);
87 static void handleColormapNotify(XEvent
*event
);
88 static void handleMapNotify(XEvent
*event
);
89 static void handleUnmapNotify(XEvent
*event
);
90 static void handleButtonPress(XEvent
*event
);
91 static void handleExpose(XEvent
*event
);
92 static void handleDestroyNotify(XEvent
*event
);
93 static void handleConfigureRequest(XEvent
*event
);
94 static void handleMapRequest(XEvent
*event
);
95 static void handlePropertyNotify(XEvent
*event
);
96 static void handleEnterNotify(XEvent
*event
);
97 static void handleLeaveNotify(XEvent
*event
);
98 static void handleExtensions(XEvent
*event
);
99 static void handleClientMessage(XEvent
*event
);
100 static void handleKeyPress(XEvent
*event
);
101 static void handleFocusIn(XEvent
*event
);
102 static void handleMotionNotify(XEvent
*event
);
103 static void handleVisibilityNotify(XEvent
*event
);
104 static void handle_inotify_events(int fd
, int wd
);
105 static void wdelete_death_handler(WMagicNumber id
);
109 static void handleShapeNotify(XEvent
*event
);
112 #ifdef KEEP_XKB_LOCK_STATUS
113 static void handleXkbIndicatorStateNotify(XEvent
*event
);
116 /* real dead process handler */
117 static void handleDeadProcess(void *foo
);
119 typedef struct DeadProcesses
{
121 unsigned char exit_status
;
124 /* stack of dead processes */
125 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
126 static int deadProcessPtr
= 0;
128 typedef struct DeathHandler
{
129 WDeathHandler
*callback
;
134 static WMArray
*deathHandlers
= NULL
;
136 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
138 DeathHandler
*handler
;
140 handler
= malloc(sizeof(DeathHandler
));
145 handler
->callback
= callback
;
146 handler
->client_data
= cdata
;
149 deathHandlers
= WMCreateArrayWithDestructor(8, free
);
151 WMAddToArray(deathHandlers
, handler
);
156 static void wdelete_death_handler(WMagicNumber id
)
158 DeathHandler
*handler
= (DeathHandler
*) id
;
160 if (!handler
|| !deathHandlers
)
163 /* array destructor will call free(handler) */
164 WMRemoveFromArray(deathHandlers
, handler
);
167 void DispatchEvent(XEvent
* event
)
170 handleDeadProcess(NULL
);
172 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
173 WCHANGE_STATE(WSTATE_EXITING
);
174 /* received SIGTERM */
176 * WMHandleEvent() can't be called from anything
177 * executed inside here, or we can get in a infinite
180 Shutdown(WSExitMode
);
182 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
183 WCHANGE_STATE(WSTATE_RESTARTING
);
185 Shutdown(WSRestartPreparationMode
);
186 /* received SIGHUP */
188 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
189 WCHANGE_STATE(WSTATE_NORMAL
);
190 wDefaultsCheckDomains(NULL
);
193 /* for the case that all that is wanted to be dispatched is
198 saveTimestamp(event
);
199 switch (event
->type
) {
201 handleMapRequest(event
);
205 handleKeyPress(event
);
209 handleMotionNotify(event
);
212 case ConfigureRequest
:
213 handleConfigureRequest(event
);
217 handleDestroyNotify(event
);
221 handleMapNotify(event
);
225 handleUnmapNotify(event
);
229 handleButtonPress(event
);
237 handlePropertyNotify(event
);
241 handleEnterNotify(event
);
245 handleLeaveNotify(event
);
249 handleClientMessage(event
);
253 handleColormapNotify(event
);
257 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
258 XRefreshKeyboardMapping(&event
->xmapping
);
262 handleFocusIn(event
);
265 case VisibilityNotify
:
266 handleVisibilityNotify(event
);
269 case ConfigureNotify
:
271 if (event
->xconfigure
.window
== DefaultRootWindow(dpy
))
272 XRRUpdateConfiguration(event
);
277 handleExtensions(event
);
284 *----------------------------------------------------------------------
285 * handle_inotify_events-
286 * Check for inotify events
289 * After reading events for the given file descriptor (fd) and
290 * watch descriptor (wd)
293 * Calls wDefaultsCheckDomains if config database is updated
294 *----------------------------------------------------------------------
296 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
297 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
298 static void handle_inotify_events(int fd
, int wd
)
300 ssize_t eventQLength
, i
= 0;
301 char buff
[BUFF_SIZE
] = { 0 };
302 /* Check config only once per read of the event queue */
306 * Read off the queued events
307 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
308 * not occur; the block is on Xevents, but a config file change will normally
309 * occur as a result of an Xevent - so the event queue should never have more than
310 * a few entries before a read().
312 eventQLength
= read(fd
, buff
, BUFF_SIZE
);
314 /* check what events occured */
315 /* Should really check wd here too, but for now we only have one watch! */
316 while (i
< eventQLength
) {
317 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
320 * see inotify.h for event types.
322 if (pevent
->mask
& IN_DELETE_SELF
) {
323 wwarning(_("the defaults database has been deleted!"
324 " Restart Window Maker to create the database" " with the default settings"));
327 if (pevent
->mask
& IN_UNMOUNT
) {
328 wwarning(_("the unit containing the defaults database has"
329 " been unmounted. Setting --static mode." " Any changes will not be saved."));
331 wPreferences
.flags
.noupdates
= 1;
333 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
334 wwarning(_("Inotify: Reading config files in defaults database."));
335 wDefaultsCheckDomains(NULL
);
338 /* move to next event in the buffer */
339 i
+= sizeof(struct inotify_event
) + pevent
->len
;
342 #endif /* HAVE_INOTIFY */
345 *----------------------------------------------------------------------
347 * Processes X and internal events indefinitely.
353 * The LastTimestamp global variable is updated.
354 * Calls inotifyGetEvents if defaults database changes.
355 *----------------------------------------------------------------------
357 noreturn
void EventLoop(void)
365 if (w_global
.inotify
.fd_event_queue
< 0 || w_global
.inotify
.wd_defaults
< 0)
371 WMNextEvent(dpy
, &event
); /* Blocks here */
372 WMHandleEvent(&event
);
378 FD_SET(w_global
.inotify
.fd_event_queue
, &rfds
);
380 /* check for available read data from inotify - don't block! */
381 retVal
= select(w_global
.inotify
.fd_event_queue
+ 1, &rfds
, NULL
, NULL
, &time
);
383 if (retVal
< 0) { /* an error has occured */
384 wwarning(_("select failed. The inotify instance will be closed."
385 " Changes to the defaults database will require"
386 " a restart to take effect."));
387 close(w_global
.inotify
.fd_event_queue
);
388 w_global
.inotify
.fd_event_queue
= -1;
391 if (FD_ISSET(w_global
.inotify
.fd_event_queue
, &rfds
))
392 handle_inotify_events(w_global
.inotify
.fd_event_queue
, w_global
.inotify
.wd_defaults
);
399 *----------------------------------------------------------------------
400 * ProcessPendingEvents --
401 * Processes the events that are currently pending (at the time
402 * this function is called) in the display's queue.
405 * After the pending events that were present at the function call
409 * Many -- whatever handling events may involve.
411 *----------------------------------------------------------------------
413 void ProcessPendingEvents(void)
420 /* Take a snapshot of the event count in the queue */
421 count
= XPending(dpy
);
423 while (count
> 0 && XPending(dpy
)) {
424 WMNextEvent(dpy
, &event
);
425 WMHandleEvent(&event
);
430 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
432 if ((scr
->last_click_time
> 0) &&
433 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
434 && (event
->xbutton
.button
== scr
->last_click_button
)
435 && (event
->xbutton
.window
== scr
->last_click_window
)) {
437 scr
->flags
.next_click_is_not_double
= 1;
438 scr
->last_click_time
= 0;
439 scr
->last_click_window
= event
->xbutton
.window
;
446 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
448 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
449 wwarning("stack overflow: too many dead processes");
452 /* stack the process to be handled later,
453 * as this is called from the signal handler */
454 deadProcesses
[deadProcessPtr
].pid
= pid
;
455 deadProcesses
[deadProcessPtr
].exit_status
= status
;
459 static void handleDeadProcess(void *foo
)
464 for (i
= 0; i
< deadProcessPtr
; i
++) {
465 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
468 if (!deathHandlers
) {
473 /* get the pids on the queue and call handlers */
474 while (deadProcessPtr
> 0) {
477 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
478 tmp
= WMGetFromArray(deathHandlers
, i
);
482 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
483 (*tmp
->callback
) (tmp
->pid
,
484 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
485 wdelete_death_handler(tmp
);
491 static void saveTimestamp(XEvent
* event
)
494 * Never save CurrentTime as LastTimestamp because CurrentTime
495 * it's not a real timestamp (it's the 0L constant)
498 switch (event
->type
) {
501 w_global
.timestamp
.last_event
= event
->xbutton
.time
;
505 w_global
.timestamp
.last_event
= event
->xkey
.time
;
508 w_global
.timestamp
.last_event
= event
->xmotion
.time
;
511 w_global
.timestamp
.last_event
= event
->xproperty
.time
;
515 w_global
.timestamp
.last_event
= event
->xcrossing
.time
;
518 w_global
.timestamp
.last_event
= event
->xselectionclear
.time
;
520 case SelectionRequest
:
521 w_global
.timestamp
.last_event
= event
->xselectionrequest
.time
;
523 case SelectionNotify
:
524 w_global
.timestamp
.last_event
= event
->xselection
.time
;
526 wXDNDProcessSelection(event
);
532 static int matchWindow(const void *item
, const void *cdata
)
534 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
537 static void handleExtensions(XEvent
* event
)
539 #ifdef KEEP_XKB_LOCK_STATUS
541 xkbevent
= (XkbEvent
*) event
;
542 #endif /*KEEP_XKB_LOCK_STATUS */
544 if (w_global
.xext
.shape
.supported
&& event
->type
== (w_global
.xext
.shape
.event_base
+ ShapeNotify
)) {
545 handleShapeNotify(event
);
548 #ifdef KEEP_XKB_LOCK_STATUS
549 if (wPreferences
.modelock
&& (xkbevent
->type
== w_global
.xext
.xkb
.event_base
)) {
550 handleXkbIndicatorStateNotify(event
);
552 #endif /*KEEP_XKB_LOCK_STATUS */
554 if (w_global
.xext
.randr
.supported
&& event
->type
== (w_global
.xext
.randr
.event_base
+ RRScreenChangeNotify
)) {
555 /* From xrandr man page: "Clients must call back into Xlib using
556 * XRRUpdateConfiguration when screen configuration change notify
557 * events are generated */
558 XRRUpdateConfiguration(event
);
559 WCHANGE_STATE(WSTATE_RESTARTING
);
560 Shutdown(WSRestartPreparationMode
);
566 static void handleMapRequest(XEvent
* ev
)
570 Window window
= ev
->xmaprequest
.window
;
572 if ((wwin
= wWindowFor(window
))) {
573 if (wwin
->flags
.shaded
) {
574 wUnshadeWindow(wwin
);
576 /* deiconify window */
577 if (wwin
->flags
.miniaturized
) {
578 wDeiconifyWindow(wwin
);
579 } else if (wwin
->flags
.hidden
) {
580 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
581 /* go to the last workspace that the user worked on the app */
583 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
585 wUnhideApplication(wapp
, False
, False
);
590 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
592 wwin
= wManageWindow(scr
, window
);
595 * This is to let the Dock know that the application it launched
596 * has already been mapped (eg: it has finished launching).
597 * It is not necessary for normally docked apps, but is needed for
598 * apps that were forcedly docked (like with dockit).
600 if (scr
->last_dock
) {
601 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
602 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
604 wDockTrackWindowLaunch(scr
->last_dock
, window
);
608 wClientSetState(wwin
, NormalState
, None
);
609 if (wwin
->flags
.maximized
) {
610 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
612 if (wwin
->flags
.shaded
) {
613 wwin
->flags
.shaded
= 0;
614 wwin
->flags
.skip_next_animation
= 1;
617 if (wwin
->flags
.miniaturized
) {
618 wwin
->flags
.miniaturized
= 0;
619 wwin
->flags
.skip_next_animation
= 1;
620 wIconifyWindow(wwin
);
622 if (wwin
->flags
.fullscreen
) {
623 wwin
->flags
.fullscreen
= 0;
624 wFullscreenWindow(wwin
);
626 if (wwin
->flags
.hidden
) {
627 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
629 wwin
->flags
.hidden
= 0;
630 wwin
->flags
.skip_next_animation
= 1;
632 wHideApplication(wapp
);
638 static void handleDestroyNotify(XEvent
* event
)
642 Window window
= event
->xdestroywindow
.window
;
643 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
646 wwin
= wWindowFor(window
);
648 wUnmanageWindow(wwin
, False
, True
);
652 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
653 WFakeGroupLeader
*fPtr
;
655 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
656 if (fPtr
->retainCount
> 0) {
658 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
659 XDestroyWindow(dpy
, fPtr
->leader
);
664 fPtr
->origLeader
= None
;
668 app
= wApplicationOf(window
);
670 if (window
== app
->main_window
) {
672 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
674 if (wwin
->main_window
== window
) {
675 wwin
->main_window
= None
;
680 wApplicationDestroy(app
);
684 static void handleExpose(XEvent
* event
)
686 WObjDescriptor
*desc
;
689 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
691 if (XFindContext(dpy
, event
->xexpose
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
695 if (desc
->handle_expose
) {
696 (*desc
->handle_expose
) (desc
, event
);
700 static void executeButtonAction(WScreen
* scr
, XEvent
* event
, int action
)
703 case WA_SELECT_WINDOWS
:
704 wUnselectWindows(scr
);
705 wSelectWindows(scr
, event
);
707 case WA_OPEN_APPMENU
:
708 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
710 if (scr
->root_menu
) {
711 if (scr
->root_menu
->brother
->flags
.mapped
)
712 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
714 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
717 case WA_OPEN_WINLISTMENU
:
718 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
719 if (scr
->switch_menu
) {
720 if (scr
->switch_menu
->brother
->flags
.mapped
)
721 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
723 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
732 static void handleButtonPress(XEvent
* event
)
734 WObjDescriptor
*desc
;
737 scr
= wScreenForRootWindow(event
->xbutton
.root
);
743 if (event
->xbutton
.window
== scr
->root_win
) {
744 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
745 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
746 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
747 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
748 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
749 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
750 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
751 wWorkspaceRelativeChange(scr
, 1);
752 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
753 wWorkspaceRelativeChange(scr
, -1);
758 if (XFindContext(dpy
, event
->xbutton
.subwindow
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
759 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
764 if (desc
->parent_type
== WCLASS_WINDOW
) {
767 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
768 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
770 /* if (wPreferences.focus_mode == WKF_CLICK) { */
771 if (wPreferences
.ignore_focus_click
) {
772 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
774 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
778 } else if (desc
->parent_type
== WCLASS_APPICON
779 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
780 if (event
->xbutton
.state
& MOD_MASK
) {
782 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
787 if (desc
->handle_mousedown
!= NULL
) {
788 (*desc
->handle_mousedown
) (desc
, event
);
791 /* save double-click information */
792 if (scr
->flags
.next_click_is_not_double
) {
793 scr
->flags
.next_click_is_not_double
= 0;
795 scr
->last_click_time
= event
->xbutton
.time
;
796 scr
->last_click_button
= event
->xbutton
.button
;
797 scr
->last_click_window
= event
->xbutton
.window
;
801 static void handleMapNotify(XEvent
* event
)
805 wwin
= wWindowFor(event
->xmap
.event
);
806 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
807 if (wwin
->flags
.miniaturized
) {
808 wDeiconifyWindow(wwin
);
812 wClientSetState(wwin
, NormalState
, None
);
818 static void handleUnmapNotify(XEvent
* event
)
822 Bool withdraw
= False
;
824 /* only process windows with StructureNotify selected
825 * (ignore SubstructureNotify) */
826 wwin
= wWindowFor(event
->xunmap
.window
);
830 /* whether the event is a Withdrawal request */
831 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
834 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
837 if (!wwin
->flags
.mapped
&& !withdraw
838 && wwin
->frame
->workspace
== w_global
.workspace
.current
839 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
843 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
844 wwin
->flags
.mapped
= 0;
846 /* check if the window was destroyed */
847 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
850 Bool reparented
= False
;
852 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
855 /* withdraw window */
856 wwin
->flags
.mapped
= 0;
858 wClientSetState(wwin
, WithdrawnState
, None
);
860 /* if the window was reparented, do not reparent it back to the
862 wUnmanageWindow(wwin
, !reparented
, False
);
867 static void handleConfigureRequest(XEvent
* event
)
871 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
873 * Configure request for unmapped window
875 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
877 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
881 static void handlePropertyNotify(XEvent
* event
)
889 wwin
= wWindowFor(event
->xproperty
.window
);
891 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
894 wClientCheckProperty(wwin
, &event
->xproperty
);
896 wapp
= wApplicationOf(event
->xproperty
.window
);
898 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
902 static void handleClientMessage(XEvent
* event
)
905 WObjDescriptor
*desc
;
907 /* handle transition from Normal to Iconic state */
908 if (event
->xclient
.message_type
== w_global
.atom
.wm
.change_state
909 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
911 wwin
= wWindowFor(event
->xclient
.window
);
914 if (!wwin
->flags
.miniaturized
)
915 wIconifyWindow(wwin
);
916 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.colormap_notify
&& event
->xclient
.format
== 32) {
917 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
922 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
923 wColormapAllowClientInstallation(scr
, True
);
924 } else { /* stopping */
925 wColormapAllowClientInstallation(scr
, False
);
927 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.command
) {
932 len
= sizeof(event
->xclient
.data
.b
) + 1;
933 command
= wmalloc(len
);
934 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
936 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
937 wwarning(_("Got Reconfigure command"));
938 wDefaultsCheckDomains(NULL
);
940 wwarning(_("Got unknown command %s"), command
);
945 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.wm_function
) {
948 wapp
= wApplicationOf(event
->xclient
.window
);
950 switch (event
->xclient
.data
.l
[0]) {
951 case WMFHideOtherApplications
:
952 wHideOtherApplications(wapp
->main_window_desc
);
956 case WMFHideApplication
:
957 wHideApplication(wapp
);
963 wwin
= wWindowFor(event
->xclient
.window
);
965 switch (event
->xclient
.data
.l
[0]) {
966 case WMFHideOtherApplications
:
967 wHideOtherApplications(wwin
);
970 case WMFHideApplication
:
971 wHideApplication(wApplicationOf(wwin
->main_window
));
976 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.wm_attr
) {
977 wwin
= wWindowFor(event
->xclient
.window
);
980 switch (event
->xclient
.data
.l
[0]) {
981 case GSWindowLevelAttr
:
983 int level
= (int)event
->xclient
.data
.l
[1];
985 if (WINDOW_LEVEL(wwin
) != level
) {
986 ChangeStackingLevel(wwin
->frame
->core
, level
);
991 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.titlebar_state
) {
992 wwin
= wWindowFor(event
->xclient
.window
);
995 switch (event
->xclient
.data
.l
[0]) {
996 case WMTitleBarNormal
:
997 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1000 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1003 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1006 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.ignore_focus_events
) {
1007 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1010 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1011 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1014 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1019 * Non-standard thing, but needed by OffiX DND.
1020 * For when the icon frame gets a ClientMessage
1021 * that should have gone to the icon_window.
1023 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1024 struct WIcon
*icon
= NULL
;
1026 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1027 icon
= (WIcon
*) desc
->parent
;
1028 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1029 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1031 if (icon
&& (wwin
= icon
->owner
)) {
1032 if (wwin
->client_win
!= event
->xclient
.window
) {
1033 event
->xclient
.window
= wwin
->client_win
;
1034 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1041 static void raiseWindow(WScreen
* scr
)
1045 scr
->autoRaiseTimer
= NULL
;
1047 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1051 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1052 wRaiseFrame(wwin
->frame
->core
);
1053 /* this is needed or a race condition will occur */
1058 static void handleEnterNotify(XEvent
* event
)
1061 WObjDescriptor
*desc
= NULL
;
1063 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1065 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1066 /* already left the window... */
1068 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1073 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1074 if (desc
->handle_enternotify
)
1075 (*desc
->handle_enternotify
) (desc
, event
);
1078 /* enter to window */
1079 wwin
= wWindowFor(event
->xcrossing
.window
);
1081 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1082 wColormapInstallForWindow(scr
, NULL
);
1084 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1085 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1086 scr
->autoRaiseTimer
= NULL
;
1089 /* set auto raise timer even if in focus-follows-mouse mode
1090 * and the event is for the frame window, even if the window
1091 * has focus already. useful if you move the pointer from a focused
1092 * window to the root window and back pretty fast
1094 * set focus if in focus-follows-mouse mode and the event
1095 * is for the frame window and window doesn't have focus yet */
1096 if (wPreferences
.focus_mode
== WKF_SLOPPY
1097 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1099 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1100 wSetFocusTo(scr
, wwin
);
1102 if (scr
->autoRaiseTimer
)
1103 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1104 scr
->autoRaiseTimer
= NULL
;
1106 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1107 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1109 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1112 /* Install colormap for window, if the colormap installation mode
1113 * is colormap_follows_mouse */
1114 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1115 if (wwin
->client_win
== event
->xcrossing
.window
)
1116 wColormapInstallForWindow(scr
, wwin
);
1118 wColormapInstallForWindow(scr
, NULL
);
1122 if (event
->xcrossing
.window
== event
->xcrossing
.root
1123 && event
->xcrossing
.detail
== NotifyNormal
1124 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1126 wSetFocusTo(scr
, scr
->focused_window
);
1129 wBalloonEnteredObject(scr
, desc
);
1133 static void handleLeaveNotify(XEvent
* event
)
1135 WObjDescriptor
*desc
= NULL
;
1137 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1138 if (desc
->handle_leavenotify
)
1139 (*desc
->handle_leavenotify
) (desc
, event
);
1144 static void handleShapeNotify(XEvent
* event
)
1146 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1153 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1154 if (ev
.xshape
.kind
== ShapeBounding
) {
1155 if (ev
.xshape
.shaped
== shev
->shaped
) {
1158 XPutBackEvent(dpy
, &ev
.xevent
);
1164 wwin
= wWindowFor(shev
->window
);
1165 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1168 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1170 wwin
->flags
.shaped
= 0;
1171 wWindowClearShape(wwin
);
1173 } else if (shev
->shaped
) {
1175 wwin
->flags
.shaped
= 1;
1176 wWindowSetShape(wwin
);
1181 #ifdef KEEP_XKB_LOCK_STATUS
1182 /* please help ]d if you know what to do */
1183 static void handleXkbIndicatorStateNotify(XEvent
*event
)
1187 XkbStateRec staterec
;
1190 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1191 scr
= wScreenWithNumber(i
);
1192 wwin
= scr
->focused_window
;
1193 if (wwin
&& wwin
->flags
.focused
) {
1194 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1195 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1196 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1197 wwin
->frame
->languagemode
= staterec
.group
;
1199 #ifdef XKB_BUTTON_HINT
1200 if (wwin
->frame
->titlebar
) {
1201 wFrameWindowPaint(wwin
->frame
);
1207 #endif /*KEEP_XKB_LOCK_STATUS */
1209 static void handleColormapNotify(XEvent
* event
)
1213 Bool reinstall
= False
;
1215 wwin
= wWindowFor(event
->xcolormap
.window
);
1219 scr
= wwin
->screen_ptr
;
1223 if (event
->xcolormap
.new) {
1224 XWindowAttributes attr
;
1226 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1228 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1229 scr
->current_colormap
= attr
.colormap
;
1232 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1233 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1235 /* some bastard app (like XV) removed our colormap */
1237 * can't enforce or things like xscreensaver wont work
1240 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1241 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1243 /* someone has put our colormap back */
1247 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1248 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1250 if (reinstall
&& scr
->current_colormap
!= None
) {
1251 if (!scr
->flags
.colormap_stuff_blocked
)
1252 XInstallColormap(dpy
, scr
->current_colormap
);
1256 static void handleFocusIn(XEvent
* event
)
1261 * For applications that like stealing the focus.
1263 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1264 saveTimestamp(event
);
1265 if (event
->xfocus
.mode
== NotifyUngrab
1266 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1270 wwin
= wWindowFor(event
->xfocus
.window
);
1271 if (wwin
&& !wwin
->flags
.focused
) {
1272 if (wwin
->flags
.mapped
)
1273 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1275 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1277 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1279 wSetFocusTo(scr
, NULL
);
1283 static WWindow
*windowUnderPointer(WScreen
* scr
)
1289 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1290 return wWindowFor(win
);
1294 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1296 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1302 static void handleKeyPress(XEvent
* event
)
1304 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1305 WWindow
*wwin
= scr
->focused_window
;
1309 #ifdef KEEP_XKB_LOCK_STATUS
1310 XkbStateRec staterec
;
1311 #endif /*KEEP_XKB_LOCK_STATUS */
1313 /* ignore CapsLock */
1314 modifiers
= event
->xkey
.state
& ValidModMask
;
1316 for (i
= 0; i
< WKBD_LAST
; i
++) {
1317 if (wKeyBindings
[i
].keycode
== 0)
1320 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1321 || */ wKeyBindings
[i
].modifier
==
1330 if (!wRootMenuPerformShortcut(event
)) {
1331 static int dontLoop
= 0;
1333 if (dontLoop
> 10) {
1334 wwarning("problem with key event processing code");
1338 /* if the focused window is an internal window, try redispatching
1339 * the event to the managed window, as it can be a WINGs window */
1340 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1341 /* client_leader contains the WINGs toplevel */
1342 event
->xany
.window
= wwin
->client_leader
;
1343 WMHandleEvent(event
);
1349 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1350 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1355 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1356 if (!CheckFullScreenWindowFocused(scr
)) {
1357 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1358 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1362 case WKBD_WINDOWLIST
:
1363 if (!CheckFullScreenWindowFocused(scr
)) {
1364 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1365 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1370 case WKBD_WINDOWMENU
:
1371 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1372 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1374 case WKBD_MINIMIZEALL
:
1375 CloseWindowMenu(scr
);
1378 case WKBD_MINIATURIZE
:
1379 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1380 && !WFLAGP(wwin
, no_miniaturizable
)) {
1381 CloseWindowMenu(scr
);
1383 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1384 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
, event
->xbutton
.time
);
1386 wIconifyWindow(wwin
);
1391 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1392 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1393 CloseWindowMenu(scr
);
1395 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1396 wHideApplication(wapp
);
1400 case WKBD_HIDE_OTHERS
:
1401 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1402 CloseWindowMenu(scr
);
1404 wHideOtherApplications(wwin
);
1408 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1409 CloseWindowMenu(scr
);
1411 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1414 case WKBD_VMAXIMIZE
:
1415 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1416 CloseWindowMenu(scr
);
1418 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1421 case WKBD_HMAXIMIZE
:
1422 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1423 CloseWindowMenu(scr
);
1425 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1428 case WKBD_LHMAXIMIZE
:
1429 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1430 CloseWindowMenu(scr
);
1432 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1435 case WKBD_RHMAXIMIZE
:
1436 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1437 CloseWindowMenu(scr
);
1439 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1442 case WKBD_THMAXIMIZE
:
1443 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1444 CloseWindowMenu(scr
);
1446 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1449 case WKBD_BHMAXIMIZE
:
1450 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1451 CloseWindowMenu(scr
);
1453 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1456 case WKBD_LTCMAXIMIZE
:
1457 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1458 CloseWindowMenu(scr
);
1460 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1463 case WKBD_RTCMAXIMIZE
:
1464 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1465 CloseWindowMenu(scr
);
1467 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1470 case WKBD_LBCMAXIMIZE
:
1471 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1472 CloseWindowMenu(scr
);
1474 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1477 case WKBD_RBCMAXIMIZE
:
1478 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1479 CloseWindowMenu(scr
);
1481 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1485 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1486 CloseWindowMenu(scr
);
1488 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1492 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1493 CloseWindowMenu(scr
);
1495 wRaiseFrame(wwin
->frame
->core
);
1499 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1500 CloseWindowMenu(scr
);
1502 wLowerFrame(wwin
->frame
->core
);
1505 case WKBD_RAISELOWER
:
1506 /* raise or lower the window under the pointer, not the
1509 wwin
= windowUnderPointer(scr
);
1511 wRaiseLowerFrame(wwin
->frame
->core
);
1514 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1515 if (wwin
->flags
.shaded
)
1516 wUnshadeWindow(wwin
);
1521 case WKBD_MOVERESIZE
:
1522 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1523 CloseWindowMenu(scr
);
1525 wKeyboardMoveResizeWindow(wwin
);
1529 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1530 CloseWindowMenu(scr
);
1531 if (wwin
->protocols
.DELETE_WINDOW
)
1532 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
, event
->xkey
.time
);
1536 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1537 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1540 case WKBD_FOCUSNEXT
:
1541 StartWindozeCycle(wwin
, event
, True
, False
);
1544 case WKBD_FOCUSPREV
:
1545 StartWindozeCycle(wwin
, event
, False
, False
);
1548 case WKBD_GROUPNEXT
:
1549 StartWindozeCycle(wwin
, event
, True
, True
);
1552 case WKBD_GROUPPREV
:
1553 StartWindozeCycle(wwin
, event
, False
, True
);
1556 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1557 widx
= command
- WKBD_WORKSPACE1
;
1558 i
= (w_global
.workspace
.current
/ 10) * 10 + widx
;
1559 if (wPreferences
.ws_advance
|| i
< w_global
.workspace
.count
)
1560 wWorkspaceChange(scr
, i
);
1563 case WKBD_NEXTWORKSPACE
:
1564 wWorkspaceRelativeChange(scr
, 1);
1566 case WKBD_PREVWORKSPACE
:
1567 wWorkspaceRelativeChange(scr
, -1);
1569 case WKBD_LASTWORKSPACE
:
1570 wWorkspaceChange(scr
, w_global
.workspace
.last_used
);
1573 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1574 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1575 i
= (w_global
.workspace
.current
/ 10) * 10 + widx
;
1576 if (wwin
&& (wPreferences
.ws_advance
|| i
< w_global
.workspace
.count
))
1577 wWindowChangeWorkspace(wwin
, i
);
1580 case WKBD_MOVE_NEXTWORKSPACE
:
1582 wWindowChangeWorkspaceRelative(wwin
, 1);
1584 case WKBD_MOVE_PREVWORKSPACE
:
1586 wWindowChangeWorkspaceRelative(wwin
, -1);
1588 case WKBD_MOVE_LASTWORKSPACE
:
1590 wWindowChangeWorkspace(wwin
, w_global
.workspace
.last_used
);
1593 case WKBD_MOVE_NEXTWSLAYER
:
1594 case WKBD_MOVE_PREVWSLAYER
:
1599 row
= w_global
.workspace
.current
/ 10;
1600 column
= w_global
.workspace
.current
% 10;
1602 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1603 if ((row
+ 1) * 10 < w_global
.workspace
.count
)
1604 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1607 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1624 widx
= command
- WKBD_WINDOW1
;
1626 if (w_global
.shortcut
.windows
[widx
]) {
1627 WMArray
*list
= w_global
.shortcut
.windows
[widx
];
1629 int count
= WMGetArrayItemCount(list
);
1631 WMArrayIterator iter
;
1634 wUnselectWindows(scr
);
1635 cw
= w_global
.workspace
.current
;
1637 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1639 wWindowChangeWorkspace(wwin
, cw
);
1641 wMakeWindowVisible(wwin
);
1644 wSelectWindow(wwin
, True
);
1647 /* rotate the order of windows, to create a cycling effect */
1648 twin
= WMGetFromArray(list
, 0);
1649 WMDeleteFromArray(list
, 0);
1650 WMAddToArray(list
, twin
);
1652 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1653 if (w_global
.shortcut
.windows
[widx
]) {
1654 WMFreeArray(w_global
.shortcut
.windows
[widx
]);
1655 w_global
.shortcut
.windows
[widx
] = NULL
;
1658 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1659 w_global
.shortcut
.windows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1661 w_global
.shortcut
.windows
[widx
] = WMCreateArray(4);
1662 WMAddToArray(w_global
.shortcut
.windows
[widx
], wwin
);
1665 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1668 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1671 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1672 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1673 if (w_global
.shortcut
.windows
[widx
])
1674 WMFreeArray(w_global
.shortcut
.windows
[widx
]);
1676 w_global
.shortcut
.windows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1683 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1684 (void) RelaunchWindow(wwin
);
1688 case WKBD_SWITCH_SCREEN
:
1689 if (w_global
.screen_count
> 1) {
1693 /* find index of this screen */
1694 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1695 if (wScreenWithNumber(i
) == scr
)
1699 if (i
>= w_global
.screen_count
) {
1702 scr2
= wScreenWithNumber(i
);
1705 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1706 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1711 case WKBD_NEXTWSLAYER
:
1712 case WKBD_PREVWSLAYER
:
1716 row
= w_global
.workspace
.current
/ 10;
1717 column
= w_global
.workspace
.current
% 10;
1719 if (command
== WKBD_NEXTWSLAYER
) {
1720 if ((row
+ 1) * 10 < w_global
.workspace
.count
)
1721 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1724 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1728 case WKBD_CLIPRAISELOWER
:
1729 if (!wPreferences
.flags
.noclip
)
1730 wDockRaiseLower(w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
);
1732 case WKBD_DOCKRAISELOWER
:
1733 if (!wPreferences
.flags
.nodock
)
1734 wDockRaiseLower(scr
->dock
);
1736 #ifdef KEEP_XKB_LOCK_STATUS
1738 if (wPreferences
.modelock
) {
1740 wwin
= scr
->focused_window
;
1742 if (wwin
&& wwin
->flags
.mapped
1743 && wwin
->frame
->workspace
== w_global
.workspace
.current
1744 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1745 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1747 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1748 wwin
->frame
->last_languagemode
= staterec
.group
;
1749 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1754 #endif /* KEEP_XKB_LOCK_STATUS */
1758 static void handleMotionNotify(XEvent
* event
)
1760 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1762 if (wPreferences
.scrollable_menus
) {
1763 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1764 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1766 if (scr
->flags
.jump_back_pending
||
1767 p
.x
<= (rect
.pos
.x
+ 1) ||
1768 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1769 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1772 menu
= wMenuUnderPointer(scr
);
1774 wMenuScroll(menu
, event
);
1779 static void handleVisibilityNotify(XEvent
* event
)
1783 wwin
= wWindowFor(event
->xvisibility
.window
);
1786 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);