diff --git a/src/controlCenter/controlCenter.vala b/src/controlCenter/controlCenter.vala index e73e199..d792a5a 100644 --- a/src/controlCenter/controlCenter.vala +++ b/src/controlCenter/controlCenter.vala @@ -9,20 +9,6 @@ namespace SwayNotificatonCenter { cc = new ControlCenterWidget (); } - public void close_notification (uint32 id) throws DBusError, IOError { - try { - foreach (NotifyParams n in dbusInit.notifications) { - if (n.applied_id == id) { - dbusInit.notifications.remove (n); - update (); - break; - } - } - } catch (Error e) { - print ("Error: %s\n", e.message); - } - } - public bool get_visibility () throws DBusError, IOError { return cc.visible; } @@ -33,8 +19,12 @@ namespace SwayNotificatonCenter { } } - public void update () throws DBusError, IOError { - cc.update (this.dbusInit.notifications, dbusInit.notiDaemon); + public void add_notification (NotifyParams param) throws DBusError, IOError { + cc.add_notification (param, dbusInit.notiDaemon); + } + + public void close_notification (uint32 id) throws DBusError, IOError { + cc.close_notification (id); } } @@ -52,22 +42,32 @@ namespace SwayNotificatonCenter { GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.RIGHT, true); } + private void removeWidget (Gtk.Widget widget) { + uint len = box.get_children ().length () - 1; + box.remove (widget); + if (len <= 0) { + // Do something in the future! + } + } + public bool toggle_visibility () { var vis = !this.visible; this.set_visible (vis); return vis; } - public void update (List notifications, NotiDaemon notiDaemon) { - foreach (var child in box.get_children ()) { - box.remove (child); - } - var notis = notifications.copy (); - notis.reverse (); - foreach (var param in notis) { - var noti = new Notification (param, notiDaemon, true); - box.add (noti); + public void close_notification (uint32 id) { + foreach (var w in box.get_children ()) { + if (((Notification) w).param.applied_id == id) { + removeWidget (w); + break; + } } } + + public void add_notification (NotifyParams param, NotiDaemon notiDaemon) { + var noti = new Notification (param, notiDaemon, true); + box.pack_end (noti, false, true, 0); + } } } diff --git a/src/main.vala b/src/main.vala index 890c3dd..d673d51 100644 --- a/src/main.vala +++ b/src/main.vala @@ -1,6 +1,6 @@ namespace SwayNotificatonCenter { - public class NotifyParams { + public struct NotifyParams { public uint32 applied_id { get; set; } public string app_name { get; set; } public uint32 replaces_id { get; set; } @@ -29,38 +29,30 @@ namespace SwayNotificatonCenter { this.actions = actions; this.hints = hints; this.expire_timeout = expire_timeout; - - get_icon (); - } - - private void get_icon () { } public void printParams () { - print ("----START---- \n"); // print (applied_id.to_string () + "\n"); - print (app_name + "\n"); + // print (app_name + "\n"); // print (replaces_id.to_string () + "\n"); // print (app_icon + "\n"); // print (summary + "\n"); // print (body + "\n"); - print ("-----------\n"); + print ("----Actions----\n"); foreach (var action in actions) { print (action + "\n"); } - print ("-----------\n"); - // print(hints.get ("icon_data").print (false) + "\n"); - // hints.get ("icon_data") + print ("----END----\n"); // foreach (var hint in hints.get_values ()) { // hint.print (false); // } - print ("-----------\n"); + print ("----Hints----\n"); foreach (var key in hints.get_keys ()) { print (key + "\n"); } - print ("-----------\n"); - print (expire_timeout.to_string () + "\n"); + print ("----END----\n"); + // print (expire_timeout.to_string () + "\n"); } } @@ -93,7 +85,7 @@ namespace SwayNotificatonCenter { throws DBusError, IOError { uint32 id = replaces_id == 0 ? ++noti_id : replaces_id; - var param = new NotifyParams ( + var param = NotifyParams ( id, app_name, replaces_id, @@ -105,19 +97,13 @@ namespace SwayNotificatonCenter { expire_timeout); if (id == replaces_id) { - notiWin.replace_notification (param); - foreach (NotifyParams n in dbusInit.notifications) { - if (n.applied_id == replaces_id) { - dbusInit.notifications.remove (n); - break; - } - } + notiWin.close_notification (id); + dbusInit.ccDaemon.close_notification (id); } if (!dbusInit.ccDaemon.get_visibility ()) { notiWin.add_notification (param, this); } - dbusInit.notifications.append (param); - dbusInit.ccDaemon.update (); + dbusInit.ccDaemon.add_notification (param); return id; } @@ -126,6 +112,7 @@ namespace SwayNotificatonCenter { dbusInit.ccDaemon.close_notification (id); } + // Only remove the popup without removing the it from the panel public void CloseNotification (uint32 id) throws DBusError, IOError { notiWin.close_notification (id); } @@ -148,7 +135,6 @@ namespace SwayNotificatonCenter { public class DBusInit { - public List notifications = new List (); public NotiDaemon notiDaemon; public CcDaemon ccDaemon; diff --git a/src/notiWindow/notiWindow.vala b/src/notiWindow/notiWindow.vala index b62e549..1591230 100644 --- a/src/notiWindow/notiWindow.vala +++ b/src/notiWindow/notiWindow.vala @@ -18,19 +18,8 @@ namespace SwayNotificatonCenter { if (len <= 0) box.set_visible (false); } - public void replace_notification (NotifyParams param) { - foreach (var w in box.get_children ()) { - if (((Notification) w).param.applied_id == param.replaces_id) { - removeWidget (w); - break; - } - } - } - - // public delegate void Close_click (NotifyParams param); public void add_notification (NotifyParams param, NotiDaemon notiDaemon) { var noti = new Notification (param, notiDaemon); - // param.printParams (); box.pack_end (noti, false, false, 0); noti.show_notification ((v_noti) => { box.remove (v_noti);