From 970e45559b4e0a6677bcc5cf5b77311bd48b8d21 Mon Sep 17 00:00:00 2001 From: Adam Wolf Date: Mon, 30 Dec 2024 07:39:56 -0600 Subject: [PATCH] apprt/glfw: handle setting initial window position when window is created --- include/ghostty.h | 8 -------- src/Surface.zig | 10 ---------- src/apprt/action.zig | 11 ----------- src/apprt/glfw.zig | 28 +++++++++++++--------------- src/config/Config.zig | 4 ++-- 5 files changed, 15 insertions(+), 46 deletions(-) diff --git a/include/ghostty.h b/include/ghostty.h index 6dab5c27d..4b8d409e9 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -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; diff --git a/src/Surface.zig b/src/Surface.zig index ace392bb3..c359efd8a 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -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| { diff --git a/src/apprt/action.zig b/src/apprt/action.zig index 35ad3c0ce..de6758d6c 100644 --- a/src/apprt/action.zig +++ b/src/apprt/action.zig @@ -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, diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index 8f5519a56..3481e4833 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -149,10 +149,14 @@ pub const App = struct { value: apprt.Action.Value(action), ) !void { switch (action) { - .new_window => _ = try self.newSurface(switch (target) { - .app => null, - .surface => |v| v, - }), + .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. diff --git a/src/config/Config.zig b/src/config/Config.zig index c9cf188b5..7fba7ddd9 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -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