/* Copyright 1998 by Vadim Kolontsov
* All rights reserved
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
*
* Vadim Kolontsov <sb@123.org>
*-----------------------------------------------------------------------
* This program sets attribute "override_redirect" to True for any window
* you've specified (using window name). Window Managers should ignore
* such windows; it's useful, for example, if you're using wmx Window Manager,
* and want to have a clock on every virtual screen and without any
* borders. Just add the following string to your X-startfile (after
* starting watch app):
*
* xnodecor -w watch
*
* (assuming that your watch application has a window named "watch")
*
* For details see http://sb.123.org/xnodecor.html
*
* Tested on FreeBSD 2.2.2, XFree86 3.2, wmx-4
*
* Compilation:
*
* gcc -o xnodecor xnodecor.c -L/usr/X11R6/lib -I/usr/X11R6/include -lX11 */
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#define WAIT_DEFAULT 0
#define WAIT_TIMEOUT 15
#define VERBOSE_DEFAULT 0
int main(int argc, char *argv[])
{
Display *d;
Window w1, w2, *wins;
int c;
XSetWindowAttributes a;
char *name, *program_name, *display_name = NULL;
unsigned int i, n, found = 0,
f_wait = WAIT_DEFAULT,
f_verbose = VERBOSE_DEFAULT,
delay = WAIT_TIMEOUT;
if (argv && argv[0] && *argv[0])
program_name = (program_name = rindex(argv[0], '/')) ?
(*++program_name ? program_name : "xnodecor") : argv[0];
while ((c = getopt(argc, argv, "vd:wt:h")) != EOF)
switch (c)
{
case 'd':
display_name = strdup(optarg);
break;
case 'w':
f_wait = f_wait ? 0 : 1;
break;
case 'v':
f_verbose = f_verbose ? 0 : 1;
break;
case 't':
delay = atoi(optarg);
break;
case 'h':
default:
fprintf(stderr, "Usage: %s [options] window-name\n\n"
" -d display specify alternative display\n"
" -w wait for specified window (default: %swait)\n"
" -t n timeout for waiting (default: %d sec)\n"
" -v verbose mode (default: %s)\n"
" -h this help\n\n", program_name,
f_wait ? "" : "no ", delay,
f_verbose ? "on" : "off");
exit(0);
}
argc -= optind;
argv += optind;
if (argc != 1)
{
fprintf(stderr, "%s: Window name not specified\n", program_name);
exit(1);
}
d = XOpenDisplay(display_name);
if (!d)
{
fprintf(stderr, "%s: Can't open display\n", program_name);
exit(1);
}
do
{
if (XQueryTree(d, RootWindow(d, 0), &w1, &w2, &wins, &n) == 0)
{
fprintf(stderr, "%s: XQueryTree failed\n", program_name);
exit(1);
}
found = 0;
for (i = 0; i < n; i++)
if (XFetchName(d, wins[i], &name))
{
if (f_verbose) printf("%s\n", name);
if (!strcmp(name, argv[0]))
{
if (f_verbose) printf("(found!)\n");
a.override_redirect = 1;
XChangeWindowAttributes(d, wins[i], CWOverrideRedirect, &a);
found = 1;
}
}
if (f_wait)
sleep(1);
} while (f_wait && delay-- && !found);
XCloseDisplay(d);
}