2 * Copyright (C) 1984-2011 Mark Nudelman
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
7 * For more information about less, or for information on how to
8 * contact the author, see the README file.
12 * This program is used to determine the screen dimensions on OS/2 systems.
13 * Adapted from code written by Kyosuke Tokoro (NBG01720@nifty.ne.jp).
17 * When I wrote this routine, I consulted some part of the source code
18 * of the xwininfo utility by X Consortium.
20 * Copyright (c) 1987, X Consortium
22 * Permission is hereby granted, free of charge, to any person obtaining a copy
23 * of this software and associated documentation files (the "Software"), to
24 * deal in the Software without restriction, including without limitation the
25 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
26 * sell copies of the Software, and to permit persons to whom the Software is
27 * furnished to do so, subject to the following conditions:
29 * The above copyright notice and this permission notice shall be included in
30 * all copies or substantial portions of the Software.
32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35 * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
36 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
37 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 * Except as contained in this notice, the name of the X Consortium shall not
40 * be used in advertising or otherwise to promote the sale, use or other
41 * dealings in this Software without prior written authorization from the X
45 #include <X11/Xutil.h>
49 static int get_winsize(dpy, window, p_width, p_height)
55 XWindowAttributes win_attributes;
59 if (!XGetWindowAttributes(dpy, window, &win_attributes))
61 if (!XGetWMNormalHints(dpy, window, &hints, &longjunk))
63 if (!(hints.flags & PResizeInc))
65 if (hints.width_inc == 0 || hints.height_inc == 0)
67 if (!(hints.flags & (PBaseSize|PMinSize)))
69 if (hints.flags & PBaseSize)
71 win_attributes.width -= hints.base_width;
72 win_attributes.height -= hints.base_height;
75 win_attributes.width -= hints.min_width;
76 win_attributes.height -= hints.min_height;
78 *p_width = win_attributes.width / hints.width_inc;
79 *p_height = win_attributes.height / hints.height_inc;
92 cp = getenv("WINDOWID");
95 dpy = XOpenDisplay(NULL);
98 get_winsize(dpy, (Window) atol(cp), &size[0], &size[1]);
102 printf("%i %i\n", size[0], size[1]);