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 {
} else if (children.last ().data == noti) {
if (list_position > 0) list_position--;
}
close_notification (noti.param.applied_id);
close_notification (noti.param.applied_id, true);
}
break;
case "C":
......@@ -458,11 +458,11 @@ namespace SwayNotificationCenter {
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 ()) {
var noti = (Notification) w;
if (noti != null && noti.param.applied_id == id) {
if (replaces) {
if (!dismiss) {
noti.remove_noti_timeout ();
noti.destroy ();
} else {
......@@ -474,8 +474,22 @@ namespace SwayNotificationCenter {
}
}
public void add_notification (NotifyParams param,
NotiDaemon noti_daemon) {
public void replace_notification (uint32 id, NotifyParams new_params) {
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,
noti_daemon,
NotificationType.CONTROL_CENTER);
......
......@@ -62,9 +62,9 @@ namespace SwayNotificationCenter {
/** Method to close notification and send DISMISSED signal */
public void manually_close_notification (uint32 id, bool timeout)
throws DBusError, IOError {
NotificationWindow.instance.close_notification (id, false);
NotificationWindow.instance.close_notification (id, true);
if (!timeout) {
control_center.close_notification (id);
control_center.close_notification (id, true);
NotificationClosed (id, ClosedReasons.DISMISSED);
swaync_daemon.subscribe_v2 (control_center.notification_count (),
......@@ -170,11 +170,10 @@ namespace SwayNotificationCenter {
debug ("Notification: %s\n", param.to_string ());
// Replace notification logic
// Get the notification id to replace
uint32 replace_notification = 0;
if (id == replaces_id) {
param.replaces = true;
NotificationWindow.instance.close_notification (id, true);
control_center.close_notification (id, true);
replace_notification = id;
} else if (param.synchronous != null
&& param.synchronous.length > 0) {
// Tries replacing without replaces_id instead
......@@ -182,29 +181,38 @@ namespace SwayNotificationCenter {
// if there is any notification to replace
if (synchronous_ids.lookup_extended (
param.synchronous, null, out r_id)) {
param.replaces = true;
// Close the notification
NotificationWindow.instance.close_notification (r_id, true);
control_center.close_notification (r_id, true);
replace_notification = r_id;
}
synchronous_ids.set (param.synchronous, id);
}
// Only show popup notification if it is ENABLED or 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
if (param.urgency == UrgencyLevels.CRITICAL ||
(!dnd && !swaync_daemon.inhibited
&& param.urgency != UrgencyLevels.CRITICAL)) {
NotificationWindow.instance.add_notification (param, this);
&& (param.urgency == UrgencyLevels.CRITICAL
|| (!dnd && !swaync_daemon.inhibited && param.urgency != UrgencyLevels.CRITICAL))) {
if (replace_notification > 0) {
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
if (state != NotificationStatusEnum.IGNORED
&& state != NotificationStatusEnum.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
......@@ -292,8 +300,8 @@ namespace SwayNotificationCenter {
*/
[DBus (name = "CloseNotification")]
public void close_notification (uint32 id) throws DBusError, IOError {
NotificationWindow.instance.close_notification (id, false);
control_center.close_notification (id);
NotificationWindow.instance.close_notification (id, true);
control_center.close_notification (id, true);
NotificationClosed (id, ClosedReasons.CLOSED_BY_CLOSENOTIFICATION);
}
......
......@@ -112,9 +112,6 @@ namespace SwayNotificationCenter {
public Array<Action> actions { get; set; }
/** If the notification replaces another */
public bool replaces { get; set; }
public NotifyParams (uint32 applied_id,
string app_name,
uint32 replaces_id,
......@@ -134,7 +131,6 @@ namespace SwayNotificationCenter {
this.expire_timeout = expire_timeout;
this.time = (int64) (get_real_time () * 0.000001);
this.replaces = false;
this.has_synch = false;
parse_hints ();
......
......@@ -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
if (noti != null) {
#if HAVE_LATEST_GTK_LAYER_SHELL
......@@ -188,7 +188,7 @@ namespace SwayNotificationCenter {
noti.destroy ();
}
if (!replaces
if (dismiss
&& (!get_realized ()
|| !get_mapped ()
|| !(get_child () is Gtk.Widget)
......@@ -198,10 +198,9 @@ namespace SwayNotificationCenter {
}
}
public void add_notification (NotifyParams param,
NotiDaemon noti_daemon) {
public void add_notification (NotifyParams param) {
var noti = new Notification.timed (param,
noti_daemon,
swaync_daemon.noti_daemon,
NotificationType.POPUP,
ConfigModel.instance.timeout,
ConfigModel.instance.timeout_low,
......@@ -234,16 +233,31 @@ namespace SwayNotificationCenter {
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 ()) {
var noti = (Notification) w;
if (noti != null && noti.param.applied_id == id) {
remove_notification (noti, replaces);
remove_notification (noti, dismiss);
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 () {
List<weak Gtk.Widget> children = box.get_children ();
if (children.is_empty ()) return null;
......
......@@ -251,7 +251,7 @@ namespace SwayNotificationCenter {
/** Closes a specific notification with the `id` */
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