]> git.sur5r.net Git - i3/i3/blobdiff - src/x.c
add decoration_border color for the actual client borders
[i3/i3] / src / x.c
diff --git a/src/x.c b/src/x.c
index 17970fb8922f0dae464eb373decaf7b73b38ad8c..bef0e22ac14a4a1b1fce598d42becabcc274007d 100644 (file)
--- a/src/x.c
+++ b/src/x.c
@@ -101,47 +101,32 @@ void x_con_init(Con *con, uint16_t depth) {
     uint32_t mask = 0;
     uint32_t values[5];
 
-    xcb_visualid_t visual = XCB_COPY_FROM_PARENT;
-    xcb_colormap_t win_colormap = XCB_NONE;
-    if (depth != root_depth && depth != XCB_COPY_FROM_PARENT) {
-        /* For custom visuals, we need to create a colormap before creating
-         * this window. It will be freed directly after creating the window. */
-        visual = get_visualid_by_depth(depth);
-        win_colormap = xcb_generate_id(conn);
-        xcb_create_colormap_checked(conn, XCB_COLORMAP_ALLOC_NONE, win_colormap, root, visual);
-
-        /* We explicitly set a background color and border color (even though we
-         * don’t even have a border) because the X11 server requires us to when
-         * using 32 bit color depths, see
-         * http://stackoverflow.com/questions/3645632 */
-        mask |= XCB_CW_BACK_PIXEL;
-        values[0] = root_screen->black_pixel;
-
-        mask |= XCB_CW_BORDER_PIXEL;
-        values[1] = root_screen->black_pixel;
-
-        /* our own frames should not be managed */
-        mask |= XCB_CW_OVERRIDE_REDIRECT;
-        values[2] = 1;
-
-        /* see include/xcb.h for the FRAME_EVENT_MASK */
-        mask |= XCB_CW_EVENT_MASK;
-        values[3] = FRAME_EVENT_MASK & ~XCB_EVENT_MASK_ENTER_WINDOW;
-
-        mask |= XCB_CW_COLORMAP;
-        values[4] = win_colormap;
-    } else {
-        /* our own frames should not be managed */
-        mask = XCB_CW_OVERRIDE_REDIRECT;
-        values[0] = 1;
+    /* For custom visuals, we need to create a colormap before creating
+     * this window. It will be freed directly after creating the window. */
+    xcb_visualid_t visual = get_visualid_by_depth(depth);
+    xcb_colormap_t win_colormap = xcb_generate_id(conn);
+    xcb_create_colormap_checked(conn, XCB_COLORMAP_ALLOC_NONE, win_colormap, root, visual);
 
-        /* see include/xcb.h for the FRAME_EVENT_MASK */
-        mask |= XCB_CW_EVENT_MASK;
-        values[1] = FRAME_EVENT_MASK & ~XCB_EVENT_MASK_ENTER_WINDOW;
+    /* We explicitly set a background color and border color (even though we
+     * don’t even have a border) because the X11 server requires us to when
+     * using 32 bit color depths, see
+     * http://stackoverflow.com/questions/3645632 */
+    mask |= XCB_CW_BACK_PIXEL;
+    values[0] = root_screen->black_pixel;
 
-        mask |= XCB_CW_COLORMAP;
-        values[2] = colormap;
-    }
+    mask |= XCB_CW_BORDER_PIXEL;
+    values[1] = root_screen->black_pixel;
+
+    /* our own frames should not be managed */
+    mask |= XCB_CW_OVERRIDE_REDIRECT;
+    values[2] = 1;
+
+    /* see include/xcb.h for the FRAME_EVENT_MASK */
+    mask |= XCB_CW_EVENT_MASK;
+    values[3] = FRAME_EVENT_MASK & ~XCB_EVENT_MASK_ENTER_WINDOW;
+
+    mask |= XCB_CW_COLORMAP;
+    values[4] = win_colormap;
 
     Rect dims = {-15, -15, 10, 10};
     xcb_window_t frame_id = create_window(conn, dims, depth, visual, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCURSOR_CURSOR_POINTER, false, mask, values);
@@ -314,7 +299,7 @@ void x_window_kill(xcb_window_t window, kill_window_t kill_window) {
     free(event);
 }
 
-static void x_draw_decoration_border(Con *con, struct deco_render_params *p) {
+static void x_draw_title_border(Con *con, struct deco_render_params *p) {
     assert(con->parent != NULL);
 
     Rect *dr = &(con->deco_rect);
@@ -359,7 +344,7 @@ static void x_draw_decoration_after_title(Con *con, struct deco_render_params *p
     }
 
     /* Redraw the border. */
-    x_draw_decoration_border(con, p);
+    x_draw_title_border(con, p);
 }
 
 /*
@@ -479,21 +464,24 @@ void x_draw_decoration(Con *con) {
          * rectangle because some childs are not freely resizable and we want
          * their background color to "shine through". */
         if (!(borders_to_hide & ADJ_LEFT_SCREEN_EDGE)) {
-            draw_util_rectangle(conn, &(con->frame_buffer), p->color->background,
-                                0, 0, br.x, r->height);
+            draw_util_rectangle(conn, &(con->frame_buffer), p->color->decoration_border, 0, 0, br.x, r->height);
         }
         if (!(borders_to_hide & ADJ_RIGHT_SCREEN_EDGE)) {
-            draw_util_rectangle(conn, &(con->frame_buffer), p->color->background,
-                                r->width + (br.width + br.x), 0, -(br.width + br.x), r->height);
+            draw_util_rectangle(conn, &(con->frame_buffer),
+                                p->color->decoration_border, r->width + (br.width + br.x), 0,
+                                -(br.width + br.x), r->height);
         }
         if (!(borders_to_hide & ADJ_LOWER_SCREEN_EDGE)) {
-            draw_util_rectangle(conn, &(con->frame_buffer), p->color->background,
-                                br.x, r->height + (br.height + br.y), r->width + br.width, -(br.height + br.y));
+            draw_util_rectangle(conn, &(con->frame_buffer),
+                                p->color->decoration_border, br.x, r->height + (br.height +
+                                                                                br.y),
+                                r->width + br.width, -(br.height + br.y));
         }
         /* pixel border needs an additional line at the top */
         if (p->border_style == BS_PIXEL && !(borders_to_hide & ADJ_UPPER_SCREEN_EDGE)) {
-            draw_util_rectangle(conn, &(con->frame_buffer), p->color->background,
-                                br.x, 0, r->width + br.width, br.y);
+            draw_util_rectangle(conn, &(con->frame_buffer),
+                                p->color->decoration_border, br.x, 0, r->width + br.width,
+                                br.y);
         }
 
         /* Highlight the side of the border at which the next window will be
@@ -523,12 +511,20 @@ void x_draw_decoration(Con *con) {
     if (parent->frame_buffer.id == XCB_NONE)
         goto copy_pixmaps;
 
+    /* For the first child, we clear the parent pixmap to ensure there's no
+     * garbage left on there. This is important to avoid tearing when using
+     * transparency. */
+    if (con == TAILQ_FIRST(&(con->parent->nodes_head))) {
+        draw_util_clear_surface(conn, &(con->parent->frame_buffer), COLOR_TRANSPARENT);
+        FREE(con->parent->deco_render_params);
+    }
+
     /* 4: paint the bar */
     draw_util_rectangle(conn, &(parent->frame_buffer), p->color->background,
                         con->deco_rect.x, con->deco_rect.y, con->deco_rect.width, con->deco_rect.height);
 
     /* 5: draw two unconnected horizontal lines in border color */
-    x_draw_decoration_border(con, p);
+    x_draw_title_border(con, p);
 
     /* 6: draw the title */
     int text_offset_y = (con->deco_rect.height - config.font.height) / 2;
@@ -790,8 +786,8 @@ void x_push_node(Con *con) {
             /* Ensure we have valid dimensions for our surface. */
             // TODO This is probably a bug in the condition above as we should never enter this path
             //      for height == 0. Also, we should probably handle width == 0 the same way.
-            int width = MAX(rect.width, 1);
-            int height = MAX(rect.height, 1);
+            int width = MAX((int32_t)rect.width, 1);
+            int height = MAX((int32_t)rect.height, 1);
 
             xcb_create_pixmap_checked(conn, win_depth, con->frame_buffer.id, con->frame.id, width, height);
             draw_util_surface_init(conn, &(con->frame_buffer), con->frame_buffer.id,
@@ -991,7 +987,10 @@ void x_push_changes(Con *con) {
 
     DLOG("-- PUSHING WINDOW STACK --\n");
     //DLOG("Disabling EnterNotify\n");
-    uint32_t values[1] = {XCB_NONE};
+    /* We need to keep SubstructureRedirect around, otherwise clients can send
+     * ConfigureWindow requests and get them applied directly instead of having
+     * them become ConfigureRequests that i3 handles. */
+    uint32_t values[1] = {XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT};
     CIRCLEQ_FOREACH_REVERSE(state, &state_head, state) {
         if (state->mapped)
             xcb_change_window_attributes(conn, state->id, XCB_CW_EVENT_MASK, values);