1 /* $NetBSD: scrsize.c,v 1.3 2013/09/04 19:44:21 tron Exp $ */
4 * Copyright (C) 1984-2012 Mark Nudelman
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Less License, as specified in the README file.
9 * For more information, see the README file.
13 * This program is used to determine the screen dimensions on OS/2 systems.
14 * Adapted from code written by Kyosuke Tokoro (NBG01720@nifty.ne.jp).
18 * When I wrote this routine, I consulted some part of the source code
19 * of the xwininfo utility by X Consortium.
21 * Copyright (c) 1987, X Consortium
23 * Permission is hereby granted, free of charge, to any person obtaining a copy
24 * of this software and associated documentation files (the "Software"), to
25 * deal in the Software without restriction, including without limitation the
26 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
27 * sell copies of the Software, and to permit persons to whom the Software is
28 * furnished to do so, subject to the following conditions:
30 * The above copyright notice and this permission notice shall be included in
31 * all copies or substantial portions of the Software.
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
37 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
38 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 * Except as contained in this notice, the name of the X Consortium shall not
41 * be used in advertising or otherwise to promote the sale, use or other
42 * dealings in this Software without prior written authorization from the X
46 #include <X11/Xutil.h>
50 static int get_winsize(dpy
, window
, p_width
, p_height
)
56 XWindowAttributes win_attributes
;
60 if (!XGetWindowAttributes(dpy
, window
, &win_attributes
))
62 if (!XGetWMNormalHints(dpy
, window
, &hints
, &longjunk
))
64 if (!(hints
.flags
& PResizeInc
))
66 if (hints
.width_inc
== 0 || hints
.height_inc
== 0)
68 if (!(hints
.flags
& (PBaseSize
|PMinSize
)))
70 if (hints
.flags
& PBaseSize
)
72 win_attributes
.width
-= hints
.base_width
;
73 win_attributes
.height
-= hints
.base_height
;
76 win_attributes
.width
-= hints
.min_width
;
77 win_attributes
.height
-= hints
.min_height
;
79 *p_width
= win_attributes
.width
/ hints
.width_inc
;
80 *p_height
= win_attributes
.height
/ hints
.height_inc
;
93 cp
= getenv("WINDOWID");
96 dpy
= XOpenDisplay(NULL
);
99 get_winsize(dpy
, (Window
) atol(cp
), &size
[0], &size
[1]);
103 printf("%i %i\n", size
[0], size
[1]);