1 /* event.c- event loop and handling
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 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"
67 /******** Global Variables **********/
68 extern XContext wWinContext
;
69 extern XContext wVEdgeContext
;
71 extern Cursor wCursor
[WCUR_LAST
];
73 extern WShortKey wKeyBindings
[WKBD_LAST
];
74 extern int wScreenCount
;
75 extern Time LastTimestamp
;
76 extern Time LastFocusChange
;
78 extern WPreferences wPreferences
;
80 #define MOD_MASK wPreferences.modifier_mask
82 extern Atom _XA_WM_COLORMAP_NOTIFY
;
84 extern Atom _XA_WM_CHANGE_STATE
;
85 extern Atom _XA_WM_DELETE_WINDOW
;
86 extern Atom _XA_GNUSTEP_WM_ATTR
;
87 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
88 extern Atom _XA_GNUSTEP_TITLEBAR_STATE
;
89 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
90 extern Atom _XA_WINDOWMAKER_COMMAND
;
94 extern Bool wShapeSupported
;
95 extern int wShapeEventBase
;
98 #ifdef KEEP_XKB_LOCK_STATUS
99 extern int wXkbEventBase
;
103 extern char WDelayedActionSet
;
106 /************ Local stuff ***********/
109 static void saveTimestamp(XEvent
*event
);
110 static void handleColormapNotify();
111 static void handleMapNotify();
112 static void handleUnmapNotify();
113 static void handleButtonPress();
114 static void handleExpose();
115 static void handleDestroyNotify();
116 static void handleConfigureRequest();
117 static void handleMapRequest();
118 static void handlePropertyNotify();
119 static void handleEnterNotify();
120 static void handleLeaveNotify();
121 static void handleExtensions();
122 static void handleClientMessage();
123 static void handleKeyPress();
124 static void handleFocusIn();
125 static void handleMotionNotify();
126 static void handleVisibilityNotify();
130 static void handleShapeNotify();
133 /* called from the signal handler */
134 void NotifyDeadProcess(pid_t pid
, unsigned char status
);
136 /* real dead process handler */
137 static void handleDeadProcess(void *foo
);
140 typedef struct DeadProcesses
{
142 unsigned char exit_status
;
145 /* stack of dead processes */
146 static DeadProcesses deadProcesses
[MAX_DEAD_PROCESSES
];
147 static int deadProcessPtr
=0;
150 typedef struct DeathHandler
{
151 WDeathHandler
*callback
;
156 static WMArray
*deathHandlers
=NULL
;
161 wAddDeathHandler(pid_t pid
, WDeathHandler
*callback
, void *cdata
)
163 DeathHandler
*handler
;
165 handler
= malloc(sizeof(DeathHandler
));
170 handler
->callback
= callback
;
171 handler
->client_data
= cdata
;
174 deathHandlers
= WMCreateArrayWithDestructor(8, wfree
);
176 WMAddToArray(deathHandlers
, handler
);
184 wDeleteDeathHandler(WMagicNumber id
)
186 DeathHandler
*handler
=(DeathHandler
*)id
;
188 if (!handler
|| !deathHandlers
)
191 /* array destructor will call wfree(handler) */
192 WMRemoveFromArray(deathHandlers
, handler
);
197 DispatchEvent(XEvent
*event
)
200 handleDeadProcess(NULL
);
202 if (WCHECK_STATE(WSTATE_NEED_EXIT
)) {
203 WCHANGE_STATE(WSTATE_EXITING
);
204 /* received SIGTERM */
206 * WMHandleEvent() can't be called from anything
207 * executed inside here, or we can get in a infinite
210 Shutdown(WSExitMode
);
212 } else if (WCHECK_STATE(WSTATE_NEED_RESTART
)) {
213 WCHANGE_STATE(WSTATE_RESTARTING
);
215 Shutdown(WSRestartPreparationMode
);
216 /* received SIGHUP */
218 } else if (WCHECK_STATE(WSTATE_NEED_REREAD
)) {
219 WCHANGE_STATE(WSTATE_NORMAL
);
220 wDefaultsCheckDomains("bla");
223 /* for the case that all that is wanted to be dispatched is
228 saveTimestamp(event
);
229 switch (event
->type
) {
231 handleMapRequest(event
);
235 handleKeyPress(event
);
239 handleMotionNotify(event
);
242 case ConfigureRequest
:
243 handleConfigureRequest(event
);
247 handleDestroyNotify(event
);
251 handleMapNotify(event
);
255 handleUnmapNotify(event
);
259 handleButtonPress(event
);
267 handlePropertyNotify(event
);
271 handleEnterNotify(event
);
275 handleLeaveNotify(event
);
279 handleClientMessage(event
);
283 handleColormapNotify(event
);
287 if (event
->xmapping
.request
== MappingKeyboard
288 || event
->xmapping
.request
== MappingModifier
)
289 XRefreshKeyboardMapping(&event
->xmapping
);
293 handleFocusIn(event
);
296 case VisibilityNotify
:
297 handleVisibilityNotify(event
);
300 handleExtensions(event
);
307 *----------------------------------------------------------------------
309 * Processes X and internal events indefinitely.
315 * The LastTimestamp global variable is updated.
316 *----------------------------------------------------------------------
322 extern volatile int filesChanged
;
323 extern void wDefaultsCheckDomains();
326 WMNextEvent(dpy
, &event
);
327 WMHandleEvent(&event
);
330 * If dnotify detects changes in configuration
331 * files we have to read them again.
334 fprintf(stdout
,"wmaker: reading config files in defaults database.\n");
335 wDefaultsCheckDomains(NULL
);
343 *----------------------------------------------------------------------
344 * ProcessPendingEvents --
345 * Processes the events that are currently pending (at the time
346 * this function is called) in the display's queue.
349 * After the pending events that were present at the function call
353 * Many -- whatever handling events may involve.
355 *----------------------------------------------------------------------
358 ProcessPendingEvents()
365 /* Take a snapshot of the event count in the queue */
366 count
= XPending(dpy
);
368 while (count
>0 && XPending(dpy
)) {
369 WMNextEvent(dpy
, &event
);
370 WMHandleEvent(&event
);
377 IsDoubleClick(WScreen
*scr
, XEvent
*event
)
379 if ((scr
->last_click_time
>0) &&
380 (event
->xbutton
.time
-scr
->last_click_time
<=wPreferences
.dblclick_time
)
381 && (event
->xbutton
.button
== scr
->last_click_button
)
382 && (event
->xbutton
.window
== scr
->last_click_window
)) {
384 scr
->flags
.next_click_is_not_double
= 1;
385 scr
->last_click_time
= 0;
386 scr
->last_click_window
= event
->xbutton
.window
;
395 NotifyDeadProcess(pid_t pid
, unsigned char status
)
397 if (deadProcessPtr
>=MAX_DEAD_PROCESSES
-1) {
398 wwarning("stack overflow: too many dead processes");
401 /* stack the process to be handled later,
402 * as this is called from the signal handler */
403 deadProcesses
[deadProcessPtr
].pid
= pid
;
404 deadProcesses
[deadProcessPtr
].exit_status
= status
;
410 handleDeadProcess(void *foo
)
415 for (i
=0; i
<deadProcessPtr
; i
++) {
416 wWindowDeleteSavedStatesForPID(deadProcesses
[i
].pid
);
419 if (!deathHandlers
) {
424 /* get the pids on the queue and call handlers */
425 while (deadProcessPtr
>0) {
428 for (i
= WMGetArrayItemCount(deathHandlers
)-1; i
>= 0; i
--) {
429 tmp
= WMGetFromArray(deathHandlers
, i
);
433 if (tmp
->pid
== deadProcesses
[deadProcessPtr
].pid
) {
434 (*tmp
->callback
)(tmp
->pid
,
435 deadProcesses
[deadProcessPtr
].exit_status
,
437 wDeleteDeathHandler(tmp
);
445 saveTimestamp(XEvent
*event
)
448 * Never save CurrentTime as LastTimestamp because CurrentTime
449 * it's not a real timestamp (it's the 0L constant)
452 switch (event
->type
) {
455 LastTimestamp
= event
->xbutton
.time
;
459 LastTimestamp
= event
->xkey
.time
;
462 LastTimestamp
= event
->xmotion
.time
;
465 LastTimestamp
= event
->xproperty
.time
;
469 LastTimestamp
= event
->xcrossing
.time
;
472 LastTimestamp
= event
->xselectionclear
.time
;
474 case SelectionRequest
:
475 LastTimestamp
= event
->xselectionrequest
.time
;
477 case SelectionNotify
:
478 LastTimestamp
= event
->xselection
.time
;
480 wXDNDProcessSelection(event
);
488 matchWindow(void *item
, void *cdata
)
490 return (((WFakeGroupLeader
*)item
)->origLeader
== (Window
)cdata
);
495 handleExtensions(XEvent
*event
)
497 #ifdef KEEP_XKB_LOCK_STATUS
499 xkbevent
= (XkbEvent
*)event
;
500 #endif /*KEEP_XKB_LOCK_STATUS*/
502 if (wShapeSupported
&& event
->type
== (wShapeEventBase
+ShapeNotify
)) {
503 handleShapeNotify(event
);
506 #ifdef KEEP_XKB_LOCK_STATUS
507 if (wPreferences
.modelock
&& (xkbevent
->type
== wXkbEventBase
)){
508 handleXkbIndicatorStateNotify(event
);
510 #endif /*KEEP_XKB_LOCK_STATUS*/
515 handleMapRequest(XEvent
*ev
)
519 Window window
= ev
->xmaprequest
.window
;
522 printf("got map request for %x\n", (unsigned)window
);
524 if ((wwin
= wWindowFor(window
))) {
525 if (wwin
->flags
.shaded
) {
526 wUnshadeWindow(wwin
);
528 /* deiconify window */
529 if (wwin
->flags
.miniaturized
) {
530 wDeiconifyWindow(wwin
);
531 } else if (wwin
->flags
.hidden
) {
532 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
533 /* go to the last workspace that the user worked on the app */
535 wWorkspaceChange(wwin
->screen_ptr
, wapp
->last_workspace
);
537 wUnhideApplication(wapp
, False
, False
);
542 scr
= wScreenForRootWindow(ev
->xmaprequest
.parent
);
544 wwin
= wManageWindow(scr
, window
);
547 * This is to let the Dock know that the application it launched
548 * has already been mapped (eg: it has finished launching).
549 * It is not necessary for normally docked apps, but is needed for
550 * apps that were forcedly docked (like with dockit).
552 if (scr
->last_dock
) {
553 if (wwin
&& wwin
->main_window
!=None
&& wwin
->main_window
!=window
)
554 wDockTrackWindowLaunch(scr
->last_dock
, wwin
->main_window
);
556 wDockTrackWindowLaunch(scr
->last_dock
, window
);
560 wClientSetState(wwin
, NormalState
, None
);
561 if (wwin
->flags
.maximized
) {
562 wMaximizeWindow(wwin
, wwin
->flags
.maximized
);
564 if (wwin
->flags
.shaded
) {
565 wwin
->flags
.shaded
= 0;
566 wwin
->flags
.skip_next_animation
= 1;
569 if (wwin
->flags
.miniaturized
) {
570 wwin
->flags
.miniaturized
= 0;
571 wwin
->flags
.skip_next_animation
= 1;
572 wIconifyWindow(wwin
);
574 if (wwin
->flags
.fullscreen
) {
575 wwin
->flags
.fullscreen
= 0;
576 wFullscreenWindow(wwin
);
578 if (wwin
->flags
.hidden
) {
579 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
581 wwin
->flags
.hidden
= 0;
582 wwin
->flags
.skip_next_animation
= 1;
584 wHideApplication(wapp
);
592 handleDestroyNotify(XEvent
*event
)
596 Window window
= event
->xdestroywindow
.window
;
597 WScreen
*scr
= wScreenForRootWindow(event
->xdestroywindow
.event
);
601 printf("got destroy notify\n");
603 wwin
= wWindowFor(window
);
605 wUnmanageWindow(wwin
, False
, True
);
609 while ((index
= WMFindInArray(scr
->fakeGroupLeaders
, matchWindow
,
610 (void*)window
)) != WANotFound
) {
611 WFakeGroupLeader
*fPtr
;
613 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
614 if (fPtr
->retainCount
> 0) {
616 if (fPtr
->retainCount
==0 && fPtr
->leader
!=None
) {
617 XDestroyWindow(dpy
, fPtr
->leader
);
622 fPtr
->origLeader
= None
;
626 app
= wApplicationOf(window
);
628 if (window
== app
->main_window
) {
630 wwin
= app
->main_window_desc
->screen_ptr
->focused_window
;
632 if (wwin
->main_window
== window
) {
633 wwin
->main_window
= None
;
638 wApplicationDestroy(app
);
645 handleExpose(XEvent
*event
)
647 WObjDescriptor
*desc
;
651 printf("got expose\n");
653 while (XCheckTypedWindowEvent(dpy
, event
->xexpose
.window
, Expose
, &ev
));
655 if (XFindContext(dpy
, event
->xexpose
.window
, wWinContext
,
656 (XPointer
*)&desc
)==XCNOENT
) {
660 if (desc
->handle_expose
) {
661 (*desc
->handle_expose
)(desc
, event
);
666 executeButtonAction(WScreen
*scr
, XEvent
*event
, int action
)
669 case WA_SELECT_WINDOWS
:
670 wUnselectWindows(scr
);
671 wSelectWindows(scr
, event
);
673 case WA_OPEN_APPMENU
:
674 OpenRootMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
676 if (scr
->root_menu
) {
677 if (scr
->root_menu
->brother
->flags
.mapped
)
678 event
->xbutton
.window
= scr
->root_menu
->brother
->frame
->core
->window
;
680 event
->xbutton
.window
= scr
->root_menu
->frame
->core
->window
;
683 case WA_OPEN_WINLISTMENU
:
684 OpenSwitchMenu(scr
, event
->xbutton
.x_root
, event
->xbutton
.y_root
, False
);
685 if (scr
->switch_menu
) {
686 if (scr
->switch_menu
->brother
->flags
.mapped
)
687 event
->xbutton
.window
= scr
->switch_menu
->brother
->frame
->core
->window
;
689 event
->xbutton
.window
= scr
->switch_menu
->frame
->core
->window
;
700 handleButtonPress(XEvent
*event
)
702 WObjDescriptor
*desc
;
706 printf("got button press\n");
708 scr
= wScreenForRootWindow(event
->xbutton
.root
);
716 if (event
->xbutton
.window
==scr
->root_win
) {
717 if (event
->xbutton
.button
==Button1
&&
718 wPreferences
.mouse_button1
!=WA_NONE
) {
719 executeButtonAction(scr
, event
, wPreferences
.mouse_button1
);
720 } else if (event
->xbutton
.button
==Button2
&&
721 wPreferences
.mouse_button2
!=WA_NONE
) {
722 executeButtonAction(scr
, event
, wPreferences
.mouse_button2
);
723 } else if (event
->xbutton
.button
==Button3
&&
724 wPreferences
.mouse_button3
!=WA_NONE
) {
725 executeButtonAction(scr
, event
, wPreferences
.mouse_button3
);
726 } else if (event
->xbutton
.button
==Button4
&&
727 wPreferences
.mouse_wheel
!=WA_NONE
) {
728 wWorkspaceRelativeChange(scr
, 1);
729 } else if (event
->xbutton
.button
==Button5
&&
730 wPreferences
.mouse_wheel
!=WA_NONE
) {
731 wWorkspaceRelativeChange(scr
, -1);
737 if (XFindContext(dpy
, event
->xbutton
.subwindow
, wWinContext
,
738 (XPointer
*)&desc
)==XCNOENT
) {
739 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
,
740 (XPointer
*)&desc
)==XCNOENT
) {
745 if (desc
->parent_type
== WCLASS_WINDOW
) {
748 if (event
->xbutton
.state
& MOD_MASK
) {
749 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
752 /* if (wPreferences.focus_mode == WKF_CLICK) {*/
753 if (wPreferences
.ignore_focus_click
) {
754 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
756 XAllowEvents(dpy
, ReplayPointer
, CurrentTime
);
759 } else if (desc
->parent_type
== WCLASS_APPICON
760 || desc
->parent_type
== WCLASS_MINIWINDOW
761 || desc
->parent_type
== WCLASS_DOCK_ICON
) {
762 if (event
->xbutton
.state
& MOD_MASK
) {
764 XAllowEvents(dpy
, AsyncPointer
, CurrentTime
);
769 if (desc
->handle_mousedown
!=NULL
) {
770 (*desc
->handle_mousedown
)(desc
, event
);
773 /* save double-click information */
774 if (scr
->flags
.next_click_is_not_double
) {
775 scr
->flags
.next_click_is_not_double
= 0;
777 scr
->last_click_time
= event
->xbutton
.time
;
778 scr
->last_click_button
= event
->xbutton
.button
;
779 scr
->last_click_window
= event
->xbutton
.window
;
785 handleMapNotify(XEvent
*event
)
791 wwin
= wWindowFor(event
->xmap
.event
);
792 if (wwin
&& wwin
->client_win
== event
->xmap
.event
) {
793 if (wwin
->flags
.miniaturized
) {
794 wDeiconifyWindow(wwin
);
798 wClientSetState(wwin
, NormalState
, None
);
806 handleUnmapNotify(XEvent
*event
)
810 Bool withdraw
= False
;
812 printf("got unmap\n");
814 /* only process windows with StructureNotify selected
815 * (ignore SubstructureNotify) */
816 wwin
= wWindowFor(event
->xunmap
.window
);
820 /* whether the event is a Withdrawal request */
821 if (event
->xunmap
.event
== wwin
->screen_ptr
->root_win
822 && event
->xunmap
.send_event
)
825 if (wwin
->client_win
!= event
->xunmap
.event
&& !withdraw
)
828 if (!wwin
->flags
.mapped
&& !withdraw
829 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
830 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
)
834 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
835 wwin
->flags
.mapped
= 0;
837 /* check if the window was destroyed */
838 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, DestroyNotify
,&ev
)) {
841 Bool reparented
= False
;
843 if (XCheckTypedWindowEvent(dpy
, wwin
->client_win
, ReparentNotify
, &ev
))
846 /* withdraw window */
847 wwin
->flags
.mapped
= 0;
849 wClientSetState(wwin
, WithdrawnState
, None
);
851 /* if the window was reparented, do not reparent it back to the
853 wUnmanageWindow(wwin
, !reparented
, False
);
860 handleConfigureRequest(XEvent
*event
)
864 printf("got configure request\n");
866 if (!(wwin
=wWindowFor(event
->xconfigurerequest
.window
))) {
868 * Configure request for unmapped window
870 wClientConfigure(NULL
, &(event
->xconfigurerequest
));
872 wClientConfigure(wwin
, &(event
->xconfigurerequest
));
878 handlePropertyNotify(XEvent
*event
)
887 printf("got property notify\n");
889 if ((wwin
=wWindowFor(event
->xproperty
.window
))) {
890 if (!XGetGeometry(dpy
, wwin
->client_win
, &jr
, &ji
, &ji
,
891 &ju
, &ju
, &ju
, &ju
)) {
894 wClientCheckProperty(wwin
, &event
->xproperty
);
896 wapp
= wApplicationOf(event
->xproperty
.window
);
898 wClientCheckProperty(wapp
->main_window_desc
, &event
->xproperty
);
901 scr
= wScreenForWindow(event
->xproperty
.window
);
906 handleClientMessage(XEvent
*event
)
909 WObjDescriptor
*desc
;
911 printf("got client message\n");
913 /* handle transition from Normal to Iconic state */
914 if (event
->xclient
.message_type
== _XA_WM_CHANGE_STATE
915 && event
->xclient
.format
== 32
916 && event
->xclient
.data
.l
[0] == IconicState
) {
918 wwin
= wWindowFor(event
->xclient
.window
);
920 if (!wwin
->flags
.miniaturized
)
921 wIconifyWindow(wwin
);
922 } else if (event
->xclient
.message_type
== _XA_WM_COLORMAP_NOTIFY
923 && event
->xclient
.format
== 32) {
924 WScreen
*scr
= wScreenSearchForRootWindow(event
->xclient
.window
);
929 if (event
->xclient
.data
.l
[1] == 1) { /* starting */
930 wColormapAllowClientInstallation(scr
, True
);
931 } else { /* stopping */
932 wColormapAllowClientInstallation(scr
, False
);
934 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_COMMAND
) {
936 wDefaultsCheckDomains("bla");
938 } else if (event
->xclient
.message_type
== _XA_WINDOWMAKER_WM_FUNCTION
) {
941 wapp
= wApplicationOf(event
->xclient
.window
);
943 switch (event
->xclient
.data
.l
[0]) {
944 case WMFHideOtherApplications
:
945 wHideOtherApplications(wapp
->main_window_desc
);
949 case WMFHideApplication
:
950 wHideApplication(wapp
);
956 wwin
= wWindowFor(event
->xclient
.window
);
958 switch (event
->xclient
.data
.l
[0]) {
959 case WMFHideOtherApplications
:
960 wHideOtherApplications(wwin
);
963 case WMFHideApplication
:
964 wHideApplication(wApplicationOf(wwin
->main_window
));
969 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_WM_ATTR
) {
970 wwin
= wWindowFor(event
->xclient
.window
);
972 switch (event
->xclient
.data
.l
[0]) {
973 case GSWindowLevelAttr
:
975 int level
= (int)event
->xclient
.data
.l
[1];
977 if (WINDOW_LEVEL(wwin
) != level
) {
978 ChangeStackingLevel(wwin
->frame
->core
, level
);
983 } else if (event
->xclient
.message_type
== _XA_GNUSTEP_TITLEBAR_STATE
) {
984 wwin
= wWindowFor(event
->xclient
.window
);
986 switch (event
->xclient
.data
.l
[0]) {
987 case WMTitleBarNormal
:
988 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
991 wFrameWindowChangeState(wwin
->frame
, WS_PFOCUSED
);
994 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
998 } else if (wNETWMProcessClientMessage(&event
->xclient
)) {
1002 } else if (wXDNDProcessClientMessage(&event
->xclient
)) {
1007 * Non-standard thing, but needed by OffiX DND.
1008 * For when the icon frame gets a ClientMessage
1009 * that should have gone to the icon_window.
1011 if (XFindContext(dpy
, event
->xbutton
.window
, wWinContext
,
1012 (XPointer
*)&desc
)!=XCNOENT
) {
1013 struct WIcon
*icon
=NULL
;
1015 if (desc
->parent_type
== WCLASS_MINIWINDOW
) {
1016 icon
= (WIcon
*)desc
->parent
;
1017 } else if (desc
->parent_type
== WCLASS_DOCK_ICON
1018 || desc
->parent_type
== WCLASS_APPICON
) {
1019 icon
= ((WAppIcon
*)desc
->parent
)->icon
;
1021 if (icon
&& (wwin
=icon
->owner
)) {
1022 if (wwin
->client_win
!=event
->xclient
.window
) {
1023 event
->xclient
.window
= wwin
->client_win
;
1024 XSendEvent(dpy
, wwin
->client_win
, False
, NoEventMask
,
1034 raiseWindow(WScreen
*scr
)
1038 scr
->autoRaiseTimer
= NULL
;
1040 wwin
= wWindowFor(scr
->autoRaiseWindow
);
1044 if (!wwin
->flags
.destroyed
&& wwin
->flags
.focused
) {
1045 wRaiseFrame(wwin
->frame
->core
);
1046 /* this is needed or a race condition will occur */
1053 handleEnterNotify(XEvent
*event
)
1056 WObjDescriptor
*desc
= NULL
;
1057 #ifdef VIRTUAL_DESKTOP
1058 void (*vdHandler
)(XEvent
* event
);
1061 WScreen
*scr
= wScreenForRootWindow(event
->xcrossing
.root
);
1063 printf("got enter notify\n");
1066 #ifdef VIRTUAL_DESKTOP
1067 if (XFindContext(dpy
, event
->xcrossing
.window
, wVEdgeContext
,
1068 (XPointer
*)&vdHandler
)!=XCNOENT
) {
1069 (*vdHandler
)(event
);
1073 if (XCheckTypedWindowEvent(dpy
, event
->xcrossing
.window
, LeaveNotify
,
1075 /* already left the window... */
1077 if (ev
.xcrossing
.mode
==event
->xcrossing
.mode
1078 && ev
.xcrossing
.detail
==event
->xcrossing
.detail
) {
1083 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
,
1084 (XPointer
*)&desc
)!=XCNOENT
) {
1085 if(desc
->handle_enternotify
)
1086 (*desc
->handle_enternotify
)(desc
, event
);
1089 /* enter to window */
1090 wwin
= wWindowFor(event
->xcrossing
.window
);
1092 if (wPreferences
.colormap_mode
==WCM_POINTER
) {
1093 wColormapInstallForWindow(scr
, NULL
);
1095 if (scr
->autoRaiseTimer
1096 && event
->xcrossing
.root
==event
->xcrossing
.window
) {
1097 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1098 scr
->autoRaiseTimer
= NULL
;
1101 /* set auto raise timer even if in focus-follows-mouse mode
1102 * and the event is for the frame window, even if the window
1103 * has focus already. useful if you move the pointer from a focused
1104 * window to the root window and back pretty fast
1106 * set focus if in focus-follows-mouse mode and the event
1107 * is for the frame window and window doesn't have focus yet */
1108 if (wPreferences
.focus_mode
==WKF_SLOPPY
1109 && wwin
->frame
->core
->window
==event
->xcrossing
.window
1110 && !scr
->flags
.doing_alt_tab
) {
1112 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
))
1113 wSetFocusTo(scr
, wwin
);
1115 if (scr
->autoRaiseTimer
)
1116 WMDeleteTimerHandler(scr
->autoRaiseTimer
);
1117 scr
->autoRaiseTimer
= NULL
;
1119 if (wPreferences
.raise_delay
&& !WFLAGP(wwin
, no_focusable
)) {
1120 scr
->autoRaiseWindow
= wwin
->frame
->core
->window
;
1122 = WMAddTimerHandler(wPreferences
.raise_delay
,
1123 (WMCallback
*)raiseWindow
, scr
);
1126 /* Install colormap for window, if the colormap installation mode
1127 * is colormap_follows_mouse */
1128 if (wPreferences
.colormap_mode
==WCM_POINTER
) {
1129 if (wwin
->client_win
==event
->xcrossing
.window
)
1130 wColormapInstallForWindow(scr
, wwin
);
1132 wColormapInstallForWindow(scr
, NULL
);
1136 /* a little kluge to hide the clip balloon */
1137 if (!wPreferences
.flags
.noclip
&& scr
->flags
.clip_balloon_mapped
) {
1139 XUnmapWindow(dpy
, scr
->clip_balloon
);
1140 scr
->flags
.clip_balloon_mapped
= 0;
1142 if (desc
->parent_type
!=WCLASS_DOCK_ICON
1143 || scr
->clip_icon
!= desc
->parent
) {
1144 XUnmapWindow(dpy
, scr
->clip_balloon
);
1145 scr
->flags
.clip_balloon_mapped
= 0;
1150 if (event
->xcrossing
.window
== event
->xcrossing
.root
1151 && event
->xcrossing
.detail
== NotifyNormal
1152 && event
->xcrossing
.detail
!= NotifyInferior
1153 && wPreferences
.focus_mode
!= WKF_CLICK
) {
1155 wSetFocusTo(scr
, scr
->focused_window
);
1159 wBalloonEnteredObject(scr
, desc
);
1165 handleLeaveNotify(XEvent
*event
)
1167 WObjDescriptor
*desc
= NULL
;
1169 if (XFindContext(dpy
, event
->xcrossing
.window
, wWinContext
,
1170 (XPointer
*)&desc
)!=XCNOENT
) {
1171 if(desc
->handle_leavenotify
)
1172 (*desc
->handle_leavenotify
)(desc
, event
);
1179 handleShapeNotify(XEvent
*event
)
1181 XShapeEvent
*shev
= (XShapeEvent
*)event
;
1185 printf("got shape notify\n");
1187 while (XCheckTypedWindowEvent(dpy
, shev
->window
, event
->type
, &ev
)) {
1188 XShapeEvent
*sev
= (XShapeEvent
*)&ev
;
1190 if (sev
->kind
== ShapeBounding
) {
1191 if (sev
->shaped
== shev
->shaped
) {
1194 XPutBackEvent(dpy
, &ev
);
1200 wwin
= wWindowFor(shev
->window
);
1201 if (!wwin
|| shev
->kind
!= ShapeBounding
)
1204 if (!shev
->shaped
&& wwin
->flags
.shaped
) {
1206 wwin
->flags
.shaped
= 0;
1207 wWindowClearShape(wwin
);
1209 } else if (shev
->shaped
) {
1211 wwin
->flags
.shaped
= 1;
1212 wWindowSetShape(wwin
);
1217 #ifdef KEEP_XKB_LOCK_STATUS
1218 /* please help ]d if you know what to do */
1219 handleXkbIndicatorStateNotify(XEvent
*event
)
1223 XkbStateRec staterec
;
1226 for (i
=0; i
<wScreenCount
; i
++) {
1227 scr
= wScreenWithNumber(i
);
1228 wwin
= scr
->focused_window
;
1229 if (wwin
&& wwin
->flags
.focused
) {
1230 XkbGetState(dpy
,XkbUseCoreKbd
,&staterec
);
1231 if (wwin
->frame
->languagemode
!= staterec
.group
) {
1232 wwin
->frame
->last_languagemode
= wwin
->frame
->languagemode
;
1233 wwin
->frame
->languagemode
= staterec
.group
;
1235 #ifdef XKB_BUTTON_HINT
1236 if (wwin
->frame
->titlebar
) {
1237 wFrameWindowPaint(wwin
->frame
);
1243 #endif /*KEEP_XKB_LOCK_STATUS*/
1246 handleColormapNotify(XEvent
*event
)
1250 Bool reinstall
= False
;
1252 wwin
= wWindowFor(event
->xcolormap
.window
);
1256 scr
= wwin
->screen_ptr
;
1260 if (event
->xcolormap
.new) {
1261 XWindowAttributes attr
;
1263 XGetWindowAttributes(dpy
, wwin
->client_win
, &attr
);
1265 if (wwin
== scr
->cmap_window
&& wwin
->cmap_window_no
== 0)
1266 scr
->current_colormap
= attr
.colormap
;
1269 } else if (event
->xcolormap
.state
== ColormapUninstalled
&&
1270 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1272 /* some bastard app (like XV) removed our colormap */
1274 * can't enforce or things like xscreensaver wont work
1277 } else if (event
->xcolormap
.state
== ColormapInstalled
&&
1278 scr
->current_colormap
== event
->xcolormap
.colormap
) {
1280 /* someone has put our colormap back */
1284 } while (XCheckTypedEvent(dpy
, ColormapNotify
, event
)
1285 && ((wwin
= wWindowFor(event
->xcolormap
.window
)) || 1));
1287 if (reinstall
&& scr
->current_colormap
!=None
) {
1288 if (!scr
->flags
.colormap_stuff_blocked
)
1289 XInstallColormap(dpy
, scr
->current_colormap
);
1296 handleFocusIn(XEvent
*event
)
1301 * For applications that like stealing the focus.
1303 while (XCheckTypedEvent(dpy
, FocusIn
, event
));
1304 saveTimestamp(event
);
1305 if (event
->xfocus
.mode
== NotifyUngrab
1306 || event
->xfocus
.mode
== NotifyGrab
1307 || event
->xfocus
.detail
> NotifyNonlinearVirtual
) {
1311 wwin
= wWindowFor(event
->xfocus
.window
);
1312 if (wwin
&& !wwin
->flags
.focused
) {
1313 if (wwin
->flags
.mapped
)
1314 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1316 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1318 WScreen
*scr
= wScreenForWindow(event
->xfocus
.window
);
1320 wSetFocusTo(scr
, NULL
);
1326 windowUnderPointer(WScreen
*scr
)
1332 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
,
1334 return wWindowFor(win
);
1339 static int CheckFullScreenWindowFocused(WScreen
*scr
)
1341 if (scr
->focused_window
&& scr
->focused_window
->flags
.fullscreen
)
1349 handleKeyPress(XEvent
*event
)
1351 WScreen
*scr
= wScreenForRootWindow(event
->xkey
.root
);
1352 WWindow
*wwin
= scr
->focused_window
;
1355 int command
=-1, index
;
1356 #ifdef KEEP_XKB_LOCK_STATUS
1357 XkbStateRec staterec
;
1358 #endif /*KEEP_XKB_LOCK_STATUS*/
1360 /* ignore CapsLock */
1361 modifiers
= event
->xkey
.state
& ValidModMask
;
1363 for (i
=0; i
<WKBD_LAST
; i
++) {
1364 if (wKeyBindings
[i
].keycode
==0)
1367 if (wKeyBindings
[i
].keycode
==event
->xkey
.keycode
1368 && (/*wKeyBindings[i].modifier==0
1369 ||*/ wKeyBindings
[i
].modifier
==modifiers
)) {
1383 if (!wRootMenuPerformShortcut(event
)) {
1385 static int dontLoop
= 0;
1387 if (dontLoop
> 10) {
1388 wwarning("problem with key event processing code");
1392 /* if the focused window is an internal window, try redispatching
1393 * the event to the managed window, as it can be a WINGs window */
1394 if (wwin
&& wwin
->flags
.internal_window
1395 && wwin
->client_leader
!=None
) {
1396 /* client_leader contains the WINGs toplevel */
1397 event
->xany
.window
= wwin
->client_leader
;
1398 WMHandleEvent(event
);
1405 #define ISMAPPED(w) ((w) && !(w)->flags.miniaturized && ((w)->flags.mapped || (w)->flags.shaded))
1406 #define ISFOCUSED(w) ((w) && (w)->flags.focused)
1411 /*OpenRootMenu(scr, event->xkey.x_root, event->xkey.y_root, True);*/
1412 if (!CheckFullScreenWindowFocused(scr
)) {
1413 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1414 OpenRootMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/2, rect
.pos
.y
+ rect
.size
.height
/2, True
);
1417 case WKBD_WINDOWLIST
:
1418 if (!CheckFullScreenWindowFocused(scr
)) {
1419 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1420 OpenSwitchMenu(scr
, rect
.pos
.x
+ rect
.size
.width
/2, rect
.pos
.y
+ rect
.size
.height
/2, True
);
1424 case WKBD_WINDOWMENU
:
1425 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
))
1426 OpenWindowMenu(wwin
, wwin
->frame_x
,
1427 wwin
->frame_y
+wwin
->frame
->top_width
, True
);
1429 case WKBD_MINIATURIZE
:
1430 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)
1431 && !WFLAGP(wwin
, no_miniaturizable
)) {
1432 CloseWindowMenu(scr
);
1434 if (wwin
->protocols
.MINIATURIZE_WINDOW
)
1435 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
1436 event
->xbutton
.time
);
1438 wIconifyWindow(wwin
);
1443 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1444 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1445 CloseWindowMenu(scr
);
1447 if (wapp
&& !WFLAGP(wapp
->main_window_desc
, no_appicon
)) {
1448 wHideApplication(wapp
);
1452 case WKBD_HIDE_OTHERS
:
1453 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1454 CloseWindowMenu(scr
);
1456 wHideOtherApplications(wwin
);
1460 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1461 int newdir
= (MAX_VERTICAL
|MAX_HORIZONTAL
);
1463 CloseWindowMenu(scr
);
1465 if (wwin
->flags
.maximized
== newdir
) {
1466 wUnmaximizeWindow(wwin
);
1468 wMaximizeWindow(wwin
, newdir
|MAX_KEYBOARD
);
1472 case WKBD_VMAXIMIZE
:
1473 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1474 int newdir
= (MAX_VERTICAL
^ wwin
->flags
.maximized
);
1476 CloseWindowMenu(scr
);
1479 wMaximizeWindow(wwin
, newdir
|MAX_KEYBOARD
);
1481 wUnmaximizeWindow(wwin
);
1485 case WKBD_HMAXIMIZE
:
1486 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && IS_RESIZABLE(wwin
)) {
1487 int newdir
= (MAX_HORIZONTAL
^ wwin
->flags
.maximized
);
1489 CloseWindowMenu(scr
);
1492 wMaximizeWindow(wwin
, newdir
|MAX_KEYBOARD
);
1494 wUnmaximizeWindow(wwin
);
1499 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1500 CloseWindowMenu(scr
);
1502 wRaiseFrame(wwin
->frame
->core
);
1506 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1507 CloseWindowMenu(scr
);
1509 wLowerFrame(wwin
->frame
->core
);
1512 case WKBD_RAISELOWER
:
1513 /* raise or lower the window under the pointer, not the
1516 wwin
= windowUnderPointer(scr
);
1518 wRaiseLowerFrame(wwin
->frame
->core
);
1521 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_shadeable
)) {
1522 if (wwin
->flags
.shaded
)
1523 wUnshadeWindow(wwin
);
1528 case WKBD_MOVERESIZE
:
1529 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) &&
1530 (IS_RESIZABLE(wwin
) || IS_MOVABLE(wwin
))) {
1531 CloseWindowMenu(scr
);
1533 wKeyboardMoveResizeWindow(wwin
);
1537 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
) && !WFLAGP(wwin
, no_closable
)) {
1538 CloseWindowMenu(scr
);
1539 if (wwin
->protocols
.DELETE_WINDOW
)
1540 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
,
1545 if (ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1546 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1549 case WKBD_FOCUSNEXT
:
1550 StartWindozeCycle(wwin
, event
, True
);
1553 case WKBD_FOCUSPREV
:
1554 StartWindozeCycle(wwin
, event
, False
);
1557 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
1558 #define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\
1559 i = (scr->current_workspace/10)*10 + wk - 1;\
1560 if (wPreferences.ws_advance || i<scr->workspace_count)\
1561 wWorkspaceChange(scr, i);\
1564 #define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\
1565 i = (scr->current_workspace/10)*10 + wk - 1;\
1566 if (wPreferences.ws_advance || i<scr->workspace_count)\
1567 wWorkspaceChange(scr, i);\
1581 case WKBD_NEXTWORKSPACE
:
1582 wWorkspaceRelativeChange(scr
, 1);
1584 case WKBD_PREVWORKSPACE
:
1585 wWorkspaceRelativeChange(scr
, -1);
1598 index
= command
-WKBD_WINDOW1
;
1600 if (scr
->shortcutWindows
[index
]) {
1601 WMArray
*list
= scr
->shortcutWindows
[index
];
1603 int count
= WMGetArrayItemCount(list
);
1605 WMArrayIterator iter
;
1608 wUnselectWindows(scr
);
1609 cw
= scr
->current_workspace
;
1611 WM_ETARETI_ARRAY(list
, wwin
, iter
) {
1613 wWindowChangeWorkspace(wwin
, cw
);
1615 wMakeWindowVisible(wwin
);
1618 wSelectWindow(wwin
, True
);
1621 /* rotate the order of windows, to create a cycling effect */
1622 twin
= WMGetFromArray(list
, 0);
1623 WMDeleteFromArray(list
, 0);
1624 WMAddToArray(list
, twin
);
1626 } else if (wwin
&& ISMAPPED(wwin
) && ISFOCUSED(wwin
)) {
1627 if (scr
->shortcutWindows
[index
]) {
1628 WMFreeArray(scr
->shortcutWindows
[index
]);
1629 scr
->shortcutWindows
[index
] = NULL
;
1632 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1633 scr
->shortcutWindows
[index
] =
1634 WMDuplicateArray(scr
->selected_windows
);
1635 /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
1636 WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
1638 scr
->shortcutWindows
[index
] = WMCreateArray(4);
1639 WMAddToArray(scr
->shortcutWindows
[index
], wwin
);
1642 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1645 wSelectWindow(wwin
, !wwin
->flags
.selected
);
1648 } else if (scr
->selected_windows
1649 && WMGetArrayItemCount(scr
->selected_windows
)) {
1651 if (wwin
->flags
.selected
&& scr
->selected_windows
) {
1652 if (scr
->shortcutWindows
[index
]) {
1653 WMFreeArray(scr
->shortcutWindows
[index
]);
1655 scr
->shortcutWindows
[index
] =
1656 WMDuplicateArray(scr
->selected_windows
);
1662 case WKBD_SWITCH_SCREEN
:
1663 if (wScreenCount
> 1) {
1667 /* find index of this screen */
1668 for (i
= 0; i
< wScreenCount
; i
++) {
1669 if (wScreenWithNumber(i
) == scr
)
1673 if (i
>= wScreenCount
) {
1676 scr2
= wScreenWithNumber(i
);
1679 XWarpPointer(dpy
, scr
->root_win
, scr2
->root_win
, 0, 0, 0, 0,
1680 scr2
->scr_width
/2, scr2
->scr_height
/2);
1685 case WKBD_NEXTWSLAYER
:
1686 case WKBD_PREVWSLAYER
:
1690 row
= scr
->current_workspace
/10;
1691 column
= scr
->current_workspace
%10;
1693 if (command
==WKBD_NEXTWSLAYER
) {
1694 if ((row
+1)*10 < scr
->workspace_count
)
1695 wWorkspaceChange(scr
, column
+(row
+1)*10);
1698 wWorkspaceChange(scr
, column
+(row
-1)*10);
1702 case WKBD_CLIPLOWER
:
1703 if (!wPreferences
.flags
.noclip
)
1704 wDockLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1706 case WKBD_CLIPRAISE
:
1707 if (!wPreferences
.flags
.noclip
)
1708 wDockRaise(scr
->workspaces
[scr
->current_workspace
]->clip
);
1710 case WKBD_CLIPRAISELOWER
:
1711 if (!wPreferences
.flags
.noclip
)
1712 wDockRaiseLower(scr
->workspaces
[scr
->current_workspace
]->clip
);
1714 #ifdef KEEP_XKB_LOCK_STATUS
1716 if(wPreferences
.modelock
) {
1718 wwin
= scr
->focused_window
;
1720 if (wwin
&& wwin
->flags
.mapped
1721 && wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
1722 && !wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
) {
1723 XkbGetState(dpy
,XkbUseCoreKbd
,&staterec
);
1725 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
1726 wwin
->frame
->last_languagemode
= staterec
.group
;
1727 XkbLockGroup(dpy
,XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1732 #endif /* KEEP_XKB_LOCK_STATUS */
1733 #ifdef VIRTUAL_DESKTOP
1734 case WKBD_VDESK_LEFT
:
1735 wWorkspaceKeyboardMoveDesktop(scr
, VEC_LEFT
);
1738 case WKBD_VDESK_RIGHT
:
1739 wWorkspaceKeyboardMoveDesktop(scr
, VEC_RIGHT
);
1743 wWorkspaceKeyboardMoveDesktop(scr
, VEC_UP
);
1746 case WKBD_VDESK_DOWN
:
1747 wWorkspaceKeyboardMoveDesktop(scr
, VEC_DOWN
);
1756 handleMotionNotify(XEvent
*event
)
1758 WScreen
*scr
= wScreenForRootWindow(event
->xmotion
.root
);
1760 if (wPreferences
.scrollable_menus
) {
1761 WMPoint p
= wmkpoint(event
->xmotion
.x_root
, event
->xmotion
.y_root
);
1762 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPoint(scr
, p
));
1764 if (scr
->flags
.jump_back_pending
||
1765 p
.x
<= (rect
.pos
.x
+ 1) ||
1766 p
.x
>= (rect
.pos
.x
+ rect
.size
.width
- 2) ||
1767 p
.y
<= (rect
.pos
.y
+ 1) ||
1768 p
.y
>= (rect
.pos
.y
+ rect
.size
.height
- 2)) {
1771 printf("pointer at screen edge\n");
1773 menu
= wMenuUnderPointer(scr
);
1775 wMenuScroll(menu
, event
);
1782 handleVisibilityNotify(XEvent
*event
)
1786 wwin
= wWindowFor(event
->xvisibility
.window
);
1789 wwin
->flags
.obscured
=
1790 (event
->xvisibility
.state
== VisibilityFullyObscured
);