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 occured */
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 occured */
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
);
637 if (wwin
->flags
.shaded
) {
638 wwin
->flags
.shaded
= 0;
639 wwin
->flags
.skip_next_animation
= 1;
642 if (wwin
->flags
.miniaturized
) {
643 wwin
->flags
.miniaturized
= 0;
644 wwin
->flags
.skip_next_animation
= 1;
645 wIconifyWindow(wwin
);
647 if (wwin
->flags
.fullscreen
) {
648 wwin
->flags
.fullscreen
= 0;
649 wFullscreenWindow(wwin
);
651 if (wwin
->flags
.hidden
) {
652 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
654 wwin
->flags
.hidden
= 0;
655 wwin
->flags
.skip_next_animation
= 1;
657 wHideApplication(wapp
);
663 static void handleDestroyNotify(XEvent
* event
)
667 Window window
= event
->xdestroywindow
.window
;
668 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
671 wwin
= wWindowFor(window
);
673 wUnmanageWindow(wwin
, False
, True
);
677 while ((widx
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
, (void *)window
)) != WANotFound
) {
678 WFakeGroupLeader
*fPtr
;
680 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, widx
);
681 if (fPtr
->retainCount
> 0) {
683 if (fPtr
->retainCount
== 0 && fPtr
->leader
!= None
) {
684 XDestroyWindow(dpy
, fPtr
->leader
);
689 fPtr
->origLeader
= None
;
693 app
= wApplicationOf(window
);
695 if (window
== app
->main_window
) {
697 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
699 if (wwin
->main_window
== window
) {
700 wwin
->main_window
= None
;
705 wApplicationDestroy(app
);
709 static void handleExpose(XEvent
* event
)
711 WObjDescriptor
*desc
;
714 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
)) ;
716 if (XFindContext(dpy
, event
->xexpose
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
720 if (desc
->handle_expose
) {
721 (*desc
->handle_expose
) (desc
, event
);
725 static void executeWheelAction(WScreen
*scr
, XEvent
*event
, int action
)
730 if (event
->xbutton
.button
== Button5
|| event
->xbutton
.button
== Button6
)
731 next_direction
= False
;
733 next_direction
= True
;
736 case WA_SWITCH_WORKSPACES
:
738 wWorkspaceRelativeChange(scr
, 1);
740 wWorkspaceRelativeChange(scr
, -1);
743 case WA_SWITCH_WINDOWS
:
744 wwin
= scr
->focused_window
;
746 wWindowFocusNext(wwin
, True
);
748 wWindowFocusPrev(wwin
, True
);
753 static void executeButtonAction(WScreen
*scr
, XEvent
*event
, int action
)
758 case WA_SELECT_WINDOWS
:
759 wUnselectWindows(scr
);
760 wSelectWindows(scr
, event
);
762 case WA_OPEN_APPMENU
:
763 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
765 if (scr
->root_menu
) {
766 if (scr
->root_menu
->brother
->flags
.mapped
)
767 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
769 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
772 case WA_OPEN_WINLISTMENU
:
773 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
774 if (scr
->switch_menu
) {
775 if (scr
->switch_menu
->brother
->flags
.mapped
)
776 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
778 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
781 case WA_MOVE_PREVWORKSPACE
:
782 wWorkspaceRelativeChange(scr
, -1);
784 case WA_MOVE_NEXTWORKSPACE
:
785 wWorkspaceRelativeChange(scr
, 1);
787 case WA_MOVE_PREVWINDOW
:
788 wwin
= scr
->focused_window
;
789 wWindowFocusPrev(wwin
, True
);
791 case WA_MOVE_NEXTWINDOW
:
792 wwin
= scr
->focused_window
;
793 wWindowFocusNext(wwin
, True
);
799 static void handleButtonPress(XEvent
* event
)
801 WObjDescriptor
*desc
;
804 scr
= wScreenForRootWindow(event
->xbutton
.root
);
810 if (!wPreferences
.disable_root_mouse
&& event
->xbutton
.window
== scr
->root_win
) {
811 if (event
->xbutton
.button
== Button1
&& wPreferences
.mouse_button1
!= WA_NONE
) {
812 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
813 } else if (event
->xbutton
.button
== Button2
&& wPreferences
.mouse_button2
!= WA_NONE
) {
814 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
815 } else if (event
->xbutton
.button
== Button3
&& wPreferences
.mouse_button3
!= WA_NONE
) {
816 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
817 } else if (event
->xbutton
.button
== Button8
&& wPreferences
.mouse_button8
!= WA_NONE
) {
818 executeButtonAction(scr
, event
, wPreferences
.mouse_button8
);
819 }else if (event
->xbutton
.button
== Button9
&& wPreferences
.mouse_button9
!= WA_NONE
) {
820 executeButtonAction(scr
, event
, wPreferences
.mouse_button9
);
821 } else if (event
->xbutton
.button
== Button4
&& wPreferences
.mouse_wheel_scroll
!= WA_NONE
) {
822 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_scroll
);
823 } else if (event
->xbutton
.button
== Button5
&& wPreferences
.mouse_wheel_scroll
!= WA_NONE
) {
824 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_scroll
);
825 } else if (event
->xbutton
.button
== Button6
&& wPreferences
.mouse_wheel_tilt
!= WA_NONE
) {
826 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_tilt
);
827 } else if (event
->xbutton
.button
== Button7
&& wPreferences
.mouse_wheel_tilt
!= WA_NONE
) {
828 executeWheelAction(scr
, event
, wPreferences
.mouse_wheel_tilt
);
833 if (XFindContext(dpy
, event
->xbutton
.subwindow
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
834 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
) {
839 if (desc
->parent_type
== WCLASS_WINDOW
) {
842 if (event
->xbutton
.state
& ( MOD_MASK
| ControlMask
)) {
843 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
845 /* if (wPreferences.focus_mode == WKF_CLICK) { */
846 if (wPreferences
.ignore_focus_click
) {
847 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
849 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
853 } else if (desc
->parent_type
== WCLASS_APPICON
854 || desc
->parent_type
== WCLASS_MINIWINDOW
|| desc
->parent_type
== WCLASS_DOCK_ICON
) {
855 if (event
->xbutton
.state
& MOD_MASK
) {
857 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
862 if (desc
->handle_mousedown
!= NULL
) {
863 (*desc
->handle_mousedown
) (desc
, event
);
866 /* save double-click information */
867 if (scr
->flags
.next_click_is_not_double
) {
868 scr
->flags
.next_click_is_not_double
= 0;
870 scr
->last_click_time
= event
->xbutton
.time
;
871 scr
->last_click_button
= event
->xbutton
.button
;
872 scr
->last_click_window
= event
->xbutton
.window
;
876 static void handleMapNotify(XEvent
* event
)
880 wwin
= wWindowFor(event
->xmap
.event
);
881 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
882 if (wwin
->flags
.miniaturized
) {
883 wDeiconifyWindow(wwin
);
887 wClientSetState(wwin
, NormalState
, None
);
893 static void handleUnmapNotify(XEvent
* event
)
897 Bool withdraw
= False
;
899 /* only process windows with StructureNotify selected
900 * (ignore SubstructureNotify) */
901 wwin
= wWindowFor(event
->xunmap
.window
);
905 /* whether the event is a Withdrawal request */
906 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
&& event
->xunmap
.send_event
)
909 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
912 if (!wwin
->flags
.mapped
&& !withdraw
913 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
914 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
918 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
919 wwin
->flags
.mapped
= 0;
921 /* check if the window was destroyed */
922 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
, &ev
)) {
925 Bool reparented
= False
;
927 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
930 /* withdraw window */
931 wwin
->flags
.mapped
= 0;
933 wClientSetState(wwin
, WithdrawnState
, None
);
935 /* if the window was reparented, do not reparent it back to the
937 wUnmanageWindow(wwin
, !reparented
, False
);
942 static void handleConfigureRequest(XEvent
* event
)
946 wwin
= wWindowFor(event
->xconfigurerequest
.window
);
949 * Configure request for unmapped window
951 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
953 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
957 static void handlePropertyNotify(XEvent
* event
)
965 wwin
= wWindowFor(event
->xproperty
.window
);
967 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
, &ju
, &ju
, &ju
, &ju
)) {
970 wClientCheckProperty(wwin
, &event
->xproperty
);
972 wapp
= wApplicationOf(event
->xproperty
.window
);
974 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
978 static void handleClientMessage(XEvent
* event
)
981 WObjDescriptor
*desc
;
983 /* handle transition from Normal to Iconic state */
984 if (event
->xclient
.message_type
== w_global
.atom
.wm
.change_state
985 && event
->xclient
.format
== 32 && event
->xclient
.data
.l
[0] == IconicState
) {
987 wwin
= wWindowFor(event
->xclient
.window
);
990 if (!wwin
->flags
.miniaturized
)
991 wIconifyWindow(wwin
);
992 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.colormap_notify
&& event
->xclient
.format
== 32) {
993 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
998 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
999 wColormapAllowClientInstallation(scr
, True
);
1000 } else { /* stopping */
1001 wColormapAllowClientInstallation(scr
, False
);
1003 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.command
) {
1008 len
= sizeof(event
->xclient
.data
.b
) + 1;
1009 command
= wmalloc(len
);
1010 strncpy(command
, event
->xclient
.data
.b
, sizeof(event
->xclient
.data
.b
));
1012 if (strncmp(command
, "Reconfigure", sizeof("Reconfigure")) == 0) {
1013 wwarning(_("Got Reconfigure command"));
1014 wDefaultsCheckDomains(NULL
);
1016 wwarning(_("Got unknown command %s"), command
);
1021 } else if (event
->xclient
.message_type
== w_global
.atom
.wmaker
.wm_function
) {
1024 wapp
= wApplicationOf(event
->xclient
.window
);
1026 switch (event
->xclient
.data
.l
[0]) {
1027 case WMFHideOtherApplications
:
1028 wHideOtherApplications(wapp
->main_window_desc
);
1032 case WMFHideApplication
:
1033 wHideApplication(wapp
);
1039 wwin
= wWindowFor(event
->xclient
.window
);
1041 switch (event
->xclient
.data
.l
[0]) {
1042 case WMFHideOtherApplications
:
1043 wHideOtherApplications(wwin
);
1046 case WMFHideApplication
:
1047 wHideApplication(wApplicationOf(wwin
->main_window
));
1052 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.wm_attr
) {
1053 wwin
= wWindowFor(event
->xclient
.window
);
1056 switch (event
->xclient
.data
.l
[0]) {
1057 case GSWindowLevelAttr
:
1059 int level
= (int)event
->xclient
.data
.l
[1];
1061 if (WINDOW_LEVEL(wwin
) != level
) {
1062 ChangeStackingLevel(wwin
->frame
->core
, level
);
1067 } else if (event
->xclient
.message_type
== w_global
.atom
.gnustep
.titlebar_state
) {
1068 wwin
= wWindowFor(event
->xclient
.window
);
1071 switch (event
->xclient
.data
.l
[0]) {
1072 case WMTitleBarNormal
:
1073 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1075 case WMTitleBarMain
:
1076 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
1079 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1082 } else if (event
->xclient
.message_type
== w_global
.atom
.wm
.ignore_focus_events
) {
1083 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
1086 scr
->flags
.ignore_focus_events
= event
->xclient
.data
.l
[0] ? 1 : 0;
1087 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1089 #ifdef USE_DOCK_XDND
1090 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1092 #endif /* USE_DOCK_XDND */
1095 * Non-standard thing, but needed by OffiX DND.
1096 * For when the icon frame gets a ClientMessage
1097 * that should have gone to the icon_window.
1099 if (XFindContext(dpy
, event
->xbutton
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1100 struct WIcon
*icon
= NULL
;
1102 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1103 icon
= (WIcon
*) desc
->parent
;
1104 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
|| desc
->parent_type
== WCLASS_APPICON
) {
1105 icon
= ((WAppIcon
*) desc
->parent
)->icon
;
1107 if (icon
&& (wwin
= icon
->owner
)) {
1108 if (wwin
->client_win
!= event
->xclient
.window
) {
1109 event
->xclient
.window
= wwin
->client_win
;
1110 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
, event
);
1117 static void raiseWindow(WScreen
* scr
)
1121 scr
->autoRaiseTimer
= NULL
;
1123 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1127 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1128 wRaiseFrame(wwin
->frame
->core
);
1129 /* this is needed or a race condition will occur */
1134 static void handleEnterNotify(XEvent
* event
)
1137 WObjDescriptor
*desc
= NULL
;
1139 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1141 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
, &ev
)) {
1142 /* already left the window... */
1144 if (ev
.xcrossing
.mode
== event
->xcrossing
.mode
&& ev
.xcrossing
.detail
== event
->xcrossing
.detail
) {
1149 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1150 if (desc
->handle_enternotify
)
1151 (*desc
->handle_enternotify
) (desc
, event
);
1154 /* enter to window */
1155 wwin
= wWindowFor(event
->xcrossing
.window
);
1157 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1158 wColormapInstallForWindow(scr
, NULL
);
1160 if (scr
->autoRaiseTimer
&& event
->xcrossing
.root
== event
->xcrossing
.window
) {
1161 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1162 scr
->autoRaiseTimer
= NULL
;
1165 /* set auto raise timer even if in focus-follows-mouse mode
1166 * and the event is for the frame window, even if the window
1167 * has focus already. useful if you move the pointer from a focused
1168 * window to the root window and back pretty fast
1170 * set focus if in focus-follows-mouse mode and the event
1171 * is for the frame window and window doesn't have focus yet */
1172 if (wPreferences
.focus_mode
== WKF_SLOPPY
1173 && wwin
->frame
->core
->window
== event
->xcrossing
.window
&& !scr
->flags
.doing_alt_tab
) {
1175 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1176 wSetFocusTo(scr
, wwin
);
1178 if (scr
->autoRaiseTimer
)
1179 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1180 scr
->autoRaiseTimer
= NULL
;
1182 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1183 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1185 = WMAddTimerHandler(wPreferences
.raise_delay
, (WMCallback
*) raiseWindow
, scr
);
1188 /* Install colormap for window, if the colormap installation mode
1189 * is colormap_follows_mouse */
1190 if (wPreferences
.colormap_mode
== WCM_POINTER
) {
1191 if (wwin
->client_win
== event
->xcrossing
.window
)
1192 wColormapInstallForWindow(scr
, wwin
);
1194 wColormapInstallForWindow(scr
, NULL
);
1198 if (event
->xcrossing
.window
== event
->xcrossing
.root
1199 && event
->xcrossing
.detail
== NotifyNormal
1200 && event
->xcrossing
.detail
!= NotifyInferior
&& wPreferences
.focus_mode
!= WKF_CLICK
) {
1202 wSetFocusTo(scr
, scr
->focused_window
);
1205 wBalloonEnteredObject(scr
, desc
);
1209 static void handleLeaveNotify(XEvent
* event
)
1211 WObjDescriptor
*desc
= NULL
;
1213 if (XFindContext(dpy
, event
->xcrossing
.window
, w_global
.context
.client_win
, (XPointer
*) & desc
) != XCNOENT
) {
1214 if (desc
->handle_leavenotify
)
1215 (*desc
->handle_leavenotify
) (desc
, event
);
1220 static void handleShapeNotify(XEvent
* event
)
1222 XShapeEvent
*shev
= (XShapeEvent
*) event
;
1229 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
.xevent
)) {
1230 if (ev
.xshape
.kind
== ShapeBounding
) {
1231 if (ev
.xshape
.shaped
== shev
->shaped
) {
1234 XPutBackEvent(dpy
, &ev
.xevent
);
1240 wwin
= wWindowFor(shev
->window
);
1241 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1244 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1246 wwin
->flags
.shaped
= 0;
1247 wWindowClearShape(wwin
);
1249 } else if (shev
->shaped
) {
1251 wwin
->flags
.shaped
= 1;
1252 wWindowSetShape(wwin
);
1255 #endif /* USE_XSHAPE */
1257 #ifdef KEEP_XKB_LOCK_STATUS
1258 /* please help ]d if you know what to do */
1259 static void handleXkbIndicatorStateNotify(XkbEvent
*event
)
1263 XkbStateRec staterec
;
1266 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1267 scr
= wScreenWithNumber(i
);
1268 wwin
= scr
->focused_window
;
1269 if (wwin
&& wwin
->flags
.focused
) {
1270 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1271 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1272 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1273 wwin
->frame
->languagemode
= staterec
.group
;
1275 #ifdef XKB_BUTTON_HINT
1276 if (wwin
->frame
->titlebar
) {
1277 wFrameWindowPaint(wwin
->frame
);
1283 #endif /*KEEP_XKB_LOCK_STATUS */
1285 static void handleColormapNotify(XEvent
* event
)
1289 Bool reinstall
= False
;
1291 wwin
= wWindowFor(event
->xcolormap
.window
);
1295 scr
= wwin
->screen_ptr
;
1299 if (event
->xcolormap
.new) {
1300 XWindowAttributes attr
;
1302 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1304 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1305 scr
->current_colormap
= attr
.colormap
;
1308 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1309 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1311 /* some bastard app (like XV) removed our colormap */
1313 * can't enforce or things like xscreensaver wont work
1316 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1317 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1319 /* someone has put our colormap back */
1323 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1324 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1326 if (reinstall
&& scr
->current_colormap
!= None
) {
1327 if (!scr
->flags
.colormap_stuff_blocked
)
1328 XInstallColormap(dpy
, scr
->current_colormap
);
1332 static void handleFocusIn(XEvent
* event
)
1337 * For applications that like stealing the focus.
1339 while (XCheckTypedEvent(dpy
, FocusIn
, event
)) ;
1340 saveTimestamp(event
);
1341 if (event
->xfocus
.mode
== NotifyUngrab
1342 || event
->xfocus
.mode
== NotifyGrab
|| event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1346 wwin
= wWindowFor(event
->xfocus
.window
);
1347 if (wwin
&& !wwin
->flags
.focused
) {
1348 if (wwin
->flags
.mapped
)
1349 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1351 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1353 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1355 wSetFocusTo(scr
, NULL
);
1359 static WWindow
*windowUnderPointer(WScreen
* scr
)
1365 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1366 return wWindowFor(win
);
1370 static int CheckFullScreenWindowFocused(WScreen
* scr
)
1372 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1378 static void handleKeyPress(XEvent
* event
)
1380 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1381 WWindow
*wwin
= scr
->focused_window
;
1385 #ifdef KEEP_XKB_LOCK_STATUS
1386 XkbStateRec staterec
;
1387 #endif /*KEEP_XKB_LOCK_STATUS */
1389 /* ignore CapsLock */
1390 modifiers
= event
->xkey
.state
& w_global
.shortcut
.modifiers_mask
;
1392 for (i
= 0; i
< WKBD_LAST
; i
++) {
1393 if (wKeyBindings
[i
].keycode
== 0)
1396 if (wKeyBindings
[i
].keycode
== event
->xkey
.keycode
&& ( /*wKeyBindings[i].modifier==0
1397 || */ wKeyBindings
[i
].modifier
==
1406 if (!wRootMenuPerformShortcut(event
)) {
1407 static int dontLoop
= 0;
1409 if (dontLoop
> 10) {
1410 wwarning("problem with key event processing code");
1414 /* if the focused window is an internal window, try redispatching
1415 * the event to the managed window, as it can be a WINGs window */
1416 if (wwin
&& wwin
->flags
.internal_window
&& wwin
->client_leader
!= None
) {
1417 /* client_leader contains the WINGs toplevel */
1418 event
->xany
.window
= wwin
->client_leader
;
1419 WMHandleEvent(event
);
1425 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1426 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1431 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True); */
1432 if (!CheckFullScreenWindowFocused(scr
)) {
1433 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1434 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1438 case WKBD_WINDOWLIST
:
1439 if (!CheckFullScreenWindowFocused(scr
)) {
1440 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1441 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/ 2, rect
.pos
.y
+ rect
.size
.height
/ 2,
1446 case WKBD_WINDOWMENU
:
1447 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1448 OpenWindowMenu(wwin
, wwin
->frame_x
, wwin
->frame_y
+ wwin
->frame
->top_width
, True
);
1450 case WKBD_MINIMIZEALL
:
1451 CloseWindowMenu(scr
);
1454 case WKBD_MINIATURIZE
:
1455 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1456 && !WFLAGP(wwin
, no_miniaturizable
)) {
1457 CloseWindowMenu(scr
);
1459 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1460 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
, event
->xbutton
.time
);
1462 wIconifyWindow(wwin
);
1467 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1468 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1469 CloseWindowMenu(scr
);
1471 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1472 wHideApplication(wapp
);
1476 case WKBD_HIDE_OTHERS
:
1477 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1478 CloseWindowMenu(scr
);
1480 wHideOtherApplications(wwin
);
1484 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1485 CloseWindowMenu(scr
);
1487 handleMaximize(wwin
, MAX_VERTICAL
| MAX_HORIZONTAL
| MAX_KEYBOARD
);
1490 case WKBD_VMAXIMIZE
:
1491 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1492 CloseWindowMenu(scr
);
1494 handleMaximize(wwin
, MAX_VERTICAL
| MAX_KEYBOARD
);
1497 case WKBD_HMAXIMIZE
:
1498 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1499 CloseWindowMenu(scr
);
1501 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_KEYBOARD
);
1504 case WKBD_LHMAXIMIZE
:
1505 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1506 CloseWindowMenu(scr
);
1508 handleMaximize(wwin
, MAX_VERTICAL
| MAX_LEFTHALF
| MAX_KEYBOARD
);
1511 case WKBD_RHMAXIMIZE
:
1512 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1513 CloseWindowMenu(scr
);
1515 handleMaximize(wwin
, MAX_VERTICAL
| MAX_RIGHTHALF
| MAX_KEYBOARD
);
1518 case WKBD_THMAXIMIZE
:
1519 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1520 CloseWindowMenu(scr
);
1522 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_TOPHALF
| MAX_KEYBOARD
);
1525 case WKBD_BHMAXIMIZE
:
1526 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1527 CloseWindowMenu(scr
);
1529 handleMaximize(wwin
, MAX_HORIZONTAL
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1532 case WKBD_LTCMAXIMIZE
:
1533 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1534 CloseWindowMenu(scr
);
1536 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1539 case WKBD_RTCMAXIMIZE
:
1540 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1541 CloseWindowMenu(scr
);
1543 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_KEYBOARD
);
1546 case WKBD_LBCMAXIMIZE
:
1547 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1548 CloseWindowMenu(scr
);
1550 handleMaximize(wwin
, MAX_LEFTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1553 case WKBD_RBCMAXIMIZE
:
1554 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1555 CloseWindowMenu(scr
);
1557 handleMaximize(wwin
, MAX_RIGHTHALF
| MAX_BOTTOMHALF
| MAX_KEYBOARD
);
1561 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1562 CloseWindowMenu(scr
);
1564 handleMaximize(wwin
, MAX_MAXIMUS
| MAX_KEYBOARD
);
1567 case WKBD_OMNIPRESENT
:
1568 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1569 CloseWindowMenu(scr
);
1571 wWindowSetOmnipresent(wwin
, !wwin
->flags
.omnipresent
);
1575 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1576 CloseWindowMenu(scr
);
1578 wRaiseFrame(wwin
->frame
->core
);
1582 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1583 CloseWindowMenu(scr
);
1585 wLowerFrame(wwin
->frame
->core
);
1588 case WKBD_RAISELOWER
:
1589 /* raise or lower the window under the pointer, not the
1592 wwin
= windowUnderPointer(scr
);
1594 wRaiseLowerFrame(wwin
->frame
->core
);
1597 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1598 if (wwin
->flags
.shaded
)
1599 wUnshadeWindow(wwin
);
1604 case WKBD_MOVERESIZE
:
1605 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1606 CloseWindowMenu(scr
);
1608 wKeyboardMoveResizeWindow(wwin
);
1612 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1613 CloseWindowMenu(scr
);
1614 if (wwin
->protocols
.DELETE_WINDOW
)
1615 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
, event
->xkey
.time
);
1619 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1620 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1624 case WKBD_WORKSPACEMAP
:
1625 if (wPreferences
.enable_workspace_pager
)
1626 StartWorkspaceMap(scr
);
1629 case WKBD_FOCUSNEXT
:
1630 StartWindozeCycle(wwin
, event
, True
, False
);
1633 case WKBD_FOCUSPREV
:
1634 StartWindozeCycle(wwin
, event
, False
, False
);
1637 case WKBD_GROUPNEXT
:
1638 StartWindozeCycle(wwin
, event
, True
, True
);
1641 case WKBD_GROUPPREV
:
1642 StartWindozeCycle(wwin
, event
, False
, True
);
1645 case WKBD_WORKSPACE1
... WKBD_WORKSPACE10
:
1646 widx
= command
- WKBD_WORKSPACE1
;
1647 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1648 if (wPreferences
.ws_advance
|| i
< scr
->workspace_count
)
1649 wWorkspaceChange(scr
, i
);
1652 case WKBD_NEXTWORKSPACE
:
1653 wWorkspaceRelativeChange(scr
, 1);
1655 case WKBD_PREVWORKSPACE
:
1656 wWorkspaceRelativeChange(scr
, -1);
1658 case WKBD_LASTWORKSPACE
:
1659 wWorkspaceChange(scr
, scr
->last_workspace
);
1662 case WKBD_MOVE_WORKSPACE1
... WKBD_MOVE_WORKSPACE10
:
1663 widx
= command
- WKBD_MOVE_WORKSPACE1
;
1664 i
= (scr
->current_workspace
/ 10) * 10 + widx
;
1665 if (wwin
&& (wPreferences
.ws_advance
|| i
< scr
->workspace_count
))
1666 wWindowChangeWorkspace(wwin
, i
);
1669 case WKBD_MOVE_NEXTWORKSPACE
:
1671 wWindowChangeWorkspaceRelative(wwin
, 1);
1673 case WKBD_MOVE_PREVWORKSPACE
:
1675 wWindowChangeWorkspaceRelative(wwin
, -1);
1677 case WKBD_MOVE_LASTWORKSPACE
:
1679 wWindowChangeWorkspace(wwin
, scr
->last_workspace
);
1682 case WKBD_MOVE_NEXTWSLAYER
:
1683 case WKBD_MOVE_PREVWSLAYER
:
1688 row
= scr
->current_workspace
/ 10;
1689 column
= scr
->current_workspace
% 10;
1691 if (command
== WKBD_MOVE_NEXTWSLAYER
) {
1692 if ((row
+ 1) * 10 < scr
->workspace_count
)
1693 wWindowChangeWorkspace(wwin
, column
+ (row
+ 1) * 10);
1696 wWindowChangeWorkspace(wwin
, column
+ (row
- 1) * 10);
1713 widx
= command
- WKBD_WINDOW1
;
1715 if (scr
->shortcutWindows
[widx
]) {
1716 WMArray
*list
= scr
->shortcutWindows
[widx
];
1718 int count
= WMGetArrayItemCount(list
);
1720 WMArrayIterator iter
;
1723 wUnselectWindows(scr
);
1724 cw
= scr
->current_workspace
;
1726 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1728 wWindowChangeWorkspace(wwin
, cw
);
1730 wMakeWindowVisible(wwin
);
1733 wSelectWindow(wwin
, True
);
1736 /* rotate the order of windows, to create a cycling effect */
1737 twin
= WMGetFromArray(list
, 0);
1738 WMDeleteFromArray(list
, 0);
1739 WMAddToArray(list
, twin
);
1741 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1742 if (scr
->shortcutWindows
[widx
]) {
1743 WMFreeArray(scr
->shortcutWindows
[widx
]);
1744 scr
->shortcutWindows
[widx
] = NULL
;
1747 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1748 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1749 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1750 WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
1752 scr
->shortcutWindows
[widx
] = WMCreateArray(4);
1753 WMAddToArray(scr
->shortcutWindows
[widx
], wwin
);
1756 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1759 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1762 } else if (scr
->selected_windows
&& WMGetArrayItemCount(scr
->selected_windows
)) {
1764 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1765 if (scr
->shortcutWindows
[widx
]) {
1766 WMFreeArray(scr
->shortcutWindows
[widx
]);
1768 scr
->shortcutWindows
[widx
] = WMDuplicateArray(scr
->selected_windows
);
1775 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1776 (void) RelaunchWindow(wwin
);
1780 case WKBD_SWITCH_SCREEN
:
1781 if (w_global
.screen_count
> 1) {
1785 /* find index of this screen */
1786 for (i
= 0; i
< w_global
.screen_count
; i
++) {
1787 if (wScreenWithNumber(i
) == scr
)
1791 if (i
>= w_global
.screen_count
) {
1794 scr2
= wScreenWithNumber(i
);
1797 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1798 scr2
->scr_width
/ 2, scr2
->scr_height
/ 2);
1807 cmdline
= ExpandOptions(scr
, _("exec %A(Run,Type command to run:)"));
1810 XGrabPointer(dpy
, scr
->root_win
, True
, 0,
1811 GrabModeAsync
, GrabModeAsync
, None
, wPreferences
.cursor
[WCUR_WAIT
], CurrentTime
);
1814 ExecuteShellCommand(scr
, cmdline
);
1817 XUngrabPointer(dpy
, CurrentTime
);
1823 case WKBD_NEXTWSLAYER
:
1824 case WKBD_PREVWSLAYER
:
1828 row
= scr
->current_workspace
/ 10;
1829 column
= scr
->current_workspace
% 10;
1831 if (command
== WKBD_NEXTWSLAYER
) {
1832 if ((row
+ 1) * 10 < scr
->workspace_count
)
1833 wWorkspaceChange(scr
, column
+ (row
+ 1) * 10);
1836 wWorkspaceChange(scr
, column
+ (row
- 1) * 10);
1840 case WKBD_CLIPRAISELOWER
:
1841 if (!wPreferences
.flags
.noclip
)
1842 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1844 case WKBD_DOCKRAISELOWER
:
1845 if (!wPreferences
.flags
.nodock
)
1846 wDockRaiseLower(scr
->dock
);
1848 #ifdef KEEP_XKB_LOCK_STATUS
1850 if (wPreferences
.modelock
) {
1852 wwin
= scr
->focused_window
;
1854 if (wwin
&& wwin
->flags
.mapped
1855 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1856 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1857 XkbGetState(dpy
, XkbUseCoreKbd
, &staterec
);
1859 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1860 wwin
->frame
->last_languagemode
= staterec
.group
;
1861 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1866 #endif /* KEEP_XKB_LOCK_STATUS */
1870 static void handleMotionNotify(XEvent
* event
)
1872 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1874 if (wPreferences
.scrollable_menus
) {
1875 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1876 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1878 if (scr
->flags
.jump_back_pending
||
1879 p
.x
<= (rect
.pos
.x
+ 1) ||
1880 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1881 p
.y
<= (rect
.pos
.y
+ 1) || p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1884 menu
= wMenuUnderPointer(scr
);
1891 static void handleVisibilityNotify(XEvent
* event
)
1895 wwin
= wWindowFor(event
->xvisibility
.window
);
1898 wwin
->flags
.obscured
= (event
->xvisibility
.state
== VisibilityFullyObscured
);
1901 static void handle_selection_request(XSelectionRequestEvent
*event
)
1903 #ifdef USE_ICCCM_WMREPLACE
1904 static Atom atom_version
= None
;
1906 XSelectionEvent notify
;
1909 * This event must be sent to the slection requester to not block him
1911 * We create it with the answer 'there is no selection' by default
1913 notify
.type
= SelectionNotify
;
1914 notify
.display
= dpy
;
1915 notify
.requestor
= event
->requestor
;
1916 notify
.selection
= event
->selection
;
1917 notify
.target
= event
->target
;
1918 notify
.property
= None
; /* This says that there is no selection */
1919 notify
.time
= event
->time
;
1921 scr
= wScreenForWindow(event
->owner
);
1923 goto not_our_selection
;
1925 if (event
->owner
!= scr
->info_window
)
1926 goto not_our_selection
;
1928 if (event
->selection
!= scr
->sn_atom
)
1929 goto not_our_selection
;
1931 if (atom_version
== None
)
1932 atom_version
= XInternAtom(dpy
, "VERSION", False
);
1934 if (event
->target
== atom_version
) {
1935 static const long icccm_version
[] = { 2, 0 };
1938 * This protocol is defined in ICCCM 2.0:
1939 * http://www.x.org/releases/X11R7.7/doc/xorg-docs/icccm/icccm.html
1940 * "Communication with the Window Manager by Means of Selections"
1944 * Setting the property means the content of the selection is available
1945 * According to the ICCCM spec, we need to support being asked for a property
1946 * set to 'None' for compatibility with old clients
1948 notify
.property
= (event
->property
== None
)?(event
->target
):(event
->property
);
1950 XChangeProperty(dpy
, event
->requestor
, notify
.property
,
1951 XA_INTEGER
, 32, PropModeReplace
,
1952 (unsigned char *) icccm_version
, wlengthof(icccm_version
));
1956 if (notify
.property
== None
)
1957 wwarning("received SelectionRequest(%s) for target=\"%s\" from requestor 0x%lX but we have no answer",
1958 XGetAtomName(dpy
, event
->selection
), XGetAtomName(dpy
, event
->target
), (long) event
->requestor
);
1960 /* Send the answer to the requestor */
1961 XSendEvent(dpy
, event
->requestor
, False
, 0L, (XEvent
*) ¬ify
);
1965 * If the support for ICCCM window manager replacement was not enabled, we should not receive
1966 * this kind of event, so we just ignore it (Conceptually, we should reply with 'SelectionNotify'
1967 * event with property set to 'None' to tell that we don't have this selection, but that is a bit
1968 * costly for an event that shall never happen).
1974 static void handle_selection_clear(XSelectionClearEvent
*event
)
1976 #ifdef USE_ICCCM_WMREPLACE
1977 WScreen
*scr
= wScreenForWindow(event
->window
);
1982 if (event
->selection
!= scr
->sn_atom
)
1985 wmessage(_("another window manager is replacing us!"));
1986 Shutdown(WSExitMode
);
1989 * If the support for ICCCM window manager replacement was not enabled, we should not receive
1990 * this kind of event, so we simply do nothing.