Skip to content

Commit a0fccac

Browse files
committed
When blur is requested, open the window before blurring
When locking screen, first open the window with a color (specified with `--color`) as background, then, if blurring is requested, do that and redraw window. Relates to Raymo111#239
1 parent e8b9943 commit a0fccac

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

i3lock.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,20 +2533,10 @@ int main(int argc, char *argv[]) {
25332533

25342534
free(image_raw_format);
25352535

2536+
xcb_pixmap_t bg_pixmap; // Initialized only `if (blur)`
25362537
if (blur) {
2537-
xcb_pixmap_t bg_pixmap = capture_bg_pixmap(conn, screen, last_resolution);
2538-
cairo_surface_t *xcb_img = cairo_xcb_surface_create(conn, bg_pixmap, get_root_visual_type(screen), last_resolution[0], last_resolution[1]);
2539-
2540-
blur_bg_img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, last_resolution[0], last_resolution[1]);
2541-
cairo_t *ctx = cairo_create(blur_bg_img);
2542-
2543-
cairo_set_source_surface(ctx, xcb_img, 0, 0);
2544-
cairo_paint(ctx);
2545-
blur_image_surface(blur_bg_img, blur_sigma);
2546-
2547-
cairo_destroy(ctx);
2548-
cairo_surface_destroy(xcb_img);
2549-
xcb_free_pixmap(conn, bg_pixmap);
2538+
// Make the screenshot before opening the window, blur it later
2539+
bg_pixmap = capture_bg_pixmap(conn, screen, last_resolution);
25502540
}
25512541

25522542
xcb_window_t stolen_focus = find_focused_window(conn, screen->root);
@@ -2581,6 +2571,23 @@ int main(int argc, char *argv[]) {
25812571
}
25822572
}
25832573

2574+
if (blur) {
2575+
// Blurring the earlier taken screenshot (`bg_pixmap`)
2576+
2577+
cairo_surface_t *xcb_img = cairo_xcb_surface_create(conn, bg_pixmap, get_root_visual_type(screen), last_resolution[0], last_resolution[1]);
2578+
2579+
blur_bg_img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, last_resolution[0], last_resolution[1]);
2580+
cairo_t *ctx = cairo_create(blur_bg_img);
2581+
2582+
cairo_set_source_surface(ctx, xcb_img, 0, 0);
2583+
cairo_paint(ctx);
2584+
blur_image_surface(blur_bg_img, blur_sigma);
2585+
2586+
cairo_destroy(ctx);
2587+
cairo_surface_destroy(xcb_img);
2588+
xcb_free_pixmap(conn, bg_pixmap);
2589+
}
2590+
25842591
pid_t pid = fork();
25852592
/* The pid == -1 case is intentionally ignored here:
25862593
* While the child process is useful for preventing other windows from

0 commit comments

Comments
 (0)