diff options
Diffstat (limited to 'xdeadzone.c')
-rw-r--r-- | xdeadzone.c | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/xdeadzone.c b/xdeadzone.c index ab36f8c..6ec1e10 100644 --- a/xdeadzone.c +++ b/xdeadzone.c @@ -7,6 +7,7 @@ #include <X11/Xlib.h> #include <X11/Xatom.h> +#include <X11/Xutil.h> #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -18,7 +19,7 @@ #define NAME "XDeadZone" /* define this to print some debug info at runtime. */ -// #define DEBUG +#define DEBUG #ifdef DEBUG # define DBG(x) x @@ -44,8 +45,8 @@ void usage(const int ret) { banner(); printf( "Usage:\n %s " - "[-nw | -ne | -sw | -se | -abs xpos ypos] [width] [height]" - "\n", + "[-nw | -ne | -sw | -se | -abs] <geometry>\n\n" + " <geometry> is WxH for all modes but -abs, or\n WxH[+-]xpos[+-]ypos for -abs\n", exe_name); exit(ret); } @@ -67,36 +68,33 @@ int main(int argc, char **argv) { XWindowAttributes attr; XSetWindowAttributes setattr; - int x = 0, y = 0, width = 0, height = 0; + int x = -1, y = -1, gflags; + unsigned int width, height; set_exe_name(argv[0]); - if(argc < 2) - usage(1); - if(argc == 2) { if(streq(argv[1], "--help")) { usage(0); } else if(streq(argv[1], "--version")) { banner(); exit(0); - } else { - usage(1); } } + if(argc != 3) + errmsg("wrong number of arguments (try --help)"); + + gflags = XParseGeometry(argv[2], &x, &y, &width, &height); + if(!(gflags & (WidthValue | HeightValue))) + errmsg("bad geometry (can't parse width and height)"); + if(streq(argv[1], "-abs")) { - if(argc != 6) - errmsg("wrong number of arguments for -abs"); - x = atoi(argv[2]); - y = atoi(argv[3]); - width = atoi(argv[4]); - height = atoi(argv[5]); + if(!(gflags & (XValue | YValue))) + errmsg("bad geometry: -abs requires X and Y coords"); } else { - if(argc != 4) - errmsg("wrong number of arguments for non-abs mode"); - width = atoi(argv[2]); - height = atoi(argv[3]); + if(gflags & (XValue | YValue)) + errmsg("bad geometry: don't give X and Y coords with -nw/-ne/-sw/-se"); if(streq(argv[1], "-nw")) { x = 0; y = 0; } else if(streq(argv[1], "-ne")) { @@ -106,19 +104,19 @@ int main(int argc, char **argv) { } else if(streq(argv[1], "-se")) { x = -width; y = -height; } else { - errmsg("invalid first argument (not -abs/-nw/-ne/-sw/-se)"); + errmsg("bad first argument (not -abs/-nw/-ne/-sw/-se)"); } } - if(width <= 0 || height <= 0) - errmsg("width and height must be positive and non-zero"); + if(width == 0 || height == 0) + errmsg("bad geometry: width and height must be non-zero"); if(!(d = XOpenDisplay(NULL))) errmsg("can't open X display"); XGetWindowAttributes(d, DefaultRootWindow(d), &attr); - if(x < 0) x = attr.width + x; - if(y < 0) y = attr.height + y; + if(gflags & XNegative) x = (attr.width + x) - width; + if(gflags & YNegative) y = (attr.height + y) - height; DBG(printf("X size %d x %d, x %d, y %d, width %d, height %d\n", attr.width, attr.height, x, y, width, height)); |