diff options
author | delphij <delphij@FreeBSD.org> | 2009-05-08 23:34:35 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2009-05-08 23:34:35 +0000 |
commit | d069efd47cacc3156036ed37d5532d6a1d4f55c3 (patch) | |
tree | 2526f6b109843b646672c1537476dc51e56c0454 /scrsize.c | |
parent | 6aa3e25391d160482339ee072c010bcd22dfbbd1 (diff) | |
download | FreeBSD-src-d069efd47cacc3156036ed37d5532d6a1d4f55c3.zip FreeBSD-src-d069efd47cacc3156036ed37d5532d6a1d4f55c3.tar.gz |
Flatten all tags of the dist tree of less.
Diffstat (limited to 'scrsize.c')
-rw-r--r-- | scrsize.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/scrsize.c b/scrsize.c new file mode 100644 index 0000000..45cf20a --- /dev/null +++ b/scrsize.c @@ -0,0 +1,104 @@ +/* + * Copyright (C) 1984-2007 Mark Nudelman + * + * You may distribute under the terms of either the GNU General Public + * License or the Less License, as specified in the README file. + * + * For more information about less, or for information on how to + * contact the author, see the README file. + */ + +/* + * This program is used to determine the screen dimensions on OS/2 systems. + * Adapted from code written by Kyosuke Tokoro (NBG01720@nifty.ne.jp). + */ + +/* + * When I wrote this routine, I consulted some part of the source code + * of the xwininfo utility by X Consortium. + * + * Copyright (c) 1987, X Consortium + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of the X Consortium shall not + * be used in advertising or otherwise to promote the sale, use or other + * dealings in this Software without prior written authorization from the X + * Consortium. + */ +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <stdlib.h> +#include <stdio.h> + +static int get_winsize(dpy, window, p_width, p_height) + Display *dpy; + Window window; + int *p_width; + int *p_height; +{ + XWindowAttributes win_attributes; + XSizeHints hints; + long longjunk; + + if (!XGetWindowAttributes(dpy, window, &win_attributes)) + return 1; + if (!XGetWMNormalHints(dpy, window, &hints, &longjunk)) + return 1; + if (!(hints.flags & PResizeInc)) + return 1; + if (hints.width_inc == 0 || hints.height_inc == 0) + return 1; + if (!(hints.flags & (PBaseSize|PMinSize))) + return 1; + if (hints.flags & PBaseSize) + { + win_attributes.width -= hints.base_width; + win_attributes.height -= hints.base_height; + } else + { + win_attributes.width -= hints.min_width; + win_attributes.height -= hints.min_height; + } + *p_width = win_attributes.width / hints.width_inc; + *p_height = win_attributes.height / hints.height_inc; + return 0; +} + +int main(argc, argv) + int argc; + char *argv[]; +{ + char *cp; + Display *dpy; + int size[2]; + + _scrsize(size); + cp = getenv("WINDOWID"); + if (cp != NULL) + { + dpy = XOpenDisplay(NULL); + if (dpy != NULL) + { + get_winsize(dpy, (Window) atol(cp), &size[0], &size[1]); + XCloseDisplay(dpy); + } + } + printf("%i %i\n", size[0], size[1]); + return (0); +} |