diff --git a/Makefile b/Makefile index 407b364..e1c4d7f 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ HDR = arg.h util.h SRC = \ wew.c \ chwb2.c \ + chwb3.c \ wname.c \ xmmv.c \ xmrs.c \ diff --git a/README.md b/README.md index c1d1389..85cd33b 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ utilities opt has less utilities than core, here is a little overview: +* chwb3 - control an inner window border and two outer window borders * chwb2 - control two different window borders * wew - print window events * wname - print a window's name diff --git a/chwb2.c b/chwb2.c index ce652b4..6c99238 100644 --- a/chwb2.c +++ b/chwb2.c @@ -75,11 +75,7 @@ int is; /* inner size */ }; xcb_rectangle_t outer[] = { - {w + b - o, 0, o, h + b * 2}, - {w + b, 0, o, h + b * 2}, - {0, h + b - o, w + b * 2, o}, - {0, h + b, w + b * 2, o}, - {1, 1, 1, 1} + {0, 0, w+(b*2), h+(b*2)} }; xcb_pixmap_t pmap = xcb_generate_id(conn); @@ -91,7 +87,7 @@ int is; /* inner size */ values[0] = oc; xcb_change_gc(conn, gc, XCB_GC_FOREGROUND, values); - xcb_poly_fill_rectangle(conn, pmap, gc, 5, outer); + xcb_poly_fill_rectangle(conn, pmap, gc, 1, outer); values[0] = ic; xcb_change_gc(conn, gc, XCB_GC_FOREGROUND, values); diff --git a/chwb3.c b/chwb3.c new file mode 100644 index 0000000..fe22e44 --- /dev/null +++ b/chwb3.c @@ -0,0 +1,145 @@ +/** +* Copyright (c) 2014, Broseph +* +* Permission to use, copy, modify, and/or distribute this software for any +* purpose with or without fee is hereby granted, provided that the above +* copyright notice and this permission notice appear in all copies. +* +* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +**/ + +#include +#include +#include +#include +#include + +#include "arg.h" +#include "util.h" + +char *argv0; +static xcb_connection_t *conn; +static xcb_screen_t *scr; + +static void usage (char *name); +static void set3border (xcb_window_t, int, int, int, int); + +static void +usage (char *name) +{ + fprintf(stderr, "usage: %s <-I color> <-O color> <-i size> <-o size> [wid...]\n", name); + exit(1); +} + +static void +set3border (win, oc, os, ic, is) +xcb_window_t win; +int oc; /* outer color */ +int os; /* outer size */ +int ic; /* inner color */ +int is; /* inner size */ +{ + if (os < 0 || oc < 0 || is < 0 || ic < 0) + return; + + uint32_t values[1]; + short w, h, b, o, i; + + xcb_get_geometry_reply_t *geom = xcb_get_geometry_reply(conn, + xcb_get_geometry(conn, win), NULL); + + if (geom == NULL) + return; + + if ((is + (os*2)) > geom->border_width) + warnx("warning: pixmap is greater than border size"); + + w = (short)geom->width; + h = (short)geom->height; + b = (unsigned short)is+(os*2); + o = (unsigned short)os; + i = (unsigned short)is; + + xcb_rectangle_t inner[] = { + {w+os, 0, i, h+o+i}, + {0, h+os, w+o, i}, + {w+b+os, 0, i, h+o}, + {0, h+b+os, w+o, i}, + {w+b+os, h+b+os, i, o+i}, + {w+b+os, h+b+os, o+i, i}, + {w+os, h+b+os, i, o+i}, + {w+b+os, h+os, o+i, i} + }; + + xcb_rectangle_t outer[] = { + {0, 0, w+(b*2), h+(b*2)} + }; + + xcb_pixmap_t pmap = xcb_generate_id(conn); + xcb_create_pixmap(conn, scr->root_depth, pmap, win, + geom->width + (b*2), + geom->height + (b*2)); + xcb_gcontext_t gc = xcb_generate_id(conn); + xcb_create_gc(conn, gc, pmap, 0, NULL); + + values[0] = oc; + xcb_change_gc(conn, gc, XCB_GC_FOREGROUND, values); + xcb_poly_fill_rectangle(conn, pmap, gc, 1, outer); + + values[0] = ic; + xcb_change_gc(conn, gc, XCB_GC_FOREGROUND, values); + xcb_poly_fill_rectangle(conn, pmap, gc, 8, inner); + + values[0] = pmap; + xcb_change_window_attributes(conn, win, XCB_CW_BORDER_PIXMAP, values); + + xcb_free_pixmap(conn, pmap); + xcb_free_gc(conn, gc); +} + +int +main (int argc, char **argv) +{ + int oc,os,ic,is; + + if (argc < 2) + usage(argv[0]); + + oc = os = ic = is = -1; + ARGBEGIN { + case 'I': + ic = strtoul(EARGF(usage(argv0)), NULL, 16); + break; + case 'O': + oc = strtoul(EARGF(usage(argv0)), NULL, 16); + break; + case 'i': + is = strtoul(EARGF(usage(argv0)), NULL, 10); + break; + case 'o': + os = strtoul(EARGF(usage(argv0)), NULL, 10); + break; + case 'h': + usage(argv0); + /* NOTREACHED */ + } ARGEND + + init_xcb(&conn); + get_screen(conn, &scr); + + /* assume remaining arguments are windows */ + while (*argv) + set3border(strtoul(*argv++, NULL, 16), oc, os, ic, is); + + xcb_aux_sync(conn); + + kill_xcb(&conn); + + return 0; +} diff --git a/man/chwb3.1 b/man/chwb3.1 new file mode 100644 index 0000000..7ae6d9e --- /dev/null +++ b/man/chwb3.1 @@ -0,0 +1,45 @@ +.Dd Auguest 22, 2018 +.Dt CHWB3 1 +.Os wmutils +.Sh NAME +.Nm chwb3 +.Nd change window triple-borders +.Sh SYNOPSIS +.Nm chwb3 +.Op Fl I Ar inner color +.Op Fl O Ar outer color +.Op Fl i Ar inner size +.Op Fl o Ar outer size +.Ar wid Op Ar ... +.Sh DESCRIPTION +.Nm +applies a triple pixmap border to +.Ar wid . +.Bl -tag -width Ds +.It Fl I Ar inner color +.It Fl O Ar outer color +Set the inner/outer border color of +.Ar wid +to +.Ar color . +Colors should be passed as a hex triplet without the '#' prefix (see +.Xr strtoul 3 ) +in RGB format. +.It Fl i Ar size +.It Fl o Ar size +Sets the inner/outer border width of +.Ar wid +to +.Ar size . +.El +.Sh ENVIRONMENT +.Nm +acts on the X display specified by the +.Ev DISPLAY +variable. +.Sh EXAMPLES +Set the inner border of the current window to yellow with a black outer rim: +.Dl $ chwb3 -O 000000 -I ffff00 -i 3 -o 1 $(pfw) +.Sh SEE ALSO +.Xr chwb 1 +.Xr strtoul 3