[gtk/wip/chergert/for-main: 5/10] macos: add clamp helper for monitor workarea
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/for-main: 5/10] macos: add clamp helper for monitor workarea
- Date: Tue, 1 Mar 2022 07:09:57 +0000 (UTC)
commit 2e760e3b7dc0ed9f6bbdfe658ebd9616ef131b85
Author: Christian Hergert <christian hergert me>
Date: Mon Feb 28 22:42:00 2022 -0800
macos: add clamp helper for monitor workarea
This adds a convenience wrapper we can use to clamp a surface rectangle to
the workarea of a monitor.
gdk/macos/gdkmacosmonitor-private.h | 2 ++
gdk/macos/gdkmacosmonitor.c | 26 ++++++++++++++++++++++++++
2 files changed, 28 insertions(+)
---
diff --git a/gdk/macos/gdkmacosmonitor-private.h b/gdk/macos/gdkmacosmonitor-private.h
index dfde4142c0..1a4e197f76 100644
--- a/gdk/macos/gdkmacosmonitor-private.h
+++ b/gdk/macos/gdkmacosmonitor-private.h
@@ -41,6 +41,8 @@ void _gdk_macos_monitor_add_frame_callback (GdkMacosMonitor *
GdkMacosSurface *surface);
void _gdk_macos_monitor_remove_frame_callback (GdkMacosMonitor *self,
GdkMacosSurface *surface);
+void _gdk_macos_monitor_clamp (GdkMacosMonitor *self,
+ GdkRectangle *area);
G_END_DECLS
diff --git a/gdk/macos/gdkmacosmonitor.c b/gdk/macos/gdkmacosmonitor.c
index bfec76b7ef..a9aba3634b 100644
--- a/gdk/macos/gdkmacosmonitor.c
+++ b/gdk/macos/gdkmacosmonitor.c
@@ -431,3 +431,29 @@ _gdk_macos_monitor_remove_frame_callback (GdkMacosMonitor *self,
gdk_display_link_source_pause (self->display_link);
}
}
+
+void
+_gdk_macos_monitor_clamp (GdkMacosMonitor *self,
+ GdkRectangle *area)
+{
+ GdkRectangle workarea;
+ GdkRectangle geom;
+
+ g_return_if_fail (GDK_IS_MACOS_MONITOR (self));
+ g_return_if_fail (area != NULL);
+
+ gdk_macos_monitor_get_workarea (GDK_MONITOR (self), &workarea);
+ gdk_monitor_get_geometry (GDK_MONITOR (self), &geom);
+
+ if (area->x + area->width > workarea.x + workarea.width)
+ area->x = workarea.x + workarea.width - area->width;
+
+ if (area->x < workarea.x)
+ area->x = workarea.x;
+
+ if (area->y + area->height > workarea.y + workarea.height)
+ area->y = workarea.y + workarea.height - area->height;
+
+ if (area->y < workarea.y)
+ area->y = workarea.y;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]