dwmblocks

Kris's build of dwmblocks
git clone git clone https://git.krisyotam.com/krisyotam/dwmblocks.git
Log | Files | Refs | README | LICENSE

x11.c (1293B)


      1 #include "x11.h"
      2 
      3 #include <stdio.h>
      4 #include <string.h>
      5 #include <xcb/xcb.h>
      6 #include <xcb/xproto.h>
      7 
      8 x11_connection *x11_connection_open(void) {
      9     xcb_connection_t *const connection = xcb_connect(NULL, NULL);
     10     if (xcb_connection_has_error(connection)) {
     11         (void)fprintf(stderr, "error: could not connect to X server\n");
     12         return NULL;
     13     }
     14 
     15     return connection;
     16 }
     17 
     18 void x11_connection_close(xcb_connection_t *const connection) {
     19     xcb_disconnect(connection);
     20 }
     21 
     22 int x11_set_root_name(x11_connection *const connection, const char *name) {
     23     xcb_screen_t *const screen =
     24         xcb_setup_roots_iterator(xcb_get_setup(connection)).data;
     25     const xcb_window_t root_window = screen->root;
     26 
     27     const unsigned short name_format = 8;
     28     const xcb_void_cookie_t cookie = xcb_change_property(
     29         connection, XCB_PROP_MODE_REPLACE, root_window, XCB_ATOM_WM_NAME,
     30         XCB_ATOM_STRING, name_format, strlen(name), name);
     31 
     32     xcb_generic_error_t *error = xcb_request_check(connection, cookie);
     33     if (error != NULL) {
     34         (void)fprintf(stderr, "error: could not set X root name\n");
     35         return 1;
     36     }
     37 
     38     if (xcb_flush(connection) <= 0) {
     39         (void)fprintf(stderr, "error: could not flush X output buffer\n");
     40         return 1;
     41     }
     42 
     43     return 0;
     44 }