├── LICENSE ├── Makefile ├── README.md ├── arg.h ├── atomx.c ├── chwb.c ├── chwso.c ├── config.mk ├── ignw.c ├── killw.c ├── lsw.c ├── man ├── Makefile ├── atomx.1 ├── chwb.1 ├── chwso.1 ├── ignw.1 ├── killw.1 ├── lsw.1 ├── mapw.1 ├── pdw.1 ├── pfw.1 ├── slw.1 ├── wattr.1 ├── wmp.1 ├── wmutils.1 ├── wmv.1 ├── wrs.1 ├── wtf.1 └── wtp.1 ├── mapw.c ├── pdw.c ├── pfw.c ├── slw.c ├── util.c ├── util.h ├── wattr.c ├── wmp.c ├── wmv.c ├── wrs.c ├── wtf.c └── wtp.c /LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2014-2016 brosephs , 4 | 5 | 6 | Permission to use, copy, modify, and distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 11 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 12 | FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 13 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 14 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 15 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 | PERFORMANCE OF THIS SOFTWARE. 17 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include config.mk 2 | 3 | HDR = arg.h util.h 4 | SRC = \ 5 | pfw.c \ 6 | pdw.c \ 7 | lsw.c \ 8 | mapw.c \ 9 | killw.c \ 10 | wattr.c \ 11 | wtp.c \ 12 | wmv.c \ 13 | chwso.c \ 14 | wtf.c \ 15 | wrs.c \ 16 | chwb.c \ 17 | ignw.c \ 18 | wmp.c \ 19 | slw.c \ 20 | atomx.c 21 | 22 | OBJ = $(SRC:.c=.o) 23 | BIN = $(SRC:.c=) 24 | MAN = $(SRC:.c=.1) 25 | 26 | .POSIX: 27 | .SUFFIXES: .1 .1.gz 28 | 29 | all: binutils 30 | 31 | binutils: $(BIN) 32 | 33 | $(OBJ): $(HDR) util.o 34 | 35 | .o: 36 | @echo "LD $@" 37 | @$(LD) $< util.o -o $@ $(LDFLAGS) 38 | 39 | .c.o: 40 | @echo "CC $<" 41 | @$(CC) -c $< -o $@ $(CFLAGS) 42 | 43 | install: $(BIN) 44 | mkdir -p $(DESTDIR)$(PREFIX)/bin/ 45 | cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin/ 46 | cd man; $(MAKE) install 47 | 48 | uninstall: 49 | @echo "uninstalling binaries" 50 | @for util in $(BIN); do \ 51 | rm -f $(DESTDIR)$(PREFIX)/bin/$$util; \ 52 | done 53 | cd man; $(MAKE) uninstall 54 | 55 | clean : 56 | rm -f $(OBJ) $(BIN) util.o 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | wmutils' core 2 | ============= 3 | 4 | wmutils' core is a set of tools for X windows manipulation. Each tool only has 5 | one purpose, to make it as flexible and reliable as possible. 6 | 7 | Here's a quick example. This snippet will put the currently focused window in 8 | the middle of the screen: 9 | 10 | #!/bin/sh 11 | 12 | # get current window id, width and height 13 | WID=$(pfw) 14 | WW=$(wattr w $WID) 15 | WH=$(wattr h $WID) 16 | 17 | # get screen width and height 18 | ROOT=$(lsw -r) 19 | SW=$(wattr w $ROOT) 20 | SH=$(wattr h $ROOT) 21 | 22 | # move the current window to the center of the screen 23 | wtp $(((SW - WW)/2)) $(((SH - WH)/2)) $WW $WH $WID 24 | 25 | You also might want to check [sxhkd](https://github.com/baskerville/sxhkd), a 26 | daemon which allow binding applications to hot keys. 27 | 28 | utilities 29 | --------- 30 | 31 | * chwb - change window's border 32 | * chwso - change window's stacking order 33 | * ignw - ignore/unignore window 34 | * killw - kill windows 35 | * lsw - list windows 36 | * mapw - map/unmap windows 37 | * pfw - print focused window 38 | * pdw - print decoration window 39 | * slw - select window interactively 40 | * wattr - show window's attributes 41 | * wmp - move the mouse pointer 42 | * wmv - move a window 43 | * wrs - resize a window 44 | * wtf - focus a window 45 | * wtp - teleport a window 46 | * atomx - modify atoms on a window 47 | 48 | All these tools come with a manpage ! read them for further informations. 49 | 50 | dependencies 51 | ------------ 52 | 53 | wmutils only relies on the XCB library. 54 | 55 | license 56 | ------- 57 | 58 | All the code of this project is released under the 59 | [ISC](http://www.openbsd.org/policy.html) license. See LICENSE file. 60 | 61 | build & install 62 | --------------- 63 | 64 | System-wide installation (default PREFIX is `/usr`): 65 | 66 | $ make 67 | # make install 68 | 69 | Here are the variables you can override, along with their default values: 70 | 71 | CC = cc 72 | LD = $(CC) 73 | CFLAGS = -std=c99 -pedantic -Wall -Os 74 | LDFLAGS = -lxcb 75 | PREFIX = /usr 76 | MANPREFIX = $(PREFIX)/man 77 | DESTDIR = 78 | 79 | You can override them by passing them on the command line: 80 | 81 | make DESTDIR=/newroot install 82 | 83 | Or by setting them via the environment: 84 | 85 | CC=c99; export CC 86 | make -e 87 | 88 | contribute 89 | ---------- 90 | 91 | You can contribute to the project in many ways; be it by testing the software, 92 | reporting bugs, submitting patches, or simply talking about it to other 93 | people! 94 | The official IRC channel for wmutils' talks is #wmutils @irc.freenode.net. 95 | 96 | If you find a bug in the software, please report an issue. Same goes for 97 | feature requests, if they match the project's philosophy. 98 | 99 | When submitting pull requests, please reference the issue number. If there is 100 | no issue to reference, then create one and wait for a validation of the bug 101 | before submitting the pull request. 102 | 103 | IF YOUR PULL REQUEST DOESN'T REFER TO A VALID ISSUE, IT WILL BE DISCARDED. 104 | -------------------------------------------------------------------------------- /arg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copy me if you can. 3 | * by 20h 4 | */ 5 | 6 | #ifndef ARG_H__ 7 | #define ARG_H__ 8 | 9 | extern char *argv0; 10 | 11 | /* use main(int argc, char *argv[]) */ 12 | #define ARGBEGIN for (argv0 = *argv, argv++, argc--;\ 13 | argv[0] && argv[0][1]\ 14 | && argv[0][0] == '-';\ 15 | argc--, argv++) {\ 16 | char argc_;\ 17 | char **argv_;\ 18 | int brk_;\ 19 | if (argv[0][1] == '-' && argv[0][2] == '\0') {\ 20 | argv++;\ 21 | argc--;\ 22 | break;\ 23 | }\ 24 | for (brk_ = 0, argv[0]++, argv_ = argv;\ 25 | argv[0][0] && !brk_;\ 26 | argv[0]++) {\ 27 | if (argv_ != argv)\ 28 | break;\ 29 | argc_ = argv[0][0];\ 30 | switch (argc_) 31 | 32 | /* Handles obsolete -NUM syntax */ 33 | #define ARGNUM case '0':\ 34 | case '1':\ 35 | case '2':\ 36 | case '3':\ 37 | case '4':\ 38 | case '5':\ 39 | case '6':\ 40 | case '7':\ 41 | case '8':\ 42 | case '9' 43 | 44 | #define ARGEND }\ 45 | } 46 | 47 | #define ARGC() argc_ 48 | 49 | #define ARGNUMF(base) (brk_ = 1, estrtol(argv[0], (base))) 50 | 51 | #define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\ 52 | ((x), abort(), (char *)0) :\ 53 | (brk_ = 1, (argv[0][1] != '\0')?\ 54 | (&argv[0][1]) :\ 55 | (argc--, argv++, argv[0]))) 56 | 57 | #define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\ 58 | (char *)0 :\ 59 | (brk_ = 1, (argv[0][1] != '\0')?\ 60 | (&argv[0][1]) :\ 61 | (argc--, argv++, argv[0]))) 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /atomx.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "util.h" 11 | #include "arg.h" 12 | 13 | #define MAXLEN 512 14 | 15 | static xcb_connection_t *conn; 16 | 17 | void 18 | usage(char *name) 19 | { 20 | fprintf(stderr, "%s [-d] atom[=value] wid\n", name); 21 | } 22 | 23 | xcb_atom_t 24 | add_atom(xcb_atom_t type, char *name, size_t len) 25 | { 26 | xcb_atom_t atom; 27 | xcb_intern_atom_cookie_t c; 28 | xcb_intern_atom_reply_t *r; 29 | 30 | c = xcb_intern_atom(conn, 0, len, name); 31 | r = xcb_intern_atom_reply(conn, c, NULL); 32 | if (!r) 33 | return 0; 34 | 35 | atom = r->atom; 36 | free(r); 37 | 38 | return atom; 39 | } 40 | 41 | int 42 | set_atom(xcb_window_t wid, xcb_atom_t atom, xcb_atom_t type, size_t len, void *data) 43 | { 44 | int errcode; 45 | xcb_void_cookie_t c; 46 | xcb_generic_error_t *e; 47 | 48 | c = xcb_change_property_checked(conn, XCB_PROP_MODE_REPLACE, 49 | wid, atom, type, 8, len, data); 50 | e = xcb_request_check(conn, c); 51 | if (!e) 52 | return 0; 53 | 54 | errcode = e->error_code; 55 | free(e); 56 | 57 | return errcode; 58 | } 59 | 60 | int 61 | get_atom(xcb_window_t wid, xcb_atom_t atom, char *data, xcb_atom_t *type) 62 | { 63 | size_t n; 64 | xcb_get_property_cookie_t c; 65 | xcb_get_property_reply_t *r; 66 | 67 | c = xcb_get_property(conn, 0, wid, atom, XCB_ATOM_ANY, 0, MAXLEN); 68 | r = xcb_get_property_reply(conn, c, NULL); 69 | if (!r) 70 | return -1; 71 | 72 | if (!(n = xcb_get_property_value_length(r))) { 73 | free(r); 74 | return -1; 75 | } 76 | 77 | strncpy(data, xcb_get_property_value(r), n); 78 | data[n] = 0; 79 | 80 | *type = r->type; 81 | 82 | free(r); 83 | 84 | return 0; 85 | } 86 | 87 | 88 | int 89 | main(int argc, char **argv) 90 | { 91 | int i, dflag = 0; 92 | char *key, *val, *argv0; 93 | char data[MAXLEN]; 94 | xcb_window_t wid; 95 | xcb_atom_t atom; 96 | 97 | ARGBEGIN { 98 | case 'd': 99 | dflag = 1; 100 | break; 101 | default: 102 | usage(argv0); 103 | return -1; 104 | } ARGEND; 105 | 106 | if (argc < 1) 107 | return -1; 108 | 109 | key = strtok(argv[0], "="); 110 | val = strtok(NULL, "="); 111 | 112 | init_xcb(&conn); 113 | 114 | for (i = 0; i < argc - 1; i++) { 115 | wid = strtoul(argv[i+1], NULL, 16); 116 | 117 | /* retrieve atom ID from server */ 118 | atom = add_atom(XCB_ATOM_STRING, key, strlen(key)); 119 | if (!atom) 120 | return -1; 121 | 122 | /* set property on window (must be a string) */ 123 | if (val) 124 | set_atom(wid, atom, XCB_ATOM_STRING, strlen(val), val); 125 | 126 | /* remove property from window */ 127 | if (dflag) 128 | xcb_delete_property(conn, wid, atom); 129 | 130 | /* retrieve and print atom value to stdout */ 131 | xcb_atom_t type; 132 | if (!get_atom(wid, atom, data, &type)) 133 | switch (type) { 134 | case XCB_ATOM_INTEGER: 135 | printf("%d\n", *data); 136 | break; 137 | default: 138 | printf("%s\n", data); 139 | } 140 | } 141 | 142 | kill_xcb(&conn); 143 | 144 | return 0; 145 | } 146 | -------------------------------------------------------------------------------- /chwb.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "arg.h" 10 | #include "util.h" 11 | 12 | static xcb_connection_t *conn; 13 | 14 | static void usage(char *name); 15 | static void set_border(int, int, xcb_window_t); 16 | 17 | static void 18 | usage(char *name) 19 | { 20 | fprintf(stderr, "usage: %s <-sc ...> [wid...]\n", name); 21 | exit(1); 22 | } 23 | 24 | static void 25 | set_border(int width, int color, xcb_window_t win) 26 | { 27 | uint32_t values[3]; 28 | uint16_t curr_width; 29 | int mask; 30 | xcb_get_geometry_reply_t *geom; 31 | 32 | if (width != -1) { 33 | geom = xcb_get_geometry_reply(conn, xcb_get_geometry(conn, win), NULL); 34 | if (!geom) 35 | return; 36 | 37 | /* Windows track position based on the top left corner of the border. 38 | * To make the border move instead of the window, we move the window up and left 39 | * by the amount the border would have shifted it down and right.*/ 40 | curr_width = geom->border_width; 41 | values[0] = geom->x + curr_width - width; 42 | values[1] = geom->y + curr_width - width; 43 | values[2] = width; 44 | 45 | mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_BORDER_WIDTH ; 46 | xcb_configure_window(conn, win, mask, values); 47 | 48 | xcb_aux_sync(conn); 49 | 50 | free(geom); 51 | } 52 | 53 | if (color != -1) { 54 | values[0] = color; 55 | mask = XCB_CW_BORDER_PIXEL; 56 | xcb_change_window_attributes(conn, win, mask, values); 57 | 58 | xcb_aux_sync(conn); 59 | } 60 | } 61 | 62 | int 63 | main(int argc, char **argv) 64 | { 65 | char *argv0; 66 | int color,width; 67 | 68 | color = width = -1; 69 | 70 | if (argc < 2) 71 | usage(argv[0]); 72 | 73 | ARGBEGIN { 74 | case 's': 75 | width = strtoul(EARGF(usage(argv0)), NULL, 10); 76 | break; 77 | case 'c': 78 | color = strtoul(EARGF(usage(argv0)), NULL, 16); 79 | break; 80 | default: 81 | usage(argv0); 82 | /* NOTREACHED */ 83 | } ARGEND 84 | 85 | init_xcb(&conn); 86 | 87 | /* assume remaining arguments are windows */ 88 | while (*argv) 89 | set_border(width, color, strtoul(*argv++, NULL, 16)); 90 | 91 | xcb_aux_sync(conn); 92 | 93 | kill_xcb(&conn); 94 | 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /chwso.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "arg.h" 10 | #include "util.h" 11 | 12 | static xcb_connection_t *conn; 13 | 14 | static void usage(char *); 15 | static void stack(xcb_window_t, uint32_t[1]); 16 | 17 | static void 18 | usage(char *name) 19 | { 20 | fprintf(stderr, "usage: %s -rli \n", name); 21 | exit(1); 22 | } 23 | 24 | static void 25 | stack(xcb_window_t win, uint32_t values[1]) 26 | { 27 | xcb_configure_window(conn, win, XCB_CONFIG_WINDOW_STACK_MODE, values); 28 | } 29 | 30 | int 31 | main(int argc, char **argv) 32 | { 33 | xcb_window_t win; 34 | uint32_t values[1]; 35 | char *argv0 = NULL; 36 | 37 | if (argc != 3) 38 | usage(argv[0]); 39 | 40 | init_xcb(&conn); 41 | 42 | win = strtoul(argv[2], NULL, 16); 43 | if (!win) 44 | return 1; 45 | 46 | ARGBEGIN { 47 | case 'r': 48 | values[0] = XCB_STACK_MODE_ABOVE; 49 | break; 50 | case 'l': 51 | values[0] = XCB_STACK_MODE_BELOW; 52 | break; 53 | case 'i': 54 | values[0] = XCB_STACK_MODE_OPPOSITE; 55 | break; 56 | default: 57 | usage(argv0); 58 | break; 59 | } ARGEND 60 | 61 | stack(win, values); 62 | xcb_aux_sync(conn); 63 | 64 | kill_xcb(&conn); 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /config.mk: -------------------------------------------------------------------------------- 1 | PREFIX = /usr 2 | MANPREFIX = $(PREFIX)/man 3 | 4 | CC = cc 5 | LD = $(CC) 6 | 7 | CFLAGS = -std=c99 -pedantic -Wall -Os -I/usr/X11R6/include 8 | LDFLAGS = -lxcb -lxcb-util -lxcb-cursor -L/usr/X11R6/lib 9 | 10 | -------------------------------------------------------------------------------- /ignw.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "arg.h" 10 | #include "util.h" 11 | 12 | static xcb_connection_t *conn; 13 | 14 | static void usage(char *); 15 | static void set_override(xcb_window_t, int); 16 | 17 | static void 18 | usage(char *name) 19 | { 20 | fprintf(stderr, "usage: %s [-sr] [wid..]\n", name); 21 | exit(1); 22 | } 23 | 24 | static void 25 | set_override(xcb_window_t w, int or) 26 | { 27 | uint32_t mask = XCB_CW_OVERRIDE_REDIRECT; 28 | uint32_t val[] = { or }; 29 | 30 | xcb_change_window_attributes(conn, w, mask, val); 31 | } 32 | 33 | int 34 | main(int argc, char **argv) 35 | { 36 | int setflag = 0; 37 | char *argv0; 38 | 39 | ARGBEGIN { 40 | case 's': setflag = 1; break; 41 | case 'r': setflag = 0; break; 42 | default: usage(argv0); 43 | } ARGEND; 44 | 45 | init_xcb(&conn); 46 | 47 | while (*argv) 48 | set_override(strtoul(*argv++, NULL, 16), setflag); 49 | 50 | xcb_aux_sync(conn); 51 | 52 | kill_xcb(&conn); 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /killw.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "arg.h" 10 | #include "util.h" 11 | 12 | static xcb_connection_t *conn; 13 | 14 | static void usage(char *); 15 | 16 | static void 17 | usage (char *name) 18 | { 19 | fprintf(stderr, "usage: %s [-p] [wid...]\n", name); 20 | exit(1); 21 | } 22 | 23 | int 24 | main(int argc, char **argv) 25 | { 26 | int parent = 0; 27 | char *argv0; 28 | 29 | if (argc < 2) 30 | usage(argv[0]); 31 | 32 | ARGBEGIN{ 33 | case 'p': parent=1; break; 34 | default: usage(argv0); 35 | }ARGEND; 36 | 37 | init_xcb(&conn); 38 | 39 | /* assume remaining arguments are windows */ 40 | while (*argv) { 41 | if (parent) { 42 | /* kills the client whose WID belongs to */ 43 | xcb_kill_client(conn, strtoul(*argv++, NULL, 16)); 44 | } else { 45 | /* destroy the given window and all its children */ 46 | xcb_destroy_window(conn, strtoul(*argv++, NULL, 16)); 47 | } 48 | } 49 | 50 | xcb_aux_sync(conn); 51 | kill_xcb(&conn); 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /lsw.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "arg.h" 10 | #include "util.h" 11 | 12 | static xcb_connection_t *conn; 13 | static xcb_screen_t *scrn; 14 | 15 | static void usage(char *); 16 | static int should_list(xcb_window_t, int); 17 | static void list_windows(xcb_window_t, int); 18 | 19 | enum { 20 | LIST_HIDDEN = 1 << 0, 21 | LIST_IGNORE = 1 << 1, 22 | LIST_ALL = 1 << 2 23 | }; 24 | 25 | static void 26 | usage(char *name) 27 | { 28 | fprintf(stderr, "usage: %s [-houra] [wid...]\n", name); 29 | exit(1); 30 | } 31 | 32 | static int 33 | should_list(xcb_window_t w, int mask) 34 | { 35 | if ((mask & LIST_ALL) 36 | || (!mapped(conn, w) && mask & LIST_HIDDEN) 37 | || (ignore(conn, w) && mask & LIST_IGNORE) 38 | || (mapped(conn, w) 39 | && !ignore(conn, w) 40 | && mask == 0)) 41 | return 1; 42 | 43 | return 0; 44 | } 45 | 46 | static void 47 | list_windows(xcb_window_t w, int listmask) 48 | { 49 | int i, wn; 50 | xcb_window_t *wc; 51 | 52 | wn = get_windows(conn, w, &wc); 53 | 54 | if (wc == NULL) 55 | errx(1, "0x%08x: unable to retrieve children", w); 56 | 57 | for (i=0; iroot); 84 | return 0; 85 | } 86 | 87 | if (argc == 0) 88 | list_windows(scrn->root, listmask); 89 | 90 | while (*argv) 91 | list_windows(strtoul(*argv++, NULL, 16), listmask); 92 | 93 | kill_xcb(&conn); 94 | 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /man/Makefile: -------------------------------------------------------------------------------- 1 | include ../config.mk 2 | 3 | MAN = \ 4 | pfw.1 \ 5 | lsw.1 \ 6 | mapw.1 \ 7 | killw.1 \ 8 | wattr.1 \ 9 | wtp.1 \ 10 | wmv.1 \ 11 | chwso.1 \ 12 | wtf.1 \ 13 | wrs.1 \ 14 | chwb.1 \ 15 | ignw.1 \ 16 | wmp.1 \ 17 | slw.1 \ 18 | atomx.1 \ 19 | wmutils.1 20 | 21 | .POSIX: 22 | 23 | install: $(MAN) 24 | mkdir -p $(DESTDIR)$(MANPREFIX)/man1/ 25 | cp -f $(MAN) $(DESTDIR)$(MANPREFIX)/man1/ 26 | 27 | uninstall: 28 | @echo "uninstalling manpages" 29 | @for page in $(MAN); do \ 30 | rm -f $(DESTDIR)$(MANPREFIX)/man1/$$page; \ 31 | done 32 | -------------------------------------------------------------------------------- /man/atomx.1: -------------------------------------------------------------------------------- 1 | .Dd November 21, 2019 2 | .Dt ATOMX 1 3 | .Os wmutils 4 | .Sh NAME 5 | .Nm atomx 6 | .Nd manage X atoms on a window 7 | .Sh SYNOPSIS 8 | .Nm atomx 9 | .Op Fl d 10 | .Ar atom 11 | .Op Ar =value 12 | .Ar wid 13 | .Sh DESCRIPTION 14 | .Nm 15 | will print, add, change and remove X atoms on the window with ID 16 | .Ar wid . 17 | By default 18 | .Nm 19 | will print the value of the atom 20 | .Ar atom 21 | if it exists. 22 | .Pp 23 | To set an atom on a window, you must specify it as 24 | .Ar atom=value . 25 | .Bl -tag -width Ds 26 | .It Fl d 27 | Delete atom 28 | .Ar atom 29 | from the window. 30 | .Sh ENVIRONMENT 31 | .Nm 32 | acts on the X display specified by the 33 | .Ev DISPLAY 34 | variable. 35 | .Sh EXAMPLES 36 | Print value of property "WM_CLASS" 37 | .Dl $ atomx WM_CLASS 0x00e00005 38 | .Pp 39 | Change window name to "atomx" 40 | .Dl $ atomx WM_NAME=atomx 0x00e00005 41 | .Pp 42 | Delete property "IS_FULLSCREEN" on a window 43 | .Dl $ atomx -d IS_FULLSCREEN 0x00e00005 44 | -------------------------------------------------------------------------------- /man/chwb.1: -------------------------------------------------------------------------------- 1 | .Dd December 13, 2014 2 | .Dt CHWB 1 3 | .Os wmutils 4 | .Sh NAME 5 | .Nm chwb 6 | .Nd change window borders 7 | .Sh SYNOPSIS 8 | .Nm chwb 9 | .Op Fl c Ar color 10 | .Op Fl s Ar size 11 | .Ar wid Op Ar ... 12 | .Sh DESCRIPTION 13 | .Nm 14 | changes the border size or color of the window 15 | .Ar wid . 16 | .Bl -tag -width Ds 17 | .It Fl c Ar color 18 | Set border color of 19 | .Ar wid 20 | to 21 | .Ar color . 22 | Colors should be passed as numerical values (see 23 | .Xr strtoul 3 ) 24 | in RGB format. 25 | .It Fl s Ar size 26 | Set border width of 27 | .Ar wid 28 | to 29 | .Ar size . 30 | .El 31 | .Sh ENVIRONMENT 32 | .Nm 33 | acts on the X display specified by the 34 | .Ev DISPLAY 35 | variable. 36 | .Sh EXAMPLES 37 | Set the border color to 128 red, 100 green, 204 blue: 38 | .Dl $ chwb -c 0x8064cc 39 | .Sh SEE ALSO 40 | .Xr strtoul 3 41 | -------------------------------------------------------------------------------- /man/chwso.1: -------------------------------------------------------------------------------- 1 | .Dd December 13, 2014 2 | .Dt CHWSO 1 3 | .Os wmutils 4 | .Sh NAME 5 | .Nm chwso 6 | .Nd change window stacking order 7 | .Sh SYNOPSIS 8 | .Nm chwso 9 | .Op Fl ilr 10 | .Ar wid 11 | .Sh DESCRIPTION 12 | .Nm 13 | will change the place of a window in the server\(cqs window stack, 14 | putting it in either the foreground or the background. 15 | .Bl -tag -width Ds 16 | .It Fl i 17 | Invert 18 | .Ar wid Ns \(cqs 19 | position in the window stack. 20 | .It Fl l 21 | Put 22 | .Ar wid 23 | at the bottom of the window stack. 24 | .It Fl r 25 | Put 26 | .Ar wid 27 | on top of the window stack. 28 | .El 29 | .Sh ENVIRONMENT 30 | .Nm 31 | acts on the X display specified by the 32 | .Ev DISPLAY 33 | variable. 34 | -------------------------------------------------------------------------------- /man/ignw.1: -------------------------------------------------------------------------------- 1 | .Dd December 13, 2014 2 | .Dt IGNW 1 3 | .Os wmutils 4 | .Sh NAME 5 | .Nm ignw 6 | .Nd ignore window 7 | .Sh SYNOPSIS 8 | .Nm ignw 9 | .Fl rs 10 | .Ar wid Op ... 11 | .Sh DESCRIPTION 12 | .Nm 13 | changes the value of the 14 | .Em override_redirect 15 | attribute of a window to either 0 or 1. 16 | This affects whether the window manager ignores the window. 17 | .Bl -tag -width Ds 18 | .It Fl r 19 | Reset 20 | .Ar wid Ns \(cqs 21 | .Em override_redirect 22 | value to 0, unignoring the window. 23 | .It Fl s 24 | Set 25 | .Ar wid Ns \(cqs 26 | .Em override_redirect 27 | value to 1, ignoring the window. 28 | .El 29 | .Sh ENVIRONMENT 30 | .Nm 31 | acts on the X display specified by the 32 | .Ev DISPLAY 33 | variable. 34 | .Sh SEE ALSO 35 | .Xr lsw 1 , 36 | .Xr wattr 1 , 37 | .Xr xcb_get_window_attributes 3 38 | -------------------------------------------------------------------------------- /man/killw.1: -------------------------------------------------------------------------------- 1 | .Dd December 13, 2014 2 | .Dt KILLW 1 3 | .Os wmutils 4 | .Sh NAME 5 | .Nm killw 6 | .Nd kill windows 7 | .Sh SYNOPSIS 8 | .Nm killw 9 | .Op Fl p 10 | .Ar wid Op ... 11 | .Sh DESCRIPTION 12 | .Nm 13 | will destroy the window passed as an argument, and all its children. 14 | .Sh OPTIONS 15 | .Bl -tag -width Ds 16 | .It Fl p 17 | Kill the parent application of the window instead of the window itself. 18 | This is useful to terminate frozen applications (This will close all the windows 19 | belonging to the applications). 20 | .El 21 | .Sh ENVIRONMENT 22 | .Nm 23 | acts on the X display specified by the 24 | .Ev DISPLAY 25 | variable. 26 | -------------------------------------------------------------------------------- /man/lsw.1: -------------------------------------------------------------------------------- 1 | .Dd December 13, 2014 2 | .Dt LSW 1 3 | .Os wmutils 4 | .Sh NAME 5 | .Nm lsw 6 | .Nd list child windows 7 | .Sh SYNOPSIS 8 | .Nm lsw 9 | .Op Fl arou 10 | .Op Ar wid ... 11 | .Sh DESCRIPTION 12 | .Nm 13 | lists child windows of the given window. 14 | If no windows are given, 15 | .Nm 16 | lists the children of the root window. 17 | .Pp 18 | By default, 19 | .Nm 20 | lists only windows that are mapped (visible) and with the 21 | .Em override_redirect 22 | value set to 0 (i.e., unignored). 23 | .Bl -tag -width Ds 24 | .It Fl a 25 | List all windows. 26 | .It Fl r 27 | Print the ID of the root window. 28 | .It Fl o 29 | List windows whose 30 | .Em override_redirect 31 | attribute is set to 1. 32 | .It Fl u 33 | List unmapped (invisible) windows. 34 | .El 35 | .Sh ENVIRONMENT 36 | .Nm 37 | acts on the X display specified by the 38 | .Ev DISPLAY 39 | variable. 40 | .Sh SEE ALSO 41 | .Xr ignw 1 , 42 | .Xr mapw 1 , 43 | .Xr xargs 1 44 | -------------------------------------------------------------------------------- /man/mapw.1: -------------------------------------------------------------------------------- 1 | .Dd December 13, 2014 2 | .Dt MAPW 1 3 | .Os wmutils 4 | .Sh NAME 5 | .Nm mapw 6 | .Nd map or unmap window 7 | .Sh SYNOPSIS 8 | .Nm mapw 9 | .Op Fl mtu 10 | .Ar wid Op ... 11 | .Sh DESCRIPTION 12 | .Nm 13 | will either map or unmap a window from the screen, 14 | thus modifying the visibility state of the window. 15 | .Bl -tag -width Ds 16 | .It Fl m 17 | Map (show) 18 | .Ar wid . 19 | .It Fl t 20 | Toggle 21 | .Ar wid Ns \(cqs visibility. 22 | .It Fl u 23 | Unmap (hide) 24 | .Ar wid . 25 | .El 26 | .Sh ENVIRONMENT 27 | .Nm 28 | acts on the X display specified by the 29 | .Ev DISPLAY 30 | variable. 31 | .Sh SEE ALSO 32 | .Xr lsw 1 33 | -------------------------------------------------------------------------------- /man/pdw.1: -------------------------------------------------------------------------------- 1 | .Dd July 01, 2022 2 | .Dt PDW 1 3 | .Os wmutils 4 | .Sh NAME 5 | .Nm pdw 6 | .Nd print decoration window 7 | .Sh SYNOPSIS 8 | .Nm pdw 9 | .Op Ar wid 10 | .Sh DESCRIPTION 11 | Print the ID of the highest parent related to 12 | .Ar wid 13 | (or currently focused window when 14 | .Ar wid 15 | is omitted). 16 | .Pp 17 | In reparenting environments, this is usually the decoration window. 18 | .Sh ENVIRONMENT 19 | .Nm 20 | acts on the X display specified by the 21 | .Ev DISPLAY 22 | variable. 23 | .Sh SEE ALSO 24 | .Xr pfw 1 25 | -------------------------------------------------------------------------------- /man/pfw.1: -------------------------------------------------------------------------------- 1 | .Dd December 13, 2014 2 | .Dt PFW 1 3 | .Os wmutils 4 | .Sh NAME 5 | .Nm pfw 6 | .Nd print focused window 7 | .Sh SYNOPSIS 8 | .Nm pfw 9 | .Sh DESCRIPTION 10 | Print the ID of the currently focused window to 11 | .Dv stdout . 12 | .Sh ENVIRONMENT 13 | .Nm 14 | acts on the X display specified by the 15 | .Ev DISPLAY 16 | variable. 17 | -------------------------------------------------------------------------------- /man/slw.1: -------------------------------------------------------------------------------- 1 | .Dd October 14, 2019 2 | .Dt SLW 1 3 | .Os wmutils 4 | .Sh NAME 5 | .Nm slw 6 | .Nd select window interactively 7 | .Sh SYNOPSIS 8 | .Nm slw 9 | .Sh DESCRIPTION 10 | Wait for a button press event and print the window ID that got the 11 | event to 12 | .Dv stdout . 13 | .Sh ENVIRONMENT 14 | .Nm 15 | acts on the X display specified by the 16 | .Ev DISPLAY 17 | variable. 18 | -------------------------------------------------------------------------------- /man/wattr.1: -------------------------------------------------------------------------------- 1 | '\" e 2 | .Dd December 13, 2014 3 | .Dt WATTR 1 4 | .Os wmutils 5 | .Sh NAME 6 | .Nm wattr 7 | .Nd get window attributes 8 | .Sh SYNOPSIS 9 | .Nm wattr 10 | .Op Cm bmiowhxy 11 | .Ar wid 12 | .Sh DESCRIPTION 13 | .Nm 14 | prints information about the window 15 | .Ar wid 16 | to 17 | .Dv stdout . 18 | .Pp 19 | What information is presented depends on the commands given to 20 | .Nm . 21 | The queried arguments are printed in the order they are requested, 22 | separated by a space. 23 | If no commands are given, 24 | .Nm 25 | will return 0 if 26 | .Ar wid 27 | exists, and 1 otherwise. 28 | .Bl -tag -width Ds 29 | .It Cm i 30 | Print 31 | .Ar wid 32 | .It Cm b 33 | Print 34 | .Ar wid Ns \(cqs border width. 35 | .It Cm x 36 | Print 37 | .Ar wid Ns \(cqs 38 | .EQ 39 | x 40 | .EN 41 | offset. 42 | .It Cm y 43 | Print 44 | .Ar wid Ns \(cqs 45 | .EQ 46 | y 47 | .EN 48 | offset. 49 | .It Cm w 50 | Print 51 | .Ar wid Ns \(cqs width. 52 | .It Cm h 53 | Print 54 | .Ar wid Ns \(cqs 55 | height. 56 | .It Cm o 57 | .Nm 58 | returns 0 if the override_redirect attribute is set on the window. 59 | .It Cm m 60 | .Nm 61 | returns 0 if 62 | .Ar wid 63 | is mapped on screen, and 1 otherwise. 64 | .El 65 | .Sh ENVIRONMENT 66 | .Nm 67 | acts on the X display specified by the 68 | .Ev DISPLAY 69 | variable. 70 | .Sh EXAMPLES 71 | .Dl $ wattr m 0x01000006 && echo ismapped 72 | .Dl ismapped 73 | .Pp 74 | .Dl $ wattr whxy 0x01000006 75 | .Dl 484 244 756 166 76 | .Pp 77 | .Dl $ wattr xyhw 0x01000006 78 | .Dl 756 166 244 484 79 | .Pp 80 | .Dl $ wattr 0x00000000 ; echo $? 81 | .Dl 1 82 | -------------------------------------------------------------------------------- /man/wmp.1: -------------------------------------------------------------------------------- 1 | .Dd December 17, 2014 2 | .Dt WMP 1 3 | .Os wmutils 4 | .Sh NAME 5 | .Nm wmp 6 | .Nd warp mouse cursor 7 | .Sh SYNOPSIS 8 | .Nm wmp 9 | .Fl [ ar 10 | .Ar ] 11 | .Ar [ wid ] 12 | .Sh DESCRIPTION 13 | .Nm 14 | warps cursor to an absolute or relative position, passed by 15 | .Ar x 16 | and 17 | .Ar y . 18 | Returns the position relative to the root window, or 19 | .Ar wid . 20 | .Sh ENVIRONMENT 21 | .Nm 22 | acts on the X display specified by the 23 | .Ev DISPLAY 24 | variable. 25 | .Sh EXAMPLES 26 | .Pp 27 | .Dl $ wmp -a $(wattr xy $(pfw)) 28 | .Pp 29 | .Dl $ wmp -r 100 0 30 | .Pp 31 | .Dl $ wmp -r -- -100 0 32 | .Pp 33 | .Dl $ wmp 0x01600006 34 | .Dl 311 49 35 | .Pp 36 | .Dl $ wmp 37 | .Dl 915 548 38 | -------------------------------------------------------------------------------- /man/wmutils.1: -------------------------------------------------------------------------------- 1 | .Dd June 9, 2015 2 | .Dt WMUTILS 1 3 | .Os wmutils 4 | .Sh NAME 5 | .Nm wmutils 6 | .Nd window manipulation utilities 7 | .Sh DESCRIPTION 8 | .Nm 9 | is a compilation of utilities for manipulating windows in X 10 | .Sh COMMANDS 11 | .Bl -tag -width Ds -offset 60 12 | .It chwb 13 | change window's border 14 | .It chwso 15 | change window's stacking order 16 | .It ignw 17 | ignore/unignore window 18 | .It killw 19 | kill windows 20 | .It lsw 21 | list windows 22 | .It mapw 23 | map/unmap windows 24 | .It pfw 25 | print focused window 26 | .It pdw 27 | print decoration window 28 | .It wattr 29 | show window's attributes 30 | .It wmp 31 | move the mouse pointer 32 | .It wmv 33 | move a window 34 | .It wrs 35 | resize a window 36 | .It wtf 37 | focus a window 38 | .It wtp 39 | teleport a window 40 | .It atomx 41 | modify atoms on a window 42 | .El 43 | .Sh ENVIRONMENT 44 | .Nm 45 | acts on the X display specified by the 46 | .Ev DISPLAY 47 | variable. 48 | .Sh SEE ALSO 49 | .Xr chwb 1 , 50 | .Xr chwso 1 , 51 | .Xr ignw 1 , 52 | .Xr killw 1 , 53 | .Xr lsw 1 , 54 | .Xr mapw 1 , 55 | .Xr pfw 1 , 56 | .Xr pdw 1 , 57 | .Xr wattr 1 , 58 | .Xr wmp 1 , 59 | .Xr wmv 1 , 60 | .Xr wname 1 , 61 | .Xr wrs 1 , 62 | .Xr wtf 1 , 63 | .Xr wtp 1 , 64 | .Xr atomx 1 65 | -------------------------------------------------------------------------------- /man/wmv.1: -------------------------------------------------------------------------------- 1 | '\" e 2 | .Dd December 13, 2014 3 | .Dt WMV 1 4 | .Os wmutils 5 | .Sh NAME 6 | .Nm wmv 7 | .Nd move windows 8 | .Sh SYNOPSIS 9 | .Nm wmv 10 | .Op Fl a 11 | .Ar x y wid 12 | .Sh DESCRIPTION 13 | .Nm wmv 14 | repositions 15 | .Ar wid 16 | relatively, 17 | .Ar x 18 | pixels in the 19 | .EQ 20 | x 21 | .EN 22 | direction and 23 | .Ar y 24 | pixels in the 25 | .EQ 26 | y 27 | .EN 28 | direction. 29 | .Bl -tag -width Ds 30 | .It Fl a 31 | Absolute mode. The window will be centered to the 32 | .Ar x 33 | and 34 | .Ar y 35 | coordinates. 36 | .El 37 | .Sh ENVIRONMENT 38 | .Nm 39 | acts on the X display specified by the 40 | .Ev DISPLAY 41 | variable. 42 | -------------------------------------------------------------------------------- /man/wrs.1: -------------------------------------------------------------------------------- 1 | .Dd December 13, 2014 2 | .Dt WRS 1 3 | .Os wmutils 4 | .Sh NAME 5 | .Nm wrs 6 | .Nd resize windows 7 | .Sh SYNOPSIS 8 | .Nm wrs 9 | .Op Fl a 10 | .Ar x y wid Op ... 11 | .Sh DESCRIPTION 12 | .Nm 13 | resizes the window 14 | .Ar wid 15 | based on the relative pixel values 16 | .Ar x 17 | and 18 | .Ar y . 19 | .Bl -tag -width Ds 20 | .It Fl a 21 | Absolute mode. The window will be resized up to the 22 | .Ar x 23 | and 24 | .Ar y 25 | coordinates. 26 | .El 27 | .Sh ENVIRONMENT 28 | .Nm 29 | acts on the X display specified by the 30 | .Ev DISPLAY 31 | variable. 32 | -------------------------------------------------------------------------------- /man/wtf.1: -------------------------------------------------------------------------------- 1 | .Dd December 13, 2014 2 | .Dt WTF 1 3 | .Os wmutils 4 | .Sh NAME 5 | .Nm wtf 6 | .Nd transfer window focus 7 | .Sh SYNOPSIS 8 | .Nm wtf 9 | .Ar wid 10 | .Sh DESCRIPTION 11 | .Nm 12 | sets the keyboard input focus to the window 13 | .Ar wid 14 | if it exists and is viewable. 15 | .Sh ENVIRONMENT 16 | .Nm 17 | acts on the X display specified by the 18 | .Ev DISPLAY 19 | variable. 20 | -------------------------------------------------------------------------------- /man/wtp.1: -------------------------------------------------------------------------------- 1 | .Dd December 13, 2014 2 | .Dt WTP 1 3 | .Os wmutils 4 | .Sh NAME 5 | .Nm wtp 6 | .Nd teleport window (absolutely) 7 | .Sh SYNOPSIS 8 | .Nm wtp 9 | .Ar x y w h wid 10 | .Sh DESCRIPTION 11 | .Nm 12 | moves (or teleports) the window 13 | .Ar wid 14 | to the position given by 15 | .Ar x 16 | and 17 | .Ar y , 18 | and resize it to width 19 | .Ar w 20 | and height 21 | .Ar h . 22 | Value are absolute value from the the upper-left-hand corner. 23 | .Sh ENVIRONMENT 24 | .Nm 25 | acts on the X display specified by the 26 | .Ev DISPLAY 27 | variable. 28 | -------------------------------------------------------------------------------- /mapw.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "arg.h" 10 | #include "util.h" 11 | 12 | enum { 13 | MAP = 1 << 0, 14 | UNMAP = 1 << 1, 15 | TOGGLE = 1 << 2 16 | }; 17 | 18 | static xcb_connection_t *conn; 19 | 20 | static void usage(char *); 21 | 22 | static void 23 | usage(char *name) 24 | { 25 | fprintf(stderr, "usage: %s [-h] [-mut [wid..]]\n", name); 26 | exit(1); 27 | } 28 | 29 | int 30 | main(int argc, char **argv) 31 | { 32 | int mapflag = 0; 33 | xcb_window_t w = 0; 34 | char *argv0; 35 | 36 | ARGBEGIN { 37 | case 'm': mapflag = MAP; break; 38 | case 'u': mapflag = UNMAP; break; 39 | case 't': mapflag = TOGGLE; break; 40 | default : usage(argv0); 41 | } ARGEND; 42 | 43 | if (argc < 1 || mapflag == 0) 44 | usage(argv0); 45 | 46 | init_xcb(&conn); 47 | 48 | while (*argv) { 49 | w = strtoul(*argv++, NULL, 16); 50 | 51 | switch (mapflag) { 52 | case MAP: 53 | xcb_map_window(conn, w); 54 | break; 55 | case UNMAP: 56 | xcb_unmap_window(conn, w); 57 | break; 58 | case TOGGLE: 59 | if (mapped(conn, w)) 60 | xcb_unmap_window(conn, w); 61 | else 62 | xcb_map_window(conn, w); 63 | break; 64 | } 65 | } 66 | xcb_aux_sync(conn); 67 | 68 | kill_xcb(&conn); 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /pdw.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "util.h" 11 | 12 | static xcb_connection_t *conn; 13 | static xcb_screen_t *scrn; 14 | 15 | static void usage(char *); 16 | static xcb_window_t focus_window(void); 17 | static xcb_window_t parent(xcb_window_t); 18 | 19 | static void 20 | usage(char *name) 21 | { 22 | fprintf(stderr, "usage: %s [wid]\n", name); 23 | exit(1); 24 | } 25 | 26 | static xcb_window_t 27 | focus_window(void) 28 | { 29 | xcb_window_t w = 0; 30 | xcb_get_input_focus_cookie_t c; 31 | xcb_get_input_focus_reply_t *r; 32 | 33 | c = xcb_get_input_focus(conn); 34 | r = xcb_get_input_focus_reply(conn, c, NULL); 35 | if (r == NULL) 36 | errx(1, "xcb_get_input_focus"); 37 | 38 | w = r->focus; 39 | free(r); 40 | 41 | if (w == XCB_NONE || w == XCB_INPUT_FOCUS_POINTER_ROOT) 42 | errx(1, "focus not set"); 43 | 44 | return w; 45 | } 46 | 47 | static xcb_window_t 48 | parent(xcb_window_t w) 49 | { 50 | xcb_query_tree_cookie_t c; 51 | xcb_query_tree_reply_t *r; 52 | 53 | c = xcb_query_tree(conn, w); 54 | r = xcb_query_tree_reply(conn, c, NULL); 55 | if (r == NULL) 56 | errx(1, "failed to get parent"); 57 | 58 | w = (!r->parent || r->parent == scrn->root) ? w : parent(r->parent); 59 | free(r); 60 | 61 | return w; 62 | } 63 | 64 | int 65 | main(int argc, char **argv) 66 | { 67 | xcb_window_t w; 68 | 69 | if (argc > 2 || (argc > 1 && (!strncmp(argv[1], "-h", 2)))) 70 | usage(argv[0]); 71 | 72 | init_xcb(&conn); 73 | get_screen(conn, &scrn); 74 | 75 | w = (argc > 1) ? strtoul(argv[1], NULL, 16) : focus_window(); 76 | 77 | printf("0x%08x\n", parent(w)); 78 | 79 | kill_xcb(&conn); 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /pfw.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "util.h" 10 | 11 | static xcb_connection_t *conn; 12 | 13 | static xcb_window_t focus_window(void); 14 | 15 | static xcb_window_t 16 | focus_window(void) 17 | { 18 | xcb_window_t w = 0; 19 | xcb_get_input_focus_cookie_t c; 20 | xcb_get_input_focus_reply_t *r; 21 | 22 | c = xcb_get_input_focus(conn); 23 | r = xcb_get_input_focus_reply(conn, c, NULL); 24 | if (r == NULL) 25 | errx(1, "xcb_get_input_focus"); 26 | 27 | w = r->focus; 28 | free(r); 29 | 30 | if (w == XCB_NONE || w == XCB_INPUT_FOCUS_POINTER_ROOT) 31 | errx(1, "focus not set"); 32 | 33 | return w; 34 | } 35 | 36 | int 37 | main(int argc, char **argv) 38 | { 39 | init_xcb(&conn); 40 | 41 | printf("0x%08x\n", focus_window()); 42 | 43 | kill_xcb(&conn); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /slw.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "util.h" 11 | 12 | /* use "heart" to show us your love! */ 13 | #define XHAIR "tcross" 14 | 15 | static xcb_connection_t *conn; 16 | static xcb_screen_t *scr; 17 | 18 | static xcb_window_t 19 | select_window(void) 20 | { 21 | uint32_t val[] = { XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE }; 22 | xcb_window_t w = 0; 23 | xcb_cursor_t p; 24 | xcb_cursor_context_t *ctx; 25 | xcb_grab_pointer_cookie_t c; 26 | xcb_grab_pointer_reply_t *r; 27 | xcb_generic_event_t *e; 28 | 29 | if (xcb_cursor_context_new(conn, scr, &ctx) < 0) 30 | errx(1, "cannot instantiate cursor"); 31 | 32 | p = xcb_cursor_load_cursor(ctx, XHAIR); 33 | xcb_flush(conn); 34 | 35 | c = xcb_grab_pointer(conn, 0, scr->root, 36 | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE, 37 | XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, p, 38 | XCB_CURRENT_TIME); 39 | 40 | r = xcb_grab_pointer_reply(conn, c, NULL); 41 | if (!r || r->status != XCB_GRAB_STATUS_SUCCESS) 42 | errx(1, "couldn't grab pointer"); 43 | 44 | xcb_change_window_attributes(conn, scr->root, XCB_CW_EVENT_MASK, val); 45 | xcb_flush(conn); 46 | 47 | for (;;) { 48 | e = xcb_wait_for_event(conn); 49 | switch ((e->response_type & ~0x80)) { 50 | case XCB_BUTTON_PRESS: 51 | w = ((xcb_button_press_event_t*)e)->child; 52 | break; 53 | case XCB_BUTTON_RELEASE: 54 | xcb_cursor_context_free(ctx); 55 | return w; 56 | break; /* NOTREACHED */ 57 | } 58 | } 59 | } 60 | 61 | int 62 | main(int argc, char **argv) 63 | { 64 | init_xcb(&conn); 65 | get_screen(conn, &scr); 66 | 67 | printf("0x%08x\n", select_window()); 68 | 69 | kill_xcb(&conn); 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /util.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "util.h" 8 | 9 | void 10 | init_xcb(xcb_connection_t **con) 11 | { 12 | *con = xcb_connect(NULL, NULL); 13 | if (xcb_connection_has_error(*con)) 14 | errx(1, "unable connect to the X server"); 15 | } 16 | 17 | void 18 | kill_xcb(xcb_connection_t **con) 19 | { 20 | if (*con) 21 | xcb_disconnect(*con); 22 | } 23 | 24 | void 25 | get_screen(xcb_connection_t *con, xcb_screen_t **scr) 26 | { 27 | *scr = xcb_setup_roots_iterator(xcb_get_setup(con)).data; 28 | if (*scr == NULL) 29 | errx(1, "unable to retrieve screen informations"); 30 | } 31 | 32 | int 33 | exists(xcb_connection_t *con, xcb_window_t w) 34 | { 35 | xcb_get_window_attributes_cookie_t c; 36 | xcb_get_window_attributes_reply_t *r; 37 | 38 | c = xcb_get_window_attributes(con, w); 39 | r = xcb_get_window_attributes_reply(con, c, NULL); 40 | 41 | if (r == NULL) 42 | return 0; 43 | 44 | free(r); 45 | return 1; 46 | } 47 | 48 | int 49 | mapped(xcb_connection_t *con, xcb_window_t w) 50 | { 51 | int ms; 52 | xcb_get_window_attributes_cookie_t c; 53 | xcb_get_window_attributes_reply_t *r; 54 | 55 | c = xcb_get_window_attributes(con, w); 56 | r = xcb_get_window_attributes_reply(con, c, NULL); 57 | 58 | if (r == NULL) 59 | return 0; 60 | 61 | ms = r->map_state; 62 | 63 | free(r); 64 | return ms == XCB_MAP_STATE_VIEWABLE; 65 | } 66 | 67 | int 68 | ignore(xcb_connection_t *con, xcb_window_t w) 69 | { 70 | int or; 71 | xcb_get_window_attributes_cookie_t c; 72 | xcb_get_window_attributes_reply_t *r; 73 | 74 | c = xcb_get_window_attributes(con, w); 75 | r = xcb_get_window_attributes_reply(con, c, NULL); 76 | 77 | if (r == NULL) 78 | return 0; 79 | 80 | or = r->override_redirect; 81 | 82 | free(r); 83 | return or; 84 | } 85 | 86 | int 87 | get_windows(xcb_connection_t *con, xcb_window_t w, xcb_window_t **l) 88 | { 89 | uint32_t childnum = 0; 90 | xcb_query_tree_cookie_t c; 91 | xcb_query_tree_reply_t *r; 92 | 93 | c = xcb_query_tree(con, w); 94 | r = xcb_query_tree_reply(con, c, NULL); 95 | if (r == NULL) 96 | errx(1, "0x%08x: no such window", w); 97 | 98 | *l = malloc(sizeof(xcb_window_t) * r->children_len); 99 | memcpy(*l, xcb_query_tree_children(r), 100 | sizeof(xcb_window_t) * r->children_len); 101 | 102 | childnum = r->children_len; 103 | 104 | free(r); 105 | return childnum; 106 | } 107 | -------------------------------------------------------------------------------- /util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_H__ 2 | #define UTIL_H__ 3 | 4 | void init_xcb(xcb_connection_t **); 5 | void kill_xcb(xcb_connection_t **); 6 | 7 | void get_screen(xcb_connection_t *, xcb_screen_t **); 8 | int get_windows(xcb_connection_t *, xcb_window_t, xcb_window_t **); 9 | 10 | int exists(xcb_connection_t *, xcb_window_t); 11 | int mapped(xcb_connection_t *, xcb_window_t); 12 | int ignore(xcb_connection_t *, xcb_window_t); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /wattr.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "util.h" 11 | 12 | static xcb_connection_t *conn; 13 | 14 | static void usage(char *); 15 | static int get_attribute(xcb_window_t, int); 16 | 17 | enum { 18 | ATTR_W = 1 << 0, 19 | ATTR_H = 1 << 1, 20 | ATTR_X = 1 << 2, 21 | ATTR_Y = 1 << 3, 22 | ATTR_B = 1 << 4, 23 | ATTR_M = 1 << 5, 24 | ATTR_I = 1 << 6, 25 | ATTR_MAX 26 | }; 27 | 28 | static void 29 | usage(char *name) 30 | { 31 | fprintf(stderr, "usage: %s [-h] [bmiowhxy] \n", name); 32 | exit(1); 33 | } 34 | 35 | static int 36 | get_attribute(xcb_window_t w, int attr) 37 | { 38 | xcb_get_geometry_cookie_t c; 39 | xcb_get_geometry_reply_t *r; 40 | 41 | c = xcb_get_geometry(conn, w); 42 | r = xcb_get_geometry_reply(conn, c, NULL); 43 | 44 | if (r == NULL) 45 | errx(1, "0x%08x: no such window", w); 46 | 47 | switch (attr) { 48 | case ATTR_X: attr = r->x; break; 49 | case ATTR_Y: attr = r->y; break; 50 | case ATTR_W: attr = r->width; break; 51 | case ATTR_H: attr = r->height; break; 52 | case ATTR_B: attr = r->border_width; break; 53 | } 54 | 55 | free(r); 56 | return attr; 57 | } 58 | 59 | int 60 | main(int argc, char **argv) 61 | { 62 | int c, ret = 0; 63 | size_t i; 64 | xcb_window_t w = 0; 65 | 66 | if (argc < 2 || (strncmp(argv[1], "-h", 2) == 0)) { 67 | usage(argv[0]); 68 | } 69 | 70 | init_xcb(&conn); 71 | 72 | if (argc == 2) { 73 | w = strtoul(argv[1], NULL, 16); 74 | ret = exists(conn, w) ? 0 : 1; 75 | goto end; 76 | } 77 | 78 | for (c=2; argv[c]; c++) { 79 | w = strtoul(argv[c], NULL, 16); 80 | 81 | for (i=0; i 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "arg.h" 10 | #include "util.h" 11 | 12 | enum { 13 | ABSOLUTE = 0, 14 | RELATIVE = 1 15 | }; 16 | 17 | static xcb_screen_t *scr; 18 | static xcb_connection_t *conn; 19 | 20 | static void usage(char *); 21 | static void spot_cursor(int, uint32_t); 22 | static void warp_cursor(int, int, int); 23 | 24 | static void 25 | usage(char *name) 26 | { 27 | fprintf(stderr, "usage: %s [-ar ] [wid]\n", name); 28 | exit(1); 29 | } 30 | 31 | static void 32 | spot_cursor(int mode, uint32_t win) 33 | { 34 | xcb_query_pointer_reply_t *r; 35 | xcb_query_pointer_cookie_t c; 36 | 37 | c = xcb_query_pointer(conn, win); 38 | r = xcb_query_pointer_reply(conn, c, NULL); 39 | 40 | if (r == NULL) 41 | errx(1, "cannot retrieve pointer position"); 42 | 43 | if (r->child != XCB_NONE) { 44 | printf("%d %d\n", r->win_x, r->win_y); 45 | } else { 46 | printf("%d %d\n", r->root_x, r->root_y); 47 | } 48 | } 49 | 50 | static void 51 | warp_cursor(int x, int y, int mode) 52 | { 53 | xcb_warp_pointer(conn, XCB_NONE, mode ? XCB_NONE : scr->root, 54 | 0, 0, 0, 0, x, y); 55 | } 56 | 57 | int 58 | main(int argc, char **argv) 59 | { 60 | char *argv0; 61 | int mode = ABSOLUTE; 62 | uint32_t win; 63 | 64 | ARGBEGIN { 65 | case 'a': mode = ABSOLUTE; 66 | break; 67 | case 'r': mode = RELATIVE; 68 | break; 69 | default : usage(argv0); 70 | } ARGEND; 71 | 72 | init_xcb(&conn); 73 | get_screen(conn, &scr); 74 | 75 | switch (argc) { 76 | case 0: 77 | case 1: 78 | win = argc > 0 ? strtoul(*argv, NULL, 16) : scr->root; 79 | spot_cursor(mode, win); 80 | break; 81 | case 2: 82 | warp_cursor(atoi(argv[0]), atoi(argv[1]), mode); 83 | break; 84 | default: 85 | usage(argv0); 86 | } 87 | 88 | xcb_aux_sync(conn); 89 | 90 | kill_xcb(&conn); 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /wmv.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "util.h" 10 | 11 | enum { 12 | ABSOLUTE = 0, 13 | RELATIVE = 1 14 | }; 15 | 16 | static xcb_connection_t *conn; 17 | static xcb_screen_t *scr; 18 | 19 | static void usage(char *); 20 | static void move(xcb_window_t, int, int, int); 21 | 22 | static void 23 | usage(char *name) 24 | { 25 | fprintf(stderr, "usage: %s [-a] \n", name); 26 | exit(1); 27 | } 28 | 29 | static void 30 | move(xcb_window_t win, int mode, int x, int y) 31 | { 32 | uint32_t values[2]; 33 | int real; 34 | xcb_get_geometry_reply_t *geom; 35 | 36 | if (!win || win == scr->root) 37 | return; 38 | 39 | geom = xcb_get_geometry_reply(conn, xcb_get_geometry(conn, win), NULL); 40 | if (!geom) 41 | return; 42 | 43 | if (mode == ABSOLUTE) { 44 | x -= geom->x + geom->width /2; 45 | y -= geom->y + geom->height/2; 46 | } 47 | values[0] = x ? geom->x + x : geom->x; 48 | values[1] = y ? geom->y + y : geom->y; 49 | 50 | if (x) 51 | { 52 | real = geom->width + (geom->border_width * 2); 53 | if (geom->x + x < 1) 54 | values[0] = 0; 55 | if (geom->x + x > scr->width_in_pixels - real) 56 | values[0] = scr->width_in_pixels - real; 57 | } 58 | 59 | if (y) 60 | { 61 | real = geom->height + (geom->border_width * 2); 62 | if (geom->y + y < 1) 63 | values[1] = 0; 64 | if (geom->y + y > scr->height_in_pixels - real) 65 | values[1] = scr->height_in_pixels - real; 66 | } 67 | 68 | xcb_configure_window(conn, win, XCB_CONFIG_WINDOW_X 69 | | XCB_CONFIG_WINDOW_Y, values); 70 | 71 | free(geom); 72 | } 73 | 74 | int 75 | main(int argc, char **argv) 76 | { 77 | int x, y, mode = RELATIVE; 78 | if (argc < 4) 79 | usage(argv[0]); 80 | 81 | init_xcb(&conn); 82 | get_screen(conn, &scr); 83 | 84 | if (argv[1][0] == '-' && argv[1][1] == 'a') { 85 | mode = ABSOLUTE; 86 | argv++; 87 | } 88 | 89 | x = atoi(*(++argv)); 90 | y = atoi(*(++argv)); 91 | 92 | while (*argv) 93 | move(strtoul(*argv++, NULL, 16), mode, x, y); 94 | 95 | xcb_aux_sync(conn); 96 | 97 | kill_xcb(&conn); 98 | 99 | return 0; 100 | } 101 | -------------------------------------------------------------------------------- /wrs.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "util.h" 10 | 11 | enum { 12 | ABSOLUTE = 0, 13 | RELATIVE = 1 14 | }; 15 | 16 | static xcb_connection_t *conn; 17 | static xcb_screen_t *scr; 18 | 19 | static void usage(char *); 20 | static void resize(xcb_window_t, int, int, int); 21 | 22 | static void 23 | usage(char *name) 24 | { 25 | fprintf(stderr, "usage: %s [-a] [wid..]\n", name); 26 | exit(1); 27 | } 28 | 29 | static void 30 | resize(xcb_window_t w, int mode, int x, int y) 31 | { 32 | uint32_t val[3]; 33 | uint32_t mask = XCB_CONFIG_WINDOW_WIDTH 34 | | XCB_CONFIG_WINDOW_HEIGHT 35 | | XCB_CONFIG_WINDOW_STACK_MODE; 36 | xcb_get_geometry_cookie_t c; 37 | xcb_get_geometry_reply_t *r; 38 | 39 | c = xcb_get_geometry(conn, w); 40 | r = xcb_get_geometry_reply(conn, c, NULL); 41 | 42 | if (r == NULL) 43 | return; 44 | 45 | if (mode == ABSOLUTE) { 46 | x -= r->x + r->width; 47 | y -= r->y + r->height; 48 | } 49 | 50 | if ((r->x + r->width + 2*r->border_width + x) > scr->width_in_pixels) 51 | x = scr->width_in_pixels - ( 52 | r->x + r->width + (2*r->border_width)); 53 | 54 | if ((r->y + r->height + 2*r->border_width + y) > scr->height_in_pixels) 55 | y = scr->height_in_pixels - ( 56 | r->y + r->height + (2*r->border_width)); 57 | 58 | val[0] = r->width + x; 59 | val[1] = r->height + y; 60 | val[2] = XCB_STACK_MODE_ABOVE; 61 | 62 | xcb_configure_window(conn, w, mask, val); 63 | 64 | free(r); 65 | } 66 | 67 | int 68 | main(int argc, char **argv) 69 | { 70 | int x, y, mode = RELATIVE; 71 | if (argc < 4) 72 | usage(argv[0]); 73 | 74 | init_xcb(&conn); 75 | get_screen(conn, &scr); 76 | 77 | if (argv[1][0] == '-' && argv[1][1] == 'a') { 78 | mode = ABSOLUTE; 79 | argv++; 80 | } 81 | 82 | x = atoi(*(++argv)); 83 | y = atoi(*(++argv)); 84 | 85 | while (*argv) 86 | resize(strtoul(*argv++, NULL, 16), mode, x, y); 87 | 88 | xcb_aux_sync(conn); 89 | 90 | kill_xcb(&conn); 91 | 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /wtf.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "util.h" 11 | 12 | static xcb_connection_t *conn; 13 | 14 | static void usage (char *); 15 | 16 | static void 17 | usage(char *name) 18 | { 19 | fprintf(stderr, "usage: %s \n", name); 20 | exit(1); 21 | } 22 | 23 | int 24 | main(int argc, char **argv) 25 | { 26 | xcb_window_t win; 27 | 28 | if (argc != 2 || strncmp(argv[0], "-h", 2) == 0) 29 | usage(argv[0]); 30 | 31 | init_xcb(&conn); 32 | 33 | win = strtoul(argv[1], NULL, 16); 34 | 35 | if (win) { 36 | xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, win, 37 | XCB_CURRENT_TIME); 38 | 39 | xcb_aux_sync(conn); 40 | } 41 | 42 | kill_xcb(&conn); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /wtp.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "util.h" 10 | 11 | static xcb_connection_t *conn; 12 | 13 | static void usage(char *name); 14 | static void teleport(xcb_window_t, int, int, int, int); 15 | 16 | static void 17 | usage(char *name) 18 | { 19 | fprintf(stderr, "usage: %s \n", name); 20 | exit(1); 21 | } 22 | 23 | static void 24 | teleport(xcb_window_t win, int x, int y, int w, int h) 25 | { 26 | uint32_t values[4]; 27 | uint32_t mask = XCB_CONFIG_WINDOW_X 28 | | XCB_CONFIG_WINDOW_Y 29 | | XCB_CONFIG_WINDOW_WIDTH 30 | | XCB_CONFIG_WINDOW_HEIGHT; 31 | 32 | values[0] = x; 33 | values[1] = y; 34 | values[2] = w; 35 | values[3] = h; 36 | 37 | xcb_configure_window(conn, win, mask, values); 38 | } 39 | 40 | int 41 | main(int argc, char **argv) 42 | { 43 | xcb_window_t win; 44 | 45 | if (argc != 6) 46 | usage(argv[0]); 47 | 48 | init_xcb(&conn); 49 | 50 | win = strtoul(argv[5], NULL, 16); 51 | if (!win) 52 | errx(1, "cannot get window"); 53 | 54 | teleport(win, atoi(argv[1]), atoi(argv[2]), 55 | atoi(argv[3]), atoi(argv[4])); 56 | xcb_aux_sync(conn); 57 | 58 | kill_xcb(&conn); 59 | 60 | return 0; 61 | } 62 | --------------------------------------------------------------------------------