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"
59 #include "application.h"
62 #include "workspace.h"
65 #include "properties.h"
70 /******** Global Variables **********/
71 extern XContext wWinContext
;
72 extern XContext wVEdgeContext
;
74 extern Cursor wCursor
[WCUR_LAST
];
76 extern WShortKey wKeyBindings
[WKBD_LAST
];
77 extern int wScreenCount
;
78 extern Time LastTimestamp
;
79 extern Time LastFocusChange
;
81 extern WPreferences wPreferences
;
83 #define MOD_MASK wPreferences.modifier_mask
85 extern Atom _XA_WM_COLORMAP_NOTIFY
;
87 extern Atom _XA_WM_CHANGE_STATE
;
88 extern Atom _XA_WM_DELETE_WINDOW
;
89 extern Atom _XA_GNUSTEP_WM_ATTR
;
90 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
91 extern Atom _XA_GNUSTEP_TITLEBAR_STATE
;
92 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
93 extern Atom _XA_WINDOWMAKER_COMMAND
;
94 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS
;
97 extern Bool wShapeSupported
;
98 extern int wShapeEventBase
;
101 #ifdef KEEP_XKB_LOCK_STATUS
102 extern int wXkbEventBase
;
106 extern Bool has_randr
;
107 extern int randr_event_base
;
111 /*extern char WDelayedActionSet;*/
113 /************ Local stuff ***********/
115 static void saveTimestamp(XEvent
*event
);
116 static void handleColormapNotify(XEvent
*event
);
117 static void handleMapNotify(XEvent
*event
);
118 static void handleUnmapNotify(XEvent
*event
);
119 static void handleButtonPress(XEvent
*event
);
120 static void handleExpose(XEvent
*event
);
121 static void handleDestroyNotify(XEvent
*event
);
122 static void handleConfigureRequest(XEvent
*event
);
123 static void handleMapRequest(XEvent
*event
);
124 static void handlePropertyNotify(XEvent
*event
);
125 static void handleEnterNotify(XEvent
*event
);
126 static void handleLeaveNotify(XEvent
*event
);
127 static void handleExtensions(XEvent
*event
);
128 static void handleClientMessage(XEvent
*event
);
129 static void handleKeyPress(XEvent
*event
);
130 static void handleFocusIn(XEvent
*event
);
131 static void handleMotionNotify(XEvent
*event
);
132 static void handleVisibilityNotify(XEvent
*event
);
135 static void handleShapeNotify(XEvent
*event
);
138 #ifdef KEEP_XKB_LOCK_STATUS
139 static void handleXkbIndicatorStateNotify(XEvent
*event
);
142 /* called from the signal handler */
143 void NotifyDeadProcess(pid_t pid
, unsigned char status
);
145 /* real dead process handler */
146 static void handleDeadProcess(void *foo
);
148 typedef struct DeadProcesses
{
150 unsigned char exit_status
;
153 /* stack of dead processes */
154 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
155 static int deadProcessPtr
= 0;
157 typedef struct DeathHandler
{
158 WDeathHandler
*callback
;
163 static WMArray
*deathHandlers
= NULL
;
165 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
167 DeathHandler
*handler
;
169 handler
= malloc(sizeof(DeathHandler
));
174 handler
->callback
= callback
;
175 handler
->client_data
= cdata
;
178 deathHandlers
= WMCreateArrayWithDestructor(8, wfree
);
180 WMAddToArray(deathHandlers
, handler
);
185 void wDeleteDeathHandler(WMagicNumber id
)
187 DeathHandler
*handler
= (DeathHandler
*) id
;
189 if (!handler
|| !deathHandlers
)
192 /* array destructor will call wfree(handler) */
193 WMRemoveFromArray(deathHandlers
, handler
);
196 void DispatchEvent(XEvent
* event
)
199 handleDeadProcess(NULL
);
201 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
202 WCHANGE_STATE(WSTATE_EXITING
);
203 /* received SIGTERM */
205 * WMHandleEvent() can't be called from anything
206 * executed inside here, or we can get in a infinite
209 Shutdown(WSExitMode
);
211 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
212 WCHANGE_STATE(WSTATE_RESTARTING
);
214 Shutdown(WSRestartPreparationMode
);
215 /* received SIGHUP */
217 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
218 WCHANGE_STATE(WSTATE_NORMAL
);
219 wDefaultsCheckDomains(NULL
);
222 /* for the case that all that is wanted to be dispatched is
227 saveTimestamp(event
);
228 switch (event
->type
) {
230 handleMapRequest(event
);
234 handleKeyPress(event
);
238 handleMotionNotify(event
);
241 case ConfigureRequest
:
242 handleConfigureRequest(event
);
246 handleDestroyNotify(event
);
250 handleMapNotify(event
);
254 handleUnmapNotify(event
);
258 handleButtonPress(event
);
266 handlePropertyNotify(event
);
270 handleEnterNotify(event
);
274 handleLeaveNotify(event
);
278 handleClientMessage(event
);
282 handleColormapNotify(event
);
286 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
287 XRefreshKeyboardMapping(&event
->xmapping
);
291 handleFocusIn(event
);
294 case VisibilityNotify
:
295 handleVisibilityNotify(event
);
298 case ConfigureNotify
:
299 if (event
->xconfigure
.window
== DefaultRootWindow(dpy
)) {
301 XRRUpdateConfiguration(event
);
307 handleExtensions(event
);
314 *----------------------------------------------------------------------
315 * inotifyHandleEvents-
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 void inotifyHandleEvents(int fd
, int wd
)
330 extern void wDefaultsCheckDomains(void *);
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 fprintf(stdout
, "wmaker: reading config files in defaults database.\n");
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 *----------------------------------------------------------------------
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 inotifyHandleEvents(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 wDeleteDeathHandler(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
= wScreenSearchForRootWindow(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 memset(command
, 0, len
);
967 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
969 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
970 wwarning(_("Got Reconfigure command"));
971 wDefaultsCheckDomains(NULL
);
973 wwarning(_("Got unknown command %s"), command
);
978 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
981 wapp
= wApplicationOf(event
->xclient
.window
);
983 switch (event
->xclient
.data
.l
[0]) {
984 case WMFHideOtherApplications
:
985 wHideOtherApplications(wapp
->main_window_desc
);
989 case WMFHideApplication
:
990 wHideApplication(wapp
);
996 wwin
= wWindowFor(event
->xclient
.window
);
998 switch (event
->xclient
.data
.l
[0]) {
999 case WMFHideOtherApplications
:
1000 wHideOtherApplications(wwin
);
1003 case WMFHideApplication
:
1004 wHideApplication(wApplicationOf(wwin
->main_window
));
1009 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_WM_ATTR
) {
1010 wwin
= wWindowFor(event
->xclient
.window
);
1013 switch (event
->xclient
.data
.l
[0]) {
1014 case GSWindowLevelAttr
:
1016 int level
= (int)event
->xclient
.data
.l
[1];
1018 if (WINDOW_LEVEL(wwin
) != level
) {
1019 ChangeStackingLevel(wwin
->frame
->core
, level
);
1024 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_TITLEBAR_STATE
) {
1025 wwin
= wWindowFor(event
->xclient
.window
);
1028 switch (event
->xclient
.data
.l
[0]) {
1029 case WMTitleBarNormal
:
1030 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1032 case WMTitleBarMain
:
1033 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1036 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1039 } else if (event
->xclient
.message_type
== _XA_WM_IGNORE_FOCUS_EVENTS
) {
1040 WScreen
*scr
= wScreenSearchForRootWindow(event
->xclient
.window
);
1043 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1044 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1047 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1052 * Non-standard thing, but needed by OffiX DND.
1053 * For when the icon frame gets a ClientMessage
1054 * that should have gone to the icon_window.
1056 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1057 struct WIcon
*icon
= NULL
;
1059 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1060 icon
= (WIcon
*) desc
->parent
;
1061 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1062 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1064 if (icon
&& (wwin
= icon
->owner
)) {
1065 if (wwin
->client_win
!= event
->xclient
.window
) {
1066 event
->xclient
.window
= wwin
->client_win
;
1067 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1074 static void raiseWindow(WScreen
* scr
)
1078 scr
->autoRaiseTimer
= NULL
;
1080 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1084 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1085 wRaiseFrame(wwin
->frame
->core
);
1086 /* this is needed or a race condition will occur */
1091 static void handleEnterNotify(XEvent
* event
)
1094 WObjDescriptor
*desc
= NULL
;
1096 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1098 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1099 /* already left the window... */
1101 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1106 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1107 if (desc
->handle_enternotify
)
1108 (*desc
->handle_enternotify
) (desc
, event
);
1111 /* enter to window */
1112 wwin
= wWindowFor(event
->xcrossing
.window
);
1114 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1115 wColormapInstallForWindow(scr
, NULL
);
1117 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1118 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1119 scr
->autoRaiseTimer
= NULL
;
1122 /* set auto raise timer even if in focus-follows-mouse mode
1123 * and the event is for the frame window, even if the window
1124 * has focus already. useful if you move the pointer from a focused
1125 * window to the root window and back pretty fast
1127 * set focus if in focus-follows-mouse mode and the event
1128 * is for the frame window and window doesn't have focus yet */
1129 if (wPreferences
.focus_mode
== WKF_SLOPPY
1130 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1132 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1133 wSetFocusTo(scr
, wwin
);
1135 if (scr
->autoRaiseTimer
)
1136 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1137 scr
->autoRaiseTimer
= NULL
;
1139 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1140 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1142 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1145 /* Install colormap for window, if the colormap installation mode
1146 * is colormap_follows_mouse */
1147 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1148 if (wwin
->client_win
== event
->xcrossing
.window
)
1149 wColormapInstallForWindow(scr
, wwin
);
1151 wColormapInstallForWindow(scr
, NULL
);
1155 /* a little kluge to hide the clip balloon */
1156 if (!wPreferences
.flags
.noclip
&& scr
->flags
.clip_balloon_mapped
) {
1158 XUnmapWindow(dpy
, scr
->clip_balloon
);
1159 scr
->flags
.clip_balloon_mapped
= 0;
1161 if (desc
->parent_type
!= WCLASS_DOCK_ICON
|| scr
->clip_icon
!= desc
->parent
) {
1162 XUnmapWindow(dpy
, scr
->clip_balloon
);
1163 scr
->flags
.clip_balloon_mapped
= 0;
1168 if (event
->xcrossing
.window
== event
->xcrossing
.root
1169 && event
->xcrossing
.detail
== NotifyNormal
1170 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1172 wSetFocusTo(scr
, scr
->focused_window
);
1175 wBalloonEnteredObject(scr
, desc
);
1179 static void handleLeaveNotify(XEvent
* event
)
1181 WObjDescriptor
*desc
= NULL
;
1183 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
, (XPointer
*) & desc
) != XCNOENT
) {
1184 if (desc
->handle_leavenotify
)
1185 (*desc
->handle_leavenotify
) (desc
, event
);
1190 static void handleShapeNotify(XEvent
* event
)
1192 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1199 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1200 if (ev
.xshape
.kind
== ShapeBounding
) {
1201 if (ev
.xshape
.shaped
== shev
->shaped
) {
1204 XPutBackEvent(dpy
, &ev
.xevent
);
1210 wwin
= wWindowFor(shev
->window
);
1211 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1214 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1216 wwin
->flags
.shaped
= 0;
1217 wWindowClearShape(wwin
);
1219 } else if (shev
->shaped
) {
1221 wwin
->flags
.shaped
= 1;
1222 wWindowSetShape(wwin
);
1227 #ifdef KEEP_XKB_LOCK_STATUS
1228 /* please help ]d if you know what to do */
1229 static void handleXkbIndicatorStateNotify(XEvent
*event
)
1233 XkbStateRec staterec
;
1236 for (i
= 0; i
< wScreenCount
; i
++) {
1237 scr
= wScreenWithNumber(i
);
1238 wwin
= scr
->focused_window
;
1239 if (wwin
&& wwin
->flags
.focused
) {
1240 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1241 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1242 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1243 wwin
->frame
->languagemode
= staterec
.group
;
1245 #ifdef XKB_BUTTON_HINT
1246 if (wwin
->frame
->titlebar
) {
1247 wFrameWindowPaint(wwin
->frame
);
1253 #endif /*KEEP_XKB_LOCK_STATUS */
1255 static void handleColormapNotify(XEvent
* event
)
1259 Bool reinstall
= False
;
1261 wwin
= wWindowFor(event
->xcolormap
.window
);
1265 scr
= wwin
->screen_ptr
;
1269 if (event
->xcolormap
.new) {
1270 XWindowAttributes attr
;
1272 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1274 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1275 scr
->current_colormap
= attr
.colormap
;
1278 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1279 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1281 /* some bastard app (like XV) removed our colormap */
1283 * can't enforce or things like xscreensaver wont work
1286 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1287 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1289 /* someone has put our colormap back */
1293 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1294 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1296 if (reinstall
&& scr
->current_colormap
!= None
) {
1297 if (!scr
->flags
.colormap_stuff_blocked
)
1298 XInstallColormap(dpy
, scr
->current_colormap
);
1302 static void handleFocusIn(XEvent
* event
)
1307 * For applications that like stealing the focus.
1309 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1310 saveTimestamp(event
);
1311 if (event
->xfocus
.mode
== NotifyUngrab
1312 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1316 wwin
= wWindowFor(event
->xfocus
.window
);
1317 if (wwin
&& !wwin
->flags
.focused
) {
1318 if (wwin
->flags
.mapped
)
1319 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1321 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1323 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1325 wSetFocusTo(scr
, NULL
);
1329 static WWindow
*windowUnderPointer(WScreen
* scr
)
1335 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1336 return wWindowFor(win
);
1340 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1342 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1348 static void handleKeyPress(XEvent
* event
)
1350 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1351 WWindow
*wwin
= scr
->focused_window
;
1355 #ifdef KEEP_XKB_LOCK_STATUS
1356 XkbStateRec staterec
;
1357 #endif /*KEEP_XKB_LOCK_STATUS */
1359 /* ignore CapsLock */
1360 modifiers
= event
->xkey
.state
& ValidModMask
;
1362 for (i
= 0; i
< WKBD_LAST
; i
++) {
1363 if (wKeyBindings
[i
].keycode
== 0)
1366 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1367 || */ wKeyBindings
[i
].modifier
==
1376 if (!wRootMenuPerformShortcut(event
)) {
1377 static int dontLoop
= 0;
1379 if (dontLoop
> 10) {
1380 wwarning("problem with key event processing code");
1384 /* if the focused window is an internal window, try redispatching
1385 * the event to the managed window, as it can be a WINGs window */
1386 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1387 /* client_leader contains the WINGs toplevel */
1388 event
->xany
.window
= wwin
->client_leader
;
1389 WMHandleEvent(event
);
1395 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1396 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1401 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1402 if (!CheckFullScreenWindowFocused(scr
)) {
1403 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1404 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1408 case WKBD_WINDOWLIST
:
1409 if (!CheckFullScreenWindowFocused(scr
)) {
1410 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1411 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1416 case WKBD_WINDOWMENU
:
1417 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1418 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1420 case WKBD_MINIMIZEALL
:
1421 CloseWindowMenu(scr
);
1424 case WKBD_MINIATURIZE
:
1425 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1426 && !WFLAGP(wwin
, no_miniaturizable
)) {
1427 CloseWindowMenu(scr
);
1429 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1430 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, event
->xbutton
.time
);
1432 wIconifyWindow(wwin
);
1437 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1438 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1439 CloseWindowMenu(scr
);
1441 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1442 wHideApplication(wapp
);
1446 case WKBD_HIDE_OTHERS
:
1447 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1448 CloseWindowMenu(scr
);
1450 wHideOtherApplications(wwin
);
1454 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1455 CloseWindowMenu(scr
);
1457 if (wwin
->flags
.maximized
== (MAX_VERTICAL
| MAX_HORIZONTAL
))
1458 wUnmaximizeWindow(wwin
);
1460 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1463 case WKBD_VMAXIMIZE
:
1464 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1465 CloseWindowMenu(scr
);
1467 if (wwin
->flags
.maximized
== MAX_VERTICAL
)
1468 wUnmaximizeWindow(wwin
);
1470 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1473 case WKBD_HMAXIMIZE
:
1474 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1475 CloseWindowMenu(scr
);
1477 if (wwin
->flags
.maximized
== MAX_HORIZONTAL
)
1478 wUnmaximizeWindow(wwin
);
1480 wMaximizeWindow(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1483 case WKBD_LHMAXIMIZE
:
1484 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1485 CloseWindowMenu(scr
);
1487 if (wwin
->flags
.maximized
== (MAX_VERTICAL
| MAX_LEFTHALF
))
1488 wUnmaximizeWindow(wwin
);
1490 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1493 case WKBD_RHMAXIMIZE
:
1494 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1495 CloseWindowMenu(scr
);
1497 if (wwin
->flags
.maximized
== (MAX_VERTICAL
| MAX_RIGHTHALF
))
1498 wUnmaximizeWindow(wwin
);
1500 wMaximizeWindow(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1504 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1505 CloseWindowMenu(scr
);
1507 if (wwin
->flags
.maximized
== MAX_MAXIMUS
)
1508 wUnmaximizeWindow(wwin
);
1510 wMaximizeWindow(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1514 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1515 CloseWindowMenu(scr
);
1517 wRaiseFrame(wwin
->frame
->core
);
1521 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1522 CloseWindowMenu(scr
);
1524 wLowerFrame(wwin
->frame
->core
);
1527 case WKBD_RAISELOWER
:
1528 /* raise or lower the window under the pointer, not the
1531 wwin
= windowUnderPointer(scr
);
1533 wRaiseLowerFrame(wwin
->frame
->core
);
1536 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1537 if (wwin
->flags
.shaded
)
1538 wUnshadeWindow(wwin
);
1543 case WKBD_MOVERESIZE
:
1544 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1545 CloseWindowMenu(scr
);
1547 wKeyboardMoveResizeWindow(wwin
);
1551 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1552 CloseWindowMenu(scr
);
1553 if (wwin
->protocols
.DELETE_WINDOW
)
1554 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, event
->xkey
.time
);
1558 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1559 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1562 case WKBD_FOCUSNEXT
:
1563 StartWindozeCycle(wwin
, event
, True
, False
);
1566 case WKBD_FOCUSPREV
:
1567 StartWindozeCycle(wwin
, event
, False
, False
);
1570 case WKBD_GROUPNEXT
:
1571 StartWindozeCycle(wwin
, event
, True
, True
);
1574 case WKBD_GROUPPREV
:
1575 StartWindozeCycle(wwin
, event
, False
, True
);
1578 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1579 widx
= command
- WKBD_WORKSPACE1
;
1580 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1581 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1582 wWorkspaceChange(scr
, i
);
1585 case WKBD_NEXTWORKSPACE
:
1586 wWorkspaceRelativeChange(scr
, 1);
1588 case WKBD_PREVWORKSPACE
:
1589 wWorkspaceRelativeChange(scr
, -1);
1603 widx
= command
- WKBD_WINDOW1
;
1605 if (scr
->shortcutWindows
[widx
]) {
1606 WMArray
*list
= scr
->shortcutWindows
[widx
];
1608 int count
= WMGetArrayItemCount(list
);
1610 WMArrayIterator iter
;
1613 wUnselectWindows(scr
);
1614 cw
= scr
->current_workspace
;
1616 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1618 wWindowChangeWorkspace(wwin
, cw
);
1620 wMakeWindowVisible(wwin
);
1623 wSelectWindow(wwin
, True
);
1626 /* rotate the order of windows, to create a cycling effect */
1627 twin
= WMGetFromArray(list
, 0);
1628 WMDeleteFromArray(list
, 0);
1629 WMAddToArray(list
, twin
);
1631 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1632 if (scr
->shortcutWindows
[widx
]) {
1633 WMFreeArray(scr
->shortcutWindows
[widx
]);
1634 scr
->shortcutWindows
[widx
] = NULL
;
1637 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1638 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1639 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1640 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1642 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1643 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1646 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1649 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1652 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1654 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1655 if (scr
->shortcutWindows
[widx
]) {
1656 WMFreeArray(scr
->shortcutWindows
[widx
]);
1658 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1664 case WKBD_SWITCH_SCREEN
:
1665 if (wScreenCount
> 1) {
1669 /* find index of this screen */
1670 for (i
= 0; i
< wScreenCount
; i
++) {
1671 if (wScreenWithNumber(i
) == scr
)
1675 if (i
>= wScreenCount
) {
1678 scr2
= wScreenWithNumber(i
);
1681 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1682 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1687 case WKBD_NEXTWSLAYER
:
1688 case WKBD_PREVWSLAYER
:
1692 row
= scr
->current_workspace
/ 10;
1693 column
= scr
->current_workspace
% 10;
1695 if (command
== WKBD_NEXTWSLAYER
) {
1696 if ((row
+ 1) * 10 < scr
->workspace_count
)
1697 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1700 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1704 case WKBD_CLIPRAISELOWER
:
1705 if (!wPreferences
.flags
.noclip
)
1706 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1708 case WKBD_DOCKRAISELOWER
:
1709 if (!wPreferences
.flags
.nodock
)
1710 wDockRaiseLower(scr
->dock
);
1712 #ifdef KEEP_XKB_LOCK_STATUS
1714 if (wPreferences
.modelock
) {
1716 wwin
= scr
->focused_window
;
1718 if (wwin
&& wwin
->flags
.mapped
1719 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1720 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1721 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1723 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1724 wwin
->frame
->last_languagemode
= staterec
.group
;
1725 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1730 #endif /* KEEP_XKB_LOCK_STATUS */
1734 static void handleMotionNotify(XEvent
* event
)
1736 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1738 if (wPreferences
.scrollable_menus
) {
1739 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1740 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1742 if (scr
->flags
.jump_back_pending
||
1743 p
.x
<= (rect
.pos
.x
+ 1) ||
1744 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1745 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1748 menu
= wMenuUnderPointer(scr
);
1750 wMenuScroll(menu
, event
);
1755 static void handleVisibilityNotify(XEvent
* event
)
1759 wwin
= wWindowFor(event
->xvisibility
.window
);
1762 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);