aboutsummaryrefslogtreecommitdiff
path: root/connection.c
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2023-11-17 00:19:53 +0100
committerFederico Angelilli <code@fedang.net>2023-11-17 00:50:05 +0100
commitf28d0af32e28005a4b28857fa4fd4232d6849442 (patch)
tree390ba9ea0e4647c17da1e44d203e97053558650f /connection.c
parent68ca7d2e289290f3142fda529d67c5e87a0b6c30 (diff)
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
Diffstat (limited to 'connection.c')
-rw-r--r--connection.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/connection.c b/connection.c
index 8e26283..1ee29bc 100644
--- a/connection.c
+++ b/connection.c
@@ -1,5 +1,6 @@
#include <glib.h>
#include <xcb/xcb.h>
+#include <xcb/xcb_aux.h>
#include <xcb/xcb_ewmh.h>
#include <xcb/xcb_xrm.h>
#include <xcb/xcb_errors.h>
@@ -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");