mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-22 11:46:11 +03:00
termio: change resize message to use new size struct
This commit is contained in:
@ -1365,14 +1365,7 @@ fn setCellSize(self: *Surface, size: renderer.CellSize) !void {
|
|||||||
if (self.config.window_padding_balance) self.size.balancePadding();
|
if (self.config.window_padding_balance) self.size.balancePadding();
|
||||||
|
|
||||||
// Notify the terminal
|
// Notify the terminal
|
||||||
self.io.queueMessage(.{
|
self.io.queueMessage(.{ .resize = self.size }, .unlocked);
|
||||||
.resize = .{
|
|
||||||
.grid_size = self.size.grid(),
|
|
||||||
.cell_size = self.size.cell,
|
|
||||||
.screen_size = self.size.screen,
|
|
||||||
.padding = self.size.padding,
|
|
||||||
},
|
|
||||||
}, .unlocked);
|
|
||||||
|
|
||||||
// Notify the window
|
// Notify the window
|
||||||
try self.rt_app.performAction(
|
try self.rt_app.performAction(
|
||||||
@ -1468,14 +1461,7 @@ fn resize(self: *Surface, size: renderer.ScreenSize) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mail the IO thread
|
// Mail the IO thread
|
||||||
self.io.queueMessage(.{
|
self.io.queueMessage(.{ .resize = self.size }, .unlocked);
|
||||||
.resize = .{
|
|
||||||
.grid_size = grid_size,
|
|
||||||
.cell_size = self.size.cell,
|
|
||||||
.screen_size = self.size.screen,
|
|
||||||
.padding = self.size.padding,
|
|
||||||
},
|
|
||||||
}, .unlocked);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called to set the preedit state for character input. Preedit is used
|
/// Called to set the preedit state for character input. Preedit is used
|
||||||
|
@ -25,6 +25,12 @@ pub const Size = struct {
|
|||||||
return GridSize.init(self.screen.subPadding(self.padding), self.cell);
|
return GridSize.init(self.screen.subPadding(self.padding), self.cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The size of the terminal. This is the same as the screen without
|
||||||
|
/// padding.
|
||||||
|
pub fn terminal(self: Size) ScreenSize {
|
||||||
|
return self.screen.subPadding(self.padding);
|
||||||
|
}
|
||||||
|
|
||||||
/// Set the padding to be balanced around the grid. Overwrites the current
|
/// Set the padding to be balanced around the grid. Overwrites the current
|
||||||
/// padding.
|
/// padding.
|
||||||
pub fn balancePadding(self: *Size) void {
|
pub fn balancePadding(self: *Size) void {
|
||||||
|
@ -349,18 +349,16 @@ pub fn changeConfig(self: *Termio, td: *ThreadData, config: *DerivedConfig) !voi
|
|||||||
pub fn resize(
|
pub fn resize(
|
||||||
self: *Termio,
|
self: *Termio,
|
||||||
td: *ThreadData,
|
td: *ThreadData,
|
||||||
grid_size: renderer.GridSize,
|
size: renderer.Size,
|
||||||
cell_size: renderer.CellSize,
|
|
||||||
screen_size: renderer.ScreenSize,
|
|
||||||
padding: renderer.Padding,
|
|
||||||
) !void {
|
) !void {
|
||||||
|
const grid_size = size.grid();
|
||||||
|
|
||||||
// Update the size of our pty.
|
// Update the size of our pty.
|
||||||
const padded_size = screen_size.subPadding(padding);
|
try self.backend.resize(grid_size, size.terminal());
|
||||||
try self.backend.resize(grid_size, padded_size);
|
|
||||||
|
|
||||||
// Update our cached grid size
|
// Update our cached grid size
|
||||||
self.grid_size = grid_size;
|
self.grid_size = size.grid();
|
||||||
self.cell_size = cell_size;
|
self.cell_size = size.cell;
|
||||||
|
|
||||||
// Enter the critical area that we want to keep small
|
// Enter the critical area that we want to keep small
|
||||||
{
|
{
|
||||||
@ -375,8 +373,8 @@ pub fn resize(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Update our pixel sizes
|
// Update our pixel sizes
|
||||||
self.terminal.width_px = self.grid_size.columns * self.cell_size.width;
|
self.terminal.width_px = grid_size.columns * self.cell_size.width;
|
||||||
self.terminal.height_px = self.grid_size.rows * self.cell_size.height;
|
self.terminal.height_px = grid_size.rows * self.cell_size.height;
|
||||||
|
|
||||||
// Disable synchronized output mode so that we show changes
|
// Disable synchronized output mode so that we show changes
|
||||||
// immediately for a resize. This is allowed by the spec.
|
// immediately for a resize. This is allowed by the spec.
|
||||||
@ -391,8 +389,8 @@ pub fn resize(
|
|||||||
// Mail the renderer so that it can update the GPU and re-render
|
// Mail the renderer so that it can update the GPU and re-render
|
||||||
_ = self.renderer_mailbox.push(.{
|
_ = self.renderer_mailbox.push(.{
|
||||||
.resize = .{
|
.resize = .{
|
||||||
.screen_size = screen_size,
|
.screen_size = size.screen,
|
||||||
.padding = padding,
|
.padding = size.padding,
|
||||||
},
|
},
|
||||||
}, .{ .forever = {} });
|
}, .{ .forever = {} });
|
||||||
self.renderer_wakeup.notify() catch {};
|
self.renderer_wakeup.notify() catch {};
|
||||||
|
@ -17,6 +17,7 @@ const builtin = @import("builtin");
|
|||||||
const xev = @import("xev");
|
const xev = @import("xev");
|
||||||
const crash = @import("../crash/main.zig");
|
const crash = @import("../crash/main.zig");
|
||||||
const termio = @import("../termio.zig");
|
const termio = @import("../termio.zig");
|
||||||
|
const renderer = @import("../renderer.zig");
|
||||||
const BlockingQueue = @import("../datastruct/main.zig").BlockingQueue;
|
const BlockingQueue = @import("../datastruct/main.zig").BlockingQueue;
|
||||||
|
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
@ -28,7 +29,7 @@ const Coalesce = struct {
|
|||||||
/// Not all message types are coalesced.
|
/// Not all message types are coalesced.
|
||||||
const min_ms = 25;
|
const min_ms = 25;
|
||||||
|
|
||||||
resize: ?termio.Message.Resize = null,
|
resize: ?renderer.Size = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The number of milliseconds before we reset the synchronized output flag
|
/// The number of milliseconds before we reset the synchronized output flag
|
||||||
@ -324,7 +325,7 @@ fn startSynchronizedOutput(self: *Thread, cb: *CallbackData) void {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleResize(self: *Thread, cb: *CallbackData, resize: termio.Message.Resize) void {
|
fn handleResize(self: *Thread, cb: *CallbackData, resize: renderer.Size) void {
|
||||||
self.coalesce_data.resize = resize;
|
self.coalesce_data.resize = resize;
|
||||||
|
|
||||||
// If the timer is already active we just return. In the future we want
|
// If the timer is already active we just return. In the future we want
|
||||||
@ -380,13 +381,7 @@ fn coalesceCallback(
|
|||||||
|
|
||||||
if (cb.self.coalesce_data.resize) |v| {
|
if (cb.self.coalesce_data.resize) |v| {
|
||||||
cb.self.coalesce_data.resize = null;
|
cb.self.coalesce_data.resize = null;
|
||||||
cb.io.resize(
|
cb.io.resize(&cb.data, v) catch |err| {
|
||||||
&cb.data,
|
|
||||||
v.grid_size,
|
|
||||||
v.cell_size,
|
|
||||||
v.screen_size,
|
|
||||||
v.padding,
|
|
||||||
) catch |err| {
|
|
||||||
log.warn("error during resize err={}", .{err});
|
log.warn("error during resize err={}", .{err});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -16,22 +16,6 @@ pub const Message = union(enum) {
|
|||||||
/// in the future.
|
/// in the future.
|
||||||
pub const WriteReq = MessageData(u8, 38);
|
pub const WriteReq = MessageData(u8, 38);
|
||||||
|
|
||||||
pub const Resize = struct {
|
|
||||||
/// The grid size for the given screen size with padding applied.
|
|
||||||
grid_size: renderer.GridSize,
|
|
||||||
|
|
||||||
/// The updated cell size.
|
|
||||||
cell_size: renderer.CellSize,
|
|
||||||
|
|
||||||
/// The full screen (drawable) size. This does NOT include padding.
|
|
||||||
/// This should be sent on to the renderer.
|
|
||||||
screen_size: renderer.ScreenSize,
|
|
||||||
|
|
||||||
/// The padding, so that the terminal implementation can subtract
|
|
||||||
/// this to send to the pty.
|
|
||||||
padding: renderer.Padding,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Purposely crash the renderer. This is used for testing and debugging.
|
/// Purposely crash the renderer. This is used for testing and debugging.
|
||||||
/// See the "crash" binding action.
|
/// See the "crash" binding action.
|
||||||
crash: void,
|
crash: void,
|
||||||
@ -47,7 +31,7 @@ pub const Message = union(enum) {
|
|||||||
inspector: bool,
|
inspector: bool,
|
||||||
|
|
||||||
/// Resize the window.
|
/// Resize the window.
|
||||||
resize: Resize,
|
resize: renderer.Size,
|
||||||
|
|
||||||
/// Request a size report is sent to the pty ([in-band
|
/// Request a size report is sent to the pty ([in-band
|
||||||
/// size report, mode 2048](https://gist.github.com/rockorager/e695fb2924d36b2bcf1fff4a3704bd83) and
|
/// size report, mode 2048](https://gist.github.com/rockorager/e695fb2924d36b2bcf1fff4a3704bd83) and
|
||||||
|
Reference in New Issue
Block a user