diff --git a/src/apprt/gtk/App.zig b/src/apprt/gtk/App.zig index cc7dac1c4..ef299e31f 100644 --- a/src/apprt/gtk/App.zig +++ b/src/apprt/gtk/App.zig @@ -156,6 +156,35 @@ pub fn init(core_app: *CoreApp, opts: Options) !App { return error.GtkApplicationRegisterFailed; } + const display = c.gdk_display_get_default(); + if (c.g_type_check_instance_is_a(@ptrCast(@alignCast(display)), c.gdk_x11_display_get_type()) != 0) { + // Set the X11 window class property (WM_CLASS) if are are on an X11 + // display. + // + // Note that we also set the program name here using g_set_prgname. + // This is how the instance name field for WM_CLASS is derived when + // calling gdk_x11_display_set_program_class; there does not seem to be + // a way to set it directly. It does not look like this is being set by + // our other app initialization routines currently, but since we're + // currently deriving its value from x11-instance-name effectively, I + // feel like gating it behind an X11 check is better intent. + // + // This makes the property show up like so when using xprop: + // + // WM_CLASS(STRING) = "ghostty", "com.mitchellh.ghostty" + // + // Append "-debug" on both when using the debug build. + // + const prgname = if (config.@"x11-instance-name") |pn| + pn + else if (builtin.mode == .Debug) + "ghostty-debug" + else + "ghostty"; + c.g_set_prgname(prgname); + c.gdk_x11_display_set_program_class(display, app_id); + } + // This just calls the "activate" signal but its part of the normal // startup routine so we just call it: // https://gitlab.gnome.org/GNOME/glib/-/blob/bd2ccc2f69ecfd78ca3f34ab59e42e2b462bad65/gio/gapplication.c#L2302 diff --git a/src/apprt/gtk/c.zig b/src/apprt/gtk/c.zig index 31fc2c1b3..d7e85f376 100644 --- a/src/apprt/gtk/c.zig +++ b/src/apprt/gtk/c.zig @@ -1,6 +1,10 @@ const c = @cImport({ @cInclude("gtk/gtk.h"); if (@import("build_options").libadwaita) @cInclude("libadwaita-1/adwaita.h"); + + // Add in X11-specific GDK backend which we use for specific things (e.g. + // X11 window class). + @cInclude("gdk/x11/gdkx.h"); }); pub usingnamespace c; diff --git a/src/config/Config.zig b/src/config/Config.zig index f49d21d82..2b7df501a 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -366,16 +366,31 @@ fullscreen: bool = false, /// set title escape sequences programs (such as Neovim) may send. title: ?[:0]const u8 = null, -/// The setting that will change the application class value. This value is -/// often used with Linux window managers to change behavior (such as -/// floating vs tiled). If you don't know what this is, don't set it. +/// The setting that will change the application class value. +/// +/// This controls the class field of the WM_CLASS X11 property (when running +/// under X11), and the Wayland application ID (when running under Wayland). +/// +/// Note that changing this value between invocations will create new, separate +/// instances, of Ghostty when running with --gtk-single-instance=true. See +/// that option for more details. /// /// The class name must follow the GTK requirements defined here: /// https://docs.gtk.org/gio/type_func.Application.id_is_valid.html /// +/// The default is "com.mitchellh.ghostty". +/// /// This only affects GTK builds. class: ?[:0]const u8 = null, +/// This controls the instance name field of the WM_CLASS X11 property when +/// running under X11. It has no effect otherwise. +/// +/// The default is "ghostty". +/// +/// This only affects GTK builds. +@"x11-instance-name": ?[:0]const u8 = null, + /// The directory to change to after starting the command. /// /// This setting is secondary to the "window-inherit-working-directory"