Added hide and close latest notification to client (#113)

This commit is contained in:
Erik Reider 2022-04-18 00:18:46 +02:00 committed by GitHub
parent f400e4a134
commit c54bf8ba16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 58 additions and 1 deletions

View File

@ -30,6 +30,8 @@ _swaync-client() {
--toggle-dnd
--get-dnd
--count
--hide-latest
--close-latest
--close-all
--skip-wait
--subscribe

View File

@ -9,6 +9,8 @@ complete -c swaync-client -s cp -l close-panel --description "Closes the notific
complete -c swaync-client -s d -l toggle-dnd --description "Toggle and print the current dnd state" -r
complete -c swaync-client -s D -l get-dnd --description "Print the current dnd state" -r
complete -c swaync-client -s c -l count --description "Print the current notificaion count" -r
complete -c swaync-client -l hide-latest --description "Hides latest notification. Still shown in Control Center" -r
complete -c swaync-client -l close-latest --description "Closes latest notification" -r
complete -c swaync-client -s C -l close-all --description "Closes all notifications" -r
complete -c swaync-client -s sw -l skip-wait --description "Doesn't wait when swaync hasn't been started" -r
complete -c swaync-client -s s -l subscribe --description "Subscribe to notificaion add and close events" -r

View File

@ -11,7 +11,9 @@ _arguments -s \
'(-d --toggle-dnd)'{-d,--toggle-dnd}'[Toggle and print the current dnd state]' \
'(-D --get-dnd)'{-D,--get-dnd}'[Print the current dnd state]' \
'(-c --count)'{-c,--count}'[Print the current notificaion count]' \
'(-C --close-all)'{-C,--close-all}'[Closes all notifications]' \
'(--hide-latest)'{--hide-latest}'[Closes all notifications]' \
'(--close-latest)'{--close-latest}'[Hides latest notification. Still shown in Control Center]' \
'(-C --close-all)'{-C,--close-all}'[Closes latest notification]' \
'(-sw --skip-wait)'{-sw,--skip-wait}"[Doesn't wait when swaync hasn't been started]" \
'(-s --subscribe)'{-s,--subscribe}'[Subscribe to notificaion add and close events]' \
'(-swb --subscribe-waybar)'{-swb,--subscribe-waybar}'[Subscribe to notificaion add and close events with waybar support. Read README for example]' \

View File

@ -40,6 +40,12 @@ swaync-client - Client executable
*-c, --count*
Print the current notificaion count
*--hide-latest*
Hides latest notification. Still shown in Control Center
*--close-latest*
Closes latest notification
*-C, --close-all*
Closes all notifications

View File

@ -70,6 +70,12 @@ namespace SwayNotificationCenter {
return controlCenter.get_visibility ();
}
/** Closes latest popup notification */
public void hide_latest_notifications (bool close)
throws DBusError, IOError {
notiDaemon.hide_latest_notification (close);
}
/** Closes all popup and controlcenter notifications */
public void close_all_notifications () throws DBusError, IOError {
notiDaemon.close_all_notifications ();

View File

@ -5,6 +5,8 @@ interface CcDaemon : GLib.Object {
public abstract void reload_config () throws Error;
public abstract void hide_latest_notifications (bool close) throws DBusError, IOError;
public abstract void close_all_notifications () throws DBusError, IOError;
public abstract uint notification_count () throws DBusError, IOError;
@ -39,6 +41,8 @@ private void print_help (string[] args) {
print (@"\t -d, \t --toggle-dnd \t\t Toggle and print the current dnd state\n");
print (@"\t -D, \t --get-dnd \t\t Print the current dnd state\n");
print (@"\t -c, \t --count \t\t Print the current notificaion count\n");
print (@"\t \t --hide-latest \t\t Hides latest notification. Still shown in Control Center\n");
print (@"\t \t --close-latest \t Closes latest notification\n");
print (@"\t -C, \t --close-all \t\t Closes all notifications\n");
print (@"\t -sw, \t --skip-wait \t\t Doesn't wait when swaync hasn't been started\n");
print (@"\t -s, \t --subscribe \t\t Subscribe to notificaion add and close events\n");
@ -118,6 +122,12 @@ public int command_line (string[] args) {
case "-c":
print (cc_daemon.notification_count ().to_string ());
break;
case "--close-latest":
cc_daemon.hide_latest_notifications (true);
break;
case "--hide-latest":
cc_daemon.hide_latest_notifications (false);
break;
case "--close-all":
case "-C":
cc_daemon.close_all_notifications ();

View File

@ -78,6 +78,14 @@ namespace SwayNotificationCenter {
ccDaemon.controlCenter.close_all_notifications ();
}
/** Closes latest popup notification */
public void hide_latest_notification (bool close)
throws DBusError, IOError {
uint32 ? id = notiWindow.get_latest_notification ();
if (id == null) return;
manually_close_notification (id, !close);
}
/*
* D-Bus Specification
* https://specifications.freedesktop.org/notification-spec/latest/ar01s09.html

View File

@ -27,6 +27,11 @@ namespace SwayNotificationCenter {
public void close_notification (uint32 id) {
notificationWindow.close_notification (id);
}
public uint32 ? get_latest_notification () {
if (!notis.get_realized () || notis.closed) return null;
return notificationWindow.get_latest_notification ();
}
}
[GtkTemplate (ui = "/org/erikreider/sway-notification-center/notiWindow/notiWindow.ui")]
@ -169,5 +174,21 @@ namespace SwayNotificationCenter {
}
}
}
public uint32 ? get_latest_notification () {
List<weak Gtk.Widget> children = box.get_children ();
if (children.is_empty ()) return null;
Gtk.Widget ? child = null;
if (list_reverse) {
child = children.last ().data;
} else {
child = children.first ().data;
}
if (child == null || !(child is Notification)) return null;
Notification noti = (Notification) child;
return noti.param.applied_id;
}
}
}