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,
26 #include <sys/inotify.h>
35 #include <X11/Xutil.h>
37 # include <X11/extensions/shape.h>
44 #include <X11/extensions/Xrandr.h>
47 #ifdef KEEP_XKB_LOCK_STATUS
48 #include <X11/XKBlib.h>
49 #endif /* KEEP_XKB_LOCK_STATUS */
51 #include "WindowMaker.h"
57 #include "application.h"
60 #include "workspace.h"
63 #include "properties.h"
68 /******** Global Variables **********/
69 extern XContext wWinContext
;
70 extern XContext wVEdgeContext
;
72 extern Cursor wCursor
[WCUR_LAST
];
74 extern WShortKey wKeyBindings
[WKBD_LAST
];
75 extern int wScreenCount
;
76 extern Time LastTimestamp
;
77 extern Time LastFocusChange
;
79 extern WPreferences wPreferences
;
81 #define MOD_MASK wPreferences.modifier_mask
83 extern Atom _XA_WM_COLORMAP_NOTIFY
;
85 extern Atom _XA_WM_CHANGE_STATE
;
86 extern Atom _XA_WM_DELETE_WINDOW
;
87 extern Atom _XA_GNUSTEP_WM_ATTR
;
88 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
89 extern Atom _XA_GNUSTEP_TITLEBAR_STATE
;
90 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
91 extern Atom _XA_WINDOWMAKER_COMMAND
;
92 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS
;
95 extern Bool wShapeSupported
;
96 extern int wShapeEventBase
;
99 #ifdef KEEP_XKB_LOCK_STATUS
100 extern int wXkbEventBase
;
104 extern Bool has_randr
;
105 extern int randr_event_base
;
109 /*extern char WDelayedActionSet;*/
111 /************ Local stuff ***********/
113 static void saveTimestamp(XEvent
*event
);
114 static void handleColormapNotify(XEvent
*event
);
115 static void handleMapNotify(XEvent
*event
);
116 static void handleUnmapNotify(XEvent
*event
);
117 static void handleButtonPress(XEvent
*event
);
118 static void handleExpose(XEvent
*event
);
119 static void handleDestroyNotify(XEvent
*event
);
120 static void handleConfigureRequest(XEvent
*event
);
121 static void handleMapRequest(XEvent
*event
);
122 static void handlePropertyNotify(XEvent
*event
);
123 static void handleEnterNotify(XEvent
*event
);
124 static void handleLeaveNotify(XEvent
*event
);
125 static void handleExtensions(XEvent
*event
);
126 static void handleClientMessage(XEvent
*event
);
127 static void handleKeyPress(XEvent
*event
);
128 static void handleFocusIn(XEvent
*event
);
129 static void handleMotionNotify(XEvent
*event
);
130 static void handleVisibilityNotify(XEvent
*event
);
133 static void handleShapeNotify(XEvent
*event
);
136 #ifdef KEEP_XKB_LOCK_STATUS
137 static void handleXkbIndicatorStateNotify(XEvent
*event
);
140 /* called from the signal handler */
141 void NotifyDeadProcess(pid_t pid
, unsigned char status
);
143 /* real dead process handler */
144 static void handleDeadProcess(void *foo
);
146 typedef struct DeadProcesses
{
148 unsigned char exit_status
;
151 /* stack of dead processes */
152 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
153 static int deadProcessPtr
= 0;
155 typedef struct DeathHandler
{
156 WDeathHandler
*callback
;
161 static WMArray
*deathHandlers
= NULL
;
163 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
165 DeathHandler
*handler
;
167 handler
= malloc(sizeof(DeathHandler
));
172 handler
->callback
= callback
;
173 handler
->client_data
= cdata
;
176 deathHandlers
= WMCreateArrayWithDestructor(8, wfree
);
178 WMAddToArray(deathHandlers
, handler
);
183 void wDeleteDeathHandler(WMagicNumber id
)
185 DeathHandler
*handler
= (DeathHandler
*) id
;
187 if (!handler
|| !deathHandlers
)
190 /* array destructor will call wfree(handler) */
191 WMRemoveFromArray(deathHandlers
, handler
);
194 void DispatchEvent(XEvent
* event
)
197 handleDeadProcess(NULL
);
199 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
200 WCHANGE_STATE(WSTATE_EXITING
);
201 /* received SIGTERM */
203 * WMHandleEvent() can't be called from anything
204 * executed inside here, or we can get in a infinite
207 Shutdown(WSExitMode
);
209 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
210 WCHANGE_STATE(WSTATE_RESTARTING
);
212 Shutdown(WSRestartPreparationMode
);
213 /* received SIGHUP */
215 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
216 WCHANGE_STATE(WSTATE_NORMAL
);
217 wDefaultsCheckDomains(NULL
);
220 /* for the case that all that is wanted to be dispatched is
225 saveTimestamp(event
);
226 switch (event
->type
) {
228 handleMapRequest(event
);
232 handleKeyPress(event
);
236 handleMotionNotify(event
);
239 case ConfigureRequest
:
240 handleConfigureRequest(event
);
244 handleDestroyNotify(event
);
248 handleMapNotify(event
);
252 handleUnmapNotify(event
);
256 handleButtonPress(event
);
264 handlePropertyNotify(event
);
268 handleEnterNotify(event
);
272 handleLeaveNotify(event
);
276 handleClientMessage(event
);
280 handleColormapNotify(event
);
284 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
285 XRefreshKeyboardMapping(&event
->xmapping
);
289 handleFocusIn(event
);
292 case VisibilityNotify
:
293 handleVisibilityNotify(event
);
296 handleExtensions(event
);
303 *----------------------------------------------------------------------
304 * inotifyHandleEvents-
305 * Check for inotify events
308 * After reading events for the given file descriptor (fd) and
309 * watch descriptor (wd)
312 * Calls wDefaultsCheckDomains if config database is updated
313 *----------------------------------------------------------------------
315 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
316 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
317 void inotifyHandleEvents(int fd
, int wd
)
319 extern void wDefaultsCheckDomains(void *);
320 ssize_t eventQLength
, i
= 0;
321 char buff
[BUFF_SIZE
] = { 0 };
322 /* Check config only once per read of the event queue */
326 * Read off the queued events
327 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
328 * not occur; the block is on Xevents, but a config file change will normally
329 * occur as a result of an Xevent - so the event queue should never have more than
330 * a few entries before a read().
332 eventQLength
= read(fd
, buff
, BUFF_SIZE
);
334 /* check what events occured */
335 /* Should really check wd here too, but for now we only have one watch! */
336 while (i
< eventQLength
) {
337 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
340 * see inotify.h for event types.
342 if (pevent
->mask
& IN_DELETE_SELF
) {
343 wwarning(_("the defaults database has been deleted!"
344 " Restart Window Maker to create the database" " with the default settings"));
347 if (pevent
->mask
& IN_UNMOUNT
) {
348 wwarning(_("the unit containing the defaults database has"
349 " been unmounted. Setting --static mode." " Any changes will not be saved."));
351 wPreferences
.flags
.noupdates
= 1;
353 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
354 fprintf(stdout
, "wmaker: reading config files in defaults database.\n");
355 wDefaultsCheckDomains(NULL
);
358 /* move to next event in the buffer */
359 i
+= sizeof(struct inotify_event
) + pevent
->len
;
362 #endif /* HAVE_INOTIFY */
365 *----------------------------------------------------------------------
367 * Processes X and internal events indefinitely.
373 * The LastTimestamp global variable is updated.
374 * Calls inotifyGetEvents if defaults database changes.
375 *----------------------------------------------------------------------
381 extern int inotifyFD
;
382 extern int inotifyWD
;
387 if (inotifyFD
< 0 || inotifyWD
< 0)
393 WMNextEvent(dpy
, &event
); /* Blocks here */
394 WMHandleEvent(&event
);
400 FD_SET(inotifyFD
, &rfds
);
402 /* check for available read data from inotify - don't block! */
403 retVal
= select(inotifyFD
+ 1, &rfds
, NULL
, NULL
, &time
);
405 if (retVal
< 0) { /* an error has occured */
406 wwarning(_("select failed. The inotify instance will be closed."
407 " Changes to the defaults database will require"
408 " a restart to take effect."));
412 if (FD_ISSET(inotifyFD
, &rfds
))
413 inotifyHandleEvents(inotifyFD
, inotifyWD
);
420 *----------------------------------------------------------------------
421 * ProcessPendingEvents --
422 * Processes the events that are currently pending (at the time
423 * this function is called) in the display's queue.
426 * After the pending events that were present at the function call
430 * Many -- whatever handling events may involve.
432 *----------------------------------------------------------------------
434 void ProcessPendingEvents(void)
441 /* Take a snapshot of the event count in the queue */
442 count
= XPending(dpy
);
444 while (count
> 0 && XPending(dpy
)) {
445 WMNextEvent(dpy
, &event
);
446 WMHandleEvent(&event
);
451 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
453 if ((scr
->last_click_time
> 0) &&
454 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
455 && (event
->xbutton
.button
== scr
->last_click_button
)
456 && (event
->xbutton
.window
== scr
->last_click_window
)) {
458 scr
->flags
.next_click_is_not_double
= 1;
459 scr
->last_click_time
= 0;
460 scr
->last_click_window
= event
->xbutton
.window
;
467 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
469 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
470 wwarning("stack overflow: too many dead processes");
473 /* stack the process to be handled later,
474 * as this is called from the signal handler */
475 deadProcesses
[deadProcessPtr
].pid
= pid
;
476 deadProcesses
[deadProcessPtr
].exit_status
= status
;
480 static void handleDeadProcess(void *foo
)
485 for (i
= 0; i
< deadProcessPtr
; i
++) {
486 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
489 if (!deathHandlers
) {
494 /* get the pids on the queue and call handlers */
495 while (deadProcessPtr
> 0) {
498 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
499 tmp
= WMGetFromArray(deathHandlers
, i
);
503 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
504 (*tmp
->callback
) (tmp
->pid
,
505 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
506 wDeleteDeathHandler(tmp
);
512 static void saveTimestamp(XEvent
* event
)
515 * Never save CurrentTime as LastTimestamp because CurrentTime
516 * it's not a real timestamp (it's the 0L constant)
519 switch (event
->type
) {
522 LastTimestamp
= event
->xbutton
.time
;
526 LastTimestamp
= event
->xkey
.time
;
529 LastTimestamp
= event
->xmotion
.time
;
532 LastTimestamp
= event
->xproperty
.time
;
536 LastTimestamp
= event
->xcrossing
.time
;
539 LastTimestamp
= event
->xselectionclear
.time
;
541 case SelectionRequest
:
542 LastTimestamp
= event
->xselectionrequest
.time
;
544 case SelectionNotify
:
545 LastTimestamp
= event
->xselection
.time
;
547 wXDNDProcessSelection(event
);
553 static int matchWindow(const void *item
, const void *cdata
)
555 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
558 static void handleExtensions(XEvent
* event
)
560 #ifdef KEEP_XKB_LOCK_STATUS
562 xkbevent
= (XkbEvent
*) event
;
563 #endif /*KEEP_XKB_LOCK_STATUS */
565 if (wShapeSupported
&& event
->type
== (wShapeEventBase
+ ShapeNotify
)) {
566 handleShapeNotify(event
);
569 #ifdef KEEP_XKB_LOCK_STATUS
570 if (wPreferences
.modelock
&& (xkbevent
->type
== wXkbEventBase
)) {
571 handleXkbIndicatorStateNotify(event
);
573 #endif /*KEEP_XKB_LOCK_STATUS */
575 if (has_randr
&& event
->type
== (randr_event_base
+ RRScreenChangeNotify
))
580 static void handleMapRequest(XEvent
* ev
)
584 Window window
= ev
->xmaprequest
.window
;
586 if ((wwin
= wWindowFor(window
))) {
587 if (wwin
->flags
.shaded
) {
588 wUnshadeWindow(wwin
);
590 /* deiconify window */
591 if (wwin
->flags
.miniaturized
) {
592 wDeiconifyWindow(wwin
);
593 } else if (wwin
->flags
.hidden
) {
594 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
595 /* go to the last workspace that the user worked on the app */
597 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
599 wUnhideApplication(wapp
, False
, False
);
604 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
606 wwin
= wManageWindow(scr
, window
);
609 * This is to let the Dock know that the application it launched
610 * has already been mapped (eg: it has finished launching).
611 * It is not necessary for normally docked apps, but is needed for
612 * apps that were forcedly docked (like with dockit).
614 if (scr
->last_dock
) {
615 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
616 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
618 wDockTrackWindowLaunch(scr
->last_dock
, window
);
622 wClientSetState(wwin
, NormalState
, None
);
623 if (wwin
->flags
.maximized
) {
624 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
626 if (wwin
->flags
.shaded
) {
627 wwin
->flags
.shaded
= 0;
628 wwin
->flags
.skip_next_animation
= 1;
631 if (wwin
->flags
.miniaturized
) {
632 wwin
->flags
.miniaturized
= 0;
633 wwin
->flags
.skip_next_animation
= 1;
634 wIconifyWindow(wwin
);
636 if (wwin
->flags
.fullscreen
) {
637 wwin
->flags
.fullscreen
= 0;
638 wFullscreenWindow(wwin
);
640 if (wwin
->flags
.hidden
) {
641 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
643 wwin
->flags
.hidden
= 0;
644 wwin
->flags
.skip_next_animation
= 1;
646 wHideApplication(wapp
);
652 static void handleDestroyNotify(XEvent
* event
)
656 Window window
= event
->xdestroywindow
.window
;
657 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
660 wwin
= wWindowFor(window
);
662 wUnmanageWindow(wwin
, False
, True
);
666 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
667 WFakeGroupLeader
*fPtr
;
669 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
670 if (fPtr
->retainCount
> 0) {
672 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
673 XDestroyWindow(dpy
, fPtr
->leader
);
678 fPtr
->origLeader
= None
;
682 app
= wApplicationOf(window
);
684 if (window
== app
->main_window
) {
686 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
688 if (wwin
->main_window
== window
) {
689 wwin
->main_window
= None
;
694 wApplicationDestroy(app
);
698 static void handleExpose(XEvent
* event
)
700 WObjDescriptor
*desc
;
703 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
705 if (XFindContext(dpy
, event
->xexpose
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
709 if (desc
->handle_expose
) {
710 (*desc
->handle_expose
) (desc
, event
);
714 static void executeButtonAction(WScreen
* scr
, XEvent
* event
, int action
)
717 case WA_SELECT_WINDOWS
:
718 wUnselectWindows(scr
);
719 wSelectWindows(scr
, event
);
721 case WA_OPEN_APPMENU
:
722 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
724 if (scr
->root_menu
) {
725 if (scr
->root_menu
->brother
->flags
.mapped
)
726 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
728 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
731 case WA_OPEN_WINLISTMENU
:
732 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
733 if (scr
->switch_menu
) {
734 if (scr
->switch_menu
->brother
->flags
.mapped
)
735 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
737 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
746 static void handleButtonPress(XEvent
* event
)
748 WObjDescriptor
*desc
;
751 scr
= wScreenForRootWindow(event
->xbutton
.root
);
757 if (event
->xbutton
.window
== scr
->root_win
) {
758 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
759 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
760 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
761 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
762 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
763 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
764 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
765 wWorkspaceRelativeChange(scr
, 1);
766 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
767 wWorkspaceRelativeChange(scr
, -1);
772 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
773 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
778 if (desc
->parent_type
== WCLASS_WINDOW
) {
781 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
782 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
784 /* if (wPreferences.focus_mode == WKF_CLICK) { */
785 if (wPreferences
.ignore_focus_click
) {
786 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
788 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
792 } else if (desc
->parent_type
== WCLASS_APPICON
793 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
794 if (event
->xbutton
.state
& MOD_MASK
) {
796 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
801 if (desc
->handle_mousedown
!= NULL
) {
802 (*desc
->handle_mousedown
) (desc
, event
);
805 /* save double-click information */
806 if (scr
->flags
.next_click_is_not_double
) {
807 scr
->flags
.next_click_is_not_double
= 0;
809 scr
->last_click_time
= event
->xbutton
.time
;
810 scr
->last_click_button
= event
->xbutton
.button
;
811 scr
->last_click_window
= event
->xbutton
.window
;
815 static void handleMapNotify(XEvent
* event
)
819 wwin
= wWindowFor(event
->xmap
.event
);
820 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
821 if (wwin
->flags
.miniaturized
) {
822 wDeiconifyWindow(wwin
);
826 wClientSetState(wwin
, NormalState
, None
);
832 static void handleUnmapNotify(XEvent
* event
)
836 Bool withdraw
= False
;
838 /* only process windows with StructureNotify selected
839 * (ignore SubstructureNotify) */
840 wwin
= wWindowFor(event
->xunmap
.window
);
844 /* whether the event is a Withdrawal request */
845 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
848 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
851 if (!wwin
->flags
.mapped
&& !withdraw
852 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
853 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
857 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
858 wwin
->flags
.mapped
= 0;
860 /* check if the window was destroyed */
861 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
864 Bool reparented
= False
;
866 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
869 /* withdraw window */
870 wwin
->flags
.mapped
= 0;
872 wClientSetState(wwin
, WithdrawnState
, None
);
874 /* if the window was reparented, do not reparent it back to the
876 wUnmanageWindow(wwin
, !reparented
, False
);
881 static void handleConfigureRequest(XEvent
* event
)
885 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
887 * Configure request for unmapped window
889 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
891 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
895 static void handlePropertyNotify(XEvent
* event
)
904 wwin
= wWindowFor(event
->xproperty
.window
);
906 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
909 wClientCheckProperty(wwin
, &event
->xproperty
);
911 wapp
= wApplicationOf(event
->xproperty
.window
);
913 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
916 scr
= wScreenForWindow(event
->xproperty
.window
);
919 static void handleClientMessage(XEvent
* event
)
922 WObjDescriptor
*desc
;
924 /* handle transition from Normal to Iconic state */
925 if (event
->xclient
.message_type
== _XA_WM_CHANGE_STATE
926 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
928 wwin
= wWindowFor(event
->xclient
.window
);
931 if (!wwin
->flags
.miniaturized
)
932 wIconifyWindow(wwin
);
933 } else if (event
->xclient
.message_type
== _XA_WM_COLORMAP_NOTIFY
&& event
->xclient
.format
== 32) {
934 WScreen
*scr
= wScreenSearchForRootWindow(event
->xclient
.window
);
939 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
940 wColormapAllowClientInstallation(scr
, True
);
941 } else { /* stopping */
942 wColormapAllowClientInstallation(scr
, False
);
944 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_COMMAND
) {
949 len
= sizeof(event
->xclient
.data
.b
) + 1;
950 command
= wmalloc(len
);
951 memset(command
, 0, len
);
952 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
954 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
955 wwarning(_("Got Reconfigure command"));
956 wDefaultsCheckDomains(NULL
);
958 wwarning(_("Got unknown command %s"), command
);
963 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
966 wapp
= wApplicationOf(event
->xclient
.window
);
968 switch (event
->xclient
.data
.l
[0]) {
969 case WMFHideOtherApplications
:
970 wHideOtherApplications(wapp
->main_window_desc
);
974 case WMFHideApplication
:
975 wHideApplication(wapp
);
981 wwin
= wWindowFor(event
->xclient
.window
);
983 switch (event
->xclient
.data
.l
[0]) {
984 case WMFHideOtherApplications
:
985 wHideOtherApplications(wwin
);
988 case WMFHideApplication
:
989 wHideApplication(wApplicationOf(wwin
->main_window
));
994 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_WM_ATTR
) {
995 wwin
= wWindowFor(event
->xclient
.window
);
998 switch (event
->xclient
.data
.l
[0]) {
999 case GSWindowLevelAttr
:
1001 int level
= (int)event
->xclient
.data
.l
[1];
1003 if (WINDOW_LEVEL(wwin
) != level
) {
1004 ChangeStackingLevel(wwin
->frame
->core
, level
);
1009 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_TITLEBAR_STATE
) {
1010 wwin
= wWindowFor(event
->xclient
.window
);
1013 switch (event
->xclient
.data
.l
[0]) {
1014 case WMTitleBarNormal
:
1015 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1017 case WMTitleBarMain
:
1018 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1021 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1024 } else if (event
->xclient
.message_type
== _XA_WM_IGNORE_FOCUS_EVENTS
) {
1025 WScreen
*scr
= wScreenSearchForRootWindow(event
->xclient
.window
);
1028 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1029 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1032 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1037 * Non-standard thing, but needed by OffiX DND.
1038 * For when the icon frame gets a ClientMessage
1039 * that should have gone to the icon_window.
1041 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1042 struct WIcon
*icon
= NULL
;
1044 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1045 icon
= (WIcon
*) desc
->parent
;
1046 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1047 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1049 if (icon
&& (wwin
= icon
->owner
)) {
1050 if (wwin
->client_win
!= event
->xclient
.window
) {
1051 event
->xclient
.window
= wwin
->client_win
;
1052 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1059 static void raiseWindow(WScreen
* scr
)
1063 scr
->autoRaiseTimer
= NULL
;
1065 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1069 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1070 wRaiseFrame(wwin
->frame
->core
);
1071 /* this is needed or a race condition will occur */
1076 static void handleEnterNotify(XEvent
* event
)
1079 WObjDescriptor
*desc
= NULL
;
1081 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
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
;
1184 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1185 if (ev
.xshape
.kind
== ShapeBounding
) {
1186 if (ev
.xshape
.shaped
== shev
->shaped
) {
1189 XPutBackEvent(dpy
, &ev
.xevent
);
1195 wwin
= wWindowFor(shev
->window
);
1196 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1199 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1201 wwin
->flags
.shaped
= 0;
1202 wWindowClearShape(wwin
);
1204 } else if (shev
->shaped
) {
1206 wwin
->flags
.shaped
= 1;
1207 wWindowSetShape(wwin
);
1212 #ifdef KEEP_XKB_LOCK_STATUS
1213 /* please help ]d if you know what to do */
1214 static void handleXkbIndicatorStateNotify(XEvent
*event
)
1218 XkbStateRec staterec
;
1221 for (i
= 0; i
< wScreenCount
; i
++) {
1222 scr
= wScreenWithNumber(i
);
1223 wwin
= scr
->focused_window
;
1224 if (wwin
&& wwin
->flags
.focused
) {
1225 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1226 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1227 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1228 wwin
->frame
->languagemode
= staterec
.group
;
1230 #ifdef XKB_BUTTON_HINT
1231 if (wwin
->frame
->titlebar
) {
1232 wFrameWindowPaint(wwin
->frame
);
1238 #endif /*KEEP_XKB_LOCK_STATUS */
1240 static void handleColormapNotify(XEvent
* event
)
1244 Bool reinstall
= False
;
1246 wwin
= wWindowFor(event
->xcolormap
.window
);
1250 scr
= wwin
->screen_ptr
;
1254 if (event
->xcolormap
.new) {
1255 XWindowAttributes attr
;
1257 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1259 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1260 scr
->current_colormap
= attr
.colormap
;
1263 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1264 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1266 /* some bastard app (like XV) removed our colormap */
1268 * can't enforce or things like xscreensaver wont work
1271 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1272 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1274 /* someone has put our colormap back */
1278 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1279 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1281 if (reinstall
&& scr
->current_colormap
!= None
) {
1282 if (!scr
->flags
.colormap_stuff_blocked
)
1283 XInstallColormap(dpy
, scr
->current_colormap
);
1287 static void handleFocusIn(XEvent
* event
)
1292 * For applications that like stealing the focus.
1294 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1295 saveTimestamp(event
);
1296 if (event
->xfocus
.mode
== NotifyUngrab
1297 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1301 wwin
= wWindowFor(event
->xfocus
.window
);
1302 if (wwin
&& !wwin
->flags
.focused
) {
1303 if (wwin
->flags
.mapped
)
1304 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1306 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1308 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1310 wSetFocusTo(scr
, NULL
);
1314 static WWindow
*windowUnderPointer(WScreen
* scr
)
1320 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1321 return wWindowFor(win
);
1325 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1327 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1333 static void handleKeyPress(XEvent
* event
)
1335 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1336 WWindow
*wwin
= scr
->focused_window
;
1340 #ifdef KEEP_XKB_LOCK_STATUS
1341 XkbStateRec staterec
;
1342 #endif /*KEEP_XKB_LOCK_STATUS */
1344 /* ignore CapsLock */
1345 modifiers
= event
->xkey
.state
& ValidModMask
;
1347 for (i
= 0; i
< WKBD_LAST
; i
++) {
1348 if (wKeyBindings
[i
].keycode
== 0)
1351 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1352 || */ wKeyBindings
[i
].modifier
==
1361 if (!wRootMenuPerformShortcut(event
)) {
1362 static int dontLoop
= 0;
1364 if (dontLoop
> 10) {
1365 wwarning("problem with key event processing code");
1369 /* if the focused window is an internal window, try redispatching
1370 * the event to the managed window, as it can be a WINGs window */
1371 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1372 /* client_leader contains the WINGs toplevel */
1373 event
->xany
.window
= wwin
->client_leader
;
1374 WMHandleEvent(event
);
1380 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1381 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1386 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1387 if (!CheckFullScreenWindowFocused(scr
)) {
1388 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1389 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1393 case WKBD_WINDOWLIST
:
1394 if (!CheckFullScreenWindowFocused(scr
)) {
1395 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1396 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1401 case WKBD_WINDOWMENU
:
1402 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1403 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1405 case WKBD_MINIATURIZE
:
1406 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1407 && !WFLAGP(wwin
, no_miniaturizable
)) {
1408 CloseWindowMenu(scr
);
1410 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1411 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, event
->xbutton
.time
);
1413 wIconifyWindow(wwin
);
1418 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1419 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1420 CloseWindowMenu(scr
);
1422 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1423 wHideApplication(wapp
);
1427 case WKBD_HIDE_OTHERS
:
1428 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1429 CloseWindowMenu(scr
);
1431 wHideOtherApplications(wwin
);
1435 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1436 CloseWindowMenu(scr
);
1438 if (wwin
->flags
.maximized
== (MAX_VERTICAL
| MAX_HORIZONTAL
))
1439 wUnmaximizeWindow(wwin
);
1441 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1444 case WKBD_VMAXIMIZE
:
1445 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1446 CloseWindowMenu(scr
);
1448 if (wwin
->flags
.maximized
== MAX_VERTICAL
)
1449 wUnmaximizeWindow(wwin
);
1451 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1454 case WKBD_HMAXIMIZE
:
1455 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1456 CloseWindowMenu(scr
);
1458 if (wwin
->flags
.maximized
== MAX_HORIZONTAL
)
1459 wUnmaximizeWindow(wwin
);
1461 wMaximizeWindow(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1464 case WKBD_LHMAXIMIZE
:
1465 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1466 CloseWindowMenu(scr
);
1468 if (wwin
->flags
.maximized
== (MAX_VERTICAL
| MAX_LEFTHALF
))
1469 wUnmaximizeWindow(wwin
);
1471 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1474 case WKBD_RHMAXIMIZE
:
1475 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1476 CloseWindowMenu(scr
);
1478 if (wwin
->flags
.maximized
== (MAX_VERTICAL
| MAX_RIGHTHALF
))
1479 wUnmaximizeWindow(wwin
);
1481 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1485 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1486 CloseWindowMenu(scr
);
1488 if (wwin
->flags
.maximized
== MAX_MAXIMUS
)
1489 wUnmaximizeWindow(wwin
);
1491 wMaximizeWindow(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1495 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1496 CloseWindowMenu(scr
);
1498 wRaiseFrame(wwin
->frame
->core
);
1502 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1503 CloseWindowMenu(scr
);
1505 wLowerFrame(wwin
->frame
->core
);
1508 case WKBD_RAISELOWER
:
1509 /* raise or lower the window under the pointer, not the
1512 wwin
= windowUnderPointer(scr
);
1514 wRaiseLowerFrame(wwin
->frame
->core
);
1517 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1518 if (wwin
->flags
.shaded
)
1519 wUnshadeWindow(wwin
);
1524 case WKBD_MOVERESIZE
:
1525 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1526 CloseWindowMenu(scr
);
1528 wKeyboardMoveResizeWindow(wwin
);
1532 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1533 CloseWindowMenu(scr
);
1534 if (wwin
->protocols
.DELETE_WINDOW
)
1535 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, event
->xkey
.time
);
1539 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1540 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1543 case WKBD_FOCUSNEXT
:
1544 StartWindozeCycle(wwin
, event
, True
, False
);
1547 case WKBD_FOCUSPREV
:
1548 StartWindozeCycle(wwin
, event
, False
, False
);
1551 case WKBD_GROUPNEXT
:
1552 StartWindozeCycle(wwin
, event
, True
, True
);
1555 case WKBD_GROUPPREV
:
1556 StartWindozeCycle(wwin
, event
, False
, True
);
1559 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1560 widx
= command
- WKBD_WORKSPACE1
;
1561 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1562 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1563 wWorkspaceChange(scr
, i
);
1566 case WKBD_NEXTWORKSPACE
:
1567 wWorkspaceRelativeChange(scr
, 1);
1569 case WKBD_PREVWORKSPACE
:
1570 wWorkspaceRelativeChange(scr
, -1);
1584 widx
= command
- WKBD_WINDOW1
;
1586 if (scr
->shortcutWindows
[widx
]) {
1587 WMArray
*list
= scr
->shortcutWindows
[widx
];
1589 int count
= WMGetArrayItemCount(list
);
1591 WMArrayIterator iter
;
1594 wUnselectWindows(scr
);
1595 cw
= scr
->current_workspace
;
1597 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1599 wWindowChangeWorkspace(wwin
, cw
);
1601 wMakeWindowVisible(wwin
);
1604 wSelectWindow(wwin
, True
);
1607 /* rotate the order of windows, to create a cycling effect */
1608 twin
= WMGetFromArray(list
, 0);
1609 WMDeleteFromArray(list
, 0);
1610 WMAddToArray(list
, twin
);
1612 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1613 if (scr
->shortcutWindows
[widx
]) {
1614 WMFreeArray(scr
->shortcutWindows
[widx
]);
1615 scr
->shortcutWindows
[widx
] = NULL
;
1618 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1619 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1620 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1621 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1623 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1624 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1627 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1630 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1633 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1635 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1636 if (scr
->shortcutWindows
[widx
]) {
1637 WMFreeArray(scr
->shortcutWindows
[widx
]);
1639 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1645 case WKBD_SWITCH_SCREEN
:
1646 if (wScreenCount
> 1) {
1650 /* find index of this screen */
1651 for (i
= 0; i
< wScreenCount
; i
++) {
1652 if (wScreenWithNumber(i
) == scr
)
1656 if (i
>= wScreenCount
) {
1659 scr2
= wScreenWithNumber(i
);
1662 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1663 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1668 case WKBD_NEXTWSLAYER
:
1669 case WKBD_PREVWSLAYER
:
1673 row
= scr
->current_workspace
/ 10;
1674 column
= scr
->current_workspace
% 10;
1676 if (command
== WKBD_NEXTWSLAYER
) {
1677 if ((row
+ 1) * 10 < scr
->workspace_count
)
1678 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1681 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1685 case WKBD_CLIPRAISELOWER
:
1686 if (!wPreferences
.flags
.noclip
)
1687 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1689 case WKBD_DOCKRAISELOWER
:
1690 if (!wPreferences
.flags
.nodock
)
1691 wDockRaiseLower(scr
->dock
);
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 */
1715 static void handleMotionNotify(XEvent
* event
)
1717 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1719 if (wPreferences
.scrollable_menus
) {
1720 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1721 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1723 if (scr
->flags
.jump_back_pending
||
1724 p
.x
<= (rect
.pos
.x
+ 1) ||
1725 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1726 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1729 menu
= wMenuUnderPointer(scr
);
1731 wMenuScroll(menu
, event
);
1736 static void handleVisibilityNotify(XEvent
* event
)
1740 wwin
= wWindowFor(event
->xvisibility
.window
);
1743 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);