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"
61 /******** Global Variables **********/
62 extern XContext wWinContext
;
63 extern XContext wVEdgeContext
;
65 extern Cursor wCursor
[WCUR_LAST
];
67 extern WShortKey wKeyBindings
[WKBD_LAST
];
68 extern int wScreenCount
;
69 extern Time LastTimestamp
;
70 extern Time LastFocusChange
;
72 extern WPreferences wPreferences
;
74 #define MOD_MASK wPreferences.modifier_mask
76 extern Atom _XA_WM_COLORMAP_NOTIFY
;
78 extern Atom _XA_WM_CHANGE_STATE
;
79 extern Atom _XA_WM_DELETE_WINDOW
;
80 extern Atom _XA_GNUSTEP_WM_ATTR
;
81 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
82 extern Atom _XA_GNUSTEP_TITLEBAR_STATE
;
83 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
84 extern Atom _XA_WINDOWMAKER_COMMAND
;
85 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS
;
88 extern Bool wShapeSupported
;
89 extern int wShapeEventBase
;
92 #ifdef KEEP_XKB_LOCK_STATUS
93 extern int wXkbEventBase
;
97 /*extern char WDelayedActionSet;*/
99 /************ Local stuff ***********/
101 static void saveTimestamp(XEvent
*event
);
102 static void handleColormapNotify(XEvent
*event
);
103 static void handleMapNotify(XEvent
*event
);
104 static void handleUnmapNotify(XEvent
*event
);
105 static void handleButtonPress(XEvent
*event
);
106 static void handleExpose(XEvent
*event
);
107 static void handleDestroyNotify(XEvent
*event
);
108 static void handleConfigureRequest(XEvent
*event
);
109 static void handleMapRequest(XEvent
*event
);
110 static void handlePropertyNotify(XEvent
*event
);
111 static void handleEnterNotify(XEvent
*event
);
112 static void handleLeaveNotify(XEvent
*event
);
113 static void handleExtensions(XEvent
*event
);
114 static void handleClientMessage(XEvent
*event
);
115 static void handleKeyPress(XEvent
*event
);
116 static void handleFocusIn(XEvent
*event
);
117 static void handleMotionNotify(XEvent
*event
);
118 static void handleVisibilityNotify(XEvent
*event
);
121 static void handleShapeNotify(XEvent
*event
);
124 /* called from the signal handler */
125 void NotifyDeadProcess(pid_t pid
, unsigned char status
);
127 /* real dead process handler */
128 static void handleDeadProcess(void *foo
);
130 typedef struct DeadProcesses
{
132 unsigned char exit_status
;
135 /* stack of dead processes */
136 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
137 static int deadProcessPtr
= 0;
139 typedef struct DeathHandler
{
140 WDeathHandler
*callback
;
145 static WMArray
*deathHandlers
= NULL
;
147 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
149 DeathHandler
*handler
;
151 handler
= malloc(sizeof(DeathHandler
));
156 handler
->callback
= callback
;
157 handler
->client_data
= cdata
;
160 deathHandlers
= WMCreateArrayWithDestructor(8, wfree
);
162 WMAddToArray(deathHandlers
, handler
);
167 void wDeleteDeathHandler(WMagicNumber id
)
169 DeathHandler
*handler
= (DeathHandler
*) id
;
171 if (!handler
|| !deathHandlers
)
174 /* array destructor will call wfree(handler) */
175 WMRemoveFromArray(deathHandlers
, handler
);
178 void DispatchEvent(XEvent
* event
)
181 handleDeadProcess(NULL
);
183 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
184 WCHANGE_STATE(WSTATE_EXITING
);
185 /* received SIGTERM */
187 * WMHandleEvent() can't be called from anything
188 * executed inside here, or we can get in a infinite
191 Shutdown(WSExitMode
);
193 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
194 WCHANGE_STATE(WSTATE_RESTARTING
);
196 Shutdown(WSRestartPreparationMode
);
197 /* received SIGHUP */
199 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
200 WCHANGE_STATE(WSTATE_NORMAL
);
201 wDefaultsCheckDomains();
204 /* for the case that all that is wanted to be dispatched is
209 saveTimestamp(event
);
210 switch (event
->type
) {
212 handleMapRequest(event
);
216 handleKeyPress(event
);
220 handleMotionNotify(event
);
223 case ConfigureRequest
:
224 handleConfigureRequest(event
);
228 handleDestroyNotify(event
);
232 handleMapNotify(event
);
236 handleUnmapNotify(event
);
240 handleButtonPress(event
);
248 handlePropertyNotify(event
);
252 handleEnterNotify(event
);
256 handleLeaveNotify(event
);
260 handleClientMessage(event
);
264 handleColormapNotify(event
);
268 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
269 XRefreshKeyboardMapping(&event
->xmapping
);
273 handleFocusIn(event
);
276 case VisibilityNotify
:
277 handleVisibilityNotify(event
);
280 handleExtensions(event
);
286 *----------------------------------------------------------------------
287 * inotifyHandleEvents-
288 * Check for inotify events
291 * After reading events for the given file descriptor (fd) and
292 * watch descriptor (wd)
295 * Calls wDefaultsCheckDomains if config database is updated
296 *----------------------------------------------------------------------
298 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
299 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
300 void inotifyHandleEvents(int fd
, int wd
)
302 extern void wDefaultsCheckDomains(void);
303 ssize_t eventQLength
, i
= 0;
304 char buff
[BUFF_SIZE
] = { 0 };
305 /* Check config only once per read of the event queue */
309 * Read off the queued events
310 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
311 * not occur; the block is on Xevents, but a config file change will normally
312 * occur as a result of an Xevent - so the event queue should never have more than
313 * a few entries before a read().
315 eventQLength
= read(fd
, buff
, BUFF_SIZE
);
317 /* check what events occured */
318 /* Should really check wd here too, but for now we only have one watch! */
319 while (i
< eventQLength
) {
320 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
323 * see inotify.h for event types.
325 if (pevent
->mask
& IN_DELETE_SELF
) {
326 wwarning(_("the defaults database has been deleted!"
327 " Restart Window Maker to create the database" " with the default settings"));
330 if (pevent
->mask
& IN_UNMOUNT
) {
331 wwarning(_("the unit containing the defaults database has"
332 " been unmounted. Setting --static mode." " Any changes will not be saved."));
334 wPreferences
.flags
.noupdates
= 1;
336 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
337 fprintf(stdout
, "wmaker: reading config files in defaults database.\n");
338 wDefaultsCheckDomains();
341 /* move to next event in the buffer */
342 i
+= sizeof(struct inotify_event
) + pevent
->len
;
347 *----------------------------------------------------------------------
349 * Processes X and internal events indefinitely.
355 * The LastTimestamp global variable is updated.
356 * Calls inotifyGetEvents if defaults database changes.
357 *----------------------------------------------------------------------
362 extern int inotifyFD
;
363 extern int inotifyWD
;
368 if (inotifyFD
< 0 || inotifyWD
< 0)
373 WMNextEvent(dpy
, &event
); /* Blocks here */
374 WMHandleEvent(&event
);
380 FD_SET(inotifyFD
, &rfds
);
382 /* check for available read data from inotify - don't block! */
383 retVal
= select(inotifyFD
+ 1, &rfds
, NULL
, NULL
, &time
);
385 if (retVal
< 0) { /* an error has occured */
386 wwarning(_("select failed. The inotify instance will be closed."
387 " Changes to the defaults database will require"
388 " a restart to take effect."));
392 if (FD_ISSET(inotifyFD
, &rfds
))
393 inotifyHandleEvents(inotifyFD
, inotifyWD
);
399 *----------------------------------------------------------------------
400 * ProcessPendingEvents --
401 * Processes the events that are currently pending (at the time
402 * this function is called) in the display's queue.
405 * After the pending events that were present at the function call
409 * Many -- whatever handling events may involve.
411 *----------------------------------------------------------------------
413 void ProcessPendingEvents(void)
420 /* Take a snapshot of the event count in the queue */
421 count
= XPending(dpy
);
423 while (count
> 0 && XPending(dpy
)) {
424 WMNextEvent(dpy
, &event
);
425 WMHandleEvent(&event
);
430 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
432 if ((scr
->last_click_time
> 0) &&
433 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
434 && (event
->xbutton
.button
== scr
->last_click_button
)
435 && (event
->xbutton
.window
== scr
->last_click_window
)) {
437 scr
->flags
.next_click_is_not_double
= 1;
438 scr
->last_click_time
= 0;
439 scr
->last_click_window
= event
->xbutton
.window
;
446 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
448 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
449 wwarning("stack overflow: too many dead processes");
452 /* stack the process to be handled later,
453 * as this is called from the signal handler */
454 deadProcesses
[deadProcessPtr
].pid
= pid
;
455 deadProcesses
[deadProcessPtr
].exit_status
= status
;
459 static void handleDeadProcess(void *foo
)
464 for (i
= 0; i
< deadProcessPtr
; i
++) {
465 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
468 if (!deathHandlers
) {
473 /* get the pids on the queue and call handlers */
474 while (deadProcessPtr
> 0) {
477 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
478 tmp
= WMGetFromArray(deathHandlers
, i
);
482 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
483 (*tmp
->callback
) (tmp
->pid
,
484 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
485 wDeleteDeathHandler(tmp
);
491 static void saveTimestamp(XEvent
* event
)
494 * Never save CurrentTime as LastTimestamp because CurrentTime
495 * it's not a real timestamp (it's the 0L constant)
498 switch (event
->type
) {
501 LastTimestamp
= event
->xbutton
.time
;
505 LastTimestamp
= event
->xkey
.time
;
508 LastTimestamp
= event
->xmotion
.time
;
511 LastTimestamp
= event
->xproperty
.time
;
515 LastTimestamp
= event
->xcrossing
.time
;
518 LastTimestamp
= event
->xselectionclear
.time
;
520 case SelectionRequest
:
521 LastTimestamp
= event
->xselectionrequest
.time
;
523 case SelectionNotify
:
524 LastTimestamp
= event
->xselection
.time
;
526 wXDNDProcessSelection(event
);
532 static int matchWindow(void *item
, void *cdata
)
534 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
537 static void handleExtensions(XEvent
* event
)
539 #ifdef KEEP_XKB_LOCK_STATUS
541 xkbevent
= (XkbEvent
*) event
;
542 #endif /*KEEP_XKB_LOCK_STATUS */
544 if (wShapeSupported
&& event
->type
== (wShapeEventBase
+ ShapeNotify
)) {
545 handleShapeNotify(event
);
548 #ifdef KEEP_XKB_LOCK_STATUS
549 if (wPreferences
.modelock
&& (xkbevent
->type
== wXkbEventBase
)) {
550 handleXkbIndicatorStateNotify(event
);
552 #endif /*KEEP_XKB_LOCK_STATUS */
555 static void handleMapRequest(XEvent
* ev
)
559 Window window
= ev
->xmaprequest
.window
;
562 printf("got map request for %x\n", (unsigned)window
);
564 if ((wwin
= wWindowFor(window
))) {
565 if (wwin
->flags
.shaded
) {
566 wUnshadeWindow(wwin
);
568 /* deiconify window */
569 if (wwin
->flags
.miniaturized
) {
570 wDeiconifyWindow(wwin
);
571 } else if (wwin
->flags
.hidden
) {
572 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
573 /* go to the last workspace that the user worked on the app */
575 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
577 wUnhideApplication(wapp
, False
, False
);
582 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
584 wwin
= wManageWindow(scr
, window
);
587 * This is to let the Dock know that the application it launched
588 * has already been mapped (eg: it has finished launching).
589 * It is not necessary for normally docked apps, but is needed for
590 * apps that were forcedly docked (like with dockit).
592 if (scr
->last_dock
) {
593 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
594 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
596 wDockTrackWindowLaunch(scr
->last_dock
, window
);
600 wClientSetState(wwin
, NormalState
, None
);
601 if (wwin
->flags
.maximized
) {
602 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
604 if (wwin
->flags
.shaded
) {
605 wwin
->flags
.shaded
= 0;
606 wwin
->flags
.skip_next_animation
= 1;
609 if (wwin
->flags
.miniaturized
) {
610 wwin
->flags
.miniaturized
= 0;
611 wwin
->flags
.skip_next_animation
= 1;
612 wIconifyWindow(wwin
);
614 if (wwin
->flags
.fullscreen
) {
615 wwin
->flags
.fullscreen
= 0;
616 wFullscreenWindow(wwin
);
618 if (wwin
->flags
.hidden
) {
619 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
621 wwin
->flags
.hidden
= 0;
622 wwin
->flags
.skip_next_animation
= 1;
624 wHideApplication(wapp
);
630 static void handleDestroyNotify(XEvent
* event
)
634 Window window
= event
->xdestroywindow
.window
;
635 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
639 printf("got destroy notify\n");
641 wwin
= wWindowFor(window
);
643 wUnmanageWindow(wwin
, False
, True
);
647 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
648 WFakeGroupLeader
*fPtr
;
650 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
651 if (fPtr
->retainCount
> 0) {
653 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
654 XDestroyWindow(dpy
, fPtr
->leader
);
659 fPtr
->origLeader
= None
;
663 app
= wApplicationOf(window
);
665 if (window
== app
->main_window
) {
667 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
669 if (wwin
->main_window
== window
) {
670 wwin
->main_window
= None
;
675 wApplicationDestroy(app
);
679 static void handleExpose(XEvent
* event
)
681 WObjDescriptor
*desc
;
685 printf("got expose\n");
687 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
689 if (XFindContext(dpy
, event
->xexpose
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
693 if (desc
->handle_expose
) {
694 (*desc
->handle_expose
) (desc
, event
);
698 static void executeButtonAction(WScreen
* scr
, XEvent
* event
, int action
)
701 case WA_SELECT_WINDOWS
:
702 wUnselectWindows(scr
);
703 wSelectWindows(scr
, event
);
705 case WA_OPEN_APPMENU
:
706 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
708 if (scr
->root_menu
) {
709 if (scr
->root_menu
->brother
->flags
.mapped
)
710 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
712 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
715 case WA_OPEN_WINLISTMENU
:
716 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
717 if (scr
->switch_menu
) {
718 if (scr
->switch_menu
->brother
->flags
.mapped
)
719 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
721 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
730 static void handleButtonPress(XEvent
* event
)
732 WObjDescriptor
*desc
;
736 printf("got button press\n");
738 scr
= wScreenForRootWindow(event
->xbutton
.root
);
744 if (event
->xbutton
.window
== scr
->root_win
) {
745 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
746 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
747 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
748 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
749 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
750 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
751 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
752 wWorkspaceRelativeChange(scr
, 1);
753 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
754 wWorkspaceRelativeChange(scr
, -1);
759 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
760 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
765 if (desc
->parent_type
== WCLASS_WINDOW
) {
768 if (event
->xbutton
.state
& MOD_MASK
) {
769 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
772 /* if (wPreferences.focus_mode == WKF_CLICK) { */
773 if (wPreferences
.ignore_focus_click
) {
774 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
776 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
779 } else if (desc
->parent_type
== WCLASS_APPICON
780 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
781 if (event
->xbutton
.state
& MOD_MASK
) {
783 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
788 if (desc
->handle_mousedown
!= NULL
) {
789 (*desc
->handle_mousedown
) (desc
, event
);
792 /* save double-click information */
793 if (scr
->flags
.next_click_is_not_double
) {
794 scr
->flags
.next_click_is_not_double
= 0;
796 scr
->last_click_time
= event
->xbutton
.time
;
797 scr
->last_click_button
= event
->xbutton
.button
;
798 scr
->last_click_window
= event
->xbutton
.window
;
802 static void handleMapNotify(XEvent
* event
)
808 wwin
= wWindowFor(event
->xmap
.event
);
809 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
810 if (wwin
->flags
.miniaturized
) {
811 wDeiconifyWindow(wwin
);
815 wClientSetState(wwin
, NormalState
, None
);
821 static void handleUnmapNotify(XEvent
* event
)
825 Bool withdraw
= False
;
827 printf("got unmap\n");
829 /* only process windows with StructureNotify selected
830 * (ignore SubstructureNotify) */
831 wwin
= wWindowFor(event
->xunmap
.window
);
835 /* whether the event is a Withdrawal request */
836 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
839 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
842 if (!wwin
->flags
.mapped
&& !withdraw
843 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
844 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
848 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
849 wwin
->flags
.mapped
= 0;
851 /* check if the window was destroyed */
852 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
855 Bool reparented
= False
;
857 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
860 /* withdraw window */
861 wwin
->flags
.mapped
= 0;
863 wClientSetState(wwin
, WithdrawnState
, None
);
865 /* if the window was reparented, do not reparent it back to the
867 wUnmanageWindow(wwin
, !reparented
, False
);
872 static void handleConfigureRequest(XEvent
* event
)
876 printf("got configure request\n");
878 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
880 * Configure request for unmapped window
882 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
884 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
888 static void handlePropertyNotify(XEvent
* event
)
897 printf("got property notify\n");
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
);
912 scr
= wScreenForWindow(event
->xproperty
.window
);
915 static void handleClientMessage(XEvent
* event
)
918 WObjDescriptor
*desc
;
920 printf("got client message\n");
922 /* handle transition from Normal to Iconic state */
923 if (event
->xclient
.message_type
== _XA_WM_CHANGE_STATE
924 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
926 wwin
= wWindowFor(event
->xclient
.window
);
929 if (!wwin
->flags
.miniaturized
)
930 wIconifyWindow(wwin
);
931 } else if (event
->xclient
.message_type
== _XA_WM_COLORMAP_NOTIFY
&& event
->xclient
.format
== 32) {
932 WScreen
*scr
= wScreenSearchForRootWindow(event
->xclient
.window
);
937 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
938 wColormapAllowClientInstallation(scr
, True
);
939 } else { /* stopping */
940 wColormapAllowClientInstallation(scr
, False
);
942 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_COMMAND
) {
944 wDefaultsCheckDomains();
946 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
949 wapp
= wApplicationOf(event
->xclient
.window
);
951 switch (event
->xclient
.data
.l
[0]) {
952 case WMFHideOtherApplications
:
953 wHideOtherApplications(wapp
->main_window_desc
);
957 case WMFHideApplication
:
958 wHideApplication(wapp
);
964 wwin
= wWindowFor(event
->xclient
.window
);
966 switch (event
->xclient
.data
.l
[0]) {
967 case WMFHideOtherApplications
:
968 wHideOtherApplications(wwin
);
971 case WMFHideApplication
:
972 wHideApplication(wApplicationOf(wwin
->main_window
));
977 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_WM_ATTR
) {
978 wwin
= wWindowFor(event
->xclient
.window
);
981 switch (event
->xclient
.data
.l
[0]) {
982 case GSWindowLevelAttr
:
984 int level
= (int)event
->xclient
.data
.l
[1];
986 if (WINDOW_LEVEL(wwin
) != level
) {
987 ChangeStackingLevel(wwin
->frame
->core
, level
);
992 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_TITLEBAR_STATE
) {
993 wwin
= wWindowFor(event
->xclient
.window
);
996 switch (event
->xclient
.data
.l
[0]) {
997 case WMTitleBarNormal
:
998 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1000 case WMTitleBarMain
:
1001 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1004 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1007 } else if (event
->xclient
.message_type
== _XA_WM_IGNORE_FOCUS_EVENTS
) {
1008 WScreen
*scr
= wScreenSearchForRootWindow(event
->xclient
.window
);
1011 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1012 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1015 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1020 * Non-standard thing, but needed by OffiX DND.
1021 * For when the icon frame gets a ClientMessage
1022 * that should have gone to the icon_window.
1024 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1025 struct WIcon
*icon
= NULL
;
1027 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1028 icon
= (WIcon
*) desc
->parent
;
1029 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1030 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1032 if (icon
&& (wwin
= icon
->owner
)) {
1033 if (wwin
->client_win
!= event
->xclient
.window
) {
1034 event
->xclient
.window
= wwin
->client_win
;
1035 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1042 static void raiseWindow(WScreen
* scr
)
1046 scr
->autoRaiseTimer
= NULL
;
1048 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1052 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1053 wRaiseFrame(wwin
->frame
->core
);
1054 /* this is needed or a race condition will occur */
1059 static void handleEnterNotify(XEvent
* event
)
1062 WObjDescriptor
*desc
= NULL
;
1063 #ifdef VIRTUAL_DESKTOP
1064 void (*vdHandler
) (XEvent
* event
);
1067 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1069 printf("got enter notify\n");
1072 #ifdef VIRTUAL_DESKTOP
1073 if (XFindContext(dpy
, event
->xcrossing
.window
, wVEdgeContext
, (XPointer
*) & vdHandler
) != XCNOENT
) {
1074 (*vdHandler
) (event
);
1078 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1079 /* already left the window... */
1081 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1086 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1087 if (desc
->handle_enternotify
)
1088 (*desc
->handle_enternotify
) (desc
, event
);
1091 /* enter to window */
1092 wwin
= wWindowFor(event
->xcrossing
.window
);
1094 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1095 wColormapInstallForWindow(scr
, NULL
);
1097 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1098 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1099 scr
->autoRaiseTimer
= NULL
;
1102 /* set auto raise timer even if in focus-follows-mouse mode
1103 * and the event is for the frame window, even if the window
1104 * has focus already. useful if you move the pointer from a focused
1105 * window to the root window and back pretty fast
1107 * set focus if in focus-follows-mouse mode and the event
1108 * is for the frame window and window doesn't have focus yet */
1109 if (wPreferences
.focus_mode
== WKF_SLOPPY
1110 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1112 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1113 wSetFocusTo(scr
, wwin
);
1115 if (scr
->autoRaiseTimer
)
1116 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1117 scr
->autoRaiseTimer
= NULL
;
1119 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1120 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1122 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1125 /* Install colormap for window, if the colormap installation mode
1126 * is colormap_follows_mouse */
1127 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1128 if (wwin
->client_win
== event
->xcrossing
.window
)
1129 wColormapInstallForWindow(scr
, wwin
);
1131 wColormapInstallForWindow(scr
, NULL
);
1135 /* a little kluge to hide the clip balloon */
1136 if (!wPreferences
.flags
.noclip
&& scr
->flags
.clip_balloon_mapped
) {
1138 XUnmapWindow(dpy
, scr
->clip_balloon
);
1139 scr
->flags
.clip_balloon_mapped
= 0;
1141 if (desc
->parent_type
!= WCLASS_DOCK_ICON
|| scr
->clip_icon
!= desc
->parent
) {
1142 XUnmapWindow(dpy
, scr
->clip_balloon
);
1143 scr
->flags
.clip_balloon_mapped
= 0;
1148 if (event
->xcrossing
.window
== event
->xcrossing
.root
1149 && event
->xcrossing
.detail
== NotifyNormal
1150 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1152 wSetFocusTo(scr
, scr
->focused_window
);
1155 wBalloonEnteredObject(scr
, desc
);
1159 static void handleLeaveNotify(XEvent
* event
)
1161 WObjDescriptor
*desc
= NULL
;
1163 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1164 if (desc
->handle_leavenotify
)
1165 (*desc
->handle_leavenotify
) (desc
, event
);
1170 static void handleShapeNotify(XEvent
* event
)
1172 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1176 printf("got shape notify\n");
1178 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
)) {
1179 XShapeEvent
*sev
= (XShapeEvent
*) & ev
;
1181 if (sev
->kind
== ShapeBounding
) {
1182 if (sev
->shaped
== shev
->shaped
) {
1185 XPutBackEvent(dpy
, &ev
);
1191 wwin
= wWindowFor(shev
->window
);
1192 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1195 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1197 wwin
->flags
.shaped
= 0;
1198 wWindowClearShape(wwin
);
1200 } else if (shev
->shaped
) {
1202 wwin
->flags
.shaped
= 1;
1203 wWindowSetShape(wwin
);
1208 #ifdef KEEP_XKB_LOCK_STATUS
1209 /* please help ]d if you know what to do */
1210 handleXkbIndicatorStateNotify(XEvent
* event
)
1214 XkbStateRec staterec
;
1217 for (i
= 0; i
< wScreenCount
; i
++) {
1218 scr
= wScreenWithNumber(i
);
1219 wwin
= scr
->focused_window
;
1220 if (wwin
&& wwin
->flags
.focused
) {
1221 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1222 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1223 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1224 wwin
->frame
->languagemode
= staterec
.group
;
1226 #ifdef XKB_BUTTON_HINT
1227 if (wwin
->frame
->titlebar
) {
1228 wFrameWindowPaint(wwin
->frame
);
1234 #endif /*KEEP_XKB_LOCK_STATUS */
1236 static void handleColormapNotify(XEvent
* event
)
1240 Bool reinstall
= False
;
1242 wwin
= wWindowFor(event
->xcolormap
.window
);
1246 scr
= wwin
->screen_ptr
;
1250 if (event
->xcolormap
.new) {
1251 XWindowAttributes attr
;
1253 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1255 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1256 scr
->current_colormap
= attr
.colormap
;
1259 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1260 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1262 /* some bastard app (like XV) removed our colormap */
1264 * can't enforce or things like xscreensaver wont work
1267 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1268 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1270 /* someone has put our colormap back */
1274 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1275 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1277 if (reinstall
&& scr
->current_colormap
!= None
) {
1278 if (!scr
->flags
.colormap_stuff_blocked
)
1279 XInstallColormap(dpy
, scr
->current_colormap
);
1283 static void handleFocusIn(XEvent
* event
)
1288 * For applications that like stealing the focus.
1290 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1291 saveTimestamp(event
);
1292 if (event
->xfocus
.mode
== NotifyUngrab
1293 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1297 wwin
= wWindowFor(event
->xfocus
.window
);
1298 if (wwin
&& !wwin
->flags
.focused
) {
1299 if (wwin
->flags
.mapped
)
1300 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1302 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1304 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1306 wSetFocusTo(scr
, NULL
);
1310 static WWindow
*windowUnderPointer(WScreen
* scr
)
1316 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1317 return wWindowFor(win
);
1321 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1323 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1329 static void handleKeyPress(XEvent
* event
)
1331 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1332 WWindow
*wwin
= scr
->focused_window
;
1336 #ifdef KEEP_XKB_LOCK_STATUS
1337 XkbStateRec staterec
;
1338 #endif /*KEEP_XKB_LOCK_STATUS */
1340 /* ignore CapsLock */
1341 modifiers
= event
->xkey
.state
& ValidModMask
;
1343 for (i
= 0; i
< WKBD_LAST
; i
++) {
1344 if (wKeyBindings
[i
].keycode
== 0)
1347 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1348 || */ wKeyBindings
[i
].modifier
==
1357 if (!wRootMenuPerformShortcut(event
)) {
1358 static int dontLoop
= 0;
1360 if (dontLoop
> 10) {
1361 wwarning("problem with key event processing code");
1365 /* if the focused window is an internal window, try redispatching
1366 * the event to the managed window, as it can be a WINGs window */
1367 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1368 /* client_leader contains the WINGs toplevel */
1369 event
->xany
.window
= wwin
->client_leader
;
1370 WMHandleEvent(event
);
1376 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1377 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1382 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1383 if (!CheckFullScreenWindowFocused(scr
)) {
1384 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1385 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1389 case WKBD_WINDOWLIST
:
1390 if (!CheckFullScreenWindowFocused(scr
)) {
1391 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1392 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1397 case WKBD_WINDOWMENU
:
1398 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1399 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1401 case WKBD_MINIATURIZE
:
1402 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1403 && !WFLAGP(wwin
, no_miniaturizable
)) {
1404 CloseWindowMenu(scr
);
1406 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1407 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, event
->xbutton
.time
);
1409 wIconifyWindow(wwin
);
1414 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1415 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1416 CloseWindowMenu(scr
);
1418 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1419 wHideApplication(wapp
);
1423 case WKBD_HIDE_OTHERS
:
1424 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1425 CloseWindowMenu(scr
);
1427 wHideOtherApplications(wwin
);
1431 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1432 CloseWindowMenu(scr
);
1434 if (wwin
->flags
.maximized
== (MAX_VERTICAL
| MAX_HORIZONTAL
))
1435 wUnmaximizeWindow(wwin
);
1437 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1440 case WKBD_VMAXIMIZE
:
1441 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1442 CloseWindowMenu(scr
);
1444 if (wwin
->flags
.maximized
== MAX_VERTICAL
)
1445 wUnmaximizeWindow(wwin
);
1447 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1450 case WKBD_HMAXIMIZE
:
1451 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1452 CloseWindowMenu(scr
);
1454 if (wwin
->flags
.maximized
== MAX_HORIZONTAL
)
1455 wUnmaximizeWindow(wwin
);
1457 wMaximizeWindow(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1460 case WKBD_LHMAXIMIZE
:
1461 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1462 CloseWindowMenu(scr
);
1464 if (wwin
->flags
.maximized
== (MAX_VERTICAL
| MAX_LEFTHALF
))
1465 wUnmaximizeWindow(wwin
);
1467 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1470 case WKBD_RHMAXIMIZE
:
1471 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1472 CloseWindowMenu(scr
);
1474 if (wwin
->flags
.maximized
== (MAX_VERTICAL
| MAX_RIGHTHALF
))
1475 wUnmaximizeWindow(wwin
);
1477 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1481 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1482 CloseWindowMenu(scr
);
1484 if (wwin
->flags
.maximized
== MAX_MAXIMUS
)
1485 wUnmaximizeWindow(wwin
);
1487 wMaximizeWindow(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1491 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1492 CloseWindowMenu(scr
);
1494 wRaiseFrame(wwin
->frame
->core
);
1498 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1499 CloseWindowMenu(scr
);
1501 wLowerFrame(wwin
->frame
->core
);
1504 case WKBD_RAISELOWER
:
1505 /* raise or lower the window under the pointer, not the
1508 wwin
= windowUnderPointer(scr
);
1510 wRaiseLowerFrame(wwin
->frame
->core
);
1513 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1514 if (wwin
->flags
.shaded
)
1515 wUnshadeWindow(wwin
);
1520 case WKBD_MOVERESIZE
:
1521 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1522 CloseWindowMenu(scr
);
1524 wKeyboardMoveResizeWindow(wwin
);
1528 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1529 CloseWindowMenu(scr
);
1530 if (wwin
->protocols
.DELETE_WINDOW
)
1531 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, event
->xkey
.time
);
1535 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1536 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1539 case WKBD_FOCUSNEXT
:
1540 StartWindozeCycle(wwin
, event
, True
, False
);
1543 case WKBD_FOCUSPREV
:
1544 StartWindozeCycle(wwin
, event
, False
, False
);
1547 case WKBD_GROUPNEXT
:
1548 StartWindozeCycle(wwin
, event
, True
, True
);
1551 case WKBD_GROUPPREV
:
1552 StartWindozeCycle(wwin
, event
, False
, True
);
1555 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1556 widx
= command
- WKBD_WORKSPACE1
;
1557 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1558 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1559 wWorkspaceChange(scr
, i
);
1562 case WKBD_NEXTWORKSPACE
:
1563 wWorkspaceRelativeChange(scr
, 1);
1565 case WKBD_PREVWORKSPACE
:
1566 wWorkspaceRelativeChange(scr
, -1);
1580 widx
= command
- WKBD_WINDOW1
;
1582 if (scr
->shortcutWindows
[widx
]) {
1583 WMArray
*list
= scr
->shortcutWindows
[widx
];
1585 int count
= WMGetArrayItemCount(list
);
1587 WMArrayIterator iter
;
1590 wUnselectWindows(scr
);
1591 cw
= scr
->current_workspace
;
1593 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1595 wWindowChangeWorkspace(wwin
, cw
);
1597 wMakeWindowVisible(wwin
);
1600 wSelectWindow(wwin
, True
);
1603 /* rotate the order of windows, to create a cycling effect */
1604 twin
= WMGetFromArray(list
, 0);
1605 WMDeleteFromArray(list
, 0);
1606 WMAddToArray(list
, twin
);
1608 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1609 if (scr
->shortcutWindows
[widx
]) {
1610 WMFreeArray(scr
->shortcutWindows
[widx
]);
1611 scr
->shortcutWindows
[widx
] = NULL
;
1614 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1615 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1616 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1617 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1619 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1620 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1623 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1626 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1629 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1631 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1632 if (scr
->shortcutWindows
[widx
]) {
1633 WMFreeArray(scr
->shortcutWindows
[widx
]);
1635 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1641 case WKBD_SWITCH_SCREEN
:
1642 if (wScreenCount
> 1) {
1646 /* find index of this screen */
1647 for (i
= 0; i
< wScreenCount
; i
++) {
1648 if (wScreenWithNumber(i
) == scr
)
1652 if (i
>= wScreenCount
) {
1655 scr2
= wScreenWithNumber(i
);
1658 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1659 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1664 case WKBD_NEXTWSLAYER
:
1665 case WKBD_PREVWSLAYER
:
1669 row
= scr
->current_workspace
/ 10;
1670 column
= scr
->current_workspace
% 10;
1672 if (command
== WKBD_NEXTWSLAYER
) {
1673 if ((row
+ 1) * 10 < scr
->workspace_count
)
1674 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1677 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1681 case WKBD_CLIPLOWER
:
1682 if (!wPreferences
.flags
.noclip
)
1683 wDockLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1685 case WKBD_CLIPRAISE
:
1686 if (!wPreferences
.flags
.noclip
)
1687 wDockRaise(scr
->workspaces
[scr
->current_workspace
]->clip
);
1689 case WKBD_CLIPRAISELOWER
:
1690 if (!wPreferences
.flags
.noclip
)
1691 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1693 #ifdef KEEP_XKB_LOCK_STATUS
1695 if (wPreferences
.modelock
) {
1697 wwin
= scr
->focused_window
;
1699 if (wwin
&& wwin
->flags
.mapped
1700 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1701 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1702 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1704 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1705 wwin
->frame
->last_languagemode
= staterec
.group
;
1706 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1711 #endif /* KEEP_XKB_LOCK_STATUS */
1712 #ifdef VIRTUAL_DESKTOP
1713 case WKBD_VDESK_LEFT
:
1714 wWorkspaceKeyboardMoveDesktop(scr
, VEC_LEFT
);
1717 case WKBD_VDESK_RIGHT
:
1718 wWorkspaceKeyboardMoveDesktop(scr
, VEC_RIGHT
);
1722 wWorkspaceKeyboardMoveDesktop(scr
, VEC_UP
);
1725 case WKBD_VDESK_DOWN
:
1726 wWorkspaceKeyboardMoveDesktop(scr
, VEC_DOWN
);
1733 static void handleMotionNotify(XEvent
* event
)
1735 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1737 if (wPreferences
.scrollable_menus
) {
1738 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1739 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1741 if (scr
->flags
.jump_back_pending
||
1742 p
.x
<= (rect
.pos
.x
+ 1) ||
1743 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1744 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1747 printf("pointer at screen edge\n");
1749 menu
= wMenuUnderPointer(scr
);
1751 wMenuScroll(menu
, event
);
1756 static void handleVisibilityNotify(XEvent
* event
)
1760 wwin
= wWindowFor(event
->xvisibility
.window
);
1763 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);