Merge pull request #969 from vancluever/vancluever-fix-x11-window-class

gtk: make sure WM_CLASS is being set on X11
This commit is contained in:
Mitchell Hashimoto
2023-11-30 21:40:53 -08:00
committed by GitHub
3 changed files with 51 additions and 3 deletions

View File

@ -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

View File

@ -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;

View File

@ -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"