diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 00a3d2bbb..4722c2f7d 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -300,6 +300,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_notifications_position" = "Location on the screen"; "lng_settings_notifications_count" = "Notifications count"; "lng_settings_sound_notify" = "Play sound"; +"lng_settings_alert_windows" = "Flash the taskbar icon"; +"lng_settings_alert_mac" = "Bounce the dock icon"; +"lng_settings_alert_linux" = "Draw attention to the window"; "lng_settings_badge_title" = "Badge counter"; "lng_settings_include_muted" = "Include muted chats in unread count"; "lng_settings_count_unread" = "Count unread messages"; diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 685766d11..ec52368c4 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -381,7 +381,9 @@ struct Data { bool VoiceMsgPlaybackDoubled = false; bool SoundNotify = true; bool DesktopNotify = true; + bool FlashBounceNotify = true; bool RestoreSoundNotifyFromTray = false; + bool RestoreFlashBounceNotifyFromTray = false; DBINotifyView NotifyView = dbinvShowPreview; bool NativeNotifications = false; int NotificationsCount = 3; @@ -508,7 +510,9 @@ DefineRefVar(Global, base::Observable, DownloadPathChanged); DefineVar(Global, bool, VoiceMsgPlaybackDoubled); DefineVar(Global, bool, SoundNotify); DefineVar(Global, bool, DesktopNotify); +DefineVar(Global, bool, FlashBounceNotify); DefineVar(Global, bool, RestoreSoundNotifyFromTray); +DefineVar(Global, bool, RestoreFlashBounceNotifyFromTray); DefineVar(Global, DBINotifyView, NotifyView); DefineVar(Global, bool, NativeNotifications); DefineVar(Global, int, NotificationsCount); diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index fd598df9f..2a18db821 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -210,7 +210,9 @@ DeclareRefVar(base::Observable, DownloadPathChanged); DeclareVar(bool, VoiceMsgPlaybackDoubled); DeclareVar(bool, SoundNotify); DeclareVar(bool, DesktopNotify); +DeclareVar(bool, FlashBounceNotify); DeclareVar(bool, RestoreSoundNotifyFromTray); +DeclareVar(bool, RestoreFlashBounceNotifyFromTray); DeclareVar(DBINotifyView, NotifyView); DeclareVar(bool, NativeNotifications); DeclareVar(int, NotificationsCount); diff --git a/Telegram/SourceFiles/intro/intro_step.cpp b/Telegram/SourceFiles/intro/intro_step.cpp index a749e6395..b47b1cfdb 100644 --- a/Telegram/SourceFiles/intro/intro_step.cpp +++ b/Telegram/SourceFiles/intro/intro_step.cpp @@ -40,6 +40,7 @@ void PrepareSupportMode() { Global::SetDesktopNotify(false); Global::SetSoundNotify(false); + Global::SetFlashBounceNotify(false); Auth().settings().autoDownload() = Full::FullDisabled(); Local::writeUserSettings(); } diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index f5192d683..5e6c68731 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -757,7 +757,8 @@ void MainWindow::toggleDisplayNotifyFromTray() { return; } - bool soundNotifyChanged = false; + auto soundNotifyChanged = false; + auto flashBounceNotifyChanged = false; Global::SetDesktopNotify(!Global::DesktopNotify()); if (Global::DesktopNotify()) { if (Global::RestoreSoundNotifyFromTray() && !Global::SoundNotify()) { @@ -765,6 +766,12 @@ void MainWindow::toggleDisplayNotifyFromTray() { Global::SetRestoreSoundNotifyFromTray(false); soundNotifyChanged = true; } + if (Global::RestoreFlashBounceNotifyFromTray() + && !Global::FlashBounceNotify()) { + Global::SetFlashBounceNotify(true); + Global::SetRestoreFlashBounceNotifyFromTray(false); + flashBounceNotifyChanged = true; + } } else { if (Global::SoundNotify()) { Global::SetSoundNotify(false); @@ -773,13 +780,23 @@ void MainWindow::toggleDisplayNotifyFromTray() { } else { Global::SetRestoreSoundNotifyFromTray(false); } + if (Global::FlashBounceNotify()) { + Global::SetFlashBounceNotify(false); + Global::SetRestoreFlashBounceNotifyFromTray(true); + flashBounceNotifyChanged = true; + } else { + Global::SetRestoreFlashBounceNotifyFromTray(false); + } } Local::writeUserSettings(); - account().session().notifications().settingsChanged().notify( - Window::Notifications::ChangeType::DesktopEnabled); + using Change = Window::Notifications::ChangeType; + auto &changes = account().session().notifications().settingsChanged(); + changes.notify(Change::DesktopEnabled); if (soundNotifyChanged) { - account().session().notifications().settingsChanged().notify( - Window::Notifications::ChangeType::SoundEnabled); + changes.notify(Change::SoundEnabled); + } + if (flashBounceNotifyChanged) { + changes.notify(Change::FlashBounceEnabled); } } diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index 52635d210..6db3a13c9 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -457,15 +457,11 @@ bool SkipAudio() { } bool SkipToast() { -#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION - if (Supported() - && GetCapabilities().contains(qsl("inhibitions")) - && !InhibitedNotSupported) { - return Inhibited(); - } -#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION + return SkipAudio(); +} - return false; +bool SkipFlashBounce() { + return SkipAudio(); } bool Supported() { diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h index ba6bcc88f..1005c0403 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h @@ -19,9 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Platform { namespace Notifications { -inline void FlashBounce() { -} - #ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION class NotificationData : public QObject { Q_OBJECT diff --git a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h index 19a279102..59a741d0c 100644 --- a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h +++ b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h @@ -13,9 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Platform { namespace Notifications { -bool SkipAudio(); -bool SkipToast(); - class Manager : public Window::Notifications::NativeManager, public base::has_weak_ptr { public: Manager(Window::Notifications::System *system); diff --git a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm index 3459086fe..6f327d121 100644 --- a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm +++ b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm @@ -143,6 +143,10 @@ bool SkipToast() { return DoNotDisturbEnabled; } +bool SkipFlashBounce() { + return SkipAudio(); +} + bool Supported() { return Platform::IsMac10_8OrGreater(); } @@ -154,10 +158,6 @@ std::unique_ptr Create(Window::Notifications::Sy return nullptr; } -void FlashBounce() { - [NSApp requestUserAttention:NSInformationalRequest]; -} - class Manager::Private : public QObject, private base::Subscriber { public: Private(Manager *manager); diff --git a/Telegram/SourceFiles/platform/platform_notifications_manager.h b/Telegram/SourceFiles/platform/platform_notifications_manager.h index 692f4b4e1..f0cdb152e 100644 --- a/Telegram/SourceFiles/platform/platform_notifications_manager.h +++ b/Telegram/SourceFiles/platform/platform_notifications_manager.h @@ -12,12 +12,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Platform { namespace Notifications { -bool SkipAudio(); -bool SkipToast(); +[[nodiscard]] bool SkipAudio(); +[[nodiscard]] bool SkipToast(); +[[nodiscard]] bool SkipFlashBounce(); -bool Supported(); -std::unique_ptr Create(Window::Notifications::System *system); -void FlashBounce(); +[[nodiscard]] bool Supported(); +[[nodiscard]] std::unique_ptr Create( + Window::Notifications::System *system); } // namespace Notifications } // namespace Platform diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp index 1d0e01d61..506f4b6fc 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp @@ -321,21 +321,6 @@ std::unique_ptr Create(Window::Notifications::Sy return nullptr; } -void FlashBounce() { - auto window = App::wnd(); - if (!window || GetForegroundWindow() == window->psHwnd()) { - return; - } - - FLASHWINFO info; - info.cbSize = sizeof(info); - info.hwnd = window->psHwnd(); - info.dwFlags = FLASHW_ALL; - info.dwTimeout = 0; - info.uCount = 1; - FlashWindowEx(&info); -} - class Manager::Private { public: using Type = Window::Notifications::CachedUserpics::Type; @@ -723,5 +708,9 @@ bool SkipToast() { return false; } +bool SkipFlashBounce() { + return SkipToast(); +} + } // namespace Notifications } // namespace Platform diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index 9ec30eb9c..e4e456e27 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -568,6 +568,13 @@ void SetupNotificationsContent( const auto sound = addCheckbox( tr::lng_settings_sound_notify(tr::now), Global::SoundNotify()); + const auto flashbounce = addCheckbox( + (Platform::IsWindows() + ? tr::lng_settings_alert_windows + : Platform::IsMac() + ? tr::lng_settings_alert_mac + : tr::lng_settings_alert_linux)(tr::now), + Global::FlashBounceNotify()); AddSkip(container, st::settingsCheckboxesSkip); AddDivider(container); @@ -714,6 +721,14 @@ void SetupNotificationsContent( changed(Change::SoundEnabled); }, sound->lifetime()); + flashbounce->checkedChanges( + ) | rpl::filter([](bool checked) { + return (checked != Global::FlashBounceNotify()); + }) | rpl::start_with_next([=](bool checked) { + Global::SetFlashBounceNotify(checked); + changed(Change::FlashBounceEnabled); + }, flashbounce->lifetime()); + muted->checkedChanges( ) | rpl::filter([=](bool checked) { return (checked != session->settings().includeMutedCounter()); @@ -743,6 +758,8 @@ void SetupNotificationsContent( preview->toggle(name->entity()->checked(), anim::type::normal); } else if (change == Change::SoundEnabled) { sound->setChecked(Global::SoundNotify()); + } else if (change == Change::FlashBounceEnabled) { + flashbounce->setChecked(Global::FlashBounceNotify()); } }, desktop->lifetime()); diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 7a9163ab8..ddc1e1a58 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -649,7 +649,7 @@ enum { dbiSendKeyOld = 0x05, dbiAutoStart = 0x06, dbiStartMinimized = 0x07, - dbiSoundNotify = 0x08, + dbiSoundFlashBounceNotify = 0x08, dbiWorkMode = 0x09, dbiSeenTrayTooltip = 0x0a, dbiDesktopNotify = 0x0b, @@ -1189,12 +1189,13 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting anim::SetDisabled(disabled == 1); } break; - case dbiSoundNotify: { + case dbiSoundFlashBounceNotify: { qint32 v; stream >> v; if (!_checkStreamStatus(stream)) return false; - Global::SetSoundNotify(v == 1); + Global::SetSoundNotify((v & 0x01) == 0x01); + Global::SetFlashBounceNotify((v & 0x02) == 0x00); } break; case dbiAutoDownloadOld: { @@ -2202,6 +2203,9 @@ void _writeUserSettings() { } size += sizeof(quint32) + Serialize::bytearraySize(callSettings); + const auto soundFlashBounce = (Global::SoundNotify() ? 0x01 : 0x00) + | (Global::FlashBounceNotify() ? 0x00 : 0x02); + EncryptedDescriptor data(size); data.stream << quint32(dbiTileBackground) @@ -2209,7 +2213,7 @@ void _writeUserSettings() { << qint32(Window::Theme::Background()->tileNight() ? 1 : 0); data.stream << quint32(dbiAdaptiveForWide) << qint32(Global::AdaptiveForWide() ? 1 : 0); data.stream << quint32(dbiAutoLock) << qint32(Global::AutoLock()); - data.stream << quint32(dbiSoundNotify) << qint32(Global::SoundNotify()); + data.stream << quint32(dbiSoundFlashBounceNotify) << qint32(soundFlashBounce); data.stream << quint32(dbiDesktopNotify) << qint32(Global::DesktopNotify()); data.stream << quint32(dbiNotifyView) << qint32(Global::NotifyView()); data.stream << quint32(dbiNativeNotifications) << qint32(Global::NativeNotifications()); diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index c3131598d..2d297637b 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -27,6 +27,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "facades.h" #include "app.h" +#include + namespace Window { namespace Notifications { namespace { @@ -290,7 +292,14 @@ void System::showNext() { } } if (alert) { - Platform::Notifications::FlashBounce(); + if (Global::FlashBounceNotify() && !Platform::Notifications::SkipFlashBounce()) { + if (const auto widget = App::wnd()) { + if (const auto window = widget->windowHandle()) { + window->alert(0); + // (window, SLOT(_q_clearAlert())); in the future. + } + } + } if (Global::SoundNotify() && !Platform::Notifications::SkipAudio()) { ensureSoundCreated(); _soundTrack->playOnce(); diff --git a/Telegram/SourceFiles/window/notifications_manager.h b/Telegram/SourceFiles/window/notifications_manager.h index 2b634d12f..b9c6ecceb 100644 --- a/Telegram/SourceFiles/window/notifications_manager.h +++ b/Telegram/SourceFiles/window/notifications_manager.h @@ -32,6 +32,7 @@ namespace Notifications { enum class ChangeType { SoundEnabled, + FlashBounceEnabled, IncludeMuted, CountMessages, DesktopEnabled,