mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-25 13:16:11 +03:00
rename more stuff
This commit is contained in:
@ -29,8 +29,8 @@ visible: bool = false,
|
|||||||
/// Our app config
|
/// Our app config
|
||||||
config: ?*const Config = null,
|
config: ?*const Config = null,
|
||||||
|
|
||||||
/// The window we're tracking.
|
/// The surface we're tracking.
|
||||||
window: ?*Surface = null,
|
surface: ?*Surface = null,
|
||||||
|
|
||||||
/// Update the state associated with the dev mode. This should generally
|
/// Update the state associated with the dev mode. This should generally
|
||||||
/// only be called paired with a render since it otherwise wastes CPU
|
/// only be called paired with a render since it otherwise wastes CPU
|
||||||
@ -86,20 +86,20 @@ pub fn update(self: *const DevMode) !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.window) |window| {
|
if (self.surface) |surface| {
|
||||||
if (imgui.collapsingHeader("Font Manager", null, .{})) {
|
if (imgui.collapsingHeader("Font Manager", null, .{})) {
|
||||||
imgui.text("Glyphs: %d", window.font_group.glyphs.count());
|
imgui.text("Glyphs: %d", surface.font_group.glyphs.count());
|
||||||
imgui.sameLine(0, -1);
|
imgui.sameLine(0, -1);
|
||||||
helpMarker("The number of glyphs loaded and rendered into a " ++
|
helpMarker("The number of glyphs loaded and rendered into a " ++
|
||||||
"font atlas currently.");
|
"font atlas currently.");
|
||||||
|
|
||||||
const Renderer = @TypeOf(window.renderer);
|
const Renderer = @TypeOf(surface.renderer);
|
||||||
if (imgui.treeNode("Atlas: Greyscale", .{ .default_open = true })) {
|
if (imgui.treeNode("Atlas: Greyscale", .{ .default_open = true })) {
|
||||||
defer imgui.treePop();
|
defer imgui.treePop();
|
||||||
const atlas = &window.font_group.atlas_greyscale;
|
const atlas = &surface.font_group.atlas_greyscale;
|
||||||
const tex = switch (Renderer) {
|
const tex = switch (Renderer) {
|
||||||
renderer.OpenGL => @intCast(usize, window.renderer.texture.id),
|
renderer.OpenGL => @intCast(usize, surface.renderer.texture.id),
|
||||||
renderer.Metal => @ptrToInt(window.renderer.texture_greyscale.value),
|
renderer.Metal => @ptrToInt(surface.renderer.texture_greyscale.value),
|
||||||
else => @compileError("renderer unsupported, add it!"),
|
else => @compileError("renderer unsupported, add it!"),
|
||||||
};
|
};
|
||||||
try self.atlasInfo(atlas, tex);
|
try self.atlasInfo(atlas, tex);
|
||||||
@ -107,10 +107,10 @@ pub fn update(self: *const DevMode) !void {
|
|||||||
|
|
||||||
if (imgui.treeNode("Atlas: Color (Emoji)", .{ .default_open = true })) {
|
if (imgui.treeNode("Atlas: Color (Emoji)", .{ .default_open = true })) {
|
||||||
defer imgui.treePop();
|
defer imgui.treePop();
|
||||||
const atlas = &window.font_group.atlas_color;
|
const atlas = &surface.font_group.atlas_color;
|
||||||
const tex = switch (Renderer) {
|
const tex = switch (Renderer) {
|
||||||
renderer.OpenGL => @intCast(usize, window.renderer.texture_color.id),
|
renderer.OpenGL => @intCast(usize, surface.renderer.texture_color.id),
|
||||||
renderer.Metal => @ptrToInt(window.renderer.texture_color.value),
|
renderer.Metal => @ptrToInt(surface.renderer.texture_color.value),
|
||||||
else => @compileError("renderer unsupported, add it!"),
|
else => @compileError("renderer unsupported, add it!"),
|
||||||
};
|
};
|
||||||
try self.atlasInfo(atlas, tex);
|
try self.atlasInfo(atlas, tex);
|
||||||
|
@ -34,7 +34,7 @@ const DevMode = @import("DevMode.zig");
|
|||||||
const App = @import("App.zig");
|
const App = @import("App.zig");
|
||||||
const internal_os = @import("os/main.zig");
|
const internal_os = @import("os/main.zig");
|
||||||
|
|
||||||
const log = std.log.scoped(.window);
|
const log = std.log.scoped(.surface);
|
||||||
|
|
||||||
// The renderer implementation to use.
|
// The renderer implementation to use.
|
||||||
const Renderer = renderer.Renderer;
|
const Renderer = renderer.Renderer;
|
||||||
@ -56,7 +56,7 @@ font_size: font.face.DesiredSize,
|
|||||||
/// Imgui context
|
/// Imgui context
|
||||||
imgui_ctx: if (DevMode.enabled) *imgui.Context else void,
|
imgui_ctx: if (DevMode.enabled) *imgui.Context else void,
|
||||||
|
|
||||||
/// The renderer for this window.
|
/// The renderer for this surface.
|
||||||
renderer: Renderer,
|
renderer: Renderer,
|
||||||
|
|
||||||
/// The render state
|
/// The render state
|
||||||
@ -94,7 +94,7 @@ config: *const Config,
|
|||||||
/// like such as "control-v" will write a "v" even if they're intercepted.
|
/// like such as "control-v" will write a "v" even if they're intercepted.
|
||||||
ignore_char: bool = false,
|
ignore_char: bool = false,
|
||||||
|
|
||||||
/// Mouse state for the window.
|
/// Mouse state for the surface.
|
||||||
const Mouse = struct {
|
const Mouse = struct {
|
||||||
/// The last tracked mouse button state by button.
|
/// The last tracked mouse button state by button.
|
||||||
click_state: [input.MouseButton.max]input.MouseButtonState = .{.release} ** input.MouseButton.max,
|
click_state: [input.MouseButton.max]input.MouseButtonState = .{.release} ** input.MouseButton.max,
|
||||||
@ -109,7 +109,7 @@ const Mouse = struct {
|
|||||||
|
|
||||||
/// The starting xpos/ypos of the left click. Note that if scrolling occurs,
|
/// The starting xpos/ypos of the left click. Note that if scrolling occurs,
|
||||||
/// these will point to different "cells", but the xpos/ypos will stay
|
/// these will point to different "cells", but the xpos/ypos will stay
|
||||||
/// stable during scrolling relative to the window.
|
/// stable during scrolling relative to the surface.
|
||||||
left_click_xpos: f64 = 0,
|
left_click_xpos: f64 = 0,
|
||||||
left_click_ypos: f64 = 0,
|
left_click_ypos: f64 = 0,
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ pub fn init(
|
|||||||
.left = padding_x,
|
.left = padding_x,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create our terminal grid with the initial window size
|
// Create our terminal grid with the initial size
|
||||||
var renderer_impl = try Renderer.init(alloc, .{
|
var renderer_impl = try Renderer.init(alloc, .{
|
||||||
.config = config,
|
.config = config,
|
||||||
.font_group = font_group,
|
.font_group = font_group,
|
||||||
@ -291,15 +291,15 @@ pub fn init(
|
|||||||
.explicit = padding,
|
.explicit = padding,
|
||||||
.balance = config.@"window-padding-balance",
|
.balance = config.@"window-padding-balance",
|
||||||
},
|
},
|
||||||
.window_mailbox = .{ .window = self, .app = app.mailbox },
|
.surface_mailbox = .{ .surface = self, .app = app.mailbox },
|
||||||
});
|
});
|
||||||
errdefer renderer_impl.deinit();
|
errdefer renderer_impl.deinit();
|
||||||
|
|
||||||
// Calculate our grid size based on known dimensions.
|
// Calculate our grid size based on known dimensions.
|
||||||
const window_size = try rt_surface.getSize();
|
const surface_size = try rt_surface.getSize();
|
||||||
const screen_size: renderer.ScreenSize = .{
|
const screen_size: renderer.ScreenSize = .{
|
||||||
.width = window_size.width,
|
.width = surface_size.width,
|
||||||
.height = window_size.height,
|
.height = surface_size.height,
|
||||||
};
|
};
|
||||||
const grid_size = renderer.GridSize.init(
|
const grid_size = renderer.GridSize.init(
|
||||||
screen_size.subPadding(padding),
|
screen_size.subPadding(padding),
|
||||||
@ -328,7 +328,7 @@ pub fn init(
|
|||||||
.renderer_state = &self.renderer_state,
|
.renderer_state = &self.renderer_state,
|
||||||
.renderer_wakeup = render_thread.wakeup,
|
.renderer_wakeup = render_thread.wakeup,
|
||||||
.renderer_mailbox = render_thread.mailbox,
|
.renderer_mailbox = render_thread.mailbox,
|
||||||
.window_mailbox = .{ .window = self, .app = app.mailbox },
|
.surface_mailbox = .{ .surface = self, .app = app.mailbox },
|
||||||
});
|
});
|
||||||
errdefer io.deinit();
|
errdefer io.deinit();
|
||||||
|
|
||||||
@ -336,10 +336,10 @@ pub fn init(
|
|||||||
var io_thread = try termio.Thread.init(alloc, &self.io);
|
var io_thread = try termio.Thread.init(alloc, &self.io);
|
||||||
errdefer io_thread.deinit();
|
errdefer io_thread.deinit();
|
||||||
|
|
||||||
// True if this window is hosting devmode. We only host devmode on
|
// True if this surface is hosting devmode. We only host devmode on
|
||||||
// the first window since imgui is not threadsafe. We need to do some
|
// the first surface since imgui is not threadsafe. We need to do some
|
||||||
// work to make DevMode work with multiple threads.
|
// work to make DevMode work with multiple threads.
|
||||||
const host_devmode = DevMode.enabled and DevMode.instance.window == null;
|
const host_devmode = DevMode.enabled and DevMode.instance.surface == null;
|
||||||
|
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.alloc = alloc,
|
.alloc = alloc,
|
||||||
@ -383,15 +383,15 @@ pub fn init(
|
|||||||
}, null);
|
}, null);
|
||||||
|
|
||||||
// Call our size callback which handles all our retina setup
|
// Call our size callback which handles all our retina setup
|
||||||
// Note: this shouldn't be necessary and when we clean up the window
|
// Note: this shouldn't be necessary and when we clean up the surface
|
||||||
// init stuff we should get rid of this. But this is required because
|
// init stuff we should get rid of this. But this is required because
|
||||||
// sizeCallback does retina-aware stuff we don't do here and don't want
|
// sizeCallback does retina-aware stuff we don't do here and don't want
|
||||||
// to duplicate.
|
// to duplicate.
|
||||||
try self.sizeCallback(window_size);
|
try self.sizeCallback(surface_size);
|
||||||
|
|
||||||
// Load imgui. This must be done LAST because it has to be done after
|
// Load imgui. This must be done LAST because it has to be done after
|
||||||
// all our GLFW setup is complete.
|
// all our GLFW setup is complete.
|
||||||
if (DevMode.enabled and DevMode.instance.window == null) {
|
if (DevMode.enabled and DevMode.instance.surface == null) {
|
||||||
const dev_io = try imgui.IO.get();
|
const dev_io = try imgui.IO.get();
|
||||||
dev_io.cval().IniFilename = "ghostty_dev_mode.ini";
|
dev_io.cval().IniFilename = "ghostty_dev_mode.ini";
|
||||||
|
|
||||||
@ -406,14 +406,14 @@ pub fn init(
|
|||||||
const style = try imgui.Style.get();
|
const style = try imgui.Style.get();
|
||||||
style.colorsDark();
|
style.colorsDark();
|
||||||
|
|
||||||
// Add our window to the instance if it isn't set.
|
// Add our surface to the instance if it isn't set.
|
||||||
DevMode.instance.window = self;
|
DevMode.instance.surface = self;
|
||||||
|
|
||||||
// Let our renderer setup
|
// Let our renderer setup
|
||||||
try renderer_impl.initDevMode(rt_surface);
|
try renderer_impl.initDevMode(rt_surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give the renderer one more opportunity to finalize any window
|
// Give the renderer one more opportunity to finalize any surface
|
||||||
// setup on the main thread prior to spinning up the rendering thread.
|
// setup on the main thread prior to spinning up the rendering thread.
|
||||||
try renderer_impl.finalizeSurfaceInit(rt_surface);
|
try renderer_impl.finalizeSurfaceInit(rt_surface);
|
||||||
|
|
||||||
@ -434,7 +434,7 @@ pub fn init(
|
|||||||
self.io_thr.setName("io") catch {};
|
self.io_thr.setName("io") catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy(self: *Surface) void {
|
pub fn deinit(self: *Surface) void {
|
||||||
// Stop rendering thread
|
// Stop rendering thread
|
||||||
{
|
{
|
||||||
self.renderer_thread.stop.notify() catch |err|
|
self.renderer_thread.stop.notify() catch |err|
|
||||||
@ -445,12 +445,12 @@ pub fn destroy(self: *Surface) void {
|
|||||||
self.renderer.threadEnter(self.rt_surface) catch unreachable;
|
self.renderer.threadEnter(self.rt_surface) catch unreachable;
|
||||||
|
|
||||||
// If we are devmode-owning, clean that up.
|
// If we are devmode-owning, clean that up.
|
||||||
if (DevMode.enabled and DevMode.instance.window == self) {
|
if (DevMode.enabled and DevMode.instance.surface == self) {
|
||||||
// Let our renderer clean up
|
// Let our renderer clean up
|
||||||
self.renderer.deinitDevMode();
|
self.renderer.deinitDevMode();
|
||||||
|
|
||||||
// Clear the window
|
// Clear the surface
|
||||||
DevMode.instance.window = null;
|
DevMode.instance.surface = null;
|
||||||
|
|
||||||
// Uninitialize imgui
|
// Uninitialize imgui
|
||||||
self.imgui_ctx.destroy();
|
self.imgui_ctx.destroy();
|
||||||
@ -471,19 +471,15 @@ pub fn destroy(self: *Surface) void {
|
|||||||
self.io_thread.deinit();
|
self.io_thread.deinit();
|
||||||
self.io.deinit();
|
self.io.deinit();
|
||||||
|
|
||||||
self.rt_surface.deinit();
|
|
||||||
|
|
||||||
self.font_group.deinit(self.alloc);
|
self.font_group.deinit(self.alloc);
|
||||||
self.font_lib.deinit();
|
self.font_lib.deinit();
|
||||||
self.alloc.destroy(self.font_group);
|
self.alloc.destroy(self.font_group);
|
||||||
|
|
||||||
self.alloc.destroy(self.renderer_state.mutex);
|
self.alloc.destroy(self.renderer_state.mutex);
|
||||||
|
|
||||||
self.alloc.destroy(self);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called from the app thread to handle mailbox messages to our specific
|
/// Called from the app thread to handle mailbox messages to our specific
|
||||||
/// window.
|
/// surface.
|
||||||
pub fn handleMessage(self: *Surface, msg: Message) !void {
|
pub fn handleMessage(self: *Surface, msg: Message) !void {
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
.set_title => |*v| {
|
.set_title => |*v| {
|
||||||
@ -657,7 +653,7 @@ fn queueRender(self: *const Surface) !void {
|
|||||||
try self.renderer_thread.wakeup.notify();
|
try self.renderer_thread.wakeup.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sizeCallback(self: *Surface, size: apprt.WindowSize) !void {
|
pub fn sizeCallback(self: *Surface, size: apprt.SurfaceSize) !void {
|
||||||
const tracy = trace(@src());
|
const tracy = trace(@src());
|
||||||
defer tracy.end();
|
defer tracy.end();
|
||||||
|
|
||||||
@ -1034,8 +1030,8 @@ pub fn scrollCallback(self: *Surface, xoff: f64, yoff: f64) !void {
|
|||||||
const tracy = trace(@src());
|
const tracy = trace(@src());
|
||||||
defer tracy.end();
|
defer tracy.end();
|
||||||
|
|
||||||
// If our dev mode window is visible then we always schedule a render on
|
// If our dev mode surface is visible then we always schedule a render on
|
||||||
// cursor move because the cursor might touch our windows.
|
// cursor move because the cursor might touch our surfaces.
|
||||||
if (DevMode.enabled and DevMode.instance.visible) {
|
if (DevMode.enabled and DevMode.instance.visible) {
|
||||||
try self.queueRender();
|
try self.queueRender();
|
||||||
|
|
||||||
@ -1081,8 +1077,8 @@ fn mouseReport(
|
|||||||
mods: input.Mods,
|
mods: input.Mods,
|
||||||
pos: apprt.CursorPos,
|
pos: apprt.CursorPos,
|
||||||
) !void {
|
) !void {
|
||||||
// TODO: posToViewport currently clamps to the window boundary,
|
// TODO: posToViewport currently clamps to the surface boundary,
|
||||||
// do we want to not report mouse events at all outside the window?
|
// do we want to not report mouse events at all outside the surface?
|
||||||
|
|
||||||
// Depending on the event, we may do nothing at all.
|
// Depending on the event, we may do nothing at all.
|
||||||
switch (self.io.terminal.modes.mouse_event) {
|
switch (self.io.terminal.modes.mouse_event) {
|
||||||
@ -1278,8 +1274,8 @@ pub fn mouseButtonCallback(
|
|||||||
const tracy = trace(@src());
|
const tracy = trace(@src());
|
||||||
defer tracy.end();
|
defer tracy.end();
|
||||||
|
|
||||||
// If our dev mode window is visible then we always schedule a render on
|
// If our dev mode surface is visible then we always schedule a render on
|
||||||
// cursor move because the cursor might touch our windows.
|
// cursor move because the cursor might touch our surfaces.
|
||||||
if (DevMode.enabled and DevMode.instance.visible) {
|
if (DevMode.enabled and DevMode.instance.visible) {
|
||||||
try self.queueRender();
|
try self.queueRender();
|
||||||
|
|
||||||
@ -1395,8 +1391,8 @@ pub fn cursorPosCallback(
|
|||||||
const tracy = trace(@src());
|
const tracy = trace(@src());
|
||||||
defer tracy.end();
|
defer tracy.end();
|
||||||
|
|
||||||
// If our dev mode window is visible then we always schedule a render on
|
// If our dev mode surface is visible then we always schedule a render on
|
||||||
// cursor move because the cursor might touch our windows.
|
// cursor move because the cursor might touch our surfaces.
|
||||||
if (DevMode.enabled and DevMode.instance.visible) {
|
if (DevMode.enabled and DevMode.instance.visible) {
|
||||||
try self.queueRender();
|
try self.queueRender();
|
||||||
|
|
||||||
@ -1608,8 +1604,8 @@ fn dragLeftClickSingle(
|
|||||||
|
|
||||||
fn posToViewport(self: Surface, xpos: f64, ypos: f64) terminal.point.Viewport {
|
fn posToViewport(self: Surface, xpos: f64, ypos: f64) terminal.point.Viewport {
|
||||||
// xpos and ypos can be negative if while dragging, the user moves the
|
// xpos and ypos can be negative if while dragging, the user moves the
|
||||||
// mouse off the window. Likewise, they can be larger than our window
|
// mouse off the surface. Likewise, they can be larger than our surface
|
||||||
// width if the user drags out of the window positively.
|
// width if the user drags out of the surface positively.
|
||||||
return .{
|
return .{
|
||||||
.x = if (xpos < 0) 0 else x: {
|
.x = if (xpos < 0) 0 else x: {
|
||||||
// Our cell is the mouse divided by cell width
|
// Our cell is the mouse divided by cell width
|
||||||
|
@ -17,7 +17,7 @@ pub const glfw = @import("apprt/glfw.zig");
|
|||||||
pub const gtk = @import("apprt/gtk.zig");
|
pub const gtk = @import("apprt/gtk.zig");
|
||||||
pub const browser = @import("apprt/browser.zig");
|
pub const browser = @import("apprt/browser.zig");
|
||||||
pub const embedded = @import("apprt/embedded.zig");
|
pub const embedded = @import("apprt/embedded.zig");
|
||||||
pub const surface = @import("apprt/Surface.zig");
|
pub const surface = @import("apprt/surface.zig");
|
||||||
|
|
||||||
/// The implementation to use for the app runtime. This is comptime chosen
|
/// The implementation to use for the app runtime. This is comptime chosen
|
||||||
/// so that every build has exactly one application runtime implementation.
|
/// so that every build has exactly one application runtime implementation.
|
||||||
|
@ -83,6 +83,7 @@ pub const App = struct {
|
|||||||
|
|
||||||
// Create the surface -- because windows are surfaces for glfw.
|
// Create the surface -- because windows are surfaces for glfw.
|
||||||
try surface.init(self);
|
try surface.init(self);
|
||||||
|
errdefer surface.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn glfwErrorCallback(code: glfw.ErrorCode, desc: [:0]const u8) void {
|
fn glfwErrorCallback(code: glfw.ErrorCode, desc: [:0]const u8) void {
|
||||||
@ -232,12 +233,15 @@ pub const Surface = struct {
|
|||||||
|
|
||||||
// Initialize our surface now that we have the stable pointer.
|
// Initialize our surface now that we have the stable pointer.
|
||||||
try self.core_surface.init(app.app, app.app.config, self);
|
try self.core_surface.init(app.app, app.app.config, self);
|
||||||
errdefer self.core_surface.destroy();
|
errdefer self.core_surface.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Surface) void {
|
pub fn deinit(self: *Surface) void {
|
||||||
var tabgroup_opt: if (builtin.target.isDarwin()) ?objc.Object else void = undefined;
|
// First clean up our core surface so that all the rendering and IO stop.
|
||||||
if (comptime builtin.target.isDarwin()) {
|
self.core_surface.deinit();
|
||||||
|
|
||||||
|
var tabgroup_opt: if (App.Darwin.enabled) ?objc.Object else void = undefined;
|
||||||
|
if (App.Darwin.enabled) {
|
||||||
const nswindow = objc.Object.fromId(glfwNative.getCocoaWindow(self.window).?);
|
const nswindow = objc.Object.fromId(glfwNative.getCocoaWindow(self.window).?);
|
||||||
const tabgroup = nswindow.getProperty(objc.Object, "tabGroup");
|
const tabgroup = nswindow.getProperty(objc.Object, "tabGroup");
|
||||||
|
|
||||||
@ -286,7 +290,7 @@ pub const Surface = struct {
|
|||||||
/// Note: this interface is not good, we should redo it if we plan
|
/// Note: this interface is not good, we should redo it if we plan
|
||||||
/// to use this more. i.e. you can't set max width but no max height,
|
/// to use this more. i.e. you can't set max width but no max height,
|
||||||
/// or no mins.
|
/// or no mins.
|
||||||
pub fn setSizeLimits(self: *Surface, min: apprt.WindowSize, max_: ?apprt.WindowSize) !void {
|
pub fn setSizeLimits(self: *Surface, min: apprt.SurfaceSize, max_: ?apprt.SurfaceSize) !void {
|
||||||
self.window.setSizeLimits(.{
|
self.window.setSizeLimits(.{
|
||||||
.width = min.width,
|
.width = min.width,
|
||||||
.height = min.height,
|
.height = min.height,
|
||||||
@ -308,9 +312,9 @@ pub const Surface = struct {
|
|||||||
/// Returns the size of the window in pixels. The pixel size may
|
/// Returns the size of the window in pixels. The pixel size may
|
||||||
/// not match screen coordinate size but we should be able to convert
|
/// not match screen coordinate size but we should be able to convert
|
||||||
/// back and forth using getContentScale.
|
/// back and forth using getContentScale.
|
||||||
pub fn getSize(self: *const Surface) !apprt.WindowSize {
|
pub fn getSize(self: *const Surface) !apprt.SurfaceSize {
|
||||||
const size = self.window.getFramebufferSize();
|
const size = self.window.getFramebufferSize();
|
||||||
return apprt.WindowSize{ .width = size.width, .height = size.height };
|
return apprt.SurfaceSize{ .width = size.width, .height = size.height };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the cursor position in scaled pixels relative to the
|
/// Returns the cursor position in scaled pixels relative to the
|
||||||
|
@ -6,8 +6,8 @@ pub const ContentScale = struct {
|
|||||||
y: f32,
|
y: f32,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The size of the window in pixels.
|
/// The size of the surface in pixels.
|
||||||
pub const WindowSize = struct {
|
pub const SurfaceSize = struct {
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
};
|
};
|
||||||
|
@ -3,13 +3,13 @@ const Surface = @import("../Surface.zig");
|
|||||||
const renderer = @import("../renderer.zig");
|
const renderer = @import("../renderer.zig");
|
||||||
const termio = @import("../termio.zig");
|
const termio = @import("../termio.zig");
|
||||||
|
|
||||||
/// The message types that can be sent to a single window.
|
/// The message types that can be sent to a single surface.
|
||||||
pub const Message = union(enum) {
|
pub const Message = union(enum) {
|
||||||
/// Represents a write request. Magic number comes from the max size
|
/// Represents a write request. Magic number comes from the max size
|
||||||
/// we want this union to be.
|
/// we want this union to be.
|
||||||
pub const WriteReq = termio.MessageData(u8, 256);
|
pub const WriteReq = termio.MessageData(u8, 256);
|
||||||
|
|
||||||
/// Set the title of the window.
|
/// Set the title of the surface.
|
||||||
/// TODO: we should change this to a "WriteReq" style structure in
|
/// TODO: we should change this to a "WriteReq" style structure in
|
||||||
/// the termio message so that we can more efficiently send strings
|
/// the termio message so that we can more efficiently send strings
|
||||||
/// of any length
|
/// of any length
|
||||||
@ -25,25 +25,25 @@ pub const Message = union(enum) {
|
|||||||
clipboard_write: WriteReq,
|
clipboard_write: WriteReq,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A window mailbox.
|
/// A surface mailbox.
|
||||||
pub const Mailbox = struct {
|
pub const Mailbox = struct {
|
||||||
window: *Surface,
|
surface: *Surface,
|
||||||
app: *App.Mailbox,
|
app: *App.Mailbox,
|
||||||
|
|
||||||
/// Send a message to the window.
|
/// Send a message to the surface.
|
||||||
pub fn push(self: Mailbox, msg: Message, timeout: App.Mailbox.Timeout) App.Mailbox.Size {
|
pub fn push(self: Mailbox, msg: Message, timeout: App.Mailbox.Timeout) App.Mailbox.Size {
|
||||||
// Surface message sending is actually implemented on the app
|
// Surface message sending is actually implemented on the app
|
||||||
// thread, so we have to rewrap the message with our window
|
// thread, so we have to rewrap the message with our surface
|
||||||
// pointer and send it to the app thread.
|
// pointer and send it to the app thread.
|
||||||
const result = self.app.push(.{
|
const result = self.app.push(.{
|
||||||
.surface_message = .{
|
.surface_message = .{
|
||||||
.surface = self.window,
|
.surface = self.surface,
|
||||||
.message = msg,
|
.message = msg,
|
||||||
},
|
},
|
||||||
}, timeout);
|
}, timeout);
|
||||||
|
|
||||||
// Wake up our app loop
|
// Wake up our app loop
|
||||||
self.window.app.wakeup();
|
self.surface.app.wakeup();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
@ -89,7 +89,7 @@ focused: bool,
|
|||||||
padding: renderer.Options.Padding,
|
padding: renderer.Options.Padding,
|
||||||
|
|
||||||
/// The mailbox for communicating with the window.
|
/// The mailbox for communicating with the window.
|
||||||
window_mailbox: apprt.surface.Mailbox,
|
surface_mailbox: apprt.surface.Mailbox,
|
||||||
|
|
||||||
/// The raw structure that maps directly to the buffer sent to the vertex shader.
|
/// The raw structure that maps directly to the buffer sent to the vertex shader.
|
||||||
/// This must be "extern" so that the field order is not reordered by the
|
/// This must be "extern" so that the field order is not reordered by the
|
||||||
@ -311,7 +311,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !OpenGL {
|
|||||||
null,
|
null,
|
||||||
.focused = true,
|
.focused = true,
|
||||||
.padding = options.padding,
|
.padding = options.padding,
|
||||||
.window_mailbox = options.window_mailbox,
|
.surface_mailbox = options.surface_mailbox,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,7 +504,7 @@ pub fn setFontSize(self: *OpenGL, size: font.face.DesiredSize) !void {
|
|||||||
self.cell_size = new_cell_size;
|
self.cell_size = new_cell_size;
|
||||||
|
|
||||||
// Notify the window that the cell size changed.
|
// Notify the window that the cell size changed.
|
||||||
_ = self.window_mailbox.push(.{
|
_ = self.surface_mailbox.push(.{
|
||||||
.cell_size = new_cell_size,
|
.cell_size = new_cell_size,
|
||||||
}, .{ .forever = {} });
|
}, .{ .forever = {} });
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,12 @@ font_group: *font.GroupCache,
|
|||||||
/// Padding options for the viewport.
|
/// Padding options for the viewport.
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
|
|
||||||
/// The mailbox for sending the window messages. This is only valid
|
/// The mailbox for sending the surface messages. This is only valid
|
||||||
/// once the thread has started and should not be used outside of the thread.
|
/// once the thread has started and should not be used outside of the thread.
|
||||||
window_mailbox: apprt.surface.Mailbox,
|
surface_mailbox: apprt.surface.Mailbox,
|
||||||
|
|
||||||
pub const Padding = struct {
|
pub const Padding = struct {
|
||||||
// Explicit padding options, in pixels. The windowing thread is
|
// Explicit padding options, in pixels. The surface thread is
|
||||||
// expected to convert points to pixels for a given DPI.
|
// expected to convert points to pixels for a given DPI.
|
||||||
explicit: renderer.Padding,
|
explicit: renderer.Padding,
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ renderer_wakeup: xev.Async,
|
|||||||
/// The mailbox for notifying the renderer of things.
|
/// The mailbox for notifying the renderer of things.
|
||||||
renderer_mailbox: *renderer.Thread.Mailbox,
|
renderer_mailbox: *renderer.Thread.Mailbox,
|
||||||
|
|
||||||
/// The mailbox for communicating with the window.
|
/// The mailbox for communicating with the surface.
|
||||||
window_mailbox: apprt.surface.Mailbox,
|
surface_mailbox: apprt.surface.Mailbox,
|
||||||
|
|
||||||
/// The cached grid size whenever a resize is called.
|
/// The cached grid size whenever a resize is called.
|
||||||
grid_size: renderer.GridSize,
|
grid_size: renderer.GridSize,
|
||||||
@ -83,7 +83,7 @@ pub fn init(alloc: Allocator, opts: termio.Options) !Exec {
|
|||||||
.renderer_state = opts.renderer_state,
|
.renderer_state = opts.renderer_state,
|
||||||
.renderer_wakeup = opts.renderer_wakeup,
|
.renderer_wakeup = opts.renderer_wakeup,
|
||||||
.renderer_mailbox = opts.renderer_mailbox,
|
.renderer_mailbox = opts.renderer_mailbox,
|
||||||
.window_mailbox = opts.window_mailbox,
|
.surface_mailbox = opts.surface_mailbox,
|
||||||
.grid_size = opts.grid_size,
|
.grid_size = opts.grid_size,
|
||||||
.data = null,
|
.data = null,
|
||||||
};
|
};
|
||||||
@ -131,7 +131,7 @@ pub fn threadEnter(self: *Exec, thread: *termio.Thread) !ThreadData {
|
|||||||
.ev = ev_data_ptr,
|
.ev = ev_data_ptr,
|
||||||
.terminal = &self.terminal,
|
.terminal = &self.terminal,
|
||||||
.grid_size = &self.grid_size,
|
.grid_size = &self.grid_size,
|
||||||
.window_mailbox = self.window_mailbox,
|
.surface_mailbox = self.surface_mailbox,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -638,7 +638,7 @@ const StreamHandler = struct {
|
|||||||
alloc: Allocator,
|
alloc: Allocator,
|
||||||
grid_size: *renderer.GridSize,
|
grid_size: *renderer.GridSize,
|
||||||
terminal: *terminal.Terminal,
|
terminal: *terminal.Terminal,
|
||||||
window_mailbox: apprt.surface.Mailbox,
|
surface_mailbox: apprt.surface.Mailbox,
|
||||||
|
|
||||||
/// This is set to true when a message was written to the writer
|
/// This is set to true when a message was written to the writer
|
||||||
/// mailbox. This can be used by callers to determine if they need
|
/// mailbox. This can be used by callers to determine if they need
|
||||||
@ -983,7 +983,7 @@ const StreamHandler = struct {
|
|||||||
std.mem.copy(u8, &buf, title);
|
std.mem.copy(u8, &buf, title);
|
||||||
buf[title.len] = 0;
|
buf[title.len] = 0;
|
||||||
|
|
||||||
_ = self.window_mailbox.push(.{
|
_ = self.surface_mailbox.push(.{
|
||||||
.set_title = buf,
|
.set_title = buf,
|
||||||
}, .{ .forever = {} });
|
}, .{ .forever = {} });
|
||||||
}
|
}
|
||||||
@ -995,14 +995,14 @@ const StreamHandler = struct {
|
|||||||
|
|
||||||
// Get clipboard contents
|
// Get clipboard contents
|
||||||
if (data.len == 1 and data[0] == '?') {
|
if (data.len == 1 and data[0] == '?') {
|
||||||
_ = self.window_mailbox.push(.{
|
_ = self.surface_mailbox.push(.{
|
||||||
.clipboard_read = kind,
|
.clipboard_read = kind,
|
||||||
}, .{ .forever = {} });
|
}, .{ .forever = {} });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write clipboard contents
|
// Write clipboard contents
|
||||||
_ = self.window_mailbox.push(.{
|
_ = self.surface_mailbox.push(.{
|
||||||
.clipboard_write = try apprt.surface.Message.WriteReq.init(
|
.clipboard_write = try apprt.surface.Message.WriteReq.init(
|
||||||
self.alloc,
|
self.alloc,
|
||||||
data,
|
data,
|
||||||
|
@ -15,7 +15,7 @@ screen_size: renderer.ScreenSize,
|
|||||||
config: *const Config,
|
config: *const Config,
|
||||||
|
|
||||||
/// The render state. The IO implementation can modify anything here. The
|
/// The render state. The IO implementation can modify anything here. The
|
||||||
/// window thread will setup the initial "terminal" pointer but the IO impl
|
/// surface thread will setup the initial "terminal" pointer but the IO impl
|
||||||
/// is free to change that if that is useful (i.e. doing some sort of dual
|
/// is free to change that if that is useful (i.e. doing some sort of dual
|
||||||
/// terminal implementation.)
|
/// terminal implementation.)
|
||||||
renderer_state: *renderer.State,
|
renderer_state: *renderer.State,
|
||||||
@ -27,5 +27,5 @@ renderer_wakeup: xev.Async,
|
|||||||
/// The mailbox for renderer messages.
|
/// The mailbox for renderer messages.
|
||||||
renderer_mailbox: *renderer.Thread.Mailbox,
|
renderer_mailbox: *renderer.Thread.Mailbox,
|
||||||
|
|
||||||
/// The mailbox for sending the window messages.
|
/// The mailbox for sending the surface messages.
|
||||||
window_mailbox: apprt.surface.Mailbox,
|
surface_mailbox: apprt.surface.Mailbox,
|
||||||
|
Reference in New Issue
Block a user