summaryrefslogtreecommitdiff
path: root/src/debug
diff options
context:
space:
mode:
authorItsDrike <itsdrike@protonmail.com>2024-03-02 19:12:31 +0100
committerGitHub <noreply@github.com>2024-03-02 18:12:31 +0000
commitbe89d6faa988f6bd33a66f02746872c649a16180 (patch)
tree1e2bfbf8d184a7209a5b973c42a869931572f8ef /src/debug
parent8811f4b69ade469285635c539f20194d717c8e17 (diff)
notifs: Implement notification dimissing (#4790)
Diffstat (limited to 'src/debug')
-rw-r--r--src/debug/HyprCtl.cpp21
-rw-r--r--src/debug/HyprNotificationOverlay.cpp12
-rw-r--r--src/debug/HyprNotificationOverlay.hpp1
3 files changed, 34 insertions, 0 deletions
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp
index b3fb0af3..962496f7 100644
--- a/src/debug/HyprCtl.cpp
+++ b/src/debug/HyprCtl.cpp
@@ -1430,6 +1430,26 @@ std::string dispatchNotify(eHyprCtlOutputFormat format, std::string request) {
return "ok";
}
+std::string dispatchDismissNotify(eHyprCtlOutputFormat format, std::string request) {
+ CVarList vars(request, 0, ' ');
+
+ int amount = -1;
+
+ if (vars.size() > 1) {
+ const auto AMOUNT = vars[1];
+ if (!isNumber(AMOUNT))
+ return "invalid arg 1";
+
+ try {
+ amount = std::stoi(AMOUNT);
+ } catch (std::exception& e) { return "invalid arg 1"; }
+ }
+
+ g_pHyprNotificationOverlay->dismissNotifications(amount);
+
+ return "ok";
+}
+
CHyprCtl::CHyprCtl() {
registerCommand(SHyprCtlCommand{"workspaces", true, workspacesRequest});
registerCommand(SHyprCtlCommand{"workspacerules", true, workspaceRulesRequest});
@@ -1453,6 +1473,7 @@ CHyprCtl::CHyprCtl() {
registerCommand(SHyprCtlCommand{"reload", false, reloadRequest});
registerCommand(SHyprCtlCommand{"plugin", false, dispatchPlugin});
registerCommand(SHyprCtlCommand{"notify", false, dispatchNotify});
+ registerCommand(SHyprCtlCommand{"dismissnotify", false, dispatchDismissNotify});
registerCommand(SHyprCtlCommand{"setprop", false, dispatchSetProp});
registerCommand(SHyprCtlCommand{"seterror", false, dispatchSeterror});
registerCommand(SHyprCtlCommand{"switchxkblayout", false, switchXKBLayoutRequest});
diff --git a/src/debug/HyprNotificationOverlay.cpp b/src/debug/HyprNotificationOverlay.cpp
index 2968134b..98c68f1f 100644
--- a/src/debug/HyprNotificationOverlay.cpp
+++ b/src/debug/HyprNotificationOverlay.cpp
@@ -50,6 +50,18 @@ void CHyprNotificationOverlay::addNotification(const std::string& text, const CC
}
}
+void CHyprNotificationOverlay::dismissNotifications(const int amount) {
+ if (amount == -1)
+ m_dNotifications.clear();
+ else {
+ const int AMT = std::min(amount, static_cast<int>(m_dNotifications.size()));
+
+ for (int i = 0; i < AMT; ++i) {
+ m_dNotifications.pop_front();
+ }
+ }
+}
+
CBox CHyprNotificationOverlay::drawNotifications(CMonitor* pMonitor) {
static constexpr auto ANIM_DURATION_MS = 600.0;
static constexpr auto ANIM_LAG_MS = 100.0;
diff --git a/src/debug/HyprNotificationOverlay.hpp b/src/debug/HyprNotificationOverlay.hpp
index 7a883f15..ef81b014 100644
--- a/src/debug/HyprNotificationOverlay.hpp
+++ b/src/debug/HyprNotificationOverlay.hpp
@@ -41,6 +41,7 @@ class CHyprNotificationOverlay {
void draw(CMonitor* pMonitor);
void addNotification(const std::string& text, const CColor& color, const float timeMs, const eIcons icon = ICON_NONE);
+ void dismissNotifications(const int amount);
bool hasAny();
private: