1 /* event.c- event loop and handling
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 2014 Window Maker Team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <sys/select.h>
27 #include <sys/inotify.h>
39 #include <X11/Xutil.h>
41 # include <X11/extensions/shape.h>
48 #include <X11/extensions/Xrandr.h>
51 #ifdef KEEP_XKB_LOCK_STATUS
52 #include <X11/XKBlib.h>
53 #endif /* KEEP_XKB_LOCK_STATUS */
55 #include "WindowMaker.h"
62 #include "application.h"
65 #include "workspace.h"
68 #include "properties.h"
79 #include "switchmenu.h"
83 #define MOD_MASK wPreferences.modifier_mask
85 /************ Local stuff ***********/
87 static void saveTimestamp(XEvent
*event
);
88 static void handleColormapNotify(XEvent
*event
);
89 static void handleMapNotify(XEvent
*event
);
90 static void handleUnmapNotify(XEvent
*event
);
91 static void handleButtonPress(XEvent
*event
);
92 static void handleExpose(XEvent
*event
);
93 static void handleDestroyNotify(XEvent
*event
);
94 static void handleConfigureRequest(XEvent
*event
);
95 static void handleMapRequest(XEvent
*event
);
96 static void handlePropertyNotify(XEvent
*event
);
97 static void handleEnterNotify(XEvent
*event
);
98 static void handleLeaveNotify(XEvent
*event
);
99 static void handleExtensions(XEvent
*event
);
100 static void handleClientMessage(XEvent
*event
);
101 static void handleKeyPress(XEvent
*event
);
102 static void handleFocusIn(XEvent
*event
);
103 static void handleMotionNotify(XEvent
*event
);
104 static void handleVisibilityNotify(XEvent
*event
);
105 static void handle_inotify_events(void);
106 static void wdelete_death_handler(WMagicNumber id
);
110 static void handleShapeNotify(XEvent
*event
);
113 #ifdef KEEP_XKB_LOCK_STATUS
114 static void handleXkbIndicatorStateNotify(XkbEvent
*event
);
117 /* real dead process handler */
118 static void handleDeadProcess(void);
120 typedef struct DeadProcesses
{
122 unsigned char exit_status
;
125 /* stack of dead processes */
126 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
127 static int deadProcessPtr
= 0;
129 typedef struct DeathHandler
{
130 WDeathHandler
*callback
;
135 static WMArray
*deathHandlers
= NULL
;
137 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
139 DeathHandler
*handler
;
141 handler
= malloc(sizeof(DeathHandler
));
146 handler
->callback
= callback
;
147 handler
->client_data
= cdata
;
150 deathHandlers
= WMCreateArrayWithDestructor(8, free
);
152 WMAddToArray(deathHandlers
, handler
);
157 static void wdelete_death_handler(WMagicNumber id
)
159 DeathHandler
*handler
= (DeathHandler
*) id
;
161 if (!handler
|| !deathHandlers
)
164 /* array destructor will call free(handler) */
165 WMRemoveFromArray(deathHandlers
, handler
);
168 void DispatchEvent(XEvent
* event
)
173 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
174 WCHANGE_STATE(WSTATE_EXITING
);
175 /* received SIGTERM */
177 * WMHandleEvent() can't be called from anything
178 * executed inside here, or we can get in a infinite
181 Shutdown(WSExitMode
);
183 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
184 WCHANGE_STATE(WSTATE_RESTARTING
);
186 Shutdown(WSRestartPreparationMode
);
187 /* received SIGHUP */
189 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
190 WCHANGE_STATE(WSTATE_NORMAL
);
191 wDefaultsCheckDomains(NULL
);
194 /* for the case that all that is wanted to be dispatched is
199 saveTimestamp(event
);
200 switch (event
->type
) {
202 handleMapRequest(event
);
206 handleKeyPress(event
);
210 handleMotionNotify(event
);
213 case ConfigureRequest
:
214 handleConfigureRequest(event
);
218 handleDestroyNotify(event
);
222 handleMapNotify(event
);
226 handleUnmapNotify(event
);
230 handleButtonPress(event
);
238 handlePropertyNotify(event
);
242 handleEnterNotify(event
);
246 handleLeaveNotify(event
);
250 handleClientMessage(event
);
254 handleColormapNotify(event
);
258 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
259 XRefreshKeyboardMapping(&event
->xmapping
);
263 handleFocusIn(event
);
266 case VisibilityNotify
:
267 handleVisibilityNotify(event
);
270 case ConfigureNotify
:
272 if (event
->xconfigure
.window
== DefaultRootWindow(dpy
))
273 XRRUpdateConfiguration(event
);
278 handleExtensions(event
);
285 *----------------------------------------------------------------------
286 * handle_inotify_events-
287 * Check for inotify events
290 * After reading events for the given file descriptor (fd) and
291 * watch descriptor (wd)
294 * Calls wDefaultsCheckDomains if config database is updated
295 *----------------------------------------------------------------------
297 static void handle_inotify_events(void)
299 ssize_t eventQLength
;
301 /* Make room for at lease 5 simultaneous events, with path + filenames */
302 char buff
[ (sizeof(struct inotify_event
) + NAME_MAX
+ 1) * 5 ];
303 /* Check config only once per read of the event queue */
307 * Read off the queued events
308 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
309 * not occur; the block is on Xevents, but a config file change will normally
310 * occur as a result of an Xevent - so the event queue should never have more than
311 * a few entries before a read().
313 eventQLength
= read(w_global
.inotify
.fd_event_queue
,
314 buff
, sizeof(buff
) );
316 if (eventQLength
< 0) {
317 wwarning(_("read problem when trying to get INotify event: %s"), strerror(errno
));
321 /* check what events occured */
322 /* Should really check wd here too, but for now we only have one watch! */
323 while (i
< eventQLength
) {
324 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
327 * see inotify.h for event types.
329 if (pevent
->mask
& IN_DELETE_SELF
) {
330 wwarning(_("the defaults database has been deleted!"
331 " Restart Window Maker to create the database" " with the default settings"));
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 if (pevent
->mask
& IN_UNMOUNT
) {
339 wwarning(_("the unit containing the defaults database has"
340 " been unmounted. Setting --static mode." " Any changes will not be saved."));
342 if (w_global
.inotify
.fd_event_queue
>= 0) {
343 close(w_global
.inotify
.fd_event_queue
);
344 w_global
.inotify
.fd_event_queue
= -1;
347 wPreferences
.flags
.noupdates
= 1;
349 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
350 wwarning(_("Inotify: Reading config files in defaults database."));
351 wDefaultsCheckDomains(NULL
);
355 /* move to next event in the buffer */
356 i
+= sizeof(struct inotify_event
) + pevent
->len
;
359 #endif /* HAVE_INOTIFY */
362 *----------------------------------------------------------------------
364 * Processes X and internal events indefinitely.
370 * The LastTimestamp global variable is updated.
371 * Calls inotifyGetEvents if defaults database changes.
372 *----------------------------------------------------------------------
374 noreturn
void EventLoop(void)
382 if (w_global
.inotify
.fd_event_queue
< 0 || w_global
.inotify
.wd_defaults
< 0)
388 WMNextEvent(dpy
, &event
); /* Blocks here */
389 WMHandleEvent(&event
);
395 FD_SET(w_global
.inotify
.fd_event_queue
, &rfds
);
397 /* check for available read data from inotify - don't block! */
398 retVal
= select(w_global
.inotify
.fd_event_queue
+ 1, &rfds
, NULL
, NULL
, &time
);
400 if (retVal
< 0) { /* an error has occured */
401 wwarning(_("select failed. The inotify instance will be closed."
402 " Changes to the defaults database will require"
403 " a restart to take effect."));
404 close(w_global
.inotify
.fd_event_queue
);
405 w_global
.inotify
.fd_event_queue
= -1;
408 if (FD_ISSET(w_global
.inotify
.fd_event_queue
, &rfds
))
409 handle_inotify_events();
416 *----------------------------------------------------------------------
417 * ProcessPendingEvents --
418 * Processes the events that are currently pending (at the time
419 * this function is called) in the display's queue.
422 * After the pending events that were present at the function call
426 * Many -- whatever handling events may involve.
428 *----------------------------------------------------------------------
430 void ProcessPendingEvents(void)
437 /* Take a snapshot of the event count in the queue */
438 count
= XPending(dpy
);
440 while (count
> 0 && XPending(dpy
)) {
441 WMNextEvent(dpy
, &event
);
442 WMHandleEvent(&event
);
447 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
449 if ((scr
->last_click_time
> 0) &&
450 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
451 && (event
->xbutton
.button
== scr
->last_click_button
)
452 && (event
->xbutton
.window
== scr
->last_click_window
)) {
454 scr
->flags
.next_click_is_not_double
= 1;
455 scr
->last_click_time
= 0;
456 scr
->last_click_window
= event
->xbutton
.window
;
463 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
465 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
466 wwarning("stack overflow: too many dead processes");
469 /* stack the process to be handled later,
470 * as this is called from the signal handler */
471 deadProcesses
[deadProcessPtr
].pid
= pid
;
472 deadProcesses
[deadProcessPtr
].exit_status
= status
;
476 static void handleDeadProcess(void)
481 for (i
= 0; i
< deadProcessPtr
; i
++) {
482 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
485 if (!deathHandlers
) {
490 /* get the pids on the queue and call handlers */
491 while (deadProcessPtr
> 0) {
494 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
495 tmp
= WMGetFromArray(deathHandlers
, i
);
499 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
500 (*tmp
->callback
) (tmp
->pid
,
501 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
502 wdelete_death_handler(tmp
);
508 static void saveTimestamp(XEvent
* event
)
511 * Never save CurrentTime as LastTimestamp because CurrentTime
512 * it's not a real timestamp (it's the 0L constant)
515 switch (event
->type
) {
518 w_global
.timestamp
.last_event
= event
->xbutton
.time
;
522 w_global
.timestamp
.last_event
= event
->xkey
.time
;
525 w_global
.timestamp
.last_event
= event
->xmotion
.time
;
528 w_global
.timestamp
.last_event
= event
->xproperty
.time
;
532 w_global
.timestamp
.last_event
= event
->xcrossing
.time
;
535 w_global
.timestamp
.last_event
= event
->xselectionclear
.time
;
537 case SelectionRequest
:
538 w_global
.timestamp
.last_event
= event
->xselectionrequest
.time
;
540 case SelectionNotify
:
541 w_global
.timestamp
.last_event
= event
->xselection
.time
;
543 wXDNDProcessSelection(event
);
549 static int matchWindow(const void *item
, const void *cdata
)
551 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
554 static void handleExtensions(XEvent
* event
)
557 if (w_global
.xext
.shape
.supported
&& event
->type
== (w_global
.xext
.shape
.event_base
+ ShapeNotify
)) {
558 handleShapeNotify(event
);
561 #ifdef KEEP_XKB_LOCK_STATUS
562 if (wPreferences
.modelock
&& (event
->type
== w_global
.xext
.xkb
.event_base
)) {
563 handleXkbIndicatorStateNotify((XkbEvent
*) event
);
565 #endif /*KEEP_XKB_LOCK_STATUS */
567 if (w_global
.xext
.randr
.supported
&& event
->type
== (w_global
.xext
.randr
.event_base
+ RRScreenChangeNotify
)) {
568 /* From xrandr man page: "Clients must call back into Xlib using
569 * XRRUpdateConfiguration when screen configuration change notify
570 * events are generated */
571 XRRUpdateConfiguration(event
);
572 WCHANGE_STATE(WSTATE_RESTARTING
);
573 Shutdown(WSRestartPreparationMode
);
579 static void handleMapRequest(XEvent
* ev
)
583 Window window
= ev
->xmaprequest
.window
;
585 if ((wwin
= wWindowFor(window
))) {
586 if (wwin
->flags
.shaded
) {
587 wUnshadeWindow(wwin
);
589 /* deiconify window */
590 if (wwin
->flags
.miniaturized
) {
591 wDeiconifyWindow(wwin
);
592 } else if (wwin
->flags
.hidden
) {
593 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
594 /* go to the last workspace that the user worked on the app */
596 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
598 wUnhideApplication(wapp
, False
, False
);
603 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
605 wwin
= wManageWindow(scr
, window
);
608 * This is to let the Dock know that the application it launched
609 * has already been mapped (eg: it has finished launching).
610 * It is not necessary for normally docked apps, but is needed for
611 * apps that were forcedly docked (like with dockit).
613 if (scr
->last_dock
) {
614 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
615 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
617 wDockTrackWindowLaunch(scr
->last_dock
, window
);
621 wClientSetState(wwin
, NormalState
, None
);
622 if (wwin
->flags
.maximized
) {
623 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
625 if (wwin
->flags
.shaded
) {
626 wwin
->flags
.shaded
= 0;
627 wwin
->flags
.skip_next_animation
= 1;
630 if (wwin
->flags
.miniaturized
) {
631 wwin
->flags
.miniaturized
= 0;
632 wwin
->flags
.skip_next_animation
= 1;
633 wIconifyWindow(wwin
);
635 if (wwin
->flags
.fullscreen
) {
636 wwin
->flags
.fullscreen
= 0;
637 wFullscreenWindow(wwin
);
639 if (wwin
->flags
.hidden
) {
640 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
642 wwin
->flags
.hidden
= 0;
643 wwin
->flags
.skip_next_animation
= 1;
645 wHideApplication(wapp
);
651 static void handleDestroyNotify(XEvent
* event
)
655 Window window
= event
->xdestroywindow
.window
;
656 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
659 wwin
= wWindowFor(window
);
661 wUnmanageWindow(wwin
, False
, True
);
665 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
666 WFakeGroupLeader
*fPtr
;
668 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
669 if (fPtr
->retainCount
> 0) {
671 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
672 XDestroyWindow(dpy
, fPtr
->leader
);
677 fPtr
->origLeader
= None
;
681 app
= wApplicationOf(window
);
683 if (window
== app
->main_window
) {
685 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
687 if (wwin
->main_window
== window
) {
688 wwin
->main_window
= None
;
693 wApplicationDestroy(app
);
697 static void handleExpose(XEvent
* event
)
699 WObjDescriptor
*desc
;
702 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
704 if (XFindContext(dpy
, event
->xexpose
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
708 if (desc
->handle_expose
) {
709 (*desc
->handle_expose
) (desc
, event
);
713 static void executeWheelAction(WScreen
*scr
, XEvent
*event
, int action
)
718 if (event
->xbutton
.button
== Button5
|| event
->xbutton
.button
== Button6
)
719 next_direction
= False
;
721 next_direction
= True
;
724 case WA_SWITCH_WORKSPACES
:
726 wWorkspaceRelativeChange(scr
, 1);
728 wWorkspaceRelativeChange(scr
, -1);
731 case WA_SWITCH_WINDOWS
:
732 wwin
= scr
->focused_window
;
734 wWindowFocusNext(wwin
, True
);
736 wWindowFocusPrev(wwin
, True
);
741 static void executeButtonAction(WScreen
*scr
, XEvent
*event
, int action
)
746 case WA_SELECT_WINDOWS
:
747 wUnselectWindows(scr
);
748 wSelectWindows(scr
, event
);
750 case WA_OPEN_APPMENU
:
751 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
753 if (scr
->root_menu
) {
754 if (scr
->root_menu
->brother
->flags
.mapped
)
755 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
757 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
760 case WA_OPEN_WINLISTMENU
:
761 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
762 if (scr
->switch_menu
) {
763 if (scr
->switch_menu
->brother
->flags
.mapped
)
764 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
766 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
769 case WA_MOVE_PREVWORKSPACE
:
770 wWorkspaceRelativeChange(scr
, -1);
772 case WA_MOVE_NEXTWORKSPACE
:
773 wWorkspaceRelativeChange(scr
, 1);
775 case WA_MOVE_PREVWINDOW
:
776 wwin
= scr
->focused_window
;
777 wWindowFocusPrev(wwin
, True
);
779 case WA_MOVE_NEXTWINDOW
:
780 wwin
= scr
->focused_window
;
781 wWindowFocusNext(wwin
, True
);
787 static void handleButtonPress(XEvent
* event
)
789 WObjDescriptor
*desc
;
792 scr
= wScreenForRootWindow(event
->xbutton
.root
);
798 if (!wPreferences
.disable_root_mouse
&& event
->xbutton
.window
== scr
->root_win
) {
799 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
800 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
801 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
802 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
803 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
804 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
805 } else if (event
->xbutton
.button
== Button8
&& wPreferences
.mouse_button8
!= WA_NONE
) {
806 executeButtonAction(scr
, event
, wPreferences
.mouse_button8
);
807 }else if (event
->xbutton
.button
== Button9
&& wPreferences
.mouse_button9
!= WA_NONE
) {
808 executeButtonAction(scr
, event
, wPreferences
.mouse_button9
);
809 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel_scroll
!= WA_NONE
) {
810 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_scroll
);
811 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel_scroll
!= WA_NONE
) {
812 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_scroll
);
813 } else if (event
->xbutton
.button
== Button6
&& wPreferences
.mouse_wheel_tilt
!= WA_NONE
) {
814 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_tilt
);
815 } else if (event
->xbutton
.button
== Button7
&& wPreferences
.mouse_wheel_tilt
!= WA_NONE
) {
816 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_tilt
);
821 if (XFindContext(dpy
, event
->xbutton
.subwindow
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
822 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
827 if (desc
->parent_type
== WCLASS_WINDOW
) {
830 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
831 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
833 /* if (wPreferences.focus_mode == WKF_CLICK) { */
834 if (wPreferences
.ignore_focus_click
) {
835 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
837 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
841 } else if (desc
->parent_type
== WCLASS_APPICON
842 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
843 if (event
->xbutton
.state
& MOD_MASK
) {
845 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
850 if (desc
->handle_mousedown
!= NULL
) {
851 (*desc
->handle_mousedown
) (desc
, event
);
854 /* save double-click information */
855 if (scr
->flags
.next_click_is_not_double
) {
856 scr
->flags
.next_click_is_not_double
= 0;
858 scr
->last_click_time
= event
->xbutton
.time
;
859 scr
->last_click_button
= event
->xbutton
.button
;
860 scr
->last_click_window
= event
->xbutton
.window
;
864 static void handleMapNotify(XEvent
* event
)
868 wwin
= wWindowFor(event
->xmap
.event
);
869 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
870 if (wwin
->flags
.miniaturized
) {
871 wDeiconifyWindow(wwin
);
875 wClientSetState(wwin
, NormalState
, None
);
881 static void handleUnmapNotify(XEvent
* event
)
885 Bool withdraw
= False
;
887 /* only process windows with StructureNotify selected
888 * (ignore SubstructureNotify) */
889 wwin
= wWindowFor(event
->xunmap
.window
);
893 /* whether the event is a Withdrawal request */
894 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
897 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
900 if (!wwin
->flags
.mapped
&& !withdraw
901 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
902 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
906 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
907 wwin
->flags
.mapped
= 0;
909 /* check if the window was destroyed */
910 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
913 Bool reparented
= False
;
915 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
918 /* withdraw window */
919 wwin
->flags
.mapped
= 0;
921 wClientSetState(wwin
, WithdrawnState
, None
);
923 /* if the window was reparented, do not reparent it back to the
925 wUnmanageWindow(wwin
, !reparented
, False
);
930 static void handleConfigureRequest(XEvent
* event
)
934 if (!(wwin
= wWindowFor(event
->xconfigurerequest
.window
))) {
936 * Configure request for unmapped window
938 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
940 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
944 static void handlePropertyNotify(XEvent
* event
)
952 wwin
= wWindowFor(event
->xproperty
.window
);
954 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
957 wClientCheckProperty(wwin
, &event
->xproperty
);
959 wapp
= wApplicationOf(event
->xproperty
.window
);
961 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
965 static void handleClientMessage(XEvent
* event
)
968 WObjDescriptor
*desc
;
970 /* handle transition from Normal to Iconic state */
971 if (event
->xclient
.message_type
== w_global
.atom
.wm
.change_state
972 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
974 wwin
= wWindowFor(event
->xclient
.window
);
977 if (!wwin
->flags
.miniaturized
)
978 wIconifyWindow(wwin
);
979 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.colormap_notify
&& event
->xclient
.format
== 32) {
980 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
985 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
986 wColormapAllowClientInstallation(scr
, True
);
987 } else { /* stopping */
988 wColormapAllowClientInstallation(scr
, False
);
990 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.command
) {
995 len
= sizeof(event
->xclient
.data
.b
) + 1;
996 command
= wmalloc(len
);
997 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
999 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
1000 wwarning(_("Got Reconfigure command"));
1001 wDefaultsCheckDomains(NULL
);
1003 wwarning(_("Got unknown command %s"), command
);
1008 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.wm_function
) {
1011 wapp
= wApplicationOf(event
->xclient
.window
);
1013 switch (event
->xclient
.data
.l
[0]) {
1014 case WMFHideOtherApplications
:
1015 wHideOtherApplications(wapp
->main_window_desc
);
1019 case WMFHideApplication
:
1020 wHideApplication(wapp
);
1026 wwin
= wWindowFor(event
->xclient
.window
);
1028 switch (event
->xclient
.data
.l
[0]) {
1029 case WMFHideOtherApplications
:
1030 wHideOtherApplications(wwin
);
1033 case WMFHideApplication
:
1034 wHideApplication(wApplicationOf(wwin
->main_window
));
1039 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.wm_attr
) {
1040 wwin
= wWindowFor(event
->xclient
.window
);
1043 switch (event
->xclient
.data
.l
[0]) {
1044 case GSWindowLevelAttr
:
1046 int level
= (int)event
->xclient
.data
.l
[1];
1048 if (WINDOW_LEVEL(wwin
) != level
) {
1049 ChangeStackingLevel(wwin
->frame
->core
, level
);
1054 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.titlebar_state
) {
1055 wwin
= wWindowFor(event
->xclient
.window
);
1058 switch (event
->xclient
.data
.l
[0]) {
1059 case WMTitleBarNormal
:
1060 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1062 case WMTitleBarMain
:
1063 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1066 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1069 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.ignore_focus_events
) {
1070 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1073 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1074 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1077 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1082 * Non-standard thing, but needed by OffiX DND.
1083 * For when the icon frame gets a ClientMessage
1084 * that should have gone to the icon_window.
1086 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1087 struct WIcon
*icon
= NULL
;
1089 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1090 icon
= (WIcon
*) desc
->parent
;
1091 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1092 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1094 if (icon
&& (wwin
= icon
->owner
)) {
1095 if (wwin
->client_win
!= event
->xclient
.window
) {
1096 event
->xclient
.window
= wwin
->client_win
;
1097 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1104 static void raiseWindow(WScreen
* scr
)
1108 scr
->autoRaiseTimer
= NULL
;
1110 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1114 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1115 wRaiseFrame(wwin
->frame
->core
);
1116 /* this is needed or a race condition will occur */
1121 static void handleEnterNotify(XEvent
* event
)
1124 WObjDescriptor
*desc
= NULL
;
1126 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1128 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1129 /* already left the window... */
1131 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1136 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1137 if (desc
->handle_enternotify
)
1138 (*desc
->handle_enternotify
) (desc
, event
);
1141 /* enter to window */
1142 wwin
= wWindowFor(event
->xcrossing
.window
);
1144 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1145 wColormapInstallForWindow(scr
, NULL
);
1147 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1148 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1149 scr
->autoRaiseTimer
= NULL
;
1152 /* set auto raise timer even if in focus-follows-mouse mode
1153 * and the event is for the frame window, even if the window
1154 * has focus already. useful if you move the pointer from a focused
1155 * window to the root window and back pretty fast
1157 * set focus if in focus-follows-mouse mode and the event
1158 * is for the frame window and window doesn't have focus yet */
1159 if (wPreferences
.focus_mode
== WKF_SLOPPY
1160 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1162 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1163 wSetFocusTo(scr
, wwin
);
1165 if (scr
->autoRaiseTimer
)
1166 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1167 scr
->autoRaiseTimer
= NULL
;
1169 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1170 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1172 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1175 /* Install colormap for window, if the colormap installation mode
1176 * is colormap_follows_mouse */
1177 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1178 if (wwin
->client_win
== event
->xcrossing
.window
)
1179 wColormapInstallForWindow(scr
, wwin
);
1181 wColormapInstallForWindow(scr
, NULL
);
1185 if (event
->xcrossing
.window
== event
->xcrossing
.root
1186 && event
->xcrossing
.detail
== NotifyNormal
1187 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1189 wSetFocusTo(scr
, scr
->focused_window
);
1192 wBalloonEnteredObject(scr
, desc
);
1196 static void handleLeaveNotify(XEvent
* event
)
1198 WObjDescriptor
*desc
= NULL
;
1200 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1201 if (desc
->handle_leavenotify
)
1202 (*desc
->handle_leavenotify
) (desc
, event
);
1207 static void handleShapeNotify(XEvent
* event
)
1209 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1216 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1217 if (ev
.xshape
.kind
== ShapeBounding
) {
1218 if (ev
.xshape
.shaped
== shev
->shaped
) {
1221 XPutBackEvent(dpy
, &ev
.xevent
);
1227 wwin
= wWindowFor(shev
->window
);
1228 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1231 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1233 wwin
->flags
.shaped
= 0;
1234 wWindowClearShape(wwin
);
1236 } else if (shev
->shaped
) {
1238 wwin
->flags
.shaped
= 1;
1239 wWindowSetShape(wwin
);
1242 #endif /* USE_XSHAPE */
1244 #ifdef KEEP_XKB_LOCK_STATUS
1245 /* please help ]d if you know what to do */
1246 static void handleXkbIndicatorStateNotify(XkbEvent
*event
)
1250 XkbStateRec staterec
;
1253 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1254 scr
= wScreenWithNumber(i
);
1255 wwin
= scr
->focused_window
;
1256 if (wwin
&& wwin
->flags
.focused
) {
1257 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1258 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1259 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1260 wwin
->frame
->languagemode
= staterec
.group
;
1262 #ifdef XKB_BUTTON_HINT
1263 if (wwin
->frame
->titlebar
) {
1264 wFrameWindowPaint(wwin
->frame
);
1270 #endif /*KEEP_XKB_LOCK_STATUS */
1272 static void handleColormapNotify(XEvent
* event
)
1276 Bool reinstall
= False
;
1278 wwin
= wWindowFor(event
->xcolormap
.window
);
1282 scr
= wwin
->screen_ptr
;
1286 if (event
->xcolormap
.new) {
1287 XWindowAttributes attr
;
1289 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1291 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1292 scr
->current_colormap
= attr
.colormap
;
1295 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1296 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1298 /* some bastard app (like XV) removed our colormap */
1300 * can't enforce or things like xscreensaver wont work
1303 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1304 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1306 /* someone has put our colormap back */
1310 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1311 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1313 if (reinstall
&& scr
->current_colormap
!= None
) {
1314 if (!scr
->flags
.colormap_stuff_blocked
)
1315 XInstallColormap(dpy
, scr
->current_colormap
);
1319 static void handleFocusIn(XEvent
* event
)
1324 * For applications that like stealing the focus.
1326 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1327 saveTimestamp(event
);
1328 if (event
->xfocus
.mode
== NotifyUngrab
1329 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1333 wwin
= wWindowFor(event
->xfocus
.window
);
1334 if (wwin
&& !wwin
->flags
.focused
) {
1335 if (wwin
->flags
.mapped
)
1336 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1338 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1340 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1342 wSetFocusTo(scr
, NULL
);
1346 static WWindow
*windowUnderPointer(WScreen
* scr
)
1352 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1353 return wWindowFor(win
);
1357 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1359 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1365 static void handleKeyPress(XEvent
* event
)
1367 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1368 WWindow
*wwin
= scr
->focused_window
;
1372 #ifdef KEEP_XKB_LOCK_STATUS
1373 XkbStateRec staterec
;
1374 #endif /*KEEP_XKB_LOCK_STATUS */
1376 /* ignore CapsLock */
1377 modifiers
= event
->xkey
.state
& w_global
.shortcut
.modifiers_mask
;
1379 for (i
= 0; i
< WKBD_LAST
; i
++) {
1380 if (wKeyBindings
[i
].keycode
== 0)
1383 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1384 || */ wKeyBindings
[i
].modifier
==
1393 if (!wRootMenuPerformShortcut(event
)) {
1394 static int dontLoop
= 0;
1396 if (dontLoop
> 10) {
1397 wwarning("problem with key event processing code");
1401 /* if the focused window is an internal window, try redispatching
1402 * the event to the managed window, as it can be a WINGs window */
1403 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1404 /* client_leader contains the WINGs toplevel */
1405 event
->xany
.window
= wwin
->client_leader
;
1406 WMHandleEvent(event
);
1412 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1413 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1418 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1419 if (!CheckFullScreenWindowFocused(scr
)) {
1420 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1421 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1425 case WKBD_WINDOWLIST
:
1426 if (!CheckFullScreenWindowFocused(scr
)) {
1427 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1428 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1433 case WKBD_WINDOWMENU
:
1434 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1435 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1437 case WKBD_MINIMIZEALL
:
1438 CloseWindowMenu(scr
);
1441 case WKBD_MINIATURIZE
:
1442 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1443 && !WFLAGP(wwin
, no_miniaturizable
)) {
1444 CloseWindowMenu(scr
);
1446 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1447 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
, event
->xbutton
.time
);
1449 wIconifyWindow(wwin
);
1454 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1455 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1456 CloseWindowMenu(scr
);
1458 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1459 wHideApplication(wapp
);
1463 case WKBD_HIDE_OTHERS
:
1464 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1465 CloseWindowMenu(scr
);
1467 wHideOtherApplications(wwin
);
1471 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1472 CloseWindowMenu(scr
);
1474 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1477 case WKBD_VMAXIMIZE
:
1478 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1479 CloseWindowMenu(scr
);
1481 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1484 case WKBD_HMAXIMIZE
:
1485 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1486 CloseWindowMenu(scr
);
1488 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1491 case WKBD_LHMAXIMIZE
:
1492 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1493 CloseWindowMenu(scr
);
1495 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1498 case WKBD_RHMAXIMIZE
:
1499 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1500 CloseWindowMenu(scr
);
1502 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1505 case WKBD_THMAXIMIZE
:
1506 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1507 CloseWindowMenu(scr
);
1509 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1512 case WKBD_BHMAXIMIZE
:
1513 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1514 CloseWindowMenu(scr
);
1516 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1519 case WKBD_LTCMAXIMIZE
:
1520 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1521 CloseWindowMenu(scr
);
1523 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1526 case WKBD_RTCMAXIMIZE
:
1527 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1528 CloseWindowMenu(scr
);
1530 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1533 case WKBD_LBCMAXIMIZE
:
1534 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1535 CloseWindowMenu(scr
);
1537 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1540 case WKBD_RBCMAXIMIZE
:
1541 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1542 CloseWindowMenu(scr
);
1544 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1548 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1549 CloseWindowMenu(scr
);
1551 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1554 case WKBD_OMNIPRESENT
:
1555 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1556 CloseWindowMenu(scr
);
1558 wWindowSetOmnipresent(wwin
, !wwin
->flags
.omnipresent
);
1562 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1563 CloseWindowMenu(scr
);
1565 wRaiseFrame(wwin
->frame
->core
);
1569 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1570 CloseWindowMenu(scr
);
1572 wLowerFrame(wwin
->frame
->core
);
1575 case WKBD_RAISELOWER
:
1576 /* raise or lower the window under the pointer, not the
1579 wwin
= windowUnderPointer(scr
);
1581 wRaiseLowerFrame(wwin
->frame
->core
);
1584 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1585 if (wwin
->flags
.shaded
)
1586 wUnshadeWindow(wwin
);
1591 case WKBD_MOVERESIZE
:
1592 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1593 CloseWindowMenu(scr
);
1595 wKeyboardMoveResizeWindow(wwin
);
1599 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1600 CloseWindowMenu(scr
);
1601 if (wwin
->protocols
.DELETE_WINDOW
)
1602 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
, event
->xkey
.time
);
1606 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1607 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1611 case WKBD_WORKSPACEMAP
:
1612 if (!wPreferences
.disable_workspace_pager
)
1613 StartWorkspaceMap(scr
);
1616 case WKBD_FOCUSNEXT
:
1617 StartWindozeCycle(wwin
, event
, True
, False
);
1620 case WKBD_FOCUSPREV
:
1621 StartWindozeCycle(wwin
, event
, False
, False
);
1624 case WKBD_GROUPNEXT
:
1625 StartWindozeCycle(wwin
, event
, True
, True
);
1628 case WKBD_GROUPPREV
:
1629 StartWindozeCycle(wwin
, event
, False
, True
);
1632 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1633 widx
= command
- WKBD_WORKSPACE1
;
1634 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1635 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1636 wWorkspaceChange(scr
, i
);
1639 case WKBD_NEXTWORKSPACE
:
1640 wWorkspaceRelativeChange(scr
, 1);
1642 case WKBD_PREVWORKSPACE
:
1643 wWorkspaceRelativeChange(scr
, -1);
1645 case WKBD_LASTWORKSPACE
:
1646 wWorkspaceChange(scr
, scr
->last_workspace
);
1649 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1650 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1651 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1652 if (wwin
&& (wPreferences
.ws_advance
|| i
< scr
->workspace_count
))
1653 wWindowChangeWorkspace(wwin
, i
);
1656 case WKBD_MOVE_NEXTWORKSPACE
:
1658 wWindowChangeWorkspaceRelative(wwin
, 1);
1660 case WKBD_MOVE_PREVWORKSPACE
:
1662 wWindowChangeWorkspaceRelative(wwin
, -1);
1664 case WKBD_MOVE_LASTWORKSPACE
:
1666 wWindowChangeWorkspace(wwin
, scr
->last_workspace
);
1669 case WKBD_MOVE_NEXTWSLAYER
:
1670 case WKBD_MOVE_PREVWSLAYER
:
1675 row
= scr
->current_workspace
/ 10;
1676 column
= scr
->current_workspace
% 10;
1678 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1679 if ((row
+ 1) * 10 < scr
->workspace_count
)
1680 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1683 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1700 widx
= command
- WKBD_WINDOW1
;
1702 if (scr
->shortcutWindows
[widx
]) {
1703 WMArray
*list
= scr
->shortcutWindows
[widx
];
1705 int count
= WMGetArrayItemCount(list
);
1707 WMArrayIterator iter
;
1710 wUnselectWindows(scr
);
1711 cw
= scr
->current_workspace
;
1713 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1715 wWindowChangeWorkspace(wwin
, cw
);
1717 wMakeWindowVisible(wwin
);
1720 wSelectWindow(wwin
, True
);
1723 /* rotate the order of windows, to create a cycling effect */
1724 twin
= WMGetFromArray(list
, 0);
1725 WMDeleteFromArray(list
, 0);
1726 WMAddToArray(list
, twin
);
1728 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1729 if (scr
->shortcutWindows
[widx
]) {
1730 WMFreeArray(scr
->shortcutWindows
[widx
]);
1731 scr
->shortcutWindows
[widx
] = NULL
;
1734 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1735 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1736 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1737 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1739 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1740 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1743 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1746 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1749 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1751 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1752 if (scr
->shortcutWindows
[widx
]) {
1753 WMFreeArray(scr
->shortcutWindows
[widx
]);
1755 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1762 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1763 (void) RelaunchWindow(wwin
);
1767 case WKBD_SWITCH_SCREEN
:
1768 if (w_global
.screen_count
> 1) {
1772 /* find index of this screen */
1773 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1774 if (wScreenWithNumber(i
) == scr
)
1778 if (i
>= w_global
.screen_count
) {
1781 scr2
= wScreenWithNumber(i
);
1784 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1785 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1794 cmdline
= ExpandOptions(scr
, _("exec %a(Run,Type command to run:)"));
1797 XGrabPointer(dpy
, scr
->root_win
, True
, 0,
1798 GrabModeAsync
, GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_WAIT
], CurrentTime
);
1801 ExecuteShellCommand(scr
, cmdline
);
1804 XUngrabPointer(dpy
, CurrentTime
);
1810 case WKBD_NEXTWSLAYER
:
1811 case WKBD_PREVWSLAYER
:
1815 row
= scr
->current_workspace
/ 10;
1816 column
= scr
->current_workspace
% 10;
1818 if (command
== WKBD_NEXTWSLAYER
) {
1819 if ((row
+ 1) * 10 < scr
->workspace_count
)
1820 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1823 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1827 case WKBD_CLIPRAISELOWER
:
1828 if (!wPreferences
.flags
.noclip
)
1829 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1831 case WKBD_DOCKRAISELOWER
:
1832 if (!wPreferences
.flags
.nodock
)
1833 wDockRaiseLower(scr
->dock
);
1835 #ifdef KEEP_XKB_LOCK_STATUS
1837 if (wPreferences
.modelock
) {
1839 wwin
= scr
->focused_window
;
1841 if (wwin
&& wwin
->flags
.mapped
1842 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1843 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1844 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1846 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1847 wwin
->frame
->last_languagemode
= staterec
.group
;
1848 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1853 #endif /* KEEP_XKB_LOCK_STATUS */
1857 static void handleMotionNotify(XEvent
* event
)
1859 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1861 if (wPreferences
.scrollable_menus
) {
1862 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1863 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1865 if (scr
->flags
.jump_back_pending
||
1866 p
.x
<= (rect
.pos
.x
+ 1) ||
1867 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1868 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1871 menu
= wMenuUnderPointer(scr
);
1878 static void handleVisibilityNotify(XEvent
* event
)
1882 wwin
= wWindowFor(event
->xvisibility
.window
);
1885 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);