Fixed notification overlays over each other
This commit is contained in:
@@ -6,14 +6,16 @@ namespace SwayNotificatonCenter {
|
|||||||
private bool dnd = false;
|
private bool dnd = false;
|
||||||
|
|
||||||
private DBusInit dbusInit;
|
private DBusInit dbusInit;
|
||||||
|
private NotiWindow notiWindow;
|
||||||
|
|
||||||
public NotiDaemon (DBusInit dbusInit) {
|
public NotiDaemon (DBusInit dbusInit) {
|
||||||
this.dbusInit = dbusInit;
|
this.dbusInit = dbusInit;
|
||||||
|
this.notiWindow = new NotiWindow (this.dbusInit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set_noti_window_visibility (bool value)
|
public void set_noti_window_visibility (bool value)
|
||||||
throws DBusError, IOError {
|
throws DBusError, IOError {
|
||||||
NotiWindow.instance (dbusInit).change_visibility (value);
|
notiWindow.change_visibility (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public uint32 Notify (string app_name,
|
public uint32 Notify (string app_name,
|
||||||
@@ -40,14 +42,13 @@ namespace SwayNotificatonCenter {
|
|||||||
expire_timeout);
|
expire_timeout);
|
||||||
|
|
||||||
if (id == replaces_id) {
|
if (id == replaces_id) {
|
||||||
NotiWindow.instance (dbusInit).close_notification (id);
|
notiWindow.close_notification (id);
|
||||||
dbusInit.ccDaemon.close_notification (id);
|
dbusInit.ccDaemon.close_notification (id);
|
||||||
}
|
}
|
||||||
if (!dbusInit.ccDaemon.get_visibility ()) {
|
if (!dbusInit.ccDaemon.get_visibility ()) {
|
||||||
if (param.urgency == UrgencyLevels.CRITICAL ||
|
if (param.urgency == UrgencyLevels.CRITICAL ||
|
||||||
(!dnd && param.urgency != UrgencyLevels.CRITICAL)) {
|
(!dnd && param.urgency != UrgencyLevels.CRITICAL)) {
|
||||||
NotiWindow.instance (dbusInit)
|
notiWindow.add_notification (param, this);
|
||||||
.add_notification (param, this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbusInit.ccDaemon.add_notification (param);
|
dbusInit.ccDaemon.add_notification (param);
|
||||||
@@ -72,17 +73,17 @@ namespace SwayNotificatonCenter {
|
|||||||
|
|
||||||
public void click_close_notification (uint32 id)
|
public void click_close_notification (uint32 id)
|
||||||
throws DBusError, IOError {
|
throws DBusError, IOError {
|
||||||
NotiWindow.instance (dbusInit).close_notification (id);
|
notiWindow.close_notification (id);
|
||||||
dbusInit.ccDaemon.close_notification (id);
|
dbusInit.ccDaemon.close_notification (id);
|
||||||
NotificationClosed (id, ClosedReasons.DISMISSED);
|
NotificationClosed (id, ClosedReasons.DISMISSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close_all_notifications () throws DBusError, IOError {
|
public void close_all_notifications () throws DBusError, IOError {
|
||||||
NotiWindow.instance (dbusInit).close_all_notifications ();
|
notiWindow.close_all_notifications ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CloseNotification (uint32 id) throws DBusError, IOError {
|
public void CloseNotification (uint32 id) throws DBusError, IOError {
|
||||||
NotiWindow.instance (dbusInit).close_notification (id);
|
notiWindow.close_notification (id);
|
||||||
dbusInit.ccDaemon.close_notification (id);
|
dbusInit.ccDaemon.close_notification (id);
|
||||||
NotificationClosed (id, ClosedReasons.CLOSED_BY_CLOSENOTIFICATION);
|
NotificationClosed (id, ClosedReasons.CLOSED_BY_CLOSENOTIFICATION);
|
||||||
}
|
}
|
||||||
|
@@ -2,8 +2,9 @@
|
|||||||
<!-- Generated with glade 3.38.2 -->
|
<!-- Generated with glade 3.38.2 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.24"/>
|
<requires lib="gtk+" version="3.24"/>
|
||||||
<template class="SwayNotificatonCenterNotiWindow" parent="GtkApplicationWindow">
|
<template class="SwayNotificatonCenterNotificationWindow" parent="GtkApplicationWindow">
|
||||||
<property name="can-focus">False</property>
|
<property name="can-focus">False</property>
|
||||||
|
<property name="role">NotificationWindow</property>
|
||||||
<property name="resizable">False</property>
|
<property name="resizable">False</property>
|
||||||
<property name="default-width">500</property>
|
<property name="default-width">500</property>
|
||||||
<property name="type-hint">notification</property>
|
<property name="type-hint">notification</property>
|
||||||
|
@@ -1,28 +1,50 @@
|
|||||||
namespace SwayNotificatonCenter {
|
namespace SwayNotificatonCenter {
|
||||||
[GtkTemplate (ui = "/org/erikreider/sway-notification-center/notiWindow/notiWindow.ui")]
|
public class NotiWindow {
|
||||||
public class NotiWindow : Gtk.ApplicationWindow {
|
private DBusInit dbusInit;
|
||||||
|
private NotificationWindow notis = new NotificationWindow ();
|
||||||
|
|
||||||
private static NotiWindow _noti_window = null;
|
private unowned NotificationWindow notificationWindow {
|
||||||
|
get {
|
||||||
public static NotiWindow instance (DBusInit dbusInit) {
|
if (!notis.get_realized ()) notis = new NotificationWindow ();
|
||||||
if (_noti_window == null) _noti_window = new NotiWindow (dbusInit);
|
return notis;
|
||||||
return _noti_window;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotiWindow (DBusInit dbusInit) {
|
||||||
|
this.dbusInit = dbusInit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void change_visibility (bool value) {
|
||||||
|
notificationWindow.change_visibility (value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close_all_notifications () {
|
||||||
|
notificationWindow.close_all_notifications ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add_notification (NotifyParams param,
|
||||||
|
NotiDaemon notiDaemon) {
|
||||||
|
notificationWindow.add_notification (param, notiDaemon);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close_notification (uint32 id) {
|
||||||
|
notificationWindow.close_notification (id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[GtkTemplate (ui = "/org/erikreider/sway-notification-center/notiWindow/notiWindow.ui")]
|
||||||
|
private class NotificationWindow : Gtk.ApplicationWindow {
|
||||||
|
|
||||||
[GtkChild]
|
[GtkChild]
|
||||||
unowned Gtk.Viewport viewport;
|
unowned Gtk.Viewport viewport;
|
||||||
[GtkChild]
|
[GtkChild]
|
||||||
unowned Gtk.Box box;
|
unowned Gtk.Box box;
|
||||||
|
|
||||||
private DBusInit dbusInit;
|
|
||||||
|
|
||||||
private bool list_reverse = false;
|
private bool list_reverse = false;
|
||||||
|
|
||||||
private double last_upper = 0;
|
private double last_upper = 0;
|
||||||
|
|
||||||
private NotiWindow (DBusInit dbusInit) {
|
public NotificationWindow () {
|
||||||
this.dbusInit = dbusInit;
|
|
||||||
|
|
||||||
GtkLayerShell.init_for_window (this);
|
GtkLayerShell.init_for_window (this);
|
||||||
GtkLayerShell.set_layer (this, GtkLayerShell.Layer.OVERLAY);
|
GtkLayerShell.set_layer (this, GtkLayerShell.Layer.OVERLAY);
|
||||||
this.set_anchor ();
|
this.set_anchor ();
|
||||||
@@ -84,7 +106,6 @@ namespace SwayNotificatonCenter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void change_visibility (bool value) {
|
public void change_visibility (bool value) {
|
||||||
this.set_visible (value);
|
|
||||||
if (!value) {
|
if (!value) {
|
||||||
close_all_notifications ();
|
close_all_notifications ();
|
||||||
} else {
|
} else {
|
||||||
@@ -93,26 +114,20 @@ namespace SwayNotificatonCenter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void close_all_notifications () {
|
public void close_all_notifications () {
|
||||||
|
if (!this.get_realized ()) return;
|
||||||
foreach (var w in box.get_children ()) {
|
foreach (var w in box.get_children ()) {
|
||||||
var noti = (Notification) w;
|
remove_notification ((Notification) w);
|
||||||
if (noti != null) remove_notification (noti);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void remove_notification (Notification noti) {
|
private void remove_notification (Notification noti) {
|
||||||
if (_noti_window == null) return;
|
// Remove notification
|
||||||
if (box.get_children ().index (noti) >= 0) {
|
if (noti != null) {
|
||||||
if (noti != null) box.remove (noti);
|
noti.destroy ();
|
||||||
}
|
|
||||||
if (box.get_children ().length () == 0) {
|
|
||||||
// Hack to close and recreate the window
|
|
||||||
// Fixes notifications enter_notify_event still being active
|
|
||||||
// when closed
|
|
||||||
this.close ();
|
|
||||||
this.destroy ();
|
|
||||||
this.dispose ();
|
|
||||||
_noti_window = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.get_realized ()) return;
|
||||||
|
if (box.get_children ().length () == 0) this.close ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add_notification (NotifyParams param,
|
public void add_notification (NotifyParams param,
|
||||||
|
Reference in New Issue
Block a user