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 OPEN SOFTWARE FOUNDATION, INC.
32 static char rcsid[] = "$TOG: WmProtocol.c /main/8 1997/06/18 17:31:34 samborn $"
36 * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
46 * include extern functions
50 #include "WmFunction.h"
51 #include "WmKeyFocus.h"
53 #include "WmWinInfo.h"
56 #endif /* NO_WMQUERY */
61 #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL))
64 #endif /* !defined(WSM) || defined(MWM_QATS_PROTOCOL) */
67 * Function Declarations:
70 #include "WmProtocol.h"
72 static Boolean wmq_convert (Widget w, Atom *pSelection, Atom *pTarget,
73 Atom *pType_return, XtPointer *pValue_return, unsigned long *pLength_return,
75 static Boolean wmq_convert_all_clients (Widget w, int screen,
76 Atom *pType_return, XtPointer *pValue_return, unsigned long *pLength_return,
78 static void wmq_list_subtree (ClientData *pCD);
79 static void wmq_add_xid (XID win);
80 static void wmq_done (Widget w, Atom *pSelection, Atom *pTarget);
81 static void wmq_lose (Widget w, Atom *pSelection);
82 static void wmq_bump_xids(void);
83 #endif /* NO_WMQUERY */
85 #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL))
86 static void OwnWMSelections (Time timestamp);
87 static Boolean WMiConvert (Widget, Atom, Atom,
88 XtPointer, unsigned long, int, Atom *,
89 XtPointer *, unsigned long *, int *);
90 static void WMiConvertCB (Widget, XtPointer, XtPointer);
91 #endif /* !defined(WSM) || defined(MWM_QATS_PROTOCOL) */
97 Atom *xa_WM_QUERY = NULL;
98 Atom xa_WM_POINTER_WINDOW;
99 Atom xa_WM_CLIENT_WINDOW;
100 Atom xa_WM_ALL_CLIENTS;
104 #endif /* NO_WMQUERY */
108 /*************************************<->*************************************
115 * This function sets up the window manager handling of the inter-client
116 * communications conventions.
121 * (wmGD) = Atoms id's are setup.
123 *************************************<->***********************************/
125 void SetupWmICCC (void)
128 #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL))
129 XA_TARGETS, XA_MULTIPLE, XA_TIMESTAMP,
131 XA_WM_STATE, XA_WM_PROTOCOLS, XA_WM_CHANGE_STATE,
132 XA_WM_SAVE_YOURSELF, XA_WM_DELETE_WINDOW,
133 XA_WM_COLORMAP_WINDOWS, XA_WM_TAKE_FOCUS, XA_MWM_HINTS,
134 XA_MWM_MENU, XA_MWM_MESSAGES, XA_MOTIF_WM_OFFSET,
135 #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL) || !defined(NO_WMQUERY))
136 XA_MOTIF_WM_CLIENT_WINDOW, XA_MOTIF_WM_POINTER_WINDOW,
137 XA_MOTIF_WM_ALL_CLIENTS,
139 #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL))
140 XA_MOTIF_WM_DEFINE_COMMAND, XA_MOTIF_WM_INCLUDE_COMMAND,
141 XA_MOTIF_WM_REMOVE_COMMAND, XA_MOTIF_WM_ENABLE_COMMAND,
142 XA_MOTIF_WM_DISABLE_COMMAND, XA_MOTIF_WM_RENAME_COMMAND,
143 XA_MOTIF_WM_INVOKE_COMMAND, XA_MOTIF_WM_REQUEST_COMMAND,
144 XA_MOTIF_WM_WINDOW_FLAGS, XA_MOTIF_WM_AUTOMATION,
146 XA_COMPOUND_TEXT, NUM_ATOMS };
148 static char *atom_names[] = {
149 #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL))
150 _XA_TARGETS, _XA_MULTIPLE, _XA_TIMESTAMP,
152 _XA_WM_STATE, _XA_WM_PROTOCOLS, _XA_WM_CHANGE_STATE,
153 _XA_WM_SAVE_YOURSELF, _XA_WM_DELETE_WINDOW,
154 _XA_WM_COLORMAP_WINDOWS, _XA_WM_TAKE_FOCUS, _XA_MWM_HINTS,
155 _XA_MWM_MENU, _XA_MWM_MESSAGES, _XA_MOTIF_WM_OFFSET,
156 #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL) || !defined(NO_WMQUERY))
157 # ifdef _XA_MOTIF_WM_CLIENT_WINDOW
158 _XA_MOTIF_WM_CLIENT_WINDOW, _XA_MOTIF_WM_POINTER_WINDOW,
159 _XA_MOTIF_WM_ALL_CLIENTS,
161 "_MOTIF_WM_CLIENT_WINDOW", "_MOTIF_WM_POINTER_WINDOW",
162 "_MOTIF_WM_ALL_CLIENTS"
165 #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL))
166 _XA_MOTIF_WM_DEFINE_COMMAND, _XA_MOTIF_WM_INCLUDE_COMMAND,
167 _XA_MOTIF_WM_REMOVE_COMMAND, _XA_MOTIF_WM_ENABLE_COMMAND,
168 _XA_MOTIF_WM_DISABLE_COMMAND, _XA_MOTIF_WM_RENAME_COMMAND,
169 _XA_MOTIF_WM_INVOKE_COMMAND, _XA_MOTIF_WM_REQUEST_COMMAND,
170 _XA_MOTIF_WM_WINDOW_FLAGS, _XA_MOTIF_WM_AUTOMATION,
177 Atom atoms[XtNumber(atom_names)];
180 * Make atoms that are required by the ICCC and mwm. The atom for
181 * _MOTIF_WM_INFO is intern'ed in ProcessMotifWmInfo.
183 XInternAtoms(DISPLAY, atom_names, XtNumber(atom_names), False, atoms);
186 #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL))
187 wmGD.xa_TARGETS = atoms[XA_TARGETS];
189 wmGD.xa_MULTIPLE = atoms[XA_MULTIPLE];
190 wmGD.xa_TIMESTAMP = atoms[XA_TIMESTAMP];
191 #endif /* !defined(WSM) || defined(MWM_QATS_PROTOCOL) */
193 wmGD.xa_WM_STATE = atoms[XA_WM_STATE];
194 wmGD.xa_WM_PROTOCOLS = atoms[XA_WM_PROTOCOLS];
195 wmGD.xa_WM_CHANGE_STATE = atoms[XA_WM_CHANGE_STATE];
196 wmGD.xa_WM_SAVE_YOURSELF = atoms[XA_WM_SAVE_YOURSELF];
197 wmGD.xa_WM_DELETE_WINDOW = atoms[XA_WM_DELETE_WINDOW];
198 wmGD.xa_WM_COLORMAP_WINDOWS = atoms[XA_WM_COLORMAP_WINDOWS];
199 wmGD.xa_WM_TAKE_FOCUS = atoms[XA_WM_TAKE_FOCUS];
200 wmGD.xa_MWM_HINTS = atoms[XA_MWM_HINTS];
201 wmGD.xa_MWM_MENU = atoms[XA_MWM_MENU];
202 wmGD.xa_MWM_MESSAGES = atoms[XA_MWM_MESSAGES];
203 wmGD.xa_MWM_OFFSET = atoms[XA_MOTIF_WM_OFFSET];
205 #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL))
206 /* wm query targets */
207 wmGD._MOTIF_WM_CLIENT_WINDOW = atoms[XA_MOTIF_WM_CLIENT_WINDOW];
208 wmGD._MOTIF_WM_POINTER_WINDOW = atoms[XA_MOTIF_WM_POINTER_WINDOW];
209 wmGD._MOTIF_WM_ALL_CLIENTS = atoms[XA_MOTIF_WM_ALL_CLIENTS];
211 /* intern atoms for Client-Commmand Interface protocol. */
212 wmGD._MOTIF_WM_DEFINE_COMMAND = atoms[XA_MOTIF_WM_DEFINE_COMMAND];
213 wmGD._MOTIF_WM_INCLUDE_COMMAND= atoms[XA_MOTIF_WM_INCLUDE_COMMAND];
214 wmGD._MOTIF_WM_REMOVE_COMMAND = atoms[XA_MOTIF_WM_REMOVE_COMMAND];
215 wmGD._MOTIF_WM_ENABLE_COMMAND = atoms[XA_MOTIF_WM_ENABLE_COMMAND];
216 wmGD._MOTIF_WM_DISABLE_COMMAND= atoms[XA_MOTIF_WM_DISABLE_COMMAND];
217 wmGD._MOTIF_WM_RENAME_COMMAND = atoms[XA_MOTIF_WM_RENAME_COMMAND];
218 wmGD._MOTIF_WM_INVOKE_COMMAND = atoms[XA_MOTIF_WM_INVOKE_COMMAND];
219 wmGD._MOTIF_WM_REQUEST_COMMAND= atoms[XA_MOTIF_WM_REQUEST_COMMAND];
220 wmGD._MOTIF_WM_WINDOW_FLAGS = atoms[XA_MOTIF_WM_WINDOW_FLAGS];
222 wmGD._MOTIF_WM_AUTOMATION = atoms[XA_MOTIF_WM_AUTOMATION];
223 #endif /* !defined(WSM) || defined(MWM_QATS_PROTOCOL) */
226 #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL))
228 * Assert ownership of the WINDOW_MANAGER selection
229 * on each screen that the window manager controls.
230 * these use the format WM_Si.
232 OwnWMSelections(GetTimestamp());
233 #endif /* !defined(WSM) || defined(MWM_QATS_PROTOCOL) */
235 wmGD.xa_COMPOUND_TEXT = atoms[XA_COMPOUND_TEXT];
238 if (!(xa_WM_QUERY = (Atom *) XtMalloc (wmGD.numScreens * (sizeof (Atom)))))
240 Warning (((char *)GETMESSAGE(56, 2, "Insufficient memory to XInternAtom _MOTIF_WM_QUERY_nn")));
243 for (scr = 0; scr < wmGD.numScreens; scr++)
245 if (wmGD.Screens[scr].managed)
247 char wm_query_scr[32];
249 sprintf(wm_query_scr, "_MOTIF_WM_QUERY_%d",
250 wmGD.Screens[scr].screen);
251 xa_WM_QUERY[scr] = XInternAtom(DISPLAY, wm_query_scr, False);
255 xa_WM_QUERY[scr] = 0;
258 xa_WM_CLIENT_WINDOW = atoms[XA_MOTIF_WM_CLIENT_WINDOW];
259 xa_WM_POINTER_WINDOW = atoms[XA_MOTIF_WM_POINTER_WINDOW];
260 xa_WM_ALL_CLIENTS = atoms[XA_MOTIF_WM_ALL_CLIENTS];
261 #endif /* NO_WMQUERY */
265 * Setup the icon size property on the root window.
268 sizeList.width_inc = 1;
269 sizeList.height_inc = 1;
271 for (scr = 0; scr < wmGD.numScreens; scr++)
273 if (wmGD.Screens[scr].managed)
275 sizeList.min_width = wmGD.Screens[scr].iconImageMinimum.width;
276 sizeList.min_height = wmGD.Screens[scr].iconImageMinimum.height;
277 sizeList.max_width = wmGD.Screens[scr].iconImageMaximum.width;
278 sizeList.max_height = wmGD.Screens[scr].iconImageMaximum.height;
280 XSetIconSizes (DISPLAY, wmGD.Screens[scr].rootWindow,
287 * Assert ownership of the WM_QUERY selection
289 for (scr = 0; scr < wmGD.numScreens; scr++)
291 if (wmGD.Screens[scr].managed)
293 if (!XtOwnSelection(wmGD.topLevelW,
300 Warning (((char *)GETMESSAGE(56, 3, "Failed to own _MOTIF_WM_QUERY_nn selection")));
304 #endif /* NO_WMQUERY */
307 } /* END OF FUNCTION SetupWmICCC */
311 /*************************************<->*************************************
313 * SendConfigureNotify (pCD)
318 * This function is used to send a synthetic ConfigureNotify event when
319 * a client window is reconfigured in certain ways (e.g., the window is
320 * moved without being resized).
325 * pCD = pointer to client data (window id and client size data)
327 *************************************<->***********************************/
329 void SendConfigureNotify (ClientData *pCD)
331 XConfigureEvent notifyEvent;
335 * Send a synthetic ConfigureNotify message:
338 notifyEvent.type = ConfigureNotify;
339 notifyEvent.display = DISPLAY;
340 notifyEvent.event = pCD->client;
341 notifyEvent.window = pCD->client;
347 WmFpEmbeddedClientData *pECD = (WmFpEmbeddedClientData *)pCD->pECD;
350 * The front panel uses clientX, clientY for position in
351 * front panel. Translate to root coords for client's
355 XTranslateCoordinates (DISPLAY, pECD->winParent,
356 ROOT_FOR_CLIENT(pCD), pCD->clientX, pCD->clientY,
357 &rootX, &rootY, &wChild);
359 notifyEvent.x = rootX;
360 notifyEvent.y = rootY;
361 notifyEvent.width = pCD->clientWidth;
362 notifyEvent.height = pCD->clientHeight;
366 #endif /* PANELIST */
369 notifyEvent.x = pCD->maxX;
370 notifyEvent.y = pCD->maxY;
371 notifyEvent.width = pCD->maxWidth;
372 notifyEvent.height = pCD->maxHeight;
376 notifyEvent.x = pCD->clientX;
377 notifyEvent.y = pCD->clientY;
378 notifyEvent.width = pCD->clientWidth;
379 notifyEvent.height = pCD->clientHeight;
381 notifyEvent.border_width = 0;
382 notifyEvent.above = None;
383 notifyEvent.override_redirect = False;
385 XSendEvent (DISPLAY, pCD->client, False, StructureNotifyMask,
386 (XEvent *)¬ifyEvent);
389 } /* END OF FUNCTION SendConfigureNotify */
393 /*************************************<->*************************************
395 * SendClientOffsetMessage (pCD)
400 * This function is used to send a client message containing the offset
401 * between the window position reported to the user and the actual
402 * window position of the client over the root.
404 * This can be used by clients that map and unmap windows to help them
405 * work with the window manager to place the window in the same location
410 * pCD = pointer to client data (frame geometry info)
412 *************************************<->***********************************/
414 void SendClientOffsetMessage (ClientData *pCD)
416 long borderWidth = (long)pCD->xBorderWidth;
417 long offsetX = pCD->clientOffset.x;
418 long offsetY = pCD->clientOffset.y;
420 XClientMessageEvent clientMsgEvent;
422 clientMsgEvent.type = ClientMessage;
423 clientMsgEvent.window = pCD->client;
424 clientMsgEvent.message_type = wmGD.xa_MWM_MESSAGES;
425 clientMsgEvent.format = 32;
426 clientMsgEvent.data.l[0] = wmGD.xa_MWM_OFFSET;
429 * Use window gravity to allow the user to specify the window
430 * position on the screen without having to know the dimensions
431 * of the decoration that mwm is adding.
434 switch (pCD->windowGravity)
436 case NorthWestGravity:
439 clientMsgEvent.data.l[1] = offsetX;
440 clientMsgEvent.data.l[2] = offsetY;
446 clientMsgEvent.data.l[1] = borderWidth;
447 clientMsgEvent.data.l[2] = offsetY;
451 case NorthEastGravity:
453 clientMsgEvent.data.l[1] = -(offsetX - (2 * borderWidth));
454 clientMsgEvent.data.l[2] = offsetY;
460 clientMsgEvent.data.l[1] = -(offsetX - (2 * borderWidth));
461 clientMsgEvent.data.l[2] = borderWidth + (offsetY - offsetX)/2;
465 case SouthEastGravity:
467 clientMsgEvent.data.l[1] = -(offsetX - (2 * borderWidth));
468 clientMsgEvent.data.l[2] = -(offsetX - (2 * borderWidth));
474 clientMsgEvent.data.l[1] = borderWidth;
475 clientMsgEvent.data.l[2] = -(offsetX - (2 * borderWidth));
479 case SouthWestGravity:
481 clientMsgEvent.data.l[1] = offsetX;
482 clientMsgEvent.data.l[2] = -(offsetX - (2 * borderWidth));
488 clientMsgEvent.data.l[1] = offsetX;
489 clientMsgEvent.data.l[2] = borderWidth + (offsetY - offsetX)/2;
495 clientMsgEvent.data.l[2] = (offsetY - offsetX)/2;
500 XSendEvent (DISPLAY, pCD->client, False, NoEventMask,
501 (XEvent *)&clientMsgEvent);
504 } /* END OF FUNCTION SendClientOffsetMessage */
507 /*************************************<->*************************************
509 * SendClientMsg (window, type, data0, time, pData, dataLen)
514 * This function is used to send a client message event that to a client
515 * window. The message may be sent as part of a protocol arranged for by
516 * the client with the WM_PROTOCOLS property.
521 * window = destination window for the client message event
523 * type = client message type
525 * data0 = data0 value in the client message
527 * time = timestamp to be used in the event
529 * pData = pointer to data to be used in the event
531 * dataLen = len of data (in 32 bit units)
533 *************************************<->***********************************/
535 void SendClientMsg (Window window, long type, long data0, Time time, long *pData, int dataLen)
537 XClientMessageEvent clientMsgEvent;
541 clientMsgEvent.type = ClientMessage;
542 clientMsgEvent.window = window;
543 clientMsgEvent.message_type = type;
544 clientMsgEvent.format = 32;
545 clientMsgEvent.data.l[0] = data0;
546 clientMsgEvent.data.l[1] = (long)time;
550 * Fill in the rest of the ClientMessage event (that holds up to
558 for (i = 2; i < (2 + dataLen); i++)
560 clientMsgEvent.data.l[i] = pData[i];
565 XSendEvent (DISPLAY, window, False, NoEventMask,
566 (XEvent *)&clientMsgEvent);
570 } /* END OF FUNCTION SendClientMsg */
574 /*************************************<->*************************************
576 * AddWmTimer (timerType, timerInterval, pCD)
581 * This function sets a window manager timer of the specified type.
586 * timerType = type of timer to be set
588 * timerInterval = length of timeout in ms
590 * pCD = pointer to client data associated with the timer
592 * return = True if timer could be set
594 *************************************<->***********************************/
596 Boolean AddWmTimer (unsigned int timerType, unsigned long timerInterval, ClientData *pCD)
601 if (!(pWmTimer = (WmTimer *)XtMalloc (sizeof (WmTimer))))
603 Warning (((char *)GETMESSAGE(56, 1, "Insufficient memory for window manager data")));
607 /* !!! handle for XtAppAddTimeOut error !!! */
608 pWmTimer->timerId = XtAppAddTimeOut (wmGD.mwmAppContext,
609 timerInterval, (XtTimerCallbackProc)TimeoutProc, (caddr_t)pCD);
610 pWmTimer->timerCD = pCD;
611 pWmTimer->timerType = timerType;
612 pWmTimer->nextWmTimer = wmGD.wmTimers;
613 wmGD.wmTimers = pWmTimer;
617 } /* END OF FUNCTION AddWmTimer */
621 /*************************************<->*************************************
623 * DeleteClientWmTimers (pCD)
628 * This function deletes all window manager timers that are associated with
629 * the specified client window.
634 * pCD = pointer to client data for client whose timers are to be deleted
638 *************************************<->***********************************/
640 void DeleteClientWmTimers (ClientData *pCD)
644 WmTimer *pRemoveTimer;
648 pWmTimer = wmGD.wmTimers;
651 if (pWmTimer->timerCD == pCD)
655 pPrevTimer->nextWmTimer = pWmTimer->nextWmTimer;
659 wmGD.wmTimers = pWmTimer->nextWmTimer;
661 pRemoveTimer = pWmTimer;
662 pWmTimer = pWmTimer->nextWmTimer;
663 XtRemoveTimeOut (pRemoveTimer->timerId);
664 XtFree ((char *)pRemoveTimer);
668 pPrevTimer = pWmTimer;
669 pWmTimer = pWmTimer->nextWmTimer;
674 } /* END OF FUNCTION DeleteClientWmTimers */
678 /*************************************<->*************************************
680 * TimeoutProc (client_data, id)
685 * This function is an Xtk timeout handler. It is used to handle various
686 * window manager timers (i.e. WM_SAVE_YOURSELF quit timeout).
691 * client_data = pointer to window manager client data
695 *************************************<->***********************************/
697 void TimeoutProc (caddr_t client_data, XtIntervalId *id)
704 * Find out if the timer still needs to be serviced.
708 pWmTimer = wmGD.wmTimers;
711 if (pWmTimer->timerId == *id)
715 pPrevTimer = pWmTimer;
716 pWmTimer = pWmTimer->nextWmTimer;
722 * Do the timer related action.
725 switch (pWmTimer->timerType)
729 XKillClient (DISPLAY, pWmTimer->timerCD->client);
737 if ((wmGD.keyboardFocus == pWmTimer->timerCD) &&
738 (pWmTimer->timerCD->focusPriority ==
739 (PSD_FOR_CLIENT(pWmTimer->timerCD))->focusPriority) &&
740 (wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_POINTER) &&
741 (pWmTimer->timerCD == GetClientUnderPointer(&sameScreen)))
743 Do_Raise (pWmTimer->timerCD, (ClientListEntry *)NULL, STACK_NORMAL);
751 * Remove the timer from the wm timer list.
756 pPrevTimer->nextWmTimer = pWmTimer->nextWmTimer;
760 wmGD.wmTimers = pWmTimer->nextWmTimer;
762 XtFree ((char *)pWmTimer);
769 XtRemoveTimeOut (*id);
772 } /* END OF FUNCTION TimeoutProc */
777 /*************************************<->*************************************
779 * Boolean wmq_convert (w, pSelection, pTarget, pType_return,
780 * pValue_return, pLength_return, pFormat_return)
785 * This function converts WM_QUERY selections
790 * pSelection - pointer to selection type (atom)
791 * pTarget - pointer to requested target type (atom)
795 * pType_return - pointer to type of data returned (atom)
796 * pValue_return - pointer to pointer to data returned
797 * pLength_return - ptr to length of data returned
798 * pFormat_return - ptr to format of data returned
803 *************************************<->***********************************/
810 XtPointer *pValue_return,
811 unsigned long *pLength_return,
816 Boolean wm_query_found = False;
820 for (scr = 0; scr < wmGD.numScreens; scr++)
822 if (wmGD.Screens[scr].managed)
824 if (*pSelection == xa_WM_QUERY[scr])
826 wm_query_found = True;
834 if (*pTarget == xa_WM_POINTER_WINDOW)
838 else if (*pTarget == xa_WM_CLIENT_WINDOW)
842 else if (*pTarget == xa_WM_ALL_CLIENTS)
844 return (wmq_convert_all_clients (w, scr, pType_return,
845 pValue_return, pLength_return,
850 return (wm_query_found);
851 } /* END OF FUNCTION wmq_convert */
854 /*************************************<->*************************************
856 * Boolean wmq_convert_all_clients (w, screen, pType_return,
857 * pValue_return, pLength_return, pFormat_return)
862 * This function converts the WM_QUERY selection target WM_ALL_CLIENTS
867 * screen - screen number
871 * pType_return - pointer to type of data returned (atom)
872 * pValue_return - pointer to pointer to data returned
873 * pLength_return - ptr to length of data returned
874 * pFormat_return - ptr to format of data returned
879 *************************************<->***********************************/
881 wmq_convert_all_clients (
885 XtPointer *pValue_return,
886 unsigned long *pLength_return,
890 WmScreenData *pSD = NULL;
891 ClientListEntry *pEntry;
895 * Start with empty client list
900 * Get all clients on the specified screen
903 if (wmGD.Screens[screen].managed)
905 pSD = &wmGD.Screens[screen];
908 * Traverse the client list for this screen and
909 * add to the list of window IDs
911 pEntry = pSD->clientList;
916 * Filter out entries for icons
918 if (pEntry->type != MINIMIZED_STATE)
921 if (pCD->transientChildren)
923 wmq_list_subtree(pCD->transientChildren);
925 wmq_add_xid ((XID) pCD->client);
927 pEntry = pEntry->nextSibling;
931 *pType_return = XA_WINDOW;
932 *pValue_return = (XtPointer) pXids;
933 *pLength_return = curXids;
934 *pFormat_return = 32;
937 } /* END OF FUNCTION wmq_convert_all_clients */
940 /*************************************<->*************************************
942 * void wmq_list_subtree (pCD)
947 * This function adds the windows in a transient subtree to the
952 * pCD - client data for "leftmost" child of a subtree
960 *************************************<->***********************************/
970 if (pCD->transientChildren)
972 wmq_list_subtree(pCD->transientChildren);
978 wmq_add_xid ((XID) pCD->client);
983 if (pCD->transientSiblings)
985 wmq_list_subtree(pCD->transientSiblings);
988 } /* END OF FUNCTION wmq_list_subtree */
992 /*************************************<->*************************************
994 * void wmq_add_xid (win)
999 * This function adds an xid to the list
1011 *************************************<->***********************************/
1017 if (curXids >= numXids)
1022 if (curXids < numXids)
1024 pXids[curXids++] = win;
1027 } /* END OF FUNCTION wmq_add_xid */
1031 /*************************************<->*************************************
1033 * void wmq_lose (w, pSelection)
1038 * This function is called when we lose the WM_QUERY selection
1043 * pSelection - pointer to selection type (atom)
1050 * This shouldn't happen!
1052 *************************************<->***********************************/
1059 Warning (((char *)GETMESSAGE(56, 4, "Lost _MOTIF_WM_QUERY_nn selection")));
1060 } /* END OF FUNCTION wmq_lose */
1064 /*************************************<->*************************************
1066 * void wmq_done (w, pSelection, pTarget)
1071 * This function is called when selection conversion is done.
1076 * pSelection - pointer to selection type (atom)
1077 * pTarget - pointer to requested target type (atom)
1084 * This is here to prevent Xt from freeing our buffers.
1086 *************************************<->***********************************/
1094 } /* END OF FUNCTION wmq_done */
1098 /*************************************<->*************************************
1100 * static void wmq_bump_xids ()
1105 * This function allocates more xids in our local buffer
1110 * pSelection - pointer to selection type (atom)
1111 * pTarget - pointer to requested target type (atom)
1118 * This is here to prevent Xt from freeing our buffers.
1120 *************************************<->***********************************/
1122 wmq_bump_xids ( void )
1129 XtRealloc ((char *) pXids, (numXids + 32) * (sizeof (XID)))))
1131 Warning (((char *)GETMESSAGE(56, 5, "Insufficient memory to convert _MOTIF_WM_QUERY_nn selection")));
1141 if (!(pXids = (XID *)
1142 XtMalloc (32 * (sizeof (XID)))))
1144 Warning (((char *)GETMESSAGE(56, 5, "Insufficient memory to convert _MOTIF_WM_QUERY_nn selection")));
1153 #endif /* NO_WMQUERY */
1157 #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL))
1158 /*************************************<->*************************************
1160 * static void OwnWMSelections ()
1165 * Get the selection ownership for each managed screen. The selection mwm
1166 * will own is WM_Si.
1181 *************************************<->***********************************/
1183 OwnWMSelections ( Time timestamp )
1188 wmGD.xa_WM = (Atom *) XtMalloc (wmGD.numScreens * (sizeof (Atom)));
1190 for (scr = 0; scr < wmGD.numScreens; scr++)
1192 if (wmGD.Screens[scr].managed)
1196 sprintf(wm_scr, "WM_S%d", DefaultScreen(DISPLAY));
1197 wmGD.xa_WM[scr] = XInternAtom (DISPLAY, wm_scr, False);
1201 * This registers the callback to be invoked when a request
1202 * is made against a WSM Protocol target. The request
1203 * callback is stored by the WSM Protocol code and is
1204 * invoked in the convert routine (WMiConvert) below.
1205 * See WSMProcessProtoTargets().
1208 WSMRegisterRequestCallback(DISPLAY, scr, HandleWsmConvertRequest,
1213 * Own the selection through UTM. This sets-up a convert function
1214 * that is invoked when a convert request is made on this selection.
1215 * The convert function is specified in the drawing area's
1216 * XmNconvertCallback resource.
1219 XtAddCallback(wmGD.Screens[scr].utmShell, XmNconvertCallback,
1220 WMiConvertCB, NULL);
1222 if (! XmeNamedSource(wmGD.Screens[scr].utmShell,
1223 wmGD.xa_WM[scr], timestamp))
1225 Warning (((char *)GETMESSAGE(56, 6,
1226 "Failed to own WM_nn selection")));
1230 PRINT("Owning selection %s\n", wm_scr);
1239 /*************************************<->*************************************
1241 * Boolean WMiConvert ( )
1246 * This function converts WM_Si selections using the new param selections
1248 *************************************<->***********************************/
1257 unsigned long inputLen,
1261 unsigned long *outputLen,
1265 Boolean found = False;
1268 /* set up some defaults. selection code doesn't like garbage! */
1273 scr = XScreenNumberOfScreen(XtScreen(w));
1274 if (!wmGD.Screens[scr].managed)
1276 Warning (((char *)GETMESSAGE(56, 7,
1277 "Got convert request from unmanaged screen")));
1282 if (target == wmGD.xa_TARGETS) {
1283 Atom *targs = (Atom *)XtMalloc((unsigned) (28 * sizeof(Atom)));
1284 int targetCount = 0;
1286 *output = (XtPointer) targs;
1288 /* required targets */
1289 *targs++ = wmGD.xa_TARGETS; targetCount++;
1290 *targs++ = wmGD.xa_MULTIPLE; targetCount++;
1291 *targs++ = wmGD.xa_TIMESTAMP; targetCount++;
1295 *targs++ = _WSMReqTypeToTarget(DISPLAY, WSM_CONNECT); targetCount++;
1296 *targs++ = _WSMReqTypeToTarget(DISPLAY, WSM_EXTENSIONS); targetCount++;
1297 *targs++ = _WSMReqTypeToTarget(DISPLAY, WSM_CONFIG_FMT); targetCount++;
1298 *targs++ = _WSMReqTypeToTarget(DISPLAY, WSM_GET_STATE); targetCount++;
1299 *targs++ = _WSMReqTypeToTarget(DISPLAY, WSM_SET_STATE); targetCount++;
1300 *targs++ = _WSMReqTypeToTarget(DISPLAY, WSM_REG_WINDOW); targetCount++;
1303 /* menu command interface support */
1304 *targs++ = wmGD._MOTIF_WM_DEFINE_COMMAND; targetCount++;
1305 *targs++ = wmGD._MOTIF_WM_INCLUDE_COMMAND; targetCount++;
1306 *targs++ = wmGD._MOTIF_WM_REMOVE_COMMAND; targetCount++;
1307 *targs++ = wmGD._MOTIF_WM_ENABLE_COMMAND; targetCount++;
1308 *targs++ = wmGD._MOTIF_WM_DISABLE_COMMAND; targetCount++;
1309 *targs++ = wmGD._MOTIF_WM_RENAME_COMMAND; targetCount++;
1310 *targs++ = wmGD._MOTIF_WM_INVOKE_COMMAND; targetCount++;
1311 *targs++ = wmGD._MOTIF_WM_REQUEST_COMMAND; targetCount++;
1312 *targs++ = wmGD._MOTIF_WM_WINDOW_FLAGS; targetCount++;
1315 /* virtual screen support */
1316 *targs++ = wmGD._MOTIF_WM_PAN; targetCount++;
1317 *targs++ = wmGD._MOTIF_WM_GOTO; targetCount++;
1320 /* automation support */
1322 *targs++ = wmGD._MOTIF_WM_AUTOMATION; targetCount++;
1324 *outputType = XA_ATOM;
1325 *outputLen = (targetCount * sizeof(Atom)) >> 2;
1332 /* virtual screen support */
1333 else if (target == wmGD._MOTIF_WM_PAN)
1338 dx = (int) UnpackCARD32(&input);
1339 dy = (int) UnpackCARD32(&input);
1340 config = (Boolean) UnpackCARD8(&input);
1342 PanRoot(dx, dy, config);
1345 * Update the root property
1348 SetPanPosition (ACTIVE_PSD->panDx, ACTIVE_PSD->panDy);
1352 else if (target == wmGD._MOTIF_WM_GOTO)
1356 x = (int) UnpackCARD32(&input);
1357 y = (int) UnpackCARD32(&input);
1359 PanRoot(x - ACTIVE_PSD->panDx, y - ACTIVE_PSD->panDy, 1);
1365 * Handle the workspace manager protocol targets...
1368 else if (WSMIsKnownTarget(w, target))
1371 * Unpack data send in request and invoke CB specified
1372 * in WSMRegisterRequestCallback.
1374 found = WSMProcessProtoTarget
1376 input, inputLen, inputFmt,
1377 outputType, output, outputLen, outputFmt);
1379 #endif /* MWM_WSM */
1382 * Handle client-command interface targets.
1385 else if (target == wmGD._MOTIF_WM_DEFINE_COMMAND)
1387 PRINT("Convert request made for _MOTIF_WM_DEFINE_COMMAND.\n");
1388 DefineCommand(w, target, (MessageData)input, inputLen, inputFmt);
1389 PRINT("Returning from _MOTIF_WM_DEFINE_COMMAND.\n");
1393 else if (target == wmGD._MOTIF_WM_INCLUDE_COMMAND)
1395 PRINT("Convert request made for _MOTIF_WM_INCLUDE_COMMAND.\n");
1396 IncludeCommand(w, target, (MessageData)input, inputLen, inputFmt);
1397 PRINT("Returning from _MOTIF_WM_INCLUDE_COMMAND.\n");
1401 else if (target == wmGD._MOTIF_WM_REMOVE_COMMAND)
1403 PRINT("Convert request made for _MOTIF_WM_REMOVE_COMMAND.\n");
1404 RemoveCommand(w, target, (MessageData)input, inputLen, inputFmt);
1408 else if (target == wmGD._MOTIF_WM_ENABLE_COMMAND)
1410 PRINT("Convert request made for _MOTIF_WM_ENABLE_COMMAND.\n");
1411 EnableCommand(w, target, (MessageData)input, inputLen, inputFmt);
1415 else if (target == wmGD._MOTIF_WM_DISABLE_COMMAND)
1417 PRINT("Convert request made for _MOTIF_WM_DISABLE_COMMAND.\n");
1418 DisableCommand(w, target, (MessageData)input, inputLen, inputFmt);
1422 else if (target == wmGD._MOTIF_WM_RENAME_COMMAND)
1424 PRINT("Convert request made for _MOTIF_WM_RENAME_COMMAND.\n");
1425 RenameCommand(w, target, (MessageData)input, inputLen, inputFmt);
1429 else if (target == wmGD._MOTIF_WM_INVOKE_COMMAND)
1431 /* Shouldn't get here! */
1433 else if (target == wmGD._MOTIF_WM_REQUEST_COMMAND)
1436 else if (target == wmGD._MOTIF_WM_WINDOW_FLAGS)
1440 else if (target == wmGD._MOTIF_WM_AUTOMATION)
1443 * This function needs to pack the necessary info into the
1444 * output data variable to send back to the requesting
1447 GetAutomationData(input,outputType,output,outputLen,outputFmt);
1452 Warning (((char *)GETMESSAGE(56, 8,
1453 "Conversion request made for unknown target type")));
1463 /*************************************<->*************************************
1465 * void WMiConvertCB ( )
1470 * This function is invoked by UTM to handle the convert request
1471 * made by a requesting application.
1476 * This function is set-up as a callback on a drawing area kept on each
1477 * screen. This is done in WmInitWs.c
1479 *************************************<->***********************************/
1485 XtPointer clientData,
1488 XmConvertCallbackStruct *cnv = (XmConvertCallbackStruct *)callData;
1489 Atom _MOTIF_LOSE_SELECTION =
1490 XInternAtom(DISPLAY, "_MOTIF_LOSE_SELECTION", False);
1491 int scr = XScreenNumberOfScreen(XtScreen(w));
1494 /* Check to make sure we're dealing with the right selection.
1496 if (cnv->selection != wmGD.xa_WM[scr])
1498 Warning (((char *)GETMESSAGE(56, 9,
1499 "Conversion request received for unknown selection")));
1503 if (cnv->target == _MOTIF_LOSE_SELECTION)
1505 /* Done with the conversion - free any data used. */
1508 /* Handle a conversion request with parameter data.
1512 WMiConvert (w, cnv->selection, cnv->target,
1513 cnv->parm, cnv->parm_length, cnv->parm_format,
1514 &(cnv->type), &(cnv->value), &(cnv->length), &(cnv->format));
1517 #endif /* !defined(WSM) || defined(MWM_QATS_PROTOCOL) */