mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
fix callback struct ordering, use internal_os.open
This commit is contained in:
@ -353,8 +353,8 @@ typedef struct {
|
||||
} ghostty_surface_config_s;
|
||||
|
||||
typedef void (*ghostty_runtime_wakeup_cb)(void *);
|
||||
typedef void (*ghostty_runtime_open_config_cb)(void *);
|
||||
typedef const ghostty_config_t (*ghostty_runtime_reload_config_cb)(void *);
|
||||
typedef void (*ghostty_runtime_open_config_cb)(void *);
|
||||
typedef void (*ghostty_runtime_set_title_cb)(void *, const char *);
|
||||
typedef void (*ghostty_runtime_set_mouse_shape_cb)(void *, ghostty_mouse_shape_e);
|
||||
typedef void (*ghostty_runtime_set_mouse_visibility_cb)(void *, bool);
|
||||
@ -381,8 +381,8 @@ typedef struct {
|
||||
void *userdata;
|
||||
bool supports_selection_clipboard;
|
||||
ghostty_runtime_wakeup_cb wakeup_cb;
|
||||
ghostty_runtime_open_config_cb open_config_cb;
|
||||
ghostty_runtime_reload_config_cb reload_config_cb;
|
||||
ghostty_runtime_open_config_cb open_config_cb;
|
||||
ghostty_runtime_set_title_cb set_title_cb;
|
||||
ghostty_runtime_set_mouse_shape_cb set_mouse_shape_cb;
|
||||
ghostty_runtime_set_mouse_visibility_cb set_mouse_visibility_cb;
|
||||
|
@ -146,8 +146,8 @@ extension Ghostty {
|
||||
userdata: Unmanaged.passUnretained(self).toOpaque(),
|
||||
supports_selection_clipboard: false,
|
||||
wakeup_cb: { userdata in AppState.wakeup(userdata) },
|
||||
open_config_cb: { userdata in AppState.openConfig(userdata) },
|
||||
reload_config_cb: { userdata in AppState.reloadConfig(userdata) },
|
||||
open_config_cb: { userdata in AppState.openConfig(userdata) },
|
||||
set_title_cb: { userdata, title in AppState.setTitle(userdata, title: title) },
|
||||
set_mouse_shape_cb: { userdata, shape in AppState.setMouseShape(userdata, shape: shape) },
|
||||
set_mouse_visibility_cb: { userdata, visible in AppState.setMouseVisibility(userdata, visible: visible) },
|
||||
|
@ -164,7 +164,7 @@ pub const App = struct {
|
||||
}
|
||||
|
||||
pub fn openConfig(self: *App) !void {
|
||||
try Config.edit(self.core_app.alloc);
|
||||
try configpkg.edit.open(self.core_app.alloc);
|
||||
}
|
||||
|
||||
pub fn reloadConfig(self: *App) !?*const Config {
|
||||
|
@ -3,6 +3,7 @@ const builtin = @import("builtin");
|
||||
pub usingnamespace @import("config/key.zig");
|
||||
pub const Config = @import("config/Config.zig");
|
||||
pub const string = @import("config/string.zig");
|
||||
pub const edit = @import("config/edit.zig");
|
||||
pub const url = @import("config/url.zig");
|
||||
|
||||
// Field types
|
||||
|
@ -5,6 +5,7 @@ const global = &@import("../main.zig").state;
|
||||
|
||||
const Config = @import("Config.zig");
|
||||
const c_get = @import("c_get.zig");
|
||||
const edit = @import("edit.zig");
|
||||
const Key = @import("key.zig").Key;
|
||||
|
||||
const log = std.log.scoped(.config);
|
||||
@ -121,7 +122,7 @@ export fn ghostty_config_get_error(self: *Config, idx: u32) Error {
|
||||
}
|
||||
|
||||
export fn ghostty_config_open() void {
|
||||
Config.edit(global.alloc) catch |err| {
|
||||
edit.open(global.alloc) catch |err| {
|
||||
log.err("error opening config in editor err={}", .{err});
|
||||
};
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ const Key = @import("key.zig").Key;
|
||||
const KeyValue = @import("key.zig").Value;
|
||||
const ErrorList = @import("ErrorList.zig");
|
||||
const MetricModifier = fontpkg.face.Metrics.Modifier;
|
||||
const Command = @import("../Command.zig");
|
||||
|
||||
const log = std.log.scoped(.config);
|
||||
|
||||
@ -820,42 +819,6 @@ pub fn deinit(self: *Config) void {
|
||||
self.* = undefined;
|
||||
}
|
||||
|
||||
/// Open the configuration in the OS default editor according to the default paths the main config file could be in:
|
||||
///
|
||||
/// 1. XDG Config File
|
||||
///
|
||||
pub fn edit(alloc_gpa: Allocator) !void {
|
||||
// default location
|
||||
const config_path = try internal_os.xdg.config(alloc_gpa, .{ .subdir = "ghostty/config" });
|
||||
defer alloc_gpa.free(config_path);
|
||||
|
||||
// Try to create file and go on if it already exists
|
||||
_ = std.fs.createFileAbsolute(config_path, .{ .exclusive = true }) catch |err| {
|
||||
switch (err) {
|
||||
error.PathAlreadyExists => log.info("config file found at {s}", .{config_path}),
|
||||
else => return err,
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: maybe add editor config property to allow users to set the editor they want to use when opening a file.
|
||||
const editor = try Command.expandPath(alloc_gpa, "open") orelse "/usr/bin/open"; // should always be found, but worse case we use a hardcoded absolute path.
|
||||
defer alloc_gpa.free(editor);
|
||||
|
||||
// the command to run
|
||||
const argv = [_][]const u8{ editor, config_path };
|
||||
|
||||
var proc = std.ChildProcess.init(&argv, alloc_gpa);
|
||||
proc.stdin_behavior = .Ignore;
|
||||
proc.stdout_behavior = .Ignore;
|
||||
proc.stderr_behavior = .Ignore;
|
||||
|
||||
try proc.spawn();
|
||||
log.info("started subcommand path={s} pid={?}", .{ editor, proc.id });
|
||||
|
||||
// the process only ends after this call returns.
|
||||
if (try proc.wait() != std.ChildProcess.Term.Exited) return error.ExitError;
|
||||
}
|
||||
|
||||
/// Load the configuration according to the default rules:
|
||||
///
|
||||
/// 1. Defaults
|
||||
|
29
src/config/edit.zig
Normal file
29
src/config/edit.zig
Normal file
@ -0,0 +1,29 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const assert = std.debug.assert;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const internal_os = @import("../os/main.zig");
|
||||
const Command = @import("../Command.zig");
|
||||
|
||||
const log = std.log.scoped(.config);
|
||||
|
||||
/// Open the configuration in the OS default editor according to the default
|
||||
/// paths the main config file could be in.
|
||||
pub fn open(alloc_gpa: Allocator) !void {
|
||||
// default location
|
||||
const config_path = try internal_os.xdg.config(alloc_gpa, .{ .subdir = "ghostty/config" });
|
||||
defer alloc_gpa.free(config_path);
|
||||
|
||||
// Try to create file and go on if it already exists
|
||||
_ = std.fs.createFileAbsolute(
|
||||
config_path,
|
||||
.{ .exclusive = true },
|
||||
) catch |err| {
|
||||
switch (err) {
|
||||
error.PathAlreadyExists => {},
|
||||
else => return err,
|
||||
}
|
||||
};
|
||||
|
||||
try internal_os.open(alloc_gpa, config_path);
|
||||
}
|
Reference in New Issue
Block a user