wmutils

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

commit 69df5f3dd6b64cf3c99e2c4ad3913a047a99ca7b
parent 7b86e8b8e80cd91e7cd7c4e2b8c8be51db7e1c91
Author: z3bra <willyatmailoodotorg>
Date:   Sun Sep 20 23:53:10 2015

Export all functions to wmlib.c

Diffstat:
 Makefile |   9 +-
 chwb.c   |  29 +------
 chwso.c  |  24 +----
 ignw.c   |   5 +-
 killw.c  |   5 +-
 lsw.c    |  31 +------
 mapw.c   |  13 +---
 pfw.c    |   5 +-
 util.c   | 105 +---------------------
 util.h   |  14 +---
 wattr.c  |  48 +---------
 wmlib.c  | 315 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 wmlib.h  |  57 ++++++++++++-
 wmp.c    |  50 +---------
 wmv.c    |  59 +------------
 wrs.c    |  52 +-----------
 wtf.c    |  12 +--
 wtp.c    |  27 +-----
 18 files changed, 437 insertions(+), 423 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,6 +1,6 @@ include config.mk -HDR = arg.h util.h +HDR = arg.h wmlib.h SRC = \ pfw.c \ lsw.c \ @@ -19,6 +19,7 @@ SRC = \ OBJ = $(SRC:.c=.o) BIN = $(SRC:.c=) MAN = $(SRC:.c=.1) +LIB = wmlib.o .POSIX: .SUFFIXES: .1 .1.gz @@ -27,11 +28,11 @@ all: binutils binutils: $(BIN) -$(OBJ): $(HDR) util.o +$(OBJ): $(HDR) wmlib.o .o: @echo "LD $@" - @$(LD) $< util.o -o $@ $(LDFLAGS) + @$(LD) $< $(LIB) -o $@ $(LDFLAGS) .c.o: @echo "CC $<" @@ -50,4 +51,4 @@ uninstall: cd man; $(MAKE) uninstall clean : - rm -f $(OBJ) $(BIN) util.o + rm -f $(OBJ) $(BIN) $(LIB) diff --git a/chwb.c b/chwb.c @@ -6,12 +6,12 @@ #include <err.h> #include "arg.h" -#include "util.h" +#include "wmlib.h" -static xcb_connection_t *conn; +xcb_connection_t *conn; +xcb_screen_t *scrn; static void usage(char *name); -static void set_border(int, int, xcb_window_t); static void usage(char *name) @@ -20,29 +20,6 @@ usage(char *name) exit(1); } -static void -set_border(int width, int color, xcb_window_t win) -{ - uint32_t values[1]; - int mask; - - if (width != -1) { - values[0] = width; - mask = XCB_CONFIG_WINDOW_BORDER_WIDTH; - xcb_configure_window(conn, win, mask, values); - - xcb_flush(conn); - } - - if (color != -1) { - values[0] = color; - mask = XCB_CW_BORDER_PIXEL; - xcb_change_window_attributes(conn, win, mask, values); - - xcb_flush(conn); - } -} - int main(int argc, char **argv) { diff --git a/chwso.c b/chwso.c @@ -6,12 +6,12 @@ #include <err.h> #include "arg.h" -#include "util.h" +#include "wmlib.h" -static xcb_connection_t *conn; +xcb_connection_t *conn; +xcb_screen_t *scrn; static void usage(char *); -static void stack(xcb_window_t, uint32_t[1]); static void usage(char *name) @@ -20,17 +20,11 @@ usage(char *name) exit(1); } -static void -stack(xcb_window_t win, uint32_t values[1]) -{ - xcb_configure_window(conn, win, XCB_CONFIG_WINDOW_STACK_MODE, values); -} - int main(int argc, char **argv) { xcb_window_t win; - uint32_t values[1]; + uint32_t mode = 0; char *argv0 = NULL; if (argc != 3) @@ -44,23 +38,21 @@ main(int argc, char **argv) ARGBEGIN { case 'r': - values[0] = XCB_STACK_MODE_ABOVE; + mode = XCB_STACK_MODE_ABOVE; break; case 'l': - values[0] = XCB_STACK_MODE_BELOW; + mode = XCB_STACK_MODE_BELOW; break; case 'i': - values[0] = XCB_STACK_MODE_OPPOSITE; + mode = XCB_STACK_MODE_OPPOSITE; break; default: usage(argv0); break; } ARGEND - stack(win, values); - xcb_flush(conn); + restack(win, mode); kill_xcb(&conn); - return 0; } diff --git a/ignw.c b/ignw.c @@ -6,9 +6,10 @@ #include <xcb/xcb.h> #include "arg.h" -#include "util.h" +#include "wmlib.h" -static xcb_connection_t *conn; +xcb_connection_t *conn; +xcb_screen_t *scrn; static void usage(char *); static void set_override(xcb_window_t, int); diff --git a/killw.c b/killw.c @@ -5,9 +5,10 @@ #include <err.h> #include <xcb/xcb.h> -#include "util.h" +#include "wmlib.h" -static xcb_connection_t *conn; +xcb_connection_t *conn; +xcb_screen_t *scrn; static void usage(char *); diff --git a/lsw.c b/lsw.c @@ -6,20 +6,13 @@ #include <xcb/xcb.h> #include "arg.h" -#include "util.h" +#include "wmlib.h" -static xcb_connection_t *conn; -static xcb_screen_t *scrn; +xcb_connection_t *conn; +xcb_screen_t *scrn; static void usage(char *); -static int should_list(xcb_window_t, int); -static void list_windows(xcb_window_t, int); - -enum { - LIST_HIDDEN = 1 << 0, - LIST_IGNORE = 1 << 1, - LIST_ALL = 1 << 2 -}; +static void list_windows(xcb_window_t w, int mask); static void usage(char *name) @@ -28,20 +21,6 @@ usage(char *name) exit(1); } -static int -should_list(xcb_window_t w, int mask) -{ - if ((mask & LIST_ALL) - || (!mapped(conn, w) && mask & LIST_HIDDEN) - || (ignore(conn, w) && mask & LIST_IGNORE) - || (mapped(conn, w) - && !ignore(conn, w) - && mask == 0)) - return 1; - - return 0; -} - static void list_windows(xcb_window_t w, int listmask) { @@ -54,7 +33,7 @@ list_windows(xcb_window_t w, int listmask) errx(1, "0x%08x: unable to retrieve children", w); for (i=0; i<wn; i++) { - if (should_list(wc[i], listmask)) + if (is_listable(wc[i], listmask)) printf("0x%08x\n", wc[i]); } diff --git a/mapw.c b/mapw.c @@ -6,15 +6,10 @@ #include <xcb/xcb.h> #include "arg.h" -#include "util.h" +#include "wmlib.h" -enum { - MAP = 1 << 0, - UNMAP = 1 << 1, - TOGGLE = 1 << 2 -}; - -static xcb_connection_t *conn; +xcb_connection_t *conn; +xcb_screen_t *scrn; static void usage(char *); @@ -55,7 +50,7 @@ main(int argc, char **argv) xcb_unmap_window(conn, w); break; case TOGGLE: - if (mapped(conn, w)) + if (is_mapped(conn, w)) xcb_unmap_window(conn, w); else xcb_map_window(conn, w); diff --git a/pfw.c b/pfw.c @@ -5,9 +5,10 @@ #include <stdlib.h> #include <xcb/xcb.h> -#include "util.h" +#include "wmlib.h" -static xcb_connection_t *conn; +xcb_connection_t *conn; +xcb_screen_t *scrn; static xcb_window_t focus_window(void); diff --git a/util.c b/util.c @@ -1,105 +0,0 @@ -#include <err.h> -#include <stdlib.h> -#include <string.h> -#include <xcb/xcb.h> - -#include "util.h" - -void -init_xcb(xcb_connection_t **con) -{ - *con = xcb_connect(NULL, NULL); - if (xcb_connection_has_error(*con)) - errx(1, "unable connect to the X server"); -} - -void -kill_xcb(xcb_connection_t **con) -{ - if (*con) - xcb_disconnect(*con); -} - -void -get_screen(xcb_connection_t *con, xcb_screen_t **scr) -{ - *scr = xcb_setup_roots_iterator(xcb_get_setup(con)).data; - if (*scr == NULL) - errx(1, "unable to retrieve screen informations"); -} - -int -exists(xcb_connection_t *con, xcb_window_t w) -{ - xcb_get_window_attributes_cookie_t c; - xcb_get_window_attributes_reply_t *r; - - c = xcb_get_window_attributes(con, w); - r = xcb_get_window_attributes_reply(con, c, NULL); - - if (r == NULL) - return 0; - - free(r); - return 1; -} - -int -mapped(xcb_connection_t *con, 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(con, w); - r = xcb_get_window_attributes_reply(con, c, NULL); - - if (r == NULL) - return 0; - - ms = r->map_state; - - free(r); - return ms == XCB_MAP_STATE_VIEWABLE; -} - -int -ignore(xcb_connection_t *con, xcb_window_t w) -{ - int or; - xcb_get_window_attributes_cookie_t c; - xcb_get_window_attributes_reply_t *r; - - c = xcb_get_window_attributes(con, w); - r = xcb_get_window_attributes_reply(con, c, NULL); - - if (r == NULL) - return 0; - - or = r->override_redirect; - - free(r); - return or; -} - -int -get_windows(xcb_connection_t *con, 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(con, w); - r = xcb_query_tree_reply(con, c, NULL); - if (r == NULL) - errx(1, "0x%08x: no such window", w); - - *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; -} diff --git a/util.h b/util.h @@ -1,14 +0,0 @@ -#ifndef UTIL_H__ -#define UTIL_H__ - -void init_xcb(xcb_connection_t **); -void kill_xcb(xcb_connection_t **); - -void get_screen(xcb_connection_t *, xcb_screen_t **); -int get_windows(xcb_connection_t *, xcb_window_t, xcb_window_t **); - -int exists(xcb_connection_t *, xcb_window_t); -int mapped(xcb_connection_t *, xcb_window_t); -int ignore(xcb_connection_t *, xcb_window_t); - -#endif diff --git a/wattr.c b/wattr.c @@ -6,23 +6,12 @@ #include <err.h> #include <xcb/xcb.h> -#include "util.h" +#include "wmlib.h" -static xcb_connection_t *conn; +xcb_connection_t *conn; +xcb_screen_t *scrn; static void usage(char *); -static int get_attribute(xcb_window_t, int); - -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 -}; static void usage(char *name) @@ -31,30 +20,6 @@ usage(char *name) exit(1); } -static 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) - errx(1, "0x%08x: no such window", w); - - 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 main(int argc, char **argv) { @@ -70,7 +35,7 @@ main(int argc, char **argv) if (argc == 2) { w = strtoul(argv[1], NULL, 16); - ret = exists(conn, w) ? 0 : 1; + ret = is_alive(conn, w) ? 0 : 1; goto end; } @@ -98,10 +63,10 @@ main(int argc, char **argv) printf("%d", get_attribute(w, ATTR_W)); break; case 'o': - ret = ignore(conn, w) ? 0 : 1; + ret = is_ignored(conn, w) ? 0 : 1; goto end; case 'm': - ret = mapped(conn, w) ? 0 : 1; + ret = is_mapped(conn, w) ? 0 : 1; goto end; default: kill_xcb(&conn); usage(argv[0]); } @@ -112,6 +77,5 @@ main(int argc, char **argv) end: kill_xcb(&conn); - return ret; } diff --git a/wmlib.c b/wmlib.c @@ -0,0 +1,315 @@ +#include <xcb/xcb.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "wmlib.h" + + int +init_xcb(xcb_connection_t **con) +{ + *con = xcb_connect(NULL, NULL); + if (xcb_connection_has_error(*con)) + return 0; + return 1; +} + + int +kill_xcb(xcb_connection_t **con) +{ + if (*con) { + xcb_disconnect(*con); + return 1; + } + return 0; +} + + int +is_alive(xcb_connection_t *con, xcb_window_t w) +{ + xcb_get_window_attributes_cookie_t c; + xcb_get_window_attributes_reply_t *r; + + c = xcb_get_window_attributes(con, w); + r = xcb_get_window_attributes_reply(con, c, NULL); + + if (r == NULL) + return 0; + + free(r); + return 1; +} + + int +is_mapped(xcb_connection_t *con, 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(con, w); + r = xcb_get_window_attributes_reply(con, c, NULL); + + if (r == NULL) + return 0; + + ms = r->map_state; + + free(r); + return ms == XCB_MAP_STATE_VIEWABLE; +} + + int +is_ignored(xcb_connection_t *con, 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(con, wid); + r = xcb_get_window_attributes_reply(con, c, NULL); + + if (r == NULL) + return 0; + + or = r->override_redirect; + + free(r); + return or; +} + + int +get_screen(xcb_connection_t *con, xcb_screen_t **scr) +{ + *scr = xcb_setup_roots_iterator(xcb_get_setup(con)).data; + if (*scr == NULL) + return 0; + return 1; +} + + int +get_windows(xcb_connection_t *con, 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(con, w); + r = xcb_query_tree_reply(con, 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 (conn, w) && mask & LIST_HIDDEN) + || ( is_ignored(conn, w) && mask & LIST_IGNORE) + || ( is_mapped (conn, w) && !is_ignored(conn, 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(conn, 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(conn, 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 @@ -0,0 +1,57 @@ +#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(xcb_connection_t **con); +int kill_xcb(xcb_connection_t **con); + +int is_alive(xcb_connection_t *con, xcb_window_t wid); +int is_ignored(xcb_connection_t *con, xcb_window_t wid); +int is_listable(xcb_window_t wid, int mask); +int is_mapped(xcb_connection_t *con, xcb_window_t wid); + +int get_screen(xcb_connection_t *con, xcb_screen_t **scr); +int get_windows(xcb_connection_t *con, 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 @@ -6,19 +6,12 @@ #include <err.h> #include "arg.h" -#include "util.h" +#include "wmlib.h" -enum { - ABSOLUTE = 0, - RELATIVE = 1 -}; - -static xcb_screen_t *scr; -static xcb_connection_t *conn; +xcb_connection_t *conn; +xcb_screen_t *scrn; static void usage(char *); -static void spot_cursor(int, uint32_t); -static void warp_cursor(int, int, int); static void usage(char *name) @@ -27,37 +20,11 @@ usage(char *name) exit(1); } -static void -spot_cursor(int mode, uint32_t win) -{ - xcb_query_pointer_reply_t *r; - xcb_query_pointer_cookie_t c; - - c = xcb_query_pointer(conn, win); - r = xcb_query_pointer_reply(conn, c, NULL); - - if (r == NULL) - errx(1, "cannot retrieve pointer position"); - - if (r->child != XCB_NONE) { - printf("%d %d\n", r->win_x, r->win_y); - } else { - printf("%d %d\n", r->root_x, r->root_y); - } -} - -static void -warp_cursor(int x, int y, int mode) -{ - xcb_warp_pointer(conn, XCB_NONE, mode ? XCB_NONE : scr->root, - 0, 0, 0, 0, x, y); -} - int main(int argc, char **argv) { char *argv0; - int mode = ABSOLUTE; + int mode = ABSOLUTE, x, y; uint32_t win; ARGBEGIN { @@ -69,16 +36,17 @@ main(int argc, char **argv) } ARGEND; init_xcb(&conn); - get_screen(conn, &scr); + get_screen(conn, &scrn); switch (argc) { case 0: case 1: - win = argc > 0 ? strtoul(*argv, NULL, 16) : scr->root; - spot_cursor(mode, win); + win = argc > 0 ? strtoul(*argv, NULL, 16) : scrn->root; + if (get_cursor(mode, win, &x, &y)) + printf("%d %d\n", x, y); break; case 2: - warp_cursor(atoi(argv[0]), atoi(argv[1]), mode); + set_cursor(atoi(argv[0]), atoi(argv[1]), mode); break; default: usage(argv0); diff --git a/wmv.c b/wmv.c @@ -5,18 +5,12 @@ #include <stdlib.h> #include <err.h> -#include "util.h" +#include "wmlib.h" -enum { - ABSOLUTE = 0, - RELATIVE = 1 -}; - -static xcb_connection_t *conn; -static xcb_screen_t *scr; +xcb_connection_t *conn; +xcb_screen_t *scrn; static void usage(char *); -static void move(xcb_window_t, int, int, int); static void usage(char *name) @@ -25,51 +19,6 @@ usage(char *name) exit(1); } -static void -move(xcb_window_t win, int mode, int x, int y) -{ - uint32_t values[2]; - int real; - xcb_get_geometry_reply_t *geom; - - if (!win || win == scr->root) - return; - - geom = xcb_get_geometry_reply(conn, xcb_get_geometry(conn, win), NULL); - if (!geom) - return; - - if (mode == ABSOLUTE) { - x -= geom->x + geom->width /2; - y -= geom->y + geom->height/2; - } - values[0] = x ? geom->x + x : geom->x; - values[1] = y ? geom->y + y : geom->y; - - if (x) - { - real = geom->width + (geom->border_width * 2); - if (geom->x + x < 1) - values[0] = 0; - if (geom->x + x > scr->width_in_pixels - real) - values[0] = scr->width_in_pixels - real; - } - - if (y) - { - real = geom->height + (geom->border_width * 2); - if (geom->y + y < 1) - values[1] = 0; - if (geom->y + y > scr->height_in_pixels - real) - values[1] = scr->height_in_pixels - real; - } - - xcb_configure_window(conn, win, XCB_CONFIG_WINDOW_X - | XCB_CONFIG_WINDOW_Y, values); - - free(geom); -} - int main(int argc, char **argv) { @@ -78,7 +27,7 @@ main(int argc, char **argv) usage(argv[0]); init_xcb(&conn); - get_screen(conn, &scr); + get_screen(conn, &scrn); if (argv[1][0] == '-' && argv[1][1] == 'a') { mode = ABSOLUTE; diff --git a/wrs.c b/wrs.c @@ -5,18 +5,12 @@ #include <stdlib.h> #include <err.h> -#include "util.h" +#include "wmlib.h" -enum { - ABSOLUTE = 0, - RELATIVE = 1 -}; - -static xcb_connection_t *conn; -static xcb_screen_t *scr; +xcb_connection_t *conn; +xcb_screen_t *scrn; static void usage(char *); -static void resize(xcb_window_t, int, int, int); static void usage(char *name) @@ -25,44 +19,6 @@ usage(char *name) exit(1); } -static void -resize(xcb_window_t w, int mode, int x, int y) -{ - uint32_t val[3]; - uint32_t mask = XCB_CONFIG_WINDOW_WIDTH - | XCB_CONFIG_WINDOW_HEIGHT - | XCB_CONFIG_WINDOW_STACK_MODE; - 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; - - if (mode == ABSOLUTE) { - x -= r->x + r->width; - y -= r->y + r->height; - } - - if ((r->x + r->width + 2*r->border_width + x) > scr->width_in_pixels) - x = scr->width_in_pixels - ( - r->x + r->width + (2*r->border_width)); - - if ((r->y + r->height + 2*r->border_width + y) > scr->height_in_pixels) - y = scr->height_in_pixels - ( - r->y + r->height + (2*r->border_width)); - - val[0] = r->width + x; - val[1] = r->height + y; - val[2] = XCB_STACK_MODE_ABOVE; - - xcb_configure_window(conn, w, mask, val); - - free(r); -} - int main(int argc, char **argv) { @@ -71,7 +27,7 @@ main(int argc, char **argv) usage(argv[0]); init_xcb(&conn); - get_screen(conn, &scr); + get_screen(conn, &scrn); if (argv[1][0] == '-' && argv[1][1] == 'a') { mode = ABSOLUTE; diff --git a/wtf.c b/wtf.c @@ -6,9 +6,10 @@ #include <string.h> #include <err.h> -#include "util.h" +#include "wmlib.h" -static xcb_connection_t *conn; +xcb_connection_t *conn; +xcb_screen_t *scrn; static void usage (char *); @@ -31,12 +32,7 @@ main(int argc, char **argv) win = strtoul(argv[1], NULL, 16); - if (win) { - xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, win, - XCB_CURRENT_TIME); - - xcb_flush(conn); - } + set_focus(win); kill_xcb(&conn); return 0; diff --git a/wtp.c b/wtp.c @@ -5,12 +5,12 @@ #include <stdio.h> #include <err.h> -#include "util.h" +#include "wmlib.h" -static xcb_connection_t *conn; +xcb_connection_t *conn; +xcb_screen_t *scrn; static void usage(char *name); -static void teleport(xcb_window_t, int, int, int, int); static void usage(char *name) @@ -19,23 +19,6 @@ usage(char *name) exit(1); } -static void -teleport(xcb_window_t win, 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, win, mask, values); -} - int main(int argc, char **argv) { @@ -51,10 +34,8 @@ main(int argc, char **argv) errx(1, "cannot get window"); teleport(win, atoi(argv[1]), atoi(argv[2]), - atoi(argv[3]), atoi(argv[4])); - xcb_flush(conn); + atoi(argv[3]), atoi(argv[4])); kill_xcb(&conn); - return 0; }