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
;
86 extern Atom _XA_WINDOWMAKER_COMMAND
;
89 extern Atom _XA_DND_PROTOCOL
;
94 extern Bool wShapeSupported
;
95 extern int wShapeEventBase
;
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();
120 static void handleVisibilityNotify();
124 static void handleShapeNotify();
127 /* called from the signal handler */
128 void NotifyDeadProcess(pid_t pid
, unsigned char status
);
130 /* real dead process handler */
131 static void handleDeadProcess(void *foo
);
134 typedef struct DeadProcesses
{
136 unsigned char exit_status
;
139 /* stack of dead processes */
140 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
141 static int deadProcessPtr
=0;
144 typedef struct DeathHandler
{
145 WDeathHandler
*callback
;
147 struct DeathHandler
*next
;
151 static DeathHandler
*deathHandler
=NULL
;
156 wAddDeathHandler(pid_t pid
, WDeathHandler
*callback
, void *cdata
)
158 DeathHandler
*handler
;
160 handler
= malloc(sizeof(DeathHandler
));
165 handler
->callback
= callback
;
166 handler
->client_data
= cdata
;
168 handler
->next
= deathHandler
;
170 deathHandler
= handler
;
178 wDeleteDeathHandler(WMagicNumber id
)
180 DeathHandler
*tmp
, *handler
=(DeathHandler
*)id
;
182 if (!handler
|| !deathHandler
)
187 deathHandler
= handler
->next
;
191 if (tmp
->next
==handler
) {
192 tmp
->next
=handler
->next
;
203 DispatchEvent(XEvent
*event
)
206 handleDeadProcess(NULL
);
208 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
209 WCHANGE_STATE(WSTATE_EXITING
);
210 /* received SIGTERM */
212 * WMHandleEvent() can't be called from anything
213 * executed inside here, or we can get in a infinite
216 Shutdown(WSExitMode
);
218 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
219 WCHANGE_STATE(WSTATE_RESTARTING
);
221 Shutdown(WSRestartPreparationMode
);
222 /* received SIGHUP */
226 /* for the case that all that is wanted to be dispatched is
231 saveTimestamp(event
);
232 switch (event
->type
) {
234 handleMapRequest(event
);
238 handleKeyPress(event
);
242 handleMotionNotify(event
);
245 case ConfigureRequest
:
246 handleConfigureRequest(event
);
250 handleDestroyNotify(event
);
254 handleMapNotify(event
);
258 handleUnmapNotify(event
);
262 handleButtonPress(event
);
270 handlePropertyNotify(event
);
274 handleEnterNotify(event
);
278 handleLeaveNotify(event
);
282 handleClientMessage(event
);
286 handleColormapNotify(event
);
290 if (event
->xmapping
.request
== MappingKeyboard
291 || event
->xmapping
.request
== MappingModifier
)
292 XRefreshKeyboardMapping(&event
->xmapping
);
296 handleFocusIn(event
);
299 case VisibilityNotify
:
300 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
);
449 #ifdef KEEP_XKB_LOCK_STATUS
450 if (wPreferences
.modelock
&& event
->type
== (0x50|XkbIndicatorStateNotify
)){
451 /* if someone know how to call this 0x50
452 * or how to clean code this please tell ]d */
453 handleXkbIndicatorStateNotify(event
);
455 #endif /*KEEP_XKB_LOCK_STATUS*/
460 handleMapRequest(XEvent
*ev
)
464 Window window
= ev
->xmaprequest
.window
;
467 printf("got map request for %x\n", (unsigned)window
);
470 if ((wwin
= wWindowFor(window
))) {
471 if (wwin
->flags
.shaded
) {
472 wUnshadeWindow(wwin
);
474 /* deiconify window */
475 if (wwin
->flags
.miniaturized
) {
476 wDeiconifyWindow(wwin
);
477 } else if (wwin
->flags
.hidden
) {
478 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
479 /* go to the last workspace that the user worked on the app */
480 #ifndef REDUCE_APPICONS
481 /* This severely breaks REDUCE_APPICONS. last_workspace is a neat
482 * concept but it needs to be reworked to handle REDUCE_APPICONS -cls
485 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
488 wUnhideApplication(wapp
, False
, False
);
493 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
495 wwin
= wManageWindow(scr
, window
);
498 * This is to let the Dock know that the application it launched
499 * has already been mapped (eg: it has finished launching).
500 * It is not necessary for normally docked apps, but is needed for
501 * apps that were forcedly docked (like with dockit).
503 if (scr
->last_dock
) {
504 if (wwin
&& wwin
->main_window
!=None
&& wwin
->main_window
!=window
)
505 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
507 wDockTrackWindowLaunch(scr
->last_dock
, window
);
511 wClientSetState(wwin
, NormalState
, None
);
512 if (wwin
->flags
.maximized
) {
513 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
515 if (wwin
->flags
.shaded
) {
516 wwin
->flags
.shaded
= 0;
517 wwin
->flags
.skip_next_animation
= 1;
520 if (wwin
->flags
.miniaturized
) {
521 wwin
->flags
.miniaturized
= 0;
522 wwin
->flags
.skip_next_animation
= 1;
523 wIconifyWindow(wwin
);
525 if (wwin
->flags
.hidden
) {
526 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
528 wwin
->flags
.hidden
= 0;
529 wwin
->flags
.skip_next_animation
= 1;
531 wHideApplication(wapp
);
539 handleDestroyNotify(XEvent
*event
)
543 Window window
= event
->xdestroywindow
.window
;
546 puts("got destroy notify");
549 wwin
= wWindowFor(window
);
551 wUnmanageWindow(wwin
, False
, True
);
554 app
= wApplicationOf(window
);
556 if (window
== app
->main_window
) {
558 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
560 if (wwin
->main_window
== window
) {
561 wwin
->main_window
= None
;
566 wApplicationDestroy(app
);
570 wKWMCheckDestroy(&event
->xdestroywindow
);
577 handleExpose(XEvent
*event
)
579 WObjDescriptor
*desc
;
586 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
));
588 if (XFindContext(dpy
, event
->xexpose
.window
, wWinContext
,
589 (XPointer
*)&desc
)==XCNOENT
) {
593 if (desc
->handle_expose
) {
594 (*desc
->handle_expose
)(desc
, event
);
601 handleButtonPress(XEvent
*event
)
603 WObjDescriptor
*desc
;
607 puts("got button press");
610 scr
= wScreenForRootWindow(event
->xbutton
.root
);
618 if (event
->xbutton
.window
==scr
->root_win
) {
621 if (wGNOMEProxyizeButtonEvent(scr
, event
))
625 if (event
->xbutton
.button
==wPreferences
.menu_button
) {
626 OpenRootMenu(scr
, event
->xbutton
.x_root
,
627 event
->xbutton
.y_root
, False
);
629 if (scr
->root_menu
) {
630 if (scr
->root_menu
->brother
->flags
.mapped
)
631 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
633 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
635 } else if (event
->xbutton
.button
==wPreferences
.windowl_button
) {
636 OpenSwitchMenu(scr
, event
->xbutton
.x_root
,
637 event
->xbutton
.y_root
, False
);
638 if (scr
->switch_menu
) {
639 if (scr
->switch_menu
->brother
->flags
.mapped
)
640 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
642 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
644 } else if (event
->xbutton
.button
==wPreferences
.select_button
) {
645 wUnselectWindows(scr
);
646 wSelectWindows(scr
, event
);
648 #ifdef MOUSE_WS_SWITCH
649 else if (event
->xbutton
.button
==Button5
) {
651 wWorkspaceRelativeChange(scr
, -1);
653 } else if (event
->xbutton
.button
==Button4
) {
655 wWorkspaceRelativeChange(scr
, 1);
658 #endif /* MOUSE_WS_SWITCH */
662 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
,
663 (XPointer
*)&desc
)==XCNOENT
) {
664 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
,
665 (XPointer
*)&desc
)==XCNOENT
) {
670 if (desc
->handle_mousedown
!=NULL
) {
671 (*desc
->handle_mousedown
)(desc
, event
);
674 if (desc
->parent_type
== WCLASS_WINDOW
) {
677 if (event
->xbutton
.state
& MOD_MASK
) {
678 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
681 if (wPreferences
.focus_mode
== WKF_CLICK
) {
682 if (wPreferences
.ignore_focus_click
) {
683 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
685 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
688 } else if (desc
->parent_type
== WCLASS_APPICON
689 || desc
->parent_type
== WCLASS_MINIWINDOW
690 || desc
->parent_type
== WCLASS_DOCK_ICON
) {
691 if (event
->xbutton
.state
& MOD_MASK
) {
693 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
698 /* save double-click information */
699 if (scr
->flags
.next_click_is_not_double
) {
700 scr
->flags
.next_click_is_not_double
= 0;
702 scr
->last_click_time
= event
->xbutton
.time
;
703 scr
->last_click_button
= event
->xbutton
.button
;
704 scr
->last_click_window
= event
->xbutton
.window
;
710 handleMapNotify(XEvent
*event
)
718 wwin
= wWindowFor(event
->xmap
.event
);
719 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
720 if (wwin
->flags
.miniaturized
) {
721 wDeiconifyWindow(wwin
);
725 wClientSetState(wwin
, NormalState
, None
);
733 handleUnmapNotify(XEvent
*event
)
737 Bool withdraw
= False
;
743 /* only process windows with StructureNotify selected
744 * (ignore SubstructureNotify) */
745 wwin
= wWindowFor(event
->xunmap
.window
);
749 /* whether the event is a Withdrawal request */
750 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
751 && event
->xunmap
.send_event
)
754 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
757 if (!wwin
->flags
.mapped
&& !withdraw
758 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
759 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
763 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
764 wwin
->flags
.mapped
= 0;
766 /* check if the window was destroyed */
767 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
,&ev
)) {
770 Bool reparented
= False
;
772 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
775 /* withdraw window */
776 wwin
->flags
.mapped
= 0;
778 wClientSetState(wwin
, WithdrawnState
, None
);
780 /* if the window was reparented, do not reparent it back to the
782 wUnmanageWindow(wwin
, !reparented
, False
);
789 handleConfigureRequest(XEvent
*event
)
794 puts("got configure request");
796 if (!(wwin
=wWindowFor(event
->xconfigurerequest
.window
))) {
798 * Configure request for unmapped window
800 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
802 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
808 handlePropertyNotify(XEvent
*event
)
818 puts("got property notify");
820 if ((wwin
=wWindowFor(event
->xproperty
.window
))) {
821 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
,
822 &ju
, &ju
, &ju
, &ju
)) {
825 wClientCheckProperty(wwin
, &event
->xproperty
);
827 wapp
= wApplicationOf(event
->xproperty
.window
);
829 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
832 scr
= wScreenForWindow(event
->xproperty
.window
);
833 if (scr
&& scr
->root_win
== event
->xproperty
.window
) {
835 wKWMCheckRootHintChange(scr
, &event
->xproperty
);
842 handleClientMessage(XEvent
*event
)
845 WObjDescriptor
*desc
;
848 puts("got client message");
850 /* handle transition from Normal to Iconic state */
851 if (event
->xclient
.message_type
== _XA_WM_CHANGE_STATE
852 && event
->xclient
.format
== 32
853 && event
->xclient
.data
.l
[0] == IconicState
) {
855 wwin
= wWindowFor(event
->xclient
.window
);
857 if (!wwin
->flags
.miniaturized
)
858 wIconifyWindow(wwin
);
859 } else if (event
->xclient
.message_type
== _XA_WM_COLORMAP_NOTIFY
860 && event
->xclient
.format
== 32) {
861 WScreen
*scr
= wScreenSearchForRootWindow(event
->xclient
.window
);
866 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
867 wColormapAllowClientInstallation(scr
, True
);
868 } else { /* stopping */
869 wColormapAllowClientInstallation(scr
, False
);
871 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_COMMAND
) {
873 wDefaultsCheckDomains("bla");
875 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
878 wapp
= wApplicationOf(event
->xclient
.window
);
880 switch (event
->xclient
.data
.l
[0]) {
881 case WMFHideOtherApplications
:
882 wHideOtherApplications(wapp
->main_window_desc
);
886 case WMFHideApplication
:
887 wHideApplication(wapp
);
893 wwin
= wWindowFor(event
->xclient
.window
);
895 switch (event
->xclient
.data
.l
[0]) {
896 case WMFHideOtherApplications
:
897 wHideOtherApplications(wwin
);
900 case WMFHideApplication
:
901 wHideApplication(wApplicationOf(wwin
->main_window
));
907 } else if (wGNOMEProcessClientMessage(&event
->xclient
)) {
909 #endif /* GNOME_STUFF */
911 } else if (wKWMProcessClientMessage(&event
->xclient
)) {
913 #endif /* KWM_HINTS */
915 } else if (wXDEProcessClientMessage(&event
->xclient
)) {
919 } else if (event
->xclient
.message_type
==_XA_DND_PROTOCOL
) {
920 WScreen
*scr
= wScreenForWindow(event
->xclient
.window
);
921 if (scr
&& wDockReceiveDNDDrop(scr
,event
))
922 goto redirect_message
;
923 #endif /* OFFIX_DND */
929 * Non-standard thing, but needed by OffiX DND.
930 * For when the icon frame gets a ClientMessage
931 * that should have gone to the icon_window.
933 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
,
934 (XPointer
*)&desc
)!=XCNOENT
) {
935 struct WIcon
*icon
=NULL
;
937 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
938 icon
= (WIcon
*)desc
->parent
;
939 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
940 || desc
->parent_type
== WCLASS_APPICON
) {
941 icon
= ((WAppIcon
*)desc
->parent
)->icon
;
943 if (icon
&& (wwin
=icon
->owner
)) {
944 if (wwin
->client_win
!=event
->xclient
.window
) {
945 event
->xclient
.window
= wwin
->client_win
;
946 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
,
956 raiseWindow(WScreen
*scr
)
960 scr
->autoRaiseTimer
= NULL
;
962 wwin
= wWindowFor(scr
->autoRaiseWindow
);
966 if (!wwin
->flags
.destroyed
) {
967 wRaiseFrame(wwin
->frame
->core
);
968 /* this is needed or a race condition will occur */
975 handleEnterNotify(XEvent
*event
)
978 WObjDescriptor
*desc
= NULL
;
980 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
984 puts("got enter notify");
987 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
,
989 /* already left the window... */
991 if (ev
.xcrossing
.mode
==event
->xcrossing
.mode
992 && ev
.xcrossing
.detail
==event
->xcrossing
.detail
) {
997 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
,
998 (XPointer
*)&desc
)!=XCNOENT
) {
999 if(desc
->handle_enternotify
)
1000 (*desc
->handle_enternotify
)(desc
, event
);
1003 /* enter to window */
1004 wwin
= wWindowFor(event
->xcrossing
.window
);
1006 if (wPreferences
.focus_mode
==WKF_POINTER
1007 && event
->xcrossing
.window
==event
->xcrossing
.root
) {
1008 wSetFocusTo(scr
, NULL
);
1010 if (wPreferences
.colormap_mode
==WKF_POINTER
) {
1011 wColormapInstallForWindow(scr
, NULL
);
1013 if (scr
->autoRaiseTimer
1014 && event
->xcrossing
.root
==event
->xcrossing
.window
) {
1015 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1016 scr
->autoRaiseTimer
= NULL
;
1019 /* set auto raise timer even if in focus-follows-mouse mode
1020 * and the event is for the frame window, even if the window
1021 * has focus already. useful if you move the pointer from a focused
1022 * window to the root window and back pretty fast
1024 * set focus if in focus-follows-mouse mode and the event
1025 * is for the frame window and window doesn't have focus yet */
1026 if ((wPreferences
.focus_mode
==WKF_POINTER
1027 || wPreferences
.focus_mode
==WKF_SLOPPY
)
1028 && wwin
->frame
->core
->window
==event
->xcrossing
.window
1029 && !scr
->flags
.doing_alt_tab
) {
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
);
1147 #ifdef KEEP_XKB_LOCK_STATUS
1148 /* please help ]d if you know what to do */
1149 handleXkbIndicatorStateNotify(XEvent
*event
)
1153 XkbStateRec staterec
;
1156 XkbGetState(dpy
,XkbUseCoreKbd
,&staterec
);
1157 for (i
=0; i
<wScreenCount
; i
++) {
1158 scr
= wScreenWithNumber(i
);
1159 wwin
= scr
->focused_window
;
1160 if (wwin
->flags
.focused
) {
1161 wwin
->frame
->languagemode
=staterec
.compat_state
&32?1:0;
1162 #ifdef XKB_TITLE_HINT
1163 if (wwin
->frame
->titlebar
) {
1164 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
1165 wFrameWindowPaint(wwin
->frame
);
1167 #endif /* XKB_TITLE_HINT */
1171 #endif /*KEEP_XKB_LOCK_STATUS*/
1174 handleColormapNotify(XEvent
*event
)
1178 Bool reinstall
= False
;
1180 wwin
= wWindowFor(event
->xcolormap
.window
);
1184 scr
= wwin
->screen_ptr
;
1188 if (event
->xcolormap
.new) {
1189 XWindowAttributes attr
;
1191 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1193 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1194 scr
->current_colormap
= attr
.colormap
;
1197 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1198 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1200 /* some bastard app (like XV) removed our colormap */
1202 * can't enforce or things like xscreensaver wont work
1205 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1206 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1208 /* someone has put our colormap back */
1212 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1213 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1215 if (reinstall
&& scr
->current_colormap
!=None
) {
1216 if (!scr
->flags
.colormap_stuff_blocked
)
1217 XInstallColormap(dpy
, scr
->current_colormap
);
1224 handleFocusIn(XEvent
*event
)
1229 * For applications that like stealing the focus.
1231 while (XCheckTypedEvent(dpy
, FocusIn
, event
));
1232 saveTimestamp(event
);
1233 if (event
->xfocus
.mode
== NotifyUngrab
1234 || event
->xfocus
.mode
== NotifyGrab
1235 || event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1239 wwin
= wWindowFor(event
->xfocus
.window
);
1240 if (wwin
&& !wwin
->flags
.focused
) {
1241 if (wwin
->flags
.mapped
)
1242 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1244 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1246 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1248 wSetFocusTo(scr
, NULL
);
1254 windowUnderPointer(WScreen
*scr
)
1260 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
,
1262 return wWindowFor(win
);
1266 #ifdef WEENDOZE_CYCLE
1269 nextToFocusAfter(WWindow
*wwin
)
1271 WWindow
*tmp
= wwin
->next
;
1274 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
1282 /* start over from the beginning of the list */
1286 while (tmp
&& tmp
!= wwin
) {
1287 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
1299 nextToFocusBefore(WWindow
*wwin
)
1301 WWindow
*tmp
= wwin
->prev
;
1304 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
1311 /* start over from the beginning of the list */
1316 while (tmp
&& tmp
!= wwin
) {
1317 if (wWindowCanReceiveFocus(tmp
) && !WFLAGP(tmp
, skip_window_list
)) {
1328 doWindozeCycle(WWindow
*wwin
, XEvent
*event
, Bool next
)
1330 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1332 WWindow
*newFocused
;
1333 WWindow
*oldFocused
;
1335 XModifierKeymap
*keymap
;
1341 keymap
= XGetModifierMapping(dpy
);
1344 XGrabKeyboard(dpy
, scr
->root_win
, False
, GrabModeAsync
, GrabModeAsync
,
1348 newFocused
= nextToFocusAfter(wwin
);
1350 newFocused
= nextToFocusBefore(wwin
);
1353 scr
->flags
.doing_alt_tab
= 1;
1355 wWindowFocus(newFocused
, scr
->focused_window
);
1356 oldFocused
= newFocused
;
1358 OpenSwitchMenu(scr
, scr
->scr_width
/2, scr
->scr_height
/2, False
);
1363 WMMaskEvent(dpy
,KeyPressMask
|KeyReleaseMask
|ExposureMask
, &ev
);
1364 /* WMNextEvent(dpy, &ev);*/
1365 if (ev
.type
!= KeyRelease
&& ev
.type
!= KeyPress
) {
1370 /* ignore CapsLock */
1371 modifiers
= ev
.xkey
.state
& ValidModMask
;
1373 if (ev
.type
== KeyPress
1374 && wKeyBindings
[WKBD_FOCUSNEXT
].keycode
== ev
.xkey
.keycode
1375 && wKeyBindings
[WKBD_FOCUSNEXT
].modifier
== modifiers
) {
1377 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
1378 newFocused
= nextToFocusAfter(newFocused
);
1379 wWindowFocus(newFocused
, oldFocused
);
1380 oldFocused
= newFocused
;
1381 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
1383 } else if (ev
.type
== KeyPress
1384 && wKeyBindings
[WKBD_FOCUSPREV
].keycode
== ev
.xkey
.keycode
1385 && wKeyBindings
[WKBD_FOCUSPREV
].modifier
== modifiers
) {
1387 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
1388 newFocused
= nextToFocusBefore(newFocused
);
1389 wWindowFocus(newFocused
, oldFocused
);
1390 oldFocused
= newFocused
;
1391 UpdateSwitchMenu(scr
, newFocused
, ACTION_CHANGE_STATE
);
1393 if (ev
.type
== KeyRelease
) {
1396 for (i
= 0; i
<= 8 * keymap
->max_keypermod
; i
++) {
1397 if (keymap
->modifiermap
[i
] == ev
.xkey
.keycode
&&
1398 wKeyBindings
[WKBD_FOCUSNEXT
].modifier
1399 & 1<<(i
/keymap
->max_keypermod
)) {
1409 XUngrabKeyboard(dpy
, CurrentTime
);
1410 wSetFocusTo(scr
, newFocused
);
1411 scr
->flags
.doing_alt_tab
= 0;
1412 OpenSwitchMenu(scr
, scr
->scr_width
/2, scr
->scr_height
/2, False
);
1416 #endif /* WEENDOZE_CYCLE */
1422 handleKeyPress(XEvent
*event
)
1424 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1425 WWindow
*wwin
= scr
->focused_window
;
1429 #ifdef KEEP_XKB_LOCK_STATUS
1430 XkbStateRec staterec
;
1431 #endif /*KEEP_XKB_LOCK_STATUS*/
1433 /* ignore CapsLock */
1434 modifiers
= event
->xkey
.state
& ValidModMask
;
1436 for (i
=0; i
<WKBD_LAST
; i
++) {
1437 if (wKeyBindings
[i
].keycode
==0)
1440 if (wKeyBindings
[i
].keycode
==event
->xkey
.keycode
1441 && (/*wKeyBindings[i].modifier==0
1442 ||*/ wKeyBindings
[i
].modifier
==modifiers
)) {
1455 if (!wRootMenuPerformShortcut(event
)) {
1457 static int dontLoop
= 0;
1459 if (dontLoop
> 10) {
1460 wwarning("problem with key event processing code");
1464 /* if the focused window is an internal window, try redispatching
1465 * the event to the managed window, as it can be a WINGs window */
1466 if (wwin
&& wwin
->flags
.internal_window
1467 && wwin
->client_leader
!=None
) {
1468 /* client_leader contains the WINGs toplevel */
1469 event
->xany
.window
= wwin
->client_leader
;
1470 WMHandleEvent(event
);
1477 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1478 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1483 OpenRootMenu(scr
, event
->xkey
.x_root
, event
->xkey
.y_root
, True
);
1485 case WKBD_WINDOWLIST
:
1486 OpenSwitchMenu(scr
, event
->xkey
.x_root
, event
->xkey
.y_root
, True
);
1489 case WKBD_WINDOWMENU
:
1490 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1491 OpenWindowMenu(wwin
, wwin
->frame_x
,
1492 wwin
->frame_y
+wwin
->frame
->top_width
, True
);
1494 case WKBD_MINIATURIZE
:
1495 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1496 && !WFLAGP(wwin
, no_miniaturizable
)) {
1497 CloseWindowMenu(scr
);
1499 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1500 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
1501 event
->xbutton
.time
);
1503 wIconifyWindow(wwin
);
1508 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1509 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1510 CloseWindowMenu(scr
);
1512 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1513 wHideApplication(wapp
);
1518 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_resizable
)) {
1519 CloseWindowMenu(scr
);
1521 if (wwin
->flags
.maximized
) {
1522 wUnmaximizeWindow(wwin
);
1524 wMaximizeWindow(wwin
, MAX_VERTICAL
|MAX_HORIZONTAL
);
1528 case WKBD_VMAXIMIZE
:
1529 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_resizable
)) {
1530 CloseWindowMenu(scr
);
1532 if (wwin
->flags
.maximized
) {
1533 wUnmaximizeWindow(wwin
);
1535 wMaximizeWindow(wwin
, MAX_VERTICAL
);
1540 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1541 CloseWindowMenu(scr
);
1543 wRaiseFrame(wwin
->frame
->core
);
1547 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1548 CloseWindowMenu(scr
);
1550 wLowerFrame(wwin
->frame
->core
);
1553 case WKBD_RAISELOWER
:
1554 /* raise or lower the window under the pointer, not the
1557 wwin
= windowUnderPointer(scr
);
1559 wRaiseLowerFrame(wwin
->frame
->core
);
1562 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1563 if (wwin
->flags
.shaded
)
1564 wUnshadeWindow(wwin
);
1569 case WKBD_MOVERESIZE
:
1570 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1571 CloseWindowMenu(scr
);
1573 wKeyboardMoveResizeWindow(wwin
);
1577 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1578 CloseWindowMenu(scr
);
1579 if (wwin
->protocols
.DELETE_WINDOW
)
1580 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
,
1585 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1586 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1589 case WKBD_FOCUSNEXT
:
1590 #ifdef WEENDOZE_CYCLE
1591 if (wPreferences
.windoze_cycling
) {
1592 doWindozeCycle(wwin
, event
, True
);
1594 #endif /* WEENDOZE_CYCLE */
1596 wwin
= NextFocusWindow(scr
);
1598 wSetFocusTo(scr
, wwin
);
1599 if (wPreferences
.circ_raise
)
1600 wRaiseFrame(wwin
->frame
->core
);
1605 case WKBD_FOCUSPREV
:
1606 #ifdef WEENDOZE_CYCLE
1607 if (wPreferences
.windoze_cycling
) {
1608 doWindozeCycle(wwin
, event
, False
);
1610 #endif /* WEENDOZE_CYCLE */
1612 wwin
= PrevFocusWindow(scr
);
1614 wSetFocusTo(scr
, wwin
);
1615 if (wPreferences
.circ_raise
)
1616 wRaiseFrame(wwin
->frame
->core
);
1621 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1622 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1623 i = (scr->current_workspace/10)*10 + wk - 1;\
1624 if (wPreferences.ws_advance || i<scr->workspace_count)\
1625 wWorkspaceChange(scr, i);\
1628 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1629 i = (scr->current_workspace/10)*10 + wk - 1;\
1630 if (wPreferences.ws_advance || i<scr->workspace_count)\
1631 wWorkspaceChange(scr, i);\
1645 case WKBD_NEXTWORKSPACE
:
1646 wWorkspaceRelativeChange(scr
, 1);
1648 case WKBD_PREVWORKSPACE
:
1649 wWorkspaceRelativeChange(scr
, -1);
1655 #ifdef EXTEND_WINDOWSHORTCUT
1663 if (scr
->shortcutWindow
[command
-WKBD_WINDOW1
]) {
1664 wMakeWindowVisible(scr
->shortcutWindow
[command
-WKBD_WINDOW1
]);
1665 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1666 scr
->shortcutWindow
[command
-WKBD_WINDOW1
] = wwin
;
1667 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1670 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1674 case WKBD_NEXTWSLAYER
:
1675 case WKBD_PREVWSLAYER
:
1679 row
= scr
->current_workspace
/10;
1680 column
= scr
->current_workspace
%10;
1682 if (command
==WKBD_NEXTWSLAYER
) {
1683 if ((row
+1)*10 < scr
->workspace_count
)
1684 wWorkspaceChange(scr
, column
+(row
+1)*10);
1687 wWorkspaceChange(scr
, column
+(row
-1)*10);
1691 case WKBD_CLIPLOWER
:
1692 if (!wPreferences
.flags
.noclip
)
1693 wDockLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1695 case WKBD_CLIPRAISE
:
1696 if (!wPreferences
.flags
.noclip
)
1697 wDockRaise(scr
->workspaces
[scr
->current_workspace
]->clip
);
1699 case WKBD_CLIPRAISELOWER
:
1700 if (!wPreferences
.flags
.noclip
)
1701 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1703 #ifdef KEEP_XKB_LOCK_STATUS
1705 if(wPreferences
.modelock
){
1706 XkbGetState(dpy
,XkbUseCoreKbd
,&staterec
);
1708 XkbLockGroup(dpy
,XkbUseCoreKbd
,
1709 wwin
->frame
->languagemode
=staterec
.compat_state
&32?0:1);
1712 #endif /* KEEP_XKB_LOCK_STATUS */
1719 handleMotionNotify(XEvent
*event
)
1722 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1724 if (wPreferences
.scrollable_menus
) {
1725 if (event
->xmotion
.x_root
<= 1 ||
1726 event
->xmotion
.x_root
>= (scr
->scr_width
- 2) ||
1727 event
->xmotion
.y_root
<= 1 ||
1728 event
->xmotion
.y_root
>= (scr
->scr_height
- 2)) {
1731 puts("pointer at screen edge");
1734 menu
= wMenuUnderPointer(scr
);
1736 wMenuScroll(menu
, event
);
1740 if (event
->xmotion
.subwindow
== None
)
1743 if (scr
->scrolledFMaximize
!= None
) {
1746 twin
= wWindowFor(scr
->scrolledFMaximize
);
1747 if (twin
&& twin
->frame_y
==) {
1751 scr
->scrolledFMaximize
= NULL
;
1755 /* scroll full maximized window */
1756 if (event
->xmotion
.y_root
< 1
1757 || event
->xmotion
.y_root
> scr
->scr_height
- 1) {
1759 wwin
= wWindowFor(event
->xmotion
.subwindow
);
1761 if (wwin
&& (wwin
->flags
.maximized
& MAX_VERTICAL
)
1762 && WFLAGP(wwin
, full_maximize
)
1763 && event
->xmotion
.x_root
>= wwin
->frame_x
1764 && event
->xmotion
.x_root
<= wwin
->frame_x
+ wwin
->frame
->core
->width
) {
1766 if (!WFLAGP(wwin
, no_titlebar
)
1767 && wwin
->frame_y
<= - wwin
->frame
->top_width
) {
1769 wWindowMove(wwin
, wwin
->frame_x
, 0);
1770 wwin
->flags
.dragged_while_fmaximized
= 0;
1772 } else if (!WFLAGP(wwin
, no_resizebar
)
1773 && wwin
->frame_y
+ wwin
->frame
->core
->height
>=
1774 scr
->scr_height
+ wwin
->frame
->bottom_width
) {
1776 int y
= scr
->scr_height
+ wwin
->frame
->bottom_width
;
1778 y
= scr
->scr_height
- wwin
->frame_y
- wwin
->frame
->core
->height
;
1780 wWindowMove(wwin
, wwin
->frame_x
, y
);
1781 wwin
->flags
.dragged_while_fmaximized
= 0;
1790 handleVisibilityNotify(XEvent
*event
)
1794 wwin
= wWindowFor(event
->xvisibility
.window
);
1797 wwin
->flags
.obscured
=
1798 (event
->xvisibility
.state
== VisibilityFullyObscured
);