From 68ca7d2e289290f3142fda529d67c5e87a0b6c30 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Thu, 16 Nov 2023 19:38:12 +0100 Subject: Refactor `window_create` --- draw.c | 11 +++++++---- window.c | 28 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/draw.c b/draw.c index ebaf004..1dfa773 100644 --- a/draw.c +++ b/draw.c @@ -49,7 +49,10 @@ void draw(Window *win) int radius = height / 2; double degree = M_PI / 180.0; - cairo_set_source_rgb(cr, 0.3, 0.3, 0.3); + // FIXME: Alpha transparency is not working + double alpha = 0.8; + + cairo_set_source_rgba(cr, 0.3, 0.3, 0.3, alpha); // TODO: Here we should paint the shape of the bar, however there is a problem with the surface // painted in the pixmap to mask the window shape in window_paint_corners. @@ -73,18 +76,18 @@ void draw(Window *win) int x = (height + cairo_get_line_width(cr) * scale * 2) * i; // purple - cairo_set_source_rgb(cr, 0.502, 0.168, 0.886); + cairo_set_source_rgba(cr, 0.502, 0.168, 0.886, alpha); cairo_arc(cr, x + radius, radius, radius, 0 * degree, 360 * degree); cairo_fill(cr); - cairo_set_source_rgb(cr, 0.8, 0.8, 0.8); + cairo_set_source_rgba(cr, 0.8, 0.8, 0.8, alpha); cairo_arc(cr, x + radius, radius, radius - 1, 0 * degree, 360 * degree); cairo_stroke(cr); + cairo_set_source_rgb(cr, 0.8, 0.8, 0.8); char btn[] = { '1' + i, '\0' }; pango_layout_set_text(layout, btn, -1); - int text_w, text_h; pango_layout_get_pixel_size(layout, &text_w, &text_h); text_w = ceil(text_w / scale); diff --git a/window.c b/window.c index 9136339..027fdb1 100644 --- a/window.c +++ b/window.c @@ -128,14 +128,14 @@ Window *window_create(Connection *con) | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_FOCUS_CHANGE | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS; - xcb_colormap_t colormap = xcb_generate_id(win->con->connection); - xcb_create_colormap(win->con->connection, XCB_COLORMAP_ALLOC_NONE, colormap, win->con->screen->root, win->con->visual_type->visual_id); + xcb_colormap_t colormap = xcb_generate_id(con->connection); + xcb_create_colormap(con->connection, XCB_COLORMAP_ALLOC_NONE, colormap, con->screen->root, con->visual_type->visual_id); log_debug("Xcb colormap created [id=%u]", colormap); const uint32_t value_list[] = { XCB_NONE, // back pixmap - 0x000000, // back pixel - 0x000000, // border pixel + 0x00000000, // back pixel + 0x00000000, // border pixel true, // override redirect event_mask, // event mask colormap // colormap @@ -147,15 +147,15 @@ Window *window_create(Connection *con) win->x = win->y = 0; log_debug("Window temporary position [x=%d, y=%d]", win->x, win->y); - win->window = xcb_generate_id(win->con->connection); - xcb_create_window(win->con->connection, + win->window = xcb_generate_id(con->connection); + xcb_create_window(con->connection, XCB_COPY_FROM_PARENT, - win->window, win->con->screen->root, + win->window, con->screen->root, win->x, win->y, win->width, win->height, 0, // border XCB_WINDOW_CLASS_INPUT_OUTPUT, - win->con->screen->root_visual, + con->screen->root_visual, value_mask, value_list); @@ -164,15 +164,15 @@ Window *window_create(Connection *con) wm_setup(win); log_debug("Window wm options completed"); - xcb_map_window(win->con->connection, win->window); - xcb_flush(win->con->connection); + xcb_map_window(con->connection, win->window); + xcb_flush(con->connection); log_debug("Xcb initialized"); - win->surface = cairo_xcb_surface_create(win->con->connection, + win->surface = cairo_xcb_surface_create(con->connection, win->window, - win->con->visual_type, - win->con->screen_size->width, - win->con->screen_size->height); + con->visual_type, + con->screen_size->width, + con->screen_size->height); g_assert_cmpint(cairo_surface_status(win->surface), ==, CAIRO_STATUS_SUCCESS); log_debug("Cairo surface created"); -- cgit v1.2.3