From f28d0af32e28005a4b28857fa4fd4232d6849442 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Fri, 17 Nov 2023 00:19:53 +0100 Subject: Simplify visual type search and fix window depth Transparency started working due to the explicit selection of a depth (preferring 32 bit) instead of copying that of the root window --- connection.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'connection.c') diff --git a/connection.c b/connection.c index 8e26283..1ee29bc 100644 --- a/connection.c +++ b/connection.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -183,7 +184,7 @@ Connection *connection_create() g_assert_true(con->connection != NULL && !xcb_connection_has_error(con->connection)); log_debug("Xcb connection established"); - log_debug("Default screen %d", preferred_screen); + log_debug("Default screen '%d'", preferred_screen); xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(con->connection)); while (preferred_screen != 0 && iter.rem) { @@ -220,28 +221,18 @@ Connection *connection_create() XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE | XCB_RANDR_NOTIFY_MASK_OUTPUT_PROPERTY); - con->database = xcb_xrm_database_from_default(con->connection); - g_assert_nonnull(con->database); + log_debug("Xcb searching 32 bit visual"); + con->visual_type = xcb_aux_find_visual_by_attrs(con->screen, XCB_VISUAL_CLASS_TRUE_COLOR, 32); + con->screen_depth = 32; - g_assert(xcb_errors_context_new(con->connection, &con->errors) == 0); - log_debug("Xcb errors loaded"); - - xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(con->screen); - while (depth_iter.rem) { - xcb_visualtype_iterator_t visual_iter = xcb_depth_visuals_iterator(depth_iter.data); - - while (visual_iter.rem) { - if (con->screen->root_visual == visual_iter.data->visual_id) { - con->visual_type = visual_iter.data; - con->depth = depth_iter.data; - goto found_visual; - } - xcb_visualtype_next(&visual_iter); - } - xcb_depth_next(&depth_iter); + if (con->visual_type == NULL) { + // NOTE: 24 bit visuals don't have the alpha channel for transparency + log_debug("Fallback to 24 bit visual"); + con->visual_type = xcb_aux_find_visual_by_attrs(con->screen, XCB_VISUAL_CLASS_TRUE_COLOR, 24); + con->screen_depth = 24; } -found_visual: + g_assert_nonnull(con->visual_type); log_debug("Xcb visual type found [id=%u]", con->visual_type->visual_id); xcb_intern_atom_cookie_t *ewmh_cookie = xcb_ewmh_init_atoms(con->connection, &con->ewmh); @@ -249,8 +240,14 @@ found_visual: g_assert_null(error); log_debug("Xcb ewmh initialized"); + con->database = xcb_xrm_database_from_default(con->connection); + g_assert_nonnull(con->database); + update_scale(con); + g_assert(xcb_errors_context_new(con->connection, &con->errors) == 0); + log_debug("Xcb errors loaded"); + xcb_flush(con->connection); log_debug("Xcb set up"); -- cgit v1.2.3