@@ -14,6 +14,8 @@ const configpkg = @import("../../config.zig");
14
14
const font = @import ("../../font/main.zig" );
15
15
const input = @import ("../../input.zig" );
16
16
const CoreSurface = @import ("../../Surface.zig" );
17
+ const gtk = @import ("gtk" );
18
+ const gobject = @import ("gobject" );
17
19
18
20
const App = @import ("App.zig" );
19
21
const Color = configpkg .Config .Color ;
@@ -73,6 +75,7 @@ pub const DerivedConfig = struct {
73
75
gtk_wide_tabs : bool ,
74
76
gtk_toolbar_style : configpkg.Config.GtkToolbarStyle ,
75
77
78
+ title : ? [:0 ]const u8 ,
76
79
maximize : bool ,
77
80
fullscreen : bool ,
78
81
window_decoration : configpkg.Config.WindowDecoration ,
@@ -88,6 +91,7 @@ pub const DerivedConfig = struct {
88
91
.gtk_wide_tabs = config .@"gtk-wide-tabs" ,
89
92
.gtk_toolbar_style = config .@"gtk-toolbar-style" ,
90
93
94
+ .title = config .title ,
91
95
.maximize = config .maximize ,
92
96
.fullscreen = config .fullscreen ,
93
97
.window_decoration = config .@"window-decoration" ,
@@ -130,17 +134,10 @@ pub fn init(self: *Window, app: *App) !void {
130
134
131
135
self .window = @ptrCast (@alignCast (gtk_widget ));
132
136
133
- c .gtk_window_set_title (self .window , "Ghostty" );
134
- c .gtk_window_set_default_size (self .window , 1000 , 600 );
135
- c .gtk_widget_add_css_class (gtk_widget , "window" );
136
- c .gtk_widget_add_css_class (gtk_widget , "terminal-window" );
137
-
138
137
// GTK4 grabs F10 input by default to focus the menubar icon. We want
139
138
// to disable this so that terminal programs can capture F10 (such as htop)
140
139
c .gtk_window_set_handle_menubar_accel (self .window , 0 );
141
140
142
- c .gtk_window_set_icon_name (self .window , build_config .bundle_id );
143
-
144
141
// Create our box which will hold our widgets in the main content area.
145
142
const box = c .gtk_box_new (c .GTK_ORIENTATION_VERTICAL , 0 );
146
143
@@ -353,11 +350,7 @@ pub fn init(self: *Window, app: *App) !void {
353
350
if (! self .config .gtk_wide_tabs ) c .adw_tab_bar_set_expand_tabs (tab_bar , 0 );
354
351
}
355
352
356
- // If we want the window to be maximized, we do that here.
357
- if (self .config .maximize ) c .gtk_window_maximize (self .window );
358
-
359
- // If we are in fullscreen mode, new windows start fullscreen.
360
- if (self .config .fullscreen ) c .gtk_window_fullscreen (self .window );
353
+ try self .initAppearance ();
361
354
362
355
// Show the window
363
356
c .gtk_widget_show (gtk_widget );
@@ -380,23 +373,44 @@ pub fn updateConfig(
380
373
try self .syncAppearance ();
381
374
}
382
375
376
+ /// Initializes the appearance of the window.
377
+ ///
378
+ /// Not all appearance changes *should* be applied when a config option is
379
+ /// reloaded (for instance, the maximize and fullscreen settings should only
380
+ /// apply to new windows), so we apply them here.
381
+ pub fn initAppearance (self : * Window ) ! void {
382
+ const window = gobject .ext .cast (gtk .Window , self .window ).? ;
383
+
384
+ window .setTitle (self .config .title orelse "Ghostty" );
385
+ window .setDefaultSize (1000 , 600 );
386
+ window .as (gtk .Widget ).addCssClass ("window" );
387
+ window .as (gtk .Widget ).addCssClass ("terminal-window" );
388
+ window .setIconName (build_config .bundle_id );
389
+
390
+ if (self .config .maximize ) window .maximize ();
391
+ if (self .config .fullscreen ) window .fullscreen ();
392
+
393
+ try self .syncAppearance ();
394
+ }
395
+
383
396
/// Updates appearance based on config settings. Will be called once upon window
384
397
/// realization, every time the config is reloaded, and every time a window state
385
398
/// is toggled (un-/maximized, un-/fullscreened, window decorations toggled, etc.)
386
399
///
387
400
/// TODO: Many of the initial style settings in `create` could possibly be made
388
401
/// reactive by moving them here.
389
402
pub fn syncAppearance (self : * Window ) ! void {
403
+ const window = gobject .ext .cast (gtk .Window , self .window ).? ;
390
404
const csd_enabled = self .winproto .clientSideDecorationEnabled ();
391
- c . gtk_window_set_decorated ( self . window , @intFromBool (csd_enabled ));
405
+ window . setDecorated ( @intFromBool (csd_enabled ));
392
406
393
407
// Fix any artifacting that may occur in window corners. The .ssd CSS
394
408
// class is defined in the GtkWindow documentation:
395
409
// https://docs.gtk.org/gtk4/class.Window.html#css-nodes. A definition
396
410
// for .ssd is provided by GTK and Adwaita.
397
- toggleCssClass (@ptrCast ( self . window ) , "csd" , csd_enabled );
398
- toggleCssClass (@ptrCast ( self . window ) , "ssd" , ! csd_enabled );
399
- toggleCssClass (@ptrCast ( self . window ) , "no-border-radius" , ! csd_enabled );
411
+ toggleCssClass (window , "csd" , csd_enabled );
412
+ toggleCssClass (window , "ssd" , ! csd_enabled );
413
+ toggleCssClass (window , "no-border-radius" , ! csd_enabled );
400
414
401
415
self .headerbar .setVisible (visible : {
402
416
// Never display the header bar when CSDs are disabled.
@@ -414,7 +428,7 @@ pub fn syncAppearance(self: *Window) !void {
414
428
});
415
429
416
430
toggleCssClass (
417
- @ptrCast ( self . window ) ,
431
+ window ,
418
432
"background" ,
419
433
self .config .background_opacity >= 1 ,
420
434
);
@@ -423,7 +437,7 @@ pub fn syncAppearance(self: *Window) !void {
423
437
// GTK version is before 4.16. The conditional is because above 4.16
424
438
// we use GTK CSS color variables.
425
439
toggleCssClass (
426
- @ptrCast ( self . window ) ,
440
+ window ,
427
441
"window-theme-ghostty" ,
428
442
! version .atLeast (4 , 16 , 0 ) and self .config .window_theme == .ghostty ,
429
443
);
@@ -451,23 +465,17 @@ pub fn syncAppearance(self: *Window) !void {
451
465
self .winproto .syncAppearance () catch | err | {
452
466
log .warn ("failed to sync winproto appearance error={}" , .{err });
453
467
};
454
-
455
- toggleCssClass (
456
- @ptrCast (self .window ),
457
- "background" ,
458
- self .config .background_opacity >= 1 ,
459
- );
460
468
}
461
469
462
470
fn toggleCssClass (
463
- widget : * c.GtkWidget ,
471
+ widget : anytype ,
464
472
class : [:0 ]const u8 ,
465
473
v : bool ,
466
474
) void {
467
475
if (v ) {
468
- c . gtk_widget_add_css_class ( widget , class );
476
+ widget . as ( gtk . Widget ). addCssClass ( class );
469
477
} else {
470
- c . gtk_widget_remove_css_class ( widget , class );
478
+ widget . as ( gtk . Widget ). removeCssClass ( class );
471
479
}
472
480
}
473
481
0 commit comments