From ffaa7e11e26b88da4294c48cdc7f3f09d90fc719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlad=20P=C4=83n=C4=83zan?= Date: Fri, 27 Oct 2023 23:26:21 +0200 Subject: [PATCH] apprt/gtk: handle surface scale changes --- src/apprt/gtk/Surface.zig | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/apprt/gtk/Surface.zig b/src/apprt/gtk/Surface.zig index 86a6c816e..06c7ebf8d 100644 --- a/src/apprt/gtk/Surface.zig +++ b/src/apprt/gtk/Surface.zig @@ -354,10 +354,12 @@ pub fn shouldClose(self: *const Surface) bool { } pub fn getContentScale(self: *const Surface) !apprt.ContentScale { - _ = self; - const monitor = glfw.Monitor.getPrimary() orelse return error.NoMonitor; - const scale = monitor.getContentScale(); - return apprt.ContentScale{ .x = scale.x_scale, .y = scale.y_scale }; + const window_scale: f32 = scale: { + const window = @as(*c.GtkNative, @ptrCast(self.window.window)); + const gdk_surface = c.gtk_native_get_surface(window); + break :scale @floatCast(c.gdk_surface_get_scale(gdk_surface)); + }; + return apprt.ContentScale{ .x = window_scale, .y = window_scale }; } pub fn getSize(self: *const Surface) !apprt.SurfaceSize { @@ -625,6 +627,13 @@ fn gtkResize(area: *c.GtkGLArea, width: c.gint, height: c.gint, ud: ?*anyopaque) .height = @intCast(height), }; + if (self.getContentScale()) |scale| { + self.core_surface.contentScaleCallback(scale) catch |err| { + log.err("error in content scale callback err={}", .{err}); + return; + }; + } else |_|{} + // Call the primary callback. if (self.realized) { self.core_surface.sizeCallback(self.size) catch |err| {