1 /* event.c- event loop and handling
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <sys/select.h>
26 #include <sys/inotify.h>
37 #include <X11/Xutil.h>
39 # include <X11/extensions/shape.h>
46 #include <X11/extensions/Xrandr.h>
49 #ifdef KEEP_XKB_LOCK_STATUS
50 #include <X11/XKBlib.h>
51 #endif /* KEEP_XKB_LOCK_STATUS */
53 #include "WindowMaker.h"
60 #include "application.h"
63 #include "workspace.h"
66 #include "properties.h"
77 #include "switchmenu.h"
79 /******** Global Variables **********/
80 extern WShortKey wKeyBindings
[WKBD_LAST
];
81 extern int wScreenCount
;
83 #define MOD_MASK wPreferences.modifier_mask
86 extern Bool wShapeSupported
;
87 extern int wShapeEventBase
;
90 #ifdef KEEP_XKB_LOCK_STATUS
91 extern int wXkbEventBase
;
94 /************ Local stuff ***********/
96 static void saveTimestamp(XEvent
*event
);
97 static void handleColormapNotify(XEvent
*event
);
98 static void handleMapNotify(XEvent
*event
);
99 static void handleUnmapNotify(XEvent
*event
);
100 static void handleButtonPress(XEvent
*event
);
101 static void handleExpose(XEvent
*event
);
102 static void handleDestroyNotify(XEvent
*event
);
103 static void handleConfigureRequest(XEvent
*event
);
104 static void handleMapRequest(XEvent
*event
);
105 static void handlePropertyNotify(XEvent
*event
);
106 static void handleEnterNotify(XEvent
*event
);
107 static void handleLeaveNotify(XEvent
*event
);
108 static void handleExtensions(XEvent
*event
);
109 static void handleClientMessage(XEvent
*event
);
110 static void handleKeyPress(XEvent
*event
);
111 static void handleFocusIn(XEvent
*event
);
112 static void handleMotionNotify(XEvent
*event
);
113 static void handleVisibilityNotify(XEvent
*event
);
114 static void handle_inotify_events(int fd
, int wd
);
115 static void wdelete_death_handler(WMagicNumber id
);
119 static void handleShapeNotify(XEvent
*event
);
122 #ifdef KEEP_XKB_LOCK_STATUS
123 static void handleXkbIndicatorStateNotify(XEvent
*event
);
126 /* real dead process handler */
127 static void handleDeadProcess(void *foo
);
129 typedef struct DeadProcesses
{
131 unsigned char exit_status
;
134 /* stack of dead processes */
135 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
136 static int deadProcessPtr
= 0;
138 typedef struct DeathHandler
{
139 WDeathHandler
*callback
;
144 static WMArray
*deathHandlers
= NULL
;
146 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
148 DeathHandler
*handler
;
150 handler
= malloc(sizeof(DeathHandler
));
155 handler
->callback
= callback
;
156 handler
->client_data
= cdata
;
159 deathHandlers
= WMCreateArrayWithDestructor(8, free
);
161 WMAddToArray(deathHandlers
, handler
);
166 static void wdelete_death_handler(WMagicNumber id
)
168 DeathHandler
*handler
= (DeathHandler
*) id
;
170 if (!handler
|| !deathHandlers
)
173 /* array destructor will call free(handler) */
174 WMRemoveFromArray(deathHandlers
, handler
);
177 void DispatchEvent(XEvent
* event
)
180 handleDeadProcess(NULL
);
182 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
183 WCHANGE_STATE(WSTATE_EXITING
);
184 /* received SIGTERM */
186 * WMHandleEvent() can't be called from anything
187 * executed inside here, or we can get in a infinite
190 Shutdown(WSExitMode
);
192 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
193 WCHANGE_STATE(WSTATE_RESTARTING
);
195 Shutdown(WSRestartPreparationMode
);
196 /* received SIGHUP */
198 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
199 WCHANGE_STATE(WSTATE_NORMAL
);
200 wDefaultsCheckDomains(NULL
);
203 /* for the case that all that is wanted to be dispatched is
208 saveTimestamp(event
);
209 switch (event
->type
) {
211 handleMapRequest(event
);
215 handleKeyPress(event
);
219 handleMotionNotify(event
);
222 case ConfigureRequest
:
223 handleConfigureRequest(event
);
227 handleDestroyNotify(event
);
231 handleMapNotify(event
);
235 handleUnmapNotify(event
);
239 handleButtonPress(event
);
247 handlePropertyNotify(event
);
251 handleEnterNotify(event
);
255 handleLeaveNotify(event
);
259 handleClientMessage(event
);
263 handleColormapNotify(event
);
267 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
268 XRefreshKeyboardMapping(&event
->xmapping
);
272 handleFocusIn(event
);
275 case VisibilityNotify
:
276 handleVisibilityNotify(event
);
279 case ConfigureNotify
:
281 if (event
->xconfigure
.window
== DefaultRootWindow(dpy
))
282 XRRUpdateConfiguration(event
);
287 handleExtensions(event
);
294 *----------------------------------------------------------------------
295 * handle_inotify_events-
296 * Check for inotify events
299 * After reading events for the given file descriptor (fd) and
300 * watch descriptor (wd)
303 * Calls wDefaultsCheckDomains if config database is updated
304 *----------------------------------------------------------------------
306 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
307 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
308 static void handle_inotify_events(int fd
, int wd
)
310 ssize_t eventQLength
, i
= 0;
311 char buff
[BUFF_SIZE
] = { 0 };
312 /* Check config only once per read of the event queue */
316 * Read off the queued events
317 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
318 * not occur; the block is on Xevents, but a config file change will normally
319 * occur as a result of an Xevent - so the event queue should never have more than
320 * a few entries before a read().
322 eventQLength
= read(fd
, buff
, BUFF_SIZE
);
324 /* check what events occured */
325 /* Should really check wd here too, but for now we only have one watch! */
326 while (i
< eventQLength
) {
327 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
330 * see inotify.h for event types.
332 if (pevent
->mask
& IN_DELETE_SELF
) {
333 wwarning(_("the defaults database has been deleted!"
334 " Restart Window Maker to create the database" " with the default settings"));
337 if (pevent
->mask
& IN_UNMOUNT
) {
338 wwarning(_("the unit containing the defaults database has"
339 " been unmounted. Setting --static mode." " Any changes will not be saved."));
341 wPreferences
.flags
.noupdates
= 1;
343 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
344 wwarning(_("Inotify: Reading config files in defaults database."));
345 wDefaultsCheckDomains(NULL
);
348 /* move to next event in the buffer */
349 i
+= sizeof(struct inotify_event
) + pevent
->len
;
352 #endif /* HAVE_INOTIFY */
355 *----------------------------------------------------------------------
357 * Processes X and internal events indefinitely.
363 * The LastTimestamp global variable is updated.
364 * Calls inotifyGetEvents if defaults database changes.
365 *----------------------------------------------------------------------
367 noreturn
void EventLoop(void)
371 extern int inotifyFD
;
372 extern int inotifyWD
;
377 if (inotifyFD
< 0 || inotifyWD
< 0)
383 WMNextEvent(dpy
, &event
); /* Blocks here */
384 WMHandleEvent(&event
);
390 FD_SET(inotifyFD
, &rfds
);
392 /* check for available read data from inotify - don't block! */
393 retVal
= select(inotifyFD
+ 1, &rfds
, NULL
, NULL
, &time
);
395 if (retVal
< 0) { /* an error has occured */
396 wwarning(_("select failed. The inotify instance will be closed."
397 " Changes to the defaults database will require"
398 " a restart to take effect."));
402 if (FD_ISSET(inotifyFD
, &rfds
))
403 handle_inotify_events(inotifyFD
, inotifyWD
);
410 *----------------------------------------------------------------------
411 * ProcessPendingEvents --
412 * Processes the events that are currently pending (at the time
413 * this function is called) in the display's queue.
416 * After the pending events that were present at the function call
420 * Many -- whatever handling events may involve.
422 *----------------------------------------------------------------------
424 void ProcessPendingEvents(void)
431 /* Take a snapshot of the event count in the queue */
432 count
= XPending(dpy
);
434 while (count
> 0 && XPending(dpy
)) {
435 WMNextEvent(dpy
, &event
);
436 WMHandleEvent(&event
);
441 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
443 if ((scr
->last_click_time
> 0) &&
444 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
445 && (event
->xbutton
.button
== scr
->last_click_button
)
446 && (event
->xbutton
.window
== scr
->last_click_window
)) {
448 scr
->flags
.next_click_is_not_double
= 1;
449 scr
->last_click_time
= 0;
450 scr
->last_click_window
= event
->xbutton
.window
;
457 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
459 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
460 wwarning("stack overflow: too many dead processes");
463 /* stack the process to be handled later,
464 * as this is called from the signal handler */
465 deadProcesses
[deadProcessPtr
].pid
= pid
;
466 deadProcesses
[deadProcessPtr
].exit_status
= status
;
470 static void handleDeadProcess(void *foo
)
475 for (i
= 0; i
< deadProcessPtr
; i
++) {
476 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
479 if (!deathHandlers
) {
484 /* get the pids on the queue and call handlers */
485 while (deadProcessPtr
> 0) {
488 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
489 tmp
= WMGetFromArray(deathHandlers
, i
);
493 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
494 (*tmp
->callback
) (tmp
->pid
,
495 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
496 wdelete_death_handler(tmp
);
502 static void saveTimestamp(XEvent
* event
)
505 * Never save CurrentTime as LastTimestamp because CurrentTime
506 * it's not a real timestamp (it's the 0L constant)
509 switch (event
->type
) {
512 w_global
.timestamp
.last_event
= event
->xbutton
.time
;
516 w_global
.timestamp
.last_event
= event
->xkey
.time
;
519 w_global
.timestamp
.last_event
= event
->xmotion
.time
;
522 w_global
.timestamp
.last_event
= event
->xproperty
.time
;
526 w_global
.timestamp
.last_event
= event
->xcrossing
.time
;
529 w_global
.timestamp
.last_event
= event
->xselectionclear
.time
;
531 case SelectionRequest
:
532 w_global
.timestamp
.last_event
= event
->xselectionrequest
.time
;
534 case SelectionNotify
:
535 w_global
.timestamp
.last_event
= event
->xselection
.time
;
537 wXDNDProcessSelection(event
);
543 static int matchWindow(const void *item
, const void *cdata
)
545 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
548 static void handleExtensions(XEvent
* event
)
550 #ifdef KEEP_XKB_LOCK_STATUS
552 xkbevent
= (XkbEvent
*) event
;
553 #endif /*KEEP_XKB_LOCK_STATUS */
555 if (wShapeSupported
&& event
->type
== (wShapeEventBase
+ ShapeNotify
)) {
556 handleShapeNotify(event
);
559 #ifdef KEEP_XKB_LOCK_STATUS
560 if (wPreferences
.modelock
&& (xkbevent
->type
== wXkbEventBase
)) {
561 handleXkbIndicatorStateNotify(event
);
563 #endif /*KEEP_XKB_LOCK_STATUS */
565 if (has_randr
&& event
->type
== (randr_event_base
+ RRScreenChangeNotify
)) {
566 /* From xrandr man page: "Clients must call back into Xlib using
567 * XRRUpdateConfiguration when screen configuration change notify
568 * events are generated */
569 XRRUpdateConfiguration(event
);
570 WCHANGE_STATE(WSTATE_RESTARTING
);
571 Shutdown(WSRestartPreparationMode
);
577 static void handleMapRequest(XEvent
* ev
)
581 Window window
= ev
->xmaprequest
.window
;
583 if ((wwin
= wWindowFor(window
))) {
584 if (wwin
->flags
.shaded
) {
585 wUnshadeWindow(wwin
);
587 /* deiconify window */
588 if (wwin
->flags
.miniaturized
) {
589 wDeiconifyWindow(wwin
);
590 } else if (wwin
->flags
.hidden
) {
591 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
592 /* go to the last workspace that the user worked on the app */
594 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
596 wUnhideApplication(wapp
, False
, False
);
601 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
603 wwin
= wManageWindow(scr
, window
);
606 * This is to let the Dock know that the application it launched
607 * has already been mapped (eg: it has finished launching).
608 * It is not necessary for normally docked apps, but is needed for
609 * apps that were forcedly docked (like with dockit).
611 if (scr
->last_dock
) {
612 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
613 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
615 wDockTrackWindowLaunch(scr
->last_dock
, window
);
619 wClientSetState(wwin
, NormalState
, None
);
620 if (wwin
->flags
.maximized
) {
621 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
623 if (wwin
->flags
.shaded
) {
624 wwin
->flags
.shaded
= 0;
625 wwin
->flags
.skip_next_animation
= 1;
628 if (wwin
->flags
.miniaturized
) {
629 wwin
->flags
.miniaturized
= 0;
630 wwin
->flags
.skip_next_animation
= 1;
631 wIconifyWindow(wwin
);
633 if (wwin
->flags
.fullscreen
) {
634 wwin
->flags
.fullscreen
= 0;
635 wFullscreenWindow(wwin
);
637 if (wwin
->flags
.hidden
) {
638 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
640 wwin
->flags
.hidden
= 0;
641 wwin
->flags
.skip_next_animation
= 1;
643 wHideApplication(wapp
);
649 static void handleDestroyNotify(XEvent
* event
)
653 Window window
= event
->xdestroywindow
.window
;
654 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
657 wwin
= wWindowFor(window
);
659 wUnmanageWindow(wwin
, False
, True
);
663 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
664 WFakeGroupLeader
*fPtr
;
666 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
667 if (fPtr
->retainCount
> 0) {
669 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
670 XDestroyWindow(dpy
, fPtr
->leader
);
675 fPtr
->origLeader
= None
;
679 app
= wApplicationOf(window
);
681 if (window
== app
->main_window
) {
683 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
685 if (wwin
->main_window
== window
) {
686 wwin
->main_window
= None
;
691 wApplicationDestroy(app
);
695 static void handleExpose(XEvent
* event
)
697 WObjDescriptor
*desc
;
700 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
702 if (XFindContext(dpy
, event
->xexpose
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
706 if (desc
->handle_expose
) {
707 (*desc
->handle_expose
) (desc
, event
);
711 static void executeButtonAction(WScreen
* scr
, XEvent
* event
, int action
)
714 case WA_SELECT_WINDOWS
:
715 wUnselectWindows(scr
);
716 wSelectWindows(scr
, event
);
718 case WA_OPEN_APPMENU
:
719 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
721 if (scr
->root_menu
) {
722 if (scr
->root_menu
->brother
->flags
.mapped
)
723 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
725 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
728 case WA_OPEN_WINLISTMENU
:
729 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
730 if (scr
->switch_menu
) {
731 if (scr
->switch_menu
->brother
->flags
.mapped
)
732 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
734 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
743 static void handleButtonPress(XEvent
* event
)
745 WObjDescriptor
*desc
;
748 scr
= wScreenForRootWindow(event
->xbutton
.root
);
754 if (event
->xbutton
.window
== scr
->root_win
) {
755 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
756 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
757 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
758 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
759 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
760 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
761 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
762 wWorkspaceRelativeChange(scr
, 1);
763 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
764 wWorkspaceRelativeChange(scr
, -1);
769 if (XFindContext(dpy
, event
->xbutton
.subwindow
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
770 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
775 if (desc
->parent_type
== WCLASS_WINDOW
) {
778 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
779 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
781 /* if (wPreferences.focus_mode == WKF_CLICK) { */
782 if (wPreferences
.ignore_focus_click
) {
783 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
785 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
789 } else if (desc
->parent_type
== WCLASS_APPICON
790 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
791 if (event
->xbutton
.state
& MOD_MASK
) {
793 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
798 if (desc
->handle_mousedown
!= NULL
) {
799 (*desc
->handle_mousedown
) (desc
, event
);
802 /* save double-click information */
803 if (scr
->flags
.next_click_is_not_double
) {
804 scr
->flags
.next_click_is_not_double
= 0;
806 scr
->last_click_time
= event
->xbutton
.time
;
807 scr
->last_click_button
= event
->xbutton
.button
;
808 scr
->last_click_window
= event
->xbutton
.window
;
812 static void handleMapNotify(XEvent
* event
)
816 wwin
= wWindowFor(event
->xmap
.event
);
817 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
818 if (wwin
->flags
.miniaturized
) {
819 wDeiconifyWindow(wwin
);
823 wClientSetState(wwin
, NormalState
, None
);
829 static void handleUnmapNotify(XEvent
* event
)
833 Bool withdraw
= False
;
835 /* only process windows with StructureNotify selected
836 * (ignore SubstructureNotify) */
837 wwin
= wWindowFor(event
->xunmap
.window
);
841 /* whether the event is a Withdrawal request */
842 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
845 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
848 if (!wwin
->flags
.mapped
&& !withdraw
849 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
850 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
854 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
855 wwin
->flags
.mapped
= 0;
857 /* check if the window was destroyed */
858 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
861 Bool reparented
= False
;
863 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
866 /* withdraw window */
867 wwin
->flags
.mapped
= 0;
869 wClientSetState(wwin
, WithdrawnState
, None
);
871 /* if the window was reparented, do not reparent it back to the
873 wUnmanageWindow(wwin
, !reparented
, False
);
878 static void handleConfigureRequest(XEvent
* event
)
882 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
884 * Configure request for unmapped window
886 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
888 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
892 static void handlePropertyNotify(XEvent
* event
)
900 wwin
= wWindowFor(event
->xproperty
.window
);
902 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
905 wClientCheckProperty(wwin
, &event
->xproperty
);
907 wapp
= wApplicationOf(event
->xproperty
.window
);
909 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
913 static void handleClientMessage(XEvent
* event
)
916 WObjDescriptor
*desc
;
918 /* handle transition from Normal to Iconic state */
919 if (event
->xclient
.message_type
== w_global
.atom
.wm
.change_state
920 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
922 wwin
= wWindowFor(event
->xclient
.window
);
925 if (!wwin
->flags
.miniaturized
)
926 wIconifyWindow(wwin
);
927 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.colormap_notify
&& event
->xclient
.format
== 32) {
928 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
933 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
934 wColormapAllowClientInstallation(scr
, True
);
935 } else { /* stopping */
936 wColormapAllowClientInstallation(scr
, False
);
938 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.command
) {
943 len
= sizeof(event
->xclient
.data
.b
) + 1;
944 command
= wmalloc(len
);
945 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
947 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
948 wwarning(_("Got Reconfigure command"));
949 wDefaultsCheckDomains(NULL
);
951 wwarning(_("Got unknown command %s"), command
);
956 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.wm_function
) {
959 wapp
= wApplicationOf(event
->xclient
.window
);
961 switch (event
->xclient
.data
.l
[0]) {
962 case WMFHideOtherApplications
:
963 wHideOtherApplications(wapp
->main_window_desc
);
967 case WMFHideApplication
:
968 wHideApplication(wapp
);
974 wwin
= wWindowFor(event
->xclient
.window
);
976 switch (event
->xclient
.data
.l
[0]) {
977 case WMFHideOtherApplications
:
978 wHideOtherApplications(wwin
);
981 case WMFHideApplication
:
982 wHideApplication(wApplicationOf(wwin
->main_window
));
987 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.wm_attr
) {
988 wwin
= wWindowFor(event
->xclient
.window
);
991 switch (event
->xclient
.data
.l
[0]) {
992 case GSWindowLevelAttr
:
994 int level
= (int)event
->xclient
.data
.l
[1];
996 if (WINDOW_LEVEL(wwin
) != level
) {
997 ChangeStackingLevel(wwin
->frame
->core
, level
);
1002 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.titlebar_state
) {
1003 wwin
= wWindowFor(event
->xclient
.window
);
1006 switch (event
->xclient
.data
.l
[0]) {
1007 case WMTitleBarNormal
:
1008 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1010 case WMTitleBarMain
:
1011 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1014 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1017 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.ignore_focus_events
) {
1018 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1021 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1022 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1025 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1030 * Non-standard thing, but needed by OffiX DND.
1031 * For when the icon frame gets a ClientMessage
1032 * that should have gone to the icon_window.
1034 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1035 struct WIcon
*icon
= NULL
;
1037 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1038 icon
= (WIcon
*) desc
->parent
;
1039 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1040 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1042 if (icon
&& (wwin
= icon
->owner
)) {
1043 if (wwin
->client_win
!= event
->xclient
.window
) {
1044 event
->xclient
.window
= wwin
->client_win
;
1045 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1052 static void raiseWindow(WScreen
* scr
)
1056 scr
->autoRaiseTimer
= NULL
;
1058 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1062 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1063 wRaiseFrame(wwin
->frame
->core
);
1064 /* this is needed or a race condition will occur */
1069 static void handleEnterNotify(XEvent
* event
)
1072 WObjDescriptor
*desc
= NULL
;
1074 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1076 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1077 /* already left the window... */
1079 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1084 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1085 if (desc
->handle_enternotify
)
1086 (*desc
->handle_enternotify
) (desc
, event
);
1089 /* enter to window */
1090 wwin
= wWindowFor(event
->xcrossing
.window
);
1092 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1093 wColormapInstallForWindow(scr
, NULL
);
1095 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1096 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1097 scr
->autoRaiseTimer
= NULL
;
1100 /* set auto raise timer even if in focus-follows-mouse mode
1101 * and the event is for the frame window, even if the window
1102 * has focus already. useful if you move the pointer from a focused
1103 * window to the root window and back pretty fast
1105 * set focus if in focus-follows-mouse mode and the event
1106 * is for the frame window and window doesn't have focus yet */
1107 if (wPreferences
.focus_mode
== WKF_SLOPPY
1108 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1110 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1111 wSetFocusTo(scr
, wwin
);
1113 if (scr
->autoRaiseTimer
)
1114 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1115 scr
->autoRaiseTimer
= NULL
;
1117 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1118 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1120 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1123 /* Install colormap for window, if the colormap installation mode
1124 * is colormap_follows_mouse */
1125 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1126 if (wwin
->client_win
== event
->xcrossing
.window
)
1127 wColormapInstallForWindow(scr
, wwin
);
1129 wColormapInstallForWindow(scr
, NULL
);
1133 if (event
->xcrossing
.window
== event
->xcrossing
.root
1134 && event
->xcrossing
.detail
== NotifyNormal
1135 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1137 wSetFocusTo(scr
, scr
->focused_window
);
1140 wBalloonEnteredObject(scr
, desc
);
1144 static void handleLeaveNotify(XEvent
* event
)
1146 WObjDescriptor
*desc
= NULL
;
1148 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1149 if (desc
->handle_leavenotify
)
1150 (*desc
->handle_leavenotify
) (desc
, event
);
1155 static void handleShapeNotify(XEvent
* event
)
1157 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1164 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1165 if (ev
.xshape
.kind
== ShapeBounding
) {
1166 if (ev
.xshape
.shaped
== shev
->shaped
) {
1169 XPutBackEvent(dpy
, &ev
.xevent
);
1175 wwin
= wWindowFor(shev
->window
);
1176 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1179 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1181 wwin
->flags
.shaped
= 0;
1182 wWindowClearShape(wwin
);
1184 } else if (shev
->shaped
) {
1186 wwin
->flags
.shaped
= 1;
1187 wWindowSetShape(wwin
);
1192 #ifdef KEEP_XKB_LOCK_STATUS
1193 /* please help ]d if you know what to do */
1194 static void handleXkbIndicatorStateNotify(XEvent
*event
)
1198 XkbStateRec staterec
;
1201 for (i
= 0; i
< wScreenCount
; i
++) {
1202 scr
= wScreenWithNumber(i
);
1203 wwin
= scr
->focused_window
;
1204 if (wwin
&& wwin
->flags
.focused
) {
1205 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1206 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1207 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1208 wwin
->frame
->languagemode
= staterec
.group
;
1210 #ifdef XKB_BUTTON_HINT
1211 if (wwin
->frame
->titlebar
) {
1212 wFrameWindowPaint(wwin
->frame
);
1218 #endif /*KEEP_XKB_LOCK_STATUS */
1220 static void handleColormapNotify(XEvent
* event
)
1224 Bool reinstall
= False
;
1226 wwin
= wWindowFor(event
->xcolormap
.window
);
1230 scr
= wwin
->screen_ptr
;
1234 if (event
->xcolormap
.new) {
1235 XWindowAttributes attr
;
1237 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1239 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1240 scr
->current_colormap
= attr
.colormap
;
1243 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1244 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1246 /* some bastard app (like XV) removed our colormap */
1248 * can't enforce or things like xscreensaver wont work
1251 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1252 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1254 /* someone has put our colormap back */
1258 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1259 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1261 if (reinstall
&& scr
->current_colormap
!= None
) {
1262 if (!scr
->flags
.colormap_stuff_blocked
)
1263 XInstallColormap(dpy
, scr
->current_colormap
);
1267 static void handleFocusIn(XEvent
* event
)
1272 * For applications that like stealing the focus.
1274 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1275 saveTimestamp(event
);
1276 if (event
->xfocus
.mode
== NotifyUngrab
1277 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1281 wwin
= wWindowFor(event
->xfocus
.window
);
1282 if (wwin
&& !wwin
->flags
.focused
) {
1283 if (wwin
->flags
.mapped
)
1284 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1286 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1288 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1290 wSetFocusTo(scr
, NULL
);
1294 static WWindow
*windowUnderPointer(WScreen
* scr
)
1300 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1301 return wWindowFor(win
);
1305 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1307 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1313 static void handleKeyPress(XEvent
* event
)
1315 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1316 WWindow
*wwin
= scr
->focused_window
;
1320 #ifdef KEEP_XKB_LOCK_STATUS
1321 XkbStateRec staterec
;
1322 #endif /*KEEP_XKB_LOCK_STATUS */
1324 /* ignore CapsLock */
1325 modifiers
= event
->xkey
.state
& ValidModMask
;
1327 for (i
= 0; i
< WKBD_LAST
; i
++) {
1328 if (wKeyBindings
[i
].keycode
== 0)
1331 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1332 || */ wKeyBindings
[i
].modifier
==
1341 if (!wRootMenuPerformShortcut(event
)) {
1342 static int dontLoop
= 0;
1344 if (dontLoop
> 10) {
1345 wwarning("problem with key event processing code");
1349 /* if the focused window is an internal window, try redispatching
1350 * the event to the managed window, as it can be a WINGs window */
1351 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1352 /* client_leader contains the WINGs toplevel */
1353 event
->xany
.window
= wwin
->client_leader
;
1354 WMHandleEvent(event
);
1360 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1361 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1366 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1367 if (!CheckFullScreenWindowFocused(scr
)) {
1368 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1369 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1373 case WKBD_WINDOWLIST
:
1374 if (!CheckFullScreenWindowFocused(scr
)) {
1375 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1376 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1381 case WKBD_WINDOWMENU
:
1382 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1383 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1385 case WKBD_MINIMIZEALL
:
1386 CloseWindowMenu(scr
);
1389 case WKBD_MINIATURIZE
:
1390 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1391 && !WFLAGP(wwin
, no_miniaturizable
)) {
1392 CloseWindowMenu(scr
);
1394 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1395 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
, event
->xbutton
.time
);
1397 wIconifyWindow(wwin
);
1402 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1403 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1404 CloseWindowMenu(scr
);
1406 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1407 wHideApplication(wapp
);
1411 case WKBD_HIDE_OTHERS
:
1412 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1413 CloseWindowMenu(scr
);
1415 wHideOtherApplications(wwin
);
1419 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1420 CloseWindowMenu(scr
);
1422 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1425 case WKBD_VMAXIMIZE
:
1426 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1427 CloseWindowMenu(scr
);
1429 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1432 case WKBD_HMAXIMIZE
:
1433 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1434 CloseWindowMenu(scr
);
1436 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1439 case WKBD_LHMAXIMIZE
:
1440 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1441 CloseWindowMenu(scr
);
1443 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1446 case WKBD_RHMAXIMIZE
:
1447 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1448 CloseWindowMenu(scr
);
1450 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1453 case WKBD_THMAXIMIZE
:
1454 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1455 CloseWindowMenu(scr
);
1457 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1460 case WKBD_BHMAXIMIZE
:
1461 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1462 CloseWindowMenu(scr
);
1464 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1467 case WKBD_LTCMAXIMIZE
:
1468 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1469 CloseWindowMenu(scr
);
1471 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1474 case WKBD_RTCMAXIMIZE
:
1475 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1476 CloseWindowMenu(scr
);
1478 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1481 case WKBD_LBCMAXIMIZE
:
1482 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1483 CloseWindowMenu(scr
);
1485 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1488 case WKBD_RBCMAXIMIZE
:
1489 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1490 CloseWindowMenu(scr
);
1492 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1496 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1497 CloseWindowMenu(scr
);
1499 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1503 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1504 CloseWindowMenu(scr
);
1506 wRaiseFrame(wwin
->frame
->core
);
1510 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1511 CloseWindowMenu(scr
);
1513 wLowerFrame(wwin
->frame
->core
);
1516 case WKBD_RAISELOWER
:
1517 /* raise or lower the window under the pointer, not the
1520 wwin
= windowUnderPointer(scr
);
1522 wRaiseLowerFrame(wwin
->frame
->core
);
1525 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1526 if (wwin
->flags
.shaded
)
1527 wUnshadeWindow(wwin
);
1532 case WKBD_MOVERESIZE
:
1533 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1534 CloseWindowMenu(scr
);
1536 wKeyboardMoveResizeWindow(wwin
);
1540 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1541 CloseWindowMenu(scr
);
1542 if (wwin
->protocols
.DELETE_WINDOW
)
1543 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
, event
->xkey
.time
);
1547 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1548 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1551 case WKBD_FOCUSNEXT
:
1552 StartWindozeCycle(wwin
, event
, True
, False
);
1555 case WKBD_FOCUSPREV
:
1556 StartWindozeCycle(wwin
, event
, False
, False
);
1559 case WKBD_GROUPNEXT
:
1560 StartWindozeCycle(wwin
, event
, True
, True
);
1563 case WKBD_GROUPPREV
:
1564 StartWindozeCycle(wwin
, event
, False
, True
);
1567 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1568 widx
= command
- WKBD_WORKSPACE1
;
1569 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1570 if (wPreferences
.ws_advance
|| i
< w_global
.workspace
.count
)
1571 wWorkspaceChange(scr
, i
);
1574 case WKBD_NEXTWORKSPACE
:
1575 wWorkspaceRelativeChange(scr
, 1);
1577 case WKBD_PREVWORKSPACE
:
1578 wWorkspaceRelativeChange(scr
, -1);
1580 case WKBD_LASTWORKSPACE
:
1581 wWorkspaceChange(scr
, w_global
.workspace
.last_used
);
1584 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1585 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1586 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1587 if (wwin
&& (wPreferences
.ws_advance
|| i
< w_global
.workspace
.count
))
1588 wWindowChangeWorkspace(wwin
, i
);
1591 case WKBD_MOVE_NEXTWORKSPACE
:
1593 wWindowChangeWorkspaceRelative(wwin
, 1);
1595 case WKBD_MOVE_PREVWORKSPACE
:
1597 wWindowChangeWorkspaceRelative(wwin
, -1);
1599 case WKBD_MOVE_LASTWORKSPACE
:
1601 wWindowChangeWorkspace(wwin
, w_global
.workspace
.last_used
);
1604 case WKBD_MOVE_NEXTWSLAYER
:
1605 case WKBD_MOVE_PREVWSLAYER
:
1610 row
= scr
->current_workspace
/ 10;
1611 column
= scr
->current_workspace
% 10;
1613 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1614 if ((row
+ 1) * 10 < w_global
.workspace
.count
)
1615 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1618 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1635 widx
= command
- WKBD_WINDOW1
;
1637 if (scr
->shortcutWindows
[widx
]) {
1638 WMArray
*list
= scr
->shortcutWindows
[widx
];
1640 int count
= WMGetArrayItemCount(list
);
1642 WMArrayIterator iter
;
1645 wUnselectWindows(scr
);
1646 cw
= scr
->current_workspace
;
1648 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1650 wWindowChangeWorkspace(wwin
, cw
);
1652 wMakeWindowVisible(wwin
);
1655 wSelectWindow(wwin
, True
);
1658 /* rotate the order of windows, to create a cycling effect */
1659 twin
= WMGetFromArray(list
, 0);
1660 WMDeleteFromArray(list
, 0);
1661 WMAddToArray(list
, twin
);
1663 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1664 if (scr
->shortcutWindows
[widx
]) {
1665 WMFreeArray(scr
->shortcutWindows
[widx
]);
1666 scr
->shortcutWindows
[widx
] = NULL
;
1669 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1670 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1671 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1672 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1674 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1675 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1678 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1681 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1684 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1686 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1687 if (scr
->shortcutWindows
[widx
]) {
1688 WMFreeArray(scr
->shortcutWindows
[widx
]);
1690 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1697 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1698 (void) RelaunchWindow(wwin
);
1702 case WKBD_SWITCH_SCREEN
:
1703 if (wScreenCount
> 1) {
1707 /* find index of this screen */
1708 for (i
= 0; i
< wScreenCount
; i
++) {
1709 if (wScreenWithNumber(i
) == scr
)
1713 if (i
>= wScreenCount
) {
1716 scr2
= wScreenWithNumber(i
);
1719 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1720 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1725 case WKBD_NEXTWSLAYER
:
1726 case WKBD_PREVWSLAYER
:
1730 row
= scr
->current_workspace
/ 10;
1731 column
= scr
->current_workspace
% 10;
1733 if (command
== WKBD_NEXTWSLAYER
) {
1734 if ((row
+ 1) * 10 < w_global
.workspace
.count
)
1735 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1738 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1742 case WKBD_CLIPRAISELOWER
:
1743 if (!wPreferences
.flags
.noclip
)
1744 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1746 case WKBD_DOCKRAISELOWER
:
1747 if (!wPreferences
.flags
.nodock
)
1748 wDockRaiseLower(scr
->dock
);
1750 #ifdef KEEP_XKB_LOCK_STATUS
1752 if (wPreferences
.modelock
) {
1754 wwin
= scr
->focused_window
;
1756 if (wwin
&& wwin
->flags
.mapped
1757 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1758 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1759 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1761 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1762 wwin
->frame
->last_languagemode
= staterec
.group
;
1763 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1768 #endif /* KEEP_XKB_LOCK_STATUS */
1772 static void handleMotionNotify(XEvent
* event
)
1774 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1776 if (wPreferences
.scrollable_menus
) {
1777 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1778 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1780 if (scr
->flags
.jump_back_pending
||
1781 p
.x
<= (rect
.pos
.x
+ 1) ||
1782 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1783 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1786 menu
= wMenuUnderPointer(scr
);
1788 wMenuScroll(menu
, event
);
1793 static void handleVisibilityNotify(XEvent
* event
)
1797 wwin
= wWindowFor(event
->xvisibility
.window
);
1800 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);