Skip to content

Commit

Permalink
Add timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
ikrivosheev committed Mar 27, 2022
1 parent fb7e287 commit a8ccc2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions man/batify.1
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 16 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
};

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -435,6 +444,10 @@ options_init(int argc, char* argv[])
return FALSE;
}

if (config.timeout > 0) {
config.timeout *= 1000;
}

return TRUE;
}

Expand Down

0 comments on commit a8ccc2a

Please sign in to comment.