2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * (c) Copyright 1989, 1990, 1991, 1992, 1993, 1994 OPEN SOFTWARE FOUNDATION, INC.
32 static char rcsid[] = "$XConsortium: WmEvent.c /main/7 1996/11/20 15:27:47 rswiston $"
36 * (c) Copyright 1987, 1988, 1989, 1990, 1993, 1994 HEWLETT-PACKARD COMPANY
37 * (c) Copyright 1993, 1994 International Business Machines Corp.
38 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
39 * (c) Copyright 1993, 1994 Novell, Inc.
48 * include extern functions
52 #include "WmBackdrop.h"
57 #include "WmColormap.h"
58 #include "WmFunction.h"
59 #include "WmKeyFocus.h"
61 #include "WmPanelP.h" /* for typedef in WmManage.h */
67 #include "WmProperty.h"
69 #include "WmWinInfo.h"
70 #include "WmWinState.h"
72 #include "WmResNames.h"
73 #include "WmResParse.h"
78 #include <Xm/RowColumnP.h> /* for MS_LastManagedMenuTime */
79 extern XmMenuState _XmGetMenuState();
83 * FUNCTION PARSER TABLE
88 Context greyedContext;
89 unsigned int resource;
91 WmFunction wmFunction;
92 Boolean (*parseProc)();
102 extern unsigned int buttonModifierMasks[];
104 int smAckState = SM_UNITIALIZED;
105 extern FunctionTableEntry functionTable[];
106 extern int F_NOP_INDEX;
109 #ifndef MOTIF_ONE_DOT_ONE
110 #include <Xm/MenuShellP.h>
115 /*************************************<->*************************************
117 * InitEventHandling ()
122 * This function initializes window manager event handling in preparation
123 * for managing client windows.
130 *************************************<->***********************************/
132 void InitEventHandling (void)
135 XSetWindowAttributes setAttributes;
136 unsigned long base_mask;
141 * Prepare to get root (workspace) window events that are used to
142 * manage client windows. Setup accelerator event processing.
145 base_mask = SubstructureRedirectMask | FocusChangeMask;
147 /* handle entry of root window */
148 base_mask |= EnterWindowMask | LeaveWindowMask;
150 for (scr=0; scr<wmGD.numScreens; scr++)
152 pSD = &(wmGD.Screens[scr]);
156 setAttributes.event_mask = base_mask;
158 if (pSD->buttonBindings)
161 * The desktop menu and button bindings for window
162 * manager functions use button press and button
165 setAttributes.event_mask |=
166 (ButtonPressMask | ButtonReleaseMask);
169 XChangeWindowAttributes (DISPLAY, pSD->rootWindow,
170 CWEventMask, &setAttributes);
174 * Setup event handling for "accelerated" window management
175 * functions done with key bindings.
180 SetupKeyBindings (pSD->keySpecs, pSD->rootWindow,
181 GrabModeSync, F_CONTEXT_ALL);
184 if (pSD->acceleratorMenuCount)
186 for (n = 0; n < pSD->acceleratorMenuCount; n++)
189 pSD->acceleratorMenuSpecs[n]->accelKeySpecs,
190 pSD->rootWindow, GrabModeSync, F_CONTEXT_ALL);
193 } /* end if (managed) */
194 } /* end for (all screens) */
195 } /* END OF FUNCTION InitEventHandling */
198 /*************************************<->*************************************
200 * _WmGrabMasks (modifiers, pnum_masks)
205 * This function returns a set of grab masks to use that effectively
206 * filters out the effects of locking modifiers. Redundant masks
212 * modifiers - keymask of modifiers
216 * *pnum_masks - number of masks returned
220 * pointer to a NULL-terminated list of modifier masks. This memory is
221 * statically allocated and reused. Do no free or modify. Make a copy
222 * if you need to keep it.
224 *************************************<->***********************************/
226 static unsigned int *
227 _WmGrabMasks ( unsigned int modifiers, int *pnum_masks )
229 static unsigned int *pRetMasks = NULL;
230 static int len_ret_masks = 0;
236 /* count the number of masks in the lock sequence */
237 for (num_masks=0; wmGD.pLockMaskSequence[num_masks] != NULL; num_masks++);
239 /* insure we have enough space for our returned masks */
240 if ((pRetMasks == NULL) || (len_ret_masks < num_masks+2))
242 if (pRetMasks != NULL)
243 XtFree ((char *)pRetMasks);
245 len_ret_masks = num_masks+2;
246 pRetMasks = (unsigned int *)
247 XtCalloc (len_ret_masks, sizeof(unsigned int));
250 /* fill up the array of masks we return */
252 for (i=0; i<num_masks; i++)
254 /* combine with this set of locking mods */
255 mask = (modifiers | wmGD.pLockMaskSequence[i]);
257 /* skip if exact match */
258 if (mask == modifiers) continue;
260 /* add this mask to the list if not already there */
261 for (j=0; j<num_ret_masks; j++)
263 if (mask == pRetMasks[j])
266 if (j >= num_ret_masks)
268 /* we don't have this mask yet, add it */
269 pRetMasks[num_ret_masks] = mask;
275 * Add the original mask to the list at the end
277 pRetMasks[num_ret_masks++] = modifiers;
278 pRetMasks[num_ret_masks] = 0; /* terminator */
280 *pnum_masks = num_ret_masks;
286 /*************************************<->*************************************
288 * WmGrabKey (display, keycode, modifiers, grab_window, owner_events,
289 * pointer_mode, keyboard_mode)
294 * This function does several grabs on a key to make sure the
295 * key is grabbed irrespective of the state of locking modifiers
296 * It is a wrapper for XGrabKey, so the parameters are all the
302 * display - X server connection
303 * keycode - keycode to grab
304 * modifiers - keymask of modifiers
305 * grab_window - window to do grab on
306 * owner_events - does app receive events normally?
307 * pointer_mode - pointer event processing during grab
308 * keyboard_mode - keyboard event processing during grab
309 * wmGD.pLockMaskSequence - extra modifier masks to grab with
313 * The function is asynchronous.
315 *************************************<->***********************************/
321 unsigned int modifiers,
328 unsigned int *pGrabMasks;
331 pGrabMasks = _WmGrabMasks (modifiers, &num_masks);
333 for (i=0; i<num_masks; i++, pGrabMasks++)
335 XGrabKey (display, keycode, *pGrabMasks, grab_window,
336 owner_events, pointer_mode, keyboard_mode);
341 /*************************************<->*************************************
343 * WmGrabButton (display, button, modifiers, grab_window, owner_events,
344 * event_mask, pointer_mode, keyboard_mode, confine_to, cursor)
349 * This function does several grabs on a button to make sure the
350 * button is grabbed irrespective of the state of locking modifiers
351 * It is a wrapper for XGrabButton, so the parameters are all the
357 * display - X server connection
358 * button - button to grab
359 * modifiers - keymask of modifiers
360 * grab_window - window to do grab on
361 * event_mask - event mask in effect during grab
362 * owner_events - does app receive events normally?
363 * pointer_mode - pointer event processing during grab
364 * keyboard_mode - keyboard event processing during grab
365 * confine_to - window to confine the pointer to
366 * cursor - cursor to be displayed during grab
367 * wmGD.pLockMaskSequence - extra modifier masks to grab with
371 * The function is asynchronous.
373 *************************************<->***********************************/
379 unsigned int modifiers,
381 unsigned int event_mask,
389 unsigned int *pGrabMasks;
392 pGrabMasks = _WmGrabMasks (modifiers, &num_masks);
394 for (i=0; i<num_masks; i++, pGrabMasks++)
396 XGrabButton (display, button, *pGrabMasks, grab_window, event_mask,
397 owner_events, pointer_mode, keyboard_mode, confine_to,
403 /*************************************<->*************************************
405 * WmUngrabButton (display, button, modifiers, grab_window)
410 * This function is the complement of WmGrabButton. It does several
411 * ungrabs on a button to undo the set of grabs done to ignore
412 * the state of locking modifiers.
414 * It is a wrapper for XUngrabButton, so the parameters are all the
420 * display - X server connection
421 * button - button to grab
422 * modifiers - keymask of modifiers
423 * grab_window - window to do grab on
424 * wmGD.pLockMaskSequence - extra modifier masks to grab with
428 * The function is asynchronous.
430 *************************************<->***********************************/
436 unsigned int modifiers,
440 unsigned int *pGrabMasks;
443 pGrabMasks = _WmGrabMasks (modifiers, &num_masks);
445 for (i=0; i<num_masks; i++, pGrabMasks++)
447 XUngrabButton (display, button, *pGrabMasks, grab_window);
452 /*************************************<->*************************************
454 * SetupKeyBindings (keySpecs, grabWindow, keyboardMode, context)
459 * This function sets up the event handling necessary to support user
460 * specified key bindings for window manager functions.
465 * keySpecs = list of key bindings for window manager functions.
467 * grabWindow = window that is to be associated with the passive key grab.
469 * keyboardMode = indicates keyboard mode for grab.
471 * context = context of key binding to set
476 * RETURN = number of key bindings set
478 *************************************<->***********************************/
480 int SetupKeyBindings (KeySpec *keySpecs, Window grabWindow, int keyboardMode, long context)
488 * Use key grabs to get the keys that invoke window manger functions.
491 iconContext = (context == F_CONTEXT_ICON);
496 if (((keySpec->context == F_CONTEXT_ICON) && iconContext) ||
497 ((keySpec->context != F_CONTEXT_ICON) && !iconContext))
499 if (((F_CONTEXT_ICON == (keySpec->context ^
501 F_SUBCONTEXT_IB_IICON |
502 F_SUBCONTEXT_IB_WICON))) &&
504 ((F_CONTEXT_ICON != (keySpec->context ^
506 F_SUBCONTEXT_IB_IICON |
507 F_SUBCONTEXT_IB_WICON))) &&
511 WmGrabKey (DISPLAY, keySpec->keycode, keySpec->state, grabWindow,
512 False, GrabModeAsync, keyboardMode);
517 keySpec = keySpec->nextKeySpec;
522 } /* END OF FUNCTION SetupKeyBindings */
526 /*************************************<->*************************************
528 * WmDispatchMenuEvent (event)
533 * This function detects and processes events that affect menu behavior that
534 * are NOT dispatched (processed) by the toolkit. The events may cause the
535 * menu to be unposted, may trigger hotspot processing, or may represent
536 * menu accelerators. This processing is generally done when the system
537 * menu is posted in "sticky" mode.
542 * event = This is an X event that has been retrieved by XtNextEvent.
543 * wmGD.menuActive == nonNULL
548 * RETURN = If True the event should be dispatched by the toolkit,
549 * otherwise the event should not be dispatched.
551 *************************************<->***********************************/
553 Boolean WmDispatchMenuEvent (XButtonEvent *event)
555 ClientData *pCD = wmGD.menuClient;
556 Boolean doXtDispatchEvent = True;
557 Boolean checkContext;
559 /* For fixing the bug CR 5227 */
562 MenuButton *menuBtnPtr;
565 if (event->type == KeyPress)
567 if (wmGD.menuActive->accelKeySpecs)
570 * Check to see if the KeyPress is a menu accelerator
571 * (don't require context match for system menu accelerators).
572 * If so, the active menu will be unposted and the KeyPress event
573 * will not be sent on to the toolkit.
576 checkContext = (!pCD || (pCD->systemMenuSpec != wmGD.menuActive));
581 if (pCD->clientState == MINIMIZED_STATE)
583 context = F_CONTEXT_ICON;
585 else if (pCD->clientState == NORMAL_STATE)
587 context = F_CONTEXT_NORMAL;
591 context = F_CONTEXT_MAXIMIZE;
596 context = F_CONTEXT_ROOT;
599 /* Begin fixing CR 5227 */
600 keySpecs = wmGD.menuActive->accelKeySpecs;
601 keyEvent = (XKeyEvent *)event;
602 menuBtnPtr = wmGD.menuActive->menuButtons +
603 (wmGD.menuActive->menuButtonSize - 1);
607 if ((keyEvent->keycode == keySpecs->keycode) &&
608 ((keyEvent->state == keySpecs->state) ||
609 (NOLOCKMOD(keyEvent->state) == keySpecs->state))
610 && ((!checkContext) || (context & keySpecs->context)))
613 XtIsSensitive(menuBtnPtr->buttonWidget);
616 keySpecs = keySpecs->nextKeySpec;
620 doXtDispatchEvent = doXtDispatchEvent &&
621 HandleKeyPress ((XKeyEvent *)event,
622 wmGD.menuActive->accelKeySpecs,
623 checkContext, context,
624 TRUE, (ClientData *)NULL);
627 if (wmGD.menuActive && wmGD.menuUnpostKeySpec)
629 if ((wmGD.menuUnpostKeySpec->keycode == event->button) &&
630 ((wmGD.menuUnpostKeySpec->state == event->state) ||
631 (wmGD.menuUnpostKeySpec->state == NOLOCKMOD(event->state))))
634 * This is an alternate key for unposting a menu from the
635 * keyboard (in addition to [ESC]).
638 UnpostMenu (wmGD.menuActive);
639 doXtDispatchEvent = False;
642 #ifdef ROOT_ICON_MENU
643 if (wmGD.menuActive && wmGD.F_NextKeySpec)
645 if (((wmGD.F_NextKeySpec->state == event->state) ||
646 (wmGD.F_NextKeySpec->state == NOLOCKMOD(event->state))) &&
647 (wmGD.F_NextKeySpec->keycode == event->button))
650 * This is a key spec to traverse to the next window
654 UnpostMenu (wmGD.menuActive);
655 doXtDispatchEvent = False;
658 if (wmGD.menuActive && wmGD.F_PrevKeySpec)
660 if (((wmGD.F_PrevKeySpec->state == event->state) ||
661 (wmGD.F_PrevKeySpec->state == NOLOCKMOD(event->state))) &&
662 (wmGD.F_PrevKeySpec->keycode == event->button))
665 * This is a key spec to traverse to the previous window
669 UnpostMenu (wmGD.menuActive);
670 doXtDispatchEvent = False;
673 #endif /* ROOT_ICON_MENU */
676 else if (wmGD.checkHotspot &&
677 ((event->type == ButtonPress) ||
678 (event->type == ButtonRelease)) &&
679 (event->x_root >= wmGD.hotspotRectangle.x) &&
680 (event->y_root >= wmGD.hotspotRectangle.y) &&
681 (event->x_root < (wmGD.hotspotRectangle.x +
682 (short) wmGD.hotspotRectangle.width)) &&
683 (event->y_root < (wmGD.hotspotRectangle.y +
684 (short) wmGD.hotspotRectangle.height))&&
687 (wmGD.rootButtonClick && wmGD.clickData.clickPending)))
693 * Added check for NULL pCD in the above condition.
694 * We should never get here with a NULL pCD, but,
695 * sometimes our UnmapCallback for a menu does not
696 * get called, so..., we get to this point because
697 * wmGD.menuActive is not cleared, but, wmGD.menuClient
698 * is set to NULL when we unmanage the client window.
702 * The event triggers hotspot processing for the system menu button
706 if (event->type == ButtonRelease)
713 * The system menu is posted from a system menu button or an
714 * icon. By doing a button release over the system menu button
715 * or icon the system menu that is posted is put into keyboard
719 ProcessClickBRelease (event, pCD, wmGD.clickData.context,
720 wmGD.clickData.subContext);
722 if (wmGD.clickData.context == F_SUBCONTEXT_W_SYSTEM)
724 PopGadgetOut (pCD, FRAME_SYSTEM);
726 #ifdef MOTIF_ONE_DOT_ONE
727 TraversalOn (pCD->systemMenuSpec);
728 doXtDispatchEvent = False;
730 _XmGetMenuState(XtParent(pCD->systemMenuSpec->menuWidget))
731 ->MS_LastManagedMenuTime = ((XButtonEvent *)event)->time;
732 doXtDispatchEvent = True;
736 else if ((!wmGD.clickData.pCD) &&
737 (((XButtonEvent *)event)->button == wmGD.clickData.button) &&
738 ((((XButtonEvent *)event)->state ==
739 wmGD.clickData.releaseState) ||
740 (NOLOCKMOD(((XButtonEvent *)event)->state) ==
741 wmGD.clickData.releaseState)))
744 * This is a button release over the root. Check for
745 * root menu click and keep the menu up in a sticky
753 if (((XButtonEvent *)event)->time > wmGD.clickData.time)
756 ((XButtonEvent *)event)->time - wmGD.clickData.time;
761 ~wmGD.clickData.time + ((XButtonEvent *)event)->time + 1;
764 if (timeDiff < wmGD.doubleClickTime)
766 #ifdef MOTIF_ONE_DOT_ONE
767 TraversalOn (wmGD.menuActive);
768 doXtDispatchEvent = False;
770 _XmGetMenuState (XtParent(wmGD.menuActive->menuWidget))
771 ->MS_LastManagedMenuTime =
772 ((XButtonEvent *)event)->time;
773 doXtDispatchEvent = True;
776 wmGD.clickData.clickPending = False;
783 * A button press over a system menu button or an icon when the
784 * system menu is posted indicates that a double-click action is
785 * to be done if appropriate and the menu is to be taken
786 * out of traversal mode (done by the menu widget).
789 ProcessClickBPress (event, pCD, wmGD.clickData.context,
790 wmGD.clickData.subContext);
792 if (wmGD.clickData.subContext == F_SUBCONTEXT_W_SYSTEM)
794 PushGadgetIn (pCD, FRAME_SYSTEM);
797 if (wmGD.clickData.doubleClickContext == F_SUBCONTEXT_W_SYSTEM)
799 if (wmGD.systemButtonClick2 &&
800 (pCD->clientFunctions & MWM_FUNC_CLOSE))
803 * Close the client window. Cancel other system menu
807 UnpostMenu (pCD->systemMenuSpec);
808 F_Kill (NULL, pCD, (XEvent *) event);
809 doXtDispatchEvent = False;
813 if (wmGD.clickData.doubleClickContext == F_SUBCONTEXT_I_ALL)
816 * Normalize the icon.
820 UnpostMenu (pCD->systemMenuSpec);
823 newState = MAXIMIZED_STATE;
827 newState = NORMAL_STATE;
830 SetClientState (pCD, newState, event->time);
831 wmGD.clickData.clickPending = False;
832 wmGD.clickData.doubleClickPending = False;
833 doXtDispatchEvent = False;
836 if ((wmGD.clickData.doubleClickContext == F_SUBCONTEXT_IB_IICON)||
837 (wmGD.clickData.doubleClickContext == F_SUBCONTEXT_IB_WICON))
840 * Raise the Window and Normalize
843 UnpostMenu (pCD->systemMenuSpec);
844 F_Restore_And_Raise ((String)NULL, pCD, (XEvent *)NULL);
845 /* F_Normalize_And_Raise ((String)NULL, pCD, (XEvent *)NULL);
846 */ doXtDispatchEvent = False;
850 * Else no special button press processing; have the toolkit
851 * dispatch the event to the menu widgets.
856 return (doXtDispatchEvent);
859 } /* END OF FUNCTION WmDispatchMenuEvent */
863 /*************************************<->*************************************
865 * WmDispatchWsEvent (event)
870 * This function detects and dispatches events that are reported to the root
871 * (workspace) window and that are not widget-related (i.e. they would not be
872 * dispatched by the Xtk intrinsics).
877 * event = This is an X event that has been retrieved by XtNextEvent.
882 * RETURN = If True the event should be dispatched by the toolkit,
883 * otherwise the event should not be dispatched.
885 *************************************<->***********************************/
887 Boolean WmDispatchWsEvent (XEvent *event)
890 Boolean dispatchEvent = False;
895 * Detect and dispatch non-widget events that have been reported to
904 * The key press is to initiate some window management
905 * function (e.g., shuffle the client windows).
908 dispatchEvent = HandleWsKeyPress ((XKeyEvent *)event);
915 * The button press is to initiate some window management
916 * function (e.g., pop up the desktop menu).
921 dispatchEvent = True; /* have the toolkit dispatch the event */
925 HandleWsButtonPress ((XButtonEvent *)event);
933 * The button release may do some window management
939 dispatchEvent = True; /* have the toolkit dispatch the event */
943 HandleWsButtonRelease ((XButtonEvent *)event);
951 if ( (!XFindContext (DISPLAY, event->xunmap.window,
952 wmGD.windowContextType,
955 && (((XUnmapEvent *)event)->window == pCD->client)
960 * This is a synthetic UnmapNotity used to withdraw a client
961 * window form window manager control.
964 UnManageWindow (pCD);
971 HandleWsEnterNotify ((XEnterWindowEvent *)event);
977 HandleWsLeaveNotify ((XLeaveWindowEvent *)event);
981 case ConfigureRequest:
983 HandleWsConfigureRequest ((XConfigureRequestEvent *)event);
990 * Determine if the window is already being managed:
993 if ((XFindContext (DISPLAY, event->xmaprequest.window,
994 wmGD.windowContextType, (caddr_t *)&pCD)) &&
995 (pSD = GetScreenForWindow (event->xmaprequest.window)))
998 * The window is not yet managed and it's parented to a
999 * screen/root window that we manage. Start to manage the
1000 * new window. Management details are dependent on the
1001 * type of the window. For a typical top-level application
1002 * window reparent the window to a window frame, add it to
1003 * the wm saveset, ...
1006 ManageWindow (pSD, event->xmaprequest.window, MANAGEW_NORMAL);
1009 * The context information on the window WAS found.
1010 * The window is already managed by the window manager
1011 * so this is redundant request to have the client
1020 HandleWsFocusIn ((XFocusInEvent *)event);
1029 } /* end of event.type switch */
1032 return (dispatchEvent);
1034 } /* END OF FUNCTION WmDispatchWsEvent */
1038 /*************************************<->*************************************
1040 * HandleWsKeyPress (keyEvent)
1045 * This function processes KeyPress events that are reported to the root
1046 * window. These events are generally associated with accelerators.
1051 * keyEvent = pointer to a key press event on the root window.
1055 * RETURN = True is the event is to be dispatched by XtDispatch.
1057 *************************************<->***********************************/
1059 Boolean HandleWsKeyPress (XKeyEvent *keyEvent)
1061 Boolean dispatchEvent = False;
1062 Boolean checkKeyEvent = True;
1066 if (wmGD.menuActive)
1069 * The active menu accelerators have been checked and keyEvent was
1070 * not one of them. We will check for pass keys mode and then
1071 * have the toolkit dispatch the event, without searching any other
1072 * key or accelerator specification list.
1075 dispatchEvent = True;
1076 checkKeyEvent = False;
1080 * If pass keys is active then only check for getting out of the
1081 * pass keys mode. Unfreeze the keyboard and replay the key if
1082 * pass keys is active.
1085 if (wmGD.passKeysActive)
1087 if (wmGD.passKeysKeySpec &&
1088 ((wmGD.passKeysKeySpec->state == keyEvent->state) ||
1089 (wmGD.passKeysKeySpec->state == NOLOCKMOD(keyEvent->state))) &&
1090 (wmGD.passKeysKeySpec->keycode == keyEvent->keycode))
1093 * Get out of the pass keys mode.
1096 F_Pass_Key (NULL, (ClientData *) NULL, (XEvent *) NULL);
1097 XAllowEvents (DISPLAY, AsyncKeyboard, CurrentTime);
1101 XAllowEvents (DISPLAY, ReplayKeyboard, CurrentTime);
1103 checkKeyEvent = False;
1108 * Search through the key specification list and the menu
1109 * accelerator lists until these lists are exhausted or
1110 * the event is handled.
1115 if (wmGD.keyboardFocus)
1117 if (wmGD.keyboardFocus->clientState == MINIMIZED_STATE)
1119 context = F_CONTEXT_ICON;
1121 else if (wmGD.keyboardFocus->clientState == NORMAL_STATE)
1123 context = F_CONTEXT_NORMAL;
1127 context = F_CONTEXT_MAXIMIZE;
1132 context = F_CONTEXT_ROOT;
1135 if (HandleKeyPress (keyEvent, ACTIVE_PSD->keySpecs,
1136 TRUE, context, FALSE, (ClientData *)NULL) &&
1137 ACTIVE_PSD->acceleratorMenuCount)
1139 for (n = 0; ((keyEvent->keycode != 0) &&
1140 (n < ACTIVE_PSD->acceleratorMenuCount)); n++)
1142 if (!HandleKeyPress (keyEvent,
1143 ACTIVE_PSD->acceleratorMenuSpecs[n]->accelKeySpecs,
1144 TRUE, context, TRUE,(ClientData *)NULL))
1152 * Fix for CR 3117 - Do the XAllowEvents after calling HandleKeyPress so that
1153 * keys meant for an application can be sent to it.
1155 XAllowEvents (DISPLAY, AsyncKeyboard, CurrentTime);
1157 * End Fix for CR 3117
1161 return (dispatchEvent);
1163 } /* END OF FUNCTION HandleWsKeyPress */
1167 /*************************************<->*************************************
1169 * HandleKeyPress (keyEvent, keySpecs, checkContext, context, onlyFirst, pCD)
1174 * This function identifies window manager functions that are triggered by
1175 * a KeyPress event. The window manager functions are done if appropriate.
1180 * keyEvent = pointer to a key press event on the root window
1181 * keySpecs = pointer to a key specification list to search
1182 * checkContext = TRUE iff the context must match the keySpec context.
1183 * context = context to match keySpec context.
1184 * onlyFirst = TRUE iff key processing should stop with the first match.
1188 * RETURN = False if key binding processing should be terminated; True if
1189 * key binding processing can continue
1191 *************************************<->***********************************/
1193 Boolean HandleKeyPress (XKeyEvent *keyEvent,
1195 Boolean checkContext,
1200 Boolean processKey = True;
1201 ClientData *functionClient;
1202 Boolean haveRootBinding = False;
1203 Boolean haveWindowBinding = False;
1206 * Search for matching key specification.
1209 while (processKey && keySpecs)
1211 if (((keyEvent->state == keySpecs->state) ||
1212 (NOLOCKMOD(keyEvent->state) == keySpecs->state)) &&
1213 (keyEvent->keycode == keySpecs->keycode))
1215 if ((!checkContext) || (context & keySpecs->context))
1218 * A matching key binding has been found.
1219 * Determine the client to which the key binding function is to
1221 * Unpost any active menu and specify that no futher key binding
1222 * processing should be done.
1223 * Do the function associated with the matching key binding.
1224 * Stop if onlyFirst == TRUE
1229 functionClient = pCD;
1233 functionClient = wmGD.keyboardFocus;
1236 if (wmGD.menuActive)
1238 functionClient = wmGD.menuClient; /* might not have focus! */
1239 UnpostMenu (wmGD.menuActive);
1247 if ((keySpecs->wmFunction == F_Menu) ||
1248 #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL))
1249 (keySpecs->wmFunction == F_Post_RMenu) ||
1250 #endif /* !defined(WSM) || defined(MWM_QATS_PROTOCOL) */
1251 (keySpecs->wmFunction == F_Post_SMenu))
1253 wmGD.menuUnpostKeySpec = keySpecs; /* menu unpost key spec */
1255 else if (keySpecs->wmFunction == F_Pass_Key)
1257 wmGD.passKeysKeySpec = keySpecs;
1259 #ifdef ROOT_ICON_MENU
1260 else if (keySpecs->wmFunction == F_Next_Key)
1262 wmGD.F_NextKeySpec = keySpecs;
1264 else if (keySpecs->wmFunction == F_Prev_Key)
1266 wmGD.F_PrevKeySpec = keySpecs;
1268 #endif /* ROOT_ICON_MENU */
1269 if (!(keySpecs->wmFunction (keySpecs->wmFuncArgs,
1270 functionClient, keyEvent)))
1273 * The window manager function return indicates that further
1274 * key binding processing should not be done.
1280 * Note that for key bindings, frame, title, border, and app contexts
1281 * are equivalent to the window context. This is NOT the same as for
1284 if ((context & (F_CONTEXT_WINDOW)))
1285 haveWindowBinding = True;
1287 /* Fix for 3117 -- If the keypress looks as if it had been intended
1288 * for the application, send it back.
1291 else if ((context & (F_CONTEXT_WINDOW)) &&
1292 (keySpecs->context & F_CONTEXT_ROOT))
1294 haveRootBinding = True;
1297 keySpecs = keySpecs->nextKeySpec;
1301 if (haveRootBinding && (!haveWindowBinding) )
1303 XAllowEvents (DISPLAY, ReplayKeyboard, CurrentTime);
1306 return (processKey);
1309 } /* END OF FUNCTION HandleKeyPress */
1313 /*************************************<->*************************************
1315 * HandleWsButtonPress (buttonEvent)
1320 * This function identifies button events that are associated with window
1321 * manager functions. Window manager functions are done if appropriate.
1326 * buttonEvent = pointer to a button press event on the root window
1328 *************************************<->***********************************/
1330 void HandleWsButtonPress (XButtonEvent *buttonEvent)
1339 * Determine if the top-level window that contains the pointer is a
1340 * client managed by the window manager (there may be no window under
1341 * the pointer or it may be an "override-redirect" window).
1344 if ((buttonEvent->subwindow == None) ||
1345 (XFindContext (DISPLAY, buttonEvent->subwindow, wmGD.windowContextType,
1348 /* no managed window under the pointer */
1354 * Look through the window manager function button binding list for
1355 * matches with the event:
1358 IdentifyEventContext (buttonEvent, pCD, &context, &partContext);
1359 subContext = (1L << partContext);
1361 ProcessClickBPress (buttonEvent, pCD, context, subContext);
1363 if (CheckForButtonAction (buttonEvent, context, subContext, pCD) && pCD)
1366 * Button bindings have been processed, now check for bindings that
1367 * are associated with the built-in semantics of the window frame
1371 CheckButtonPressBuiltin (buttonEvent, context, subContext, partContext,
1375 * Else skip built-in processing due to execution of a function that
1376 * does on-going event processing or that has changed the client state
1377 * (e.g., f.move or f.minimize).
1381 } /* END OF FUNCTION HandleWsButtonPress */
1385 /*************************************<->*************************************
1387 * HandleWsButtonRelease (buttonEvent)
1392 * This function identifies button release events that are associated with
1393 * window manager functions. Window manager functions are done if
1399 * buttonEvent = pointer to a button release event
1401 *************************************<->***********************************/
1403 void HandleWsButtonRelease (XButtonEvent *buttonEvent)
1412 * Determine if the top-level window that contains the pointer is a
1413 * client managed by the window manager (there may be no window under
1414 * the pointer or it may be an "override-redirect" window).
1417 if ((buttonEvent->subwindow == None) ||
1418 (XFindContext (DISPLAY, buttonEvent->subwindow, wmGD.windowContextType,
1421 /* no managed window under the pointer */
1427 * Look for a builtin function that may be done by this event.
1430 IdentifyEventContext (buttonEvent, pCD, &context, &partContext);
1431 subContext = (1L << partContext);
1433 ProcessClickBRelease (buttonEvent, pCD, context, subContext);
1435 if (CheckForButtonAction (buttonEvent, context, subContext, pCD) && pCD)
1438 * Button bindings have been processed, now check for bindings that
1439 * are associated with the built-in semantics of the window frame
1443 CheckButtonReleaseBuiltin (buttonEvent, context, subContext, pCD);
1446 * Else skip built-in processing due to execution of a function that
1447 * does on-going event processing or that has changed the client state
1448 * (e.g., f.move or f.minimize).
1452 } /* END OF FUNCTION HandleWsButtonRelease */
1456 /*************************************<->*************************************
1458 * CheckForButtonAction (buttonEvent, context, subContext, pCD)
1463 * This function checks to see if a button event is to do a button binding
1464 * action. The action is done if specified.
1469 * buttonEvent = a button event handled by the window manager
1471 * context = button event context (root, icon, window)
1473 * subContext = button event subContext (title, system button, etc.)
1475 * pCD = a pointer to client data that is associated with the button event
1480 * RETURN = If True then further button binding processing can be done;
1481 * if false then a state change function, menu function, or
1482 * configuration function is ongoing and further button binding
1483 * processing should not be done.
1486 *************************************<->***********************************/
1488 Boolean CheckForButtonAction (XButtonEvent *buttonEvent, Context context, Context subContext, ClientData *pCD)
1490 ButtonSpec *buttonSpec;
1493 * Look through the window manager function button binding list for
1494 * matches with the event:
1497 buttonSpec = ACTIVE_PSD->buttonSpecs;
1500 if ((buttonEvent->button == buttonSpec->button) &&
1501 ((buttonEvent->state == buttonSpec->state) ||
1502 (NOLOCKMOD(buttonEvent->state) == buttonSpec->state)))
1505 * See if the event context matches the binding context.
1508 if ((buttonEvent->type == buttonSpec->eventType) &&
1509 (context & buttonSpec->context) &&
1510 (subContext & buttonSpec->subContext))
1514 * For click type bindings check for a match between the
1515 * event context and the click / double-click context.
1518 if (buttonEvent->type == ButtonRelease)
1521 * Clicks occur on button releases. A button release
1522 * binding is always treated as a click binding.
1525 if ((buttonSpec->subContext | wmGD.clickData.clickContext)
1526 != buttonSpec->subContext)
1528 /* click binding and event contexts do not match */
1529 buttonSpec = buttonSpec->nextButtonSpec;
1532 /* else there is a click match */
1534 else if (buttonSpec->click && (buttonEvent->type==ButtonPress))
1537 * Double-clicks occur on button presses.
1540 if ((buttonSpec->subContext |
1541 wmGD.clickData.doubleClickContext)
1542 != buttonSpec->subContext)
1544 /* click binding and event contexts do not match */
1545 buttonSpec = buttonSpec->nextButtonSpec;
1551 * The is a double-click match. Don't do any click
1552 * or double-click matches for the following button
1553 * press and release.
1556 wmGD.clickData.clickPending = False;
1557 wmGD.clickData.doubleClickPending = False;
1561 if (!(buttonSpec->wmFunction (buttonSpec->wmFuncArgs, pCD,
1565 * The window manager function return indicates that
1566 * further button binding processing should not be done.
1573 buttonSpec = buttonSpec->nextButtonSpec;
1579 } /* END OF FUNCTION CheckForButtonAction */
1583 /*************************************<->*************************************
1585 * IdentifyEventContext (event, pCD, pContext, pPartContext)
1590 * This function identifies the context in which an event occured. The
1591 * pointer position is used to identify the context if the event is a
1592 * button event. If the context and the window state are incompatible
1593 * (e.g., the context is window and the window is minimized) then the
1594 * context is reset to 0 (none).
1599 * event = find the context of this X event
1601 * pCD = client data (maybe NULL) that the event is associated with
1606 * pContext = event context
1608 * pPartContext = part (e.g, frame) context associated with the event
1610 *************************************<->***********************************/
1612 void IdentifyEventContext (XButtonEvent *event, ClientData *pCD, Context *pContext, int *pPartContext)
1614 Boolean eventOnRoot;
1615 Window actionWindow;
1621 eventOnRoot = (event->window == ACTIVE_ROOT) ?
1626 actionWindow = (eventOnRoot) ? event->subwindow : event->window;
1627 if (actionWindow == pCD->clientFrameWin)
1629 *pContext = F_CONTEXT_WINDOW;
1633 clientX = event->x -
1634 (pCD->maxConfig ? pCD->maxX : pCD->clientX) +
1635 pCD->clientOffset.x;
1636 clientY = event->y -
1637 (pCD->maxConfig ? pCD->maxY : pCD->clientY) +
1638 pCD->clientOffset.y;
1645 framePart = IdentifyFramePart (pCD, clientX, clientY);
1646 *pPartContext = framePart;
1648 else if (actionWindow == pCD->clientBaseWin)
1650 *pContext = F_CONTEXT_WINDOW;
1651 *pPartContext = FRAME_CLIENT;
1653 else if ((actionWindow == ICON_FRAME_WIN(pCD)) ||
1654 (actionWindow == ACTIVE_PSD->activeIconTextWin))
1656 if (P_ICON_BOX(pCD))
1658 *pContext = F_CONTEXT_ICONBOX;
1659 if (pCD->clientState == MINIMIZED_STATE)
1661 *pPartContext = ICONBOX_PART_IICON;
1665 *pPartContext = ICONBOX_PART_WICON;
1670 *pContext = F_CONTEXT_ICON;
1671 *pPartContext = ICON_PART_ALL;
1676 *pContext = F_CONTEXT_ROOT;
1677 *pPartContext = ROOT_PART_ALL;
1681 * Check for an incompatible context and window state.
1684 if (((*pContext & F_CONTEXT_WINDOW) &&
1685 (pCD->clientState != NORMAL_STATE) &&
1686 (pCD->clientState != MAXIMIZED_STATE)) ||
1687 ((*pContext & F_CONTEXT_ICON) &&
1688 (pCD->clientState != MINIMIZED_STATE)))
1690 *pContext = F_CONTEXT_NONE;
1695 *pContext = F_CONTEXT_ROOT;
1696 *pPartContext = ROOT_PART_ALL;
1700 } /* END OF FUNCTION IdentifyEventContext */
1704 /*************************************<->*************************************
1706 * ProcessClickBPress (buttonEvent, pCD, context, subContext)
1711 * This function checks for a double-click match and saves state information
1712 * to do click and double-click processing.
1717 * buttonEvent = pointer to a button press event
1719 * pCD = pointer to client data (identifies client window)
1721 * context = root/window/icon context for the event
1723 * subContext = subcontext for the event (title, system button, etc.)
1728 * (wmGD.clickData) = click processing information
1730 * (wmGD.clickData.doubleClickContext) = set if double click occured
1732 *************************************<->***********************************/
1734 void ProcessClickBPress (XButtonEvent *buttonEvent, ClientData *pCD, Context context, Context subContext)
1741 * Check for a double-click. If a double click has occurred then
1742 * save the double-click context.
1745 wmGD.clickData.doubleClickContext = F_SUBCONTEXT_NONE;
1746 if (wmGD.clickData.doubleClickPending &&
1747 (buttonEvent->button == wmGD.clickData.button) &&
1748 ((buttonEvent->state == wmGD.clickData.state) ||
1749 (NOLOCKMOD(buttonEvent->state) == wmGD.clickData.state)) &&
1750 (pCD == wmGD.clickData.pCD) &&
1751 (context == wmGD.clickData.context))
1754 * Check the time between button release events.
1757 if (buttonEvent->time > wmGD.clickData.time)
1759 timeDiff = buttonEvent->time - wmGD.clickData.time;
1763 timeDiff = ~wmGD.clickData.time + buttonEvent->time + 1;
1766 if (timeDiff < wmGD.doubleClickTime)
1769 * A double-click has been done; save the context.
1772 wmGD.clickData.doubleClickContext = subContext |
1773 wmGD.clickData.subContext;
1779 * Save state data for click checking. If a button binding match
1780 * occurs for a double-click then clear out the clickData (don't
1781 * do any click/double-click matches for the following button press
1782 * and release). If the button press is done on the client area and
1783 * is used to set the focus to the window then don't use it in
1784 * setting up clickData.
1787 if ((buttonEvent->button == SELECT_BUTTON) &&
1788 ((buttonEvent->state == 0) ||
1789 (NOLOCKMOD(buttonEvent->state) == 0)))
1791 passButton = wmGD.passSelectButton;
1795 passButton = wmGD.passButtons;
1798 if (!(pCD && (buttonEvent->window == pCD->clientBaseWin) && passButton))
1800 wmGD.clickData.button = buttonEvent->button;
1801 wmGD.clickData.state = buttonEvent->state;
1802 /* add in event button mask (this will show up in the button release */
1803 wmGD.clickData.releaseState = buttonEvent->state |
1804 buttonModifierMasks[buttonEvent->button];
1805 wmGD.clickData.pCD = pCD;
1806 wmGD.clickData.context = context;
1807 wmGD.clickData.subContext = subContext;
1808 wmGD.clickData.time = buttonEvent->time;
1809 wmGD.clickData.clickPending = True;
1810 wmGD.clickData.doubleClickPending = True;
1812 wmGD.clickData.bReplayed = wmGD.bReplayedButton;
1817 } /* END OF FUNCTION ProcessClickBPress */
1821 /*************************************<->*************************************
1823 * ProcessClickBRelease (buttonEvent, pCD, context, subContext)
1828 * This function checks to see if a "click" was done. The button release
1829 * completes a click if there is a click pending and the button release
1830 * context is the same as the button press context. Configuration or
1831 * menu activity cancels a pending click.
1836 * buttonEvent = pointer to a button press event
1838 * pCD = pointer to client data (identifies client window)
1840 * context = root/window/icon context for the event
1842 * subContext = window subcontext for the event (title, system button, etc.)
1844 * (wmGD.clickData) = click processing information
1849 * (wmGD.clickData) = click processing information
1851 * (wmGD.clickData.clickContext) = set if click occured
1853 *************************************<->***********************************/
1855 void ProcessClickBRelease (XButtonEvent *buttonEvent, ClientData *pCD, Context context, Context subContext)
1859 * Restore the state of the last "depressed" frame gadget
1862 if (pCD && (wmGD.gadgetClient == pCD) && (pCD->decorFlags))
1864 PopGadgetOut(pCD, wmGD.gadgetDepressed);
1869 * Check to see if a click has been done.
1872 wmGD.clickData.clickContext = F_SUBCONTEXT_NONE;
1873 if (wmGD.clickData.clickPending &&
1874 (buttonEvent->button == wmGD.clickData.button) &&
1875 (buttonEvent->state == wmGD.clickData.releaseState) &&
1876 (pCD == wmGD.clickData.pCD) &&
1877 (context == wmGD.clickData.context))
1879 wmGD.clickData.clickContext = subContext | wmGD.clickData.subContext;
1880 /* !!! check for double click time? !!! */
1884 wmGD.clickData.doubleClickPending = False;
1887 wmGD.clickData.clickPending = False;
1890 } /* END OF FUNCTION ProcessClickBRelease */
1895 /*************************************<->*************************************
1897 * HandleDtWmClientMessage (clientEvent)
1902 * This function handles client message events that are sent to the
1903 * wm window. The window manager action that is taken depends on the
1904 * message_type of the event.
1909 * clientEvent = pointer to a client message event on the wm window
1911 *************************************<->***********************************/
1913 void HandleDtWmClientMessage (XClientMessageEvent *clientEvent)
1917 * Process the client message event based on the message_type.
1920 if (clientEvent->message_type == wmGD.xa_DT_SM_WM_PROTOCOL)
1922 if (clientEvent->data.l[0] == wmGD.xa_DT_SM_START_ACK_WINDOWS)
1924 smAckState = SM_START_ACK;
1926 else if (clientEvent->data.l[0] == wmGD.xa_DT_SM_STOP_ACK_WINDOWS)
1928 smAckState = SM_STOP_ACK;
1932 if (clientEvent->message_type == wmGD.xa_WM_PROTOCOLS)
1934 if (clientEvent->data.l[0] == wmGD.xa_WM_SAVE_YOURSELF)
1936 for (scr = 0; scr < wmGD.numScreens; scr++)
1938 if (wmGD.Screens[scr].managed)
1941 * Write out current workspace, frontpanel
1942 * position and iconbox position and size.
1944 SaveResources(&wmGD.Screens[scr]);
1947 XSetCommand(DISPLAY, wmGD.commandWindow, 0, 0);
1949 } /* WM_SAVE_YOURSELF */
1950 } /* WM_PROTOCOLS */
1951 } /* END OF FUNCTION HandleDtWmClientMessage */
1954 /*************************************<->*************************************
1956 * HandleDtWmRequest (pSD, pev)
1961 * This function processes _DT_WM_REQUESTs that come in from
1967 * pSD - pointer to screen data
1968 * pev - pointer to the triggering event (PropertyNotify)
1972 * This reuses the global parse buffer. It assumes that no parsing
1973 * is in progress. All parsing of the config file must be completed
1974 * before we call this routine.
1977 *************************************<->***********************************/
1980 HandleDtWmRequest (WmScreenData *pSD, XEvent *pev)
1982 Boolean more = True;
1983 char *pchReq = NULL;
1984 String sRequest = NULL;
1985 unsigned char *lineP;
1987 WmFunction wmFunction;
1990 Context ctxDisallowed;
1994 * Save state of global parse buffer
1996 memcpy (&wmPB, wmGD.pWmPB, sizeof(DtWmpParseBuf));
2000 GetDtWmRequest (pSD, &pchReq, &more);
2005 ctxDisallowed = F_CONTEXT_ROOT;
2006 if (wmGD.requestContextWin != (Window) 0L)
2008 if (!XFindContext (DISPLAY, wmGD.requestContextWin,
2009 wmGD.windowContextType,
2013 * A valid client window was specified
2014 * in a previous F_Set_Context request.
2015 * Remove the restriction to root-only context.
2017 ctxDisallowed = F_CONTEXT_NONE;
2020 sRequest = XtNewString (pchReq);
2021 _DtWmParseSetLine (wmGD.pWmPB, (unsigned char *)sRequest);
2022 lineP = wmGD.pWmPB->pchLine;
2023 iFuncIndex = ParseWmFunction (&lineP, CRS_BUTTON|CRS_KEY,
2026 if (iFuncIndex != F_NOP_INDEX)
2028 if (functionTable[iFuncIndex].greyedContext & ctxDisallowed)
2031 * Sorry, we have to disallow this function request
2032 * based on context problems.
2034 XtFree ((char *)sRequest);
2040 * Apply the function argument parser.
2042 if ((*(functionTable [iFuncIndex].parseProc))
2043 (&lineP, wmFunction, &wmFuncArgs))
2046 * Found it in the function table!
2047 * Apply the function.
2049 wmFunction (wmFuncArgs, pCD, NULL);
2052 * Free up allocated args, if any
2056 if ((functionTable[iFuncIndex].parseProc ==
2057 ParseWmFuncStrArg) ||
2058 (functionTable[iFuncIndex].parseProc ==
2059 ParseWmFuncMaybeStrArg))
2061 XtFree ((char *)wmFuncArgs);
2063 else if ((functionTable[iFuncIndex].parseProc ==
2064 ParseWmFuncActionArg))
2066 WmActionArg *pAP = (WmActionArg *) wmFuncArgs;
2068 if (pAP->actionName)
2069 XtFree ((char *) pAP->actionName);
2070 if (pAP->szExecParms)
2071 XtFree ((char *) pAP->szExecParms);
2072 while (pAP->numArgs > 0)
2075 pAP->aap[--(pAP->numArgs)].u.file.name);
2077 XtFree ((char *) pAP);
2082 else if (!strncmp (pchReq, DTWM_REQ_CHANGE_BACKDROP,
2083 strlen(DTWM_REQ_CHANGE_BACKDROP)))
2085 Pixmap pixmap = None;
2087 char *pchFile = NULL;
2089 /* skip function name */
2091 (void) strtok (pch, " ");
2094 pch = strtok (NULL, " ");
2097 pchFile = (char *) XtMalloc (1+strlen(pch));
2101 Warning (((char *)GETMESSAGE(32, 3, "Missing path name for backdrop change request.")));
2106 strcpy (pchFile, pch);
2109 pch = strtok (NULL, " ");
2112 sscanf (pch, "%lx", &pixmap);
2113 SetNewBackdrop (ACTIVE_WS, pixmap, (String)pchFile);
2117 Warning (((char *)GETMESSAGE(32, 4, "Missing pixmap id for backdrop change request.")));
2123 Warning (((char *)GETMESSAGE(32, 2, "Insufficient memory to handle backdrop change.")));
2128 XtFree ((char *) sRequest);
2135 * Restore state of global parse buffer
2137 memcpy (wmGD.pWmPB, &wmPB, sizeof(DtWmpParseBuf));
2139 } /* END OF FUNCTION HandleDtWmRequest */
2145 /*************************************<->*************************************
2147 * HandleWsEnterNotify (enterEvent)
2152 * This function processes EnterNotify events that are reported to
2158 * enterEvent = pointer to an enter notify event on the root window.
2160 *************************************<->***********************************/
2162 void HandleWsEnterNotify (XEnterWindowEvent *enterEvent)
2167 * If the pointer entered a screen that we manage, then set the
2168 * new active screen.
2170 if (wmGD.queryScreen &&
2171 (!XFindContext (DISPLAY, enterEvent->window, wmGD.screenContextType,
2174 SetActiveScreen (pSD);
2178 * The root window was entered; do focus processing
2183 if (!wmGD.menuActive &&
2184 ((enterEvent->mode == NotifyNormal) ||
2185 (enterEvent->mode == NotifyUngrab) ||
2186 (enterEvent->mode == NotifyWhileGrabbed)))
2188 if (wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_POINTER)
2190 Do_Focus_Key ((ClientData *) NULL, enterEvent->time,
2193 else if ((wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_EXPLICIT) &&
2194 ((enterEvent->detail == NotifyNonlinearVirtual) ||
2195 (enterEvent->detail == NotifyNonlinear)) &&
2196 (wmGD.keyboardFocus == NULL) &&
2200 * Reset the explicit selection focus to the workspace
2204 Do_Focus_Key ((ClientData *) NULL, enterEvent->time,
2208 if (wmGD.colormapFocusPolicy == CMAP_FOCUS_POINTER)
2210 SetColormapFocus (ACTIVE_PSD, (ClientData *) NULL);
2214 } /* END OF FUNCTION HandleWsEnterNotify */
2218 /*************************************<->*************************************
2220 * HandleWsLeaveNotify (leaveEvent)
2225 * This function processes LeaveNotify events that are reported to
2231 * enterEvent = pointer to an leave notify event on the root window.
2233 *************************************<->***********************************/
2235 void HandleWsLeaveNotify (XLeaveWindowEvent *leaveEvent)
2240 * The root window was exited; do focus processing
2244 if (!wmGD.menuActive &&
2245 ((leaveEvent->detail == NotifyNonlinear) ||
2246 (leaveEvent->detail == NotifyNonlinearVirtual)))
2249 * The pointer has moved to another screen. Fix the
2250 * focus on the screen controlled by the window manager.
2253 if ((wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_POINTER) ||
2254 (wmGD.colormapFocusPolicy == CMAP_FOCUS_POINTER))
2256 if (wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_POINTER)
2258 Do_Focus_Key ((ClientData *) NULL, leaveEvent->time,
2259 (SCREEN_SWITCH_FOCUS | ALWAYS_SET_FOCUS));
2261 if (wmGD.colormapFocusPolicy == CMAP_FOCUS_POINTER)
2263 SetColormapFocus (ACTIVE_PSD, (ClientData *) NULL);
2267 /* Set new active screen */
2269 if (!XFindContext (DISPLAY, leaveEvent->root, wmGD.screenContextType,
2272 /* moved to another screen we manage! */
2273 SetActiveScreen (pSD);
2277 /* off onto an unmanaged screen */
2278 wmGD.queryScreen = True;
2280 /* set input focus to pointer root */
2281 XSetInputFocus (DISPLAY, PointerRoot,
2282 RevertToPointerRoot, leaveEvent->time);
2285 } /* END OF FUNCTION HandleWsLeaveNotify */
2289 /*************************************<->*************************************
2291 * HandleWsConfigureRequest (focusEvent)
2296 * This function processes ConfigureRequest events that are reported to
2302 * focusEvent = pointer to a configure request event on the root window.
2304 *************************************<->***********************************/
2306 void HandleWsConfigureRequest (XConfigureRequestEvent *configureEvent)
2309 XConfigureEvent notifyEvent;
2310 Boolean configChanged;
2311 XWindowChanges values;
2315 * A window that is a child of the root window is being
2316 * configured. Either it is an un-managed window or it is a
2317 * managed window that did the configuration before it was
2321 if (XFindContext (DISPLAY, configureEvent->window, wmGD.windowContextType,
2325 * Get window attribute information; this is used later on
2326 * to decide if a synthetic ConfigureNotify event should
2327 * be send to the client.
2330 if (WmGetWindowAttributes (configureEvent->window))
2333 (wmGD.windowAttributes.x != configureEvent->x) ||
2334 (wmGD.windowAttributes.y != configureEvent->y) ||
2335 (wmGD.windowAttributes.width != configureEvent->width) ||
2336 (wmGD.windowAttributes.height != configureEvent->height) ||
2337 (wmGD.windowAttributes.border_width !=
2338 configureEvent->border_width) ||
2339 (configureEvent->value_mask & (CWSibling|CWStackMode));
2342 * The window is not (yet) managed. Do the window
2348 values.x = configureEvent->x;
2349 values.y = configureEvent->y;
2350 values.width = configureEvent->width;
2351 values.height = configureEvent->height;
2352 values.border_width = configureEvent->border_width;
2353 values.sibling = configureEvent->above;
2354 values.stack_mode = configureEvent->detail;
2355 XConfigureWindow (DISPLAY, configureEvent->window,
2356 (unsigned int) (configureEvent->value_mask), &values);
2360 * Some clients expect a ConfigureNotify event even if the
2361 * XConfigureWindow call has NO effect. Send a synthetic
2362 * ConfigureNotify event just to be sure.
2367 notifyEvent.type = ConfigureNotify;
2368 notifyEvent.display = DISPLAY;
2369 notifyEvent.event = configureEvent->window;
2370 notifyEvent.window = configureEvent->window;
2371 notifyEvent.x = configureEvent->x;
2372 notifyEvent.y = configureEvent->y;
2373 notifyEvent.width = configureEvent->width;
2374 notifyEvent.height = configureEvent->height;
2375 notifyEvent.border_width = configureEvent->border_width;
2376 notifyEvent.above = None;
2377 notifyEvent.override_redirect = False;
2379 XSendEvent (DISPLAY, configureEvent->window, False,
2380 StructureNotifyMask, (XEvent *)¬ifyEvent);
2387 * The context information on the window WAS found.
2388 * The window is already managed by the window manager
2389 * so this is a configuration request that was made before
2390 * the window was reparented.
2393 HandleCConfigureRequest (pCD, configureEvent);
2396 } /* END OF FUNCTION HandleWsConfigureRequest */
2400 /*************************************<->*************************************
2402 * HandleWsFocusIn (focusEvent)
2407 * This function processes FocusIn events that are reported to the root
2413 * focusEvent = pointer to a focus in event on the root window.
2415 *************************************<->***********************************/
2417 void HandleWsFocusIn (XFocusInEvent *focusEvent)
2423 * This code is used to handle the case of the focus being
2424 * set to pointer root (either explicitly by some client, by the window
2425 * manager or as a result of a "revert to" action).
2426 * It also handles the case where the focus is manipulated by a window
2427 * manager on another screen (in this case let the other window manager
2428 * control the focus). Reset the focus to a client window if appropriate.
2431 if (((focusEvent->mode == NotifyNormal) ||
2432 (focusEvent->mode == NotifyUngrab)) &&
2433 ((focusEvent->detail == NotifyPointerRoot) ||
2434 (focusEvent->detail == NotifyDetailNone) ||
2435 (focusEvent->detail == NotifyInferior)))
2438 * Fix the keyboard focus if it should be set to a particular client.
2441 pCD = GetClientUnderPointer (&sameScreen);
2442 if (wmGD.keyboardFocus && (focusEvent->detail != NotifyInferior))
2447 * Assume that the focus still belongs to the screen
2448 * controlled by mwm. Repair the focus if the client
2452 if (wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_EXPLICIT)
2454 Do_Focus_Key (wmGD.keyboardFocus, GetTimestamp (),
2459 if (pCD || (focusEvent->detail == NotifyDetailNone))
2461 /* !!! check for redundant focus setting !!! */
2462 Do_Focus_Key (pCD, GetTimestamp (), ALWAYS_SET_FOCUS);
2465 SetKeyboardFocus ((ClientData *) NULL, REFRESH_LAST_FOCUS);
2470 * Assume that the focus is now controlled by a
2471 * window manager on another screen. Clear the
2475 SetKeyboardFocus ((ClientData *) NULL, REFRESH_LAST_FOCUS);
2481 * No client window currently has the focus. If the pointer
2482 * is on the mwm-controlled screen set the focus to
2483 * the window management window if the focus is explicit.
2488 if (wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_EXPLICIT)
2490 if (((focusEvent->detail == NotifyInferior) ||
2491 (focusEvent->detail == NotifyPointerRoot)) &&
2492 (wmGD.keyboardFocus != wmGD.nextKeyboardFocus))
2495 * Window that had the focus went away. Try to
2496 * reset the window to the next keyboard focus
2497 * client window if there is one.
2500 Do_Focus_Key (wmGD.nextKeyboardFocus, GetTimestamp (),
2506 /* The previous version would pass NULL widget to this */
2507 /* this routine. This doesn't seem to make sense. NULL */
2508 /* has been replaced by pCD which seems to fix the icon */
2509 /* focus problem. */
2510 /* Another related patch is made in WmCEvent.c. */
2511 Do_Focus_Key ((ClientData *) pCD, GetTimestamp(),
2515 else /*KEYBOARD_FOCUS_POINTER*/
2517 if (pCD || focusEvent->detail != NotifyPointerRoot)
2519 Do_Focus_Key (pCD, GetTimestamp (), ALWAYS_SET_FOCUS);
2526 } /* END OF FUNCTION HandleWsFocusIn */
2530 /*************************************<->*************************************
2537 * This function is used to provide a timestamp for use with X calls that
2538 * require a timestamp (and a timestamp is not available from a prior
2544 * Return = a timestamp value
2548 * This costs a server round-trip
2550 *************************************<->***********************************/
2552 Time GetTimestamp (void)
2555 WmScreenData *pSD = ACTIVE_PSD;
2560 * Do zero-length append to our own WM_STATE
2562 XChangeProperty (DISPLAY, pSD->wmWorkspaceWin, wmGD.xa_WM_STATE,
2563 wmGD.xa_WM_STATE, 32, PropModeAppend,
2564 (unsigned char *)&property, 0);
2567 * Pick up the property notify event
2569 XSync (DISPLAY, False);
2570 if (XCheckWindowEvent (DISPLAY, pSD->wmWorkspaceWin,
2571 PropertyChangeMask, &event))
2573 if (event.type == PropertyNotify)
2575 timestamp = event.xproperty.time;
2579 /* not sure what happened here ... use CurrentTime */
2580 timestamp = CurrentTime;
2582 if ((event.type != PropertyNotify) ||
2583 (event.xproperty.atom != wmGD.xa_WM_STATE))
2586 * This wasn't the event we caused, put it back for
2587 * later processing. We'll keep the timestamp, though.
2589 XPutBackEvent (DISPLAY, &event);
2594 /* Hmm... didn't get the prop notify, fall back to current time */
2595 timestamp = CurrentTime;
2600 } /* END OF FUNCTION GetTimestamp */
2602 #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL))
2603 /*************************************<->*************************************
2610 * This function is used to provide a timestamp for use with X calls that
2611 * require a timestamp. It returns the last timestamp processed if one
2612 * exists or it generates a new one.
2621 * Return = a timestamp value - NOT CurrentTime
2623 *************************************<->***********************************/
2629 if (! (evTime = XtLastTimestampProcessed(DISPLAY)) )
2630 evTime = GetTimestamp();
2634 #endif /* !defined(WSM) || defined(MWM_QATS_PROTOCOL) */
2637 /*************************************<->*************************************
2639 * PullExposureEvents ()
2644 * Pull in and process all outstanding exposure events
2655 * Useful for cleaning up display after menu popdown
2657 *************************************<->***********************************/
2658 void PullExposureEvents (void)
2661 Boolean dispatchEvent;
2664 * Force the exposure events into the queue
2666 XSync (DISPLAY, False);
2668 XSync (DISPLAY1, False);
2671 * Selectively extract the exposure events
2674 while (XCheckMaskEvent (DISPLAY,
2675 ExposureMask|VisibilityChangeMask, &event) ||
2676 XCheckMaskEvent (DISPLAY1,
2677 ExposureMask|VisibilityChangeMask, &event))
2679 while (XCheckMaskEvent (DISPLAY, ExposureMask, &event))
2683 * Check for, and process non-widget events. The events may be
2684 * reported to the root window, to some client frame window,
2685 * to an icon window, or to a "special" window management window.
2693 if (event.xany.window == ACTIVE_ROOT)
2695 dispatchEvent = WmDispatchWsEvent (&event);
2699 dispatchEvent = WmDispatchClientEvent (&event);
2703 dispatchEvent = True;
2710 * Dispatch widget related event:
2713 XtDispatchEvent (&event);
2717 } /* END OF FUNCTION PullExposureEvents */
2721 /*************************************<->*************************************
2723 * ReplayedButtonEvent ()
2728 * Compare to button events to see if it's one event that's been
2737 * return = True if event is replayed.
2742 *************************************<->***********************************/
2744 ReplayedButtonEvent (
2745 XButtonEvent *pevB1,
2746 XButtonEvent *pevB2)
2748 Boolean rval = False;
2750 if ( (pevB1->type == pevB2->type) &&
2751 (pevB1->send_event == pevB2->send_event) &&
2752 (pevB1->display == pevB2->display) &&
2753 (pevB1->window == pevB2->window) &&
2754 (pevB1->root == pevB2->root) &&
2755 (pevB1->subwindow == pevB2->subwindow) &&
2756 (pevB1->time == pevB2->time) &&
2757 (pevB1->x == pevB2->x) &&
2758 (pevB1->y == pevB2->y) &&
2759 (pevB1->x_root == pevB2->x_root) &&
2760 (pevB1->y_root == pevB2->y_root) &&
2761 (pevB1->state == pevB2->state) &&
2762 (pevB1->button == pevB2->button) &&
2763 (pevB1->same_screen == pevB2->same_screen)