winmultiwindowclass.c revision 05b261ec
1/* 2 *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. 3 * 4 *Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files (the 6 *"Software"), to deal in the Software without restriction, including 7 *without limitation the rights to use, copy, modify, merge, publish, 8 *distribute, sublicense, and/or sell copies of the Software, and to 9 *permit persons to whom the Software is furnished to do so, subject to 10 *the following conditions: 11 * 12 *The above copyright notice and this permission notice shall be 13 *included in all copies or substantial portions of the Software. 14 * 15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR 19 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 20 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 * 23 *Except as contained in this notice, the name of the XFree86 Project 24 *shall not be used in advertising or otherwise to promote the sale, use 25 *or other dealings in this Software without prior written authorization 26 *from the XFree86 Project. 27 * 28 * Authors: Earle F. Philhower, III 29 */ 30 31#ifdef HAVE_XWIN_CONFIG_H 32#include <xwin-config.h> 33#endif 34#include <X11/Xatom.h> 35#include "propertyst.h" 36#include "windowstr.h" 37#include "winmultiwindowclass.h" 38#include "win.h" 39 40/* 41 * Local function 42 */ 43 44DEFINE_ATOM_HELPER(AtmWmWindowRole, "WM_WINDOW_ROLE") 45 46 47int 48winMultiWindowGetClassHint (WindowPtr pWin, char **res_name, char **res_class) 49{ 50 struct _Window *pwin; 51 struct _Property *prop; 52 int len_name, len_class; 53 54 if (!pWin || !res_name || !res_class) 55 { 56 ErrorF ("winMultiWindowGetClassHint - pWin, res_name, or res_class was " 57 "NULL\n"); 58 return 0; 59 } 60 61 pwin = (struct _Window*) pWin; 62 63 if (pwin->optional) 64 prop = (struct _Property *) pwin->optional->userProps; 65 else 66 prop = NULL; 67 68 *res_name = *res_class = NULL; 69 70 while (prop) 71 { 72 if (prop->propertyName == XA_WM_CLASS 73 && prop->type == XA_STRING 74 && prop->format == 8 75 && prop->data) 76 { 77 len_name = strlen ((char *) prop->data); 78 79 (*res_name) = malloc (len_name + 1); 80 81 if (!*res_name) 82 { 83 ErrorF ("winMultiWindowGetClassHint - *res_name was NULL\n"); 84 return 0; 85 } 86 87 /* Add one to len_name to allow copying of trailing 0 */ 88 strncpy ((*res_name), prop->data, len_name + 1); 89 90 if (len_name == prop->size) 91 len_name--; 92 93 len_class = strlen (((char *)prop->data) + 1 + len_name); 94 95 (*res_class) = malloc (len_class + 1); 96 97 if (!*res_class) 98 { 99 ErrorF ("winMultiWindowGetClassHint - *res_class was NULL\n"); 100 101 /* Free the previously allocated res_name */ 102 free (*res_name); 103 return 0; 104 } 105 106 strcpy ((*res_class), ((char *)prop->data) + 1 + len_name); 107 108 return 1; 109 } 110 else 111 prop = prop->next; 112 } 113 114 return 0; 115} 116 117 118int 119winMultiWindowGetWMHints (WindowPtr pWin, WinXWMHints *hints) 120{ 121 struct _Window *pwin; 122 struct _Property *prop; 123 124 if (!pWin || !hints) 125 { 126 ErrorF ("winMultiWindowGetWMHints - pWin or hints was NULL\n"); 127 return 0; 128 } 129 130 pwin = (struct _Window*) pWin; 131 132 if (pwin->optional) 133 prop = (struct _Property *) pwin->optional->userProps; 134 else 135 prop = NULL; 136 137 memset (hints, 0, sizeof (WinXWMHints)); 138 139 while (prop) 140 { 141 if (prop->propertyName == XA_WM_HINTS 142 && prop->data) 143 { 144 memcpy (hints, prop->data, sizeof (WinXWMHints)); 145 return 1; 146 } 147 else 148 prop = prop->next; 149 } 150 151 return 0; 152} 153 154 155int 156winMultiWindowGetWindowRole (WindowPtr pWin, char **res_role) 157{ 158 struct _Window *pwin; 159 struct _Property *prop; 160 int len_role; 161 162 if (!pWin || !res_role) 163 return 0; 164 165 pwin = (struct _Window*) pWin; 166 167 if (pwin->optional) 168 prop = (struct _Property *) pwin->optional->userProps; 169 else 170 prop = NULL; 171 172 *res_role = NULL; 173 while (prop) 174 { 175 if (prop->propertyName == AtmWmWindowRole () 176 && prop->type == XA_STRING 177 && prop->format == 8 178 && prop->data) 179 { 180 len_role= prop->size; 181 182 (*res_role) = malloc (len_role + 1); 183 184 if (!*res_role) 185 { 186 ErrorF ("winMultiWindowGetWindowRole - *res_role was NULL\n"); 187 return 0; 188 } 189 190 strncpy ((*res_role), prop->data, len_role); 191 (*res_role)[len_role] = 0; 192 193 return 1; 194 } 195 else 196 prop = prop->next; 197 } 198 199 return 0; 200} 201 202 203int 204winMultiWindowGetWMNormalHints (WindowPtr pWin, WinXSizeHints *hints) 205{ 206 struct _Window *pwin; 207 struct _Property *prop; 208 209 if (!pWin || !hints) 210 { 211 ErrorF ("winMultiWindowGetWMNormalHints - pWin or hints was NULL\n"); 212 return 0; 213 } 214 215 pwin = (struct _Window*) pWin; 216 217 if (pwin->optional) 218 prop = (struct _Property *) pwin->optional->userProps; 219 else 220 prop = NULL; 221 222 memset (hints, 0, sizeof (WinXSizeHints)); 223 224 while (prop) 225 { 226 if (prop->propertyName == XA_WM_NORMAL_HINTS 227 && prop->data) 228 { 229 memcpy (hints, prop->data, sizeof (WinXSizeHints)); 230 return 1; 231 } 232 else 233 prop = prop->next; 234 } 235 236 return 0; 237} 238 239int 240winMultiWindowGetTransientFor (WindowPtr pWin, WindowPtr *ppDaddy) 241{ 242 struct _Window *pwin; 243 struct _Property *prop; 244 245 if (!pWin) 246 { 247 ErrorF ("winMultiWindowGetTransientFor - pWin was NULL\n"); 248 return 0; 249 } 250 251 pwin = (struct _Window*) pWin; 252 253 if (pwin->optional) 254 prop = (struct _Property *) pwin->optional->userProps; 255 else 256 prop = NULL; 257 258 if (ppDaddy) 259 *ppDaddy = NULL; 260 261 while (prop) 262 { 263 if (prop->propertyName == XA_WM_TRANSIENT_FOR) 264 { 265 if (ppDaddy) 266 memcpy (*ppDaddy, prop->data, sizeof (WindowPtr)); 267 return 1; 268 } 269 else 270 prop = prop->next; 271 } 272 273 return 0; 274} 275 276int 277winMultiWindowGetWMName (WindowPtr pWin, char **wmName) 278{ 279 struct _Window *pwin; 280 struct _Property *prop; 281 int len_name; 282 283 if (!pWin || !wmName) 284 { 285 ErrorF ("winMultiWindowGetClassHint - pWin, res_name, or res_class was " 286 "NULL\n"); 287 return 0; 288 } 289 290 pwin = (struct _Window*) pWin; 291 292 if (pwin->optional) 293 prop = (struct _Property *) pwin->optional->userProps; 294 else 295 prop = NULL; 296 297 *wmName = NULL; 298 299 while (prop) 300 { 301 if (prop->propertyName == XA_WM_NAME 302 && prop->type == XA_STRING 303 && prop->data) 304 { 305 len_name = prop->size; 306 307 (*wmName) = malloc (len_name + 1); 308 309 if (!*wmName) 310 { 311 ErrorF ("winMultiWindowGetWMName - *wmName was NULL\n"); 312 return 0; 313 } 314 315 strncpy ((*wmName), prop->data, len_name); 316 (*wmName)[len_name] = 0; 317 318 return 1; 319 } 320 else 321 prop = prop->next; 322 } 323 324 return 0; 325} 326