Skip to content

Commit

Permalink
Merge 014233e into e8b9943
Browse files Browse the repository at this point in the history
  • Loading branch information
kolayne committed May 20, 2023
2 parents e8b9943 + 014233e commit 479ae5e
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions i3lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ int failed_attempts = 0;
bool show_failed_attempts = false;
bool retry_verification = false;

/* Set to true by `input_done` when the password is correct.
* Needed if user has entered password before intialization completed. */
bool unlocked = false;

static struct xkb_state *xkb_state;
static struct xkb_context *xkb_context;
static struct xkb_keymap *xkb_keymap;
Expand Down Expand Up @@ -564,6 +568,7 @@ static void input_done(void) {

if (no_verify) {
ev_break(EV_DEFAULT, EVBREAK_ALL);
unlocked = true;
return;
}

Expand All @@ -578,6 +583,7 @@ static void input_done(void) {
clear_password_memory();

ev_break(EV_DEFAULT, EVBREAK_ALL);
unlocked = true;
return;
}
#else
Expand All @@ -593,6 +599,7 @@ static void input_done(void) {
pam_cleanup = true;

ev_break(EV_DEFAULT, EVBREAK_ALL);
unlocked = true;
return;
}
#endif
Expand Down Expand Up @@ -2533,20 +2540,10 @@ int main(int argc, char *argv[]) {

free(image_raw_format);

xcb_pixmap_t bg_pixmap = 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 +2578,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
Expand Down Expand Up @@ -2626,19 +2640,24 @@ int main(int argc, char *argv[]) {
* file descriptor becomes readable). */
ev_invoke(main_loop, xcb_check, 0);

if (show_clock || bar_enabled || slideshow_enabled) {
if (redraw_thread) {
struct timespec ts;
double s;
double ns = modf(refresh_rate, &s);
ts.tv_sec = (time_t) s;
ts.tv_nsec = ns * NANOSECONDS_IN_SECOND;
(void) pthread_create(&draw_thread, NULL, start_time_redraw_tick_pthread, (void*) &ts);
} else {
start_time_redraw_tick(main_loop);
/* If the user was fast enough to have typed their password (and pressed Enter) before
* i3lock has finished intializing, all of that is processed in the above `ev_invoke`.
* If the password was correct (`unlocked` is true), we should not enter the event loop. */
if (!unlocked) {
if (show_clock || bar_enabled || slideshow_enabled) {
if (redraw_thread) {
struct timespec ts;
double s;
double ns = modf(refresh_rate, &s);
ts.tv_sec = (time_t) s;
ts.tv_nsec = ns * NANOSECONDS_IN_SECOND;
(void) pthread_create(&draw_thread, NULL, start_time_redraw_tick_pthread, (void*) &ts);
} else {
start_time_redraw_tick(main_loop);
}
}
ev_loop(main_loop, 0);
}
ev_loop(main_loop, 0);

#ifndef __OpenBSD__
if (pam_cleanup) {
Expand Down

0 comments on commit 479ae5e

Please sign in to comment.