Skip to content

Commit a8ccc2a

Browse files
committed
Add timeout
1 parent fb7e287 commit a8ccc2a

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

man/batify.1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Default: 10%.
3636
Full capacity for battery.
3737
.br
3838
Default: 98%.
39+
.IP "\fB-t\fR, \fB--timeout\fR" 5
40+
Notification timeout in seconds (-1 - default notification timeout, 0 - notification never expires)
3941

4042
.SH EXAMPLES
4143

src/main.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ static struct config
3838
gint low_level;
3939
gint critical_level;
4040
gint full_capacity;
41+
gint timeout;
4142
gboolean debug;
4243
} config = {
43-
DEFAULT_INTERVAL, DEFAULT_LOW_LEVEL, DEFAULT_CRITICAL_LEVEL,
44-
DEFAULT_FULL_CAPACITY, DEFAULT_DEBUG,
44+
DEFAULT_INTERVAL, DEFAULT_LOW_LEVEL, DEFAULT_CRITICAL_LEVEL,
45+
DEFAULT_FULL_CAPACITY, NOTIFY_EXPIRES_DEFAULT, DEFAULT_DEBUG,
4546
};
4647

4748
struct _Context
@@ -92,6 +93,14 @@ static GOptionEntry option_entries[] = {
9293
"Critical battery level in percent",
9394
NULL },
9495
{ "full-capacity", 'f', 0, G_OPTION_ARG_INT, &config, "Full capacity for battery", NULL },
96+
{ "timeout",
97+
't',
98+
0,
99+
G_OPTION_ARG_INT,
100+
&config.timeout,
101+
"Notification timeout in seconds (-1 - default notification timeout, 0 - notification never "
102+
"expires)",
103+
NULL },
95104
{ NULL }
96105
};
97106

@@ -194,7 +203,7 @@ battery_status_notification(const Battery* battery,
194203
get_battery_body_string(seconds),
195204
NOTIFY_URGENCY_NORMAL,
196205
percent,
197-
NOTIFY_EXPIRES_DEFAULT);
206+
config.timeout);
198207
}
199208

200209
static void
@@ -435,6 +444,10 @@ options_init(int argc, char* argv[])
435444
return FALSE;
436445
}
437446

447+
if (config.timeout > 0) {
448+
config.timeout *= 1000;
449+
}
450+
438451
return TRUE;
439452
}
440453

0 commit comments

Comments
 (0)