aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--Makefile1
-rw-r--r--connection.c37
-rw-r--r--connection.h2
-rw-r--r--window.c9
4 files changed, 24 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index 6ea520e..70f37f6 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@ BIN = comet.bin
DEPS = \
xcb \
+ xcb-aux \
xcb-icccm \
xcb-ewmh \
xcb-xrm \
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");
diff --git a/connection.h b/connection.h
index 1cb0160..b187b7a 100644
--- a/connection.h
+++ b/connection.h
@@ -16,8 +16,8 @@ struct Connection {
xcb_screen_t *screen;
xcb_randr_screen_size_t *screen_size;
double screen_dpi;
+ int screen_depth;
xcb_visualtype_t *visual_type;
- xcb_depth_t *depth;
xcb_xrm_database_t *database;
xcb_errors_context_t *errors;
xcb_ewmh_connection_t ewmh;
diff --git a/window.c b/window.c
index 027fdb1..e7391be 100644
--- a/window.c
+++ b/window.c
@@ -149,13 +149,14 @@ Window *window_create(Connection *con)
win->window = xcb_generate_id(con->connection);
xcb_create_window(con->connection,
- XCB_COPY_FROM_PARENT,
- win->window, con->screen->root,
+ con->screen_depth,
+ win->window,
+ con->screen->root,
win->x, win->y,
win->width, win->height,
0, // border
- XCB_WINDOW_CLASS_INPUT_OUTPUT,
- con->screen->root_visual,
+ XCB_WINDOW_CLASS_COPY_FROM_PARENT,
+ con->visual_type->visual_id,
value_mask,
value_list);