6b206aeaa24125f23c42eaff3fa93df465e43cd3
3 * $Id: xscsize.c,v 1.6 2004/04/08 01:36:29 mdw Exp $
5 * Return X display size to shell script
7 * (c) 1998 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of the Edgeware X tools collection.
14 * X tools is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * X tools is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with X tools; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Header files ------------------------------------------------------*/
37 #include <mLib/mdwopt.h>
38 #include <mLib/quis.h>
40 /*----- Main code ---------------------------------------------------------*/
42 static void version(FILE *fp
)
44 fprintf(fp
, "%s (xtoys version " VERSION
")\n", QUIS
);
47 static void usage(FILE *fp
)
49 fprintf(fp
, "Usage: %s [-bcx] [-d display]\n", QUIS
);
52 int main(int argc
, char *argv
[])
54 const char *display
= 0;
63 /* --- Parse command line options --- */
68 static struct option opt
[] = {
69 { "help", 0, 0, 'h' },
70 { "usage", 0, 0, 'u' },
71 { "version", 0, 0, 'v' },
72 { "display", OPTF_ARGREQ
, 0, 'd' },
73 { "bourne-shell", 0, 0, 'b' },
74 { "c-shell", 0, 0, 'c' },
75 { "export", 0, 0, 'x' },
79 int i
= getopt_long(argc
, argv
, "huv d:bcx", opt
, 0);
89 "Reads the size of the X root window and outputs it in a form suitable\n"
90 "for use as a shell assignment statement, defining variables XWIDTH and\n"
95 "-h, --help Display this help text\n"
96 "-u, --usage Display a short usage summary\n"
97 "-v, --version Display the program's version number\n"
99 "-d, --display=DISPLAY Choose X display to connect to\n"
100 "-b, --bourne-shell Output text suitable for a Bourne shell\n"
101 "-c, --c-shell Output text suitable for a C shell\n"
102 "-x, --export Export the variables into the environment\n",
134 /* --- Sort out the shell type --- *
136 * If the shell name contains the string `csh' then assume it's a C shell.
137 * Otherwise assume it's Bourne. This seems to work in practice.
140 if (!(f
& f_shell
)) {
141 const char *s
= getenv("SHELL");
144 if (strstr(s
, "csh"))
150 if ((f
& f_sh
) && (f
& f_csh
)) {
151 fprintf(stderr
, "xscsize: make your mind up about your shell type\n");
155 /* --- Get the important information --- */
158 Display
*dpy
= XOpenDisplay(display
);
161 fprintf(stderr
, "xscsize: couldn't open display\n");
164 sc
= DefaultScreen(dpy
);
165 wd
= DisplayWidth(dpy
, sc
);
166 ht
= DisplayHeight(dpy
, sc
);
170 /* --- Do the output thing --- */
173 printf("XWIDTH=%lu XHEIGHT=%lu", wd
, ht
);
175 printf("; export XWIDTH XHEIGHT");
179 printf("setenv XWIDTH %lu; setenv XHEIGHT %lu", wd
, ht
);
181 printf("set XWIDTH=%lu XHEIGHT=%lu", wd
, ht
);
190 /*----- That's all, folks -------------------------------------------------*/