mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
feat(widgets): add hide when unread option to notification widget
This commit is contained in:
@@ -939,6 +939,10 @@
|
||||
"label": "Hide When Off",
|
||||
"description": "Hide the lock key indicator when inactive"
|
||||
},
|
||||
"hide_when_no_unread": {
|
||||
"label": "Hide When No New",
|
||||
"description": "Hide the notifications widget when there are no unread notifications"
|
||||
},
|
||||
"high_color": {
|
||||
"label": "High Color",
|
||||
"description": "Color used for high visualizer values"
|
||||
|
||||
@@ -260,3 +260,6 @@ battery_low_percent_threshold = 0 # set to e.g. 15 to enable battery_under_thr
|
||||
|
||||
# [widget.control-center]
|
||||
# use_distro_logo = true
|
||||
|
||||
# [widget.notifications]
|
||||
# hide_when_no_unread = true
|
||||
|
||||
@@ -246,7 +246,8 @@ std::unique_ptr<Widget> WidgetFactory::create(const std::string& name, wl_output
|
||||
}
|
||||
|
||||
if (type == "notifications") {
|
||||
auto widget = std::make_unique<NotificationWidget>(m_notifications, output);
|
||||
const bool hideWhenNoUnread = wc != nullptr ? wc->getBool("hide_when_no_unread", false) : false;
|
||||
auto widget = std::make_unique<NotificationWidget>(m_notifications, output, hideWhenNoUnread);
|
||||
widget->setContentScale(contentScale);
|
||||
return widget;
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace {
|
||||
constexpr float kDotBaseSize = 6.0f;
|
||||
} // namespace
|
||||
|
||||
NotificationWidget::NotificationWidget(NotificationManager* manager, wl_output* output)
|
||||
: m_manager(manager), m_output(output) {}
|
||||
NotificationWidget::NotificationWidget(NotificationManager* manager, wl_output* output, bool hideWhenNoUnread)
|
||||
: m_manager(manager), m_output(output), m_hideWhenNoUnread(hideWhenNoUnread) {}
|
||||
|
||||
void NotificationWidget::create() {
|
||||
auto area = std::make_unique<InputArea>();
|
||||
@@ -80,6 +80,13 @@ void NotificationWidget::doUpdate(Renderer& /*renderer*/) { refreshIndicatorStat
|
||||
void NotificationWidget::refreshIndicatorState() {
|
||||
const bool hasNotifications = (m_manager != nullptr) && m_manager->hasUnreadNotificationHistory();
|
||||
const bool dndEnabled = (m_manager != nullptr) && m_manager->doNotDisturb();
|
||||
|
||||
if (Node* rootNode = root(); rootNode != nullptr) {
|
||||
const bool showWidget = !m_hideWhenNoUnread || hasNotifications;
|
||||
rootNode->setVisible(showWidget);
|
||||
rootNode->setParticipatesInLayout(showWidget);
|
||||
}
|
||||
|
||||
if (hasNotifications == m_hasNotifications && dndEnabled == m_dndEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ class NotificationManager;
|
||||
|
||||
class NotificationWidget : public Widget {
|
||||
public:
|
||||
NotificationWidget(NotificationManager* manager, wl_output* output);
|
||||
NotificationWidget(NotificationManager* manager, wl_output* output, bool hideWhenNoUnread = false);
|
||||
|
||||
void create() override;
|
||||
|
||||
@@ -22,6 +22,7 @@ private:
|
||||
wl_output* m_output = nullptr;
|
||||
Glyph* m_glyph = nullptr;
|
||||
Node* m_dot = nullptr;
|
||||
bool m_hideWhenNoUnread = false;
|
||||
bool m_hasNotifications = false;
|
||||
bool m_dndEnabled = false;
|
||||
};
|
||||
|
||||
@@ -458,6 +458,8 @@ namespace settings {
|
||||
add(doubleSpec("art_size", 16.0, 8.0, 96.0, 1.0));
|
||||
} else if (type == "network") {
|
||||
add(boolSpec("show_label", true));
|
||||
} else if (type == "notifications") {
|
||||
add(boolSpec("hide_when_no_unread", false));
|
||||
} else if (type == "scripted") {
|
||||
add(stringSpec("script"));
|
||||
add(boolSpec("hot_reload", false, true));
|
||||
|
||||
Reference in New Issue
Block a user