Unverified Commit 0d368c2f authored by Erik Reider's avatar Erik Reider Committed by GitHub

Remove notification replace flicker (#320)

parent 7de2c71b
...@@ -174,7 +174,7 @@ namespace SwayNotificationCenter { ...@@ -174,7 +174,7 @@ namespace SwayNotificationCenter {
} else if (children.last ().data == noti) { } else if (children.last ().data == noti) {
if (list_position > 0) list_position--; if (list_position > 0) list_position--;
} }
close_notification (noti.param.applied_id); close_notification (noti.param.applied_id, true);
} }
break; break;
case "C": case "C":
...@@ -458,11 +458,11 @@ namespace SwayNotificationCenter { ...@@ -458,11 +458,11 @@ namespace SwayNotificationCenter {
on_visibility_change (); on_visibility_change ();
} }
public void close_notification (uint32 id, bool replaces = false) { public void close_notification (uint32 id, bool dismiss) {
foreach (var w in list_box.get_children ()) { foreach (var w in list_box.get_children ()) {
var noti = (Notification) w; var noti = (Notification) w;
if (noti != null && noti.param.applied_id == id) { if (noti != null && noti.param.applied_id == id) {
if (replaces) { if (!dismiss) {
noti.remove_noti_timeout (); noti.remove_noti_timeout ();
noti.destroy (); noti.destroy ();
} else { } else {
...@@ -474,8 +474,22 @@ namespace SwayNotificationCenter { ...@@ -474,8 +474,22 @@ namespace SwayNotificationCenter {
} }
} }
public void add_notification (NotifyParams param, public void replace_notification (uint32 id, NotifyParams new_params) {
NotiDaemon noti_daemon) { foreach (var w in list_box.get_children ()) {
var noti = (Notification) w;
if (noti != null && noti.param.applied_id == id) {
noti.replace_notification (new_params);
// Position the notification in the beginning of the list
list_box.invalidate_sort ();
return;
}
}
// Add a new notification if the old one isn't visible
add_notification (new_params);
}
public void add_notification (NotifyParams param) {
var noti = new Notification.regular (param, var noti = new Notification.regular (param,
noti_daemon, noti_daemon,
NotificationType.CONTROL_CENTER); NotificationType.CONTROL_CENTER);
......
...@@ -62,9 +62,9 @@ namespace SwayNotificationCenter { ...@@ -62,9 +62,9 @@ namespace SwayNotificationCenter {
/** Method to close notification and send DISMISSED signal */ /** Method to close notification and send DISMISSED signal */
public void manually_close_notification (uint32 id, bool timeout) public void manually_close_notification (uint32 id, bool timeout)
throws DBusError, IOError { throws DBusError, IOError {
NotificationWindow.instance.close_notification (id, false); NotificationWindow.instance.close_notification (id, true);
if (!timeout) { if (!timeout) {
control_center.close_notification (id); control_center.close_notification (id, true);
NotificationClosed (id, ClosedReasons.DISMISSED); NotificationClosed (id, ClosedReasons.DISMISSED);
swaync_daemon.subscribe_v2 (control_center.notification_count (), swaync_daemon.subscribe_v2 (control_center.notification_count (),
...@@ -170,11 +170,10 @@ namespace SwayNotificationCenter { ...@@ -170,11 +170,10 @@ namespace SwayNotificationCenter {
debug ("Notification: %s\n", param.to_string ()); debug ("Notification: %s\n", param.to_string ());
// Replace notification logic // Get the notification id to replace
uint32 replace_notification = 0;
if (id == replaces_id) { if (id == replaces_id) {
param.replaces = true; replace_notification = id;
NotificationWindow.instance.close_notification (id, true);
control_center.close_notification (id, true);
} else if (param.synchronous != null } else if (param.synchronous != null
&& param.synchronous.length > 0) { && param.synchronous.length > 0) {
// Tries replacing without replaces_id instead // Tries replacing without replaces_id instead
...@@ -182,29 +181,38 @@ namespace SwayNotificationCenter { ...@@ -182,29 +181,38 @@ namespace SwayNotificationCenter {
// if there is any notification to replace // if there is any notification to replace
if (synchronous_ids.lookup_extended ( if (synchronous_ids.lookup_extended (
param.synchronous, null, out r_id)) { param.synchronous, null, out r_id)) {
param.replaces = true; replace_notification = r_id;
// Close the notification
NotificationWindow.instance.close_notification (r_id, true);
control_center.close_notification (r_id, true);
} }
synchronous_ids.set (param.synchronous, id); synchronous_ids.set (param.synchronous, id);
} }
// Only show popup notification if it is ENABLED or TRANSIENT // Only show popup notification if it is ENABLED or TRANSIENT
if ((state == NotificationStatusEnum.ENABLED || state == NotificationStatusEnum.TRANSIENT) if ((state == NotificationStatusEnum.ENABLED || state == NotificationStatusEnum.TRANSIENT)
&& !control_center.get_visibility ()) { && !control_center.get_visibility ()
// Also check if urgency is Critical and not inhibited and dnd // Also check if urgency is Critical and not inhibited and dnd
if (param.urgency == UrgencyLevels.CRITICAL || && (param.urgency == UrgencyLevels.CRITICAL
(!dnd && !swaync_daemon.inhibited || (!dnd && !swaync_daemon.inhibited && param.urgency != UrgencyLevels.CRITICAL))) {
&& param.urgency != UrgencyLevels.CRITICAL)) { if (replace_notification > 0) {
NotificationWindow.instance.add_notification (param, this); NotificationWindow.instance.replace_notification (replace_notification, param);
} else {
NotificationWindow.instance.add_notification (param);
} }
} else if (replace_notification > 0) {
// Remove the old notification due to it not being replaced
NotificationWindow.instance.close_notification (replace_notification, false);
} }
// Only add notification to CC if it isn't IGNORED and not transient/TRANSIENT // Only add notification to CC if it isn't IGNORED and not transient/TRANSIENT
if (state != NotificationStatusEnum.IGNORED if (state != NotificationStatusEnum.IGNORED
&& state != NotificationStatusEnum.TRANSIENT && state != NotificationStatusEnum.TRANSIENT
&& !param.transient) { && !param.transient) {
control_center.add_notification (param, this); if (replace_notification > 0) {
control_center.replace_notification (replace_notification, param);
} else {
control_center.add_notification (param);
}
} else if (replace_notification > 0) {
// Remove the old notification due to it not being replaced
control_center.close_notification (replace_notification, false);
} }
#if WANT_SCRIPTING #if WANT_SCRIPTING
...@@ -292,8 +300,8 @@ namespace SwayNotificationCenter { ...@@ -292,8 +300,8 @@ namespace SwayNotificationCenter {
*/ */
[DBus (name = "CloseNotification")] [DBus (name = "CloseNotification")]
public void close_notification (uint32 id) throws DBusError, IOError { public void close_notification (uint32 id) throws DBusError, IOError {
NotificationWindow.instance.close_notification (id, false); NotificationWindow.instance.close_notification (id, true);
control_center.close_notification (id); control_center.close_notification (id, true);
NotificationClosed (id, ClosedReasons.CLOSED_BY_CLOSENOTIFICATION); NotificationClosed (id, ClosedReasons.CLOSED_BY_CLOSENOTIFICATION);
} }
......
...@@ -112,9 +112,6 @@ namespace SwayNotificationCenter { ...@@ -112,9 +112,6 @@ namespace SwayNotificationCenter {
public Array<Action> actions { get; set; } public Array<Action> actions { get; set; }
/** If the notification replaces another */
public bool replaces { get; set; }
public NotifyParams (uint32 applied_id, public NotifyParams (uint32 applied_id,
string app_name, string app_name,
uint32 replaces_id, uint32 replaces_id,
...@@ -134,7 +131,6 @@ namespace SwayNotificationCenter { ...@@ -134,7 +131,6 @@ namespace SwayNotificationCenter {
this.expire_timeout = expire_timeout; this.expire_timeout = expire_timeout;
this.time = (int64) (get_real_time () * 0.000001); this.time = (int64) (get_real_time () * 0.000001);
this.replaces = false;
this.has_synch = false; this.has_synch = false;
parse_hints (); parse_hints ();
......
...@@ -170,7 +170,7 @@ namespace SwayNotificationCenter { ...@@ -170,7 +170,7 @@ namespace SwayNotificationCenter {
} }
} }
private void remove_notification (Notification ? noti, bool replaces) { private void remove_notification (Notification ? noti, bool dismiss) {
// Remove notification and its destruction timeout // Remove notification and its destruction timeout
if (noti != null) { if (noti != null) {
#if HAVE_LATEST_GTK_LAYER_SHELL #if HAVE_LATEST_GTK_LAYER_SHELL
...@@ -188,7 +188,7 @@ namespace SwayNotificationCenter { ...@@ -188,7 +188,7 @@ namespace SwayNotificationCenter {
noti.destroy (); noti.destroy ();
} }
if (!replaces if (dismiss
&& (!get_realized () && (!get_realized ()
|| !get_mapped () || !get_mapped ()
|| !(get_child () is Gtk.Widget) || !(get_child () is Gtk.Widget)
...@@ -198,10 +198,9 @@ namespace SwayNotificationCenter { ...@@ -198,10 +198,9 @@ namespace SwayNotificationCenter {
} }
} }
public void add_notification (NotifyParams param, public void add_notification (NotifyParams param) {
NotiDaemon noti_daemon) {
var noti = new Notification.timed (param, var noti = new Notification.timed (param,
noti_daemon, swaync_daemon.noti_daemon,
NotificationType.POPUP, NotificationType.POPUP,
ConfigModel.instance.timeout, ConfigModel.instance.timeout,
ConfigModel.instance.timeout_low, ConfigModel.instance.timeout_low,
...@@ -234,16 +233,31 @@ namespace SwayNotificationCenter { ...@@ -234,16 +233,31 @@ namespace SwayNotificationCenter {
scroll_to_start (list_reverse); scroll_to_start (list_reverse);
} }
public void close_notification (uint32 id, bool replaces) { public void close_notification (uint32 id, bool dismiss) {
foreach (var w in box.get_children ()) { foreach (var w in box.get_children ()) {
var noti = (Notification) w; var noti = (Notification) w;
if (noti != null && noti.param.applied_id == id) { if (noti != null && noti.param.applied_id == id) {
remove_notification (noti, replaces); remove_notification (noti, dismiss);
break; break;
} }
} }
} }
public void replace_notification (uint32 id, NotifyParams new_params) {
foreach (var w in box.get_children ()) {
var noti = (Notification) w;
if (noti != null && noti.param.applied_id == id) {
noti.replace_notification (new_params);
// Position the notification in the beginning of the list
box.reorder_child (noti, (int) box.get_children ().length ());
return;
}
}
// Display a new notification if the old one isn't visible
add_notification (new_params);
}
public uint32 ? get_latest_notification () { public uint32 ? get_latest_notification () {
List<weak Gtk.Widget> children = box.get_children (); List<weak Gtk.Widget> children = box.get_children ();
if (children.is_empty ()) return null; if (children.is_empty ()) return null;
......
...@@ -251,7 +251,7 @@ namespace SwayNotificationCenter { ...@@ -251,7 +251,7 @@ namespace SwayNotificationCenter {
/** Closes a specific notification with the `id` */ /** Closes a specific notification with the `id` */
public void close_notification (uint32 id) throws DBusError, IOError { public void close_notification (uint32 id) throws DBusError, IOError {
noti_daemon.control_center.close_notification (id); noti_daemon.control_center.close_notification (id, true);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment