2 * Copyright (C) 1984-2019 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, see the README file.
11 * This program is used to determine the screen dimensions on OS/2 systems.
12 * Adapted from code written by Kyosuke Tokoro (NBG01720@nifty.ne.jp).
16 * When I wrote this routine, I consulted some part of the source code
17 * of the xwininfo utility by X Consortium.
19 * Copyright (c) 1987, X Consortium
21 * Permission is hereby granted, free of charge, to any person obtaining a copy
22 * of this software and associated documentation files (the "Software"), to
23 * deal in the Software without restriction, including without limitation the
24 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
25 * sell copies of the Software, and to permit persons to whom the Software is
26 * furnished to do so, subject to the following conditions:
28 * The above copyright notice and this permission notice shall be included in
29 * all copies or substantial portions of the Software.
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34 * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
35 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
36 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 * Except as contained in this notice, the name of the X Consortium shall not
39 * be used in advertising or otherwise to promote the sale, use or other
40 * dealings in this Software without prior written authorization from the X
44 #include <X11/Xutil.h>
48 static int get_winsize(dpy, window, p_width, p_height)
54 XWindowAttributes win_attributes;
58 if (!XGetWindowAttributes(dpy, window, &win_attributes))
60 if (!XGetWMNormalHints(dpy, window, &hints, &longjunk))
62 if (!(hints.flags & PResizeInc))
64 if (hints.width_inc == 0 || hints.height_inc == 0)
66 if (!(hints.flags & (PBaseSize|PMinSize)))
68 if (hints.flags & PBaseSize)
70 win_attributes.width -= hints.base_width;
71 win_attributes.height -= hints.base_height;
74 win_attributes.width -= hints.min_width;
75 win_attributes.height -= hints.min_height;
77 *p_width = win_attributes.width / hints.width_inc;
78 *p_height = win_attributes.height / hints.height_inc;
91 cp = getenv("WINDOWID");
94 dpy = XOpenDisplay(NULL);
97 get_winsize(dpy, (Window) atol(cp), &size[0], &size[1]);
101 printf("%i %i\n", size[0], size[1]);