aboutsummaryrefslogtreecommitdiff
path: root/xshove.c
diff options
context:
space:
mode:
authorDerek Stevens <nilix@nilfm.cc>2021-02-26 14:50:23 -0500
committerDerek Stevens <nilix@nilfm.cc>2021-02-26 14:50:23 -0500
commitb0fb6654c8d361fe5ca98d486cad7317f6c6f8e3 (patch)
tree963b025df90244d99cfc51b5e9aaca474788385f /xshove.c
parent1af2175f2e624bff341e99d4da19fe5a1aa6f691 (diff)
tweak formatting
Diffstat (limited to 'xshove.c')
-rw-r--r--xshove.c118
1 files changed, 75 insertions, 43 deletions
diff --git a/xshove.c b/xshove.c
index 27d3c10..7b0b8fa 100644
--- a/xshove.c
+++ b/xshove.c
@@ -42,25 +42,28 @@ void listwindows(void);
int parsewinsize(char*, Rectangle*, int*, int*, int*);
void shove(char*, char*);
-void
-usage(void) {
+void usage(void) {
fprint(2, "usage: xshove [window rectangle]\n");
exits("usage");
}
-void
-main(int argc, char** argv) {
+void main(int argc, char** argv) {
int screen;
screen = 0;
ARGBEGIN {
- case 's': screen = atoi(EARGF(usage())); break;
- default: usage(); break;
+ case 's':
+ screen = atoi(EARGF(usage()));
+ break;
+ default:
+ usage();
+ break;
}
ARGEND
dpy = XOpenDisplay("");
- if (dpy == nil) sysfatal("open display: %r");
+ if (dpy == nil)
+ sysfatal("open display: %r");
root = RootWindow(dpy, screen);
getinfo();
@@ -69,13 +72,13 @@ main(int argc, char** argv) {
listwindows();
exits(0);
}
- if (argc != 2) usage();
+ if (argc != 2)
+ usage();
shove(argv[0], argv[1]);
exits(0);
}
-char*
-getproperty(Window w, Atom a) {
+char* getproperty(Window w, Atom a) {
uchar* p;
int fmt;
Atom type;
@@ -84,41 +87,57 @@ getproperty(Window w, Atom a) {
n = 100;
p = nil;
XGetWindowProperty(
- dpy, w, a, 0, 100L, 0, AnyPropertyType, &type, &fmt, &n, &dummy, &p);
- if (p == nil || *p == 0) return nil;
+ dpy,
+ w,
+ a,
+ 0,
+ 100L,
+ 0,
+ AnyPropertyType,
+ &type,
+ &fmt,
+ &n,
+ &dummy,
+ &p);
+ if (p == nil || *p == 0)
+ return nil;
return strdup((char*)p);
}
-Window
-findname(Window w) {
+Window findname(Window w) {
int i;
uint nxwin;
Window dw1, dw2, *xwin;
- if (getproperty(w, XA_WM_NAME)) return w;
- if (!XQueryTree(dpy, w, &dw1, &dw2, &xwin, &nxwin)) return 0;
+ if (getproperty(w, XA_WM_NAME))
+ return w;
+ if (!XQueryTree(dpy, w, &dw1, &dw2, &xwin, &nxwin))
+ return 0;
for (i = 0; i < nxwin; i++)
- if ((w = findname(xwin[i])) != 0) return w;
+ if ((w = findname(xwin[i])) != 0)
+ return w;
return 0;
}
-void
-getinfo(void) {
+void getinfo(void) {
int i;
uint nxwin;
Window dw1, dw2, *xwin;
XClassHint class;
XWindowAttributes attr;
- if (!XQueryTree(dpy, root, &dw1, &dw2, &xwin, &nxwin)) return;
+ if (!XQueryTree(dpy, root, &dw1, &dw2, &xwin, &nxwin))
+ return;
w = mallocz(nxwin * sizeof w[0], 1);
- if (w == 0) sysfatal("malloc: %r");
+ if (w == 0)
+ sysfatal("malloc: %r");
Win* ww = w;
for (i = 0; i < nxwin; i++) {
memset(&attr, 0, sizeof attr);
xwin[i] = findname(xwin[i]);
- if (xwin[i] == 0) continue;
+ if (xwin[i] == 0)
+ continue;
XGetWindowAttributes(dpy, xwin[i], &attr);
if (
attr.width <= 0 || attr.override_redirect || attr.map_state != IsViewable)
@@ -140,8 +159,7 @@ getinfo(void) {
nw = ww - w;
}
-void
-listwindows(void) {
+void listwindows(void) {
int i;
for (i = 0; i < nw; i++) {
@@ -159,8 +177,7 @@ listwindows(void) {
}
}
-void
-shove(char* name, char* geom) {
+void shove(char* name, char* geom) {
int i;
int isdelta, havemin, havesize;
int old, new;
@@ -205,8 +222,8 @@ shove(char* name, char* geom) {
}
}
-int
-parsewinsize(char* s, Rectangle* r, int* isdelta, int* havemin, int* havesize) {
+int parsewinsize(
+ char* s, Rectangle* r, int* isdelta, int* havemin, int* havesize) {
char c, *os;
int i, j, k, l;
@@ -222,26 +239,34 @@ parsewinsize(char* s, Rectangle* r, int* isdelta, int* havemin, int* havesize) {
*havemin = 0;
*havesize = 0;
memset(r, 0, sizeof *r);
- if (!isdigit((uchar)*s)) goto oops;
+ if (!isdigit((uchar)*s))
+ goto oops;
i = strtol(s, &s, 0);
if (*s == 'x') {
s++;
- if (!isdigit((uchar)*s)) goto oops;
+ if (!isdigit((uchar)*s))
+ goto oops;
j = strtol(s, &s, 0);
r->max.x = i;
r->max.y = j;
*havesize = 1;
- if (*s == 0) return 0;
- if (*s != '@') goto oops;
+ if (*s == 0)
+ return 0;
+ if (*s != '@')
+ goto oops;
s++;
- if (!isdigit((uchar)*s)) goto oops;
+ if (!isdigit((uchar)*s))
+ goto oops;
i = strtol(s, &s, 0);
- if (*s != ',' && *s != ' ') goto oops;
+ if (*s != ',' && *s != ' ')
+ goto oops;
s++;
- if (!isdigit((uchar)*s)) goto oops;
+ if (!isdigit((uchar)*s))
+ goto oops;
j = strtol(s, &s, 0);
- if (*s != 0) goto oops;
+ if (*s != 0)
+ goto oops;
r->min.x += i;
r->max.x += i;
r->min.y += j;
@@ -252,9 +277,11 @@ parsewinsize(char* s, Rectangle* r, int* isdelta, int* havemin, int* havesize) {
}
c = *s;
- if (c != ' ' && c != ',') goto oops;
+ if (c != ' ' && c != ',')
+ goto oops;
s++;
- if (!isdigit((uchar)*s)) goto oops;
+ if (!isdigit((uchar)*s))
+ goto oops;
j = strtol(s, &s, 0);
if (*s == 0) {
r->min.x = i;
@@ -262,15 +289,20 @@ parsewinsize(char* s, Rectangle* r, int* isdelta, int* havemin, int* havesize) {
*havemin = 1;
return 0;
}
- if (*s != c) goto oops;
+ if (*s != c)
+ goto oops;
s++;
- if (!isdigit((uchar)*s)) goto oops;
+ if (!isdigit((uchar)*s))
+ goto oops;
k = strtol(s, &s, 0);
- if (*s != c) goto oops;
+ if (*s != c)
+ goto oops;
s++;
- if (!isdigit((uchar)*s)) goto oops;
+ if (!isdigit((uchar)*s))
+ goto oops;
l = strtol(s, &s, 0);
- if (*s != 0) goto oops;
+ if (*s != 0)
+ goto oops;
r->min.x = i;
r->min.y = j;
r->max.x = k;