2 *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
4 *Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 *"Software"), to deal in the Software without restriction, including
7 *without limitation the rights to use, copy, modify, merge, publish,
8 *distribute, sublicense, and/or sell copies of the Software, and to
9 *permit persons to whom the Software is furnished to do so, subject to
10 *the following conditions:
12 *The above copyright notice and this permission notice shall be
13 *included in all copies or substantial portions of the Software.
15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
19 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *Except as contained in this notice, the name of the XFree86 Project
24 *shall not be used in advertising or otherwise to promote the sale, use
25 *or other dealings in this Software without prior written authorization
26 *from the XFree86 Project.
28 * Authors: Earle F. Philhower, III
31 #ifdef HAVE_XWIN_CONFIG_H
32 #include <xwin-config.h>
34 #include <X11/Xatom.h>
35 #include "propertyst.h"
36 #include "windowstr.h"
37 #include "winmultiwindowclass.h"
44 DEFINE_ATOM_HELPER(AtmWmWindowRole
, "WM_WINDOW_ROLE")
47 winMultiWindowGetClassHint(WindowPtr pWin
, char **res_name
, char **res_class
)
50 struct _Property
*prop
;
51 int len_name
, len_class
;
53 if (!pWin
|| !res_name
|| !res_class
) {
54 ErrorF("winMultiWindowGetClassHint - pWin, res_name, or res_class was "
59 pwin
= (struct _Window
*) pWin
;
62 prop
= (struct _Property
*) pwin
->optional
->userProps
;
66 *res_name
= *res_class
= NULL
;
69 if (prop
->propertyName
== XA_WM_CLASS
70 && prop
->type
== XA_STRING
&& prop
->format
== 8 && prop
->data
) {
72 WM_CLASS property should consist of 2 null terminated strings, but we
73 must handle the cases when one or both is absent or not null terminated
75 len_name
= strlen((char *) prop
->data
);
76 if (len_name
> prop
->size
) len_name
= prop
->size
;
78 (*res_name
) = malloc(len_name
+ 1);
81 ErrorF("winMultiWindowGetClassHint - *res_name was NULL\n");
85 /* Copy name and ensure null terminated */
86 strncpy((*res_name
), prop
->data
, len_name
);
87 (*res_name
)[len_name
] = '\0';
89 /* Compute length of class name, it could be that it is absent or not null terminated */
90 len_class
= (len_name
>= prop
->size
) ? 0 : (strlen(((char *) prop
->data
) + 1 + len_name
));
91 if (len_class
> prop
->size
- 1 - len_name
) len_class
= prop
->size
- 1 - len_name
;
93 (*res_class
) = malloc(len_class
+ 1);
96 ErrorF("winMultiWindowGetClassHint - *res_class was NULL\n");
98 /* Free the previously allocated res_name */
103 /* Copy class name and ensure null terminated */
104 strncpy((*res_class
), ((char *) prop
->data
) + 1 + len_name
, len_class
);
105 (*res_class
)[len_class
] = '\0';
117 winMultiWindowGetWMHints(WindowPtr pWin
, WinXWMHints
* hints
)
119 struct _Window
*pwin
;
120 struct _Property
*prop
;
122 if (!pWin
|| !hints
) {
123 ErrorF("winMultiWindowGetWMHints - pWin or hints was NULL\n");
127 pwin
= (struct _Window
*) pWin
;
130 prop
= (struct _Property
*) pwin
->optional
->userProps
;
134 memset(hints
, 0, sizeof(WinXWMHints
));
137 if (prop
->propertyName
== XA_WM_HINTS
&& prop
->data
) {
138 memcpy(hints
, prop
->data
, sizeof(WinXWMHints
));
149 winMultiWindowGetWindowRole(WindowPtr pWin
, char **res_role
)
151 struct _Window
*pwin
;
152 struct _Property
*prop
;
155 if (!pWin
|| !res_role
)
158 pwin
= (struct _Window
*) pWin
;
161 prop
= (struct _Property
*) pwin
->optional
->userProps
;
167 if (prop
->propertyName
== AtmWmWindowRole()
168 && prop
->type
== XA_STRING
&& prop
->format
== 8 && prop
->data
) {
169 len_role
= prop
->size
;
171 (*res_role
) = malloc(len_role
+ 1);
174 ErrorF("winMultiWindowGetWindowRole - *res_role was NULL\n");
178 strncpy((*res_role
), prop
->data
, len_role
);
179 (*res_role
)[len_role
] = 0;
191 winMultiWindowGetWMNormalHints(WindowPtr pWin
, WinXSizeHints
* hints
)
193 struct _Window
*pwin
;
194 struct _Property
*prop
;
196 if (!pWin
|| !hints
) {
197 ErrorF("winMultiWindowGetWMNormalHints - pWin or hints was NULL\n");
201 pwin
= (struct _Window
*) pWin
;
204 prop
= (struct _Property
*) pwin
->optional
->userProps
;
208 memset(hints
, 0, sizeof(WinXSizeHints
));
211 if (prop
->propertyName
== XA_WM_NORMAL_HINTS
&& prop
->data
) {
212 memcpy(hints
, prop
->data
, sizeof(WinXSizeHints
));
223 winMultiWindowGetTransientFor(WindowPtr pWin
, Window
*pDaddyId
)
225 struct _Window
*pwin
;
226 struct _Property
*prop
;
229 ErrorF("winMultiWindowGetTransientFor - pWin was NULL\n");
233 pwin
= (struct _Window
*) pWin
;
236 prop
= (struct _Property
*) pwin
->optional
->userProps
;
244 if (prop
->propertyName
== XA_WM_TRANSIENT_FOR
) {
246 memcpy(pDaddyId
, prop
->data
, sizeof(Window
));
257 winMultiWindowGetWMName(WindowPtr pWin
, char **wmName
)
259 struct _Window
*pwin
;
260 struct _Property
*prop
;
263 if (!pWin
|| !wmName
) {
264 ErrorF("winMultiWindowGetClassHint - pWin, res_name, or res_class was "
269 pwin
= (struct _Window
*) pWin
;
272 prop
= (struct _Property
*) pwin
->optional
->userProps
;
279 if (prop
->propertyName
== XA_WM_NAME
280 && prop
->type
== XA_STRING
&& prop
->data
) {
281 len_name
= prop
->size
;
283 (*wmName
) = malloc(len_name
+ 1);
286 ErrorF("winMultiWindowGetWMName - *wmName was NULL\n");
290 strncpy((*wmName
), prop
->data
, len_name
);
291 (*wmName
)[len_name
] = 0;