189019Sps/*
2240121Sdelphij * Copyright (C) 1984-2012  Mark Nudelman
389019Sps *
489019Sps * You may distribute under the terms of either the GNU General Public
589019Sps * License or the Less License, as specified in the README file.
689019Sps *
7240121Sdelphij * For more information, see the README file.
889019Sps */
989019Sps
1089019Sps/*
1189019Sps * This program is used to determine the screen dimensions on OS/2 systems.
1289019Sps * Adapted from code written by Kyosuke Tokoro (NBG01720@nifty.ne.jp).
1389019Sps */
1489019Sps
1589019Sps/*
1689019Sps * When I wrote this routine, I consulted some part of the source code
1789019Sps * of the xwininfo utility by X Consortium.
1889019Sps *
1989019Sps * Copyright (c) 1987, X Consortium
2089019Sps *
2189019Sps * Permission is hereby granted, free of charge, to any person obtaining a copy
2289019Sps * of this software and associated documentation files (the "Software"), to
2389019Sps * deal in the Software without restriction, including without limitation the
2489019Sps * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
2589019Sps * sell copies of the Software, and to permit persons to whom the Software is
2689019Sps * furnished to do so, subject to the following conditions:
2789019Sps *
2889019Sps * The above copyright notice and this permission notice shall be included in
2989019Sps * all copies or substantial portions of the Software.
3089019Sps *
3189019Sps * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3289019Sps * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3389019Sps * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
3489019Sps * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
3589019Sps * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
3689019Sps * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3789019Sps *
3889019Sps * Except as contained in this notice, the name of the X Consortium shall not
3989019Sps * be used in advertising or otherwise to promote the sale, use or other
4089019Sps * dealings in this Software without prior written authorization from the X
4189019Sps * Consortium.
4289019Sps */
4389019Sps#include <X11/Xlib.h>
4489019Sps#include <X11/Xutil.h>
4589019Sps#include <stdlib.h>
4689019Sps#include <stdio.h>
4789019Sps
4889019Spsstatic int get_winsize(dpy, window, p_width, p_height)
4989019Sps	Display *dpy;
5089019Sps	Window window;
5189019Sps	int *p_width;
5289019Sps	int *p_height;
5389019Sps{
5489019Sps	XWindowAttributes win_attributes;
5589019Sps	XSizeHints hints;
5689019Sps	long longjunk;
5789019Sps
5889019Sps	if (!XGetWindowAttributes(dpy, window, &win_attributes))
5989019Sps		return 1;
6089019Sps	if (!XGetWMNormalHints(dpy, window, &hints, &longjunk))
6189019Sps		return 1;
6289019Sps	if (!(hints.flags & PResizeInc))
6389019Sps		return 1;
6489019Sps	if (hints.width_inc == 0 || hints.height_inc == 0)
6589019Sps		return 1;
6689019Sps	if (!(hints.flags & (PBaseSize|PMinSize)))
6789019Sps		return 1;
6889019Sps	if (hints.flags & PBaseSize)
6989019Sps	{
7089019Sps		win_attributes.width -= hints.base_width;
7189019Sps		win_attributes.height -= hints.base_height;
7289019Sps	} else
7389019Sps	{
7489019Sps		win_attributes.width -= hints.min_width;
7589019Sps		win_attributes.height -= hints.min_height;
7689019Sps	}
7789019Sps	*p_width = win_attributes.width / hints.width_inc;
7889019Sps	*p_height = win_attributes.height / hints.height_inc;
7989019Sps	return 0;
8089019Sps}
8189019Sps
8289019Spsint main(argc, argv)
8389019Sps	int argc;
8489019Sps	char *argv[];
8589019Sps{
8689019Sps	char *cp;
8789019Sps	Display *dpy;
8889019Sps	int size[2];
8989019Sps
9089019Sps	_scrsize(size);
9189019Sps	cp = getenv("WINDOWID");
9289019Sps	if (cp != NULL)
9389019Sps	{
9489019Sps		dpy = XOpenDisplay(NULL);
9589019Sps		if (dpy != NULL)
9689019Sps		{
9789019Sps			get_winsize(dpy, (Window) atol(cp), &size[0], &size[1]);
9889019Sps			XCloseDisplay(dpy);
9989019Sps		}
10089019Sps	}
10189019Sps	printf("%i %i\n", size[0], size[1]);
10289019Sps	return (0);
10389019Sps}
104