master ohmu/wmutils / src / core / pfw.c
ohmu  ·  2026-07-25
 1/* See LICENSE file for copyright and license details. */
 2
 3#include <err.h>
 4#include <stdio.h>
 5#include <stdlib.h>
 6#include <xcb/xcb.h>
 7#include <xcb/xcb_aux.h>
 8
 9#include "util.h"
10
11static xcb_connection_t *conn;
12
13static xcb_window_t focus_window(void);
14
15static xcb_window_t
16focus_window(void)
17{
18	xcb_window_t w = 0;
19	xcb_get_input_focus_cookie_t c;
20	xcb_get_input_focus_reply_t *r;
21
22	c = xcb_get_input_focus(conn);
23	r = xcb_get_input_focus_reply(conn, c, NULL);
24	if (r == NULL)
25		errx(1, "xcb_get_input_focus");
26
27	w = r->focus;
28	free(r);
29
30	if (w == XCB_NONE || w == XCB_INPUT_FOCUS_POINTER_ROOT)
31		errx(1, "focus not set");
32
33	return w;
34}
35
36int
37main(int argc, char **argv)
38{
39	init_xcb(&conn);
40
41	printf("0x%08x\n", focus_window());
42
43	kill_xcb(&conn);
44	return 0;
45}