apprt/gtk: use gtk widget scale to get content scale

This commit is contained in:
Mitchell Hashimoto
2023-10-27 15:03:41 -07:00
parent ffaa7e11e2
commit b985b28918
2 changed files with 3 additions and 20 deletions

View File

@ -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.

View File

@ -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 {