From 313731f0f273356744c051fa76f2839ab0284579 Mon Sep 17 00:00:00 2001 From: Moritz Luedecke Date: Mon, 21 Dec 2020 11:45:54 +0100 Subject: [PATCH 1/5] Add dbus properties for number of displayed, waiting and shown notifications --- src/dbus.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/dbus.c b/src/dbus.c index d789bd2..9c05111 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -85,6 +85,10 @@ static const char *introspection_xml = " " " " + " " + " " + " " + " " ""; @@ -597,6 +601,15 @@ GVariant *dbus_cb_dunst_Properties_Get(GDBusConnection *connection, if (STR_EQ(property_name, "paused")) { return g_variant_new_boolean(!status.running); + } else if (STR_EQ(property_name, "displayed")) { + unsigned int displayed = queues_length_displayed(); + return g_variant_new_uint32(displayed); + } else if (STR_EQ(property_name, "history")) { + unsigned int history = queues_length_history(); + return g_variant_new_uint32(history); + } else if (STR_EQ(property_name, "waiting")) { + unsigned int waiting = queues_length_waiting(); + return g_variant_new_uint32(waiting); } else { LOG_W("Unknown property!\n"); *error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_PROPERTY, "Unknown property"); From 137361a95dbf4064668f32d4872fa3093e2c1db3 Mon Sep 17 00:00:00 2001 From: Moritz Luedecke Date: Mon, 21 Dec 2020 11:46:57 +0100 Subject: [PATCH 2/5] Show the number of notifications via dunstctl --- dunstctl | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/dunstctl b/dunstctl index 78419b7..71f2938 100755 --- a/dunstctl +++ b/dunstctl @@ -14,17 +14,18 @@ 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 - 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 + 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 + status [displayed|history|waiting] Show the number of notifications + debug Print debugging information + help Show this help EOH } dbus_send_checked() { @@ -83,6 +84,17 @@ case "${1:-}" in property_set paused variant:boolean:"$2" fi ;; + "status") + [ $# -eq 1 ] || [ "${2}" = "displayed" ] || [ "${2}" = "history" ] || [ "${2}" = "waiting" ] \ + || die "Please give either 'displayed', 'history', 'waiting' or none as status parameter." + if [ $# -eq 1 ]; then + property_get waiting | ( read -r _ _ waiting; printf " Waiting: %s\n" "${waiting}" ) + property_get displayed | ( read -r _ _ displayed; printf " Currently displayed: %s\n" "${displayed}" ) + property_get history | ( read -r _ _ history; printf " History: %s\n" "${history}") + else + property_get ${2} | ( read -r _ _ notifications; printf "%s\n" "${notifications}"; ) + fi + ;; "help"|"--help"|"-h") show_help ;; From 5b81b43aa620b0c3b41566d8b79da37a41ed8f1d Mon Sep 17 00:00:00 2001 From: Moritz Luedecke Date: Mon, 21 Dec 2020 12:02:20 +0100 Subject: [PATCH 3/5] Add documentation for 'dunstctl status' --- docs/dunstctl.pod | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/dunstctl.pod b/docs/dunstctl.pod index 2a637fb..87dcc81 100644 --- a/docs/dunstctl.pod +++ b/docs/dunstctl.pod @@ -46,6 +46,11 @@ 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 [displayed/history/waiting] + +Returns the number of displayed, shown and waiting notifications. If no argument +is provided, everything will be printed. + =item B Tries to contact dunst and checks for common faults between dunstctl and dunst. From 4d74c7b46e7a1e9660f5f116947bdbd09ce8ead8 Mon Sep 17 00:00:00 2001 From: Moritz Luedecke Date: Wed, 23 Dec 2020 16:30:41 +0100 Subject: [PATCH 4/5] Rename the dunstctl sub-command 'status' to 'count' --- docs/dunstctl.pod | 10 +++++----- dunstctl | 46 +++++++++++++++++++++++----------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/docs/dunstctl.pod b/docs/dunstctl.pod index 87dcc81..8dc7a69 100644 --- a/docs/dunstctl.pod +++ b/docs/dunstctl.pod @@ -29,6 +29,11 @@ Close all notifications currently being displayed Open the context menu, presenting all available actions and urls for the currently open notifications. +=item B [displayed/history/waiting] + +Returns the number of displayed, shown and waiting notifications. If no argument +is provided, everything will be printed. + =item B Redisplay the notification that was most recently closed. This can be called @@ -46,11 +51,6 @@ 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 [displayed/history/waiting] - -Returns the number of displayed, shown and waiting notifications. If no argument -is provided, everything will be printed. - =item B Tries to contact dunst and checks for common faults between dunstctl and dunst. diff --git a/dunstctl b/dunstctl index 71f2938..c166fd8 100755 --- a/dunstctl +++ b/dunstctl @@ -14,18 +14,18 @@ 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 - is-paused Check if dunst is running or paused - set-paused [true|false|toggle] Set the pause status - status [displayed|history|waiting] Show the number of notifications - 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 + count [displayed|history|waiting] Show the number of notifications + 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() { @@ -62,6 +62,17 @@ case "${1:-}" in "context") method_call "${DBUS_IFAC_DUNST}.ContextMenuCall" >/dev/null ;; + "count") + [ $# -eq 1 ] || [ "${2}" = "displayed" ] || [ "${2}" = "history" ] || [ "${2}" = "waiting" ] \ + || die "Please give either 'displayed', 'history', 'waiting' or none as count parameter." + if [ $# -eq 1 ]; then + property_get waiting | ( read -r _ _ waiting; printf " Waiting: %s\n" "${waiting}" ) + property_get displayed | ( read -r _ _ displayed; printf " Currently displayed: %s\n" "${displayed}" ) + property_get history | ( read -r _ _ history; printf " History: %s\n" "${history}") + else + property_get ${2} | ( read -r _ _ notifications; printf "%s\n" "${notifications}"; ) + fi + ;; "history-pop") method_call "${DBUS_IFAC_DUNST}.NotificationShow" >/dev/null ;; @@ -84,17 +95,6 @@ case "${1:-}" in property_set paused variant:boolean:"$2" fi ;; - "status") - [ $# -eq 1 ] || [ "${2}" = "displayed" ] || [ "${2}" = "history" ] || [ "${2}" = "waiting" ] \ - || die "Please give either 'displayed', 'history', 'waiting' or none as status parameter." - if [ $# -eq 1 ]; then - property_get waiting | ( read -r _ _ waiting; printf " Waiting: %s\n" "${waiting}" ) - property_get displayed | ( read -r _ _ displayed; printf " Currently displayed: %s\n" "${displayed}" ) - property_get history | ( read -r _ _ history; printf " History: %s\n" "${history}") - else - property_get ${2} | ( read -r _ _ notifications; printf "%s\n" "${notifications}"; ) - fi - ;; "help"|"--help"|"-h") show_help ;; From 1827f0d9744868e6f81a695f53aeeaac031a50de Mon Sep 17 00:00:00 2001 From: Moritz Luedecke Date: Fri, 25 Dec 2020 15:03:50 +0100 Subject: [PATCH 5/5] Suffix "Length" to the dbus variables for the number of notifications --- dunstctl | 8 ++++---- src/dbus.c | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dunstctl b/dunstctl index c166fd8..50b63d0 100755 --- a/dunstctl +++ b/dunstctl @@ -66,11 +66,11 @@ case "${1:-}" in [ $# -eq 1 ] || [ "${2}" = "displayed" ] || [ "${2}" = "history" ] || [ "${2}" = "waiting" ] \ || die "Please give either 'displayed', 'history', 'waiting' or none as count parameter." if [ $# -eq 1 ]; then - property_get waiting | ( read -r _ _ waiting; printf " Waiting: %s\n" "${waiting}" ) - property_get displayed | ( read -r _ _ displayed; printf " Currently displayed: %s\n" "${displayed}" ) - property_get history | ( read -r _ _ history; printf " History: %s\n" "${history}") + property_get waitingLength | ( read -r _ _ waiting; printf " Waiting: %s\n" "${waiting}" ) + property_get displayedLength | ( read -r _ _ displayed; printf " Currently displayed: %s\n" "${displayed}" ) + property_get historyLength | ( read -r _ _ history; printf " History: %s\n" "${history}") else - property_get ${2} | ( read -r _ _ notifications; printf "%s\n" "${notifications}"; ) + property_get ${2}Length | ( read -r _ _ notifications; printf "%s\n" "${notifications}"; ) fi ;; "history-pop") diff --git a/src/dbus.c b/src/dbus.c index 9c05111..f19fdcf 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -85,9 +85,9 @@ static const char *introspection_xml = " " " " - " " - " " - " " + " " + " " + " " " " ""; @@ -601,13 +601,13 @@ GVariant *dbus_cb_dunst_Properties_Get(GDBusConnection *connection, if (STR_EQ(property_name, "paused")) { return g_variant_new_boolean(!status.running); - } else if (STR_EQ(property_name, "displayed")) { + } else if (STR_EQ(property_name, "displayedLength")) { unsigned int displayed = queues_length_displayed(); return g_variant_new_uint32(displayed); - } else if (STR_EQ(property_name, "history")) { + } else if (STR_EQ(property_name, "historyLength")) { unsigned int history = queues_length_history(); return g_variant_new_uint32(history); - } else if (STR_EQ(property_name, "waiting")) { + } else if (STR_EQ(property_name, "waitingLength")) { unsigned int waiting = queues_length_waiting(); return g_variant_new_uint32(waiting); } else {