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>
40 #include <X11/Xatom.h>
42 # include <X11/extensions/shape.h>
49 #include <X11/extensions/Xrandr.h>
52 #ifdef KEEP_XKB_LOCK_STATUS
53 #include <X11/XKBlib.h>
54 #endif /* KEEP_XKB_LOCK_STATUS */
56 #include "WindowMaker.h"
63 #include "application.h"
66 #include "workspace.h"
69 #include "properties.h"
80 #include "switchmenu.h"
84 #define MOD_MASK wPreferences.modifier_mask
86 /************ Local stuff ***********/
88 static void saveTimestamp(XEvent
*event
);
89 static void handleColormapNotify(XEvent
*event
);
90 static void handleMapNotify(XEvent
*event
);
91 static void handleUnmapNotify(XEvent
*event
);
92 static void handleButtonPress(XEvent
*event
);
93 static void handleExpose(XEvent
*event
);
94 static void handleDestroyNotify(XEvent
*event
);
95 static void handleConfigureRequest(XEvent
*event
);
96 static void handleMapRequest(XEvent
*event
);
97 static void handlePropertyNotify(XEvent
*event
);
98 static void handleEnterNotify(XEvent
*event
);
99 static void handleLeaveNotify(XEvent
*event
);
100 static void handleExtensions(XEvent
*event
);
101 static void handleClientMessage(XEvent
*event
);
102 static void handleKeyPress(XEvent
*event
);
103 static void handleFocusIn(XEvent
*event
);
104 static void handleMotionNotify(XEvent
*event
);
105 static void handleVisibilityNotify(XEvent
*event
);
106 static void handle_inotify_events(void);
107 static void handle_selection_request(XSelectionRequestEvent
*event
);
108 static void handle_selection_clear(XSelectionClearEvent
*event
);
109 static void wdelete_death_handler(WMagicNumber id
);
113 static void handleShapeNotify(XEvent
*event
);
116 #ifdef KEEP_XKB_LOCK_STATUS
117 static void handleXkbIndicatorStateNotify(XkbEvent
*event
);
120 /* real dead process handler */
121 static void handleDeadProcess(void);
123 typedef struct DeadProcesses
{
125 unsigned char exit_status
;
128 /* stack of dead processes */
129 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
130 static int deadProcessPtr
= 0;
132 typedef struct DeathHandler
{
133 WDeathHandler
*callback
;
138 static WMArray
*deathHandlers
= NULL
;
140 WMagicNumber
wAddDeathHandler(pid_t pid
, WDeathHandler
* callback
, void *cdata
)
142 DeathHandler
*handler
;
144 handler
= malloc(sizeof(DeathHandler
));
149 handler
->callback
= callback
;
150 handler
->client_data
= cdata
;
153 deathHandlers
= WMCreateArrayWithDestructor(8, free
);
155 WMAddToArray(deathHandlers
, handler
);
160 static void wdelete_death_handler(WMagicNumber id
)
162 DeathHandler
*handler
= (DeathHandler
*) id
;
164 if (!handler
|| !deathHandlers
)
167 /* array destructor will call free(handler) */
168 WMRemoveFromArray(deathHandlers
, handler
);
171 void DispatchEvent(XEvent
* event
)
176 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
177 WCHANGE_STATE(WSTATE_EXITING
);
178 /* received SIGTERM */
180 * WMHandleEvent() can't be called from anything
181 * executed inside here, or we can get in a infinite
184 Shutdown(WSExitMode
);
186 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
187 WCHANGE_STATE(WSTATE_RESTARTING
);
189 Shutdown(WSRestartPreparationMode
);
190 /* received SIGHUP */
192 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
193 WCHANGE_STATE(WSTATE_NORMAL
);
194 wDefaultsCheckDomains(NULL
);
197 /* for the case that all that is wanted to be dispatched is
202 saveTimestamp(event
);
203 switch (event
->type
) {
205 handleMapRequest(event
);
209 handleKeyPress(event
);
213 handleMotionNotify(event
);
216 case ConfigureRequest
:
217 handleConfigureRequest(event
);
221 handleDestroyNotify(event
);
225 handleMapNotify(event
);
229 handleUnmapNotify(event
);
233 handleButtonPress(event
);
241 handlePropertyNotify(event
);
245 handleEnterNotify(event
);
249 handleLeaveNotify(event
);
253 handleClientMessage(event
);
257 handleColormapNotify(event
);
261 if (event
->xmapping
.request
== MappingKeyboard
|| event
->xmapping
.request
== MappingModifier
)
262 XRefreshKeyboardMapping(&event
->xmapping
);
266 handleFocusIn(event
);
269 case VisibilityNotify
:
270 handleVisibilityNotify(event
);
273 case ConfigureNotify
:
275 if (event
->xconfigure
.window
== DefaultRootWindow(dpy
))
276 XRRUpdateConfiguration(event
);
280 case SelectionRequest
:
281 handle_selection_request(&event
->xselectionrequest
);
285 handle_selection_clear(&event
->xselectionclear
);
289 handleExtensions(event
);
296 *----------------------------------------------------------------------
297 * handle_inotify_events-
298 * Check for inotify events
301 * After reading events for the given file descriptor (fd) and
302 * watch descriptor (wd)
305 * Calls wDefaultsCheckDomains if config database is updated
306 *----------------------------------------------------------------------
308 static void handle_inotify_events(void)
310 ssize_t eventQLength
;
312 /* Make room for at lease 5 simultaneous events, with path + filenames */
313 char buff
[ (sizeof(struct inotify_event
) + NAME_MAX
+ 1) * 5 ];
314 /* Check config only once per read of the event queue */
318 * Read off the queued events
319 * queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
320 * not occur; the block is on Xevents, but a config file change will normally
321 * occur as a result of an Xevent - so the event queue should never have more than
322 * a few entries before a read().
324 eventQLength
= read(w_global
.inotify
.fd_event_queue
,
325 buff
, sizeof(buff
) );
327 if (eventQLength
< 0) {
328 wwarning(_("read problem when trying to get INotify event: %s"), strerror(errno
));
332 /* check what events occurred */
333 /* Should really check wd here too, but for now we only have one watch! */
334 while (i
< eventQLength
) {
335 struct inotify_event
*pevent
= (struct inotify_event
*)&buff
[i
];
338 * see inotify.h for event types.
340 if (pevent
->mask
& IN_DELETE_SELF
) {
341 wwarning(_("the defaults database has been deleted!"
342 " Restart Window Maker to create the database" " with the default settings"));
344 if (w_global
.inotify
.fd_event_queue
>= 0) {
345 close(w_global
.inotify
.fd_event_queue
);
346 w_global
.inotify
.fd_event_queue
= -1;
349 if (pevent
->mask
& IN_UNMOUNT
) {
350 wwarning(_("the unit containing the defaults database has"
351 " been unmounted. Setting --static mode." " Any changes will not be saved."));
353 if (w_global
.inotify
.fd_event_queue
>= 0) {
354 close(w_global
.inotify
.fd_event_queue
);
355 w_global
.inotify
.fd_event_queue
= -1;
358 wPreferences
.flags
.noupdates
= 1;
360 if ((pevent
->mask
& IN_MODIFY
) && oneShotFlag
== 0) {
361 wwarning(_("Inotify: Reading config files in defaults database."));
362 wDefaultsCheckDomains(NULL
);
366 /* move to next event in the buffer */
367 i
+= sizeof(struct inotify_event
) + pevent
->len
;
370 #endif /* HAVE_INOTIFY */
373 *----------------------------------------------------------------------
375 * Processes X and internal events indefinitely.
381 * The LastTimestamp global variable is updated.
382 * Calls inotifyGetEvents if defaults database changes.
383 *----------------------------------------------------------------------
385 noreturn
void EventLoop(void)
393 if (w_global
.inotify
.fd_event_queue
< 0 || w_global
.inotify
.wd_defaults
< 0)
399 WMNextEvent(dpy
, &event
); /* Blocks here */
400 WMHandleEvent(&event
);
406 FD_SET(w_global
.inotify
.fd_event_queue
, &rfds
);
408 /* check for available read data from inotify - don't block! */
409 retVal
= select(w_global
.inotify
.fd_event_queue
+ 1, &rfds
, NULL
, NULL
, &time
);
411 if (retVal
< 0) { /* an error has occurred */
412 wwarning(_("select failed. The inotify instance will be closed."
413 " Changes to the defaults database will require"
414 " a restart to take effect."));
415 close(w_global
.inotify
.fd_event_queue
);
416 w_global
.inotify
.fd_event_queue
= -1;
419 if (FD_ISSET(w_global
.inotify
.fd_event_queue
, &rfds
))
420 handle_inotify_events();
427 *----------------------------------------------------------------------
428 * ProcessPendingEvents --
429 * Processes the events that are currently pending (at the time
430 * this function is called) in the display's queue.
433 * After the pending events that were present at the function call
437 * Many -- whatever handling events may involve.
439 *----------------------------------------------------------------------
441 void ProcessPendingEvents(void)
448 /* Take a snapshot of the event count in the queue */
449 count
= XPending(dpy
);
451 while (count
> 0 && XPending(dpy
)) {
452 WMNextEvent(dpy
, &event
);
453 WMHandleEvent(&event
);
458 Bool
IsDoubleClick(WScreen
* scr
, XEvent
* event
)
460 if ((scr
->last_click_time
> 0) &&
461 (event
->xbutton
.time
- scr
->last_click_time
<= wPreferences
.dblclick_time
)
462 && (event
->xbutton
.button
== scr
->last_click_button
)
463 && (event
->xbutton
.window
== scr
->last_click_window
)) {
465 scr
->flags
.next_click_is_not_double
= 1;
466 scr
->last_click_time
= 0;
467 scr
->last_click_window
= event
->xbutton
.window
;
474 void NotifyDeadProcess(pid_t pid
, unsigned char status
)
476 if (deadProcessPtr
>= MAX_DEAD_PROCESSES
- 1) {
477 wwarning("stack overflow: too many dead processes");
480 /* stack the process to be handled later,
481 * as this is called from the signal handler */
482 deadProcesses
[deadProcessPtr
].pid
= pid
;
483 deadProcesses
[deadProcessPtr
].exit_status
= status
;
487 static void handleDeadProcess(void)
492 for (i
= 0; i
< deadProcessPtr
; i
++) {
493 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
496 if (!deathHandlers
) {
501 /* get the pids on the queue and call handlers */
502 while (deadProcessPtr
> 0) {
505 for (i
= WMGetArrayItemCount(deathHandlers
) - 1; i
>= 0; i
--) {
506 tmp
= WMGetFromArray(deathHandlers
, i
);
510 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
511 (*tmp
->callback
) (tmp
->pid
,
512 deadProcesses
[deadProcessPtr
].exit_status
, tmp
->client_data
);
513 wdelete_death_handler(tmp
);
519 static void saveTimestamp(XEvent
* event
)
522 * Never save CurrentTime as LastTimestamp because CurrentTime
523 * it's not a real timestamp (it's the 0L constant)
526 switch (event
->type
) {
529 w_global
.timestamp
.last_event
= event
->xbutton
.time
;
533 w_global
.timestamp
.last_event
= event
->xkey
.time
;
536 w_global
.timestamp
.last_event
= event
->xmotion
.time
;
539 w_global
.timestamp
.last_event
= event
->xproperty
.time
;
543 w_global
.timestamp
.last_event
= event
->xcrossing
.time
;
546 w_global
.timestamp
.last_event
= event
->xselectionclear
.time
;
548 case SelectionRequest
:
549 w_global
.timestamp
.last_event
= event
->xselectionrequest
.time
;
551 case SelectionNotify
:
552 w_global
.timestamp
.last_event
= event
->xselection
.time
;
554 wXDNDProcessSelection(event
);
560 static int matchWindow(const void *item
, const void *cdata
)
562 return (((WFakeGroupLeader
*) item
)->origLeader
== (Window
) cdata
);
565 static void handleExtensions(XEvent
* event
)
568 if (w_global
.xext
.shape
.supported
&& event
->type
== (w_global
.xext
.shape
.event_base
+ ShapeNotify
)) {
569 handleShapeNotify(event
);
572 #ifdef KEEP_XKB_LOCK_STATUS
573 if (wPreferences
.modelock
&& (event
->type
== w_global
.xext
.xkb
.event_base
)) {
574 handleXkbIndicatorStateNotify((XkbEvent
*) event
);
576 #endif /*KEEP_XKB_LOCK_STATUS */
578 if (w_global
.xext
.randr
.supported
&& event
->type
== (w_global
.xext
.randr
.event_base
+ RRScreenChangeNotify
)) {
579 /* From xrandr man page: "Clients must call back into Xlib using
580 * XRRUpdateConfiguration when screen configuration change notify
581 * events are generated */
582 XRRUpdateConfiguration(event
);
583 WCHANGE_STATE(WSTATE_RESTARTING
);
584 Shutdown(WSRestartPreparationMode
);
590 static void handleMapRequest(XEvent
* ev
)
594 Window window
= ev
->xmaprequest
.window
;
596 wwin
= wWindowFor(window
);
598 if (wwin
->flags
.shaded
) {
599 wUnshadeWindow(wwin
);
601 /* deiconify window */
602 if (wwin
->flags
.miniaturized
) {
603 wDeiconifyWindow(wwin
);
604 } else if (wwin
->flags
.hidden
) {
605 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
606 /* go to the last workspace that the user worked on the app */
608 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
610 wUnhideApplication(wapp
, False
, False
);
615 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
617 wwin
= wManageWindow(scr
, window
);
620 * This is to let the Dock know that the application it launched
621 * has already been mapped (eg: it has finished launching).
622 * It is not necessary for normally docked apps, but is needed for
623 * apps that were forcedly docked (like with dockit).
625 if (scr
->last_dock
) {
626 if (wwin
&& wwin
->main_window
!= None
&& wwin
->main_window
!= window
)
627 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
629 wDockTrackWindowLaunch(scr
->last_dock
, window
);
633 wClientSetState(wwin
, NormalState
, None
);
634 if (wwin
->flags
.maximized
) {
635 wMaximizeWindow(wwin
, wwin
->flags
.maximized
,
636 wGetHeadForWindow(wwin
));
638 if (wwin
->flags
.shaded
) {
639 wwin
->flags
.shaded
= 0;
640 wwin
->flags
.skip_next_animation
= 1;
643 if (wwin
->flags
.miniaturized
) {
644 wwin
->flags
.miniaturized
= 0;
645 wwin
->flags
.skip_next_animation
= 1;
646 wIconifyWindow(wwin
);
648 if (wwin
->flags
.fullscreen
) {
649 wwin
->flags
.fullscreen
= 0;
650 wFullscreenWindow(wwin
);
652 if (wwin
->flags
.hidden
) {
653 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
655 wwin
->flags
.hidden
= 0;
656 wwin
->flags
.skip_next_animation
= 1;
658 wHideApplication(wapp
);
664 static void handleDestroyNotify(XEvent
* event
)
668 Window window
= event
->xdestroywindow
.window
;
669 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
672 wwin
= wWindowFor(window
);
674 wUnmanageWindow(wwin
, False
, True
);
678 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
679 WFakeGroupLeader
*fPtr
;
681 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
682 if (fPtr
->retainCount
> 0) {
684 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
685 XDestroyWindow(dpy
, fPtr
->leader
);
690 fPtr
->origLeader
= None
;
694 app
= wApplicationOf(window
);
696 if (window
== app
->main_window
) {
698 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
700 if (wwin
->main_window
== window
) {
701 wwin
->main_window
= None
;
706 wApplicationDestroy(app
);
710 static void handleExpose(XEvent
* event
)
712 WObjDescriptor
*desc
;
715 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
717 if (XFindContext(dpy
, event
->xexpose
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
721 if (desc
->handle_expose
) {
722 (*desc
->handle_expose
) (desc
, event
);
726 static void executeWheelAction(WScreen
*scr
, XEvent
*event
, int action
)
731 if (event
->xbutton
.button
== Button5
|| event
->xbutton
.button
== Button6
)
732 next_direction
= False
;
734 next_direction
= True
;
737 case WA_SWITCH_WORKSPACES
:
739 wWorkspaceRelativeChange(scr
, 1);
741 wWorkspaceRelativeChange(scr
, -1);
744 case WA_SWITCH_WINDOWS
:
745 wwin
= scr
->focused_window
;
747 wWindowFocusNext(wwin
, True
);
749 wWindowFocusPrev(wwin
, True
);
754 static void executeButtonAction(WScreen
*scr
, XEvent
*event
, int action
)
759 case WA_SELECT_WINDOWS
:
760 wUnselectWindows(scr
);
761 wSelectWindows(scr
, event
);
763 case WA_OPEN_APPMENU
:
764 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
766 if (scr
->root_menu
) {
767 if (scr
->root_menu
->brother
->flags
.mapped
)
768 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
770 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
773 case WA_OPEN_WINLISTMENU
:
774 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
775 if (scr
->switch_menu
) {
776 if (scr
->switch_menu
->brother
->flags
.mapped
)
777 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
779 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
782 case WA_MOVE_PREVWORKSPACE
:
783 wWorkspaceRelativeChange(scr
, -1);
785 case WA_MOVE_NEXTWORKSPACE
:
786 wWorkspaceRelativeChange(scr
, 1);
788 case WA_MOVE_PREVWINDOW
:
789 wwin
= scr
->focused_window
;
790 wWindowFocusPrev(wwin
, True
);
792 case WA_MOVE_NEXTWINDOW
:
793 wwin
= scr
->focused_window
;
794 wWindowFocusNext(wwin
, True
);
800 static void handleButtonPress(XEvent
* event
)
802 WObjDescriptor
*desc
;
805 scr
= wScreenForRootWindow(event
->xbutton
.root
);
811 if (!wPreferences
.disable_root_mouse
&& event
->xbutton
.window
== scr
->root_win
) {
812 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
813 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
814 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
815 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
816 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
817 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
818 } else if (event
->xbutton
.button
== Button8
&& wPreferences
.mouse_button8
!= WA_NONE
) {
819 executeButtonAction(scr
, event
, wPreferences
.mouse_button8
);
820 }else if (event
->xbutton
.button
== Button9
&& wPreferences
.mouse_button9
!= WA_NONE
) {
821 executeButtonAction(scr
, event
, wPreferences
.mouse_button9
);
822 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel_scroll
!= WA_NONE
) {
823 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_scroll
);
824 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel_scroll
!= WA_NONE
) {
825 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_scroll
);
826 } else if (event
->xbutton
.button
== Button6
&& wPreferences
.mouse_wheel_tilt
!= WA_NONE
) {
827 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_tilt
);
828 } else if (event
->xbutton
.button
== Button7
&& wPreferences
.mouse_wheel_tilt
!= WA_NONE
) {
829 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_tilt
);
834 if (XFindContext(dpy
, event
->xbutton
.subwindow
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
835 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
840 if (desc
->parent_type
== WCLASS_WINDOW
) {
843 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
844 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
846 /* if (wPreferences.focus_mode == WKF_CLICK) { */
847 if (wPreferences
.ignore_focus_click
) {
848 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
850 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
854 } else if (desc
->parent_type
== WCLASS_APPICON
855 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
856 if (event
->xbutton
.state
& MOD_MASK
) {
858 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
863 if (desc
->handle_mousedown
!= NULL
) {
864 (*desc
->handle_mousedown
) (desc
, event
);
867 /* save double-click information */
868 if (scr
->flags
.next_click_is_not_double
) {
869 scr
->flags
.next_click_is_not_double
= 0;
871 scr
->last_click_time
= event
->xbutton
.time
;
872 scr
->last_click_button
= event
->xbutton
.button
;
873 scr
->last_click_window
= event
->xbutton
.window
;
877 static void handleMapNotify(XEvent
* event
)
881 wwin
= wWindowFor(event
->xmap
.event
);
882 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
883 if (wwin
->flags
.miniaturized
) {
884 wDeiconifyWindow(wwin
);
888 wClientSetState(wwin
, NormalState
, None
);
894 static void handleUnmapNotify(XEvent
* event
)
898 Bool withdraw
= False
;
900 /* only process windows with StructureNotify selected
901 * (ignore SubstructureNotify) */
902 wwin
= wWindowFor(event
->xunmap
.window
);
906 /* whether the event is a Withdrawal request */
907 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
910 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
913 if (!wwin
->flags
.mapped
&& !withdraw
914 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
915 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
919 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
920 wwin
->flags
.mapped
= 0;
922 /* check if the window was destroyed */
923 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
926 Bool reparented
= False
;
928 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
931 /* withdraw window */
932 wwin
->flags
.mapped
= 0;
934 wClientSetState(wwin
, WithdrawnState
, None
);
936 /* if the window was reparented, do not reparent it back to the
938 wUnmanageWindow(wwin
, !reparented
, False
);
943 static void handleConfigureRequest(XEvent
* event
)
947 wwin
= wWindowFor(event
->xconfigurerequest
.window
);
950 * Configure request for unmapped window
952 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
954 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
958 static void handlePropertyNotify(XEvent
* event
)
966 wwin
= wWindowFor(event
->xproperty
.window
);
968 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
971 wClientCheckProperty(wwin
, &event
->xproperty
);
973 wapp
= wApplicationOf(event
->xproperty
.window
);
975 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
979 static void handleClientMessage(XEvent
* event
)
982 WObjDescriptor
*desc
;
984 /* handle transition from Normal to Iconic state */
985 if (event
->xclient
.message_type
== w_global
.atom
.wm
.change_state
986 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
988 wwin
= wWindowFor(event
->xclient
.window
);
991 if (!wwin
->flags
.miniaturized
)
992 wIconifyWindow(wwin
);
993 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.colormap_notify
&& event
->xclient
.format
== 32) {
994 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
999 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
1000 wColormapAllowClientInstallation(scr
, True
);
1001 } else { /* stopping */
1002 wColormapAllowClientInstallation(scr
, False
);
1004 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.command
) {
1009 len
= sizeof(event
->xclient
.data
.b
);
1010 command
= wmalloc(len
+ 1);
1011 strncpy(command
, event
->xclient
.data
.b
, len
);
1013 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
1014 wwarning(_("Got Reconfigure command"));
1015 wDefaultsCheckDomains(NULL
);
1017 wwarning(_("Got unknown command %s"), command
);
1022 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.wm_function
) {
1025 wapp
= wApplicationOf(event
->xclient
.window
);
1027 switch (event
->xclient
.data
.l
[0]) {
1028 case WMFHideOtherApplications
:
1029 wHideOtherApplications(wapp
->main_window_desc
);
1033 case WMFHideApplication
:
1034 wHideApplication(wapp
);
1040 wwin
= wWindowFor(event
->xclient
.window
);
1042 switch (event
->xclient
.data
.l
[0]) {
1043 case WMFHideOtherApplications
:
1044 wHideOtherApplications(wwin
);
1047 case WMFHideApplication
:
1048 wHideApplication(wApplicationOf(wwin
->main_window
));
1053 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.wm_attr
) {
1054 wwin
= wWindowFor(event
->xclient
.window
);
1057 switch (event
->xclient
.data
.l
[0]) {
1058 case GSWindowLevelAttr
:
1060 int level
= (int)event
->xclient
.data
.l
[1];
1062 if (WINDOW_LEVEL(wwin
) != level
) {
1063 ChangeStackingLevel(wwin
->frame
->core
, level
);
1068 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.titlebar_state
) {
1069 wwin
= wWindowFor(event
->xclient
.window
);
1072 switch (event
->xclient
.data
.l
[0]) {
1073 case WMTitleBarNormal
:
1074 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1076 case WMTitleBarMain
:
1077 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1080 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1083 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.ignore_focus_events
) {
1084 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1087 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1088 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1090 #ifdef USE_DOCK_XDND
1091 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1093 #endif /* USE_DOCK_XDND */
1096 * Non-standard thing, but needed by OffiX DND.
1097 * For when the icon frame gets a ClientMessage
1098 * that should have gone to the icon_window.
1100 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1101 struct WIcon
*icon
= NULL
;
1103 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1104 icon
= (WIcon
*) desc
->parent
;
1105 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1106 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1108 if (icon
&& (wwin
= icon
->owner
)) {
1109 if (wwin
->client_win
!= event
->xclient
.window
) {
1110 event
->xclient
.window
= wwin
->client_win
;
1111 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1118 static void raiseWindow(WScreen
* scr
)
1122 scr
->autoRaiseTimer
= NULL
;
1124 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1128 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1129 wRaiseFrame(wwin
->frame
->core
);
1130 /* this is needed or a race condition will occur */
1135 static void handleEnterNotify(XEvent
* event
)
1138 WObjDescriptor
*desc
= NULL
;
1140 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1142 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1143 /* already left the window... */
1145 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1150 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1151 if (desc
->handle_enternotify
)
1152 (*desc
->handle_enternotify
) (desc
, event
);
1155 /* enter to window */
1156 wwin
= wWindowFor(event
->xcrossing
.window
);
1158 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1159 wColormapInstallForWindow(scr
, NULL
);
1161 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1162 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1163 scr
->autoRaiseTimer
= NULL
;
1166 /* set auto raise timer even if in focus-follows-mouse mode
1167 * and the event is for the frame window, even if the window
1168 * has focus already. useful if you move the pointer from a focused
1169 * window to the root window and back pretty fast
1171 * set focus if in focus-follows-mouse mode and the event
1172 * is for the frame window and window doesn't have focus yet */
1173 if (wPreferences
.focus_mode
== WKF_SLOPPY
1174 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1176 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1177 wSetFocusTo(scr
, wwin
);
1179 if (scr
->autoRaiseTimer
)
1180 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1181 scr
->autoRaiseTimer
= NULL
;
1183 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1184 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1186 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1189 /* Install colormap for window, if the colormap installation mode
1190 * is colormap_follows_mouse */
1191 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1192 if (wwin
->client_win
== event
->xcrossing
.window
)
1193 wColormapInstallForWindow(scr
, wwin
);
1195 wColormapInstallForWindow(scr
, NULL
);
1199 if (event
->xcrossing
.window
== event
->xcrossing
.root
1200 && event
->xcrossing
.detail
== NotifyNormal
1201 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1203 wSetFocusTo(scr
, scr
->focused_window
);
1206 wBalloonEnteredObject(scr
, desc
);
1210 static void handleLeaveNotify(XEvent
* event
)
1212 WObjDescriptor
*desc
= NULL
;
1214 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1215 if (desc
->handle_leavenotify
)
1216 (*desc
->handle_leavenotify
) (desc
, event
);
1221 static void handleShapeNotify(XEvent
* event
)
1223 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1230 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1231 if (ev
.xshape
.kind
== ShapeBounding
) {
1232 if (ev
.xshape
.shaped
== shev
->shaped
) {
1235 XPutBackEvent(dpy
, &ev
.xevent
);
1241 wwin
= wWindowFor(shev
->window
);
1242 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1245 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1247 wwin
->flags
.shaped
= 0;
1248 wWindowClearShape(wwin
);
1250 } else if (shev
->shaped
) {
1252 wwin
->flags
.shaped
= 1;
1253 wWindowSetShape(wwin
);
1256 #endif /* USE_XSHAPE */
1258 #ifdef KEEP_XKB_LOCK_STATUS
1259 /* please help ]d if you know what to do */
1260 static void handleXkbIndicatorStateNotify(XkbEvent
*event
)
1264 XkbStateRec staterec
;
1267 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1268 scr
= wScreenWithNumber(i
);
1269 wwin
= scr
->focused_window
;
1270 if (wwin
&& wwin
->flags
.focused
) {
1271 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1272 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1273 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1274 wwin
->frame
->languagemode
= staterec
.group
;
1276 #ifdef XKB_BUTTON_HINT
1277 if (wwin
->frame
->titlebar
) {
1278 wFrameWindowPaint(wwin
->frame
);
1284 #endif /*KEEP_XKB_LOCK_STATUS */
1286 static void handleColormapNotify(XEvent
* event
)
1290 Bool reinstall
= False
;
1292 wwin
= wWindowFor(event
->xcolormap
.window
);
1296 scr
= wwin
->screen_ptr
;
1300 if (event
->xcolormap
.new) {
1301 XWindowAttributes attr
;
1303 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1305 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1306 scr
->current_colormap
= attr
.colormap
;
1309 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1310 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1312 /* some bastard app (like XV) removed our colormap */
1314 * can't enforce or things like xscreensaver won't work
1317 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1318 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1320 /* someone has put our colormap back */
1324 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1325 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1327 if (reinstall
&& scr
->current_colormap
!= None
) {
1328 if (!scr
->flags
.colormap_stuff_blocked
)
1329 XInstallColormap(dpy
, scr
->current_colormap
);
1333 static void handleFocusIn(XEvent
* event
)
1338 * For applications that like stealing the focus.
1340 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1341 saveTimestamp(event
);
1342 if (event
->xfocus
.mode
== NotifyUngrab
1343 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1347 wwin
= wWindowFor(event
->xfocus
.window
);
1348 if (wwin
&& !wwin
->flags
.focused
) {
1349 if (wwin
->flags
.mapped
)
1350 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1352 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1354 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1356 wSetFocusTo(scr
, NULL
);
1360 static WWindow
*windowUnderPointer(WScreen
* scr
)
1366 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1367 return wWindowFor(win
);
1371 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1373 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1379 static void handleKeyPress(XEvent
* event
)
1381 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1382 WWindow
*wwin
= scr
->focused_window
;
1386 #ifdef KEEP_XKB_LOCK_STATUS
1387 XkbStateRec staterec
;
1388 #endif /*KEEP_XKB_LOCK_STATUS */
1390 /* ignore CapsLock */
1391 modifiers
= event
->xkey
.state
& w_global
.shortcut
.modifiers_mask
;
1393 for (i
= 0; i
< WKBD_LAST
; i
++) {
1394 if (wKeyBindings
[i
].keycode
== 0)
1397 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1398 || */ wKeyBindings
[i
].modifier
==
1407 if (!wRootMenuPerformShortcut(event
)) {
1408 static int dontLoop
= 0;
1410 if (dontLoop
> 10) {
1411 wwarning("problem with key event processing code");
1415 /* if the focused window is an internal window, try redispatching
1416 * the event to the managed window, as it can be a WINGs window */
1417 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1418 /* client_leader contains the WINGs toplevel */
1419 event
->xany
.window
= wwin
->client_leader
;
1420 WMHandleEvent(event
);
1426 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1427 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1432 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1433 if (!CheckFullScreenWindowFocused(scr
)) {
1434 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1435 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1439 case WKBD_WINDOWLIST
:
1440 if (!CheckFullScreenWindowFocused(scr
)) {
1441 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1442 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1447 case WKBD_WINDOWMENU
:
1448 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1449 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1451 case WKBD_MINIMIZEALL
:
1452 CloseWindowMenu(scr
);
1455 case WKBD_MINIATURIZE
:
1456 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1457 && !WFLAGP(wwin
, no_miniaturizable
)) {
1458 CloseWindowMenu(scr
);
1460 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1461 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
, event
->xbutton
.time
);
1463 wIconifyWindow(wwin
);
1468 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1469 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1470 CloseWindowMenu(scr
);
1472 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1473 wHideApplication(wapp
);
1477 case WKBD_HIDE_OTHERS
:
1478 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1479 CloseWindowMenu(scr
);
1481 wHideOtherApplications(wwin
);
1485 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1486 CloseWindowMenu(scr
);
1488 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1491 case WKBD_VMAXIMIZE
:
1492 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1493 CloseWindowMenu(scr
);
1495 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1498 case WKBD_HMAXIMIZE
:
1499 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1500 CloseWindowMenu(scr
);
1502 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1503 movePionterToWindowCenter(wwin
);
1506 case WKBD_LHMAXIMIZE
:
1507 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1508 CloseWindowMenu(scr
);
1510 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1511 movePionterToWindowCenter(wwin
);
1514 case WKBD_RHMAXIMIZE
:
1515 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1516 CloseWindowMenu(scr
);
1518 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1519 movePionterToWindowCenter(wwin
);
1522 case WKBD_THMAXIMIZE
:
1523 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1524 CloseWindowMenu(scr
);
1526 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1527 movePionterToWindowCenter(wwin
);
1530 case WKBD_BHMAXIMIZE
:
1531 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1532 CloseWindowMenu(scr
);
1534 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1535 movePionterToWindowCenter(wwin
);
1538 case WKBD_LTCMAXIMIZE
:
1539 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1540 CloseWindowMenu(scr
);
1542 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1543 movePionterToWindowCenter(wwin
);
1546 case WKBD_RTCMAXIMIZE
:
1547 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1548 CloseWindowMenu(scr
);
1550 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1551 movePionterToWindowCenter(wwin
);
1554 case WKBD_LBCMAXIMIZE
:
1555 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1556 CloseWindowMenu(scr
);
1558 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1559 movePionterToWindowCenter(wwin
);
1562 case WKBD_RBCMAXIMIZE
:
1563 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1564 CloseWindowMenu(scr
);
1566 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1567 movePionterToWindowCenter(wwin
);
1571 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1572 CloseWindowMenu(scr
);
1574 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1577 case WKBD_KEEP_ON_TOP
:
1578 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1579 CloseWindowMenu(scr
);
1581 if (wwin
->frame
->core
->stacking
->window_level
!= WMFloatingLevel
)
1582 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
1584 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
1588 case WKBD_KEEP_AT_BOTTOM
:
1589 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1590 CloseWindowMenu(scr
);
1592 if (wwin
->frame
->core
->stacking
->window_level
!= WMSunkenLevel
)
1593 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
1595 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
1598 case WKBD_OMNIPRESENT
:
1599 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1600 CloseWindowMenu(scr
);
1602 wWindowSetOmnipresent(wwin
, !wwin
->flags
.omnipresent
);
1606 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1607 CloseWindowMenu(scr
);
1609 wRaiseFrame(wwin
->frame
->core
);
1613 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1614 CloseWindowMenu(scr
);
1616 wLowerFrame(wwin
->frame
->core
);
1619 case WKBD_RAISELOWER
:
1620 /* raise or lower the window under the pointer, not the
1623 wwin
= windowUnderPointer(scr
);
1625 wRaiseLowerFrame(wwin
->frame
->core
);
1628 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1629 if (wwin
->flags
.shaded
)
1630 wUnshadeWindow(wwin
);
1635 case WKBD_MOVERESIZE
:
1636 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1637 CloseWindowMenu(scr
);
1639 wKeyboardMoveResizeWindow(wwin
);
1643 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1644 CloseWindowMenu(scr
);
1645 if (wwin
->protocols
.DELETE_WINDOW
)
1646 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
, event
->xkey
.time
);
1650 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1651 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1655 case WKBD_WORKSPACEMAP
:
1656 if (wPreferences
.enable_workspace_pager
)
1657 StartWorkspaceMap(scr
);
1660 case WKBD_FOCUSNEXT
:
1661 StartWindozeCycle(wwin
, event
, True
, False
);
1664 case WKBD_FOCUSPREV
:
1665 StartWindozeCycle(wwin
, event
, False
, False
);
1668 case WKBD_GROUPNEXT
:
1669 StartWindozeCycle(wwin
, event
, True
, True
);
1672 case WKBD_GROUPPREV
:
1673 StartWindozeCycle(wwin
, event
, False
, True
);
1676 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1677 widx
= command
- WKBD_WORKSPACE1
;
1678 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1679 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1680 wWorkspaceChange(scr
, i
);
1683 case WKBD_NEXTWORKSPACE
:
1684 wWorkspaceRelativeChange(scr
, 1);
1686 case WKBD_PREVWORKSPACE
:
1687 wWorkspaceRelativeChange(scr
, -1);
1689 case WKBD_LASTWORKSPACE
:
1690 wWorkspaceChange(scr
, scr
->last_workspace
);
1693 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1694 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1695 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1696 if (wwin
&& (wPreferences
.ws_advance
|| i
< scr
->workspace_count
))
1697 wWindowChangeWorkspace(wwin
, i
);
1700 case WKBD_MOVE_NEXTWORKSPACE
:
1702 wWindowChangeWorkspaceRelative(wwin
, 1);
1704 case WKBD_MOVE_PREVWORKSPACE
:
1706 wWindowChangeWorkspaceRelative(wwin
, -1);
1708 case WKBD_MOVE_LASTWORKSPACE
:
1710 wWindowChangeWorkspace(wwin
, scr
->last_workspace
);
1713 case WKBD_MOVE_NEXTWSLAYER
:
1714 case WKBD_MOVE_PREVWSLAYER
:
1719 row
= scr
->current_workspace
/ 10;
1720 column
= scr
->current_workspace
% 10;
1722 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1723 if ((row
+ 1) * 10 < scr
->workspace_count
)
1724 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1727 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1744 widx
= command
- WKBD_WINDOW1
;
1746 if (scr
->shortcutWindows
[widx
]) {
1747 WMArray
*list
= scr
->shortcutWindows
[widx
];
1749 int count
= WMGetArrayItemCount(list
);
1751 WMArrayIterator iter
;
1754 wUnselectWindows(scr
);
1755 cw
= scr
->current_workspace
;
1757 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1759 wWindowChangeWorkspace(wwin
, cw
);
1761 wMakeWindowVisible(wwin
);
1764 wSelectWindow(wwin
, True
);
1767 /* rotate the order of windows, to create a cycling effect */
1768 twin
= WMGetFromArray(list
, 0);
1769 WMDeleteFromArray(list
, 0);
1770 WMAddToArray(list
, twin
);
1772 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1773 if (scr
->shortcutWindows
[widx
]) {
1774 WMFreeArray(scr
->shortcutWindows
[widx
]);
1775 scr
->shortcutWindows
[widx
] = NULL
;
1778 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1779 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1780 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1781 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1783 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1784 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1787 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1790 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1793 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1795 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1796 if (scr
->shortcutWindows
[widx
]) {
1797 WMFreeArray(scr
->shortcutWindows
[widx
]);
1799 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1805 case WKBD_MOVE_12_TO_6_HEAD
:
1806 case WKBD_MOVE_6_TO_12_HEAD
:
1808 moveBetweenHeads(wwin
, command
- WKBD_MOVE_12_TO_6_HEAD
);
1813 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1814 (void) RelaunchWindow(wwin
);
1818 case WKBD_SWITCH_SCREEN
:
1819 if (w_global
.screen_count
> 1) {
1823 /* find index of this screen */
1824 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1825 if (wScreenWithNumber(i
) == scr
)
1829 if (i
>= w_global
.screen_count
) {
1832 scr2
= wScreenWithNumber(i
);
1835 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1836 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1845 cmdline
= ExpandOptions(scr
, _("exec %A(Run,Type command to run:)"));
1848 XGrabPointer(dpy
, scr
->root_win
, True
, 0,
1849 GrabModeAsync
, GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_WAIT
], CurrentTime
);
1852 ExecuteShellCommand(scr
, cmdline
);
1855 XUngrabPointer(dpy
, CurrentTime
);
1861 case WKBD_NEXTWSLAYER
:
1862 case WKBD_PREVWSLAYER
:
1866 row
= scr
->current_workspace
/ 10;
1867 column
= scr
->current_workspace
% 10;
1869 if (command
== WKBD_NEXTWSLAYER
) {
1870 if ((row
+ 1) * 10 < scr
->workspace_count
)
1871 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1874 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1878 case WKBD_CLIPRAISELOWER
:
1879 if (!wPreferences
.flags
.noclip
)
1880 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1882 case WKBD_DOCKRAISELOWER
:
1883 if (!wPreferences
.flags
.nodock
)
1884 wDockRaiseLower(scr
->dock
);
1886 #ifdef KEEP_XKB_LOCK_STATUS
1888 if (wPreferences
.modelock
) {
1890 wwin
= scr
->focused_window
;
1892 if (wwin
&& wwin
->flags
.mapped
1893 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1894 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1895 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1897 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1898 wwin
->frame
->last_languagemode
= staterec
.group
;
1899 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1904 #endif /* KEEP_XKB_LOCK_STATUS */
1908 static void handleMotionNotify(XEvent
* event
)
1910 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1912 if (wPreferences
.scrollable_menus
) {
1913 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1914 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1916 if (scr
->flags
.jump_back_pending
||
1917 p
.x
<= (rect
.pos
.x
+ 1) ||
1918 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1919 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1922 menu
= wMenuUnderPointer(scr
);
1929 static void handleVisibilityNotify(XEvent
* event
)
1933 wwin
= wWindowFor(event
->xvisibility
.window
);
1936 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);
1939 static void handle_selection_request(XSelectionRequestEvent
*event
)
1941 #ifdef USE_ICCCM_WMREPLACE
1942 static Atom atom_version
= None
;
1944 XSelectionEvent notify
;
1947 * This event must be sent to the slection requester to not block him
1949 * We create it with the answer 'there is no selection' by default
1951 notify
.type
= SelectionNotify
;
1952 notify
.display
= dpy
;
1953 notify
.requestor
= event
->requestor
;
1954 notify
.selection
= event
->selection
;
1955 notify
.target
= event
->target
;
1956 notify
.property
= None
; /* This says that there is no selection */
1957 notify
.time
= event
->time
;
1959 scr
= wScreenForWindow(event
->owner
);
1961 goto not_our_selection
;
1963 if (event
->owner
!= scr
->info_window
)
1964 goto not_our_selection
;
1966 if (event
->selection
!= scr
->sn_atom
)
1967 goto not_our_selection
;
1969 if (atom_version
== None
)
1970 atom_version
= XInternAtom(dpy
, "VERSION", False
);
1972 if (event
->target
== atom_version
) {
1973 static const long icccm_version
[] = { 2, 0 };
1976 * This protocol is defined in ICCCM 2.0:
1977 * http://www.x.org/releases/X11R7.7/doc/xorg-docs/icccm/icccm.html
1978 * "Communication with the Window Manager by Means of Selections"
1982 * Setting the property means the content of the selection is available
1983 * According to the ICCCM spec, we need to support being asked for a property
1984 * set to 'None' for compatibility with old clients
1986 notify
.property
= (event
->property
== None
)?(event
->target
):(event
->property
);
1988 XChangeProperty(dpy
, event
->requestor
, notify
.property
,
1989 XA_INTEGER
, 32, PropModeReplace
,
1990 (unsigned char *) icccm_version
, wlengthof(icccm_version
));
1994 if (notify
.property
== None
)
1995 wwarning("received SelectionRequest(%s) for target=\"%s\" from requestor 0x%lX but we have no answer",
1996 XGetAtomName(dpy
, event
->selection
), XGetAtomName(dpy
, event
->target
), (long) event
->requestor
);
1998 /* Send the answer to the requestor */
1999 XSendEvent(dpy
, event
->requestor
, False
, 0L, (XEvent
*) ¬ify
);
2003 * If the support for ICCCM window manager replacement was not enabled, we should not receive
2004 * this kind of event, so we just ignore it (Conceptually, we should reply with 'SelectionNotify'
2005 * event with property set to 'None' to tell that we don't have this selection, but that is a bit
2006 * costly for an event that shall never happen).
2012 static void handle_selection_clear(XSelectionClearEvent
*event
)
2014 #ifdef USE_ICCCM_WMREPLACE
2015 WScreen
*scr
= wScreenForWindow(event
->window
);
2020 if (event
->selection
!= scr
->sn_atom
)
2023 wmessage(_("another window manager is replacing us!"));
2024 Shutdown(WSExitMode
);
2027 * If the support for ICCCM window manager replacement was not enabled, we should not receive
2028 * this kind of event, so we simply do nothing.