1/* 2 3Copyright 1987, 1988, 1993, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included 12in all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20OTHER DEALINGS IN THE SOFTWARE. 21 22Except as contained in this notice, the name of The Open Group shall 23not be used in advertising or otherwise to promote the sale, use or 24other dealings in this Software without prior written authorization 25from The Open Group. 26 27*/ 28 29/*********************************************************** 30Copyright 1988 by Wyse Technology, Inc., San Jose, Ca., 31Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, 32 33 All Rights Reserved 34 35Permission to use, copy, modify, and distribute this software and its 36documentation for any purpose and without fee is hereby granted, 37provided that the above copyright notice appear in all copies and that 38both that copyright notice and this permission notice appear in 39supporting documentation, and that the name of Wyse not be 40used in advertising or publicity pertaining to distribution of the 41software without specific, written prior permission. 42 43WYSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 44ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 45DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 46ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 47WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 48ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 49SOFTWARE. 50 51******************************************************************/ 52 53#ifdef HAVE_CONFIG_H 54#include <config.h> 55#endif 56#include <X11/Xlibint.h> 57#include <X11/Xatom.h> 58#include <X11/Xutil.h> 59#include <X11/Xos.h> 60#include <X11/Xlocale.h> 61 62 63/* 64 * XSetWMProperties sets the following properties: 65 * WM_NAME type: TEXT format: varies? 66 * WM_ICON_NAME type: TEXT format: varies? 67 * WM_HINTS type: WM_HINTS format: 32 68 * WM_COMMAND type: TEXT format: varies? 69 * WM_CLIENT_MACHINE type: TEXT format: varies? 70 * WM_NORMAL_HINTS type: WM_SIZE_HINTS format: 32 71 * WM_CLASS type: STRING/STRING format: 8 72 * WM_LOCALE_NAME type: STRING format: 8 73 */ 74 75void XSetWMProperties ( 76 Display *dpy, 77 Window w, /* window to decorate */ 78 XTextProperty *windowName, /* name of application */ 79 XTextProperty *iconName, /* name string for icon */ 80 char **argv, /* command line */ 81 int argc, /* size of command line */ 82 XSizeHints *sizeHints, /* size hints for window in its normal state */ 83 XWMHints *wmHints, /* miscellaneous window manager hints */ 84 XClassHint *classHints) /* resource name and class */ 85{ 86 XTextProperty textprop; 87 char hostName[256]; 88 int len = _XGetHostname (hostName, sizeof hostName); 89 char *locale; 90 91 /* set names of window and icon */ 92 if (windowName) XSetWMName (dpy, w, windowName); 93 if (iconName) XSetWMIconName (dpy, w, iconName); 94 95 /* set the command if given */ 96 if (argv) { 97 /* 98 * for UNIX and other operating systems which use nul-terminated 99 * arrays of STRINGs. 100 */ 101 XSetCommand (dpy, w, argv, argc); 102 } 103 104 /* set the name of the machine on which this application is running */ 105 textprop.value = (unsigned char *) hostName; 106 textprop.encoding = XA_STRING; 107 textprop.format = 8; 108 textprop.nitems = (unsigned long) len; 109 XSetWMClientMachine (dpy, w, &textprop); 110 111 /* set hints about how geometry and window manager interaction */ 112 if (sizeHints) XSetWMNormalHints (dpy, w, sizeHints); 113 if (wmHints) XSetWMHints (dpy, w, wmHints); 114 if (classHints) { 115 XClassHint tmp; 116 117 if (!classHints->res_name) { 118 tmp.res_name = getenv ("RESOURCE_NAME"); 119 if (!tmp.res_name && argv && argv[0]) { 120 /* 121 * UNIX uses /dir/subdir/.../basename; other operating 122 * systems will have to change this. 123 */ 124 char *cp = strrchr (argv[0], '/'); 125 tmp.res_name = (cp ? cp + 1 : argv[0]); 126 } 127 tmp.res_class = classHints->res_class; 128 classHints = &tmp; 129 } 130 XSetClassHint (dpy, w, classHints); 131 } 132 133 locale = setlocale(LC_CTYPE, (char *)NULL); 134 if (locale) 135 XChangeProperty (dpy, w, XInternAtom(dpy, "WM_LOCALE_NAME", False), 136 XA_STRING, 8, PropModeReplace, 137 (unsigned char *)locale, (int) strlen(locale)); 138} 139 140