mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
apprt/gtk: small stylistic edits
This commit is contained in:
@ -13,13 +13,13 @@ const App = @This();
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
|
const apprt = @import("../../apprt.zig");
|
||||||
const configpkg = @import("../../config.zig");
|
const configpkg = @import("../../config.zig");
|
||||||
const input = @import("../../input.zig");
|
const input = @import("../../input.zig");
|
||||||
const internal_os = @import("../../os/main.zig");
|
const internal_os = @import("../../os/main.zig");
|
||||||
const Config = configpkg.Config;
|
const Config = configpkg.Config;
|
||||||
const CoreApp = @import("../../App.zig");
|
const CoreApp = @import("../../App.zig");
|
||||||
const CoreSurface = @import("../../Surface.zig");
|
const CoreSurface = @import("../../Surface.zig");
|
||||||
const ColorScheme = @import("../../apprt.zig").ColorScheme;
|
|
||||||
|
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
|
|
||||||
@ -225,25 +225,22 @@ pub fn init(core_app: *CoreApp, opts: Options) !App {
|
|||||||
// https://gitlab.gnome.org/GNOME/glib/-/blob/bd2ccc2f69ecfd78ca3f34ab59e42e2b462bad65/gio/gapplication.c#L2302
|
// https://gitlab.gnome.org/GNOME/glib/-/blob/bd2ccc2f69ecfd78ca3f34ab59e42e2b462bad65/gio/gapplication.c#L2302
|
||||||
c.g_application_activate(gapp);
|
c.g_application_activate(gapp);
|
||||||
|
|
||||||
const dbus_connection = c.g_application_get_dbus_connection(gapp);
|
// Register for dbus events
|
||||||
if (dbus_connection == null) {
|
if (c.g_application_get_dbus_connection(gapp)) |dbus_connection| {
|
||||||
log.err("unable to get dbus connection", .{});
|
_ = c.g_dbus_connection_signal_subscribe(
|
||||||
return error.NoDBusConnection;
|
dbus_connection,
|
||||||
|
null,
|
||||||
|
"org.freedesktop.portal.Settings",
|
||||||
|
"SettingChanged",
|
||||||
|
"/org/freedesktop/portal/desktop",
|
||||||
|
"org.freedesktop.appearance",
|
||||||
|
c.G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_NAMESPACE,
|
||||||
|
>kNotifyColorScheme,
|
||||||
|
core_app,
|
||||||
|
null,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = c.g_dbus_connection_signal_subscribe(
|
|
||||||
dbus_connection,
|
|
||||||
null,
|
|
||||||
"org.freedesktop.portal.Settings",
|
|
||||||
"SettingChanged",
|
|
||||||
"/org/freedesktop/portal/desktop",
|
|
||||||
"org.freedesktop.appearance",
|
|
||||||
c.G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_NAMESPACE,
|
|
||||||
>kNotifyColorScheme,
|
|
||||||
core_app,
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.core_app = core_app,
|
.core_app = core_app,
|
||||||
.app = app,
|
.app = app,
|
||||||
@ -509,8 +506,9 @@ fn gtkActivate(app: *c.GtkApplication, ud: ?*anyopaque) callconv(.C) void {
|
|||||||
}, .{ .forever = {} });
|
}, .{ .forever = {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call a D-Bus method to determine the current color scheme.
|
/// Call a D-Bus method to determine the current color scheme. If there
|
||||||
pub fn getColorScheme(self: *App) ColorScheme {
|
/// is any error at any point we'll log the error and return "light"
|
||||||
|
pub fn getColorScheme(self: *App) apprt.ColorScheme {
|
||||||
const dbus_connection = c.g_application_get_dbus_connection(@ptrCast(self.app));
|
const dbus_connection = c.g_application_get_dbus_connection(@ptrCast(self.app));
|
||||||
|
|
||||||
var err: ?*c.GError = null;
|
var err: ?*c.GError = null;
|
||||||
@ -569,9 +567,7 @@ fn gtkNotifyColorScheme(
|
|||||||
var namespace: [*c]u8 = undefined;
|
var namespace: [*c]u8 = undefined;
|
||||||
var setting: [*c]u8 = undefined;
|
var setting: [*c]u8 = undefined;
|
||||||
var value: *c.GVariant = undefined;
|
var value: *c.GVariant = undefined;
|
||||||
|
|
||||||
c.g_variant_get(parameters, "(ssv)", &namespace, &setting, &value);
|
c.g_variant_get(parameters, "(ssv)", &namespace, &setting, &value);
|
||||||
|
|
||||||
defer c.g_free(namespace);
|
defer c.g_free(namespace);
|
||||||
defer c.g_free(setting);
|
defer c.g_free(setting);
|
||||||
defer c.g_variant_unref(value);
|
defer c.g_variant_unref(value);
|
||||||
@ -585,7 +581,11 @@ fn gtkNotifyColorScheme(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const color_scheme: ColorScheme = if (c.g_variant_get_uint32(value) == 1) .dark else .light;
|
const color_scheme: apprt.ColorScheme = if (c.g_variant_get_uint32(value) == 1)
|
||||||
|
.dark
|
||||||
|
else
|
||||||
|
.light;
|
||||||
|
|
||||||
for (core_app.surfaces.items) |surface| {
|
for (core_app.surfaces.items) |surface| {
|
||||||
surface.core_surface.colorSchemeCallback(color_scheme) catch |err| {
|
surface.core_surface.colorSchemeCallback(color_scheme) catch |err| {
|
||||||
log.err("unable to tell surface about color scheme change: {}", .{err});
|
log.err("unable to tell surface about color scheme change: {}", .{err});
|
||||||
|
@ -418,8 +418,8 @@ fn realize(self: *Surface) !void {
|
|||||||
self.core_surface.setFontSize(size);
|
self.core_surface.setFontSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the intial color scheme
|
// Set the intial color scheme
|
||||||
self.core_surface.color_scheme = self.app.getColorScheme();
|
try self.core_surface.colorSchemeCallback(self.app.getColorScheme());
|
||||||
|
|
||||||
// Note we're realized
|
// Note we're realized
|
||||||
self.realized = true;
|
self.realized = true;
|
||||||
|
Reference in New Issue
Block a user