summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2023-04-02 08:45:28 -0400
committerMatthias Clasen <mclasen@redhat.com>2023-04-02 08:45:28 -0400
commit2f137b212a58f9d99ff5d833b84270611e3efa64 (patch)
treed1ad0282f3c7540a6895ce10cd7e24497a836470
parent8bbed27a5fe46ca74eab78f55ae6cae1fc0078a0 (diff)
downloadgtk+-gdk-scale-wayland.tar.gz
wayland: Read GDK_SCALEgdk-scale-wayland
This is somewhat disappointing, because the surface size stays the same, just the rendering changes.
-rw-r--r--gdk/wayland/gdkprivate-wayland.h1
-rw-r--r--gdk/wayland/gdksurface-wayland-private.h1
-rw-r--r--gdk/wayland/gdksurface-wayland.c33
3 files changed, 34 insertions, 1 deletions
diff --git a/gdk/wayland/gdkprivate-wayland.h b/gdk/wayland/gdkprivate-wayland.h
index 8db2dd8f49..e9752f3696 100644
--- a/gdk/wayland/gdkprivate-wayland.h
+++ b/gdk/wayland/gdkprivate-wayland.h
@@ -58,6 +58,7 @@ struct _GdkFractionalScale
#define GDK_FRACTIONAL_SCALE_INIT(fractional_scale) (GdkFractionalScale) { fractional_scale }
#define GDK_FRACTIONAL_SCALE_INIT_INT(scale) GDK_FRACTIONAL_SCALE_INIT (scale * GDK_FRACTIONAL_SCALE_FACTOR)
+#define GDK_FRACTIONAL_SCALE_INIT_FLOAT(scale) GDK_FRACTIONAL_SCALE_INIT ((int) (scale * GDK_FRACTIONAL_SCALE_FACTOR))
static inline int
gdk_fractional_scale_to_int (const GdkFractionalScale *self)
diff --git a/gdk/wayland/gdksurface-wayland-private.h b/gdk/wayland/gdksurface-wayland-private.h
index 1d87cc4b09..bb6354839c 100644
--- a/gdk/wayland/gdksurface-wayland-private.h
+++ b/gdk/wayland/gdksurface-wayland-private.h
@@ -48,6 +48,7 @@ struct _GdkWaylandSurface
unsigned int mapped : 1;
unsigned int awaiting_frame : 1;
unsigned int awaiting_frame_frozen : 1;
+ unsigned int scale_overridden : 1;
int pending_buffer_offset_x;
int pending_buffer_offset_y;
diff --git a/gdk/wayland/gdksurface-wayland.c b/gdk/wayland/gdksurface-wayland.c
index f51f081a43..62cfcac477 100644
--- a/gdk/wayland/gdksurface-wayland.c
+++ b/gdk/wayland/gdksurface-wayland.c
@@ -172,6 +172,31 @@ gdk_wayland_surface_init (GdkWaylandSurface *impl)
{
impl->scale = GDK_FRACTIONAL_SCALE_INIT_INT (1);
impl->viewport_dirty = TRUE;
+
+ if (g_getenv ("GDK_SCALE"))
+ {
+ const char *scale_str;
+ char *endptr = NULL;
+ double scale;
+
+ scale_str = g_getenv ("GDK_SCALE");
+
+ scale = g_ascii_strtod (scale_str, &endptr);
+
+ if (endptr && *endptr != '\0')
+ {
+ if (strcmp (endptr, "%") == 0)
+ scale /= 100.;
+ else
+ {
+ g_warning ("Failed to parse GDK_SCALE");
+ return;
+ }
+ }
+
+ impl->scale = GDK_FRACTIONAL_SCALE_INIT_FLOAT (scale);
+ impl->scale_overridden = TRUE;
+ }
}
void
@@ -464,6 +489,9 @@ gdk_wayland_surface_update_scale (GdkSurface *surface)
wl_surface_get_version (impl->display_server.wl_surface) < WL_SURFACE_SET_BUFFER_SCALE_SINCE_VERSION)
return;
+ if (impl->scale_overridden)
+ return;
+
/* scale is tracked by the fractional scale extension */
if (impl->display_server.fractional_scale)
return;
@@ -831,7 +859,10 @@ gdk_wayland_surface_fractional_scale_preferred_scale_cb (void *data,
{
GdkWaylandSurface *self = GDK_WAYLAND_SURFACE (data);
GdkSurface *surface = GDK_SURFACE (self);
-
+
+ if (self->scale_overridden)
+ return;
+
/* Notify app that scale changed */
gdk_wayland_surface_maybe_resize (surface,
surface->width, surface->height,