Problem
With the KeePass option "Minimize main window after opening a database" enabled, unlocking the database through Kee (e.g. the "Open KeePass" button while the database is locked) leaves the KeePass main window open in the foreground. Unlocking the same database directly in KeePass (tray icon, hotkey) minimizes the window as expected.
Steps to reproduce
- KeePass options → Interface: enable "Minimize main window after opening a database" and "Minimize to tray instead of taskbar".
- Lock the workspace (KeePass sits in the tray).
- In Kee, click the KeePass button and unlock the database.
- Expected: KeePass goes back to the tray after unlocking. Actual: the main window stays open and focused.
Without "Minimize to tray" the window briefly minimizes and is then restored again.
Cause
Both effects come from PromptUserToOpenDb in KeePassRPCService.cs:
-
After the unlock, the window state is set back explicitly:
// Set the program state back to what is was unless the user has
// configured "lock on minimise" in which case we always set it to Normal
if (!Program.Config.Security.WorkspaceLocking.LockOnWindowMinimize)
{
minimised = false;
trayed = false;
}
Program.MainForm.WindowState = minimised ? FormWindowState.Minimized : FormWindowState.Normal;
This overrides the minimize that MainForm.OpenDatabase performs when MinimizeAfterOpeningDatabase is set. (Side note: the comment describes the opposite of what the condition does.)
-
When KeePass is in the tray, Native.AttachToActiveAndBringToForeground shows the window via the native ShowWindow(SW_RESTORE). That does not update Form.Visible, which stays false. While Visible is false, WinForms ignores WindowState changes, so KeePass's own minimize after opening the database has no effect either.
I confirmed the sequence with temporary logging of the window state and Form.Visible (Windows 11, KeePass 2.61.1, KeePassRPC 2.0.2, KeePassWinHello for unlocking). The unlock prompt runs synchronously inside the native restore, so the database is already open when PromptUserToOpenDb finishes.
Proposed fix
At the end of PromptUserToOpenDb, if the database was closed or locked at the start and is open now, and the user has enabled MinimizeAfterOpeningDatabase, minimize the main window (deferred with BeginInvoke, after the state restore). If Form.Visible is out of sync, set it to true first so WinForms applies the state change. KeePass's own OnFormResize then decides between tray and taskbar as usual.
Nothing changes for users without that option. The window is also left alone when the database was already open (showing KeePass stays possible), when the unlock is cancelled, and when minimizing would lock the workspace again (LockOnWindowMinimize, or LockOnWindowMinimizeToTray together with MinimizeToTray). No new setting, no platform-specific code.
I have a small patch (one file, ~30 added lines) and can open a pull request if you're interested.
Problem
With the KeePass option "Minimize main window after opening a database" enabled, unlocking the database through Kee (e.g. the "Open KeePass" button while the database is locked) leaves the KeePass main window open in the foreground. Unlocking the same database directly in KeePass (tray icon, hotkey) minimizes the window as expected.
Steps to reproduce
Without "Minimize to tray" the window briefly minimizes and is then restored again.
Cause
Both effects come from
PromptUserToOpenDbinKeePassRPCService.cs:After the unlock, the window state is set back explicitly:
This overrides the minimize that
MainForm.OpenDatabaseperforms whenMinimizeAfterOpeningDatabaseis set. (Side note: the comment describes the opposite of what the condition does.)When KeePass is in the tray,
Native.AttachToActiveAndBringToForegroundshows the window via the nativeShowWindow(SW_RESTORE). That does not updateForm.Visible, which staysfalse. WhileVisibleisfalse, WinForms ignoresWindowStatechanges, so KeePass's own minimize after opening the database has no effect either.I confirmed the sequence with temporary logging of the window state and
Form.Visible(Windows 11, KeePass 2.61.1, KeePassRPC 2.0.2, KeePassWinHello for unlocking). The unlock prompt runs synchronously inside the native restore, so the database is already open whenPromptUserToOpenDbfinishes.Proposed fix
At the end of
PromptUserToOpenDb, if the database was closed or locked at the start and is open now, and the user has enabledMinimizeAfterOpeningDatabase, minimize the main window (deferred withBeginInvoke, after the state restore). IfForm.Visibleis out of sync, set it totruefirst so WinForms applies the state change. KeePass's ownOnFormResizethen decides between tray and taskbar as usual.Nothing changes for users without that option. The window is also left alone when the database was already open (showing KeePass stays possible), when the unlock is cancelled, and when minimizing would lock the workspace again (
LockOnWindowMinimize, orLockOnWindowMinimizeToTraytogether withMinimizeToTray). No new setting, no platform-specific code.I have a small patch (one file, ~30 added lines) and can open a pull request if you're interested.