Skip to content

Ensure that input focus is returned to correct window when i3lock quits - #302

Open
CometStorm991 wants to merge 1 commit into
Raymo111:masterfrom
CometStorm991:master
Open

Ensure that input focus is returned to correct window when i3lock quits#302
CometStorm991 wants to merge 1 commit into
Raymo111:masterfrom
CometStorm991:master

Conversation

@CometStorm991

Copy link
Copy Markdown

Description

  • The input focus does not always return to the previously focused window after i3lock-color quits.
  • For example, when the --composite option is enabled, the parent window set by parent_win = composite_reply->overlay_win; in xcb.c can be different from the window from which focus was stolen.
  • If i3-lock fails to grab the pointer and keyboard on its first attempt, the input focus will be set to i3lock and will later revert to the parent window (which may not be the correct window when the --composite option is enabled) as shown below (comments removed)
    auth_state = STATE_AUTH_LOCK;
    if (!grab_pointer_and_keyboard(conn, screen, cursor, 1000)) {
        DEBUG("stole focus from X11 window 0x%08x\n", stolen_focus);

        xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT /* revert_to */, win, XCB_CURRENT_TIME);
        ...
    }
  • Incorrectly reverting the input focus can cause user input in DE/WMs to seem "frozen" since keyboard input may not appear to work (although the mouse may work).
  • Adding xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT /* revert_to */, stolen_focus, XCB_CURRENT_TIME); to the end of main(...), ensures that focus returns to the correct window stolen_focus.

@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: Adds one line to the exit path of main() that sets X input focus back to stolen_focus immediately after the existing set_focused_window() call, fixing cases (notably --composite) where focus otherwise reverts to the wrong window.

Correctness: Sound and matches intent. stolen_focus is captured from the root's _NET_ACTIVE_WINDOW (the WM's real managed client), not i3lock's win nor the composite overlay, so targeting it with xcb_set_input_focus is correct. The added call is reached only when stolen_focus != XCB_NONE, so the value is always valid here. Ordering is fine — it runs after xcb_destroy_window(win), so it overrides X's automatic focus-revert (which, under --composite, would land on the overlay window rather than the original client). Applies cleanly to current master.

Nit: set_focused_window() and the new set_input_focus() now both fire and look redundant at a glance — they're actually complementary (the former updates the WM's active-window state, the latter fixes the raw X input focus). A one-line comment explaining why both are kept would help future readers.

Recommendation: Merge — small, correct, well-motivated fix with no functional downside.

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