1 /***********************************************************
3 Copyright 1987, 1988, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
26 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
46 ******************************************************************/
49 * Kitchen sink version, useful for clearing small areas and flashing the
57 #include <X11/Xutil.h>
63 static char *ProgramName;
68 fprintf (stderr, "usage: %s [-options] [geometry] [display]\n\n",
70 fprintf (stderr, "where the available options are:\n");
71 fprintf (stderr, " -display host:dpy or -d\n");
72 fprintf (stderr, " -geometry WxH+X+Y or -g spec\n");
73 fprintf (stderr, " -black use BlackPixel\n");
74 fprintf (stderr, " -white use WhitePixel\n");
75 fprintf (stderr, " -solid colorname use the color indicated\n");
76 fprintf (stderr, " -root use the root background\n");
77 fprintf (stderr, " -none no background in window\n");
78 fprintf (stderr, "\nThe default is: %s -none\n\n", ProgramName);
83 * The following parses options that should be yes or no; it returns -1, 0, 1
88 parse_boolean_option(char *option)
90 static struct _booltable {
94 { "off", 0 }, { "n", 0 }, { "no", 0 }, { "false", 0 },
95 { "on", 1 }, { "y", 1 }, { "yes", 1 }, { "true", 1 },
97 register struct _booltable *t;
100 for (cp = option; *cp; cp++) {
101 if (isascii (*cp) && isupper (*cp)) *cp = tolower (*cp);
104 for (t = booltable; t->name; t++) {
105 if (strcmp (option, t->name) == 0) return (t->value);
112 * The following is a hack until XrmParseCommand is ready. It determines
113 * whether or not the given string is an abbreviation of the arg.
117 isabbreviation(char *arg, char *s, int minslen)
123 if (strcmp (arg, s) == 0) return (True);
125 arglen = strlen (arg);
128 /* too long or too short */
129 if (slen >= arglen || slen < minslen) return (False);
132 if (strncmp (arg, s, slen) == 0) return (True);
139 enum e_action {doDefault, doBlack, doWhite, doSolid, doNone, doRoot};
141 static struct s_pair {
143 enum e_action action;
145 { "Black", doBlack },
146 { "White", doWhite },
149 { NULL, doDefault }};
152 main(int argc, char *argv[])
155 XSetWindowAttributes xswa;
157 char *displayname = NULL;
160 enum e_action action = doDefault;
163 int x, y, width, height;
166 int display_width, display_height;
167 char *solidcolor = NULL;
170 ProgramName = argv[0];
172 for (i = 1; i < argc; i++) {
176 if (isabbreviation ("-display", arg, 2)) {
177 if (++i >= argc) Syntax ();
178 displayname = argv[i];
180 } else if (isabbreviation ("-geometry", arg, 2)) {
181 if (++i >= argc) Syntax ();
184 } else if (isabbreviation ("-black", arg, 2)) {
187 } else if (isabbreviation ("-white", arg, 2)) {
190 } else if (isabbreviation ("-solid", arg, 2)) {
191 if (++i >= argc) Syntax ();
192 solidcolor = argv[i];
195 } else if (isabbreviation ("-none", arg, 2)) {
198 } else if (isabbreviation ("-root", arg, 2)) {
203 } else if (arg[0] == '=') /* obsolete */
209 if ((dpy = XOpenDisplay(displayname)) == NULL) {
210 fprintf (stderr, "%s: unable to open display '%s'\n",
211 ProgramName, XDisplayName (displayname));
215 if (action == doDefault) {
218 if ((def = XGetDefault (dpy, ProgramName, "Solid")) != NULL) {
219 solidcolor = strdup (def);
220 if (solidcolor == NULL) {
222 "%s: unable to allocate memory for string.\n",
230 for (pp = pair_table; pp->resource_name != NULL; pp++) {
231 def = XGetDefault (dpy, ProgramName, pp->resource_name);
232 if (def && parse_boolean_option (def) == 1) {
239 if (geom == NULL) geom = XGetDefault (dpy, ProgramName, "Geometry");
241 screen = DefaultScreen (dpy);
242 display_width = DisplayWidth (dpy, screen);
243 display_height = DisplayHeight (dpy, screen);
245 width = display_width;
246 height = display_height;
248 if (DisplayCells (dpy, screen) <= 2 && action == doSolid) {
249 if (strcmp (solidcolor, "black") == 0)
251 else if (strcmp (solidcolor, "white") == 0)
255 "%s: can't use colors on a monochrome display.\n",
262 geom_result = XParseGeometry (geom, &x, &y,
263 (unsigned int *)&width,
264 (unsigned int *)&height);
266 geom_result = NoValue;
269 * For parsing geometry, we want to have the following
271 * = (0,0) for (display_width,display_height)
272 * =WxH+X+Y (X,Y) for (W,H)
273 * =WxH-X-Y (display_width-W-X,display_height-H-Y) for (W,H)
274 * =+X+Y (X,Y) for (display_width-X,display_height-Y)
275 * =WxH (0,0) for (W,H)
276 * =-X-Y (0,0) for (display_width-X,display_height-Y)
278 * If we let any missing values be taken from (0,0) for
279 * (display_width,display_height) we just have to deal with the
283 if (geom_result & XNegative) {
284 if (geom_result & WidthValue) {
285 x = display_width - width + x;
287 width = display_width + x;
291 if (geom_result & YNegative) {
292 if (geom_result & HeightValue) {
293 y = display_height - height + y;
295 height = display_height + y;
303 xswa.background_pixel = BlackPixel (dpy, screen);
307 xswa.background_pixel = WhitePixel (dpy, screen);
311 cmap = DefaultColormap (dpy, screen);
312 if (XParseColor (dpy, cmap, solidcolor, &cdef) &&
313 XAllocColor (dpy, cmap, &cdef)) {
314 xswa.background_pixel = cdef.pixel;
317 fprintf (stderr,"%s: unable to allocate color '%s'.\n",
318 ProgramName, solidcolor);
324 xswa.background_pixmap = None;
325 mask |= CWBackPixmap;
328 xswa.background_pixmap = ParentRelative;
329 mask |= CWBackPixmap;
332 xswa.override_redirect = True;
333 xswa.backing_store = NotUseful;
334 xswa.save_under = False;
335 mask |= (CWOverrideRedirect | CWBackingStore | CWSaveUnder);
336 visual.visualid = CopyFromParent;
337 win = XCreateWindow(dpy, DefaultRootWindow(dpy), x, y, width, height,
338 0, DefaultDepth(dpy, screen), InputOutput, &visual, mask, &xswa);
341 * at some point, we really ought to go walk the tree and turn off
342 * backing store; or do a ClearArea generating exposures on all windows
344 XMapWindow (dpy, win);
345 /* the following will free the color that we might have allocateded */