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 handle_selection_clear(XSelectionClearEvent
*event
);
107 static void wdelete_death_handler(WMagicNumber id
);
111 static void handleShapeNotify(XEvent
*event
);
114 #ifdef KEEP_XKB_LOCK_STATUS
115 static void handleXkbIndicatorStateNotify(XkbEvent
*event
);
118 /* real dead process handler */
119 static void handleDeadProcess(void);
121 typedef struct DeadProcesses
{
123 unsigned char exit_status
;
126 /* stack of dead processes */
127 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
128 static int deadProcessPtr
= 0;
130 typedef struct DeathHandler
{
131 WDeathHandler
*callback
;
136 static WMArray
*deathHandlers
= NULL
;
138 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
140 DeathHandler
*handler
;
142 handler
= malloc(sizeof(DeathHandler
));
147 handler
->callback
= callback
;
148 handler
->client_data
= cdata
;
151 deathHandlers
= WMCreateArrayWithDestructor(8, free
);
153 WMAddToArray(deathHandlers
, handler
);
158 static void wdelete_death_handler(WMagicNumber id
)
160 DeathHandler
*handler
= (DeathHandler
*) id
;
162 if (!handler
|| !deathHandlers
)
165 /* array destructor will call free(handler) */
166 WMRemoveFromArray(deathHandlers
, handler
);
169 void DispatchEvent(XEvent
* event
)
174 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
175 WCHANGE_STATE(WSTATE_EXITING
);
176 /* received SIGTERM */
178 * WMHandleEvent() can't be called from anything
179 * executed inside here, or we can get in a infinite
182 Shutdown(WSExitMode
);
184 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
185 WCHANGE_STATE(WSTATE_RESTARTING
);
187 Shutdown(WSRestartPreparationMode
);
188 /* received SIGHUP */
190 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
191 WCHANGE_STATE(WSTATE_NORMAL
);
192 wDefaultsCheckDomains(NULL
);
195 /* for the case that all that is wanted to be dispatched is
200 saveTimestamp(event
);
201 switch (event
->type
) {
203 handleMapRequest(event
);
207 handleKeyPress(event
);
211 handleMotionNotify(event
);
214 case ConfigureRequest
:
215 handleConfigureRequest(event
);
219 handleDestroyNotify(event
);
223 handleMapNotify(event
);
227 handleUnmapNotify(event
);
231 handleButtonPress(event
);
239 handlePropertyNotify(event
);
243 handleEnterNotify(event
);
247 handleLeaveNotify(event
);
251 handleClientMessage(event
);
255 handleColormapNotify(event
);
259 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
260 XRefreshKeyboardMapping(&event
->xmapping
);
264 handleFocusIn(event
);
267 case VisibilityNotify
:
268 handleVisibilityNotify(event
);
271 case ConfigureNotify
:
273 if (event
->xconfigure
.window
== DefaultRootWindow(dpy
))
274 XRRUpdateConfiguration(event
);
279 handle_selection_clear(&event
->xselectionclear
);
283 handleExtensions(event
);
290 *----------------------------------------------------------------------
291 * handle_inotify_events-
292 * Check for inotify events
295 * After reading events for the given file descriptor (fd) and
296 * watch descriptor (wd)
299 * Calls wDefaultsCheckDomains if config database is updated
300 *----------------------------------------------------------------------
302 static void handle_inotify_events(void)
304 ssize_t eventQLength
;
306 /* Make room for at lease 5 simultaneous events, with path + filenames */
307 char buff
[ (sizeof(struct inotify_event
) + NAME_MAX
+ 1) * 5 ];
308 /* Check config only once per read of the event queue */
312 * Read off the queued events
313 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
314 * not occur; the block is on Xevents, but a config file change will normally
315 * occur as a result of an Xevent - so the event queue should never have more than
316 * a few entries before a read().
318 eventQLength
= read(w_global
.inotify
.fd_event_queue
,
319 buff
, sizeof(buff
) );
321 if (eventQLength
< 0) {
322 wwarning(_("read problem when trying to get INotify event: %s"), strerror(errno
));
326 /* check what events occured */
327 /* Should really check wd here too, but for now we only have one watch! */
328 while (i
< eventQLength
) {
329 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
332 * see inotify.h for event types.
334 if (pevent
->mask
& IN_DELETE_SELF
) {
335 wwarning(_("the defaults database has been deleted!"
336 " Restart Window Maker to create the database" " with the default settings"));
338 if (w_global
.inotify
.fd_event_queue
>= 0) {
339 close(w_global
.inotify
.fd_event_queue
);
340 w_global
.inotify
.fd_event_queue
= -1;
343 if (pevent
->mask
& IN_UNMOUNT
) {
344 wwarning(_("the unit containing the defaults database has"
345 " been unmounted. Setting --static mode." " Any changes will not be saved."));
347 if (w_global
.inotify
.fd_event_queue
>= 0) {
348 close(w_global
.inotify
.fd_event_queue
);
349 w_global
.inotify
.fd_event_queue
= -1;
352 wPreferences
.flags
.noupdates
= 1;
354 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
355 wwarning(_("Inotify: Reading config files in defaults database."));
356 wDefaultsCheckDomains(NULL
);
360 /* move to next event in the buffer */
361 i
+= sizeof(struct inotify_event
) + pevent
->len
;
364 #endif /* HAVE_INOTIFY */
367 *----------------------------------------------------------------------
369 * Processes X and internal events indefinitely.
375 * The LastTimestamp global variable is updated.
376 * Calls inotifyGetEvents if defaults database changes.
377 *----------------------------------------------------------------------
379 noreturn
void EventLoop(void)
387 if (w_global
.inotify
.fd_event_queue
< 0 || w_global
.inotify
.wd_defaults
< 0)
393 WMNextEvent(dpy
, &event
); /* Blocks here */
394 WMHandleEvent(&event
);
400 FD_SET(w_global
.inotify
.fd_event_queue
, &rfds
);
402 /* check for available read data from inotify - don't block! */
403 retVal
= select(w_global
.inotify
.fd_event_queue
+ 1, &rfds
, NULL
, NULL
, &time
);
405 if (retVal
< 0) { /* an error has occured */
406 wwarning(_("select failed. The inotify instance will be closed."
407 " Changes to the defaults database will require"
408 " a restart to take effect."));
409 close(w_global
.inotify
.fd_event_queue
);
410 w_global
.inotify
.fd_event_queue
= -1;
413 if (FD_ISSET(w_global
.inotify
.fd_event_queue
, &rfds
))
414 handle_inotify_events();
421 *----------------------------------------------------------------------
422 * ProcessPendingEvents --
423 * Processes the events that are currently pending (at the time
424 * this function is called) in the display's queue.
427 * After the pending events that were present at the function call
431 * Many -- whatever handling events may involve.
433 *----------------------------------------------------------------------
435 void ProcessPendingEvents(void)
442 /* Take a snapshot of the event count in the queue */
443 count
= XPending(dpy
);
445 while (count
> 0 && XPending(dpy
)) {
446 WMNextEvent(dpy
, &event
);
447 WMHandleEvent(&event
);
452 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
454 if ((scr
->last_click_time
> 0) &&
455 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
456 && (event
->xbutton
.button
== scr
->last_click_button
)
457 && (event
->xbutton
.window
== scr
->last_click_window
)) {
459 scr
->flags
.next_click_is_not_double
= 1;
460 scr
->last_click_time
= 0;
461 scr
->last_click_window
= event
->xbutton
.window
;
468 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
470 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
471 wwarning("stack overflow: too many dead processes");
474 /* stack the process to be handled later,
475 * as this is called from the signal handler */
476 deadProcesses
[deadProcessPtr
].pid
= pid
;
477 deadProcesses
[deadProcessPtr
].exit_status
= status
;
481 static void handleDeadProcess(void)
486 for (i
= 0; i
< deadProcessPtr
; i
++) {
487 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
490 if (!deathHandlers
) {
495 /* get the pids on the queue and call handlers */
496 while (deadProcessPtr
> 0) {
499 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
500 tmp
= WMGetFromArray(deathHandlers
, i
);
504 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
505 (*tmp
->callback
) (tmp
->pid
,
506 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
507 wdelete_death_handler(tmp
);
513 static void saveTimestamp(XEvent
* event
)
516 * Never save CurrentTime as LastTimestamp because CurrentTime
517 * it's not a real timestamp (it's the 0L constant)
520 switch (event
->type
) {
523 w_global
.timestamp
.last_event
= event
->xbutton
.time
;
527 w_global
.timestamp
.last_event
= event
->xkey
.time
;
530 w_global
.timestamp
.last_event
= event
->xmotion
.time
;
533 w_global
.timestamp
.last_event
= event
->xproperty
.time
;
537 w_global
.timestamp
.last_event
= event
->xcrossing
.time
;
540 w_global
.timestamp
.last_event
= event
->xselectionclear
.time
;
542 case SelectionRequest
:
543 w_global
.timestamp
.last_event
= event
->xselectionrequest
.time
;
545 case SelectionNotify
:
546 w_global
.timestamp
.last_event
= event
->xselection
.time
;
548 wXDNDProcessSelection(event
);
554 static int matchWindow(const void *item
, const void *cdata
)
556 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
559 static void handleExtensions(XEvent
* event
)
562 if (w_global
.xext
.shape
.supported
&& event
->type
== (w_global
.xext
.shape
.event_base
+ ShapeNotify
)) {
563 handleShapeNotify(event
);
566 #ifdef KEEP_XKB_LOCK_STATUS
567 if (wPreferences
.modelock
&& (event
->type
== w_global
.xext
.xkb
.event_base
)) {
568 handleXkbIndicatorStateNotify((XkbEvent
*) event
);
570 #endif /*KEEP_XKB_LOCK_STATUS */
572 if (w_global
.xext
.randr
.supported
&& event
->type
== (w_global
.xext
.randr
.event_base
+ RRScreenChangeNotify
)) {
573 /* From xrandr man page: "Clients must call back into Xlib using
574 * XRRUpdateConfiguration when screen configuration change notify
575 * events are generated */
576 XRRUpdateConfiguration(event
);
577 WCHANGE_STATE(WSTATE_RESTARTING
);
578 Shutdown(WSRestartPreparationMode
);
584 static void handleMapRequest(XEvent
* ev
)
588 Window window
= ev
->xmaprequest
.window
;
590 wwin
= wWindowFor(window
);
592 if (wwin
->flags
.shaded
) {
593 wUnshadeWindow(wwin
);
595 /* deiconify window */
596 if (wwin
->flags
.miniaturized
) {
597 wDeiconifyWindow(wwin
);
598 } else if (wwin
->flags
.hidden
) {
599 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
600 /* go to the last workspace that the user worked on the app */
602 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
604 wUnhideApplication(wapp
, False
, False
);
609 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
611 wwin
= wManageWindow(scr
, window
);
614 * This is to let the Dock know that the application it launched
615 * has already been mapped (eg: it has finished launching).
616 * It is not necessary for normally docked apps, but is needed for
617 * apps that were forcedly docked (like with dockit).
619 if (scr
->last_dock
) {
620 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
621 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
623 wDockTrackWindowLaunch(scr
->last_dock
, window
);
627 wClientSetState(wwin
, NormalState
, None
);
628 if (wwin
->flags
.maximized
) {
629 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
631 if (wwin
->flags
.shaded
) {
632 wwin
->flags
.shaded
= 0;
633 wwin
->flags
.skip_next_animation
= 1;
636 if (wwin
->flags
.miniaturized
) {
637 wwin
->flags
.miniaturized
= 0;
638 wwin
->flags
.skip_next_animation
= 1;
639 wIconifyWindow(wwin
);
641 if (wwin
->flags
.fullscreen
) {
642 wwin
->flags
.fullscreen
= 0;
643 wFullscreenWindow(wwin
);
645 if (wwin
->flags
.hidden
) {
646 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
648 wwin
->flags
.hidden
= 0;
649 wwin
->flags
.skip_next_animation
= 1;
651 wHideApplication(wapp
);
657 static void handleDestroyNotify(XEvent
* event
)
661 Window window
= event
->xdestroywindow
.window
;
662 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
665 wwin
= wWindowFor(window
);
667 wUnmanageWindow(wwin
, False
, True
);
671 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
672 WFakeGroupLeader
*fPtr
;
674 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
675 if (fPtr
->retainCount
> 0) {
677 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
678 XDestroyWindow(dpy
, fPtr
->leader
);
683 fPtr
->origLeader
= None
;
687 app
= wApplicationOf(window
);
689 if (window
== app
->main_window
) {
691 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
693 if (wwin
->main_window
== window
) {
694 wwin
->main_window
= None
;
699 wApplicationDestroy(app
);
703 static void handleExpose(XEvent
* event
)
705 WObjDescriptor
*desc
;
708 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
710 if (XFindContext(dpy
, event
->xexpose
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
714 if (desc
->handle_expose
) {
715 (*desc
->handle_expose
) (desc
, event
);
719 static void executeWheelAction(WScreen
*scr
, XEvent
*event
, int action
)
724 if (event
->xbutton
.button
== Button5
|| event
->xbutton
.button
== Button6
)
725 next_direction
= False
;
727 next_direction
= True
;
730 case WA_SWITCH_WORKSPACES
:
732 wWorkspaceRelativeChange(scr
, 1);
734 wWorkspaceRelativeChange(scr
, -1);
737 case WA_SWITCH_WINDOWS
:
738 wwin
= scr
->focused_window
;
740 wWindowFocusNext(wwin
, True
);
742 wWindowFocusPrev(wwin
, True
);
747 static void executeButtonAction(WScreen
*scr
, XEvent
*event
, int action
)
752 case WA_SELECT_WINDOWS
:
753 wUnselectWindows(scr
);
754 wSelectWindows(scr
, event
);
756 case WA_OPEN_APPMENU
:
757 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
759 if (scr
->root_menu
) {
760 if (scr
->root_menu
->brother
->flags
.mapped
)
761 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
763 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
766 case WA_OPEN_WINLISTMENU
:
767 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
768 if (scr
->switch_menu
) {
769 if (scr
->switch_menu
->brother
->flags
.mapped
)
770 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
772 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
775 case WA_MOVE_PREVWORKSPACE
:
776 wWorkspaceRelativeChange(scr
, -1);
778 case WA_MOVE_NEXTWORKSPACE
:
779 wWorkspaceRelativeChange(scr
, 1);
781 case WA_MOVE_PREVWINDOW
:
782 wwin
= scr
->focused_window
;
783 wWindowFocusPrev(wwin
, True
);
785 case WA_MOVE_NEXTWINDOW
:
786 wwin
= scr
->focused_window
;
787 wWindowFocusNext(wwin
, True
);
793 static void handleButtonPress(XEvent
* event
)
795 WObjDescriptor
*desc
;
798 scr
= wScreenForRootWindow(event
->xbutton
.root
);
804 if (!wPreferences
.disable_root_mouse
&& event
->xbutton
.window
== scr
->root_win
) {
805 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
806 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
807 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
808 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
809 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
810 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
811 } else if (event
->xbutton
.button
== Button8
&& wPreferences
.mouse_button8
!= WA_NONE
) {
812 executeButtonAction(scr
, event
, wPreferences
.mouse_button8
);
813 }else if (event
->xbutton
.button
== Button9
&& wPreferences
.mouse_button9
!= WA_NONE
) {
814 executeButtonAction(scr
, event
, wPreferences
.mouse_button9
);
815 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel_scroll
!= WA_NONE
) {
816 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_scroll
);
817 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel_scroll
!= WA_NONE
) {
818 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_scroll
);
819 } else if (event
->xbutton
.button
== Button6
&& wPreferences
.mouse_wheel_tilt
!= WA_NONE
) {
820 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_tilt
);
821 } else if (event
->xbutton
.button
== Button7
&& wPreferences
.mouse_wheel_tilt
!= WA_NONE
) {
822 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_tilt
);
827 if (XFindContext(dpy
, event
->xbutton
.subwindow
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
828 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
833 if (desc
->parent_type
== WCLASS_WINDOW
) {
836 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
837 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
839 /* if (wPreferences.focus_mode == WKF_CLICK) { */
840 if (wPreferences
.ignore_focus_click
) {
841 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
843 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
847 } else if (desc
->parent_type
== WCLASS_APPICON
848 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
849 if (event
->xbutton
.state
& MOD_MASK
) {
851 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
856 if (desc
->handle_mousedown
!= NULL
) {
857 (*desc
->handle_mousedown
) (desc
, event
);
860 /* save double-click information */
861 if (scr
->flags
.next_click_is_not_double
) {
862 scr
->flags
.next_click_is_not_double
= 0;
864 scr
->last_click_time
= event
->xbutton
.time
;
865 scr
->last_click_button
= event
->xbutton
.button
;
866 scr
->last_click_window
= event
->xbutton
.window
;
870 static void handleMapNotify(XEvent
* event
)
874 wwin
= wWindowFor(event
->xmap
.event
);
875 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
876 if (wwin
->flags
.miniaturized
) {
877 wDeiconifyWindow(wwin
);
881 wClientSetState(wwin
, NormalState
, None
);
887 static void handleUnmapNotify(XEvent
* event
)
891 Bool withdraw
= False
;
893 /* only process windows with StructureNotify selected
894 * (ignore SubstructureNotify) */
895 wwin
= wWindowFor(event
->xunmap
.window
);
899 /* whether the event is a Withdrawal request */
900 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
903 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
906 if (!wwin
->flags
.mapped
&& !withdraw
907 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
908 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
912 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
913 wwin
->flags
.mapped
= 0;
915 /* check if the window was destroyed */
916 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
919 Bool reparented
= False
;
921 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
924 /* withdraw window */
925 wwin
->flags
.mapped
= 0;
927 wClientSetState(wwin
, WithdrawnState
, None
);
929 /* if the window was reparented, do not reparent it back to the
931 wUnmanageWindow(wwin
, !reparented
, False
);
936 static void handleConfigureRequest(XEvent
* event
)
940 wwin
= wWindowFor(event
->xconfigurerequest
.window
);
943 * Configure request for unmapped window
945 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
947 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
951 static void handlePropertyNotify(XEvent
* event
)
959 wwin
= wWindowFor(event
->xproperty
.window
);
961 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
964 wClientCheckProperty(wwin
, &event
->xproperty
);
966 wapp
= wApplicationOf(event
->xproperty
.window
);
968 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
972 static void handleClientMessage(XEvent
* event
)
975 WObjDescriptor
*desc
;
977 /* handle transition from Normal to Iconic state */
978 if (event
->xclient
.message_type
== w_global
.atom
.wm
.change_state
979 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
981 wwin
= wWindowFor(event
->xclient
.window
);
984 if (!wwin
->flags
.miniaturized
)
985 wIconifyWindow(wwin
);
986 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.colormap_notify
&& event
->xclient
.format
== 32) {
987 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
992 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
993 wColormapAllowClientInstallation(scr
, True
);
994 } else { /* stopping */
995 wColormapAllowClientInstallation(scr
, False
);
997 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.command
) {
1002 len
= sizeof(event
->xclient
.data
.b
) + 1;
1003 command
= wmalloc(len
);
1004 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
1006 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
1007 wwarning(_("Got Reconfigure command"));
1008 wDefaultsCheckDomains(NULL
);
1010 wwarning(_("Got unknown command %s"), command
);
1015 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.wm_function
) {
1018 wapp
= wApplicationOf(event
->xclient
.window
);
1020 switch (event
->xclient
.data
.l
[0]) {
1021 case WMFHideOtherApplications
:
1022 wHideOtherApplications(wapp
->main_window_desc
);
1026 case WMFHideApplication
:
1027 wHideApplication(wapp
);
1033 wwin
= wWindowFor(event
->xclient
.window
);
1035 switch (event
->xclient
.data
.l
[0]) {
1036 case WMFHideOtherApplications
:
1037 wHideOtherApplications(wwin
);
1040 case WMFHideApplication
:
1041 wHideApplication(wApplicationOf(wwin
->main_window
));
1046 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.wm_attr
) {
1047 wwin
= wWindowFor(event
->xclient
.window
);
1050 switch (event
->xclient
.data
.l
[0]) {
1051 case GSWindowLevelAttr
:
1053 int level
= (int)event
->xclient
.data
.l
[1];
1055 if (WINDOW_LEVEL(wwin
) != level
) {
1056 ChangeStackingLevel(wwin
->frame
->core
, level
);
1061 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.titlebar_state
) {
1062 wwin
= wWindowFor(event
->xclient
.window
);
1065 switch (event
->xclient
.data
.l
[0]) {
1066 case WMTitleBarNormal
:
1067 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1069 case WMTitleBarMain
:
1070 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1073 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1076 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.ignore_focus_events
) {
1077 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1080 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1081 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1083 #ifdef USE_DOCK_XDND
1084 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1086 #endif /* USE_DOCK_XDND */
1089 * Non-standard thing, but needed by OffiX DND.
1090 * For when the icon frame gets a ClientMessage
1091 * that should have gone to the icon_window.
1093 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1094 struct WIcon
*icon
= NULL
;
1096 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1097 icon
= (WIcon
*) desc
->parent
;
1098 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1099 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1101 if (icon
&& (wwin
= icon
->owner
)) {
1102 if (wwin
->client_win
!= event
->xclient
.window
) {
1103 event
->xclient
.window
= wwin
->client_win
;
1104 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1111 static void raiseWindow(WScreen
* scr
)
1115 scr
->autoRaiseTimer
= NULL
;
1117 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1121 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1122 wRaiseFrame(wwin
->frame
->core
);
1123 /* this is needed or a race condition will occur */
1128 static void handleEnterNotify(XEvent
* event
)
1131 WObjDescriptor
*desc
= NULL
;
1133 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1135 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1136 /* already left the window... */
1138 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1143 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1144 if (desc
->handle_enternotify
)
1145 (*desc
->handle_enternotify
) (desc
, event
);
1148 /* enter to window */
1149 wwin
= wWindowFor(event
->xcrossing
.window
);
1151 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1152 wColormapInstallForWindow(scr
, NULL
);
1154 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1155 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1156 scr
->autoRaiseTimer
= NULL
;
1159 /* set auto raise timer even if in focus-follows-mouse mode
1160 * and the event is for the frame window, even if the window
1161 * has focus already. useful if you move the pointer from a focused
1162 * window to the root window and back pretty fast
1164 * set focus if in focus-follows-mouse mode and the event
1165 * is for the frame window and window doesn't have focus yet */
1166 if (wPreferences
.focus_mode
== WKF_SLOPPY
1167 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1169 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1170 wSetFocusTo(scr
, wwin
);
1172 if (scr
->autoRaiseTimer
)
1173 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1174 scr
->autoRaiseTimer
= NULL
;
1176 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1177 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1179 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1182 /* Install colormap for window, if the colormap installation mode
1183 * is colormap_follows_mouse */
1184 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1185 if (wwin
->client_win
== event
->xcrossing
.window
)
1186 wColormapInstallForWindow(scr
, wwin
);
1188 wColormapInstallForWindow(scr
, NULL
);
1192 if (event
->xcrossing
.window
== event
->xcrossing
.root
1193 && event
->xcrossing
.detail
== NotifyNormal
1194 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1196 wSetFocusTo(scr
, scr
->focused_window
);
1199 wBalloonEnteredObject(scr
, desc
);
1203 static void handleLeaveNotify(XEvent
* event
)
1205 WObjDescriptor
*desc
= NULL
;
1207 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1208 if (desc
->handle_leavenotify
)
1209 (*desc
->handle_leavenotify
) (desc
, event
);
1214 static void handleShapeNotify(XEvent
* event
)
1216 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1223 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1224 if (ev
.xshape
.kind
== ShapeBounding
) {
1225 if (ev
.xshape
.shaped
== shev
->shaped
) {
1228 XPutBackEvent(dpy
, &ev
.xevent
);
1234 wwin
= wWindowFor(shev
->window
);
1235 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1238 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1240 wwin
->flags
.shaped
= 0;
1241 wWindowClearShape(wwin
);
1243 } else if (shev
->shaped
) {
1245 wwin
->flags
.shaped
= 1;
1246 wWindowSetShape(wwin
);
1249 #endif /* USE_XSHAPE */
1251 #ifdef KEEP_XKB_LOCK_STATUS
1252 /* please help ]d if you know what to do */
1253 static void handleXkbIndicatorStateNotify(XkbEvent
*event
)
1257 XkbStateRec staterec
;
1260 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1261 scr
= wScreenWithNumber(i
);
1262 wwin
= scr
->focused_window
;
1263 if (wwin
&& wwin
->flags
.focused
) {
1264 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1265 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1266 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1267 wwin
->frame
->languagemode
= staterec
.group
;
1269 #ifdef XKB_BUTTON_HINT
1270 if (wwin
->frame
->titlebar
) {
1271 wFrameWindowPaint(wwin
->frame
);
1277 #endif /*KEEP_XKB_LOCK_STATUS */
1279 static void handleColormapNotify(XEvent
* event
)
1283 Bool reinstall
= False
;
1285 wwin
= wWindowFor(event
->xcolormap
.window
);
1289 scr
= wwin
->screen_ptr
;
1293 if (event
->xcolormap
.new) {
1294 XWindowAttributes attr
;
1296 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1298 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1299 scr
->current_colormap
= attr
.colormap
;
1302 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1303 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1305 /* some bastard app (like XV) removed our colormap */
1307 * can't enforce or things like xscreensaver wont work
1310 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1311 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1313 /* someone has put our colormap back */
1317 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1318 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1320 if (reinstall
&& scr
->current_colormap
!= None
) {
1321 if (!scr
->flags
.colormap_stuff_blocked
)
1322 XInstallColormap(dpy
, scr
->current_colormap
);
1326 static void handleFocusIn(XEvent
* event
)
1331 * For applications that like stealing the focus.
1333 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1334 saveTimestamp(event
);
1335 if (event
->xfocus
.mode
== NotifyUngrab
1336 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1340 wwin
= wWindowFor(event
->xfocus
.window
);
1341 if (wwin
&& !wwin
->flags
.focused
) {
1342 if (wwin
->flags
.mapped
)
1343 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1345 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1347 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1349 wSetFocusTo(scr
, NULL
);
1353 static WWindow
*windowUnderPointer(WScreen
* scr
)
1359 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1360 return wWindowFor(win
);
1364 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1366 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1372 static void handleKeyPress(XEvent
* event
)
1374 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1375 WWindow
*wwin
= scr
->focused_window
;
1379 #ifdef KEEP_XKB_LOCK_STATUS
1380 XkbStateRec staterec
;
1381 #endif /*KEEP_XKB_LOCK_STATUS */
1383 /* ignore CapsLock */
1384 modifiers
= event
->xkey
.state
& w_global
.shortcut
.modifiers_mask
;
1386 for (i
= 0; i
< WKBD_LAST
; i
++) {
1387 if (wKeyBindings
[i
].keycode
== 0)
1390 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1391 || */ wKeyBindings
[i
].modifier
==
1400 if (!wRootMenuPerformShortcut(event
)) {
1401 static int dontLoop
= 0;
1403 if (dontLoop
> 10) {
1404 wwarning("problem with key event processing code");
1408 /* if the focused window is an internal window, try redispatching
1409 * the event to the managed window, as it can be a WINGs window */
1410 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1411 /* client_leader contains the WINGs toplevel */
1412 event
->xany
.window
= wwin
->client_leader
;
1413 WMHandleEvent(event
);
1419 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1420 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1425 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1426 if (!CheckFullScreenWindowFocused(scr
)) {
1427 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1428 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1432 case WKBD_WINDOWLIST
:
1433 if (!CheckFullScreenWindowFocused(scr
)) {
1434 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1435 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1440 case WKBD_WINDOWMENU
:
1441 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1442 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1444 case WKBD_MINIMIZEALL
:
1445 CloseWindowMenu(scr
);
1448 case WKBD_MINIATURIZE
:
1449 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1450 && !WFLAGP(wwin
, no_miniaturizable
)) {
1451 CloseWindowMenu(scr
);
1453 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1454 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
, event
->xbutton
.time
);
1456 wIconifyWindow(wwin
);
1461 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1462 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1463 CloseWindowMenu(scr
);
1465 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1466 wHideApplication(wapp
);
1470 case WKBD_HIDE_OTHERS
:
1471 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1472 CloseWindowMenu(scr
);
1474 wHideOtherApplications(wwin
);
1478 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1479 CloseWindowMenu(scr
);
1481 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1484 case WKBD_VMAXIMIZE
:
1485 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1486 CloseWindowMenu(scr
);
1488 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1491 case WKBD_HMAXIMIZE
:
1492 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1493 CloseWindowMenu(scr
);
1495 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1498 case WKBD_LHMAXIMIZE
:
1499 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1500 CloseWindowMenu(scr
);
1502 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1505 case WKBD_RHMAXIMIZE
:
1506 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1507 CloseWindowMenu(scr
);
1509 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1512 case WKBD_THMAXIMIZE
:
1513 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1514 CloseWindowMenu(scr
);
1516 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1519 case WKBD_BHMAXIMIZE
:
1520 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1521 CloseWindowMenu(scr
);
1523 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1526 case WKBD_LTCMAXIMIZE
:
1527 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1528 CloseWindowMenu(scr
);
1530 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1533 case WKBD_RTCMAXIMIZE
:
1534 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1535 CloseWindowMenu(scr
);
1537 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1540 case WKBD_LBCMAXIMIZE
:
1541 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1542 CloseWindowMenu(scr
);
1544 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1547 case WKBD_RBCMAXIMIZE
:
1548 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1549 CloseWindowMenu(scr
);
1551 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1555 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1556 CloseWindowMenu(scr
);
1558 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1561 case WKBD_OMNIPRESENT
:
1562 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1563 CloseWindowMenu(scr
);
1565 wWindowSetOmnipresent(wwin
, !wwin
->flags
.omnipresent
);
1569 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1570 CloseWindowMenu(scr
);
1572 wRaiseFrame(wwin
->frame
->core
);
1576 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1577 CloseWindowMenu(scr
);
1579 wLowerFrame(wwin
->frame
->core
);
1582 case WKBD_RAISELOWER
:
1583 /* raise or lower the window under the pointer, not the
1586 wwin
= windowUnderPointer(scr
);
1588 wRaiseLowerFrame(wwin
->frame
->core
);
1591 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1592 if (wwin
->flags
.shaded
)
1593 wUnshadeWindow(wwin
);
1598 case WKBD_MOVERESIZE
:
1599 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1600 CloseWindowMenu(scr
);
1602 wKeyboardMoveResizeWindow(wwin
);
1606 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1607 CloseWindowMenu(scr
);
1608 if (wwin
->protocols
.DELETE_WINDOW
)
1609 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
, event
->xkey
.time
);
1613 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1614 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1618 case WKBD_WORKSPACEMAP
:
1619 if (!wPreferences
.disable_workspace_pager
)
1620 StartWorkspaceMap(scr
);
1623 case WKBD_FOCUSNEXT
:
1624 StartWindozeCycle(wwin
, event
, True
, False
);
1627 case WKBD_FOCUSPREV
:
1628 StartWindozeCycle(wwin
, event
, False
, False
);
1631 case WKBD_GROUPNEXT
:
1632 StartWindozeCycle(wwin
, event
, True
, True
);
1635 case WKBD_GROUPPREV
:
1636 StartWindozeCycle(wwin
, event
, False
, True
);
1639 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1640 widx
= command
- WKBD_WORKSPACE1
;
1641 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1642 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1643 wWorkspaceChange(scr
, i
);
1646 case WKBD_NEXTWORKSPACE
:
1647 wWorkspaceRelativeChange(scr
, 1);
1649 case WKBD_PREVWORKSPACE
:
1650 wWorkspaceRelativeChange(scr
, -1);
1652 case WKBD_LASTWORKSPACE
:
1653 wWorkspaceChange(scr
, scr
->last_workspace
);
1656 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1657 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1658 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1659 if (wwin
&& (wPreferences
.ws_advance
|| i
< scr
->workspace_count
))
1660 wWindowChangeWorkspace(wwin
, i
);
1663 case WKBD_MOVE_NEXTWORKSPACE
:
1665 wWindowChangeWorkspaceRelative(wwin
, 1);
1667 case WKBD_MOVE_PREVWORKSPACE
:
1669 wWindowChangeWorkspaceRelative(wwin
, -1);
1671 case WKBD_MOVE_LASTWORKSPACE
:
1673 wWindowChangeWorkspace(wwin
, scr
->last_workspace
);
1676 case WKBD_MOVE_NEXTWSLAYER
:
1677 case WKBD_MOVE_PREVWSLAYER
:
1682 row
= scr
->current_workspace
/ 10;
1683 column
= scr
->current_workspace
% 10;
1685 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1686 if ((row
+ 1) * 10 < scr
->workspace_count
)
1687 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1690 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1707 widx
= command
- WKBD_WINDOW1
;
1709 if (scr
->shortcutWindows
[widx
]) {
1710 WMArray
*list
= scr
->shortcutWindows
[widx
];
1712 int count
= WMGetArrayItemCount(list
);
1714 WMArrayIterator iter
;
1717 wUnselectWindows(scr
);
1718 cw
= scr
->current_workspace
;
1720 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1722 wWindowChangeWorkspace(wwin
, cw
);
1724 wMakeWindowVisible(wwin
);
1727 wSelectWindow(wwin
, True
);
1730 /* rotate the order of windows, to create a cycling effect */
1731 twin
= WMGetFromArray(list
, 0);
1732 WMDeleteFromArray(list
, 0);
1733 WMAddToArray(list
, twin
);
1735 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1736 if (scr
->shortcutWindows
[widx
]) {
1737 WMFreeArray(scr
->shortcutWindows
[widx
]);
1738 scr
->shortcutWindows
[widx
] = NULL
;
1741 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1742 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1743 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1744 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1746 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1747 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1750 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1753 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1756 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1758 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1759 if (scr
->shortcutWindows
[widx
]) {
1760 WMFreeArray(scr
->shortcutWindows
[widx
]);
1762 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1769 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1770 (void) RelaunchWindow(wwin
);
1774 case WKBD_SWITCH_SCREEN
:
1775 if (w_global
.screen_count
> 1) {
1779 /* find index of this screen */
1780 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1781 if (wScreenWithNumber(i
) == scr
)
1785 if (i
>= w_global
.screen_count
) {
1788 scr2
= wScreenWithNumber(i
);
1791 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1792 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1801 cmdline
= ExpandOptions(scr
, _("exec %A(Run,Type command to run:)"));
1804 XGrabPointer(dpy
, scr
->root_win
, True
, 0,
1805 GrabModeAsync
, GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_WAIT
], CurrentTime
);
1808 ExecuteShellCommand(scr
, cmdline
);
1811 XUngrabPointer(dpy
, CurrentTime
);
1817 case WKBD_NEXTWSLAYER
:
1818 case WKBD_PREVWSLAYER
:
1822 row
= scr
->current_workspace
/ 10;
1823 column
= scr
->current_workspace
% 10;
1825 if (command
== WKBD_NEXTWSLAYER
) {
1826 if ((row
+ 1) * 10 < scr
->workspace_count
)
1827 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1830 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1834 case WKBD_CLIPRAISELOWER
:
1835 if (!wPreferences
.flags
.noclip
)
1836 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1838 case WKBD_DOCKRAISELOWER
:
1839 if (!wPreferences
.flags
.nodock
)
1840 wDockRaiseLower(scr
->dock
);
1842 #ifdef KEEP_XKB_LOCK_STATUS
1844 if (wPreferences
.modelock
) {
1846 wwin
= scr
->focused_window
;
1848 if (wwin
&& wwin
->flags
.mapped
1849 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1850 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1851 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1853 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1854 wwin
->frame
->last_languagemode
= staterec
.group
;
1855 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1860 #endif /* KEEP_XKB_LOCK_STATUS */
1864 static void handleMotionNotify(XEvent
* event
)
1866 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1868 if (wPreferences
.scrollable_menus
) {
1869 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1870 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1872 if (scr
->flags
.jump_back_pending
||
1873 p
.x
<= (rect
.pos
.x
+ 1) ||
1874 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1875 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1878 menu
= wMenuUnderPointer(scr
);
1885 static void handleVisibilityNotify(XEvent
* event
)
1889 wwin
= wWindowFor(event
->xvisibility
.window
);
1892 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);
1895 static void handle_selection_clear(XSelectionClearEvent
*event
)
1897 WScreen
*scr
= wScreenForWindow(event
->window
);
1902 if (event
->selection
!= scr
->sn_atom
)
1905 wmessage(_("another window manager is replacing us!"));
1906 Shutdown(WSExitMode
);