From 0dfcc1420da0e784af10a4adacc218db518a7274 Mon Sep 17 00:00:00 2001 From: mrossinek Date: Fri, 1 May 2020 21:54:53 +0200 Subject: [PATCH] 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; }