From c68f8082df8dfffe1730394d1a5b4c0b6798f751 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 17 Feb 2023 09:03:23 -0800 Subject: [PATCH] apprt: can pass options through to Windows --- include/ghostty.h | 1 + src/App.zig | 6 +++++- src/Window.zig | 9 +++++++-- src/apprt/embedded.zig | 13 +++++++++---- src/apprt/glfw.zig | 6 +++++- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/ghostty.h b/include/ghostty.h index 8ed455aea..5557844ea 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -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 diff --git a/src/App.zig b/src/App.zig index 462847d14..c55f22d67 100644 --- a/src/App.zig +++ b/src/App.zig @@ -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(); diff --git a/src/Window.zig b/src/Window.zig index c43f68b08..423432409 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -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. diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index 596b36f5d..3faa445b3 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -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 }; diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index f64ad200d..1e03f30e9 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -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,