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"
80 #define MOD_MASK wPreferences.modifier_mask
82 /************ Local stuff ***********/
84 static void saveTimestamp(XEvent
*event
);
85 static void handleColormapNotify(XEvent
*event
);
86 static void handleMapNotify(XEvent
*event
);
87 static void handleUnmapNotify(XEvent
*event
);
88 static void handleButtonPress(XEvent
*event
);
89 static void handleExpose(XEvent
*event
);
90 static void handleDestroyNotify(XEvent
*event
);
91 static void handleConfigureRequest(XEvent
*event
);
92 static void handleMapRequest(XEvent
*event
);
93 static void handlePropertyNotify(XEvent
*event
);
94 static void handleEnterNotify(XEvent
*event
);
95 static void handleLeaveNotify(XEvent
*event
);
96 static void handleExtensions(XEvent
*event
);
97 static void handleClientMessage(XEvent
*event
);
98 static void handleKeyPress(XEvent
*event
);
99 static void handleFocusIn(XEvent
*event
);
100 static void handleMotionNotify(XEvent
*event
);
101 static void handleVisibilityNotify(XEvent
*event
);
102 static void handle_inotify_events(void);
103 static void wdelete_death_handler(WMagicNumber id
);
107 static void handleShapeNotify(XEvent
*event
);
110 #ifdef KEEP_XKB_LOCK_STATUS
111 static void handleXkbIndicatorStateNotify(XkbEvent
*event
);
114 /* real dead process handler */
115 static void handleDeadProcess(void);
117 typedef struct DeadProcesses
{
119 unsigned char exit_status
;
122 /* stack of dead processes */
123 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
124 static int deadProcessPtr
= 0;
126 typedef struct DeathHandler
{
127 WDeathHandler
*callback
;
132 static WMArray
*deathHandlers
= NULL
;
134 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
136 DeathHandler
*handler
;
138 handler
= malloc(sizeof(DeathHandler
));
143 handler
->callback
= callback
;
144 handler
->client_data
= cdata
;
147 deathHandlers
= WMCreateArrayWithDestructor(8, free
);
149 WMAddToArray(deathHandlers
, handler
);
154 static void wdelete_death_handler(WMagicNumber id
)
156 DeathHandler
*handler
= (DeathHandler
*) id
;
158 if (!handler
|| !deathHandlers
)
161 /* array destructor will call free(handler) */
162 WMRemoveFromArray(deathHandlers
, handler
);
165 void DispatchEvent(XEvent
* event
)
170 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
171 WCHANGE_STATE(WSTATE_EXITING
);
172 /* received SIGTERM */
174 * WMHandleEvent() can't be called from anything
175 * executed inside here, or we can get in a infinite
178 Shutdown(WSExitMode
);
180 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
181 WCHANGE_STATE(WSTATE_RESTARTING
);
183 Shutdown(WSRestartPreparationMode
);
184 /* received SIGHUP */
186 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
187 WCHANGE_STATE(WSTATE_NORMAL
);
188 wDefaultsCheckDomains(NULL
);
191 /* for the case that all that is wanted to be dispatched is
196 saveTimestamp(event
);
197 switch (event
->type
) {
199 handleMapRequest(event
);
203 handleKeyPress(event
);
207 handleMotionNotify(event
);
210 case ConfigureRequest
:
211 handleConfigureRequest(event
);
215 handleDestroyNotify(event
);
219 handleMapNotify(event
);
223 handleUnmapNotify(event
);
227 handleButtonPress(event
);
235 handlePropertyNotify(event
);
239 handleEnterNotify(event
);
243 handleLeaveNotify(event
);
247 handleClientMessage(event
);
251 handleColormapNotify(event
);
255 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
256 XRefreshKeyboardMapping(&event
->xmapping
);
260 handleFocusIn(event
);
263 case VisibilityNotify
:
264 handleVisibilityNotify(event
);
267 case ConfigureNotify
:
269 if (event
->xconfigure
.window
== DefaultRootWindow(dpy
))
270 XRRUpdateConfiguration(event
);
275 handleExtensions(event
);
282 *----------------------------------------------------------------------
283 * handle_inotify_events-
284 * Check for inotify events
287 * After reading events for the given file descriptor (fd) and
288 * watch descriptor (wd)
291 * Calls wDefaultsCheckDomains if config database is updated
292 *----------------------------------------------------------------------
294 static void handle_inotify_events(void)
296 ssize_t eventQLength
, i
= 0;
297 /* Make room for at lease 5 simultaneous events, with path + filenames */
298 char buff
[ (sizeof(struct inotify_event
) + NAME_MAX
+ 1) * 5 ];
299 /* Check config only once per read of the event queue */
303 * Read off the queued events
304 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
305 * not occur; the block is on Xevents, but a config file change will normally
306 * occur as a result of an Xevent - so the event queue should never have more than
307 * a few entries before a read().
309 eventQLength
= read(w_global
.inotify
.fd_event_queue
,
310 buff
, sizeof(buff
) );
312 /* check what events occured */
313 /* Should really check wd here too, but for now we only have one watch! */
314 while (i
< eventQLength
) {
315 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
318 * see inotify.h for event types.
320 if (pevent
->mask
& IN_DELETE_SELF
) {
321 wwarning(_("the defaults database has been deleted!"
322 " Restart Window Maker to create the database" " with the default settings"));
324 if (w_global
.inotify
.fd_event_queue
>= 0) {
325 close(w_global
.inotify
.fd_event_queue
);
326 w_global
.inotify
.fd_event_queue
= -1;
329 if (pevent
->mask
& IN_UNMOUNT
) {
330 wwarning(_("the unit containing the defaults database has"
331 " been unmounted. Setting --static mode." " Any changes will not be saved."));
333 if (w_global
.inotify
.fd_event_queue
>= 0) {
334 close(w_global
.inotify
.fd_event_queue
);
335 w_global
.inotify
.fd_event_queue
= -1;
338 wPreferences
.flags
.noupdates
= 1;
340 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
341 wwarning(_("Inotify: Reading config files in defaults database."));
342 wDefaultsCheckDomains(NULL
);
346 /* move to next event in the buffer */
347 i
+= sizeof(struct inotify_event
) + pevent
->len
;
350 #endif /* HAVE_INOTIFY */
353 *----------------------------------------------------------------------
355 * Processes X and internal events indefinitely.
361 * The LastTimestamp global variable is updated.
362 * Calls inotifyGetEvents if defaults database changes.
363 *----------------------------------------------------------------------
365 noreturn
void EventLoop(void)
373 if (w_global
.inotify
.fd_event_queue
< 0 || w_global
.inotify
.wd_defaults
< 0)
379 WMNextEvent(dpy
, &event
); /* Blocks here */
380 WMHandleEvent(&event
);
386 FD_SET(w_global
.inotify
.fd_event_queue
, &rfds
);
388 /* check for available read data from inotify - don't block! */
389 retVal
= select(w_global
.inotify
.fd_event_queue
+ 1, &rfds
, NULL
, NULL
, &time
);
391 if (retVal
< 0) { /* an error has occured */
392 wwarning(_("select failed. The inotify instance will be closed."
393 " Changes to the defaults database will require"
394 " a restart to take effect."));
395 close(w_global
.inotify
.fd_event_queue
);
396 w_global
.inotify
.fd_event_queue
= -1;
399 if (FD_ISSET(w_global
.inotify
.fd_event_queue
, &rfds
))
400 handle_inotify_events();
407 *----------------------------------------------------------------------
408 * ProcessPendingEvents --
409 * Processes the events that are currently pending (at the time
410 * this function is called) in the display's queue.
413 * After the pending events that were present at the function call
417 * Many -- whatever handling events may involve.
419 *----------------------------------------------------------------------
421 void ProcessPendingEvents(void)
428 /* Take a snapshot of the event count in the queue */
429 count
= XPending(dpy
);
431 while (count
> 0 && XPending(dpy
)) {
432 WMNextEvent(dpy
, &event
);
433 WMHandleEvent(&event
);
438 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
440 if ((scr
->last_click_time
> 0) &&
441 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
442 && (event
->xbutton
.button
== scr
->last_click_button
)
443 && (event
->xbutton
.window
== scr
->last_click_window
)) {
445 scr
->flags
.next_click_is_not_double
= 1;
446 scr
->last_click_time
= 0;
447 scr
->last_click_window
= event
->xbutton
.window
;
454 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
456 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
457 wwarning("stack overflow: too many dead processes");
460 /* stack the process to be handled later,
461 * as this is called from the signal handler */
462 deadProcesses
[deadProcessPtr
].pid
= pid
;
463 deadProcesses
[deadProcessPtr
].exit_status
= status
;
467 static void handleDeadProcess(void)
472 for (i
= 0; i
< deadProcessPtr
; i
++) {
473 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
476 if (!deathHandlers
) {
481 /* get the pids on the queue and call handlers */
482 while (deadProcessPtr
> 0) {
485 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
486 tmp
= WMGetFromArray(deathHandlers
, i
);
490 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
491 (*tmp
->callback
) (tmp
->pid
,
492 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
493 wdelete_death_handler(tmp
);
499 static void saveTimestamp(XEvent
* event
)
502 * Never save CurrentTime as LastTimestamp because CurrentTime
503 * it's not a real timestamp (it's the 0L constant)
506 switch (event
->type
) {
509 w_global
.timestamp
.last_event
= event
->xbutton
.time
;
513 w_global
.timestamp
.last_event
= event
->xkey
.time
;
516 w_global
.timestamp
.last_event
= event
->xmotion
.time
;
519 w_global
.timestamp
.last_event
= event
->xproperty
.time
;
523 w_global
.timestamp
.last_event
= event
->xcrossing
.time
;
526 w_global
.timestamp
.last_event
= event
->xselectionclear
.time
;
528 case SelectionRequest
:
529 w_global
.timestamp
.last_event
= event
->xselectionrequest
.time
;
531 case SelectionNotify
:
532 w_global
.timestamp
.last_event
= event
->xselection
.time
;
534 wXDNDProcessSelection(event
);
540 static int matchWindow(const void *item
, const void *cdata
)
542 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
545 static void handleExtensions(XEvent
* event
)
548 if (w_global
.xext
.shape
.supported
&& event
->type
== (w_global
.xext
.shape
.event_base
+ ShapeNotify
)) {
549 handleShapeNotify(event
);
552 #ifdef KEEP_XKB_LOCK_STATUS
553 if (wPreferences
.modelock
&& (event
->type
== w_global
.xext
.xkb
.event_base
)) {
554 handleXkbIndicatorStateNotify((XkbEvent
*) event
);
556 #endif /*KEEP_XKB_LOCK_STATUS */
558 if (w_global
.xext
.randr
.supported
&& event
->type
== (w_global
.xext
.randr
.event_base
+ RRScreenChangeNotify
)) {
559 /* From xrandr man page: "Clients must call back into Xlib using
560 * XRRUpdateConfiguration when screen configuration change notify
561 * events are generated */
562 XRRUpdateConfiguration(event
);
563 WCHANGE_STATE(WSTATE_RESTARTING
);
564 Shutdown(WSRestartPreparationMode
);
570 static void handleMapRequest(XEvent
* ev
)
574 Window window
= ev
->xmaprequest
.window
;
576 if ((wwin
= wWindowFor(window
))) {
577 if (wwin
->flags
.shaded
) {
578 wUnshadeWindow(wwin
);
580 /* deiconify window */
581 if (wwin
->flags
.miniaturized
) {
582 wDeiconifyWindow(wwin
);
583 } else if (wwin
->flags
.hidden
) {
584 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
585 /* go to the last workspace that the user worked on the app */
587 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
589 wUnhideApplication(wapp
, False
, False
);
594 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
596 wwin
= wManageWindow(scr
, window
);
599 * This is to let the Dock know that the application it launched
600 * has already been mapped (eg: it has finished launching).
601 * It is not necessary for normally docked apps, but is needed for
602 * apps that were forcedly docked (like with dockit).
604 if (scr
->last_dock
) {
605 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
606 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
608 wDockTrackWindowLaunch(scr
->last_dock
, window
);
612 wClientSetState(wwin
, NormalState
, None
);
613 if (wwin
->flags
.maximized
) {
614 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
616 if (wwin
->flags
.shaded
) {
617 wwin
->flags
.shaded
= 0;
618 wwin
->flags
.skip_next_animation
= 1;
621 if (wwin
->flags
.miniaturized
) {
622 wwin
->flags
.miniaturized
= 0;
623 wwin
->flags
.skip_next_animation
= 1;
624 wIconifyWindow(wwin
);
626 if (wwin
->flags
.fullscreen
) {
627 wwin
->flags
.fullscreen
= 0;
628 wFullscreenWindow(wwin
);
630 if (wwin
->flags
.hidden
) {
631 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
633 wwin
->flags
.hidden
= 0;
634 wwin
->flags
.skip_next_animation
= 1;
636 wHideApplication(wapp
);
642 static void handleDestroyNotify(XEvent
* event
)
646 Window window
= event
->xdestroywindow
.window
;
647 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
650 wwin
= wWindowFor(window
);
652 wUnmanageWindow(wwin
, False
, True
);
656 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
657 WFakeGroupLeader
*fPtr
;
659 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
660 if (fPtr
->retainCount
> 0) {
662 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
663 XDestroyWindow(dpy
, fPtr
->leader
);
668 fPtr
->origLeader
= None
;
672 app
= wApplicationOf(window
);
674 if (window
== app
->main_window
) {
676 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
678 if (wwin
->main_window
== window
) {
679 wwin
->main_window
= None
;
684 wApplicationDestroy(app
);
688 static void handleExpose(XEvent
* event
)
690 WObjDescriptor
*desc
;
693 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
695 if (XFindContext(dpy
, event
->xexpose
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
699 if (desc
->handle_expose
) {
700 (*desc
->handle_expose
) (desc
, event
);
704 static void executeButtonAction(WScreen
* scr
, XEvent
* event
, int action
)
707 case WA_SELECT_WINDOWS
:
708 wUnselectWindows(scr
);
709 wSelectWindows(scr
, event
);
711 case WA_OPEN_APPMENU
:
712 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
714 if (scr
->root_menu
) {
715 if (scr
->root_menu
->brother
->flags
.mapped
)
716 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
718 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
721 case WA_OPEN_WINLISTMENU
:
722 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
723 if (scr
->switch_menu
) {
724 if (scr
->switch_menu
->brother
->flags
.mapped
)
725 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
727 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
736 static void handleButtonPress(XEvent
* event
)
738 WObjDescriptor
*desc
;
741 scr
= wScreenForRootWindow(event
->xbutton
.root
);
747 if (event
->xbutton
.window
== scr
->root_win
) {
748 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
749 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
750 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
751 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
752 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
753 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
754 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
755 wWorkspaceRelativeChange(scr
, 1);
756 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
757 wWorkspaceRelativeChange(scr
, -1);
762 if (XFindContext(dpy
, event
->xbutton
.subwindow
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
763 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
768 if (desc
->parent_type
== WCLASS_WINDOW
) {
771 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
772 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
774 /* if (wPreferences.focus_mode == WKF_CLICK) { */
775 if (wPreferences
.ignore_focus_click
) {
776 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
778 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
782 } else if (desc
->parent_type
== WCLASS_APPICON
783 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
784 if (event
->xbutton
.state
& MOD_MASK
) {
786 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
791 if (desc
->handle_mousedown
!= NULL
) {
792 (*desc
->handle_mousedown
) (desc
, event
);
795 /* save double-click information */
796 if (scr
->flags
.next_click_is_not_double
) {
797 scr
->flags
.next_click_is_not_double
= 0;
799 scr
->last_click_time
= event
->xbutton
.time
;
800 scr
->last_click_button
= event
->xbutton
.button
;
801 scr
->last_click_window
= event
->xbutton
.window
;
805 static void handleMapNotify(XEvent
* event
)
809 wwin
= wWindowFor(event
->xmap
.event
);
810 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
811 if (wwin
->flags
.miniaturized
) {
812 wDeiconifyWindow(wwin
);
816 wClientSetState(wwin
, NormalState
, None
);
822 static void handleUnmapNotify(XEvent
* event
)
826 Bool withdraw
= False
;
828 /* only process windows with StructureNotify selected
829 * (ignore SubstructureNotify) */
830 wwin
= wWindowFor(event
->xunmap
.window
);
834 /* whether the event is a Withdrawal request */
835 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
838 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
841 if (!wwin
->flags
.mapped
&& !withdraw
842 && wwin
->frame
->workspace
== w_global
.workspace
.current
843 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
847 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
848 wwin
->flags
.mapped
= 0;
850 /* check if the window was destroyed */
851 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
854 Bool reparented
= False
;
856 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
859 /* withdraw window */
860 wwin
->flags
.mapped
= 0;
862 wClientSetState(wwin
, WithdrawnState
, None
);
864 /* if the window was reparented, do not reparent it back to the
866 wUnmanageWindow(wwin
, !reparented
, False
);
871 static void handleConfigureRequest(XEvent
* event
)
875 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
877 * Configure request for unmapped window
879 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
881 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
885 static void handlePropertyNotify(XEvent
* event
)
893 wwin
= wWindowFor(event
->xproperty
.window
);
895 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
898 wClientCheckProperty(wwin
, &event
->xproperty
);
900 wapp
= wApplicationOf(event
->xproperty
.window
);
902 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
906 static void handleClientMessage(XEvent
* event
)
909 WObjDescriptor
*desc
;
911 /* handle transition from Normal to Iconic state */
912 if (event
->xclient
.message_type
== w_global
.atom
.wm
.change_state
913 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
915 wwin
= wWindowFor(event
->xclient
.window
);
918 if (!wwin
->flags
.miniaturized
)
919 wIconifyWindow(wwin
);
920 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.colormap_notify
&& event
->xclient
.format
== 32) {
921 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
926 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
927 wColormapAllowClientInstallation(scr
, True
);
928 } else { /* stopping */
929 wColormapAllowClientInstallation(scr
, False
);
931 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.command
) {
936 len
= sizeof(event
->xclient
.data
.b
) + 1;
937 command
= wmalloc(len
);
938 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
940 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
941 wwarning(_("Got Reconfigure command"));
942 wDefaultsCheckDomains(NULL
);
944 wwarning(_("Got unknown command %s"), command
);
949 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.wm_function
) {
952 wapp
= wApplicationOf(event
->xclient
.window
);
954 switch (event
->xclient
.data
.l
[0]) {
955 case WMFHideOtherApplications
:
956 wHideOtherApplications(wapp
->main_window_desc
);
960 case WMFHideApplication
:
961 wHideApplication(wapp
);
967 wwin
= wWindowFor(event
->xclient
.window
);
969 switch (event
->xclient
.data
.l
[0]) {
970 case WMFHideOtherApplications
:
971 wHideOtherApplications(wwin
);
974 case WMFHideApplication
:
975 wHideApplication(wApplicationOf(wwin
->main_window
));
980 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.wm_attr
) {
981 wwin
= wWindowFor(event
->xclient
.window
);
984 switch (event
->xclient
.data
.l
[0]) {
985 case GSWindowLevelAttr
:
987 int level
= (int)event
->xclient
.data
.l
[1];
989 if (WINDOW_LEVEL(wwin
) != level
) {
990 ChangeStackingLevel(wwin
->frame
->core
, level
);
995 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.titlebar_state
) {
996 wwin
= wWindowFor(event
->xclient
.window
);
999 switch (event
->xclient
.data
.l
[0]) {
1000 case WMTitleBarNormal
:
1001 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1003 case WMTitleBarMain
:
1004 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1007 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1010 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.ignore_focus_events
) {
1011 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1014 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1015 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1018 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1023 * Non-standard thing, but needed by OffiX DND.
1024 * For when the icon frame gets a ClientMessage
1025 * that should have gone to the icon_window.
1027 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1028 struct WIcon
*icon
= NULL
;
1030 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1031 icon
= (WIcon
*) desc
->parent
;
1032 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1033 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1035 if (icon
&& (wwin
= icon
->owner
)) {
1036 if (wwin
->client_win
!= event
->xclient
.window
) {
1037 event
->xclient
.window
= wwin
->client_win
;
1038 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1045 static void raiseWindow(WScreen
* scr
)
1049 scr
->autoRaiseTimer
= NULL
;
1051 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1055 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1056 wRaiseFrame(wwin
->frame
->core
);
1057 /* this is needed or a race condition will occur */
1062 static void handleEnterNotify(XEvent
* event
)
1065 WObjDescriptor
*desc
= NULL
;
1067 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1069 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1070 /* already left the window... */
1072 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1077 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1078 if (desc
->handle_enternotify
)
1079 (*desc
->handle_enternotify
) (desc
, event
);
1082 /* enter to window */
1083 wwin
= wWindowFor(event
->xcrossing
.window
);
1085 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1086 wColormapInstallForWindow(scr
, NULL
);
1088 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1089 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1090 scr
->autoRaiseTimer
= NULL
;
1093 /* set auto raise timer even if in focus-follows-mouse mode
1094 * and the event is for the frame window, even if the window
1095 * has focus already. useful if you move the pointer from a focused
1096 * window to the root window and back pretty fast
1098 * set focus if in focus-follows-mouse mode and the event
1099 * is for the frame window and window doesn't have focus yet */
1100 if (wPreferences
.focus_mode
== WKF_SLOPPY
1101 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1103 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1104 wSetFocusTo(scr
, wwin
);
1106 if (scr
->autoRaiseTimer
)
1107 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1108 scr
->autoRaiseTimer
= NULL
;
1110 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1111 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1113 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1116 /* Install colormap for window, if the colormap installation mode
1117 * is colormap_follows_mouse */
1118 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1119 if (wwin
->client_win
== event
->xcrossing
.window
)
1120 wColormapInstallForWindow(scr
, wwin
);
1122 wColormapInstallForWindow(scr
, NULL
);
1126 if (event
->xcrossing
.window
== event
->xcrossing
.root
1127 && event
->xcrossing
.detail
== NotifyNormal
1128 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1130 wSetFocusTo(scr
, scr
->focused_window
);
1133 wBalloonEnteredObject(scr
, desc
);
1137 static void handleLeaveNotify(XEvent
* event
)
1139 WObjDescriptor
*desc
= NULL
;
1141 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1142 if (desc
->handle_leavenotify
)
1143 (*desc
->handle_leavenotify
) (desc
, event
);
1148 static void handleShapeNotify(XEvent
* event
)
1150 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1157 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1158 if (ev
.xshape
.kind
== ShapeBounding
) {
1159 if (ev
.xshape
.shaped
== shev
->shaped
) {
1162 XPutBackEvent(dpy
, &ev
.xevent
);
1168 wwin
= wWindowFor(shev
->window
);
1169 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1172 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1174 wwin
->flags
.shaped
= 0;
1175 wWindowClearShape(wwin
);
1177 } else if (shev
->shaped
) {
1179 wwin
->flags
.shaped
= 1;
1180 wWindowSetShape(wwin
);
1183 #endif /* USE_XSHAPE */
1185 #ifdef KEEP_XKB_LOCK_STATUS
1186 /* please help ]d if you know what to do */
1187 static void handleXkbIndicatorStateNotify(XkbEvent
*event
)
1191 XkbStateRec staterec
;
1194 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1195 scr
= wScreenWithNumber(i
);
1196 wwin
= scr
->focused_window
;
1197 if (wwin
&& wwin
->flags
.focused
) {
1198 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1199 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1200 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1201 wwin
->frame
->languagemode
= staterec
.group
;
1203 #ifdef XKB_BUTTON_HINT
1204 if (wwin
->frame
->titlebar
) {
1205 wFrameWindowPaint(wwin
->frame
);
1211 #endif /*KEEP_XKB_LOCK_STATUS */
1213 static void handleColormapNotify(XEvent
* event
)
1217 Bool reinstall
= False
;
1219 wwin
= wWindowFor(event
->xcolormap
.window
);
1223 scr
= wwin
->screen_ptr
;
1227 if (event
->xcolormap
.new) {
1228 XWindowAttributes attr
;
1230 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1232 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1233 scr
->current_colormap
= attr
.colormap
;
1236 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1237 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1239 /* some bastard app (like XV) removed our colormap */
1241 * can't enforce or things like xscreensaver wont work
1244 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1245 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1247 /* someone has put our colormap back */
1251 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1252 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1254 if (reinstall
&& scr
->current_colormap
!= None
) {
1255 if (!scr
->flags
.colormap_stuff_blocked
)
1256 XInstallColormap(dpy
, scr
->current_colormap
);
1260 static void handleFocusIn(XEvent
* event
)
1265 * For applications that like stealing the focus.
1267 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1268 saveTimestamp(event
);
1269 if (event
->xfocus
.mode
== NotifyUngrab
1270 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1274 wwin
= wWindowFor(event
->xfocus
.window
);
1275 if (wwin
&& !wwin
->flags
.focused
) {
1276 if (wwin
->flags
.mapped
)
1277 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1279 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1281 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1283 wSetFocusTo(scr
, NULL
);
1287 static WWindow
*windowUnderPointer(WScreen
* scr
)
1293 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1294 return wWindowFor(win
);
1298 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1300 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1306 static void handleKeyPress(XEvent
* event
)
1308 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1309 WWindow
*wwin
= scr
->focused_window
;
1313 #ifdef KEEP_XKB_LOCK_STATUS
1314 XkbStateRec staterec
;
1315 #endif /*KEEP_XKB_LOCK_STATUS */
1317 /* ignore CapsLock */
1318 modifiers
= event
->xkey
.state
& w_global
.shortcut
.modifiers_mask
;
1320 for (i
= 0; i
< WKBD_LAST
; i
++) {
1321 if (wKeyBindings
[i
].keycode
== 0)
1324 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1325 || */ wKeyBindings
[i
].modifier
==
1334 if (!wRootMenuPerformShortcut(event
)) {
1335 static int dontLoop
= 0;
1337 if (dontLoop
> 10) {
1338 wwarning("problem with key event processing code");
1342 /* if the focused window is an internal window, try redispatching
1343 * the event to the managed window, as it can be a WINGs window */
1344 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1345 /* client_leader contains the WINGs toplevel */
1346 event
->xany
.window
= wwin
->client_leader
;
1347 WMHandleEvent(event
);
1353 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1354 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1359 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1360 if (!CheckFullScreenWindowFocused(scr
)) {
1361 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1362 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1366 case WKBD_WINDOWLIST
:
1367 if (!CheckFullScreenWindowFocused(scr
)) {
1368 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1369 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1374 case WKBD_WINDOWMENU
:
1375 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1376 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1378 case WKBD_MINIMIZEALL
:
1379 CloseWindowMenu(scr
);
1382 case WKBD_MINIATURIZE
:
1383 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1384 && !WFLAGP(wwin
, no_miniaturizable
)) {
1385 CloseWindowMenu(scr
);
1387 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1388 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
, event
->xbutton
.time
);
1390 wIconifyWindow(wwin
);
1395 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1396 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1397 CloseWindowMenu(scr
);
1399 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1400 wHideApplication(wapp
);
1404 case WKBD_HIDE_OTHERS
:
1405 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1406 CloseWindowMenu(scr
);
1408 wHideOtherApplications(wwin
);
1412 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1413 CloseWindowMenu(scr
);
1415 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1418 case WKBD_VMAXIMIZE
:
1419 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1420 CloseWindowMenu(scr
);
1422 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1425 case WKBD_HMAXIMIZE
:
1426 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1427 CloseWindowMenu(scr
);
1429 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1432 case WKBD_LHMAXIMIZE
:
1433 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1434 CloseWindowMenu(scr
);
1436 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1439 case WKBD_RHMAXIMIZE
:
1440 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1441 CloseWindowMenu(scr
);
1443 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1446 case WKBD_THMAXIMIZE
:
1447 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1448 CloseWindowMenu(scr
);
1450 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1453 case WKBD_BHMAXIMIZE
:
1454 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1455 CloseWindowMenu(scr
);
1457 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1460 case WKBD_LTCMAXIMIZE
:
1461 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1462 CloseWindowMenu(scr
);
1464 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1467 case WKBD_RTCMAXIMIZE
:
1468 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1469 CloseWindowMenu(scr
);
1471 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1474 case WKBD_LBCMAXIMIZE
:
1475 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1476 CloseWindowMenu(scr
);
1478 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1481 case WKBD_RBCMAXIMIZE
:
1482 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1483 CloseWindowMenu(scr
);
1485 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1489 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1490 CloseWindowMenu(scr
);
1492 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1496 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1497 CloseWindowMenu(scr
);
1499 wRaiseFrame(wwin
->frame
->core
);
1503 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1504 CloseWindowMenu(scr
);
1506 wLowerFrame(wwin
->frame
->core
);
1509 case WKBD_RAISELOWER
:
1510 /* raise or lower the window under the pointer, not the
1513 wwin
= windowUnderPointer(scr
);
1515 wRaiseLowerFrame(wwin
->frame
->core
);
1518 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1519 if (wwin
->flags
.shaded
)
1520 wUnshadeWindow(wwin
);
1525 case WKBD_MOVERESIZE
:
1526 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1527 CloseWindowMenu(scr
);
1529 wKeyboardMoveResizeWindow(wwin
);
1533 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1534 CloseWindowMenu(scr
);
1535 if (wwin
->protocols
.DELETE_WINDOW
)
1536 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
, event
->xkey
.time
);
1540 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1541 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1544 case WKBD_FOCUSNEXT
:
1545 StartWindozeCycle(wwin
, event
, True
, False
);
1548 case WKBD_FOCUSPREV
:
1549 StartWindozeCycle(wwin
, event
, False
, False
);
1552 case WKBD_GROUPNEXT
:
1553 StartWindozeCycle(wwin
, event
, True
, True
);
1556 case WKBD_GROUPPREV
:
1557 StartWindozeCycle(wwin
, event
, False
, True
);
1560 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1561 widx
= command
- WKBD_WORKSPACE1
;
1562 i
= (w_global
.workspace
.current
/ 10) * 10 + widx
;
1563 if (wPreferences
.ws_advance
|| i
< w_global
.workspace
.count
)
1564 wWorkspaceChange(scr
, i
);
1567 case WKBD_NEXTWORKSPACE
:
1568 wWorkspaceRelativeChange(scr
, 1);
1570 case WKBD_PREVWORKSPACE
:
1571 wWorkspaceRelativeChange(scr
, -1);
1573 case WKBD_LASTWORKSPACE
:
1574 wWorkspaceChange(scr
, w_global
.workspace
.last_used
);
1577 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1578 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1579 i
= (w_global
.workspace
.current
/ 10) * 10 + widx
;
1580 if (wwin
&& (wPreferences
.ws_advance
|| i
< w_global
.workspace
.count
))
1581 wWindowChangeWorkspace(wwin
, i
);
1584 case WKBD_MOVE_NEXTWORKSPACE
:
1586 wWindowChangeWorkspaceRelative(wwin
, 1);
1588 case WKBD_MOVE_PREVWORKSPACE
:
1590 wWindowChangeWorkspaceRelative(wwin
, -1);
1592 case WKBD_MOVE_LASTWORKSPACE
:
1594 wWindowChangeWorkspace(wwin
, w_global
.workspace
.last_used
);
1597 case WKBD_MOVE_NEXTWSLAYER
:
1598 case WKBD_MOVE_PREVWSLAYER
:
1603 row
= w_global
.workspace
.current
/ 10;
1604 column
= w_global
.workspace
.current
% 10;
1606 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1607 if ((row
+ 1) * 10 < w_global
.workspace
.count
)
1608 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1611 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1628 widx
= command
- WKBD_WINDOW1
;
1630 if (w_global
.shortcut
.windows
[widx
]) {
1631 WMArray
*list
= w_global
.shortcut
.windows
[widx
];
1633 int count
= WMGetArrayItemCount(list
);
1635 WMArrayIterator iter
;
1638 wUnselectWindows(scr
);
1639 cw
= w_global
.workspace
.current
;
1641 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1643 wWindowChangeWorkspace(wwin
, cw
);
1645 wMakeWindowVisible(wwin
);
1648 wSelectWindow(wwin
, True
);
1651 /* rotate the order of windows, to create a cycling effect */
1652 twin
= WMGetFromArray(list
, 0);
1653 WMDeleteFromArray(list
, 0);
1654 WMAddToArray(list
, twin
);
1656 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1657 if (w_global
.shortcut
.windows
[widx
]) {
1658 WMFreeArray(w_global
.shortcut
.windows
[widx
]);
1659 w_global
.shortcut
.windows
[widx
] = NULL
;
1662 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1663 w_global
.shortcut
.windows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1665 w_global
.shortcut
.windows
[widx
] = WMCreateArray(4);
1666 WMAddToArray(w_global
.shortcut
.windows
[widx
], wwin
);
1669 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1672 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1675 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1676 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1677 if (w_global
.shortcut
.windows
[widx
])
1678 WMFreeArray(w_global
.shortcut
.windows
[widx
]);
1680 w_global
.shortcut
.windows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1687 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1688 (void) RelaunchWindow(wwin
);
1692 case WKBD_SWITCH_SCREEN
:
1693 if (w_global
.screen_count
> 1) {
1697 /* find index of this screen */
1698 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1699 if (wScreenWithNumber(i
) == scr
)
1703 if (i
>= w_global
.screen_count
) {
1706 scr2
= wScreenWithNumber(i
);
1709 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1710 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1719 cmdline
= ExpandOptions(scr
, _("exec %a(Run,Type command to run:)"));
1722 XGrabPointer(dpy
, scr
->root_win
, True
, 0,
1723 GrabModeAsync
, GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_WAIT
], CurrentTime
);
1726 ExecuteShellCommand(scr
, cmdline
);
1729 XUngrabPointer(dpy
, CurrentTime
);
1735 case WKBD_NEXTWSLAYER
:
1736 case WKBD_PREVWSLAYER
:
1740 row
= w_global
.workspace
.current
/ 10;
1741 column
= w_global
.workspace
.current
% 10;
1743 if (command
== WKBD_NEXTWSLAYER
) {
1744 if ((row
+ 1) * 10 < w_global
.workspace
.count
)
1745 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1748 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1752 case WKBD_CLIPRAISELOWER
:
1753 if (!wPreferences
.flags
.noclip
)
1754 wDockRaiseLower(w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
);
1756 case WKBD_DOCKRAISELOWER
:
1757 if (!wPreferences
.flags
.nodock
)
1758 wDockRaiseLower(scr
->dock
);
1760 #ifdef KEEP_XKB_LOCK_STATUS
1762 if (wPreferences
.modelock
) {
1764 wwin
= scr
->focused_window
;
1766 if (wwin
&& wwin
->flags
.mapped
1767 && wwin
->frame
->workspace
== w_global
.workspace
.current
1768 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1769 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1771 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1772 wwin
->frame
->last_languagemode
= staterec
.group
;
1773 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1778 #endif /* KEEP_XKB_LOCK_STATUS */
1782 static void handleMotionNotify(XEvent
* event
)
1784 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1786 if (wPreferences
.scrollable_menus
) {
1787 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1788 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1790 if (scr
->flags
.jump_back_pending
||
1791 p
.x
<= (rect
.pos
.x
+ 1) ||
1792 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1793 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1796 menu
= wMenuUnderPointer(scr
);
1803 static void handleVisibilityNotify(XEvent
* event
)
1807 wwin
= wWindowFor(event
->xvisibility
.window
);
1810 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);