scrsize.c (2672B)
1 /* 2 * Copyright (c) 1999, NBG01720@nifty.ne.jp 3 * 4 * To compile this program: 5 * gcc -D__ST_MT_ERRNO__ -O2 -s -Zomf -Zmtd -lX11 scrsize.c 6 * 7 * When I wrote this routine, I consulted some part of the source code of the 8 * xwininfo utility by X Consortium. 9 * 10 * Copyright (c) 1987, X Consortium 11 * 12 * Permission is hereby granted, free of charge, to any person obtaining a copy 13 * of this software and associated documentation files (the "Software"), to 14 * deal in the Software without restriction, including without limitation the 15 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16 * sell copies of the Software, and to permit persons to whom the Software is 17 * furnished to do so, subject to the following conditions: 18 * 19 * The above copyright notice and this permission notice shall be included in 20 * all copies or substantial portions of the Software. 21 * 22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 * 29 * Except as contained in this notice, the name of the X Consortium shall not 30 * be used in advertising or otherwise to promote the sale, use or other 31 * dealings in this Software without prior written authorization from the X 32 * Consortium. 33 */ 34 #include <X11/Xlib.h> 35 #include <X11/Xutil.h> 36 #include <stdlib.h> 37 #include <stdio.h> 38 39 int 40 main() 41 { 42 char *cp; 43 Display *dpy; 44 Window window; 45 XWindowAttributes win_attributes; 46 XSizeHints hints; 47 long longjunk; 48 int dst[2]; 49 50 _scrsize(dst); 51 cp = getenv("WINDOWID"); 52 if (cp) { 53 dpy = XOpenDisplay(NULL); 54 if (dpy) { 55 if (XGetWindowAttributes(dpy, window = atol(cp), &win_attributes)) 56 if (XGetWMNormalHints(dpy, window, &hints, &longjunk)) 57 if (hints.flags & PResizeInc && hints.width_inc 58 && hints.height_inc) { 59 if (hints.flags & (PBaseSize | PMinSize)) { 60 if (hints.flags & PBaseSize) { 61 win_attributes.width -= hints.base_width; 62 win_attributes.height -= hints.base_height; 63 } 64 else { 65 win_attributes.width -= hints.min_width; 66 win_attributes.height -= hints.min_height; 67 } 68 } 69 dst[0] = win_attributes.width / hints.width_inc; 70 dst[1] = win_attributes.height / hints.height_inc; 71 } 72 XCloseDisplay(dpy); 73 } 74 } 75 printf("%i %i\n", dst[0], dst[1]); 76 return 0; 77 }