1 /* event.c- event loop and handling
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <sys/select.h>
26 #include <sys/inotify.h>
37 #include <X11/Xutil.h>
39 # include <X11/extensions/shape.h>
46 #include <X11/extensions/Xrandr.h>
49 #ifdef KEEP_XKB_LOCK_STATUS
50 #include <X11/XKBlib.h>
51 #endif /* KEEP_XKB_LOCK_STATUS */
53 #include "WindowMaker.h"
60 #include "application.h"
63 #include "workspace.h"
66 #include "properties.h"
77 #include "switchmenu.h"
79 /******** Global Variables **********/
80 extern XContext wWinContext
;
81 extern XContext wVEdgeContext
;
83 extern Cursor wCursor
[WCUR_LAST
];
85 extern WShortKey wKeyBindings
[WKBD_LAST
];
86 extern int wScreenCount
;
87 extern Time LastFocusChange
;
89 #define MOD_MASK wPreferences.modifier_mask
91 extern Atom _XA_WM_COLORMAP_NOTIFY
;
93 extern Atom _XA_WM_CHANGE_STATE
;
94 extern Atom _XA_WM_DELETE_WINDOW
;
95 extern Atom _XA_GNUSTEP_WM_ATTR
;
96 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
97 extern Atom _XA_GNUSTEP_TITLEBAR_STATE
;
98 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
99 extern Atom _XA_WINDOWMAKER_COMMAND
;
100 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS
;
103 extern Bool wShapeSupported
;
104 extern int wShapeEventBase
;
107 #ifdef KEEP_XKB_LOCK_STATUS
108 extern int wXkbEventBase
;
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
);
131 static void handle_inotify_events(int fd
, int wd
);
132 static void wdelete_death_handler(WMagicNumber id
);
136 static void handleShapeNotify(XEvent
*event
);
139 #ifdef KEEP_XKB_LOCK_STATUS
140 static void handleXkbIndicatorStateNotify(XEvent
*event
);
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, free
);
178 WMAddToArray(deathHandlers
, handler
);
183 static void wdelete_death_handler(WMagicNumber id
)
185 DeathHandler
*handler
= (DeathHandler
*) id
;
187 if (!handler
|| !deathHandlers
)
190 /* array destructor will call free(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 case ConfigureNotify
:
298 if (event
->xconfigure
.window
== DefaultRootWindow(dpy
))
299 XRRUpdateConfiguration(event
);
304 handleExtensions(event
);
311 *----------------------------------------------------------------------
312 * handle_inotify_events-
313 * Check for inotify events
316 * After reading events for the given file descriptor (fd) and
317 * watch descriptor (wd)
320 * Calls wDefaultsCheckDomains if config database is updated
321 *----------------------------------------------------------------------
323 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
324 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
325 static void handle_inotify_events(int fd
, int wd
)
327 ssize_t eventQLength
, i
= 0;
328 char buff
[BUFF_SIZE
] = { 0 };
329 /* Check config only once per read of the event queue */
333 * Read off the queued events
334 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
335 * not occur; the block is on Xevents, but a config file change will normally
336 * occur as a result of an Xevent - so the event queue should never have more than
337 * a few entries before a read().
339 eventQLength
= read(fd
, buff
, BUFF_SIZE
);
341 /* check what events occured */
342 /* Should really check wd here too, but for now we only have one watch! */
343 while (i
< eventQLength
) {
344 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
347 * see inotify.h for event types.
349 if (pevent
->mask
& IN_DELETE_SELF
) {
350 wwarning(_("the defaults database has been deleted!"
351 " Restart Window Maker to create the database" " with the default settings"));
354 if (pevent
->mask
& IN_UNMOUNT
) {
355 wwarning(_("the unit containing the defaults database has"
356 " been unmounted. Setting --static mode." " Any changes will not be saved."));
358 wPreferences
.flags
.noupdates
= 1;
360 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
361 wwarning(_("Inotify: Reading config files in defaults database."));
362 wDefaultsCheckDomains(NULL
);
365 /* move to next event in the buffer */
366 i
+= sizeof(struct inotify_event
) + pevent
->len
;
369 #endif /* HAVE_INOTIFY */
372 *----------------------------------------------------------------------
374 * Processes X and internal events indefinitely.
380 * The LastTimestamp global variable is updated.
381 * Calls inotifyGetEvents if defaults database changes.
382 *----------------------------------------------------------------------
384 noreturn
void EventLoop(void)
388 extern int inotifyFD
;
389 extern int inotifyWD
;
394 if (inotifyFD
< 0 || inotifyWD
< 0)
400 WMNextEvent(dpy
, &event
); /* Blocks here */
401 WMHandleEvent(&event
);
407 FD_SET(inotifyFD
, &rfds
);
409 /* check for available read data from inotify - don't block! */
410 retVal
= select(inotifyFD
+ 1, &rfds
, NULL
, NULL
, &time
);
412 if (retVal
< 0) { /* an error has occured */
413 wwarning(_("select failed. The inotify instance will be closed."
414 " Changes to the defaults database will require"
415 " a restart to take effect."));
419 if (FD_ISSET(inotifyFD
, &rfds
))
420 handle_inotify_events(inotifyFD
, inotifyWD
);
427 *----------------------------------------------------------------------
428 * ProcessPendingEvents --
429 * Processes the events that are currently pending (at the time
430 * this function is called) in the display's queue.
433 * After the pending events that were present at the function call
437 * Many -- whatever handling events may involve.
439 *----------------------------------------------------------------------
441 void ProcessPendingEvents(void)
448 /* Take a snapshot of the event count in the queue */
449 count
= XPending(dpy
);
451 while (count
> 0 && XPending(dpy
)) {
452 WMNextEvent(dpy
, &event
);
453 WMHandleEvent(&event
);
458 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
460 if ((scr
->last_click_time
> 0) &&
461 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
462 && (event
->xbutton
.button
== scr
->last_click_button
)
463 && (event
->xbutton
.window
== scr
->last_click_window
)) {
465 scr
->flags
.next_click_is_not_double
= 1;
466 scr
->last_click_time
= 0;
467 scr
->last_click_window
= event
->xbutton
.window
;
474 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
476 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
477 wwarning("stack overflow: too many dead processes");
480 /* stack the process to be handled later,
481 * as this is called from the signal handler */
482 deadProcesses
[deadProcessPtr
].pid
= pid
;
483 deadProcesses
[deadProcessPtr
].exit_status
= status
;
487 static void handleDeadProcess(void *foo
)
492 for (i
= 0; i
< deadProcessPtr
; i
++) {
493 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
496 if (!deathHandlers
) {
501 /* get the pids on the queue and call handlers */
502 while (deadProcessPtr
> 0) {
505 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
506 tmp
= WMGetFromArray(deathHandlers
, i
);
510 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
511 (*tmp
->callback
) (tmp
->pid
,
512 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
513 wdelete_death_handler(tmp
);
519 static void saveTimestamp(XEvent
* event
)
522 * Never save CurrentTime as LastTimestamp because CurrentTime
523 * it's not a real timestamp (it's the 0L constant)
526 switch (event
->type
) {
529 w_global
.timestamp
.last_event
= event
->xbutton
.time
;
533 w_global
.timestamp
.last_event
= event
->xkey
.time
;
536 w_global
.timestamp
.last_event
= event
->xmotion
.time
;
539 w_global
.timestamp
.last_event
= event
->xproperty
.time
;
543 w_global
.timestamp
.last_event
= event
->xcrossing
.time
;
546 w_global
.timestamp
.last_event
= event
->xselectionclear
.time
;
548 case SelectionRequest
:
549 w_global
.timestamp
.last_event
= event
->xselectionrequest
.time
;
551 case SelectionNotify
:
552 w_global
.timestamp
.last_event
= event
->xselection
.time
;
554 wXDNDProcessSelection(event
);
560 static int matchWindow(const void *item
, const void *cdata
)
562 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
565 static void handleExtensions(XEvent
* event
)
567 #ifdef KEEP_XKB_LOCK_STATUS
569 xkbevent
= (XkbEvent
*) event
;
570 #endif /*KEEP_XKB_LOCK_STATUS */
572 if (wShapeSupported
&& event
->type
== (wShapeEventBase
+ ShapeNotify
)) {
573 handleShapeNotify(event
);
576 #ifdef KEEP_XKB_LOCK_STATUS
577 if (wPreferences
.modelock
&& (xkbevent
->type
== wXkbEventBase
)) {
578 handleXkbIndicatorStateNotify(event
);
580 #endif /*KEEP_XKB_LOCK_STATUS */
582 if (has_randr
&& event
->type
== (randr_event_base
+ RRScreenChangeNotify
)) {
583 /* From xrandr man page: "Clients must call back into Xlib using
584 * XRRUpdateConfiguration when screen configuration change notify
585 * events are generated */
586 XRRUpdateConfiguration(event
);
587 WCHANGE_STATE(WSTATE_RESTARTING
);
588 Shutdown(WSRestartPreparationMode
);
594 static void handleMapRequest(XEvent
* ev
)
598 Window window
= ev
->xmaprequest
.window
;
600 if ((wwin
= wWindowFor(window
))) {
601 if (wwin
->flags
.shaded
) {
602 wUnshadeWindow(wwin
);
604 /* deiconify window */
605 if (wwin
->flags
.miniaturized
) {
606 wDeiconifyWindow(wwin
);
607 } else if (wwin
->flags
.hidden
) {
608 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
609 /* go to the last workspace that the user worked on the app */
611 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
613 wUnhideApplication(wapp
, False
, False
);
618 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
620 wwin
= wManageWindow(scr
, window
);
623 * This is to let the Dock know that the application it launched
624 * has already been mapped (eg: it has finished launching).
625 * It is not necessary for normally docked apps, but is needed for
626 * apps that were forcedly docked (like with dockit).
628 if (scr
->last_dock
) {
629 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
630 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
632 wDockTrackWindowLaunch(scr
->last_dock
, window
);
636 wClientSetState(wwin
, NormalState
, None
);
637 if (wwin
->flags
.maximized
) {
638 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
640 if (wwin
->flags
.shaded
) {
641 wwin
->flags
.shaded
= 0;
642 wwin
->flags
.skip_next_animation
= 1;
645 if (wwin
->flags
.miniaturized
) {
646 wwin
->flags
.miniaturized
= 0;
647 wwin
->flags
.skip_next_animation
= 1;
648 wIconifyWindow(wwin
);
650 if (wwin
->flags
.fullscreen
) {
651 wwin
->flags
.fullscreen
= 0;
652 wFullscreenWindow(wwin
);
654 if (wwin
->flags
.hidden
) {
655 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
657 wwin
->flags
.hidden
= 0;
658 wwin
->flags
.skip_next_animation
= 1;
660 wHideApplication(wapp
);
666 static void handleDestroyNotify(XEvent
* event
)
670 Window window
= event
->xdestroywindow
.window
;
671 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
674 wwin
= wWindowFor(window
);
676 wUnmanageWindow(wwin
, False
, True
);
680 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
681 WFakeGroupLeader
*fPtr
;
683 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
684 if (fPtr
->retainCount
> 0) {
686 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
687 XDestroyWindow(dpy
, fPtr
->leader
);
692 fPtr
->origLeader
= None
;
696 app
= wApplicationOf(window
);
698 if (window
== app
->main_window
) {
700 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
702 if (wwin
->main_window
== window
) {
703 wwin
->main_window
= None
;
708 wApplicationDestroy(app
);
712 static void handleExpose(XEvent
* event
)
714 WObjDescriptor
*desc
;
717 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
719 if (XFindContext(dpy
, event
->xexpose
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
723 if (desc
->handle_expose
) {
724 (*desc
->handle_expose
) (desc
, event
);
728 static void executeButtonAction(WScreen
* scr
, XEvent
* event
, int action
)
731 case WA_SELECT_WINDOWS
:
732 wUnselectWindows(scr
);
733 wSelectWindows(scr
, event
);
735 case WA_OPEN_APPMENU
:
736 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
738 if (scr
->root_menu
) {
739 if (scr
->root_menu
->brother
->flags
.mapped
)
740 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
742 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
745 case WA_OPEN_WINLISTMENU
:
746 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
747 if (scr
->switch_menu
) {
748 if (scr
->switch_menu
->brother
->flags
.mapped
)
749 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
751 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
760 static void handleButtonPress(XEvent
* event
)
762 WObjDescriptor
*desc
;
765 scr
= wScreenForRootWindow(event
->xbutton
.root
);
771 if (event
->xbutton
.window
== scr
->root_win
) {
772 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
773 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
774 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
775 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
776 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
777 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
778 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
779 wWorkspaceRelativeChange(scr
, 1);
780 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
781 wWorkspaceRelativeChange(scr
, -1);
786 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
787 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
792 if (desc
->parent_type
== WCLASS_WINDOW
) {
795 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
796 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
798 /* if (wPreferences.focus_mode == WKF_CLICK) { */
799 if (wPreferences
.ignore_focus_click
) {
800 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
802 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
806 } else if (desc
->parent_type
== WCLASS_APPICON
807 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
808 if (event
->xbutton
.state
& MOD_MASK
) {
810 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
815 if (desc
->handle_mousedown
!= NULL
) {
816 (*desc
->handle_mousedown
) (desc
, event
);
819 /* save double-click information */
820 if (scr
->flags
.next_click_is_not_double
) {
821 scr
->flags
.next_click_is_not_double
= 0;
823 scr
->last_click_time
= event
->xbutton
.time
;
824 scr
->last_click_button
= event
->xbutton
.button
;
825 scr
->last_click_window
= event
->xbutton
.window
;
829 static void handleMapNotify(XEvent
* event
)
833 wwin
= wWindowFor(event
->xmap
.event
);
834 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
835 if (wwin
->flags
.miniaturized
) {
836 wDeiconifyWindow(wwin
);
840 wClientSetState(wwin
, NormalState
, None
);
846 static void handleUnmapNotify(XEvent
* event
)
850 Bool withdraw
= False
;
852 /* only process windows with StructureNotify selected
853 * (ignore SubstructureNotify) */
854 wwin
= wWindowFor(event
->xunmap
.window
);
858 /* whether the event is a Withdrawal request */
859 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
862 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
865 if (!wwin
->flags
.mapped
&& !withdraw
866 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
867 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
871 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
872 wwin
->flags
.mapped
= 0;
874 /* check if the window was destroyed */
875 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
878 Bool reparented
= False
;
880 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
883 /* withdraw window */
884 wwin
->flags
.mapped
= 0;
886 wClientSetState(wwin
, WithdrawnState
, None
);
888 /* if the window was reparented, do not reparent it back to the
890 wUnmanageWindow(wwin
, !reparented
, False
);
895 static void handleConfigureRequest(XEvent
* event
)
899 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
901 * Configure request for unmapped window
903 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
905 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
909 static void handlePropertyNotify(XEvent
* event
)
917 wwin
= wWindowFor(event
->xproperty
.window
);
919 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
922 wClientCheckProperty(wwin
, &event
->xproperty
);
924 wapp
= wApplicationOf(event
->xproperty
.window
);
926 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
930 static void handleClientMessage(XEvent
* event
)
933 WObjDescriptor
*desc
;
935 /* handle transition from Normal to Iconic state */
936 if (event
->xclient
.message_type
== _XA_WM_CHANGE_STATE
937 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
939 wwin
= wWindowFor(event
->xclient
.window
);
942 if (!wwin
->flags
.miniaturized
)
943 wIconifyWindow(wwin
);
944 } else if (event
->xclient
.message_type
== _XA_WM_COLORMAP_NOTIFY
&& event
->xclient
.format
== 32) {
945 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
950 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
951 wColormapAllowClientInstallation(scr
, True
);
952 } else { /* stopping */
953 wColormapAllowClientInstallation(scr
, False
);
955 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_COMMAND
) {
960 len
= sizeof(event
->xclient
.data
.b
) + 1;
961 command
= wmalloc(len
);
962 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
964 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
965 wwarning(_("Got Reconfigure command"));
966 wDefaultsCheckDomains(NULL
);
968 wwarning(_("Got unknown command %s"), command
);
973 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
976 wapp
= wApplicationOf(event
->xclient
.window
);
978 switch (event
->xclient
.data
.l
[0]) {
979 case WMFHideOtherApplications
:
980 wHideOtherApplications(wapp
->main_window_desc
);
984 case WMFHideApplication
:
985 wHideApplication(wapp
);
991 wwin
= wWindowFor(event
->xclient
.window
);
993 switch (event
->xclient
.data
.l
[0]) {
994 case WMFHideOtherApplications
:
995 wHideOtherApplications(wwin
);
998 case WMFHideApplication
:
999 wHideApplication(wApplicationOf(wwin
->main_window
));
1004 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_WM_ATTR
) {
1005 wwin
= wWindowFor(event
->xclient
.window
);
1008 switch (event
->xclient
.data
.l
[0]) {
1009 case GSWindowLevelAttr
:
1011 int level
= (int)event
->xclient
.data
.l
[1];
1013 if (WINDOW_LEVEL(wwin
) != level
) {
1014 ChangeStackingLevel(wwin
->frame
->core
, level
);
1019 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_TITLEBAR_STATE
) {
1020 wwin
= wWindowFor(event
->xclient
.window
);
1023 switch (event
->xclient
.data
.l
[0]) {
1024 case WMTitleBarNormal
:
1025 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1027 case WMTitleBarMain
:
1028 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1031 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1034 } else if (event
->xclient
.message_type
== _XA_WM_IGNORE_FOCUS_EVENTS
) {
1035 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1038 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1039 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1042 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1047 * Non-standard thing, but needed by OffiX DND.
1048 * For when the icon frame gets a ClientMessage
1049 * that should have gone to the icon_window.
1051 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1052 struct WIcon
*icon
= NULL
;
1054 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1055 icon
= (WIcon
*) desc
->parent
;
1056 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1057 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1059 if (icon
&& (wwin
= icon
->owner
)) {
1060 if (wwin
->client_win
!= event
->xclient
.window
) {
1061 event
->xclient
.window
= wwin
->client_win
;
1062 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1069 static void raiseWindow(WScreen
* scr
)
1073 scr
->autoRaiseTimer
= NULL
;
1075 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1079 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1080 wRaiseFrame(wwin
->frame
->core
);
1081 /* this is needed or a race condition will occur */
1086 static void handleEnterNotify(XEvent
* event
)
1089 WObjDescriptor
*desc
= NULL
;
1091 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1093 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1094 /* already left the window... */
1096 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1101 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1102 if (desc
->handle_enternotify
)
1103 (*desc
->handle_enternotify
) (desc
, event
);
1106 /* enter to window */
1107 wwin
= wWindowFor(event
->xcrossing
.window
);
1109 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1110 wColormapInstallForWindow(scr
, NULL
);
1112 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1113 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1114 scr
->autoRaiseTimer
= NULL
;
1117 /* set auto raise timer even if in focus-follows-mouse mode
1118 * and the event is for the frame window, even if the window
1119 * has focus already. useful if you move the pointer from a focused
1120 * window to the root window and back pretty fast
1122 * set focus if in focus-follows-mouse mode and the event
1123 * is for the frame window and window doesn't have focus yet */
1124 if (wPreferences
.focus_mode
== WKF_SLOPPY
1125 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1127 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1128 wSetFocusTo(scr
, wwin
);
1130 if (scr
->autoRaiseTimer
)
1131 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1132 scr
->autoRaiseTimer
= NULL
;
1134 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1135 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1137 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1140 /* Install colormap for window, if the colormap installation mode
1141 * is colormap_follows_mouse */
1142 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1143 if (wwin
->client_win
== event
->xcrossing
.window
)
1144 wColormapInstallForWindow(scr
, wwin
);
1146 wColormapInstallForWindow(scr
, NULL
);
1150 if (event
->xcrossing
.window
== event
->xcrossing
.root
1151 && event
->xcrossing
.detail
== NotifyNormal
1152 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1154 wSetFocusTo(scr
, scr
->focused_window
);
1157 wBalloonEnteredObject(scr
, desc
);
1161 static void handleLeaveNotify(XEvent
* event
)
1163 WObjDescriptor
*desc
= NULL
;
1165 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1166 if (desc
->handle_leavenotify
)
1167 (*desc
->handle_leavenotify
) (desc
, event
);
1172 static void handleShapeNotify(XEvent
* event
)
1174 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1181 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1182 if (ev
.xshape
.kind
== ShapeBounding
) {
1183 if (ev
.xshape
.shaped
== shev
->shaped
) {
1186 XPutBackEvent(dpy
, &ev
.xevent
);
1192 wwin
= wWindowFor(shev
->window
);
1193 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1196 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1198 wwin
->flags
.shaped
= 0;
1199 wWindowClearShape(wwin
);
1201 } else if (shev
->shaped
) {
1203 wwin
->flags
.shaped
= 1;
1204 wWindowSetShape(wwin
);
1209 #ifdef KEEP_XKB_LOCK_STATUS
1210 /* please help ]d if you know what to do */
1211 static void handleXkbIndicatorStateNotify(XEvent
*event
)
1215 XkbStateRec staterec
;
1218 for (i
= 0; i
< wScreenCount
; i
++) {
1219 scr
= wScreenWithNumber(i
);
1220 wwin
= scr
->focused_window
;
1221 if (wwin
&& wwin
->flags
.focused
) {
1222 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1223 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1224 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1225 wwin
->frame
->languagemode
= staterec
.group
;
1227 #ifdef XKB_BUTTON_HINT
1228 if (wwin
->frame
->titlebar
) {
1229 wFrameWindowPaint(wwin
->frame
);
1235 #endif /*KEEP_XKB_LOCK_STATUS */
1237 static void handleColormapNotify(XEvent
* event
)
1241 Bool reinstall
= False
;
1243 wwin
= wWindowFor(event
->xcolormap
.window
);
1247 scr
= wwin
->screen_ptr
;
1251 if (event
->xcolormap
.new) {
1252 XWindowAttributes attr
;
1254 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1256 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1257 scr
->current_colormap
= attr
.colormap
;
1260 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1261 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1263 /* some bastard app (like XV) removed our colormap */
1265 * can't enforce or things like xscreensaver wont work
1268 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1269 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1271 /* someone has put our colormap back */
1275 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1276 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1278 if (reinstall
&& scr
->current_colormap
!= None
) {
1279 if (!scr
->flags
.colormap_stuff_blocked
)
1280 XInstallColormap(dpy
, scr
->current_colormap
);
1284 static void handleFocusIn(XEvent
* event
)
1289 * For applications that like stealing the focus.
1291 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1292 saveTimestamp(event
);
1293 if (event
->xfocus
.mode
== NotifyUngrab
1294 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1298 wwin
= wWindowFor(event
->xfocus
.window
);
1299 if (wwin
&& !wwin
->flags
.focused
) {
1300 if (wwin
->flags
.mapped
)
1301 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1303 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1305 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1307 wSetFocusTo(scr
, NULL
);
1311 static WWindow
*windowUnderPointer(WScreen
* scr
)
1317 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1318 return wWindowFor(win
);
1322 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1324 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1330 static void handleKeyPress(XEvent
* event
)
1332 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1333 WWindow
*wwin
= scr
->focused_window
;
1337 #ifdef KEEP_XKB_LOCK_STATUS
1338 XkbStateRec staterec
;
1339 #endif /*KEEP_XKB_LOCK_STATUS */
1341 /* ignore CapsLock */
1342 modifiers
= event
->xkey
.state
& ValidModMask
;
1344 for (i
= 0; i
< WKBD_LAST
; i
++) {
1345 if (wKeyBindings
[i
].keycode
== 0)
1348 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1349 || */ wKeyBindings
[i
].modifier
==
1358 if (!wRootMenuPerformShortcut(event
)) {
1359 static int dontLoop
= 0;
1361 if (dontLoop
> 10) {
1362 wwarning("problem with key event processing code");
1366 /* if the focused window is an internal window, try redispatching
1367 * the event to the managed window, as it can be a WINGs window */
1368 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1369 /* client_leader contains the WINGs toplevel */
1370 event
->xany
.window
= wwin
->client_leader
;
1371 WMHandleEvent(event
);
1377 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1378 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1383 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1384 if (!CheckFullScreenWindowFocused(scr
)) {
1385 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1386 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1390 case WKBD_WINDOWLIST
:
1391 if (!CheckFullScreenWindowFocused(scr
)) {
1392 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1393 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1398 case WKBD_WINDOWMENU
:
1399 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1400 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1402 case WKBD_MINIMIZEALL
:
1403 CloseWindowMenu(scr
);
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 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1442 case WKBD_VMAXIMIZE
:
1443 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1444 CloseWindowMenu(scr
);
1446 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1449 case WKBD_HMAXIMIZE
:
1450 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1451 CloseWindowMenu(scr
);
1453 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1456 case WKBD_LHMAXIMIZE
:
1457 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1458 CloseWindowMenu(scr
);
1460 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1463 case WKBD_RHMAXIMIZE
:
1464 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1465 CloseWindowMenu(scr
);
1467 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1470 case WKBD_THMAXIMIZE
:
1471 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1472 CloseWindowMenu(scr
);
1474 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1477 case WKBD_BHMAXIMIZE
:
1478 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1479 CloseWindowMenu(scr
);
1481 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1484 case WKBD_LTCMAXIMIZE
:
1485 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1486 CloseWindowMenu(scr
);
1488 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1491 case WKBD_RTCMAXIMIZE
:
1492 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1493 CloseWindowMenu(scr
);
1495 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1498 case WKBD_LBCMAXIMIZE
:
1499 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1500 CloseWindowMenu(scr
);
1502 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1505 case WKBD_RBCMAXIMIZE
:
1506 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1507 CloseWindowMenu(scr
);
1509 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1513 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1514 CloseWindowMenu(scr
);
1516 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1520 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1521 CloseWindowMenu(scr
);
1523 wRaiseFrame(wwin
->frame
->core
);
1527 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1528 CloseWindowMenu(scr
);
1530 wLowerFrame(wwin
->frame
->core
);
1533 case WKBD_RAISELOWER
:
1534 /* raise or lower the window under the pointer, not the
1537 wwin
= windowUnderPointer(scr
);
1539 wRaiseLowerFrame(wwin
->frame
->core
);
1542 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1543 if (wwin
->flags
.shaded
)
1544 wUnshadeWindow(wwin
);
1549 case WKBD_MOVERESIZE
:
1550 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1551 CloseWindowMenu(scr
);
1553 wKeyboardMoveResizeWindow(wwin
);
1557 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1558 CloseWindowMenu(scr
);
1559 if (wwin
->protocols
.DELETE_WINDOW
)
1560 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, event
->xkey
.time
);
1564 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1565 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1568 case WKBD_FOCUSNEXT
:
1569 StartWindozeCycle(wwin
, event
, True
, False
);
1572 case WKBD_FOCUSPREV
:
1573 StartWindozeCycle(wwin
, event
, False
, False
);
1576 case WKBD_GROUPNEXT
:
1577 StartWindozeCycle(wwin
, event
, True
, True
);
1580 case WKBD_GROUPPREV
:
1581 StartWindozeCycle(wwin
, event
, False
, True
);
1584 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1585 widx
= command
- WKBD_WORKSPACE1
;
1586 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1587 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1588 wWorkspaceChange(scr
, i
);
1591 case WKBD_NEXTWORKSPACE
:
1592 wWorkspaceRelativeChange(scr
, 1);
1594 case WKBD_PREVWORKSPACE
:
1595 wWorkspaceRelativeChange(scr
, -1);
1597 case WKBD_LASTWORKSPACE
:
1598 wWorkspaceChange(scr
, scr
->last_workspace
);
1601 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1602 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1603 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1604 if (wwin
&& (wPreferences
.ws_advance
|| i
< scr
->workspace_count
))
1605 wWindowChangeWorkspace(wwin
, i
);
1608 case WKBD_MOVE_NEXTWORKSPACE
:
1610 wWindowChangeWorkspaceRelative(wwin
, 1);
1612 case WKBD_MOVE_PREVWORKSPACE
:
1614 wWindowChangeWorkspaceRelative(wwin
, -1);
1616 case WKBD_MOVE_LASTWORKSPACE
:
1618 wWindowChangeWorkspace(wwin
, scr
->last_workspace
);
1621 case WKBD_MOVE_NEXTWSLAYER
:
1622 case WKBD_MOVE_PREVWSLAYER
:
1627 row
= scr
->current_workspace
/ 10;
1628 column
= scr
->current_workspace
% 10;
1630 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1631 if ((row
+ 1) * 10 < scr
->workspace_count
)
1632 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1635 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1652 widx
= command
- WKBD_WINDOW1
;
1654 if (scr
->shortcutWindows
[widx
]) {
1655 WMArray
*list
= scr
->shortcutWindows
[widx
];
1657 int count
= WMGetArrayItemCount(list
);
1659 WMArrayIterator iter
;
1662 wUnselectWindows(scr
);
1663 cw
= scr
->current_workspace
;
1665 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1667 wWindowChangeWorkspace(wwin
, cw
);
1669 wMakeWindowVisible(wwin
);
1672 wSelectWindow(wwin
, True
);
1675 /* rotate the order of windows, to create a cycling effect */
1676 twin
= WMGetFromArray(list
, 0);
1677 WMDeleteFromArray(list
, 0);
1678 WMAddToArray(list
, twin
);
1680 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1681 if (scr
->shortcutWindows
[widx
]) {
1682 WMFreeArray(scr
->shortcutWindows
[widx
]);
1683 scr
->shortcutWindows
[widx
] = NULL
;
1686 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1687 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1688 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1689 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1691 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1692 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1695 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1698 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1701 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1703 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1704 if (scr
->shortcutWindows
[widx
]) {
1705 WMFreeArray(scr
->shortcutWindows
[widx
]);
1707 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1714 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1715 (void) RelaunchWindow(wwin
);
1719 case WKBD_SWITCH_SCREEN
:
1720 if (wScreenCount
> 1) {
1724 /* find index of this screen */
1725 for (i
= 0; i
< wScreenCount
; i
++) {
1726 if (wScreenWithNumber(i
) == scr
)
1730 if (i
>= wScreenCount
) {
1733 scr2
= wScreenWithNumber(i
);
1736 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1737 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1742 case WKBD_NEXTWSLAYER
:
1743 case WKBD_PREVWSLAYER
:
1747 row
= scr
->current_workspace
/ 10;
1748 column
= scr
->current_workspace
% 10;
1750 if (command
== WKBD_NEXTWSLAYER
) {
1751 if ((row
+ 1) * 10 < scr
->workspace_count
)
1752 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1755 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1759 case WKBD_CLIPRAISELOWER
:
1760 if (!wPreferences
.flags
.noclip
)
1761 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1763 case WKBD_DOCKRAISELOWER
:
1764 if (!wPreferences
.flags
.nodock
)
1765 wDockRaiseLower(scr
->dock
);
1767 #ifdef KEEP_XKB_LOCK_STATUS
1769 if (wPreferences
.modelock
) {
1771 wwin
= scr
->focused_window
;
1773 if (wwin
&& wwin
->flags
.mapped
1774 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1775 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1776 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1778 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1779 wwin
->frame
->last_languagemode
= staterec
.group
;
1780 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1785 #endif /* KEEP_XKB_LOCK_STATUS */
1789 static void handleMotionNotify(XEvent
* event
)
1791 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1793 if (wPreferences
.scrollable_menus
) {
1794 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1795 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1797 if (scr
->flags
.jump_back_pending
||
1798 p
.x
<= (rect
.pos
.x
+ 1) ||
1799 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1800 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1803 menu
= wMenuUnderPointer(scr
);
1805 wMenuScroll(menu
, event
);
1810 static void handleVisibilityNotify(XEvent
* event
)
1814 wwin
= wWindowFor(event
->xvisibility
.window
);
1817 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);