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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
23 #include <sys/inotify.h>
32 #include <X11/Xutil.h>
34 # include <X11/extensions/shape.h>
40 #ifdef KEEP_XKB_LOCK_STATUS
41 #include <X11/XKBlib.h>
42 #endif /* KEEP_XKB_LOCK_STATUS */
44 #include "WindowMaker.h"
50 #include "application.h"
53 #include "workspace.h"
56 #include "properties.h"
64 /******** Global Variables **********/
65 extern XContext wWinContext
;
66 extern XContext wVEdgeContext
;
68 extern Cursor wCursor
[WCUR_LAST
];
70 extern WShortKey wKeyBindings
[WKBD_LAST
];
71 extern int wScreenCount
;
72 extern Time LastTimestamp
;
73 extern Time LastFocusChange
;
75 extern WPreferences wPreferences
;
77 #define MOD_MASK wPreferences.modifier_mask
79 extern Atom _XA_WM_COLORMAP_NOTIFY
;
81 extern Atom _XA_WM_CHANGE_STATE
;
82 extern Atom _XA_WM_DELETE_WINDOW
;
83 extern Atom _XA_GNUSTEP_WM_ATTR
;
84 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
85 extern Atom _XA_GNUSTEP_TITLEBAR_STATE
;
86 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
87 extern Atom _XA_WINDOWMAKER_COMMAND
;
88 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS
;
91 extern Bool wShapeSupported
;
92 extern int wShapeEventBase
;
95 #ifdef KEEP_XKB_LOCK_STATUS
96 extern int wXkbEventBase
;
100 /*extern char WDelayedActionSet;*/
102 /************ Local stuff ***********/
104 static void saveTimestamp(XEvent
*event
);
105 static void handleColormapNotify(XEvent
*event
);
106 static void handleMapNotify(XEvent
*event
);
107 static void handleUnmapNotify(XEvent
*event
);
108 static void handleButtonPress(XEvent
*event
);
109 static void handleExpose(XEvent
*event
);
110 static void handleDestroyNotify(XEvent
*event
);
111 static void handleConfigureRequest(XEvent
*event
);
112 static void handleMapRequest(XEvent
*event
);
113 static void handlePropertyNotify(XEvent
*event
);
114 static void handleEnterNotify(XEvent
*event
);
115 static void handleLeaveNotify(XEvent
*event
);
116 static void handleExtensions(XEvent
*event
);
117 static void handleClientMessage(XEvent
*event
);
118 static void handleKeyPress(XEvent
*event
);
119 static void handleFocusIn(XEvent
*event
);
120 static void handleMotionNotify(XEvent
*event
);
121 static void handleVisibilityNotify(XEvent
*event
);
124 static void handleShapeNotify(XEvent
*event
);
127 /* called from the signal handler */
128 void NotifyDeadProcess(pid_t pid
, unsigned char status
);
130 /* real dead process handler */
131 static void handleDeadProcess(void *foo
);
133 typedef struct DeadProcesses
{
135 unsigned char exit_status
;
138 /* stack of dead processes */
139 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
140 static int deadProcessPtr
= 0;
142 typedef struct DeathHandler
{
143 WDeathHandler
*callback
;
148 static WMArray
*deathHandlers
= NULL
;
150 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
152 DeathHandler
*handler
;
154 handler
= malloc(sizeof(DeathHandler
));
159 handler
->callback
= callback
;
160 handler
->client_data
= cdata
;
163 deathHandlers
= WMCreateArrayWithDestructor(8, wfree
);
165 WMAddToArray(deathHandlers
, handler
);
170 void wDeleteDeathHandler(WMagicNumber id
)
172 DeathHandler
*handler
= (DeathHandler
*) id
;
174 if (!handler
|| !deathHandlers
)
177 /* array destructor will call wfree(handler) */
178 WMRemoveFromArray(deathHandlers
, handler
);
181 void DispatchEvent(XEvent
* event
)
184 handleDeadProcess(NULL
);
186 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
187 WCHANGE_STATE(WSTATE_EXITING
);
188 /* received SIGTERM */
190 * WMHandleEvent() can't be called from anything
191 * executed inside here, or we can get in a infinite
194 Shutdown(WSExitMode
);
196 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
197 WCHANGE_STATE(WSTATE_RESTARTING
);
199 Shutdown(WSRestartPreparationMode
);
200 /* received SIGHUP */
202 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
203 WCHANGE_STATE(WSTATE_NORMAL
);
204 wDefaultsCheckDomains();
207 /* for the case that all that is wanted to be dispatched is
212 saveTimestamp(event
);
213 switch (event
->type
) {
215 handleMapRequest(event
);
219 handleKeyPress(event
);
223 handleMotionNotify(event
);
226 case ConfigureRequest
:
227 handleConfigureRequest(event
);
231 handleDestroyNotify(event
);
235 handleMapNotify(event
);
239 handleUnmapNotify(event
);
243 handleButtonPress(event
);
251 handlePropertyNotify(event
);
255 handleEnterNotify(event
);
259 handleLeaveNotify(event
);
263 handleClientMessage(event
);
267 handleColormapNotify(event
);
271 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
272 XRefreshKeyboardMapping(&event
->xmapping
);
276 handleFocusIn(event
);
279 case VisibilityNotify
:
280 handleVisibilityNotify(event
);
283 handleExtensions(event
);
289 *----------------------------------------------------------------------
290 * inotifyHandleEvents-
291 * Check for inotify events
294 * After reading events for the given file descriptor (fd) and
295 * watch descriptor (wd)
298 * Calls wDefaultsCheckDomains if config database is updated
299 *----------------------------------------------------------------------
301 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
302 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
303 void inotifyHandleEvents(int fd
, int wd
)
305 extern void wDefaultsCheckDomains(void);
306 ssize_t eventQLength
, i
= 0;
307 char buff
[BUFF_SIZE
] = { 0 };
308 /* Check config only once per read of the event queue */
312 * Read off the queued events
313 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
314 * not occur; the block is on Xevents, but a config file change will normally
315 * occur as a result of an Xevent - so the event queue should never have more than
316 * a few entries before a read().
318 eventQLength
= read(fd
, buff
, BUFF_SIZE
);
320 /* check what events occured */
321 /* Should really check wd here too, but for now we only have one watch! */
322 while (i
< eventQLength
) {
323 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
326 * see inotify.h for event types.
328 if (pevent
->mask
& IN_DELETE_SELF
) {
329 wwarning(_("the defaults database has been deleted!"
330 " Restart Window Maker to create the database" " with the default settings"));
333 if (pevent
->mask
& IN_UNMOUNT
) {
334 wwarning(_("the unit containing the defaults database has"
335 " been unmounted. Setting --static mode." " Any changes will not be saved."));
337 wPreferences
.flags
.noupdates
= 1;
339 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
340 fprintf(stdout
, "wmaker: reading config files in defaults database.\n");
341 wDefaultsCheckDomains();
344 /* move to next event in the buffer */
345 i
+= sizeof(struct inotify_event
) + pevent
->len
;
350 *----------------------------------------------------------------------
352 * Processes X and internal events indefinitely.
358 * The LastTimestamp global variable is updated.
359 * Calls inotifyGetEvents if defaults database changes.
360 *----------------------------------------------------------------------
365 extern int inotifyFD
;
366 extern int inotifyWD
;
371 if (inotifyFD
< 0 || inotifyWD
< 0)
376 WMNextEvent(dpy
, &event
); /* Blocks here */
377 WMHandleEvent(&event
);
383 FD_SET(inotifyFD
, &rfds
);
385 /* check for available read data from inotify - don't block! */
386 retVal
= select(inotifyFD
+ 1, &rfds
, NULL
, NULL
, &time
);
388 if (retVal
< 0) { /* an error has occured */
389 wwarning(_("select failed. The inotify instance will be closed."
390 " Changes to the defaults database will require"
391 " a restart to take effect."));
395 if (FD_ISSET(inotifyFD
, &rfds
))
396 inotifyHandleEvents(inotifyFD
, inotifyWD
);
402 *----------------------------------------------------------------------
403 * ProcessPendingEvents --
404 * Processes the events that are currently pending (at the time
405 * this function is called) in the display's queue.
408 * After the pending events that were present at the function call
412 * Many -- whatever handling events may involve.
414 *----------------------------------------------------------------------
416 void ProcessPendingEvents(void)
423 /* Take a snapshot of the event count in the queue */
424 count
= XPending(dpy
);
426 while (count
> 0 && XPending(dpy
)) {
427 WMNextEvent(dpy
, &event
);
428 WMHandleEvent(&event
);
433 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
435 if ((scr
->last_click_time
> 0) &&
436 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
437 && (event
->xbutton
.button
== scr
->last_click_button
)
438 && (event
->xbutton
.window
== scr
->last_click_window
)) {
440 scr
->flags
.next_click_is_not_double
= 1;
441 scr
->last_click_time
= 0;
442 scr
->last_click_window
= event
->xbutton
.window
;
449 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
451 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
452 wwarning("stack overflow: too many dead processes");
455 /* stack the process to be handled later,
456 * as this is called from the signal handler */
457 deadProcesses
[deadProcessPtr
].pid
= pid
;
458 deadProcesses
[deadProcessPtr
].exit_status
= status
;
462 static void handleDeadProcess(void *foo
)
467 for (i
= 0; i
< deadProcessPtr
; i
++) {
468 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
471 if (!deathHandlers
) {
476 /* get the pids on the queue and call handlers */
477 while (deadProcessPtr
> 0) {
480 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
481 tmp
= WMGetFromArray(deathHandlers
, i
);
485 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
486 (*tmp
->callback
) (tmp
->pid
,
487 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
488 wDeleteDeathHandler(tmp
);
494 static void saveTimestamp(XEvent
* event
)
497 * Never save CurrentTime as LastTimestamp because CurrentTime
498 * it's not a real timestamp (it's the 0L constant)
501 switch (event
->type
) {
504 LastTimestamp
= event
->xbutton
.time
;
508 LastTimestamp
= event
->xkey
.time
;
511 LastTimestamp
= event
->xmotion
.time
;
514 LastTimestamp
= event
->xproperty
.time
;
518 LastTimestamp
= event
->xcrossing
.time
;
521 LastTimestamp
= event
->xselectionclear
.time
;
523 case SelectionRequest
:
524 LastTimestamp
= event
->xselectionrequest
.time
;
526 case SelectionNotify
:
527 LastTimestamp
= event
->xselection
.time
;
529 wXDNDProcessSelection(event
);
535 static int matchWindow(void *item
, void *cdata
)
537 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
540 static void handleExtensions(XEvent
* event
)
542 #ifdef KEEP_XKB_LOCK_STATUS
544 xkbevent
= (XkbEvent
*) event
;
545 #endif /*KEEP_XKB_LOCK_STATUS */
547 if (wShapeSupported
&& event
->type
== (wShapeEventBase
+ ShapeNotify
)) {
548 handleShapeNotify(event
);
551 #ifdef KEEP_XKB_LOCK_STATUS
552 if (wPreferences
.modelock
&& (xkbevent
->type
== wXkbEventBase
)) {
553 handleXkbIndicatorStateNotify(event
);
555 #endif /*KEEP_XKB_LOCK_STATUS */
558 static void handleMapRequest(XEvent
* ev
)
562 Window window
= ev
->xmaprequest
.window
;
565 printf("got map request for %x\n", (unsigned)window
);
567 if ((wwin
= wWindowFor(window
))) {
568 if (wwin
->flags
.shaded
) {
569 wUnshadeWindow(wwin
);
571 /* deiconify window */
572 if (wwin
->flags
.miniaturized
) {
573 wDeiconifyWindow(wwin
);
574 } else if (wwin
->flags
.hidden
) {
575 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
576 /* go to the last workspace that the user worked on the app */
578 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
580 wUnhideApplication(wapp
, False
, False
);
585 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
587 wwin
= wManageWindow(scr
, window
);
590 * This is to let the Dock know that the application it launched
591 * has already been mapped (eg: it has finished launching).
592 * It is not necessary for normally docked apps, but is needed for
593 * apps that were forcedly docked (like with dockit).
595 if (scr
->last_dock
) {
596 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
597 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
599 wDockTrackWindowLaunch(scr
->last_dock
, window
);
603 wClientSetState(wwin
, NormalState
, None
);
604 if (wwin
->flags
.maximized
) {
605 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
607 if (wwin
->flags
.shaded
) {
608 wwin
->flags
.shaded
= 0;
609 wwin
->flags
.skip_next_animation
= 1;
612 if (wwin
->flags
.miniaturized
) {
613 wwin
->flags
.miniaturized
= 0;
614 wwin
->flags
.skip_next_animation
= 1;
615 wIconifyWindow(wwin
);
617 if (wwin
->flags
.fullscreen
) {
618 wwin
->flags
.fullscreen
= 0;
619 wFullscreenWindow(wwin
);
621 if (wwin
->flags
.hidden
) {
622 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
624 wwin
->flags
.hidden
= 0;
625 wwin
->flags
.skip_next_animation
= 1;
627 wHideApplication(wapp
);
633 static void handleDestroyNotify(XEvent
* event
)
637 Window window
= event
->xdestroywindow
.window
;
638 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
642 printf("got destroy notify\n");
644 wwin
= wWindowFor(window
);
646 wUnmanageWindow(wwin
, False
, True
);
650 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
651 WFakeGroupLeader
*fPtr
;
653 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
654 if (fPtr
->retainCount
> 0) {
656 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
657 XDestroyWindow(dpy
, fPtr
->leader
);
662 fPtr
->origLeader
= None
;
666 app
= wApplicationOf(window
);
668 if (window
== app
->main_window
) {
670 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
672 if (wwin
->main_window
== window
) {
673 wwin
->main_window
= None
;
678 wApplicationDestroy(app
);
682 static void handleExpose(XEvent
* event
)
684 WObjDescriptor
*desc
;
688 printf("got expose\n");
690 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
692 if (XFindContext(dpy
, event
->xexpose
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
696 if (desc
->handle_expose
) {
697 (*desc
->handle_expose
) (desc
, event
);
701 static void executeButtonAction(WScreen
* scr
, XEvent
* event
, int action
)
704 case WA_SELECT_WINDOWS
:
705 wUnselectWindows(scr
);
706 wSelectWindows(scr
, event
);
708 case WA_OPEN_APPMENU
:
709 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
711 if (scr
->root_menu
) {
712 if (scr
->root_menu
->brother
->flags
.mapped
)
713 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
715 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
718 case WA_OPEN_WINLISTMENU
:
719 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
720 if (scr
->switch_menu
) {
721 if (scr
->switch_menu
->brother
->flags
.mapped
)
722 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
724 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
733 static void handleButtonPress(XEvent
* event
)
735 WObjDescriptor
*desc
;
739 printf("got button press\n");
741 scr
= wScreenForRootWindow(event
->xbutton
.root
);
747 if (event
->xbutton
.window
== scr
->root_win
) {
748 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
749 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
750 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
751 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
752 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
753 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
754 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
755 wWorkspaceRelativeChange(scr
, 1);
756 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
757 wWorkspaceRelativeChange(scr
, -1);
762 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
763 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
768 if (desc
->parent_type
== WCLASS_WINDOW
) {
771 if (event
->xbutton
.state
& MOD_MASK
) {
772 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
775 /* if (wPreferences.focus_mode == WKF_CLICK) { */
776 if (wPreferences
.ignore_focus_click
) {
777 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
779 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
782 } else if (desc
->parent_type
== WCLASS_APPICON
783 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
784 if (event
->xbutton
.state
& MOD_MASK
) {
786 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
791 if (desc
->handle_mousedown
!= NULL
) {
792 (*desc
->handle_mousedown
) (desc
, event
);
795 /* save double-click information */
796 if (scr
->flags
.next_click_is_not_double
) {
797 scr
->flags
.next_click_is_not_double
= 0;
799 scr
->last_click_time
= event
->xbutton
.time
;
800 scr
->last_click_button
= event
->xbutton
.button
;
801 scr
->last_click_window
= event
->xbutton
.window
;
805 static void handleMapNotify(XEvent
* event
)
811 wwin
= wWindowFor(event
->xmap
.event
);
812 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
813 if (wwin
->flags
.miniaturized
) {
814 wDeiconifyWindow(wwin
);
818 wClientSetState(wwin
, NormalState
, None
);
824 static void handleUnmapNotify(XEvent
* event
)
828 Bool withdraw
= False
;
830 printf("got unmap\n");
832 /* only process windows with StructureNotify selected
833 * (ignore SubstructureNotify) */
834 wwin
= wWindowFor(event
->xunmap
.window
);
838 /* whether the event is a Withdrawal request */
839 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
842 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
845 if (!wwin
->flags
.mapped
&& !withdraw
846 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
847 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
851 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
852 wwin
->flags
.mapped
= 0;
854 /* check if the window was destroyed */
855 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
858 Bool reparented
= False
;
860 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
863 /* withdraw window */
864 wwin
->flags
.mapped
= 0;
866 wClientSetState(wwin
, WithdrawnState
, None
);
868 /* if the window was reparented, do not reparent it back to the
870 wUnmanageWindow(wwin
, !reparented
, False
);
875 static void handleConfigureRequest(XEvent
* event
)
879 printf("got configure request\n");
881 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
883 * Configure request for unmapped window
885 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
887 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
891 static void handlePropertyNotify(XEvent
* event
)
900 printf("got property notify\n");
903 wwin
= wWindowFor(event
->xproperty
.window
);
905 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
908 wClientCheckProperty(wwin
, &event
->xproperty
);
910 wapp
= wApplicationOf(event
->xproperty
.window
);
912 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
915 scr
= wScreenForWindow(event
->xproperty
.window
);
918 static void handleClientMessage(XEvent
* event
)
921 WObjDescriptor
*desc
;
923 printf("got client message\n");
925 /* handle transition from Normal to Iconic state */
926 if (event
->xclient
.message_type
== _XA_WM_CHANGE_STATE
927 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
929 wwin
= wWindowFor(event
->xclient
.window
);
932 if (!wwin
->flags
.miniaturized
)
933 wIconifyWindow(wwin
);
934 } else if (event
->xclient
.message_type
== _XA_WM_COLORMAP_NOTIFY
&& event
->xclient
.format
== 32) {
935 WScreen
*scr
= wScreenSearchForRootWindow(event
->xclient
.window
);
940 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
941 wColormapAllowClientInstallation(scr
, True
);
942 } else { /* stopping */
943 wColormapAllowClientInstallation(scr
, False
);
945 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_COMMAND
) {
947 wDefaultsCheckDomains();
949 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
952 wapp
= wApplicationOf(event
->xclient
.window
);
954 switch (event
->xclient
.data
.l
[0]) {
955 case WMFHideOtherApplications
:
956 wHideOtherApplications(wapp
->main_window_desc
);
960 case WMFHideApplication
:
961 wHideApplication(wapp
);
967 wwin
= wWindowFor(event
->xclient
.window
);
969 switch (event
->xclient
.data
.l
[0]) {
970 case WMFHideOtherApplications
:
971 wHideOtherApplications(wwin
);
974 case WMFHideApplication
:
975 wHideApplication(wApplicationOf(wwin
->main_window
));
980 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_WM_ATTR
) {
981 wwin
= wWindowFor(event
->xclient
.window
);
984 switch (event
->xclient
.data
.l
[0]) {
985 case GSWindowLevelAttr
:
987 int level
= (int)event
->xclient
.data
.l
[1];
989 if (WINDOW_LEVEL(wwin
) != level
) {
990 ChangeStackingLevel(wwin
->frame
->core
, level
);
995 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_TITLEBAR_STATE
) {
996 wwin
= wWindowFor(event
->xclient
.window
);
999 switch (event
->xclient
.data
.l
[0]) {
1000 case WMTitleBarNormal
:
1001 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1003 case WMTitleBarMain
:
1004 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1007 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1010 } else if (event
->xclient
.message_type
== _XA_WM_IGNORE_FOCUS_EVENTS
) {
1011 WScreen
*scr
= wScreenSearchForRootWindow(event
->xclient
.window
);
1014 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1016 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1020 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1025 * Non-standard thing, but needed by OffiX DND.
1026 * For when the icon frame gets a ClientMessage
1027 * that should have gone to the icon_window.
1029 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1030 struct WIcon
*icon
= NULL
;
1032 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1033 icon
= (WIcon
*) desc
->parent
;
1034 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1035 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1037 if (icon
&& (wwin
= icon
->owner
)) {
1038 if (wwin
->client_win
!= event
->xclient
.window
) {
1039 event
->xclient
.window
= wwin
->client_win
;
1040 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1047 static void raiseWindow(WScreen
* scr
)
1051 scr
->autoRaiseTimer
= NULL
;
1053 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1057 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1058 wRaiseFrame(wwin
->frame
->core
);
1059 /* this is needed or a race condition will occur */
1064 static void handleEnterNotify(XEvent
* event
)
1067 WObjDescriptor
*desc
= NULL
;
1068 #ifdef VIRTUAL_DESKTOP
1069 void (*vdHandler
) (XEvent
* event
);
1072 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1074 printf("got enter notify\n");
1077 #ifdef VIRTUAL_DESKTOP
1078 if (XFindContext(dpy
, event
->xcrossing
.window
, wVEdgeContext
, (XPointer
*) & vdHandler
) != XCNOENT
) {
1079 (*vdHandler
) (event
);
1083 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1084 /* already left the window... */
1086 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1091 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1092 if (desc
->handle_enternotify
)
1093 (*desc
->handle_enternotify
) (desc
, event
);
1096 /* enter to window */
1097 wwin
= wWindowFor(event
->xcrossing
.window
);
1099 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1100 wColormapInstallForWindow(scr
, NULL
);
1102 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1103 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1104 scr
->autoRaiseTimer
= NULL
;
1107 /* set auto raise timer even if in focus-follows-mouse mode
1108 * and the event is for the frame window, even if the window
1109 * has focus already. useful if you move the pointer from a focused
1110 * window to the root window and back pretty fast
1112 * set focus if in focus-follows-mouse mode and the event
1113 * is for the frame window and window doesn't have focus yet */
1114 if (wPreferences
.focus_mode
== WKF_SLOPPY
1115 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1117 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1118 wSetFocusTo(scr
, wwin
);
1120 if (scr
->autoRaiseTimer
)
1121 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1122 scr
->autoRaiseTimer
= NULL
;
1124 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1125 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1127 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1130 /* Install colormap for window, if the colormap installation mode
1131 * is colormap_follows_mouse */
1132 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1133 if (wwin
->client_win
== event
->xcrossing
.window
)
1134 wColormapInstallForWindow(scr
, wwin
);
1136 wColormapInstallForWindow(scr
, NULL
);
1140 /* a little kluge to hide the clip balloon */
1141 if (!wPreferences
.flags
.noclip
&& scr
->flags
.clip_balloon_mapped
) {
1143 XUnmapWindow(dpy
, scr
->clip_balloon
);
1144 scr
->flags
.clip_balloon_mapped
= 0;
1146 if (desc
->parent_type
!= WCLASS_DOCK_ICON
|| scr
->clip_icon
!= desc
->parent
) {
1147 XUnmapWindow(dpy
, scr
->clip_balloon
);
1148 scr
->flags
.clip_balloon_mapped
= 0;
1153 if (event
->xcrossing
.window
== event
->xcrossing
.root
1154 && event
->xcrossing
.detail
== NotifyNormal
1155 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1157 wSetFocusTo(scr
, scr
->focused_window
);
1160 wBalloonEnteredObject(scr
, desc
);
1164 static void handleLeaveNotify(XEvent
* event
)
1166 WObjDescriptor
*desc
= NULL
;
1168 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1169 if (desc
->handle_leavenotify
)
1170 (*desc
->handle_leavenotify
) (desc
, event
);
1175 static void handleShapeNotify(XEvent
* event
)
1177 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1181 printf("got shape notify\n");
1183 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
)) {
1184 XShapeEvent
*sev
= (XShapeEvent
*) & ev
;
1186 if (sev
->kind
== ShapeBounding
) {
1187 if (sev
->shaped
== shev
->shaped
) {
1190 XPutBackEvent(dpy
, &ev
);
1196 wwin
= wWindowFor(shev
->window
);
1197 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1200 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1202 wwin
->flags
.shaped
= 0;
1203 wWindowClearShape(wwin
);
1205 } else if (shev
->shaped
) {
1207 wwin
->flags
.shaped
= 1;
1208 wWindowSetShape(wwin
);
1213 #ifdef KEEP_XKB_LOCK_STATUS
1214 /* please help ]d if you know what to do */
1215 handleXkbIndicatorStateNotify(XEvent
* event
)
1219 XkbStateRec staterec
;
1222 for (i
= 0; i
< wScreenCount
; i
++) {
1223 scr
= wScreenWithNumber(i
);
1224 wwin
= scr
->focused_window
;
1225 if (wwin
&& wwin
->flags
.focused
) {
1226 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1227 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1228 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1229 wwin
->frame
->languagemode
= staterec
.group
;
1231 #ifdef XKB_BUTTON_HINT
1232 if (wwin
->frame
->titlebar
) {
1233 wFrameWindowPaint(wwin
->frame
);
1239 #endif /*KEEP_XKB_LOCK_STATUS */
1241 static void handleColormapNotify(XEvent
* event
)
1245 Bool reinstall
= False
;
1247 wwin
= wWindowFor(event
->xcolormap
.window
);
1251 scr
= wwin
->screen_ptr
;
1255 if (event
->xcolormap
.new) {
1256 XWindowAttributes attr
;
1258 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1260 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1261 scr
->current_colormap
= attr
.colormap
;
1264 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1265 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1267 /* some bastard app (like XV) removed our colormap */
1269 * can't enforce or things like xscreensaver wont work
1272 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1273 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1275 /* someone has put our colormap back */
1279 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1280 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1282 if (reinstall
&& scr
->current_colormap
!= None
) {
1283 if (!scr
->flags
.colormap_stuff_blocked
)
1284 XInstallColormap(dpy
, scr
->current_colormap
);
1288 static void handleFocusIn(XEvent
* event
)
1293 * For applications that like stealing the focus.
1295 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1296 saveTimestamp(event
);
1297 if (event
->xfocus
.mode
== NotifyUngrab
1298 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1302 wwin
= wWindowFor(event
->xfocus
.window
);
1303 if (wwin
&& !wwin
->flags
.focused
) {
1304 if (wwin
->flags
.mapped
)
1305 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1307 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1309 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1311 wSetFocusTo(scr
, NULL
);
1315 static WWindow
*windowUnderPointer(WScreen
* scr
)
1321 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1322 return wWindowFor(win
);
1326 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1328 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1334 static void handleKeyPress(XEvent
* event
)
1336 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1337 WWindow
*wwin
= scr
->focused_window
;
1341 #ifdef KEEP_XKB_LOCK_STATUS
1342 XkbStateRec staterec
;
1343 #endif /*KEEP_XKB_LOCK_STATUS */
1345 /* ignore CapsLock */
1346 modifiers
= event
->xkey
.state
& ValidModMask
;
1348 for (i
= 0; i
< WKBD_LAST
; i
++) {
1349 if (wKeyBindings
[i
].keycode
== 0)
1352 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1353 || */ wKeyBindings
[i
].modifier
==
1362 if (!wRootMenuPerformShortcut(event
)) {
1363 static int dontLoop
= 0;
1365 if (dontLoop
> 10) {
1366 wwarning("problem with key event processing code");
1370 /* if the focused window is an internal window, try redispatching
1371 * the event to the managed window, as it can be a WINGs window */
1372 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1373 /* client_leader contains the WINGs toplevel */
1374 event
->xany
.window
= wwin
->client_leader
;
1375 WMHandleEvent(event
);
1381 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1382 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1387 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1388 if (!CheckFullScreenWindowFocused(scr
)) {
1389 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1390 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1394 case WKBD_WINDOWLIST
:
1395 if (!CheckFullScreenWindowFocused(scr
)) {
1396 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1397 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1402 case WKBD_WINDOWMENU
:
1403 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1404 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1406 case WKBD_MINIATURIZE
:
1407 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1408 && !WFLAGP(wwin
, no_miniaturizable
)) {
1409 CloseWindowMenu(scr
);
1411 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1412 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, event
->xbutton
.time
);
1414 wIconifyWindow(wwin
);
1419 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1420 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1421 CloseWindowMenu(scr
);
1423 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1424 wHideApplication(wapp
);
1428 case WKBD_HIDE_OTHERS
:
1429 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1430 CloseWindowMenu(scr
);
1432 wHideOtherApplications(wwin
);
1436 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1437 CloseWindowMenu(scr
);
1439 if (wwin
->flags
.maximized
== (MAX_VERTICAL
| MAX_HORIZONTAL
))
1440 wUnmaximizeWindow(wwin
);
1442 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1445 case WKBD_VMAXIMIZE
:
1446 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1447 CloseWindowMenu(scr
);
1449 if (wwin
->flags
.maximized
== MAX_VERTICAL
)
1450 wUnmaximizeWindow(wwin
);
1452 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1455 case WKBD_HMAXIMIZE
:
1456 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1457 CloseWindowMenu(scr
);
1459 if (wwin
->flags
.maximized
== MAX_HORIZONTAL
)
1460 wUnmaximizeWindow(wwin
);
1462 wMaximizeWindow(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1465 case WKBD_LHMAXIMIZE
:
1466 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1467 CloseWindowMenu(scr
);
1469 if (wwin
->flags
.maximized
== (MAX_VERTICAL
| MAX_LEFTHALF
))
1470 wUnmaximizeWindow(wwin
);
1472 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1475 case WKBD_RHMAXIMIZE
:
1476 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1477 CloseWindowMenu(scr
);
1479 if (wwin
->flags
.maximized
== (MAX_VERTICAL
| MAX_RIGHTHALF
))
1480 wUnmaximizeWindow(wwin
);
1482 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1486 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1487 CloseWindowMenu(scr
);
1489 if (wwin
->flags
.maximized
== MAX_MAXIMUS
)
1490 wUnmaximizeWindow(wwin
);
1492 wMaximizeWindow(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1496 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1497 CloseWindowMenu(scr
);
1499 wRaiseFrame(wwin
->frame
->core
);
1503 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1504 CloseWindowMenu(scr
);
1506 wLowerFrame(wwin
->frame
->core
);
1509 case WKBD_RAISELOWER
:
1510 /* raise or lower the window under the pointer, not the
1513 wwin
= windowUnderPointer(scr
);
1515 wRaiseLowerFrame(wwin
->frame
->core
);
1518 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1519 if (wwin
->flags
.shaded
)
1520 wUnshadeWindow(wwin
);
1525 case WKBD_MOVERESIZE
:
1526 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1527 CloseWindowMenu(scr
);
1529 wKeyboardMoveResizeWindow(wwin
);
1533 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1534 CloseWindowMenu(scr
);
1535 if (wwin
->protocols
.DELETE_WINDOW
)
1536 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, event
->xkey
.time
);
1540 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1541 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1544 case WKBD_FOCUSNEXT
:
1545 StartWindozeCycle(wwin
, event
, True
);
1548 case WKBD_FOCUSPREV
:
1549 StartWindozeCycle(wwin
, event
, False
);
1552 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1553 widx
= command
- WKBD_WORKSPACE1
;
1554 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1555 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1556 wWorkspaceChange(scr
, i
);
1559 case WKBD_NEXTWORKSPACE
:
1560 wWorkspaceRelativeChange(scr
, 1);
1562 case WKBD_PREVWORKSPACE
:
1563 wWorkspaceRelativeChange(scr
, -1);
1577 widx
= command
- WKBD_WINDOW1
;
1579 if (scr
->shortcutWindows
[widx
]) {
1580 WMArray
*list
= scr
->shortcutWindows
[widx
];
1582 int count
= WMGetArrayItemCount(list
);
1584 WMArrayIterator iter
;
1587 wUnselectWindows(scr
);
1588 cw
= scr
->current_workspace
;
1590 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1592 wWindowChangeWorkspace(wwin
, cw
);
1594 wMakeWindowVisible(wwin
);
1597 wSelectWindow(wwin
, True
);
1600 /* rotate the order of windows, to create a cycling effect */
1601 twin
= WMGetFromArray(list
, 0);
1602 WMDeleteFromArray(list
, 0);
1603 WMAddToArray(list
, twin
);
1605 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1606 if (scr
->shortcutWindows
[widx
]) {
1607 WMFreeArray(scr
->shortcutWindows
[widx
]);
1608 scr
->shortcutWindows
[widx
] = NULL
;
1611 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1612 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1613 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1614 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1616 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1617 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1620 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1623 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1626 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1628 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1629 if (scr
->shortcutWindows
[widx
]) {
1630 WMFreeArray(scr
->shortcutWindows
[widx
]);
1632 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1638 case WKBD_SWITCH_SCREEN
:
1639 if (wScreenCount
> 1) {
1643 /* find index of this screen */
1644 for (i
= 0; i
< wScreenCount
; i
++) {
1645 if (wScreenWithNumber(i
) == scr
)
1649 if (i
>= wScreenCount
) {
1652 scr2
= wScreenWithNumber(i
);
1655 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1656 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1661 case WKBD_NEXTWSLAYER
:
1662 case WKBD_PREVWSLAYER
:
1666 row
= scr
->current_workspace
/ 10;
1667 column
= scr
->current_workspace
% 10;
1669 if (command
== WKBD_NEXTWSLAYER
) {
1670 if ((row
+ 1) * 10 < scr
->workspace_count
)
1671 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1674 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1678 case WKBD_CLIPLOWER
:
1679 if (!wPreferences
.flags
.noclip
)
1680 wDockLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1682 case WKBD_CLIPRAISE
:
1683 if (!wPreferences
.flags
.noclip
)
1684 wDockRaise(scr
->workspaces
[scr
->current_workspace
]->clip
);
1686 case WKBD_CLIPRAISELOWER
:
1687 if (!wPreferences
.flags
.noclip
)
1688 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1690 #ifdef KEEP_XKB_LOCK_STATUS
1692 if (wPreferences
.modelock
) {
1694 wwin
= scr
->focused_window
;
1696 if (wwin
&& wwin
->flags
.mapped
1697 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1698 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1699 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1701 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1702 wwin
->frame
->last_languagemode
= staterec
.group
;
1703 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1708 #endif /* KEEP_XKB_LOCK_STATUS */
1709 #ifdef VIRTUAL_DESKTOP
1710 case WKBD_VDESK_LEFT
:
1711 wWorkspaceKeyboardMoveDesktop(scr
, VEC_LEFT
);
1714 case WKBD_VDESK_RIGHT
:
1715 wWorkspaceKeyboardMoveDesktop(scr
, VEC_RIGHT
);
1719 wWorkspaceKeyboardMoveDesktop(scr
, VEC_UP
);
1722 case WKBD_VDESK_DOWN
:
1723 wWorkspaceKeyboardMoveDesktop(scr
, VEC_DOWN
);
1730 static void handleMotionNotify(XEvent
* event
)
1732 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1734 if (wPreferences
.scrollable_menus
) {
1735 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1736 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1738 if (scr
->flags
.jump_back_pending
||
1739 p
.x
<= (rect
.pos
.x
+ 1) ||
1740 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1741 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1744 printf("pointer at screen edge\n");
1746 menu
= wMenuUnderPointer(scr
);
1748 wMenuScroll(menu
, event
);
1753 static void handleVisibilityNotify(XEvent
* event
)
1757 wwin
= wWindowFor(event
->xvisibility
.window
);
1760 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);