From 9a83bcd2bd33ee95a69069d07c56bedec05c7d02 Mon Sep 17 00:00:00 2001 From: Aylur Date: Thu, 23 Jan 2025 17:58:23 +0100 Subject: feat: monitor get_current_monitor --- lib/astal/gtk3/src/widget/window.vala | 9 ++++++++- lib/astal/gtk4/src/widget/window.vala | 7 +++++++ nix/devshell.nix | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/astal/gtk3/src/widget/window.vala b/lib/astal/gtk3/src/widget/window.vala index 11d542d..a066806 100644 --- a/lib/astal/gtk3/src/widget/window.vala +++ b/lib/astal/gtk3/src/widget/window.vala @@ -50,6 +50,13 @@ public class Astal.Window : Gtk.Window { private InhibitManager? inhibit_manager; private Inhibitor? inhibitor; + /** + * Get the current [class@Gdk.Monitor] this window resides in. + */ + public Gdk.Monitor get_current_monitor() { + return Gdk.Display.get_default().get_monitor_at_window(base.get_window()); + } + private bool check(string action) { if (!is_supported()) { critical(@"can not $action on window: layer shell not supported"); @@ -63,7 +70,7 @@ public class Astal.Window : Gtk.Window { } construct { - // If the window has no size allocatoted when it gets mapped. + // If the window has no size allocatoted when it gets mapped // It won't show up later either when it size changes by adding children. height_request = 1; width_request = 1; diff --git a/lib/astal/gtk4/src/widget/window.vala b/lib/astal/gtk4/src/widget/window.vala index 0cf3d11..3b0d113 100644 --- a/lib/astal/gtk4/src/widget/window.vala +++ b/lib/astal/gtk4/src/widget/window.vala @@ -47,6 +47,13 @@ public enum Astal.Keymode { * Subclass of [class@Gtk.Window] which integrates GtkLayerShell as class fields. */ public class Astal.Window : Gtk.Window { + /** + * Get the current [class@Gdk.Monitor] this window resides in. + */ + public Gdk.Monitor get_current_monitor() { + return Gdk.Display.get_default().get_monitor_at_surface(base.get_surface()); + } + private bool check(string action) { if (!is_supported()) { critical(@"can not $action on window: layer shell not supported"); diff --git a/nix/devshell.nix b/nix/devshell.nix index f5a7c96..2e409c4 100644 --- a/nix/devshell.nix +++ b/nix/devshell.nix @@ -41,6 +41,7 @@ wayland blueprint-compiler libadwaita + wayland-scanner dart-sass lua -- cgit v1.2.3