wmv.c (1784B)
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 move(xcb_window_t, int, int, int); 21 22 static void 23 usage(char *name) 24 { 25 fprintf(stderr, "usage: %s [-a] <x> <y> <win>\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 }