From f9847090f9c7e75d7980590cd7e14f318fd96b04 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 14 Feb 2023 20:47:11 +0400 Subject: [PATCH] Cmd+Q quit prevention in windowed media viewer. --- Telegram/SourceFiles/core/application.cpp | 9 +++++---- .../SourceFiles/platform/linux/specific_linux.h | 4 ++++ .../SourceFiles/platform/mac/main_window_mac.h | 2 -- .../SourceFiles/platform/mac/main_window_mac.mm | 14 -------------- Telegram/SourceFiles/platform/mac/specific_mac.mm | 14 ++++++++++++++ Telegram/SourceFiles/platform/platform_specific.h | 6 ++++++ Telegram/SourceFiles/platform/win/specific_win.h | 4 ++++ Telegram/SourceFiles/window/main_window.h | 4 ---- 8 files changed, 33 insertions(+), 24 deletions(-) diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index a070a5be44..83cbe5045d 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -983,10 +983,11 @@ bool Application::preventsQuit(QuitReason reason) { || uploadPreventsQuit() || downloadPreventsQuit()) { return true; - } else if (const auto window = activeWindow()) { - if (window->widget()->isActive()) { - return window->widget()->preventsQuit(reason); - } + } else if ((!_mediaView + || _mediaView->isHidden() + || !_mediaView->isFullScreen()) + && Platform::PreventsQuit(reason)) { + return true; } return false; } diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.h b/Telegram/SourceFiles/platform/linux/specific_linux.h index 8b58cc8d36..e5e40cd2e1 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.h +++ b/Telegram/SourceFiles/platform/linux/specific_linux.h @@ -24,6 +24,10 @@ inline void WriteCrashDumpDetails() { inline void AutostartRequestStateFromSystem(Fn callback) { } +inline bool PreventsQuit(Core::QuitReason reason) { + return false; +} + inline void ActivateThisProcess() { } diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.h b/Telegram/SourceFiles/platform/mac/main_window_mac.h index 56674dc3a0..81579cf6ea 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.h +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.h @@ -30,8 +30,6 @@ public: void updateWindowIcon() override; - bool preventsQuit(Core::QuitReason reason) override; - class Private; protected: diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 108b094bd6..950fadaa88 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -29,7 +29,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_specific.h" #include "platform/platform_notifications_manager.h" #include "base/platform/base_platform_info.h" -#include "base/platform/mac/base_confirm_quit.h" #include "boxes/peer_list_controllers.h" #include "boxes/about_box.h" #include "lang/lang_keys.h" @@ -261,19 +260,6 @@ void MainWindow::hideAndDeactivate() { hide(); } -bool MainWindow::preventsQuit(Core::QuitReason reason) { - // Thanks Chromium, see - // chromium.org/developers/design-documents/confirm-to-quit-experiment - return (reason == Core::QuitReason::QtQuitEvent) - && Core::App().settings().macWarnBeforeQuit() - && ([[NSApp currentEvent] type] == NSEventTypeKeyDown) - && !Platform::ConfirmQuit::RunModal( - tr::lng_mac_hold_to_quit( - tr::now, - lt_text, - Platform::ConfirmQuit::QuitKeysString())); -} - void MainWindow::unreadCounterChangedHook() { updateDockCounter(); } diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.mm b/Telegram/SourceFiles/platform/mac/specific_mac.mm index 64592db02e..aeb6706b81 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.mm +++ b/Telegram/SourceFiles/platform/mac/specific_mac.mm @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_controller.h" #include "mainwindow.h" #include "history/history_location_manager.h" +#include "base/platform/mac/base_confirm_quit.h" #include "base/platform/mac/base_utilities_mac.h" #include "base/platform/base_platform_info.h" @@ -187,6 +188,19 @@ bool AutostartSkip() { void NewVersionLaunched(int oldVersion) { } +bool PreventsQuit(Core::QuitReason reason) { + // Thanks Chromium, see + // chromium.org/developers/design-documents/confirm-to-quit-experiment + return (reason == Core::QuitReason::QtQuitEvent) + && Core::App().settings().macWarnBeforeQuit() + && ([[NSApp currentEvent] type] == NSEventTypeKeyDown) + && !ConfirmQuit::RunModal( + tr::lng_mac_hold_to_quit( + tr::now, + lt_text, + ConfirmQuit::QuitKeysString())); +} + void ActivateThisProcess() { const auto window = Core::App().activeWindow(); objc_activateProgram(window ? window->widget()->winId() : 0); diff --git a/Telegram/SourceFiles/platform/platform_specific.h b/Telegram/SourceFiles/platform/platform_specific.h index e36f64e38c..7b35e7af35 100644 --- a/Telegram/SourceFiles/platform/platform_specific.h +++ b/Telegram/SourceFiles/platform/platform_specific.h @@ -7,6 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +namespace Core { +enum class QuitReason; +} // namespace Core + namespace Platform { void start(); @@ -43,6 +47,8 @@ bool SkipTaskbarSupported(); void WriteCrashDumpDetails(); void NewVersionLaunched(int oldVersion); +[[nodiscard]] bool PreventsQuit(Core::QuitReason reason); + [[nodiscard]] std::optional IsDarkMode(); [[nodiscard]] inline bool IsDarkModeSupported() { return IsDarkMode().has_value(); diff --git a/Telegram/SourceFiles/platform/win/specific_win.h b/Telegram/SourceFiles/platform/win/specific_win.h index e2a8c1cdf0..db10b458ee 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.h +++ b/Telegram/SourceFiles/platform/win/specific_win.h @@ -27,6 +27,10 @@ inline bool SkipTaskbarSupported() { return true; } +inline bool PreventsQuit(Core::QuitReason reason) { + return false; +} + inline void ActivateThisProcess() { } diff --git a/Telegram/SourceFiles/window/main_window.h b/Telegram/SourceFiles/window/main_window.h index 11686b5b66..0fcd9cf80f 100644 --- a/Telegram/SourceFiles/window/main_window.h +++ b/Telegram/SourceFiles/window/main_window.h @@ -134,10 +134,6 @@ public: updateGlobalMenuHook(); } - [[nodiscard]] virtual bool preventsQuit(Core::QuitReason reason) { - return false; - } - protected: void leaveEventHook(QEvent *e) override;