Configurable critical notification timeout (#40)

I think there was also a logic error related to setting an expiry
timeout.

It was only set if `params.expire_timeout` was not `0`, instead of
checking that both the user configured timeout and the one requested was
set to `0`.
This commit is contained in:
Nicolas Berbiche 2021-12-23 15:22:43 -05:00 committed by GitHub
parent 9fb9ffa54f
commit a41f2b6e56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 4 deletions

View File

@ -88,6 +88,7 @@ To reload the config, you'll need to run `swaync-client --reload-config`
- `positionY`: `top` or `bottom`
- `timeout`: uint (Any positive number). The notification timeout for notifications with normal priority
- `timeout-low`: uint (any positive number without decimals). The notification timeout for notifications with low priority
- `timeout-critical`: uint (any positive number without decimals, 0 to disable). The notification timeout for notifications with critical priority
- `keyboard-shortcuts`: `true` or `false`. If control center should use keyboard shortcuts
- `image-visibility`: `always`, `when-available` or `never`. Notification image visiblilty
- `transition-time`: uint (Any positive number, 0 to disable). The notification animation duration

View File

@ -3,6 +3,7 @@
"positionY": "top",
"timeout": 10,
"timeout-low": 5,
"timeout-critical": 0,
"keyboard-shortcuts": true,
"image-visibility": "always",
"transition-time": 200

View File

@ -119,6 +119,18 @@ namespace SwayNotificatonCenter {
}
}
/** The timeout for notifications with CRITICAL priority */
private const int _timeout_critical_def = 0;
private int _timeout_critical = _timeout_critical_def;
public int timeout_critical {
get {
return _timeout_critical;
}
set {
_timeout_critical = value < 0 ? _timeout_critical_def : value;
}
}
/*
* Specifies if the control center should use keyboard shortcuts
* and block keyboard input for other applications while open

View File

@ -131,7 +131,8 @@ namespace SwayNotificatonCenter {
var noti = new Notification.timed (param,
notiDaemon,
ConfigModel.instance.timeout,
ConfigModel.instance.timeout_low);
ConfigModel.instance.timeout_low,
ConfigModel.instance.timeout_critical);
if (list_reverse) {
box.pack_start (noti);

View File

@ -41,6 +41,7 @@ namespace SwayNotificatonCenter {
private uint timeout_delay;
private uint timeout_low_delay;
private int transition_time;
private uint timeout_critical_delay;
private int carpusel_empty_widget_index = 0;
@ -54,10 +55,12 @@ namespace SwayNotificatonCenter {
public Notification.timed (NotifyParams param,
NotiDaemon notiDaemon,
uint timeout,
uint timeout_low) {
uint timeout_low,
uint timeout_critical) {
this.is_timed = true;
this.timeout_delay = timeout;
this.timeout_low_delay = timeout_low;
this.timeout_critical_delay = timeout_critical;
build_noti (param, notiDaemon);
add_noti_timeout ();
}
@ -366,10 +369,14 @@ namespace SwayNotificatonCenter {
timeout = timeout_delay * 1000;
break;
case UrgencyLevels.CRITICAL:
return;
if (timeout_critical_delay == 0) {
return;
}
timeout = timeout_critical_delay * 1000;
break;
}
uint ms = param.expire_timeout > 0 ? param.expire_timeout : timeout;
if (param.expire_timeout != 0) {
if (ms != 0) {
timeout_id = Timeout.add (ms, () => {
close_notification (true);
return GLib.Source.REMOVE;