1 /* event.c- event loop and handling
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 2014-2023 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
);
762 if (wPreferences
.close_rootmenu_left_right_click
){
764 WMPropList
*definition
;
765 menu
= scr
->root_menu
;
767 wMenuDestroy(menu
,True
);
768 scr
->root_menu
= NULL
;
769 definition
= w_global
.domain
.root_menu
->dictionary
;
770 menu
= configureMenu(scr
, definition
);
771 scr
->root_menu
= menu
;
775 case WA_OPEN_APPMENU
:
776 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
778 if (scr
->root_menu
) {
779 if (scr
->root_menu
->brother
->flags
.mapped
)
780 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
782 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
785 case WA_OPEN_WINLISTMENU
:
786 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
787 if (scr
->switch_menu
) {
788 if (scr
->switch_menu
->brother
->flags
.mapped
)
789 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
791 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
794 case WA_MOVE_PREVWORKSPACE
:
795 wWorkspaceRelativeChange(scr
, -1);
797 case WA_MOVE_NEXTWORKSPACE
:
798 wWorkspaceRelativeChange(scr
, 1);
800 case WA_MOVE_PREVWINDOW
:
801 wwin
= scr
->focused_window
;
802 wWindowFocusPrev(wwin
, True
);
804 case WA_MOVE_NEXTWINDOW
:
805 wwin
= scr
->focused_window
;
806 wWindowFocusNext(wwin
, True
);
812 static void handleButtonPress(XEvent
* event
)
814 WObjDescriptor
*desc
;
817 scr
= wScreenForRootWindow(event
->xbutton
.root
);
823 if (!wPreferences
.disable_root_mouse
&& event
->xbutton
.window
== scr
->root_win
) {
824 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
825 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
826 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
827 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
828 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
829 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
830 } else if (event
->xbutton
.button
== Button8
&& wPreferences
.mouse_button8
!= WA_NONE
) {
831 executeButtonAction(scr
, event
, wPreferences
.mouse_button8
);
832 }else if (event
->xbutton
.button
== Button9
&& wPreferences
.mouse_button9
!= WA_NONE
) {
833 executeButtonAction(scr
, event
, wPreferences
.mouse_button9
);
834 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel_scroll
!= WA_NONE
) {
835 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_scroll
);
836 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel_scroll
!= WA_NONE
) {
837 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_scroll
);
838 } else if (event
->xbutton
.button
== Button6
&& wPreferences
.mouse_wheel_tilt
!= WA_NONE
) {
839 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_tilt
);
840 } else if (event
->xbutton
.button
== Button7
&& wPreferences
.mouse_wheel_tilt
!= WA_NONE
) {
841 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_tilt
);
846 if (XFindContext(dpy
, event
->xbutton
.subwindow
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
847 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
852 if (desc
->parent_type
== WCLASS_WINDOW
) {
855 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
856 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
858 /* if (wPreferences.focus_mode == WKF_CLICK) { */
859 if (wPreferences
.ignore_focus_click
) {
860 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
862 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
866 } else if (desc
->parent_type
== WCLASS_APPICON
867 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
868 if (event
->xbutton
.state
& MOD_MASK
) {
870 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
875 if (desc
->handle_mousedown
!= NULL
) {
876 (*desc
->handle_mousedown
) (desc
, event
);
879 /* save double-click information */
880 if (scr
->flags
.next_click_is_not_double
) {
881 scr
->flags
.next_click_is_not_double
= 0;
883 scr
->last_click_time
= event
->xbutton
.time
;
884 scr
->last_click_button
= event
->xbutton
.button
;
885 scr
->last_click_window
= event
->xbutton
.window
;
889 static void handleMapNotify(XEvent
* event
)
893 wwin
= wWindowFor(event
->xmap
.event
);
894 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
895 if (wwin
->flags
.miniaturized
) {
896 wDeiconifyWindow(wwin
);
900 wClientSetState(wwin
, NormalState
, None
);
906 static void handleUnmapNotify(XEvent
* event
)
910 Bool withdraw
= False
;
912 /* only process windows with StructureNotify selected
913 * (ignore SubstructureNotify) */
914 wwin
= wWindowFor(event
->xunmap
.window
);
918 /* whether the event is a Withdrawal request */
919 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
922 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
925 if (!wwin
->flags
.mapped
&& !withdraw
926 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
927 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
931 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
932 wwin
->flags
.mapped
= 0;
934 /* check if the window was destroyed */
935 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
938 Bool reparented
= False
;
940 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
943 /* withdraw window */
944 wwin
->flags
.mapped
= 0;
946 wClientSetState(wwin
, WithdrawnState
, None
);
948 /* if the window was reparented, do not reparent it back to the
950 wUnmanageWindow(wwin
, !reparented
, False
);
955 static void handleConfigureRequest(XEvent
* event
)
959 wwin
= wWindowFor(event
->xconfigurerequest
.window
);
962 * Configure request for unmapped window
964 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
966 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
970 static void handlePropertyNotify(XEvent
* event
)
978 wwin
= wWindowFor(event
->xproperty
.window
);
980 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
983 wClientCheckProperty(wwin
, &event
->xproperty
);
985 wapp
= wApplicationOf(event
->xproperty
.window
);
987 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
991 static void handleClientMessage(XEvent
* event
)
994 WObjDescriptor
*desc
;
996 /* handle transition from Normal to Iconic state */
997 if (event
->xclient
.message_type
== w_global
.atom
.wm
.change_state
998 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
1000 wwin
= wWindowFor(event
->xclient
.window
);
1003 if (!wwin
->flags
.miniaturized
)
1004 wIconifyWindow(wwin
);
1005 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.colormap_notify
&& event
->xclient
.format
== 32) {
1006 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1011 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
1012 wColormapAllowClientInstallation(scr
, True
);
1013 } else { /* stopping */
1014 wColormapAllowClientInstallation(scr
, False
);
1016 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.command
) {
1021 len
= sizeof(event
->xclient
.data
.b
);
1022 command
= wmalloc(len
+ 1);
1023 strncpy(command
, event
->xclient
.data
.b
, len
);
1025 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
1026 wwarning(_("Got Reconfigure command"));
1027 wDefaultsCheckDomains(NULL
);
1029 wwarning(_("Got unknown command %s"), command
);
1034 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.wm_function
) {
1037 wapp
= wApplicationOf(event
->xclient
.window
);
1039 switch (event
->xclient
.data
.l
[0]) {
1040 case WMFHideOtherApplications
:
1041 wHideOtherApplications(wapp
->main_window_desc
);
1045 case WMFHideApplication
:
1046 wHideApplication(wapp
);
1052 wwin
= wWindowFor(event
->xclient
.window
);
1054 switch (event
->xclient
.data
.l
[0]) {
1055 case WMFHideOtherApplications
:
1056 wHideOtherApplications(wwin
);
1059 case WMFHideApplication
:
1060 wHideApplication(wApplicationOf(wwin
->main_window
));
1065 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.wm_attr
) {
1066 wwin
= wWindowFor(event
->xclient
.window
);
1069 switch (event
->xclient
.data
.l
[0]) {
1070 case GSWindowLevelAttr
:
1072 int level
= (int)event
->xclient
.data
.l
[1];
1074 if (WINDOW_LEVEL(wwin
) != level
) {
1075 ChangeStackingLevel(wwin
->frame
->core
, level
);
1080 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.titlebar_state
) {
1081 wwin
= wWindowFor(event
->xclient
.window
);
1084 switch (event
->xclient
.data
.l
[0]) {
1085 case WMTitleBarNormal
:
1086 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1088 case WMTitleBarMain
:
1089 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1092 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1095 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.ignore_focus_events
) {
1096 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1099 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1100 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1102 #ifdef USE_DOCK_XDND
1103 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1105 #endif /* USE_DOCK_XDND */
1108 * Non-standard thing, but needed by OffiX DND.
1109 * For when the icon frame gets a ClientMessage
1110 * that should have gone to the icon_window.
1112 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1113 struct WIcon
*icon
= NULL
;
1115 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1116 icon
= (WIcon
*) desc
->parent
;
1117 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1118 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1120 if (icon
&& (wwin
= icon
->owner
)) {
1121 if (wwin
->client_win
!= event
->xclient
.window
) {
1122 event
->xclient
.window
= wwin
->client_win
;
1123 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1130 static void raiseWindow(WScreen
* scr
)
1134 scr
->autoRaiseTimer
= NULL
;
1136 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1140 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1141 wRaiseFrame(wwin
->frame
->core
);
1142 /* this is needed or a race condition will occur */
1147 static void handleEnterNotify(XEvent
* event
)
1150 WObjDescriptor
*desc
= NULL
;
1152 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1154 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1155 /* already left the window... */
1157 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1162 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1163 if (desc
->handle_enternotify
)
1164 (*desc
->handle_enternotify
) (desc
, event
);
1167 /* enter to window */
1168 wwin
= wWindowFor(event
->xcrossing
.window
);
1170 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1171 wColormapInstallForWindow(scr
, NULL
);
1173 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1174 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1175 scr
->autoRaiseTimer
= NULL
;
1178 /* set auto raise timer even if in focus-follows-mouse mode
1179 * and the event is for the frame window, even if the window
1180 * has focus already. useful if you move the pointer from a focused
1181 * window to the root window and back pretty fast
1183 * set focus if in focus-follows-mouse mode and the event
1184 * is for the frame window and window doesn't have focus yet */
1185 if (wPreferences
.focus_mode
== WKF_SLOPPY
1186 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1188 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1189 wSetFocusTo(scr
, wwin
);
1191 if (scr
->autoRaiseTimer
)
1192 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1193 scr
->autoRaiseTimer
= NULL
;
1195 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1196 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1198 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1201 /* Install colormap for window, if the colormap installation mode
1202 * is colormap_follows_mouse */
1203 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1204 if (wwin
->client_win
== event
->xcrossing
.window
)
1205 wColormapInstallForWindow(scr
, wwin
);
1207 wColormapInstallForWindow(scr
, NULL
);
1211 if (event
->xcrossing
.window
== event
->xcrossing
.root
1212 && event
->xcrossing
.detail
== NotifyNormal
1213 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1215 wSetFocusTo(scr
, scr
->focused_window
);
1218 wBalloonEnteredObject(scr
, desc
);
1222 static void handleLeaveNotify(XEvent
* event
)
1224 WObjDescriptor
*desc
= NULL
;
1226 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1227 if (desc
->handle_leavenotify
)
1228 (*desc
->handle_leavenotify
) (desc
, event
);
1233 static void handleShapeNotify(XEvent
* event
)
1235 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1242 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1243 if (ev
.xshape
.kind
== ShapeBounding
) {
1244 if (ev
.xshape
.shaped
== shev
->shaped
) {
1247 XPutBackEvent(dpy
, &ev
.xevent
);
1253 wwin
= wWindowFor(shev
->window
);
1254 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1257 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1259 wwin
->flags
.shaped
= 0;
1260 wWindowClearShape(wwin
);
1262 } else if (shev
->shaped
) {
1264 wwin
->flags
.shaped
= 1;
1265 wWindowSetShape(wwin
);
1268 #endif /* USE_XSHAPE */
1270 #ifdef KEEP_XKB_LOCK_STATUS
1271 /* please help ]d if you know what to do */
1272 static void handleXkbIndicatorStateNotify(XkbEvent
*event
)
1276 XkbStateRec staterec
;
1279 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1280 scr
= wScreenWithNumber(i
);
1281 wwin
= scr
->focused_window
;
1282 if (wwin
&& wwin
->flags
.focused
) {
1283 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1284 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1285 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1286 wwin
->frame
->languagemode
= staterec
.group
;
1288 #ifdef XKB_BUTTON_HINT
1289 if (wwin
->frame
->titlebar
) {
1290 wFrameWindowPaint(wwin
->frame
);
1296 #endif /*KEEP_XKB_LOCK_STATUS */
1298 static void handleColormapNotify(XEvent
* event
)
1302 Bool reinstall
= False
;
1304 wwin
= wWindowFor(event
->xcolormap
.window
);
1308 scr
= wwin
->screen_ptr
;
1312 if (event
->xcolormap
.new) {
1313 XWindowAttributes attr
;
1315 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1317 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1318 scr
->current_colormap
= attr
.colormap
;
1321 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1322 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1324 /* some bastard app (like XV) removed our colormap */
1326 * can't enforce or things like xscreensaver won't work
1329 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1330 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1332 /* someone has put our colormap back */
1336 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1337 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1339 if (reinstall
&& scr
->current_colormap
!= None
) {
1340 if (!scr
->flags
.colormap_stuff_blocked
)
1341 XInstallColormap(dpy
, scr
->current_colormap
);
1345 static void handleFocusIn(XEvent
* event
)
1350 * For applications that like stealing the focus.
1352 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1353 saveTimestamp(event
);
1354 if (event
->xfocus
.mode
== NotifyUngrab
1355 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1359 wwin
= wWindowFor(event
->xfocus
.window
);
1360 if (wwin
&& !wwin
->flags
.focused
) {
1361 if (wwin
->flags
.mapped
)
1362 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1364 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1366 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1368 wSetFocusTo(scr
, NULL
);
1372 static WWindow
*windowUnderPointer(WScreen
* scr
)
1378 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1379 return wWindowFor(win
);
1383 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1385 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1391 static void handleKeyPress(XEvent
* event
)
1393 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1394 WWindow
*wwin
= scr
->focused_window
;
1398 #ifdef KEEP_XKB_LOCK_STATUS
1399 XkbStateRec staterec
;
1400 #endif /*KEEP_XKB_LOCK_STATUS */
1402 /* ignore CapsLock */
1403 modifiers
= event
->xkey
.state
& w_global
.shortcut
.modifiers_mask
;
1405 for (i
= 0; i
< WKBD_LAST
; i
++) {
1406 if (wKeyBindings
[i
].keycode
== 0)
1409 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1410 || */ wKeyBindings
[i
].modifier
==
1419 if (!wRootMenuPerformShortcut(event
)) {
1420 static int dontLoop
= 0;
1422 if (dontLoop
> 10) {
1423 wwarning("problem with key event processing code");
1427 /* if the focused window is an internal window, try redispatching
1428 * the event to the managed window, as it can be a WINGs window */
1429 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1430 /* client_leader contains the WINGs toplevel */
1431 event
->xany
.window
= wwin
->client_leader
;
1432 WMHandleEvent(event
);
1438 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1439 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1444 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1445 if (!CheckFullScreenWindowFocused(scr
)) {
1446 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1447 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1451 case WKBD_WINDOWLIST
:
1452 if (!CheckFullScreenWindowFocused(scr
)) {
1453 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1454 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1459 case WKBD_WINDOWMENU
:
1460 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1461 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1463 case WKBD_MINIMIZEALL
:
1464 CloseWindowMenu(scr
);
1467 case WKBD_MINIATURIZE
:
1468 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1469 && !WFLAGP(wwin
, no_miniaturizable
)) {
1470 CloseWindowMenu(scr
);
1472 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1473 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
, event
->xbutton
.time
);
1475 wIconifyWindow(wwin
);
1480 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1481 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1482 CloseWindowMenu(scr
);
1484 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1485 wHideApplication(wapp
);
1489 case WKBD_HIDE_OTHERS
:
1490 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1491 CloseWindowMenu(scr
);
1493 wHideOtherApplications(wwin
);
1497 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1498 CloseWindowMenu(scr
);
1500 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1503 case WKBD_VMAXIMIZE
:
1504 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1505 CloseWindowMenu(scr
);
1507 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1510 case WKBD_HMAXIMIZE
:
1511 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1512 CloseWindowMenu(scr
);
1514 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1515 movePointerToWindowCenter(wwin
);
1519 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1520 CloseWindowMenu(scr
);
1522 handleMaximize(wwin
, MAX_CENTRAL
| MAX_KEYBOARD
);
1523 movePointerToWindowCenter(wwin
);
1526 case WKBD_LHMAXIMIZE
:
1527 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1528 CloseWindowMenu(scr
);
1530 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1531 movePointerToWindowCenter(wwin
);
1534 case WKBD_RHMAXIMIZE
:
1535 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1536 CloseWindowMenu(scr
);
1538 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1539 movePointerToWindowCenter(wwin
);
1542 case WKBD_THMAXIMIZE
:
1543 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1544 CloseWindowMenu(scr
);
1546 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1547 movePointerToWindowCenter(wwin
);
1550 case WKBD_BHMAXIMIZE
:
1551 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1552 CloseWindowMenu(scr
);
1554 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1555 movePointerToWindowCenter(wwin
);
1558 case WKBD_LTCMAXIMIZE
:
1559 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1560 CloseWindowMenu(scr
);
1562 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1563 movePointerToWindowCenter(wwin
);
1566 case WKBD_RTCMAXIMIZE
:
1567 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1568 CloseWindowMenu(scr
);
1570 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1571 movePointerToWindowCenter(wwin
);
1574 case WKBD_LBCMAXIMIZE
:
1575 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1576 CloseWindowMenu(scr
);
1578 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1579 movePointerToWindowCenter(wwin
);
1582 case WKBD_RBCMAXIMIZE
:
1583 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1584 CloseWindowMenu(scr
);
1586 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1587 movePointerToWindowCenter(wwin
);
1591 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1592 CloseWindowMenu(scr
);
1594 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1597 case WKBD_KEEP_ON_TOP
:
1598 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1599 CloseWindowMenu(scr
);
1601 if (wwin
->frame
->core
->stacking
->window_level
!= WMFloatingLevel
)
1602 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
1604 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
1608 case WKBD_KEEP_AT_BOTTOM
:
1609 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1610 CloseWindowMenu(scr
);
1612 if (wwin
->frame
->core
->stacking
->window_level
!= WMSunkenLevel
)
1613 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
1615 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
1618 case WKBD_OMNIPRESENT
:
1619 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1620 CloseWindowMenu(scr
);
1622 wWindowSetOmnipresent(wwin
, !wwin
->flags
.omnipresent
);
1626 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1627 CloseWindowMenu(scr
);
1629 wRaiseFrame(wwin
->frame
->core
);
1633 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1634 CloseWindowMenu(scr
);
1636 wLowerFrame(wwin
->frame
->core
);
1639 case WKBD_RAISELOWER
:
1640 /* raise or lower the window under the pointer, not the
1643 wwin
= windowUnderPointer(scr
);
1645 wRaiseLowerFrame(wwin
->frame
->core
);
1648 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1649 if (wwin
->flags
.shaded
)
1650 wUnshadeWindow(wwin
);
1655 case WKBD_MOVERESIZE
:
1656 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1657 CloseWindowMenu(scr
);
1659 wKeyboardMoveResizeWindow(wwin
);
1663 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1664 CloseWindowMenu(scr
);
1665 if (wwin
->protocols
.DELETE_WINDOW
)
1666 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
, event
->xkey
.time
);
1670 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1671 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1675 case WKBD_WORKSPACEMAP
:
1676 if (wPreferences
.enable_workspace_pager
)
1677 StartWorkspaceMap(scr
);
1680 case WKBD_FOCUSNEXT
:
1681 StartWindozeCycle(wwin
, event
, True
, False
);
1684 case WKBD_FOCUSPREV
:
1685 StartWindozeCycle(wwin
, event
, False
, False
);
1688 case WKBD_GROUPNEXT
:
1689 StartWindozeCycle(wwin
, event
, True
, True
);
1692 case WKBD_GROUPPREV
:
1693 StartWindozeCycle(wwin
, event
, False
, True
);
1696 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1697 widx
= command
- WKBD_WORKSPACE1
;
1698 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1699 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1700 wWorkspaceChange(scr
, i
);
1703 case WKBD_NEXTWORKSPACE
:
1704 wWorkspaceRelativeChange(scr
, 1);
1706 case WKBD_PREVWORKSPACE
:
1707 wWorkspaceRelativeChange(scr
, -1);
1709 case WKBD_LASTWORKSPACE
:
1710 wWorkspaceChange(scr
, scr
->last_workspace
);
1713 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1714 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1715 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1716 if (wwin
&& (wPreferences
.ws_advance
|| i
< scr
->workspace_count
))
1717 wWindowChangeWorkspace(wwin
, i
);
1720 case WKBD_MOVE_NEXTWORKSPACE
:
1722 wWindowChangeWorkspaceRelative(wwin
, 1);
1724 case WKBD_MOVE_PREVWORKSPACE
:
1726 wWindowChangeWorkspaceRelative(wwin
, -1);
1728 case WKBD_MOVE_LASTWORKSPACE
:
1730 wWindowChangeWorkspace(wwin
, scr
->last_workspace
);
1733 case WKBD_MOVE_NEXTWSLAYER
:
1734 case WKBD_MOVE_PREVWSLAYER
:
1739 row
= scr
->current_workspace
/ 10;
1740 column
= scr
->current_workspace
% 10;
1742 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1743 if ((row
+ 1) * 10 < scr
->workspace_count
)
1744 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1747 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1764 widx
= command
- WKBD_WINDOW1
;
1766 if (scr
->shortcutWindows
[widx
]) {
1767 WMArray
*list
= scr
->shortcutWindows
[widx
];
1769 int count
= WMGetArrayItemCount(list
);
1771 WMArrayIterator iter
;
1774 wUnselectWindows(scr
);
1775 cw
= scr
->current_workspace
;
1777 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1779 wWindowChangeWorkspace(wwin
, cw
);
1781 wMakeWindowVisible(wwin
);
1784 wSelectWindow(wwin
, True
);
1787 /* rotate the order of windows, to create a cycling effect */
1788 twin
= WMGetFromArray(list
, 0);
1789 WMDeleteFromArray(list
, 0);
1790 WMAddToArray(list
, twin
);
1792 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1793 if (scr
->shortcutWindows
[widx
]) {
1794 WMFreeArray(scr
->shortcutWindows
[widx
]);
1795 scr
->shortcutWindows
[widx
] = NULL
;
1798 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1799 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1800 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1801 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1803 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1804 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1807 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1810 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1813 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1815 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1816 if (scr
->shortcutWindows
[widx
]) {
1817 WMFreeArray(scr
->shortcutWindows
[widx
]);
1819 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1825 case WKBD_MOVE_12_TO_6_HEAD
:
1826 case WKBD_MOVE_6_TO_12_HEAD
:
1828 moveBetweenHeads(wwin
, command
- WKBD_MOVE_12_TO_6_HEAD
);
1833 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1834 (void) RelaunchWindow(wwin
);
1838 case WKBD_SWITCH_SCREEN
:
1839 if (w_global
.screen_count
> 1) {
1843 /* find index of this screen */
1844 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1845 if (wScreenWithNumber(i
) == scr
)
1849 if (i
>= w_global
.screen_count
) {
1852 scr2
= wScreenWithNumber(i
);
1855 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1856 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1863 ExecuteInputCommand(scr
, _("exec %A(Run, Type command:)"));
1869 /* quick mode is not allowed to prevent inadvertently call */
1870 ExecuteExitCommand(scr
, 0);
1876 ScreenCapture(scr
, PRINT_SCREEN
);
1882 ScreenCapture(scr
, PRINT_WINDOW
);
1888 ScreenCapture(scr
, PRINT_PARTIAL
);
1892 case WKBD_NEXTWSLAYER
:
1893 case WKBD_PREVWSLAYER
:
1897 row
= scr
->current_workspace
/ 10;
1898 column
= scr
->current_workspace
% 10;
1900 if (command
== WKBD_NEXTWSLAYER
) {
1901 if ((row
+ 1) * 10 < scr
->workspace_count
)
1902 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1905 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1909 case WKBD_CLIPRAISELOWER
:
1910 if (!wPreferences
.flags
.noclip
)
1911 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1913 case WKBD_DOCKRAISELOWER
:
1914 if (!wPreferences
.flags
.nodock
)
1915 wDockRaiseLower(scr
->dock
);
1917 #ifdef KEEP_XKB_LOCK_STATUS
1919 if (wPreferences
.modelock
) {
1921 wwin
= scr
->focused_window
;
1923 if (wwin
&& wwin
->flags
.mapped
1924 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1925 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1926 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1928 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1929 wwin
->frame
->last_languagemode
= staterec
.group
;
1930 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1935 #endif /* KEEP_XKB_LOCK_STATUS */
1939 #define CORNER_NONE 0
1940 #define CORNER_TOPLEFT 1
1941 #define CORNER_TOPRIGHT 2
1942 #define CORNER_BOTTOMLEFT 3
1943 #define CORNER_BOTTOMRIGHT 4
1945 static int get_corner(WMRect rect
, WMPoint p
)
1947 if (p
.x
<= (rect
.pos
.x
+ wPreferences
.hot_corner_edge
) && p
.y
<= (rect
.pos
.y
+ wPreferences
.hot_corner_edge
))
1948 return CORNER_TOPLEFT
;
1949 if (p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- wPreferences
.hot_corner_edge
) && p
.y
<= (rect
.pos
.y
+ wPreferences
.hot_corner_edge
))
1950 return CORNER_TOPRIGHT
;
1951 if (p
.x
<= (rect
.pos
.x
+ wPreferences
.hot_corner_edge
) && p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- wPreferences
.hot_corner_edge
))
1952 return CORNER_BOTTOMLEFT
;
1953 if (p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- wPreferences
.hot_corner_edge
) && p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- wPreferences
.hot_corner_edge
))
1954 return CORNER_BOTTOMRIGHT
;
1958 static void hotCornerDelay(void *data
)
1960 WScreen
*scr
= (WScreen
*) data
;
1961 if (scr
->flags
.in_hot_corner
&& wPreferences
.hot_corner_actions
[scr
->flags
.in_hot_corner
- 1])
1962 ExecuteShellCommand(scr
, wPreferences
.hot_corner_actions
[scr
->flags
.in_hot_corner
- 1]);
1963 WMDeleteTimerHandler(scr
->hot_corner_timer
);
1964 scr
->hot_corner_timer
= NULL
;
1967 static void handleMotionNotify(XEvent
*event
)
1969 if (wPreferences
.scrollable_menus
|| wPreferences
.hot_corners
) {
1970 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1971 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1972 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1974 if (wPreferences
.hot_corners
) {
1975 if (!scr
->flags
.in_hot_corner
) {
1976 scr
->flags
.in_hot_corner
= get_corner(rect
, p
);
1977 if (scr
->flags
.in_hot_corner
&& !scr
->hot_corner_timer
)
1978 scr
->hot_corner_timer
= WMAddTimerHandler(wPreferences
.hot_corner_delay
, hotCornerDelay
, scr
);
1980 int out_hot_corner
= 0;
1982 switch (scr
->flags
.in_hot_corner
) {
1983 case CORNER_TOPLEFT
:
1984 if ((p
.x
> (rect
.pos
.x
+ wPreferences
.hot_corner_edge
)) ||
1985 (p
.y
> (rect
.pos
.y
+ wPreferences
.hot_corner_edge
)))
1988 case CORNER_TOPRIGHT
:
1989 if ((p
.x
< (rect
.pos
.x
+ rect
.size
.width
- wPreferences
.hot_corner_edge
)) ||
1990 (p
.y
> (rect
.pos
.y
+ wPreferences
.hot_corner_edge
)))
1993 case CORNER_BOTTOMLEFT
:
1994 if ((p
.x
> (rect
.pos
.x
+ wPreferences
.hot_corner_edge
)) ||
1995 (p
.y
< (rect
.pos
.y
+ rect
.size
.height
- wPreferences
.hot_corner_edge
)))
1998 case CORNER_BOTTOMRIGHT
:
1999 if ((p
.x
< (rect
.pos
.x
+ rect
.size
.width
- wPreferences
.hot_corner_edge
)) ||
2000 (p
.y
< (rect
.pos
.y
+ rect
.size
.height
- wPreferences
.hot_corner_edge
)))
2005 if (out_hot_corner
) {
2006 scr
->flags
.in_hot_corner
= CORNER_NONE
;
2007 if (scr
->hot_corner_timer
) {
2008 WMDeleteTimerHandler(scr
->hot_corner_timer
);
2009 scr
->hot_corner_timer
= NULL
;
2016 if (wPreferences
.scrollable_menus
) {
2017 if (scr
->flags
.jump_back_pending
||
2018 p
.x
<= (rect
.pos
.x
+ 1) ||
2019 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
2020 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
2023 menu
= wMenuUnderPointer(scr
);
2032 #undef CORNER_TOPLEFT
2033 #undef CORNER_TOPRIGHT
2034 #undef CORNER_BOTTOMLEFT
2035 #undef CORNER_BOTTOMRIGHT
2037 static void handleVisibilityNotify(XEvent
* event
)
2041 wwin
= wWindowFor(event
->xvisibility
.window
);
2044 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);
2047 static void handle_selection_request(XSelectionRequestEvent
*event
)
2049 #ifdef USE_ICCCM_WMREPLACE
2050 static Atom atom_version
= None
;
2052 XSelectionEvent notify
;
2055 * This event must be sent to the slection requester to not block him
2057 * We create it with the answer 'there is no selection' by default
2059 notify
.type
= SelectionNotify
;
2060 notify
.display
= dpy
;
2061 notify
.requestor
= event
->requestor
;
2062 notify
.selection
= event
->selection
;
2063 notify
.target
= event
->target
;
2064 notify
.property
= None
; /* This says that there is no selection */
2065 notify
.time
= event
->time
;
2067 scr
= wScreenForWindow(event
->owner
);
2069 goto not_our_selection
;
2071 if (event
->owner
!= scr
->info_window
)
2072 goto not_our_selection
;
2074 if (event
->selection
!= scr
->sn_atom
)
2075 goto not_our_selection
;
2077 if (atom_version
== None
)
2078 atom_version
= XInternAtom(dpy
, "VERSION", False
);
2080 if (event
->target
== atom_version
) {
2081 static const long icccm_version
[] = { 2, 0 };
2084 * This protocol is defined in ICCCM 2.0:
2085 * http://www.x.org/releases/X11R7.7/doc/xorg-docs/icccm/icccm.html
2086 * "Communication with the Window Manager by Means of Selections"
2090 * Setting the property means the content of the selection is available
2091 * According to the ICCCM spec, we need to support being asked for a property
2092 * set to 'None' for compatibility with old clients
2094 notify
.property
= (event
->property
== None
)?(event
->target
):(event
->property
);
2096 XChangeProperty(dpy
, event
->requestor
, notify
.property
,
2097 XA_INTEGER
, 32, PropModeReplace
,
2098 (unsigned char *) icccm_version
, wlengthof(icccm_version
));
2102 if (notify
.property
== None
)
2103 wwarning("received SelectionRequest(%s) for target=\"%s\" from requestor 0x%lX but we have no answer",
2104 XGetAtomName(dpy
, event
->selection
), XGetAtomName(dpy
, event
->target
), (long) event
->requestor
);
2106 /* Send the answer to the requestor */
2107 XSendEvent(dpy
, event
->requestor
, False
, 0L, (XEvent
*) ¬ify
);
2111 * If the support for ICCCM window manager replacement was not enabled, we should not receive
2112 * this kind of event, so we just ignore it (Conceptually, we should reply with 'SelectionNotify'
2113 * event with property set to 'None' to tell that we don't have this selection, but that is a bit
2114 * costly for an event that shall never happen).
2120 static void handle_selection_clear(XSelectionClearEvent
*event
)
2122 #ifdef USE_ICCCM_WMREPLACE
2123 WScreen
*scr
= wScreenForWindow(event
->window
);
2128 if (event
->selection
!= scr
->sn_atom
)
2131 wmessage(_("another window manager is replacing us!"));
2132 Shutdown(WSExitMode
);
2135 * If the support for ICCCM window manager replacement was not enabled, we should not receive
2136 * this kind of event, so we simply do nothing.