1
/* $Xorg: SetHints.c,v 1.5 2001/02/09 02:03:36 xorgcvs Exp $ */
3
/***********************************************************
5
Copyright 1987, 1998 The Open Group
7
Permission to use, copy, modify, distribute, and sell this software and its
8
documentation for any purpose is hereby granted without fee, provided that
9
the above copyright notice appear in all copies and that both that
10
copyright notice and this permission notice appear in supporting
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall not be
24
used in advertising or otherwise to promote the sale, use or other dealings
25
in this Software without prior written authorization from The Open Group.
28
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
32
Permission to use, copy, modify, and distribute this software and its
33
documentation for any purpose and without fee is hereby granted,
34
provided that the above copyright notice appear in all copies and that
35
both that copyright notice and this permission notice appear in
36
supporting documentation, and that the name of Digital not be
37
used in advertising or publicity pertaining to distribution of the
38
software without specific, written prior permission.
40
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
41
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
42
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
43
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
44
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
45
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
48
******************************************************************/
49
/* $XFree86: xc/lib/X11/SetHints.c,v 1.4 2001/12/14 19:54:06 dawes Exp $ */
51
#include <X11/Xlibint.h>
52
#include <X11/Xutil.h>
53
#include "Xatomtype.h"
54
#include <X11/Xatom.h>
57
#define safestrlen(s) ((s) ? strlen(s) : 0)
60
XSetSizeHints(dpy, w, hints, property) /* old routine */
67
prop.flags = (hints->flags & (USPosition|USSize|PAllHints));
70
prop.width = hints->width;
71
prop.height = hints->height;
72
prop.minWidth = hints->min_width;
73
prop.minHeight = hints->min_height;
74
prop.maxWidth = hints->max_width;
75
prop.maxHeight = hints->max_height;
76
prop.widthInc = hints->width_inc;
77
prop.heightInc = hints->height_inc;
78
prop.minAspectX = hints->min_aspect.x;
79
prop.minAspectY = hints->min_aspect.y;
80
prop.maxAspectX = hints->max_aspect.x;
81
prop.maxAspectY = hints->max_aspect.y;
82
return XChangeProperty (dpy, w, property, XA_WM_SIZE_HINTS, 32,
83
PropModeReplace, (unsigned char *) &prop,
84
OldNumPropSizeElements);
88
* XSetWMHints sets the property
89
* WM_HINTS type: WM_HINTS format:32
93
XSetWMHints (dpy, w, wmhints)
99
prop.flags = wmhints->flags;
100
prop.input = (wmhints->input == True ? 1 : 0);
101
prop.initialState = wmhints->initial_state;
102
prop.iconPixmap = wmhints->icon_pixmap;
103
prop.iconWindow = wmhints->icon_window;
104
prop.iconX = wmhints->icon_x;
105
prop.iconY = wmhints->icon_y;
106
prop.iconMask = wmhints->icon_mask;
107
prop.windowGroup = wmhints->window_group;
108
return XChangeProperty (dpy, w, XA_WM_HINTS, XA_WM_HINTS, 32,
109
PropModeReplace, (unsigned char *) &prop,
110
NumPropWMHintsElements);
116
* XSetZoomHints sets the property
117
* WM_ZOOM_HINTS type: WM_SIZE_HINTS format: 32
121
XSetZoomHints (dpy, w, zhints)
126
return XSetSizeHints (dpy, w, zhints, XA_WM_ZOOM_HINTS);
131
* XSetNormalHints sets the property
132
* WM_NORMAL_HINTS type: WM_SIZE_HINTS format: 32
136
XSetNormalHints (dpy, w, hints) /* old routine */
141
return XSetSizeHints (dpy, w, hints, XA_WM_NORMAL_HINTS);
147
* Note, the following is one of the few cases were we really do want sizeof
148
* when examining a protocol structure. This is because the XChangeProperty
149
* routine will take care of converting to host to network data structures.
153
XSetIconSizes (dpy, w, list, count)
155
Window w; /* typically, root */
157
int count; /* number of items on the list */
160
xPropIconSize *pp, *prop;
161
#define size_of_the_real_thing sizeof /* avoid grepping screwups */
162
unsigned nbytes = count * size_of_the_real_thing(xPropIconSize);
163
#undef size_of_the_real_thing
164
if ((prop = pp = (xPropIconSize *) Xmalloc (nbytes))) {
165
for (i = 0; i < count; i++) {
166
pp->minWidth = list->min_width;
167
pp->minHeight = list->min_height;
168
pp->maxWidth = list->max_width;
169
pp->maxHeight = list->max_height;
170
pp->widthInc = list->width_inc;
171
pp->heightInc = list->height_inc;
175
XChangeProperty (dpy, w, XA_WM_ICON_SIZE, XA_WM_ICON_SIZE, 32,
176
PropModeReplace, (unsigned char *) prop,
177
count * NumPropIconSizeElements);
178
Xfree ((char *)prop);
184
XSetCommand (dpy, w, argv, argc)
192
register char *buf, *bp;
193
for (i = 0, nbytes = 0; i < argc; i++) {
194
nbytes += safestrlen(argv[i]) + 1;
196
if ((bp = buf = Xmalloc((unsigned) nbytes))) {
197
/* copy arguments into single buffer */
198
for (i = 0; i < argc; i++) {
200
(void) strcpy(bp, argv[i]);
201
bp += strlen(argv[i]) + 1;
206
XChangeProperty (dpy, w, XA_WM_COMMAND, XA_STRING, 8,
207
PropModeReplace, (unsigned char *)buf, nbytes);
213
* XSetStandardProperties sets the following properties:
214
* WM_NAME type: STRING format: 8
215
* WM_ICON_NAME type: STRING format: 8
216
* WM_HINTS type: WM_HINTS format: 32
217
* WM_COMMAND type: STRING
218
* WM_NORMAL_HINTS type: WM_SIZE_HINTS format: 32
222
#if NeedFunctionPrototypes
223
XSetStandardProperties (
225
Window w, /* window to decorate */
226
_Xconst char *name, /* name of application */
227
_Xconst char *icon_string,/* name string for icon */
228
Pixmap icon_pixmap, /* pixmap to use as icon, or None */
229
char **argv, /* command to be used to restart application */
230
int argc, /* count of arguments */
231
XSizeHints *hints) /* size hints for window in its normal state */
233
XSetStandardProperties (dpy, w, name, icon_string, icon_pixmap, argv, argc, hints)
235
Window w; /* window to decorate */
236
char *name; /* name of application */
237
char *icon_string; /* name string for icon */
238
Pixmap icon_pixmap; /* pixmap to use as icon, or None */
239
char **argv; /* command to be used to restart application */
240
int argc; /* count of arguments */
241
XSizeHints *hints; /* size hints for window in its normal state */
247
if (name != NULL) XStoreName (dpy, w, name);
249
if (icon_string != NULL) {
250
XChangeProperty (dpy, w, XA_WM_ICON_NAME, XA_STRING, 8,
251
PropModeReplace, (unsigned char *)icon_string, safestrlen(icon_string));
254
if (icon_pixmap != None) {
255
phints.icon_pixmap = icon_pixmap;
256
phints.flags |= IconPixmapHint;
258
if (argv != NULL) XSetCommand(dpy, w, argv, argc);
260
if (hints != NULL) XSetNormalHints(dpy, w, hints);
262
if (phints.flags != 0) XSetWMHints(dpy, w, &phints);
268
XSetTransientForHint(dpy, w, propWindow)
273
return XChangeProperty(dpy, w, XA_WM_TRANSIENT_FOR, XA_WINDOW, 32,
274
PropModeReplace, (unsigned char *) &propWindow, 1);
278
XSetClassHint(dpy, w, classhint)
281
XClassHint *classhint;
287
len_nm = safestrlen(classhint->res_name);
288
len_cl = safestrlen(classhint->res_class);
289
if ((class_string = s = Xmalloc((unsigned) (len_nm + len_cl + 2)))) {
291
strcpy(s, classhint->res_name);
297
strcpy(s, classhint->res_class);
300
XChangeProperty(dpy, w, XA_WM_CLASS, XA_STRING, 8,
301
PropModeReplace, (unsigned char *) class_string,