From b985b289185ed9e6a272f8145faf581f5e8bf4d7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 27 Oct 2023 15:03:41 -0700 Subject: [PATCH] apprt/gtk: use gtk widget scale to get content scale --- src/apprt/gtk/App.zig | 9 --------- src/apprt/gtk/Surface.zig | 14 +++----------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/apprt/gtk/App.zig b/src/apprt/gtk/App.zig index 74d3c6b76..47e69eba3 100644 --- a/src/apprt/gtk/App.zig +++ b/src/apprt/gtk/App.zig @@ -13,7 +13,6 @@ const App = @This(); const std = @import("std"); const assert = std.debug.assert; const builtin = @import("builtin"); -const glfw = @import("glfw"); const configpkg = @import("../../config.zig"); const input = @import("../../input.zig"); const internal_os = @import("../../os/main.zig"); @@ -53,12 +52,6 @@ running: bool = true, pub fn init(core_app: *CoreApp, opts: Options) !App { _ = opts; - // This is super weird, but we still use GLFW with GTK only so that - // we can tap into their folklore logic to get screen DPI. If we can - // figure out a reliable way to determine this ourselves, we can get - // rid of this dep. - if (!glfw.init(.{})) return error.GlfwInitFailed; - // Load our configuration var config = try Config.load(core_app.alloc); errdefer config.deinit(); @@ -166,8 +159,6 @@ pub fn terminate(self: *App) void { if (self.menu) |menu| c.g_object_unref(menu); self.config.deinit(); - - glfw.terminate(); } /// Reload the configuration. This should return the new configuration. diff --git a/src/apprt/gtk/Surface.zig b/src/apprt/gtk/Surface.zig index 06c7ebf8d..64151ff89 100644 --- a/src/apprt/gtk/Surface.zig +++ b/src/apprt/gtk/Surface.zig @@ -4,7 +4,6 @@ const Surface = @This(); const std = @import("std"); -const glfw = @import("glfw"); const configpkg = @import("../../config.zig"); const apprt = @import("../../apprt.zig"); const font = @import("../../font/main.zig"); @@ -19,9 +18,6 @@ const c = @import("c.zig"); const log = std.log.scoped(.gtk); -// We need native X11 access to access the primary clipboard. -const glfw_native = glfw.Native(.{ .x11 = true }); - /// This is detected by the OpenGL renderer to move to a single-threaded /// draw operation. This basically puts locks around our draw path. pub const opengl_single_threaded_draw = true; @@ -354,12 +350,8 @@ pub fn shouldClose(self: *const Surface) bool { } pub fn getContentScale(self: *const Surface) !apprt.ContentScale { - 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 }; + const scale = c.gtk_widget_get_scale_factor(@ptrCast(self.gl_area)); + return .{ .x = @floatFromInt(scale), .y = @floatFromInt(scale) }; } pub fn getSize(self: *const Surface) !apprt.SurfaceSize { @@ -632,7 +624,7 @@ fn gtkResize(area: *c.GtkGLArea, width: c.gint, height: c.gint, ud: ?*anyopaque) log.err("error in content scale callback err={}", .{err}); return; }; - } else |_|{} + } else |_| {} // Call the primary callback. if (self.realized) {