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
) + 1;
1010 command
= wmalloc(len
);
1011 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
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
);
1505 case WKBD_LHMAXIMIZE
:
1506 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1507 CloseWindowMenu(scr
);
1509 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1512 case WKBD_RHMAXIMIZE
:
1513 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1514 CloseWindowMenu(scr
);
1516 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1519 case WKBD_THMAXIMIZE
:
1520 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1521 CloseWindowMenu(scr
);
1523 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1526 case WKBD_BHMAXIMIZE
:
1527 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1528 CloseWindowMenu(scr
);
1530 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1533 case WKBD_LTCMAXIMIZE
:
1534 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1535 CloseWindowMenu(scr
);
1537 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1540 case WKBD_RTCMAXIMIZE
:
1541 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1542 CloseWindowMenu(scr
);
1544 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1547 case WKBD_LBCMAXIMIZE
:
1548 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1549 CloseWindowMenu(scr
);
1551 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1554 case WKBD_RBCMAXIMIZE
:
1555 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1556 CloseWindowMenu(scr
);
1558 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1562 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1563 CloseWindowMenu(scr
);
1565 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1568 case WKBD_KEEP_ON_TOP
:
1569 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1570 CloseWindowMenu(scr
);
1572 if (wwin
->frame
->core
->stacking
->window_level
!= WMFloatingLevel
)
1573 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
1575 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
1579 case WKBD_KEEP_AT_BOTTOM
:
1580 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1581 CloseWindowMenu(scr
);
1583 if (wwin
->frame
->core
->stacking
->window_level
!= WMSunkenLevel
)
1584 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
1586 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
1589 case WKBD_OMNIPRESENT
:
1590 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1591 CloseWindowMenu(scr
);
1593 wWindowSetOmnipresent(wwin
, !wwin
->flags
.omnipresent
);
1597 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1598 CloseWindowMenu(scr
);
1600 wRaiseFrame(wwin
->frame
->core
);
1604 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1605 CloseWindowMenu(scr
);
1607 wLowerFrame(wwin
->frame
->core
);
1610 case WKBD_RAISELOWER
:
1611 /* raise or lower the window under the pointer, not the
1614 wwin
= windowUnderPointer(scr
);
1616 wRaiseLowerFrame(wwin
->frame
->core
);
1619 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1620 if (wwin
->flags
.shaded
)
1621 wUnshadeWindow(wwin
);
1626 case WKBD_MOVERESIZE
:
1627 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1628 CloseWindowMenu(scr
);
1630 wKeyboardMoveResizeWindow(wwin
);
1634 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1635 CloseWindowMenu(scr
);
1636 if (wwin
->protocols
.DELETE_WINDOW
)
1637 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
, event
->xkey
.time
);
1641 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1642 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1646 case WKBD_WORKSPACEMAP
:
1647 if (wPreferences
.enable_workspace_pager
)
1648 StartWorkspaceMap(scr
);
1651 case WKBD_FOCUSNEXT
:
1652 StartWindozeCycle(wwin
, event
, True
, False
);
1655 case WKBD_FOCUSPREV
:
1656 StartWindozeCycle(wwin
, event
, False
, False
);
1659 case WKBD_GROUPNEXT
:
1660 StartWindozeCycle(wwin
, event
, True
, True
);
1663 case WKBD_GROUPPREV
:
1664 StartWindozeCycle(wwin
, event
, False
, True
);
1667 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1668 widx
= command
- WKBD_WORKSPACE1
;
1669 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1670 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1671 wWorkspaceChange(scr
, i
);
1674 case WKBD_NEXTWORKSPACE
:
1675 wWorkspaceRelativeChange(scr
, 1);
1677 case WKBD_PREVWORKSPACE
:
1678 wWorkspaceRelativeChange(scr
, -1);
1680 case WKBD_LASTWORKSPACE
:
1681 wWorkspaceChange(scr
, scr
->last_workspace
);
1684 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1685 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1686 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1687 if (wwin
&& (wPreferences
.ws_advance
|| i
< scr
->workspace_count
))
1688 wWindowChangeWorkspace(wwin
, i
);
1691 case WKBD_MOVE_NEXTWORKSPACE
:
1693 wWindowChangeWorkspaceRelative(wwin
, 1);
1695 case WKBD_MOVE_PREVWORKSPACE
:
1697 wWindowChangeWorkspaceRelative(wwin
, -1);
1699 case WKBD_MOVE_LASTWORKSPACE
:
1701 wWindowChangeWorkspace(wwin
, scr
->last_workspace
);
1704 case WKBD_MOVE_NEXTWSLAYER
:
1705 case WKBD_MOVE_PREVWSLAYER
:
1710 row
= scr
->current_workspace
/ 10;
1711 column
= scr
->current_workspace
% 10;
1713 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1714 if ((row
+ 1) * 10 < scr
->workspace_count
)
1715 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1718 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1735 widx
= command
- WKBD_WINDOW1
;
1737 if (scr
->shortcutWindows
[widx
]) {
1738 WMArray
*list
= scr
->shortcutWindows
[widx
];
1740 int count
= WMGetArrayItemCount(list
);
1742 WMArrayIterator iter
;
1745 wUnselectWindows(scr
);
1746 cw
= scr
->current_workspace
;
1748 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1750 wWindowChangeWorkspace(wwin
, cw
);
1752 wMakeWindowVisible(wwin
);
1755 wSelectWindow(wwin
, True
);
1758 /* rotate the order of windows, to create a cycling effect */
1759 twin
= WMGetFromArray(list
, 0);
1760 WMDeleteFromArray(list
, 0);
1761 WMAddToArray(list
, twin
);
1763 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1764 if (scr
->shortcutWindows
[widx
]) {
1765 WMFreeArray(scr
->shortcutWindows
[widx
]);
1766 scr
->shortcutWindows
[widx
] = NULL
;
1769 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1770 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1771 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1772 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1774 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1775 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1778 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1781 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1784 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1786 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1787 if (scr
->shortcutWindows
[widx
]) {
1788 WMFreeArray(scr
->shortcutWindows
[widx
]);
1790 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1797 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1798 (void) RelaunchWindow(wwin
);
1802 case WKBD_SWITCH_SCREEN
:
1803 if (w_global
.screen_count
> 1) {
1807 /* find index of this screen */
1808 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1809 if (wScreenWithNumber(i
) == scr
)
1813 if (i
>= w_global
.screen_count
) {
1816 scr2
= wScreenWithNumber(i
);
1819 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1820 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1829 cmdline
= ExpandOptions(scr
, _("exec %A(Run,Type command to run:)"));
1832 XGrabPointer(dpy
, scr
->root_win
, True
, 0,
1833 GrabModeAsync
, GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_WAIT
], CurrentTime
);
1836 ExecuteShellCommand(scr
, cmdline
);
1839 XUngrabPointer(dpy
, CurrentTime
);
1845 case WKBD_NEXTWSLAYER
:
1846 case WKBD_PREVWSLAYER
:
1850 row
= scr
->current_workspace
/ 10;
1851 column
= scr
->current_workspace
% 10;
1853 if (command
== WKBD_NEXTWSLAYER
) {
1854 if ((row
+ 1) * 10 < scr
->workspace_count
)
1855 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1858 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1862 case WKBD_CLIPRAISELOWER
:
1863 if (!wPreferences
.flags
.noclip
)
1864 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1866 case WKBD_DOCKRAISELOWER
:
1867 if (!wPreferences
.flags
.nodock
)
1868 wDockRaiseLower(scr
->dock
);
1870 #ifdef KEEP_XKB_LOCK_STATUS
1872 if (wPreferences
.modelock
) {
1874 wwin
= scr
->focused_window
;
1876 if (wwin
&& wwin
->flags
.mapped
1877 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1878 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1879 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1881 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1882 wwin
->frame
->last_languagemode
= staterec
.group
;
1883 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1888 #endif /* KEEP_XKB_LOCK_STATUS */
1892 static void handleMotionNotify(XEvent
* event
)
1894 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1896 if (wPreferences
.scrollable_menus
) {
1897 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1898 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1900 if (scr
->flags
.jump_back_pending
||
1901 p
.x
<= (rect
.pos
.x
+ 1) ||
1902 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1903 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1906 menu
= wMenuUnderPointer(scr
);
1913 static void handleVisibilityNotify(XEvent
* event
)
1917 wwin
= wWindowFor(event
->xvisibility
.window
);
1920 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);
1923 static void handle_selection_request(XSelectionRequestEvent
*event
)
1925 #ifdef USE_ICCCM_WMREPLACE
1926 static Atom atom_version
= None
;
1928 XSelectionEvent notify
;
1931 * This event must be sent to the slection requester to not block him
1933 * We create it with the answer 'there is no selection' by default
1935 notify
.type
= SelectionNotify
;
1936 notify
.display
= dpy
;
1937 notify
.requestor
= event
->requestor
;
1938 notify
.selection
= event
->selection
;
1939 notify
.target
= event
->target
;
1940 notify
.property
= None
; /* This says that there is no selection */
1941 notify
.time
= event
->time
;
1943 scr
= wScreenForWindow(event
->owner
);
1945 goto not_our_selection
;
1947 if (event
->owner
!= scr
->info_window
)
1948 goto not_our_selection
;
1950 if (event
->selection
!= scr
->sn_atom
)
1951 goto not_our_selection
;
1953 if (atom_version
== None
)
1954 atom_version
= XInternAtom(dpy
, "VERSION", False
);
1956 if (event
->target
== atom_version
) {
1957 static const long icccm_version
[] = { 2, 0 };
1960 * This protocol is defined in ICCCM 2.0:
1961 * http://www.x.org/releases/X11R7.7/doc/xorg-docs/icccm/icccm.html
1962 * "Communication with the Window Manager by Means of Selections"
1966 * Setting the property means the content of the selection is available
1967 * According to the ICCCM spec, we need to support being asked for a property
1968 * set to 'None' for compatibility with old clients
1970 notify
.property
= (event
->property
== None
)?(event
->target
):(event
->property
);
1972 XChangeProperty(dpy
, event
->requestor
, notify
.property
,
1973 XA_INTEGER
, 32, PropModeReplace
,
1974 (unsigned char *) icccm_version
, wlengthof(icccm_version
));
1978 if (notify
.property
== None
)
1979 wwarning("received SelectionRequest(%s) for target=\"%s\" from requestor 0x%lX but we have no answer",
1980 XGetAtomName(dpy
, event
->selection
), XGetAtomName(dpy
, event
->target
), (long) event
->requestor
);
1982 /* Send the answer to the requestor */
1983 XSendEvent(dpy
, event
->requestor
, False
, 0L, (XEvent
*) ¬ify
);
1987 * If the support for ICCCM window manager replacement was not enabled, we should not receive
1988 * this kind of event, so we just ignore it (Conceptually, we should reply with 'SelectionNotify'
1989 * event with property set to 'None' to tell that we don't have this selection, but that is a bit
1990 * costly for an event that shall never happen).
1996 static void handle_selection_clear(XSelectionClearEvent
*event
)
1998 #ifdef USE_ICCCM_WMREPLACE
1999 WScreen
*scr
= wScreenForWindow(event
->window
);
2004 if (event
->selection
!= scr
->sn_atom
)
2007 wmessage(_("another window manager is replacing us!"));
2008 Shutdown(WSExitMode
);
2011 * If the support for ICCCM window manager replacement was not enabled, we should not receive
2012 * this kind of event, so we simply do nothing.