diff --git a/config.h b/config.h index 40207a3..42de31d 100644 --- a/config.h +++ b/config.h @@ -12,7 +12,7 @@ struct settings defaults = { .lowfgcolor = "#000000", .format = "%s %b", /* default format */ -.timeouts = { 10*G_USEC_PER_SEC, 10*G_USEC_PER_SEC, 0 }, /* low, normal, critical */ +.timeouts = { S2US(10), S2US(10), S2US(0) }, /* low, normal, critical */ .icons = { "dialog-information", "dialog-information", "dialog-warning" }, /* low, normal, critical */ .transparency = 0, /* transparency */ diff --git a/src/dunst.c b/src/dunst.c index 1449a43..88031e8 100644 --- a/src/dunst.c +++ b/src/dunst.c @@ -156,7 +156,7 @@ int dunst_main(int argc, char *argv[]) n->summary = g_strdup("startup"); n->body = g_strdup("dunst is up and running"); n->progress = -1; - n->timeout = 10 * G_USEC_PER_SEC; + n->timeout = S2US(10); n->markup = MARKUP_NO; n->urgency = URG_LOW; notification_init(n); diff --git a/src/queues.c b/src/queues.c index c90faf2..9f292ff 100644 --- a/src/queues.c +++ b/src/queues.c @@ -490,7 +490,7 @@ gint64 queues_get_next_datachange(gint64 time) if (age > settings.show_age_threshold) // sleep exactly until the next shift of the second happens - sleep = MIN(sleep, ((G_USEC_PER_SEC) - (age % (G_USEC_PER_SEC)))); + sleep = MIN(sleep, (S2US(1) - (age % S2US(1)))); else if (n->timeout == 0 || ttl > settings.show_age_threshold) sleep = MIN(sleep, settings.show_age_threshold); } diff --git a/src/utils.c b/src/utils.c index 22a0c50..4dcffa5 100644 --- a/src/utils.c +++ b/src/utils.c @@ -170,7 +170,7 @@ gint64 string_to_time(const char *string) LOG_W("Time: '%s': Unknown error.", string); return 0; } else if (errno == 0 && !*endptr) { - return val * G_USEC_PER_SEC; + return S2US(val); } // endptr may point to a separating space @@ -180,13 +180,13 @@ gint64 string_to_time(const char *string) if (STRN_EQ(endptr, "ms", 2)) return val * 1000; else if (STRN_EQ(endptr, "s", 1)) - return val * G_USEC_PER_SEC; + return S2US(val); else if (STRN_EQ(endptr, "m", 1)) - return val * G_USEC_PER_SEC * 60; + return S2US(val) * 60; else if (STRN_EQ(endptr, "h", 1)) - return val * G_USEC_PER_SEC * 60 * 60; + return S2US(val) * 60 * 60; else if (STRN_EQ(endptr, "d", 1)) - return val * G_USEC_PER_SEC * 60 * 60 * 24; + return S2US(val) * 60 * 60 * 24; else return 0; } @@ -205,7 +205,6 @@ gint64 time_monotonic_now(void) #else clock_gettime(CLOCK_MONOTONIC, &tv_now); #endif - return (gint64)tv_now.tv_sec * G_USEC_PER_SEC - + tv_now.tv_nsec / 1000; + return S2US(tv_now.tv_sec) + tv_now.tv_nsec / 1000; } /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/src/utils.h b/src/utils.h index b77fa28..6b8a7a7 100644 --- a/src/utils.h +++ b/src/utils.h @@ -16,6 +16,9 @@ //! Test if string a and b are the same case-insensitively #define STR_CASEQ(a, b) (strcasecmp(a, b) == 0) +//! Convert a second into the internal time representation +#define S2US(s) (((gint64)(s)) * 1000 * 1000) + /** * Replaces all occurrences of the char \p needle with the char \p replacement in \p haystack. *