Skip to content

drawers: restore focus to previous window on dismiss#1323

Open
1letme wants to merge 1 commit into
caelestia-dots:mainfrom
1letme:fix/restore-focus-on-launcher-dismiss
Open

drawers: restore focus to previous window on dismiss#1323
1letme wants to merge 1 commit into
caelestia-dots:mainfrom
1letme:fix/restore-focus-on-launcher-dismiss

Conversation

@1letme
Copy link
Copy Markdown

@1letme 1letme commented Mar 22, 2026

Fixes #1322

What this does

When a drawer (launcher, session, sidebar, dashboard) is opened via HyprlandFocusGrab, it takes keyboard focus from the active window. Previously, when the drawer was dismissed (via Escape, keybind toggle, or clicking outside), focus was not restored to the previously active window. Hyprland would then fall back to focusing whatever window happened to be under the mouse cursor.

This patch stores the active toplevel's address when the focus grab activates, and dispatches focuswindow to restore it when the grab deactivates.

How it works

  • onActiveChanged handler on the existing HyprlandFocusGrab
  • When active becomes true: saves Hypr.activeToplevel.lastIpcObject.address
  • When active becomes false: dispatches focuswindow address:0x{saved} to restore focus
  • If the saved window was closed while the drawer was open, the dispatch is silently ignored by Hyprland and focus falls back to the default behavior (no regression)
  • When an app is launched from the launcher, focus is briefly restored to the previous window, then the newly spawned window takes focus naturally

Breaking changes

None.

Side effects

This also restores focus after dismissing the session menu, sidebar, and dashboard, not just the launcher. This should be the expected behavior for all of these.

When a drawer (launcher, session, sidebar, dashboard) is opened, the
HyprlandFocusGrab takes keyboard focus away from the active window.
On dismiss, focus was not restored, causing Hyprland to fall back to
focusing whatever window is under the mouse cursor.

This stores the active window address when the focus grab activates
and dispatches focuswindow to restore it when the grab deactivates.
@1letme 1letme force-pushed the fix/restore-focus-on-launcher-dismiss branch from bc49983 to 8e0cfbd Compare March 22, 2026 20:49
@soramanew
Copy link
Copy Markdown
Collaborator

This is not a bug with Caelestia, it is simply how Hyprland focus grabs behave by default. Your mouse will still change the window focus if you move it to hover over another window while the focus grab is active, just that it will not receive mouse events.

Hmm, actually I see what you mean. Even if you don't move the mouse it won't focus back the original window if your mouse if over another. But this is still an issue with Hyprland, not Caelestia.

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.

[BUG] Launcher dismissal doesn't restore focus to previously focused window

2 participants