ohmu
·
2026-07-15
1// root attributes
2
3#include <stdio.h>
4#include <xcb/xcb.h>
5#include <stdlib.h>
6#include <unistd.h>
7
8xcb_connection_t *connection;
9
10int
11get_root_info(char attr_name)
12{
13 int attr;
14 const xcb_setup_t *setup = xcb_get_setup(connection);
15 xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup);
16 xcb_screen_t *screen = iter.data;
17 switch (attr_name) {
18 case 'w':
19 attr = screen->width_in_pixels;
20 break;
21 case 'h':
22 attr = screen->height_in_pixels;
23 break;
24 case '?':
25 fprintf(stderr, "wrong attr\n");
26 exit(1);
27 }
28 return attr;
29}
30
31int
32main(int argc, char *argv[])
33{
34 int opt;
35 if (argc < 2) {
36 fprintf(stderr, "usage: %s -wh\n", argv[0]);
37 exit(1);
38 }
39 connection = xcb_connect(NULL, NULL);
40 while ((opt = getopt(argc, argv, "wh")) != -1) {
41 printf("%d ", get_root_info(opt));
42 }
43 printf("\n");
44 xcb_disconnect(connection);
45 return 0;
46}