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"
76 /******** Global Variables **********/
77 extern XContext wWinContext
;
78 extern XContext wVEdgeContext
;
80 extern Cursor wCursor
[WCUR_LAST
];
82 extern WShortKey wKeyBindings
[WKBD_LAST
];
83 extern int wScreenCount
;
84 extern Time LastTimestamp
;
85 extern Time LastFocusChange
;
87 extern WPreferences wPreferences
;
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 /* called from the signal handler */
144 void NotifyDeadProcess(pid_t pid
, unsigned char status
);
146 /* real dead process handler */
147 static void handleDeadProcess(void *foo
);
149 typedef struct DeadProcesses
{
151 unsigned char exit_status
;
154 /* stack of dead processes */
155 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
156 static int deadProcessPtr
= 0;
158 typedef struct DeathHandler
{
159 WDeathHandler
*callback
;
164 static WMArray
*deathHandlers
= NULL
;
166 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
168 DeathHandler
*handler
;
170 handler
= malloc(sizeof(DeathHandler
));
175 handler
->callback
= callback
;
176 handler
->client_data
= cdata
;
179 deathHandlers
= WMCreateArrayWithDestructor(8, free
);
181 WMAddToArray(deathHandlers
, handler
);
186 static void wdelete_death_handler(WMagicNumber id
)
188 DeathHandler
*handler
= (DeathHandler
*) id
;
190 if (!handler
|| !deathHandlers
)
193 /* array destructor will call free(handler) */
194 WMRemoveFromArray(deathHandlers
, handler
);
197 void DispatchEvent(XEvent
* event
)
200 handleDeadProcess(NULL
);
202 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
203 WCHANGE_STATE(WSTATE_EXITING
);
204 /* received SIGTERM */
206 * WMHandleEvent() can't be called from anything
207 * executed inside here, or we can get in a infinite
210 Shutdown(WSExitMode
);
212 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
213 WCHANGE_STATE(WSTATE_RESTARTING
);
215 Shutdown(WSRestartPreparationMode
);
216 /* received SIGHUP */
218 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
219 WCHANGE_STATE(WSTATE_NORMAL
);
220 wDefaultsCheckDomains(NULL
);
223 /* for the case that all that is wanted to be dispatched is
228 saveTimestamp(event
);
229 switch (event
->type
) {
231 handleMapRequest(event
);
235 handleKeyPress(event
);
239 handleMotionNotify(event
);
242 case ConfigureRequest
:
243 handleConfigureRequest(event
);
247 handleDestroyNotify(event
);
251 handleMapNotify(event
);
255 handleUnmapNotify(event
);
259 handleButtonPress(event
);
267 handlePropertyNotify(event
);
271 handleEnterNotify(event
);
275 handleLeaveNotify(event
);
279 handleClientMessage(event
);
283 handleColormapNotify(event
);
287 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
288 XRefreshKeyboardMapping(&event
->xmapping
);
292 handleFocusIn(event
);
295 case VisibilityNotify
:
296 handleVisibilityNotify(event
);
299 case ConfigureNotify
:
301 if (event
->xconfigure
.window
== DefaultRootWindow(dpy
))
302 XRRUpdateConfiguration(event
);
307 handleExtensions(event
);
314 *----------------------------------------------------------------------
315 * handle_inotify_events-
316 * Check for inotify events
319 * After reading events for the given file descriptor (fd) and
320 * watch descriptor (wd)
323 * Calls wDefaultsCheckDomains if config database is updated
324 *----------------------------------------------------------------------
326 /* allow 5 simultaneous events, with path + filenames up to 64 chars */
327 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
328 static void handle_inotify_events(int fd
, int wd
)
330 ssize_t eventQLength
, i
= 0;
331 char buff
[BUFF_SIZE
] = { 0 };
332 /* Check config only once per read of the event queue */
336 * Read off the queued events
337 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
338 * not occur; the block is on Xevents, but a config file change will normally
339 * occur as a result of an Xevent - so the event queue should never have more than
340 * a few entries before a read().
342 eventQLength
= read(fd
, buff
, BUFF_SIZE
);
344 /* check what events occured */
345 /* Should really check wd here too, but for now we only have one watch! */
346 while (i
< eventQLength
) {
347 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
350 * see inotify.h for event types.
352 if (pevent
->mask
& IN_DELETE_SELF
) {
353 wwarning(_("the defaults database has been deleted!"
354 " Restart Window Maker to create the database" " with the default settings"));
357 if (pevent
->mask
& IN_UNMOUNT
) {
358 wwarning(_("the unit containing the defaults database has"
359 " been unmounted. Setting --static mode." " Any changes will not be saved."));
361 wPreferences
.flags
.noupdates
= 1;
363 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
364 wwarning(_("Inotify: Reading config files in defaults database."));
365 wDefaultsCheckDomains(NULL
);
368 /* move to next event in the buffer */
369 i
+= sizeof(struct inotify_event
) + pevent
->len
;
372 #endif /* HAVE_INOTIFY */
375 *----------------------------------------------------------------------
377 * Processes X and internal events indefinitely.
383 * The LastTimestamp global variable is updated.
384 * Calls inotifyGetEvents if defaults database changes.
385 *----------------------------------------------------------------------
391 extern int inotifyFD
;
392 extern int inotifyWD
;
397 if (inotifyFD
< 0 || inotifyWD
< 0)
403 WMNextEvent(dpy
, &event
); /* Blocks here */
404 WMHandleEvent(&event
);
410 FD_SET(inotifyFD
, &rfds
);
412 /* check for available read data from inotify - don't block! */
413 retVal
= select(inotifyFD
+ 1, &rfds
, NULL
, NULL
, &time
);
415 if (retVal
< 0) { /* an error has occured */
416 wwarning(_("select failed. The inotify instance will be closed."
417 " Changes to the defaults database will require"
418 " a restart to take effect."));
422 if (FD_ISSET(inotifyFD
, &rfds
))
423 handle_inotify_events(inotifyFD
, inotifyWD
);
430 *----------------------------------------------------------------------
431 * ProcessPendingEvents --
432 * Processes the events that are currently pending (at the time
433 * this function is called) in the display's queue.
436 * After the pending events that were present at the function call
440 * Many -- whatever handling events may involve.
442 *----------------------------------------------------------------------
444 void ProcessPendingEvents(void)
451 /* Take a snapshot of the event count in the queue */
452 count
= XPending(dpy
);
454 while (count
> 0 && XPending(dpy
)) {
455 WMNextEvent(dpy
, &event
);
456 WMHandleEvent(&event
);
461 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
463 if ((scr
->last_click_time
> 0) &&
464 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
465 && (event
->xbutton
.button
== scr
->last_click_button
)
466 && (event
->xbutton
.window
== scr
->last_click_window
)) {
468 scr
->flags
.next_click_is_not_double
= 1;
469 scr
->last_click_time
= 0;
470 scr
->last_click_window
= event
->xbutton
.window
;
477 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
479 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
480 wwarning("stack overflow: too many dead processes");
483 /* stack the process to be handled later,
484 * as this is called from the signal handler */
485 deadProcesses
[deadProcessPtr
].pid
= pid
;
486 deadProcesses
[deadProcessPtr
].exit_status
= status
;
490 static void handleDeadProcess(void *foo
)
495 for (i
= 0; i
< deadProcessPtr
; i
++) {
496 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
499 if (!deathHandlers
) {
504 /* get the pids on the queue and call handlers */
505 while (deadProcessPtr
> 0) {
508 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
509 tmp
= WMGetFromArray(deathHandlers
, i
);
513 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
514 (*tmp
->callback
) (tmp
->pid
,
515 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
516 wdelete_death_handler(tmp
);
522 static void saveTimestamp(XEvent
* event
)
525 * Never save CurrentTime as LastTimestamp because CurrentTime
526 * it's not a real timestamp (it's the 0L constant)
529 switch (event
->type
) {
532 LastTimestamp
= event
->xbutton
.time
;
536 LastTimestamp
= event
->xkey
.time
;
539 LastTimestamp
= event
->xmotion
.time
;
542 LastTimestamp
= event
->xproperty
.time
;
546 LastTimestamp
= event
->xcrossing
.time
;
549 LastTimestamp
= event
->xselectionclear
.time
;
551 case SelectionRequest
:
552 LastTimestamp
= event
->xselectionrequest
.time
;
554 case SelectionNotify
:
555 LastTimestamp
= event
->xselection
.time
;
557 wXDNDProcessSelection(event
);
563 static int matchWindow(const void *item
, const void *cdata
)
565 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
568 static void handleExtensions(XEvent
* event
)
570 #ifdef KEEP_XKB_LOCK_STATUS
572 xkbevent
= (XkbEvent
*) event
;
573 #endif /*KEEP_XKB_LOCK_STATUS */
575 if (wShapeSupported
&& event
->type
== (wShapeEventBase
+ ShapeNotify
)) {
576 handleShapeNotify(event
);
579 #ifdef KEEP_XKB_LOCK_STATUS
580 if (wPreferences
.modelock
&& (xkbevent
->type
== wXkbEventBase
)) {
581 handleXkbIndicatorStateNotify(event
);
583 #endif /*KEEP_XKB_LOCK_STATUS */
585 if (has_randr
&& event
->type
== (randr_event_base
+ RRScreenChangeNotify
)) {
586 /* From xrandr man page: "Clients must call back into Xlib using
587 * XRRUpdateConfiguration when screen configuration change notify
588 * events are generated */
589 XRRUpdateConfiguration(event
);
590 WCHANGE_STATE(WSTATE_RESTARTING
);
591 Shutdown(WSRestartPreparationMode
);
597 static void handleMapRequest(XEvent
* ev
)
601 Window window
= ev
->xmaprequest
.window
;
603 if ((wwin
= wWindowFor(window
))) {
604 if (wwin
->flags
.shaded
) {
605 wUnshadeWindow(wwin
);
607 /* deiconify window */
608 if (wwin
->flags
.miniaturized
) {
609 wDeiconifyWindow(wwin
);
610 } else if (wwin
->flags
.hidden
) {
611 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
612 /* go to the last workspace that the user worked on the app */
614 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
616 wUnhideApplication(wapp
, False
, False
);
621 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
623 wwin
= wManageWindow(scr
, window
);
626 * This is to let the Dock know that the application it launched
627 * has already been mapped (eg: it has finished launching).
628 * It is not necessary for normally docked apps, but is needed for
629 * apps that were forcedly docked (like with dockit).
631 if (scr
->last_dock
) {
632 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
633 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
635 wDockTrackWindowLaunch(scr
->last_dock
, window
);
639 wClientSetState(wwin
, NormalState
, None
);
640 if (wwin
->flags
.maximized
) {
641 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
643 if (wwin
->flags
.shaded
) {
644 wwin
->flags
.shaded
= 0;
645 wwin
->flags
.skip_next_animation
= 1;
648 if (wwin
->flags
.miniaturized
) {
649 wwin
->flags
.miniaturized
= 0;
650 wwin
->flags
.skip_next_animation
= 1;
651 wIconifyWindow(wwin
);
653 if (wwin
->flags
.fullscreen
) {
654 wwin
->flags
.fullscreen
= 0;
655 wFullscreenWindow(wwin
);
657 if (wwin
->flags
.hidden
) {
658 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
660 wwin
->flags
.hidden
= 0;
661 wwin
->flags
.skip_next_animation
= 1;
663 wHideApplication(wapp
);
669 static void handleDestroyNotify(XEvent
* event
)
673 Window window
= event
->xdestroywindow
.window
;
674 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
677 wwin
= wWindowFor(window
);
679 wUnmanageWindow(wwin
, False
, True
);
683 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
684 WFakeGroupLeader
*fPtr
;
686 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
687 if (fPtr
->retainCount
> 0) {
689 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
690 XDestroyWindow(dpy
, fPtr
->leader
);
695 fPtr
->origLeader
= None
;
699 app
= wApplicationOf(window
);
701 if (window
== app
->main_window
) {
703 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
705 if (wwin
->main_window
== window
) {
706 wwin
->main_window
= None
;
711 wApplicationDestroy(app
);
715 static void handleExpose(XEvent
* event
)
717 WObjDescriptor
*desc
;
720 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
722 if (XFindContext(dpy
, event
->xexpose
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
726 if (desc
->handle_expose
) {
727 (*desc
->handle_expose
) (desc
, event
);
731 static void executeButtonAction(WScreen
* scr
, XEvent
* event
, int action
)
734 case WA_SELECT_WINDOWS
:
735 wUnselectWindows(scr
);
736 wSelectWindows(scr
, event
);
738 case WA_OPEN_APPMENU
:
739 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
741 if (scr
->root_menu
) {
742 if (scr
->root_menu
->brother
->flags
.mapped
)
743 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
745 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
748 case WA_OPEN_WINLISTMENU
:
749 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
750 if (scr
->switch_menu
) {
751 if (scr
->switch_menu
->brother
->flags
.mapped
)
752 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
754 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
763 static void handleButtonPress(XEvent
* event
)
765 WObjDescriptor
*desc
;
768 scr
= wScreenForRootWindow(event
->xbutton
.root
);
774 if (event
->xbutton
.window
== scr
->root_win
) {
775 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
776 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
777 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
778 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
779 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
780 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
781 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
782 wWorkspaceRelativeChange(scr
, 1);
783 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel
!= WA_NONE
) {
784 wWorkspaceRelativeChange(scr
, -1);
789 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
790 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
) {
795 if (desc
->parent_type
== WCLASS_WINDOW
) {
798 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
799 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
801 /* if (wPreferences.focus_mode == WKF_CLICK) { */
802 if (wPreferences
.ignore_focus_click
) {
803 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
805 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
809 } else if (desc
->parent_type
== WCLASS_APPICON
810 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
811 if (event
->xbutton
.state
& MOD_MASK
) {
813 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
818 if (desc
->handle_mousedown
!= NULL
) {
819 (*desc
->handle_mousedown
) (desc
, event
);
822 /* save double-click information */
823 if (scr
->flags
.next_click_is_not_double
) {
824 scr
->flags
.next_click_is_not_double
= 0;
826 scr
->last_click_time
= event
->xbutton
.time
;
827 scr
->last_click_button
= event
->xbutton
.button
;
828 scr
->last_click_window
= event
->xbutton
.window
;
832 static void handleMapNotify(XEvent
* event
)
836 wwin
= wWindowFor(event
->xmap
.event
);
837 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
838 if (wwin
->flags
.miniaturized
) {
839 wDeiconifyWindow(wwin
);
843 wClientSetState(wwin
, NormalState
, None
);
849 static void handleUnmapNotify(XEvent
* event
)
853 Bool withdraw
= False
;
855 /* only process windows with StructureNotify selected
856 * (ignore SubstructureNotify) */
857 wwin
= wWindowFor(event
->xunmap
.window
);
861 /* whether the event is a Withdrawal request */
862 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
865 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
868 if (!wwin
->flags
.mapped
&& !withdraw
869 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
870 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
874 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
875 wwin
->flags
.mapped
= 0;
877 /* check if the window was destroyed */
878 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
881 Bool reparented
= False
;
883 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
886 /* withdraw window */
887 wwin
->flags
.mapped
= 0;
889 wClientSetState(wwin
, WithdrawnState
, None
);
891 /* if the window was reparented, do not reparent it back to the
893 wUnmanageWindow(wwin
, !reparented
, False
);
898 static void handleConfigureRequest(XEvent
* event
)
902 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
904 * Configure request for unmapped window
906 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
908 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
912 static void handlePropertyNotify(XEvent
* event
)
920 wwin
= wWindowFor(event
->xproperty
.window
);
922 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
925 wClientCheckProperty(wwin
, &event
->xproperty
);
927 wapp
= wApplicationOf(event
->xproperty
.window
);
929 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
933 static void handleClientMessage(XEvent
* event
)
936 WObjDescriptor
*desc
;
938 /* handle transition from Normal to Iconic state */
939 if (event
->xclient
.message_type
== _XA_WM_CHANGE_STATE
940 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
942 wwin
= wWindowFor(event
->xclient
.window
);
945 if (!wwin
->flags
.miniaturized
)
946 wIconifyWindow(wwin
);
947 } else if (event
->xclient
.message_type
== _XA_WM_COLORMAP_NOTIFY
&& event
->xclient
.format
== 32) {
948 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
953 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
954 wColormapAllowClientInstallation(scr
, True
);
955 } else { /* stopping */
956 wColormapAllowClientInstallation(scr
, False
);
958 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_COMMAND
) {
963 len
= sizeof(event
->xclient
.data
.b
) + 1;
964 command
= wmalloc(len
);
965 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
967 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
968 wwarning(_("Got Reconfigure command"));
969 wDefaultsCheckDomains(NULL
);
971 wwarning(_("Got unknown command %s"), command
);
976 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
979 wapp
= wApplicationOf(event
->xclient
.window
);
981 switch (event
->xclient
.data
.l
[0]) {
982 case WMFHideOtherApplications
:
983 wHideOtherApplications(wapp
->main_window_desc
);
987 case WMFHideApplication
:
988 wHideApplication(wapp
);
994 wwin
= wWindowFor(event
->xclient
.window
);
996 switch (event
->xclient
.data
.l
[0]) {
997 case WMFHideOtherApplications
:
998 wHideOtherApplications(wwin
);
1001 case WMFHideApplication
:
1002 wHideApplication(wApplicationOf(wwin
->main_window
));
1007 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_WM_ATTR
) {
1008 wwin
= wWindowFor(event
->xclient
.window
);
1011 switch (event
->xclient
.data
.l
[0]) {
1012 case GSWindowLevelAttr
:
1014 int level
= (int)event
->xclient
.data
.l
[1];
1016 if (WINDOW_LEVEL(wwin
) != level
) {
1017 ChangeStackingLevel(wwin
->frame
->core
, level
);
1022 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_TITLEBAR_STATE
) {
1023 wwin
= wWindowFor(event
->xclient
.window
);
1026 switch (event
->xclient
.data
.l
[0]) {
1027 case WMTitleBarNormal
:
1028 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1030 case WMTitleBarMain
:
1031 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1034 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1037 } else if (event
->xclient
.message_type
== _XA_WM_IGNORE_FOCUS_EVENTS
) {
1038 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1041 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1042 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1045 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1050 * Non-standard thing, but needed by OffiX DND.
1051 * For when the icon frame gets a ClientMessage
1052 * that should have gone to the icon_window.
1054 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1055 struct WIcon
*icon
= NULL
;
1057 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1058 icon
= (WIcon
*) desc
->parent
;
1059 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1060 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1062 if (icon
&& (wwin
= icon
->owner
)) {
1063 if (wwin
->client_win
!= event
->xclient
.window
) {
1064 event
->xclient
.window
= wwin
->client_win
;
1065 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1072 static void raiseWindow(WScreen
* scr
)
1076 scr
->autoRaiseTimer
= NULL
;
1078 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1082 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1083 wRaiseFrame(wwin
->frame
->core
);
1084 /* this is needed or a race condition will occur */
1089 static void handleEnterNotify(XEvent
* event
)
1092 WObjDescriptor
*desc
= NULL
;
1094 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1096 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1097 /* already left the window... */
1099 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1104 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1105 if (desc
->handle_enternotify
)
1106 (*desc
->handle_enternotify
) (desc
, event
);
1109 /* enter to window */
1110 wwin
= wWindowFor(event
->xcrossing
.window
);
1112 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1113 wColormapInstallForWindow(scr
, NULL
);
1115 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1116 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1117 scr
->autoRaiseTimer
= NULL
;
1120 /* set auto raise timer even if in focus-follows-mouse mode
1121 * and the event is for the frame window, even if the window
1122 * has focus already. useful if you move the pointer from a focused
1123 * window to the root window and back pretty fast
1125 * set focus if in focus-follows-mouse mode and the event
1126 * is for the frame window and window doesn't have focus yet */
1127 if (wPreferences
.focus_mode
== WKF_SLOPPY
1128 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1130 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1131 wSetFocusTo(scr
, wwin
);
1133 if (scr
->autoRaiseTimer
)
1134 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1135 scr
->autoRaiseTimer
= NULL
;
1137 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1138 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1140 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1143 /* Install colormap for window, if the colormap installation mode
1144 * is colormap_follows_mouse */
1145 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1146 if (wwin
->client_win
== event
->xcrossing
.window
)
1147 wColormapInstallForWindow(scr
, wwin
);
1149 wColormapInstallForWindow(scr
, NULL
);
1153 if (event
->xcrossing
.window
== event
->xcrossing
.root
1154 && event
->xcrossing
.detail
== NotifyNormal
1155 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1157 wSetFocusTo(scr
, scr
->focused_window
);
1160 wBalloonEnteredObject(scr
, desc
);
1164 static void handleLeaveNotify(XEvent
* event
)
1166 WObjDescriptor
*desc
= NULL
;
1168 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1169 if (desc
->handle_leavenotify
)
1170 (*desc
->handle_leavenotify
) (desc
, event
);
1175 static void handleShapeNotify(XEvent
* event
)
1177 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1184 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1185 if (ev
.xshape
.kind
== ShapeBounding
) {
1186 if (ev
.xshape
.shaped
== shev
->shaped
) {
1189 XPutBackEvent(dpy
, &ev
.xevent
);
1195 wwin
= wWindowFor(shev
->window
);
1196 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1199 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1201 wwin
->flags
.shaped
= 0;
1202 wWindowClearShape(wwin
);
1204 } else if (shev
->shaped
) {
1206 wwin
->flags
.shaped
= 1;
1207 wWindowSetShape(wwin
);
1212 #ifdef KEEP_XKB_LOCK_STATUS
1213 /* please help ]d if you know what to do */
1214 static void handleXkbIndicatorStateNotify(XEvent
*event
)
1218 XkbStateRec staterec
;
1221 for (i
= 0; i
< wScreenCount
; i
++) {
1222 scr
= wScreenWithNumber(i
);
1223 wwin
= scr
->focused_window
;
1224 if (wwin
&& wwin
->flags
.focused
) {
1225 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1226 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1227 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1228 wwin
->frame
->languagemode
= staterec
.group
;
1230 #ifdef XKB_BUTTON_HINT
1231 if (wwin
->frame
->titlebar
) {
1232 wFrameWindowPaint(wwin
->frame
);
1238 #endif /*KEEP_XKB_LOCK_STATUS */
1240 static void handleColormapNotify(XEvent
* event
)
1244 Bool reinstall
= False
;
1246 wwin
= wWindowFor(event
->xcolormap
.window
);
1250 scr
= wwin
->screen_ptr
;
1254 if (event
->xcolormap
.new) {
1255 XWindowAttributes attr
;
1257 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1259 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1260 scr
->current_colormap
= attr
.colormap
;
1263 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1264 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1266 /* some bastard app (like XV) removed our colormap */
1268 * can't enforce or things like xscreensaver wont work
1271 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1272 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1274 /* someone has put our colormap back */
1278 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1279 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1281 if (reinstall
&& scr
->current_colormap
!= None
) {
1282 if (!scr
->flags
.colormap_stuff_blocked
)
1283 XInstallColormap(dpy
, scr
->current_colormap
);
1287 static void handleFocusIn(XEvent
* event
)
1292 * For applications that like stealing the focus.
1294 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1295 saveTimestamp(event
);
1296 if (event
->xfocus
.mode
== NotifyUngrab
1297 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1301 wwin
= wWindowFor(event
->xfocus
.window
);
1302 if (wwin
&& !wwin
->flags
.focused
) {
1303 if (wwin
->flags
.mapped
)
1304 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1306 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1308 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1310 wSetFocusTo(scr
, NULL
);
1314 static WWindow
*windowUnderPointer(WScreen
* scr
)
1320 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1321 return wWindowFor(win
);
1325 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1327 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1333 static void handleKeyPress(XEvent
* event
)
1335 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1336 WWindow
*wwin
= scr
->focused_window
;
1340 #ifdef KEEP_XKB_LOCK_STATUS
1341 XkbStateRec staterec
;
1342 #endif /*KEEP_XKB_LOCK_STATUS */
1344 /* ignore CapsLock */
1345 modifiers
= event
->xkey
.state
& ValidModMask
;
1347 for (i
= 0; i
< WKBD_LAST
; i
++) {
1348 if (wKeyBindings
[i
].keycode
== 0)
1351 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1352 || */ wKeyBindings
[i
].modifier
==
1361 if (!wRootMenuPerformShortcut(event
)) {
1362 static int dontLoop
= 0;
1364 if (dontLoop
> 10) {
1365 wwarning("problem with key event processing code");
1369 /* if the focused window is an internal window, try redispatching
1370 * the event to the managed window, as it can be a WINGs window */
1371 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1372 /* client_leader contains the WINGs toplevel */
1373 event
->xany
.window
= wwin
->client_leader
;
1374 WMHandleEvent(event
);
1380 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1381 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1386 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1387 if (!CheckFullScreenWindowFocused(scr
)) {
1388 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1389 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1393 case WKBD_WINDOWLIST
:
1394 if (!CheckFullScreenWindowFocused(scr
)) {
1395 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1396 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1401 case WKBD_WINDOWMENU
:
1402 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1403 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1405 case WKBD_MINIMIZEALL
:
1406 CloseWindowMenu(scr
);
1409 case WKBD_MINIATURIZE
:
1410 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1411 && !WFLAGP(wwin
, no_miniaturizable
)) {
1412 CloseWindowMenu(scr
);
1414 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1415 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, event
->xbutton
.time
);
1417 wIconifyWindow(wwin
);
1422 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1423 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1424 CloseWindowMenu(scr
);
1426 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1427 wHideApplication(wapp
);
1431 case WKBD_HIDE_OTHERS
:
1432 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1433 CloseWindowMenu(scr
);
1435 wHideOtherApplications(wwin
);
1439 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1440 CloseWindowMenu(scr
);
1442 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1445 case WKBD_VMAXIMIZE
:
1446 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1447 CloseWindowMenu(scr
);
1449 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1452 case WKBD_HMAXIMIZE
:
1453 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1454 CloseWindowMenu(scr
);
1456 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1459 case WKBD_LHMAXIMIZE
:
1460 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1461 CloseWindowMenu(scr
);
1463 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1466 case WKBD_RHMAXIMIZE
:
1467 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1468 CloseWindowMenu(scr
);
1470 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1474 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1475 CloseWindowMenu(scr
);
1477 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1481 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1482 CloseWindowMenu(scr
);
1484 wRaiseFrame(wwin
->frame
->core
);
1488 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1489 CloseWindowMenu(scr
);
1491 wLowerFrame(wwin
->frame
->core
);
1494 case WKBD_RAISELOWER
:
1495 /* raise or lower the window under the pointer, not the
1498 wwin
= windowUnderPointer(scr
);
1500 wRaiseLowerFrame(wwin
->frame
->core
);
1503 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1504 if (wwin
->flags
.shaded
)
1505 wUnshadeWindow(wwin
);
1510 case WKBD_MOVERESIZE
:
1511 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1512 CloseWindowMenu(scr
);
1514 wKeyboardMoveResizeWindow(wwin
);
1518 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1519 CloseWindowMenu(scr
);
1520 if (wwin
->protocols
.DELETE_WINDOW
)
1521 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, event
->xkey
.time
);
1525 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1526 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1529 case WKBD_FOCUSNEXT
:
1530 StartWindozeCycle(wwin
, event
, True
, False
);
1533 case WKBD_FOCUSPREV
:
1534 StartWindozeCycle(wwin
, event
, False
, False
);
1537 case WKBD_GROUPNEXT
:
1538 StartWindozeCycle(wwin
, event
, True
, True
);
1541 case WKBD_GROUPPREV
:
1542 StartWindozeCycle(wwin
, event
, False
, True
);
1545 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1546 widx
= command
- WKBD_WORKSPACE1
;
1547 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1548 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1549 wWorkspaceChange(scr
, i
);
1552 case WKBD_NEXTWORKSPACE
:
1553 wWorkspaceRelativeChange(scr
, 1);
1555 case WKBD_PREVWORKSPACE
:
1556 wWorkspaceRelativeChange(scr
, -1);
1558 case WKBD_LASTWORKSPACE
:
1559 wWorkspaceChange(scr
, scr
->last_workspace
);
1562 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1563 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1564 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1565 if (wwin
&& (wPreferences
.ws_advance
|| i
< scr
->workspace_count
))
1566 wWindowChangeWorkspace(wwin
, i
);
1569 case WKBD_MOVE_NEXTWORKSPACE
:
1571 wWindowChangeWorkspaceRelative(wwin
, 1);
1573 case WKBD_MOVE_PREVWORKSPACE
:
1575 wWindowChangeWorkspaceRelative(wwin
, -1);
1577 case WKBD_MOVE_LASTWORKSPACE
:
1579 wWindowChangeWorkspace(wwin
, scr
->last_workspace
);
1582 case WKBD_MOVE_NEXTWSLAYER
:
1583 case WKBD_MOVE_PREVWSLAYER
:
1588 row
= scr
->current_workspace
/ 10;
1589 column
= scr
->current_workspace
% 10;
1591 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1592 if ((row
+ 1) * 10 < scr
->workspace_count
)
1593 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1596 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1613 widx
= command
- WKBD_WINDOW1
;
1615 if (scr
->shortcutWindows
[widx
]) {
1616 WMArray
*list
= scr
->shortcutWindows
[widx
];
1618 int count
= WMGetArrayItemCount(list
);
1620 WMArrayIterator iter
;
1623 wUnselectWindows(scr
);
1624 cw
= scr
->current_workspace
;
1626 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1628 wWindowChangeWorkspace(wwin
, cw
);
1630 wMakeWindowVisible(wwin
);
1633 wSelectWindow(wwin
, True
);
1636 /* rotate the order of windows, to create a cycling effect */
1637 twin
= WMGetFromArray(list
, 0);
1638 WMDeleteFromArray(list
, 0);
1639 WMAddToArray(list
, twin
);
1641 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1642 if (scr
->shortcutWindows
[widx
]) {
1643 WMFreeArray(scr
->shortcutWindows
[widx
]);
1644 scr
->shortcutWindows
[widx
] = NULL
;
1647 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1648 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1649 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1650 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1652 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1653 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1656 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1659 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1662 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1664 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1665 if (scr
->shortcutWindows
[widx
]) {
1666 WMFreeArray(scr
->shortcutWindows
[widx
]);
1668 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1675 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1676 (void) RelaunchWindow(wwin
);
1680 case WKBD_SWITCH_SCREEN
:
1681 if (wScreenCount
> 1) {
1685 /* find index of this screen */
1686 for (i
= 0; i
< wScreenCount
; i
++) {
1687 if (wScreenWithNumber(i
) == scr
)
1691 if (i
>= wScreenCount
) {
1694 scr2
= wScreenWithNumber(i
);
1697 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1698 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1703 case WKBD_NEXTWSLAYER
:
1704 case WKBD_PREVWSLAYER
:
1708 row
= scr
->current_workspace
/ 10;
1709 column
= scr
->current_workspace
% 10;
1711 if (command
== WKBD_NEXTWSLAYER
) {
1712 if ((row
+ 1) * 10 < scr
->workspace_count
)
1713 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1716 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1720 case WKBD_CLIPRAISELOWER
:
1721 if (!wPreferences
.flags
.noclip
)
1722 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1724 case WKBD_DOCKRAISELOWER
:
1725 if (!wPreferences
.flags
.nodock
)
1726 wDockRaiseLower(scr
->dock
);
1728 #ifdef KEEP_XKB_LOCK_STATUS
1730 if (wPreferences
.modelock
) {
1732 wwin
= scr
->focused_window
;
1734 if (wwin
&& wwin
->flags
.mapped
1735 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1736 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1737 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1739 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1740 wwin
->frame
->last_languagemode
= staterec
.group
;
1741 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1746 #endif /* KEEP_XKB_LOCK_STATUS */
1750 static void handleMotionNotify(XEvent
* event
)
1752 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1754 if (wPreferences
.scrollable_menus
) {
1755 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1756 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1758 if (scr
->flags
.jump_back_pending
||
1759 p
.x
<= (rect
.pos
.x
+ 1) ||
1760 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1761 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1764 menu
= wMenuUnderPointer(scr
);
1766 wMenuScroll(menu
, event
);
1771 static void handleVisibilityNotify(XEvent
* event
)
1775 wwin
= wWindowFor(event
->xvisibility
.window
);
1778 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);