@@ -10,6 +10,7 @@ const builtin = @import("builtin");
10
10
const Allocator = std .mem .Allocator ;
11
11
const assert = std .debug .assert ;
12
12
13
+ const adw = @import ("adw" );
13
14
const gio = @import ("gio" );
14
15
const glib = @import ("glib" );
15
16
const gobject = @import ("gobject" );
@@ -52,6 +53,9 @@ window: *c.GtkWindow,
52
53
/// The header bar for the window.
53
54
headerbar : HeaderBar ,
54
55
56
+ /// The tab bar for the window.
57
+ tab_bar : * adw.TabBar ,
58
+
55
59
/// The tab overview for the window. This is possibly null since there is no
56
60
/// taboverview without a AdwApplicationWindow (libadwaita >= 1.4.0).
57
61
tab_overview : ? * c.GtkWidget ,
@@ -80,6 +84,7 @@ pub const DerivedConfig = struct {
80
84
gtk_tabs_location : configpkg.Config.GtkTabsLocation ,
81
85
gtk_wide_tabs : bool ,
82
86
gtk_toolbar_style : configpkg.Config.GtkToolbarStyle ,
87
+ window_show_tab_bar : configpkg.Config.WindowShowTabBar ,
83
88
84
89
quick_terminal_position : configpkg.Config.QuickTerminalPosition ,
85
90
quick_terminal_size : configpkg.Config.QuickTerminalSize ,
@@ -99,6 +104,7 @@ pub const DerivedConfig = struct {
99
104
.gtk_tabs_location = config .@"gtk-tabs-location" ,
100
105
.gtk_wide_tabs = config .@"gtk-wide-tabs" ,
101
106
.gtk_toolbar_style = config .@"gtk-toolbar-style" ,
107
+ .window_show_tab_bar = config .@"window-show-tab-bar" ,
102
108
103
109
.quick_terminal_position = config .@"quick-terminal-position" ,
104
110
.quick_terminal_size = config .@"quick-terminal-size" ,
@@ -133,6 +139,7 @@ pub fn init(self: *Window, app: *App) !void {
133
139
.config = DerivedConfig .init (& app .config ),
134
140
.window = undefined ,
135
141
.headerbar = undefined ,
142
+ .tab_bar = undefined ,
136
143
.tab_overview = null ,
137
144
.notebook = undefined ,
138
145
.titlebar_menu = undefined ,
@@ -215,8 +222,10 @@ pub fn init(self: *Window, app: *App) !void {
215
222
// If we're using an AdwWindow then we can support the tab overview.
216
223
if (self .tab_overview ) | tab_overview | {
217
224
if (! adwaita .versionAtLeast (1 , 4 , 0 )) unreachable ;
218
- const btn = switch (self .config .gtk_tabs_location ) {
219
- .top , .bottom = > btn : {
225
+
226
+ // TODO: Move this to syncAppearance and make it reactive
227
+ const btn = switch (self .config .window_show_tab_bar ) {
228
+ .always , .auto = > btn : {
220
229
const btn = c .gtk_toggle_button_new ();
221
230
c .gtk_widget_set_tooltip_text (btn , i18n ._ ("View Open Tabs" ));
222
231
c .gtk_button_set_icon_name (@ptrCast (btn ), "view-grid-symbolic" );
@@ -230,8 +239,7 @@ pub fn init(self: *Window, app: *App) !void {
230
239
231
240
break :btn btn ;
232
241
},
233
-
234
- .hidden = > btn : {
242
+ .never = > btn : {
235
243
const btn = c .adw_tab_button_new ();
236
244
c .adw_tab_button_set_view (@ptrCast (btn ), @ptrCast (@alignCast (self .notebook .tab_view )));
237
245
c .gtk_actionable_set_action_name (@ptrCast (btn ), "overview.open" );
@@ -310,23 +318,17 @@ pub fn init(self: *Window, app: *App) !void {
310
318
// Our actions for the menu
311
319
initActions (self );
312
320
321
+ self .tab_bar = adw .TabBar .new ();
322
+ self .tab_bar .setView (self .notebook .tab_view );
323
+
313
324
if (adwaita .versionAtLeast (1 , 4 , 0 )) {
314
325
const toolbar_view : * c.AdwToolbarView = @ptrCast (c .adw_toolbar_view_new ());
315
326
316
327
c .adw_toolbar_view_add_top_bar (toolbar_view , self .headerbar .asWidget ());
317
328
318
- if (self .config .gtk_tabs_location != .hidden ) {
319
- const tab_bar = c .adw_tab_bar_new ();
320
- c .adw_tab_bar_set_view (tab_bar , @ptrCast (@alignCast (self .notebook .tab_view )));
321
-
322
- if (! self .config .gtk_wide_tabs ) c .adw_tab_bar_set_expand_tabs (tab_bar , 0 );
323
-
324
- const tab_bar_widget : * c.GtkWidget = @ptrCast (@alignCast (tab_bar ));
325
- switch (self .config .gtk_tabs_location ) {
326
- .top = > c .adw_toolbar_view_add_top_bar (toolbar_view , tab_bar_widget ),
327
- .bottom = > c .adw_toolbar_view_add_bottom_bar (toolbar_view , tab_bar_widget ),
328
- .hidden = > unreachable ,
329
- }
329
+ switch (self .config .gtk_tabs_location ) {
330
+ .top = > c .adw_toolbar_view_add_top_bar (toolbar_view , @ptrCast (@alignCast (self .tab_bar ))),
331
+ .bottom = > c .adw_toolbar_view_add_bottom_bar (toolbar_view , @ptrCast (@alignCast (self .tab_bar ))),
330
332
}
331
333
c .adw_toolbar_view_set_content (toolbar_view , box );
332
334
@@ -347,27 +349,22 @@ pub fn init(self: *Window, app: *App) !void {
347
349
@ptrCast (gtk_widget ),
348
350
@ptrCast (@alignCast (self .tab_overview )),
349
351
);
350
- } else tab_bar : {
351
- if (self .config .gtk_tabs_location == .hidden ) break :tab_bar ;
352
+ } else {
352
353
// In earlier adwaita versions, we need to add the tabbar manually since we do not use
353
354
// an AdwToolbarView.
354
- const tab_bar : * c.AdwTabBar = c . adw_tab_bar_new () .? ;
355
- c . gtk_widget_add_css_class ( @ptrCast ( @alignCast ( tab_bar )), "inline" );
355
+ self . tab_bar . as ( gtk . Widget ). addCssClass ( "inline" ) ;
356
+
356
357
switch (self .config .gtk_tabs_location ) {
357
358
.top = > c .gtk_box_insert_child_after (
358
359
@ptrCast (box ),
359
- @ptrCast (@alignCast (tab_bar )),
360
+ @ptrCast (@alignCast (self . tab_bar )),
360
361
@ptrCast (@alignCast (self .headerbar .asWidget ())),
361
362
),
362
363
.bottom = > c .gtk_box_append (
363
364
@ptrCast (box ),
364
- @ptrCast (@alignCast (tab_bar )),
365
+ @ptrCast (@alignCast (self . tab_bar )),
365
366
),
366
- .hidden = > unreachable ,
367
367
}
368
- c .adw_tab_bar_set_view (tab_bar , @ptrCast (@alignCast (self .notebook .tab_view )));
369
-
370
- if (! self .config .gtk_wide_tabs ) c .adw_tab_bar_set_expand_tabs (tab_bar , 0 );
371
368
}
372
369
373
370
// If we want the window to be maximized, we do that here.
@@ -480,6 +477,16 @@ pub fn syncAppearance(self: *Window) !void {
480
477
c .adw_toolbar_view_set_bottom_bar_style (toolbar_view , toolbar_style );
481
478
}
482
479
480
+ self .tab_bar .setExpandTabs (@intFromBool (self .config .gtk_wide_tabs ));
481
+ self .tab_bar .setAutohide (switch (self .config .window_show_tab_bar ) {
482
+ .auto , .never = > @intFromBool (true ),
483
+ .always = > @intFromBool (false ),
484
+ });
485
+ self .tab_bar .as (gtk .Widget ).setVisible (switch (self .config .window_show_tab_bar ) {
486
+ .always , .auto = > @intFromBool (true ),
487
+ .never = > @intFromBool (false ),
488
+ });
489
+
483
490
self .winproto .syncAppearance () catch | err | {
484
491
log .warn ("failed to sync winproto appearance error={}" , .{err });
485
492
};
0 commit comments