Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: globally suppress highlight notifications #5629

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unversioned

- Minor: Add muting of all application notifications via keybind/window menu. (#5629)

## 2.5.2-beta.1

- Major: Add option to show pronouns in user card. (#5442, #5583)
Expand Down
13 changes: 13 additions & 0 deletions src/controllers/hotkeys/ActionNames.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,19 @@ inline const std::map<HotkeyCategory, ActionDefinitionMap> actionNames{
.argumentsPromptHover = "Should the tabs be enabled, disabled, "
"toggled, or live-only.",
}},
{"toggleGlobalNotificationSuppression",
ActionDefinition{
.displayName = "Toggle muting of all notifications",
.argumentDescription = "[on, off, or toggle. default: toggle]",
.minCountArguments = 0,
.maxCountArguments = 1,
.possibleArguments{{"Toggle", {}},
{"Mute notifications", {"on"}},
{"Unmute notifications", {"off"}}},
.argumentsPrompt = "New value:",
.argumentsPromptHover = "Should all highlight notifications be "
"enabled, disabled, or toggled.",
}},
}},
};

Expand Down
6 changes: 6 additions & 0 deletions src/messages/MessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ void actuallyTriggerHighlights(const QString &channelName, bool playSound,
return;
}

if (getSettings()->globallySuppressNotifications)
{
// Notifications are globally suppressed, ignore it.
return;
}

const bool hasFocus = (QApplication::focusWidget() != nullptr);
const bool resolveFocus =
!hasFocus || getSettings()->highlightAlwaysPlaySound;
Expand Down
3 changes: 3 additions & 0 deletions src/singletons/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ class Settings
BoolSetting suppressInitialLiveNotification = {
"/notifications/suppressInitialLive", false};

BoolSetting globallySuppressNotifications = {
"/notifications/globalSuppression", false};

BoolSetting notificationToast = {"/notifications/enableToast", false};
IntSetting openFromToast = {"/notifications/openFromToast",
static_cast<int>(ToastReaction::OpenInBrowser)};
Expand Down
60 changes: 59 additions & 1 deletion src/widgets/Notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ Notebook::Notebook(QWidget *parent)
<< "Notebook must be created within a BaseWindow";
}

this->toggleNotificationSuppression_ =
new QAction("Mute all notifications", this);
this->toggleNotificationSuppression_->setCheckable(true);
this->toggleNotificationSuppression_->setChecked(
getSettings()->globallySuppressNotifications);
this->toggleNotificationSuppression_->setShortcut(
getApp()->getHotkeys()->getDisplaySequence(
HotkeyCategory::Window, "toggleGlobalNotificationSuppression"));

QObject::connect(this->toggleNotificationSuppression_, &QAction::triggered,
[] {
getSettings()->globallySuppressNotifications =
!getSettings()->globallySuppressNotifications;
});
getSettings()->globallySuppressNotifications.connect(
[this](const bool &value) {
this->toggleNotificationSuppression_->setChecked(value);
},
this->signalHolder_);

// Manually resize the add button so the initial paint uses the correct
// width when computing the maximum width occupied per column in vertical
// tab rendering.
Expand Down Expand Up @@ -1241,8 +1261,8 @@ void Notebook::setLockNotebookLayout(bool value)
void Notebook::addNotebookActionsToMenu(QMenu *menu)
{
menu->addAction(this->lockNotebookLayoutAction_);

menu->addAction(this->toggleTopMostAction_);
menu->addAction(this->toggleNotificationSuppression_);
}

NotebookButton *Notebook::getAddButton()
Expand Down Expand Up @@ -1558,6 +1578,19 @@ void SplitNotebook::addCustomButtons()
});
QObject::connect(getApp()->getStreamerMode(), &IStreamerMode::changed, this,
&SplitNotebook::updateStreamerModeIcon);

// do not disturb
this->doNotDisturbIcon_ = this->addCustomButton();
QObject::connect(this->doNotDisturbIcon_, &NotebookButton::leftClicked,
[this] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: lambda capture 'this' is not used [clang-diagnostic-unused-lambda-capture]

Suggested change
[this] {
[] {

getSettings()->globallySuppressNotifications = false;
});
getSettings()->globallySuppressNotifications.connect(
[this] {
this->updateDoNotDisturbIcon();
},
this->signalHolder_);

this->updateStreamerModeIcon();
}

Expand All @@ -1584,6 +1617,31 @@ void SplitNotebook::updateStreamerModeIcon()
getApp()->getStreamerMode()->isEnabled());
}

void SplitNotebook::updateDoNotDisturbIcon()
{
// TODO(jupjohn): add custom icon for this
if (this->doNotDisturbIcon_ == nullptr)
{
return;
}

// A duplicate of this code is in Window class
// That copy handles the TitleBar icon in Window (main window on Windows)
// This one is the one near splits (on linux and mac or non-main windows on Windows)
if (getTheme()->isLightTheme())
{
this->doNotDisturbIcon_->setPixmap(
getResources().buttons.streamerModeEnabledLight);
}
else
{
this->doNotDisturbIcon_->setPixmap(
getResources().buttons.streamerModeEnabledDark);
}
this->doNotDisturbIcon_->setVisible(
getSettings()->globallySuppressNotifications);
}

void SplitNotebook::themeChangedEvent()
{
this->updateStreamerModeIcon();
Expand Down
4 changes: 4 additions & 0 deletions src/widgets/Notebook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class Notebook : public BaseWidget

QAction *lockNotebookLayoutAction_;
QAction *toggleTopMostAction_;
QAction *toggleNotificationSuppression_;

// This filter, if set, is used to figure out the visibility of
// the tabs in this notebook.
Expand Down Expand Up @@ -252,6 +253,9 @@ class SplitNotebook : public Notebook
// Main window on Windows has basically a duplicate of this in Window
NotebookButton *streamerModeIcon_{};
void updateStreamerModeIcon();

NotebookButton *doNotDisturbIcon_{};
void updateDoNotDisturbIcon();
};

} // namespace chatterino
76 changes: 75 additions & 1 deletion src/widgets/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ void Window::addCustomTitlebarButtons()
QObject::connect(getApp()->getStreamerMode(), &IStreamerMode::changed, this,
&Window::updateStreamerModeIcon);

// do not disturb
this->doNotDisturbTitlebarIcon_ =
this->addTitleBarButton(TitleBarButtonStyle::DoNotDisturb, [this] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: lambda capture 'this' is not used [clang-diagnostic-unused-lambda-capture]

Suggested change
this->addTitleBarButton(TitleBarButtonStyle::DoNotDisturb, [this] {
this->addTitleBarButton(TitleBarButtonStyle::DoNotDisturb, [] {

getSettings()->globallySuppressNotifications = false;
});
getSettings()->globallySuppressNotifications.connect(
[this] {
this->updateDoNotDisturbIcon();
},
this->signalHolder_);

// Update initial state
this->updateStreamerModeIcon();
}
Expand Down Expand Up @@ -256,6 +267,38 @@ void Window::updateStreamerModeIcon()
#endif
}

void Window::updateDoNotDisturbIcon()
{
// TODO(jupjohn): add custom icon for this

// A duplicate of this code is in SplitNotebook class (in Notebook.{c,h}pp)
// That one is the one near splits (on linux and mac or non-main windows on Windows)
// This copy handles the TitleBar icon in Window (main window on Windows)
if (this->doNotDisturbTitlebarIcon_ == nullptr)
{
return;
}
#ifdef Q_OS_WIN
assert(this->getType() == WindowType::Main);
if (getTheme()->isLightTheme())
{
this->doNotDisturbIcon_->setPixmap(
getResources().buttons.streamerModeEnabledLight);
}
else
{
this->doNotDisturbIcon_->setPixmap(
getResources().buttons.streamerModeEnabledDark);
}
this->doNotDisturbIcon_->setVisible(
getSettings()->globallySuppressNotifications);
#else
// clang-format off
assert(false && "Streamer mode TitleBar icon should not exist on non-Windows OSes");
// clang-format on
#endif
}

void Window::themeChangedEvent()
{
this->updateStreamerModeIcon();
Expand Down Expand Up @@ -682,7 +725,38 @@ void Window::addShortcuts()

return "";
}},
};
{"toggleGlobalNotificationSuppression",
[](const std::vector<QString> &arguments) -> QString {
QString arg = arguments.empty() ? "toggle" : arguments.front();

bool desiredValue = false;
if (arg == "toggle")
{
desiredValue = !getSettings()->globallySuppressNotifications;
}
else if (arg == "on")
{
desiredValue = true;
}
else if (arg == "off")
{
desiredValue = false;
}
else
{
qCWarning(chatterinoHotkeys)
<< "Invalid argument for "
"toggleGlobalNotificationSuppression hotkey: "
<< arg;
return QString("Invalid argument for "
"toggleGlobalNotificationSuppression hotkey: "
"%1. Use \"on\", \"off\", or \"toggle\".")
.arg(arg);
}

getSettings()->globallySuppressNotifications = desiredValue;
return "";
}}};

this->addDebugStuff(actions);

Expand Down
3 changes: 3 additions & 0 deletions src/widgets/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class Window : public BaseWindow
TitleBarButton *streamerModeTitlebarIcon_ = nullptr;
void updateStreamerModeIcon();

TitleBarButton *doNotDisturbTitlebarIcon_ = nullptr;
void updateDoNotDisturbIcon();

friend class Notebook;
};

Expand Down
1 change: 1 addition & 0 deletions src/widgets/helper/TitlebarButton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum class TitleBarButtonStyle {
User = 16,
Settings = 32,
StreamerMode = 64,
DoNotDisturb = 128,
};

class TitleBarButton : public Button
Expand Down
Loading