mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
lots of stubbing so window will kind of compile for embedded
This commit is contained in:
@ -44,6 +44,7 @@ void ghostty_config_finalize(ghostty_config_t);
|
|||||||
|
|
||||||
ghostty_app_t ghostty_app_new(ghostty_runtime_config_s *, ghostty_config_t);
|
ghostty_app_t ghostty_app_new(ghostty_runtime_config_s *, ghostty_config_t);
|
||||||
void ghostty_app_free(ghostty_app_t);
|
void ghostty_app_free(ghostty_app_t);
|
||||||
|
int ghostty_app_tick(ghostty_app_t);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
21
src/App.zig
21
src/App.zig
@ -147,6 +147,13 @@ pub fn wakeup(self: App) void {
|
|||||||
/// application quits or every window is closed.
|
/// application quits or every window is closed.
|
||||||
pub fn run(self: *App) !void {
|
pub fn run(self: *App) !void {
|
||||||
while (!self.quit and self.windows.items.len > 0) {
|
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.
|
// Block for any events.
|
||||||
try self.runtime.wait();
|
try self.runtime.wait();
|
||||||
|
|
||||||
@ -165,7 +172,6 @@ pub fn run(self: *App) !void {
|
|||||||
|
|
||||||
// Drain our mailbox only if we're not quitting.
|
// Drain our mailbox only if we're not quitting.
|
||||||
if (!self.quit) try self.drainMailbox();
|
if (!self.quit) try self.drainMailbox();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Drain the mailbox.
|
/// Drain the mailbox.
|
||||||
@ -201,6 +207,11 @@ fn newTab(self: *App, msg: Message.NewWindow) !void {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (comptime build_config.artifact != .exe) {
|
||||||
|
log.warn("tabbing is not supported in embedded mode", .{});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const parent = msg.parent orelse {
|
const parent = msg.parent orelse {
|
||||||
log.warn("parent must be set in new_tab message", .{});
|
log.warn("parent must be set in new_tab message", .{});
|
||||||
return;
|
return;
|
||||||
@ -332,6 +343,14 @@ pub const CAPI = struct {
|
|||||||
return app;
|
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 {
|
export fn ghostty_app_free(ptr: ?*App) void {
|
||||||
if (ptr) |v| {
|
if (ptr) |v| {
|
||||||
v.destroy();
|
v.destroy();
|
||||||
|
@ -4,6 +4,14 @@
|
|||||||
//! example for the macOS build of Ghostty so that we can use a native
|
//! example for the macOS build of Ghostty so that we can use a native
|
||||||
//! Swift+XCode-based application.
|
//! 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 {
|
pub const App = struct {
|
||||||
/// Because we only expect the embedding API to be used in embedded
|
/// Because we only expect the embedding API to be used in embedded
|
||||||
/// environments, the options are extern so that we can expose it
|
/// 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 {
|
pub fn deinit(self: *Window) void {
|
||||||
_ = self;
|
_ = 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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -308,6 +308,7 @@ pub fn finalizeWindowInit(self: *const Metal, win: apprt.runtime.Window) !void {
|
|||||||
// Set our window backing layer to be our swapchain
|
// Set our window backing layer to be our swapchain
|
||||||
const nswindow = switch (apprt.runtime) {
|
const nswindow = switch (apprt.runtime) {
|
||||||
apprt.glfw => objc.Object.fromId(glfwNative.getCocoaWindow(win.window).?),
|
apprt.glfw => objc.Object.fromId(glfwNative.getCocoaWindow(win.window).?),
|
||||||
|
apprt.embedded => @panic("TODO"),
|
||||||
else => @compileError("unsupported apprt for metal"),
|
else => @compileError("unsupported apprt for metal"),
|
||||||
};
|
};
|
||||||
const contentView = objc.Object.fromId(nswindow.getProperty(?*anyopaque, "contentView").?);
|
const contentView = objc.Object.fromId(nswindow.getProperty(?*anyopaque, "contentView").?);
|
||||||
@ -613,6 +614,7 @@ pub fn render(
|
|||||||
state.mutex.lock();
|
state.mutex.lock();
|
||||||
defer state.mutex.unlock();
|
defer state.mutex.unlock();
|
||||||
|
|
||||||
|
if (DevMode.enabled) {
|
||||||
if (state.devmode) |dm| {
|
if (state.devmode) |dm| {
|
||||||
if (dm.visible) {
|
if (dm.visible) {
|
||||||
imgui.ImplMetal.newFrame(desc.value);
|
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("presentDrawable:"), .{surface.value});
|
||||||
buffer.msgSend(void, objc.sel("commit"), .{});
|
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.
|
// and we split them equal across all boundaries.
|
||||||
const padding = self.padding.explicit.add(if (self.padding.balance)
|
const padding = self.padding.explicit.add(if (self.padding.balance)
|
||||||
renderer.Padding.balanced(dim, grid_size, self.cell_size)
|
renderer.Padding.balanced(dim, grid_size, self.cell_size)
|
||||||
else .{});
|
else
|
||||||
|
.{});
|
||||||
const padded_dim = dim.subPadding(padding);
|
const padded_dim = dim.subPadding(padding);
|
||||||
|
|
||||||
// Update our shaper
|
// Update our shaper
|
||||||
|
Reference in New Issue
Block a user