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 executeWheelAction(WScreen
*scr
, XEvent
*event
, int action
)
710 if (event
->xbutton
.button
== Button5
|| event
->xbutton
.button
== Button6
)
711 next_direction
= False
;
713 next_direction
= True
;
716 case WA_SWITCH_WORKSPACES
:
718 wWorkspaceRelativeChange(scr
, 1);
720 wWorkspaceRelativeChange(scr
, -1);
723 case WA_SWITCH_WINDOWS
:
724 wwin
= scr
->focused_window
;
726 wWindowFocusNext(wwin
, True
);
728 wWindowFocusPrev(wwin
, True
);
733 static void executeButtonAction(WScreen
*scr
, XEvent
*event
, int action
)
738 case WA_SELECT_WINDOWS
:
739 wUnselectWindows(scr
);
740 wSelectWindows(scr
, event
);
742 case WA_OPEN_APPMENU
:
743 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
745 if (scr
->root_menu
) {
746 if (scr
->root_menu
->brother
->flags
.mapped
)
747 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
749 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
752 case WA_OPEN_WINLISTMENU
:
753 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
754 if (scr
->switch_menu
) {
755 if (scr
->switch_menu
->brother
->flags
.mapped
)
756 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
758 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
761 case WA_MOVE_PREVWORKSPACE
:
762 wWorkspaceRelativeChange(scr
, -1);
764 case WA_MOVE_NEXTWORKSPACE
:
765 wWorkspaceRelativeChange(scr
, 1);
767 case WA_MOVE_PREVWINDOW
:
768 wwin
= scr
->focused_window
;
769 wWindowFocusPrev(wwin
, True
);
771 case WA_MOVE_NEXTWINDOW
:
772 wwin
= scr
->focused_window
;
773 wWindowFocusNext(wwin
, True
);
779 static void handleButtonPress(XEvent
* event
)
781 WObjDescriptor
*desc
;
784 scr
= wScreenForRootWindow(event
->xbutton
.root
);
790 if (!wPreferences
.disable_root_mouse
&& event
->xbutton
.window
== scr
->root_win
) {
791 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
792 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
793 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
794 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
795 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
796 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
797 } else if (event
->xbutton
.button
== Button8
&& wPreferences
.mouse_button8
!= WA_NONE
) {
798 executeButtonAction(scr
, event
, wPreferences
.mouse_button8
);
799 }else if (event
->xbutton
.button
== Button9
&& wPreferences
.mouse_button9
!= WA_NONE
) {
800 executeButtonAction(scr
, event
, wPreferences
.mouse_button9
);
801 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel_scroll
!= WA_NONE
) {
802 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_scroll
);
803 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel_scroll
!= WA_NONE
) {
804 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_scroll
);
805 } else if (event
->xbutton
.button
== Button6
&& wPreferences
.mouse_wheel_tilt
!= WA_NONE
) {
806 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_tilt
);
807 } else if (event
->xbutton
.button
== Button7
&& wPreferences
.mouse_wheel_tilt
!= WA_NONE
) {
808 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_tilt
);
813 if (XFindContext(dpy
, event
->xbutton
.subwindow
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
814 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
819 if (desc
->parent_type
== WCLASS_WINDOW
) {
822 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
823 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
825 /* if (wPreferences.focus_mode == WKF_CLICK) { */
826 if (wPreferences
.ignore_focus_click
) {
827 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
829 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
833 } else if (desc
->parent_type
== WCLASS_APPICON
834 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
835 if (event
->xbutton
.state
& MOD_MASK
) {
837 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
842 if (desc
->handle_mousedown
!= NULL
) {
843 (*desc
->handle_mousedown
) (desc
, event
);
846 /* save double-click information */
847 if (scr
->flags
.next_click_is_not_double
) {
848 scr
->flags
.next_click_is_not_double
= 0;
850 scr
->last_click_time
= event
->xbutton
.time
;
851 scr
->last_click_button
= event
->xbutton
.button
;
852 scr
->last_click_window
= event
->xbutton
.window
;
856 static void handleMapNotify(XEvent
* event
)
860 wwin
= wWindowFor(event
->xmap
.event
);
861 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
862 if (wwin
->flags
.miniaturized
) {
863 wDeiconifyWindow(wwin
);
867 wClientSetState(wwin
, NormalState
, None
);
873 static void handleUnmapNotify(XEvent
* event
)
877 Bool withdraw
= False
;
879 /* only process windows with StructureNotify selected
880 * (ignore SubstructureNotify) */
881 wwin
= wWindowFor(event
->xunmap
.window
);
885 /* whether the event is a Withdrawal request */
886 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
889 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
892 if (!wwin
->flags
.mapped
&& !withdraw
893 && wwin
->frame
->workspace
== w_global
.workspace
.current
894 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
898 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
899 wwin
->flags
.mapped
= 0;
901 /* check if the window was destroyed */
902 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
905 Bool reparented
= False
;
907 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
910 /* withdraw window */
911 wwin
->flags
.mapped
= 0;
913 wClientSetState(wwin
, WithdrawnState
, None
);
915 /* if the window was reparented, do not reparent it back to the
917 wUnmanageWindow(wwin
, !reparented
, False
);
922 static void handleConfigureRequest(XEvent
* event
)
926 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
928 * Configure request for unmapped window
930 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
932 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
936 static void handlePropertyNotify(XEvent
* event
)
944 wwin
= wWindowFor(event
->xproperty
.window
);
946 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
949 wClientCheckProperty(wwin
, &event
->xproperty
);
951 wapp
= wApplicationOf(event
->xproperty
.window
);
953 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
957 static void handleClientMessage(XEvent
* event
)
960 WObjDescriptor
*desc
;
962 /* handle transition from Normal to Iconic state */
963 if (event
->xclient
.message_type
== w_global
.atom
.wm
.change_state
964 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
966 wwin
= wWindowFor(event
->xclient
.window
);
969 if (!wwin
->flags
.miniaturized
)
970 wIconifyWindow(wwin
);
971 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.colormap_notify
&& event
->xclient
.format
== 32) {
972 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
977 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
978 wColormapAllowClientInstallation(scr
, True
);
979 } else { /* stopping */
980 wColormapAllowClientInstallation(scr
, False
);
982 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.command
) {
987 len
= sizeof(event
->xclient
.data
.b
) + 1;
988 command
= wmalloc(len
);
989 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
991 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
992 wwarning(_("Got Reconfigure command"));
993 wDefaultsCheckDomains(NULL
);
995 wwarning(_("Got unknown command %s"), command
);
1000 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.wm_function
) {
1003 wapp
= wApplicationOf(event
->xclient
.window
);
1005 switch (event
->xclient
.data
.l
[0]) {
1006 case WMFHideOtherApplications
:
1007 wHideOtherApplications(wapp
->main_window_desc
);
1011 case WMFHideApplication
:
1012 wHideApplication(wapp
);
1018 wwin
= wWindowFor(event
->xclient
.window
);
1020 switch (event
->xclient
.data
.l
[0]) {
1021 case WMFHideOtherApplications
:
1022 wHideOtherApplications(wwin
);
1025 case WMFHideApplication
:
1026 wHideApplication(wApplicationOf(wwin
->main_window
));
1031 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.wm_attr
) {
1032 wwin
= wWindowFor(event
->xclient
.window
);
1035 switch (event
->xclient
.data
.l
[0]) {
1036 case GSWindowLevelAttr
:
1038 int level
= (int)event
->xclient
.data
.l
[1];
1040 if (WINDOW_LEVEL(wwin
) != level
) {
1041 ChangeStackingLevel(wwin
->frame
->core
, level
);
1046 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.titlebar_state
) {
1047 wwin
= wWindowFor(event
->xclient
.window
);
1050 switch (event
->xclient
.data
.l
[0]) {
1051 case WMTitleBarNormal
:
1052 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1054 case WMTitleBarMain
:
1055 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1058 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1061 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.ignore_focus_events
) {
1062 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1065 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1066 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1069 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1074 * Non-standard thing, but needed by OffiX DND.
1075 * For when the icon frame gets a ClientMessage
1076 * that should have gone to the icon_window.
1078 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1079 struct WIcon
*icon
= NULL
;
1081 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1082 icon
= (WIcon
*) desc
->parent
;
1083 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1084 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1086 if (icon
&& (wwin
= icon
->owner
)) {
1087 if (wwin
->client_win
!= event
->xclient
.window
) {
1088 event
->xclient
.window
= wwin
->client_win
;
1089 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1096 static void raiseWindow(WScreen
* scr
)
1100 scr
->autoRaiseTimer
= NULL
;
1102 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1106 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1107 wRaiseFrame(wwin
->frame
->core
);
1108 /* this is needed or a race condition will occur */
1113 static void handleEnterNotify(XEvent
* event
)
1116 WObjDescriptor
*desc
= NULL
;
1118 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1120 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1121 /* already left the window... */
1123 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1128 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1129 if (desc
->handle_enternotify
)
1130 (*desc
->handle_enternotify
) (desc
, event
);
1133 /* enter to window */
1134 wwin
= wWindowFor(event
->xcrossing
.window
);
1136 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1137 wColormapInstallForWindow(scr
, NULL
);
1139 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1140 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1141 scr
->autoRaiseTimer
= NULL
;
1144 /* set auto raise timer even if in focus-follows-mouse mode
1145 * and the event is for the frame window, even if the window
1146 * has focus already. useful if you move the pointer from a focused
1147 * window to the root window and back pretty fast
1149 * set focus if in focus-follows-mouse mode and the event
1150 * is for the frame window and window doesn't have focus yet */
1151 if (wPreferences
.focus_mode
== WKF_SLOPPY
1152 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1154 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1155 wSetFocusTo(scr
, wwin
);
1157 if (scr
->autoRaiseTimer
)
1158 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1159 scr
->autoRaiseTimer
= NULL
;
1161 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1162 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1164 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1167 /* Install colormap for window, if the colormap installation mode
1168 * is colormap_follows_mouse */
1169 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1170 if (wwin
->client_win
== event
->xcrossing
.window
)
1171 wColormapInstallForWindow(scr
, wwin
);
1173 wColormapInstallForWindow(scr
, NULL
);
1177 if (event
->xcrossing
.window
== event
->xcrossing
.root
1178 && event
->xcrossing
.detail
== NotifyNormal
1179 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1181 wSetFocusTo(scr
, scr
->focused_window
);
1184 wBalloonEnteredObject(scr
, desc
);
1188 static void handleLeaveNotify(XEvent
* event
)
1190 WObjDescriptor
*desc
= NULL
;
1192 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1193 if (desc
->handle_leavenotify
)
1194 (*desc
->handle_leavenotify
) (desc
, event
);
1199 static void handleShapeNotify(XEvent
* event
)
1201 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1208 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1209 if (ev
.xshape
.kind
== ShapeBounding
) {
1210 if (ev
.xshape
.shaped
== shev
->shaped
) {
1213 XPutBackEvent(dpy
, &ev
.xevent
);
1219 wwin
= wWindowFor(shev
->window
);
1220 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1223 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1225 wwin
->flags
.shaped
= 0;
1226 wWindowClearShape(wwin
);
1228 } else if (shev
->shaped
) {
1230 wwin
->flags
.shaped
= 1;
1231 wWindowSetShape(wwin
);
1234 #endif /* USE_XSHAPE */
1236 #ifdef KEEP_XKB_LOCK_STATUS
1237 /* please help ]d if you know what to do */
1238 static void handleXkbIndicatorStateNotify(XkbEvent
*event
)
1242 XkbStateRec staterec
;
1245 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1246 scr
= wScreenWithNumber(i
);
1247 wwin
= scr
->focused_window
;
1248 if (wwin
&& wwin
->flags
.focused
) {
1249 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1250 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1251 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1252 wwin
->frame
->languagemode
= staterec
.group
;
1254 #ifdef XKB_BUTTON_HINT
1255 if (wwin
->frame
->titlebar
) {
1256 wFrameWindowPaint(wwin
->frame
);
1262 #endif /*KEEP_XKB_LOCK_STATUS */
1264 static void handleColormapNotify(XEvent
* event
)
1268 Bool reinstall
= False
;
1270 wwin
= wWindowFor(event
->xcolormap
.window
);
1274 scr
= wwin
->screen_ptr
;
1278 if (event
->xcolormap
.new) {
1279 XWindowAttributes attr
;
1281 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1283 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1284 scr
->current_colormap
= attr
.colormap
;
1287 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1288 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1290 /* some bastard app (like XV) removed our colormap */
1292 * can't enforce or things like xscreensaver wont work
1295 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1296 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1298 /* someone has put our colormap back */
1302 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1303 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1305 if (reinstall
&& scr
->current_colormap
!= None
) {
1306 if (!scr
->flags
.colormap_stuff_blocked
)
1307 XInstallColormap(dpy
, scr
->current_colormap
);
1311 static void handleFocusIn(XEvent
* event
)
1316 * For applications that like stealing the focus.
1318 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1319 saveTimestamp(event
);
1320 if (event
->xfocus
.mode
== NotifyUngrab
1321 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1325 wwin
= wWindowFor(event
->xfocus
.window
);
1326 if (wwin
&& !wwin
->flags
.focused
) {
1327 if (wwin
->flags
.mapped
)
1328 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1330 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1332 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1334 wSetFocusTo(scr
, NULL
);
1338 static WWindow
*windowUnderPointer(WScreen
* scr
)
1344 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1345 return wWindowFor(win
);
1349 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1351 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1357 static void handleKeyPress(XEvent
* event
)
1359 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1360 WWindow
*wwin
= scr
->focused_window
;
1364 #ifdef KEEP_XKB_LOCK_STATUS
1365 XkbStateRec staterec
;
1366 #endif /*KEEP_XKB_LOCK_STATUS */
1368 /* ignore CapsLock */
1369 modifiers
= event
->xkey
.state
& w_global
.shortcut
.modifiers_mask
;
1371 for (i
= 0; i
< WKBD_LAST
; i
++) {
1372 if (wKeyBindings
[i
].keycode
== 0)
1375 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1376 || */ wKeyBindings
[i
].modifier
==
1385 if (!wRootMenuPerformShortcut(event
)) {
1386 static int dontLoop
= 0;
1388 if (dontLoop
> 10) {
1389 wwarning("problem with key event processing code");
1393 /* if the focused window is an internal window, try redispatching
1394 * the event to the managed window, as it can be a WINGs window */
1395 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1396 /* client_leader contains the WINGs toplevel */
1397 event
->xany
.window
= wwin
->client_leader
;
1398 WMHandleEvent(event
);
1404 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1405 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1410 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1411 if (!CheckFullScreenWindowFocused(scr
)) {
1412 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1413 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1417 case WKBD_WINDOWLIST
:
1418 if (!CheckFullScreenWindowFocused(scr
)) {
1419 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1420 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1425 case WKBD_WINDOWMENU
:
1426 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1427 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1429 case WKBD_MINIMIZEALL
:
1430 CloseWindowMenu(scr
);
1433 case WKBD_MINIATURIZE
:
1434 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1435 && !WFLAGP(wwin
, no_miniaturizable
)) {
1436 CloseWindowMenu(scr
);
1438 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1439 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
, event
->xbutton
.time
);
1441 wIconifyWindow(wwin
);
1446 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1447 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1448 CloseWindowMenu(scr
);
1450 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1451 wHideApplication(wapp
);
1455 case WKBD_HIDE_OTHERS
:
1456 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1457 CloseWindowMenu(scr
);
1459 wHideOtherApplications(wwin
);
1463 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1464 CloseWindowMenu(scr
);
1466 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1469 case WKBD_VMAXIMIZE
:
1470 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1471 CloseWindowMenu(scr
);
1473 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1476 case WKBD_HMAXIMIZE
:
1477 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1478 CloseWindowMenu(scr
);
1480 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1483 case WKBD_LHMAXIMIZE
:
1484 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1485 CloseWindowMenu(scr
);
1487 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1490 case WKBD_RHMAXIMIZE
:
1491 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1492 CloseWindowMenu(scr
);
1494 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1497 case WKBD_THMAXIMIZE
:
1498 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1499 CloseWindowMenu(scr
);
1501 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1504 case WKBD_BHMAXIMIZE
:
1505 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1506 CloseWindowMenu(scr
);
1508 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1511 case WKBD_LTCMAXIMIZE
:
1512 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1513 CloseWindowMenu(scr
);
1515 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1518 case WKBD_RTCMAXIMIZE
:
1519 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1520 CloseWindowMenu(scr
);
1522 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1525 case WKBD_LBCMAXIMIZE
:
1526 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1527 CloseWindowMenu(scr
);
1529 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1532 case WKBD_RBCMAXIMIZE
:
1533 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1534 CloseWindowMenu(scr
);
1536 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1540 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1541 CloseWindowMenu(scr
);
1543 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1547 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1548 CloseWindowMenu(scr
);
1550 wRaiseFrame(wwin
->frame
->core
);
1554 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1555 CloseWindowMenu(scr
);
1557 wLowerFrame(wwin
->frame
->core
);
1560 case WKBD_RAISELOWER
:
1561 /* raise or lower the window under the pointer, not the
1564 wwin
= windowUnderPointer(scr
);
1566 wRaiseLowerFrame(wwin
->frame
->core
);
1569 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1570 if (wwin
->flags
.shaded
)
1571 wUnshadeWindow(wwin
);
1576 case WKBD_MOVERESIZE
:
1577 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1578 CloseWindowMenu(scr
);
1580 wKeyboardMoveResizeWindow(wwin
);
1584 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1585 CloseWindowMenu(scr
);
1586 if (wwin
->protocols
.DELETE_WINDOW
)
1587 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
, event
->xkey
.time
);
1591 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1592 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1595 case WKBD_FOCUSNEXT
:
1596 StartWindozeCycle(wwin
, event
, True
, False
);
1599 case WKBD_FOCUSPREV
:
1600 StartWindozeCycle(wwin
, event
, False
, False
);
1603 case WKBD_GROUPNEXT
:
1604 StartWindozeCycle(wwin
, event
, True
, True
);
1607 case WKBD_GROUPPREV
:
1608 StartWindozeCycle(wwin
, event
, False
, True
);
1611 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1612 widx
= command
- WKBD_WORKSPACE1
;
1613 i
= (w_global
.workspace
.current
/ 10) * 10 + widx
;
1614 if (wPreferences
.ws_advance
|| i
< w_global
.workspace
.count
)
1615 wWorkspaceChange(scr
, i
);
1618 case WKBD_NEXTWORKSPACE
:
1619 wWorkspaceRelativeChange(scr
, 1);
1621 case WKBD_PREVWORKSPACE
:
1622 wWorkspaceRelativeChange(scr
, -1);
1624 case WKBD_LASTWORKSPACE
:
1625 wWorkspaceChange(scr
, w_global
.workspace
.last_used
);
1628 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1629 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1630 i
= (w_global
.workspace
.current
/ 10) * 10 + widx
;
1631 if (wwin
&& (wPreferences
.ws_advance
|| i
< w_global
.workspace
.count
))
1632 wWindowChangeWorkspace(wwin
, i
);
1635 case WKBD_MOVE_NEXTWORKSPACE
:
1637 wWindowChangeWorkspaceRelative(wwin
, 1);
1639 case WKBD_MOVE_PREVWORKSPACE
:
1641 wWindowChangeWorkspaceRelative(wwin
, -1);
1643 case WKBD_MOVE_LASTWORKSPACE
:
1645 wWindowChangeWorkspace(wwin
, w_global
.workspace
.last_used
);
1648 case WKBD_MOVE_NEXTWSLAYER
:
1649 case WKBD_MOVE_PREVWSLAYER
:
1654 row
= w_global
.workspace
.current
/ 10;
1655 column
= w_global
.workspace
.current
% 10;
1657 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1658 if ((row
+ 1) * 10 < w_global
.workspace
.count
)
1659 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1662 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1679 widx
= command
- WKBD_WINDOW1
;
1681 if (w_global
.shortcut
.windows
[widx
]) {
1682 WMArray
*list
= w_global
.shortcut
.windows
[widx
];
1684 int count
= WMGetArrayItemCount(list
);
1686 WMArrayIterator iter
;
1689 wUnselectWindows(scr
);
1690 cw
= w_global
.workspace
.current
;
1692 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1694 wWindowChangeWorkspace(wwin
, cw
);
1696 wMakeWindowVisible(wwin
);
1699 wSelectWindow(wwin
, True
);
1702 /* rotate the order of windows, to create a cycling effect */
1703 twin
= WMGetFromArray(list
, 0);
1704 WMDeleteFromArray(list
, 0);
1705 WMAddToArray(list
, twin
);
1707 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1708 if (w_global
.shortcut
.windows
[widx
]) {
1709 WMFreeArray(w_global
.shortcut
.windows
[widx
]);
1710 w_global
.shortcut
.windows
[widx
] = NULL
;
1713 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1714 w_global
.shortcut
.windows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1716 w_global
.shortcut
.windows
[widx
] = WMCreateArray(4);
1717 WMAddToArray(w_global
.shortcut
.windows
[widx
], wwin
);
1720 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1723 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1726 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1727 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1728 if (w_global
.shortcut
.windows
[widx
])
1729 WMFreeArray(w_global
.shortcut
.windows
[widx
]);
1731 w_global
.shortcut
.windows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1738 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1739 (void) RelaunchWindow(wwin
);
1743 case WKBD_SWITCH_SCREEN
:
1744 if (w_global
.screen_count
> 1) {
1748 /* find index of this screen */
1749 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1750 if (wScreenWithNumber(i
) == scr
)
1754 if (i
>= w_global
.screen_count
) {
1757 scr2
= wScreenWithNumber(i
);
1760 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1761 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1770 cmdline
= ExpandOptions(scr
, _("exec %a(Run,Type command to run:)"));
1773 XGrabPointer(dpy
, scr
->root_win
, True
, 0,
1774 GrabModeAsync
, GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_WAIT
], CurrentTime
);
1777 ExecuteShellCommand(scr
, cmdline
);
1780 XUngrabPointer(dpy
, CurrentTime
);
1786 case WKBD_NEXTWSLAYER
:
1787 case WKBD_PREVWSLAYER
:
1791 row
= w_global
.workspace
.current
/ 10;
1792 column
= w_global
.workspace
.current
% 10;
1794 if (command
== WKBD_NEXTWSLAYER
) {
1795 if ((row
+ 1) * 10 < w_global
.workspace
.count
)
1796 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1799 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1803 case WKBD_CLIPRAISELOWER
:
1804 if (!wPreferences
.flags
.noclip
)
1805 wDockRaiseLower(w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
);
1807 case WKBD_DOCKRAISELOWER
:
1808 if (!wPreferences
.flags
.nodock
)
1809 wDockRaiseLower(scr
->dock
);
1811 #ifdef KEEP_XKB_LOCK_STATUS
1813 if (wPreferences
.modelock
) {
1815 wwin
= scr
->focused_window
;
1817 if (wwin
&& wwin
->flags
.mapped
1818 && wwin
->frame
->workspace
== w_global
.workspace
.current
1819 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1820 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1822 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1823 wwin
->frame
->last_languagemode
= staterec
.group
;
1824 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1829 #endif /* KEEP_XKB_LOCK_STATUS */
1833 static void handleMotionNotify(XEvent
* event
)
1835 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1837 if (wPreferences
.scrollable_menus
) {
1838 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1839 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1841 if (scr
->flags
.jump_back_pending
||
1842 p
.x
<= (rect
.pos
.x
+ 1) ||
1843 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1844 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1847 menu
= wMenuUnderPointer(scr
);
1854 static void handleVisibilityNotify(XEvent
* event
)
1858 wwin
= wWindowFor(event
->xvisibility
.window
);
1861 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);