Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions man/swaync-client.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ swaync-client - Client executable
*-C, --close-all*
Closes all notifications

*-a, --action [ACTION_ID]*
Invokes the action [ACTION_ID] (or 0) of the latest notification

*-sw, --skip-wait*
Doesn't wait when swaync hasn't been started

Expand Down
11 changes: 11 additions & 0 deletions src/client.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ interface CcDaemon : Object {

public abstract void set_visibility (bool value) throws DBusError, IOError;

public abstract void invoke_action (uint32 action) throws DBusError, IOError;

[DBus (name = "GetSubscribeData")]
public abstract SwayncDaemonData get_subscribe_data () throws Error;

Expand Down Expand Up @@ -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_ID]\t\t Invokes the action [ACTION_ID] 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 "
Expand Down Expand Up @@ -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 = 0;
if ( args.length >= 3 ) {
action = int.parse(args[2]);
}
cc_daemon.invoke_action ((uint32) action);
break;
case "--get-inhibited":
case "-I":
print (cc_daemon.is_inhibited ().to_string ());
Expand Down
6 changes: 6 additions & 0 deletions src/notiDaemon/notiDaemon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ namespace SwayNotificationCenter {
manually_close_notification (id, !close);
}

/** Activates the `noti_id` action of the latest notification */
public void invoke_action (uint32 noti_id)
throws DBusError, IOError {
NotificationWindow.instance.latest_notification_action (noti_id);
}

/*
* D-Bus Specification
* https://specifications.freedesktop.org/notification-spec/latest/ar01s09.html
Expand Down
17 changes: 17 additions & 0 deletions src/notificationWindow/notificationWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,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 ();
}
}
}
6 changes: 6 additions & 0 deletions src/swayncDaemon/swayncDaemon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ namespace SwayNotificationCenter {
noti_daemon.control_center.close_notification (id, true);
}

/** Activates the `noti_id` action of the latest notification */
public void invoke_action (uint32 noti_id)
throws DBusError, IOError {
noti_daemon.invoke_action (noti_id);
}

/**
* Adds an inhibitor with the Application ID
* (ex: "org.erikreider.swaysettings", "swayidle", etc...).
Expand Down