apprt/glfw: handle setting initial window position when window is

created
This commit is contained in:
Adam Wolf
2024-12-30 07:39:56 -06:00
committed by Mitchell Hashimoto
parent 13d935a401
commit 970e45559b
5 changed files with 15 additions and 46 deletions

View File

@ -514,12 +514,6 @@ typedef struct {
uint32_t height; uint32_t height;
} ghostty_action_initial_size_s; } ghostty_action_initial_size_s;
// apprt.action.InitialPosition
typedef struct {
int32_t x;
int32_t y;
} ghostty_action_initial_position_s;
// apprt.action.CellSize // apprt.action.CellSize
typedef struct { typedef struct {
uint32_t width; uint32_t width;
@ -583,7 +577,6 @@ typedef enum {
GHOSTTY_ACTION_PRESENT_TERMINAL, GHOSTTY_ACTION_PRESENT_TERMINAL,
GHOSTTY_ACTION_SIZE_LIMIT, GHOSTTY_ACTION_SIZE_LIMIT,
GHOSTTY_ACTION_INITIAL_SIZE, GHOSTTY_ACTION_INITIAL_SIZE,
GHOSTTY_ACTION_INITIAL_POSITION,
GHOSTTY_ACTION_CELL_SIZE, GHOSTTY_ACTION_CELL_SIZE,
GHOSTTY_ACTION_INSPECTOR, GHOSTTY_ACTION_INSPECTOR,
GHOSTTY_ACTION_RENDER_INSPECTOR, GHOSTTY_ACTION_RENDER_INSPECTOR,
@ -612,7 +605,6 @@ typedef union {
ghostty_action_resize_split_s resize_split; ghostty_action_resize_split_s resize_split;
ghostty_action_size_limit_s size_limit; ghostty_action_size_limit_s size_limit;
ghostty_action_initial_size_s initial_size; ghostty_action_initial_size_s initial_size;
ghostty_action_initial_position_s initial_position;
ghostty_action_cell_size_s cell_size; ghostty_action_cell_size_s cell_size;
ghostty_action_inspector_e inspector; ghostty_action_inspector_e inspector;
ghostty_action_desktop_notification_s desktop_notification; ghostty_action_desktop_notification_s desktop_notification;

View File

@ -621,8 +621,6 @@ pub fn init(
const width = @max(config.@"window-width" * cell_size.width, 640); const width = @max(config.@"window-width" * cell_size.width, 640);
const width_f32: f32 = @floatFromInt(width); const width_f32: f32 = @floatFromInt(width);
const height_f32: f32 = @floatFromInt(height); const height_f32: f32 = @floatFromInt(height);
const position_x = config.@"window-position-x";
const position_y = config.@"window-position-y";
// The final values are affected by content scale and we need to // The final values are affected by content scale and we need to
// account for the padding so we get the exact correct grid size. // account for the padding so we get the exact correct grid size.
@ -644,14 +642,6 @@ pub fn init(
// an initial size shouldn't stop our terminal from working. // an initial size shouldn't stop our terminal from working.
log.warn("unable to set initial window size: {s}", .{err}); log.warn("unable to set initial window size: {s}", .{err});
}; };
rt_app.performAction(
.{ .surface = self },
.initial_position,
.{ .x = position_x, .y = position_y },
) catch |err| {
log.warn("unable to set initial window position: {s}", .{err});
};
} }
if (config.title) |title| { if (config.title) |title| {

View File

@ -136,11 +136,6 @@ pub const Action = union(Key) {
/// after the surface is initialized it should be ignored. /// after the surface is initialized it should be ignored.
initial_size: InitialSize, initial_size: InitialSize,
// Specifies the initial position of the target terminal. This will be
// sent only during the initialization of a surface. If it is received
// after the surface is initialized it should be ignored.
initial_position: InitialPosition,
/// The cell size has changed to the given dimensions in pixels. /// The cell size has changed to the given dimensions in pixels.
cell_size: CellSize, cell_size: CellSize,
@ -242,7 +237,6 @@ pub const Action = union(Key) {
present_terminal, present_terminal,
size_limit, size_limit,
initial_size, initial_size,
initial_position,
cell_size, cell_size,
inspector, inspector,
render_inspector, render_inspector,
@ -433,11 +427,6 @@ pub const InitialSize = extern struct {
height: u32, height: u32,
}; };
pub const InitialPosition = extern struct {
x: i32,
y: i32,
};
pub const CellSize = extern struct { pub const CellSize = extern struct {
width: u32, width: u32,
height: u32, height: u32,

View File

@ -149,10 +149,14 @@ pub const App = struct {
value: apprt.Action.Value(action), value: apprt.Action.Value(action),
) !void { ) !void {
switch (action) { switch (action) {
.new_window => _ = try self.newSurface(switch (target) { .new_window => {
.app => null, var surface = try self.newSurface(switch (target) {
.surface => |v| v, .app => null,
}), .surface => |v| v,
});
try surface.setInitialWindowPosition(self.config.@"window-position-x", self.config.@"window-position-y");
},
.new_tab => try self.newTab(switch (target) { .new_tab => try self.newTab(switch (target) {
.app => null, .app => null,
@ -178,14 +182,6 @@ pub const App = struct {
), ),
}, },
.initial_position => switch (target) {
.app => {},
.surface => |surface| try surface.rt_surface.setInitialWindowPosition(
value.x,
value.y,
),
},
.toggle_fullscreen => self.toggleFullscreen(target), .toggle_fullscreen => self.toggleFullscreen(target),
.open_config => try configpkg.edit.open(self.app.alloc), .open_config => try configpkg.edit.open(self.app.alloc),
@ -674,10 +670,12 @@ pub const Surface = struct {
/// Set the initial window position. This is called exactly once at /// Set the initial window position. This is called exactly once at
/// surface initialization time. This may be called before "self" /// surface initialization time. This may be called before "self"
/// is fully initialized. /// is fully initialized.
fn setInitialWindowPosition(self: *const Surface, x: i32, y: i32) !void { fn setInitialWindowPosition(self: *const Surface, x: ?i16, y: ?i16) !void {
log.debug("setting initial window position ({},{})", .{ x, y }); const start_position_x = x orelse return;
const start_position_y = y orelse return;
self.window.setPos(.{ .x = x, .y = y }); log.debug("setting initial window position ({},{})", .{ start_position_x, start_position_y });
self.window.setPos(.{ .x = start_position_x, .y = start_position_y });
} }
/// Set the size limits of the window. /// Set the size limits of the window.

View File

@ -1121,8 +1121,8 @@ keybind: Keybinds = .{},
/// on Linux. GTK 4.0 does not support setting the window position. /// on Linux. GTK 4.0 does not support setting the window position.
/// ///
/// This will default to the top-left corner of the screen if not set (0, 0). /// This will default to the top-left corner of the screen if not set (0, 0).
@"window-position-x": i32 = 0, @"window-position-x": ?i16 = null,
@"window-position-y": i32 = 0, @"window-position-y": ?i16 = null,
/// Whether to enable saving and restoring window state. Window state includes /// Whether to enable saving and restoring window state. Window state includes
/// their position, size, tabs, splits, etc. Some window state requires shell /// their position, size, tabs, splits, etc. Some window state requires shell