apprt/glfw: minor stylistic things

This commit is contained in:
Mitchell Hashimoto
2023-11-09 15:00:16 -08:00
parent b0f6b1e2c9
commit 126f02187a

View File

@ -149,7 +149,18 @@ pub const App = struct {
_ = self;
const win = surface.window;
if (!surface.isFullscreen()) {
if (surface.isFullscreen()) {
win.setMonitor(
null,
@intCast(surface.monitor_dims.position_x),
@intCast(surface.monitor_dims.position_y),
surface.monitor_dims.width,
surface.monitor_dims.height,
0,
);
return;
}
const monitor = win.getMonitor() orelse monitor: {
log.warn("window had null monitor, getting primary monitor", .{});
break :monitor glfw.Monitor.getPrimary() orelse {
@ -157,6 +168,7 @@ pub const App = struct {
return;
};
};
const video_mode = monitor.getVideoMode() orelse {
log.warn("failed to get video mode. will not perform action", .{});
return;
@ -168,7 +180,7 @@ pub const App = struct {
return;
};
surface.window_dimensions = .{
surface.monitor_dims = .{
.width = size.width,
.height = size.height,
.position_x = position.x,
@ -176,9 +188,6 @@ pub const App = struct {
};
win.setMonitor(monitor, 0, 0, video_mode.getWidth(), video_mode.getHeight(), 0);
} else {
win.setMonitor(null, @as(i32, @intCast(surface.window_dimensions.position_x)), @as(i32, @intCast(surface.window_dimensions.position_y)), surface.window_dimensions.width, surface.window_dimensions.height, 0);
}
}
/// Create a new window for the app.
@ -304,8 +313,8 @@ pub const App = struct {
};
};
/// These are used to keep track of the original monitor values so that we can safely
/// toggle on and off of fullscreen.
/// These are used to keep track of the original monitor values so that we can
/// safely toggle on and off of fullscreen.
const MonitorDimensions = struct {
width: u32,
height: u32,
@ -343,21 +352,21 @@ pub const Surface = struct {
/// (GLFW guarantees that charCallback is called after keyCallback).
key_event: ?input.KeyEvent = null,
window_dimensions: MonitorDimensions,
/// The monitor dimensions so we can toggle fullscreen on and off.
monitor_dims: MonitorDimensions,
pub const Options = struct {};
/// Initialize the surface into the given self pointer. This gives a
/// stable pointer to the destination that can be used for callbacks.
pub fn init(self: *Surface, app: *App) !void {
const fullscreen = if (app.config.fullscreen) glfw.Monitor.getPrimary().? else null;
// Create our window
const win = glfw.Window.create(
640,
480,
"ghostty",
fullscreen,
if (app.config.fullscreen) glfw.Monitor.getPrimary() else null,
null,
Renderer.glfwWindowHints(&app.config),
) orelse return glfw.mustGetErrorCode();
@ -405,17 +414,24 @@ pub const Surface = struct {
win.setMouseButtonCallback(mouseButtonCallback);
win.setDropCallback(dropCallback);
const dimensions: MonitorDimensions = dimensions: {
const pos = win.getPos();
const size = win.getFramebufferSize();
break :dimensions .{
.width = size.width,
.height = size.height,
.position_x = pos.x,
.position_y = pos.y,
};
};
const dimensions = .{ .width = size.width, .height = size.height, .position_x = pos.x, .position_y = pos.y };
// Build our result
self.* = .{
.app = app,
.window = win,
.cursor = null,
.core_surface = undefined,
.window_dimensions = dimensions,
.monitor_dims = dimensions,
};
errdefer self.* = undefined;