@@ -1480,33 +1480,37 @@ void MainWindow::wheelEvent( QWheelEvent * ev )
14801480
14811481void MainWindow::closeEvent ( QCloseEvent * ev )
14821482{
1483- if ( cfg.preferences .enableTrayIcon && cfg.preferences .closeToTray ) {
1484- if ( !cfg.preferences .searchInDock ) {
1485- translateBox->setPopupEnabled ( false );
1486- }
1483+ // If tray icon is disabled or closing to tray is not enabled, quit the application
1484+ if ( !cfg.preferences .enableTrayIcon || !cfg.preferences .closeToTray ) {
1485+ ev->accept ();
1486+ quitApp ();
1487+ return ;
1488+ }
1489+
1490+ // Hide translation popup if necessary
1491+ if ( !cfg.preferences .searchInDock ) {
1492+ translateBox->setPopupEnabled ( false );
1493+ }
14871494
14881495#ifdef Q_OS_MACOS
1489- if ( !ev->spontaneous () || !isVisible () ) {
1490- return ;
1491- }
1496+ // On macOS, ignore non-spontaneous events or already hidden windows to avoid redundant logic
1497+ if ( !ev->spontaneous () || !isVisible () ) {
1498+ return ;
1499+ }
14921500#endif
1501+
1502+ // Handle window hiding based on platform characteristics
14931503#if defined( Q_OS_UNIX ) && !defined( Q_OS_MACOS )
1494- // Don't ignore the close event, because doing so cancels session logout if
1495- // the main window is visible when the user attempts to log out.
1496- // The main window will be only hidden, because QApplication::quitOnLastWindowClosed
1497- // property is false and Qt::WA_DeleteOnClose widget is not set.
1498- Q_ASSERT ( !QApplication::quitOnLastWindowClosed () );
1499- Q_ASSERT ( !testAttribute ( Qt::WA_DeleteOnClose ) );
1504+ // On Linux/Unix, do not call ignore() as it blocks session logout.
1505+ // The window is hidden instead of closed because quitOnLastWindowClosed is false.
1506+ Q_ASSERT ( !QApplication::quitOnLastWindowClosed () );
1507+ Q_ASSERT ( !testAttribute ( Qt::WA_DeleteOnClose ) );
15001508#else
1501- // Ignore the close event because closing the main window breaks global hotkeys on Windows.
1502- ev->ignore ();
1503- hide ();
1509+ // On Windows and macOS (manual close), ignore the event and hide the window.
1510+ // This ensures global hotkey hooks remain valid on Windows.
1511+ ev->ignore ();
1512+ hide ();
15041513#endif
1505- }
1506- else {
1507- ev->accept ();
1508- quitApp ();
1509- }
15101514}
15111515
15121516void MainWindow::quitApp ()
0 commit comments