From a8ccc2ac8e8e127b953319d8e1d190f469cbfd8f Mon Sep 17 00:00:00 2001 From: Ivan Krivosheev Date: Sun, 27 Mar 2022 21:13:10 +0300 Subject: [PATCH] Add timeout --- man/batify.1 | 2 ++ src/main.c | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/man/batify.1 b/man/batify.1 index 570580b..cf33b25 100644 --- a/man/batify.1 +++ b/man/batify.1 @@ -36,6 +36,8 @@ Default: 10%. Full capacity for battery. .br Default: 98%. +.IP "\fB-t\fR, \fB--timeout\fR" 5 +Notification timeout in seconds (-1 - default notification timeout, 0 - notification never expires) .SH EXAMPLES diff --git a/src/main.c b/src/main.c index 0353dfe..5d1c3ee 100644 --- a/src/main.c +++ b/src/main.c @@ -38,10 +38,11 @@ static struct config gint low_level; gint critical_level; gint full_capacity; + gint timeout; gboolean debug; } config = { - DEFAULT_INTERVAL, DEFAULT_LOW_LEVEL, DEFAULT_CRITICAL_LEVEL, - DEFAULT_FULL_CAPACITY, DEFAULT_DEBUG, + DEFAULT_INTERVAL, DEFAULT_LOW_LEVEL, DEFAULT_CRITICAL_LEVEL, + DEFAULT_FULL_CAPACITY, NOTIFY_EXPIRES_DEFAULT, DEFAULT_DEBUG, }; struct _Context @@ -92,6 +93,14 @@ static GOptionEntry option_entries[] = { "Critical battery level in percent", NULL }, { "full-capacity", 'f', 0, G_OPTION_ARG_INT, &config, "Full capacity for battery", NULL }, + { "timeout", + 't', + 0, + G_OPTION_ARG_INT, + &config.timeout, + "Notification timeout in seconds (-1 - default notification timeout, 0 - notification never " + "expires)", + NULL }, { NULL } }; @@ -194,7 +203,7 @@ battery_status_notification(const Battery* battery, get_battery_body_string(seconds), NOTIFY_URGENCY_NORMAL, percent, - NOTIFY_EXPIRES_DEFAULT); + config.timeout); } static void @@ -435,6 +444,10 @@ options_init(int argc, char* argv[]) return FALSE; } + if (config.timeout > 0) { + config.timeout *= 1000; + } + return TRUE; }