Initial commit
[xorg_rtime.git] / xorg-server-1.4 / hw / xwin / winmultiwindowclass.c
blob5b47c3976be05f7e98691386fc64991994c33451
1 /*
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>
33 #endif
34 #include <X11/Xatom.h>
35 #include "propertyst.h"
36 #include "windowstr.h"
37 #include "winmultiwindowclass.h"
38 #include "win.h"
41 * Local function
44 DEFINE_ATOM_HELPER(AtmWmWindowRole, "WM_WINDOW_ROLE")
47 int
48 winMultiWindowGetClassHint (WindowPtr pWin, char **res_name, char **res_class)
50 struct _Window *pwin;
51 struct _Property *prop;
52 int len_name, len_class;
54 if (!pWin || !res_name || !res_class)
56 ErrorF ("winMultiWindowGetClassHint - pWin, res_name, or res_class was "
57 "NULL\n");
58 return 0;
61 pwin = (struct _Window*) pWin;
63 if (pwin->optional)
64 prop = (struct _Property *) pwin->optional->userProps;
65 else
66 prop = NULL;
68 *res_name = *res_class = NULL;
70 while (prop)
72 if (prop->propertyName == XA_WM_CLASS
73 && prop->type == XA_STRING
74 && prop->format == 8
75 && prop->data)
77 len_name = strlen ((char *) prop->data);
79 (*res_name) = malloc (len_name + 1);
81 if (!*res_name)
83 ErrorF ("winMultiWindowGetClassHint - *res_name was NULL\n");
84 return 0;
87 /* Add one to len_name to allow copying of trailing 0 */
88 strncpy ((*res_name), prop->data, len_name + 1);
90 if (len_name == prop->size)
91 len_name--;
93 len_class = strlen (((char *)prop->data) + 1 + len_name);
95 (*res_class) = malloc (len_class + 1);
97 if (!*res_class)
99 ErrorF ("winMultiWindowGetClassHint - *res_class was NULL\n");
101 /* Free the previously allocated res_name */
102 free (*res_name);
103 return 0;
106 strcpy ((*res_class), ((char *)prop->data) + 1 + len_name);
108 return 1;
110 else
111 prop = prop->next;
114 return 0;
119 winMultiWindowGetWMHints (WindowPtr pWin, WinXWMHints *hints)
121 struct _Window *pwin;
122 struct _Property *prop;
124 if (!pWin || !hints)
126 ErrorF ("winMultiWindowGetWMHints - pWin or hints was NULL\n");
127 return 0;
130 pwin = (struct _Window*) pWin;
132 if (pwin->optional)
133 prop = (struct _Property *) pwin->optional->userProps;
134 else
135 prop = NULL;
137 memset (hints, 0, sizeof (WinXWMHints));
139 while (prop)
141 if (prop->propertyName == XA_WM_HINTS
142 && prop->data)
144 memcpy (hints, prop->data, sizeof (WinXWMHints));
145 return 1;
147 else
148 prop = prop->next;
151 return 0;
156 winMultiWindowGetWindowRole (WindowPtr pWin, char **res_role)
158 struct _Window *pwin;
159 struct _Property *prop;
160 int len_role;
162 if (!pWin || !res_role)
163 return 0;
165 pwin = (struct _Window*) pWin;
167 if (pwin->optional)
168 prop = (struct _Property *) pwin->optional->userProps;
169 else
170 prop = NULL;
172 *res_role = NULL;
173 while (prop)
175 if (prop->propertyName == AtmWmWindowRole ()
176 && prop->type == XA_STRING
177 && prop->format == 8
178 && prop->data)
180 len_role= prop->size;
182 (*res_role) = malloc (len_role + 1);
184 if (!*res_role)
186 ErrorF ("winMultiWindowGetWindowRole - *res_role was NULL\n");
187 return 0;
190 strncpy ((*res_role), prop->data, len_role);
191 (*res_role)[len_role] = 0;
193 return 1;
195 else
196 prop = prop->next;
199 return 0;
204 winMultiWindowGetWMNormalHints (WindowPtr pWin, WinXSizeHints *hints)
206 struct _Window *pwin;
207 struct _Property *prop;
209 if (!pWin || !hints)
211 ErrorF ("winMultiWindowGetWMNormalHints - pWin or hints was NULL\n");
212 return 0;
215 pwin = (struct _Window*) pWin;
217 if (pwin->optional)
218 prop = (struct _Property *) pwin->optional->userProps;
219 else
220 prop = NULL;
222 memset (hints, 0, sizeof (WinXSizeHints));
224 while (prop)
226 if (prop->propertyName == XA_WM_NORMAL_HINTS
227 && prop->data)
229 memcpy (hints, prop->data, sizeof (WinXSizeHints));
230 return 1;
232 else
233 prop = prop->next;
236 return 0;
240 winMultiWindowGetTransientFor (WindowPtr pWin, WindowPtr *ppDaddy)
242 struct _Window *pwin;
243 struct _Property *prop;
245 if (!pWin)
247 ErrorF ("winMultiWindowGetTransientFor - pWin was NULL\n");
248 return 0;
251 pwin = (struct _Window*) pWin;
253 if (pwin->optional)
254 prop = (struct _Property *) pwin->optional->userProps;
255 else
256 prop = NULL;
258 if (ppDaddy)
259 *ppDaddy = NULL;
261 while (prop)
263 if (prop->propertyName == XA_WM_TRANSIENT_FOR)
265 if (ppDaddy)
266 memcpy (*ppDaddy, prop->data, sizeof (WindowPtr));
267 return 1;
269 else
270 prop = prop->next;
273 return 0;
277 winMultiWindowGetWMName (WindowPtr pWin, char **wmName)
279 struct _Window *pwin;
280 struct _Property *prop;
281 int len_name;
283 if (!pWin || !wmName)
285 ErrorF ("winMultiWindowGetClassHint - pWin, res_name, or res_class was "
286 "NULL\n");
287 return 0;
290 pwin = (struct _Window*) pWin;
292 if (pwin->optional)
293 prop = (struct _Property *) pwin->optional->userProps;
294 else
295 prop = NULL;
297 *wmName = NULL;
299 while (prop)
301 if (prop->propertyName == XA_WM_NAME
302 && prop->type == XA_STRING
303 && prop->data)
305 len_name = prop->size;
307 (*wmName) = malloc (len_name + 1);
309 if (!*wmName)
311 ErrorF ("winMultiWindowGetWMName - *wmName was NULL\n");
312 return 0;
315 strncpy ((*wmName), prop->data, len_name);
316 (*wmName)[len_name] = 0;
318 return 1;
320 else
321 prop = prop->next;
324 return 0;