Skip to content

Commit dc23a83

Browse files
committed
implement notification time freezing
1 parent e124c66 commit dc23a83

File tree

6 files changed

+60
-9
lines changed

6 files changed

+60
-9
lines changed

config.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ void init_default_style(struct mako_style *style) {
105105
style->actions = true;
106106
style->default_timeout = 0;
107107
style->ignore_timeout = false;
108+
style->freeze = false;
108109

109110
style->colors.background = 0x285577FF;
110111
style->colors.text = 0xFFFFFFFF;
@@ -301,6 +302,11 @@ bool apply_style(struct mako_style *target, const struct mako_style *style) {
301302
target->spec.ignore_timeout = true;
302303
}
303304

305+
if (style->spec.freeze) {
306+
target->freeze = style->freeze;
307+
target->spec.freeze = true;
308+
}
309+
304310
if (style->spec.colors.background) {
305311
target->colors.background = style->colors.background;
306312
target->spec.colors.background = true;
@@ -623,6 +629,8 @@ static bool apply_style_option(struct mako_style *style, const char *name,
623629
} else if (strcmp(name, "ignore-timeout") == 0) {
624630
return spec->ignore_timeout =
625631
parse_boolean(value, &style->ignore_timeout);
632+
} else if (strcmp(name, "freeze") == 0) {
633+
return spec->freeze = parse_boolean(value, &style->freeze);
626634
} else if (strcmp(name, "group-by") == 0) {
627635
return spec->group_criteria_spec =
628636
parse_criteria_spec(value, &style->group_criteria_spec);

criteria.c

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,21 +418,39 @@ struct mako_criteria *global_criteria(struct mako_config *config) {
418418
return criteria;
419419
}
420420

421-
static void timespec_add(struct timespec *t, int delta_ms) {
422-
static const long ms = 1000000, s = 1000000000;
421+
static void timespec_from_ms(struct timespec *t, long time_ms) {
422+
static const long ms = 1000000;
423423

424-
int delta_ms_low = delta_ms % 1000;
425-
int delta_s_high = delta_ms / 1000;
424+
t->tv_sec = time_ms / 1000;
425+
t->tv_nsec = (time_ms % 1000) * ms;
426+
}
427+
428+
static void timespec_add(struct timespec *t, struct timespec *u) {
429+
static const long s = 1000000000;
426430

427-
t->tv_sec += delta_s_high;
431+
t->tv_sec += u->tv_sec;
432+
t->tv_nsec += u->tv_nsec;
428433

429-
t->tv_nsec += (long)delta_ms_low * ms;
430434
if (t->tv_nsec >= s) {
431435
t->tv_nsec -= s;
432436
++t->tv_sec;
433437
}
434438
}
435439

440+
static void timespec_sub(struct timespec *t, struct timespec *u) {
441+
static const long s = 1000000000;
442+
443+
t->tv_sec -= u->tv_sec;
444+
t->tv_nsec += s;
445+
t->tv_nsec -= u->tv_nsec;
446+
447+
if (t->tv_nsec >= s) {
448+
t->tv_nsec -= s;
449+
} else {
450+
--t->tv_sec;
451+
}
452+
}
453+
436454
static void handle_notification_timer(void *data) {
437455
struct mako_notification *notif = data;
438456
struct mako_surface *surface = notif->surface;
@@ -474,10 +492,25 @@ ssize_t apply_each_criteria(struct mako_state *state, struct mako_notification *
474492
if (expire_timeout < 0 || notif->style.ignore_timeout) {
475493
expire_timeout = notif->style.default_timeout;
476494
}
495+
if (notif->frozen != notif->style.freeze) {
496+
struct timespec now;
497+
clock_gettime(CLOCK_MONOTONIC, &now);
498+
if (notif->style.freeze) {
499+
notif->froze_at = now;
500+
} else {
501+
timespec_sub(&now, &notif->froze_at);
502+
timespec_add(&notif->at, &now);
503+
}
504+
notif->frozen = notif->style.freeze;
505+
}
506+
if (notif->frozen) {
507+
expire_timeout = 0;
508+
}
477509

478510
if (expire_timeout > 0) {
479-
struct timespec at = notif->at;
480-
timespec_add(&at, expire_timeout);
511+
struct timespec at = notif->at, delta;
512+
timespec_from_ms(&delta, expire_timeout);
513+
timespec_add(&at, &delta);
481514
if (notif->timer) {
482515
notif->timer->at = at;
483516
} else {

doc/mako.5.scd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,12 @@ associated command-line option.
408408

409409
Default: 0
410410

411+
*freeze*=0|1
412+
Whether to freeze this notification's active timeout, stopping it from
413+
progressing. This can be used for pausing notifications while you're away.
414+
415+
Default: 0
416+
411417
# COLORS
412418

413419
Colors can be specified as _#RRGGBB_ or _#RRGGBBAA_.

include/config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct mako_style_spec {
4242
bool width, height, outer_margin, margin, padding, border_size, border_radius, font,
4343
markup, format, text_alignment, actions, default_timeout, ignore_timeout,
4444
icons, max_icon_size, icon_path, group_criteria_spec, invisible, history,
45-
icon_location, max_visible, layer, output, anchor;
45+
icon_location, max_visible, layer, output, anchor, freeze;
4646
struct {
4747
bool background, text, border, progress;
4848
} colors;
@@ -76,6 +76,7 @@ struct mako_style {
7676
bool actions;
7777
int default_timeout; // in ms
7878
bool ignore_timeout;
79+
bool freeze;
7980

8081
struct {
8182
uint32_t background;

include/notification.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ struct mako_notification {
4949
struct mako_hotspot hotspot;
5050
struct mako_timer *timer;
5151
struct timespec at;
52+
struct timespec froze_at;
53+
bool frozen;
5254
};
5355

5456
struct mako_action {

notification.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void reset_notification(struct mako_notification *notif) {
6868
notif->icon = NULL;
6969

7070
clock_gettime(CLOCK_MONOTONIC, &notif->at);
71+
notif->frozen = false;
7172
}
7273

7374
struct mako_notification *create_notification(struct mako_state *state) {

0 commit comments

Comments
 (0)