Debian Codegraph @

nx-X11/lib/src/GetHints.c

raw
1
2 /***********************************************************
3
4 Copyright 1987, 1998 The Open Group
5
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
10 documentation.
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 Except as contained in this notice, the name of The Open Group shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from The Open Group.
25
26
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28
29 All Rights Reserved
30
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
38
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 SOFTWARE.
46
47 ******************************************************************/
48
49 #ifdef HAVE_CONFIG_H
50 #include <config.h>
51 #endif
52 #include <nx-X11/Xlibint.h>
53 #include <nx-X11/Xos.h>
54 #include <nx-X11/Xutil.h>
55 #include "Xatomtype.h"
56 #include <nx-X11/Xatom.h>
57 #include <stdio.h>
58
59 Status XGetSizeHints (
60 Display *dpy,
61 Window w,
62 XSizeHints *hints,
63 Atom property)
64 {
65 xPropSizeHints *prop = NULL;
66 Atom actual_type;
67 int actual_format;
68 unsigned long leftover;
69 unsigned long nitems;
70 if (XGetWindowProperty(dpy, w, property, 0L,
71 (long) OldNumPropSizeElements,
72 False, XA_WM_SIZE_HINTS, &actual_type, &actual_format,
73 &nitems, &leftover, (unsigned char **)&prop)
74 != Success) return (0);
75
76 if ((actual_type != XA_WM_SIZE_HINTS) ||
77 (nitems < OldNumPropSizeElements) || (actual_format != 32)) {
78 Xfree (prop);
79 return(0);
80 }
81 hints->flags = (prop->flags & (USPosition|USSize|PAllHints));
82 hints->x = cvtINT32toInt (prop->x);
83 hints->y = cvtINT32toInt (prop->y);
84 hints->width = cvtINT32toInt (prop->width);
85 hints->height = cvtINT32toInt (prop->height);
86 hints->min_width = cvtINT32toInt (prop->minWidth);
87 hints->min_height = cvtINT32toInt (prop->minHeight);
88 hints->max_width = cvtINT32toInt (prop->maxWidth);
89 hints->max_height = cvtINT32toInt (prop->maxHeight);
90 hints->width_inc = cvtINT32toInt (prop->widthInc);
91 hints->height_inc = cvtINT32toInt (prop->heightInc);
92 hints->min_aspect.x = cvtINT32toInt (prop->minAspectX);
93 hints->min_aspect.y = cvtINT32toInt (prop->minAspectY);
94 hints->max_aspect.x = cvtINT32toInt (prop->maxAspectX);
95 hints->max_aspect.y = cvtINT32toInt (prop->maxAspectY);
96 Xfree(prop);
97 return(1);
98 }
99
100 /*
101 * must return a pointer to the hint, in malloc'd memory, or routine is not
102 * extensible; any use of the caller's memory would cause things to be stepped
103 * on.
104 */
105
106 XWMHints *XGetWMHints (
107 Display *dpy,
108 Window w)
109 {
110 xPropWMHints *prop = NULL;
111 register XWMHints *hints;
112 Atom actual_type;
113 int actual_format;
114 unsigned long leftover;
115 unsigned long nitems;
116 if (XGetWindowProperty(dpy, w, XA_WM_HINTS,
117 0L, (long)NumPropWMHintsElements,
118 False, XA_WM_HINTS, &actual_type, &actual_format,
119 &nitems, &leftover, (unsigned char **)&prop)
120 != Success) return (NULL);
121
122 /* If the property is undefined on the window, return null pointer. */
123 /* pre-R3 bogusly truncated window_group, don't fail on them */
124
125 if ((actual_type != XA_WM_HINTS) ||
126 (nitems < (NumPropWMHintsElements - 1)) || (actual_format != 32)) {
127 Xfree (prop);
128 return(NULL);
129 }
130 /* static copies not allowed in library, due to reentrancy constraint*/
131 if ((hints = Xcalloc (1, sizeof(XWMHints)))) {
132 hints->flags = prop->flags;
133 hints->input = (prop->input ? True : False);
134 hints->initial_state = cvtINT32toInt (prop->initialState);
135 hints->icon_pixmap = prop->iconPixmap;
136 hints->icon_window = prop->iconWindow;
137 hints->icon_x = cvtINT32toInt (prop->iconX);
138 hints->icon_y = cvtINT32toInt (prop->iconY);
139 hints->icon_mask = prop->iconMask;
140 if (nitems >= NumPropWMHintsElements)
141 hints->window_group = prop->windowGroup;
142 else
143 hints->window_group = 0;
144 }
145 Xfree (prop);
146 return(hints);
147 }
148
149 Status
150 XGetZoomHints (
151 Display *dpy,
152 Window w,
153 XSizeHints *zhints)
154 {
155 return (XGetSizeHints(dpy, w, zhints, XA_WM_ZOOM_HINTS));
156 }
157
158 Status
159 XGetNormalHints (
160 Display *dpy,
161 Window w,
162 XSizeHints *hints)
163 {
164 return (XGetSizeHints(dpy, w, hints, XA_WM_NORMAL_HINTS));
165 }
166
167
168 /*
169 * XGetIconSizes reads the property
170 * ICONSIZE_ATOM type: ICONSIZE_ATOM format: 32
171 */
172
173 Status XGetIconSizes (
174 Display *dpy,
175 Window w, /* typically, root */
176 XIconSize **size_list, /* RETURN */
177 int *count) /* RETURN number of items on the list */
178 {
179 xPropIconSize *prop = NULL;
180 register xPropIconSize *pp;
181 register XIconSize *hp, *hints;
182 Atom actual_type;
183 int actual_format;
184 unsigned long leftover;
185 unsigned long nitems;
186 register int i;
187
188 if (XGetWindowProperty(dpy, w, XA_WM_ICON_SIZE, 0L, 60L,
189 False, XA_WM_ICON_SIZE, &actual_type, &actual_format,
190 &nitems, &leftover, (unsigned char **)&prop)
191 != Success) return (0);
192
193 pp = prop;
194
195 if ((actual_type != XA_WM_ICON_SIZE) ||
196 (nitems < NumPropIconSizeElements) ||
197 (nitems % NumPropIconSizeElements != 0) ||
198 (actual_format != 32)) {
199 Xfree (prop);
200 return(0);
201 }
202
203 /* static copies not allowed in library, due to reentrancy constraint*/
204
205 nitems /= NumPropIconSizeElements;
206 if (! (hp = hints = Xcalloc (nitems, sizeof(XIconSize)))) {
207 Xfree (prop);
208 return 0;
209 }
210
211 /* march down array putting things into native form */
212 for (i = 0; i < nitems; i++) {
213 hp->min_width = cvtINT32toInt (pp->minWidth);
214 hp->min_height = cvtINT32toInt (pp->minHeight);
215 hp->max_width = cvtINT32toInt (pp->maxWidth);
216 hp->max_height = cvtINT32toInt (pp->maxHeight);
217 hp->width_inc = cvtINT32toInt (pp->widthInc);
218 hp->height_inc = cvtINT32toInt (pp->heightInc);
219 hp += 1;
220 pp += 1;
221 }
222 *count = nitems;
223 *size_list = hints;
224 Xfree (prop);
225 return(1);
226 }
227
228
229 Status XGetCommand (
230 Display *dpy,
231 Window w,
232 char ***argvp,
233 int *argcp)
234 {
235 XTextProperty tp;
236 int argc;
237 char **argv;
238
239 if (!XGetTextProperty (dpy, w, &tp, XA_WM_COMMAND)) return 0;
240
241 if (tp.encoding != XA_STRING || tp.format != 8) {
242 Xfree (tp.value);
243 return 0;
244 }
245
246
247 /*
248 * ignore final <NUL> if present since UNIX WM_COMMAND is nul-terminated
249 */
250 if (tp.nitems && (tp.value[tp.nitems - 1] == '\0')) tp.nitems--;
251
252
253 /*
254 * create a string list and return if successful
255 */
256 if (!XTextPropertyToStringList (&tp, &argv, &argc)) {
257 Xfree (tp.value);
258 return (0);
259 }
260
261 Xfree (tp.value);
262 *argvp = argv;
263 *argcp = argc;
264 return 1;
265 }
266
267
268 Status
269 XGetTransientForHint(
270 Display *dpy,
271 Window w,
272 Window *propWindow)
273 {
274 Atom actual_type;
275 int actual_format;
276 unsigned long nitems;
277 unsigned long leftover;
278 Window *data = NULL;
279 if (XGetWindowProperty(dpy, w, XA_WM_TRANSIENT_FOR, 0L, 1L, False,
280 XA_WINDOW,
281 &actual_type,
282 &actual_format, &nitems, &leftover, (unsigned char **) &data)
283 != Success) {
284 *propWindow = None;
285 return (0);
286 }
287 if ( (actual_type == XA_WINDOW) && (actual_format == 32) &&
288 (nitems != 0) ) {
289 *propWindow = *data;
290 Xfree( (char *) data);
291 return (1);
292 }
293 *propWindow = None;
294 Xfree( (char *) data);
295 return(0);
296 }
297
298 Status
299 XGetClassHint(
300 Display *dpy,
301 Window w,
302 XClassHint *classhint) /* RETURN */
303 {
304 int len_name, len_class;
305
306 Atom actual_type;
307 int actual_format;
308 unsigned long nitems;
309 unsigned long leftover;
310 unsigned char *data = NULL;
311 if (XGetWindowProperty(dpy, w, XA_WM_CLASS, 0L, (long)BUFSIZ, False,
312 XA_STRING,
313 &actual_type,
314 &actual_format, &nitems, &leftover, &data) != Success)
315 return (0);
316
317 if ( (actual_type == XA_STRING) && (actual_format == 8) ) {
318 len_name = (int) strlen((char *) data);
319 if (! (classhint->res_name = Xmalloc(len_name + 1))) {
320 Xfree(data);
321 return (0);
322 }
323 strcpy(classhint->res_name, (char *) data);
324 if (len_name == nitems) len_name--;
325 len_class = (int) strlen((char *) (data+len_name+1));
326 if (! (classhint->res_class = Xmalloc(len_class + 1))) {
327 Xfree(classhint->res_name);
328 classhint->res_name = (char *) NULL;
329 Xfree(data);
330 return (0);
331 }
332 strcpy(classhint->res_class, (char *) (data+len_name+1));
333 Xfree( (char *) data);
334 return(1);
335 }
336 Xfree( (char *) data);
337 return(0);
338 }