1 /* event.c- event loop and handling
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <sys/select.h>
26 #include <sys/inotify.h>
37 #include <X11/Xutil.h>
39 # include <X11/extensions/shape.h>
46 #include <X11/extensions/Xrandr.h>
49 #ifdef KEEP_XKB_LOCK_STATUS
50 #include <X11/XKBlib.h>
51 #endif /* KEEP_XKB_LOCK_STATUS */
53 #include "WindowMaker.h"
60 #include "application.h"
63 #include "workspace.h"
66 #include "properties.h"
77 #include "switchmenu.h"
79 /******** Global Variables **********/
80 extern XContext wWinContext
;
81 extern XContext wVEdgeContext
;
83 extern Cursor wCursor
[WCUR_LAST
];
85 extern WShortKey wKeyBindings
[WKBD_LAST
];
86 extern int wScreenCount
;
87 extern Time LastTimestamp
;
88 extern Time LastFocusChange
;
90 #define MOD_MASK wPreferences.modifier_mask
92 extern Atom _XA_WM_COLORMAP_NOTIFY
;
94 extern Atom _XA_WM_CHANGE_STATE
;
95 extern Atom _XA_WM_DELETE_WINDOW
;
96 extern Atom _XA_GNUSTEP_WM_ATTR
;
97 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
98 extern Atom _XA_GNUSTEP_TITLEBAR_STATE
;
99 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
100 extern Atom _XA_WINDOWMAKER_COMMAND
;
101 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS
;
104 extern Bool wShapeSupported
;
105 extern int wShapeEventBase
;
108 #ifdef KEEP_XKB_LOCK_STATUS
109 extern int wXkbEventBase
;
112 /************ Local stuff ***********/
114 static void saveTimestamp(XEvent
*event
);
115 static void handleColormapNotify(XEvent
*event
);
116 static void handleMapNotify(XEvent
*event
);
117 static void handleUnmapNotify(XEvent
*event
);
118 static void handleButtonPress(XEvent
*event
);
119 static void handleExpose(XEvent
*event
);
120 static void handleDestroyNotify(XEvent
*event
);
121 static void handleConfigureRequest(XEvent
*event
);
122 static void handleMapRequest(XEvent
*event
);
123 static void handlePropertyNotify(XEvent
*event
);
124 static void handleEnterNotify(XEvent
*event
);
125 static void handleLeaveNotify(XEvent
*event
);
126 static void handleExtensions(XEvent
*event
);
127 static void handleClientMessage(XEvent
*event
);
128 static void handleKeyPress(XEvent
*event
);
129 static void handleFocusIn(XEvent
*event
);
130 static void handleMotionNotify(XEvent
*event
);
131 static void handleVisibilityNotify(XEvent
*event
);
132 static void handle_inotify_events(int fd
, int wd
);
133 static void wdelete_death_handler(WMagicNumber id
);
137 static void handleShapeNotify(XEvent
*event
);
140 #ifdef KEEP_XKB_LOCK_STATUS
141 static void handleXkbIndicatorStateNotify(XEvent
*event
);
144 /* called from the signal handler */
145 void NotifyDeadProcess(pid_t pid
, unsigned char status
);
147 /* real dead process handler */
148 static void handleDeadProcess(void *foo
);
150 typedef struct DeadProcesses
{
152 unsigned char exit_status
;
155 /* stack of dead processes */
156 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
157 static int deadProcessPtr
= 0;
159 typedef struct DeathHandler
{
160 WDeathHandler
*callback
;
165 static WMArray
*deathHandlers
= NULL
;
167 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
169 DeathHandler
*handler
;
171 handler
= malloc(sizeof(DeathHandler
));
176 handler
->callback
= callback
;
177 handler
->client_data
= cdata
;
180 deathHandlers
= WMCreateArrayWithDestructor(8, free
);
182 WMAddToArray(deathHandlers
, handler
);
187 static void wdelete_death_handler(WMagicNumber id
)
189 DeathHandler
*handler
= (DeathHandler
*) id
;
191 if (!handler
|| !deathHandlers
)
194 /* array destructor will call free(handler) */
195 WMRemoveFromArray(deathHandlers
, handler
);
198 void DispatchEvent(XEvent
* event
)
201 handleDeadProcess(NULL
);
203 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
204 WCHANGE_STATE(WSTATE_EXITING
);
205 /* received SIGTERM */
207 * WMHandleEvent() can't be called from anything
208 * executed inside here, or we can get in a infinite
211 Shutdown(WSExitMode
);
213 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
214 WCHANGE_STATE(WSTATE_RESTARTING
);
216 Shutdown(WSRestartPreparationMode
);
217 /* received SIGHUP */
219 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
220 WCHANGE_STATE(WSTATE_NORMAL
);
221 wDefaultsCheckDomains(NULL
);
224 /* for the case that all that is wanted to be dispatched is
229 saveTimestamp(event
);
230 switch (event
->type
) {
232 handleMapRequest(event
);
236 handleKeyPress(event
);
240 handleMotionNotify(event
);
243 case ConfigureRequest
:
244 handleConfigureRequest(event
);
248 handleDestroyNotify(event
);
252 handleMapNotify(event
);
256 handleUnmapNotify(event
);
260 handleButtonPress(event
);
268 handlePropertyNotify(event
);
272 handleEnterNotify(event
);
276 handleLeaveNotify(event
);
280 handleClientMessage(event
);
284 handleColormapNotify(event
);
288 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
289 XRefreshKeyboardMapping(&event
->xmapping
);
293 handleFocusIn(event
);
296 case VisibilityNotify
:
297 handleVisibilityNotify(event
);
300 case ConfigureNotify
:
302 if (event
->xconfigure
.window
== DefaultRootWindow(dpy
))
303 XRRUpdateConfiguration(event
);
308 handleExtensions(event
);
315 *----------------------------------------------------------------------
316 * handle_inotify_events-
317 * Check for inotify events
320 * After reading events for the given file descriptor (fd) and
321 * watch descriptor (wd)
324 * Calls wDefaultsCheckDomains if config database is updated
325 *----------------------------------------------------------------------
327 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
328 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
329 static void handle_inotify_events(int fd
, int wd
)
331 ssize_t eventQLength
, i
= 0;
332 char buff
[BUFF_SIZE
] = { 0 };
333 /* Check config only once per read of the event queue */
337 * Read off the queued events
338 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
339 * not occur; the block is on Xevents, but a config file change will normally
340 * occur as a result of an Xevent - so the event queue should never have more than
341 * a few entries before a read().
343 eventQLength
= read(fd
, buff
, BUFF_SIZE
);
345 /* check what events occured */
346 /* Should really check wd here too, but for now we only have one watch! */
347 while (i
< eventQLength
) {
348 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
351 * see inotify.h for event types.
353 if (pevent
->mask
& IN_DELETE_SELF
) {
354 wwarning(_("the defaults database has been deleted!"
355 " Restart Window Maker to create the database" " with the default settings"));
358 if (pevent
->mask
& IN_UNMOUNT
) {
359 wwarning(_("the unit containing the defaults database has"
360 " been unmounted. Setting --static mode." " Any changes will not be saved."));
362 wPreferences
.flags
.noupdates
= 1;
364 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
365 wwarning(_("Inotify: Reading config files in defaults database."));
366 wDefaultsCheckDomains(NULL
);
369 /* move to next event in the buffer */
370 i
+= sizeof(struct inotify_event
) + pevent
->len
;
373 #endif /* HAVE_INOTIFY */
376 *----------------------------------------------------------------------
378 * Processes X and internal events indefinitely.
384 * The LastTimestamp global variable is updated.
385 * Calls inotifyGetEvents if defaults database changes.
386 *----------------------------------------------------------------------
388 noreturn
void EventLoop(void)
392 extern int inotifyFD
;
393 extern int inotifyWD
;
398 if (inotifyFD
< 0 || inotifyWD
< 0)
404 WMNextEvent(dpy
, &event
); /* Blocks here */
405 WMHandleEvent(&event
);
411 FD_SET(inotifyFD
, &rfds
);
413 /* check for available read data from inotify - don't block! */
414 retVal
= select(inotifyFD
+ 1, &rfds
, NULL
, NULL
, &time
);
416 if (retVal
< 0) { /* an error has occured */
417 wwarning(_("select failed. The inotify instance will be closed."
418 " Changes to the defaults database will require"
419 " a restart to take effect."));
423 if (FD_ISSET(inotifyFD
, &rfds
))
424 handle_inotify_events(inotifyFD
, inotifyWD
);
431 *----------------------------------------------------------------------
432 * ProcessPendingEvents --
433 * Processes the events that are currently pending (at the time
434 * this function is called) in the display's queue.
437 * After the pending events that were present at the function call
441 * Many -- whatever handling events may involve.
443 *----------------------------------------------------------------------
445 void ProcessPendingEvents(void)
452 /* Take a snapshot of the event count in the queue */
453 count
= XPending(dpy
);
455 while (count
> 0 && XPending(dpy
)) {
456 WMNextEvent(dpy
, &event
);
457 WMHandleEvent(&event
);
462 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
464 if ((scr
->last_click_time
> 0) &&
465 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
466 && (event
->xbutton
.button
== scr
->last_click_button
)
467 && (event
->xbutton
.window
== scr
->last_click_window
)) {
469 scr
->flags
.next_click_is_not_double
= 1;
470 scr
->last_click_time
= 0;
471 scr
->last_click_window
= event
->xbutton
.window
;
478 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
480 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
481 wwarning("stack overflow: too many dead processes");
484 /* stack the process to be handled later,
485 * as this is called from the signal handler */
486 deadProcesses
[deadProcessPtr
].pid
= pid
;
487 deadProcesses
[deadProcessPtr
].exit_status
= status
;
491 static void handleDeadProcess(void *foo
)
496 for (i
= 0; i
< deadProcessPtr
; i
++) {
497 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
500 if (!deathHandlers
) {
505 /* get the pids on the queue and call handlers */
506 while (deadProcessPtr
> 0) {
509 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
510 tmp
= WMGetFromArray(deathHandlers
, i
);
514 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
515 (*tmp
->callback
) (tmp
->pid
,
516 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
517 wdelete_death_handler(tmp
);
523 static void saveTimestamp(XEvent
* event
)
526 * Never save CurrentTime as LastTimestamp because CurrentTime
527 * it's not a real timestamp (it's the 0L constant)
530 switch (event
->type
) {
533 LastTimestamp
= event
->xbutton
.time
;
537 LastTimestamp
= event
->xkey
.time
;
540 LastTimestamp
= event
->xmotion
.time
;
543 LastTimestamp
= event
->xproperty
.time
;
547 LastTimestamp
= event
->xcrossing
.time
;
550 LastTimestamp
= event
->xselectionclear
.time
;
552 case SelectionRequest
:
553 LastTimestamp
= event
->xselectionrequest
.time
;
555 case SelectionNotify
:
556 LastTimestamp
= event
->xselection
.time
;
558 wXDNDProcessSelection(event
);
564 static int matchWindow(const void *item
, const void *cdata
)
566 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
569 static void handleExtensions(XEvent
* event
)
571 #ifdef KEEP_XKB_LOCK_STATUS
573 xkbevent
= (XkbEvent
*) event
;
574 #endif /*KEEP_XKB_LOCK_STATUS */
576 if (wShapeSupported
&& event
->type
== (wShapeEventBase
+ ShapeNotify
)) {
577 handleShapeNotify(event
);
580 #ifdef KEEP_XKB_LOCK_STATUS
581 if (wPreferences
.modelock
&& (xkbevent
->type
== wXkbEventBase
)) {
582 handleXkbIndicatorStateNotify(event
);
584 #endif /*KEEP_XKB_LOCK_STATUS */
586 if (has_randr
&& event
->type
== (randr_event_base
+ RRScreenChangeNotify
)) {
587 /* From xrandr man page: "Clients must call back into Xlib using
588 * XRRUpdateConfiguration when screen configuration change notify
589 * events are generated */
590 XRRUpdateConfiguration(event
);
591 WCHANGE_STATE(WSTATE_RESTARTING
);
592 Shutdown(WSRestartPreparationMode
);
598 static void handleMapRequest(XEvent
* ev
)
602 Window window
= ev
->xmaprequest
.window
;
604 if ((wwin
= wWindowFor(window
))) {
605 if (wwin
->flags
.shaded
) {
606 wUnshadeWindow(wwin
);
608 /* deiconify window */
609 if (wwin
->flags
.miniaturized
) {
610 wDeiconifyWindow(wwin
);
611 } else if (wwin
->flags
.hidden
) {
612 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
613 /* go to the last workspace that the user worked on the app */
615 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
617 wUnhideApplication(wapp
, False
, False
);
622 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
624 wwin
= wManageWindow(scr
, window
);
627 * This is to let the Dock know that the application it launched
628 * has already been mapped (eg: it has finished launching).
629 * It is not necessary for normally docked apps, but is needed for
630 * apps that were forcedly docked (like with dockit).
632 if (scr
->last_dock
) {
633 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
634 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
636 wDockTrackWindowLaunch(scr
->last_dock
, window
);
640 wClientSetState(wwin
, NormalState
, None
);
641 if (wwin
->flags
.maximized
) {
642 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
644 if (wwin
->flags
.shaded
) {
645 wwin
->flags
.shaded
= 0;
646 wwin
->flags
.skip_next_animation
= 1;
649 if (wwin
->flags
.miniaturized
) {
650 wwin
->flags
.miniaturized
= 0;
651 wwin
->flags
.skip_next_animation
= 1;
652 wIconifyWindow(wwin
);
654 if (wwin
->flags
.fullscreen
) {
655 wwin
->flags
.fullscreen
= 0;
656 wFullscreenWindow(wwin
);
658 if (wwin
->flags
.hidden
) {
659 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
661 wwin
->flags
.hidden
= 0;
662 wwin
->flags
.skip_next_animation
= 1;
664 wHideApplication(wapp
);
670 static void handleDestroyNotify(XEvent
* event
)
674 Window window
= event
->xdestroywindow
.window
;
675 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
678 wwin
= wWindowFor(window
);
680 wUnmanageWindow(wwin
, False
, True
);
684 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
685 WFakeGroupLeader
*fPtr
;
687 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
688 if (fPtr
->retainCount
> 0) {
690 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
691 XDestroyWindow(dpy
, fPtr
->leader
);
696 fPtr
->origLeader
= None
;
700 app
= wApplicationOf(window
);
702 if (window
== app
->main_window
) {
704 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
706 if (wwin
->main_window
== window
) {
707 wwin
->main_window
= None
;
712 wApplicationDestroy(app
);
716 static void handleExpose(XEvent
* event
)
718 WObjDescriptor
*desc
;
721 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
723 if (XFindContext(dpy
, event
->xexpose
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
727 if (desc
->handle_expose
) {
728 (*desc
->handle_expose
) (desc
, event
);
732 static void executeButtonAction(WScreen
* scr
, XEvent
* event
, int action
)
735 case WA_SELECT_WINDOWS
:
736 wUnselectWindows(scr
);
737 wSelectWindows(scr
, event
);
739 case WA_OPEN_APPMENU
:
740 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
742 if (scr
->root_menu
) {
743 if (scr
->root_menu
->brother
->flags
.mapped
)
744 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
746 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
749 case WA_OPEN_WINLISTMENU
:
750 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
751 if (scr
->switch_menu
) {
752 if (scr
->switch_menu
->brother
->flags
.mapped
)
753 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
755 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
764 static void handleButtonPress(XEvent
* event
)
766 WObjDescriptor
*desc
;
769 scr
= wScreenForRootWindow(event
->xbutton
.root
);
775 if (event
->xbutton
.window
== scr
->root_win
) {
776 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
777 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
778 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
779 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
780 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
781 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
782 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
783 wWorkspaceRelativeChange(scr
, 1);
784 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
785 wWorkspaceRelativeChange(scr
, -1);
790 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
791 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
796 if (desc
->parent_type
== WCLASS_WINDOW
) {
799 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
800 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
802 /* if (wPreferences.focus_mode == WKF_CLICK) { */
803 if (wPreferences
.ignore_focus_click
) {
804 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
806 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
810 } else if (desc
->parent_type
== WCLASS_APPICON
811 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
812 if (event
->xbutton
.state
& MOD_MASK
) {
814 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
819 if (desc
->handle_mousedown
!= NULL
) {
820 (*desc
->handle_mousedown
) (desc
, event
);
823 /* save double-click information */
824 if (scr
->flags
.next_click_is_not_double
) {
825 scr
->flags
.next_click_is_not_double
= 0;
827 scr
->last_click_time
= event
->xbutton
.time
;
828 scr
->last_click_button
= event
->xbutton
.button
;
829 scr
->last_click_window
= event
->xbutton
.window
;
833 static void handleMapNotify(XEvent
* event
)
837 wwin
= wWindowFor(event
->xmap
.event
);
838 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
839 if (wwin
->flags
.miniaturized
) {
840 wDeiconifyWindow(wwin
);
844 wClientSetState(wwin
, NormalState
, None
);
850 static void handleUnmapNotify(XEvent
* event
)
854 Bool withdraw
= False
;
856 /* only process windows with StructureNotify selected
857 * (ignore SubstructureNotify) */
858 wwin
= wWindowFor(event
->xunmap
.window
);
862 /* whether the event is a Withdrawal request */
863 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
866 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
869 if (!wwin
->flags
.mapped
&& !withdraw
870 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
871 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
875 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
876 wwin
->flags
.mapped
= 0;
878 /* check if the window was destroyed */
879 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
882 Bool reparented
= False
;
884 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
887 /* withdraw window */
888 wwin
->flags
.mapped
= 0;
890 wClientSetState(wwin
, WithdrawnState
, None
);
892 /* if the window was reparented, do not reparent it back to the
894 wUnmanageWindow(wwin
, !reparented
, False
);
899 static void handleConfigureRequest(XEvent
* event
)
903 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
905 * Configure request for unmapped window
907 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
909 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
913 static void handlePropertyNotify(XEvent
* event
)
921 wwin
= wWindowFor(event
->xproperty
.window
);
923 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
926 wClientCheckProperty(wwin
, &event
->xproperty
);
928 wapp
= wApplicationOf(event
->xproperty
.window
);
930 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
934 static void handleClientMessage(XEvent
* event
)
937 WObjDescriptor
*desc
;
939 /* handle transition from Normal to Iconic state */
940 if (event
->xclient
.message_type
== _XA_WM_CHANGE_STATE
941 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
943 wwin
= wWindowFor(event
->xclient
.window
);
946 if (!wwin
->flags
.miniaturized
)
947 wIconifyWindow(wwin
);
948 } else if (event
->xclient
.message_type
== _XA_WM_COLORMAP_NOTIFY
&& event
->xclient
.format
== 32) {
949 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
954 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
955 wColormapAllowClientInstallation(scr
, True
);
956 } else { /* stopping */
957 wColormapAllowClientInstallation(scr
, False
);
959 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_COMMAND
) {
964 len
= sizeof(event
->xclient
.data
.b
) + 1;
965 command
= wmalloc(len
);
966 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
968 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
969 wwarning(_("Got Reconfigure command"));
970 wDefaultsCheckDomains(NULL
);
972 wwarning(_("Got unknown command %s"), command
);
977 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
980 wapp
= wApplicationOf(event
->xclient
.window
);
982 switch (event
->xclient
.data
.l
[0]) {
983 case WMFHideOtherApplications
:
984 wHideOtherApplications(wapp
->main_window_desc
);
988 case WMFHideApplication
:
989 wHideApplication(wapp
);
995 wwin
= wWindowFor(event
->xclient
.window
);
997 switch (event
->xclient
.data
.l
[0]) {
998 case WMFHideOtherApplications
:
999 wHideOtherApplications(wwin
);
1002 case WMFHideApplication
:
1003 wHideApplication(wApplicationOf(wwin
->main_window
));
1008 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_WM_ATTR
) {
1009 wwin
= wWindowFor(event
->xclient
.window
);
1012 switch (event
->xclient
.data
.l
[0]) {
1013 case GSWindowLevelAttr
:
1015 int level
= (int)event
->xclient
.data
.l
[1];
1017 if (WINDOW_LEVEL(wwin
) != level
) {
1018 ChangeStackingLevel(wwin
->frame
->core
, level
);
1023 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_TITLEBAR_STATE
) {
1024 wwin
= wWindowFor(event
->xclient
.window
);
1027 switch (event
->xclient
.data
.l
[0]) {
1028 case WMTitleBarNormal
:
1029 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1031 case WMTitleBarMain
:
1032 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1035 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1038 } else if (event
->xclient
.message_type
== _XA_WM_IGNORE_FOCUS_EVENTS
) {
1039 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1042 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1043 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1046 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1051 * Non-standard thing, but needed by OffiX DND.
1052 * For when the icon frame gets a ClientMessage
1053 * that should have gone to the icon_window.
1055 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1056 struct WIcon
*icon
= NULL
;
1058 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1059 icon
= (WIcon
*) desc
->parent
;
1060 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1061 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1063 if (icon
&& (wwin
= icon
->owner
)) {
1064 if (wwin
->client_win
!= event
->xclient
.window
) {
1065 event
->xclient
.window
= wwin
->client_win
;
1066 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1073 static void raiseWindow(WScreen
* scr
)
1077 scr
->autoRaiseTimer
= NULL
;
1079 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1083 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1084 wRaiseFrame(wwin
->frame
->core
);
1085 /* this is needed or a race condition will occur */
1090 static void handleEnterNotify(XEvent
* event
)
1093 WObjDescriptor
*desc
= NULL
;
1095 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1097 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1098 /* already left the window... */
1100 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1105 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1106 if (desc
->handle_enternotify
)
1107 (*desc
->handle_enternotify
) (desc
, event
);
1110 /* enter to window */
1111 wwin
= wWindowFor(event
->xcrossing
.window
);
1113 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1114 wColormapInstallForWindow(scr
, NULL
);
1116 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1117 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1118 scr
->autoRaiseTimer
= NULL
;
1121 /* set auto raise timer even if in focus-follows-mouse mode
1122 * and the event is for the frame window, even if the window
1123 * has focus already. useful if you move the pointer from a focused
1124 * window to the root window and back pretty fast
1126 * set focus if in focus-follows-mouse mode and the event
1127 * is for the frame window and window doesn't have focus yet */
1128 if (wPreferences
.focus_mode
== WKF_SLOPPY
1129 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1131 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1132 wSetFocusTo(scr
, wwin
);
1134 if (scr
->autoRaiseTimer
)
1135 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1136 scr
->autoRaiseTimer
= NULL
;
1138 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1139 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1141 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1144 /* Install colormap for window, if the colormap installation mode
1145 * is colormap_follows_mouse */
1146 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1147 if (wwin
->client_win
== event
->xcrossing
.window
)
1148 wColormapInstallForWindow(scr
, wwin
);
1150 wColormapInstallForWindow(scr
, NULL
);
1154 if (event
->xcrossing
.window
== event
->xcrossing
.root
1155 && event
->xcrossing
.detail
== NotifyNormal
1156 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1158 wSetFocusTo(scr
, scr
->focused_window
);
1161 wBalloonEnteredObject(scr
, desc
);
1165 static void handleLeaveNotify(XEvent
* event
)
1167 WObjDescriptor
*desc
= NULL
;
1169 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1170 if (desc
->handle_leavenotify
)
1171 (*desc
->handle_leavenotify
) (desc
, event
);
1176 static void handleShapeNotify(XEvent
* event
)
1178 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1185 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1186 if (ev
.xshape
.kind
== ShapeBounding
) {
1187 if (ev
.xshape
.shaped
== shev
->shaped
) {
1190 XPutBackEvent(dpy
, &ev
.xevent
);
1196 wwin
= wWindowFor(shev
->window
);
1197 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1200 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1202 wwin
->flags
.shaped
= 0;
1203 wWindowClearShape(wwin
);
1205 } else if (shev
->shaped
) {
1207 wwin
->flags
.shaped
= 1;
1208 wWindowSetShape(wwin
);
1213 #ifdef KEEP_XKB_LOCK_STATUS
1214 /* please help ]d if you know what to do */
1215 static void handleXkbIndicatorStateNotify(XEvent
*event
)
1219 XkbStateRec staterec
;
1222 for (i
= 0; i
< wScreenCount
; i
++) {
1223 scr
= wScreenWithNumber(i
);
1224 wwin
= scr
->focused_window
;
1225 if (wwin
&& wwin
->flags
.focused
) {
1226 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1227 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1228 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1229 wwin
->frame
->languagemode
= staterec
.group
;
1231 #ifdef XKB_BUTTON_HINT
1232 if (wwin
->frame
->titlebar
) {
1233 wFrameWindowPaint(wwin
->frame
);
1239 #endif /*KEEP_XKB_LOCK_STATUS */
1241 static void handleColormapNotify(XEvent
* event
)
1245 Bool reinstall
= False
;
1247 wwin
= wWindowFor(event
->xcolormap
.window
);
1251 scr
= wwin
->screen_ptr
;
1255 if (event
->xcolormap
.new) {
1256 XWindowAttributes attr
;
1258 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1260 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1261 scr
->current_colormap
= attr
.colormap
;
1264 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1265 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1267 /* some bastard app (like XV) removed our colormap */
1269 * can't enforce or things like xscreensaver wont work
1272 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1273 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1275 /* someone has put our colormap back */
1279 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1280 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1282 if (reinstall
&& scr
->current_colormap
!= None
) {
1283 if (!scr
->flags
.colormap_stuff_blocked
)
1284 XInstallColormap(dpy
, scr
->current_colormap
);
1288 static void handleFocusIn(XEvent
* event
)
1293 * For applications that like stealing the focus.
1295 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1296 saveTimestamp(event
);
1297 if (event
->xfocus
.mode
== NotifyUngrab
1298 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1302 wwin
= wWindowFor(event
->xfocus
.window
);
1303 if (wwin
&& !wwin
->flags
.focused
) {
1304 if (wwin
->flags
.mapped
)
1305 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1307 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1309 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1311 wSetFocusTo(scr
, NULL
);
1315 static WWindow
*windowUnderPointer(WScreen
* scr
)
1321 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1322 return wWindowFor(win
);
1326 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1328 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1334 static void handleKeyPress(XEvent
* event
)
1336 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1337 WWindow
*wwin
= scr
->focused_window
;
1341 #ifdef KEEP_XKB_LOCK_STATUS
1342 XkbStateRec staterec
;
1343 #endif /*KEEP_XKB_LOCK_STATUS */
1345 /* ignore CapsLock */
1346 modifiers
= event
->xkey
.state
& ValidModMask
;
1348 for (i
= 0; i
< WKBD_LAST
; i
++) {
1349 if (wKeyBindings
[i
].keycode
== 0)
1352 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1353 || */ wKeyBindings
[i
].modifier
==
1362 if (!wRootMenuPerformShortcut(event
)) {
1363 static int dontLoop
= 0;
1365 if (dontLoop
> 10) {
1366 wwarning("problem with key event processing code");
1370 /* if the focused window is an internal window, try redispatching
1371 * the event to the managed window, as it can be a WINGs window */
1372 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1373 /* client_leader contains the WINGs toplevel */
1374 event
->xany
.window
= wwin
->client_leader
;
1375 WMHandleEvent(event
);
1381 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1382 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1387 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1388 if (!CheckFullScreenWindowFocused(scr
)) {
1389 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1390 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1394 case WKBD_WINDOWLIST
:
1395 if (!CheckFullScreenWindowFocused(scr
)) {
1396 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1397 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1402 case WKBD_WINDOWMENU
:
1403 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1404 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1406 case WKBD_MINIMIZEALL
:
1407 CloseWindowMenu(scr
);
1410 case WKBD_MINIATURIZE
:
1411 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1412 && !WFLAGP(wwin
, no_miniaturizable
)) {
1413 CloseWindowMenu(scr
);
1415 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1416 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, event
->xbutton
.time
);
1418 wIconifyWindow(wwin
);
1423 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1424 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1425 CloseWindowMenu(scr
);
1427 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1428 wHideApplication(wapp
);
1432 case WKBD_HIDE_OTHERS
:
1433 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1434 CloseWindowMenu(scr
);
1436 wHideOtherApplications(wwin
);
1440 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1441 CloseWindowMenu(scr
);
1443 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1446 case WKBD_VMAXIMIZE
:
1447 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1448 CloseWindowMenu(scr
);
1450 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1453 case WKBD_HMAXIMIZE
:
1454 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1455 CloseWindowMenu(scr
);
1457 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1460 case WKBD_LHMAXIMIZE
:
1461 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1462 CloseWindowMenu(scr
);
1464 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1467 case WKBD_RHMAXIMIZE
:
1468 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1469 CloseWindowMenu(scr
);
1471 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1474 case WKBD_THMAXIMIZE
:
1475 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1476 CloseWindowMenu(scr
);
1478 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1481 case WKBD_BHMAXIMIZE
:
1482 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1483 CloseWindowMenu(scr
);
1485 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1488 case WKBD_LTCMAXIMIZE
:
1489 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1490 CloseWindowMenu(scr
);
1492 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1495 case WKBD_RTCMAXIMIZE
:
1496 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1497 CloseWindowMenu(scr
);
1499 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1502 case WKBD_LBCMAXIMIZE
:
1503 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1504 CloseWindowMenu(scr
);
1506 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1509 case WKBD_RBCMAXIMIZE
:
1510 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1511 CloseWindowMenu(scr
);
1513 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1517 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1518 CloseWindowMenu(scr
);
1520 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1524 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1525 CloseWindowMenu(scr
);
1527 wRaiseFrame(wwin
->frame
->core
);
1531 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1532 CloseWindowMenu(scr
);
1534 wLowerFrame(wwin
->frame
->core
);
1537 case WKBD_RAISELOWER
:
1538 /* raise or lower the window under the pointer, not the
1541 wwin
= windowUnderPointer(scr
);
1543 wRaiseLowerFrame(wwin
->frame
->core
);
1546 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1547 if (wwin
->flags
.shaded
)
1548 wUnshadeWindow(wwin
);
1553 case WKBD_MOVERESIZE
:
1554 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1555 CloseWindowMenu(scr
);
1557 wKeyboardMoveResizeWindow(wwin
);
1561 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1562 CloseWindowMenu(scr
);
1563 if (wwin
->protocols
.DELETE_WINDOW
)
1564 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, event
->xkey
.time
);
1568 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1569 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1572 case WKBD_FOCUSNEXT
:
1573 StartWindozeCycle(wwin
, event
, True
, False
);
1576 case WKBD_FOCUSPREV
:
1577 StartWindozeCycle(wwin
, event
, False
, False
);
1580 case WKBD_GROUPNEXT
:
1581 StartWindozeCycle(wwin
, event
, True
, True
);
1584 case WKBD_GROUPPREV
:
1585 StartWindozeCycle(wwin
, event
, False
, True
);
1588 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1589 widx
= command
- WKBD_WORKSPACE1
;
1590 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1591 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1592 wWorkspaceChange(scr
, i
);
1595 case WKBD_NEXTWORKSPACE
:
1596 wWorkspaceRelativeChange(scr
, 1);
1598 case WKBD_PREVWORKSPACE
:
1599 wWorkspaceRelativeChange(scr
, -1);
1601 case WKBD_LASTWORKSPACE
:
1602 wWorkspaceChange(scr
, scr
->last_workspace
);
1605 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1606 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1607 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1608 if (wwin
&& (wPreferences
.ws_advance
|| i
< scr
->workspace_count
))
1609 wWindowChangeWorkspace(wwin
, i
);
1612 case WKBD_MOVE_NEXTWORKSPACE
:
1614 wWindowChangeWorkspaceRelative(wwin
, 1);
1616 case WKBD_MOVE_PREVWORKSPACE
:
1618 wWindowChangeWorkspaceRelative(wwin
, -1);
1620 case WKBD_MOVE_LASTWORKSPACE
:
1622 wWindowChangeWorkspace(wwin
, scr
->last_workspace
);
1625 case WKBD_MOVE_NEXTWSLAYER
:
1626 case WKBD_MOVE_PREVWSLAYER
:
1631 row
= scr
->current_workspace
/ 10;
1632 column
= scr
->current_workspace
% 10;
1634 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1635 if ((row
+ 1) * 10 < scr
->workspace_count
)
1636 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1639 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1656 widx
= command
- WKBD_WINDOW1
;
1658 if (scr
->shortcutWindows
[widx
]) {
1659 WMArray
*list
= scr
->shortcutWindows
[widx
];
1661 int count
= WMGetArrayItemCount(list
);
1663 WMArrayIterator iter
;
1666 wUnselectWindows(scr
);
1667 cw
= scr
->current_workspace
;
1669 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1671 wWindowChangeWorkspace(wwin
, cw
);
1673 wMakeWindowVisible(wwin
);
1676 wSelectWindow(wwin
, True
);
1679 /* rotate the order of windows, to create a cycling effect */
1680 twin
= WMGetFromArray(list
, 0);
1681 WMDeleteFromArray(list
, 0);
1682 WMAddToArray(list
, twin
);
1684 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1685 if (scr
->shortcutWindows
[widx
]) {
1686 WMFreeArray(scr
->shortcutWindows
[widx
]);
1687 scr
->shortcutWindows
[widx
] = NULL
;
1690 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1691 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1692 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1693 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1695 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1696 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1699 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1702 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1705 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1707 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1708 if (scr
->shortcutWindows
[widx
]) {
1709 WMFreeArray(scr
->shortcutWindows
[widx
]);
1711 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1718 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1719 (void) RelaunchWindow(wwin
);
1723 case WKBD_SWITCH_SCREEN
:
1724 if (wScreenCount
> 1) {
1728 /* find index of this screen */
1729 for (i
= 0; i
< wScreenCount
; i
++) {
1730 if (wScreenWithNumber(i
) == scr
)
1734 if (i
>= wScreenCount
) {
1737 scr2
= wScreenWithNumber(i
);
1740 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1741 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1746 case WKBD_NEXTWSLAYER
:
1747 case WKBD_PREVWSLAYER
:
1751 row
= scr
->current_workspace
/ 10;
1752 column
= scr
->current_workspace
% 10;
1754 if (command
== WKBD_NEXTWSLAYER
) {
1755 if ((row
+ 1) * 10 < scr
->workspace_count
)
1756 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1759 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1763 case WKBD_CLIPRAISELOWER
:
1764 if (!wPreferences
.flags
.noclip
)
1765 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1767 case WKBD_DOCKRAISELOWER
:
1768 if (!wPreferences
.flags
.nodock
)
1769 wDockRaiseLower(scr
->dock
);
1771 #ifdef KEEP_XKB_LOCK_STATUS
1773 if (wPreferences
.modelock
) {
1775 wwin
= scr
->focused_window
;
1777 if (wwin
&& wwin
->flags
.mapped
1778 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1779 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1780 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1782 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1783 wwin
->frame
->last_languagemode
= staterec
.group
;
1784 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1789 #endif /* KEEP_XKB_LOCK_STATUS */
1793 static void handleMotionNotify(XEvent
* event
)
1795 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1797 if (wPreferences
.scrollable_menus
) {
1798 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1799 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1801 if (scr
->flags
.jump_back_pending
||
1802 p
.x
<= (rect
.pos
.x
+ 1) ||
1803 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1804 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1807 menu
= wMenuUnderPointer(scr
);
1809 wMenuScroll(menu
, event
);
1814 static void handleVisibilityNotify(XEvent
* event
)
1818 wwin
= wWindowFor(event
->xvisibility
.window
);
1821 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);