Skip to content

Commit 08bbc6c

Browse files
authored
Fixed floating notification keyboard mode being set too early (#716)
* Fixed floating notification keyboard mode being set too early * Only set the ON_DEMAND layer mode when needed Reduces the chance that the input focus will get stolen on KDE. KDE handles the ON_DEMAND and EXCLUSIVE modes the same, so each time a notification pops-up, the users input focus is stolen (like the old sway behavior).
1 parent 7dcd905 commit 08bbc6c

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/notificationWindow/notificationWindow.vala

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace SwayNotificationCenter {
4444
Functions.monitor_to_string (monitor));
4545

4646
// Only set ON_DEMAND after the surface has been mapped
47-
set_keyboard_mode ();
47+
Idle.add_once (() => set_keyboard_mode ());
4848
});
4949
});
5050
this.unmap.connect (() => {
@@ -89,9 +89,15 @@ namespace SwayNotificationCenter {
8989
base.snapshot (snapshot);
9090
}
9191

92+
/**
93+
* Compositors handle the layer shell ON_DEMAND mode differently, so
94+
* only set the mode while mapped to reduce the chance of the users
95+
* input focus being stolen by an incoming notification.
96+
*/
9297
private inline void set_keyboard_mode () {
9398
if (app.use_layer_shell) {
94-
if (app.has_layer_on_demand && get_mapped ()) {
99+
if (app.has_layer_on_demand && get_mapped ()
100+
&& !inline_reply_notifications.is_empty) {
95101
GtkLayerShell.set_keyboard_mode (this, GtkLayerShell.KeyboardMode.ON_DEMAND);
96102
} else {
97103
GtkLayerShell.set_keyboard_mode (this, GtkLayerShell.KeyboardMode.NONE);
@@ -275,6 +281,7 @@ namespace SwayNotificationCenter {
275281

276282
if (notification.has_inline_reply) {
277283
inline_reply_notifications.remove (param.applied_id);
284+
set_keyboard_mode ();
278285
}
279286

280287
// Remove notification and its destruction timeout
@@ -301,6 +308,14 @@ namespace SwayNotificationCenter {
301308
((Gtk.Widget) this).unrealize ();
302309
}
303310

311+
if (noti.has_inline_reply) {
312+
inline_reply_notifications.add (param.applied_id);
313+
// Update the keyboard mode when already mapped
314+
if (get_mapped ()) {
315+
set_keyboard_mode ();
316+
}
317+
}
318+
304319
set_visible (true);
305320

306321
list.append.begin (noti);

0 commit comments

Comments
 (0)