Skip to content

Fix: center unlock dialog on screen when triggered from system tray#13421

Open
yjdyamv wants to merge 2 commits into
keepassxreboot:developfrom
yjdyamv:develop
Open

Fix: center unlock dialog on screen when triggered from system tray#13421
yjdyamv wants to merge 2 commits into
keepassxreboot:developfrom
yjdyamv:develop

Conversation

@yjdyamv

@yjdyamv yjdyamv commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

When KeePassXC is minimized to the system tray and the unlock dialog is shown (e.g. via global Auto-Type shortcut), the dialog appears in the top-left corner instead of centered because Qt has no valid parent window geometry to position against.

Add centering logic to DatabaseOpenDialog::showEvent() using QApplication::screenAt(QCursor::pos()), consistent with the existing implementation in AutoTypeSelectDialog.

Fixes the issue where popup windows appear in upper left of screen on Windows with Qt6.

Fixes #13375

Screenshots

Testing strategy

  1. build this branch and run KeePassXC.
  2. "Application Settings" -> "Auto-type" -> "Global Auto-Type shortcut": set a shortcut you like (eg: Ctrl + Alt + Space)
  3. open a keepass database file. lock the db and minimise the window.
  4. use the shortcut to call an unlock window, and can see it located center

Type of change

  • ✅ Bug fix (non-breaking change that fixes an issue)

When KeePassXC is minimized to the system tray and the unlock dialog is
shown (e.g. via global Auto-Type shortcut), the dialog appears in the
top-left corner instead of centered because Qt has no valid parent window
geometry to position against.

Add centering logic to DatabaseOpenDialog::showEvent() using
QApplication::screenAt(QCursor::pos()), consistent with the existing
implementation in AutoTypeSelectDialog.

Fixes the issue where popup windows appear in upper left of screen on
Windows with Qt6.
Comment thread src/gui/DatabaseOpenDialog.cpp Outdated
@droidmonkey

Copy link
Copy Markdown
Member

Nice!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes dialog positioning when KeePassXC is minimized to the system tray (notably on Windows with Qt6), ensuring unlock-related dialogs are centered on the screen under the mouse cursor rather than appearing at (0,0) due to missing/invalid parent window geometry.

Changes:

  • Adds a shared helper (GuiTools::centerWidgetOnActiveScreen) to center a widget on the screen at the current cursor position (fallback: primary screen).
  • Uses the helper in DatabaseOpenDialog::showEvent() to center the unlock dialog when shown from the tray/global shortcut flows.
  • Refactors existing centering logic in Auto-Type dialogs to reuse the shared helper.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/gui/GuiTools.h Declares a new helper for centering widgets on the active (cursor) screen.
src/gui/GuiTools.cpp Implements the new centering helper using screenAt(QCursor::pos()) with a fallback.
src/gui/DatabaseOpenDialog.cpp Centers the unlock dialog on show to avoid top-left placement when triggered from tray.
src/autotype/PickcharsDialog.cpp Replaces inline centering code with the shared helper.
src/autotype/AutoTypeSelectDialog.cpp Reuses the shared helper after restoring/clamping dialog size.

Comment thread src/gui/GuiTools.cpp Outdated
…reen

Move screen detection and widget centering into a shared GuiTools
helper to avoid duplication across dialogs. Apply code review
suggestions: add null guards and use frameGeometry().moveCenter()
for accurate positioning with window decorations.
@yjdyamv

yjdyamv commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Ok, I just revised to follow copilot' s robust advice.

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.

Windows Qt6 - Popup windows appear in upper left of screen

3 participants