Skip to content

Commit

Permalink
Add a checkbox to disable taskbar flash.
Browse files Browse the repository at this point in the history
Also add ability to set urgent flag for the window on Linux.

Fixes #223, fixes #897, fixes #906.
  • Loading branch information
john-preston committed May 12, 2020
1 parent f4f6550 commit 6f760d5
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 48 deletions.
3 changes: 3 additions & 0 deletions Telegram/Resources/langs/lang.strings
Expand Up @@ -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";
Expand Down
4 changes: 4 additions & 0 deletions Telegram/SourceFiles/facades.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -508,7 +510,9 @@ DefineRefVar(Global, base::Observable<void>, 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);
Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/facades.h
Expand Up @@ -210,7 +210,9 @@ DeclareRefVar(base::Observable<void>, 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);
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/intro/intro_step.cpp
Expand Up @@ -40,6 +40,7 @@ void PrepareSupportMode() {

Global::SetDesktopNotify(false);
Global::SetSoundNotify(false);
Global::SetFlashBounceNotify(false);
Auth().settings().autoDownload() = Full::FullDisabled();
Local::writeUserSettings();
}
Expand Down
27 changes: 22 additions & 5 deletions Telegram/SourceFiles/mainwindow.cpp
Expand Up @@ -757,14 +757,21 @@ 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()) {
Global::SetSoundNotify(true);
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);
Expand All @@ -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);
}
}

Expand Down
Expand Up @@ -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() {
Expand Down
Expand Up @@ -19,9 +19,6 @@ For license and copyright information please follow this link:
namespace Platform {
namespace Notifications {

inline void FlashBounce() {
}

#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
class NotificationData : public QObject {
Q_OBJECT
Expand Down
3 changes: 0 additions & 3 deletions Telegram/SourceFiles/platform/mac/notifications_manager_mac.h
Expand Up @@ -13,9 +13,6 @@ For license and copyright information please follow this link:
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);
Expand Down
Expand Up @@ -143,6 +143,10 @@ bool SkipToast() {
return DoNotDisturbEnabled;
}

bool SkipFlashBounce() {
return SkipAudio();
}

bool Supported() {
return Platform::IsMac10_8OrGreater();
}
Expand All @@ -154,10 +158,6 @@ bool Supported() {
return nullptr;
}

void FlashBounce() {
[NSApp requestUserAttention:NSInformationalRequest];
}

class Manager::Private : public QObject, private base::Subscriber {
public:
Private(Manager *manager);
Expand Down
11 changes: 6 additions & 5 deletions Telegram/SourceFiles/platform/platform_notifications_manager.h
Expand Up @@ -12,12 +12,13 @@ For license and copyright information please follow this link:
namespace Platform {
namespace Notifications {

bool SkipAudio();
bool SkipToast();
[[nodiscard]] bool SkipAudio();
[[nodiscard]] bool SkipToast();
[[nodiscard]] bool SkipFlashBounce();

bool Supported();
std::unique_ptr<Window::Notifications::Manager> Create(Window::Notifications::System *system);
void FlashBounce();
[[nodiscard]] bool Supported();
[[nodiscard]] std::unique_ptr<Window::Notifications::Manager> Create(
Window::Notifications::System *system);

} // namespace Notifications
} // namespace Platform
Expand Down
19 changes: 4 additions & 15 deletions Telegram/SourceFiles/platform/win/notifications_manager_win.cpp
Expand Up @@ -321,21 +321,6 @@ std::unique_ptr<Window::Notifications::Manager> 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;
Expand Down Expand Up @@ -723,5 +708,9 @@ bool SkipToast() {
return false;
}

bool SkipFlashBounce() {
return SkipToast();
}

} // namespace Notifications
} // namespace Platform
17 changes: 17 additions & 0 deletions Telegram/SourceFiles/settings/settings_notifications.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());

Expand Down
12 changes: 8 additions & 4 deletions Telegram/SourceFiles/storage/localstorage.cpp
Expand Up @@ -649,7 +649,7 @@ enum {
dbiSendKeyOld = 0x05,
dbiAutoStart = 0x06,
dbiStartMinimized = 0x07,
dbiSoundNotify = 0x08,
dbiSoundFlashBounceNotify = 0x08,
dbiWorkMode = 0x09,
dbiSeenTrayTooltip = 0x0a,
dbiDesktopNotify = 0x0b,
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -2202,14 +2203,17 @@ 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)
<< qint32(Window::Theme::Background()->tileDay() ? 1 : 0)
<< 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());
Expand Down
11 changes: 10 additions & 1 deletion Telegram/SourceFiles/window/notifications_manager.cpp
Expand Up @@ -27,6 +27,8 @@ For license and copyright information please follow this link:
#include "facades.h"
#include "app.h"

#include <QtGui/QWindow>

namespace Window {
namespace Notifications {
namespace {
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/window/notifications_manager.h
Expand Up @@ -32,6 +32,7 @@ namespace Notifications {

enum class ChangeType {
SoundEnabled,
FlashBounceEnabled,
IncludeMuted,
CountMessages,
DesktopEnabled,
Expand Down

0 comments on commit 6f760d5

Please sign in to comment.