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.
This commit is contained in:
mrossinek 2020-05-01 21:54:53 +02:00
parent 2e301b1d39
commit 0dfcc1420d
No known key found for this signature in database
GPG Key ID: 454148C1EEA3C435
2 changed files with 10 additions and 23 deletions

View File

@ -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")

View File

@ -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;
}