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 #ifdef MOUSE_WS_SWITCH
637 else if (event
->xbutton
.button
==Button5
) {
638 wWorkspaceRelativeChange(scr
, -1);
639 } else if (event
->xbutton
.button
==Button4
) {
640 wWorkspaceRelativeChange(scr
, 1);
642 #endif /* MOUSE_WS_SWITCH */
644 else if (wGNOMEProxyizeButtonEvent(scr
, event
))
651 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
,
652 (XPointer
*)&desc
)==XCNOENT
) {
653 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
,
654 (XPointer
*)&desc
)==XCNOENT
) {
659 if (desc
->parent_type
== WCLASS_WINDOW
) {
662 if (event
->xbutton
.state
& MOD_MASK
) {
663 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
666 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
667 if (wPreferences
.ignore_focus_click
) {
668 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
670 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
673 } else if (desc
->parent_type
== WCLASS_APPICON
674 || desc
->parent_type
== WCLASS_MINIWINDOW
675 || desc
->parent_type
== WCLASS_DOCK_ICON
) {
676 if (event
->xbutton
.state
& MOD_MASK
) {
678 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
683 if (desc
->handle_mousedown
!=NULL
) {
684 (*desc
->handle_mousedown
)(desc
, event
);
687 /* save double-click information */
688 if (scr
->flags
.next_click_is_not_double
) {
689 scr
->flags
.next_click_is_not_double
= 0;
691 scr
->last_click_time
= event
->xbutton
.time
;
692 scr
->last_click_button
= event
->xbutton
.button
;
693 scr
->last_click_window
= event
->xbutton
.window
;
699 handleMapNotify(XEvent
*event
)
705 wwin
= wWindowFor(event
->xmap
.event
);
706 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
707 if (wwin
->flags
.miniaturized
) {
708 wDeiconifyWindow(wwin
);
712 wClientSetState(wwin
, NormalState
, None
);
720 handleUnmapNotify(XEvent
*event
)
724 Bool withdraw
= False
;
728 /* only process windows with StructureNotify selected
729 * (ignore SubstructureNotify) */
730 wwin
= wWindowFor(event
->xunmap
.window
);
734 /* whether the event is a Withdrawal request */
735 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
736 && event
->xunmap
.send_event
)
739 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
742 if (!wwin
->flags
.mapped
&& !withdraw
743 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
744 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
748 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
749 wwin
->flags
.mapped
= 0;
751 /* check if the window was destroyed */
752 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
,&ev
)) {
755 Bool reparented
= False
;
757 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
760 /* withdraw window */
761 wwin
->flags
.mapped
= 0;
763 wClientSetState(wwin
, WithdrawnState
, None
);
765 /* if the window was reparented, do not reparent it back to the
767 wUnmanageWindow(wwin
, !reparented
, False
);
774 handleConfigureRequest(XEvent
*event
)
778 L("got configure request");
780 if (!(wwin
=wWindowFor(event
->xconfigurerequest
.window
))) {
782 * Configure request for unmapped window
784 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
786 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
792 handlePropertyNotify(XEvent
*event
)
801 L("got property notify");
803 if ((wwin
=wWindowFor(event
->xproperty
.window
))) {
804 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
,
805 &ju
, &ju
, &ju
, &ju
)) {
808 wClientCheckProperty(wwin
, &event
->xproperty
);
810 wapp
= wApplicationOf(event
->xproperty
.window
);
812 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
815 scr
= wScreenForWindow(event
->xproperty
.window
);
816 if (scr
&& scr
->root_win
== event
->xproperty
.window
) {
818 wKWMCheckRootHintChange(scr
, &event
->xproperty
);
825 handleClientMessage(XEvent
*event
)
828 WObjDescriptor
*desc
;
830 L("got client message");
832 /* handle transition from Normal to Iconic state */
833 if (event
->xclient
.message_type
== _XA_WM_CHANGE_STATE
834 && event
->xclient
.format
== 32
835 && event
->xclient
.data
.l
[0] == IconicState
) {
837 wwin
= wWindowFor(event
->xclient
.window
);
839 if (!wwin
->flags
.miniaturized
)
840 wIconifyWindow(wwin
);
841 } else if (event
->xclient
.message_type
== _XA_WM_COLORMAP_NOTIFY
842 && event
->xclient
.format
== 32) {
843 WScreen
*scr
= wScreenSearchForRootWindow(event
->xclient
.window
);
848 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
849 wColormapAllowClientInstallation(scr
, True
);
850 } else { /* stopping */
851 wColormapAllowClientInstallation(scr
, False
);
853 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_COMMAND
) {
855 wDefaultsCheckDomains("bla");
857 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
860 wapp
= wApplicationOf(event
->xclient
.window
);
862 switch (event
->xclient
.data
.l
[0]) {
863 case WMFHideOtherApplications
:
864 wHideOtherApplications(wapp
->main_window_desc
);
868 case WMFHideApplication
:
869 wHideApplication(wapp
);
875 wwin
= wWindowFor(event
->xclient
.window
);
877 switch (event
->xclient
.data
.l
[0]) {
878 case WMFHideOtherApplications
:
879 wHideOtherApplications(wwin
);
882 case WMFHideApplication
:
883 wHideApplication(wApplicationOf(wwin
->main_window
));
888 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_WM_ATTR
) {
889 wwin
= wWindowFor(event
->xclient
.window
);
891 switch (event
->xclient
.data
.l
[0]) {
892 case GSWindowLevelAttr
:
894 int level
= (int)event
->xclient
.data
.l
[1];
896 if (WINDOW_LEVEL(wwin
) != level
) {
897 ChangeStackingLevel(wwin
->frame
->core
, level
);
902 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_TITLEBAR_STATE
) {
903 wwin
= wWindowFor(event
->xclient
.window
);
905 switch (event
->xclient
.data
.l
[0]) {
906 case WMTitleBarNormal
:
907 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
910 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
913 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
917 } else if (wGNOMEProcessClientMessage(&event
->xclient
)) {
919 #endif /* GNOME_STUFF */
921 } else if (wKWMProcessClientMessage(&event
->xclient
)) {
923 #endif /* KWM_HINTS */
925 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
929 } else if (event
->xclient
.message_type
==_XA_DND_PROTOCOL
) {
930 WScreen
*scr
= wScreenForWindow(event
->xclient
.window
);
931 if (scr
&& wDockReceiveDNDDrop(scr
,event
))
932 goto redirect_message
;
933 #endif /* OFFIX_DND */
939 * Non-standard thing, but needed by OffiX DND.
940 * For when the icon frame gets a ClientMessage
941 * that should have gone to the icon_window.
943 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
,
944 (XPointer
*)&desc
)!=XCNOENT
) {
945 struct WIcon
*icon
=NULL
;
947 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
948 icon
= (WIcon
*)desc
->parent
;
949 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
950 || desc
->parent_type
== WCLASS_APPICON
) {
951 icon
= ((WAppIcon
*)desc
->parent
)->icon
;
953 if (icon
&& (wwin
=icon
->owner
)) {
954 if (wwin
->client_win
!=event
->xclient
.window
) {
955 event
->xclient
.window
= wwin
->client_win
;
956 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
,
966 raiseWindow(WScreen
*scr
)
970 scr
->autoRaiseTimer
= NULL
;
972 wwin
= wWindowFor(scr
->autoRaiseWindow
);
976 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
977 wRaiseFrame(wwin
->frame
->core
);
978 /* this is needed or a race condition will occur */
985 handleEnterNotify(XEvent
*event
)
988 WObjDescriptor
*desc
= NULL
;
990 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
992 L("got enter notify");
995 #ifdef VIRTUAL_DESKTOP
996 /* TODO: acceleration code */
997 if (wPreferences
.vedge_thickness
) {
999 if (event
->xcrossing
.window
== scr
->virtual_edge_r
) {
1000 XWarpPointer(dpy
, None
, scr
->root_win
, 0,0,0,0, scr
->scr_width
- wPreferences
.vedge_thickness
- 1, event
->xcrossing
.y_root
);
1001 wWorkspaceGetViewPosition(scr
, scr
->current_workspace
, &x
, &y
);
1002 wWorkspaceSetViewPort(scr
, scr
->current_workspace
, x
+ VIRTUALEDGE_SCROLL_HSTEP
, y
);
1003 } else if (event
->xcrossing
.window
== scr
->virtual_edge_l
) {
1004 XWarpPointer(dpy
, None
, scr
->root_win
, 0,0,0,0, wPreferences
.vedge_thickness
+ 1, event
->xcrossing
.y_root
);
1005 wWorkspaceGetViewPosition(scr
, scr
->current_workspace
, &x
, &y
);
1006 wWorkspaceSetViewPort(scr
, scr
->current_workspace
, x
- VIRTUALEDGE_SCROLL_HSTEP
, y
);
1007 } else if (event
->xcrossing
.window
== scr
->virtual_edge_u
) {
1008 XWarpPointer(dpy
, None
, scr
->root_win
, 0,0,0,0, event
->xcrossing
.x_root
, wPreferences
.vedge_thickness
+ 1);
1009 wWorkspaceGetViewPosition(scr
, scr
->current_workspace
, &x
, &y
);
1010 wWorkspaceSetViewPort(scr
, scr
->current_workspace
, x
, y
- VIRTUALEDGE_SCROLL_VSTEP
);
1011 } else if (event
->xcrossing
.window
== scr
->virtual_edge_d
) {
1012 XWarpPointer(dpy
, None
, scr
->root_win
, 0,0,0,0, event
->xcrossing
.x_root
, scr
->scr_height
- wPreferences
.vedge_thickness
- 1);
1013 wWorkspaceGetViewPosition(scr
, scr
->current_workspace
, &x
, &y
);
1014 wWorkspaceSetViewPort(scr
, scr
->current_workspace
, x
, y
+ VIRTUALEDGE_SCROLL_VSTEP
);
1019 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
,
1021 /* already left the window... */
1023 if (ev
.xcrossing
.mode
==event
->xcrossing
.mode
1024 && ev
.xcrossing
.detail
==event
->xcrossing
.detail
) {
1029 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
,
1030 (XPointer
*)&desc
)!=XCNOENT
) {
1031 if(desc
->handle_enternotify
)
1032 (*desc
->handle_enternotify
)(desc
, event
);
1035 /* enter to window */
1036 wwin
= wWindowFor(event
->xcrossing
.window
);
1038 if (wPreferences
.focus_mode
==WKF_POINTER
1039 && event
->xcrossing
.window
==event
->xcrossing
.root
) {
1040 wSetFocusTo(scr
, NULL
);
1042 if (wPreferences
.colormap_mode
==WKF_POINTER
) {
1043 wColormapInstallForWindow(scr
, NULL
);
1045 if (scr
->autoRaiseTimer
1046 && event
->xcrossing
.root
==event
->xcrossing
.window
) {
1047 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1048 scr
->autoRaiseTimer
= NULL
;
1051 /* set auto raise timer even if in focus-follows-mouse mode
1052 * and the event is for the frame window, even if the window
1053 * has focus already. useful if you move the pointer from a focused
1054 * window to the root window and back pretty fast
1056 * set focus if in focus-follows-mouse mode and the event
1057 * is for the frame window and window doesn't have focus yet */
1058 if ((wPreferences
.focus_mode
==WKF_POINTER
1059 || wPreferences
.focus_mode
==WKF_SLOPPY
)
1060 && wwin
->frame
->core
->window
==event
->xcrossing
.window
1061 && !scr
->flags
.doing_alt_tab
) {
1063 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1064 wSetFocusTo(scr
, wwin
);
1066 if (scr
->autoRaiseTimer
)
1067 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1068 scr
->autoRaiseTimer
= NULL
;
1070 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1071 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1073 = WMAddTimerHandler(wPreferences
.raise_delay
,
1074 (WMCallback
*)raiseWindow
, scr
);
1077 /* Install colormap for window, if the colormap installation mode
1078 * is colormap_follows_mouse */
1079 if (wPreferences
.colormap_mode
==WKF_POINTER
) {
1080 if (wwin
->client_win
==event
->xcrossing
.window
)
1081 wColormapInstallForWindow(scr
, wwin
);
1083 wColormapInstallForWindow(scr
, NULL
);
1087 /* a little kluge to hide the clip balloon */
1088 if (!wPreferences
.flags
.noclip
&& scr
->flags
.clip_balloon_mapped
) {
1090 XUnmapWindow(dpy
, scr
->clip_balloon
);
1091 scr
->flags
.clip_balloon_mapped
= 0;
1093 if (desc
->parent_type
!=WCLASS_DOCK_ICON
1094 || scr
->clip_icon
!= desc
->parent
) {
1095 XUnmapWindow(dpy
, scr
->clip_balloon
);
1096 scr
->flags
.clip_balloon_mapped
= 0;
1101 if (event
->xcrossing
.window
== event
->xcrossing
.root
1102 && event
->xcrossing
.detail
== NotifyNormal
1103 && event
->xcrossing
.detail
!= NotifyInferior
1104 && wPreferences
.focus_mode
!= WKF_CLICK
) {
1106 wSetFocusTo(scr
, scr
->focused_window
);
1110 wBalloonEnteredObject(scr
, desc
);
1116 handleLeaveNotify(XEvent
*event
)
1118 WObjDescriptor
*desc
= NULL
;
1120 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
,
1121 (XPointer
*)&desc
)!=XCNOENT
) {
1122 if(desc
->handle_leavenotify
)
1123 (*desc
->handle_leavenotify
)(desc
, event
);
1125 if (event
->xcrossing
.window
== event
->xcrossing
.root
1126 && event
->xcrossing
.mode
== NotifyNormal
1127 && event
->xcrossing
.detail
!= NotifyInferior
1128 && wPreferences
.focus_mode
!= WKF_CLICK
) {
1130 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1132 wSetFocusTo(scr
, NULL
);
1139 handleShapeNotify(XEvent
*event
)
1141 XShapeEvent
*shev
= (XShapeEvent
*)event
;
1145 L("got shape notify");
1147 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
)) {
1148 XShapeEvent
*sev
= (XShapeEvent
*)&ev
;
1150 if (sev
->kind
== ShapeBounding
) {
1151 if (sev
->shaped
== shev
->shaped
) {
1154 XPutBackEvent(dpy
, &ev
);
1160 wwin
= wWindowFor(shev
->window
);
1161 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1164 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1166 wwin
->flags
.shaped
= 0;
1167 wWindowClearShape(wwin
);
1169 } else if (shev
->shaped
) {
1171 wwin
->flags
.shaped
= 1;
1172 wWindowSetShape(wwin
);
1177 #ifdef KEEP_XKB_LOCK_STATUS
1178 /* please help ]d if you know what to do */
1179 handleXkbIndicatorStateNotify(XEvent
*event
)
1183 XkbStateRec staterec
;
1186 for (i
=0; i
<wScreenCount
; i
++) {
1187 scr
= wScreenWithNumber(i
);
1188 wwin
= scr
->focused_window
;
1189 if (wwin
&& wwin
->flags
.focused
) {
1190 XkbGetState(dpy
,XkbUseCoreKbd
,&staterec
);
1191 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1192 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1193 wwin
->frame
->languagemode
= staterec
.group
;
1195 #ifdef XKB_BUTTON_HINT
1196 if (wwin
->frame
->titlebar
) {
1197 wFrameWindowPaint(wwin
->frame
);
1203 #endif /*KEEP_XKB_LOCK_STATUS*/
1206 handleColormapNotify(XEvent
*event
)
1210 Bool reinstall
= False
;
1212 wwin
= wWindowFor(event
->xcolormap
.window
);
1216 scr
= wwin
->screen_ptr
;
1220 if (event
->xcolormap
.new) {
1221 XWindowAttributes attr
;
1223 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1225 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1226 scr
->current_colormap
= attr
.colormap
;
1229 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1230 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1232 /* some bastard app (like XV) removed our colormap */
1234 * can't enforce or things like xscreensaver wont work
1237 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1238 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1240 /* someone has put our colormap back */
1244 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1245 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1247 if (reinstall
&& scr
->current_colormap
!=None
) {
1248 if (!scr
->flags
.colormap_stuff_blocked
)
1249 XInstallColormap(dpy
, scr
->current_colormap
);
1256 handleFocusIn(XEvent
*event
)
1261 * For applications that like stealing the focus.
1263 while (XCheckTypedEvent(dpy
, FocusIn
, event
));
1264 saveTimestamp(event
);
1265 if (event
->xfocus
.mode
== NotifyUngrab
1266 || event
->xfocus
.mode
== NotifyGrab
1267 || event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1271 wwin
= wWindowFor(event
->xfocus
.window
);
1272 if (wwin
&& !wwin
->flags
.focused
) {
1273 if (wwin
->flags
.mapped
)
1274 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1276 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1278 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1280 wSetFocusTo(scr
, NULL
);
1286 windowUnderPointer(WScreen
*scr
)
1292 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
,
1294 return wWindowFor(win
);
1302 handleKeyPress(XEvent
*event
)
1304 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1305 WWindow
*wwin
= scr
->focused_window
;
1308 int command
=-1, index
;
1309 #ifdef KEEP_XKB_LOCK_STATUS
1310 XkbStateRec staterec
;
1311 #endif /*KEEP_XKB_LOCK_STATUS*/
1313 /* ignore CapsLock */
1314 modifiers
= event
->xkey
.state
& ValidModMask
;
1316 for (i
=0; i
<WKBD_LAST
; i
++) {
1317 if (wKeyBindings
[i
].keycode
==0)
1320 if (wKeyBindings
[i
].keycode
==event
->xkey
.keycode
1321 && (/*wKeyBindings[i].modifier==0
1322 ||*/ wKeyBindings
[i
].modifier
==modifiers
)) {
1336 if (!wRootMenuPerformShortcut(event
)) {
1338 static int dontLoop
= 0;
1340 if (dontLoop
> 10) {
1341 wwarning("problem with key event processing code");
1345 /* if the focused window is an internal window, try redispatching
1346 * the event to the managed window, as it can be a WINGs window */
1347 if (wwin
&& wwin
->flags
.internal_window
1348 && wwin
->client_leader
!=None
) {
1349 /* client_leader contains the WINGs toplevel */
1350 event
->xany
.window
= wwin
->client_leader
;
1351 WMHandleEvent(event
);
1358 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1359 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1364 OpenRootMenu(scr
, event
->xkey
.x_root
, event
->xkey
.y_root
, True
);
1366 case WKBD_WINDOWLIST
:
1367 OpenSwitchMenu(scr
, event
->xkey
.x_root
, event
->xkey
.y_root
, True
);
1370 case WKBD_WINDOWMENU
:
1371 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1372 OpenWindowMenu(wwin
, wwin
->frame_x
,
1373 wwin
->frame_y
+wwin
->frame
->top_width
, True
);
1375 case WKBD_MINIATURIZE
:
1376 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1377 && !WFLAGP(wwin
, no_miniaturizable
)) {
1378 CloseWindowMenu(scr
);
1380 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1381 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
1382 event
->xbutton
.time
);
1384 wIconifyWindow(wwin
);
1389 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1390 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1391 CloseWindowMenu(scr
);
1393 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1394 wHideApplication(wapp
);
1399 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_resizable
)) {
1400 CloseWindowMenu(scr
);
1402 if (wwin
->flags
.maximized
) {
1403 wUnmaximizeWindow(wwin
);
1405 wMaximizeWindow(wwin
, MAX_VERTICAL
|MAX_HORIZONTAL
);
1409 case WKBD_VMAXIMIZE
:
1410 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_resizable
)) {
1411 CloseWindowMenu(scr
);
1413 if (wwin
->flags
.maximized
) {
1414 wUnmaximizeWindow(wwin
);
1416 wMaximizeWindow(wwin
, MAX_VERTICAL
);
1421 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1422 CloseWindowMenu(scr
);
1424 wRaiseFrame(wwin
->frame
->core
);
1428 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1429 CloseWindowMenu(scr
);
1431 wLowerFrame(wwin
->frame
->core
);
1434 case WKBD_RAISELOWER
:
1435 /* raise or lower the window under the pointer, not the
1438 wwin
= windowUnderPointer(scr
);
1440 wRaiseLowerFrame(wwin
->frame
->core
);
1443 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1444 if (wwin
->flags
.shaded
)
1445 wUnshadeWindow(wwin
);
1450 case WKBD_MOVERESIZE
:
1451 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1452 CloseWindowMenu(scr
);
1454 wKeyboardMoveResizeWindow(wwin
);
1458 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1459 CloseWindowMenu(scr
);
1460 if (wwin
->protocols
.DELETE_WINDOW
)
1461 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
,
1466 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1467 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1470 case WKBD_FOCUSNEXT
:
1471 StartWindozeCycle(wwin
, event
, True
);
1474 case WKBD_FOCUSPREV
:
1475 StartWindozeCycle(wwin
, event
, False
);
1478 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1479 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1480 i = (scr->current_workspace/10)*10 + wk - 1;\
1481 if (wPreferences.ws_advance || i<scr->workspace_count)\
1482 wWorkspaceChange(scr, i);\
1485 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1486 i = (scr->current_workspace/10)*10 + wk - 1;\
1487 if (wPreferences.ws_advance || i<scr->workspace_count)\
1488 wWorkspaceChange(scr, i);\
1502 case WKBD_NEXTWORKSPACE
:
1503 wWorkspaceRelativeChange(scr
, 1);
1505 case WKBD_PREVWORKSPACE
:
1506 wWorkspaceRelativeChange(scr
, -1);
1519 #define INITBAG(bag) if (bag) WMEmptyBag(bag); else bag = WMCreateBag(4)
1521 index
= command
-WKBD_WINDOW1
;
1523 if (scr
->shortcutWindows
[index
]) {
1524 WMBag
*list
= scr
->shortcutWindows
[index
];
1526 int count
= WMGetBagItemCount(list
);
1531 wUnselectWindows(scr
);
1532 cw
= scr
->current_workspace
;
1534 for (wwin
= WMBagLast(list
, &iter
);
1536 wwin
= WMBagPrevious(list
, &iter
)) {
1539 wWindowChangeWorkspace(wwin
, cw
);
1541 wMakeWindowVisible(wwin
);
1544 wSelectWindow(wwin
, True
);
1547 /* rotate the order of windows, to create a cycling effect */
1548 twin
= WMBagFirst(list
, &iter
);
1549 WMRemoveFromBag(list
, twin
);
1550 WMPutInBag(list
, twin
);
1552 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1554 INITBAG(scr
->shortcutWindows
[index
]);
1555 WMPutInBag(scr
->shortcutWindows
[index
], wwin
);
1557 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1558 WMBag
*selwins
= scr
->selected_windows
;
1561 for (i
= 0; i
< WMGetBagItemCount(selwins
); i
++) {
1562 WWindow
*tmp
= WMGetFromBag(selwins
, i
);
1565 WMPutInBag(scr
->shortcutWindows
[index
], tmp
);
1568 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1571 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1574 } else if (scr
->selected_windows
1575 && WMGetBagItemCount(scr
->selected_windows
)) {
1577 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1578 WMBag
*selwins
= scr
->selected_windows
;
1581 INITBAG(scr
->shortcutWindows
[index
]);
1583 for (i
= 0; i
< WMGetBagItemCount(selwins
); i
++) {
1584 WWindow
*tmp
= WMGetFromBag(selwins
, i
);
1586 WMPutInBag(scr
->shortcutWindows
[index
], tmp
);
1594 case WKBD_SWITCH_SCREEN
:
1595 if (wScreenCount
> 1) {
1599 /* find index of this screen */
1600 for (i
= 0; i
< wScreenCount
; i
++) {
1601 if (wScreenWithNumber(i
) == scr
)
1605 if (i
>= wScreenCount
) {
1608 scr2
= wScreenWithNumber(i
);
1611 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1612 scr2
->scr_width
/2, scr2
->scr_height
/2);
1617 case WKBD_NEXTWSLAYER
:
1618 case WKBD_PREVWSLAYER
:
1622 row
= scr
->current_workspace
/10;
1623 column
= scr
->current_workspace
%10;
1625 if (command
==WKBD_NEXTWSLAYER
) {
1626 if ((row
+1)*10 < scr
->workspace_count
)
1627 wWorkspaceChange(scr
, column
+(row
+1)*10);
1630 wWorkspaceChange(scr
, column
+(row
-1)*10);
1634 case WKBD_CLIPLOWER
:
1635 if (!wPreferences
.flags
.noclip
)
1636 wDockLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1638 case WKBD_CLIPRAISE
:
1639 if (!wPreferences
.flags
.noclip
)
1640 wDockRaise(scr
->workspaces
[scr
->current_workspace
]->clip
);
1642 case WKBD_CLIPRAISELOWER
:
1643 if (!wPreferences
.flags
.noclip
)
1644 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1646 #ifdef KEEP_XKB_LOCK_STATUS
1648 if(wPreferences
.modelock
) {
1650 wwin
= scr
->focused_window
;
1652 if (wwin
&& wwin
->flags
.mapped
1653 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1654 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1655 XkbGetState(dpy
,XkbUseCoreKbd
,&staterec
);
1657 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1658 wwin
->frame
->last_languagemode
= staterec
.group
;
1659 XkbLockGroup(dpy
,XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1664 #endif /* KEEP_XKB_LOCK_STATUS */
1671 handleMotionNotify(XEvent
*event
)
1674 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1676 if (wPreferences
.scrollable_menus
) {
1677 if (scr
->flags
.jump_back_pending
||
1678 event
->xmotion
.x_root
<= 1 ||
1679 event
->xmotion
.x_root
>= (scr
->scr_width
- 2) ||
1680 event
->xmotion
.y_root
<= 1 ||
1681 event
->xmotion
.y_root
>= (scr
->scr_height
- 2)) {
1683 L("pointer at screen edge");
1685 menu
= wMenuUnderPointer(scr
);
1687 wMenuScroll(menu
, event
);
1691 if (event
->xmotion
.subwindow
== None
)
1694 if (scr
->scrolledFMaximize
!= None
) {
1697 twin
= wWindowFor(scr
->scrolledFMaximize
);
1698 if (twin
&& twin
->frame_y
==) {
1702 scr
->scrolledFMaximize
= NULL
;
1706 /* scroll full maximized window */
1707 if (event
->xmotion
.y_root
< 1
1708 || event
->xmotion
.y_root
> scr
->scr_height
- 1) {
1710 wwin
= wWindowFor(event
->xmotion
.subwindow
);
1712 if (wwin
&& (wwin
->flags
.maximized
& MAX_VERTICAL
)
1713 && WFLAGP(wwin
, full_maximize
)
1714 && event
->xmotion
.x_root
>= wwin
->frame_x
1715 && event
->xmotion
.x_root
<= wwin
->frame_x
+ wwin
->frame
->core
->width
) {
1717 if (!WFLAGP(wwin
, no_titlebar
)
1718 && wwin
->frame_y
<= - wwin
->frame
->top_width
) {
1720 wWindowMove(wwin
, wwin
->frame_x
, 0);
1721 wwin
->flags
.dragged_while_fmaximized
= 0;
1723 } else if (!WFLAGP(wwin
, no_resizebar
)
1724 && wwin
->frame_y
+ wwin
->frame
->core
->height
>=
1725 scr
->scr_height
+ wwin
->frame
->bottom_width
) {
1727 int y
= scr
->scr_height
+ wwin
->frame
->bottom_width
;
1729 y
= scr
->scr_height
- wwin
->frame_y
- wwin
->frame
->core
->height
;
1731 wWindowMove(wwin
, wwin
->frame_x
, y
);
1732 wwin
->flags
.dragged_while_fmaximized
= 0;
1741 handleVisibilityNotify(XEvent
*event
)
1745 wwin
= wWindowFor(event
->xvisibility
.window
);
1748 wwin
->flags
.obscured
=
1749 (event
->xvisibility
.state
== VisibilityFullyObscured
);