tmisu

Notification to stdout daemon
git clone https://git.inz.fi/tmisu/
Log | Files | Refs | README | LICENSE

commit 1b874b4f34e4ec9d23ab5e94f55ffe731b10750e
parent 04744fff0daf3ddaf72ca2ff0cad0c42f33628c2
Author: Santtu Lakkala <inz@inz.fi>
Date:   Sat, 26 Feb 2022 12:42:35 +0200

Cleanup

Diffstat:
Msrc/tmisu.c | 48++++++++++++++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 14 deletions(-)

diff --git a/src/tmisu.c b/src/tmisu.c @@ -34,6 +34,7 @@ static DBusWatch *watches[MAX_WATCH] = { 0 }; static size_t nw = 1; static const char *delimiter = ", "; static int default_exp_timeout = 60; +static int need_dispatch = 0; int use_json = 0; int changed = 1; @@ -145,6 +146,15 @@ void remove_timeout(DBusTimeout *timeout, nt--; } +static void dispatch_status(DBusConnection *connection, + DBusDispatchStatus new_status, + void *data) +{ + (void)connection; + (void)data; + need_dispatch = (new_status == DBUS_DISPATCH_DATA_REMAINS); +} + void trigger_timeouts(void) { size_t i; @@ -499,6 +509,12 @@ int main(int argc, char **argv) { remove_timeout, toggle_timeout, NULL, NULL); + dbus_connection_set_dispatch_status_function(connection, + dispatch_status, + NULL, NULL); + dispatch_status(connection, + dbus_connection_get_dispatch_status(connection), + NULL); if (!connection) { @@ -537,22 +553,29 @@ int main(int argc, char **argv) { notif_check_expiry(); trigger_timeouts(); - nexp = notif_next_expiry(); - texp = timeout_next_expiry(); + if (!need_dispatch) { + nexp = notif_next_expiry(); + texp = timeout_next_expiry(); - if (changed) - notif_dump(); - changed = 0; + if (changed) + notif_dump(); + changed = 0; - if (nexp && (!texp || nexp <= texp)) - interval = (nexp - time(NULL)) * 1000; - else if (texp && (!nexp || texp < nexp)) - interval = (texp - time(NULL)) * 1000; - else - interval = -1; + if (nexp && (!texp || nexp <= texp)) + interval = (nexp - time(NULL)) * 1000; + else if (texp && (!nexp || texp < nexp)) + interval = (texp - time(NULL)) * 1000; + else + interval = -1; + } else { + interval = 0; + } int r = poll(pfdb, nw + 1, interval); + if (need_dispatch) + dbus_connection_dispatch(connection); + if (pfdb[0].revents) { char s; if (read(pfdb[0].fd, &s, 1) != 1) @@ -577,9 +600,6 @@ int main(int argc, char **argv) { toggle_watch(watches[i], NULL); r--; } - - while (dbus_connection_get_dispatch_status(connection) == DBUS_DISPATCH_DATA_REMAINS) - dbus_connection_dispatch(connection); } dbus_bus_release_name(connection, "org.freedesktop.Notifications", NULL);