FetchName.c revision 61b2299d
17706df26Smrg/* $Xorg: FetchName.c,v 1.4 2001/02/09 02:03:32 xorgcvs Exp $ */ 27706df26Smrg/* 37706df26Smrg 47706df26SmrgCopyright 1986, 1998 The Open Group 57706df26Smrg 67706df26SmrgPermission to use, copy, modify, distribute, and sell this software and its 77706df26Smrgdocumentation for any purpose is hereby granted without fee, provided that 87706df26Smrgthe above copyright notice appear in all copies and that both that 97706df26Smrgcopyright notice and this permission notice appear in supporting 107706df26Smrgdocumentation. 117706df26Smrg 127706df26SmrgThe above copyright notice and this permission notice shall be included in 137706df26Smrgall copies or substantial portions of the Software. 147706df26Smrg 157706df26SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167706df26SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177706df26SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 187706df26SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 197706df26SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 207706df26SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 217706df26Smrg 227706df26SmrgExcept as contained in this notice, the name of The Open Group shall not be 237706df26Smrgused in advertising or otherwise to promote the sale, use or other dealings 247706df26Smrgin this Software without prior written authorization from The Open Group. 257706df26Smrg 267706df26Smrg*/ 277706df26Smrg 287706df26Smrg#ifdef HAVE_CONFIG_H 297706df26Smrg#include <config.h> 307706df26Smrg#endif 317706df26Smrg#include <X11/Xlibint.h> 327706df26Smrg#include <X11/Xatom.h> 337706df26Smrg#include <X11/Xos.h> 347706df26Smrg#include <stdio.h> 357706df26Smrg 367706df26Smrg 377706df26SmrgStatus XFetchName ( 387706df26Smrg register Display *dpy, 397706df26Smrg Window w, 407706df26Smrg char **name) 417706df26Smrg{ 427706df26Smrg Atom actual_type; 437706df26Smrg int actual_format; 447706df26Smrg unsigned long nitems; 457706df26Smrg unsigned long leftover; 467706df26Smrg unsigned char *data = NULL; 477706df26Smrg if (XGetWindowProperty(dpy, w, XA_WM_NAME, 0L, (long)BUFSIZ, False, XA_STRING, 487706df26Smrg &actual_type, 497706df26Smrg &actual_format, &nitems, &leftover, &data) != Success) { 507706df26Smrg *name = NULL; 517706df26Smrg return (0); 527706df26Smrg } 537706df26Smrg if ( (actual_type == XA_STRING) && (actual_format == 8) ) { 547706df26Smrg 557706df26Smrg /* The data returned by XGetWindowProperty is guarranteed to 567706df26Smrg contain one extra byte that is null terminated to make retrieveing 577706df26Smrg string properties easy. */ 587706df26Smrg 597706df26Smrg *name = (char *)data; 607706df26Smrg return(1); 617706df26Smrg } 627706df26Smrg if (data) Xfree ((char *)data); 637706df26Smrg *name = NULL; 647706df26Smrg return(0); 657706df26Smrg} 667706df26Smrg 677706df26SmrgStatus XGetIconName ( 687706df26Smrg register Display *dpy, 697706df26Smrg Window w, 707706df26Smrg char **icon_name) 717706df26Smrg{ 727706df26Smrg Atom actual_type; 737706df26Smrg int actual_format; 747706df26Smrg unsigned long nitems; 757706df26Smrg unsigned long leftover; 767706df26Smrg unsigned char *data = NULL; 777706df26Smrg if (XGetWindowProperty(dpy, w, XA_WM_ICON_NAME, 0L, (long)BUFSIZ, False, 787706df26Smrg XA_STRING, 797706df26Smrg &actual_type, 807706df26Smrg &actual_format, &nitems, &leftover, &data) != Success) { 817706df26Smrg *icon_name = NULL; 827706df26Smrg return (0); 837706df26Smrg } 847706df26Smrg if ( (actual_type == XA_STRING) && (actual_format == 8) ) { 857706df26Smrg 867706df26Smrg /* The data returned by XGetWindowProperty is guarranteed to 877706df26Smrg contain one extra byte that is null terminated to make retrieveing 887706df26Smrg string properties easy. */ 897706df26Smrg 907706df26Smrg *icon_name = (char*)data; 917706df26Smrg return(1); 927706df26Smrg } 937706df26Smrg if (data) Xfree ((char *)data); 947706df26Smrg *icon_name = NULL; 957706df26Smrg return(0); 967706df26Smrg} 977706df26Smrg