From a0fccace5384cd96d2ca89ede59359b099f163e7 Mon Sep 17 00:00:00 2001 From: Nikolay Nechaev Date: Sat, 15 Apr 2023 13:40:11 +0300 Subject: [PATCH] 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 #239 --- i3lock.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/i3lock.c b/i3lock.c index 8406fa67..23631b2c 100644 --- a/i3lock.c +++ b/i3lock.c @@ -2533,20 +2533,10 @@ int main(int argc, char *argv[]) { free(image_raw_format); + xcb_pixmap_t bg_pixmap; // Initialized only `if (blur)` if (blur) { - xcb_pixmap_t bg_pixmap = capture_bg_pixmap(conn, screen, last_resolution); - cairo_surface_t *xcb_img = cairo_xcb_surface_create(conn, bg_pixmap, get_root_visual_type(screen), last_resolution[0], last_resolution[1]); - - blur_bg_img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, last_resolution[0], last_resolution[1]); - cairo_t *ctx = cairo_create(blur_bg_img); - - cairo_set_source_surface(ctx, xcb_img, 0, 0); - cairo_paint(ctx); - blur_image_surface(blur_bg_img, blur_sigma); - - cairo_destroy(ctx); - cairo_surface_destroy(xcb_img); - xcb_free_pixmap(conn, bg_pixmap); + // Make the screenshot before opening the window, blur it later + bg_pixmap = capture_bg_pixmap(conn, screen, last_resolution); } xcb_window_t stolen_focus = find_focused_window(conn, screen->root); @@ -2581,6 +2571,23 @@ int main(int argc, char *argv[]) { } } + if (blur) { + // Blurring the earlier taken screenshot (`bg_pixmap`) + + cairo_surface_t *xcb_img = cairo_xcb_surface_create(conn, bg_pixmap, get_root_visual_type(screen), last_resolution[0], last_resolution[1]); + + blur_bg_img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, last_resolution[0], last_resolution[1]); + cairo_t *ctx = cairo_create(blur_bg_img); + + cairo_set_source_surface(ctx, xcb_img, 0, 0); + cairo_paint(ctx); + blur_image_surface(blur_bg_img, blur_sigma); + + cairo_destroy(ctx); + cairo_surface_destroy(xcb_img); + xcb_free_pixmap(conn, bg_pixmap); + } + pid_t pid = fork(); /* The pid == -1 case is intentionally ignored here: * While the child process is useful for preventing other windows from