forked from external/yambar
misc: make use of the xcb-aux library
This commit is contained in:
parent
9d5bbe0566
commit
dff3104c85
5 changed files with 17 additions and 40 deletions
|
@ -23,7 +23,7 @@ set(CMAKE_C_FLAGS "-Wall -Werror ${CMAKE_C_FLAGS}")
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
|
|
||||||
pkg_check_modules(XCB REQUIRED xcb xcb-randr xcb-render xcb-cursor)
|
pkg_check_modules(XCB REQUIRED xcb xcb-aux xcb-randr xcb-render xcb-cursor)
|
||||||
pkg_check_modules(XCB_ERRORS xcb-errors)
|
pkg_check_modules(XCB_ERRORS xcb-errors)
|
||||||
pkg_check_modules(FONTCONFIG REQUIRED fontconfig)
|
pkg_check_modules(FONTCONFIG REQUIRED fontconfig)
|
||||||
pkg_check_modules(CAIRO REQUIRED cairo cairo-xcb cairo-ft)
|
pkg_check_modules(CAIRO REQUIRED cairo cairo-xcb cairo-ft)
|
||||||
|
|
44
bar.c
44
bar.c
|
@ -15,6 +15,7 @@
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
#include <xcb/randr.h>
|
#include <xcb/randr.h>
|
||||||
#include <xcb/render.h>
|
#include <xcb/render.h>
|
||||||
|
#include <xcb/xcb_aux.h>
|
||||||
#include <xcb/xcb_cursor.h>
|
#include <xcb/xcb_cursor.h>
|
||||||
#include <xcb/xcb_event.h>
|
#include <xcb/xcb_event.h>
|
||||||
#include <xcb/xcb_ewmh.h>
|
#include <xcb/xcb_ewmh.h>
|
||||||
|
@ -332,9 +333,7 @@ run(struct bar *_bar)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const xcb_setup_t *setup = xcb_get_setup(bar->conn);
|
xcb_screen_t *screen = xcb_aux_get_screen(bar->conn, default_screen);
|
||||||
|
|
||||||
xcb_screen_t *screen = xcb_setup_roots_iterator(setup).data;
|
|
||||||
|
|
||||||
xcb_randr_get_monitors_reply_t *monitors = xcb_randr_get_monitors_reply(
|
xcb_randr_get_monitors_reply_t *monitors = xcb_randr_get_monitors_reply(
|
||||||
bar->conn,
|
bar->conn,
|
||||||
|
@ -371,43 +370,20 @@ run(struct bar *_bar)
|
||||||
}
|
}
|
||||||
free(monitors);
|
free(monitors);
|
||||||
|
|
||||||
/* Find a 32-bit visual (TODO: fallback to 24-bit) */
|
|
||||||
const uint8_t wanted_depth = 32;
|
|
||||||
const uint8_t wanted_class = 0;
|
|
||||||
|
|
||||||
uint8_t depth = 0;
|
uint8_t depth = 0;
|
||||||
xcb_visualtype_t *vis = NULL;
|
xcb_visualtype_t *vis = xcb_aux_find_visual_by_attrs(screen, -1, 32);
|
||||||
|
|
||||||
for (xcb_depth_iterator_t it = xcb_screen_allowed_depths_iterator(screen);
|
if (vis != NULL)
|
||||||
it.rem > 0;
|
depth = 32;
|
||||||
xcb_depth_next(&it))
|
else {
|
||||||
{
|
vis = xcb_aux_find_visual_by_attrs(screen, -1, 24);
|
||||||
const xcb_depth_t *_depth = it.data;
|
if (vis != NULL)
|
||||||
|
depth = 24;
|
||||||
if (!(wanted_depth == 0 || _depth->depth == wanted_depth))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (xcb_visualtype_iterator_t vis_it =
|
|
||||||
xcb_depth_visuals_iterator(_depth);
|
|
||||||
vis_it.rem > 0;
|
|
||||||
xcb_visualtype_next(&vis_it))
|
|
||||||
{
|
|
||||||
xcb_visualtype_t *_vis = vis_it.data;
|
|
||||||
if (!(wanted_class == 0 || _vis->_class == wanted_class))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
vis = _vis;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vis != NULL) {
|
|
||||||
depth = _depth->depth;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(depth == 32 || depth == 24);
|
assert(depth == 32 || depth == 24);
|
||||||
assert(vis != NULL);
|
assert(vis != NULL);
|
||||||
|
LOG_DBG("using a %hhu-bit visual", depth);
|
||||||
|
|
||||||
bar->colormap = xcb_generate_id(bar->conn);
|
bar->colormap = xcb_generate_id(bar->conn);
|
||||||
xcb_create_colormap(bar->conn, 0, bar->colormap, screen->root, vis->visual_id);
|
xcb_create_colormap(bar->conn, 0, bar->colormap, screen->root, vis->visual_id);
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
|
#include <xcb/xcb_aux.h>
|
||||||
#include <i3/ipc.h>
|
#include <i3/ipc.h>
|
||||||
|
|
||||||
#include <json-c/json_tokener.h>
|
#include <json-c/json_tokener.h>
|
||||||
|
@ -384,8 +385,7 @@ run(struct module *mod)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const xcb_setup_t *setup = xcb_get_setup(conn);
|
xcb_screen_t *screen = xcb_aux_get_screen(conn, default_screen);
|
||||||
xcb_screen_t *screen = xcb_setup_roots_iterator(setup).data;
|
|
||||||
|
|
||||||
xcb_atom_t atom = get_atom(conn, "I3_SOCKET_PATH");
|
xcb_atom_t atom = get_atom(conn, "I3_SOCKET_PATH");
|
||||||
assert(atom != XCB_ATOM_NONE);
|
assert(atom != XCB_ATOM_NONE);
|
||||||
|
|
|
@ -614,8 +614,9 @@ static int
|
||||||
run(struct module *mod)
|
run(struct module *mod)
|
||||||
{
|
{
|
||||||
xcb_connection_t *conn = xcb_connect(NULL, NULL);
|
xcb_connection_t *conn = xcb_connect(NULL, NULL);
|
||||||
if (conn == NULL) {
|
if (xcb_connection_has_error(conn) > 0) {
|
||||||
LOG_ERR("failed to connect to X server");
|
LOG_ERR("failed to connect to X server");
|
||||||
|
xcb_disconnect(conn);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
|
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
|
#include <xcb/xcb_aux.h>
|
||||||
#include <xcb/xcb_event.h>
|
#include <xcb/xcb_event.h>
|
||||||
|
|
||||||
#define LOG_MODULE "xwindow"
|
#define LOG_MODULE "xwindow"
|
||||||
|
@ -204,8 +205,7 @@ run(struct module *mod)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const xcb_setup_t *setup = xcb_get_setup(m->conn);
|
xcb_screen_t *screen = xcb_aux_get_screen(m->conn, default_screen);
|
||||||
xcb_screen_t *screen = xcb_setup_roots_iterator(setup).data;
|
|
||||||
m->root_win = screen->root;
|
m->root_win = screen->root;
|
||||||
|
|
||||||
/* Need a window(?) to be able to process events */
|
/* Need a window(?) to be able to process events */
|
||||||
|
|
Loading…
Add table
Reference in a new issue