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 WProgramState
;
99 extern char WDelayedActionSet
;
102 /************ Local stuff ***********/
105 static void saveTimestamp(XEvent
*event
);
106 static void handleColormapNotify();
107 static void handleMapNotify(), handleUnmapNotify();
108 static void handleButtonPress(), handleExpose();
109 static void handleDestroyNotify();
110 static void handleConfigureRequest();
111 static void handleMapRequest();
112 static void handlePropertyNotify();
113 static void handleEnterNotify();
114 static void handleLeaveNotify();
115 static void handleExtensions();
116 static void handleClientMessage();
117 static void handleKeyPress();
118 static void handleFocusIn();
119 static void handleMotionNotify();
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 (WProgramState
==WSTATE_NEED_EXIT
) {
208 WProgramState
= 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 (WProgramState
== WSTATE_NEED_RESTART
) {
218 WProgramState
= 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
->xmap
.window
);
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
);
299 handleExtensions(event
);
306 *----------------------------------------------------------------------
308 * Processes X and internal events indefinitely.
314 * The LastTimestamp global variable is updated.
315 *----------------------------------------------------------------------
323 WMNextEvent(dpy
, &event
);
324 WMHandleEvent(&event
);
331 IsDoubleClick(WScreen
*scr
, XEvent
*event
)
333 if ((scr
->last_click_time
>0) &&
334 (event
->xbutton
.time
-scr
->last_click_time
<=wPreferences
.dblclick_time
)
335 && (event
->xbutton
.button
== scr
->last_click_button
)
336 && (event
->xbutton
.subwindow
== scr
->last_click_window
)) {
338 scr
->flags
.next_click_is_not_double
= 1;
339 scr
->last_click_time
= 0;
340 scr
->last_click_window
= None
;
349 NotifyDeadProcess(pid_t pid
, unsigned char status
)
351 if (deadProcessPtr
>=MAX_DEAD_PROCESSES
-1) {
352 wwarning(_("stack overflow: too many dead processes"));
355 /* stack the process to be handled later,
356 * as this is called from the signal handler */
357 deadProcesses
[deadProcessPtr
].pid
= pid
;
358 deadProcesses
[deadProcessPtr
].exit_status
= status
;
364 handleDeadProcess(void *foo
)
369 for (i
=0; i
<deadProcessPtr
; i
++) {
370 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
378 /* get the pids on the queue and call handlers */
379 while (deadProcessPtr
>0) {
388 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
389 (*tmp
->callback
)(tmp
->pid
,
390 deadProcesses
[deadProcessPtr
].exit_status
,
392 wDeleteDeathHandler(tmp
);
401 saveTimestamp(XEvent
*event
)
403 LastTimestamp
= CurrentTime
;
405 switch (event
->type
) {
408 LastTimestamp
= event
->xbutton
.time
;
412 LastTimestamp
= event
->xkey
.time
;
415 LastTimestamp
= event
->xmotion
.time
;
418 LastTimestamp
= event
->xproperty
.time
;
422 LastTimestamp
= event
->xcrossing
.time
;
425 LastTimestamp
= event
->xselectionclear
.time
;
427 case SelectionRequest
:
428 LastTimestamp
= event
->xselectionrequest
.time
;
430 case SelectionNotify
:
431 LastTimestamp
= event
->xselection
.time
;
438 handleExtensions(XEvent
*event
)
441 if (wShapeSupported
&& event
->type
== (wShapeEventBase
+ShapeNotify
)) {
442 handleShapeNotify(event
);
449 handleMapRequest(XEvent
*ev
)
453 Window window
= ev
->xmaprequest
.window
;
456 printf("got map request for %x\n", (unsigned)window
);
459 if ((wwin
=wWindowFor(window
))) {
460 if (wwin
->flags
.shaded
) {
461 wUnshadeWindow(wwin
);
463 /* deiconify window */
464 if (wwin
->flags
.miniaturized
) {
465 wDeiconifyWindow(wwin
);
466 } else if (wwin
->flags
.hidden
) {
467 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
468 /* go to the last workspace that the user worked on the app */
469 #ifndef REDUCE_APPICONS
470 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
471 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
474 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
477 wUnhideApplication(wapp
, False
, False
);
482 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
484 wwin
= wManageWindow(scr
, window
);
487 * This is to let the Dock know that the application it launched
488 * has already been mapped (eg: it has finished launching).
489 * It is not necessary for normally docked apps, but is needed for
490 * apps that were forcedly docked (like with dockit).
492 if (scr
->last_dock
) {
493 if (wwin
&& wwin
->main_window
!=None
&& wwin
->main_window
!=window
)
494 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
496 wDockTrackWindowLaunch(scr
->last_dock
, window
);
503 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
))
504 state
= wwin
->wm_hints
->initial_state
;
508 if (state
==IconicState
)
509 wwin
->flags
.miniaturized
= 1;
511 if (state
== WithdrawnState
) {
512 wwin
->flags
.mapped
= 0;
513 wClientSetState(wwin
, WithdrawnState
, None
);
514 wUnmanageWindow(wwin
, True
, False
);
516 wClientSetState(wwin
, NormalState
, None
);
517 if (wwin
->flags
.maximized
) {
518 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
520 if (wwin
->flags
.shaded
) {
521 wwin
->flags
.shaded
= 0;
522 wwin
->flags
.skip_next_animation
= 1;
523 wwin
->flags
.ignore_next_unmap
= 1; /* ??? */
526 if (wwin
->flags
.miniaturized
) {
527 wwin
->flags
.miniaturized
= 0;
528 wwin
->flags
.hidden
= 0;
529 wwin
->flags
.skip_next_animation
= 1;
530 wwin
->flags
.ignore_next_unmap
= 1;
531 wIconifyWindow(wwin
);
532 } else if (wwin
->flags
.hidden
) {
533 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
534 wwin
->flags
.hidden
= 0;
535 wwin
->flags
.skip_next_animation
= 1;
537 wHideApplication(wapp
);
539 wwin
->flags
.ignore_next_unmap
= 1;
547 handleDestroyNotify(XEvent
*event
)
551 Window window
= event
->xdestroywindow
.window
;
554 puts("got destroy notify");
557 wwin
= wWindowFor(window
);
559 wUnmanageWindow(wwin
, False
, True
);
562 app
= wApplicationOf(window
);
564 if (window
== app
->main_window
) {
566 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
568 if (wwin
->main_window
== window
) {
569 wwin
->main_window
= None
;
574 wApplicationDestroy(app
);
578 wKWMCheckDestroy(&event
->xdestroywindow
);
585 handleExpose(XEvent
*event
)
587 WObjDescriptor
*desc
;
592 if (event
->xexpose
.count
!=0) {
596 if (XFindContext(dpy
, event
->xexpose
.window
, wWinContext
,
597 (XPointer
*)&desc
)==XCNOENT
) {
601 if (desc
->handle_expose
) {
602 (*desc
->handle_expose
)(desc
, event
);
609 handleButtonPress(XEvent
*event
)
611 WObjDescriptor
*desc
;
615 puts("got button press");
618 scr
= wScreenForRootWindow(event
->xbutton
.root
);
626 if (event
->xbutton
.window
==scr
->root_win
) {
629 if (wGNOMEProxyizeButtonEvent(scr
, event
))
633 if (event
->xbutton
.button
==wPreferences
.menu_button
) {
634 OpenRootMenu(scr
, event
->xbutton
.x_root
,
635 event
->xbutton
.y_root
, False
);
637 if (scr
->root_menu
) {
638 if (scr
->root_menu
->brother
->flags
.mapped
)
639 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
641 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
643 } else if (event
->xbutton
.button
==wPreferences
.windowl_button
) {
644 OpenSwitchMenu(scr
, event
->xbutton
.x_root
,
645 event
->xbutton
.y_root
, False
);
646 if (scr
->switch_menu
) {
647 if (scr
->switch_menu
->brother
->flags
.mapped
)
648 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
650 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
652 } else if (event
->xbutton
.button
==wPreferences
.select_button
) {
653 wUnselectWindows(scr
);
654 wSelectWindows(scr
, event
);
656 #ifdef MOUSE_WS_SWITCH
657 else if (event
->xbutton
.button
==Button4
) {
659 wWorkspaceRelativeChange(scr
, -1);
661 } else if (event
->xbutton
.button
==Button5
) {
663 wWorkspaceRelativeChange(scr
, 1);
666 #endif /* MOUSE_WS_SWITCH */
670 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
,
671 (XPointer
*)&desc
)==XCNOENT
) {
672 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
,
673 (XPointer
*)&desc
)==XCNOENT
) {
678 if (desc
->parent_type
== WCLASS_WINDOW
) {
681 if (event
->xbutton
.state
& MOD_MASK
) {
682 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
685 if (wPreferences
.focus_mode
== WKF_CLICK
) {
686 if (wPreferences
.ignore_focus_click
) {
687 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
689 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
692 } else if (desc
->parent_type
== WCLASS_APPICON
693 || desc
->parent_type
== WCLASS_MINIWINDOW
694 || desc
->parent_type
== WCLASS_DOCK_ICON
) {
695 if (event
->xbutton
.state
& MOD_MASK
) {
697 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
702 if (desc
->handle_mousedown
!=NULL
) {
703 (*desc
->handle_mousedown
)(desc
, event
);
706 /* save double-click information */
707 if (scr
->flags
.next_click_is_not_double
) {
708 scr
->flags
.next_click_is_not_double
= 0;
710 scr
->last_click_time
= event
->xbutton
.time
;
711 scr
->last_click_button
= event
->xbutton
.button
;
712 scr
->last_click_window
= event
->xbutton
.subwindow
;
718 handleMapNotify(Window window
)
725 wwin
= wWindowFor(window
);
726 if (wwin
&& wwin
->client_win
==window
) {
727 if (wwin
->flags
.ignore_next_unmap
) {
728 wwin
->flags
.ignore_next_unmap
=0;
731 if (wwin
->flags
.miniaturized
) {
732 wDeiconifyWindow(wwin
);
736 XMapWindow(dpy
, wwin
->client_win
);
737 XMapWindow(dpy
, wwin
->frame
->core
->window
);
738 wwin
->flags
.mapped
=1;
739 wClientSetState(wwin
, NormalState
, None
);
747 handleUnmapNotify(XEvent
*event
)
755 wwin
= wWindowFor(event
->xunmap
.window
);
756 if (!wwin
|| wwin
->client_win
!=event
->xunmap
.window
)
759 if (!wwin
->flags
.mapped
760 && wwin
->frame
->workspace
==wwin
->screen_ptr
->current_workspace
761 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
764 if (wwin
->flags
.ignore_next_unmap
) {
768 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
769 wwin
->flags
.mapped
= 0;
771 /* check if the window was destroyed */
772 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
,&ev
)) {
775 Bool reparented
= False
;
777 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
780 /* withdraw window */
781 wwin
->flags
.mapped
= 0;
783 wClientSetState(wwin
, WithdrawnState
, None
);
785 /* if the window was reparented, do not reparent it back to the
787 wUnmanageWindow(wwin
, !reparented
, False
);
794 handleConfigureRequest(XEvent
*event
)
799 puts("got configure request");
801 if (!(wwin
=wWindowFor(event
->xconfigurerequest
.window
))) {
803 * Configure request for unmapped window
805 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
807 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
813 handlePropertyNotify(XEvent
*event
)
823 puts("got property notify");
825 if ((wwin
=wWindowFor(event
->xproperty
.window
))) {
826 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
,
827 &ju
, &ju
, &ju
, &ju
)) {
830 wClientCheckProperty(wwin
, &event
->xproperty
);
832 wapp
= wApplicationOf(event
->xproperty
.window
);
834 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
837 scr
= wScreenForWindow(event
->xproperty
.window
);
838 if (scr
&& scr
->root_win
== event
->xproperty
.window
) {
840 wKWMCheckRootHintChange(scr
, &event
->xproperty
);
847 handleClientMessage(XEvent
*event
)
850 WObjDescriptor
*desc
;
853 puts("got client message");
855 /* handle transition from Normal to Iconic state */
856 if (event
->xclient
.message_type
== _XA_WM_CHANGE_STATE
857 && event
->xclient
.format
== 32
858 && event
->xclient
.data
.l
[0] == IconicState
) {
860 wwin
= wWindowFor(event
->xclient
.window
);
862 if (!wwin
->flags
.miniaturized
)
863 wIconifyWindow(wwin
);
864 } else if (event
->xclient
.message_type
== _XA_WM_COLORMAP_NOTIFY
865 && event
->xclient
.format
== 32) {
866 WScreen
*scr
= wScreenForRootWindow(event
->xclient
.window
);
871 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
872 wColormapAllowClientInstallation(scr
, True
);
873 } else { /* stopping */
874 wColormapAllowClientInstallation(scr
, False
);
876 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
879 wapp
= wApplicationOf(event
->xclient
.window
);
881 switch (event
->xclient
.data
.l
[0]) {
882 case WMFHideOtherApplications
:
883 wHideOtherApplications(wapp
->main_window_desc
);
887 case WMFHideApplication
:
888 wHideApplication(wapp
);
894 wwin
= wWindowFor(event
->xclient
.window
);
896 switch (event
->xclient
.data
.l
[0]) {
897 case WMFHideOtherApplications
:
898 wHideOtherApplications(wwin
);
901 case WMFHideApplication
:
902 wHideApplication(wApplicationOf(wwin
->main_window
));
908 } else if (wGNOMEProcessClientMessage(&event
->xclient
)) {
910 #endif /* GNOME_STUFF */
912 } else if (wKWMProcessClientMessage(&event
->xclient
)) {
914 #endif /* KWM_HINTS */
916 } else if (wXDEProcessClientMessage(&event
->xclient
)) {
920 } else if (event
->xclient
.message_type
==_XA_DND_PROTOCOL
) {
921 WScreen
*scr
= wScreenForWindow(event
->xclient
.window
);
922 if (scr
&& wDockReceiveDNDDrop(scr
,event
))
923 goto redirect_message
;
924 #endif /* OFFIX_DND */
930 * Non-standard thing, but needed by OffiX DND.
931 * For when the icon frame gets a ClientMessage
932 * that should have gone to the icon_window.
934 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
,
935 (XPointer
*)&desc
)!=XCNOENT
) {
936 struct WIcon
*icon
=NULL
;
938 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
939 icon
= (WIcon
*)desc
->parent
;
940 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
941 || desc
->parent_type
== WCLASS_APPICON
) {
942 icon
= ((WAppIcon
*)desc
->parent
)->icon
;
944 if (icon
&& (wwin
=icon
->owner
)) {
945 if (wwin
->client_win
!=event
->xclient
.window
) {
946 event
->xclient
.window
= wwin
->client_win
;
947 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
,
957 raiseWindow(WScreen
*scr
)
961 scr
->autoRaiseTimer
= NULL
;
963 wwin
= wWindowFor(scr
->autoRaiseWindow
);
967 if (!wwin
->flags
.destroyed
) {
968 wRaiseFrame(wwin
->frame
->core
);
969 /* this is needed or a race condition will occur */
976 handleEnterNotify(XEvent
*event
)
979 WObjDescriptor
*desc
= NULL
;
981 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
985 puts("got enter notify");
988 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
,
990 /* already left the window... */
992 if (ev
.xcrossing
.mode
==event
->xcrossing
.mode
993 && ev
.xcrossing
.detail
==event
->xcrossing
.detail
) {
998 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
,
999 (XPointer
*)&desc
)!=XCNOENT
) {
1000 if(desc
->handle_enternotify
)
1001 (*desc
->handle_enternotify
)(desc
, event
);
1004 /* enter to window */
1005 wwin
= wWindowFor(event
->xcrossing
.window
);
1007 if (wPreferences
.focus_mode
==WKF_POINTER
1008 && event
->xcrossing
.window
==event
->xcrossing
.root
) {
1009 wSetFocusTo(scr
, NULL
);
1011 if (wPreferences
.colormap_mode
==WKF_POINTER
) {
1012 wColormapInstallForWindow(scr
, NULL
);
1014 if (scr
->autoRaiseTimer
1015 && event
->xcrossing
.root
==event
->xcrossing
.window
) {
1016 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1017 scr
->autoRaiseTimer
= NULL
;
1020 /* set auto raise timer even if in focus-follows-mouse mode
1021 * and the event is for the frame window, even if the window
1022 * has focus already. useful if you move the pointer from a focused
1023 * window to the root window and back pretty fast
1025 * set focus if in focus-follows-mouse mode and the event
1026 * is for the frame window and window doesn't have focus yet */
1027 if ((wPreferences
.focus_mode
==WKF_POINTER
1028 || wPreferences
.focus_mode
==WKF_SLOPPY
)
1029 && wwin
->frame
->core
->window
==event
->xcrossing
.window
) {
1031 if (!wwin
->flags
.focused
)
1032 wSetFocusTo(scr
, wwin
);
1034 if (scr
->autoRaiseTimer
)
1035 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1036 scr
->autoRaiseTimer
= NULL
;
1038 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1039 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1041 = WMAddTimerHandler(wPreferences
.raise_delay
,
1042 (WMCallback
*)raiseWindow
, scr
);
1045 /* Install colormap for window, if the colormap installation mode
1046 * is colormap_follows_mouse */
1047 if (wPreferences
.colormap_mode
==WKF_POINTER
) {
1048 if (wwin
->client_win
==event
->xcrossing
.window
)
1049 wColormapInstallForWindow(scr
, wwin
);
1051 wColormapInstallForWindow(scr
, NULL
);
1055 /* a little kluge to hide the clip balloon */
1056 if (!wPreferences
.flags
.noclip
&& scr
->flags
.clip_balloon_mapped
) {
1058 XUnmapWindow(dpy
, scr
->clip_balloon
);
1059 scr
->flags
.clip_balloon_mapped
= 0;
1061 if (desc
->parent_type
!=WCLASS_DOCK_ICON
1062 || scr
->clip_icon
!= desc
->parent
) {
1063 XUnmapWindow(dpy
, scr
->clip_balloon
);
1064 scr
->flags
.clip_balloon_mapped
= 0;
1069 if (event
->xcrossing
.window
== event
->xcrossing
.root
1070 && event
->xcrossing
.detail
== NotifyNormal
1071 && event
->xcrossing
.detail
!= NotifyInferior
1072 && wPreferences
.focus_mode
!= WKF_CLICK
) {
1074 wSetFocusTo(scr
, scr
->focused_window
);
1078 wBalloonEnteredObject(scr
, desc
);
1084 handleLeaveNotify(XEvent
*event
)
1086 WObjDescriptor
*desc
= NULL
;
1088 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
,
1089 (XPointer
*)&desc
)!=XCNOENT
) {
1090 if(desc
->handle_leavenotify
)
1091 (*desc
->handle_leavenotify
)(desc
, event
);
1093 if (event
->xcrossing
.window
== event
->xcrossing
.root
1094 && event
->xcrossing
.mode
== NotifyNormal
1095 && event
->xcrossing
.detail
!= NotifyInferior
1096 && wPreferences
.focus_mode
!= WKF_CLICK
) {
1098 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1100 wSetFocusTo(scr
, NULL
);
1107 handleShapeNotify(XEvent
*event
)
1109 XShapeEvent
*shev
= (XShapeEvent
*)event
;
1114 puts("got shape notify");
1117 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
)) {
1118 XShapeEvent
*sev
= (XShapeEvent
*)&ev
;
1120 if (sev
->kind
== ShapeBounding
) {
1121 if (sev
->shaped
== shev
->shaped
) {
1124 XPutBackEvent(dpy
, &ev
);
1130 wwin
= wWindowFor(shev
->window
);
1131 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1134 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1136 wwin
->flags
.shaped
= 0;
1137 wWindowClearShape(wwin
);
1139 } else if (shev
->shaped
) {
1141 wwin
->flags
.shaped
= 1;
1142 wWindowSetShape(wwin
);
1149 handleColormapNotify(XEvent
*event
)
1153 Bool reinstall
= False
;
1155 wwin
= wWindowFor(event
->xcolormap
.window
);
1159 scr
= wwin
->screen_ptr
;
1163 if (event
->xcolormap
.new) {
1164 XWindowAttributes attr
;
1166 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1168 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1169 scr
->current_colormap
= attr
.colormap
;
1172 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1173 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1175 /* some bastard app (like XV) removed our colormap */
1177 * can't enforce or things like xscreensaver wont work
1180 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1181 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1183 /* someone has put our colormap back */
1187 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1188 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1190 if (reinstall
&& scr
->current_colormap
!=None
) {
1191 if (!scr
->flags
.colormap_stuff_blocked
)
1192 XInstallColormap(dpy
, scr
->current_colormap
);
1199 handleFocusIn(XEvent
*event
)
1204 * For applications that like stealing the focus.
1206 while (XCheckTypedEvent(dpy
, FocusIn
, event
));
1207 saveTimestamp(event
);
1208 if (event
->xfocus
.mode
== NotifyUngrab
1209 || event
->xfocus
.mode
== NotifyGrab
1210 || event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1214 wwin
= wWindowFor(event
->xfocus
.window
);
1215 if (wwin
&& !wwin
->flags
.focused
) {
1216 if (wwin
->flags
.mapped
)
1217 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1219 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1221 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1223 wSetFocusTo(scr
, NULL
);
1229 windowUnderPointer(WScreen
*scr
)
1235 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
,
1237 return wWindowFor(win
);
1242 handleKeyPress(XEvent
*event
)
1244 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1245 WWindow
*wwin
= scr
->focused_window
;
1249 #ifdef KEEP_XKB_LOCK_STATUS
1250 XkbStateRec staterec
;
1251 #endif /*KEEP_XKB_LOCK_STATUS*/
1253 /* ignore CapsLock */
1254 modifiers
= event
->xkey
.state
& ValidModMask
;
1256 for (i
=0; i
<WKBD_LAST
; i
++) {
1257 if (wKeyBindings
[i
].keycode
==0)
1260 if (wKeyBindings
[i
].keycode
==event
->xkey
.keycode
1261 && (/*wKeyBindings[i].modifier==0
1262 ||*/ wKeyBindings
[i
].modifier
==modifiers
)) {
1275 if (!wRootMenuPerformShortcut(event
)) {
1277 static int dontLoop
= 0;
1279 if (dontLoop
> 10) {
1280 wwarning("problem with key event processing code");
1284 /* if the focused window is an internal window, try redispatching
1285 * the event to the managed window, as it can be a WINGs window */
1286 if (wwin
&& wwin
->flags
.internal_window
1287 && wwin
->client_leader
!=None
) {
1288 /* client_leader contains the WINGs toplevel */
1289 event
->xany
.window
= wwin
->client_leader
;
1290 WMHandleEvent(event
);
1297 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1298 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1303 OpenRootMenu(scr
, event
->xkey
.x_root
, event
->xkey
.y_root
, True
);
1305 case WKBD_WINDOWLIST
:
1306 OpenSwitchMenu(scr
, event
->xkey
.x_root
, event
->xkey
.y_root
, True
);
1309 case WKBD_WINDOWMENU
:
1310 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1311 OpenWindowMenu(wwin
, wwin
->frame_x
,
1312 wwin
->frame_y
+wwin
->frame
->top_width
, True
);
1314 case WKBD_MINIATURIZE
:
1315 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1316 && !WFLAGP(wwin
, no_miniaturizable
)) {
1317 CloseWindowMenu(scr
);
1319 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1320 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
1321 event
->xbutton
.time
);
1323 wIconifyWindow(wwin
);
1328 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1329 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1330 CloseWindowMenu(scr
);
1332 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1333 wHideApplication(wapp
);
1338 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_resizable
)) {
1339 CloseWindowMenu(scr
);
1341 if (wwin
->flags
.maximized
) {
1342 wUnmaximizeWindow(wwin
);
1344 wMaximizeWindow(wwin
, MAX_VERTICAL
|MAX_HORIZONTAL
);
1348 case WKBD_VMAXIMIZE
:
1349 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_resizable
)) {
1350 CloseWindowMenu(scr
);
1352 if (wwin
->flags
.maximized
) {
1353 wUnmaximizeWindow(wwin
);
1355 wMaximizeWindow(wwin
, MAX_VERTICAL
);
1360 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1361 CloseWindowMenu(scr
);
1363 wRaiseFrame(wwin
->frame
->core
);
1367 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1368 CloseWindowMenu(scr
);
1370 wLowerFrame(wwin
->frame
->core
);
1373 case WKBD_RAISELOWER
:
1374 /* raise or lower the window under the pointer, not the
1377 wwin
= windowUnderPointer(scr
);
1379 wRaiseLowerFrame(wwin
->frame
->core
);
1382 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1383 if (wwin
->flags
.shaded
)
1384 wUnshadeWindow(wwin
);
1389 case WKBD_MOVERESIZE
:
1390 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1391 CloseWindowMenu(scr
);
1393 wKeyboardMoveResizeWindow(wwin
);
1397 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1398 CloseWindowMenu(scr
);
1399 if (wwin
->protocols
.DELETE_WINDOW
)
1400 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
,
1405 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1406 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1409 case WKBD_FOCUSNEXT
:
1410 wwin
= NextFocusWindow(scr
);
1412 wSetFocusTo(scr
, wwin
);
1413 if (wPreferences
.circ_raise
)
1414 wRaiseFrame(wwin
->frame
->core
);
1417 case WKBD_FOCUSPREV
:
1418 wwin
= PrevFocusWindow(scr
);
1420 wSetFocusTo(scr
, wwin
);
1421 if (wPreferences
.circ_raise
)
1422 wRaiseFrame(wwin
->frame
->core
);
1425 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1426 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1427 i = (scr->current_workspace/10)*10 + wk - 1;\
1428 if (wPreferences.ws_advance || i<scr->workspace_count)\
1429 wWorkspaceChange(scr, i);\
1432 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1433 i = (scr->current_workspace/10)*10 + wk - 1;\
1434 if (wPreferences.ws_advance || i<scr->workspace_count)\
1435 wWorkspaceChange(scr, i);\
1449 case WKBD_NEXTWORKSPACE
:
1450 wWorkspaceRelativeChange(scr
, 1);
1452 case WKBD_PREVWORKSPACE
:
1453 wWorkspaceRelativeChange(scr
, -1);
1459 #ifdef EXTEND_WINDOWSHORTCUT
1467 if (scr
->shortcutWindow
[command
-WKBD_WINDOW1
]) {
1468 wMakeWindowVisible(scr
->shortcutWindow
[command
-WKBD_WINDOW1
]);
1469 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1470 scr
->shortcutWindow
[command
-WKBD_WINDOW1
] = wwin
;
1471 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1474 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1478 case WKBD_NEXTWSLAYER
:
1479 case WKBD_PREVWSLAYER
:
1483 row
= scr
->current_workspace
/10;
1484 column
= scr
->current_workspace
%10;
1486 if (command
==WKBD_NEXTWSLAYER
) {
1487 if ((row
+1)*10 < scr
->workspace_count
)
1488 wWorkspaceChange(scr
, column
+(row
+1)*10);
1491 wWorkspaceChange(scr
, column
+(row
-1)*10);
1495 case WKBD_CLIPLOWER
:
1496 if (!wPreferences
.flags
.noclip
)
1497 wDockLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1499 case WKBD_CLIPRAISE
:
1500 if (!wPreferences
.flags
.noclip
)
1501 wDockRaise(scr
->workspaces
[scr
->current_workspace
]->clip
);
1503 case WKBD_CLIPRAISELOWER
:
1504 if (!wPreferences
.flags
.noclip
)
1505 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1507 #ifdef KEEP_XKB_LOCK_STATUS
1509 if(wPreferences
.modelock
){
1510 XkbGetState(dpy
,XkbUseCoreKbd
,&staterec
);
1512 XkbLockGroup(dpy
,XkbUseCoreKbd
,
1513 wwin
->languagemode
=staterec
.compat_state
&32?0:1);
1516 #endif /* KEEP_XKB_LOCK_STATUS */
1523 handleMotionNotify(XEvent
*event
)
1526 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1528 if (wPreferences
.scrollable_menus
) {
1529 if (event
->xmotion
.x_root
<= 1 ||
1530 event
->xmotion
.x_root
>= (scr
->scr_width
- 2) ||
1531 event
->xmotion
.y_root
<= 1 ||
1532 event
->xmotion
.y_root
>= (scr
->scr_height
- 2)) {
1535 puts("pointer at screen edge");
1538 menu
= wMenuUnderPointer(scr
);
1540 wMenuScroll(menu
, event
);