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
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 $"
41 #include "WmProperty.h"
42 #include <Xm/AtomMgr.h>
44 #define ValidPropertyList(pcd) ((pcd)->paInitialProperties != NULL)
48 /*************************************<->*************************************
54 * Interns the atoms necessary for OL protocols.
62 *************************************<->***********************************/
67 XmInternAtom (DISPLAY, OL_WIN_ATTR, False);
68 wmGD.xa_OL_DECOR_RESIZE =
69 XmInternAtom (DISPLAY, OL_DECOR_RESIZE, False);
70 wmGD.xa_OL_DECOR_HEADER =
71 XmInternAtom (DISPLAY, OL_DECOR_HEADER, False);
72 wmGD.xa_OL_DECOR_CLOSE =
73 XmInternAtom (DISPLAY, OL_DECOR_CLOSE, False);
74 wmGD.xa_OL_DECOR_PIN =
75 XmInternAtom (DISPLAY, OL_DECOR_PIN, False);
76 wmGD.xa_OL_DECOR_ADD =
77 XmInternAtom (DISPLAY, OL_DECOR_ADD, False);
78 wmGD.xa_OL_DECOR_DEL =
79 XmInternAtom (DISPLAY, OL_DECOR_DEL, False);
81 XmInternAtom (DISPLAY, OL_WT_BASE, False);
82 wmGD.xa_OL_WT_COMMAND =
83 XmInternAtom (DISPLAY, OL_WT_CMD, False);
85 XmInternAtom (DISPLAY, OL_WT_HELP, False);
86 wmGD.xa_OL_WT_NOTICE =
87 XmInternAtom (DISPLAY, OL_WT_NOTICE, False);
89 XmInternAtom (DISPLAY, OL_WT_OTHER, False);
91 XmInternAtom (DISPLAY, OL_PIN_IN, False);
93 XmInternAtom (DISPLAY, OL_PIN_OUT, False);
94 wmGD.xa_OL_MENU_LIMITED =
95 XmInternAtom (DISPLAY, OL_MENU_LIMITED, False);
96 wmGD.xa_OL_MENU_FULL =
97 XmInternAtom (DISPLAY, OL_MENU_FULL, False);
99 } /* END OF FUNCTION InitOLCompat */
103 /*************************************<->*************************************
105 * HasOpenLookHints (pCD)
109 * Returns True if this client has OpenLook hints on it.
113 * pCD = pointer to client data
117 * Returns True if client has the _OL_WIN_ATTR property on it.
119 *************************************<->***********************************/
124 Boolean rval = False;
125 OLWinAttr *property = NULL;
127 if (ValidPropertyList (pCD) &&
128 HasProperty(pCD, wmGD.xa_OL_WIN_ATTR))
132 else if ((property=GetOLWinAttr (pCD)) != NULL)
134 XFree ((char *) property);
140 } /* END OF FUNCTION HasOpenLookHints */
144 /*************************************<->*************************************
150 * Fetches the OLWinAttr property off of the client
154 * pCD = pointer to client data
158 * Returns a pointer to the OLWinAttr property if found and valid.
159 * (Returned data should be freed with XFree())
160 * Returns NULL pointer otherwise.
162 *************************************<->***********************************/
167 Boolean rval = False;
168 OLWinAttr *property = NULL;
172 unsigned long nitems;
173 unsigned long leftover;
176 ret_val = XGetWindowProperty (DISPLAY, pCD->client, wmGD.xa_OL_WIN_ATTR,
178 False, wmGD.xa_OL_WIN_ATTR,
179 &actual_type, &actual_format,
180 &nitems, &leftover, (unsigned char **)&property);
182 if (ret_val != Success)
186 else if ((actual_format != 32) ||
187 (actual_type != wmGD.xa_OL_WIN_ATTR))
190 XFree((char *)property);
194 if (property && (nitems == OLDOLWINATTRLENGTH))
196 /* Old size, convert to new size */
198 * !!! Should use XAlloc() here, but Xlib doesn't
199 * define an inverse function of XFree(). !!!
201 prop_new = (OLWinAttr *) malloc (sizeof(OLWinAttr));
203 prop_new->flags = WA_WINTYPE | WA_MENUTYPE | WA_PINSTATE;
204 prop_new->win_type = ((old_OLWinAttr *)property)->win_type;
205 prop_new->menu_type = ((old_OLWinAttr *)property)->menu_type;
206 prop_new->pin_initial_state =
207 ((old_OLWinAttr *)property)->pin_initial_state;
209 XFree ((char *) property);
213 /* convert pin state for old clients */
214 if (property && (property->flags & WA_PINSTATE))
216 if (property->pin_initial_state == wmGD.xa_OL_PIN_IN)
218 property->pin_initial_state = PIN_IN;
220 else if (property->pin_initial_state == wmGD.xa_OL_PIN_OUT)
222 property->pin_initial_state = PIN_OUT;
228 } /* END OF FUNCTION GetOLWinAttr */
231 /*************************************<->*************************************
233 * GetOLDecorFlags (pCD, property, pDecor)
237 * Fetches the _OL_DECOR_ADD or _OL_DECOR_DEL property off of the
238 * client and returns OL flavored decor flags.
242 * pCD = pointer to client data
243 * property = property to fetch
244 * pDecor = pointer to OL decor flags word
248 * Return = True if property found, False otherwise
249 * *pDecor = OL decor flags if valid property found,
250 * undefined if property not found.
252 *************************************<->***********************************/
257 unsigned long *pDecor)
263 unsigned long nitems;
264 unsigned long leftover;
267 status = XGetWindowProperty (DISPLAY, pCD->client, property,
270 &actual_type, &actual_format,
271 &nitems, &leftover, (unsigned char **)&pAtoms);
273 if ((status != Success) ||
276 (actual_type != XA_ATOM) ||
277 (actual_format != 32))
280 XFree((char *)pAtoms);
288 * We only look for the ones we might be interested in.
289 * Several OL decoration types are ignored.
291 for (i = 0; i < nitems; i++) {
292 if (pAtoms[i] == wmGD.xa_OL_DECOR_RESIZE)
293 *pDecor |= OLDecorResizable;
294 else if (pAtoms[i] == wmGD.xa_OL_DECOR_HEADER)
295 *pDecor |= OLDecorHeader;
296 else if (pAtoms[i] == wmGD.xa_OL_DECOR_CLOSE)
297 *pDecor |= OLDecorCloseButton;
298 else if (pAtoms[i] == wmGD.xa_OL_DECOR_PIN)
299 *pDecor |= OLDecorPushPin;
302 XFree((char *)pAtoms);
308 } /* END OF FUNCTION GetOLDecorFlags */
312 /*************************************<->*************************************
314 * ProcessOLDecoration (pCD)
321 * pCD = pointer to client data
325 * pCD = possibly modified with new decoration info
327 *************************************<->***********************************/
332 OLWinAttr * pOLWinAttr;
333 unsigned long OLdecor;
336 if (HasOpenLookHints (pCD) &&
337 ((pOLWinAttr = GetOLWinAttr (pCD)) != NULL))
340 * This window already has some decoration applied to
341 * it based on its ICCCM type (transient or not).
342 * Use the OL hints to construct a mask to further
343 * modify these decorations.
345 if ((pOLWinAttr->flags & WA_WINTYPE) == 0)
348 * Window type not specified, assume all decorations
350 decorMask = WM_DECOR_ALL;
352 else if (pOLWinAttr->win_type == wmGD.xa_OL_WT_BASE)
355 * Base windows can have all decorations
357 decorMask = WM_DECOR_ALL;
359 else if (pOLWinAttr->win_type == wmGD.xa_OL_WT_COMMAND)
362 * Command windows have titles, pins (close button), and
365 decorMask = WM_DECOR_TITLE | WM_DECOR_SYSTEM | WM_DECOR_RESIZEH;
367 else if (pOLWinAttr->win_type == wmGD.xa_OL_WT_HELP)
370 * Help windows have titles and pins (close button).
371 * No resize, but give it a border to look nicer.
373 decorMask = (WM_DECOR_TITLE | WM_DECOR_SYSTEM | WM_DECOR_BORDER);
375 else if ((pOLWinAttr->win_type == wmGD.xa_OL_WT_NOTICE) &&
376 (pOLWinAttr->win_type == wmGD.xa_OL_WT_OTHER))
378 decorMask = WM_DECOR_NONE;
382 decorMask = WM_DECOR_ALL;
385 if (GetOLDecorAdd(pCD,&OLdecor))
387 if (OLdecor & OLDecorResizable)
389 decorMask |= WM_DECOR_RESIZEH;
391 if (OLdecor & OLDecorHeader)
393 decorMask |= WM_DECOR_TITLE;
395 if (OLdecor & OLDecorCloseButton)
397 /* OL "close" is same as "Motif" minimize */
398 decorMask |= MWM_DECOR_MINIMIZE;
400 if (OLdecor & OLDecorPushPin)
403 * windows with pins can't be minimized
405 decorMask &= ~MWM_DECOR_MINIMIZE;
406 decorMask |= MWM_DECOR_TITLE | MWM_DECOR_MENU;
410 if (GetOLDecorDel(pCD,&OLdecor))
412 if (OLdecor & OLDecorResizable)
414 decorMask &= ~MWM_DECOR_RESIZEH;
416 if (OLdecor & OLDecorHeader)
418 decorMask &= ~WM_DECOR_TITLEBAR;
420 if (OLdecor & OLDecorCloseButton)
422 /* OL "close" is same as "Motif" minimize */
423 decorMask &= ~MWM_DECOR_MINIMIZE;
426 /* push pin is ignored here */
431 * If the window has a push pin or a limited menu,
432 * then consider it very similar to a secondary window.
434 if (((pOLWinAttr->flags & WA_PINSTATE) &&
435 (pOLWinAttr->pin_initial_state == PIN_IN)) ||
436 ((pOLWinAttr->flags & WA_MENUTYPE) &&
437 (pOLWinAttr->menu_type == wmGD.xa_OL_MENU_LIMITED)))
439 decorMask &= ~(MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE);
440 pCD->bPseudoTransient = True;
441 pCD->dtwmFunctions &= ~DtWM_FUNCTION_OCCUPY_WS;
445 * Reduce decoration on this window according to OL hints
447 pCD->clientDecoration &= decorMask;
450 * Reduce client functions if necessary.
452 if (!(decorMask & MWM_DECOR_MINIMIZE))
454 pCD->clientFunctions &= ~MWM_FUNC_MINIMIZE;
456 if (!(decorMask & MWM_DECOR_MAXIMIZE))
458 pCD->clientFunctions &= ~MWM_FUNC_MAXIMIZE;
460 if (!(decorMask & MWM_DECOR_RESIZEH))
462 pCD->clientFunctions &= ~MWM_FUNC_RESIZE;
466 * Set the clients secondariesOnTop value to false to allow
467 * open look transient behaviour (transients below primary).
469 pCD->secondariesOnTop = False;
472 XFree((char *)pOLWinAttr);
475 } /* END OF FUNCTION ProcessOLDecoration */
477 #endif /* NO_OL_COMPAT */