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
);
302 handleExtensions(event
);
309 *----------------------------------------------------------------------
311 * Processes X and internal events indefinitely.
317 * The LastTimestamp global variable is updated.
318 *----------------------------------------------------------------------
326 WMNextEvent(dpy
, &event
);
327 WMHandleEvent(&event
);
334 IsDoubleClick(WScreen
*scr
, XEvent
*event
)
336 if ((scr
->last_click_time
>0) &&
337 (event
->xbutton
.time
-scr
->last_click_time
<=wPreferences
.dblclick_time
)
338 && (event
->xbutton
.button
== scr
->last_click_button
)
339 && (event
->xbutton
.window
== scr
->last_click_window
)) {
341 scr
->flags
.next_click_is_not_double
= 1;
342 scr
->last_click_time
= 0;
343 scr
->last_click_window
= event
->xbutton
.window
;
352 NotifyDeadProcess(pid_t pid
, unsigned char status
)
354 if (deadProcessPtr
>=MAX_DEAD_PROCESSES
-1) {
355 wwarning("stack overflow: too many dead processes");
358 /* stack the process to be handled later,
359 * as this is called from the signal handler */
360 deadProcesses
[deadProcessPtr
].pid
= pid
;
361 deadProcesses
[deadProcessPtr
].exit_status
= status
;
367 handleDeadProcess(void *foo
)
372 for (i
=0; i
<deadProcessPtr
; i
++) {
373 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
381 /* get the pids on the queue and call handlers */
382 while (deadProcessPtr
>0) {
391 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
392 (*tmp
->callback
)(tmp
->pid
,
393 deadProcesses
[deadProcessPtr
].exit_status
,
395 wDeleteDeathHandler(tmp
);
404 saveTimestamp(XEvent
*event
)
406 LastTimestamp
= CurrentTime
;
408 switch (event
->type
) {
411 LastTimestamp
= event
->xbutton
.time
;
415 LastTimestamp
= event
->xkey
.time
;
418 LastTimestamp
= event
->xmotion
.time
;
421 LastTimestamp
= event
->xproperty
.time
;
425 LastTimestamp
= event
->xcrossing
.time
;
428 LastTimestamp
= event
->xselectionclear
.time
;
430 case SelectionRequest
:
431 LastTimestamp
= event
->xselectionrequest
.time
;
433 case SelectionNotify
:
434 LastTimestamp
= event
->xselection
.time
;
441 handleExtensions(XEvent
*event
)
444 if (wShapeSupported
&& event
->type
== (wShapeEventBase
+ShapeNotify
)) {
445 handleShapeNotify(event
);
448 #ifdef KEEP_XKB_LOCK_STATUS
449 if (wPreferences
.modelock
&& event
->type
== (0x50|XkbIndicatorStateNotify
)){
450 /* if someone know how to call this 0x50
451 * or how to clean code this please tell ]d */
452 handleXkbIndicatorStateNotify(event
);
454 #endif /*KEEP_XKB_LOCK_STATUS*/
459 handleMapRequest(XEvent
*ev
)
463 Window window
= ev
->xmaprequest
.window
;
466 printf("got map request for %x\n", (unsigned)window
);
469 if ((wwin
= wWindowFor(window
))) {
470 if (wwin
->flags
.shaded
) {
471 wUnshadeWindow(wwin
);
473 /* deiconify window */
474 if (wwin
->flags
.miniaturized
) {
475 wDeiconifyWindow(wwin
);
476 } else if (wwin
->flags
.hidden
) {
477 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
478 /* go to the last workspace that the user worked on the app */
479 #ifndef REDUCE_APPICONS
480 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
481 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
484 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
487 wUnhideApplication(wapp
, False
, False
);
492 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
494 wwin
= wManageWindow(scr
, window
);
497 * This is to let the Dock know that the application it launched
498 * has already been mapped (eg: it has finished launching).
499 * It is not necessary for normally docked apps, but is needed for
500 * apps that were forcedly docked (like with dockit).
502 if (scr
->last_dock
) {
503 if (wwin
&& wwin
->main_window
!=None
&& wwin
->main_window
!=window
)
504 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
506 wDockTrackWindowLaunch(scr
->last_dock
, window
);
510 wClientSetState(wwin
, NormalState
, None
);
511 if (wwin
->flags
.maximized
) {
512 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
514 if (wwin
->flags
.shaded
) {
515 wwin
->flags
.shaded
= 0;
516 wwin
->flags
.skip_next_animation
= 1;
519 if (wwin
->flags
.miniaturized
) {
520 wwin
->flags
.miniaturized
= 0;
521 wwin
->flags
.skip_next_animation
= 1;
522 wIconifyWindow(wwin
);
524 if (wwin
->flags
.hidden
) {
525 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
527 wwin
->flags
.hidden
= 0;
528 wwin
->flags
.skip_next_animation
= 1;
530 wHideApplication(wapp
);
538 handleDestroyNotify(XEvent
*event
)
542 Window window
= event
->xdestroywindow
.window
;
545 puts("got destroy notify");
548 wwin
= wWindowFor(window
);
550 wUnmanageWindow(wwin
, False
, True
);
553 app
= wApplicationOf(window
);
555 if (window
== app
->main_window
) {
557 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
559 if (wwin
->main_window
== window
) {
560 wwin
->main_window
= None
;
565 wApplicationDestroy(app
);
569 wKWMCheckDestroy(&event
->xdestroywindow
);
576 handleExpose(XEvent
*event
)
578 WObjDescriptor
*desc
;
585 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
));
587 if (XFindContext(dpy
, event
->xexpose
.window
, wWinContext
,
588 (XPointer
*)&desc
)==XCNOENT
) {
592 if (desc
->handle_expose
) {
593 (*desc
->handle_expose
)(desc
, event
);
600 handleButtonPress(XEvent
*event
)
602 WObjDescriptor
*desc
;
606 puts("got button press");
609 scr
= wScreenForRootWindow(event
->xbutton
.root
);
617 if (event
->xbutton
.window
==scr
->root_win
) {
620 if (wGNOMEProxyizeButtonEvent(scr
, event
))
624 if (event
->xbutton
.button
==wPreferences
.menu_button
) {
625 OpenRootMenu(scr
, event
->xbutton
.x_root
,
626 event
->xbutton
.y_root
, False
);
628 if (scr
->root_menu
) {
629 if (scr
->root_menu
->brother
->flags
.mapped
)
630 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
632 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
634 } else if (event
->xbutton
.button
==wPreferences
.windowl_button
) {
635 OpenSwitchMenu(scr
, event
->xbutton
.x_root
,
636 event
->xbutton
.y_root
, False
);
637 if (scr
->switch_menu
) {
638 if (scr
->switch_menu
->brother
->flags
.mapped
)
639 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
641 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
643 } else if (event
->xbutton
.button
==wPreferences
.select_button
) {
644 wUnselectWindows(scr
);
645 wSelectWindows(scr
, event
);
647 #ifdef MOUSE_WS_SWITCH
648 else if (event
->xbutton
.button
==Button5
) {
650 wWorkspaceRelativeChange(scr
, -1);
652 } else if (event
->xbutton
.button
==Button4
) {
654 wWorkspaceRelativeChange(scr
, 1);
657 #endif /* MOUSE_WS_SWITCH */
661 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
,
662 (XPointer
*)&desc
)==XCNOENT
) {
663 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
,
664 (XPointer
*)&desc
)==XCNOENT
) {
669 if (desc
->handle_mousedown
!=NULL
) {
670 (*desc
->handle_mousedown
)(desc
, event
);
673 if (desc
->parent_type
== WCLASS_WINDOW
) {
676 if (event
->xbutton
.state
& MOD_MASK
) {
677 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
680 if (wPreferences
.focus_mode
== WKF_CLICK
) {
681 if (wPreferences
.ignore_focus_click
) {
682 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
684 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
687 } else if (desc
->parent_type
== WCLASS_APPICON
688 || desc
->parent_type
== WCLASS_MINIWINDOW
689 || desc
->parent_type
== WCLASS_DOCK_ICON
) {
690 if (event
->xbutton
.state
& MOD_MASK
) {
692 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
697 /* save double-click information */
698 if (scr
->flags
.next_click_is_not_double
) {
699 scr
->flags
.next_click_is_not_double
= 0;
701 scr
->last_click_time
= event
->xbutton
.time
;
702 scr
->last_click_button
= event
->xbutton
.button
;
703 scr
->last_click_window
= event
->xbutton
.window
;
709 handleMapNotify(XEvent
*event
)
717 wwin
= wWindowFor(event
->xmap
.event
);
718 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
719 if (wwin
->flags
.miniaturized
) {
720 wDeiconifyWindow(wwin
);
724 wClientSetState(wwin
, NormalState
, None
);
732 handleUnmapNotify(XEvent
*event
)
736 Bool withdraw
= False
;
742 /* only process windows with StructureNotify selected
743 * (ignore SubstructureNotify) */
744 wwin
= wWindowFor(event
->xunmap
.window
);
748 /* whether the event is a Withdrawal request */
749 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
750 && event
->xunmap
.send_event
)
753 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
756 if (!wwin
->flags
.mapped
&& !withdraw
757 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
758 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
762 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
763 wwin
->flags
.mapped
= 0;
765 /* check if the window was destroyed */
766 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
,&ev
)) {
769 Bool reparented
= False
;
771 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
774 /* withdraw window */
775 wwin
->flags
.mapped
= 0;
777 wClientSetState(wwin
, WithdrawnState
, None
);
779 /* if the window was reparented, do not reparent it back to the
781 // wUnmanageWindow(wwin, !reparented, False);
788 handleConfigureRequest(XEvent
*event
)
793 puts("got configure request");
795 if (!(wwin
=wWindowFor(event
->xconfigurerequest
.window
))) {
797 * Configure request for unmapped window
799 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
801 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
807 handlePropertyNotify(XEvent
*event
)
817 puts("got property notify");
819 if ((wwin
=wWindowFor(event
->xproperty
.window
))) {
820 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
,
821 &ju
, &ju
, &ju
, &ju
)) {
824 wClientCheckProperty(wwin
, &event
->xproperty
);
826 wapp
= wApplicationOf(event
->xproperty
.window
);
828 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
831 scr
= wScreenForWindow(event
->xproperty
.window
);
832 if (scr
&& scr
->root_win
== event
->xproperty
.window
) {
834 wKWMCheckRootHintChange(scr
, &event
->xproperty
);
841 handleClientMessage(XEvent
*event
)
844 WObjDescriptor
*desc
;
847 puts("got client message");
849 /* handle transition from Normal to Iconic state */
850 if (event
->xclient
.message_type
== _XA_WM_CHANGE_STATE
851 && event
->xclient
.format
== 32
852 && event
->xclient
.data
.l
[0] == IconicState
) {
854 wwin
= wWindowFor(event
->xclient
.window
);
856 if (!wwin
->flags
.miniaturized
)
857 wIconifyWindow(wwin
);
858 } else if (event
->xclient
.message_type
== _XA_WM_COLORMAP_NOTIFY
859 && event
->xclient
.format
== 32) {
860 WScreen
*scr
= wScreenSearchForRootWindow(event
->xclient
.window
);
865 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
866 wColormapAllowClientInstallation(scr
, True
);
867 } else { /* stopping */
868 wColormapAllowClientInstallation(scr
, False
);
870 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
873 wapp
= wApplicationOf(event
->xclient
.window
);
875 switch (event
->xclient
.data
.l
[0]) {
876 case WMFHideOtherApplications
:
877 wHideOtherApplications(wapp
->main_window_desc
);
881 case WMFHideApplication
:
882 wHideApplication(wapp
);
888 wwin
= wWindowFor(event
->xclient
.window
);
890 switch (event
->xclient
.data
.l
[0]) {
891 case WMFHideOtherApplications
:
892 wHideOtherApplications(wwin
);
895 case WMFHideApplication
:
896 wHideApplication(wApplicationOf(wwin
->main_window
));
902 } else if (wGNOMEProcessClientMessage(&event
->xclient
)) {
904 #endif /* GNOME_STUFF */
906 } else if (wKWMProcessClientMessage(&event
->xclient
)) {
908 #endif /* KWM_HINTS */
910 } else if (wXDEProcessClientMessage(&event
->xclient
)) {
914 } else if (event
->xclient
.message_type
==_XA_DND_PROTOCOL
) {
915 WScreen
*scr
= wScreenForWindow(event
->xclient
.window
);
916 if (scr
&& wDockReceiveDNDDrop(scr
,event
))
917 goto redirect_message
;
918 #endif /* OFFIX_DND */
924 * Non-standard thing, but needed by OffiX DND.
925 * For when the icon frame gets a ClientMessage
926 * that should have gone to the icon_window.
928 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
,
929 (XPointer
*)&desc
)!=XCNOENT
) {
930 struct WIcon
*icon
=NULL
;
932 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
933 icon
= (WIcon
*)desc
->parent
;
934 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
935 || desc
->parent_type
== WCLASS_APPICON
) {
936 icon
= ((WAppIcon
*)desc
->parent
)->icon
;
938 if (icon
&& (wwin
=icon
->owner
)) {
939 if (wwin
->client_win
!=event
->xclient
.window
) {
940 event
->xclient
.window
= wwin
->client_win
;
941 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
,
951 raiseWindow(WScreen
*scr
)
955 scr
->autoRaiseTimer
= NULL
;
957 wwin
= wWindowFor(scr
->autoRaiseWindow
);
961 if (!wwin
->flags
.destroyed
) {
962 wRaiseFrame(wwin
->frame
->core
);
963 /* this is needed or a race condition will occur */
970 handleEnterNotify(XEvent
*event
)
973 WObjDescriptor
*desc
= NULL
;
975 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
979 puts("got enter notify");
982 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
,
984 /* already left the window... */
986 if (ev
.xcrossing
.mode
==event
->xcrossing
.mode
987 && ev
.xcrossing
.detail
==event
->xcrossing
.detail
) {
992 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
,
993 (XPointer
*)&desc
)!=XCNOENT
) {
994 if(desc
->handle_enternotify
)
995 (*desc
->handle_enternotify
)(desc
, event
);
998 /* enter to window */
999 wwin
= wWindowFor(event
->xcrossing
.window
);
1001 if (wPreferences
.focus_mode
==WKF_POINTER
1002 && event
->xcrossing
.window
==event
->xcrossing
.root
) {
1003 wSetFocusTo(scr
, NULL
);
1005 if (wPreferences
.colormap_mode
==WKF_POINTER
) {
1006 wColormapInstallForWindow(scr
, NULL
);
1008 if (scr
->autoRaiseTimer
1009 && event
->xcrossing
.root
==event
->xcrossing
.window
) {
1010 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1011 scr
->autoRaiseTimer
= NULL
;
1014 /* set auto raise timer even if in focus-follows-mouse mode
1015 * and the event is for the frame window, even if the window
1016 * has focus already. useful if you move the pointer from a focused
1017 * window to the root window and back pretty fast
1019 * set focus if in focus-follows-mouse mode and the event
1020 * is for the frame window and window doesn't have focus yet */
1021 if ((wPreferences
.focus_mode
==WKF_POINTER
1022 || wPreferences
.focus_mode
==WKF_SLOPPY
)
1023 && wwin
->frame
->core
->window
==event
->xcrossing
.window
1024 && !scr
->flags
.doing_alt_tab
) {
1026 if (!wwin
->flags
.focused
)
1027 wSetFocusTo(scr
, wwin
);
1029 if (scr
->autoRaiseTimer
)
1030 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1031 scr
->autoRaiseTimer
= NULL
;
1033 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1034 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1036 = WMAddTimerHandler(wPreferences
.raise_delay
,
1037 (WMCallback
*)raiseWindow
, scr
);
1040 /* Install colormap for window, if the colormap installation mode
1041 * is colormap_follows_mouse */
1042 if (wPreferences
.colormap_mode
==WKF_POINTER
) {
1043 if (wwin
->client_win
==event
->xcrossing
.window
)
1044 wColormapInstallForWindow(scr
, wwin
);
1046 wColormapInstallForWindow(scr
, NULL
);
1050 /* a little kluge to hide the clip balloon */
1051 if (!wPreferences
.flags
.noclip
&& scr
->flags
.clip_balloon_mapped
) {
1053 XUnmapWindow(dpy
, scr
->clip_balloon
);
1054 scr
->flags
.clip_balloon_mapped
= 0;
1056 if (desc
->parent_type
!=WCLASS_DOCK_ICON
1057 || scr
->clip_icon
!= desc
->parent
) {
1058 XUnmapWindow(dpy
, scr
->clip_balloon
);
1059 scr
->flags
.clip_balloon_mapped
= 0;
1064 if (event
->xcrossing
.window
== event
->xcrossing
.root
1065 && event
->xcrossing
.detail
== NotifyNormal
1066 && event
->xcrossing
.detail
!= NotifyInferior
1067 && wPreferences
.focus_mode
!= WKF_CLICK
) {
1069 wSetFocusTo(scr
, scr
->focused_window
);
1073 wBalloonEnteredObject(scr
, desc
);
1079 handleLeaveNotify(XEvent
*event
)
1081 WObjDescriptor
*desc
= NULL
;
1083 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
,
1084 (XPointer
*)&desc
)!=XCNOENT
) {
1085 if(desc
->handle_leavenotify
)
1086 (*desc
->handle_leavenotify
)(desc
, event
);
1088 if (event
->xcrossing
.window
== event
->xcrossing
.root
1089 && event
->xcrossing
.mode
== NotifyNormal
1090 && event
->xcrossing
.detail
!= NotifyInferior
1091 && wPreferences
.focus_mode
!= WKF_CLICK
) {
1093 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1095 wSetFocusTo(scr
, NULL
);
1102 handleShapeNotify(XEvent
*event
)
1104 XShapeEvent
*shev
= (XShapeEvent
*)event
;
1109 puts("got shape notify");
1112 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
)) {
1113 XShapeEvent
*sev
= (XShapeEvent
*)&ev
;
1115 if (sev
->kind
== ShapeBounding
) {
1116 if (sev
->shaped
== shev
->shaped
) {
1119 XPutBackEvent(dpy
, &ev
);
1125 wwin
= wWindowFor(shev
->window
);
1126 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1129 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1131 wwin
->flags
.shaped
= 0;
1132 wWindowClearShape(wwin
);
1134 } else if (shev
->shaped
) {
1136 wwin
->flags
.shaped
= 1;
1137 wWindowSetShape(wwin
);
1142 #ifdef KEEP_XKB_LOCK_STATUS
1143 /* please help ]d if you know what to do */
1144 handleXkbIndicatorStateNotify(XEvent
*event
)
1148 XkbStateRec staterec
;
1151 XkbGetState(dpy
,XkbUseCoreKbd
,&staterec
);
1152 for (i
=0; i
<wScreenCount
; i
++) {
1153 scr
= wScreenWithNumber(i
);
1154 wwin
= scr
->focused_window
;
1155 if (wwin
->flags
.focused
) {
1156 wwin
->frame
->languagemode
=staterec
.compat_state
&32?1:0;
1157 #ifdef XKB_TITLE_HINT
1158 if (wwin
->frame
->titlebar
) {
1159 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
1160 wFrameWindowPaint(wwin
->frame
);
1162 #endif /* XKB_TITLE_HINT */
1166 #endif /*KEEP_XKB_LOCK_STATUS*/
1169 handleColormapNotify(XEvent
*event
)
1173 Bool reinstall
= False
;
1175 wwin
= wWindowFor(event
->xcolormap
.window
);
1179 scr
= wwin
->screen_ptr
;
1183 if (event
->xcolormap
.new) {
1184 XWindowAttributes attr
;
1186 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1188 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1189 scr
->current_colormap
= attr
.colormap
;
1192 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1193 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1195 /* some bastard app (like XV) removed our colormap */
1197 * can't enforce or things like xscreensaver wont work
1200 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1201 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1203 /* someone has put our colormap back */
1207 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1208 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1210 if (reinstall
&& scr
->current_colormap
!=None
) {
1211 if (!scr
->flags
.colormap_stuff_blocked
)
1212 XInstallColormap(dpy
, scr
->current_colormap
);
1219 handleFocusIn(XEvent
*event
)
1224 * For applications that like stealing the focus.
1226 while (XCheckTypedEvent(dpy
, FocusIn
, event
));
1227 saveTimestamp(event
);
1228 if (event
->xfocus
.mode
== NotifyUngrab
1229 || event
->xfocus
.mode
== NotifyGrab
1230 || event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1234 wwin
= wWindowFor(event
->xfocus
.window
);
1235 if (wwin
&& !wwin
->flags
.focused
) {
1236 if (wwin
->flags
.mapped
)
1237 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1239 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1241 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1243 wSetFocusTo(scr
, NULL
);
1249 windowUnderPointer(WScreen
*scr
)
1255 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
,
1257 return wWindowFor(win
);
1261 #ifdef WEENDOZE_CYCLE
1264 nextToFocusAfter(WWindow
*wwin
)
1266 WWindow
*tmp
= wwin
->next
;
1269 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
1277 /* start over from the beginning of the list */
1281 while (tmp
&& tmp
!= wwin
) {
1282 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
1294 nextToFocusBefore(WWindow
*wwin
)
1296 WWindow
*tmp
= wwin
->prev
;
1299 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
1306 /* start over from the beginning of the list */
1311 while (tmp
&& tmp
!= wwin
) {
1312 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
1323 doWindozeCycle(WWindow
*wwin
, XEvent
*event
, Bool next
)
1325 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1327 WWindow
*newFocused
;
1328 WWindow
*oldFocused
;
1330 XModifierKeymap
*keymap
;
1336 keymap
= XGetModifierMapping(dpy
);
1339 XGrabKeyboard(dpy
, scr
->root_win
, False
, GrabModeAsync
, GrabModeAsync
,
1343 newFocused
= nextToFocusAfter(wwin
);
1345 newFocused
= nextToFocusBefore(wwin
);
1348 scr
->flags
.doing_alt_tab
= 1;
1350 wWindowFocus(newFocused
, scr
->focused_window
);
1351 oldFocused
= newFocused
;
1353 OpenSwitchMenu(scr
, scr
->scr_width
/2, scr
->scr_height
/2, False
);
1358 WMMaskEvent(dpy
,KeyPressMask
|KeyReleaseMask
|ExposureMask
, &ev
);
1359 /* WMNextEvent(dpy, &ev);*/
1360 if (ev
.type
!= KeyRelease
&& ev
.type
!= KeyPress
) {
1365 /* ignore CapsLock */
1366 modifiers
= ev
.xkey
.state
& ValidModMask
;
1368 if (ev
.type
== KeyPress
1369 && wKeyBindings
[WKBD_FOCUSNEXT
].keycode
== ev
.xkey
.keycode
1370 && wKeyBindings
[WKBD_FOCUSNEXT
].modifier
== modifiers
) {
1372 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
1373 newFocused
= nextToFocusAfter(newFocused
);
1374 wWindowFocus(newFocused
, oldFocused
);
1375 oldFocused
= newFocused
;
1376 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
1378 } else if (ev
.type
== KeyPress
1379 && wKeyBindings
[WKBD_FOCUSPREV
].keycode
== ev
.xkey
.keycode
1380 && wKeyBindings
[WKBD_FOCUSPREV
].modifier
== modifiers
) {
1382 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
1383 newFocused
= nextToFocusBefore(newFocused
);
1384 wWindowFocus(newFocused
, oldFocused
);
1385 oldFocused
= newFocused
;
1386 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
1388 if (ev
.type
== KeyRelease
) {
1391 for (i
= 0; i
<= 8 * keymap
->max_keypermod
; i
++) {
1392 if (keymap
->modifiermap
[i
] == ev
.xkey
.keycode
&&
1393 wKeyBindings
[WKBD_FOCUSNEXT
].modifier
1394 & 1<<(i
/keymap
->max_keypermod
)) {
1404 XUngrabKeyboard(dpy
, CurrentTime
);
1405 wSetFocusTo(scr
, newFocused
);
1406 scr
->flags
.doing_alt_tab
= 0;
1407 OpenSwitchMenu(scr
, scr
->scr_width
/2, scr
->scr_height
/2, False
);
1411 #endif /* WEENDOZE_CYCLE */
1417 handleKeyPress(XEvent
*event
)
1419 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1420 WWindow
*wwin
= scr
->focused_window
;
1424 #ifdef KEEP_XKB_LOCK_STATUS
1425 XkbStateRec staterec
;
1426 #endif /*KEEP_XKB_LOCK_STATUS*/
1428 /* ignore CapsLock */
1429 modifiers
= event
->xkey
.state
& ValidModMask
;
1431 for (i
=0; i
<WKBD_LAST
; i
++) {
1432 if (wKeyBindings
[i
].keycode
==0)
1435 if (wKeyBindings
[i
].keycode
==event
->xkey
.keycode
1436 && (/*wKeyBindings[i].modifier==0
1437 ||*/ wKeyBindings
[i
].modifier
==modifiers
)) {
1450 if (!wRootMenuPerformShortcut(event
)) {
1452 static int dontLoop
= 0;
1454 if (dontLoop
> 10) {
1455 wwarning("problem with key event processing code");
1459 /* if the focused window is an internal window, try redispatching
1460 * the event to the managed window, as it can be a WINGs window */
1461 if (wwin
&& wwin
->flags
.internal_window
1462 && wwin
->client_leader
!=None
) {
1463 /* client_leader contains the WINGs toplevel */
1464 event
->xany
.window
= wwin
->client_leader
;
1465 WMHandleEvent(event
);
1472 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1473 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1478 OpenRootMenu(scr
, event
->xkey
.x_root
, event
->xkey
.y_root
, True
);
1480 case WKBD_WINDOWLIST
:
1481 OpenSwitchMenu(scr
, event
->xkey
.x_root
, event
->xkey
.y_root
, True
);
1484 case WKBD_WINDOWMENU
:
1485 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1486 OpenWindowMenu(wwin
, wwin
->frame_x
,
1487 wwin
->frame_y
+wwin
->frame
->top_width
, True
);
1489 case WKBD_MINIATURIZE
:
1490 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1491 && !WFLAGP(wwin
, no_miniaturizable
)) {
1492 CloseWindowMenu(scr
);
1494 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1495 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
1496 event
->xbutton
.time
);
1498 wIconifyWindow(wwin
);
1503 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1504 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1505 CloseWindowMenu(scr
);
1507 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1508 wHideApplication(wapp
);
1513 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_resizable
)) {
1514 CloseWindowMenu(scr
);
1516 if (wwin
->flags
.maximized
) {
1517 wUnmaximizeWindow(wwin
);
1519 wMaximizeWindow(wwin
, MAX_VERTICAL
|MAX_HORIZONTAL
);
1523 case WKBD_VMAXIMIZE
:
1524 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_resizable
)) {
1525 CloseWindowMenu(scr
);
1527 if (wwin
->flags
.maximized
) {
1528 wUnmaximizeWindow(wwin
);
1530 wMaximizeWindow(wwin
, MAX_VERTICAL
);
1535 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1536 CloseWindowMenu(scr
);
1538 wRaiseFrame(wwin
->frame
->core
);
1542 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1543 CloseWindowMenu(scr
);
1545 wLowerFrame(wwin
->frame
->core
);
1548 case WKBD_RAISELOWER
:
1549 /* raise or lower the window under the pointer, not the
1552 wwin
= windowUnderPointer(scr
);
1554 wRaiseLowerFrame(wwin
->frame
->core
);
1557 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1558 if (wwin
->flags
.shaded
)
1559 wUnshadeWindow(wwin
);
1564 case WKBD_MOVERESIZE
:
1565 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1566 CloseWindowMenu(scr
);
1568 wKeyboardMoveResizeWindow(wwin
);
1572 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1573 CloseWindowMenu(scr
);
1574 if (wwin
->protocols
.DELETE_WINDOW
)
1575 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
,
1580 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1581 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1584 case WKBD_FOCUSNEXT
:
1585 #ifdef WEENDOZE_CYCLE
1586 if (wPreferences
.windoze_cycling
) {
1587 doWindozeCycle(wwin
, event
, True
);
1589 #endif /* WEENDOZE_CYCLE */
1591 wwin
= NextFocusWindow(scr
);
1593 wSetFocusTo(scr
, wwin
);
1594 if (wPreferences
.circ_raise
)
1595 wRaiseFrame(wwin
->frame
->core
);
1600 case WKBD_FOCUSPREV
:
1601 #ifdef WEENDOZE_CYCLE
1602 if (wPreferences
.windoze_cycling
) {
1603 doWindozeCycle(wwin
, event
, False
);
1605 #endif /* WEENDOZE_CYCLE */
1607 wwin
= PrevFocusWindow(scr
);
1609 wSetFocusTo(scr
, wwin
);
1610 if (wPreferences
.circ_raise
)
1611 wRaiseFrame(wwin
->frame
->core
);
1616 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1617 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1618 i = (scr->current_workspace/10)*10 + wk - 1;\
1619 if (wPreferences.ws_advance || i<scr->workspace_count)\
1620 wWorkspaceChange(scr, i);\
1623 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1624 i = (scr->current_workspace/10)*10 + wk - 1;\
1625 if (wPreferences.ws_advance || i<scr->workspace_count)\
1626 wWorkspaceChange(scr, i);\
1640 case WKBD_NEXTWORKSPACE
:
1641 wWorkspaceRelativeChange(scr
, 1);
1643 case WKBD_PREVWORKSPACE
:
1644 wWorkspaceRelativeChange(scr
, -1);
1650 #ifdef EXTEND_WINDOWSHORTCUT
1658 if (scr
->shortcutWindow
[command
-WKBD_WINDOW1
]) {
1659 wMakeWindowVisible(scr
->shortcutWindow
[command
-WKBD_WINDOW1
]);
1660 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1661 scr
->shortcutWindow
[command
-WKBD_WINDOW1
] = wwin
;
1662 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1665 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1669 case WKBD_NEXTWSLAYER
:
1670 case WKBD_PREVWSLAYER
:
1674 row
= scr
->current_workspace
/10;
1675 column
= scr
->current_workspace
%10;
1677 if (command
==WKBD_NEXTWSLAYER
) {
1678 if ((row
+1)*10 < scr
->workspace_count
)
1679 wWorkspaceChange(scr
, column
+(row
+1)*10);
1682 wWorkspaceChange(scr
, column
+(row
-1)*10);
1686 case WKBD_CLIPLOWER
:
1687 if (!wPreferences
.flags
.noclip
)
1688 wDockLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1690 case WKBD_CLIPRAISE
:
1691 if (!wPreferences
.flags
.noclip
)
1692 wDockRaise(scr
->workspaces
[scr
->current_workspace
]->clip
);
1694 case WKBD_CLIPRAISELOWER
:
1695 if (!wPreferences
.flags
.noclip
)
1696 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1698 #ifdef KEEP_XKB_LOCK_STATUS
1700 if(wPreferences
.modelock
){
1701 XkbGetState(dpy
,XkbUseCoreKbd
,&staterec
);
1703 XkbLockGroup(dpy
,XkbUseCoreKbd
,
1704 wwin
->frame
->languagemode
=staterec
.compat_state
&32?0:1);
1707 #endif /* KEEP_XKB_LOCK_STATUS */
1714 handleMotionNotify(XEvent
*event
)
1717 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1720 if (wPreferences
.scrollable_menus
) {
1721 if (event
->xmotion
.x_root
<= 1 ||
1722 event
->xmotion
.x_root
>= (scr
->scr_width
- 2) ||
1723 event
->xmotion
.y_root
<= 1 ||
1724 event
->xmotion
.y_root
>= (scr
->scr_height
- 2)) {
1727 puts("pointer at screen edge");
1730 menu
= wMenuUnderPointer(scr
);
1732 wMenuScroll(menu
, event
);
1736 if (event
->xmotion
.subwindow
== None
)
1739 if (scr
->scrolledFMaximize
!= None
) {
1742 twin
= wWindowFor(scr
->scrolledFMaximize
);
1743 if (twin
&& twin
->frame_y
==) {
1747 scr
->scrolledFMaximize
= NULL
;
1751 /* scroll full maximized window */
1752 if (event
->xmotion
.y_root
< 1
1753 || event
->xmotion
.y_root
> scr
->scr_height
- 1) {
1755 wwin
= wWindowFor(event
->xmotion
.subwindow
);
1757 if (wwin
&& (wwin
->flags
.maximized
& MAX_VERTICAL
)
1758 && WFLAGP(wwin
, full_maximize
)
1759 && event
->xmotion
.x_root
>= wwin
->frame_x
1760 && event
->xmotion
.x_root
<= wwin
->frame_x
+ wwin
->frame
->core
->width
) {
1762 if (!WFLAGP(wwin
, no_titlebar
)
1763 && wwin
->frame_y
<= - wwin
->frame
->top_width
) {
1765 wWindowMove(wwin
, wwin
->frame_x
, 0);
1766 wwin
->flags
.dragged_while_fmaximized
= 0;
1768 } else if (!WFLAGP(wwin
, no_resizebar
)
1769 && wwin
->frame_y
+ wwin
->frame
->core
->height
>=
1770 scr
->scr_height
+ wwin
->frame
->bottom_width
) {
1772 int y
= scr
->scr_height
+ wwin
->frame
->bottom_width
;
1774 y
= scr
->scr_height
- wwin
->frame_y
- wwin
->frame
->core
->height
;
1776 wWindowMove(wwin
, wwin
->frame_x
, y
);
1777 wwin
->flags
.dragged_while_fmaximized
= 0;
1786 handleVisibilityNotify(XEvent
*event
)
1790 wwin
= wWindowFor(event
->xvisibility
.window
);
1793 wwin
->flags
.obscured
=
1794 (event
->xvisibility
.state
== VisibilityFullyObscured
);