]> git.lizzy.rs Git - bspwm.git/blob - contrib/create_frame.c
Merge translate_position and translate_client
[bspwm.git] / contrib / create_frame.c
1 #include <stdlib.h>
2 #include <stdbool.h>
3 #include <string.h>
4 #include <xcb/xcb.h>
5 #include <xcb/xcb_event.h>
6 #include <xcb/xcb_icccm.h>
7
8 #define FRAME_CLASS_NAME     "BSPWM_FRAME"
9 #define FRAME_INSTANCE_NAME  "bspwm_frame"
10
11 xcb_connection_t *dpy;
12
13 bool get_atom(char *name, xcb_atom_t *atom)
14 {
15     bool ack = true;
16     xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(dpy, xcb_intern_atom(dpy, 0, strlen(name), name), NULL);
17     if (reply != NULL)
18         *atom = reply->atom;
19     else
20         ack = false;
21     free(reply);
22     return ack;
23 }
24
25 int main(int argc, char *argv[])
26 {
27     dpy = xcb_connect(NULL, NULL);
28     if (dpy == NULL)
29         return EXIT_FAILURE;
30     xcb_atom_t WM_PROTOCOLS, WM_DELETE_WINDOW;
31     if (!get_atom("WM_PROTOCOLS", &WM_PROTOCOLS)
32             || !get_atom("WM_DELETE_WINDOW", &WM_DELETE_WINDOW)) {
33         xcb_disconnect(dpy);
34         return EXIT_FAILURE;
35     }
36     xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(dpy)).data;
37     if (screen == NULL)
38         return EXIT_FAILURE;
39     xcb_window_t root = screen->root;
40     xcb_window_t win = xcb_generate_id(dpy);
41     xcb_create_window(dpy, XCB_COPY_FROM_PARENT, win, root, 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, NULL);
42     xcb_icccm_set_wm_class(dpy, win, strlen(FRAME_CLASS_NAME) + strlen(FRAME_INSTANCE_NAME) + 1, FRAME_INSTANCE_NAME "\0" FRAME_CLASS_NAME);
43     xcb_map_window(dpy, win);
44     xcb_flush(dpy);
45     xcb_generic_event_t *evt;
46     bool running = true;
47     while (running && (evt = xcb_wait_for_event(dpy)) != NULL) {
48         uint8_t rt = XCB_EVENT_RESPONSE_TYPE(evt);
49         if (rt == XCB_CLIENT_MESSAGE)  {
50             xcb_client_message_event_t *cme = (xcb_client_message_event_t *) evt;
51             if (cme->type == WM_PROTOCOLS && cme->data.data32[0] == WM_DELETE_WINDOW)
52                 running = false;
53         }
54         free(evt);
55     }
56     xcb_destroy_window(dpy, win);
57     xcb_disconnect(dpy);
58     return EXIT_SUCCESS;
59 }