mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-22 14:29:48 +01:00
notifs: Implement notification dimissing (#4790)
This commit is contained in:
parent
8811f4b69a
commit
be89d6faa9
4 changed files with 37 additions and 0 deletions
|
@ -33,6 +33,7 @@ commands:
|
|||
cursorpos
|
||||
decorations
|
||||
devices
|
||||
dismissnotify
|
||||
dispatch
|
||||
getoption
|
||||
globalshortcuts
|
||||
|
@ -388,6 +389,8 @@ int main(int argc, char** argv) {
|
|||
request(fullRequest, 3);
|
||||
else if (fullRequest.contains("/plugin"))
|
||||
request(fullRequest, 1);
|
||||
else if (fullRequest.contains("/dismissnotify"))
|
||||
request(fullRequest, 0);
|
||||
else if (fullRequest.contains("/notify"))
|
||||
request(fullRequest, 2);
|
||||
else if (fullRequest.contains("/output"))
|
||||
|
|
|
@ -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});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue