From: gg Date: Mon, 12 Jan 2026 15:52:44 +0000 (-0500) Subject: Fix minimize to tray. Add setting: toggle focus on tray left-click. X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=65c45af6be791fda8edc3978a06eacb50794d3ba;p=gamesguru%2Ffeather.git Fix minimize to tray. Add setting: toggle focus on tray left-click. --- diff --git a/setup_flags.sh b/setup_flags.sh deleted file mode 100644 index 9112cf76..00000000 --- a/setup_flags.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# Configure CMake with custom flags -# - FEATHER_VERSION_DEBUG_BUILD=ON : Use git describe for version string -# - CHECK_UPDATES=OFF : Disable built-in update checker -# - USE_DEVICE_TREZOR=OFF : Disable Trezor hardware wallet support -# - WITH_SCANNER=OFF : Disable webcam QR scanner support - -cmake \ - -DCMAKE_BUILD_TYPE=Debug \ - -DFEATHER_VERSION_DEBUG_BUILD=ON \ - -DCHECK_UPDATES=OFF \ - -DUSE_DEVICE_TREZOR=OFF \ - -DWITH_SCANNER=OFF \ - .. diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index fbcbc010..e0645c4a 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1523,31 +1523,6 @@ void MainWindow::closeEvent(QCloseEvent *event) { void MainWindow::showEvent(QShowEvent *event) { QMainWindow::showEvent(event); - qDebug() << "MainWindow::showEvent. WindowHandle:" << this->windowHandle(); - if (auto *window = this->windowHandle()) { - if (!m_visibilityConnection) { - m_visibilityConnection = connect(window, &QWindow::visibilityChanged, this, [this](QWindow::Visibility visibility){ - qDebug() << "Visibility changed:" << visibility << " WindowState:" << this->windowHandle()->windowState(); - if (visibility == QWindow::Minimized || this->windowHandle()->windowState() & Qt::WindowMinimized) { - if (conf()->get(Config::lockOnMinimize).toBool()) { - this->lockWallet(); - } - - bool showTray = conf()->get(Config::showTrayIcon).toBool(); - bool minimizeToTray = conf()->get(Config::minimizeToTray).toBool(); - - qInfo() << "Visibility: Minimized. Tray=" << showTray << " MinToTray=" << minimizeToTray; - - if (showTray && minimizeToTray) { - this->hide(); - } - } - }); - qDebug() << "Connected to visibilityChanged signal:" << (bool)m_visibilityConnection; - } - } else { - qDebug() << "MainWindow::showEvent: No window handle available!"; - } } void MainWindow::changeEvent(QEvent* event) @@ -1573,21 +1548,22 @@ void MainWindow::changeEvent(QEvent* event) } } } else if (event->type() == QEvent::ActivationChange) { - auto winHandleState = this->windowHandle() ? this->windowHandle()->windowState() : Qt::WindowNoState; - qInfo() << "changeEvent: ActivationChange. State:" << this->windowState() << " isActive:" << this->isActiveWindow() << " WinHandleState:" << winHandleState; - if (this->windowHandle() && (this->windowHandle()->windowState() & Qt::WindowMinimized || this->isMinimized())) { - qInfo() << "changeEvent: ActivationChange -> detected Minimized state"; - if (conf()->get(Config::lockOnMinimize).toBool()) { - this->lockWallet(); - } - - bool showTray = conf()->get(Config::showTrayIcon).toBool(); - bool minimizeToTray = conf()->get(Config::minimizeToTray).toBool(); + qInfo() << "changeEvent: ActivationChange. Active:" << this->isActiveWindow(); + QTimer::singleShot(500, this, [this](){ + auto handle = this->windowHandle(); + if (handle && !handle->isExposed()) { + qInfo() << "ActivationChange (delayed): Window not exposed -> Hiding to tray"; + if (conf()->get(Config::lockOnMinimize).toBool()) { + this->lockWallet(); + } - if (showTray && minimizeToTray) { - this->hide(); + bool showTray = conf()->get(Config::showTrayIcon).toBool(); + bool minimizeToTray = conf()->get(Config::minimizeToTray).toBool(); + if (showTray && minimizeToTray) { + this->hide(); + } } - } + }); } } diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index 982fef24..9dabad09 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -314,6 +314,7 @@ void Settings::setupDisplayTab() { connect(ui->checkBox_showTrayIcon, &QCheckBox::toggled, [this](bool toggled) { conf()->set(Config::showTrayIcon, toggled); ui->checkBox_minimizeToTray->setEnabled(toggled); + ui->checkBox_trayLeftClickToggles->setEnabled(toggled); emit showTrayIcon(toggled); }); @@ -323,6 +324,13 @@ void Settings::setupDisplayTab() { connect(ui->checkBox_minimizeToTray, &QCheckBox::toggled, [this](bool toggled) { conf()->set(Config::minimizeToTray, toggled); }); + + // [Left click system tray icon to toggle focus] + ui->checkBox_trayLeftClickToggles->setEnabled(ui->checkBox_showTrayIcon->isChecked()); + ui->checkBox_trayLeftClickToggles->setChecked(conf()->get(Config::trayLeftClickToggles).toBool()); + connect(ui->checkBox_trayLeftClickToggles, &QCheckBox::toggled, [this](bool toggled) { + conf()->set(Config::trayLeftClickToggles, toggled); + }); } void Settings::setupMemoryTab() { diff --git a/src/SettingsDialog.ui b/src/SettingsDialog.ui index ccaad425..f4f01107 100644 --- a/src/SettingsDialog.ui +++ b/src/SettingsDialog.ui @@ -838,6 +838,36 @@ + + + + + + Qt::Orientation::Horizontal + + + QSizePolicy::Policy::Fixed + + + + 30 + 20 + + + + + + + + false + + + Left click system tray icon to toggle focus + + + + + diff --git a/src/WindowManager.cpp b/src/WindowManager.cpp index 48daf008..d3f72c48 100644 --- a/src/WindowManager.cpp +++ b/src/WindowManager.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include "Application.h" #include "constants.h" @@ -48,6 +47,24 @@ WindowManager::WindowManager(QObject *parent) this->buildTrayMenu(); m_tray->setVisible(conf()->get(Config::showTrayIcon).toBool()); + connect(m_tray, &QSystemTrayIcon::activated, [this](QSystemTrayIcon::ActivationReason reason) { + if (reason == QSystemTrayIcon::Trigger) { + if (conf()->get(Config::trayLeftClickToggles).toBool()) { + for (const auto &window : m_windows) { + if (window->isVisible()) { + window->hide(); + } else { + window->show(); + window->raise(); + window->activateWindow(); + } + } + } else { + m_tray->contextMenu()->popup(QCursor::pos()); + } + } + }); + this->initSkins(); this->patchMacStylesheet(); @@ -95,6 +112,12 @@ void WindowManager::quitAfterLastWindow() { void WindowManager::close() { qDebug() << Q_FUNC_INFO << QThread::currentThreadId(); + if (m_closing) { + return; + } + m_closing = true; + + // Stop all threads before application shutdown to avoid QThreadStorage warnings if (m_cleanupThread && m_cleanupThread->isRunning()) { m_cleanupThread->quit(); @@ -102,6 +125,13 @@ void WindowManager::close() { qDebug() << "WindowManager: cleanup thread stopped in close()"; } + // Close all windows first to ensure they cancel their tasks/connections + // Iterate over a copy because close() modifies m_windows + auto windows = m_windows; + for (const auto &window: windows) { + window->close(); + } + // Stop Tor manager threads torManager()->stop(); @@ -112,10 +142,6 @@ void WindowManager::close() { std::_Exit(1); // Fast exit without cleanup - threads may still hold resources } - for (const auto &window: m_windows) { - window->close(); - } - if (m_splashDialog) { m_splashDialog->deleteLater(); } @@ -656,14 +682,7 @@ void WindowManager::buildTrayMenu() { for (const auto &window : m_windows) { QString name = window->walletName(); - QString displayName = name; - if (name.length() > 20) { - displayName = name.left(17) + "..."; - } - - QMenu *submenu = menu->addMenu(displayName); - submenu->setToolTip(name); - submenu->menuAction()->setToolTip(name); + QMenu *submenu = menu->addMenu(name); submenu->addAction("Show/Hide", window, &MainWindow::showOrHide); submenu->addAction("Close", window, &MainWindow::close); } diff --git a/src/WindowManager.h b/src/WindowManager.h index d0f3e460..54690e2e 100644 --- a/src/WindowManager.h +++ b/src/WindowManager.h @@ -113,6 +113,7 @@ private: bool m_openWalletTriedOnce = false; bool m_openingWallet = false; bool m_initialNetworkConfigured = false; + bool m_closing = false; QThread *m_cleanupThread; }; diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index df7179cb..cfde59f5 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -561,15 +561,6 @@ quint64 Wallet::daemonBlockChainTargetHeight() const { return m_daemonBlockChainTargetHeight; } -void Wallet::syncStatusUpdated(quint64 height, quint64 target) { - if (height >= (target - 1)) { - // TODO: is this needed? - this->updateBalance(); - } - - emit syncStatus(height, target, false); -} - void Wallet::setSyncPaused(bool paused) { m_syncPaused = paused; if (paused) { diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 4341efe2..d09604e4 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -458,7 +458,6 @@ signals: void connectionStatusChanged(int status) const; void currentSubaddressAccountChanged() const; - void syncStatus(quint64 height, quint64 target, bool daemonSync = false); void balanceUpdated(quint64 balance, quint64 spendable); diff --git a/src/utils/config.cpp b/src/utils/config.cpp index f9453d5c..9da3d876 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -75,6 +75,7 @@ static const QHash configStrings = { {Config::lockOnMinimize, {QS("lockOnMinimize"), false}}, {Config::showTrayIcon, {QS("showTrayIcon"), true}}, {Config::minimizeToTray, {QS("minimizeToTray"), false}}, + {Config::trayLeftClickToggles, {QS("trayLeftClickToggles"), false}}, {Config::disableWebsocket, {QS("disableWebsocket"), false}}, {Config::disableAutoRefresh, {QS("disableAutoRefresh"), false}}, {Config::offlineMode, {QS("offlineMode"), false}}, diff --git a/src/utils/config.h b/src/utils/config.h index ffe9a6e6..085c1331 100644 --- a/src/utils/config.h +++ b/src/utils/config.h @@ -109,6 +109,7 @@ public: lockOnMinimize, showTrayIcon, minimizeToTray, + trayLeftClickToggles, // Transactions multiBroadcast,