core

WMUtils core.
git clone git://git.zepp.club/core.git
Log | Files | Refs | README | LICENSE

wrs.c (1742B)


      1 /* See LICENSE file for copyright and license details. */
      2 
      3 #include <xcb/xcb.h>
      4 #include <xcb/xcb_aux.h>
      5 #include <stdio.h>
      6 #include <stdlib.h>
      7 #include <err.h>
      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] <x> <y> <wid> [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 }