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 Cursor wCursor
[WCUR_LAST
];
85 extern WShortKey wKeyBindings
[WKBD_LAST
];
86 extern int wScreenCount
;
87 extern Time LastTimestamp
;
88 extern Time LastFocusChange
;
90 #define MOD_MASK wPreferences.modifier_mask
92 extern Atom _XA_WM_COLORMAP_NOTIFY
;
94 extern Atom _XA_WM_CHANGE_STATE
;
95 extern Atom _XA_WM_DELETE_WINDOW
;
96 extern Atom _XA_GNUSTEP_WM_ATTR
;
97 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
98 extern Atom _XA_GNUSTEP_TITLEBAR_STATE
;
99 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
100 extern Atom _XA_WINDOWMAKER_COMMAND
;
101 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS
;
104 extern Bool wShapeSupported
;
105 extern int wShapeEventBase
;
108 #ifdef KEEP_XKB_LOCK_STATUS
109 extern int wXkbEventBase
;
112 /************ Local stuff ***********/
114 static void saveTimestamp(XEvent
*event
);
115 static void handleColormapNotify(XEvent
*event
);
116 static void handleMapNotify(XEvent
*event
);
117 static void handleUnmapNotify(XEvent
*event
);
118 static void handleButtonPress(XEvent
*event
);
119 static void handleExpose(XEvent
*event
);
120 static void handleDestroyNotify(XEvent
*event
);
121 static void handleConfigureRequest(XEvent
*event
);
122 static void handleMapRequest(XEvent
*event
);
123 static void handlePropertyNotify(XEvent
*event
);
124 static void handleEnterNotify(XEvent
*event
);
125 static void handleLeaveNotify(XEvent
*event
);
126 static void handleExtensions(XEvent
*event
);
127 static void handleClientMessage(XEvent
*event
);
128 static void handleKeyPress(XEvent
*event
);
129 static void handleFocusIn(XEvent
*event
);
130 static void handleMotionNotify(XEvent
*event
);
131 static void handleVisibilityNotify(XEvent
*event
);
132 static void handle_inotify_events(int fd
, int wd
);
133 static void wdelete_death_handler(WMagicNumber id
);
137 static void handleShapeNotify(XEvent
*event
);
140 #ifdef KEEP_XKB_LOCK_STATUS
141 static void handleXkbIndicatorStateNotify(XEvent
*event
);
144 /* real dead process handler */
145 static void handleDeadProcess(void *foo
);
147 typedef struct DeadProcesses
{
149 unsigned char exit_status
;
152 /* stack of dead processes */
153 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
154 static int deadProcessPtr
= 0;
156 typedef struct DeathHandler
{
157 WDeathHandler
*callback
;
162 static WMArray
*deathHandlers
= NULL
;
164 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
166 DeathHandler
*handler
;
168 handler
= malloc(sizeof(DeathHandler
));
173 handler
->callback
= callback
;
174 handler
->client_data
= cdata
;
177 deathHandlers
= WMCreateArrayWithDestructor(8, free
);
179 WMAddToArray(deathHandlers
, handler
);
184 static void wdelete_death_handler(WMagicNumber id
)
186 DeathHandler
*handler
= (DeathHandler
*) id
;
188 if (!handler
|| !deathHandlers
)
191 /* array destructor will call free(handler) */
192 WMRemoveFromArray(deathHandlers
, handler
);
195 void DispatchEvent(XEvent
* event
)
198 handleDeadProcess(NULL
);
200 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
201 WCHANGE_STATE(WSTATE_EXITING
);
202 /* received SIGTERM */
204 * WMHandleEvent() can't be called from anything
205 * executed inside here, or we can get in a infinite
208 Shutdown(WSExitMode
);
210 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
211 WCHANGE_STATE(WSTATE_RESTARTING
);
213 Shutdown(WSRestartPreparationMode
);
214 /* received SIGHUP */
216 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
217 WCHANGE_STATE(WSTATE_NORMAL
);
218 wDefaultsCheckDomains(NULL
);
221 /* for the case that all that is wanted to be dispatched is
226 saveTimestamp(event
);
227 switch (event
->type
) {
229 handleMapRequest(event
);
233 handleKeyPress(event
);
237 handleMotionNotify(event
);
240 case ConfigureRequest
:
241 handleConfigureRequest(event
);
245 handleDestroyNotify(event
);
249 handleMapNotify(event
);
253 handleUnmapNotify(event
);
257 handleButtonPress(event
);
265 handlePropertyNotify(event
);
269 handleEnterNotify(event
);
273 handleLeaveNotify(event
);
277 handleClientMessage(event
);
281 handleColormapNotify(event
);
285 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
286 XRefreshKeyboardMapping(&event
->xmapping
);
290 handleFocusIn(event
);
293 case VisibilityNotify
:
294 handleVisibilityNotify(event
);
297 case ConfigureNotify
:
299 if (event
->xconfigure
.window
== DefaultRootWindow(dpy
))
300 XRRUpdateConfiguration(event
);
305 handleExtensions(event
);
312 *----------------------------------------------------------------------
313 * handle_inotify_events-
314 * Check for inotify events
317 * After reading events for the given file descriptor (fd) and
318 * watch descriptor (wd)
321 * Calls wDefaultsCheckDomains if config database is updated
322 *----------------------------------------------------------------------
324 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
325 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
326 static void handle_inotify_events(int fd
, int wd
)
328 ssize_t eventQLength
, i
= 0;
329 char buff
[BUFF_SIZE
] = { 0 };
330 /* Check config only once per read of the event queue */
334 * Read off the queued events
335 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
336 * not occur; the block is on Xevents, but a config file change will normally
337 * occur as a result of an Xevent - so the event queue should never have more than
338 * a few entries before a read().
340 eventQLength
= read(fd
, buff
, BUFF_SIZE
);
342 /* check what events occured */
343 /* Should really check wd here too, but for now we only have one watch! */
344 while (i
< eventQLength
) {
345 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
348 * see inotify.h for event types.
350 if (pevent
->mask
& IN_DELETE_SELF
) {
351 wwarning(_("the defaults database has been deleted!"
352 " Restart Window Maker to create the database" " with the default settings"));
355 if (pevent
->mask
& IN_UNMOUNT
) {
356 wwarning(_("the unit containing the defaults database has"
357 " been unmounted. Setting --static mode." " Any changes will not be saved."));
359 wPreferences
.flags
.noupdates
= 1;
361 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
362 wwarning(_("Inotify: Reading config files in defaults database."));
363 wDefaultsCheckDomains(NULL
);
366 /* move to next event in the buffer */
367 i
+= sizeof(struct inotify_event
) + pevent
->len
;
370 #endif /* HAVE_INOTIFY */
373 *----------------------------------------------------------------------
375 * Processes X and internal events indefinitely.
381 * The LastTimestamp global variable is updated.
382 * Calls inotifyGetEvents if defaults database changes.
383 *----------------------------------------------------------------------
385 noreturn
void EventLoop(void)
389 extern int inotifyFD
;
390 extern int inotifyWD
;
395 if (inotifyFD
< 0 || inotifyWD
< 0)
401 WMNextEvent(dpy
, &event
); /* Blocks here */
402 WMHandleEvent(&event
);
408 FD_SET(inotifyFD
, &rfds
);
410 /* check for available read data from inotify - don't block! */
411 retVal
= select(inotifyFD
+ 1, &rfds
, NULL
, NULL
, &time
);
413 if (retVal
< 0) { /* an error has occured */
414 wwarning(_("select failed. The inotify instance will be closed."
415 " Changes to the defaults database will require"
416 " a restart to take effect."));
420 if (FD_ISSET(inotifyFD
, &rfds
))
421 handle_inotify_events(inotifyFD
, inotifyWD
);
428 *----------------------------------------------------------------------
429 * ProcessPendingEvents --
430 * Processes the events that are currently pending (at the time
431 * this function is called) in the display's queue.
434 * After the pending events that were present at the function call
438 * Many -- whatever handling events may involve.
440 *----------------------------------------------------------------------
442 void ProcessPendingEvents(void)
449 /* Take a snapshot of the event count in the queue */
450 count
= XPending(dpy
);
452 while (count
> 0 && XPending(dpy
)) {
453 WMNextEvent(dpy
, &event
);
454 WMHandleEvent(&event
);
459 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
461 if ((scr
->last_click_time
> 0) &&
462 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
463 && (event
->xbutton
.button
== scr
->last_click_button
)
464 && (event
->xbutton
.window
== scr
->last_click_window
)) {
466 scr
->flags
.next_click_is_not_double
= 1;
467 scr
->last_click_time
= 0;
468 scr
->last_click_window
= event
->xbutton
.window
;
475 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
477 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
478 wwarning("stack overflow: too many dead processes");
481 /* stack the process to be handled later,
482 * as this is called from the signal handler */
483 deadProcesses
[deadProcessPtr
].pid
= pid
;
484 deadProcesses
[deadProcessPtr
].exit_status
= status
;
488 static void handleDeadProcess(void *foo
)
493 for (i
= 0; i
< deadProcessPtr
; i
++) {
494 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
497 if (!deathHandlers
) {
502 /* get the pids on the queue and call handlers */
503 while (deadProcessPtr
> 0) {
506 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
507 tmp
= WMGetFromArray(deathHandlers
, i
);
511 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
512 (*tmp
->callback
) (tmp
->pid
,
513 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
514 wdelete_death_handler(tmp
);
520 static void saveTimestamp(XEvent
* event
)
523 * Never save CurrentTime as LastTimestamp because CurrentTime
524 * it's not a real timestamp (it's the 0L constant)
527 switch (event
->type
) {
530 LastTimestamp
= event
->xbutton
.time
;
534 LastTimestamp
= event
->xkey
.time
;
537 LastTimestamp
= event
->xmotion
.time
;
540 LastTimestamp
= event
->xproperty
.time
;
544 LastTimestamp
= event
->xcrossing
.time
;
547 LastTimestamp
= event
->xselectionclear
.time
;
549 case SelectionRequest
:
550 LastTimestamp
= event
->xselectionrequest
.time
;
552 case SelectionNotify
:
553 LastTimestamp
= event
->xselection
.time
;
555 wXDNDProcessSelection(event
);
561 static int matchWindow(const void *item
, const void *cdata
)
563 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
566 static void handleExtensions(XEvent
* event
)
568 #ifdef KEEP_XKB_LOCK_STATUS
570 xkbevent
= (XkbEvent
*) event
;
571 #endif /*KEEP_XKB_LOCK_STATUS */
573 if (wShapeSupported
&& event
->type
== (wShapeEventBase
+ ShapeNotify
)) {
574 handleShapeNotify(event
);
577 #ifdef KEEP_XKB_LOCK_STATUS
578 if (wPreferences
.modelock
&& (xkbevent
->type
== wXkbEventBase
)) {
579 handleXkbIndicatorStateNotify(event
);
581 #endif /*KEEP_XKB_LOCK_STATUS */
583 if (has_randr
&& event
->type
== (randr_event_base
+ RRScreenChangeNotify
)) {
584 /* From xrandr man page: "Clients must call back into Xlib using
585 * XRRUpdateConfiguration when screen configuration change notify
586 * events are generated */
587 XRRUpdateConfiguration(event
);
588 WCHANGE_STATE(WSTATE_RESTARTING
);
589 Shutdown(WSRestartPreparationMode
);
595 static void handleMapRequest(XEvent
* ev
)
599 Window window
= ev
->xmaprequest
.window
;
601 if ((wwin
= wWindowFor(window
))) {
602 if (wwin
->flags
.shaded
) {
603 wUnshadeWindow(wwin
);
605 /* deiconify window */
606 if (wwin
->flags
.miniaturized
) {
607 wDeiconifyWindow(wwin
);
608 } else if (wwin
->flags
.hidden
) {
609 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
610 /* go to the last workspace that the user worked on the app */
612 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
614 wUnhideApplication(wapp
, False
, False
);
619 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
621 wwin
= wManageWindow(scr
, window
);
624 * This is to let the Dock know that the application it launched
625 * has already been mapped (eg: it has finished launching).
626 * It is not necessary for normally docked apps, but is needed for
627 * apps that were forcedly docked (like with dockit).
629 if (scr
->last_dock
) {
630 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
631 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
633 wDockTrackWindowLaunch(scr
->last_dock
, window
);
637 wClientSetState(wwin
, NormalState
, None
);
638 if (wwin
->flags
.maximized
) {
639 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
641 if (wwin
->flags
.shaded
) {
642 wwin
->flags
.shaded
= 0;
643 wwin
->flags
.skip_next_animation
= 1;
646 if (wwin
->flags
.miniaturized
) {
647 wwin
->flags
.miniaturized
= 0;
648 wwin
->flags
.skip_next_animation
= 1;
649 wIconifyWindow(wwin
);
651 if (wwin
->flags
.fullscreen
) {
652 wwin
->flags
.fullscreen
= 0;
653 wFullscreenWindow(wwin
);
655 if (wwin
->flags
.hidden
) {
656 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
658 wwin
->flags
.hidden
= 0;
659 wwin
->flags
.skip_next_animation
= 1;
661 wHideApplication(wapp
);
667 static void handleDestroyNotify(XEvent
* event
)
671 Window window
= event
->xdestroywindow
.window
;
672 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
675 wwin
= wWindowFor(window
);
677 wUnmanageWindow(wwin
, False
, True
);
681 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
682 WFakeGroupLeader
*fPtr
;
684 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
685 if (fPtr
->retainCount
> 0) {
687 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
688 XDestroyWindow(dpy
, fPtr
->leader
);
693 fPtr
->origLeader
= None
;
697 app
= wApplicationOf(window
);
699 if (window
== app
->main_window
) {
701 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
703 if (wwin
->main_window
== window
) {
704 wwin
->main_window
= None
;
709 wApplicationDestroy(app
);
713 static void handleExpose(XEvent
* event
)
715 WObjDescriptor
*desc
;
718 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
720 if (XFindContext(dpy
, event
->xexpose
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
724 if (desc
->handle_expose
) {
725 (*desc
->handle_expose
) (desc
, event
);
729 static void executeButtonAction(WScreen
* scr
, XEvent
* event
, int action
)
732 case WA_SELECT_WINDOWS
:
733 wUnselectWindows(scr
);
734 wSelectWindows(scr
, event
);
736 case WA_OPEN_APPMENU
:
737 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
739 if (scr
->root_menu
) {
740 if (scr
->root_menu
->brother
->flags
.mapped
)
741 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
743 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
746 case WA_OPEN_WINLISTMENU
:
747 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
748 if (scr
->switch_menu
) {
749 if (scr
->switch_menu
->brother
->flags
.mapped
)
750 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
752 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
761 static void handleButtonPress(XEvent
* event
)
763 WObjDescriptor
*desc
;
766 scr
= wScreenForRootWindow(event
->xbutton
.root
);
772 if (event
->xbutton
.window
== scr
->root_win
) {
773 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
774 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
775 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
776 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
777 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
778 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
779 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
780 wWorkspaceRelativeChange(scr
, 1);
781 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
782 wWorkspaceRelativeChange(scr
, -1);
787 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
788 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
793 if (desc
->parent_type
== WCLASS_WINDOW
) {
796 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
797 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
799 /* if (wPreferences.focus_mode == WKF_CLICK) { */
800 if (wPreferences
.ignore_focus_click
) {
801 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
803 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
807 } else if (desc
->parent_type
== WCLASS_APPICON
808 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
809 if (event
->xbutton
.state
& MOD_MASK
) {
811 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
816 if (desc
->handle_mousedown
!= NULL
) {
817 (*desc
->handle_mousedown
) (desc
, event
);
820 /* save double-click information */
821 if (scr
->flags
.next_click_is_not_double
) {
822 scr
->flags
.next_click_is_not_double
= 0;
824 scr
->last_click_time
= event
->xbutton
.time
;
825 scr
->last_click_button
= event
->xbutton
.button
;
826 scr
->last_click_window
= event
->xbutton
.window
;
830 static void handleMapNotify(XEvent
* event
)
834 wwin
= wWindowFor(event
->xmap
.event
);
835 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
836 if (wwin
->flags
.miniaturized
) {
837 wDeiconifyWindow(wwin
);
841 wClientSetState(wwin
, NormalState
, None
);
847 static void handleUnmapNotify(XEvent
* event
)
851 Bool withdraw
= False
;
853 /* only process windows with StructureNotify selected
854 * (ignore SubstructureNotify) */
855 wwin
= wWindowFor(event
->xunmap
.window
);
859 /* whether the event is a Withdrawal request */
860 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
863 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
866 if (!wwin
->flags
.mapped
&& !withdraw
867 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
868 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
872 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
873 wwin
->flags
.mapped
= 0;
875 /* check if the window was destroyed */
876 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
879 Bool reparented
= False
;
881 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
884 /* withdraw window */
885 wwin
->flags
.mapped
= 0;
887 wClientSetState(wwin
, WithdrawnState
, None
);
889 /* if the window was reparented, do not reparent it back to the
891 wUnmanageWindow(wwin
, !reparented
, False
);
896 static void handleConfigureRequest(XEvent
* event
)
900 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
902 * Configure request for unmapped window
904 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
906 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
910 static void handlePropertyNotify(XEvent
* event
)
918 wwin
= wWindowFor(event
->xproperty
.window
);
920 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
923 wClientCheckProperty(wwin
, &event
->xproperty
);
925 wapp
= wApplicationOf(event
->xproperty
.window
);
927 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
931 static void handleClientMessage(XEvent
* event
)
934 WObjDescriptor
*desc
;
936 /* handle transition from Normal to Iconic state */
937 if (event
->xclient
.message_type
== _XA_WM_CHANGE_STATE
938 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
940 wwin
= wWindowFor(event
->xclient
.window
);
943 if (!wwin
->flags
.miniaturized
)
944 wIconifyWindow(wwin
);
945 } else if (event
->xclient
.message_type
== _XA_WM_COLORMAP_NOTIFY
&& event
->xclient
.format
== 32) {
946 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
951 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
952 wColormapAllowClientInstallation(scr
, True
);
953 } else { /* stopping */
954 wColormapAllowClientInstallation(scr
, False
);
956 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_COMMAND
) {
961 len
= sizeof(event
->xclient
.data
.b
) + 1;
962 command
= wmalloc(len
);
963 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
965 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
966 wwarning(_("Got Reconfigure command"));
967 wDefaultsCheckDomains(NULL
);
969 wwarning(_("Got unknown command %s"), command
);
974 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
977 wapp
= wApplicationOf(event
->xclient
.window
);
979 switch (event
->xclient
.data
.l
[0]) {
980 case WMFHideOtherApplications
:
981 wHideOtherApplications(wapp
->main_window_desc
);
985 case WMFHideApplication
:
986 wHideApplication(wapp
);
992 wwin
= wWindowFor(event
->xclient
.window
);
994 switch (event
->xclient
.data
.l
[0]) {
995 case WMFHideOtherApplications
:
996 wHideOtherApplications(wwin
);
999 case WMFHideApplication
:
1000 wHideApplication(wApplicationOf(wwin
->main_window
));
1005 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_WM_ATTR
) {
1006 wwin
= wWindowFor(event
->xclient
.window
);
1009 switch (event
->xclient
.data
.l
[0]) {
1010 case GSWindowLevelAttr
:
1012 int level
= (int)event
->xclient
.data
.l
[1];
1014 if (WINDOW_LEVEL(wwin
) != level
) {
1015 ChangeStackingLevel(wwin
->frame
->core
, level
);
1020 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_TITLEBAR_STATE
) {
1021 wwin
= wWindowFor(event
->xclient
.window
);
1024 switch (event
->xclient
.data
.l
[0]) {
1025 case WMTitleBarNormal
:
1026 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1028 case WMTitleBarMain
:
1029 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1032 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1035 } else if (event
->xclient
.message_type
== _XA_WM_IGNORE_FOCUS_EVENTS
) {
1036 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1039 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1040 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1043 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1048 * Non-standard thing, but needed by OffiX DND.
1049 * For when the icon frame gets a ClientMessage
1050 * that should have gone to the icon_window.
1052 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1053 struct WIcon
*icon
= NULL
;
1055 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1056 icon
= (WIcon
*) desc
->parent
;
1057 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1058 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1060 if (icon
&& (wwin
= icon
->owner
)) {
1061 if (wwin
->client_win
!= event
->xclient
.window
) {
1062 event
->xclient
.window
= wwin
->client_win
;
1063 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1070 static void raiseWindow(WScreen
* scr
)
1074 scr
->autoRaiseTimer
= NULL
;
1076 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1080 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1081 wRaiseFrame(wwin
->frame
->core
);
1082 /* this is needed or a race condition will occur */
1087 static void handleEnterNotify(XEvent
* event
)
1090 WObjDescriptor
*desc
= NULL
;
1092 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1094 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1095 /* already left the window... */
1097 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1102 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1103 if (desc
->handle_enternotify
)
1104 (*desc
->handle_enternotify
) (desc
, event
);
1107 /* enter to window */
1108 wwin
= wWindowFor(event
->xcrossing
.window
);
1110 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1111 wColormapInstallForWindow(scr
, NULL
);
1113 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1114 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1115 scr
->autoRaiseTimer
= NULL
;
1118 /* set auto raise timer even if in focus-follows-mouse mode
1119 * and the event is for the frame window, even if the window
1120 * has focus already. useful if you move the pointer from a focused
1121 * window to the root window and back pretty fast
1123 * set focus if in focus-follows-mouse mode and the event
1124 * is for the frame window and window doesn't have focus yet */
1125 if (wPreferences
.focus_mode
== WKF_SLOPPY
1126 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1128 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1129 wSetFocusTo(scr
, wwin
);
1131 if (scr
->autoRaiseTimer
)
1132 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1133 scr
->autoRaiseTimer
= NULL
;
1135 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1136 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1138 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1141 /* Install colormap for window, if the colormap installation mode
1142 * is colormap_follows_mouse */
1143 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1144 if (wwin
->client_win
== event
->xcrossing
.window
)
1145 wColormapInstallForWindow(scr
, wwin
);
1147 wColormapInstallForWindow(scr
, NULL
);
1151 if (event
->xcrossing
.window
== event
->xcrossing
.root
1152 && event
->xcrossing
.detail
== NotifyNormal
1153 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1155 wSetFocusTo(scr
, scr
->focused_window
);
1158 wBalloonEnteredObject(scr
, desc
);
1162 static void handleLeaveNotify(XEvent
* event
)
1164 WObjDescriptor
*desc
= NULL
;
1166 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1167 if (desc
->handle_leavenotify
)
1168 (*desc
->handle_leavenotify
) (desc
, event
);
1173 static void handleShapeNotify(XEvent
* event
)
1175 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1182 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1183 if (ev
.xshape
.kind
== ShapeBounding
) {
1184 if (ev
.xshape
.shaped
== shev
->shaped
) {
1187 XPutBackEvent(dpy
, &ev
.xevent
);
1193 wwin
= wWindowFor(shev
->window
);
1194 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1197 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1199 wwin
->flags
.shaped
= 0;
1200 wWindowClearShape(wwin
);
1202 } else if (shev
->shaped
) {
1204 wwin
->flags
.shaped
= 1;
1205 wWindowSetShape(wwin
);
1210 #ifdef KEEP_XKB_LOCK_STATUS
1211 /* please help ]d if you know what to do */
1212 static void handleXkbIndicatorStateNotify(XEvent
*event
)
1216 XkbStateRec staterec
;
1219 for (i
= 0; i
< wScreenCount
; i
++) {
1220 scr
= wScreenWithNumber(i
);
1221 wwin
= scr
->focused_window
;
1222 if (wwin
&& wwin
->flags
.focused
) {
1223 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1224 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1225 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1226 wwin
->frame
->languagemode
= staterec
.group
;
1228 #ifdef XKB_BUTTON_HINT
1229 if (wwin
->frame
->titlebar
) {
1230 wFrameWindowPaint(wwin
->frame
);
1236 #endif /*KEEP_XKB_LOCK_STATUS */
1238 static void handleColormapNotify(XEvent
* event
)
1242 Bool reinstall
= False
;
1244 wwin
= wWindowFor(event
->xcolormap
.window
);
1248 scr
= wwin
->screen_ptr
;
1252 if (event
->xcolormap
.new) {
1253 XWindowAttributes attr
;
1255 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1257 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1258 scr
->current_colormap
= attr
.colormap
;
1261 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1262 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1264 /* some bastard app (like XV) removed our colormap */
1266 * can't enforce or things like xscreensaver wont work
1269 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1270 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1272 /* someone has put our colormap back */
1276 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1277 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1279 if (reinstall
&& scr
->current_colormap
!= None
) {
1280 if (!scr
->flags
.colormap_stuff_blocked
)
1281 XInstallColormap(dpy
, scr
->current_colormap
);
1285 static void handleFocusIn(XEvent
* event
)
1290 * For applications that like stealing the focus.
1292 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1293 saveTimestamp(event
);
1294 if (event
->xfocus
.mode
== NotifyUngrab
1295 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1299 wwin
= wWindowFor(event
->xfocus
.window
);
1300 if (wwin
&& !wwin
->flags
.focused
) {
1301 if (wwin
->flags
.mapped
)
1302 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1304 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1306 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1308 wSetFocusTo(scr
, NULL
);
1312 static WWindow
*windowUnderPointer(WScreen
* scr
)
1318 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1319 return wWindowFor(win
);
1323 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1325 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1331 static void handleKeyPress(XEvent
* event
)
1333 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1334 WWindow
*wwin
= scr
->focused_window
;
1338 #ifdef KEEP_XKB_LOCK_STATUS
1339 XkbStateRec staterec
;
1340 #endif /*KEEP_XKB_LOCK_STATUS */
1342 /* ignore CapsLock */
1343 modifiers
= event
->xkey
.state
& ValidModMask
;
1345 for (i
= 0; i
< WKBD_LAST
; i
++) {
1346 if (wKeyBindings
[i
].keycode
== 0)
1349 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1350 || */ wKeyBindings
[i
].modifier
==
1359 if (!wRootMenuPerformShortcut(event
)) {
1360 static int dontLoop
= 0;
1362 if (dontLoop
> 10) {
1363 wwarning("problem with key event processing code");
1367 /* if the focused window is an internal window, try redispatching
1368 * the event to the managed window, as it can be a WINGs window */
1369 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1370 /* client_leader contains the WINGs toplevel */
1371 event
->xany
.window
= wwin
->client_leader
;
1372 WMHandleEvent(event
);
1378 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1379 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1384 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1385 if (!CheckFullScreenWindowFocused(scr
)) {
1386 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1387 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1391 case WKBD_WINDOWLIST
:
1392 if (!CheckFullScreenWindowFocused(scr
)) {
1393 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1394 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1399 case WKBD_WINDOWMENU
:
1400 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1401 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1403 case WKBD_MINIMIZEALL
:
1404 CloseWindowMenu(scr
);
1407 case WKBD_MINIATURIZE
:
1408 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1409 && !WFLAGP(wwin
, no_miniaturizable
)) {
1410 CloseWindowMenu(scr
);
1412 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1413 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, event
->xbutton
.time
);
1415 wIconifyWindow(wwin
);
1420 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1421 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1422 CloseWindowMenu(scr
);
1424 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1425 wHideApplication(wapp
);
1429 case WKBD_HIDE_OTHERS
:
1430 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1431 CloseWindowMenu(scr
);
1433 wHideOtherApplications(wwin
);
1437 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1438 CloseWindowMenu(scr
);
1440 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1443 case WKBD_VMAXIMIZE
:
1444 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1445 CloseWindowMenu(scr
);
1447 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1450 case WKBD_HMAXIMIZE
:
1451 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1452 CloseWindowMenu(scr
);
1454 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1457 case WKBD_LHMAXIMIZE
:
1458 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1459 CloseWindowMenu(scr
);
1461 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1464 case WKBD_RHMAXIMIZE
:
1465 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1466 CloseWindowMenu(scr
);
1468 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1471 case WKBD_THMAXIMIZE
:
1472 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1473 CloseWindowMenu(scr
);
1475 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1478 case WKBD_BHMAXIMIZE
:
1479 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1480 CloseWindowMenu(scr
);
1482 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1485 case WKBD_LTCMAXIMIZE
:
1486 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1487 CloseWindowMenu(scr
);
1489 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1492 case WKBD_RTCMAXIMIZE
:
1493 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1494 CloseWindowMenu(scr
);
1496 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1499 case WKBD_LBCMAXIMIZE
:
1500 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1501 CloseWindowMenu(scr
);
1503 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1506 case WKBD_RBCMAXIMIZE
:
1507 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1508 CloseWindowMenu(scr
);
1510 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1514 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1515 CloseWindowMenu(scr
);
1517 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1521 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1522 CloseWindowMenu(scr
);
1524 wRaiseFrame(wwin
->frame
->core
);
1528 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1529 CloseWindowMenu(scr
);
1531 wLowerFrame(wwin
->frame
->core
);
1534 case WKBD_RAISELOWER
:
1535 /* raise or lower the window under the pointer, not the
1538 wwin
= windowUnderPointer(scr
);
1540 wRaiseLowerFrame(wwin
->frame
->core
);
1543 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1544 if (wwin
->flags
.shaded
)
1545 wUnshadeWindow(wwin
);
1550 case WKBD_MOVERESIZE
:
1551 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1552 CloseWindowMenu(scr
);
1554 wKeyboardMoveResizeWindow(wwin
);
1558 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1559 CloseWindowMenu(scr
);
1560 if (wwin
->protocols
.DELETE_WINDOW
)
1561 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, event
->xkey
.time
);
1565 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1566 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1569 case WKBD_FOCUSNEXT
:
1570 StartWindozeCycle(wwin
, event
, True
, False
);
1573 case WKBD_FOCUSPREV
:
1574 StartWindozeCycle(wwin
, event
, False
, False
);
1577 case WKBD_GROUPNEXT
:
1578 StartWindozeCycle(wwin
, event
, True
, True
);
1581 case WKBD_GROUPPREV
:
1582 StartWindozeCycle(wwin
, event
, False
, True
);
1585 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1586 widx
= command
- WKBD_WORKSPACE1
;
1587 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1588 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1589 wWorkspaceChange(scr
, i
);
1592 case WKBD_NEXTWORKSPACE
:
1593 wWorkspaceRelativeChange(scr
, 1);
1595 case WKBD_PREVWORKSPACE
:
1596 wWorkspaceRelativeChange(scr
, -1);
1598 case WKBD_LASTWORKSPACE
:
1599 wWorkspaceChange(scr
, scr
->last_workspace
);
1602 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1603 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1604 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1605 if (wwin
&& (wPreferences
.ws_advance
|| i
< scr
->workspace_count
))
1606 wWindowChangeWorkspace(wwin
, i
);
1609 case WKBD_MOVE_NEXTWORKSPACE
:
1611 wWindowChangeWorkspaceRelative(wwin
, 1);
1613 case WKBD_MOVE_PREVWORKSPACE
:
1615 wWindowChangeWorkspaceRelative(wwin
, -1);
1617 case WKBD_MOVE_LASTWORKSPACE
:
1619 wWindowChangeWorkspace(wwin
, scr
->last_workspace
);
1622 case WKBD_MOVE_NEXTWSLAYER
:
1623 case WKBD_MOVE_PREVWSLAYER
:
1628 row
= scr
->current_workspace
/ 10;
1629 column
= scr
->current_workspace
% 10;
1631 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1632 if ((row
+ 1) * 10 < scr
->workspace_count
)
1633 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1636 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1653 widx
= command
- WKBD_WINDOW1
;
1655 if (scr
->shortcutWindows
[widx
]) {
1656 WMArray
*list
= scr
->shortcutWindows
[widx
];
1658 int count
= WMGetArrayItemCount(list
);
1660 WMArrayIterator iter
;
1663 wUnselectWindows(scr
);
1664 cw
= scr
->current_workspace
;
1666 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1668 wWindowChangeWorkspace(wwin
, cw
);
1670 wMakeWindowVisible(wwin
);
1673 wSelectWindow(wwin
, True
);
1676 /* rotate the order of windows, to create a cycling effect */
1677 twin
= WMGetFromArray(list
, 0);
1678 WMDeleteFromArray(list
, 0);
1679 WMAddToArray(list
, twin
);
1681 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1682 if (scr
->shortcutWindows
[widx
]) {
1683 WMFreeArray(scr
->shortcutWindows
[widx
]);
1684 scr
->shortcutWindows
[widx
] = NULL
;
1687 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1688 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1689 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1690 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1692 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1693 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1696 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1699 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1702 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1704 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1705 if (scr
->shortcutWindows
[widx
]) {
1706 WMFreeArray(scr
->shortcutWindows
[widx
]);
1708 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1715 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1716 (void) RelaunchWindow(wwin
);
1720 case WKBD_SWITCH_SCREEN
:
1721 if (wScreenCount
> 1) {
1725 /* find index of this screen */
1726 for (i
= 0; i
< wScreenCount
; i
++) {
1727 if (wScreenWithNumber(i
) == scr
)
1731 if (i
>= wScreenCount
) {
1734 scr2
= wScreenWithNumber(i
);
1737 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1738 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1743 case WKBD_NEXTWSLAYER
:
1744 case WKBD_PREVWSLAYER
:
1748 row
= scr
->current_workspace
/ 10;
1749 column
= scr
->current_workspace
% 10;
1751 if (command
== WKBD_NEXTWSLAYER
) {
1752 if ((row
+ 1) * 10 < scr
->workspace_count
)
1753 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1756 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1760 case WKBD_CLIPRAISELOWER
:
1761 if (!wPreferences
.flags
.noclip
)
1762 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1764 case WKBD_DOCKRAISELOWER
:
1765 if (!wPreferences
.flags
.nodock
)
1766 wDockRaiseLower(scr
->dock
);
1768 #ifdef KEEP_XKB_LOCK_STATUS
1770 if (wPreferences
.modelock
) {
1772 wwin
= scr
->focused_window
;
1774 if (wwin
&& wwin
->flags
.mapped
1775 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1776 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1777 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1779 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1780 wwin
->frame
->last_languagemode
= staterec
.group
;
1781 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1786 #endif /* KEEP_XKB_LOCK_STATUS */
1790 static void handleMotionNotify(XEvent
* event
)
1792 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1794 if (wPreferences
.scrollable_menus
) {
1795 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1796 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1798 if (scr
->flags
.jump_back_pending
||
1799 p
.x
<= (rect
.pos
.x
+ 1) ||
1800 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1801 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1804 menu
= wMenuUnderPointer(scr
);
1806 wMenuScroll(menu
, event
);
1811 static void handleVisibilityNotify(XEvent
* event
)
1815 wwin
= wWindowFor(event
->xvisibility
.window
);
1818 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);