wmutils

X windows manipulation utilities
git clone git://z3bra.org/wmutils
Log | Files | Refs | LICENSE

commit 0fe8af749716d9e4ccd43533b82192c1dfbb374d
parent 9372688607d8d4a75f2ca75ce7a267bb603448db
Author: z3bra <willyatmailoodotorg>
Date:   Sat Nov 14 15:06:47 2015

wmutils now depends on libwm

All functions exported to wmlib.c have now been move to a standalone
library: libwm[0].
This is now a hard dependency for wmutils.

[0] https://github.com/wmutils/libwm

Diffstat:
 Makefile  |   7 +-
 README.md |   2 +-
 chwb.c    |   2 +-
 chwso.c   |   2 +-
 config.mk |   4 +-
 ignw.c    |   2 +-
 killw.c   |   2 +-
 lsw.c     |   2 +-
 mapw.c    |  19 +----
 pfw.c     |   3 +-
 wattr.c   |   2 +-
 wmlib.c   | 315 +---------------------------------------------------------------
 wmlib.h   |  57 +-----------
 wmp.c     |   2 +-
 wmv.c     |   2 +-
 wrs.c     |   2 +-
 wtf.c     |   2 +-
 wtp.c     |   2 +-
 18 files changed, 20 insertions(+), 409 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,6 +1,6 @@ include config.mk -HDR = arg.h wmlib.h +HDR = arg.h SRC = \ pfw.c \ lsw.c \ @@ -19,7 +19,6 @@ SRC = \ OBJ = $(SRC:.c=.o) BIN = $(SRC:.c=) MAN = $(SRC:.c=.1) -LIB = wmlib.o .POSIX: .SUFFIXES: .1 .1.gz @@ -28,11 +27,11 @@ all: binutils binutils: $(BIN) -$(OBJ): $(HDR) wmlib.o +$(OBJ): $(HDR) .o: @echo "LD $@" - @$(LD) $< $(LIB) -o $@ $(LDFLAGS) + @$(LD) $< -o $@ $(LDFLAGS) .c.o: @echo "CC $<" diff --git a/README.md b/README.md @@ -50,7 +50,7 @@ All these tools come with a manpage ! read them for further informations. dependencies ------------ -wmutils only relies on the XCB library. +wmutils only relies on the XCB library and [libwm](https://github.com/wmutils/libwm) license ------- diff --git a/chwb.c b/chwb.c @@ -4,9 +4,9 @@ #include <stdlib.h> #include <stdio.h> #include <err.h> +#include <wm.h> #include "arg.h" -#include "wmlib.h" xcb_connection_t *conn; xcb_screen_t *scrn; diff --git a/chwso.c b/chwso.c @@ -4,9 +4,9 @@ #include <stdlib.h> #include <stdio.h> #include <err.h> +#include <wm.h> #include "arg.h" -#include "wmlib.h" xcb_connection_t *conn; xcb_screen_t *scrn; diff --git a/config.mk b/config.mk @@ -1,9 +1,9 @@ -PREFIX = /usr +PREFIX = /usr/local MANPREFIX = $(PREFIX)/man CC = cc LD = $(CC) CFLAGS = -std=c99 -pedantic -Wall -Os -LDFLAGS = -lxcb +LDFLAGS = -lxcb -lwm diff --git a/ignw.c b/ignw.c @@ -4,9 +4,9 @@ #include <stdlib.h> #include <err.h> #include <xcb/xcb.h> +#include <wm.h> #include "arg.h" -#include "wmlib.h" xcb_connection_t *conn; xcb_screen_t *scrn; diff --git a/killw.c b/killw.c @@ -4,8 +4,8 @@ #include <stdlib.h> #include <err.h> #include <xcb/xcb.h> +#include <wm.h> -#include "wmlib.h" xcb_connection_t *conn; xcb_screen_t *scrn; diff --git a/lsw.c b/lsw.c @@ -4,9 +4,9 @@ #include <stdlib.h> #include <err.h> #include <xcb/xcb.h> +#include <wm.h> #include "arg.h" -#include "wmlib.h" xcb_connection_t *conn; xcb_screen_t *scrn; diff --git a/mapw.c b/mapw.c @@ -4,9 +4,9 @@ #include <stdlib.h> #include <err.h> #include <xcb/xcb.h> +#include <wm.h> #include "arg.h" -#include "wmlib.h" xcb_connection_t *conn; xcb_screen_t *scrn; @@ -49,23 +49,8 @@ main(int argc, char **argv) while (*argv) { w = strtoul(*argv++, NULL, 16); - - switch (mapflag) { - case MAP: - xcb_map_window(conn, w); - break; - case UNMAP: - xcb_unmap_window(conn, w); - break; - case TOGGLE: - if (is_mapped(w)) - xcb_unmap_window(conn, w); - else - xcb_map_window(conn, w); - break; - } + remap(w, mapflag); } - xcb_flush(conn); kill_xcb(&conn); diff --git a/pfw.c b/pfw.c @@ -4,8 +4,7 @@ #include <stdio.h> #include <stdlib.h> #include <xcb/xcb.h> - -#include "wmlib.h" +#include <wm.h> xcb_connection_t *conn; xcb_screen_t *scrn; diff --git a/wattr.c b/wattr.c @@ -5,8 +5,8 @@ #include <string.h> #include <err.h> #include <xcb/xcb.h> +#include <wm.h> -#include "wmlib.h" xcb_connection_t *conn; xcb_screen_t *scrn; diff --git a/wmlib.c b/wmlib.c @@ -1,315 +0,0 @@ -#include <xcb/xcb.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include "wmlib.h" - - int -init_xcb() -{ - conn = xcb_connect(NULL, NULL); - if (xcb_connection_has_error(conn)) - return 0; - return 1; -} - - int -kill_xcb() -{ - if (conn) { - xcb_disconnect(conn); - return 1; - } - return 0; -} - - int -is_alive(xcb_window_t w) -{ - xcb_get_window_attributes_cookie_t c; - xcb_get_window_attributes_reply_t *r; - - c = xcb_get_window_attributes(conn, w); - r = xcb_get_window_attributes_reply(conn, c, NULL); - - if (r == NULL) - return 0; - - free(r); - return 1; -} - - int -is_mapped(xcb_window_t w) -{ - int ms; - xcb_get_window_attributes_cookie_t c; - xcb_get_window_attributes_reply_t *r; - - c = xcb_get_window_attributes(conn, w); - r = xcb_get_window_attributes_reply(conn, c, NULL); - - if (r == NULL) - return 0; - - ms = r->map_state; - - free(r); - return ms == XCB_MAP_STATE_VIEWABLE; -} - - int -is_ignored(xcb_window_t wid) -{ - int or; - xcb_get_window_attributes_cookie_t c; - xcb_get_window_attributes_reply_t *r; - - c = xcb_get_window_attributes(conn, wid); - r = xcb_get_window_attributes_reply(conn, c, NULL); - - if (r == NULL) - return 0; - - or = r->override_redirect; - - free(r); - return or; -} - - int -get_screen() -{ - scrn = xcb_setup_roots_iterator(xcb_get_setup(conn)).data; - if (scrn == NULL) - return 0; - return 1; -} - - int -get_windows(xcb_window_t w, xcb_window_t **l) -{ - uint32_t childnum = 0; - xcb_query_tree_cookie_t c; - xcb_query_tree_reply_t *r; - - c = xcb_query_tree(conn, w); - r = xcb_query_tree_reply(conn, c, NULL); - if (r == NULL) - return -1; - - *l = malloc(sizeof(xcb_window_t) * r->children_len); - memcpy(*l, xcb_query_tree_children(r), - sizeof(xcb_window_t) * r->children_len); - - childnum = r->children_len; - - free(r); - return childnum; -} - - int -get_attribute(xcb_window_t w, int attr) -{ - xcb_get_geometry_cookie_t c; - xcb_get_geometry_reply_t *r; - - c = xcb_get_geometry(conn, w); - r = xcb_get_geometry_reply(conn, c, NULL); - - if (r == NULL) - return -1; - - switch (attr) { - case ATTR_X: attr = r->x; break; - case ATTR_Y: attr = r->y; break; - case ATTR_W: attr = r->width; break; - case ATTR_H: attr = r->height; break; - case ATTR_B: attr = r->border_width; break; - } - - free(r); - return attr; -} - - int -get_cursor(int mode, uint32_t wid, int *x, int *y) -{ - xcb_query_pointer_reply_t *r; - xcb_query_pointer_cookie_t c; - - c = xcb_query_pointer(conn, wid); - r = xcb_query_pointer_reply(conn, c, NULL); - - if (r == NULL) - return 0; - - if (r->child != XCB_NONE) { - *x = r->win_x; - *y = r->win_y; - } else { - *x = r->root_x; - *y = r->root_y; - } - - return 1; -} - - int -set_border(int width, int color, xcb_window_t win) -{ - uint32_t values[1]; - int mask, retval = 0; - /* change width if > 0 */ - if (width > -1) { - values[0] = width; - mask = XCB_CONFIG_WINDOW_BORDER_WIDTH; - xcb_configure_window(conn, win, mask, values); - retval++; - } - - /* change color if > 0 */ - if (color > -1) { - values[0] = color; - mask = XCB_CW_BORDER_PIXEL; - xcb_change_window_attributes(conn, win, mask, values); - retval++; - } - - xcb_flush(conn); - return retval; -} - - int -set_cursor(int x, int y, int mode) -{ - xcb_warp_pointer(conn, XCB_NONE, mode ? XCB_NONE : scrn->root, - 0, 0, 0, 0, x, y); - return 1; -} - - int -is_listable(xcb_window_t w, int mask) -{ - if ((mask & LIST_ALL) - || (!is_mapped (w) && mask & LIST_HIDDEN) - || ( is_ignored(w) && mask & LIST_IGNORE) - || ( is_mapped (w) && !is_ignored(w) && mask == 0)) - return 1; - - return 0; -} - - int -teleport(xcb_window_t wid, int x, int y, int w, int h) -{ - uint32_t values[4]; - uint32_t mask = XCB_CONFIG_WINDOW_X - | XCB_CONFIG_WINDOW_Y - | XCB_CONFIG_WINDOW_WIDTH - | XCB_CONFIG_WINDOW_HEIGHT; - values[0] = x; - values[1] = y; - values[2] = w; - values[3] = h; - xcb_configure_window(conn, wid, mask, values); - - xcb_flush(conn); - return 1; -} - - int -move(xcb_window_t wid, int mode, int x, int y) -{ - int curx, cury, curw, curh, curb; - - if (!is_mapped(wid) || wid == scrn->root) - return -1; - - curb = get_attribute(wid, ATTR_B); - curx = get_attribute(wid, ATTR_X); - cury = get_attribute(wid, ATTR_Y); - curw = get_attribute(wid, ATTR_W); - curh = get_attribute(wid, ATTR_H); - - if (mode == ABSOLUTE) { - x -= curx + curw /2; - y -= cury + curh /2; - } else { - x += curx; - y += cury; - } - - /* the following prevent windows from moving off the screen */ - if (x < 0) - x = 0; - else if (x > scrn->width_in_pixels - curw - 2*curb) - x = scrn->width_in_pixels - curw - 2*curb; - - if (y < 0) - y = 0; - else if (y > scrn->height_in_pixels - curh - 2*curb) - y = scrn->height_in_pixels - curh - 2*curb; - - teleport(wid, x, y, curw, curh); - return 1; -} - - int -resize(xcb_window_t wid, int mode, int w, int h) -{ - int curx, cury, curw, curh, curb; - - if (!is_mapped(wid) || wid == scrn->root) - return -1; - - curb = get_attribute(wid, ATTR_B); - curx = get_attribute(wid, ATTR_X); - cury = get_attribute(wid, ATTR_Y); - curw = get_attribute(wid, ATTR_W); - curh = get_attribute(wid, ATTR_H); - - if (mode == ABSOLUTE) { - w -= curx + 2*curb; - h -= cury + 2*curb; - } else { - w += curw; - h += curh; - } - - /* - * The following prevent windows from growing out of the screen, or - * having a negative size - */ - if (w < 0) - w = curw; - if (curx + w > scrn->width_in_pixels) - w = scrn->width_in_pixels - curx - 2*curb; - - if (h < 0) - h = cury; - if (cury + h > scrn->height_in_pixels) - h = scrn->height_in_pixels - cury - 2*curb; - - teleport(wid, curx, cury, w, h); - return 1; -} - - int -restack(xcb_window_t wid, uint32_t mode) -{ - uint32_t values[1] = { mode }; - xcb_configure_window(conn, wid, XCB_CONFIG_WINDOW_STACK_MODE, values); - xcb_flush(conn); - return 1; -} - - int -set_focus(xcb_window_t wid) -{ - xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, wid, - XCB_CURRENT_TIME); - xcb_flush(conn); - return 1; -} diff --git a/wmlib.h b/wmlib.h @@ -1,57 +0,0 @@ -#ifndef __WMLIB_H__ -#define __WMLIB_H__ - -extern xcb_connection_t *conn; -extern xcb_screen_t *scrn; - -enum { - LIST_HIDDEN = 1 << 0, - LIST_IGNORE = 1 << 1, - LIST_ALL = 1 << 2 -}; - -enum { - MAP = 1 << 0, - UNMAP = 1 << 1, - TOGGLE = 1 << 2 -}; - -enum { - ATTR_W = 1 << 0, - ATTR_H = 1 << 1, - ATTR_X = 1 << 2, - ATTR_Y = 1 << 3, - ATTR_B = 1 << 4, - ATTR_M = 1 << 5, - ATTR_I = 1 << 6, - ATTR_MAX -}; - -enum { - ABSOLUTE = 0, - RELATIVE = 1 -}; - -int init_xcb(); -int kill_xcb(); - -int is_alive(xcb_window_t wid); -int is_ignored(xcb_window_t wid); -int is_listable(xcb_window_t wid, int mask); -int is_mapped(xcb_window_t wid); - -int get_screen(); -int get_windows(xcb_window_t wid, xcb_window_t **list); -int get_attribute(xcb_window_t, int); -int get_cursor(int mode, uint32_t wid, int *x, int *y); - -int set_border(int width, int color, xcb_window_t wid); -int set_focus(xcb_window_t wid); -int set_cursor(int x, int y, int mode); - -int teleport(xcb_window_t wid, int w, int h, int x, int y); -int move(xcb_window_t wid, int mode, int x, int y); -int resize(xcb_window_t wid, int mode, int w, int h); -int restack(xcb_window_t wid, uint32_t mode); - -#endif diff --git a/wmp.c b/wmp.c @@ -4,9 +4,9 @@ #include <stdlib.h> #include <stdio.h> #include <err.h> +#include <wm.h> #include "arg.h" -#include "wmlib.h" xcb_connection_t *conn; xcb_screen_t *scrn; diff --git a/wmv.c b/wmv.c @@ -4,8 +4,8 @@ #include <stdio.h> #include <stdlib.h> #include <err.h> +#include <wm.h> -#include "wmlib.h" xcb_connection_t *conn; xcb_screen_t *scrn; diff --git a/wrs.c b/wrs.c @@ -4,8 +4,8 @@ #include <stdio.h> #include <stdlib.h> #include <err.h> +#include <wm.h> -#include "wmlib.h" xcb_connection_t *conn; xcb_screen_t *scrn; diff --git a/wtf.c b/wtf.c @@ -5,8 +5,8 @@ #include <stdio.h> #include <string.h> #include <err.h> +#include <wm.h> -#include "wmlib.h" xcb_connection_t *conn; xcb_screen_t *scrn; diff --git a/wtp.c b/wtp.c @@ -4,8 +4,8 @@ #include <stdlib.h> #include <stdio.h> #include <err.h> +#include <wm.h> -#include "wmlib.h" xcb_connection_t *conn; xcb_screen_t *scrn;