From 71dfea7db08073684d5bd93d843e5903c0a9c529 Mon Sep 17 00:00:00 2001 From: gg Date: Mon, 12 Jan 2026 10:38:30 -0500 Subject: [PATCH] p log minimize event# Please enter the commit message for your changes. Lines starting --- src/MainWindow.cpp | 77 +++++++++++++++++++++++++++++++---- src/MainWindow.h | 4 ++ src/WindowManager.cpp | 10 ++++- src/dialog/TxImportDialog.cpp | 1 + 4 files changed, 84 insertions(+), 8 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index a67be3d4..fbcbc010 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -216,6 +216,7 @@ void MainWindow::initStatusBar() { ui->menuTools->addAction(scanTxAction); connect(pauseSyncAction, &QAction::toggled, this, [this](bool checked) { + qInfo() << "Pause Sync toggled. Checked =" << checked; conf()->set(Config::syncPaused, checked); if (m_wallet) { if (checked) { @@ -864,6 +865,7 @@ void MainWindow::onBalanceUpdated(quint64 balance, quint64 spendable) { } void MainWindow::setPausedSyncStatus() { + qInfo() << "setPausedSyncStatus called. Sync paused:" << conf()->get(Config::syncPaused).toBool(); QString tooltip; QString status = Utils::getPausedSyncStatus(m_wallet, m_nodes, &tooltip); this->setStatusText(status); @@ -981,6 +983,7 @@ void MainWindow::onMultiBroadcast(const QMap &txHexMap) { } void MainWindow::onSyncStatus(quint64 height, quint64 target, bool daemonSync) { + qInfo() << "onSyncStatus: Height" << height << "Target" << target << "DaemonSync" << daemonSync; if (height >= (target - 1) && target > 0) { this->updateNetStats(); this->setStatusText(QString("Synchronized (%1)").arg(QLocale().toString(height))); @@ -1517,20 +1520,79 @@ void MainWindow::closeEvent(QCloseEvent *event) { event->accept(); } +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) { - if ((event->type() == QEvent::WindowStateChange) && this->isMinimized()) { - if (conf()->get(Config::lockOnMinimize).toBool()) { - this->lockWallet(); + QMainWindow::changeEvent(event); + +// In changeEvent: + if (event->type() == QEvent::WindowStateChange) { + qInfo() << "changeEvent: WindowStateChange. State:" << this->windowState() << " isMinimized:" << this->isMinimized(); + if (this->isMinimized()) { + // ... existing logic ... + if (conf()->get(Config::lockOnMinimize).toBool()) { + this->lockWallet(); + } + + bool showTray = conf()->get(Config::showTrayIcon).toBool(); + bool minimizeToTray = conf()->get(Config::minimizeToTray).toBool(); + + qInfo() << "WindowStateChange: minimized. Tray=" << showTray << " MinToTray=" << minimizeToTray; + + if (showTray && minimizeToTray) { + this->hide(); + } } - if (conf()->get(Config::showTrayIcon).toBool() && conf()->get(Config::minimizeToTray).toBool()) { - this->hide(); + } 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(); + + if (showTray && minimizeToTray) { + this->hide(); + } } - } else { - QMainWindow::changeEvent(event); } } +// Add logs to sync methods (need to locate them first, assuming onSyncStatus and setPausedSyncStatus) + void MainWindow::showHistoryTab() { this->raise(); ui->tabWidget->setCurrentIndex(this->findTab("History")); @@ -1826,6 +1888,7 @@ QString MainWindow::statusDots() { } void MainWindow::showOrHide() { + qDebug() << "showOrHide called. isHidden=" << this->isHidden(); if (this->isHidden()) this->bringToFront(); else diff --git a/src/MainWindow.h b/src/MainWindow.h index d465ceba..da45aab2 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -6,6 +6,7 @@ #include #include +#include #include "components.h" #include "SettingsDialog.h" @@ -97,6 +98,7 @@ signals: protected: void changeEvent(QEvent* event) override; + void showEvent(QShowEvent *event) override; private slots: // TODO: use a consistent naming convention for slots @@ -268,6 +270,8 @@ private: EventFilter *m_eventFilter = nullptr; qint64 m_userLastActive = QDateTime::currentSecsSinceEpoch(); + QMetaObject::Connection m_visibilityConnection; + #ifdef CHECK_UPDATES QSharedPointer m_updater = nullptr; #endif diff --git a/src/WindowManager.cpp b/src/WindowManager.cpp index 69d81198..48daf008 100644 --- a/src/WindowManager.cpp +++ b/src/WindowManager.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "Application.h" #include "constants.h" @@ -655,7 +656,14 @@ void WindowManager::buildTrayMenu() { for (const auto &window : m_windows) { QString name = window->walletName(); - QMenu *submenu = menu->addMenu(name); + QString displayName = name; + if (name.length() > 20) { + displayName = name.left(17) + "..."; + } + + QMenu *submenu = menu->addMenu(displayName); + submenu->setToolTip(name); + submenu->menuAction()->setToolTip(name); submenu->addAction("Show/Hide", window, &MainWindow::showOrHide); submenu->addAction("Close", window, &MainWindow::close); } diff --git a/src/dialog/TxImportDialog.cpp b/src/dialog/TxImportDialog.cpp index 1473311f..56b2befc 100644 --- a/src/dialog/TxImportDialog.cpp +++ b/src/dialog/TxImportDialog.cpp @@ -18,6 +18,7 @@ TxImportDialog::TxImportDialog(QWidget *parent, Wallet *wallet) connect(ui->btn_import, &QPushButton::clicked, this, &TxImportDialog::onImport); this->adjustSize(); + this->layout()->setSizeConstraint(QLayout::SetFixedSize); } void TxImportDialog::onImport() { -- 2.52.0