From ac69bb6a1f3ee85f862c9df03b74615a65a64589 Mon Sep 17 00:00:00 2001 From: Bakhtiyar Neyman Date: Thu, 12 Mar 2026 03:32:56 -0700 Subject: [PATCH 1/3] Invoke default action when `swaync-client --action` is called without an index Previously, `--action` without an index would call `click_alt_action(0)`, which silently did nothing if the alt actions box wasn't visible. Now it invokes the notification's default action instead, matching user expectations. When an index is provided, the existing alt action behavior is preserved. Co-Authored-By: Claude Opus 4.6 --- src/client.vala | 9 ++++++--- src/notiDaemon/notiDaemon.vala | 5 +++++ src/notificationWindow/notificationWindow.vala | 11 +++++++++++ src/swayncDaemon/swayncDaemon.vala | 6 ++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/client.vala b/src/client.vala index 29b02897..8995affb 100644 --- a/src/client.vala +++ b/src/client.vala @@ -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; @@ -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": diff --git a/src/notiDaemon/notiDaemon.vala b/src/notiDaemon/notiDaemon.vala index 1fe4ee7d..33a35270 100644 --- a/src/notiDaemon/notiDaemon.vala +++ b/src/notiDaemon/notiDaemon.vala @@ -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 diff --git a/src/notificationWindow/notificationWindow.vala b/src/notificationWindow/notificationWindow.vala index d5e6d4a0..2de7fa76 100644 --- a/src/notificationWindow/notificationWindow.vala +++ b/src/notificationWindow/notificationWindow.vala @@ -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"); diff --git a/src/swayncDaemon/swayncDaemon.vala b/src/swayncDaemon/swayncDaemon.vala index db497703..4d57c243 100644 --- a/src/swayncDaemon/swayncDaemon.vala +++ b/src/swayncDaemon/swayncDaemon.vala @@ -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...). From 377b22d5f62b8cfd3cbcbbfc0063e4e37343c447 Mon Sep 17 00:00:00 2001 From: Bakhtiyar Neyman Date: Fri, 13 Mar 2026 10:43:47 -0700 Subject: [PATCH 2/3] Update --action help text and man page to reflect default action behavior Co-Authored-By: Claude Opus 4.6 --- man/swaync-client.1.scd | 3 ++- src/client.vala | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/man/swaync-client.1.scd b/man/swaync-client.1.scd index 50935151..bf1fd2e0 100644 --- a/man/swaync-client.1.scd +++ b/man/swaync-client.1.scd @@ -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 diff --git a/src/client.vala b/src/client.vala index 8995affb..2b4f3bdb 100644 --- a/src/client.vala +++ b/src/client.vala @@ -80,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"); 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 " From e1b8a41780da8c64ad217f98e3f0c9ca84f9cc67 Mon Sep 17 00:00:00 2001 From: Bakhtiyar Neyman Date: Sun, 12 Apr 2026 22:43:37 -0700 Subject: [PATCH 3/3] Add --action-default command instead of overloading --action Per reviewer feedback, keep --action's original behavior (default to action index 0) and add a separate --action-default / -ad command to invoke the default action of the latest notification. Co-Authored-By: Claude Opus 4.6 (1M context) --- man/swaync-client.1.scd | 6 ++++-- src/client.vala | 15 ++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/man/swaync-client.1.scd b/man/swaync-client.1.scd index bf1fd2e0..d0fe86ba 100644 --- a/man/swaync-client.1.scd +++ b/man/swaync-client.1.scd @@ -74,8 +74,10 @@ swaync-client - Client executable Closes all notifications *-a, --action [ACTION_INDEX]* - Invokes the default action, or action [ACTION_INDEX], of the latest - notification + Invokes the action [ACTION_INDEX] (or 0) of the latest notification + +*-ad, --action-default* + Invokes the default action of the latest notification *-sw, --skip-wait* Doesn't wait when swaync hasn't been started diff --git a/src/client.vala b/src/client.vala index 2b4f3bdb..c52f9a3d 100644 --- a/src/client.vala +++ b/src/client.vala @@ -80,7 +80,9 @@ 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 default action, or action [ACTION_INDEX], of the latest notification\n"); + "Invokes the action [ACTION_INDEX] (or 0) of the latest notification\n"); + print (" -ad,\t --action-default \t\t " + + "Invokes the default action 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 " @@ -211,13 +213,16 @@ 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++; - int action_index = int.parse (args[1]); - cc_daemon.latest_invoke_action ((uint32) action_index); - } else { - cc_daemon.latest_invoke_default_action (); + action_index = int.parse (args[1]); } + cc_daemon.latest_invoke_action ((uint32) action_index); + break; + case "--action-default": + case "-ad": + cc_daemon.latest_invoke_default_action (); break; case "--get-inhibited": case "-I":