Unverified Commit 96eca864 authored by SuperDuperDeou's avatar SuperDuperDeou Committed by GitHub

Invoke action from swaync-client (implements #437) (#443)

* Invoke action from swaync-client * Rename ACTION_ID to ACTION_INDEX * Fix formatting * Change noti_id to action_index * Change invoke_action to latest_invoke_action * Fixed nits --------- Co-authored-by: 's avatarErik Reider <35975961+ErikReider@users.noreply.github.com>
parent 20f41ddc
......@@ -70,6 +70,9 @@ swaync-client - Client executable
*-C, --close-all*
Closes all notifications
*-a, --action [ACTION_INDEX]*
Invokes the action [ACTION_INDEX] (or 0) of the latest notification
*-sw, --skip-wait*
Doesn't wait when swaync hasn't been started
......
......@@ -30,6 +30,8 @@ interface CcDaemon : Object {
public abstract void set_visibility (bool value) throws DBusError, IOError;
public abstract void latest_invoke_action (uint32 action_index) throws DBusError, IOError;
[DBus (name = "GetSubscribeData")]
public abstract SwayncDaemonData get_subscribe_data () throws Error;
......@@ -69,6 +71,7 @@ private void print_help (string[] args) {
print (" \t --hide-latest \t\t\t Hides latest notification. Still shown in Control Center\n");
print (" \t --close-latest \t\t Closes latest notification\n");
print (" -C, \t --close-all \t\t\t Closes all notifications\n");
print (" -a, \t --action [ACTION_INDEX]\t Invokes the action [ACTION_INDEX] of the latest notification\n");
print (" -sw, \t --skip-wait \t\t\t Doesn't wait when swaync hasn't been started\n");
print (" -s, \t --subscribe \t\t\t Subscribe to notification add and close events\n");
print (" -swb, --subscribe-waybar \t\t Subscribe to notification add and close events "
......@@ -190,6 +193,14 @@ public int command_line (string[] args) {
cc_daemon.set_dnd (false);
print (cc_daemon.get_dnd ().to_string ());
break;
case "--action":
case "-a":
int action_index = 0;
if ( args.length >= 3 ) {
action_index = int.parse (args[2]);
}
cc_daemon.latest_invoke_action ((uint32) action_index);
break;
case "--get-inhibited":
case "-I":
print (cc_daemon.is_inhibited ().to_string ());
......
......@@ -88,6 +88,12 @@ namespace SwayNotificationCenter {
manually_close_notification (id, !close);
}
/** Activates the `action_index` action of the latest notification */
public void latest_invoke_action (uint32 action_index)
throws DBusError, IOError {
NotificationWindow.instance.latest_notification_action (action_index);
}
/*
* D-Bus Specification
* https://specifications.freedesktop.org/notification-spec/latest/ar01s09.html
......
......@@ -271,5 +271,22 @@ namespace SwayNotificationCenter {
Notification noti = (Notification) child;
return noti.param.applied_id;
}
public void latest_notification_action (uint32 action) {
List<weak Gtk.Widget> children = box.get_children ();
if (children.is_empty ()) return;
Gtk.Widget ? child = null;
if (list_reverse) {
child = children.last ().data;
} else {
child = children.first ().data;
}
if (child == null || !(child is Notification)) return;
Notification noti = (Notification) child;
noti.click_alt_action (action);
noti.close_notification ();
}
}
}
......@@ -258,6 +258,12 @@ namespace SwayNotificationCenter {
noti_daemon.control_center.close_notification (id, true);
}
/** Activates the `action_index` action of the latest notification */
public void latest_invoke_action (uint32 action_index)
throws DBusError, IOError {
noti_daemon.latest_invoke_action (action_index);
}
/**
* Adds an inhibitor with the Application ID
* (ex: "org.erikreider.swaysettings", "swayidle", etc...).
......
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