Skip to content

When blur is requested, open the window before blurring - #278

Open
kolayne wants to merge 3 commits into
Raymo111:masterfrom
kolayne:show-window-early
Open

kolayne wants to merge 3 commits into
Raymo111:masterfrom
kolayne:show-window-early

Conversation

@kolayne

@kolayne kolayne commented Apr 15, 2023

Copy link
Copy Markdown

Description

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.

My use case is to lock screen when the laptop lid is closed (I use xss-lock for that) but sometimes i3lock-color doesn't manage to do the blurring in time, as a consequence, when the lid is opened, one has about a second or two to see the screen before the screen is locked. The solution is to first open the window earlier, and update it after processing the blur.

Relates to #239. Not sure if the PR resolves it, but it can certainly act as an intermediate solution before a fancier locking mechanism, as requested by the issue author, is implemented. By the way, I think, the requested behavior is achieved with running i3lock -B <sigma> --color '#00000000': it will first open the window with fully transparent background, then blur the screenshot and update the window whenever it has finished the processing.

Release notes

Notes: open the lock window earlier when locking with blurring

Behavior worth noticing

  1. If one starts typing their password when the window is open but the blurring is still in progress, the decoration won't appear immediately but after the blurring process is over, all the keyboard events are delivered and processed properly, unless the enter key was pressed. But if it was, the lock screen at first seems to behave the same way (that is, all the decorations appear and it then shows the "verifying..." caption), but it remains stuck in the verifying state until I try to retype my password and verify again. Even with the --no-verify option, pressing enter on the early window stage will bring it to the verifying state.
    I would appreciate a hint on why this could be happening. If you know how to fix this, feel free to submit a patch, otherwise I will try to dig deeper into this later when I have time.

    No 'unless' anymore, everything is fine now :)
  2. I am not sure if i3lock-color is supposed to support the --image and --blur options together and, if yes, what behavior is expected, but it would probably make sense to display the background image while the blurring is in progress, not a solid color. Should it?
  3. PR also fixes the behavior in case the user has completely typed its password and pressed Enter before the initialization has completed. This behavior was present before the patch, but with the patch it has gotten easier to encounter accidentally, so I fixed it. I had to use an additional variable, but I'm not closely familiar with the ev and xcb libraries, so I might have missed a more elegant solution.

@kolayne
kolayne force-pushed the show-window-early branch from a0fccac to eb326b9 Compare May 20, 2023 13:50
@kolayne
kolayne marked this pull request as ready for review May 20, 2023 14:03
@kolayne
kolayne force-pushed the show-window-early branch from eb326b9 to 014233e Compare May 20, 2023 14:09
kolayne added 2 commits May 20, 2023 17:09
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
If user has entered a correct password and pressed enter before the
initialization has completed, i3lock used to verify the password but not
exit correctly, which was easy to encounter with a high sigma value for blurring.

I wonder if there is a more elegant implementation...
@kolayne

kolayne commented May 26, 2023

Copy link
Copy Markdown
Author

Hello!
@Raymo111, not sure if GitHub notifies the maintainer when a draft is converted to a PR, so just wanted to let you know that this is ready for review.

Raymo111
Raymo111 previously approved these changes Jul 22, 2026

@Raymo111 Raymo111 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — Approve with nits

What it does: Takes the desktop screenshot before mapping the lock window, then maps the window with the solid --color background and grabs pointer/keyboard, and only afterwards runs the (potentially slow) blur and redraws. Also adds a global bool unlocked so that if the user typed the password and hit Enter before init finished, the process exits instead of blocking in the event loop.

Security — net improvement, no leak introduced: In both old and new code the grab happens after xcb_map_window and after the grab-retry block; the map→grab ordering is unchanged. What changes is that the slow blur now runs after the grab instead of before it — previously, with a high --sigma, the desktop stayed ungrabbed and interactive for the whole blur duration. This closes an existing exposure window rather than opening one. The screenshot is still captured before the lock window is mapped (so it captures the real desktop), and early keystrokes are only drained at ev_invoke, which runs after the grab is active.

Correctness: The unlocked flag covers all three ev_break sites (--no-verify, OpenBSD, PAM success) and not the auth-failure path, so a wrong early password still enters the loop correctly. The early-Enter fix is sound: ev_break during ev_invoke sets libev's loop_done, but ev_run still does one full blocking iteration before checking it — with the keyboard grabbed and no input, that blocks forever; gating ev_loop on !unlocked avoids it. NULL blur_bg_img during the early render is safe (guarded, falls back to solid color). No double-free on bg_pixmap.

Nit: xcb_pixmap_t bg_pixmap = bg_pixmap; (self-initialization to silence -Wmaybe-uninitialized) is a code smell and may itself trip -Winit-self. Prefer = XCB_NONE.

Recommendation: Merge after the = XCB_NONE tweak — improves lock-screen input security and fixes a genuine early-unlock hang.

Review comment (Raymo111#278 (review)):

> **Nit:** `xcb_pixmap_t bg_pixmap = bg_pixmap;` (self-initialization to silence `-Wmaybe-uninitialized`) is a code smell and may itself trip `-Winit-self`. Prefer `= XCB_NONE`.
@kolayne

kolayne commented Jul 22, 2026

Copy link
Copy Markdown
Author

👍

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants