apprt/gtk: do not use unique app mode (do not set ID for GApplication)

Fixes #101. This prevents single-instance GTK mode from being enabled.
For now, this makes the most sense in my opinion but we can revisit
later.
This commit is contained in:
Mitchell Hashimoto
2023-03-18 19:37:00 -07:00
parent bae92c5d47
commit a950adbf17

View File

@ -31,13 +31,13 @@ const log = std.log.scoped(.gtk);
/// the assumptions. /// the assumptions.
pub const App = struct { pub const App = struct {
pub const Options = struct { pub const Options = struct {
/// GTK app ID /// GTK app ID. This is currently unused but should remain populated
/// for the future.
id: [:0]const u8 = "com.mitchellh.ghostty", id: [:0]const u8 = "com.mitchellh.ghostty",
}; };
core_app: *CoreApp, core_app: *CoreApp,
app_id: [:0]const u8,
app: *c.GtkApplication, app: *c.GtkApplication,
ctx: *c.GMainContext, ctx: *c.GMainContext,
@ -45,19 +45,17 @@ pub const App = struct {
cursor_ibeam: *c.GdkCursor, cursor_ibeam: *c.GdkCursor,
pub fn init(core_app: *CoreApp, opts: Options) !App { pub fn init(core_app: *CoreApp, opts: Options) !App {
_ = opts;
// This is super weird, but we still use GLFW with GTK only so that // This is super weird, but we still use GLFW with GTK only so that
// we can tap into their folklore logic to get screen DPI. If we can // we can tap into their folklore logic to get screen DPI. If we can
// figure out a reliable way to determine this ourselves, we can get // figure out a reliable way to determine this ourselves, we can get
// rid of this dep. // rid of this dep.
if (!glfw.init(.{})) return error.GlfwInitFailed; if (!glfw.init(.{})) return error.GlfwInitFailed;
// We have to copy our app ID because GTK says we own it.
var app_id = try core_app.alloc.dupeZ(u8, opts.id);
errdefer core_app.alloc.free(app_id);
// Create our GTK Application which encapsulates our process. // Create our GTK Application which encapsulates our process.
const app = @ptrCast(?*c.GtkApplication, c.gtk_application_new( const app = @ptrCast(?*c.GtkApplication, c.gtk_application_new(
app_id.ptr, null,
// GTK >= 2.74 // GTK >= 2.74
if (@hasDecl(c, "G_APPLICATION_DEFAULT_FLAGS")) if (@hasDecl(c, "G_APPLICATION_DEFAULT_FLAGS"))
@ -109,7 +107,6 @@ pub const App = struct {
return .{ return .{
.core_app = core_app, .core_app = core_app,
.app_id = app_id,
.app = app, .app = app,
.ctx = ctx, .ctx = ctx,
.cursor_default = cursor_default, .cursor_default = cursor_default,
@ -128,8 +125,6 @@ pub const App = struct {
c.g_object_unref(self.cursor_ibeam); c.g_object_unref(self.cursor_ibeam);
c.g_object_unref(self.cursor_default); c.g_object_unref(self.cursor_default);
self.core_app.alloc.free(self.app_id);
glfw.terminate(); glfw.terminate();
} }