Skip to content

Commit 9a251ed

Browse files
committed
Fixed nasty hover bug after first notification
1 parent c1bc6f4 commit 9a251ed

3 files changed

Lines changed: 39 additions & 15 deletions

File tree

src/notiDaemon/notiDaemon.vala

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ namespace SwayNotificationCenter {
77
new HashTable<string, uint32> (str_hash, str_equal);
88

99
public ControlCenter control_center;
10-
public NotificationWindow noti_window;
1110

1211
public NotiDaemon (SwayncDaemon swaync_daemon) {
1312
this.notify["dnd"].connect (() => on_dnd_toggle (dnd));
1413

1514
// Init dnd from gsettings
1615
self_settings.bind ("dnd-state", this, "dnd", SettingsBindFlags.DEFAULT);
1716

18-
this.noti_window = new NotificationWindow ();
1917
this.control_center = new ControlCenter (swaync_daemon, this);
2018
}
2119

@@ -25,7 +23,7 @@ namespace SwayNotificationCenter {
2523
*/
2624
public void set_noti_window_visibility (bool value)
2725
throws DBusError, IOError {
28-
noti_window.change_visibility (value);
26+
NotificationWindow.instance.change_visibility (value);
2927
}
3028

3129
/** Toggles the current Do Not Disturb state */
@@ -53,7 +51,7 @@ namespace SwayNotificationCenter {
5351
/** Method to close notification and send DISMISSED signal */
5452
public void manually_close_notification (uint32 id, bool timeout)
5553
throws DBusError, IOError {
56-
noti_window.close_notification (id);
54+
NotificationWindow.instance.close_notification (id);
5755
if (!timeout) {
5856
control_center.close_notification (id);
5957
NotificationClosed (id, ClosedReasons.DISMISSED);
@@ -66,14 +64,14 @@ namespace SwayNotificationCenter {
6664

6765
/** Closes all popup and controlcenter notifications */
6866
public void close_all_notifications () throws DBusError, IOError {
69-
noti_window.close_all_notifications ();
67+
NotificationWindow.instance.close_all_notifications ();
7068
control_center.close_all_notifications ();
7169
}
7270

7371
/** Closes latest popup notification */
7472
public void hide_latest_notification (bool close)
7573
throws DBusError, IOError {
76-
uint32 ? id = noti_window.get_latest_notification ();
74+
uint32 ? id = NotificationWindow.instance.get_latest_notification ();
7775
if (id == null) return;
7876
manually_close_notification (id, !close);
7977
}
@@ -157,7 +155,7 @@ namespace SwayNotificationCenter {
157155
// Replace notification logic
158156
if (id == replaces_id) {
159157
param.replaces = true;
160-
noti_window.close_notification (id);
158+
NotificationWindow.instance.close_notification (id);
161159
control_center.close_notification (id, true);
162160
} else if (param.synchronous != null
163161
&& param.synchronous.length > 0) {
@@ -168,7 +166,7 @@ namespace SwayNotificationCenter {
168166
param.synchronous, null, out r_id)) {
169167
param.replaces = true;
170168
// Close the notification
171-
noti_window.close_notification (r_id);
169+
NotificationWindow.instance.close_notification (r_id);
172170
control_center.close_notification (r_id, true);
173171
}
174172
synchronous_ids.set (param.synchronous, id);
@@ -179,7 +177,7 @@ namespace SwayNotificationCenter {
179177
&& !control_center.get_visibility ()) {
180178
if (param.urgency == UrgencyLevels.CRITICAL ||
181179
(!dnd && param.urgency != UrgencyLevels.CRITICAL)) {
182-
noti_window.add_notification (param, this);
180+
NotificationWindow.instance.add_notification (param, this);
183181
}
184182
}
185183
// Only add notification to CC if it isn't IGNORED and not transient
@@ -255,7 +253,7 @@ namespace SwayNotificationCenter {
255253
*/
256254
[DBus (name = "CloseNotification")]
257255
public void close_notification (uint32 id) throws DBusError, IOError {
258-
noti_window.close_notification (id);
256+
NotificationWindow.instance.close_notification (id);
259257
control_center.close_notification (id);
260258
NotificationClosed (id, ClosedReasons.CLOSED_BY_CLOSENOTIFICATION);
261259
}

src/notificationWindow/notificationWindow.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!-- Generated with glade 3.38.2 -->
33
<interface>
44
<requires lib="gtk+" version="3.24"/>
5-
<template class="SwayNotificationCenterNotificationWindow" parent="GtkApplicationWindow">
5+
<template class="SwayNotificationCenterNotiWindow" parent="GtkApplicationWindow">
66
<property name="can-focus">False</property>
77
<property name="role">NotificationWindow</property>
88
<property name="resizable">False</property>

src/notificationWindow/notificationWindow.vala

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
namespace SwayNotificationCenter {
2+
public class NotificationWindow : Object {
3+
private static NotiWindow ? window = null;
4+
// Use a NotiWindow singleton due to a nasty notification
5+
// enter_notify_event bug where GTK still thinks that the cursor is at
6+
// that location after closing the last notification. The next notification
7+
// would sometimes automatically be hovered...
8+
public static NotiWindow instance {
9+
get {
10+
if (window == null) {
11+
window = new NotiWindow ();
12+
} else if (!window.get_mapped () ||
13+
!window.get_realized () ||
14+
!(window.get_child () is Gtk.Widget)) {
15+
window.destroy ();
16+
window = new NotiWindow ();
17+
}
18+
return window;
19+
}
20+
}
21+
}
22+
223
[GtkTemplate (ui = "/org/erikreider/sway-notification-center/notificationWindow/notificationWindow.ui")]
3-
public class NotificationWindow : Gtk.ApplicationWindow {
24+
public class NotiWindow : Gtk.ApplicationWindow {
425

526
[GtkChild]
627
unowned Gtk.ScrolledWindow scrolled_window;
@@ -15,7 +36,7 @@ namespace SwayNotificationCenter {
1536

1637
private const int MAX_HEIGHT = 600;
1738

18-
public NotificationWindow () {
39+
public NotiWindow () {
1940
if (!GtkLayerShell.is_supported ()) {
2041
stderr.printf ("GTKLAYERSHELL IS NOT SUPPORTED!\n");
2142
stderr.printf ("Swaync only works on Wayland!\n");
@@ -113,8 +134,13 @@ namespace SwayNotificationCenter {
113134
noti.destroy ();
114135
}
115136

116-
if (!this.get_realized ()) return;
117-
if (box.get_children ().length () == 0) this.hide ();
137+
if (!get_realized ()
138+
|| !get_mapped ()
139+
|| !(get_child () is Gtk.Widget)
140+
|| box.get_children ().length () == 0) {
141+
close ();
142+
return;
143+
}
118144
}
119145

120146
public void add_notification (NotifyParams param,

0 commit comments

Comments
 (0)