Skip to content

Commit

Permalink
When blur is requested, open the window before blurring
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kolayne committed May 20, 2023
1 parent e8b9943 commit 2894697
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions i3lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -2581,6 +2571,25 @@ int main(int argc, char *argv[]) {
}
}

if (blur) {
// Blurring the earlier taken screenshot

bg_pixmap = bg_pixmap; // Suppress the 'may be used unitialized' warning

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
Expand Down

0 comments on commit 2894697

Please sign in to comment.