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
25 * (c) Copyright 1989 Sun Microsystems, Inc.
26 * (c) Copyright 1993 HEWLETT-PACKARD COMPANY
31 static char rcsid[] = "$XConsortium: WmOL.c /main/4 1995/11/01 11:45:08 rswiston $"
40 #include "WmProperty.h"
41 #include <Xm/AtomMgr.h>
43 #define ValidPropertyList(pcd) ((pcd)->paInitialProperties != NULL)
47 /*************************************<->*************************************
53 * Interns the atoms necessary for OL protocols.
61 *************************************<->***********************************/
66 XmInternAtom (DISPLAY, OL_WIN_ATTR, False);
67 wmGD.xa_OL_DECOR_RESIZE =
68 XmInternAtom (DISPLAY, OL_DECOR_RESIZE, False);
69 wmGD.xa_OL_DECOR_HEADER =
70 XmInternAtom (DISPLAY, OL_DECOR_HEADER, False);
71 wmGD.xa_OL_DECOR_CLOSE =
72 XmInternAtom (DISPLAY, OL_DECOR_CLOSE, False);
73 wmGD.xa_OL_DECOR_PIN =
74 XmInternAtom (DISPLAY, OL_DECOR_PIN, False);
75 wmGD.xa_OL_DECOR_ADD =
76 XmInternAtom (DISPLAY, OL_DECOR_ADD, False);
77 wmGD.xa_OL_DECOR_DEL =
78 XmInternAtom (DISPLAY, OL_DECOR_DEL, False);
80 XmInternAtom (DISPLAY, OL_WT_BASE, False);
81 wmGD.xa_OL_WT_COMMAND =
82 XmInternAtom (DISPLAY, OL_WT_CMD, False);
84 XmInternAtom (DISPLAY, OL_WT_HELP, False);
85 wmGD.xa_OL_WT_NOTICE =
86 XmInternAtom (DISPLAY, OL_WT_NOTICE, False);
88 XmInternAtom (DISPLAY, OL_WT_OTHER, False);
90 XmInternAtom (DISPLAY, OL_PIN_IN, False);
92 XmInternAtom (DISPLAY, OL_PIN_OUT, False);
93 wmGD.xa_OL_MENU_LIMITED =
94 XmInternAtom (DISPLAY, OL_MENU_LIMITED, False);
95 wmGD.xa_OL_MENU_FULL =
96 XmInternAtom (DISPLAY, OL_MENU_FULL, False);
98 } /* END OF FUNCTION InitOLCompat */
102 /*************************************<->*************************************
104 * HasOpenLookHints (pCD)
108 * Returns True if this client has OpenLook hints on it.
112 * pCD = pointer to client data
116 * Returns True if client has the _OL_WIN_ATTR property on it.
118 *************************************<->***********************************/
123 Boolean rval = False;
124 OLWinAttr *property = NULL;
126 if (ValidPropertyList (pCD) &&
127 HasProperty(pCD, wmGD.xa_OL_WIN_ATTR))
131 else if ((property=GetOLWinAttr (pCD)) != NULL)
133 XFree ((char *) property);
139 } /* END OF FUNCTION HasOpenLookHints */
143 /*************************************<->*************************************
149 * Fetches the OLWinAttr property off of the client
153 * pCD = pointer to client data
157 * Returns a pointer to the OLWinAttr property if found and valid.
158 * (Returned data should be freed with XFree())
159 * Returns NULL pointer otherwise.
161 *************************************<->***********************************/
166 Boolean rval = False;
167 OLWinAttr *property = NULL;
171 unsigned long nitems;
172 unsigned long leftover;
175 ret_val = XGetWindowProperty (DISPLAY, pCD->client, wmGD.xa_OL_WIN_ATTR,
177 False, wmGD.xa_OL_WIN_ATTR,
178 &actual_type, &actual_format,
179 &nitems, &leftover, (unsigned char **)&property);
181 if (ret_val != Success)
185 else if ((actual_format != 32) ||
186 (actual_type != wmGD.xa_OL_WIN_ATTR))
189 XFree((char *)property);
193 if (property && (nitems == OLDOLWINATTRLENGTH))
195 /* Old size, convert to new size */
197 * !!! Should use XAlloc() here, but Xlib doesn't
198 * define an inverse function of XFree(). !!!
200 prop_new = (OLWinAttr *) malloc (sizeof(OLWinAttr));
202 prop_new->flags = WA_WINTYPE | WA_MENUTYPE | WA_PINSTATE;
203 prop_new->win_type = ((old_OLWinAttr *)property)->win_type;
204 prop_new->menu_type = ((old_OLWinAttr *)property)->menu_type;
205 prop_new->pin_initial_state =
206 ((old_OLWinAttr *)property)->pin_initial_state;
208 XFree ((char *) property);
212 /* convert pin state for old clients */
213 if (property && (property->flags & WA_PINSTATE))
215 if (property->pin_initial_state == wmGD.xa_OL_PIN_IN)
217 property->pin_initial_state = PIN_IN;
219 else if (property->pin_initial_state == wmGD.xa_OL_PIN_OUT)
221 property->pin_initial_state = PIN_OUT;
227 } /* END OF FUNCTION GetOLWinAttr */
230 /*************************************<->*************************************
232 * GetOLDecorFlags (pCD, property, pDecor)
236 * Fetches the _OL_DECOR_ADD or _OL_DECOR_DEL property off of the
237 * client and returns OL flavored decor flags.
241 * pCD = pointer to client data
242 * property = property to fetch
243 * pDecor = pointer to OL decor flags word
247 * Return = True if property found, False otherwise
248 * *pDecor = OL decor flags if valid property found,
249 * undefined if property not found.
251 *************************************<->***********************************/
256 unsigned long *pDecor)
262 unsigned long nitems;
263 unsigned long leftover;
266 status = XGetWindowProperty (DISPLAY, pCD->client, property,
269 &actual_type, &actual_format,
270 &nitems, &leftover, (unsigned char **)&pAtoms);
272 if ((status != Success) ||
275 (actual_type != XA_ATOM) ||
276 (actual_format != 32))
279 XFree((char *)pAtoms);
287 * We only look for the ones we might be interested in.
288 * Several OL decoration types are ignored.
290 for (i = 0; i < nitems; i++) {
291 if (pAtoms[i] == wmGD.xa_OL_DECOR_RESIZE)
292 *pDecor |= OLDecorResizeable;
293 else if (pAtoms[i] == wmGD.xa_OL_DECOR_HEADER)
294 *pDecor |= OLDecorHeader;
295 else if (pAtoms[i] == wmGD.xa_OL_DECOR_CLOSE)
296 *pDecor |= OLDecorCloseButton;
297 else if (pAtoms[i] == wmGD.xa_OL_DECOR_PIN)
298 *pDecor |= OLDecorPushPin;
301 XFree((char *)pAtoms);
307 } /* END OF FUNCTION GetOLDecorFlags */
311 /*************************************<->*************************************
313 * ProcessOLDecoration (pCD)
320 * pCD = pointer to client data
324 * pCD = possibly modified with new decoration info
326 *************************************<->***********************************/
331 OLWinAttr * pOLWinAttr;
332 unsigned long OLdecor;
335 if (HasOpenLookHints (pCD) &&
336 ((pOLWinAttr = GetOLWinAttr (pCD)) != NULL))
339 * This window already has some decoration applied to
340 * it based on its ICCCM type (transient or not).
341 * Use the OL hints to construct a mask to further
342 * modify these decorations.
344 if ((pOLWinAttr->flags & WA_WINTYPE) == 0)
347 * Window type not specified, assume all decorations
349 decorMask = WM_DECOR_ALL;
351 else if (pOLWinAttr->win_type == wmGD.xa_OL_WT_BASE)
354 * Base windows can have all decorations
356 decorMask = WM_DECOR_ALL;
358 else if (pOLWinAttr->win_type == wmGD.xa_OL_WT_COMMAND)
361 * Command windows have titles, pins (close button), and
364 decorMask = WM_DECOR_TITLE | WM_DECOR_SYSTEM | WM_DECOR_RESIZEH;
366 else if (pOLWinAttr->win_type == wmGD.xa_OL_WT_HELP)
369 * Help windows have titles and pins (close button).
370 * No resize, but give it a border to look nicer.
372 decorMask = (WM_DECOR_TITLE | WM_DECOR_SYSTEM | WM_DECOR_BORDER);
374 else if ((pOLWinAttr->win_type == wmGD.xa_OL_WT_NOTICE) &&
375 (pOLWinAttr->win_type == wmGD.xa_OL_WT_OTHER))
377 decorMask = WM_DECOR_NONE;
381 decorMask = WM_DECOR_ALL;
384 if (GetOLDecorAdd(pCD,&OLdecor))
386 if (OLdecor & OLDecorResizeable)
388 decorMask |= WM_DECOR_RESIZEH;
390 if (OLdecor & OLDecorHeader)
392 decorMask |= WM_DECOR_TITLE;
394 if (OLdecor & OLDecorCloseButton)
396 /* OL "close" is same as "Motif" minimize */
397 decorMask |= MWM_DECOR_MINIMIZE;
399 if (OLdecor & OLDecorPushPin)
402 * windows with pins can't be minimized
404 decorMask &= ~MWM_DECOR_MINIMIZE;
405 decorMask |= MWM_DECOR_TITLE | MWM_DECOR_MENU;
409 if (GetOLDecorDel(pCD,&OLdecor))
411 if (OLdecor & OLDecorResizeable)
413 decorMask &= ~MWM_DECOR_RESIZEH;
415 if (OLdecor & OLDecorHeader)
417 decorMask &= ~WM_DECOR_TITLEBAR;
419 if (OLdecor & OLDecorCloseButton)
421 /* OL "close" is same as "Motif" minimize */
422 decorMask &= ~MWM_DECOR_MINIMIZE;
425 /* push pin is ignored here */
430 * If the window has a push pin or a limited menu,
431 * then consider it very similar to a secondary window.
433 if (((pOLWinAttr->flags & WA_PINSTATE) &&
434 (pOLWinAttr->pin_initial_state == PIN_IN)) ||
435 ((pOLWinAttr->flags & WA_MENUTYPE) &&
436 (pOLWinAttr->menu_type == wmGD.xa_OL_MENU_LIMITED)))
438 decorMask &= ~(MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE);
439 pCD->bPseudoTransient = True;
440 pCD->dtwmFunctions &= ~DtWM_FUNCTION_OCCUPY_WS;
444 * Reduce decoration on this window according to OL hints
446 pCD->clientDecoration &= decorMask;
449 * Reduce client functions if necessary.
451 if (!(decorMask & MWM_DECOR_MINIMIZE))
453 pCD->clientFunctions &= ~MWM_FUNC_MINIMIZE;
455 if (!(decorMask & MWM_DECOR_MAXIMIZE))
457 pCD->clientFunctions &= ~MWM_FUNC_MAXIMIZE;
459 if (!(decorMask & MWM_DECOR_RESIZEH))
461 pCD->clientFunctions &= ~MWM_FUNC_RESIZE;
465 * Set the clients secondariesOnTop value to false to allow
466 * open look transient behaviour (transients below primary).
468 pCD->secondariesOnTop = False;
471 XFree((char *)pOLWinAttr);
474 } /* END OF FUNCTION ProcessOLDecoration */
476 #endif /* NO_OL_COMPAT */