Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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: 2 additions & 1 deletion man/swaync-client.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ swaync-client - Client executable
Closes all notifications

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

*-sw, --skip-wait*
Doesn't wait when swaync hasn't been started
Expand Down
11 changes: 7 additions & 4 deletions src/client.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ interface CcDaemon : Object {

public abstract void latest_invoke_action (uint32 action_index) throws DBusError, IOError;

public abstract void latest_invoke_default_action () throws DBusError, IOError;

public abstract bool set_cc_monitor (string monitor) throws DBusError, IOError;
public abstract bool set_noti_window_monitor (string monitor) throws DBusError, IOError;

Expand Down Expand Up @@ -78,7 +80,7 @@ private void print_help (string[] args) {
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");
"Invokes the default action, or action [ACTION_INDEX], of the latest notification\n");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better if an --action-default (or something similar) command was added instead. This wouldn't break existing configs.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, please take another look.

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 @@ -209,12 +211,13 @@ public int command_line (ref string[] args, bool skip_wait) {
break;
case "--action":
case "-a":
int action_index = 0;
if (args.length >= 2) {
used_args++;
action_index = int.parse (args[1]);
int action_index = int.parse (args[1]);
cc_daemon.latest_invoke_action ((uint32) action_index);
} else {
cc_daemon.latest_invoke_default_action ();
}
cc_daemon.latest_invoke_action ((uint32) action_index);
break;
case "--get-inhibited":
case "-I":
Expand Down
5 changes: 5 additions & 0 deletions src/notiDaemon/notiDaemon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ namespace SwayNotificationCenter {
floating_notifications.latest_notification_action (action_index);
}

/** Activates the default action of the latest notification */
internal void invoke_latest_floating_default_action () {
floating_notifications.latest_notification_default_action ();
}

/*
* D-Bus Specification
* https://specifications.freedesktop.org/notification-spec/latest/ar01s09.html
Expand Down
11 changes: 11 additions & 0 deletions src/notificationWindow/notificationWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,17 @@ namespace SwayNotificationCenter {
noti.click_alt_action (action);
}

public void latest_notification_default_action () {
unowned AnimatedListItem ?item = list.get_first_item ();
if (item == null || !(item.child is Notification)) {
warn_if_reached ();
return;
}

Notification noti = (Notification) item.child;
noti.click_default_action ();
}

public void set_monitor (Gdk.Monitor ?monitor) {
debug ("Setting monitor for Floating Notifications: %s",
Functions.monitor_to_string (monitor) ?? "Monitor Picked by Compositor");
Expand Down
6 changes: 6 additions & 0 deletions src/swayncDaemon/swayncDaemon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ namespace SwayNotificationCenter {
noti_daemon.invoke_latest_floating_action (action_index);
}

/** Activates the default action of the latest floating notification */
public inline void latest_invoke_default_action ()
throws DBusError, IOError {
noti_daemon.invoke_latest_floating_default_action ();
}

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