1 /* event.c- event loop and handling
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 2014 Window Maker Team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <sys/select.h>
27 #include <sys/inotify.h>
38 #include <X11/Xutil.h>
40 # include <X11/extensions/shape.h>
47 #include <X11/extensions/Xrandr.h>
50 #ifdef KEEP_XKB_LOCK_STATUS
51 #include <X11/XKBlib.h>
52 #endif /* KEEP_XKB_LOCK_STATUS */
54 #include "WindowMaker.h"
61 #include "application.h"
64 #include "workspace.h"
67 #include "properties.h"
78 #include "switchmenu.h"
81 #define MOD_MASK wPreferences.modifier_mask
83 /************ Local stuff ***********/
85 static void saveTimestamp(XEvent
*event
);
86 static void handleColormapNotify(XEvent
*event
);
87 static void handleMapNotify(XEvent
*event
);
88 static void handleUnmapNotify(XEvent
*event
);
89 static void handleButtonPress(XEvent
*event
);
90 static void handleExpose(XEvent
*event
);
91 static void handleDestroyNotify(XEvent
*event
);
92 static void handleConfigureRequest(XEvent
*event
);
93 static void handleMapRequest(XEvent
*event
);
94 static void handlePropertyNotify(XEvent
*event
);
95 static void handleEnterNotify(XEvent
*event
);
96 static void handleLeaveNotify(XEvent
*event
);
97 static void handleExtensions(XEvent
*event
);
98 static void handleClientMessage(XEvent
*event
);
99 static void handleKeyPress(XEvent
*event
);
100 static void handleFocusIn(XEvent
*event
);
101 static void handleMotionNotify(XEvent
*event
);
102 static void handleVisibilityNotify(XEvent
*event
);
103 static void handle_inotify_events(void);
104 static void wdelete_death_handler(WMagicNumber id
);
108 static void handleShapeNotify(XEvent
*event
);
111 #ifdef KEEP_XKB_LOCK_STATUS
112 static void handleXkbIndicatorStateNotify(XkbEvent
*event
);
115 /* real dead process handler */
116 static void handleDeadProcess(void);
118 typedef struct DeadProcesses
{
120 unsigned char exit_status
;
123 /* stack of dead processes */
124 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
125 static int deadProcessPtr
= 0;
127 typedef struct DeathHandler
{
128 WDeathHandler
*callback
;
133 static WMArray
*deathHandlers
= NULL
;
135 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
137 DeathHandler
*handler
;
139 handler
= malloc(sizeof(DeathHandler
));
144 handler
->callback
= callback
;
145 handler
->client_data
= cdata
;
148 deathHandlers
= WMCreateArrayWithDestructor(8, free
);
150 WMAddToArray(deathHandlers
, handler
);
155 static void wdelete_death_handler(WMagicNumber id
)
157 DeathHandler
*handler
= (DeathHandler
*) id
;
159 if (!handler
|| !deathHandlers
)
162 /* array destructor will call free(handler) */
163 WMRemoveFromArray(deathHandlers
, handler
);
166 void DispatchEvent(XEvent
* event
)
171 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
172 WCHANGE_STATE(WSTATE_EXITING
);
173 /* received SIGTERM */
175 * WMHandleEvent() can't be called from anything
176 * executed inside here, or we can get in a infinite
179 Shutdown(WSExitMode
);
181 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
182 WCHANGE_STATE(WSTATE_RESTARTING
);
184 Shutdown(WSRestartPreparationMode
);
185 /* received SIGHUP */
187 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
188 WCHANGE_STATE(WSTATE_NORMAL
);
189 wDefaultsCheckDomains(NULL
);
192 /* for the case that all that is wanted to be dispatched is
197 saveTimestamp(event
);
198 switch (event
->type
) {
200 handleMapRequest(event
);
204 handleKeyPress(event
);
208 handleMotionNotify(event
);
211 case ConfigureRequest
:
212 handleConfigureRequest(event
);
216 handleDestroyNotify(event
);
220 handleMapNotify(event
);
224 handleUnmapNotify(event
);
228 handleButtonPress(event
);
236 handlePropertyNotify(event
);
240 handleEnterNotify(event
);
244 handleLeaveNotify(event
);
248 handleClientMessage(event
);
252 handleColormapNotify(event
);
256 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
257 XRefreshKeyboardMapping(&event
->xmapping
);
261 handleFocusIn(event
);
264 case VisibilityNotify
:
265 handleVisibilityNotify(event
);
268 case ConfigureNotify
:
270 if (event
->xconfigure
.window
== DefaultRootWindow(dpy
))
271 XRRUpdateConfiguration(event
);
276 handleExtensions(event
);
283 *----------------------------------------------------------------------
284 * handle_inotify_events-
285 * Check for inotify events
288 * After reading events for the given file descriptor (fd) and
289 * watch descriptor (wd)
292 * Calls wDefaultsCheckDomains if config database is updated
293 *----------------------------------------------------------------------
295 static void handle_inotify_events(void)
297 ssize_t eventQLength
, i
= 0;
298 /* Make room for at lease 5 simultaneous events, with path + filenames */
299 char buff
[ (sizeof(struct inotify_event
) + NAME_MAX
+ 1) * 5 ];
300 /* Check config only once per read of the event queue */
304 * Read off the queued events
305 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
306 * not occur; the block is on Xevents, but a config file change will normally
307 * occur as a result of an Xevent - so the event queue should never have more than
308 * a few entries before a read().
310 eventQLength
= read(w_global
.inotify
.fd_event_queue
,
311 buff
, sizeof(buff
) );
313 /* check what events occured */
314 /* Should really check wd here too, but for now we only have one watch! */
315 while (i
< eventQLength
) {
316 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
319 * see inotify.h for event types.
321 if (pevent
->mask
& IN_DELETE_SELF
) {
322 wwarning(_("the defaults database has been deleted!"
323 " Restart Window Maker to create the database" " with the default settings"));
325 if (w_global
.inotify
.fd_event_queue
>= 0) {
326 close(w_global
.inotify
.fd_event_queue
);
327 w_global
.inotify
.fd_event_queue
= -1;
330 if (pevent
->mask
& IN_UNMOUNT
) {
331 wwarning(_("the unit containing the defaults database has"
332 " been unmounted. Setting --static mode." " Any changes will not be saved."));
334 if (w_global
.inotify
.fd_event_queue
>= 0) {
335 close(w_global
.inotify
.fd_event_queue
);
336 w_global
.inotify
.fd_event_queue
= -1;
339 wPreferences
.flags
.noupdates
= 1;
341 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
342 wwarning(_("Inotify: Reading config files in defaults database."));
343 wDefaultsCheckDomains(NULL
);
347 /* move to next event in the buffer */
348 i
+= sizeof(struct inotify_event
) + pevent
->len
;
351 #endif /* HAVE_INOTIFY */
354 *----------------------------------------------------------------------
356 * Processes X and internal events indefinitely.
362 * The LastTimestamp global variable is updated.
363 * Calls inotifyGetEvents if defaults database changes.
364 *----------------------------------------------------------------------
366 noreturn
void EventLoop(void)
374 if (w_global
.inotify
.fd_event_queue
< 0 || w_global
.inotify
.wd_defaults
< 0)
380 WMNextEvent(dpy
, &event
); /* Blocks here */
381 WMHandleEvent(&event
);
387 FD_SET(w_global
.inotify
.fd_event_queue
, &rfds
);
389 /* check for available read data from inotify - don't block! */
390 retVal
= select(w_global
.inotify
.fd_event_queue
+ 1, &rfds
, NULL
, NULL
, &time
);
392 if (retVal
< 0) { /* an error has occured */
393 wwarning(_("select failed. The inotify instance will be closed."
394 " Changes to the defaults database will require"
395 " a restart to take effect."));
396 close(w_global
.inotify
.fd_event_queue
);
397 w_global
.inotify
.fd_event_queue
= -1;
400 if (FD_ISSET(w_global
.inotify
.fd_event_queue
, &rfds
))
401 handle_inotify_events();
408 *----------------------------------------------------------------------
409 * ProcessPendingEvents --
410 * Processes the events that are currently pending (at the time
411 * this function is called) in the display's queue.
414 * After the pending events that were present at the function call
418 * Many -- whatever handling events may involve.
420 *----------------------------------------------------------------------
422 void ProcessPendingEvents(void)
429 /* Take a snapshot of the event count in the queue */
430 count
= XPending(dpy
);
432 while (count
> 0 && XPending(dpy
)) {
433 WMNextEvent(dpy
, &event
);
434 WMHandleEvent(&event
);
439 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
441 if ((scr
->last_click_time
> 0) &&
442 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
443 && (event
->xbutton
.button
== scr
->last_click_button
)
444 && (event
->xbutton
.window
== scr
->last_click_window
)) {
446 scr
->flags
.next_click_is_not_double
= 1;
447 scr
->last_click_time
= 0;
448 scr
->last_click_window
= event
->xbutton
.window
;
455 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
457 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
458 wwarning("stack overflow: too many dead processes");
461 /* stack the process to be handled later,
462 * as this is called from the signal handler */
463 deadProcesses
[deadProcessPtr
].pid
= pid
;
464 deadProcesses
[deadProcessPtr
].exit_status
= status
;
468 static void handleDeadProcess(void)
473 for (i
= 0; i
< deadProcessPtr
; i
++) {
474 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
477 if (!deathHandlers
) {
482 /* get the pids on the queue and call handlers */
483 while (deadProcessPtr
> 0) {
486 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
487 tmp
= WMGetFromArray(deathHandlers
, i
);
491 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
492 (*tmp
->callback
) (tmp
->pid
,
493 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
494 wdelete_death_handler(tmp
);
500 static void saveTimestamp(XEvent
* event
)
503 * Never save CurrentTime as LastTimestamp because CurrentTime
504 * it's not a real timestamp (it's the 0L constant)
507 switch (event
->type
) {
510 w_global
.timestamp
.last_event
= event
->xbutton
.time
;
514 w_global
.timestamp
.last_event
= event
->xkey
.time
;
517 w_global
.timestamp
.last_event
= event
->xmotion
.time
;
520 w_global
.timestamp
.last_event
= event
->xproperty
.time
;
524 w_global
.timestamp
.last_event
= event
->xcrossing
.time
;
527 w_global
.timestamp
.last_event
= event
->xselectionclear
.time
;
529 case SelectionRequest
:
530 w_global
.timestamp
.last_event
= event
->xselectionrequest
.time
;
532 case SelectionNotify
:
533 w_global
.timestamp
.last_event
= event
->xselection
.time
;
535 wXDNDProcessSelection(event
);
541 static int matchWindow(const void *item
, const void *cdata
)
543 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
546 static void handleExtensions(XEvent
* event
)
549 if (w_global
.xext
.shape
.supported
&& event
->type
== (w_global
.xext
.shape
.event_base
+ ShapeNotify
)) {
550 handleShapeNotify(event
);
553 #ifdef KEEP_XKB_LOCK_STATUS
554 if (wPreferences
.modelock
&& (event
->type
== w_global
.xext
.xkb
.event_base
)) {
555 handleXkbIndicatorStateNotify((XkbEvent
*) event
);
557 #endif /*KEEP_XKB_LOCK_STATUS */
559 if (w_global
.xext
.randr
.supported
&& event
->type
== (w_global
.xext
.randr
.event_base
+ RRScreenChangeNotify
)) {
560 /* From xrandr man page: "Clients must call back into Xlib using
561 * XRRUpdateConfiguration when screen configuration change notify
562 * events are generated */
563 XRRUpdateConfiguration(event
);
564 WCHANGE_STATE(WSTATE_RESTARTING
);
565 Shutdown(WSRestartPreparationMode
);
571 static void handleMapRequest(XEvent
* ev
)
575 Window window
= ev
->xmaprequest
.window
;
577 if ((wwin
= wWindowFor(window
))) {
578 if (wwin
->flags
.shaded
) {
579 wUnshadeWindow(wwin
);
581 /* deiconify window */
582 if (wwin
->flags
.miniaturized
) {
583 wDeiconifyWindow(wwin
);
584 } else if (wwin
->flags
.hidden
) {
585 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
586 /* go to the last workspace that the user worked on the app */
588 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
590 wUnhideApplication(wapp
, False
, False
);
595 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
597 wwin
= wManageWindow(scr
, window
);
600 * This is to let the Dock know that the application it launched
601 * has already been mapped (eg: it has finished launching).
602 * It is not necessary for normally docked apps, but is needed for
603 * apps that were forcedly docked (like with dockit).
605 if (scr
->last_dock
) {
606 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
607 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
609 wDockTrackWindowLaunch(scr
->last_dock
, window
);
613 wClientSetState(wwin
, NormalState
, None
);
614 if (wwin
->flags
.maximized
) {
615 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
617 if (wwin
->flags
.shaded
) {
618 wwin
->flags
.shaded
= 0;
619 wwin
->flags
.skip_next_animation
= 1;
622 if (wwin
->flags
.miniaturized
) {
623 wwin
->flags
.miniaturized
= 0;
624 wwin
->flags
.skip_next_animation
= 1;
625 wIconifyWindow(wwin
);
627 if (wwin
->flags
.fullscreen
) {
628 wwin
->flags
.fullscreen
= 0;
629 wFullscreenWindow(wwin
);
631 if (wwin
->flags
.hidden
) {
632 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
634 wwin
->flags
.hidden
= 0;
635 wwin
->flags
.skip_next_animation
= 1;
637 wHideApplication(wapp
);
643 static void handleDestroyNotify(XEvent
* event
)
647 Window window
= event
->xdestroywindow
.window
;
648 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
651 wwin
= wWindowFor(window
);
653 wUnmanageWindow(wwin
, False
, True
);
657 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
658 WFakeGroupLeader
*fPtr
;
660 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
661 if (fPtr
->retainCount
> 0) {
663 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
664 XDestroyWindow(dpy
, fPtr
->leader
);
669 fPtr
->origLeader
= None
;
673 app
= wApplicationOf(window
);
675 if (window
== app
->main_window
) {
677 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
679 if (wwin
->main_window
== window
) {
680 wwin
->main_window
= None
;
685 wApplicationDestroy(app
);
689 static void handleExpose(XEvent
* event
)
691 WObjDescriptor
*desc
;
694 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
696 if (XFindContext(dpy
, event
->xexpose
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
700 if (desc
->handle_expose
) {
701 (*desc
->handle_expose
) (desc
, event
);
705 static void executeButtonAction(WScreen
* scr
, XEvent
* event
, int action
)
708 case WA_SELECT_WINDOWS
:
709 wUnselectWindows(scr
);
710 wSelectWindows(scr
, event
);
712 case WA_OPEN_APPMENU
:
713 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
715 if (scr
->root_menu
) {
716 if (scr
->root_menu
->brother
->flags
.mapped
)
717 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
719 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
722 case WA_OPEN_WINLISTMENU
:
723 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
724 if (scr
->switch_menu
) {
725 if (scr
->switch_menu
->brother
->flags
.mapped
)
726 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
728 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
737 static void handleButtonPress(XEvent
* event
)
739 WObjDescriptor
*desc
;
742 scr
= wScreenForRootWindow(event
->xbutton
.root
);
748 if (!wPreferences
.disable_root_mouse
&& event
->xbutton
.window
== scr
->root_win
) {
749 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
750 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
751 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
752 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
753 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
754 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
755 } else if (event
->xbutton
.button
== Button8
&& wPreferences
.mouse_button8
!= WA_NONE
) {
756 executeButtonAction(scr
, event
, wPreferences
.mouse_button8
);
757 }else if (event
->xbutton
.button
== Button9
&& wPreferences
.mouse_button9
!= WA_NONE
) {
758 executeButtonAction(scr
, event
, wPreferences
.mouse_button9
);
759 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel_scroll
!= WA_NONE
) {
760 wWorkspaceRelativeChange(scr
, 1);
761 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel_scroll
!= WA_NONE
) {
762 wWorkspaceRelativeChange(scr
, -1);
763 } else if (event
->xbutton
.button
== Button6
&& wPreferences
.mouse_wheel_tilt
!= WA_NONE
) {
764 wWorkspaceRelativeChange(scr
, -1);
765 } else if (event
->xbutton
.button
== Button7
&& wPreferences
.mouse_wheel_tilt
!= WA_NONE
) {
766 wWorkspaceRelativeChange(scr
, 1);
771 if (XFindContext(dpy
, event
->xbutton
.subwindow
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
772 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
777 if (desc
->parent_type
== WCLASS_WINDOW
) {
780 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
781 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
783 /* if (wPreferences.focus_mode == WKF_CLICK) { */
784 if (wPreferences
.ignore_focus_click
) {
785 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
787 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
791 } else if (desc
->parent_type
== WCLASS_APPICON
792 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
793 if (event
->xbutton
.state
& MOD_MASK
) {
795 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
800 if (desc
->handle_mousedown
!= NULL
) {
801 (*desc
->handle_mousedown
) (desc
, event
);
804 /* save double-click information */
805 if (scr
->flags
.next_click_is_not_double
) {
806 scr
->flags
.next_click_is_not_double
= 0;
808 scr
->last_click_time
= event
->xbutton
.time
;
809 scr
->last_click_button
= event
->xbutton
.button
;
810 scr
->last_click_window
= event
->xbutton
.window
;
814 static void handleMapNotify(XEvent
* event
)
818 wwin
= wWindowFor(event
->xmap
.event
);
819 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
820 if (wwin
->flags
.miniaturized
) {
821 wDeiconifyWindow(wwin
);
825 wClientSetState(wwin
, NormalState
, None
);
831 static void handleUnmapNotify(XEvent
* event
)
835 Bool withdraw
= False
;
837 /* only process windows with StructureNotify selected
838 * (ignore SubstructureNotify) */
839 wwin
= wWindowFor(event
->xunmap
.window
);
843 /* whether the event is a Withdrawal request */
844 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
847 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
850 if (!wwin
->flags
.mapped
&& !withdraw
851 && wwin
->frame
->workspace
== w_global
.workspace
.current
852 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
856 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
857 wwin
->flags
.mapped
= 0;
859 /* check if the window was destroyed */
860 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
863 Bool reparented
= False
;
865 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
868 /* withdraw window */
869 wwin
->flags
.mapped
= 0;
871 wClientSetState(wwin
, WithdrawnState
, None
);
873 /* if the window was reparented, do not reparent it back to the
875 wUnmanageWindow(wwin
, !reparented
, False
);
880 static void handleConfigureRequest(XEvent
* event
)
884 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
886 * Configure request for unmapped window
888 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
890 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
894 static void handlePropertyNotify(XEvent
* event
)
902 wwin
= wWindowFor(event
->xproperty
.window
);
904 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
907 wClientCheckProperty(wwin
, &event
->xproperty
);
909 wapp
= wApplicationOf(event
->xproperty
.window
);
911 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
915 static void handleClientMessage(XEvent
* event
)
918 WObjDescriptor
*desc
;
920 /* handle transition from Normal to Iconic state */
921 if (event
->xclient
.message_type
== w_global
.atom
.wm
.change_state
922 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
924 wwin
= wWindowFor(event
->xclient
.window
);
927 if (!wwin
->flags
.miniaturized
)
928 wIconifyWindow(wwin
);
929 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.colormap_notify
&& event
->xclient
.format
== 32) {
930 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
935 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
936 wColormapAllowClientInstallation(scr
, True
);
937 } else { /* stopping */
938 wColormapAllowClientInstallation(scr
, False
);
940 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.command
) {
945 len
= sizeof(event
->xclient
.data
.b
) + 1;
946 command
= wmalloc(len
);
947 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
949 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
950 wwarning(_("Got Reconfigure command"));
951 wDefaultsCheckDomains(NULL
);
953 wwarning(_("Got unknown command %s"), command
);
958 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.wm_function
) {
961 wapp
= wApplicationOf(event
->xclient
.window
);
963 switch (event
->xclient
.data
.l
[0]) {
964 case WMFHideOtherApplications
:
965 wHideOtherApplications(wapp
->main_window_desc
);
969 case WMFHideApplication
:
970 wHideApplication(wapp
);
976 wwin
= wWindowFor(event
->xclient
.window
);
978 switch (event
->xclient
.data
.l
[0]) {
979 case WMFHideOtherApplications
:
980 wHideOtherApplications(wwin
);
983 case WMFHideApplication
:
984 wHideApplication(wApplicationOf(wwin
->main_window
));
989 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.wm_attr
) {
990 wwin
= wWindowFor(event
->xclient
.window
);
993 switch (event
->xclient
.data
.l
[0]) {
994 case GSWindowLevelAttr
:
996 int level
= (int)event
->xclient
.data
.l
[1];
998 if (WINDOW_LEVEL(wwin
) != level
) {
999 ChangeStackingLevel(wwin
->frame
->core
, level
);
1004 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.titlebar_state
) {
1005 wwin
= wWindowFor(event
->xclient
.window
);
1008 switch (event
->xclient
.data
.l
[0]) {
1009 case WMTitleBarNormal
:
1010 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1012 case WMTitleBarMain
:
1013 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1016 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1019 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.ignore_focus_events
) {
1020 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1023 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1024 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1027 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1032 * Non-standard thing, but needed by OffiX DND.
1033 * For when the icon frame gets a ClientMessage
1034 * that should have gone to the icon_window.
1036 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1037 struct WIcon
*icon
= NULL
;
1039 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1040 icon
= (WIcon
*) desc
->parent
;
1041 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1042 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1044 if (icon
&& (wwin
= icon
->owner
)) {
1045 if (wwin
->client_win
!= event
->xclient
.window
) {
1046 event
->xclient
.window
= wwin
->client_win
;
1047 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1054 static void raiseWindow(WScreen
* scr
)
1058 scr
->autoRaiseTimer
= NULL
;
1060 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1064 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1065 wRaiseFrame(wwin
->frame
->core
);
1066 /* this is needed or a race condition will occur */
1071 static void handleEnterNotify(XEvent
* event
)
1074 WObjDescriptor
*desc
= NULL
;
1076 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1078 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1079 /* already left the window... */
1081 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1086 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1087 if (desc
->handle_enternotify
)
1088 (*desc
->handle_enternotify
) (desc
, event
);
1091 /* enter to window */
1092 wwin
= wWindowFor(event
->xcrossing
.window
);
1094 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1095 wColormapInstallForWindow(scr
, NULL
);
1097 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1098 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1099 scr
->autoRaiseTimer
= NULL
;
1102 /* set auto raise timer even if in focus-follows-mouse mode
1103 * and the event is for the frame window, even if the window
1104 * has focus already. useful if you move the pointer from a focused
1105 * window to the root window and back pretty fast
1107 * set focus if in focus-follows-mouse mode and the event
1108 * is for the frame window and window doesn't have focus yet */
1109 if (wPreferences
.focus_mode
== WKF_SLOPPY
1110 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1112 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1113 wSetFocusTo(scr
, wwin
);
1115 if (scr
->autoRaiseTimer
)
1116 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1117 scr
->autoRaiseTimer
= NULL
;
1119 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1120 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1122 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1125 /* Install colormap for window, if the colormap installation mode
1126 * is colormap_follows_mouse */
1127 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1128 if (wwin
->client_win
== event
->xcrossing
.window
)
1129 wColormapInstallForWindow(scr
, wwin
);
1131 wColormapInstallForWindow(scr
, NULL
);
1135 if (event
->xcrossing
.window
== event
->xcrossing
.root
1136 && event
->xcrossing
.detail
== NotifyNormal
1137 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1139 wSetFocusTo(scr
, scr
->focused_window
);
1142 wBalloonEnteredObject(scr
, desc
);
1146 static void handleLeaveNotify(XEvent
* event
)
1148 WObjDescriptor
*desc
= NULL
;
1150 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1151 if (desc
->handle_leavenotify
)
1152 (*desc
->handle_leavenotify
) (desc
, event
);
1157 static void handleShapeNotify(XEvent
* event
)
1159 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1166 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1167 if (ev
.xshape
.kind
== ShapeBounding
) {
1168 if (ev
.xshape
.shaped
== shev
->shaped
) {
1171 XPutBackEvent(dpy
, &ev
.xevent
);
1177 wwin
= wWindowFor(shev
->window
);
1178 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1181 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1183 wwin
->flags
.shaped
= 0;
1184 wWindowClearShape(wwin
);
1186 } else if (shev
->shaped
) {
1188 wwin
->flags
.shaped
= 1;
1189 wWindowSetShape(wwin
);
1192 #endif /* USE_XSHAPE */
1194 #ifdef KEEP_XKB_LOCK_STATUS
1195 /* please help ]d if you know what to do */
1196 static void handleXkbIndicatorStateNotify(XkbEvent
*event
)
1200 XkbStateRec staterec
;
1203 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1204 scr
= wScreenWithNumber(i
);
1205 wwin
= scr
->focused_window
;
1206 if (wwin
&& wwin
->flags
.focused
) {
1207 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1208 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1209 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1210 wwin
->frame
->languagemode
= staterec
.group
;
1212 #ifdef XKB_BUTTON_HINT
1213 if (wwin
->frame
->titlebar
) {
1214 wFrameWindowPaint(wwin
->frame
);
1220 #endif /*KEEP_XKB_LOCK_STATUS */
1222 static void handleColormapNotify(XEvent
* event
)
1226 Bool reinstall
= False
;
1228 wwin
= wWindowFor(event
->xcolormap
.window
);
1232 scr
= wwin
->screen_ptr
;
1236 if (event
->xcolormap
.new) {
1237 XWindowAttributes attr
;
1239 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1241 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1242 scr
->current_colormap
= attr
.colormap
;
1245 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1246 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1248 /* some bastard app (like XV) removed our colormap */
1250 * can't enforce or things like xscreensaver wont work
1253 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1254 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1256 /* someone has put our colormap back */
1260 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1261 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1263 if (reinstall
&& scr
->current_colormap
!= None
) {
1264 if (!scr
->flags
.colormap_stuff_blocked
)
1265 XInstallColormap(dpy
, scr
->current_colormap
);
1269 static void handleFocusIn(XEvent
* event
)
1274 * For applications that like stealing the focus.
1276 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1277 saveTimestamp(event
);
1278 if (event
->xfocus
.mode
== NotifyUngrab
1279 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1283 wwin
= wWindowFor(event
->xfocus
.window
);
1284 if (wwin
&& !wwin
->flags
.focused
) {
1285 if (wwin
->flags
.mapped
)
1286 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1288 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1290 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1292 wSetFocusTo(scr
, NULL
);
1296 static WWindow
*windowUnderPointer(WScreen
* scr
)
1302 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1303 return wWindowFor(win
);
1307 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1309 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1315 static void handleKeyPress(XEvent
* event
)
1317 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1318 WWindow
*wwin
= scr
->focused_window
;
1322 #ifdef KEEP_XKB_LOCK_STATUS
1323 XkbStateRec staterec
;
1324 #endif /*KEEP_XKB_LOCK_STATUS */
1326 /* ignore CapsLock */
1327 modifiers
= event
->xkey
.state
& w_global
.shortcut
.modifiers_mask
;
1329 for (i
= 0; i
< WKBD_LAST
; i
++) {
1330 if (wKeyBindings
[i
].keycode
== 0)
1333 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1334 || */ wKeyBindings
[i
].modifier
==
1343 if (!wRootMenuPerformShortcut(event
)) {
1344 static int dontLoop
= 0;
1346 if (dontLoop
> 10) {
1347 wwarning("problem with key event processing code");
1351 /* if the focused window is an internal window, try redispatching
1352 * the event to the managed window, as it can be a WINGs window */
1353 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1354 /* client_leader contains the WINGs toplevel */
1355 event
->xany
.window
= wwin
->client_leader
;
1356 WMHandleEvent(event
);
1362 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1363 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1368 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1369 if (!CheckFullScreenWindowFocused(scr
)) {
1370 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1371 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1375 case WKBD_WINDOWLIST
:
1376 if (!CheckFullScreenWindowFocused(scr
)) {
1377 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1378 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1383 case WKBD_WINDOWMENU
:
1384 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1385 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1387 case WKBD_MINIMIZEALL
:
1388 CloseWindowMenu(scr
);
1391 case WKBD_MINIATURIZE
:
1392 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1393 && !WFLAGP(wwin
, no_miniaturizable
)) {
1394 CloseWindowMenu(scr
);
1396 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1397 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
, event
->xbutton
.time
);
1399 wIconifyWindow(wwin
);
1404 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1405 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1406 CloseWindowMenu(scr
);
1408 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1409 wHideApplication(wapp
);
1413 case WKBD_HIDE_OTHERS
:
1414 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1415 CloseWindowMenu(scr
);
1417 wHideOtherApplications(wwin
);
1421 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1422 CloseWindowMenu(scr
);
1424 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1427 case WKBD_VMAXIMIZE
:
1428 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1429 CloseWindowMenu(scr
);
1431 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1434 case WKBD_HMAXIMIZE
:
1435 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1436 CloseWindowMenu(scr
);
1438 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1441 case WKBD_LHMAXIMIZE
:
1442 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1443 CloseWindowMenu(scr
);
1445 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1448 case WKBD_RHMAXIMIZE
:
1449 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1450 CloseWindowMenu(scr
);
1452 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1455 case WKBD_THMAXIMIZE
:
1456 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1457 CloseWindowMenu(scr
);
1459 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1462 case WKBD_BHMAXIMIZE
:
1463 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1464 CloseWindowMenu(scr
);
1466 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1469 case WKBD_LTCMAXIMIZE
:
1470 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1471 CloseWindowMenu(scr
);
1473 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1476 case WKBD_RTCMAXIMIZE
:
1477 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1478 CloseWindowMenu(scr
);
1480 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1483 case WKBD_LBCMAXIMIZE
:
1484 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1485 CloseWindowMenu(scr
);
1487 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1490 case WKBD_RBCMAXIMIZE
:
1491 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1492 CloseWindowMenu(scr
);
1494 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1498 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1499 CloseWindowMenu(scr
);
1501 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1505 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1506 CloseWindowMenu(scr
);
1508 wRaiseFrame(wwin
->frame
->core
);
1512 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1513 CloseWindowMenu(scr
);
1515 wLowerFrame(wwin
->frame
->core
);
1518 case WKBD_RAISELOWER
:
1519 /* raise or lower the window under the pointer, not the
1522 wwin
= windowUnderPointer(scr
);
1524 wRaiseLowerFrame(wwin
->frame
->core
);
1527 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1528 if (wwin
->flags
.shaded
)
1529 wUnshadeWindow(wwin
);
1534 case WKBD_MOVERESIZE
:
1535 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1536 CloseWindowMenu(scr
);
1538 wKeyboardMoveResizeWindow(wwin
);
1542 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1543 CloseWindowMenu(scr
);
1544 if (wwin
->protocols
.DELETE_WINDOW
)
1545 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
, event
->xkey
.time
);
1549 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1550 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1553 case WKBD_FOCUSNEXT
:
1554 StartWindozeCycle(wwin
, event
, True
, False
);
1557 case WKBD_FOCUSPREV
:
1558 StartWindozeCycle(wwin
, event
, False
, False
);
1561 case WKBD_GROUPNEXT
:
1562 StartWindozeCycle(wwin
, event
, True
, True
);
1565 case WKBD_GROUPPREV
:
1566 StartWindozeCycle(wwin
, event
, False
, True
);
1569 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1570 widx
= command
- WKBD_WORKSPACE1
;
1571 i
= (w_global
.workspace
.current
/ 10) * 10 + widx
;
1572 if (wPreferences
.ws_advance
|| i
< w_global
.workspace
.count
)
1573 wWorkspaceChange(scr
, i
);
1576 case WKBD_NEXTWORKSPACE
:
1577 wWorkspaceRelativeChange(scr
, 1);
1579 case WKBD_PREVWORKSPACE
:
1580 wWorkspaceRelativeChange(scr
, -1);
1582 case WKBD_LASTWORKSPACE
:
1583 wWorkspaceChange(scr
, w_global
.workspace
.last_used
);
1586 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1587 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1588 i
= (w_global
.workspace
.current
/ 10) * 10 + widx
;
1589 if (wwin
&& (wPreferences
.ws_advance
|| i
< w_global
.workspace
.count
))
1590 wWindowChangeWorkspace(wwin
, i
);
1593 case WKBD_MOVE_NEXTWORKSPACE
:
1595 wWindowChangeWorkspaceRelative(wwin
, 1);
1597 case WKBD_MOVE_PREVWORKSPACE
:
1599 wWindowChangeWorkspaceRelative(wwin
, -1);
1601 case WKBD_MOVE_LASTWORKSPACE
:
1603 wWindowChangeWorkspace(wwin
, w_global
.workspace
.last_used
);
1606 case WKBD_MOVE_NEXTWSLAYER
:
1607 case WKBD_MOVE_PREVWSLAYER
:
1612 row
= w_global
.workspace
.current
/ 10;
1613 column
= w_global
.workspace
.current
% 10;
1615 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1616 if ((row
+ 1) * 10 < w_global
.workspace
.count
)
1617 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1620 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1637 widx
= command
- WKBD_WINDOW1
;
1639 if (w_global
.shortcut
.windows
[widx
]) {
1640 WMArray
*list
= w_global
.shortcut
.windows
[widx
];
1642 int count
= WMGetArrayItemCount(list
);
1644 WMArrayIterator iter
;
1647 wUnselectWindows(scr
);
1648 cw
= w_global
.workspace
.current
;
1650 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1652 wWindowChangeWorkspace(wwin
, cw
);
1654 wMakeWindowVisible(wwin
);
1657 wSelectWindow(wwin
, True
);
1660 /* rotate the order of windows, to create a cycling effect */
1661 twin
= WMGetFromArray(list
, 0);
1662 WMDeleteFromArray(list
, 0);
1663 WMAddToArray(list
, twin
);
1665 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1666 if (w_global
.shortcut
.windows
[widx
]) {
1667 WMFreeArray(w_global
.shortcut
.windows
[widx
]);
1668 w_global
.shortcut
.windows
[widx
] = NULL
;
1671 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1672 w_global
.shortcut
.windows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1674 w_global
.shortcut
.windows
[widx
] = WMCreateArray(4);
1675 WMAddToArray(w_global
.shortcut
.windows
[widx
], wwin
);
1678 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1681 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1684 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1685 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1686 if (w_global
.shortcut
.windows
[widx
])
1687 WMFreeArray(w_global
.shortcut
.windows
[widx
]);
1689 w_global
.shortcut
.windows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1696 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1697 (void) RelaunchWindow(wwin
);
1701 case WKBD_SWITCH_SCREEN
:
1702 if (w_global
.screen_count
> 1) {
1706 /* find index of this screen */
1707 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1708 if (wScreenWithNumber(i
) == scr
)
1712 if (i
>= w_global
.screen_count
) {
1715 scr2
= wScreenWithNumber(i
);
1718 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1719 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1728 cmdline
= ExpandOptions(scr
, _("exec %a(Run,Type command to run:)"));
1731 XGrabPointer(dpy
, scr
->root_win
, True
, 0,
1732 GrabModeAsync
, GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_WAIT
], CurrentTime
);
1735 ExecuteShellCommand(scr
, cmdline
);
1738 XUngrabPointer(dpy
, CurrentTime
);
1744 case WKBD_NEXTWSLAYER
:
1745 case WKBD_PREVWSLAYER
:
1749 row
= w_global
.workspace
.current
/ 10;
1750 column
= w_global
.workspace
.current
% 10;
1752 if (command
== WKBD_NEXTWSLAYER
) {
1753 if ((row
+ 1) * 10 < w_global
.workspace
.count
)
1754 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1757 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1761 case WKBD_CLIPRAISELOWER
:
1762 if (!wPreferences
.flags
.noclip
)
1763 wDockRaiseLower(w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
);
1765 case WKBD_DOCKRAISELOWER
:
1766 if (!wPreferences
.flags
.nodock
)
1767 wDockRaiseLower(scr
->dock
);
1769 #ifdef KEEP_XKB_LOCK_STATUS
1771 if (wPreferences
.modelock
) {
1773 wwin
= scr
->focused_window
;
1775 if (wwin
&& wwin
->flags
.mapped
1776 && wwin
->frame
->workspace
== w_global
.workspace
.current
1777 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1778 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1780 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1781 wwin
->frame
->last_languagemode
= staterec
.group
;
1782 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1787 #endif /* KEEP_XKB_LOCK_STATUS */
1791 static void handleMotionNotify(XEvent
* event
)
1793 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1795 if (wPreferences
.scrollable_menus
) {
1796 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1797 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1799 if (scr
->flags
.jump_back_pending
||
1800 p
.x
<= (rect
.pos
.x
+ 1) ||
1801 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1802 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1805 menu
= wMenuUnderPointer(scr
);
1812 static void handleVisibilityNotify(XEvent
* event
)
1816 wwin
= wWindowFor(event
->xvisibility
.window
);
1819 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);