1 /* event.c- event loop and handling
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <sys/select.h>
26 #include <sys/inotify.h>
37 #include <X11/Xutil.h>
39 # include <X11/extensions/shape.h>
46 #include <X11/extensions/Xrandr.h>
49 #ifdef KEEP_XKB_LOCK_STATUS
50 #include <X11/XKBlib.h>
51 #endif /* KEEP_XKB_LOCK_STATUS */
53 #include "WindowMaker.h"
60 #include "application.h"
63 #include "workspace.h"
66 #include "properties.h"
77 #include "switchmenu.h"
79 /******** Global Variables **********/
80 extern XContext wWinContext
;
81 extern XContext wVEdgeContext
;
83 extern WShortKey wKeyBindings
[WKBD_LAST
];
84 extern int wScreenCount
;
86 #define MOD_MASK wPreferences.modifier_mask
88 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
89 extern Atom _XA_WINDOWMAKER_COMMAND
;
92 extern Bool wShapeSupported
;
93 extern int wShapeEventBase
;
96 #ifdef KEEP_XKB_LOCK_STATUS
97 extern int wXkbEventBase
;
100 /************ Local stuff ***********/
102 static void saveTimestamp(XEvent
*event
);
103 static void handleColormapNotify(XEvent
*event
);
104 static void handleMapNotify(XEvent
*event
);
105 static void handleUnmapNotify(XEvent
*event
);
106 static void handleButtonPress(XEvent
*event
);
107 static void handleExpose(XEvent
*event
);
108 static void handleDestroyNotify(XEvent
*event
);
109 static void handleConfigureRequest(XEvent
*event
);
110 static void handleMapRequest(XEvent
*event
);
111 static void handlePropertyNotify(XEvent
*event
);
112 static void handleEnterNotify(XEvent
*event
);
113 static void handleLeaveNotify(XEvent
*event
);
114 static void handleExtensions(XEvent
*event
);
115 static void handleClientMessage(XEvent
*event
);
116 static void handleKeyPress(XEvent
*event
);
117 static void handleFocusIn(XEvent
*event
);
118 static void handleMotionNotify(XEvent
*event
);
119 static void handleVisibilityNotify(XEvent
*event
);
120 static void handle_inotify_events(int fd
, int wd
);
121 static void wdelete_death_handler(WMagicNumber id
);
125 static void handleShapeNotify(XEvent
*event
);
128 #ifdef KEEP_XKB_LOCK_STATUS
129 static void handleXkbIndicatorStateNotify(XEvent
*event
);
132 /* real dead process handler */
133 static void handleDeadProcess(void *foo
);
135 typedef struct DeadProcesses
{
137 unsigned char exit_status
;
140 /* stack of dead processes */
141 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
142 static int deadProcessPtr
= 0;
144 typedef struct DeathHandler
{
145 WDeathHandler
*callback
;
150 static WMArray
*deathHandlers
= NULL
;
152 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
154 DeathHandler
*handler
;
156 handler
= malloc(sizeof(DeathHandler
));
161 handler
->callback
= callback
;
162 handler
->client_data
= cdata
;
165 deathHandlers
= WMCreateArrayWithDestructor(8, free
);
167 WMAddToArray(deathHandlers
, handler
);
172 static void wdelete_death_handler(WMagicNumber id
)
174 DeathHandler
*handler
= (DeathHandler
*) id
;
176 if (!handler
|| !deathHandlers
)
179 /* array destructor will call free(handler) */
180 WMRemoveFromArray(deathHandlers
, handler
);
183 void DispatchEvent(XEvent
* event
)
186 handleDeadProcess(NULL
);
188 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
189 WCHANGE_STATE(WSTATE_EXITING
);
190 /* received SIGTERM */
192 * WMHandleEvent() can't be called from anything
193 * executed inside here, or we can get in a infinite
196 Shutdown(WSExitMode
);
198 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
199 WCHANGE_STATE(WSTATE_RESTARTING
);
201 Shutdown(WSRestartPreparationMode
);
202 /* received SIGHUP */
204 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
205 WCHANGE_STATE(WSTATE_NORMAL
);
206 wDefaultsCheckDomains(NULL
);
209 /* for the case that all that is wanted to be dispatched is
214 saveTimestamp(event
);
215 switch (event
->type
) {
217 handleMapRequest(event
);
221 handleKeyPress(event
);
225 handleMotionNotify(event
);
228 case ConfigureRequest
:
229 handleConfigureRequest(event
);
233 handleDestroyNotify(event
);
237 handleMapNotify(event
);
241 handleUnmapNotify(event
);
245 handleButtonPress(event
);
253 handlePropertyNotify(event
);
257 handleEnterNotify(event
);
261 handleLeaveNotify(event
);
265 handleClientMessage(event
);
269 handleColormapNotify(event
);
273 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
274 XRefreshKeyboardMapping(&event
->xmapping
);
278 handleFocusIn(event
);
281 case VisibilityNotify
:
282 handleVisibilityNotify(event
);
285 case ConfigureNotify
:
287 if (event
->xconfigure
.window
== DefaultRootWindow(dpy
))
288 XRRUpdateConfiguration(event
);
293 handleExtensions(event
);
300 *----------------------------------------------------------------------
301 * handle_inotify_events-
302 * Check for inotify events
305 * After reading events for the given file descriptor (fd) and
306 * watch descriptor (wd)
309 * Calls wDefaultsCheckDomains if config database is updated
310 *----------------------------------------------------------------------
312 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
313 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
314 static void handle_inotify_events(int fd
, int wd
)
316 ssize_t eventQLength
, i
= 0;
317 char buff
[BUFF_SIZE
] = { 0 };
318 /* Check config only once per read of the event queue */
322 * Read off the queued events
323 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
324 * not occur; the block is on Xevents, but a config file change will normally
325 * occur as a result of an Xevent - so the event queue should never have more than
326 * a few entries before a read().
328 eventQLength
= read(fd
, buff
, BUFF_SIZE
);
330 /* check what events occured */
331 /* Should really check wd here too, but for now we only have one watch! */
332 while (i
< eventQLength
) {
333 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
336 * see inotify.h for event types.
338 if (pevent
->mask
& IN_DELETE_SELF
) {
339 wwarning(_("the defaults database has been deleted!"
340 " Restart Window Maker to create the database" " with the default settings"));
343 if (pevent
->mask
& IN_UNMOUNT
) {
344 wwarning(_("the unit containing the defaults database has"
345 " been unmounted. Setting --static mode." " Any changes will not be saved."));
347 wPreferences
.flags
.noupdates
= 1;
349 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
350 wwarning(_("Inotify: Reading config files in defaults database."));
351 wDefaultsCheckDomains(NULL
);
354 /* move to next event in the buffer */
355 i
+= sizeof(struct inotify_event
) + pevent
->len
;
358 #endif /* HAVE_INOTIFY */
361 *----------------------------------------------------------------------
363 * Processes X and internal events indefinitely.
369 * The LastTimestamp global variable is updated.
370 * Calls inotifyGetEvents if defaults database changes.
371 *----------------------------------------------------------------------
373 noreturn
void EventLoop(void)
377 extern int inotifyFD
;
378 extern int inotifyWD
;
383 if (inotifyFD
< 0 || inotifyWD
< 0)
389 WMNextEvent(dpy
, &event
); /* Blocks here */
390 WMHandleEvent(&event
);
396 FD_SET(inotifyFD
, &rfds
);
398 /* check for available read data from inotify - don't block! */
399 retVal
= select(inotifyFD
+ 1, &rfds
, NULL
, NULL
, &time
);
401 if (retVal
< 0) { /* an error has occured */
402 wwarning(_("select failed. The inotify instance will be closed."
403 " Changes to the defaults database will require"
404 " a restart to take effect."));
408 if (FD_ISSET(inotifyFD
, &rfds
))
409 handle_inotify_events(inotifyFD
, inotifyWD
);
416 *----------------------------------------------------------------------
417 * ProcessPendingEvents --
418 * Processes the events that are currently pending (at the time
419 * this function is called) in the display's queue.
422 * After the pending events that were present at the function call
426 * Many -- whatever handling events may involve.
428 *----------------------------------------------------------------------
430 void ProcessPendingEvents(void)
437 /* Take a snapshot of the event count in the queue */
438 count
= XPending(dpy
);
440 while (count
> 0 && XPending(dpy
)) {
441 WMNextEvent(dpy
, &event
);
442 WMHandleEvent(&event
);
447 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
449 if ((scr
->last_click_time
> 0) &&
450 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
451 && (event
->xbutton
.button
== scr
->last_click_button
)
452 && (event
->xbutton
.window
== scr
->last_click_window
)) {
454 scr
->flags
.next_click_is_not_double
= 1;
455 scr
->last_click_time
= 0;
456 scr
->last_click_window
= event
->xbutton
.window
;
463 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
465 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
466 wwarning("stack overflow: too many dead processes");
469 /* stack the process to be handled later,
470 * as this is called from the signal handler */
471 deadProcesses
[deadProcessPtr
].pid
= pid
;
472 deadProcesses
[deadProcessPtr
].exit_status
= status
;
476 static void handleDeadProcess(void *foo
)
481 for (i
= 0; i
< deadProcessPtr
; i
++) {
482 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
485 if (!deathHandlers
) {
490 /* get the pids on the queue and call handlers */
491 while (deadProcessPtr
> 0) {
494 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
495 tmp
= WMGetFromArray(deathHandlers
, i
);
499 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
500 (*tmp
->callback
) (tmp
->pid
,
501 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
502 wdelete_death_handler(tmp
);
508 static void saveTimestamp(XEvent
* event
)
511 * Never save CurrentTime as LastTimestamp because CurrentTime
512 * it's not a real timestamp (it's the 0L constant)
515 switch (event
->type
) {
518 w_global
.timestamp
.last_event
= event
->xbutton
.time
;
522 w_global
.timestamp
.last_event
= event
->xkey
.time
;
525 w_global
.timestamp
.last_event
= event
->xmotion
.time
;
528 w_global
.timestamp
.last_event
= event
->xproperty
.time
;
532 w_global
.timestamp
.last_event
= event
->xcrossing
.time
;
535 w_global
.timestamp
.last_event
= event
->xselectionclear
.time
;
537 case SelectionRequest
:
538 w_global
.timestamp
.last_event
= event
->xselectionrequest
.time
;
540 case SelectionNotify
:
541 w_global
.timestamp
.last_event
= event
->xselection
.time
;
543 wXDNDProcessSelection(event
);
549 static int matchWindow(const void *item
, const void *cdata
)
551 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
554 static void handleExtensions(XEvent
* event
)
556 #ifdef KEEP_XKB_LOCK_STATUS
558 xkbevent
= (XkbEvent
*) event
;
559 #endif /*KEEP_XKB_LOCK_STATUS */
561 if (wShapeSupported
&& event
->type
== (wShapeEventBase
+ ShapeNotify
)) {
562 handleShapeNotify(event
);
565 #ifdef KEEP_XKB_LOCK_STATUS
566 if (wPreferences
.modelock
&& (xkbevent
->type
== wXkbEventBase
)) {
567 handleXkbIndicatorStateNotify(event
);
569 #endif /*KEEP_XKB_LOCK_STATUS */
571 if (has_randr
&& event
->type
== (randr_event_base
+ RRScreenChangeNotify
)) {
572 /* From xrandr man page: "Clients must call back into Xlib using
573 * XRRUpdateConfiguration when screen configuration change notify
574 * events are generated */
575 XRRUpdateConfiguration(event
);
576 WCHANGE_STATE(WSTATE_RESTARTING
);
577 Shutdown(WSRestartPreparationMode
);
583 static void handleMapRequest(XEvent
* ev
)
587 Window window
= ev
->xmaprequest
.window
;
589 if ((wwin
= wWindowFor(window
))) {
590 if (wwin
->flags
.shaded
) {
591 wUnshadeWindow(wwin
);
593 /* deiconify window */
594 if (wwin
->flags
.miniaturized
) {
595 wDeiconifyWindow(wwin
);
596 } else if (wwin
->flags
.hidden
) {
597 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
598 /* go to the last workspace that the user worked on the app */
600 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
602 wUnhideApplication(wapp
, False
, False
);
607 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
609 wwin
= wManageWindow(scr
, window
);
612 * This is to let the Dock know that the application it launched
613 * has already been mapped (eg: it has finished launching).
614 * It is not necessary for normally docked apps, but is needed for
615 * apps that were forcedly docked (like with dockit).
617 if (scr
->last_dock
) {
618 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
619 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
621 wDockTrackWindowLaunch(scr
->last_dock
, window
);
625 wClientSetState(wwin
, NormalState
, None
);
626 if (wwin
->flags
.maximized
) {
627 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
629 if (wwin
->flags
.shaded
) {
630 wwin
->flags
.shaded
= 0;
631 wwin
->flags
.skip_next_animation
= 1;
634 if (wwin
->flags
.miniaturized
) {
635 wwin
->flags
.miniaturized
= 0;
636 wwin
->flags
.skip_next_animation
= 1;
637 wIconifyWindow(wwin
);
639 if (wwin
->flags
.fullscreen
) {
640 wwin
->flags
.fullscreen
= 0;
641 wFullscreenWindow(wwin
);
643 if (wwin
->flags
.hidden
) {
644 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
646 wwin
->flags
.hidden
= 0;
647 wwin
->flags
.skip_next_animation
= 1;
649 wHideApplication(wapp
);
655 static void handleDestroyNotify(XEvent
* event
)
659 Window window
= event
->xdestroywindow
.window
;
660 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
663 wwin
= wWindowFor(window
);
665 wUnmanageWindow(wwin
, False
, True
);
669 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
670 WFakeGroupLeader
*fPtr
;
672 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
673 if (fPtr
->retainCount
> 0) {
675 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
676 XDestroyWindow(dpy
, fPtr
->leader
);
681 fPtr
->origLeader
= None
;
685 app
= wApplicationOf(window
);
687 if (window
== app
->main_window
) {
689 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
691 if (wwin
->main_window
== window
) {
692 wwin
->main_window
= None
;
697 wApplicationDestroy(app
);
701 static void handleExpose(XEvent
* event
)
703 WObjDescriptor
*desc
;
706 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
708 if (XFindContext(dpy
, event
->xexpose
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
712 if (desc
->handle_expose
) {
713 (*desc
->handle_expose
) (desc
, event
);
717 static void executeButtonAction(WScreen
* scr
, XEvent
* event
, int action
)
720 case WA_SELECT_WINDOWS
:
721 wUnselectWindows(scr
);
722 wSelectWindows(scr
, event
);
724 case WA_OPEN_APPMENU
:
725 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
727 if (scr
->root_menu
) {
728 if (scr
->root_menu
->brother
->flags
.mapped
)
729 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
731 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
734 case WA_OPEN_WINLISTMENU
:
735 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
736 if (scr
->switch_menu
) {
737 if (scr
->switch_menu
->brother
->flags
.mapped
)
738 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
740 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
749 static void handleButtonPress(XEvent
* event
)
751 WObjDescriptor
*desc
;
754 scr
= wScreenForRootWindow(event
->xbutton
.root
);
760 if (event
->xbutton
.window
== scr
->root_win
) {
761 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
762 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
763 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
764 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
765 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
766 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
767 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
768 wWorkspaceRelativeChange(scr
, 1);
769 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
770 wWorkspaceRelativeChange(scr
, -1);
775 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
776 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
781 if (desc
->parent_type
== WCLASS_WINDOW
) {
784 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
785 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
787 /* if (wPreferences.focus_mode == WKF_CLICK) { */
788 if (wPreferences
.ignore_focus_click
) {
789 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
791 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
795 } else if (desc
->parent_type
== WCLASS_APPICON
796 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
797 if (event
->xbutton
.state
& MOD_MASK
) {
799 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
804 if (desc
->handle_mousedown
!= NULL
) {
805 (*desc
->handle_mousedown
) (desc
, event
);
808 /* save double-click information */
809 if (scr
->flags
.next_click_is_not_double
) {
810 scr
->flags
.next_click_is_not_double
= 0;
812 scr
->last_click_time
= event
->xbutton
.time
;
813 scr
->last_click_button
= event
->xbutton
.button
;
814 scr
->last_click_window
= event
->xbutton
.window
;
818 static void handleMapNotify(XEvent
* event
)
822 wwin
= wWindowFor(event
->xmap
.event
);
823 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
824 if (wwin
->flags
.miniaturized
) {
825 wDeiconifyWindow(wwin
);
829 wClientSetState(wwin
, NormalState
, None
);
835 static void handleUnmapNotify(XEvent
* event
)
839 Bool withdraw
= False
;
841 /* only process windows with StructureNotify selected
842 * (ignore SubstructureNotify) */
843 wwin
= wWindowFor(event
->xunmap
.window
);
847 /* whether the event is a Withdrawal request */
848 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
851 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
854 if (!wwin
->flags
.mapped
&& !withdraw
855 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
856 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
860 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
861 wwin
->flags
.mapped
= 0;
863 /* check if the window was destroyed */
864 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
867 Bool reparented
= False
;
869 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
872 /* withdraw window */
873 wwin
->flags
.mapped
= 0;
875 wClientSetState(wwin
, WithdrawnState
, None
);
877 /* if the window was reparented, do not reparent it back to the
879 wUnmanageWindow(wwin
, !reparented
, False
);
884 static void handleConfigureRequest(XEvent
* event
)
888 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
890 * Configure request for unmapped window
892 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
894 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
898 static void handlePropertyNotify(XEvent
* event
)
906 wwin
= wWindowFor(event
->xproperty
.window
);
908 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
911 wClientCheckProperty(wwin
, &event
->xproperty
);
913 wapp
= wApplicationOf(event
->xproperty
.window
);
915 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
919 static void handleClientMessage(XEvent
* event
)
922 WObjDescriptor
*desc
;
924 /* handle transition from Normal to Iconic state */
925 if (event
->xclient
.message_type
== w_global
.atom
.wm
.change_state
926 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
928 wwin
= wWindowFor(event
->xclient
.window
);
931 if (!wwin
->flags
.miniaturized
)
932 wIconifyWindow(wwin
);
933 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.colormap_notify
&& event
->xclient
.format
== 32) {
934 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
939 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
940 wColormapAllowClientInstallation(scr
, True
);
941 } else { /* stopping */
942 wColormapAllowClientInstallation(scr
, False
);
944 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_COMMAND
) {
949 len
= sizeof(event
->xclient
.data
.b
) + 1;
950 command
= wmalloc(len
);
951 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
953 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
954 wwarning(_("Got Reconfigure command"));
955 wDefaultsCheckDomains(NULL
);
957 wwarning(_("Got unknown command %s"), command
);
962 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
965 wapp
= wApplicationOf(event
->xclient
.window
);
967 switch (event
->xclient
.data
.l
[0]) {
968 case WMFHideOtherApplications
:
969 wHideOtherApplications(wapp
->main_window_desc
);
973 case WMFHideApplication
:
974 wHideApplication(wapp
);
980 wwin
= wWindowFor(event
->xclient
.window
);
982 switch (event
->xclient
.data
.l
[0]) {
983 case WMFHideOtherApplications
:
984 wHideOtherApplications(wwin
);
987 case WMFHideApplication
:
988 wHideApplication(wApplicationOf(wwin
->main_window
));
993 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.wm_attr
) {
994 wwin
= wWindowFor(event
->xclient
.window
);
997 switch (event
->xclient
.data
.l
[0]) {
998 case GSWindowLevelAttr
:
1000 int level
= (int)event
->xclient
.data
.l
[1];
1002 if (WINDOW_LEVEL(wwin
) != level
) {
1003 ChangeStackingLevel(wwin
->frame
->core
, level
);
1008 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.titlebar_state
) {
1009 wwin
= wWindowFor(event
->xclient
.window
);
1012 switch (event
->xclient
.data
.l
[0]) {
1013 case WMTitleBarNormal
:
1014 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1016 case WMTitleBarMain
:
1017 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1020 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1023 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.ignore_focus_events
) {
1024 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1027 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1028 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1031 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1036 * Non-standard thing, but needed by OffiX DND.
1037 * For when the icon frame gets a ClientMessage
1038 * that should have gone to the icon_window.
1040 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1041 struct WIcon
*icon
= NULL
;
1043 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1044 icon
= (WIcon
*) desc
->parent
;
1045 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1046 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1048 if (icon
&& (wwin
= icon
->owner
)) {
1049 if (wwin
->client_win
!= event
->xclient
.window
) {
1050 event
->xclient
.window
= wwin
->client_win
;
1051 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1058 static void raiseWindow(WScreen
* scr
)
1062 scr
->autoRaiseTimer
= NULL
;
1064 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1068 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1069 wRaiseFrame(wwin
->frame
->core
);
1070 /* this is needed or a race condition will occur */
1075 static void handleEnterNotify(XEvent
* event
)
1078 WObjDescriptor
*desc
= NULL
;
1080 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1082 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1083 /* already left the window... */
1085 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1090 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1091 if (desc
->handle_enternotify
)
1092 (*desc
->handle_enternotify
) (desc
, event
);
1095 /* enter to window */
1096 wwin
= wWindowFor(event
->xcrossing
.window
);
1098 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1099 wColormapInstallForWindow(scr
, NULL
);
1101 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1102 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1103 scr
->autoRaiseTimer
= NULL
;
1106 /* set auto raise timer even if in focus-follows-mouse mode
1107 * and the event is for the frame window, even if the window
1108 * has focus already. useful if you move the pointer from a focused
1109 * window to the root window and back pretty fast
1111 * set focus if in focus-follows-mouse mode and the event
1112 * is for the frame window and window doesn't have focus yet */
1113 if (wPreferences
.focus_mode
== WKF_SLOPPY
1114 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1116 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1117 wSetFocusTo(scr
, wwin
);
1119 if (scr
->autoRaiseTimer
)
1120 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1121 scr
->autoRaiseTimer
= NULL
;
1123 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1124 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1126 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1129 /* Install colormap for window, if the colormap installation mode
1130 * is colormap_follows_mouse */
1131 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1132 if (wwin
->client_win
== event
->xcrossing
.window
)
1133 wColormapInstallForWindow(scr
, wwin
);
1135 wColormapInstallForWindow(scr
, NULL
);
1139 if (event
->xcrossing
.window
== event
->xcrossing
.root
1140 && event
->xcrossing
.detail
== NotifyNormal
1141 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1143 wSetFocusTo(scr
, scr
->focused_window
);
1146 wBalloonEnteredObject(scr
, desc
);
1150 static void handleLeaveNotify(XEvent
* event
)
1152 WObjDescriptor
*desc
= NULL
;
1154 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1155 if (desc
->handle_leavenotify
)
1156 (*desc
->handle_leavenotify
) (desc
, event
);
1161 static void handleShapeNotify(XEvent
* event
)
1163 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1170 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1171 if (ev
.xshape
.kind
== ShapeBounding
) {
1172 if (ev
.xshape
.shaped
== shev
->shaped
) {
1175 XPutBackEvent(dpy
, &ev
.xevent
);
1181 wwin
= wWindowFor(shev
->window
);
1182 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1185 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1187 wwin
->flags
.shaped
= 0;
1188 wWindowClearShape(wwin
);
1190 } else if (shev
->shaped
) {
1192 wwin
->flags
.shaped
= 1;
1193 wWindowSetShape(wwin
);
1198 #ifdef KEEP_XKB_LOCK_STATUS
1199 /* please help ]d if you know what to do */
1200 static void handleXkbIndicatorStateNotify(XEvent
*event
)
1204 XkbStateRec staterec
;
1207 for (i
= 0; i
< wScreenCount
; i
++) {
1208 scr
= wScreenWithNumber(i
);
1209 wwin
= scr
->focused_window
;
1210 if (wwin
&& wwin
->flags
.focused
) {
1211 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1212 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1213 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1214 wwin
->frame
->languagemode
= staterec
.group
;
1216 #ifdef XKB_BUTTON_HINT
1217 if (wwin
->frame
->titlebar
) {
1218 wFrameWindowPaint(wwin
->frame
);
1224 #endif /*KEEP_XKB_LOCK_STATUS */
1226 static void handleColormapNotify(XEvent
* event
)
1230 Bool reinstall
= False
;
1232 wwin
= wWindowFor(event
->xcolormap
.window
);
1236 scr
= wwin
->screen_ptr
;
1240 if (event
->xcolormap
.new) {
1241 XWindowAttributes attr
;
1243 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1245 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1246 scr
->current_colormap
= attr
.colormap
;
1249 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1250 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1252 /* some bastard app (like XV) removed our colormap */
1254 * can't enforce or things like xscreensaver wont work
1257 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1258 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1260 /* someone has put our colormap back */
1264 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1265 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1267 if (reinstall
&& scr
->current_colormap
!= None
) {
1268 if (!scr
->flags
.colormap_stuff_blocked
)
1269 XInstallColormap(dpy
, scr
->current_colormap
);
1273 static void handleFocusIn(XEvent
* event
)
1278 * For applications that like stealing the focus.
1280 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1281 saveTimestamp(event
);
1282 if (event
->xfocus
.mode
== NotifyUngrab
1283 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1287 wwin
= wWindowFor(event
->xfocus
.window
);
1288 if (wwin
&& !wwin
->flags
.focused
) {
1289 if (wwin
->flags
.mapped
)
1290 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1292 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1294 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1296 wSetFocusTo(scr
, NULL
);
1300 static WWindow
*windowUnderPointer(WScreen
* scr
)
1306 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1307 return wWindowFor(win
);
1311 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1313 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1319 static void handleKeyPress(XEvent
* event
)
1321 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1322 WWindow
*wwin
= scr
->focused_window
;
1326 #ifdef KEEP_XKB_LOCK_STATUS
1327 XkbStateRec staterec
;
1328 #endif /*KEEP_XKB_LOCK_STATUS */
1330 /* ignore CapsLock */
1331 modifiers
= event
->xkey
.state
& ValidModMask
;
1333 for (i
= 0; i
< WKBD_LAST
; i
++) {
1334 if (wKeyBindings
[i
].keycode
== 0)
1337 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1338 || */ wKeyBindings
[i
].modifier
==
1347 if (!wRootMenuPerformShortcut(event
)) {
1348 static int dontLoop
= 0;
1350 if (dontLoop
> 10) {
1351 wwarning("problem with key event processing code");
1355 /* if the focused window is an internal window, try redispatching
1356 * the event to the managed window, as it can be a WINGs window */
1357 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1358 /* client_leader contains the WINGs toplevel */
1359 event
->xany
.window
= wwin
->client_leader
;
1360 WMHandleEvent(event
);
1366 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1367 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1372 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1373 if (!CheckFullScreenWindowFocused(scr
)) {
1374 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1375 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1379 case WKBD_WINDOWLIST
:
1380 if (!CheckFullScreenWindowFocused(scr
)) {
1381 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1382 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1387 case WKBD_WINDOWMENU
:
1388 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1389 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1391 case WKBD_MINIMIZEALL
:
1392 CloseWindowMenu(scr
);
1395 case WKBD_MINIATURIZE
:
1396 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1397 && !WFLAGP(wwin
, no_miniaturizable
)) {
1398 CloseWindowMenu(scr
);
1400 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1401 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
, event
->xbutton
.time
);
1403 wIconifyWindow(wwin
);
1408 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1409 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1410 CloseWindowMenu(scr
);
1412 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1413 wHideApplication(wapp
);
1417 case WKBD_HIDE_OTHERS
:
1418 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1419 CloseWindowMenu(scr
);
1421 wHideOtherApplications(wwin
);
1425 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1426 CloseWindowMenu(scr
);
1428 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1431 case WKBD_VMAXIMIZE
:
1432 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1433 CloseWindowMenu(scr
);
1435 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1438 case WKBD_HMAXIMIZE
:
1439 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1440 CloseWindowMenu(scr
);
1442 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1445 case WKBD_LHMAXIMIZE
:
1446 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1447 CloseWindowMenu(scr
);
1449 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1452 case WKBD_RHMAXIMIZE
:
1453 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1454 CloseWindowMenu(scr
);
1456 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1459 case WKBD_THMAXIMIZE
:
1460 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1461 CloseWindowMenu(scr
);
1463 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1466 case WKBD_BHMAXIMIZE
:
1467 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1468 CloseWindowMenu(scr
);
1470 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1473 case WKBD_LTCMAXIMIZE
:
1474 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1475 CloseWindowMenu(scr
);
1477 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1480 case WKBD_RTCMAXIMIZE
:
1481 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1482 CloseWindowMenu(scr
);
1484 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1487 case WKBD_LBCMAXIMIZE
:
1488 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1489 CloseWindowMenu(scr
);
1491 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1494 case WKBD_RBCMAXIMIZE
:
1495 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1496 CloseWindowMenu(scr
);
1498 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1502 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1503 CloseWindowMenu(scr
);
1505 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1509 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1510 CloseWindowMenu(scr
);
1512 wRaiseFrame(wwin
->frame
->core
);
1516 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1517 CloseWindowMenu(scr
);
1519 wLowerFrame(wwin
->frame
->core
);
1522 case WKBD_RAISELOWER
:
1523 /* raise or lower the window under the pointer, not the
1526 wwin
= windowUnderPointer(scr
);
1528 wRaiseLowerFrame(wwin
->frame
->core
);
1531 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1532 if (wwin
->flags
.shaded
)
1533 wUnshadeWindow(wwin
);
1538 case WKBD_MOVERESIZE
:
1539 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1540 CloseWindowMenu(scr
);
1542 wKeyboardMoveResizeWindow(wwin
);
1546 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1547 CloseWindowMenu(scr
);
1548 if (wwin
->protocols
.DELETE_WINDOW
)
1549 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
, event
->xkey
.time
);
1553 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1554 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1557 case WKBD_FOCUSNEXT
:
1558 StartWindozeCycle(wwin
, event
, True
, False
);
1561 case WKBD_FOCUSPREV
:
1562 StartWindozeCycle(wwin
, event
, False
, False
);
1565 case WKBD_GROUPNEXT
:
1566 StartWindozeCycle(wwin
, event
, True
, True
);
1569 case WKBD_GROUPPREV
:
1570 StartWindozeCycle(wwin
, event
, False
, True
);
1573 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1574 widx
= command
- WKBD_WORKSPACE1
;
1575 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1576 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1577 wWorkspaceChange(scr
, i
);
1580 case WKBD_NEXTWORKSPACE
:
1581 wWorkspaceRelativeChange(scr
, 1);
1583 case WKBD_PREVWORKSPACE
:
1584 wWorkspaceRelativeChange(scr
, -1);
1586 case WKBD_LASTWORKSPACE
:
1587 wWorkspaceChange(scr
, scr
->last_workspace
);
1590 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1591 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1592 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1593 if (wwin
&& (wPreferences
.ws_advance
|| i
< scr
->workspace_count
))
1594 wWindowChangeWorkspace(wwin
, i
);
1597 case WKBD_MOVE_NEXTWORKSPACE
:
1599 wWindowChangeWorkspaceRelative(wwin
, 1);
1601 case WKBD_MOVE_PREVWORKSPACE
:
1603 wWindowChangeWorkspaceRelative(wwin
, -1);
1605 case WKBD_MOVE_LASTWORKSPACE
:
1607 wWindowChangeWorkspace(wwin
, scr
->last_workspace
);
1610 case WKBD_MOVE_NEXTWSLAYER
:
1611 case WKBD_MOVE_PREVWSLAYER
:
1616 row
= scr
->current_workspace
/ 10;
1617 column
= scr
->current_workspace
% 10;
1619 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1620 if ((row
+ 1) * 10 < scr
->workspace_count
)
1621 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1624 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1641 widx
= command
- WKBD_WINDOW1
;
1643 if (scr
->shortcutWindows
[widx
]) {
1644 WMArray
*list
= scr
->shortcutWindows
[widx
];
1646 int count
= WMGetArrayItemCount(list
);
1648 WMArrayIterator iter
;
1651 wUnselectWindows(scr
);
1652 cw
= scr
->current_workspace
;
1654 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1656 wWindowChangeWorkspace(wwin
, cw
);
1658 wMakeWindowVisible(wwin
);
1661 wSelectWindow(wwin
, True
);
1664 /* rotate the order of windows, to create a cycling effect */
1665 twin
= WMGetFromArray(list
, 0);
1666 WMDeleteFromArray(list
, 0);
1667 WMAddToArray(list
, twin
);
1669 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1670 if (scr
->shortcutWindows
[widx
]) {
1671 WMFreeArray(scr
->shortcutWindows
[widx
]);
1672 scr
->shortcutWindows
[widx
] = NULL
;
1675 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1676 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1677 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1678 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1680 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1681 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1684 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1687 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1690 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1692 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1693 if (scr
->shortcutWindows
[widx
]) {
1694 WMFreeArray(scr
->shortcutWindows
[widx
]);
1696 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1703 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1704 (void) RelaunchWindow(wwin
);
1708 case WKBD_SWITCH_SCREEN
:
1709 if (wScreenCount
> 1) {
1713 /* find index of this screen */
1714 for (i
= 0; i
< wScreenCount
; i
++) {
1715 if (wScreenWithNumber(i
) == scr
)
1719 if (i
>= wScreenCount
) {
1722 scr2
= wScreenWithNumber(i
);
1725 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1726 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1731 case WKBD_NEXTWSLAYER
:
1732 case WKBD_PREVWSLAYER
:
1736 row
= scr
->current_workspace
/ 10;
1737 column
= scr
->current_workspace
% 10;
1739 if (command
== WKBD_NEXTWSLAYER
) {
1740 if ((row
+ 1) * 10 < scr
->workspace_count
)
1741 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1744 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1748 case WKBD_CLIPRAISELOWER
:
1749 if (!wPreferences
.flags
.noclip
)
1750 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1752 case WKBD_DOCKRAISELOWER
:
1753 if (!wPreferences
.flags
.nodock
)
1754 wDockRaiseLower(scr
->dock
);
1756 #ifdef KEEP_XKB_LOCK_STATUS
1758 if (wPreferences
.modelock
) {
1760 wwin
= scr
->focused_window
;
1762 if (wwin
&& wwin
->flags
.mapped
1763 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1764 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1765 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1767 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1768 wwin
->frame
->last_languagemode
= staterec
.group
;
1769 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1774 #endif /* KEEP_XKB_LOCK_STATUS */
1778 static void handleMotionNotify(XEvent
* event
)
1780 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1782 if (wPreferences
.scrollable_menus
) {
1783 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1784 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1786 if (scr
->flags
.jump_back_pending
||
1787 p
.x
<= (rect
.pos
.x
+ 1) ||
1788 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1789 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1792 menu
= wMenuUnderPointer(scr
);
1794 wMenuScroll(menu
, event
);
1799 static void handleVisibilityNotify(XEvent
* event
)
1803 wwin
= wWindowFor(event
->xvisibility
.window
);
1806 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);