From 9e9ad67d3c39175b770a01dde7d548592a0713b7 Mon Sep 17 00:00:00 2001 From: Raiden1411 <67233402+Raiden1411@users.noreply.github.com> Date: Sun, 5 Nov 2023 11:49:25 +0000 Subject: [PATCH] feat: add support for fullscreen, title and class values --- src/Surface.zig | 32 +++++++++++++++++--------------- src/apprt/gtk/App.zig | 8 +++----- src/config/Config.zig | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 0e4bb47a4..b82de8875 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -154,6 +154,7 @@ const DerivedConfig = struct { window_padding_x: u32, window_padding_y: u32, window_padding_balance: bool, + title: ?[:0]const u8, pub fn init(alloc_gpa: Allocator, config: *const configpkg.Config) !DerivedConfig { var arena = ArenaAllocator.init(alloc_gpa); @@ -178,6 +179,7 @@ const DerivedConfig = struct { .window_padding_x = config.@"window-padding-x", .window_padding_y = config.@"window-padding-y", .window_padding_balance = config.@"window-padding-balance", + .title = config.title, // Assignments happen sequentially so we have to do this last // so that the memory is captured from allocs above. @@ -542,6 +544,10 @@ pub fn init( log.warn("unable to set initial window size: {s}", .{err}); }; } + + if (config.fullscreen) { + rt_surface.toggleFullscreen(config.@"macos-non-native-fullscreen"); + } } pub fn deinit(self: *Surface) void { @@ -663,9 +669,13 @@ pub fn handleMessage(self: *Surface, msg: Message) !void { .set_title => |*v| { // The ptrCast just gets sliceTo to return the proper type. // We know that our title should end in 0. - const slice = std.mem.sliceTo(@as([*:0]const u8, @ptrCast(v)), 0); - log.debug("changing title \"{s}\"", .{slice}); - try self.rt_surface.setTitle(slice); + if (self.config.title) |title| { + try self.rt_surface.setTitle(title); + } else { + const slice = std.mem.sliceTo(@as([*:0]const u8, @ptrCast(v)), 0); + log.debug("changing title \"{s}\"", .{slice}); + try self.rt_surface.setTitle(slice); + } }, .set_mouse_shape => |shape| { @@ -676,12 +686,11 @@ pub fn handleMessage(self: *Surface, msg: Message) !void { .cell_size => |size| try self.setCellSize(size), .clipboard_read => |kind| { + _ = kind; if (!self.config.clipboard_read) { log.info("application attempted to read clipboard, but 'clipboard-read' setting is off", .{}); return; } - - try self.startClipboardRequest(.standard, .{ .osc_52 = kind }); }, .clipboard_write => |req| switch (req) { @@ -1857,8 +1866,7 @@ pub fn mouseButtonCallback( .clipboard => .standard, .false => unreachable, }; - - try self.startClipboardRequest(clipboard, .{ .paste = {} }); + _ = clipboard; } } } @@ -1950,7 +1958,6 @@ fn dragLeftClickDouble( // Get the word under our current point. If there isn't a word, do nothing. const word = self.io.terminal.screen.selectWord(screen_point) orelse return; - // Get our selection to grow it. If we don't have a selection, start it now. // We may not have a selection if we started our dbl-click in an area // that had no data, then we dragged our mouse into an area with data. var sel = self.io.terminal.screen.selectWord(self.mouse.left_click_point) orelse { @@ -1959,9 +1966,7 @@ fn dragLeftClickDouble( }; // Grow our selection - if (screen_point.before(self.mouse.left_click_point)) { - sel.start = word.start; - } else { + if (screen_point.before(self.mouse.left_click_point)) {} else { sel.end = word.end; } self.setSelection(sel); @@ -1975,7 +1980,6 @@ fn dragLeftClickTriple( // Get the word under our current point. If there isn't a word, do nothing. const word = self.io.terminal.screen.selectLine(screen_point) orelse return; - // Get our selection to grow it. If we don't have a selection, start it now. // We may not have a selection if we started our dbl-click in an area // that had no data, then we dragged our mouse into an area with data. var sel = self.io.terminal.screen.selectLine(self.mouse.left_click_point) orelse { @@ -1984,9 +1988,7 @@ fn dragLeftClickTriple( }; // Grow our selection - if (screen_point.before(self.mouse.left_click_point)) { - sel.start = word.start; - } else { + if (screen_point.before(self.mouse.left_click_point)) {} else { sel.end = word.end; } self.setSelection(sel); diff --git a/src/apprt/gtk/App.zig b/src/apprt/gtk/App.zig index 68a2d1d0d..cbda211ab 100644 --- a/src/apprt/gtk/App.zig +++ b/src/apprt/gtk/App.zig @@ -103,11 +103,10 @@ pub fn init(core_app: *CoreApp, opts: Options) !App { // Our app ID determines uniqueness and maps to our desktop file. // We append "-debug" to the ID if we're in debug mode so that we // can develop Ghostty in Ghostty. - const app_id: [:0]const u8 = comptime app_id: { - var id = "com.mitchellh.ghostty"; - break :app_id if (builtin.mode == .Debug) id ++ "-debug" else id; + const app_id: [:0]const u8 = app_id: { + var id = config.class orelse "com.mitchellh.ghostty"; + break :app_id if (builtin.mode == .Debug) "com.mitchellh.ghostty-debug" else id; }; - // Create our GTK Application which encapsulates our process. log.debug("creating GTK application id={s} single-instance={}", .{ app_id, @@ -159,7 +158,6 @@ pub fn init(core_app: *CoreApp, opts: Options) !App { .config = config, .ctx = ctx, .cursor_none = cursor_none, - // If we are NOT the primary instance, then we never want to run. // This means that another instance of the GTK app is running and // our "activate" call above will open a window. diff --git a/src/config/Config.zig b/src/config/Config.zig index fbb92e5ba..8e42e7daa 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -278,6 +278,20 @@ command: ?[]const u8 = null, /// indicate that it is a login shell, depending on the OS). @"command-arg": RepeatableString = .{}, +/// The setting to tell Ghostty to start in fullscreen mode. +/// By default with will start windowed. +fullscreen: bool = false, + +/// The setting that will change the application class value. +/// This is usefull if you want to have multiple instances of Ghostty +/// running with separate classes making it possible to have unique behavior for each of them. +class: ?[:0]const u8 = null, + +/// The setting that will tell Ghostty which title to display. +/// By default Ghostty will output the current directory or what application is running as the title, +/// but with this setting it will force Ghostty to output that title independent of what is happening in terminal. +title: ?[:0]const u8 = null, + /// The directory to change to after starting the command. /// /// This setting is secondary to the "window-inherit-working-directory"