mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
apprt/glfw: handle setting initial window position when window is
created
This commit is contained in:

committed by
Mitchell Hashimoto

parent
13d935a401
commit
970e45559b
@ -514,12 +514,6 @@ typedef struct {
|
||||
uint32_t height;
|
||||
} ghostty_action_initial_size_s;
|
||||
|
||||
// apprt.action.InitialPosition
|
||||
typedef struct {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
} ghostty_action_initial_position_s;
|
||||
|
||||
// apprt.action.CellSize
|
||||
typedef struct {
|
||||
uint32_t width;
|
||||
@ -583,7 +577,6 @@ typedef enum {
|
||||
GHOSTTY_ACTION_PRESENT_TERMINAL,
|
||||
GHOSTTY_ACTION_SIZE_LIMIT,
|
||||
GHOSTTY_ACTION_INITIAL_SIZE,
|
||||
GHOSTTY_ACTION_INITIAL_POSITION,
|
||||
GHOSTTY_ACTION_CELL_SIZE,
|
||||
GHOSTTY_ACTION_INSPECTOR,
|
||||
GHOSTTY_ACTION_RENDER_INSPECTOR,
|
||||
@ -612,7 +605,6 @@ typedef union {
|
||||
ghostty_action_resize_split_s resize_split;
|
||||
ghostty_action_size_limit_s size_limit;
|
||||
ghostty_action_initial_size_s initial_size;
|
||||
ghostty_action_initial_position_s initial_position;
|
||||
ghostty_action_cell_size_s cell_size;
|
||||
ghostty_action_inspector_e inspector;
|
||||
ghostty_action_desktop_notification_s desktop_notification;
|
||||
|
@ -621,8 +621,6 @@ pub fn init(
|
||||
const width = @max(config.@"window-width" * cell_size.width, 640);
|
||||
const width_f32: f32 = @floatFromInt(width);
|
||||
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
|
||||
// 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.
|
||||
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| {
|
||||
|
@ -136,11 +136,6 @@ pub const Action = union(Key) {
|
||||
/// after the surface is initialized it should be ignored.
|
||||
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.
|
||||
cell_size: CellSize,
|
||||
|
||||
@ -242,7 +237,6 @@ pub const Action = union(Key) {
|
||||
present_terminal,
|
||||
size_limit,
|
||||
initial_size,
|
||||
initial_position,
|
||||
cell_size,
|
||||
inspector,
|
||||
render_inspector,
|
||||
@ -433,11 +427,6 @@ pub const InitialSize = extern struct {
|
||||
height: u32,
|
||||
};
|
||||
|
||||
pub const InitialPosition = extern struct {
|
||||
x: i32,
|
||||
y: i32,
|
||||
};
|
||||
|
||||
pub const CellSize = extern struct {
|
||||
width: u32,
|
||||
height: u32,
|
||||
|
@ -149,10 +149,14 @@ pub const App = struct {
|
||||
value: apprt.Action.Value(action),
|
||||
) !void {
|
||||
switch (action) {
|
||||
.new_window => _ = try self.newSurface(switch (target) {
|
||||
.new_window => {
|
||||
var surface = try self.newSurface(switch (target) {
|
||||
.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) {
|
||||
.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),
|
||||
|
||||
.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
|
||||
/// surface initialization time. This may be called before "self"
|
||||
/// is fully initialized.
|
||||
fn setInitialWindowPosition(self: *const Surface, x: i32, y: i32) !void {
|
||||
log.debug("setting initial window position ({},{})", .{ x, y });
|
||||
fn setInitialWindowPosition(self: *const Surface, x: ?i16, y: ?i16) !void {
|
||||
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.
|
||||
|
@ -1121,8 +1121,8 @@ keybind: Keybinds = .{},
|
||||
/// 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).
|
||||
@"window-position-x": i32 = 0,
|
||||
@"window-position-y": i32 = 0,
|
||||
@"window-position-x": ?i16 = null,
|
||||
@"window-position-y": ?i16 = null,
|
||||
|
||||
/// Whether to enable saving and restoring window state. Window state includes
|
||||
/// their position, size, tabs, splits, etc. Some window state requires shell
|
||||
|
Reference in New Issue
Block a user