From 93009618b6d72b6bb253cabc4a5813d7aea18a67 Mon Sep 17 00:00:00 2001
From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
Date: Fri, 19 Oct 2018 10:39:25 +0300
Subject: [PATCH] Fix start with the `-min` option

When GUI starts with the `-min` option, the `Minimize to tray instead of
the taskbar` option works as expected now.
---
 src/qt/bitcoin.cpp  | 13 ++++++-------
 src/qt/bitcoingui.h |  5 +++++
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index a014ad4b2..4a1576e88 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -487,14 +487,13 @@ void BitcoinApplication::initializeResult(bool success)
         }
 #endif
 
-        // If -min option passed, start window minimized.
-        if(gArgs.GetBoolArg("-min", false))
-        {
-            window->showMinimized();
-        }
-        else
-        {
+        // If -min option passed, start window minimized (iconified) or minimized to tray
+        if (!gArgs.GetBoolArg("-min", false)) {
             window->show();
+        } else if (clientModel->getOptionsModel()->getMinimizeToTray() && window->hasTrayIcon()) {
+            // do nothing as the window is managed by the tray icon
+        } else {
+            window->showMinimized();
         }
         Q_EMIT splashFinished(window);
 
diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h
index dcaca1055..d38ae404d 100644
--- a/src/qt/bitcoingui.h
+++ b/src/qt/bitcoingui.h
@@ -82,6 +82,11 @@ public:
 #endif // ENABLE_WALLET
     bool enableWallet = false;
 
+    /** Get the tray icon status.
+        Some systems have not "system tray" or "notification area" available.
+    */
+    bool hasTrayIcon() const { return trayIcon; }
+
 protected:
     void changeEvent(QEvent *e);
     void closeEvent(QCloseEvent *event);