SetHints.c revision 1ab64890
11ab64890Smrg/* $Xorg: SetHints.c,v 1.5 2001/02/09 02:03:36 xorgcvs Exp $ */ 21ab64890Smrg 31ab64890Smrg/*********************************************************** 41ab64890Smrg 51ab64890SmrgCopyright 1987, 1998 The Open Group 61ab64890Smrg 71ab64890SmrgPermission to use, copy, modify, distribute, and sell this software and its 81ab64890Smrgdocumentation for any purpose is hereby granted without fee, provided that 91ab64890Smrgthe above copyright notice appear in all copies and that both that 101ab64890Smrgcopyright notice and this permission notice appear in supporting 111ab64890Smrgdocumentation. 121ab64890Smrg 131ab64890SmrgThe above copyright notice and this permission notice shall be included in 141ab64890Smrgall copies or substantial portions of the Software. 151ab64890Smrg 161ab64890SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 171ab64890SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 181ab64890SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 191ab64890SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 201ab64890SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 211ab64890SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 221ab64890Smrg 231ab64890SmrgExcept as contained in this notice, the name of The Open Group shall not be 241ab64890Smrgused in advertising or otherwise to promote the sale, use or other dealings 251ab64890Smrgin this Software without prior written authorization from The Open Group. 261ab64890Smrg 271ab64890Smrg 281ab64890SmrgCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. 291ab64890Smrg 301ab64890Smrg All Rights Reserved 311ab64890Smrg 321ab64890SmrgPermission to use, copy, modify, and distribute this software and its 331ab64890Smrgdocumentation for any purpose and without fee is hereby granted, 341ab64890Smrgprovided that the above copyright notice appear in all copies and that 351ab64890Smrgboth that copyright notice and this permission notice appear in 361ab64890Smrgsupporting documentation, and that the name of Digital not be 371ab64890Smrgused in advertising or publicity pertaining to distribution of the 381ab64890Smrgsoftware without specific, written prior permission. 391ab64890Smrg 401ab64890SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 411ab64890SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 421ab64890SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 431ab64890SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 441ab64890SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 451ab64890SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 461ab64890SmrgSOFTWARE. 471ab64890Smrg 481ab64890Smrg******************************************************************/ 491ab64890Smrg/* $XFree86: xc/lib/X11/SetHints.c,v 1.4 2001/12/14 19:54:06 dawes Exp $ */ 501ab64890Smrg 511ab64890Smrg#ifdef HAVE_CONFIG_H 521ab64890Smrg#include <config.h> 531ab64890Smrg#endif 541ab64890Smrg#include <X11/Xlibint.h> 551ab64890Smrg#include <X11/Xutil.h> 561ab64890Smrg#include "Xatomtype.h" 571ab64890Smrg#include <X11/Xatom.h> 581ab64890Smrg#include <X11/Xos.h> 591ab64890Smrg 601ab64890Smrg#define safestrlen(s) ((s) ? strlen(s) : 0) 611ab64890Smrg 621ab64890Smrgint 631ab64890SmrgXSetSizeHints( /* old routine */ 641ab64890Smrg Display *dpy, 651ab64890Smrg Window w, 661ab64890Smrg XSizeHints *hints, 671ab64890Smrg Atom property) 681ab64890Smrg{ 691ab64890Smrg xPropSizeHints prop; 701ab64890Smrg memset(&prop, 0, sizeof(prop)); 711ab64890Smrg prop.flags = (hints->flags & (USPosition|USSize|PAllHints)); 721ab64890Smrg if (hints->flags & (USPosition|PPosition)) { 731ab64890Smrg prop.x = hints->x; 741ab64890Smrg prop.y = hints->y; 751ab64890Smrg } 761ab64890Smrg if (hints->flags & (USSize|PSize)) { 771ab64890Smrg prop.width = hints->width; 781ab64890Smrg prop.height = hints->height; 791ab64890Smrg } 801ab64890Smrg if (hints->flags & PMinSize) { 811ab64890Smrg prop.minWidth = hints->min_width; 821ab64890Smrg prop.minHeight = hints->min_height; 831ab64890Smrg } 841ab64890Smrg if (hints->flags & PMaxSize) { 851ab64890Smrg prop.maxWidth = hints->max_width; 861ab64890Smrg prop.maxHeight = hints->max_height; 871ab64890Smrg } 881ab64890Smrg if (hints->flags & PResizeInc) { 891ab64890Smrg prop.widthInc = hints->width_inc; 901ab64890Smrg prop.heightInc = hints->height_inc; 911ab64890Smrg } 921ab64890Smrg if (hints->flags & PAspect) { 931ab64890Smrg prop.minAspectX = hints->min_aspect.x; 941ab64890Smrg prop.minAspectY = hints->min_aspect.y; 951ab64890Smrg prop.maxAspectX = hints->max_aspect.x; 961ab64890Smrg prop.maxAspectY = hints->max_aspect.y; 971ab64890Smrg } 981ab64890Smrg return XChangeProperty (dpy, w, property, XA_WM_SIZE_HINTS, 32, 991ab64890Smrg PropModeReplace, (unsigned char *) &prop, 1001ab64890Smrg OldNumPropSizeElements); 1011ab64890Smrg} 1021ab64890Smrg 1031ab64890Smrg/* 1041ab64890Smrg * XSetWMHints sets the property 1051ab64890Smrg * WM_HINTS type: WM_HINTS format:32 1061ab64890Smrg */ 1071ab64890Smrg 1081ab64890Smrgint 1091ab64890SmrgXSetWMHints ( 1101ab64890Smrg Display *dpy, 1111ab64890Smrg Window w, 1121ab64890Smrg XWMHints *wmhints) 1131ab64890Smrg{ 1141ab64890Smrg xPropWMHints prop; 1151ab64890Smrg memset(&prop, 0, sizeof(prop)); 1161ab64890Smrg prop.flags = wmhints->flags; 1171ab64890Smrg if (wmhints->flags & InputHint) 1181ab64890Smrg prop.input = (wmhints->input == True ? 1 : 0); 1191ab64890Smrg if (wmhints->flags & StateHint) 1201ab64890Smrg prop.initialState = wmhints->initial_state; 1211ab64890Smrg if (wmhints->flags & IconPixmapHint) 1221ab64890Smrg prop.iconPixmap = wmhints->icon_pixmap; 1231ab64890Smrg if (wmhints->flags & IconWindowHint) 1241ab64890Smrg prop.iconWindow = wmhints->icon_window; 1251ab64890Smrg if (wmhints->flags & IconPositionHint) { 1261ab64890Smrg prop.iconX = wmhints->icon_x; 1271ab64890Smrg prop.iconY = wmhints->icon_y; 1281ab64890Smrg } 1291ab64890Smrg if (wmhints->flags & IconMaskHint) 1301ab64890Smrg prop.iconMask = wmhints->icon_mask; 1311ab64890Smrg if (wmhints->flags & WindowGroupHint) 1321ab64890Smrg prop.windowGroup = wmhints->window_group; 1331ab64890Smrg return XChangeProperty (dpy, w, XA_WM_HINTS, XA_WM_HINTS, 32, 1341ab64890Smrg PropModeReplace, (unsigned char *) &prop, 1351ab64890Smrg NumPropWMHintsElements); 1361ab64890Smrg} 1371ab64890Smrg 1381ab64890Smrg 1391ab64890Smrg 1401ab64890Smrg/* 1411ab64890Smrg * XSetZoomHints sets the property 1421ab64890Smrg * WM_ZOOM_HINTS type: WM_SIZE_HINTS format: 32 1431ab64890Smrg */ 1441ab64890Smrg 1451ab64890Smrgint 1461ab64890SmrgXSetZoomHints ( 1471ab64890Smrg Display *dpy, 1481ab64890Smrg Window w, 1491ab64890Smrg XSizeHints *zhints) 1501ab64890Smrg{ 1511ab64890Smrg return XSetSizeHints (dpy, w, zhints, XA_WM_ZOOM_HINTS); 1521ab64890Smrg} 1531ab64890Smrg 1541ab64890Smrg 1551ab64890Smrg/* 1561ab64890Smrg * XSetNormalHints sets the property 1571ab64890Smrg * WM_NORMAL_HINTS type: WM_SIZE_HINTS format: 32 1581ab64890Smrg */ 1591ab64890Smrg 1601ab64890Smrgint 1611ab64890SmrgXSetNormalHints ( /* old routine */ 1621ab64890Smrg Display *dpy, 1631ab64890Smrg Window w, 1641ab64890Smrg XSizeHints *hints) 1651ab64890Smrg{ 1661ab64890Smrg return XSetSizeHints (dpy, w, hints, XA_WM_NORMAL_HINTS); 1671ab64890Smrg} 1681ab64890Smrg 1691ab64890Smrg 1701ab64890Smrg 1711ab64890Smrg/* 1721ab64890Smrg * Note, the following is one of the few cases were we really do want sizeof 1731ab64890Smrg * when examining a protocol structure. This is because the XChangeProperty 1741ab64890Smrg * routine will take care of converting to host to network data structures. 1751ab64890Smrg */ 1761ab64890Smrg 1771ab64890Smrgint 1781ab64890SmrgXSetIconSizes ( 1791ab64890Smrg Display *dpy, 1801ab64890Smrg Window w, /* typically, root */ 1811ab64890Smrg XIconSize *list, 1821ab64890Smrg int count) /* number of items on the list */ 1831ab64890Smrg{ 1841ab64890Smrg register int i; 1851ab64890Smrg xPropIconSize *pp, *prop; 1861ab64890Smrg#define size_of_the_real_thing sizeof /* avoid grepping screwups */ 1871ab64890Smrg unsigned nbytes = count * size_of_the_real_thing(xPropIconSize); 1881ab64890Smrg#undef size_of_the_real_thing 1891ab64890Smrg if ((prop = pp = (xPropIconSize *) Xmalloc (nbytes))) { 1901ab64890Smrg for (i = 0; i < count; i++) { 1911ab64890Smrg pp->minWidth = list->min_width; 1921ab64890Smrg pp->minHeight = list->min_height; 1931ab64890Smrg pp->maxWidth = list->max_width; 1941ab64890Smrg pp->maxHeight = list->max_height; 1951ab64890Smrg pp->widthInc = list->width_inc; 1961ab64890Smrg pp->heightInc = list->height_inc; 1971ab64890Smrg pp += 1; 1981ab64890Smrg list += 1; 1991ab64890Smrg } 2001ab64890Smrg XChangeProperty (dpy, w, XA_WM_ICON_SIZE, XA_WM_ICON_SIZE, 32, 2011ab64890Smrg PropModeReplace, (unsigned char *) prop, 2021ab64890Smrg count * NumPropIconSizeElements); 2031ab64890Smrg Xfree ((char *)prop); 2041ab64890Smrg } 2051ab64890Smrg return 1; 2061ab64890Smrg} 2071ab64890Smrg 2081ab64890Smrgint 2091ab64890SmrgXSetCommand ( 2101ab64890Smrg Display *dpy, 2111ab64890Smrg Window w, 2121ab64890Smrg char **argv, 2131ab64890Smrg int argc) 2141ab64890Smrg{ 2151ab64890Smrg register int i; 2161ab64890Smrg register int nbytes; 2171ab64890Smrg register char *buf, *bp; 2181ab64890Smrg for (i = 0, nbytes = 0; i < argc; i++) { 2191ab64890Smrg nbytes += safestrlen(argv[i]) + 1; 2201ab64890Smrg } 2211ab64890Smrg if ((bp = buf = Xmalloc((unsigned) nbytes))) { 2221ab64890Smrg /* copy arguments into single buffer */ 2231ab64890Smrg for (i = 0; i < argc; i++) { 2241ab64890Smrg if (argv[i]) { 2251ab64890Smrg (void) strcpy(bp, argv[i]); 2261ab64890Smrg bp += strlen(argv[i]) + 1; 2271ab64890Smrg } 2281ab64890Smrg else 2291ab64890Smrg *bp++ = '\0'; 2301ab64890Smrg } 2311ab64890Smrg XChangeProperty (dpy, w, XA_WM_COMMAND, XA_STRING, 8, 2321ab64890Smrg PropModeReplace, (unsigned char *)buf, nbytes); 2331ab64890Smrg Xfree(buf); 2341ab64890Smrg } 2351ab64890Smrg return 1; 2361ab64890Smrg} 2371ab64890Smrg/* 2381ab64890Smrg * XSetStandardProperties sets the following properties: 2391ab64890Smrg * WM_NAME type: STRING format: 8 2401ab64890Smrg * WM_ICON_NAME type: STRING format: 8 2411ab64890Smrg * WM_HINTS type: WM_HINTS format: 32 2421ab64890Smrg * WM_COMMAND type: STRING 2431ab64890Smrg * WM_NORMAL_HINTS type: WM_SIZE_HINTS format: 32 2441ab64890Smrg */ 2451ab64890Smrg 2461ab64890Smrgint 2471ab64890SmrgXSetStandardProperties ( 2481ab64890Smrg Display *dpy, 2491ab64890Smrg Window w, /* window to decorate */ 2501ab64890Smrg _Xconst char *name, /* name of application */ 2511ab64890Smrg _Xconst char *icon_string,/* name string for icon */ 2521ab64890Smrg Pixmap icon_pixmap, /* pixmap to use as icon, or None */ 2531ab64890Smrg char **argv, /* command to be used to restart application */ 2541ab64890Smrg int argc, /* count of arguments */ 2551ab64890Smrg XSizeHints *hints) /* size hints for window in its normal state */ 2561ab64890Smrg{ 2571ab64890Smrg XWMHints phints; 2581ab64890Smrg phints.flags = 0; 2591ab64890Smrg 2601ab64890Smrg if (name != NULL) XStoreName (dpy, w, name); 2611ab64890Smrg 2621ab64890Smrg if (icon_string != NULL) { 2631ab64890Smrg XChangeProperty (dpy, w, XA_WM_ICON_NAME, XA_STRING, 8, 2641ab64890Smrg PropModeReplace, (unsigned char *)icon_string, safestrlen(icon_string)); 2651ab64890Smrg } 2661ab64890Smrg 2671ab64890Smrg if (icon_pixmap != None) { 2681ab64890Smrg phints.icon_pixmap = icon_pixmap; 2691ab64890Smrg phints.flags |= IconPixmapHint; 2701ab64890Smrg } 2711ab64890Smrg if (argv != NULL) XSetCommand(dpy, w, argv, argc); 2721ab64890Smrg 2731ab64890Smrg if (hints != NULL) XSetNormalHints(dpy, w, hints); 2741ab64890Smrg 2751ab64890Smrg if (phints.flags != 0) XSetWMHints(dpy, w, &phints); 2761ab64890Smrg 2771ab64890Smrg return 1; 2781ab64890Smrg} 2791ab64890Smrg 2801ab64890Smrgint 2811ab64890SmrgXSetTransientForHint( 2821ab64890Smrg Display *dpy, 2831ab64890Smrg Window w, 2841ab64890Smrg Window propWindow) 2851ab64890Smrg{ 2861ab64890Smrg return XChangeProperty(dpy, w, XA_WM_TRANSIENT_FOR, XA_WINDOW, 32, 2871ab64890Smrg PropModeReplace, (unsigned char *) &propWindow, 1); 2881ab64890Smrg} 2891ab64890Smrg 2901ab64890Smrgint 2911ab64890SmrgXSetClassHint( 2921ab64890Smrg Display *dpy, 2931ab64890Smrg Window w, 2941ab64890Smrg XClassHint *classhint) 2951ab64890Smrg{ 2961ab64890Smrg char *class_string; 2971ab64890Smrg char *s; 2981ab64890Smrg int len_nm, len_cl; 2991ab64890Smrg 3001ab64890Smrg len_nm = safestrlen(classhint->res_name); 3011ab64890Smrg len_cl = safestrlen(classhint->res_class); 3021ab64890Smrg if ((class_string = s = Xmalloc((unsigned) (len_nm + len_cl + 2)))) { 3031ab64890Smrg if (len_nm) { 3041ab64890Smrg strcpy(s, classhint->res_name); 3051ab64890Smrg s += len_nm + 1; 3061ab64890Smrg } 3071ab64890Smrg else 3081ab64890Smrg *s++ = '\0'; 3091ab64890Smrg if (len_cl) 3101ab64890Smrg strcpy(s, classhint->res_class); 3111ab64890Smrg else 3121ab64890Smrg *s = '\0'; 3131ab64890Smrg XChangeProperty(dpy, w, XA_WM_CLASS, XA_STRING, 8, 3141ab64890Smrg PropModeReplace, (unsigned char *) class_string, 3151ab64890Smrg len_nm+len_cl+2); 3161ab64890Smrg Xfree(class_string); 3171ab64890Smrg } 3181ab64890Smrg return 1; 3191ab64890Smrg} 320