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,
35 #include <X11/Xutil.h>
37 # include <X11/extensions/shape.h>
43 #ifdef KEEP_XKB_LOCK_STATUS
44 #include <X11/XKBlib.h>
45 #endif /* KEEP_XKB_LOCK_STATUS */
47 #include "WindowMaker.h"
53 #include "application.h"
56 #include "workspace.h"
59 #include "properties.h"
69 /******** Global Variables **********/
70 extern XContext wWinContext
;
72 extern Cursor wCursor
[WCUR_LAST
];
74 extern WShortKey wKeyBindings
[WKBD_LAST
];
75 extern int wScreenCount
;
76 extern Time LastTimestamp
;
77 extern Time LastFocusChange
;
79 extern WPreferences wPreferences
;
81 #define MOD_MASK wPreferences.modifier_mask
83 extern Atom _XA_WM_COLORMAP_NOTIFY
;
85 extern Atom _XA_WM_CHANGE_STATE
;
86 extern Atom _XA_WM_DELETE_WINDOW
;
87 extern Atom _XA_GNUSTEP_WM_ATTR
;
88 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
89 extern Atom _XA_GNUSTEP_TITLEBAR_STATE
;
90 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
91 extern Atom _XA_WINDOWMAKER_COMMAND
;
94 extern Atom _XA_DND_PROTOCOL
;
99 extern Bool wShapeSupported
;
100 extern int wShapeEventBase
;
103 #ifdef KEEP_XKB_LOCK_STATUS
104 extern int wXkbEventBase
;
108 extern char WDelayedActionSet
;
111 /************ Local stuff ***********/
114 static void saveTimestamp(XEvent
*event
);
115 static void handleColormapNotify();
116 static void handleMapNotify(), handleUnmapNotify();
117 static void handleButtonPress(), handleExpose();
118 static void handleDestroyNotify();
119 static void handleConfigureRequest();
120 static void handleMapRequest();
121 static void handlePropertyNotify();
122 static void handleEnterNotify();
123 static void handleLeaveNotify();
124 static void handleExtensions();
125 static void handleClientMessage();
126 static void handleKeyPress();
127 static void handleFocusIn();
128 static void handleMotionNotify();
129 static void handleVisibilityNotify();
133 static void handleShapeNotify();
136 /* called from the signal handler */
137 void NotifyDeadProcess(pid_t pid
, unsigned char status
);
139 /* real dead process handler */
140 static void handleDeadProcess(void *foo
);
143 typedef struct DeadProcesses
{
145 unsigned char exit_status
;
148 /* stack of dead processes */
149 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
150 static int deadProcessPtr
=0;
153 typedef struct DeathHandler
{
154 WDeathHandler
*callback
;
159 static WMBag
*deathHandlers
=NULL
;
164 wAddDeathHandler(pid_t pid
, WDeathHandler
*callback
, void *cdata
)
166 DeathHandler
*handler
;
168 handler
= malloc(sizeof(DeathHandler
));
173 handler
->callback
= callback
;
174 handler
->client_data
= cdata
;
177 deathHandlers
= WMCreateBag(8);
179 WMPutInBag(deathHandlers
, handler
);
187 wDeleteDeathHandler(WMagicNumber id
)
189 DeathHandler
*handler
=(DeathHandler
*)id
;
191 if (!handler
|| !deathHandlers
)
194 WMRemoveFromBag(deathHandlers
, handler
);
201 DispatchEvent(XEvent
*event
)
204 handleDeadProcess(NULL
);
206 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
207 WCHANGE_STATE(WSTATE_EXITING
);
208 /* received SIGTERM */
210 * WMHandleEvent() can't be called from anything
211 * executed inside here, or we can get in a infinite
214 Shutdown(WSExitMode
);
216 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
217 WCHANGE_STATE(WSTATE_RESTARTING
);
219 Shutdown(WSRestartPreparationMode
);
220 /* received SIGHUP */
222 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
223 WCHANGE_STATE(WSTATE_NORMAL
);
224 wDefaultsCheckDomains("bla");
227 /* for the case that all that is wanted to be dispatched is
232 saveTimestamp(event
);
233 switch (event
->type
) {
235 handleMapRequest(event
);
239 handleKeyPress(event
);
243 handleMotionNotify(event
);
246 case ConfigureRequest
:
247 handleConfigureRequest(event
);
251 handleDestroyNotify(event
);
255 handleMapNotify(event
);
259 handleUnmapNotify(event
);
263 handleButtonPress(event
);
271 handlePropertyNotify(event
);
275 handleEnterNotify(event
);
279 handleLeaveNotify(event
);
283 handleClientMessage(event
);
287 handleColormapNotify(event
);
291 if (event
->xmapping
.request
== MappingKeyboard
292 || event
->xmapping
.request
== MappingModifier
)
293 XRefreshKeyboardMapping(&event
->xmapping
);
297 handleFocusIn(event
);
300 case VisibilityNotify
:
301 handleVisibilityNotify(event
);
304 handleExtensions(event
);
311 *----------------------------------------------------------------------
313 * Processes X and internal events indefinitely.
319 * The LastTimestamp global variable is updated.
320 *----------------------------------------------------------------------
328 WMNextEvent(dpy
, &event
);
329 WMHandleEvent(&event
);
336 IsDoubleClick(WScreen
*scr
, XEvent
*event
)
338 if ((scr
->last_click_time
>0) &&
339 (event
->xbutton
.time
-scr
->last_click_time
<=wPreferences
.dblclick_time
)
340 && (event
->xbutton
.button
== scr
->last_click_button
)
341 && (event
->xbutton
.window
== scr
->last_click_window
)) {
343 scr
->flags
.next_click_is_not_double
= 1;
344 scr
->last_click_time
= 0;
345 scr
->last_click_window
= event
->xbutton
.window
;
354 NotifyDeadProcess(pid_t pid
, unsigned char status
)
356 if (deadProcessPtr
>=MAX_DEAD_PROCESSES
-1) {
357 wwarning("stack overflow: too many dead processes");
360 /* stack the process to be handled later,
361 * as this is called from the signal handler */
362 deadProcesses
[deadProcessPtr
].pid
= pid
;
363 deadProcesses
[deadProcessPtr
].exit_status
= status
;
369 handleDeadProcess(void *foo
)
374 for (i
=0; i
<deadProcessPtr
; i
++) {
375 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
378 if (!deathHandlers
) {
383 /* get the pids on the queue and call handlers */
384 while (deadProcessPtr
>0) {
387 for (i
= WMGetBagItemCount(deathHandlers
)-1; i
>= 0; i
--) {
388 tmp
= WMGetFromBag(deathHandlers
, i
);
392 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
393 (*tmp
->callback
)(tmp
->pid
,
394 deadProcesses
[deadProcessPtr
].exit_status
,
396 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
;
436 wXDNDProcessSelection(event
);
444 handleExtensions(XEvent
*event
)
446 #ifdef KEEP_XKB_LOCK_STATUS
448 xkbevent
= (XkbEvent
*)event
;
449 #endif /*KEEP_XKB_LOCK_STATUS*/
451 if (wShapeSupported
&& event
->type
== (wShapeEventBase
+ShapeNotify
)) {
452 handleShapeNotify(event
);
455 #ifdef KEEP_XKB_LOCK_STATUS
456 if (wPreferences
.modelock
&& (xkbevent
->type
== wXkbEventBase
)){
457 handleXkbIndicatorStateNotify(event
);
459 #endif /*KEEP_XKB_LOCK_STATUS*/
464 handleMapRequest(XEvent
*ev
)
468 Window window
= ev
->xmaprequest
.window
;
471 L("got map request for %x\n", (unsigned)window
);
473 if ((wwin
= wWindowFor(window
))) {
474 if (wwin
->flags
.shaded
) {
475 wUnshadeWindow(wwin
);
477 /* deiconify window */
478 if (wwin
->flags
.miniaturized
) {
479 wDeiconifyWindow(wwin
);
480 } else if (wwin
->flags
.hidden
) {
481 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
482 /* go to the last workspace that the user worked on the app */
484 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
486 wUnhideApplication(wapp
, False
, False
);
491 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
493 wwin
= wManageWindow(scr
, window
);
496 * This is to let the Dock know that the application it launched
497 * has already been mapped (eg: it has finished launching).
498 * It is not necessary for normally docked apps, but is needed for
499 * apps that were forcedly docked (like with dockit).
501 if (scr
->last_dock
) {
502 if (wwin
&& wwin
->main_window
!=None
&& wwin
->main_window
!=window
)
503 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
505 wDockTrackWindowLaunch(scr
->last_dock
, window
);
509 wClientSetState(wwin
, NormalState
, None
);
510 if (wwin
->flags
.maximized
) {
511 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
513 if (wwin
->flags
.shaded
) {
514 wwin
->flags
.shaded
= 0;
515 wwin
->flags
.skip_next_animation
= 1;
518 if (wwin
->flags
.miniaturized
) {
519 wwin
->flags
.miniaturized
= 0;
520 wwin
->flags
.skip_next_animation
= 1;
521 wIconifyWindow(wwin
);
523 if (wwin
->flags
.hidden
) {
524 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
526 wwin
->flags
.hidden
= 0;
527 wwin
->flags
.skip_next_animation
= 1;
529 wHideApplication(wapp
);
537 handleDestroyNotify(XEvent
*event
)
541 Window window
= event
->xdestroywindow
.window
;
544 L("got destroy notify");
546 wwin
= wWindowFor(window
);
548 wUnmanageWindow(wwin
, False
, True
);
551 app
= wApplicationOf(window
);
553 if (window
== app
->main_window
) {
555 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
557 if (wwin
->main_window
== window
) {
558 wwin
->main_window
= None
;
563 wApplicationDestroy(app
);
567 wKWMCheckDestroy(&event
->xdestroywindow
);
574 handleExpose(XEvent
*event
)
576 WObjDescriptor
*desc
;
582 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
));
584 if (XFindContext(dpy
, event
->xexpose
.window
, wWinContext
,
585 (XPointer
*)&desc
)==XCNOENT
) {
589 if (desc
->handle_expose
) {
590 (*desc
->handle_expose
)(desc
, event
);
596 handleButtonPress(XEvent
*event
)
598 WObjDescriptor
*desc
;
602 L("got button press");
604 scr
= wScreenForRootWindow(event
->xbutton
.root
);
612 if (event
->xbutton
.window
==scr
->root_win
) {
613 if (event
->xbutton
.button
==wPreferences
.menu_button
) {
614 OpenRootMenu(scr
, event
->xbutton
.x_root
,
615 event
->xbutton
.y_root
, False
);
617 if (scr
->root_menu
) {
618 if (scr
->root_menu
->brother
->flags
.mapped
)
619 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
621 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
623 } else if (event
->xbutton
.button
==wPreferences
.windowl_button
) {
624 OpenSwitchMenu(scr
, event
->xbutton
.x_root
,
625 event
->xbutton
.y_root
, False
);
626 if (scr
->switch_menu
) {
627 if (scr
->switch_menu
->brother
->flags
.mapped
)
628 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
630 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
632 } else if (event
->xbutton
.button
==wPreferences
.select_button
) {
633 wUnselectWindows(scr
);
634 wSelectWindows(scr
, event
);
636 else if (event
->xbutton
.button
==Button5
) {
637 wWorkspaceRelativeChange(scr
, -1);
638 } else if (event
->xbutton
.button
==Button4
) {
639 wWorkspaceRelativeChange(scr
, 1);
642 else if (wGNOMEProxyizeButtonEvent(scr
, event
))
649 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
,
650 (XPointer
*)&desc
)==XCNOENT
) {
651 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
,
652 (XPointer
*)&desc
)==XCNOENT
) {
657 if (desc
->parent_type
== WCLASS_WINDOW
) {
660 if (event
->xbutton
.state
& MOD_MASK
) {
661 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
664 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
665 if (wPreferences
.ignore_focus_click
) {
666 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
668 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
671 } else if (desc
->parent_type
== WCLASS_APPICON
672 || desc
->parent_type
== WCLASS_MINIWINDOW
673 || desc
->parent_type
== WCLASS_DOCK_ICON
) {
674 if (event
->xbutton
.state
& MOD_MASK
) {
676 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
681 if (desc
->handle_mousedown
!=NULL
) {
682 (*desc
->handle_mousedown
)(desc
, event
);
685 /* save double-click information */
686 if (scr
->flags
.next_click_is_not_double
) {
687 scr
->flags
.next_click_is_not_double
= 0;
689 scr
->last_click_time
= event
->xbutton
.time
;
690 scr
->last_click_button
= event
->xbutton
.button
;
691 scr
->last_click_window
= event
->xbutton
.window
;
697 handleMapNotify(XEvent
*event
)
703 wwin
= wWindowFor(event
->xmap
.event
);
704 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
705 if (wwin
->flags
.miniaturized
) {
706 wDeiconifyWindow(wwin
);
710 wClientSetState(wwin
, NormalState
, None
);
718 handleUnmapNotify(XEvent
*event
)
722 Bool withdraw
= False
;
726 /* only process windows with StructureNotify selected
727 * (ignore SubstructureNotify) */
728 wwin
= wWindowFor(event
->xunmap
.window
);
732 /* whether the event is a Withdrawal request */
733 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
734 && event
->xunmap
.send_event
)
737 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
740 if (!wwin
->flags
.mapped
&& !withdraw
741 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
742 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
746 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
747 wwin
->flags
.mapped
= 0;
749 /* check if the window was destroyed */
750 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
,&ev
)) {
753 Bool reparented
= False
;
755 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
758 /* withdraw window */
759 wwin
->flags
.mapped
= 0;
761 wClientSetState(wwin
, WithdrawnState
, None
);
763 /* if the window was reparented, do not reparent it back to the
765 wUnmanageWindow(wwin
, !reparented
, False
);
772 handleConfigureRequest(XEvent
*event
)
776 L("got configure request");
778 if (!(wwin
=wWindowFor(event
->xconfigurerequest
.window
))) {
780 * Configure request for unmapped window
782 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
784 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
790 handlePropertyNotify(XEvent
*event
)
799 L("got property notify");
801 if ((wwin
=wWindowFor(event
->xproperty
.window
))) {
802 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
,
803 &ju
, &ju
, &ju
, &ju
)) {
806 wClientCheckProperty(wwin
, &event
->xproperty
);
808 wapp
= wApplicationOf(event
->xproperty
.window
);
810 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
813 scr
= wScreenForWindow(event
->xproperty
.window
);
814 if (scr
&& scr
->root_win
== event
->xproperty
.window
) {
816 wKWMCheckRootHintChange(scr
, &event
->xproperty
);
823 handleClientMessage(XEvent
*event
)
826 WObjDescriptor
*desc
;
828 L("got client message");
830 /* handle transition from Normal to Iconic state */
831 if (event
->xclient
.message_type
== _XA_WM_CHANGE_STATE
832 && event
->xclient
.format
== 32
833 && event
->xclient
.data
.l
[0] == IconicState
) {
835 wwin
= wWindowFor(event
->xclient
.window
);
837 if (!wwin
->flags
.miniaturized
)
838 wIconifyWindow(wwin
);
839 } else if (event
->xclient
.message_type
== _XA_WM_COLORMAP_NOTIFY
840 && event
->xclient
.format
== 32) {
841 WScreen
*scr
= wScreenSearchForRootWindow(event
->xclient
.window
);
846 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
847 wColormapAllowClientInstallation(scr
, True
);
848 } else { /* stopping */
849 wColormapAllowClientInstallation(scr
, False
);
851 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_COMMAND
) {
853 wDefaultsCheckDomains("bla");
855 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
858 wapp
= wApplicationOf(event
->xclient
.window
);
860 switch (event
->xclient
.data
.l
[0]) {
861 case WMFHideOtherApplications
:
862 wHideOtherApplications(wapp
->main_window_desc
);
866 case WMFHideApplication
:
867 wHideApplication(wapp
);
873 wwin
= wWindowFor(event
->xclient
.window
);
875 switch (event
->xclient
.data
.l
[0]) {
876 case WMFHideOtherApplications
:
877 wHideOtherApplications(wwin
);
880 case WMFHideApplication
:
881 wHideApplication(wApplicationOf(wwin
->main_window
));
886 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_WM_ATTR
) {
887 wwin
= wWindowFor(event
->xclient
.window
);
889 switch (event
->xclient
.data
.l
[0]) {
890 case GSWindowLevelAttr
:
892 int level
= (int)event
->xclient
.data
.l
[1];
894 if (WINDOW_LEVEL(wwin
) != level
) {
895 ChangeStackingLevel(wwin
->frame
->core
, level
);
900 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_TITLEBAR_STATE
) {
901 wwin
= wWindowFor(event
->xclient
.window
);
903 switch (event
->xclient
.data
.l
[0]) {
904 case WMTitleBarNormal
:
905 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
908 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
911 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
915 } else if (wGNOMEProcessClientMessage(&event
->xclient
)) {
917 #endif /* GNOME_STUFF */
919 } else if (wKWMProcessClientMessage(&event
->xclient
)) {
921 #endif /* KWM_HINTS */
923 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
927 } else if (event
->xclient
.message_type
==_XA_DND_PROTOCOL
) {
928 WScreen
*scr
= wScreenForWindow(event
->xclient
.window
);
929 if (scr
&& wDockReceiveDNDDrop(scr
,event
))
930 goto redirect_message
;
931 #endif /* OFFIX_DND */
937 * Non-standard thing, but needed by OffiX DND.
938 * For when the icon frame gets a ClientMessage
939 * that should have gone to the icon_window.
941 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
,
942 (XPointer
*)&desc
)!=XCNOENT
) {
943 struct WIcon
*icon
=NULL
;
945 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
946 icon
= (WIcon
*)desc
->parent
;
947 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
948 || desc
->parent_type
== WCLASS_APPICON
) {
949 icon
= ((WAppIcon
*)desc
->parent
)->icon
;
951 if (icon
&& (wwin
=icon
->owner
)) {
952 if (wwin
->client_win
!=event
->xclient
.window
) {
953 event
->xclient
.window
= wwin
->client_win
;
954 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
,
964 raiseWindow(WScreen
*scr
)
968 scr
->autoRaiseTimer
= NULL
;
970 wwin
= wWindowFor(scr
->autoRaiseWindow
);
974 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
975 wRaiseFrame(wwin
->frame
->core
);
976 /* this is needed or a race condition will occur */
983 handleEnterNotify(XEvent
*event
)
986 WObjDescriptor
*desc
= NULL
;
988 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
990 L("got enter notify");
993 #ifdef VIRTUAL_DESKTOP
994 /* TODO: acceleration code */
995 if (wPreferences
.vedge_thickness
) {
997 if (event
->xcrossing
.window
== scr
->virtual_edge_r
) {
998 XWarpPointer(dpy
, None
, scr
->root_win
, 0,0,0,0, scr
->scr_width
- wPreferences
.vedge_thickness
- 1, event
->xcrossing
.y_root
);
999 wWorkspaceGetViewPosition(scr
, scr
->current_workspace
, &x
, &y
);
1000 wWorkspaceSetViewPort(scr
, scr
->current_workspace
, x
+ VIRTUALEDGE_SCROLL_HSTEP
, y
);
1001 } else if (event
->xcrossing
.window
== scr
->virtual_edge_l
) {
1002 XWarpPointer(dpy
, None
, scr
->root_win
, 0,0,0,0, wPreferences
.vedge_thickness
+ 1, event
->xcrossing
.y_root
);
1003 wWorkspaceGetViewPosition(scr
, scr
->current_workspace
, &x
, &y
);
1004 wWorkspaceSetViewPort(scr
, scr
->current_workspace
, x
- VIRTUALEDGE_SCROLL_HSTEP
, y
);
1005 } else if (event
->xcrossing
.window
== scr
->virtual_edge_u
) {
1006 XWarpPointer(dpy
, None
, scr
->root_win
, 0,0,0,0, event
->xcrossing
.x_root
, wPreferences
.vedge_thickness
+ 1);
1007 wWorkspaceGetViewPosition(scr
, scr
->current_workspace
, &x
, &y
);
1008 wWorkspaceSetViewPort(scr
, scr
->current_workspace
, x
, y
- VIRTUALEDGE_SCROLL_VSTEP
);
1009 } else if (event
->xcrossing
.window
== scr
->virtual_edge_d
) {
1010 XWarpPointer(dpy
, None
, scr
->root_win
, 0,0,0,0, event
->xcrossing
.x_root
, scr
->scr_height
- wPreferences
.vedge_thickness
- 1);
1011 wWorkspaceGetViewPosition(scr
, scr
->current_workspace
, &x
, &y
);
1012 wWorkspaceSetViewPort(scr
, scr
->current_workspace
, x
, y
+ VIRTUALEDGE_SCROLL_VSTEP
);
1017 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
,
1019 /* already left the window... */
1021 if (ev
.xcrossing
.mode
==event
->xcrossing
.mode
1022 && ev
.xcrossing
.detail
==event
->xcrossing
.detail
) {
1027 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
,
1028 (XPointer
*)&desc
)!=XCNOENT
) {
1029 if(desc
->handle_enternotify
)
1030 (*desc
->handle_enternotify
)(desc
, event
);
1033 /* enter to window */
1034 wwin
= wWindowFor(event
->xcrossing
.window
);
1036 if (wPreferences
.focus_mode
==WKF_POINTER
1037 && event
->xcrossing
.window
==event
->xcrossing
.root
) {
1038 wSetFocusTo(scr
, NULL
);
1040 if (wPreferences
.colormap_mode
==WKF_POINTER
) {
1041 wColormapInstallForWindow(scr
, NULL
);
1043 if (scr
->autoRaiseTimer
1044 && event
->xcrossing
.root
==event
->xcrossing
.window
) {
1045 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1046 scr
->autoRaiseTimer
= NULL
;
1049 /* set auto raise timer even if in focus-follows-mouse mode
1050 * and the event is for the frame window, even if the window
1051 * has focus already. useful if you move the pointer from a focused
1052 * window to the root window and back pretty fast
1054 * set focus if in focus-follows-mouse mode and the event
1055 * is for the frame window and window doesn't have focus yet */
1056 if ((wPreferences
.focus_mode
==WKF_POINTER
1057 || wPreferences
.focus_mode
==WKF_SLOPPY
)
1058 && wwin
->frame
->core
->window
==event
->xcrossing
.window
1059 && !scr
->flags
.doing_alt_tab
) {
1061 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1062 wSetFocusTo(scr
, wwin
);
1064 if (scr
->autoRaiseTimer
)
1065 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1066 scr
->autoRaiseTimer
= NULL
;
1068 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1069 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1071 = WMAddTimerHandler(wPreferences
.raise_delay
,
1072 (WMCallback
*)raiseWindow
, scr
);
1075 /* Install colormap for window, if the colormap installation mode
1076 * is colormap_follows_mouse */
1077 if (wPreferences
.colormap_mode
==WKF_POINTER
) {
1078 if (wwin
->client_win
==event
->xcrossing
.window
)
1079 wColormapInstallForWindow(scr
, wwin
);
1081 wColormapInstallForWindow(scr
, NULL
);
1085 /* a little kluge to hide the clip balloon */
1086 if (!wPreferences
.flags
.noclip
&& scr
->flags
.clip_balloon_mapped
) {
1088 XUnmapWindow(dpy
, scr
->clip_balloon
);
1089 scr
->flags
.clip_balloon_mapped
= 0;
1091 if (desc
->parent_type
!=WCLASS_DOCK_ICON
1092 || scr
->clip_icon
!= desc
->parent
) {
1093 XUnmapWindow(dpy
, scr
->clip_balloon
);
1094 scr
->flags
.clip_balloon_mapped
= 0;
1099 if (event
->xcrossing
.window
== event
->xcrossing
.root
1100 && event
->xcrossing
.detail
== NotifyNormal
1101 && event
->xcrossing
.detail
!= NotifyInferior
1102 && wPreferences
.focus_mode
!= WKF_CLICK
) {
1104 wSetFocusTo(scr
, scr
->focused_window
);
1108 wBalloonEnteredObject(scr
, desc
);
1114 handleLeaveNotify(XEvent
*event
)
1116 WObjDescriptor
*desc
= NULL
;
1118 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
,
1119 (XPointer
*)&desc
)!=XCNOENT
) {
1120 if(desc
->handle_leavenotify
)
1121 (*desc
->handle_leavenotify
)(desc
, event
);
1123 if (event
->xcrossing
.window
== event
->xcrossing
.root
1124 && event
->xcrossing
.mode
== NotifyNormal
1125 && event
->xcrossing
.detail
!= NotifyInferior
1126 && wPreferences
.focus_mode
!= WKF_CLICK
) {
1128 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1130 wSetFocusTo(scr
, NULL
);
1137 handleShapeNotify(XEvent
*event
)
1139 XShapeEvent
*shev
= (XShapeEvent
*)event
;
1143 L("got shape notify");
1145 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
)) {
1146 XShapeEvent
*sev
= (XShapeEvent
*)&ev
;
1148 if (sev
->kind
== ShapeBounding
) {
1149 if (sev
->shaped
== shev
->shaped
) {
1152 XPutBackEvent(dpy
, &ev
);
1158 wwin
= wWindowFor(shev
->window
);
1159 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1162 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1164 wwin
->flags
.shaped
= 0;
1165 wWindowClearShape(wwin
);
1167 } else if (shev
->shaped
) {
1169 wwin
->flags
.shaped
= 1;
1170 wWindowSetShape(wwin
);
1175 #ifdef KEEP_XKB_LOCK_STATUS
1176 /* please help ]d if you know what to do */
1177 handleXkbIndicatorStateNotify(XEvent
*event
)
1181 XkbStateRec staterec
;
1184 for (i
=0; i
<wScreenCount
; i
++) {
1185 scr
= wScreenWithNumber(i
);
1186 wwin
= scr
->focused_window
;
1187 if (wwin
&& wwin
->flags
.focused
) {
1188 XkbGetState(dpy
,XkbUseCoreKbd
,&staterec
);
1189 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1190 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1191 wwin
->frame
->languagemode
= staterec
.group
;
1193 #ifdef XKB_BUTTON_HINT
1194 if (wwin
->frame
->titlebar
) {
1195 wFrameWindowPaint(wwin
->frame
);
1201 #endif /*KEEP_XKB_LOCK_STATUS*/
1204 handleColormapNotify(XEvent
*event
)
1208 Bool reinstall
= False
;
1210 wwin
= wWindowFor(event
->xcolormap
.window
);
1214 scr
= wwin
->screen_ptr
;
1218 if (event
->xcolormap
.new) {
1219 XWindowAttributes attr
;
1221 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1223 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1224 scr
->current_colormap
= attr
.colormap
;
1227 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1228 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1230 /* some bastard app (like XV) removed our colormap */
1232 * can't enforce or things like xscreensaver wont work
1235 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1236 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1238 /* someone has put our colormap back */
1242 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1243 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1245 if (reinstall
&& scr
->current_colormap
!=None
) {
1246 if (!scr
->flags
.colormap_stuff_blocked
)
1247 XInstallColormap(dpy
, scr
->current_colormap
);
1254 handleFocusIn(XEvent
*event
)
1259 * For applications that like stealing the focus.
1261 while (XCheckTypedEvent(dpy
, FocusIn
, event
));
1262 saveTimestamp(event
);
1263 if (event
->xfocus
.mode
== NotifyUngrab
1264 || event
->xfocus
.mode
== NotifyGrab
1265 || event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1269 wwin
= wWindowFor(event
->xfocus
.window
);
1270 if (wwin
&& !wwin
->flags
.focused
) {
1271 if (wwin
->flags
.mapped
)
1272 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1274 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1276 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1278 wSetFocusTo(scr
, NULL
);
1284 windowUnderPointer(WScreen
*scr
)
1290 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
,
1292 return wWindowFor(win
);
1300 handleKeyPress(XEvent
*event
)
1302 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1303 WWindow
*wwin
= scr
->focused_window
;
1306 int command
=-1, index
;
1307 #ifdef KEEP_XKB_LOCK_STATUS
1308 XkbStateRec staterec
;
1309 #endif /*KEEP_XKB_LOCK_STATUS*/
1311 /* ignore CapsLock */
1312 modifiers
= event
->xkey
.state
& ValidModMask
;
1314 for (i
=0; i
<WKBD_LAST
; i
++) {
1315 if (wKeyBindings
[i
].keycode
==0)
1318 if (wKeyBindings
[i
].keycode
==event
->xkey
.keycode
1319 && (/*wKeyBindings[i].modifier==0
1320 ||*/ wKeyBindings
[i
].modifier
==modifiers
)) {
1334 if (!wRootMenuPerformShortcut(event
)) {
1336 static int dontLoop
= 0;
1338 if (dontLoop
> 10) {
1339 wwarning("problem with key event processing code");
1343 /* if the focused window is an internal window, try redispatching
1344 * the event to the managed window, as it can be a WINGs window */
1345 if (wwin
&& wwin
->flags
.internal_window
1346 && wwin
->client_leader
!=None
) {
1347 /* client_leader contains the WINGs toplevel */
1348 event
->xany
.window
= wwin
->client_leader
;
1349 WMHandleEvent(event
);
1356 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1357 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1362 OpenRootMenu(scr
, event
->xkey
.x_root
, event
->xkey
.y_root
, True
);
1364 case WKBD_WINDOWLIST
:
1365 OpenSwitchMenu(scr
, event
->xkey
.x_root
, event
->xkey
.y_root
, True
);
1368 case WKBD_WINDOWMENU
:
1369 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1370 OpenWindowMenu(wwin
, wwin
->frame_x
,
1371 wwin
->frame_y
+wwin
->frame
->top_width
, True
);
1373 case WKBD_MINIATURIZE
:
1374 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1375 && !WFLAGP(wwin
, no_miniaturizable
)) {
1376 CloseWindowMenu(scr
);
1378 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1379 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
1380 event
->xbutton
.time
);
1382 wIconifyWindow(wwin
);
1387 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1388 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1389 CloseWindowMenu(scr
);
1391 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1392 wHideApplication(wapp
);
1397 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_resizable
)) {
1398 CloseWindowMenu(scr
);
1400 if (wwin
->flags
.maximized
) {
1401 wUnmaximizeWindow(wwin
);
1403 wMaximizeWindow(wwin
, MAX_VERTICAL
|MAX_HORIZONTAL
);
1407 case WKBD_VMAXIMIZE
:
1408 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_resizable
)) {
1409 CloseWindowMenu(scr
);
1411 if (wwin
->flags
.maximized
) {
1412 wUnmaximizeWindow(wwin
);
1414 wMaximizeWindow(wwin
, MAX_VERTICAL
);
1419 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1420 CloseWindowMenu(scr
);
1422 wRaiseFrame(wwin
->frame
->core
);
1426 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1427 CloseWindowMenu(scr
);
1429 wLowerFrame(wwin
->frame
->core
);
1432 case WKBD_RAISELOWER
:
1433 /* raise or lower the window under the pointer, not the
1436 wwin
= windowUnderPointer(scr
);
1438 wRaiseLowerFrame(wwin
->frame
->core
);
1441 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1442 if (wwin
->flags
.shaded
)
1443 wUnshadeWindow(wwin
);
1448 case WKBD_MOVERESIZE
:
1449 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1450 CloseWindowMenu(scr
);
1452 wKeyboardMoveResizeWindow(wwin
);
1456 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1457 CloseWindowMenu(scr
);
1458 if (wwin
->protocols
.DELETE_WINDOW
)
1459 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
,
1464 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1465 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1468 case WKBD_FOCUSNEXT
:
1469 StartWindozeCycle(wwin
, event
, True
);
1472 case WKBD_FOCUSPREV
:
1473 StartWindozeCycle(wwin
, event
, False
);
1476 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1477 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1478 i = (scr->current_workspace/10)*10 + wk - 1;\
1479 if (wPreferences.ws_advance || i<scr->workspace_count)\
1480 wWorkspaceChange(scr, i);\
1483 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1484 i = (scr->current_workspace/10)*10 + wk - 1;\
1485 if (wPreferences.ws_advance || i<scr->workspace_count)\
1486 wWorkspaceChange(scr, i);\
1500 case WKBD_NEXTWORKSPACE
:
1501 wWorkspaceRelativeChange(scr
, 1);
1503 case WKBD_PREVWORKSPACE
:
1504 wWorkspaceRelativeChange(scr
, -1);
1517 #define INITBAG(bag) if (bag) WMEmptyBag(bag); else bag = WMCreateBag(4)
1519 index
= command
-WKBD_WINDOW1
;
1521 if (scr
->shortcutWindows
[index
]) {
1522 WMBag
*list
= scr
->shortcutWindows
[index
];
1524 int count
= WMGetBagItemCount(list
);
1529 wUnselectWindows(scr
);
1530 cw
= scr
->current_workspace
;
1532 for (wwin
= WMBagLast(list
, &iter
);
1534 wwin
= WMBagPrevious(list
, &iter
)) {
1537 wWindowChangeWorkspace(wwin
, cw
);
1539 wMakeWindowVisible(wwin
);
1542 wSelectWindow(wwin
, True
);
1545 /* rotate the order of windows, to create a cycling effect */
1546 twin
= WMBagFirst(list
, &iter
);
1547 WMRemoveFromBag(list
, twin
);
1548 WMPutInBag(list
, twin
);
1550 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1552 INITBAG(scr
->shortcutWindows
[index
]);
1553 WMPutInBag(scr
->shortcutWindows
[index
], wwin
);
1555 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1556 WMBag
*selwins
= scr
->selected_windows
;
1559 for (i
= 0; i
< WMGetBagItemCount(selwins
); i
++) {
1560 WWindow
*tmp
= WMGetFromBag(selwins
, i
);
1563 WMPutInBag(scr
->shortcutWindows
[index
], tmp
);
1566 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1569 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1572 } else if (scr
->selected_windows
1573 && WMGetBagItemCount(scr
->selected_windows
)) {
1575 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1576 WMBag
*selwins
= scr
->selected_windows
;
1579 INITBAG(scr
->shortcutWindows
[index
]);
1581 for (i
= 0; i
< WMGetBagItemCount(selwins
); i
++) {
1582 WWindow
*tmp
= WMGetFromBag(selwins
, i
);
1584 WMPutInBag(scr
->shortcutWindows
[index
], tmp
);
1592 case WKBD_SWITCH_SCREEN
:
1593 if (wScreenCount
> 1) {
1597 /* find index of this screen */
1598 for (i
= 0; i
< wScreenCount
; i
++) {
1599 if (wScreenWithNumber(i
) == scr
)
1603 if (i
>= wScreenCount
) {
1606 scr2
= wScreenWithNumber(i
);
1609 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1610 scr2
->scr_width
/2, scr2
->scr_height
/2);
1615 case WKBD_NEXTWSLAYER
:
1616 case WKBD_PREVWSLAYER
:
1620 row
= scr
->current_workspace
/10;
1621 column
= scr
->current_workspace
%10;
1623 if (command
==WKBD_NEXTWSLAYER
) {
1624 if ((row
+1)*10 < scr
->workspace_count
)
1625 wWorkspaceChange(scr
, column
+(row
+1)*10);
1628 wWorkspaceChange(scr
, column
+(row
-1)*10);
1632 case WKBD_CLIPLOWER
:
1633 if (!wPreferences
.flags
.noclip
)
1634 wDockLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1636 case WKBD_CLIPRAISE
:
1637 if (!wPreferences
.flags
.noclip
)
1638 wDockRaise(scr
->workspaces
[scr
->current_workspace
]->clip
);
1640 case WKBD_CLIPRAISELOWER
:
1641 if (!wPreferences
.flags
.noclip
)
1642 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1644 #ifdef KEEP_XKB_LOCK_STATUS
1646 if(wPreferences
.modelock
) {
1648 wwin
= scr
->focused_window
;
1650 if (wwin
&& wwin
->flags
.mapped
1651 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1652 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1653 XkbGetState(dpy
,XkbUseCoreKbd
,&staterec
);
1655 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1656 wwin
->frame
->last_languagemode
= staterec
.group
;
1657 XkbLockGroup(dpy
,XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1662 #endif /* KEEP_XKB_LOCK_STATUS */
1669 handleMotionNotify(XEvent
*event
)
1672 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1674 if (wPreferences
.scrollable_menus
) {
1675 if (scr
->flags
.jump_back_pending
||
1676 event
->xmotion
.x_root
<= 1 ||
1677 event
->xmotion
.x_root
>= (scr
->scr_width
- 2) ||
1678 event
->xmotion
.y_root
<= 1 ||
1679 event
->xmotion
.y_root
>= (scr
->scr_height
- 2)) {
1681 L("pointer at screen edge");
1683 menu
= wMenuUnderPointer(scr
);
1685 wMenuScroll(menu
, event
);
1689 if (event
->xmotion
.subwindow
== None
)
1692 if (scr
->scrolledFMaximize
!= None
) {
1695 twin
= wWindowFor(scr
->scrolledFMaximize
);
1696 if (twin
&& twin
->frame_y
==) {
1700 scr
->scrolledFMaximize
= NULL
;
1704 /* scroll full maximized window */
1705 if (event
->xmotion
.y_root
< 1
1706 || event
->xmotion
.y_root
> scr
->scr_height
- 1) {
1708 wwin
= wWindowFor(event
->xmotion
.subwindow
);
1710 if (wwin
&& (wwin
->flags
.maximized
& MAX_VERTICAL
)
1711 && WFLAGP(wwin
, full_maximize
)
1712 && event
->xmotion
.x_root
>= wwin
->frame_x
1713 && event
->xmotion
.x_root
<= wwin
->frame_x
+ wwin
->frame
->core
->width
) {
1715 if (!WFLAGP(wwin
, no_titlebar
)
1716 && wwin
->frame_y
<= - wwin
->frame
->top_width
) {
1718 wWindowMove(wwin
, wwin
->frame_x
, 0);
1719 wwin
->flags
.dragged_while_fmaximized
= 0;
1721 } else if (!WFLAGP(wwin
, no_resizebar
)
1722 && wwin
->frame_y
+ wwin
->frame
->core
->height
>=
1723 scr
->scr_height
+ wwin
->frame
->bottom_width
) {
1725 int y
= scr
->scr_height
+ wwin
->frame
->bottom_width
;
1727 y
= scr
->scr_height
- wwin
->frame_y
- wwin
->frame
->core
->height
;
1729 wWindowMove(wwin
, wwin
->frame_x
, y
);
1730 wwin
->flags
.dragged_while_fmaximized
= 0;
1739 handleVisibilityNotify(XEvent
*event
)
1743 wwin
= wWindowFor(event
->xvisibility
.window
);
1746 wwin
->flags
.obscured
=
1747 (event
->xvisibility
.state
== VisibilityFullyObscured
);