Unverified Commit 81bf4bdb authored by Erik Reider's avatar Erik Reider Committed by GitHub

Hide visible notifications when activating dnd (#233)

* Hide visible notifications when activating dnd * Fix linting issues --------- Co-authored-by: 's avatarErik Reider <erik.reider@protonmail.com>
parent f7daa7ac
...@@ -17,6 +17,13 @@ namespace SwayNotificationCenter { ...@@ -17,6 +17,13 @@ namespace SwayNotificationCenter {
this.notify["dnd"].connect (() => on_dnd_toggle (dnd)); this.notify["dnd"].connect (() => on_dnd_toggle (dnd));
on_dnd_toggle.connect ((dnd) => {
if (!dnd || NotificationWindow.is_null) return;
NotificationWindow.instance.close_all_notifications ((noti) => {
return noti.param.urgency != UrgencyLevels.CRITICAL;
});
});
// Init dnd from gsettings // Init dnd from gsettings
self_settings.bind ("dnd-state", this, "dnd", SettingsBindFlags.DEFAULT); self_settings.bind ("dnd-state", this, "dnd", SettingsBindFlags.DEFAULT);
...@@ -34,14 +41,12 @@ namespace SwayNotificationCenter { ...@@ -34,14 +41,12 @@ namespace SwayNotificationCenter {
/** Toggles the current Do Not Disturb state */ /** Toggles the current Do Not Disturb state */
public bool toggle_dnd () throws DBusError, IOError { public bool toggle_dnd () throws DBusError, IOError {
on_dnd_toggle (dnd = !dnd); return dnd = !dnd;
return dnd;
} }
/** Sets the current Do Not Disturb state */ /** Sets the current Do Not Disturb state */
[DBus (name = "SetDnd")] [DBus (name = "SetDnd")]
public void set_do_not_disturb (bool state) throws DBusError, IOError { public void set_do_not_disturb (bool state) throws DBusError, IOError {
on_dnd_toggle (state);
dnd = state; dnd = state;
} }
...@@ -63,9 +68,9 @@ namespace SwayNotificationCenter { ...@@ -63,9 +68,9 @@ namespace SwayNotificationCenter {
NotificationClosed (id, ClosedReasons.DISMISSED); NotificationClosed (id, ClosedReasons.DISMISSED);
swaync_daemon.subscribe_v2 (control_center.notification_count (), swaync_daemon.subscribe_v2 (control_center.notification_count (),
dnd, dnd,
control_center.get_visibility (), control_center.get_visibility (),
swaync_daemon.inhibited); swaync_daemon.inhibited);
} }
} }
......
namespace SwayNotificationCenter { namespace SwayNotificationCenter {
[GtkTemplate (ui = "/org/erikreider/sway-notification-center/notification/notification.ui")] [GtkTemplate (ui = "/org/erikreider/sway-notification-center/notification/notification.ui")]
private class Notification : Gtk.ListBoxRow { public class Notification : Gtk.ListBoxRow {
[GtkChild] [GtkChild]
unowned Gtk.Revealer revealer; unowned Gtk.Revealer revealer;
[GtkChild] [GtkChild]
......
...@@ -23,6 +23,12 @@ namespace SwayNotificationCenter { ...@@ -23,6 +23,12 @@ namespace SwayNotificationCenter {
} }
} }
public static bool is_null {
get {
return window == null;
}
}
[GtkChild] [GtkChild]
unowned Gtk.ScrolledWindow scrolled_window; unowned Gtk.ScrolledWindow scrolled_window;
[GtkChild] [GtkChild]
...@@ -122,10 +128,16 @@ namespace SwayNotificationCenter { ...@@ -122,10 +128,16 @@ namespace SwayNotificationCenter {
} }
} }
public void close_all_notifications () { /** Return true to remove notification, false to skip */
public delegate bool remove_iter_func (Notification notification);
public void close_all_notifications (remove_iter_func ? func = null) {
if (!this.get_realized ()) return; if (!this.get_realized ()) return;
foreach (var w in box.get_children ()) { foreach (var w in box.get_children ()) {
remove_notification ((Notification) w, false); Notification notification = (Notification) w;
if (func == null || func (notification)) {
remove_notification (notification, false);
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment