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