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"
80 #define MOD_MASK wPreferences.modifier_mask
82 /************ Local stuff ***********/
84 static void saveTimestamp(XEvent
*event
);
85 static void handleColormapNotify(XEvent
*event
);
86 static void handleMapNotify(XEvent
*event
);
87 static void handleUnmapNotify(XEvent
*event
);
88 static void handleButtonPress(XEvent
*event
);
89 static void handleExpose(XEvent
*event
);
90 static void handleDestroyNotify(XEvent
*event
);
91 static void handleConfigureRequest(XEvent
*event
);
92 static void handleMapRequest(XEvent
*event
);
93 static void handlePropertyNotify(XEvent
*event
);
94 static void handleEnterNotify(XEvent
*event
);
95 static void handleLeaveNotify(XEvent
*event
);
96 static void handleExtensions(XEvent
*event
);
97 static void handleClientMessage(XEvent
*event
);
98 static void handleKeyPress(XEvent
*event
);
99 static void handleFocusIn(XEvent
*event
);
100 static void handleMotionNotify(XEvent
*event
);
101 static void handleVisibilityNotify(XEvent
*event
);
102 static void handle_inotify_events(void);
103 static void wdelete_death_handler(WMagicNumber id
);
107 static void handleShapeNotify(XEvent
*event
);
110 #ifdef KEEP_XKB_LOCK_STATUS
111 static void handleXkbIndicatorStateNotify(XEvent
*event
);
114 /* real dead process handler */
115 static void handleDeadProcess(void);
117 typedef struct DeadProcesses
{
119 unsigned char exit_status
;
122 /* stack of dead processes */
123 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
124 static int deadProcessPtr
= 0;
126 typedef struct DeathHandler
{
127 WDeathHandler
*callback
;
132 static WMArray
*deathHandlers
= NULL
;
134 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
136 DeathHandler
*handler
;
138 handler
= malloc(sizeof(DeathHandler
));
143 handler
->callback
= callback
;
144 handler
->client_data
= cdata
;
147 deathHandlers
= WMCreateArrayWithDestructor(8, free
);
149 WMAddToArray(deathHandlers
, handler
);
154 static void wdelete_death_handler(WMagicNumber id
)
156 DeathHandler
*handler
= (DeathHandler
*) id
;
158 if (!handler
|| !deathHandlers
)
161 /* array destructor will call free(handler) */
162 WMRemoveFromArray(deathHandlers
, handler
);
165 void DispatchEvent(XEvent
* event
)
170 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
171 WCHANGE_STATE(WSTATE_EXITING
);
172 /* received SIGTERM */
174 * WMHandleEvent() can't be called from anything
175 * executed inside here, or we can get in a infinite
178 Shutdown(WSExitMode
);
180 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
181 WCHANGE_STATE(WSTATE_RESTARTING
);
183 Shutdown(WSRestartPreparationMode
);
184 /* received SIGHUP */
186 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
187 WCHANGE_STATE(WSTATE_NORMAL
);
188 wDefaultsCheckDomains(NULL
);
191 /* for the case that all that is wanted to be dispatched is
196 saveTimestamp(event
);
197 switch (event
->type
) {
199 handleMapRequest(event
);
203 handleKeyPress(event
);
207 handleMotionNotify(event
);
210 case ConfigureRequest
:
211 handleConfigureRequest(event
);
215 handleDestroyNotify(event
);
219 handleMapNotify(event
);
223 handleUnmapNotify(event
);
227 handleButtonPress(event
);
235 handlePropertyNotify(event
);
239 handleEnterNotify(event
);
243 handleLeaveNotify(event
);
247 handleClientMessage(event
);
251 handleColormapNotify(event
);
255 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
256 XRefreshKeyboardMapping(&event
->xmapping
);
260 handleFocusIn(event
);
263 case VisibilityNotify
:
264 handleVisibilityNotify(event
);
267 case ConfigureNotify
:
269 if (event
->xconfigure
.window
== DefaultRootWindow(dpy
))
270 XRRUpdateConfiguration(event
);
275 handleExtensions(event
);
282 *----------------------------------------------------------------------
283 * handle_inotify_events-
284 * Check for inotify events
287 * After reading events for the given file descriptor (fd) and
288 * watch descriptor (wd)
291 * Calls wDefaultsCheckDomains if config database is updated
292 *----------------------------------------------------------------------
294 static void handle_inotify_events(void)
296 ssize_t eventQLength
, i
= 0;
297 /* Make room for at lease 5 simultaneous events, with path + filenames */
298 char buff
[ (sizeof(struct inotify_event
) + NAME_MAX
+ 1) * 5 ];
299 /* Check config only once per read of the event queue */
303 * Read off the queued events
304 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
305 * not occur; the block is on Xevents, but a config file change will normally
306 * occur as a result of an Xevent - so the event queue should never have more than
307 * a few entries before a read().
309 eventQLength
= read(w_global
.inotify
.fd_event_queue
,
310 buff
, sizeof(buff
) );
312 /* check what events occured */
313 /* Should really check wd here too, but for now we only have one watch! */
314 while (i
< eventQLength
) {
315 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
318 * see inotify.h for event types.
320 if (pevent
->mask
& IN_DELETE_SELF
) {
321 wwarning(_("the defaults database has been deleted!"
322 " Restart Window Maker to create the database" " with the default settings"));
324 if (w_global
.inotify
.fd_event_queue
>= 0) {
325 close(w_global
.inotify
.fd_event_queue
);
326 w_global
.inotify
.fd_event_queue
= -1;
329 if (pevent
->mask
& IN_UNMOUNT
) {
330 wwarning(_("the unit containing the defaults database has"
331 " been unmounted. Setting --static mode." " Any changes will not be saved."));
333 if (w_global
.inotify
.fd_event_queue
>= 0) {
334 close(w_global
.inotify
.fd_event_queue
);
335 w_global
.inotify
.fd_event_queue
= -1;
338 wPreferences
.flags
.noupdates
= 1;
340 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
341 wwarning(_("Inotify: Reading config files in defaults database."));
342 wDefaultsCheckDomains(NULL
);
345 /* move to next event in the buffer */
346 i
+= sizeof(struct inotify_event
) + pevent
->len
;
349 #endif /* HAVE_INOTIFY */
352 *----------------------------------------------------------------------
354 * Processes X and internal events indefinitely.
360 * The LastTimestamp global variable is updated.
361 * Calls inotifyGetEvents if defaults database changes.
362 *----------------------------------------------------------------------
364 noreturn
void EventLoop(void)
372 if (w_global
.inotify
.fd_event_queue
< 0 || w_global
.inotify
.wd_defaults
< 0)
378 WMNextEvent(dpy
, &event
); /* Blocks here */
379 WMHandleEvent(&event
);
385 FD_SET(w_global
.inotify
.fd_event_queue
, &rfds
);
387 /* check for available read data from inotify - don't block! */
388 retVal
= select(w_global
.inotify
.fd_event_queue
+ 1, &rfds
, NULL
, NULL
, &time
);
390 if (retVal
< 0) { /* an error has occured */
391 wwarning(_("select failed. The inotify instance will be closed."
392 " Changes to the defaults database will require"
393 " a restart to take effect."));
394 close(w_global
.inotify
.fd_event_queue
);
395 w_global
.inotify
.fd_event_queue
= -1;
398 if (FD_ISSET(w_global
.inotify
.fd_event_queue
, &rfds
))
399 handle_inotify_events();
406 *----------------------------------------------------------------------
407 * ProcessPendingEvents --
408 * Processes the events that are currently pending (at the time
409 * this function is called) in the display's queue.
412 * After the pending events that were present at the function call
416 * Many -- whatever handling events may involve.
418 *----------------------------------------------------------------------
420 void ProcessPendingEvents(void)
427 /* Take a snapshot of the event count in the queue */
428 count
= XPending(dpy
);
430 while (count
> 0 && XPending(dpy
)) {
431 WMNextEvent(dpy
, &event
);
432 WMHandleEvent(&event
);
437 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
439 if ((scr
->last_click_time
> 0) &&
440 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
441 && (event
->xbutton
.button
== scr
->last_click_button
)
442 && (event
->xbutton
.window
== scr
->last_click_window
)) {
444 scr
->flags
.next_click_is_not_double
= 1;
445 scr
->last_click_time
= 0;
446 scr
->last_click_window
= event
->xbutton
.window
;
453 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
455 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
456 wwarning("stack overflow: too many dead processes");
459 /* stack the process to be handled later,
460 * as this is called from the signal handler */
461 deadProcesses
[deadProcessPtr
].pid
= pid
;
462 deadProcesses
[deadProcessPtr
].exit_status
= status
;
466 static void handleDeadProcess(void)
471 for (i
= 0; i
< deadProcessPtr
; i
++) {
472 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
475 if (!deathHandlers
) {
480 /* get the pids on the queue and call handlers */
481 while (deadProcessPtr
> 0) {
484 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
485 tmp
= WMGetFromArray(deathHandlers
, i
);
489 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
490 (*tmp
->callback
) (tmp
->pid
,
491 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
492 wdelete_death_handler(tmp
);
498 static void saveTimestamp(XEvent
* event
)
501 * Never save CurrentTime as LastTimestamp because CurrentTime
502 * it's not a real timestamp (it's the 0L constant)
505 switch (event
->type
) {
508 w_global
.timestamp
.last_event
= event
->xbutton
.time
;
512 w_global
.timestamp
.last_event
= event
->xkey
.time
;
515 w_global
.timestamp
.last_event
= event
->xmotion
.time
;
518 w_global
.timestamp
.last_event
= event
->xproperty
.time
;
522 w_global
.timestamp
.last_event
= event
->xcrossing
.time
;
525 w_global
.timestamp
.last_event
= event
->xselectionclear
.time
;
527 case SelectionRequest
:
528 w_global
.timestamp
.last_event
= event
->xselectionrequest
.time
;
530 case SelectionNotify
:
531 w_global
.timestamp
.last_event
= event
->xselection
.time
;
533 wXDNDProcessSelection(event
);
539 static int matchWindow(const void *item
, const void *cdata
)
541 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
544 static void handleExtensions(XEvent
* event
)
546 #ifdef KEEP_XKB_LOCK_STATUS
548 xkbevent
= (XkbEvent
*) event
;
549 #endif /*KEEP_XKB_LOCK_STATUS */
551 if (w_global
.xext
.shape
.supported
&& event
->type
== (w_global
.xext
.shape
.event_base
+ ShapeNotify
)) {
552 handleShapeNotify(event
);
555 #ifdef KEEP_XKB_LOCK_STATUS
556 if (wPreferences
.modelock
&& (xkbevent
->type
== w_global
.xext
.xkb
.event_base
)) {
557 handleXkbIndicatorStateNotify(event
);
559 #endif /*KEEP_XKB_LOCK_STATUS */
561 if (w_global
.xext
.randr
.supported
&& event
->type
== (w_global
.xext
.randr
.event_base
+ RRScreenChangeNotify
)) {
562 /* From xrandr man page: "Clients must call back into Xlib using
563 * XRRUpdateConfiguration when screen configuration change notify
564 * events are generated */
565 XRRUpdateConfiguration(event
);
566 WCHANGE_STATE(WSTATE_RESTARTING
);
567 Shutdown(WSRestartPreparationMode
);
573 static void handleMapRequest(XEvent
* ev
)
577 Window window
= ev
->xmaprequest
.window
;
579 if ((wwin
= wWindowFor(window
))) {
580 if (wwin
->flags
.shaded
) {
581 wUnshadeWindow(wwin
);
583 /* deiconify window */
584 if (wwin
->flags
.miniaturized
) {
585 wDeiconifyWindow(wwin
);
586 } else if (wwin
->flags
.hidden
) {
587 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
588 /* go to the last workspace that the user worked on the app */
590 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
592 wUnhideApplication(wapp
, False
, False
);
597 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
599 wwin
= wManageWindow(scr
, window
);
602 * This is to let the Dock know that the application it launched
603 * has already been mapped (eg: it has finished launching).
604 * It is not necessary for normally docked apps, but is needed for
605 * apps that were forcedly docked (like with dockit).
607 if (scr
->last_dock
) {
608 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
609 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
611 wDockTrackWindowLaunch(scr
->last_dock
, window
);
615 wClientSetState(wwin
, NormalState
, None
);
616 if (wwin
->flags
.maximized
) {
617 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
619 if (wwin
->flags
.shaded
) {
620 wwin
->flags
.shaded
= 0;
621 wwin
->flags
.skip_next_animation
= 1;
624 if (wwin
->flags
.miniaturized
) {
625 wwin
->flags
.miniaturized
= 0;
626 wwin
->flags
.skip_next_animation
= 1;
627 wIconifyWindow(wwin
);
629 if (wwin
->flags
.fullscreen
) {
630 wwin
->flags
.fullscreen
= 0;
631 wFullscreenWindow(wwin
);
633 if (wwin
->flags
.hidden
) {
634 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
636 wwin
->flags
.hidden
= 0;
637 wwin
->flags
.skip_next_animation
= 1;
639 wHideApplication(wapp
);
645 static void handleDestroyNotify(XEvent
* event
)
649 Window window
= event
->xdestroywindow
.window
;
650 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
653 wwin
= wWindowFor(window
);
655 wUnmanageWindow(wwin
, False
, True
);
659 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
660 WFakeGroupLeader
*fPtr
;
662 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
663 if (fPtr
->retainCount
> 0) {
665 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
666 XDestroyWindow(dpy
, fPtr
->leader
);
671 fPtr
->origLeader
= None
;
675 app
= wApplicationOf(window
);
677 if (window
== app
->main_window
) {
679 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
681 if (wwin
->main_window
== window
) {
682 wwin
->main_window
= None
;
687 wApplicationDestroy(app
);
691 static void handleExpose(XEvent
* event
)
693 WObjDescriptor
*desc
;
696 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
698 if (XFindContext(dpy
, event
->xexpose
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
702 if (desc
->handle_expose
) {
703 (*desc
->handle_expose
) (desc
, event
);
707 static void executeButtonAction(WScreen
* scr
, XEvent
* event
, int action
)
710 case WA_SELECT_WINDOWS
:
711 wUnselectWindows(scr
);
712 wSelectWindows(scr
, event
);
714 case WA_OPEN_APPMENU
:
715 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
717 if (scr
->root_menu
) {
718 if (scr
->root_menu
->brother
->flags
.mapped
)
719 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
721 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
724 case WA_OPEN_WINLISTMENU
:
725 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
726 if (scr
->switch_menu
) {
727 if (scr
->switch_menu
->brother
->flags
.mapped
)
728 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
730 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
739 static void handleButtonPress(XEvent
* event
)
741 WObjDescriptor
*desc
;
744 scr
= wScreenForRootWindow(event
->xbutton
.root
);
750 if (event
->xbutton
.window
== scr
->root_win
) {
751 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
752 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
753 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
754 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
755 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
756 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
757 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
758 wWorkspaceRelativeChange(scr
, 1);
759 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
760 wWorkspaceRelativeChange(scr
, -1);
765 if (XFindContext(dpy
, event
->xbutton
.subwindow
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
766 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
771 if (desc
->parent_type
== WCLASS_WINDOW
) {
774 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
775 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
777 /* if (wPreferences.focus_mode == WKF_CLICK) { */
778 if (wPreferences
.ignore_focus_click
) {
779 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
781 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
785 } else if (desc
->parent_type
== WCLASS_APPICON
786 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
787 if (event
->xbutton
.state
& MOD_MASK
) {
789 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
794 if (desc
->handle_mousedown
!= NULL
) {
795 (*desc
->handle_mousedown
) (desc
, event
);
798 /* save double-click information */
799 if (scr
->flags
.next_click_is_not_double
) {
800 scr
->flags
.next_click_is_not_double
= 0;
802 scr
->last_click_time
= event
->xbutton
.time
;
803 scr
->last_click_button
= event
->xbutton
.button
;
804 scr
->last_click_window
= event
->xbutton
.window
;
808 static void handleMapNotify(XEvent
* event
)
812 wwin
= wWindowFor(event
->xmap
.event
);
813 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
814 if (wwin
->flags
.miniaturized
) {
815 wDeiconifyWindow(wwin
);
819 wClientSetState(wwin
, NormalState
, None
);
825 static void handleUnmapNotify(XEvent
* event
)
829 Bool withdraw
= False
;
831 /* only process windows with StructureNotify selected
832 * (ignore SubstructureNotify) */
833 wwin
= wWindowFor(event
->xunmap
.window
);
837 /* whether the event is a Withdrawal request */
838 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
841 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
844 if (!wwin
->flags
.mapped
&& !withdraw
845 && wwin
->frame
->workspace
== w_global
.workspace
.current
846 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
850 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
851 wwin
->flags
.mapped
= 0;
853 /* check if the window was destroyed */
854 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
857 Bool reparented
= False
;
859 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
862 /* withdraw window */
863 wwin
->flags
.mapped
= 0;
865 wClientSetState(wwin
, WithdrawnState
, None
);
867 /* if the window was reparented, do not reparent it back to the
869 wUnmanageWindow(wwin
, !reparented
, False
);
874 static void handleConfigureRequest(XEvent
* event
)
878 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
880 * Configure request for unmapped window
882 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
884 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
888 static void handlePropertyNotify(XEvent
* event
)
896 wwin
= wWindowFor(event
->xproperty
.window
);
898 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
901 wClientCheckProperty(wwin
, &event
->xproperty
);
903 wapp
= wApplicationOf(event
->xproperty
.window
);
905 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
909 static void handleClientMessage(XEvent
* event
)
912 WObjDescriptor
*desc
;
914 /* handle transition from Normal to Iconic state */
915 if (event
->xclient
.message_type
== w_global
.atom
.wm
.change_state
916 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
918 wwin
= wWindowFor(event
->xclient
.window
);
921 if (!wwin
->flags
.miniaturized
)
922 wIconifyWindow(wwin
);
923 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.colormap_notify
&& event
->xclient
.format
== 32) {
924 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
929 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
930 wColormapAllowClientInstallation(scr
, True
);
931 } else { /* stopping */
932 wColormapAllowClientInstallation(scr
, False
);
934 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.command
) {
939 len
= sizeof(event
->xclient
.data
.b
) + 1;
940 command
= wmalloc(len
);
941 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
943 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
944 wwarning(_("Got Reconfigure command"));
945 wDefaultsCheckDomains(NULL
);
947 wwarning(_("Got unknown command %s"), command
);
952 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.wm_function
) {
955 wapp
= wApplicationOf(event
->xclient
.window
);
957 switch (event
->xclient
.data
.l
[0]) {
958 case WMFHideOtherApplications
:
959 wHideOtherApplications(wapp
->main_window_desc
);
963 case WMFHideApplication
:
964 wHideApplication(wapp
);
970 wwin
= wWindowFor(event
->xclient
.window
);
972 switch (event
->xclient
.data
.l
[0]) {
973 case WMFHideOtherApplications
:
974 wHideOtherApplications(wwin
);
977 case WMFHideApplication
:
978 wHideApplication(wApplicationOf(wwin
->main_window
));
983 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.wm_attr
) {
984 wwin
= wWindowFor(event
->xclient
.window
);
987 switch (event
->xclient
.data
.l
[0]) {
988 case GSWindowLevelAttr
:
990 int level
= (int)event
->xclient
.data
.l
[1];
992 if (WINDOW_LEVEL(wwin
) != level
) {
993 ChangeStackingLevel(wwin
->frame
->core
, level
);
998 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.titlebar_state
) {
999 wwin
= wWindowFor(event
->xclient
.window
);
1002 switch (event
->xclient
.data
.l
[0]) {
1003 case WMTitleBarNormal
:
1004 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1006 case WMTitleBarMain
:
1007 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1010 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1013 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.ignore_focus_events
) {
1014 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1017 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1018 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1021 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1026 * Non-standard thing, but needed by OffiX DND.
1027 * For when the icon frame gets a ClientMessage
1028 * that should have gone to the icon_window.
1030 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1031 struct WIcon
*icon
= NULL
;
1033 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1034 icon
= (WIcon
*) desc
->parent
;
1035 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1036 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1038 if (icon
&& (wwin
= icon
->owner
)) {
1039 if (wwin
->client_win
!= event
->xclient
.window
) {
1040 event
->xclient
.window
= wwin
->client_win
;
1041 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1048 static void raiseWindow(WScreen
* scr
)
1052 scr
->autoRaiseTimer
= NULL
;
1054 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1058 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1059 wRaiseFrame(wwin
->frame
->core
);
1060 /* this is needed or a race condition will occur */
1065 static void handleEnterNotify(XEvent
* event
)
1068 WObjDescriptor
*desc
= NULL
;
1070 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1072 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1073 /* already left the window... */
1075 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1080 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1081 if (desc
->handle_enternotify
)
1082 (*desc
->handle_enternotify
) (desc
, event
);
1085 /* enter to window */
1086 wwin
= wWindowFor(event
->xcrossing
.window
);
1088 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1089 wColormapInstallForWindow(scr
, NULL
);
1091 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1092 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1093 scr
->autoRaiseTimer
= NULL
;
1096 /* set auto raise timer even if in focus-follows-mouse mode
1097 * and the event is for the frame window, even if the window
1098 * has focus already. useful if you move the pointer from a focused
1099 * window to the root window and back pretty fast
1101 * set focus if in focus-follows-mouse mode and the event
1102 * is for the frame window and window doesn't have focus yet */
1103 if (wPreferences
.focus_mode
== WKF_SLOPPY
1104 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1106 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1107 wSetFocusTo(scr
, wwin
);
1109 if (scr
->autoRaiseTimer
)
1110 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1111 scr
->autoRaiseTimer
= NULL
;
1113 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1114 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1116 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1119 /* Install colormap for window, if the colormap installation mode
1120 * is colormap_follows_mouse */
1121 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1122 if (wwin
->client_win
== event
->xcrossing
.window
)
1123 wColormapInstallForWindow(scr
, wwin
);
1125 wColormapInstallForWindow(scr
, NULL
);
1129 if (event
->xcrossing
.window
== event
->xcrossing
.root
1130 && event
->xcrossing
.detail
== NotifyNormal
1131 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1133 wSetFocusTo(scr
, scr
->focused_window
);
1136 wBalloonEnteredObject(scr
, desc
);
1140 static void handleLeaveNotify(XEvent
* event
)
1142 WObjDescriptor
*desc
= NULL
;
1144 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1145 if (desc
->handle_leavenotify
)
1146 (*desc
->handle_leavenotify
) (desc
, event
);
1151 static void handleShapeNotify(XEvent
* event
)
1153 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1160 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1161 if (ev
.xshape
.kind
== ShapeBounding
) {
1162 if (ev
.xshape
.shaped
== shev
->shaped
) {
1165 XPutBackEvent(dpy
, &ev
.xevent
);
1171 wwin
= wWindowFor(shev
->window
);
1172 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1175 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1177 wwin
->flags
.shaped
= 0;
1178 wWindowClearShape(wwin
);
1180 } else if (shev
->shaped
) {
1182 wwin
->flags
.shaped
= 1;
1183 wWindowSetShape(wwin
);
1186 #endif /* USE_XSHAPE */
1188 #ifdef KEEP_XKB_LOCK_STATUS
1189 /* please help ]d if you know what to do */
1190 static void handleXkbIndicatorStateNotify(XEvent
*event
)
1194 XkbStateRec staterec
;
1197 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1198 scr
= wScreenWithNumber(i
);
1199 wwin
= scr
->focused_window
;
1200 if (wwin
&& wwin
->flags
.focused
) {
1201 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1202 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1203 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1204 wwin
->frame
->languagemode
= staterec
.group
;
1206 #ifdef XKB_BUTTON_HINT
1207 if (wwin
->frame
->titlebar
) {
1208 wFrameWindowPaint(wwin
->frame
);
1214 #endif /*KEEP_XKB_LOCK_STATUS */
1216 static void handleColormapNotify(XEvent
* event
)
1220 Bool reinstall
= False
;
1222 wwin
= wWindowFor(event
->xcolormap
.window
);
1226 scr
= wwin
->screen_ptr
;
1230 if (event
->xcolormap
.new) {
1231 XWindowAttributes attr
;
1233 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1235 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1236 scr
->current_colormap
= attr
.colormap
;
1239 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1240 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1242 /* some bastard app (like XV) removed our colormap */
1244 * can't enforce or things like xscreensaver wont work
1247 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1248 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1250 /* someone has put our colormap back */
1254 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1255 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1257 if (reinstall
&& scr
->current_colormap
!= None
) {
1258 if (!scr
->flags
.colormap_stuff_blocked
)
1259 XInstallColormap(dpy
, scr
->current_colormap
);
1263 static void handleFocusIn(XEvent
* event
)
1268 * For applications that like stealing the focus.
1270 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1271 saveTimestamp(event
);
1272 if (event
->xfocus
.mode
== NotifyUngrab
1273 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1277 wwin
= wWindowFor(event
->xfocus
.window
);
1278 if (wwin
&& !wwin
->flags
.focused
) {
1279 if (wwin
->flags
.mapped
)
1280 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1282 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1284 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1286 wSetFocusTo(scr
, NULL
);
1290 static WWindow
*windowUnderPointer(WScreen
* scr
)
1296 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1297 return wWindowFor(win
);
1301 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1303 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1309 static void handleKeyPress(XEvent
* event
)
1311 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1312 WWindow
*wwin
= scr
->focused_window
;
1316 #ifdef KEEP_XKB_LOCK_STATUS
1317 XkbStateRec staterec
;
1318 #endif /*KEEP_XKB_LOCK_STATUS */
1320 /* ignore CapsLock */
1321 modifiers
= event
->xkey
.state
& w_global
.shortcut
.modifiers_mask
;
1323 for (i
= 0; i
< WKBD_LAST
; i
++) {
1324 if (wKeyBindings
[i
].keycode
== 0)
1327 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1328 || */ wKeyBindings
[i
].modifier
==
1337 if (!wRootMenuPerformShortcut(event
)) {
1338 static int dontLoop
= 0;
1340 if (dontLoop
> 10) {
1341 wwarning("problem with key event processing code");
1345 /* if the focused window is an internal window, try redispatching
1346 * the event to the managed window, as it can be a WINGs window */
1347 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1348 /* client_leader contains the WINGs toplevel */
1349 event
->xany
.window
= wwin
->client_leader
;
1350 WMHandleEvent(event
);
1356 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1357 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1362 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1363 if (!CheckFullScreenWindowFocused(scr
)) {
1364 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1365 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1369 case WKBD_WINDOWLIST
:
1370 if (!CheckFullScreenWindowFocused(scr
)) {
1371 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1372 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1377 case WKBD_WINDOWMENU
:
1378 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1379 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1381 case WKBD_MINIMIZEALL
:
1382 CloseWindowMenu(scr
);
1385 case WKBD_MINIATURIZE
:
1386 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1387 && !WFLAGP(wwin
, no_miniaturizable
)) {
1388 CloseWindowMenu(scr
);
1390 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1391 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
, event
->xbutton
.time
);
1393 wIconifyWindow(wwin
);
1398 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1399 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1400 CloseWindowMenu(scr
);
1402 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1403 wHideApplication(wapp
);
1407 case WKBD_HIDE_OTHERS
:
1408 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1409 CloseWindowMenu(scr
);
1411 wHideOtherApplications(wwin
);
1415 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1416 CloseWindowMenu(scr
);
1418 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1421 case WKBD_VMAXIMIZE
:
1422 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1423 CloseWindowMenu(scr
);
1425 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1428 case WKBD_HMAXIMIZE
:
1429 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1430 CloseWindowMenu(scr
);
1432 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1435 case WKBD_LHMAXIMIZE
:
1436 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1437 CloseWindowMenu(scr
);
1439 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1442 case WKBD_RHMAXIMIZE
:
1443 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1444 CloseWindowMenu(scr
);
1446 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1449 case WKBD_THMAXIMIZE
:
1450 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1451 CloseWindowMenu(scr
);
1453 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1456 case WKBD_BHMAXIMIZE
:
1457 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1458 CloseWindowMenu(scr
);
1460 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1463 case WKBD_LTCMAXIMIZE
:
1464 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1465 CloseWindowMenu(scr
);
1467 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1470 case WKBD_RTCMAXIMIZE
:
1471 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1472 CloseWindowMenu(scr
);
1474 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1477 case WKBD_LBCMAXIMIZE
:
1478 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1479 CloseWindowMenu(scr
);
1481 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1484 case WKBD_RBCMAXIMIZE
:
1485 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1486 CloseWindowMenu(scr
);
1488 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1492 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1493 CloseWindowMenu(scr
);
1495 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1499 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1500 CloseWindowMenu(scr
);
1502 wRaiseFrame(wwin
->frame
->core
);
1506 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1507 CloseWindowMenu(scr
);
1509 wLowerFrame(wwin
->frame
->core
);
1512 case WKBD_RAISELOWER
:
1513 /* raise or lower the window under the pointer, not the
1516 wwin
= windowUnderPointer(scr
);
1518 wRaiseLowerFrame(wwin
->frame
->core
);
1521 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1522 if (wwin
->flags
.shaded
)
1523 wUnshadeWindow(wwin
);
1528 case WKBD_MOVERESIZE
:
1529 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1530 CloseWindowMenu(scr
);
1532 wKeyboardMoveResizeWindow(wwin
);
1536 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1537 CloseWindowMenu(scr
);
1538 if (wwin
->protocols
.DELETE_WINDOW
)
1539 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
, event
->xkey
.time
);
1543 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1544 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1547 case WKBD_FOCUSNEXT
:
1548 StartWindozeCycle(wwin
, event
, True
, False
);
1551 case WKBD_FOCUSPREV
:
1552 StartWindozeCycle(wwin
, event
, False
, False
);
1555 case WKBD_GROUPNEXT
:
1556 StartWindozeCycle(wwin
, event
, True
, True
);
1559 case WKBD_GROUPPREV
:
1560 StartWindozeCycle(wwin
, event
, False
, True
);
1563 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1564 widx
= command
- WKBD_WORKSPACE1
;
1565 i
= (w_global
.workspace
.current
/ 10) * 10 + widx
;
1566 if (wPreferences
.ws_advance
|| i
< w_global
.workspace
.count
)
1567 wWorkspaceChange(scr
, i
);
1570 case WKBD_NEXTWORKSPACE
:
1571 wWorkspaceRelativeChange(scr
, 1);
1573 case WKBD_PREVWORKSPACE
:
1574 wWorkspaceRelativeChange(scr
, -1);
1576 case WKBD_LASTWORKSPACE
:
1577 wWorkspaceChange(scr
, w_global
.workspace
.last_used
);
1580 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1581 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1582 i
= (w_global
.workspace
.current
/ 10) * 10 + widx
;
1583 if (wwin
&& (wPreferences
.ws_advance
|| i
< w_global
.workspace
.count
))
1584 wWindowChangeWorkspace(wwin
, i
);
1587 case WKBD_MOVE_NEXTWORKSPACE
:
1589 wWindowChangeWorkspaceRelative(wwin
, 1);
1591 case WKBD_MOVE_PREVWORKSPACE
:
1593 wWindowChangeWorkspaceRelative(wwin
, -1);
1595 case WKBD_MOVE_LASTWORKSPACE
:
1597 wWindowChangeWorkspace(wwin
, w_global
.workspace
.last_used
);
1600 case WKBD_MOVE_NEXTWSLAYER
:
1601 case WKBD_MOVE_PREVWSLAYER
:
1606 row
= w_global
.workspace
.current
/ 10;
1607 column
= w_global
.workspace
.current
% 10;
1609 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1610 if ((row
+ 1) * 10 < w_global
.workspace
.count
)
1611 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1614 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1631 widx
= command
- WKBD_WINDOW1
;
1633 if (w_global
.shortcut
.windows
[widx
]) {
1634 WMArray
*list
= w_global
.shortcut
.windows
[widx
];
1636 int count
= WMGetArrayItemCount(list
);
1638 WMArrayIterator iter
;
1641 wUnselectWindows(scr
);
1642 cw
= w_global
.workspace
.current
;
1644 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1646 wWindowChangeWorkspace(wwin
, cw
);
1648 wMakeWindowVisible(wwin
);
1651 wSelectWindow(wwin
, True
);
1654 /* rotate the order of windows, to create a cycling effect */
1655 twin
= WMGetFromArray(list
, 0);
1656 WMDeleteFromArray(list
, 0);
1657 WMAddToArray(list
, twin
);
1659 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1660 if (w_global
.shortcut
.windows
[widx
]) {
1661 WMFreeArray(w_global
.shortcut
.windows
[widx
]);
1662 w_global
.shortcut
.windows
[widx
] = NULL
;
1665 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1666 w_global
.shortcut
.windows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1668 w_global
.shortcut
.windows
[widx
] = WMCreateArray(4);
1669 WMAddToArray(w_global
.shortcut
.windows
[widx
], wwin
);
1672 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1675 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1678 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1679 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1680 if (w_global
.shortcut
.windows
[widx
])
1681 WMFreeArray(w_global
.shortcut
.windows
[widx
]);
1683 w_global
.shortcut
.windows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1690 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1691 (void) RelaunchWindow(wwin
);
1695 case WKBD_SWITCH_SCREEN
:
1696 if (w_global
.screen_count
> 1) {
1700 /* find index of this screen */
1701 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1702 if (wScreenWithNumber(i
) == scr
)
1706 if (i
>= w_global
.screen_count
) {
1709 scr2
= wScreenWithNumber(i
);
1712 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1713 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1722 cmdline
= ExpandOptions(scr
, _("exec %a(Run,Type command to run:)"));
1725 XGrabPointer(dpy
, scr
->root_win
, True
, 0,
1726 GrabModeAsync
, GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_WAIT
], CurrentTime
);
1729 ExecuteShellCommand(scr
, cmdline
);
1732 XUngrabPointer(dpy
, CurrentTime
);
1738 case WKBD_NEXTWSLAYER
:
1739 case WKBD_PREVWSLAYER
:
1743 row
= w_global
.workspace
.current
/ 10;
1744 column
= w_global
.workspace
.current
% 10;
1746 if (command
== WKBD_NEXTWSLAYER
) {
1747 if ((row
+ 1) * 10 < w_global
.workspace
.count
)
1748 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1751 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1755 case WKBD_CLIPRAISELOWER
:
1756 if (!wPreferences
.flags
.noclip
)
1757 wDockRaiseLower(w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
);
1759 case WKBD_DOCKRAISELOWER
:
1760 if (!wPreferences
.flags
.nodock
)
1761 wDockRaiseLower(scr
->dock
);
1763 #ifdef KEEP_XKB_LOCK_STATUS
1765 if (wPreferences
.modelock
) {
1767 wwin
= scr
->focused_window
;
1769 if (wwin
&& wwin
->flags
.mapped
1770 && wwin
->frame
->workspace
== w_global
.workspace
.current
1771 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1772 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1774 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1775 wwin
->frame
->last_languagemode
= staterec
.group
;
1776 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1781 #endif /* KEEP_XKB_LOCK_STATUS */
1785 static void handleMotionNotify(XEvent
* event
)
1787 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1789 if (wPreferences
.scrollable_menus
) {
1790 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1791 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1793 if (scr
->flags
.jump_back_pending
||
1794 p
.x
<= (rect
.pos
.x
+ 1) ||
1795 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1796 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1799 menu
= wMenuUnderPointer(scr
);
1806 static void handleVisibilityNotify(XEvent
* event
)
1810 wwin
= wWindowFor(event
->xvisibility
.window
);
1813 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);