1*20006a0bStron /* $NetBSD */ 2*20006a0bStron 3*20006a0bStron /* 4*20006a0bStron * Copyright (C) 1984-2011 Mark Nudelman 5*20006a0bStron * 6*20006a0bStron * You may distribute under the terms of either the GNU General Public 7*20006a0bStron * License or the Less License, as specified in the README file. 8*20006a0bStron * 9*20006a0bStron * For more information about less, or for information on how to 10*20006a0bStron * contact the author, see the README file. 11*20006a0bStron */ 12*20006a0bStron 13*20006a0bStron /* 14*20006a0bStron * This program is used to determine the screen dimensions on OS/2 systems. 15*20006a0bStron * Adapted from code written by Kyosuke Tokoro (NBG01720@nifty.ne.jp). 16*20006a0bStron */ 17*20006a0bStron 18*20006a0bStron /* 19*20006a0bStron * When I wrote this routine, I consulted some part of the source code 20*20006a0bStron * of the xwininfo utility by X Consortium. 21*20006a0bStron * 22*20006a0bStron * Copyright (c) 1987, X Consortium 23*20006a0bStron * 24*20006a0bStron * Permission is hereby granted, free of charge, to any person obtaining a copy 25*20006a0bStron * of this software and associated documentation files (the "Software"), to 26*20006a0bStron * deal in the Software without restriction, including without limitation the 27*20006a0bStron * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 28*20006a0bStron * sell copies of the Software, and to permit persons to whom the Software is 29*20006a0bStron * furnished to do so, subject to the following conditions: 30*20006a0bStron * 31*20006a0bStron * The above copyright notice and this permission notice shall be included in 32*20006a0bStron * all copies or substantial portions of the Software. 33*20006a0bStron * 34*20006a0bStron * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 35*20006a0bStron * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 36*20006a0bStron * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 37*20006a0bStron * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 38*20006a0bStron * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 39*20006a0bStron * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 40*20006a0bStron * 41*20006a0bStron * Except as contained in this notice, the name of the X Consortium shall not 42*20006a0bStron * be used in advertising or otherwise to promote the sale, use or other 43*20006a0bStron * dealings in this Software without prior written authorization from the X 44*20006a0bStron * Consortium. 45*20006a0bStron */ 46*20006a0bStron #include <X11/Xlib.h> 47*20006a0bStron #include <X11/Xutil.h> 48*20006a0bStron #include <stdlib.h> 49*20006a0bStron #include <stdio.h> 50*20006a0bStron 51*20006a0bStron static int get_winsize(dpy, window, p_width, p_height) 52*20006a0bStron Display *dpy; 53*20006a0bStron Window window; 54*20006a0bStron int *p_width; 55*20006a0bStron int *p_height; 56*20006a0bStron { 57*20006a0bStron XWindowAttributes win_attributes; 58*20006a0bStron XSizeHints hints; 59*20006a0bStron long longjunk; 60*20006a0bStron 61*20006a0bStron if (!XGetWindowAttributes(dpy, window, &win_attributes)) 62*20006a0bStron return 1; 63*20006a0bStron if (!XGetWMNormalHints(dpy, window, &hints, &longjunk)) 64*20006a0bStron return 1; 65*20006a0bStron if (!(hints.flags & PResizeInc)) 66*20006a0bStron return 1; 67*20006a0bStron if (hints.width_inc == 0 || hints.height_inc == 0) 68*20006a0bStron return 1; 69*20006a0bStron if (!(hints.flags & (PBaseSize|PMinSize))) 70*20006a0bStron return 1; 71*20006a0bStron if (hints.flags & PBaseSize) 72*20006a0bStron { 73*20006a0bStron win_attributes.width -= hints.base_width; 74*20006a0bStron win_attributes.height -= hints.base_height; 75*20006a0bStron } else 76*20006a0bStron { 77*20006a0bStron win_attributes.width -= hints.min_width; 78*20006a0bStron win_attributes.height -= hints.min_height; 79*20006a0bStron } 80*20006a0bStron *p_width = win_attributes.width / hints.width_inc; 81*20006a0bStron *p_height = win_attributes.height / hints.height_inc; 82*20006a0bStron return 0; 83*20006a0bStron } 84*20006a0bStron 85*20006a0bStron int main(argc, argv) 86*20006a0bStron int argc; 87*20006a0bStron char *argv[]; 88*20006a0bStron { 89*20006a0bStron char *cp; 90*20006a0bStron Display *dpy; 91*20006a0bStron int size[2]; 92*20006a0bStron 93*20006a0bStron _scrsize(size); 94*20006a0bStron cp = getenv("WINDOWID"); 95*20006a0bStron if (cp != NULL) 96*20006a0bStron { 97*20006a0bStron dpy = XOpenDisplay(NULL); 98*20006a0bStron if (dpy != NULL) 99*20006a0bStron { 100*20006a0bStron get_winsize(dpy, (Window) atol(cp), &size[0], &size[1]); 101*20006a0bStron XCloseDisplay(dpy); 102*20006a0bStron } 103*20006a0bStron } 104*20006a0bStron printf("%i %i\n", size[0], size[1]); 105*20006a0bStron return (0); 106*20006a0bStron } 107