mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
apprt/gtk-ng: port SIGUSR2 to reload config
This commit is contained in:
@ -128,6 +128,9 @@ pub const Application = extern struct {
|
|||||||
/// outside of our own lifecycle and that's okay.
|
/// outside of our own lifecycle and that's okay.
|
||||||
config_errors_dialog: WeakRef(ConfigErrorsDialog) = .{},
|
config_errors_dialog: WeakRef(ConfigErrorsDialog) = .{},
|
||||||
|
|
||||||
|
/// glib source for our signal handler.
|
||||||
|
signal_source: ?c_uint = null,
|
||||||
|
|
||||||
pub var offset: c_int = 0;
|
pub var offset: c_int = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -698,6 +701,9 @@ pub const Application = extern struct {
|
|||||||
// Setup our style manager (light/dark mode)
|
// Setup our style manager (light/dark mode)
|
||||||
self.startupStyleManager();
|
self.startupStyleManager();
|
||||||
|
|
||||||
|
// Setup some signal handlers
|
||||||
|
self.startupSignals();
|
||||||
|
|
||||||
// Setup our action map
|
// Setup our action map
|
||||||
self.startupActionMap();
|
self.startupActionMap();
|
||||||
|
|
||||||
@ -786,6 +792,17 @@ pub const Application = extern struct {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Setup signal handlers
|
||||||
|
fn startupSignals(self: *Self) void {
|
||||||
|
const priv = self.private();
|
||||||
|
assert(priv.signal_source == null);
|
||||||
|
priv.signal_source = glib.unixSignalAdd(
|
||||||
|
std.posix.SIG.USR2,
|
||||||
|
handleSigusr2,
|
||||||
|
self,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Setup our action map.
|
/// Setup our action map.
|
||||||
fn startupActionMap(self: *Self) void {
|
fn startupActionMap(self: *Self) void {
|
||||||
const t_variant_type = glib.ext.VariantType.newFor(u64);
|
const t_variant_type = glib.ext.VariantType.newFor(u64);
|
||||||
@ -914,6 +931,12 @@ pub const Application = extern struct {
|
|||||||
diag.close();
|
diag.close();
|
||||||
diag.unref(); // strong ref from get()
|
diag.unref(); // strong ref from get()
|
||||||
}
|
}
|
||||||
|
if (priv.signal_source) |v| {
|
||||||
|
if (glib.Source.remove(v) == 0) {
|
||||||
|
log.warn("unable to remove signal source", .{});
|
||||||
|
}
|
||||||
|
priv.signal_source = null;
|
||||||
|
}
|
||||||
|
|
||||||
gobject.Object.virtual_methods.dispose.call(
|
gobject.Object.virtual_methods.dispose.call(
|
||||||
Class.parent,
|
Class.parent,
|
||||||
@ -932,6 +955,26 @@ pub const Application = extern struct {
|
|||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
// Signal Handlers
|
// Signal Handlers
|
||||||
|
|
||||||
|
/// SIGUSR2 signal handler via g_unix_signal_add
|
||||||
|
fn handleSigusr2(ud: ?*anyopaque) callconv(.c) c_int {
|
||||||
|
const self: *Self = @ptrCast(@alignCast(ud orelse
|
||||||
|
return @intFromBool(glib.SOURCE_CONTINUE)));
|
||||||
|
|
||||||
|
log.info("received SIGUSR2, reloading configuration", .{});
|
||||||
|
Action.reloadConfig(
|
||||||
|
self,
|
||||||
|
.app,
|
||||||
|
.{},
|
||||||
|
) catch |err| {
|
||||||
|
// If we fail to reload the configuration, then we want the
|
||||||
|
// user to know it. For now we log but we should show another
|
||||||
|
// GUI.
|
||||||
|
log.warn("error reloading config: {}", .{err});
|
||||||
|
};
|
||||||
|
|
||||||
|
return @intFromBool(glib.SOURCE_CONTINUE);
|
||||||
|
}
|
||||||
|
|
||||||
fn handleCloseConfirmation(
|
fn handleCloseConfirmation(
|
||||||
_: *CloseConfirmationDialog,
|
_: *CloseConfirmationDialog,
|
||||||
self: *Self,
|
self: *Self,
|
||||||
|
Reference in New Issue
Block a user