tnew tool: wtp - wmutils - X windows manipulation utilities
(HTM) git clone git://z3bra.org/wmutils
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 9b84ff2464e35b556aa055cf44a68ad7e500e7bb
(DIR) parent 37bb3174d2b1e41e6230210cf27ed252f0bec52b
(HTM) Author: dcat <dcat@iotek.org>
Date: Fri, 28 Nov 2014 01:27:23 +0100
new tool: wtp
Diffstat:
M Makefile | 3 ++-
A wtp.c | 98 +++++++++++++++++++++++++++++++
2 files changed, 100 insertions(+), 1 deletion(-)
---
(DIR) diff --git a/Makefile b/Makefile
t@@ -12,7 +12,8 @@ SRC = \
lsw.c \
mapw.c \
killw.c \
- wattr.c
+ wattr.c \
+ wtp.c
OBJ = $(SRC:.c=.o)
BIN = $(SRC:.c=)
(DIR) diff --git a/wtp.c b/wtp.c
t@@ -0,0 +1,98 @@
+/**
+* Copyright (c) 2014, Broseph <dcat (at) iotek (dot) org>
+*
+* 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 <xcb/xcb.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <err.h>
+
+static xcb_connection_t *conn;
+
+static void cleanup (void);
+static void usage (char *name);
+static void teleport (xcb_window_t, int, int, int, int);
+static int get_border (xcb_window_t win);
+
+static void usage(char *name)
+{
+ fprintf(stderr, "usage: %s <x> <y> <w> <h> <wid>\n", name);
+ exit(1);
+}
+
+static void
+cleanup (void)
+{
+ if (conn)
+ xcb_disconnect(conn);
+}
+
+static int
+get_border (xcb_window_t win)
+{
+ xcb_get_geometry_reply_t *geom;
+ geom = xcb_get_geometry_reply(conn, xcb_get_geometry(conn, win), NULL);
+
+ if (!geom)
+ errx(1, "failed to get geometry");
+
+ return geom->border_width;
+}
+
+static void
+teleport (xcb_window_t win, int x, int y, int w, int h)
+{
+ uint32_t values[2];
+ int mode;
+
+ mode = get_border(win);
+ if (mode < 0)
+ return;
+
+ values[0] = x;
+ values[1] = y;
+
+ xcb_configure_window(conn, win, XCB_CONFIG_WINDOW_X
+ | XCB_CONFIG_WINDOW_Y, values);
+
+ values[0] = mode ? w - mode - 1 : w;
+ values[1] = mode ? h - mode - 1 : h;
+
+ xcb_configure_window(conn, win, XCB_CONFIG_WINDOW_WIDTH
+ | XCB_CONFIG_WINDOW_HEIGHT, values);
+}
+
+int
+main (int argc, char **argv)
+{
+ atexit(cleanup);
+ xcb_window_t win;
+
+ if (argc != 6)
+ usage(argv[0]);
+
+ if (xcb_connection_has_error(conn = xcb_connect(NULL, NULL)))
+ errx(1, "error connecting to X");
+
+ win = strtoul(argv[5], NULL, 16);
+ if (!win)
+ errx(1, "cannot get window");
+
+ teleport(win, atoi(argv[1]), atoi(argv[2]),
+ atoi(argv[3]), atoi(argv[4]));
+ xcb_flush(conn);
+
+ return 0;
+}