-
Notifications
You must be signed in to change notification settings - Fork 33
/
wmv.c
100 lines (78 loc) · 1.74 KB
/
wmv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* See LICENSE file for copyright and license details. */
#include <xcb/xcb.h>
#include <xcb/xcb_aux.h>
#include <stdio.h>
#include <stdlib.h>
#include <err.h>
#include "util.h"
enum {
ABSOLUTE = 0,
RELATIVE = 1
};
static xcb_connection_t *conn;
static xcb_screen_t *scr;
static void usage(char *);
static void move(xcb_window_t, int, int, int);
static void
usage(char *name)
{
fprintf(stderr, "usage: %s [-a] <x> <y> <win>\n", 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)
{
int x, y, mode = RELATIVE;
if (argc < 4)
usage(argv[0]);
init_xcb(&conn);
get_screen(conn, &scr);
if (argv[1][0] == '-' && argv[1][1] == 'a') {
mode = ABSOLUTE;
argv++;
}
x = atoi(*(++argv));
y = atoi(*(++argv));
while (*argv)
move(strtoul(*argv++, NULL, 16), mode, x, y);
xcb_aux_sync(conn);
kill_xcb(&conn);
return 0;
}