1 /* event.c- event loop and handling
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
33 #include <X11/Xutil.h>
35 #include <X11/extensions/shape.h>
41 #ifdef KEEP_XKB_LOCK_STATUS
42 #include <X11/XKBlib.h>
43 #endif /* KEEP_XKB_LOCK_STATUS */
45 #include "WindowMaker.h"
51 #include "application.h"
54 #include "workspace.h"
57 #include "properties.h"
66 /******** Global Variables **********/
67 extern XContext wWinContext
;
69 extern Cursor wCursor
[WCUR_LAST
];
71 extern WShortKey wKeyBindings
[WKBD_LAST
];
72 extern int wScreenCount
;
73 extern Time LastTimestamp
;
74 extern Time LastFocusChange
;
76 extern WPreferences wPreferences
;
78 #define MOD_MASK wPreferences.modifier_mask
80 extern Atom _XA_WM_COLORMAP_NOTIFY
;
82 extern Atom _XA_WM_CHANGE_STATE
;
83 extern Atom _XA_WM_DELETE_WINDOW
;
84 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
85 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
88 extern Atom _XA_DND_PROTOCOL
;
93 extern Bool wShapeSupported
;
94 extern int wShapeEventBase
;
98 extern char WDelayedActionSet
;
101 /************ Local stuff ***********/
104 static void saveTimestamp(XEvent
*event
);
105 static void handleColormapNotify();
106 static void handleMapNotify(), handleUnmapNotify();
107 static void handleButtonPress(), handleExpose();
108 static void handleDestroyNotify();
109 static void handleConfigureRequest();
110 static void handleMapRequest();
111 static void handlePropertyNotify();
112 static void handleEnterNotify();
113 static void handleLeaveNotify();
114 static void handleExtensions();
115 static void handleClientMessage();
116 static void handleKeyPress();
117 static void handleFocusIn();
118 static void handleMotionNotify();
119 static void handleVisibilityNotify();
123 static void handleShapeNotify();
126 /* called from the signal handler */
127 void NotifyDeadProcess(pid_t pid
, unsigned char status
);
129 /* real dead process handler */
130 static void handleDeadProcess(void *foo
);
133 typedef struct DeadProcesses
{
135 unsigned char exit_status
;
138 /* stack of dead processes */
139 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
140 static int deadProcessPtr
=0;
143 typedef struct DeathHandler
{
144 WDeathHandler
*callback
;
146 struct DeathHandler
*next
;
150 static DeathHandler
*deathHandler
=NULL
;
155 wAddDeathHandler(pid_t pid
, WDeathHandler
*callback
, void *cdata
)
157 DeathHandler
*handler
;
159 handler
= malloc(sizeof(DeathHandler
));
164 handler
->callback
= callback
;
165 handler
->client_data
= cdata
;
167 handler
->next
= deathHandler
;
169 deathHandler
= handler
;
177 wDeleteDeathHandler(WMagicNumber id
)
179 DeathHandler
*tmp
, *handler
=(DeathHandler
*)id
;
181 if (!handler
|| !deathHandler
)
186 deathHandler
= handler
->next
;
190 if (tmp
->next
==handler
) {
191 tmp
->next
=handler
->next
;
202 DispatchEvent(XEvent
*event
)
205 handleDeadProcess(NULL
);
207 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
208 WCHANGE_STATE(WSTATE_EXITING
);
209 /* received SIGTERM */
211 * WMHandleEvent() can't be called from anything
212 * executed inside here, or we can get in a infinite
215 Shutdown(WSExitMode
);
217 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
218 WCHANGE_STATE(WSTATE_RESTARTING
);
220 Shutdown(WSRestartPreparationMode
);
221 /* received SIGHUP */
225 /* for the case that all that is wanted to be dispatched is
230 saveTimestamp(event
);
231 switch (event
->type
) {
233 handleMapRequest(event
);
237 handleKeyPress(event
);
241 handleMotionNotify(event
);
244 case ConfigureRequest
:
245 handleConfigureRequest(event
);
249 handleDestroyNotify(event
);
253 handleMapNotify(event
);
257 handleUnmapNotify(event
);
261 handleButtonPress(event
);
269 handlePropertyNotify(event
);
273 handleEnterNotify(event
);
277 handleLeaveNotify(event
);
281 handleClientMessage(event
);
285 handleColormapNotify(event
);
289 if (event
->xmapping
.request
== MappingKeyboard
290 || event
->xmapping
.request
== MappingModifier
)
291 XRefreshKeyboardMapping(&event
->xmapping
);
295 handleFocusIn(event
);
298 case VisibilityNotify
:
299 handleVisibilityNotify(event
);
303 handleExtensions(event
);
310 *----------------------------------------------------------------------
312 * Processes X and internal events indefinitely.
318 * The LastTimestamp global variable is updated.
319 *----------------------------------------------------------------------
327 WMNextEvent(dpy
, &event
);
328 WMHandleEvent(&event
);
335 IsDoubleClick(WScreen
*scr
, XEvent
*event
)
337 if ((scr
->last_click_time
>0) &&
338 (event
->xbutton
.time
-scr
->last_click_time
<=wPreferences
.dblclick_time
)
339 && (event
->xbutton
.button
== scr
->last_click_button
)
340 && (event
->xbutton
.window
== scr
->last_click_window
)) {
342 scr
->flags
.next_click_is_not_double
= 1;
343 scr
->last_click_time
= 0;
344 scr
->last_click_window
= event
->xbutton
.window
;
353 NotifyDeadProcess(pid_t pid
, unsigned char status
)
355 if (deadProcessPtr
>=MAX_DEAD_PROCESSES
-1) {
356 wwarning("stack overflow: too many dead processes");
359 /* stack the process to be handled later,
360 * as this is called from the signal handler */
361 deadProcesses
[deadProcessPtr
].pid
= pid
;
362 deadProcesses
[deadProcessPtr
].exit_status
= status
;
368 handleDeadProcess(void *foo
)
373 for (i
=0; i
<deadProcessPtr
; i
++) {
374 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
382 /* get the pids on the queue and call handlers */
383 while (deadProcessPtr
>0) {
392 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
393 (*tmp
->callback
)(tmp
->pid
,
394 deadProcesses
[deadProcessPtr
].exit_status
,
396 wDeleteDeathHandler(tmp
);
405 saveTimestamp(XEvent
*event
)
407 LastTimestamp
= CurrentTime
;
409 switch (event
->type
) {
412 LastTimestamp
= event
->xbutton
.time
;
416 LastTimestamp
= event
->xkey
.time
;
419 LastTimestamp
= event
->xmotion
.time
;
422 LastTimestamp
= event
->xproperty
.time
;
426 LastTimestamp
= event
->xcrossing
.time
;
429 LastTimestamp
= event
->xselectionclear
.time
;
431 case SelectionRequest
:
432 LastTimestamp
= event
->xselectionrequest
.time
;
434 case SelectionNotify
:
435 LastTimestamp
= event
->xselection
.time
;
442 handleExtensions(XEvent
*event
)
445 if (wShapeSupported
&& event
->type
== (wShapeEventBase
+ShapeNotify
)) {
446 handleShapeNotify(event
);
453 handleMapRequest(XEvent
*ev
)
457 Window window
= ev
->xmaprequest
.window
;
460 printf("got map request for %x\n", (unsigned)window
);
463 if ((wwin
= wWindowFor(window
))) {
464 if (wwin
->flags
.shaded
) {
465 wUnshadeWindow(wwin
);
467 /* deiconify window */
468 if (wwin
->flags
.miniaturized
) {
469 wDeiconifyWindow(wwin
);
470 } else if (wwin
->flags
.hidden
) {
471 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
472 /* go to the last workspace that the user worked on the app */
473 #ifndef REDUCE_APPICONS
474 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
475 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
478 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
481 wUnhideApplication(wapp
, False
, False
);
486 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
488 wwin
= wManageWindow(scr
, window
);
491 * This is to let the Dock know that the application it launched
492 * has already been mapped (eg: it has finished launching).
493 * It is not necessary for normally docked apps, but is needed for
494 * apps that were forcedly docked (like with dockit).
496 if (scr
->last_dock
) {
497 if (wwin
&& wwin
->main_window
!=None
&& wwin
->main_window
!=window
)
498 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
500 wDockTrackWindowLaunch(scr
->last_dock
, window
);
504 wClientSetState(wwin
, NormalState
, None
);
505 if (wwin
->flags
.maximized
) {
506 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
508 if (wwin
->flags
.shaded
) {
509 wwin
->flags
.shaded
= 0;
510 wwin
->flags
.skip_next_animation
= 1;
513 if (wwin
->flags
.miniaturized
) {
514 wwin
->flags
.miniaturized
= 0;
515 wwin
->flags
.skip_next_animation
= 1;
516 wIconifyWindow(wwin
);
518 if (wwin
->flags
.hidden
) {
519 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
521 wwin
->flags
.hidden
= 0;
522 wwin
->flags
.skip_next_animation
= 1;
524 wHideApplication(wapp
);
532 handleDestroyNotify(XEvent
*event
)
536 Window window
= event
->xdestroywindow
.window
;
539 puts("got destroy notify");
542 wwin
= wWindowFor(window
);
544 wUnmanageWindow(wwin
, False
, True
);
547 app
= wApplicationOf(window
);
549 if (window
== app
->main_window
) {
551 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
553 if (wwin
->main_window
== window
) {
554 wwin
->main_window
= None
;
559 wApplicationDestroy(app
);
563 wKWMCheckDestroy(&event
->xdestroywindow
);
570 handleExpose(XEvent
*event
)
572 WObjDescriptor
*desc
;
579 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
));
581 if (XFindContext(dpy
, event
->xexpose
.window
, wWinContext
,
582 (XPointer
*)&desc
)==XCNOENT
) {
586 if (desc
->handle_expose
) {
587 (*desc
->handle_expose
)(desc
, event
);
594 handleButtonPress(XEvent
*event
)
596 WObjDescriptor
*desc
;
600 puts("got button press");
603 scr
= wScreenForRootWindow(event
->xbutton
.root
);
611 if (event
->xbutton
.window
==scr
->root_win
) {
614 if (wGNOMEProxyizeButtonEvent(scr
, event
))
618 if (event
->xbutton
.button
==wPreferences
.menu_button
) {
619 OpenRootMenu(scr
, event
->xbutton
.x_root
,
620 event
->xbutton
.y_root
, False
);
622 if (scr
->root_menu
) {
623 if (scr
->root_menu
->brother
->flags
.mapped
)
624 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
626 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
628 } else if (event
->xbutton
.button
==wPreferences
.windowl_button
) {
629 OpenSwitchMenu(scr
, event
->xbutton
.x_root
,
630 event
->xbutton
.y_root
, False
);
631 if (scr
->switch_menu
) {
632 if (scr
->switch_menu
->brother
->flags
.mapped
)
633 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
635 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
637 } else if (event
->xbutton
.button
==wPreferences
.select_button
) {
638 wUnselectWindows(scr
);
639 wSelectWindows(scr
, event
);
641 #ifdef MOUSE_WS_SWITCH
642 else if (event
->xbutton
.button
==Button5
) {
644 wWorkspaceRelativeChange(scr
, -1);
646 } else if (event
->xbutton
.button
==Button4
) {
648 wWorkspaceRelativeChange(scr
, 1);
651 #endif /* MOUSE_WS_SWITCH */
655 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
,
656 (XPointer
*)&desc
)==XCNOENT
) {
657 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
,
658 (XPointer
*)&desc
)==XCNOENT
) {
663 if (desc
->handle_mousedown
!=NULL
) {
664 (*desc
->handle_mousedown
)(desc
, event
);
667 if (desc
->parent_type
== WCLASS_WINDOW
) {
670 if (event
->xbutton
.state
& MOD_MASK
) {
671 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
674 if (wPreferences
.focus_mode
== WKF_CLICK
) {
675 if (wPreferences
.ignore_focus_click
) {
676 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
678 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
681 } else if (desc
->parent_type
== WCLASS_APPICON
682 || desc
->parent_type
== WCLASS_MINIWINDOW
683 || desc
->parent_type
== WCLASS_DOCK_ICON
) {
684 if (event
->xbutton
.state
& MOD_MASK
) {
686 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
691 /* save double-click information */
692 if (scr
->flags
.next_click_is_not_double
) {
693 scr
->flags
.next_click_is_not_double
= 0;
695 scr
->last_click_time
= event
->xbutton
.time
;
696 scr
->last_click_button
= event
->xbutton
.button
;
697 scr
->last_click_window
= event
->xbutton
.window
;
703 handleMapNotify(XEvent
*event
)
711 wwin
= wWindowFor(event
->xmap
.event
);
712 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
713 if (wwin
->flags
.miniaturized
) {
714 wDeiconifyWindow(wwin
);
718 wClientSetState(wwin
, NormalState
, None
);
726 handleUnmapNotify(XEvent
*event
)
730 Bool withdraw
= False
;
736 /* only process windows with StructureNotify selected
737 * (ignore SubstructureNotify) */
738 wwin
= wWindowFor(event
->xunmap
.window
);
742 /* whether the event is a Withdrawal request */
743 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
744 && event
->xunmap
.send_event
)
747 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
750 if (!wwin
->flags
.mapped
&& !withdraw
751 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
752 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
756 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
757 wwin
->flags
.mapped
= 0;
759 /* check if the window was destroyed */
760 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
,&ev
)) {
763 Bool reparented
= False
;
765 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
768 /* withdraw window */
769 wwin
->flags
.mapped
= 0;
771 wClientSetState(wwin
, WithdrawnState
, None
);
773 /* if the window was reparented, do not reparent it back to the
775 wUnmanageWindow(wwin
, !reparented
, False
);
782 handleConfigureRequest(XEvent
*event
)
787 puts("got configure request");
789 if (!(wwin
=wWindowFor(event
->xconfigurerequest
.window
))) {
791 * Configure request for unmapped window
793 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
795 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
801 handlePropertyNotify(XEvent
*event
)
811 puts("got property notify");
813 if ((wwin
=wWindowFor(event
->xproperty
.window
))) {
814 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
,
815 &ju
, &ju
, &ju
, &ju
)) {
818 wClientCheckProperty(wwin
, &event
->xproperty
);
820 wapp
= wApplicationOf(event
->xproperty
.window
);
822 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
825 scr
= wScreenForWindow(event
->xproperty
.window
);
826 if (scr
&& scr
->root_win
== event
->xproperty
.window
) {
828 wKWMCheckRootHintChange(scr
, &event
->xproperty
);
835 handleClientMessage(XEvent
*event
)
838 WObjDescriptor
*desc
;
841 puts("got client message");
843 /* handle transition from Normal to Iconic state */
844 if (event
->xclient
.message_type
== _XA_WM_CHANGE_STATE
845 && event
->xclient
.format
== 32
846 && event
->xclient
.data
.l
[0] == IconicState
) {
848 wwin
= wWindowFor(event
->xclient
.window
);
850 if (!wwin
->flags
.miniaturized
)
851 wIconifyWindow(wwin
);
852 } else if (event
->xclient
.message_type
== _XA_WM_COLORMAP_NOTIFY
853 && event
->xclient
.format
== 32) {
854 WScreen
*scr
= wScreenSearchForRootWindow(event
->xclient
.window
);
859 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
860 wColormapAllowClientInstallation(scr
, True
);
861 } else { /* stopping */
862 wColormapAllowClientInstallation(scr
, False
);
864 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
867 wapp
= wApplicationOf(event
->xclient
.window
);
869 switch (event
->xclient
.data
.l
[0]) {
870 case WMFHideOtherApplications
:
871 wHideOtherApplications(wapp
->main_window_desc
);
875 case WMFHideApplication
:
876 wHideApplication(wapp
);
882 wwin
= wWindowFor(event
->xclient
.window
);
884 switch (event
->xclient
.data
.l
[0]) {
885 case WMFHideOtherApplications
:
886 wHideOtherApplications(wwin
);
889 case WMFHideApplication
:
890 wHideApplication(wApplicationOf(wwin
->main_window
));
896 } else if (wGNOMEProcessClientMessage(&event
->xclient
)) {
898 #endif /* GNOME_STUFF */
900 } else if (wKWMProcessClientMessage(&event
->xclient
)) {
902 #endif /* KWM_HINTS */
904 } else if (wXDEProcessClientMessage(&event
->xclient
)) {
908 } else if (event
->xclient
.message_type
==_XA_DND_PROTOCOL
) {
909 WScreen
*scr
= wScreenForWindow(event
->xclient
.window
);
910 if (scr
&& wDockReceiveDNDDrop(scr
,event
))
911 goto redirect_message
;
912 #endif /* OFFIX_DND */
918 * Non-standard thing, but needed by OffiX DND.
919 * For when the icon frame gets a ClientMessage
920 * that should have gone to the icon_window.
922 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
,
923 (XPointer
*)&desc
)!=XCNOENT
) {
924 struct WIcon
*icon
=NULL
;
926 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
927 icon
= (WIcon
*)desc
->parent
;
928 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
929 || desc
->parent_type
== WCLASS_APPICON
) {
930 icon
= ((WAppIcon
*)desc
->parent
)->icon
;
932 if (icon
&& (wwin
=icon
->owner
)) {
933 if (wwin
->client_win
!=event
->xclient
.window
) {
934 event
->xclient
.window
= wwin
->client_win
;
935 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
,
945 raiseWindow(WScreen
*scr
)
949 scr
->autoRaiseTimer
= NULL
;
951 wwin
= wWindowFor(scr
->autoRaiseWindow
);
955 if (!wwin
->flags
.destroyed
) {
956 wRaiseFrame(wwin
->frame
->core
);
957 /* this is needed or a race condition will occur */
964 handleEnterNotify(XEvent
*event
)
967 WObjDescriptor
*desc
= NULL
;
969 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
973 puts("got enter notify");
976 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
,
978 /* already left the window... */
980 if (ev
.xcrossing
.mode
==event
->xcrossing
.mode
981 && ev
.xcrossing
.detail
==event
->xcrossing
.detail
) {
986 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
,
987 (XPointer
*)&desc
)!=XCNOENT
) {
988 if(desc
->handle_enternotify
)
989 (*desc
->handle_enternotify
)(desc
, event
);
992 /* enter to window */
993 wwin
= wWindowFor(event
->xcrossing
.window
);
995 if (wPreferences
.focus_mode
==WKF_POINTER
996 && event
->xcrossing
.window
==event
->xcrossing
.root
) {
997 wSetFocusTo(scr
, NULL
);
999 if (wPreferences
.colormap_mode
==WKF_POINTER
) {
1000 wColormapInstallForWindow(scr
, NULL
);
1002 if (scr
->autoRaiseTimer
1003 && event
->xcrossing
.root
==event
->xcrossing
.window
) {
1004 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1005 scr
->autoRaiseTimer
= NULL
;
1008 /* set auto raise timer even if in focus-follows-mouse mode
1009 * and the event is for the frame window, even if the window
1010 * has focus already. useful if you move the pointer from a focused
1011 * window to the root window and back pretty fast
1013 * set focus if in focus-follows-mouse mode and the event
1014 * is for the frame window and window doesn't have focus yet */
1015 if ((wPreferences
.focus_mode
==WKF_POINTER
1016 || wPreferences
.focus_mode
==WKF_SLOPPY
)
1017 && wwin
->frame
->core
->window
==event
->xcrossing
.window
1018 && !scr
->flags
.doing_alt_tab
) {
1020 if (!wwin
->flags
.focused
)
1021 wSetFocusTo(scr
, wwin
);
1023 if (scr
->autoRaiseTimer
)
1024 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1025 scr
->autoRaiseTimer
= NULL
;
1027 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1028 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1030 = WMAddTimerHandler(wPreferences
.raise_delay
,
1031 (WMCallback
*)raiseWindow
, scr
);
1034 /* Install colormap for window, if the colormap installation mode
1035 * is colormap_follows_mouse */
1036 if (wPreferences
.colormap_mode
==WKF_POINTER
) {
1037 if (wwin
->client_win
==event
->xcrossing
.window
)
1038 wColormapInstallForWindow(scr
, wwin
);
1040 wColormapInstallForWindow(scr
, NULL
);
1044 /* a little kluge to hide the clip balloon */
1045 if (!wPreferences
.flags
.noclip
&& scr
->flags
.clip_balloon_mapped
) {
1047 XUnmapWindow(dpy
, scr
->clip_balloon
);
1048 scr
->flags
.clip_balloon_mapped
= 0;
1050 if (desc
->parent_type
!=WCLASS_DOCK_ICON
1051 || scr
->clip_icon
!= desc
->parent
) {
1052 XUnmapWindow(dpy
, scr
->clip_balloon
);
1053 scr
->flags
.clip_balloon_mapped
= 0;
1058 if (event
->xcrossing
.window
== event
->xcrossing
.root
1059 && event
->xcrossing
.detail
== NotifyNormal
1060 && event
->xcrossing
.detail
!= NotifyInferior
1061 && wPreferences
.focus_mode
!= WKF_CLICK
) {
1063 wSetFocusTo(scr
, scr
->focused_window
);
1067 wBalloonEnteredObject(scr
, desc
);
1073 handleLeaveNotify(XEvent
*event
)
1075 WObjDescriptor
*desc
= NULL
;
1077 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
,
1078 (XPointer
*)&desc
)!=XCNOENT
) {
1079 if(desc
->handle_leavenotify
)
1080 (*desc
->handle_leavenotify
)(desc
, event
);
1082 if (event
->xcrossing
.window
== event
->xcrossing
.root
1083 && event
->xcrossing
.mode
== NotifyNormal
1084 && event
->xcrossing
.detail
!= NotifyInferior
1085 && wPreferences
.focus_mode
!= WKF_CLICK
) {
1087 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1089 wSetFocusTo(scr
, NULL
);
1096 handleShapeNotify(XEvent
*event
)
1098 XShapeEvent
*shev
= (XShapeEvent
*)event
;
1103 puts("got shape notify");
1106 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
)) {
1107 XShapeEvent
*sev
= (XShapeEvent
*)&ev
;
1109 if (sev
->kind
== ShapeBounding
) {
1110 if (sev
->shaped
== shev
->shaped
) {
1113 XPutBackEvent(dpy
, &ev
);
1119 wwin
= wWindowFor(shev
->window
);
1120 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1123 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1125 wwin
->flags
.shaped
= 0;
1126 wWindowClearShape(wwin
);
1128 } else if (shev
->shaped
) {
1130 wwin
->flags
.shaped
= 1;
1131 wWindowSetShape(wwin
);
1138 handleColormapNotify(XEvent
*event
)
1142 Bool reinstall
= False
;
1144 wwin
= wWindowFor(event
->xcolormap
.window
);
1148 scr
= wwin
->screen_ptr
;
1152 if (event
->xcolormap
.new) {
1153 XWindowAttributes attr
;
1155 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1157 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1158 scr
->current_colormap
= attr
.colormap
;
1161 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1162 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1164 /* some bastard app (like XV) removed our colormap */
1166 * can't enforce or things like xscreensaver wont work
1169 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1170 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1172 /* someone has put our colormap back */
1176 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1177 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1179 if (reinstall
&& scr
->current_colormap
!=None
) {
1180 if (!scr
->flags
.colormap_stuff_blocked
)
1181 XInstallColormap(dpy
, scr
->current_colormap
);
1188 handleFocusIn(XEvent
*event
)
1193 * For applications that like stealing the focus.
1195 while (XCheckTypedEvent(dpy
, FocusIn
, event
));
1196 saveTimestamp(event
);
1197 if (event
->xfocus
.mode
== NotifyUngrab
1198 || event
->xfocus
.mode
== NotifyGrab
1199 || event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1203 wwin
= wWindowFor(event
->xfocus
.window
);
1204 if (wwin
&& !wwin
->flags
.focused
) {
1205 if (wwin
->flags
.mapped
)
1206 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1208 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1210 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1212 wSetFocusTo(scr
, NULL
);
1218 windowUnderPointer(WScreen
*scr
)
1224 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
,
1226 return wWindowFor(win
);
1230 #ifdef WEENDOZE_CYCLE
1233 nextToFocusAfter(WWindow
*wwin
)
1235 WWindow
*tmp
= wwin
->next
;
1238 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
1246 /* start over from the beginning of the list */
1250 while (tmp
&& tmp
!= wwin
) {
1251 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
1263 nextToFocusBefore(WWindow
*wwin
)
1265 WWindow
*tmp
= wwin
->prev
;
1268 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
1275 /* start over from the beginning of the list */
1280 while (tmp
&& tmp
!= wwin
) {
1281 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
1292 doWindozeCycle(WWindow
*wwin
, XEvent
*event
, Bool next
)
1294 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1296 WWindow
*newFocused
;
1297 WWindow
*oldFocused
;
1299 XModifierKeymap
*keymap
;
1305 keymap
= XGetModifierMapping(dpy
);
1308 XGrabKeyboard(dpy
, scr
->root_win
, False
, GrabModeAsync
, GrabModeAsync
,
1312 newFocused
= nextToFocusAfter(wwin
);
1314 newFocused
= nextToFocusBefore(wwin
);
1317 scr
->flags
.doing_alt_tab
= 1;
1319 wWindowFocus(newFocused
, scr
->focused_window
);
1320 oldFocused
= newFocused
;
1322 OpenSwitchMenu(scr
, scr
->scr_width
/2, scr
->scr_height
/2, False
);
1327 WMMaskEvent(dpy
,KeyPressMask
|KeyReleaseMask
|ExposureMask
, &ev
);
1328 /* WMNextEvent(dpy, &ev);*/
1329 if (ev
.type
!= KeyRelease
&& ev
.type
!= KeyPress
) {
1334 /* ignore CapsLock */
1335 modifiers
= ev
.xkey
.state
& ValidModMask
;
1337 if (ev
.type
== KeyPress
1338 && wKeyBindings
[WKBD_FOCUSNEXT
].keycode
== ev
.xkey
.keycode
1339 && wKeyBindings
[WKBD_FOCUSNEXT
].modifier
== modifiers
) {
1341 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
1342 newFocused
= nextToFocusAfter(newFocused
);
1343 wWindowFocus(newFocused
, oldFocused
);
1344 oldFocused
= newFocused
;
1345 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
1347 } else if (ev
.type
== KeyPress
1348 && wKeyBindings
[WKBD_FOCUSPREV
].keycode
== ev
.xkey
.keycode
1349 && wKeyBindings
[WKBD_FOCUSPREV
].modifier
== modifiers
) {
1351 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
1352 newFocused
= nextToFocusBefore(newFocused
);
1353 wWindowFocus(newFocused
, oldFocused
);
1354 oldFocused
= newFocused
;
1355 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
1357 if (ev
.type
== KeyRelease
) {
1360 for (i
= 0; i
<= 8 * keymap
->max_keypermod
; i
++) {
1361 if (keymap
->modifiermap
[i
] == ev
.xkey
.keycode
&&
1362 wKeyBindings
[WKBD_FOCUSNEXT
].modifier
1363 & 1<<(i
/keymap
->max_keypermod
)) {
1373 XUngrabKeyboard(dpy
, CurrentTime
);
1374 wSetFocusTo(scr
, newFocused
);
1375 scr
->flags
.doing_alt_tab
= 0;
1376 OpenSwitchMenu(scr
, scr
->scr_width
/2, scr
->scr_height
/2, False
);
1380 #endif /* WEENDOZE_CYCLE */
1386 handleKeyPress(XEvent
*event
)
1388 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1389 WWindow
*wwin
= scr
->focused_window
;
1393 #ifdef KEEP_XKB_LOCK_STATUS
1394 XkbStateRec staterec
;
1395 #endif /*KEEP_XKB_LOCK_STATUS*/
1397 /* ignore CapsLock */
1398 modifiers
= event
->xkey
.state
& ValidModMask
;
1400 for (i
=0; i
<WKBD_LAST
; i
++) {
1401 if (wKeyBindings
[i
].keycode
==0)
1404 if (wKeyBindings
[i
].keycode
==event
->xkey
.keycode
1405 && (/*wKeyBindings[i].modifier==0
1406 ||*/ wKeyBindings
[i
].modifier
==modifiers
)) {
1419 if (!wRootMenuPerformShortcut(event
)) {
1421 static int dontLoop
= 0;
1423 if (dontLoop
> 10) {
1424 wwarning("problem with key event processing code");
1428 /* if the focused window is an internal window, try redispatching
1429 * the event to the managed window, as it can be a WINGs window */
1430 if (wwin
&& wwin
->flags
.internal_window
1431 && wwin
->client_leader
!=None
) {
1432 /* client_leader contains the WINGs toplevel */
1433 event
->xany
.window
= wwin
->client_leader
;
1434 WMHandleEvent(event
);
1441 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1442 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1447 OpenRootMenu(scr
, event
->xkey
.x_root
, event
->xkey
.y_root
, True
);
1449 case WKBD_WINDOWLIST
:
1450 OpenSwitchMenu(scr
, event
->xkey
.x_root
, event
->xkey
.y_root
, True
);
1453 case WKBD_WINDOWMENU
:
1454 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1455 OpenWindowMenu(wwin
, wwin
->frame_x
,
1456 wwin
->frame_y
+wwin
->frame
->top_width
, True
);
1458 case WKBD_MINIATURIZE
:
1459 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1460 && !WFLAGP(wwin
, no_miniaturizable
)) {
1461 CloseWindowMenu(scr
);
1463 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1464 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
1465 event
->xbutton
.time
);
1467 wIconifyWindow(wwin
);
1472 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1473 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1474 CloseWindowMenu(scr
);
1476 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1477 wHideApplication(wapp
);
1482 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_resizable
)) {
1483 CloseWindowMenu(scr
);
1485 if (wwin
->flags
.maximized
) {
1486 wUnmaximizeWindow(wwin
);
1488 wMaximizeWindow(wwin
, MAX_VERTICAL
|MAX_HORIZONTAL
);
1492 case WKBD_VMAXIMIZE
:
1493 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_resizable
)) {
1494 CloseWindowMenu(scr
);
1496 if (wwin
->flags
.maximized
) {
1497 wUnmaximizeWindow(wwin
);
1499 wMaximizeWindow(wwin
, MAX_VERTICAL
);
1504 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1505 CloseWindowMenu(scr
);
1507 wRaiseFrame(wwin
->frame
->core
);
1511 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1512 CloseWindowMenu(scr
);
1514 wLowerFrame(wwin
->frame
->core
);
1517 case WKBD_RAISELOWER
:
1518 /* raise or lower the window under the pointer, not the
1521 wwin
= windowUnderPointer(scr
);
1523 wRaiseLowerFrame(wwin
->frame
->core
);
1526 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1527 if (wwin
->flags
.shaded
)
1528 wUnshadeWindow(wwin
);
1533 case WKBD_MOVERESIZE
:
1534 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1535 CloseWindowMenu(scr
);
1537 wKeyboardMoveResizeWindow(wwin
);
1541 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1542 CloseWindowMenu(scr
);
1543 if (wwin
->protocols
.DELETE_WINDOW
)
1544 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
,
1549 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1550 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1553 case WKBD_FOCUSNEXT
:
1554 #ifdef WEENDOZE_CYCLE
1555 if (wPreferences
.windoze_cycling
) {
1556 doWindozeCycle(wwin
, event
, True
);
1558 #endif /* WEENDOZE_CYCLE */
1560 wwin
= NextFocusWindow(scr
);
1562 wSetFocusTo(scr
, wwin
);
1563 if (wPreferences
.circ_raise
)
1564 wRaiseFrame(wwin
->frame
->core
);
1569 case WKBD_FOCUSPREV
:
1570 #ifdef WEENDOZE_CYCLE
1571 if (wPreferences
.windoze_cycling
) {
1572 doWindozeCycle(wwin
, event
, False
);
1574 #endif /* WEENDOZE_CYCLE */
1576 wwin
= PrevFocusWindow(scr
);
1578 wSetFocusTo(scr
, wwin
);
1579 if (wPreferences
.circ_raise
)
1580 wRaiseFrame(wwin
->frame
->core
);
1585 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1586 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1587 i = (scr->current_workspace/10)*10 + wk - 1;\
1588 if (wPreferences.ws_advance || i<scr->workspace_count)\
1589 wWorkspaceChange(scr, i);\
1592 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1593 i = (scr->current_workspace/10)*10 + wk - 1;\
1594 if (wPreferences.ws_advance || i<scr->workspace_count)\
1595 wWorkspaceChange(scr, i);\
1609 case WKBD_NEXTWORKSPACE
:
1610 wWorkspaceRelativeChange(scr
, 1);
1612 case WKBD_PREVWORKSPACE
:
1613 wWorkspaceRelativeChange(scr
, -1);
1619 #ifdef EXTEND_WINDOWSHORTCUT
1627 if (scr
->shortcutWindow
[command
-WKBD_WINDOW1
]) {
1628 wMakeWindowVisible(scr
->shortcutWindow
[command
-WKBD_WINDOW1
]);
1629 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1630 scr
->shortcutWindow
[command
-WKBD_WINDOW1
] = wwin
;
1631 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1634 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1638 case WKBD_NEXTWSLAYER
:
1639 case WKBD_PREVWSLAYER
:
1643 row
= scr
->current_workspace
/10;
1644 column
= scr
->current_workspace
%10;
1646 if (command
==WKBD_NEXTWSLAYER
) {
1647 if ((row
+1)*10 < scr
->workspace_count
)
1648 wWorkspaceChange(scr
, column
+(row
+1)*10);
1651 wWorkspaceChange(scr
, column
+(row
-1)*10);
1655 case WKBD_CLIPLOWER
:
1656 if (!wPreferences
.flags
.noclip
)
1657 wDockLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1659 case WKBD_CLIPRAISE
:
1660 if (!wPreferences
.flags
.noclip
)
1661 wDockRaise(scr
->workspaces
[scr
->current_workspace
]->clip
);
1663 case WKBD_CLIPRAISELOWER
:
1664 if (!wPreferences
.flags
.noclip
)
1665 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1667 #ifdef KEEP_XKB_LOCK_STATUS
1669 if(wPreferences
.modelock
){
1670 XkbGetState(dpy
,XkbUseCoreKbd
,&staterec
);
1672 XkbLockGroup(dpy
,XkbUseCoreKbd
,
1673 wwin
->languagemode
=staterec
.compat_state
&32?0:1);
1676 #endif /* KEEP_XKB_LOCK_STATUS */
1683 handleMotionNotify(XEvent
*event
)
1686 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1689 if (wPreferences
.scrollable_menus
) {
1690 if (event
->xmotion
.x_root
<= 1 ||
1691 event
->xmotion
.x_root
>= (scr
->scr_width
- 2) ||
1692 event
->xmotion
.y_root
<= 1 ||
1693 event
->xmotion
.y_root
>= (scr
->scr_height
- 2)) {
1696 puts("pointer at screen edge");
1699 menu
= wMenuUnderPointer(scr
);
1701 wMenuScroll(menu
, event
);
1705 if (event
->xmotion
.subwindow
== None
)
1708 if (scr
->scrolledFMaximize
!= None
) {
1711 twin
= wWindowFor(scr
->scrolledFMaximize
);
1712 if (twin
&& twin
->frame_y
==) {
1716 scr
->scrolledFMaximize
= NULL
;
1720 /* scroll full maximized window */
1721 if (event
->xmotion
.y_root
< 1
1722 || event
->xmotion
.y_root
> scr
->scr_height
- 1) {
1724 wwin
= wWindowFor(event
->xmotion
.subwindow
);
1726 if (wwin
&& (wwin
->flags
.maximized
& MAX_VERTICAL
)
1727 && WFLAGP(wwin
, full_maximize
)
1728 && event
->xmotion
.x_root
>= wwin
->frame_x
1729 && event
->xmotion
.x_root
<= wwin
->frame_x
+ wwin
->frame
->core
->width
) {
1731 if (!WFLAGP(wwin
, no_titlebar
)
1732 && wwin
->frame_y
<= - wwin
->frame
->top_width
) {
1734 wWindowMove(wwin
, wwin
->frame_x
, 0);
1735 wwin
->flags
.dragged_while_fmaximized
= 0;
1737 } else if (!WFLAGP(wwin
, no_resizebar
)
1738 && wwin
->frame_y
+ wwin
->frame
->core
->height
>=
1739 scr
->scr_height
+ wwin
->frame
->bottom_width
) {
1741 int y
= scr
->scr_height
+ wwin
->frame
->bottom_width
;
1743 y
= scr
->scr_height
- wwin
->frame_y
- wwin
->frame
->core
->height
;
1745 wWindowMove(wwin
, wwin
->frame_x
, y
);
1746 wwin
->flags
.dragged_while_fmaximized
= 0;
1755 handleVisibilityNotify(XEvent
*event
)
1759 wwin
= wWindowFor(event
->xvisibility
.window
);
1762 wwin
->flags
.obscured
=
1763 (event
->xvisibility
.state
== VisibilityFullyObscured
);