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
This commit is contained in:
mrossinek 2020-05-01 19:37:43 +02:00
parent c45a9eac73
commit b8aa8c15e8
No known key found for this signature in database
GPG Key ID: 454148C1EEA3C435
3 changed files with 38 additions and 25 deletions

View File

@ -872,8 +872,8 @@ Example time: "1000ms" "10m"
=head1 MISCELLANEOUS =head1 MISCELLANEOUS
Dunst can be paused via the `dunstctl set-running false` command. To unpause dunst use Dunst can be paused via the `dunstctl set-paused true` command. To unpause dunst use
`dunstctl set-status true` and to unpause `dunstctl set-status false`. `dunstctl set-paused false`.
Alternatively you can send SIGUSR1 and SIGUSR2 to pause and unpause Alternatively you can send SIGUSR1 and SIGUSR2 to pause and unpause
respectively. For Example: respectively. For Example:

View File

@ -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 multiple times to show older notifications, up to the history limit configured
in dunst. in dunst.
=item B<running> =item B<is-paused>
Check if dunst is currently running or paused. If dunst is paused notifications Check if dunst is currently running or paused. If dunst is paused notifications
will be kept but not shown until it is unpaused. will be kept but not shown until it is unpaused.
=item B<set-running> true/false/toggle =item B<set-paused> true/false/toggle
Set the paused status of dunst. If true, dunst is running normally, if false, Set the paused status of dunst. If false, dunst is running normally, if true,
dunst is paused. See the running command and the dunst man page for more dunst is paused. See the is-paused command and the dunst man page for more
information. information.
=item B<debug> =item B<debug>

View File

@ -14,17 +14,17 @@ show_help() {
cat <<-EOH cat <<-EOH
Usage: dunstctl <command> [parameters]" Usage: dunstctl <command> [parameters]"
Commands: Commands:
action Perform the default action, or open the action Perform the default action, or open the
context menu of the notification at the context menu of the notification at the
given position given position
close Close the last notification close Close the last notification
close-all Close the all notifications close-all Close the all notifications
context Open context menu context Open context menu
history-pop Pop one notification from history history-pop Pop one notification from history
running Check if dunst is running or paused is-paused Check if dunst is running or paused
set-running [true|false|toggle] Set the pause status set-paused [true|false|toggle] Set the pause status
debug Print debugging information debug Print debugging information
help Show this help help Show this help
EOH EOH
} }
dbus_send_checked() { 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}" 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 || \ command -v dbus-send >/dev/null 2>/dev/null || \
die "Command dbus-send not found" die "Command dbus-send not found"
@ -64,23 +72,28 @@ case "${1:-}" in
"history-pop") "history-pop")
method_call "${DBUS_IFAC_DUNST}.NotificationShow" >/dev/null method_call "${DBUS_IFAC_DUNST}.NotificationShow" >/dev/null
;; ;;
"running") "is-paused")
property_get running | ( read -r _ _ paused; 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-running") "set-paused")
[ "${2:-}" ] \ [ "${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" ] \ [ "${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 if [ "${2}" = "toggle" ]; then
paused=$(property_get running | ( read -r _ _ paused; printf "%s\n" "${paused}"; )) running=$(property_get running | ( read -r _ _ running; printf "%s\n" "${running}"; ))
if [ "${paused}" = "true" ]; then if [ "${running}" = "true" ]; then
property_set running variant:boolean:false property_set running variant:boolean:false
else else
property_set running variant:boolean:true property_set running variant:boolean:true
fi fi
else 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 fi
;; ;;
"help"|"--help"|"-h") "help"|"--help"|"-h")