scrsize.c revision 161475
1178825Sdfr/*
2178825Sdfr * Copyright (C) 1984-2004  Mark Nudelman
3178825Sdfr *
4178825Sdfr * You may distribute under the terms of either the GNU General Public
5178825Sdfr * License or the Less License, as specified in the README file.
6178825Sdfr *
7178825Sdfr * For more information about less, or for information on how to
8178825Sdfr * contact the author, see the README file.
9178825Sdfr */
10178825Sdfr
11178825Sdfr/*
12178825Sdfr * This program is used to determine the screen dimensions on OS/2 systems.
13178825Sdfr * Adapted from code written by Kyosuke Tokoro (NBG01720@nifty.ne.jp).
14178825Sdfr */
15178825Sdfr
16178825Sdfr/*
17178825Sdfr * When I wrote this routine, I consulted some part of the source code
18178825Sdfr * of the xwininfo utility by X Consortium.
19178825Sdfr *
20178825Sdfr * Copyright (c) 1987, X Consortium
21178825Sdfr *
22178825Sdfr * Permission is hereby granted, free of charge, to any person obtaining a copy
23178825Sdfr * of this software and associated documentation files (the "Software"), to
24178825Sdfr * deal in the Software without restriction, including without limitation the
25178825Sdfr * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
26178825Sdfr * sell copies of the Software, and to permit persons to whom the Software is
27178825Sdfr * furnished to do so, subject to the following conditions:
28178825Sdfr *
29178825Sdfr * The above copyright notice and this permission notice shall be included in
30178825Sdfr * all copies or substantial portions of the Software.
31178825Sdfr *
32178825Sdfr * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33178825Sdfr * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34178825Sdfr * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
35178825Sdfr * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
36178825Sdfr * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
37178825Sdfr * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38178825Sdfr *
39178825Sdfr * Except as contained in this notice, the name of the X Consortium shall not
40178825Sdfr * be used in advertising or otherwise to promote the sale, use or other
41178825Sdfr * dealings in this Software without prior written authorization from the X
42178825Sdfr * Consortium.
43178825Sdfr */
44178825Sdfr#include <X11/Xlib.h>
45178825Sdfr#include <X11/Xutil.h>
46178825Sdfr#include <stdlib.h>
47178825Sdfr#include <stdio.h>
48178825Sdfr
49178825Sdfrstatic int get_winsize(dpy, window, p_width, p_height)
50178825Sdfr	Display *dpy;
51178825Sdfr	Window window;
52178825Sdfr	int *p_width;
53178825Sdfr	int *p_height;
54178825Sdfr{
55178825Sdfr	XWindowAttributes win_attributes;
56178825Sdfr	XSizeHints hints;
57178825Sdfr	long longjunk;
58178825Sdfr
59178825Sdfr	if (!XGetWindowAttributes(dpy, window, &win_attributes))
60178825Sdfr		return 1;
61178825Sdfr	if (!XGetWMNormalHints(dpy, window, &hints, &longjunk))
62178825Sdfr		return 1;
63178825Sdfr	if (!(hints.flags & PResizeInc))
64178825Sdfr		return 1;
65178825Sdfr	if (hints.width_inc == 0 || hints.height_inc == 0)
66178825Sdfr		return 1;
67178825Sdfr	if (!(hints.flags & (PBaseSize|PMinSize)))
68178825Sdfr		return 1;
69178825Sdfr	if (hints.flags & PBaseSize)
70178825Sdfr	{
71178825Sdfr		win_attributes.width -= hints.base_width;
72178825Sdfr		win_attributes.height -= hints.base_height;
73178825Sdfr	} else
74178825Sdfr	{
75178825Sdfr		win_attributes.width -= hints.min_width;
76178825Sdfr		win_attributes.height -= hints.min_height;
77178825Sdfr	}
78178825Sdfr	*p_width = win_attributes.width / hints.width_inc;
79178825Sdfr	*p_height = win_attributes.height / hints.height_inc;
80178825Sdfr	return 0;
81178825Sdfr}
82178825Sdfr
83178825Sdfrint main(argc, argv)
84178825Sdfr	int argc;
85178825Sdfr	char *argv[];
86178825Sdfr{
87178825Sdfr	char *cp;
88178825Sdfr	Display *dpy;
89178825Sdfr	int size[2];
90178825Sdfr
91178825Sdfr	_scrsize(size);
92178825Sdfr	cp = getenv("WINDOWID");
93178825Sdfr	if (cp != NULL)
94178825Sdfr	{
95178825Sdfr		dpy = XOpenDisplay(NULL);
96178825Sdfr		if (dpy != NULL)
97178825Sdfr		{
98178825Sdfr			get_winsize(dpy, (Window) atol(cp), &size[0], &size[1]);
99178825Sdfr			XCloseDisplay(dpy);
100178825Sdfr		}
101178825Sdfr	}
102178825Sdfr	printf("%i %i\n", size[0], size[1]);
103178825Sdfr	return (0);
104178825Sdfr}
105178825Sdfr