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 libraries 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 OPEN SOFTWARE FOUNDATION, INC.
31 * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
41 * include extern functions
45 #include "WmFunction.h"
46 #include "WmKeyFocus.h"
48 #include "WmWinInfo.h"
51 #endif /* NO_WMQUERY */
55 * Function Declarations:
58 #include "WmProtocol.h"
60 static Boolean wmq_convert (Widget w, Atom *pSelection, Atom *pTarget,
61 Atom *pType_return, XtPointer *pValue_return, unsigned long *pLength_return,
63 static Boolean wmq_convert_all_clients (Widget w, int screen,
64 Atom *pType_return, XtPointer *pValue_return, unsigned long *pLength_return,
66 static void wmq_list_subtree (ClientData *pCD);
67 static void wmq_add_xid (XID win);
68 static void wmq_done (Widget w, Atom *pSelection, Atom *pTarget);
69 static void wmq_lose (Widget w, Atom *pSelection);
70 static void wmq_bump_xids(void);
71 #endif /* NO_WMQUERY */
78 Atom *xa_WM_QUERY = NULL;
79 Atom xa_WM_POINTER_WINDOW;
80 Atom xa_WM_CLIENT_WINDOW;
81 Atom xa_WM_ALL_CLIENTS;
85 #endif /* NO_WMQUERY */
89 /*************************************<->*************************************
96 * This function sets up the window manager handling of the inter-client
97 * communications conventions.
102 * (wmGD) = Atoms id's are setup.
104 *************************************<->***********************************/
106 void SetupWmICCC (void)
109 XA_WM_STATE, XA_WM_PROTOCOLS, XA_WM_CHANGE_STATE,
110 XA_WM_SAVE_YOURSELF, XA_WM_DELETE_WINDOW,
111 XA_WM_COLORMAP_WINDOWS, XA_WM_TAKE_FOCUS, XA_MWM_HINTS,
112 XA_MWM_MENU, XA_MWM_MESSAGES, XA_MOTIF_WM_OFFSET,
113 #if !defined(NO_WMQUERY)
114 XA_MOTIF_WM_CLIENT_WINDOW, XA_MOTIF_WM_POINTER_WINDOW,
115 XA_MOTIF_WM_ALL_CLIENTS,
117 XA_COMPOUND_TEXT, NUM_ATOMS };
119 static char *atom_names[] = {
120 _XA_WM_STATE, _XA_WM_PROTOCOLS, _XA_WM_CHANGE_STATE,
121 _XA_WM_SAVE_YOURSELF, _XA_WM_DELETE_WINDOW,
122 _XA_WM_COLORMAP_WINDOWS, _XA_WM_TAKE_FOCUS, _XA_MWM_HINTS,
123 _XA_MWM_MENU, _XA_MWM_MESSAGES, _XA_MOTIF_WM_OFFSET,
124 #if !defined(NO_WMQUERY)
125 # ifdef _XA_MOTIF_WM_CLIENT_WINDOW
126 _XA_MOTIF_WM_CLIENT_WINDOW, _XA_MOTIF_WM_POINTER_WINDOW,
127 _XA_MOTIF_WM_ALL_CLIENTS,
129 "_MOTIF_WM_CLIENT_WINDOW", "_MOTIF_WM_POINTER_WINDOW",
130 "_MOTIF_WM_ALL_CLIENTS",
138 Atom atoms[XtNumber(atom_names) + 1];
141 * Make atoms that are required by the ICCC and mwm. The atom for
142 * _MOTIF_WM_INFO is intern'ed in ProcessMotifWmInfo.
144 XInternAtoms(DISPLAY, atom_names, XtNumber(atom_names), False, atoms);
146 wmGD.xa_WM_STATE = atoms[XA_WM_STATE];
147 wmGD.xa_WM_PROTOCOLS = atoms[XA_WM_PROTOCOLS];
148 wmGD.xa_WM_CHANGE_STATE = atoms[XA_WM_CHANGE_STATE];
149 wmGD.xa_WM_SAVE_YOURSELF = atoms[XA_WM_SAVE_YOURSELF];
150 wmGD.xa_WM_DELETE_WINDOW = atoms[XA_WM_DELETE_WINDOW];
151 wmGD.xa_WM_COLORMAP_WINDOWS = atoms[XA_WM_COLORMAP_WINDOWS];
152 wmGD.xa_WM_TAKE_FOCUS = atoms[XA_WM_TAKE_FOCUS];
153 wmGD.xa_MWM_HINTS = atoms[XA_MWM_HINTS];
154 wmGD.xa_MWM_MENU = atoms[XA_MWM_MENU];
155 wmGD.xa_MWM_MESSAGES = atoms[XA_MWM_MESSAGES];
156 wmGD.xa_MWM_OFFSET = atoms[XA_MOTIF_WM_OFFSET];
158 wmGD.xa_COMPOUND_TEXT = atoms[XA_COMPOUND_TEXT];
161 if (!(xa_WM_QUERY = (Atom *) XtMalloc (wmGD.numScreens * (sizeof (Atom)))))
163 Warning (((char *)GETMESSAGE(56, 2, "Insufficient memory to XInternAtom _MOTIF_WM_QUERY_nn")));
166 for (scr = 0; scr < wmGD.numScreens; scr++)
168 if (wmGD.Screens[scr].managed)
170 char wm_query_scr[32];
172 sprintf(wm_query_scr, "_MOTIF_WM_QUERY_%d",
173 wmGD.Screens[scr].screen);
174 xa_WM_QUERY[scr] = XInternAtom(DISPLAY, wm_query_scr, False);
178 xa_WM_QUERY[scr] = 0;
181 xa_WM_CLIENT_WINDOW = atoms[XA_MOTIF_WM_CLIENT_WINDOW];
182 xa_WM_POINTER_WINDOW = atoms[XA_MOTIF_WM_POINTER_WINDOW];
183 xa_WM_ALL_CLIENTS = atoms[XA_MOTIF_WM_ALL_CLIENTS];
184 #endif /* NO_WMQUERY */
188 * Setup the icon size property on the root window.
191 sizeList.width_inc = 1;
192 sizeList.height_inc = 1;
194 for (scr = 0; scr < wmGD.numScreens; scr++)
196 if (wmGD.Screens[scr].managed)
198 sizeList.min_width = wmGD.Screens[scr].iconImageMinimum.width;
199 sizeList.min_height = wmGD.Screens[scr].iconImageMinimum.height;
200 sizeList.max_width = wmGD.Screens[scr].iconImageMaximum.width;
201 sizeList.max_height = wmGD.Screens[scr].iconImageMaximum.height;
203 XSetIconSizes (DISPLAY, wmGD.Screens[scr].rootWindow,
210 * Assert ownership of the WM_QUERY selection
212 for (scr = 0; scr < wmGD.numScreens; scr++)
214 if (wmGD.Screens[scr].managed)
216 if (!XtOwnSelection(wmGD.topLevelW,
223 Warning (((char *)GETMESSAGE(56, 3, "Failed to own _MOTIF_WM_QUERY_nn selection")));
227 #endif /* NO_WMQUERY */
230 } /* END OF FUNCTION SetupWmICCC */
234 /*************************************<->*************************************
236 * SendConfigureNotify (pCD)
241 * This function is used to send a synthetic ConfigureNotify event when
242 * a client window is reconfigured in certain ways (e.g., the window is
243 * moved without being resized).
248 * pCD = pointer to client data (window id and client size data)
250 *************************************<->***********************************/
252 void SendConfigureNotify (ClientData *pCD)
254 XConfigureEvent notifyEvent;
258 * Send a synthetic ConfigureNotify message:
261 notifyEvent.type = ConfigureNotify;
262 notifyEvent.display = DISPLAY;
263 notifyEvent.event = pCD->client;
264 notifyEvent.window = pCD->client;
269 WmFpEmbeddedClientData *pECD = (WmFpEmbeddedClientData *)pCD->pECD;
272 * The front panel uses clientX, clientY for position in
273 * front panel. Translate to root coords for client's
277 XTranslateCoordinates (DISPLAY, pECD->winParent,
278 ROOT_FOR_CLIENT(pCD), pCD->clientX, pCD->clientY,
279 &rootX, &rootY, &wChild);
281 notifyEvent.x = rootX;
282 notifyEvent.y = rootY;
283 notifyEvent.width = pCD->clientWidth;
284 notifyEvent.height = pCD->clientHeight;
289 notifyEvent.x = pCD->maxX;
290 notifyEvent.y = pCD->maxY;
291 notifyEvent.width = pCD->maxWidth;
292 notifyEvent.height = pCD->maxHeight;
296 notifyEvent.x = pCD->clientX;
297 notifyEvent.y = pCD->clientY;
298 notifyEvent.width = pCD->clientWidth;
299 notifyEvent.height = pCD->clientHeight;
301 notifyEvent.border_width = 0;
302 notifyEvent.above = None;
303 notifyEvent.override_redirect = False;
305 XSendEvent (DISPLAY, pCD->client, False, StructureNotifyMask,
306 (XEvent *)¬ifyEvent);
309 } /* END OF FUNCTION SendConfigureNotify */
313 /*************************************<->*************************************
315 * SendClientOffsetMessage (pCD)
320 * This function is used to send a client message containing the offset
321 * between the window position reported to the user and the actual
322 * window position of the client over the root.
324 * This can be used by clients that map and unmap windows to help them
325 * work with the window manager to place the window in the same location
330 * pCD = pointer to client data (frame geometry info)
332 *************************************<->***********************************/
334 void SendClientOffsetMessage (ClientData *pCD)
336 long borderWidth = (long)pCD->xBorderWidth;
337 long offsetX = pCD->clientOffset.x;
338 long offsetY = pCD->clientOffset.y;
340 XClientMessageEvent clientMsgEvent;
342 clientMsgEvent.type = ClientMessage;
343 clientMsgEvent.window = pCD->client;
344 clientMsgEvent.message_type = wmGD.xa_MWM_MESSAGES;
345 clientMsgEvent.format = 32;
346 clientMsgEvent.data.l[0] = wmGD.xa_MWM_OFFSET;
349 * Use window gravity to allow the user to specify the window
350 * position on the screen without having to know the dimensions
351 * of the decoration that mwm is adding.
354 switch (pCD->windowGravity)
356 case NorthWestGravity:
359 clientMsgEvent.data.l[1] = offsetX;
360 clientMsgEvent.data.l[2] = offsetY;
366 clientMsgEvent.data.l[1] = borderWidth;
367 clientMsgEvent.data.l[2] = offsetY;
371 case NorthEastGravity:
373 clientMsgEvent.data.l[1] = -(offsetX - (2 * borderWidth));
374 clientMsgEvent.data.l[2] = offsetY;
380 clientMsgEvent.data.l[1] = -(offsetX - (2 * borderWidth));
381 clientMsgEvent.data.l[2] = borderWidth + (offsetY - offsetX)/2;
385 case SouthEastGravity:
387 clientMsgEvent.data.l[1] = -(offsetX - (2 * borderWidth));
388 clientMsgEvent.data.l[2] = -(offsetX - (2 * borderWidth));
394 clientMsgEvent.data.l[1] = borderWidth;
395 clientMsgEvent.data.l[2] = -(offsetX - (2 * borderWidth));
399 case SouthWestGravity:
401 clientMsgEvent.data.l[1] = offsetX;
402 clientMsgEvent.data.l[2] = -(offsetX - (2 * borderWidth));
408 clientMsgEvent.data.l[1] = offsetX;
409 clientMsgEvent.data.l[2] = borderWidth + (offsetY - offsetX)/2;
415 clientMsgEvent.data.l[2] = (offsetY - offsetX)/2;
420 XSendEvent (DISPLAY, pCD->client, False, NoEventMask,
421 (XEvent *)&clientMsgEvent);
424 } /* END OF FUNCTION SendClientOffsetMessage */
427 /*************************************<->*************************************
429 * SendClientMsg (window, type, data0, time, pData, dataLen)
434 * This function is used to send a client message event that to a client
435 * window. The message may be sent as part of a protocol arranged for by
436 * the client with the WM_PROTOCOLS property.
441 * window = destination window for the client message event
443 * type = client message type
445 * data0 = data0 value in the client message
447 * time = timestamp to be used in the event
449 * pData = pointer to data to be used in the event
451 * dataLen = len of data (in 32 bit units)
453 *************************************<->***********************************/
455 void SendClientMsg (Window window, long type, long data0, Time time, long *pData, int dataLen)
457 XClientMessageEvent clientMsgEvent;
461 clientMsgEvent.type = ClientMessage;
462 clientMsgEvent.window = window;
463 clientMsgEvent.message_type = type;
464 clientMsgEvent.format = 32;
465 clientMsgEvent.data.l[0] = data0;
466 clientMsgEvent.data.l[1] = (long)time;
470 * Fill in the rest of the ClientMessage event (that holds up to
478 for (i = 2; i < (2 + dataLen); i++)
480 clientMsgEvent.data.l[i] = pData[i];
485 XSendEvent (DISPLAY, window, False, NoEventMask,
486 (XEvent *)&clientMsgEvent);
490 } /* END OF FUNCTION SendClientMsg */
494 /*************************************<->*************************************
496 * AddWmTimer (timerType, timerInterval, pCD)
501 * This function sets a window manager timer of the specified type.
506 * timerType = type of timer to be set
508 * timerInterval = length of timeout in ms
510 * pCD = pointer to client data associated with the timer
512 * return = True if timer could be set
514 *************************************<->***********************************/
516 Boolean AddWmTimer (unsigned int timerType, unsigned long timerInterval, ClientData *pCD)
521 if (!(pWmTimer = (WmTimer *)XtMalloc (sizeof (WmTimer))))
523 Warning (((char *)GETMESSAGE(56, 1, "Insufficient memory for window manager data")));
527 /* !!! handle for XtAppAddTimeOut error !!! */
528 pWmTimer->timerId = XtAppAddTimeOut (wmGD.mwmAppContext,
529 timerInterval, (XtTimerCallbackProc)TimeoutProc, (caddr_t)pCD);
530 pWmTimer->timerCD = pCD;
531 pWmTimer->timerType = timerType;
532 pWmTimer->nextWmTimer = wmGD.wmTimers;
533 wmGD.wmTimers = pWmTimer;
537 } /* END OF FUNCTION AddWmTimer */
541 /*************************************<->*************************************
543 * DeleteClientWmTimers (pCD)
548 * This function deletes all window manager timers that are associated with
549 * the specified client window.
554 * pCD = pointer to client data for client whose timers are to be deleted
558 *************************************<->***********************************/
560 void DeleteClientWmTimers (ClientData *pCD)
564 WmTimer *pRemoveTimer;
568 pWmTimer = wmGD.wmTimers;
571 if (pWmTimer->timerCD == pCD)
575 pPrevTimer->nextWmTimer = pWmTimer->nextWmTimer;
579 wmGD.wmTimers = pWmTimer->nextWmTimer;
581 pRemoveTimer = pWmTimer;
582 pWmTimer = pWmTimer->nextWmTimer;
583 XtRemoveTimeOut (pRemoveTimer->timerId);
584 XtFree ((char *)pRemoveTimer);
588 pPrevTimer = pWmTimer;
589 pWmTimer = pWmTimer->nextWmTimer;
594 } /* END OF FUNCTION DeleteClientWmTimers */
598 /*************************************<->*************************************
600 * TimeoutProc (client_data, id)
605 * This function is an Xtk timeout handler. It is used to handle various
606 * window manager timers (i.e. WM_SAVE_YOURSELF quit timeout).
611 * client_data = pointer to window manager client data
615 *************************************<->***********************************/
617 void TimeoutProc (caddr_t client_data, XtIntervalId *id)
624 * Find out if the timer still needs to be serviced.
628 pWmTimer = wmGD.wmTimers;
631 if (pWmTimer->timerId == *id)
635 pPrevTimer = pWmTimer;
636 pWmTimer = pWmTimer->nextWmTimer;
642 * Do the timer related action.
645 switch (pWmTimer->timerType)
649 XKillClient (DISPLAY, pWmTimer->timerCD->client);
657 if ((wmGD.keyboardFocus == pWmTimer->timerCD) &&
658 (pWmTimer->timerCD->focusPriority ==
659 (PSD_FOR_CLIENT(pWmTimer->timerCD))->focusPriority) &&
660 (wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_POINTER) &&
661 (pWmTimer->timerCD == GetClientUnderPointer(&sameScreen)))
663 Do_Raise (pWmTimer->timerCD, (ClientListEntry *)NULL, STACK_NORMAL);
671 * Remove the timer from the wm timer list.
676 pPrevTimer->nextWmTimer = pWmTimer->nextWmTimer;
680 wmGD.wmTimers = pWmTimer->nextWmTimer;
682 XtFree ((char *)pWmTimer);
689 XtRemoveTimeOut (*id);
692 } /* END OF FUNCTION TimeoutProc */
697 /*************************************<->*************************************
699 * Boolean wmq_convert (w, pSelection, pTarget, pType_return,
700 * pValue_return, pLength_return, pFormat_return)
705 * This function converts WM_QUERY selections
710 * pSelection - pointer to selection type (atom)
711 * pTarget - pointer to requested target type (atom)
715 * pType_return - pointer to type of data returned (atom)
716 * pValue_return - pointer to pointer to data returned
717 * pLength_return - ptr to length of data returned
718 * pFormat_return - ptr to format of data returned
723 *************************************<->***********************************/
730 XtPointer *pValue_return,
731 unsigned long *pLength_return,
736 Boolean wm_query_found = False;
740 for (scr = 0; scr < wmGD.numScreens; scr++)
742 if (wmGD.Screens[scr].managed)
744 if (*pSelection == xa_WM_QUERY[scr])
746 wm_query_found = True;
754 if (*pTarget == xa_WM_POINTER_WINDOW)
758 else if (*pTarget == xa_WM_CLIENT_WINDOW)
762 else if (*pTarget == xa_WM_ALL_CLIENTS)
764 return (wmq_convert_all_clients (w, scr, pType_return,
765 pValue_return, pLength_return,
770 return (wm_query_found);
771 } /* END OF FUNCTION wmq_convert */
774 /*************************************<->*************************************
776 * Boolean wmq_convert_all_clients (w, screen, pType_return,
777 * pValue_return, pLength_return, pFormat_return)
782 * This function converts the WM_QUERY selection target WM_ALL_CLIENTS
787 * screen - screen number
791 * pType_return - pointer to type of data returned (atom)
792 * pValue_return - pointer to pointer to data returned
793 * pLength_return - ptr to length of data returned
794 * pFormat_return - ptr to format of data returned
799 *************************************<->***********************************/
801 wmq_convert_all_clients (
805 XtPointer *pValue_return,
806 unsigned long *pLength_return,
810 WmScreenData *pSD = NULL;
811 ClientListEntry *pEntry;
815 * Start with empty client list
820 * Get all clients on the specified screen
823 if (wmGD.Screens[screen].managed)
825 pSD = &wmGD.Screens[screen];
828 * Traverse the client list for this screen and
829 * add to the list of window IDs
831 pEntry = pSD->clientList;
836 * Filter out entries for icons
838 if (pEntry->type != MINIMIZED_STATE)
841 if (pCD->transientChildren)
843 wmq_list_subtree(pCD->transientChildren);
845 wmq_add_xid ((XID) pCD->client);
847 pEntry = pEntry->nextSibling;
851 *pType_return = XA_WINDOW;
852 *pValue_return = (XtPointer) pXids;
853 *pLength_return = curXids;
854 *pFormat_return = 32;
857 } /* END OF FUNCTION wmq_convert_all_clients */
860 /*************************************<->*************************************
862 * void wmq_list_subtree (pCD)
867 * This function adds the windows in a transient subtree to the
872 * pCD - client data for "leftmost" child of a subtree
880 *************************************<->***********************************/
890 if (pCD->transientChildren)
892 wmq_list_subtree(pCD->transientChildren);
898 wmq_add_xid ((XID) pCD->client);
903 if (pCD->transientSiblings)
905 wmq_list_subtree(pCD->transientSiblings);
908 } /* END OF FUNCTION wmq_list_subtree */
912 /*************************************<->*************************************
914 * void wmq_add_xid (win)
919 * This function adds an xid to the list
931 *************************************<->***********************************/
937 if (curXids >= numXids)
942 if (curXids < numXids)
944 pXids[curXids++] = win;
947 } /* END OF FUNCTION wmq_add_xid */
951 /*************************************<->*************************************
953 * void wmq_lose (w, pSelection)
958 * This function is called when we lose the WM_QUERY selection
963 * pSelection - pointer to selection type (atom)
970 * This shouldn't happen!
972 *************************************<->***********************************/
979 Warning (((char *)GETMESSAGE(56, 4, "Lost _MOTIF_WM_QUERY_nn selection")));
980 } /* END OF FUNCTION wmq_lose */
984 /*************************************<->*************************************
986 * void wmq_done (w, pSelection, pTarget)
991 * This function is called when selection conversion is done.
996 * pSelection - pointer to selection type (atom)
997 * pTarget - pointer to requested target type (atom)
1004 * This is here to prevent Xt from freeing our buffers.
1006 *************************************<->***********************************/
1014 } /* END OF FUNCTION wmq_done */
1018 /*************************************<->*************************************
1020 * static void wmq_bump_xids ()
1025 * This function allocates more xids in our local buffer
1030 * pSelection - pointer to selection type (atom)
1031 * pTarget - pointer to requested target type (atom)
1038 * This is here to prevent Xt from freeing our buffers.
1040 *************************************<->***********************************/
1042 wmq_bump_xids ( void )
1049 XtRealloc ((char *) pXids, (numXids + 32) * (sizeof (XID)))))
1051 Warning (((char *)GETMESSAGE(56, 5, "Insufficient memory to convert _MOTIF_WM_QUERY_nn selection")));
1061 if (!(pXids = (XID *)
1062 XtMalloc (32 * (sizeof (XID)))))
1064 Warning (((char *)GETMESSAGE(56, 5, "Insufficient memory to convert _MOTIF_WM_QUERY_nn selection")));
1073 #endif /* NO_WMQUERY */