mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 00:36:07 +03:00
apprt/gtk: set icon name
This commit is contained in:
@ -298,6 +298,9 @@ const Window = struct {
|
||||
/// The background CSS for the window (if any).
|
||||
css_window_background: ?[]u8 = null,
|
||||
|
||||
/// The resources directory for the icon (if any).
|
||||
icon_search_dir: ?[:0]const u8 = null,
|
||||
|
||||
pub fn init(self: *Window, app: *App) !void {
|
||||
// Set up our own state
|
||||
self.* = .{
|
||||
@ -314,6 +317,31 @@ const Window = struct {
|
||||
c.gtk_window_set_title(gtk_window, "Ghostty");
|
||||
c.gtk_window_set_default_size(gtk_window, 1000, 600);
|
||||
|
||||
// If we don't have the icon then we'll try to add our resources dir
|
||||
// to the search path and see if we can find it there.
|
||||
const icon_name = "com.mitchellh.ghostty";
|
||||
const icon_theme = c.gtk_icon_theme_get_for_display(c.gtk_widget_get_display(window));
|
||||
if (c.gtk_icon_theme_has_icon(icon_theme, icon_name) == 0) icon: {
|
||||
const base = self.app.core_app.resources_dir orelse {
|
||||
log.info("gtk app missing Ghostty icon and no resources dir detected", .{});
|
||||
log.info("gtk app will not have Ghostty icon", .{});
|
||||
break :icon;
|
||||
};
|
||||
|
||||
// Note that this method for adding the icon search path is
|
||||
// a fallback mechanism. The recommended mechanism is the
|
||||
// Freedesktop Icon Theme Specification. We distribute a ".desktop"
|
||||
// file in zig-out/share that should be installed to the proper
|
||||
// place.
|
||||
const dir = try std.fmt.allocPrintZ(app.core_app.alloc, "{s}/icons", .{base});
|
||||
self.icon_search_dir = dir;
|
||||
c.gtk_icon_theme_add_search_path(icon_theme, dir.ptr);
|
||||
if (c.gtk_icon_theme_has_icon(icon_theme, icon_name) == 0) {
|
||||
log.warn("Ghostty icon for gtk app not found", .{});
|
||||
}
|
||||
}
|
||||
c.gtk_window_set_icon_name(gtk_window, icon_name);
|
||||
|
||||
// Apply background opacity if we have it
|
||||
if (app.config.@"background-opacity" < 1) {
|
||||
var css = try std.fmt.allocPrint(
|
||||
@ -361,6 +389,7 @@ const Window = struct {
|
||||
|
||||
pub fn deinit(self: *Window) void {
|
||||
if (self.css_window_background) |ptr| self.app.core_app.alloc.free(ptr);
|
||||
if (self.icon_search_dir) |ptr| self.app.core_app.alloc.free(ptr);
|
||||
}
|
||||
|
||||
/// Add a new tab to this window.
|
||||
|
Reference in New Issue
Block a user