aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-02-01 05:01:02 -0500
committerB. Watson <urchlay@slackware.uk>2024-02-01 05:01:32 -0500
commit2bd88c14e52a8c1e96b8ef2a7e4f5ba990b59019 (patch)
treea935ba77d0beba06409c4029d3d5ba7b228f35a1
parenta5ce3ca8d6d44053f9f6c78bb3ac1edbf06bea45 (diff)
downloadxdeadzone-2bd88c14e52a8c1e96b8ef2a7e4f5ba990b59019.tar.gz
Further simplify argument procesing, fix -abs negative offsets.
-rw-r--r--xdeadzone.122
-rw-r--r--xdeadzone.c106
-rw-r--r--xdeadzone.rst25
3 files changed, 105 insertions, 48 deletions
diff --git a/xdeadzone.1 b/xdeadzone.1
index 29929d0..582ce08 100644
--- a/xdeadzone.1
+++ b/xdeadzone.1
@@ -36,7 +36,7 @@ xdeadzone \- keep the mouse pointer out of the dead zone, on mismatched multihea
.
.SH SYNOPSIS
.sp
-xdeadzone [\fB\-nw\fP | \fB\-ne\fP | \fB\-sw\fP | \fB\-se\fP | \fB\-abs\fP] \fIgeometry\fP
+xdeadzone <[\fB\-i\fP \fB\-b\fP | \fB\-w\fP ]> [\fB\-nw\fP | \fB\-ne\fP | \fB\-sw\fP | \fB\-se\fP | \fB\-abs\fP] \fIgeometry\fP
.sp
xdeadzone \fB\-\-help\fP | \fB\-\-version\fP
.SH DESCRIPTION
@@ -63,6 +63,7 @@ virtual desktop.
environments, and works properly with at least: KDE (Plasma 5), XFCE
4, Fmwv2, WindowMaker, BlackBox, and FluxBox.
.SH OPTIONS
+.SS Optional arguments
.INDENT 0.0
.TP
.B \-\-help
@@ -73,6 +74,20 @@ Print the application name and version number, and exit.
.UNINDENT
.INDENT 0.0
.TP
+.B \fB\-i\fP
+Make window invisible. This is the default.
+.TP
+.B \fB\-b\fP
+Make window visible, display as a black rectangle.
+.TP
+.B \fB\-w\fP
+Make window visible, display as a white rectangle.
+.UNINDENT
+.SS Modes
+.sp
+One mode argument is required.
+.INDENT 0.0
+.TP
.B \fB\-nw\fP
Place window at northwest (top left) corner of display.
.TP
@@ -87,10 +102,13 @@ Place window at southeast (bottom right) corner of display.
.TP
.B \fB\-abs\fP
Place window at the coordinates given by \fBgeometry\fP\&.
+.UNINDENT
+.SS Required argument
+.INDENT 0.0
.TP
.B \fBgeometry\fP
This is a standard X11 geometry specification. Its format is
-<\fIwidth\fP>x<\fIheight\fP> for all modes other than \fB\-\-abs\fP\&. For \fB\-\-abs\fP,
+<\fIwidth\fP>x<\fIheight\fP> for all modes other than \fB\-abs\fP\&. For \fB\-abs\fP,
it\(aqs <\fIwidth\fP>x<\fIheight\fP>[\fI+\-\fP]<\fIxpos\fP>[\fI+\-\fP]<\fIypos\fP>.
Negative xpos and ypos will be
treated as offsets from the right/bottom of the display.
diff --git a/xdeadzone.c b/xdeadzone.c
index a0398a8..5b89c94 100644
--- a/xdeadzone.c
+++ b/xdeadzone.c
@@ -27,6 +27,8 @@
# define DBG(x)
#endif
+enum { M_UNSET, M_ABS, M_NE, M_NW, M_SE, M_SW };
+
const char *exe_name;
void set_exe_name(const char *p) {
@@ -45,7 +47,7 @@ void usage(const int ret) {
banner();
printf(
"Usage:\n %s "
- "[-nw | -ne | -sw | -se | -abs] <geometry>\n\n"
+ "<[-b | -w | -i]> [-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);
@@ -68,62 +70,72 @@ int main(int argc, char **argv) {
XWindowAttributes attr;
XSetWindowAttributes setattr;
- int x = -1, y = -1, gflags, visible = 0, black = 0;
+ int x = -1, y = -1, gflags = -1, visible = 0, black = 0, mode = M_UNSET;
unsigned int width, height;
set_exe_name(argv[0]);
- if(argc == 2) {
- if(streq(argv[1], "--help")) {
+ while(*++argv) {
+ const char *a = *argv;
+ DBG(printf("arg: %s\n", a));
+
+ if(streq(a, "--help")) {
usage(0);
- } else if(streq(argv[1], "--version")) {
+ } else if(streq(a, "--version")) {
banner();
exit(0);
- }
- }
-
- if(argc >= 2) {
- if(streq(argv[1], "-b")) {
+ } else if(streq(a, "-b")) {
visible = 1;
black = 1;
- argv++;
- argc--;
- } else if(streq(argv[1], "-w")) {
+ } else if(streq(a, "-w")) {
visible = 1;
black = 0;
- argv++;
- argc--;
- } else if(streq(argv[1], "-i")) {
+ } else if(streq(a, "-i")) {
visible = 0;
- argv++;
- argc--;
+ } else if(streq(a, "-abs")) {
+ mode = M_ABS;
+ } else if(streq(a, "-ne")) {
+ mode = M_NE;
+ } else if(streq(a, "-nw")) {
+ mode = M_NW;
+ } else if(streq(a, "-se")) {
+ mode = M_SE;
+ } else if(streq(a, "-sw")) {
+ mode = M_SW;
+ } else if(a[0] == '-') {
+ fprintf(stderr, "%s: invalid option: %s (try --help)\n", exe_name, a);
+ exit(1);
+ } else { /* no dash, must be geometry */
+ if(gflags == -1)
+ gflags = XParseGeometry(a, &x, &y, &width, &height);
+ else
+ errmsg("multiple geometry arguments given (try --help)");
}
}
- 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(!(gflags & (XValue | YValue)))
- errmsg("bad geometry: -abs requires X and Y coords");
- } else {
- 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")) {
- x = -width; y = 0;
- } else if(streq(argv[1], "-sw")) {
- x = 0; y = -height;
- } else if(streq(argv[1], "-se")) {
- x = -width; y = -height;
- } else {
- errmsg("bad first argument (not -abs/-nw/-ne/-sw/-se)");
- }
+ if(gflags == -1)
+ errmsg("missing required geometry argument (try --help)");
+ else
+ DBG(printf("XParseGeometry got %d %d %d %d\n", x, y, width, height));
+
+ if(mode != M_ABS && (gflags & (XValue | YValue)))
+ errmsg("bad geometry: X and Y position not allowed without -abs");
+
+ switch(mode) {
+ case M_ABS:
+ if(!(gflags & (XValue | YValue)))
+ errmsg("bad geometry: -abs requires X and Y position");
+ break;
+ case M_NW:
+ x = 0; y = 0; break;
+ case M_NE:
+ x = -width; y = 0; break;
+ case M_SW:
+ x = 0; y = -height; break;
+ case M_SE:
+ x = -width; y = -height; break;
+ default:
+ errmsg("no mode given, one of -abs -ne -nw -se -sw is required");
}
if(width == 0 || height == 0)
@@ -133,8 +145,13 @@ int main(int argc, char **argv) {
errmsg("can't open X display");
XGetWindowAttributes(d, DefaultRootWindow(d), &attr);
- if(gflags & XNegative) x = (attr.width + x) - width;
- if(gflags & YNegative) y = (attr.height + y) - height;
+ if(mode == M_ABS) {
+ if(gflags & XNegative) x = (attr.width + x) - width;
+ if(gflags & YNegative) y = (attr.height + y) - height;
+ } else {
+ if(x < 0) x = (attr.width + x);
+ if(y < 0) y = (attr.height + y);
+ }
DBG(printf("X size %d x %d, x %d, y %d, width %d, height %d\n",
attr.width, attr.height, x, y, width, height));
@@ -190,6 +207,7 @@ int main(int argc, char **argv) {
ignored the x and y in the XCreateWindow(). */
XMoveWindow(d, w, x, y);
+ DBG(printf("awaiting EnterNotify events...\n"));
while(1) {
XNextEvent(d, &ev);
if(ev.type == EnterNotify) {
diff --git a/xdeadzone.rst b/xdeadzone.rst
index ea80766..f0476e1 100644
--- a/xdeadzone.rst
+++ b/xdeadzone.rst
@@ -20,7 +20,7 @@ keep the mouse pointer out of the dead zone, on mismatched multihead displays.
SYNOPSIS
========
-xdeadzone [**-nw** | **-ne** | **-sw** | **-se** | **-abs**] *geometry*
+xdeadzone <[**-i** **-b** | **-w** ]> [**-nw** | **-ne** | **-sw** | **-se** | **-abs**] *geometry*
xdeadzone **--help** | **--version**
@@ -52,12 +52,30 @@ environments, and works properly with at least: KDE (Plasma 5), XFCE
OPTIONS
=======
+Optional arguments
+------------------
+
--help
Print built-in help message and exit.
--version
Print the application name and version number, and exit.
+**-i**
+ Make window invisible. This is the default.
+
+**-b**
+ Make window visible, display as a black rectangle.
+
+**-w**
+ Make window visible, display as a white rectangle.
+
+
+Modes
+-----
+
+One mode argument is required.
+
**-nw**
Place window at northwest (top left) corner of display.
@@ -73,9 +91,12 @@ OPTIONS
**-abs**
Place window at the coordinates given by **geometry**.
+Required argument
+-----------------
+
**geometry**
This is a standard X11 geometry specification. Its format is
- <*width*>x<*height*> for all modes other than **--abs**. For **--abs**,
+ <*width*>x<*height*> for all modes other than **-abs**. For **-abs**,
it's <*width*>x<*height*>[*+-*]<*xpos*>[*+-*]<*ypos*>.
Negative xpos and ypos will be
treated as offsets from the right/bottom of the display.