lots of stubbing so window will kind of compile for embedded

This commit is contained in:
Mitchell Hashimoto
2023-02-17 08:49:43 -08:00
parent eed6979868
commit 085d462a68
4 changed files with 103 additions and 25 deletions

View File

@ -44,6 +44,7 @@ void ghostty_config_finalize(ghostty_config_t);
ghostty_app_t ghostty_app_new(ghostty_runtime_config_s *, ghostty_config_t);
void ghostty_app_free(ghostty_app_t);
int ghostty_app_tick(ghostty_app_t);
#ifdef __cplusplus
}

View File

@ -147,6 +147,13 @@ pub fn wakeup(self: App) void {
/// application quits or every window is closed.
pub fn run(self: *App) !void {
while (!self.quit and self.windows.items.len > 0) {
try self.tick();
}
}
/// Tick ticks the app loop. This will drain our mailbox and process those
/// events.
pub fn tick(self: *App) !void {
// Block for any events.
try self.runtime.wait();
@ -165,7 +172,6 @@ pub fn run(self: *App) !void {
// Drain our mailbox only if we're not quitting.
if (!self.quit) try self.drainMailbox();
}
}
/// Drain the mailbox.
@ -201,6 +207,11 @@ fn newTab(self: *App, msg: Message.NewWindow) !void {
return;
}
if (comptime build_config.artifact != .exe) {
log.warn("tabbing is not supported in embedded mode", .{});
return;
}
const parent = msg.parent orelse {
log.warn("parent must be set in new_tab message", .{});
return;
@ -332,6 +343,14 @@ pub const CAPI = struct {
return app;
}
/// Tick the event loop. This should be called whenever the "wakeup"
/// callback is invoked for the runtime.
export fn ghostty_app_tick(v: *App) void {
v.tick() catch |err| {
log.err("error app tick err={}", .{err});
};
}
export fn ghostty_app_free(ptr: ?*App) void {
if (ptr) |v| {
v.destroy();

View File

@ -4,6 +4,14 @@
//! example for the macOS build of Ghostty so that we can use a native
//! Swift+XCode-based application.
const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const apprt = @import("../apprt.zig");
const CoreApp = @import("../App.zig");
const CoreWindow = @import("../Window.zig");
pub const App = struct {
/// Because we only expect the embedding API to be used in embedded
/// environments, the options are extern so that we can expose it
@ -40,4 +48,50 @@ pub const Window = struct {
pub fn deinit(self: *Window) void {
_ = self;
}
pub fn init(app: *const CoreApp, core_win: *CoreWindow) !Window {
_ = app;
_ = core_win;
return .{};
}
pub fn getContentScale(self: *const Window) !apprt.ContentScale {
_ = self;
return apprt.ContentScale{ .x = 1, .y = 1 };
}
pub fn getSize(self: *const Window) !apprt.WindowSize {
_ = self;
return apprt.WindowSize{ .width = 1, .height = 1 };
}
pub fn setSizeLimits(self: *Window, min: apprt.WindowSize, max_: ?apprt.WindowSize) !void {
_ = self;
_ = min;
_ = max_;
}
pub fn setTitle(self: *Window, slice: [:0]const u8) !void {
_ = self;
_ = slice;
}
pub fn getClipboardString(self: *const Window) ![:0]const u8 {
_ = self;
return "";
}
pub fn setClipboardString(self: *const Window, val: [:0]const u8) !void {
_ = self;
_ = val;
}
pub fn setShouldClose(self: *Window) void {
_ = self;
}
pub fn shouldClose(self: *const Window) bool {
_ = self;
return false;
}
};

View File

@ -308,6 +308,7 @@ pub fn finalizeWindowInit(self: *const Metal, win: apprt.runtime.Window) !void {
// Set our window backing layer to be our swapchain
const nswindow = switch (apprt.runtime) {
apprt.glfw => objc.Object.fromId(glfwNative.getCocoaWindow(win.window).?),
apprt.embedded => @panic("TODO"),
else => @compileError("unsupported apprt for metal"),
};
const contentView = objc.Object.fromId(nswindow.getProperty(?*anyopaque, "contentView").?);
@ -613,6 +614,7 @@ pub fn render(
state.mutex.lock();
defer state.mutex.unlock();
if (DevMode.enabled) {
if (state.devmode) |dm| {
if (dm.visible) {
imgui.ImplMetal.newFrame(desc.value);
@ -627,6 +629,7 @@ pub fn render(
}
}
}
}
buffer.msgSend(void, objc.sel("presentDrawable:"), .{surface.value});
buffer.msgSend(void, objc.sel("commit"), .{});
@ -690,7 +693,8 @@ pub fn setScreenSize(self: *Metal, _: renderer.ScreenSize) !void {
// and we split them equal across all boundaries.
const padding = self.padding.explicit.add(if (self.padding.balance)
renderer.Padding.balanced(dim, grid_size, self.cell_size)
else .{});
else
.{});
const padded_dim = dim.subPadding(padding);
// Update our shaper