From c45a9eac73f67620b44999d2ddd8ff23b4d844a4 Mon Sep 17 00:00:00 2001 From: mrossinek Date: Fri, 1 May 2020 19:13:13 +0200 Subject: [PATCH 1/6] Add toggle option to dunstctl set-running command Fixes #709 --- docs/dunstctl.pod | 2 +- dunstctl | 39 ++++++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/docs/dunstctl.pod b/docs/dunstctl.pod index c537349..dba127f 100644 --- a/docs/dunstctl.pod +++ b/docs/dunstctl.pod @@ -40,7 +40,7 @@ in dunst. Check if dunst is currently running or paused. If dunst is paused notifications will be kept but not shown until it is unpaused. -=item B true/false +=item B true/false/toggle Set the paused status of dunst. If true, dunst is running normally, if false, dunst is paused. See the running command and the dunst man page for more diff --git a/dunstctl b/dunstctl index 347c77c..3218894 100755 --- a/dunstctl +++ b/dunstctl @@ -14,17 +14,17 @@ show_help() { cat <<-EOH Usage: dunstctl [parameters]" Commands: - action Perform the default action, or open the - context menu of the notification at the - given position - close Close the last notification - close-all Close the all notifications - context Open context menu - history-pop Pop one notification from history - running Check if dunst is running or paused - set-running [true|false] Set the pause status - debug Print debugging information - help Show this help + action Perform the default action, or open the + context menu of the notification at the + given position + close Close the last notification + close-all Close the all notifications + context Open context menu + history-pop Pop one notification from history + running Check if dunst is running or paused + set-running [true|false|toggle] Set the pause status + debug Print debugging information + help Show this help EOH } dbus_send_checked() { @@ -69,10 +69,19 @@ case "${1:-}" in ;; "set-running") [ "${2:-}" ] \ - || die "No status parameter specified. Please give either 'true' or 'false' as running parameter." - [ "${2}" = "true" ] || [ "${2}" = "false" ] \ - || die "Please give either 'true' or 'false' as running parameter." - property_set running variant:boolean:"${2}" + || die "No status parameter specified. Please give either 'true', 'false' or 'toggle' as running parameter." + [ "${2}" = "true" ] || [ "${2}" = "false" ] || [ "${2}" = "toggle" ] \ + || die "Please give either 'true', 'false' or 'toggle' as running parameter." + if [ "${2}" = "toggle" ]; then + paused=$(property_get running | ( read -r _ _ paused; printf "%s\n" "${paused}"; )) + if [ "${paused}" = "true" ]; then + property_set running variant:boolean:false + else + property_set running variant:boolean:true + fi + else + property_set running variant:boolean:"${2}" + fi ;; "help"|"--help"|"-h") show_help From b8aa8c15e87fa394da0113b764585c2c2aa374b8 Mon Sep 17 00:00:00 2001 From: mrossinek Date: Fri, 1 May 2020 19:37:43 +0200 Subject: [PATCH 2/6] Rename set-running to set-paused Since the pause status is more intuitive for the end-user than the running state (which is used internally) the interface of the dunstctl is renamed to set-paused and is-paused (previously set-running and running). This requires inversion of the boolean variables to be consistent with the inverted naming. Fixes #710 --- docs/dunst.pod | 4 ++-- docs/dunstctl.pod | 8 ++++---- dunstctl | 51 +++++++++++++++++++++++++++++------------------ 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/docs/dunst.pod b/docs/dunst.pod index b97e647..0c55472 100644 --- a/docs/dunst.pod +++ b/docs/dunst.pod @@ -872,8 +872,8 @@ Example time: "1000ms" "10m" =head1 MISCELLANEOUS -Dunst can be paused via the `dunstctl set-running false` command. To unpause dunst use -`dunstctl set-status true` and to unpause `dunstctl set-status false`. +Dunst can be paused via the `dunstctl set-paused true` command. To unpause dunst use +`dunstctl set-paused false`. Alternatively you can send SIGUSR1 and SIGUSR2 to pause and unpause respectively. For Example: diff --git a/docs/dunstctl.pod b/docs/dunstctl.pod index dba127f..2a637fb 100644 --- a/docs/dunstctl.pod +++ b/docs/dunstctl.pod @@ -35,15 +35,15 @@ Redisplay the notification that was most recently closed. This can be called multiple times to show older notifications, up to the history limit configured in dunst. -=item B +=item B Check if dunst is currently running or paused. If dunst is paused notifications will be kept but not shown until it is unpaused. -=item B true/false/toggle +=item B true/false/toggle -Set the paused status of dunst. If true, dunst is running normally, if false, -dunst is paused. See the running command and the dunst man page for more +Set the paused status of dunst. If false, dunst is running normally, if true, +dunst is paused. See the is-paused command and the dunst man page for more information. =item B diff --git a/dunstctl b/dunstctl index 3218894..a8bc1fa 100755 --- a/dunstctl +++ b/dunstctl @@ -14,17 +14,17 @@ show_help() { cat <<-EOH Usage: dunstctl [parameters]" Commands: - action Perform the default action, or open the - context menu of the notification at the - given position - close Close the last notification - close-all Close the all notifications - context Open context menu - history-pop Pop one notification from history - running Check if dunst is running or paused - set-running [true|false|toggle] Set the pause status - debug Print debugging information - help Show this help + action Perform the default action, or open the + context menu of the notification at the + given position + close Close the last notification + close-all Close the all notifications + context Open context menu + history-pop Pop one notification from history + is-paused Check if dunst is running or paused + set-paused [true|false|toggle] Set the pause status + debug Print debugging information + help Show this help EOH } dbus_send_checked() { @@ -44,6 +44,14 @@ property_set() { dbus_send_checked --print-reply=literal --dest="${DBUS_NAME}" "${DBUS_PATH}" "${DBUS_IFAC_PROP}.Set" "string:${DBUS_IFAC_DUNST}" "string:${1}" "${2}" } +invert_boolean() { + if [ "${1}" = "true" ]; then + printf "%s\n" "false" + elif [ "${1}" = "false" ]; then + printf "%s\n" "true" + fi +} + command -v dbus-send >/dev/null 2>/dev/null || \ die "Command dbus-send not found" @@ -64,23 +72,28 @@ case "${1:-}" in "history-pop") method_call "${DBUS_IFAC_DUNST}.NotificationShow" >/dev/null ;; - "running") - property_get running | ( read -r _ _ paused; printf "%s\n" "${paused}"; ) + "is-paused") + running=$(property_get running | ( read -r _ _ running; printf "%s\n" "${running}"; )) + # invert boolean to indiciate pause status rather than running one + paused=$(invert_boolean "${running}") + printf "%s\n" "${paused}" ;; - "set-running") + "set-paused") [ "${2:-}" ] \ - || die "No status parameter specified. Please give either 'true', 'false' or 'toggle' as running parameter." + || die "No status parameter specified. Please give either 'true', 'false' or 'toggle' as paused parameter." [ "${2}" = "true" ] || [ "${2}" = "false" ] || [ "${2}" = "toggle" ] \ - || die "Please give either 'true', 'false' or 'toggle' as running parameter." + || die "Please give either 'true', 'false' or 'toggle' as paused parameter." if [ "${2}" = "toggle" ]; then - paused=$(property_get running | ( read -r _ _ paused; printf "%s\n" "${paused}"; )) - if [ "${paused}" = "true" ]; then + running=$(property_get running | ( read -r _ _ running; printf "%s\n" "${running}"; )) + if [ "${running}" = "true" ]; then property_set running variant:boolean:false else property_set running variant:boolean:true fi else - property_set running variant:boolean:"${2}" + # invert boolean to indiciate running status rather than pause one + running=$(invert_boolean "${2}") + property_set running variant:boolean:"${running}" fi ;; "help"|"--help"|"-h") From 2e301b1d39287939626288b1804743ca0f7ab477 Mon Sep 17 00:00:00 2001 From: mrossinek Date: Fri, 1 May 2020 21:35:08 +0200 Subject: [PATCH 3/6] Fix indentation and use tabs for indents --- dunstctl | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/dunstctl b/dunstctl index a8bc1fa..7d09f02 100755 --- a/dunstctl +++ b/dunstctl @@ -45,11 +45,11 @@ property_set() { } invert_boolean() { - if [ "${1}" = "true" ]; then - printf "%s\n" "false" - elif [ "${1}" = "false" ]; then - printf "%s\n" "true" - fi + if [ "${1}" = "true" ]; then + printf "%s\n" "false" + elif [ "${1}" = "false" ]; then + printf "%s\n" "true" + fi } command -v dbus-send >/dev/null 2>/dev/null || \ @@ -73,28 +73,28 @@ case "${1:-}" in method_call "${DBUS_IFAC_DUNST}.NotificationShow" >/dev/null ;; "is-paused") - running=$(property_get running | ( read -r _ _ running; printf "%s\n" "${running}"; )) - # invert boolean to indiciate pause status rather than running one - paused=$(invert_boolean "${running}") - printf "%s\n" "${paused}" + running=$(property_get running | ( read -r _ _ running; printf "%s\n" "${running}"; )) + # invert boolean to indiciate pause status rather than running one + paused=$(invert_boolean "${running}") + printf "%s\n" "${paused}" ;; "set-paused") [ "${2:-}" ] \ || die "No status parameter specified. Please give either 'true', 'false' or 'toggle' as paused parameter." [ "${2}" = "true" ] || [ "${2}" = "false" ] || [ "${2}" = "toggle" ] \ || die "Please give either 'true', 'false' or 'toggle' as paused parameter." - if [ "${2}" = "toggle" ]; then - running=$(property_get running | ( read -r _ _ running; printf "%s\n" "${running}"; )) - if [ "${running}" = "true" ]; then - property_set running variant:boolean:false - else - property_set running variant:boolean:true - fi - else - # invert boolean to indiciate running status rather than pause one - running=$(invert_boolean "${2}") - property_set running variant:boolean:"${running}" - fi + if [ "${2}" = "toggle" ]; then + running=$(property_get running | ( read -r _ _ running; printf "%s\n" "${running}"; )) + if [ "${running}" = "true" ]; then + property_set running variant:boolean:false + else + property_set running variant:boolean:true + fi + else + # invert boolean to indiciate running status rather than pause one + running=$(invert_boolean "${2}") + property_set running variant:boolean:"${running}" + fi ;; "help"|"--help"|"-h") show_help From 0dfcc1420da0e784af10a4adacc218db518a7274 Mon Sep 17 00:00:00 2001 From: mrossinek Date: Fri, 1 May 2020 21:54:53 +0200 Subject: [PATCH 4/6] Change running to paused state on "server" side This allows the boolean "inversion" to happen in the C code instead of post-processing in the dunstctl shell script. --- dunstctl | 25 ++++++------------------- src/dbus.c | 8 ++++---- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/dunstctl b/dunstctl index 7d09f02..78419b7 100755 --- a/dunstctl +++ b/dunstctl @@ -44,14 +44,6 @@ property_set() { dbus_send_checked --print-reply=literal --dest="${DBUS_NAME}" "${DBUS_PATH}" "${DBUS_IFAC_PROP}.Set" "string:${DBUS_IFAC_DUNST}" "string:${1}" "${2}" } -invert_boolean() { - if [ "${1}" = "true" ]; then - printf "%s\n" "false" - elif [ "${1}" = "false" ]; then - printf "%s\n" "true" - fi -} - command -v dbus-send >/dev/null 2>/dev/null || \ die "Command dbus-send not found" @@ -73,10 +65,7 @@ case "${1:-}" in method_call "${DBUS_IFAC_DUNST}.NotificationShow" >/dev/null ;; "is-paused") - running=$(property_get running | ( read -r _ _ running; printf "%s\n" "${running}"; )) - # invert boolean to indiciate pause status rather than running one - paused=$(invert_boolean "${running}") - printf "%s\n" "${paused}" + property_get paused | ( read -r _ _ paused; printf "%s\n" "${paused}"; ) ;; "set-paused") [ "${2:-}" ] \ @@ -84,16 +73,14 @@ case "${1:-}" in [ "${2}" = "true" ] || [ "${2}" = "false" ] || [ "${2}" = "toggle" ] \ || die "Please give either 'true', 'false' or 'toggle' as paused parameter." if [ "${2}" = "toggle" ]; then - running=$(property_get running | ( read -r _ _ running; printf "%s\n" "${running}"; )) - if [ "${running}" = "true" ]; then - property_set running variant:boolean:false + paused=$(property_get paused | ( read -r _ _ paused; printf "%s\n" "${paused}"; )) + if [ "${paused}" = "true" ]; then + property_set paused variant:boolean:false else - property_set running variant:boolean:true + property_set paused variant:boolean:true fi else - # invert boolean to indiciate running status rather than pause one - running=$(invert_boolean "${2}") - property_set running variant:boolean:"${running}" + property_set paused variant:boolean:"$2" fi ;; "help"|"--help"|"-h") diff --git a/src/dbus.c b/src/dbus.c index e3427b8..5fa31f8 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -588,8 +588,8 @@ GVariant *dbus_cb_dunst_Properties_Get(GDBusConnection *connection, { struct dunst_status status = dunst_status_get(); - if (STR_EQ(property_name, "running")) { - return g_variant_new_boolean(status.running); + if (STR_EQ(property_name, "paused")) { + return !g_variant_new_boolean(status.running); } else { LOG_W("Unknown property!\n"); *error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_PROPERTY, "Unknown property"); @@ -606,8 +606,8 @@ gboolean dbus_cb_dunst_Properties_Set(GDBusConnection *connection, GError **error, gpointer user_data) { - if (STR_EQ(property_name, "running")) { - dunst_status(S_RUNNING, g_variant_get_boolean(value)); + if (STR_EQ(property_name, "paused")) { + dunst_status(S_RUNNING, !g_variant_get_boolean(value)); wake_up(); return true; } From f868f51fcda1964fd1c2f79574d744b6c3de4c13 Mon Sep 17 00:00:00 2001 From: mrossinek Date: Sat, 2 May 2020 09:19:24 +0200 Subject: [PATCH 5/6] Fix embedded XML --- src/dbus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dbus.c b/src/dbus.c index 5fa31f8..58d9d33 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -81,7 +81,7 @@ static const char *introspection_xml = " " " " - " " + " " " " " " From cfa8625699e50f23f9abb6505423810c4bb12292 Mon Sep 17 00:00:00 2001 From: mrossinek Date: Sat, 2 May 2020 10:01:51 +0200 Subject: [PATCH 6/6] Fix boolean negation --- src/dbus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dbus.c b/src/dbus.c index 58d9d33..eb63f69 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -589,7 +589,7 @@ GVariant *dbus_cb_dunst_Properties_Get(GDBusConnection *connection, struct dunst_status status = dunst_status_get(); if (STR_EQ(property_name, "paused")) { - return !g_variant_new_boolean(status.running); + return g_variant_new_boolean(!status.running); } else { LOG_W("Unknown property!\n"); *error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_PROPERTY, "Unknown property");