xref: /minix3/external/bsd/less/dist/scrsize.c (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc /*	$NetBSD: scrsize.c,v 1.3 2013/09/04 19:44:21 tron Exp $	*/
2f7cf2976SLionel Sambuc 
3f7cf2976SLionel Sambuc /*
4*84d9c625SLionel Sambuc  * Copyright (C) 1984-2012  Mark Nudelman
5f7cf2976SLionel Sambuc  *
6f7cf2976SLionel Sambuc  * You may distribute under the terms of either the GNU General Public
7f7cf2976SLionel Sambuc  * License or the Less License, as specified in the README file.
8f7cf2976SLionel Sambuc  *
9*84d9c625SLionel Sambuc  * For more information, see the README file.
10f7cf2976SLionel Sambuc  */
11f7cf2976SLionel Sambuc 
12f7cf2976SLionel Sambuc /*
13f7cf2976SLionel Sambuc  * This program is used to determine the screen dimensions on OS/2 systems.
14f7cf2976SLionel Sambuc  * Adapted from code written by Kyosuke Tokoro (NBG01720@nifty.ne.jp).
15f7cf2976SLionel Sambuc  */
16f7cf2976SLionel Sambuc 
17f7cf2976SLionel Sambuc /*
18f7cf2976SLionel Sambuc  * When I wrote this routine, I consulted some part of the source code
19f7cf2976SLionel Sambuc  * of the xwininfo utility by X Consortium.
20f7cf2976SLionel Sambuc  *
21f7cf2976SLionel Sambuc  * Copyright (c) 1987, X Consortium
22f7cf2976SLionel Sambuc  *
23f7cf2976SLionel Sambuc  * Permission is hereby granted, free of charge, to any person obtaining a copy
24f7cf2976SLionel Sambuc  * of this software and associated documentation files (the "Software"), to
25f7cf2976SLionel Sambuc  * deal in the Software without restriction, including without limitation the
26f7cf2976SLionel Sambuc  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
27f7cf2976SLionel Sambuc  * sell copies of the Software, and to permit persons to whom the Software is
28f7cf2976SLionel Sambuc  * furnished to do so, subject to the following conditions:
29f7cf2976SLionel Sambuc  *
30f7cf2976SLionel Sambuc  * The above copyright notice and this permission notice shall be included in
31f7cf2976SLionel Sambuc  * all copies or substantial portions of the Software.
32f7cf2976SLionel Sambuc  *
33f7cf2976SLionel Sambuc  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34f7cf2976SLionel Sambuc  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35f7cf2976SLionel Sambuc  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
36f7cf2976SLionel Sambuc  * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
37f7cf2976SLionel Sambuc  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
38f7cf2976SLionel Sambuc  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39f7cf2976SLionel Sambuc  *
40f7cf2976SLionel Sambuc  * Except as contained in this notice, the name of the X Consortium shall not
41f7cf2976SLionel Sambuc  * be used in advertising or otherwise to promote the sale, use or other
42f7cf2976SLionel Sambuc  * dealings in this Software without prior written authorization from the X
43f7cf2976SLionel Sambuc  * Consortium.
44f7cf2976SLionel Sambuc  */
45f7cf2976SLionel Sambuc #include <X11/Xlib.h>
46f7cf2976SLionel Sambuc #include <X11/Xutil.h>
47f7cf2976SLionel Sambuc #include <stdlib.h>
48f7cf2976SLionel Sambuc #include <stdio.h>
49f7cf2976SLionel Sambuc 
get_winsize(dpy,window,p_width,p_height)50f7cf2976SLionel Sambuc static int get_winsize(dpy, window, p_width, p_height)
51f7cf2976SLionel Sambuc 	Display *dpy;
52f7cf2976SLionel Sambuc 	Window window;
53f7cf2976SLionel Sambuc 	int *p_width;
54f7cf2976SLionel Sambuc 	int *p_height;
55f7cf2976SLionel Sambuc {
56f7cf2976SLionel Sambuc 	XWindowAttributes win_attributes;
57f7cf2976SLionel Sambuc 	XSizeHints hints;
58f7cf2976SLionel Sambuc 	long longjunk;
59f7cf2976SLionel Sambuc 
60f7cf2976SLionel Sambuc 	if (!XGetWindowAttributes(dpy, window, &win_attributes))
61f7cf2976SLionel Sambuc 		return 1;
62f7cf2976SLionel Sambuc 	if (!XGetWMNormalHints(dpy, window, &hints, &longjunk))
63f7cf2976SLionel Sambuc 		return 1;
64f7cf2976SLionel Sambuc 	if (!(hints.flags & PResizeInc))
65f7cf2976SLionel Sambuc 		return 1;
66f7cf2976SLionel Sambuc 	if (hints.width_inc == 0 || hints.height_inc == 0)
67f7cf2976SLionel Sambuc 		return 1;
68f7cf2976SLionel Sambuc 	if (!(hints.flags & (PBaseSize|PMinSize)))
69f7cf2976SLionel Sambuc 		return 1;
70f7cf2976SLionel Sambuc 	if (hints.flags & PBaseSize)
71f7cf2976SLionel Sambuc 	{
72f7cf2976SLionel Sambuc 		win_attributes.width -= hints.base_width;
73f7cf2976SLionel Sambuc 		win_attributes.height -= hints.base_height;
74f7cf2976SLionel Sambuc 	} else
75f7cf2976SLionel Sambuc 	{
76f7cf2976SLionel Sambuc 		win_attributes.width -= hints.min_width;
77f7cf2976SLionel Sambuc 		win_attributes.height -= hints.min_height;
78f7cf2976SLionel Sambuc 	}
79f7cf2976SLionel Sambuc 	*p_width = win_attributes.width / hints.width_inc;
80f7cf2976SLionel Sambuc 	*p_height = win_attributes.height / hints.height_inc;
81f7cf2976SLionel Sambuc 	return 0;
82f7cf2976SLionel Sambuc }
83f7cf2976SLionel Sambuc 
main(argc,argv)84f7cf2976SLionel Sambuc int main(argc, argv)
85f7cf2976SLionel Sambuc 	int argc;
86f7cf2976SLionel Sambuc 	char *argv[];
87f7cf2976SLionel Sambuc {
88f7cf2976SLionel Sambuc 	char *cp;
89f7cf2976SLionel Sambuc 	Display *dpy;
90f7cf2976SLionel Sambuc 	int size[2];
91f7cf2976SLionel Sambuc 
92f7cf2976SLionel Sambuc 	_scrsize(size);
93f7cf2976SLionel Sambuc 	cp = getenv("WINDOWID");
94f7cf2976SLionel Sambuc 	if (cp != NULL)
95f7cf2976SLionel Sambuc 	{
96f7cf2976SLionel Sambuc 		dpy = XOpenDisplay(NULL);
97f7cf2976SLionel Sambuc 		if (dpy != NULL)
98f7cf2976SLionel Sambuc 		{
99f7cf2976SLionel Sambuc 			get_winsize(dpy, (Window) atol(cp), &size[0], &size[1]);
100f7cf2976SLionel Sambuc 			XCloseDisplay(dpy);
101f7cf2976SLionel Sambuc 		}
102f7cf2976SLionel Sambuc 	}
103f7cf2976SLionel Sambuc 	printf("%i %i\n", size[0], size[1]);
104f7cf2976SLionel Sambuc 	return (0);
105f7cf2976SLionel Sambuc }
106