From beabe0d44c787ea286712efde3e1df38c6400192 Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Sat, 18 Jan 2025 22:13:02 +0000 Subject: [PATCH 1/5] Rejig notifications to work with layer-shell positioning --- src/bridges/labwc/rc.xml | 5 ----- src/daemon/notifications/dbus.vala | 22 ++++++++++++++++------ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/bridges/labwc/rc.xml b/src/bridges/labwc/rc.xml index 9e03b658e..d0025960f 100644 --- a/src/bridges/labwc/rc.xml +++ b/src/bridges/labwc/rc.xml @@ -300,11 +300,6 @@ - - - - - diff --git a/src/daemon/notifications/dbus.vala b/src/daemon/notifications/dbus.vala index debd16e56..34421d37d 100644 --- a/src/daemon/notifications/dbus.vala +++ b/src/daemon/notifications/dbus.vala @@ -124,6 +124,8 @@ private Settings panel_settings { private get; private set; default = null; } private uint32 latest_popup_id { private get; private set; default = 0; } + private int32 latest_popup_x; + private int32 latest_popup_y; private int paused_notifications { private get; private set; default = 0; } private Notify.Notification unpaused_noti = null; @@ -358,14 +360,15 @@ * Configures the location of a notification popup and makes it visible on the screen. */ private void configure_window(Popup? popup) { - var screen = Gdk.Screen.get_default(); + GtkLayerShell.init_for_window(popup); + GtkLayerShell.set_layer(popup, GtkLayerShell.Layer.TOP); - Gdk.Monitor mon = screen.get_display().get_primary_monitor(); - Gdk.Rectangle mon_rect = mon.get_geometry(); + var mon = libxfce4windowing.Screen.get_default().get_primary_monitor(); + Gdk.Rectangle mon_rect = mon.get_workarea(); ulong handler_id = 0; handler_id = popup.get_child().size_allocate.connect((alloc) => { - // Diconnect from the signal to avoid trying to recalculate + // Disconnect from the signal to avoid trying to recalculate // the position unexpectedly, which occurs when mousing over // or clicking the close button with some GTK themes. popup.get_child().disconnect(handler_id); @@ -374,7 +377,11 @@ /* Set the x, y position of the notification */ int x = 0, y = 0; calculate_position(popup, mon_rect, out x, out y); - popup.move(x, y); + GtkLayerShell.set_monitor(popup, mon.get_gdk_monitor()); + GtkLayerShell.set_margin(popup, GtkLayerShell.Edge.LEFT, x); + GtkLayerShell.set_margin(popup, GtkLayerShell.Edge.TOP, y); + GtkLayerShell.set_anchor(popup, GtkLayerShell.Edge.LEFT, true); + GtkLayerShell.set_anchor(popup, GtkLayerShell.Edge.TOP, true); }); popup.show_all(); @@ -392,7 +399,8 @@ if (latest_exists) { existing_height = latest.get_child().get_allocated_height(); - latest.get_position(out existing_x, out existing_y); + existing_x = this.latest_popup_x; + existing_y = this.latest_popup_y; } switch (pos) { @@ -436,6 +444,8 @@ } break; } + this.latest_popup_x = x; + this.latest_popup_y = y; } /** From 496befe4687f71e2164582a44965e2929953e6e0 Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Sat, 18 Jan 2025 23:08:55 +0000 Subject: [PATCH 2/5] Switch to using layershell anchors --- src/daemon/notifications/dbus.vala | 66 +++++++++++++++++------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/src/daemon/notifications/dbus.vala b/src/daemon/notifications/dbus.vala index 34421d37d..ed566ad37 100644 --- a/src/daemon/notifications/dbus.vala +++ b/src/daemon/notifications/dbus.vala @@ -124,7 +124,6 @@ private Settings panel_settings { private get; private set; default = null; } private uint32 latest_popup_id { private get; private set; default = 0; } - private int32 latest_popup_x; private int32 latest_popup_y; private int paused_notifications { private get; private set; default = 0; } @@ -374,77 +373,88 @@ popup.get_child().disconnect(handler_id); handler_id = 0; - /* Set the x, y position of the notification */ - int x = 0, y = 0; - calculate_position(popup, mon_rect, out x, out y); + /* Set the y position of the notification */ + int y = 0; + calculate_position(popup, mon_rect, out y); GtkLayerShell.set_monitor(popup, mon.get_gdk_monitor()); - GtkLayerShell.set_margin(popup, GtkLayerShell.Edge.LEFT, x); - GtkLayerShell.set_margin(popup, GtkLayerShell.Edge.TOP, y); - GtkLayerShell.set_anchor(popup, GtkLayerShell.Edge.LEFT, true); - GtkLayerShell.set_anchor(popup, GtkLayerShell.Edge.TOP, true); + var pos = (NotificationPosition) this.panel_settings.get_enum("notification-position"); + int edge_a, edge_b; + + switch (pos) { + case NotificationPosition.TOP_LEFT: + edge_a = GtkLayerShell.Edge.LEFT; + edge_b = GtkLayerShell.Edge.TOP; + break; + case NotificationPosition.BOTTOM_LEFT: + edge_a = GtkLayerShell.Edge.LEFT; + edge_b = GtkLayerShell.Edge.BOTTOM; + break; + case NotificationPosition.BOTTOM_RIGHT: + edge_a = GtkLayerShell.Edge.RIGHT; + edge_b = GtkLayerShell.Edge.BOTTOM; + break; + case NotificationPosition.TOP_RIGHT: // Top right should also be the default case + default: + edge_a = GtkLayerShell.Edge.RIGHT; + edge_b = GtkLayerShell.Edge.TOP; + break; + } + GtkLayerShell.set_margin(popup, edge_a, BUFFER_ZONE); + GtkLayerShell.set_margin(popup, edge_b, y); + GtkLayerShell.set_anchor(popup, edge_a, true); + GtkLayerShell.set_anchor(popup, edge_b, true); + }); popup.show_all(); } /** - * Calculate the (x, y) position of a notification popup based on the setting for where on + * Calculate the (y) position of a notification popup based on the setting for where on * the screen notifications should appear. */ - private void calculate_position(Popup window, Gdk.Rectangle rect, out int x, out int y) { + private void calculate_position(Popup window, Gdk.Rectangle rect, out int y) { var pos = (NotificationPosition) this.panel_settings.get_enum("notification-position"); var latest = this.popups.get(this.latest_popup_id); bool latest_exists = latest != null && !latest.destroying; - int existing_height = 0, existing_x = 0, existing_y = 0; + int existing_height = 0, existing_y = 0; if (latest_exists) { existing_height = latest.get_child().get_allocated_height(); - existing_x = this.latest_popup_x; existing_y = this.latest_popup_y; } switch (pos) { case NotificationPosition.TOP_LEFT: if (latest_exists) { // If a notification is already being displayed - x = existing_x; y = existing_y + existing_height + BUFFER_ZONE; - } else { // This is the first nofication on the screen - x = rect.x + BUFFER_ZONE; + } else { // This is the first notification on the screen y = rect.y + INITIAL_BUFFER_ZONE; } break; case NotificationPosition.BOTTOM_LEFT: if (latest_exists) { // If a notification is already being displayed - x = existing_x; - y = existing_y - existing_height - BUFFER_ZONE; + y = existing_y + existing_height + BUFFER_ZONE; } else { // This is the first nofication on the screen - x = rect.x + BUFFER_ZONE; - y = (rect.y + rect.height) - window.get_allocated_height() - INITIAL_BUFFER_ZONE; + y = INITIAL_BUFFER_ZONE; } break; case NotificationPosition.BOTTOM_RIGHT: if (latest_exists) { // If a notification is already being displayed - x = existing_x; - y = existing_y - existing_height - BUFFER_ZONE; + y = existing_y + existing_height + BUFFER_ZONE; } else { // This is the first nofication on the screen - x = (rect.x + rect.width) - NOTIFICATION_WIDTH; - x -= BUFFER_ZONE; // Don't touch edge of the screen - y = (rect.y + rect.height) - window.get_allocated_height() - INITIAL_BUFFER_ZONE; + y = INITIAL_BUFFER_ZONE; } break; case NotificationPosition.TOP_RIGHT: // Top right should also be the default case default: if (latest_exists) { // If a notification is already being displayed - x = existing_x; y = existing_y + existing_height + BUFFER_ZONE; } else { // This is the first nofication on the screen - x = (rect.x + rect.width) - NOTIFICATION_WIDTH; - x -= BUFFER_ZONE; // Don't touch edge of the screen y = rect.y + INITIAL_BUFFER_ZONE; } break; } - this.latest_popup_x = x; this.latest_popup_y = y; } From 5b369baad3dc4aafc9addc9ce554b57432176a25 Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Mon, 20 Jan 2025 20:02:19 +0000 Subject: [PATCH 3/5] Simplify calculation for positioning on the screen --- src/daemon/notifications/dbus.vala | 42 ++++++------------------------ 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/src/daemon/notifications/dbus.vala b/src/daemon/notifications/dbus.vala index ed566ad37..54cd8bd1a 100644 --- a/src/daemon/notifications/dbus.vala +++ b/src/daemon/notifications/dbus.vala @@ -417,44 +417,18 @@ var pos = (NotificationPosition) this.panel_settings.get_enum("notification-position"); var latest = this.popups.get(this.latest_popup_id); bool latest_exists = latest != null && !latest.destroying; - int existing_height = 0, existing_y = 0; if (latest_exists) { - existing_height = latest.get_child().get_allocated_height(); - existing_y = this.latest_popup_y; + var existing_height = latest.get_child().get_allocated_height(); + y = this.latest_popup_y + existing_height + BUFFER_ZONE; } - - switch (pos) { - case NotificationPosition.TOP_LEFT: - if (latest_exists) { // If a notification is already being displayed - y = existing_y + existing_height + BUFFER_ZONE; - } else { // This is the first notification on the screen - y = rect.y + INITIAL_BUFFER_ZONE; - } - break; - case NotificationPosition.BOTTOM_LEFT: - if (latest_exists) { // If a notification is already being displayed - y = existing_y + existing_height + BUFFER_ZONE; - } else { // This is the first nofication on the screen - y = INITIAL_BUFFER_ZONE; - } - break; - case NotificationPosition.BOTTOM_RIGHT: - if (latest_exists) { // If a notification is already being displayed - y = existing_y + existing_height + BUFFER_ZONE; - } else { // This is the first nofication on the screen - y = INITIAL_BUFFER_ZONE; - } - break; - case NotificationPosition.TOP_RIGHT: // Top right should also be the default case - default: - if (latest_exists) { // If a notification is already being displayed - y = existing_y + existing_height + BUFFER_ZONE; - } else { // This is the first nofication on the screen - y = rect.y + INITIAL_BUFFER_ZONE; - } - break; + else if (pos == NotificationPosition.BOTTOM_LEFT || pos == NotificationPosition.BOTTOM_RIGHT ) { + y = INITIAL_BUFFER_ZONE; + } + else { + y = rect.y + INITIAL_BUFFER_ZONE; } + this.latest_popup_y = y; } From 0806c5ec360d4a970f061da13da1c94901cb0e21 Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Tue, 21 Jan 2025 20:34:55 +0000 Subject: [PATCH 4/5] Reduce the number of variables we are using for the notification calculation --- src/daemon/notifications/dbus.vala | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/daemon/notifications/dbus.vala b/src/daemon/notifications/dbus.vala index 54cd8bd1a..a99909dba 100644 --- a/src/daemon/notifications/dbus.vala +++ b/src/daemon/notifications/dbus.vala @@ -373,9 +373,8 @@ popup.get_child().disconnect(handler_id); handler_id = 0; - /* Set the y position of the notification */ - int y = 0; - calculate_position(popup, mon_rect, out y); + /* determine the y position for the latest notification */ + calculate_position(mon_rect.y); GtkLayerShell.set_monitor(popup, mon.get_gdk_monitor()); var pos = (NotificationPosition) this.panel_settings.get_enum("notification-position"); int edge_a, edge_b; @@ -399,11 +398,11 @@ edge_b = GtkLayerShell.Edge.TOP; break; } + GtkLayerShell.set_margin(popup, edge_a, BUFFER_ZONE); - GtkLayerShell.set_margin(popup, edge_b, y); + GtkLayerShell.set_margin(popup, edge_b, this.latest_popup_y); GtkLayerShell.set_anchor(popup, edge_a, true); GtkLayerShell.set_anchor(popup, edge_b, true); - }); popup.show_all(); @@ -413,23 +412,21 @@ * Calculate the (y) position of a notification popup based on the setting for where on * the screen notifications should appear. */ - private void calculate_position(Popup window, Gdk.Rectangle rect, out int y) { + private void calculate_position(int monitor_height) { var pos = (NotificationPosition) this.panel_settings.get_enum("notification-position"); var latest = this.popups.get(this.latest_popup_id); bool latest_exists = latest != null && !latest.destroying; if (latest_exists) { var existing_height = latest.get_child().get_allocated_height(); - y = this.latest_popup_y + existing_height + BUFFER_ZONE; + this.latest_popup_y = this.latest_popup_y + existing_height + BUFFER_ZONE; } else if (pos == NotificationPosition.BOTTOM_LEFT || pos == NotificationPosition.BOTTOM_RIGHT ) { - y = INITIAL_BUFFER_ZONE; + this.latest_popup_y = INITIAL_BUFFER_ZONE; } else { - y = rect.y + INITIAL_BUFFER_ZONE; + this.latest_popup_y = monitor_height + INITIAL_BUFFER_ZONE; } - - this.latest_popup_y = y; } /** From a5e6bb40f0ee01d4f8e82e5c723275bfef08aeb7 Mon Sep 17 00:00:00 2001 From: Bobby Rong Date: Mon, 13 Jan 2025 23:17:13 +0800 Subject: [PATCH 5/5] meson: Explicitly add gio-unix-2.0 This is another instance of pull request 185. Since we are using DesktopAppInfo directly, let's add gio-unix-2.0 explicitly. --- src/windowing/meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/src/windowing/meson.build b/src/windowing/meson.build index 54ba5d2b6..4b3bee026 100644 --- a/src/windowing/meson.build +++ b/src/windowing/meson.build @@ -5,6 +5,7 @@ libwindowing_sources = [ ] libwindowing_deps = [ + dep_giounix, dep_xfce4windowing, dep_wnck, ]