mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
apprt/gtk: use gtk widget scale to get content scale
This commit is contained in:
@ -13,7 +13,6 @@ const App = @This();
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const glfw = @import("glfw");
|
|
||||||
const configpkg = @import("../../config.zig");
|
const configpkg = @import("../../config.zig");
|
||||||
const input = @import("../../input.zig");
|
const input = @import("../../input.zig");
|
||||||
const internal_os = @import("../../os/main.zig");
|
const internal_os = @import("../../os/main.zig");
|
||||||
@ -53,12 +52,6 @@ running: bool = true,
|
|||||||
pub fn init(core_app: *CoreApp, opts: Options) !App {
|
pub fn init(core_app: *CoreApp, opts: Options) !App {
|
||||||
_ = opts;
|
_ = 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
|
// Load our configuration
|
||||||
var config = try Config.load(core_app.alloc);
|
var config = try Config.load(core_app.alloc);
|
||||||
errdefer config.deinit();
|
errdefer config.deinit();
|
||||||
@ -166,8 +159,6 @@ pub fn terminate(self: *App) void {
|
|||||||
if (self.menu) |menu| c.g_object_unref(menu);
|
if (self.menu) |menu| c.g_object_unref(menu);
|
||||||
|
|
||||||
self.config.deinit();
|
self.config.deinit();
|
||||||
|
|
||||||
glfw.terminate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reload the configuration. This should return the new configuration.
|
/// Reload the configuration. This should return the new configuration.
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
const Surface = @This();
|
const Surface = @This();
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const glfw = @import("glfw");
|
|
||||||
const configpkg = @import("../../config.zig");
|
const configpkg = @import("../../config.zig");
|
||||||
const apprt = @import("../../apprt.zig");
|
const apprt = @import("../../apprt.zig");
|
||||||
const font = @import("../../font/main.zig");
|
const font = @import("../../font/main.zig");
|
||||||
@ -19,9 +18,6 @@ const c = @import("c.zig");
|
|||||||
|
|
||||||
const log = std.log.scoped(.gtk);
|
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
|
/// This is detected by the OpenGL renderer to move to a single-threaded
|
||||||
/// draw operation. This basically puts locks around our draw path.
|
/// draw operation. This basically puts locks around our draw path.
|
||||||
pub const opengl_single_threaded_draw = true;
|
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 {
|
pub fn getContentScale(self: *const Surface) !apprt.ContentScale {
|
||||||
const window_scale: f32 = scale: {
|
const scale = c.gtk_widget_get_scale_factor(@ptrCast(self.gl_area));
|
||||||
const window = @as(*c.GtkNative, @ptrCast(self.window.window));
|
return .{ .x = @floatFromInt(scale), .y = @floatFromInt(scale) };
|
||||||
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 {
|
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});
|
log.err("error in content scale callback err={}", .{err});
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
} else |_|{}
|
} else |_| {}
|
||||||
|
|
||||||
// Call the primary callback.
|
// Call the primary callback.
|
||||||
if (self.realized) {
|
if (self.realized) {
|
||||||
|
Reference in New Issue
Block a user