master ohmu/mwmutils / core / wa.c
ohmu  ·  2026-07-15
 1// window attributes
 2
 3#include <stdio.h>
 4#include <stdlib.h>
 5#include <xcb/xcb.h>
 6#include <unistd.h>
 7
 8xcb_connection_t *connection;
 9
10int
11get_window_info(xcb_window_t window, char attr_name)
12{
13    int attr;
14    xcb_get_geometry_cookie_t cookie;
15    xcb_get_geometry_reply_t *reply;
16    cookie = xcb_get_geometry(connection, window);
17    reply = xcb_get_geometry_reply(connection, cookie, NULL);
18    switch (attr_name) {
19        case 'x':
20            attr = reply->x;
21            break;
22        case 'y':
23            attr = reply->y;
24            break;
25        case 'w':
26            attr = reply->width;
27            break;
28        case 'h':
29            attr = reply->height;
30            break;
31        case 'b':
32            attr = reply->border_width;
33            break;
34        case '?':
35            fprintf(stderr, "wrong attr\n");
36            free(reply);
37            exit(1);
38     }
39    free(reply);
40    return attr;
41}
42
43int
44main(int argc, char *argv[]) 
45{
46    int opt;
47    if (argc < 2) {
48        fprintf(stderr, "usage: %s -xywhb winid\n", argv[0]);
49        exit(1);
50    }
51    xcb_window_t window;
52    connection = xcb_connect(NULL,NULL);
53    window = strtoul(argv[argc-1], NULL, 16);
54    if (!window) {
55        fprintf(stderr, "window id, please\n");
56        exit(1);
57    }
58    while ((opt = getopt(argc, argv, "xywhb")) != -1) {
59        printf("%d ", get_window_info(window, opt));
60    }
61    printf("\n");
62    xcb_disconnect(connection);
63    return 0;
64}