apprt: can pass options through to Windows

This commit is contained in:
Mitchell Hashimoto
2023-02-17 09:03:23 -08:00
parent 085d462a68
commit c68f8082df
5 changed files with 27 additions and 8 deletions

View File

@ -31,6 +31,7 @@ typedef struct {
// Opaque types
typedef void *ghostty_app_t;
typedef void *ghostty_config_t;
typedef void *ghostty_surface_t;
//-------------------------------------------------------------------
// Published API

View File

@ -189,7 +189,11 @@ fn drainMailbox(self: *App) !void {
/// Create a new window
fn newWindow(self: *App, msg: Message.NewWindow) !*Window {
var window = try Window.create(self.alloc, self, self.config);
if (comptime build_config.artifact != .exe) {
@panic("newWindow is not supported for embedded ghostty");
}
var window = try Window.create(self.alloc, self, self.config, .{});
errdefer window.destroy();
try self.windows.append(self.alloc, window);
errdefer _ = self.windows.pop();

View File

@ -128,12 +128,17 @@ const Mouse = struct {
/// Create a new window. This allocates and returns a pointer because we
/// need a stable pointer for user data callbacks. Therefore, a stack-only
/// initialization is not currently possible.
pub fn create(alloc: Allocator, app: *App, config: *const Config) !*Window {
pub fn create(
alloc: Allocator,
app: *App,
config: *const Config,
rt_opts: apprt.runtime.Window.Options,
) !*Window {
var self = try alloc.create(Window);
errdefer alloc.destroy(self);
// Create the windowing system
var window = try apprt.runtime.Window.init(app, self);
var window = try apprt.runtime.Window.init(app, self, rt_opts);
errdefer window.deinit();
// Initialize our renderer with our initialized windowing system.

View File

@ -45,16 +45,21 @@ pub const App = struct {
};
pub const Window = struct {
pub fn deinit(self: *Window) void {
_ = self;
}
pub const Options = extern struct {
id: usize,
};
pub fn init(app: *const CoreApp, core_win: *CoreWindow) !Window {
pub fn init(app: *const CoreApp, core_win: *CoreWindow, opts: Options) !Window {
_ = app;
_ = core_win;
_ = opts;
return .{};
}
pub fn deinit(self: *Window) void {
_ = self;
}
pub fn getContentScale(self: *const Window) !apprt.ContentScale {
_ = self;
return apprt.ContentScale{ .x = 1, .y = 1 };

View File

@ -58,7 +58,11 @@ pub const Window = struct {
/// The glfw mouse cursor handle.
cursor: glfw.Cursor,
pub fn init(app: *const CoreApp, core_win: *CoreWindow) !Window {
pub const Options = struct {};
pub fn init(app: *const CoreApp, core_win: *CoreWindow, opts: Options) !Window {
_ = opts;
// Create our window
const win = glfw.Window.create(
640,