From 6caef64e592e301b084b3c5ed6388e45c34cb025 Mon Sep 17 00:00:00 2001 From: Stan Janssen Date: Wed, 29 Mar 2023 09:57:15 +0200 Subject: [PATCH 1/3] Allow the notification stack to be moved using DBus This can be called by WingPanel to move the notifications stack out of the way when indicator menus are opened. --- lib/WindowManager.vala | 8 ++++++++ src/DBus.vala | 4 ++++ src/NotificationStack.vala | 7 ++++++- src/WindowManager.vala | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/WindowManager.vala b/lib/WindowManager.vala index a9a931bd0..5961066d1 100644 --- a/lib/WindowManager.vala +++ b/lib/WindowManager.vala @@ -165,6 +165,14 @@ namespace Gala { */ public abstract void perform_action (ActionType type); + /** + * Tells the window manager to move the Notifications Stack down + * by the given number of pixels, to make room for menus. + * + * @param offset The amount of pixels by which to move the notifications stack + */ + public abstract void offset_notifications (int32 offset); + /** * Moves the window to the workspace next to its current workspace in the given direction. * Gala currently only supports LEFT and RIGHT. diff --git a/src/DBus.vala b/src/DBus.vala index e474c1dc0..f33f3c5b4 100644 --- a/src/DBus.vala +++ b/src/DBus.vala @@ -91,6 +91,10 @@ namespace Gala { wm.perform_action (type); } + public void offset_notifications (int32 offset) throws DBusError, Error { + wm.offset_notifications (offset); + } + private const double SATURATION_WEIGHT = 1.5; private const double WEIGHT_THRESHOLD = 1.0; diff --git a/src/NotificationStack.vala b/src/NotificationStack.vala index 702c3667e..804af5799 100644 --- a/src/NotificationStack.vala +++ b/src/NotificationStack.vala @@ -22,7 +22,7 @@ public class Gala.NotificationStack : Object { // we need to keep a small offset to the top, because we clip the container to // its allocations and the close button would be off for the first notification - private const int TOP_OFFSET = 2; + private int TOP_OFFSET = 2; private const int ADDITIONAL_MARGIN = 12; private const int MARGIN = 12; @@ -146,6 +146,11 @@ public class Gala.NotificationStack : Object { } } + public void offset_notifications (int32 offset) { + TOP_OFFSET = 2 + offset; + update_positions (true); + } + public void destroy_notification (Meta.WindowActor notification, bool animate) { if (animate) { notification.save_easing_state (); diff --git a/src/WindowManager.vala b/src/WindowManager.vala index 8e29ac695..e9542fe43 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -901,6 +901,10 @@ namespace Gala { } } + public void offset_notifications (int32 offset) { + notification_stack.offset_notifications (offset); + } + public override void show_window_menu (Meta.Window window, Meta.WindowMenuType menu, int x, int y) { switch (menu) { case Meta.WindowMenuType.WM: From 7707b9ab7e5333cbffd66c4df8483f662ef58f00 Mon Sep 17 00:00:00 2001 From: Stan Janssen Date: Wed, 29 Mar 2023 11:44:20 +0200 Subject: [PATCH 2/3] Use separate variable for stack offset --- src/NotificationStack.vala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/NotificationStack.vala b/src/NotificationStack.vala index 804af5799..26c50e403 100644 --- a/src/NotificationStack.vala +++ b/src/NotificationStack.vala @@ -22,13 +22,14 @@ public class Gala.NotificationStack : Object { // we need to keep a small offset to the top, because we clip the container to // its allocations and the close button would be off for the first notification - private int TOP_OFFSET = 2; + private const int TOP_OFFSET = 2; private const int ADDITIONAL_MARGIN = 12; private const int MARGIN = 12; private const int WIDTH = 300; private int stack_y; + private int stack_y_offset; private int stack_width; public Meta.Display display { get; construct; } @@ -89,7 +90,7 @@ public class Gala.NotificationStack : Object { int notification_x_pos = area.x + area.width - window_rect.width; - move_window (notification, notification_x_pos, stack_y + TOP_OFFSET + ADDITIONAL_MARGIN * scale); + move_window (notification, notification_x_pos, stack_y + TOP_OFFSET + stack_y_offset + ADDITIONAL_MARGIN * scale); notifications.insert (0, notification); } @@ -105,7 +106,7 @@ public class Gala.NotificationStack : Object { private void update_positions (bool animate, float add_y = 0.0f) { var scale = Utils.get_ui_scaling_factor (); - var y = stack_y + TOP_OFFSET + add_y + ADDITIONAL_MARGIN * scale; + var y = stack_y + TOP_OFFSET + stack_y_offset + add_y + ADDITIONAL_MARGIN * scale; var i = notifications.size; var delay_step = i > 0 ? 150 / i : 0; var iterator = 0; @@ -147,7 +148,7 @@ public class Gala.NotificationStack : Object { } public void offset_notifications (int32 offset) { - TOP_OFFSET = 2 + offset; + stack_y_offset = offset; update_positions (true); } From 3dda4094100f44eb076fbd2a1e60f36fc7552cb0 Mon Sep 17 00:00:00 2001 From: Stan Janssen Date: Wed, 29 Mar 2023 18:56:50 +0200 Subject: [PATCH 3/3] Account for display scale when repositioning the stack --- lib/WindowManager.vala | 4 ++-- src/NotificationStack.vala | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/WindowManager.vala b/lib/WindowManager.vala index 5961066d1..3d05c18b4 100644 --- a/lib/WindowManager.vala +++ b/lib/WindowManager.vala @@ -167,9 +167,9 @@ namespace Gala { /** * Tells the window manager to move the Notifications Stack down - * by the given number of pixels, to make room for menus. + * by the given number of points, to make room for menus. * - * @param offset The amount of pixels by which to move the notifications stack + * @param offset The number of points by which to move the notifications stack */ public abstract void offset_notifications (int32 offset); diff --git a/src/NotificationStack.vala b/src/NotificationStack.vala index 26c50e403..ad98bc8de 100644 --- a/src/NotificationStack.vala +++ b/src/NotificationStack.vala @@ -90,7 +90,7 @@ public class Gala.NotificationStack : Object { int notification_x_pos = area.x + area.width - window_rect.width; - move_window (notification, notification_x_pos, stack_y + TOP_OFFSET + stack_y_offset + ADDITIONAL_MARGIN * scale); + move_window (notification, notification_x_pos, stack_y + TOP_OFFSET + (stack_y_offset + ADDITIONAL_MARGIN) * scale); notifications.insert (0, notification); } @@ -106,7 +106,7 @@ public class Gala.NotificationStack : Object { private void update_positions (bool animate, float add_y = 0.0f) { var scale = Utils.get_ui_scaling_factor (); - var y = stack_y + TOP_OFFSET + stack_y_offset + add_y + ADDITIONAL_MARGIN * scale; + var y = stack_y + TOP_OFFSET + add_y + (stack_y_offset + ADDITIONAL_MARGIN) * scale; var i = notifications.size; var delay_step = i > 0 ? 150 / i : 0; var iterator = 0;