From 79c7ff3c1d2619aaa49cb847d1a4199a58d09800 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Sat, 7 Sep 2024 16:02:45 -0400 Subject: [PATCH 1/2] hints: parse sound-name and sound-file --- src/configModel/configModel.vala | 20 ++++++++++++++++++++ src/notiModel/notiModel.vala | 14 ++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/configModel/configModel.vala b/src/configModel/configModel.vala index a02a40e5..bf025869 100644 --- a/src/configModel/configModel.vala +++ b/src/configModel/configModel.vala @@ -87,6 +87,8 @@ namespace SwayNotificationCenter { public string ? body { get; set; default = null; } public string ? urgency { get; set; default = null; } public string ? category { get; set; default = null; } + public string ? sound_name { get; set; default = null; } + public string ? sound_file { get; set; default = null; } private const RegexCompileFlags REGEX_COMPILE_OPTIONS = RegexCompileFlags.MULTILINE; @@ -141,6 +143,22 @@ namespace SwayNotificationCenter { REGEX_MATCH_FLAGS); if (!result) return false; } + if (sound_file != null) { + if (param.sound_file == null) return false; + bool result = Regex.match_simple ( + sound_file, param.sound_file, + REGEX_COMPILE_OPTIONS, + REGEX_MATCH_FLAGS); + if (!result) return false; + } + if (sound_name != null) { + if (param.sound_name == null) return false; + bool result = Regex.match_simple ( + sound_name, param.sound_name, + REGEX_COMPILE_OPTIONS, + REGEX_MATCH_FLAGS); + if (!result) return false; + } return true; } @@ -256,6 +274,8 @@ namespace SwayNotificationCenter { spawn_env += "SWAYNC_BODY=%s".printf (param.body); spawn_env += "SWAYNC_URGENCY=%s".printf (param.urgency.to_string ()); spawn_env += "SWAYNC_CATEGORY=%s".printf (param.category); + spawn_env += "SWAYNC_SOUND_NAME=%s".printf (param.sound_name); + spawn_env += "SWAYNC_SOUND_FILE=%s".printf (param.sound_file); spawn_env += "SWAYNC_ID=%s".printf (param.applied_id.to_string ()); spawn_env += "SWAYNC_REPLACES_ID=%s".printf (param.replaces_id.to_string ()); spawn_env += "SWAYNC_TIME=%s".printf (param.time.to_string ()); diff --git a/src/notiModel/notiModel.vala b/src/notiModel/notiModel.vala index ff5af7fa..dc430c16 100644 --- a/src/notiModel/notiModel.vala +++ b/src/notiModel/notiModel.vala @@ -82,6 +82,8 @@ namespace SwayNotificationCenter { public string image_path { get; set; } public string desktop_entry { get; set; } public string category { get; set; } + public string sound_name { get; set; } + public string sound_file { get; set; } public bool resident { get; set; } public bool transient { get; set; } public UrgencyLevels urgency { get; set; } @@ -250,6 +252,16 @@ namespace SwayNotificationCenter { category = hint_value.get_string (); } break; + case "sound-name": + if (hint_value.is_of_type (VariantType.STRING)) { + sound_name = hint_value.get_string (); + } + break; + case "sound-file": + if (hint_value.is_of_type (VariantType.STRING)) { + sound_file = hint_value.get_string (); + } + break; case "resident": if (hint_value.is_of_type (VariantType.BOOLEAN)) { resident = hint_value.get_boolean (); @@ -336,6 +348,8 @@ namespace SwayNotificationCenter { params.set ("image_path", image_path); params.set ("desktop_entry", desktop_entry); params.set ("category", category); + params.set ("sound_name", sound_name); + params.set ("sound_file", sound_file); params.set ("resident", resident.to_string ()); params.set ("urgency", urgency.to_string ()); string[] _actions = {}; From 3e13fb8530c61c56116c6183fd902c769d1daae2 Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Thu, 10 Jul 2025 14:59:07 +0200 Subject: [PATCH 2/2] Added docs --- man/swaync.5.scd | 30 ++++++++++++++++++++---------- src/configSchema.json | 8 ++++++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/man/swaync.5.scd b/man/swaync.5.scd index 37cd01f6..27b4d99b 100644 --- a/man/swaync.5.scd +++ b/man/swaync.5.scd @@ -751,6 +751,14 @@ config file to be able to detect config errors type: string ++ optional: true ++ description: Which category the notification belongs to. Uses Regex.++ + *sound-file*++ + type: string ++ + optional: true ++ + description: Which sound file the notification requested. Uses Regex.++ + *sound-name*++ + type: string ++ + optional: true ++ + description: Which sound name the notification requested. Uses Regex.++ *run-on*++ type: string ++ optional: true ++ @@ -781,15 +789,17 @@ config file to be able to detect config errors You can also use these environment variables in your script: ``` -SWAYNC_BODY="Notification body content" -SWAYNC_DESKTOP_ENTRY="Desktop entry" -SWAYNC_URGENCY="Notification urgency" -SWAYNC_TIME="Notification time" -SWAYNC_APP_NAME="Notification app name" -SWAYNC_CATEGORY="SwayNC notification category" -SWAYNC_REPLACES_ID="ID of notification to replace" -SWAYNC_ID="SwayNC notification ID" -SWAYNC_SUMMARY="Notification summary" -SWAYNC_HINT_[NAME]="Value of the hint [NAME]" +$SWAYNC_BODY="Notification body content" +$SWAYNC_DESKTOP_ENTRY="Desktop entry" +$SWAYNC_URGENCY="Notification urgency" +$SWAYNC_TIME="Notification time" +$SWAYNC_APP_NAME="Notification app name" +$SWAYNC_CATEGORY="SwayNC notification category" +$SWAYNC_REPLACES_ID="ID of notification to replace" +$SWAYNC_ID="SwayNC notification ID" +$SWAYNC_SUMMARY="Notification summary" +$SWAYNC_HINT_[NAME]="Value of the hint [NAME]" +$SWAYNC_SOUND_NAME="The name of the requested sound" +$SWAYNC_SOUND_FILE="The file path of the requested sound" ``` #END scripting diff --git a/src/configSchema.json b/src/configSchema.json index d129b50b..9aa5fdd4 100644 --- a/src/configSchema.json +++ b/src/configSchema.json @@ -239,6 +239,14 @@ "type": "string", "description": "Which category the notification belongs to. Uses Regex." }, + "sound-file": { + "type": "string", + "description": "Which sound file the notification requested. Uses Regex." + }, + "sound-name": { + "type": "string", + "description": "Which sound name the notification requested. Uses Regex." + }, "run-on": { "type": "string", "description": "Whether to run the script on an action being activated, or when the notification is received.",