Merge pull request #1176 from tristan957/libadwaita

Use adw_application_new() instead of adw_init()
This commit is contained in:
Mitchell Hashimoto
2023-12-29 09:11:21 -08:00
committed by GitHub

View File

@ -69,20 +69,6 @@ pub fn init(core_app: *CoreApp, opts: Options) !App {
} }
} }
// Initialize libadwaita
if (build_options.libadwaita and config.@"gtk-adwaita") {
log.debug("initializing libadwaita", .{});
c.adw_init();
c.adw_style_manager_set_color_scheme(
c.adw_style_manager_get_default(),
switch (config.@"window-theme") {
.system => c.ADW_COLOR_SCHEME_PREFER_LIGHT,
.dark => c.ADW_COLOR_SCHEME_FORCE_DARK,
.light => c.ADW_COLOR_SCHEME_FORCE_LIGHT,
},
);
}
// The "none" cursor is used for hiding the cursor // The "none" cursor is used for hiding the cursor
const cursor_none = c.gdk_cursor_new_from_name("none", null); const cursor_none = c.gdk_cursor_new_from_name("none", null);
errdefer if (cursor_none) |cursor| c.g_object_unref(cursor); errdefer if (cursor_none) |cursor| c.g_object_unref(cursor);
@ -117,14 +103,41 @@ pub fn init(core_app: *CoreApp, opts: Options) !App {
}; };
// Create our GTK Application which encapsulates our process. // Create our GTK Application which encapsulates our process.
log.debug("creating GTK application id={s} single-instance={}", .{ const app: *c.GtkApplication = app: {
const adwaita = build_options.libadwaita and config.@"gtk-adwaita";
log.debug("creating GTK application id={s} single-instance={} adwaita={}", .{
app_id, app_id,
single_instance, single_instance,
adwaita,
}); });
const app = @as(?*c.GtkApplication, @ptrCast(c.gtk_application_new(
// If not libadwaita, create a standard GTK application.
if (!adwaita) break :app @as(?*c.GtkApplication, @ptrCast(c.gtk_application_new(
app_id.ptr, app_id.ptr,
app_flags, app_flags,
))) orelse return error.GtkInitFailed; ))) orelse return error.GtkInitFailed;
// Use libadwaita if requested. Using an AdwApplication lets us use
// Adwaita widgets and access things such as the color scheme.
const adw_app = @as(?*c.AdwApplication, @ptrCast(c.adw_application_new(
app_id.ptr,
app_flags,
))) orelse return error.GtkInitFailed;
const style_manager = c.adw_application_get_style_manager(adw_app);
c.adw_style_manager_set_color_scheme(
style_manager,
switch (config.@"window-theme") {
.system => c.ADW_COLOR_SCHEME_PREFER_LIGHT,
.dark => c.ADW_COLOR_SCHEME_FORCE_DARK,
.light => c.ADW_COLOR_SCHEME_FORCE_LIGHT,
},
);
break :app @ptrCast(adw_app);
};
errdefer c.g_object_unref(app); errdefer c.g_object_unref(app);
_ = c.g_signal_connect_data( _ = c.g_signal_connect_data(
app, app,