@@ -285,81 +285,94 @@ pub fn init(self: *Window, app: *App) !void {
285
285
// Our actions for the menu
286
286
initActions (self );
287
287
288
- if ((comptime adwaita .versionAtLeast (1 , 4 , 0 )) and adwaita .versionAtLeast (1 , 4 , 0 ) and adwaita .enabled (& self .app .config )) {
289
- const toolbar_view : * c.AdwToolbarView = @ptrCast (c .adw_toolbar_view_new ());
288
+ tab_bar : {
289
+ if ((comptime ! adwaita .versionAtLeast (0 , 0 , 0 )) or ! adwaita .enabled (& self .app .config )) {
290
+ // Directly place the headerbar in the window when Adwaita is disabled,
291
+ // since the tab bar is a part of the headerbar/GtkNotebook
292
+ c .gtk_window_set_titlebar (gtk_window , self .headerbar .asWidget ());
293
+ c .gtk_window_set_child (gtk_window , box );
294
+ break :tab_bar ;
295
+ }
290
296
291
- c .adw_toolbar_view_add_top_bar (toolbar_view , self .headerbar .asWidget ());
297
+ const tab_bar = c .adw_tab_bar_new ();
298
+ c .adw_tab_bar_set_view (tab_bar , self .notebook .adw .tab_view );
292
299
293
- if (self .app .config .@"gtk-tabs-location" != .hidden ) {
294
- const tab_bar = c .adw_tab_bar_new ();
295
- c .adw_tab_bar_set_view (tab_bar , self .notebook .adw .tab_view );
300
+ if (! app .config .@"gtk-wide-tabs" ) c .adw_tab_bar_set_expand_tabs (tab_bar , 0 );
296
301
297
- if (! app .config .@"gtk-wide-tabs" ) c .adw_tab_bar_set_expand_tabs (tab_bar , 0 );
302
+ c .adw_tab_bar_set_autohide (
303
+ tab_bar ,
304
+ @intFromBool (switch (app .config .@"window-show-tab-bar" ) {
305
+ .always = > false ,
306
+ .auto , .never = > true ,
307
+ }),
308
+ );
309
+
310
+ const tab_bar_widget : * c.GtkWidget = @ptrCast (@alignCast (tab_bar ));
311
+
312
+ c .gtk_widget_set_visible (
313
+ tab_bar_widget ,
314
+ @intFromBool (switch (app .config .@"window-show-tab-bar" ) {
315
+ .always , .auto = > true ,
316
+ .never = > false ,
317
+ }),
318
+ );
319
+
320
+ // Can we use ToolbarView (libadw 1.4+)? If so, put both the headerbar
321
+ // and the tab bar as sub-bars of the toolbar view
322
+ if ((comptime adwaita .versionAtLeast (1 , 4 , 0 )) and adwaita .versionAtLeast (1 , 4 , 0 )) {
323
+ const toolbar_view : * c.AdwToolbarView = @ptrCast (c .adw_toolbar_view_new ());
324
+
325
+ c .adw_toolbar_view_add_top_bar (toolbar_view , self .headerbar .asWidget ());
298
326
299
- const tab_bar_widget : * c.GtkWidget = @ptrCast (@alignCast (tab_bar ));
300
327
switch (self .app .config .@"gtk-tabs-location" ) {
301
328
// left and right are not supported in libadwaita.
302
329
.top , .left , .right = > c .adw_toolbar_view_add_top_bar (toolbar_view , tab_bar_widget ),
303
330
.bottom = > c .adw_toolbar_view_add_bottom_bar (toolbar_view , tab_bar_widget ),
304
- .hidden = > unreachable ,
331
+ .hidden = > {},
332
+ }
333
+ c .adw_toolbar_view_set_content (toolbar_view , box );
334
+
335
+ const toolbar_style : c.AdwToolbarStyle = switch (self .app .config .@"adw-toolbar-style" ) {
336
+ .flat = > c .ADW_TOOLBAR_FLAT ,
337
+ .raised = > c .ADW_TOOLBAR_RAISED ,
338
+ .@"raised-border" = > c .ADW_TOOLBAR_RAISED_BORDER ,
339
+ };
340
+ c .adw_toolbar_view_set_top_bar_style (toolbar_view , toolbar_style );
341
+ c .adw_toolbar_view_set_bottom_bar_style (toolbar_view , toolbar_style );
342
+
343
+ // Set our application window content.
344
+ c .adw_tab_overview_set_child (
345
+ @ptrCast (self .tab_overview ),
346
+ @ptrCast (@alignCast (toolbar_view )),
347
+ );
348
+ c .adw_application_window_set_content (
349
+ @ptrCast (gtk_window ),
350
+ @ptrCast (@alignCast (self .tab_overview )),
351
+ );
352
+ } else {
353
+ // Older libadwaita versions don't support toolbar views.
354
+ // We have to add the tab bar directly to the main box, either
355
+ // as the last child of the box (bottom) or right after the
356
+ // header bar (every other option except hidden)
357
+ switch (app .config .@"gtk-tabs-location" ) {
358
+ .top ,
359
+ .left ,
360
+ .right ,
361
+ = > c .gtk_box_insert_child_after (@ptrCast (box ), @ptrCast (@alignCast (tab_bar )), @ptrCast (@alignCast (self .headerbar .asWidget ()))),
362
+
363
+ .bottom = > c .gtk_box_append (
364
+ @ptrCast (box ),
365
+ @ptrCast (@alignCast (tab_bar )),
366
+ ),
367
+ .hidden = > {},
305
368
}
306
- }
307
- c .adw_toolbar_view_set_content (toolbar_view , box );
308
-
309
- const toolbar_style : c.AdwToolbarStyle = switch (self .app .config .@"adw-toolbar-style" ) {
310
- .flat = > c .ADW_TOOLBAR_FLAT ,
311
- .raised = > c .ADW_TOOLBAR_RAISED ,
312
- .@"raised-border" = > c .ADW_TOOLBAR_RAISED_BORDER ,
313
- };
314
- c .adw_toolbar_view_set_top_bar_style (toolbar_view , toolbar_style );
315
- c .adw_toolbar_view_set_bottom_bar_style (toolbar_view , toolbar_style );
316
-
317
- // Set our application window content.
318
- c .adw_tab_overview_set_child (
319
- @ptrCast (self .tab_overview ),
320
- @ptrCast (@alignCast (toolbar_view )),
321
- );
322
- c .adw_application_window_set_content (
323
- @ptrCast (gtk_window ),
324
- @ptrCast (@alignCast (self .tab_overview )),
325
- );
326
- } else tab_bar : {
327
- switch (self .notebook ) {
328
- .adw = > | * adw | if (comptime adwaita .versionAtLeast (0 , 0 , 0 )) {
329
- if (app .config .@"gtk-tabs-location" == .hidden ) break :tab_bar ;
330
- // In earlier adwaita versions, we need to add the tabbar manually since we do not use
331
- // an AdwToolbarView.
332
- const tab_bar : * c.AdwTabBar = c .adw_tab_bar_new ().? ;
333
- c .gtk_widget_add_css_class (@ptrCast (@alignCast (tab_bar )), "inline" );
334
- switch (app .config .@"gtk-tabs-location" ) {
335
- .top ,
336
- .left ,
337
- .right ,
338
- = > c .gtk_box_insert_child_after (@ptrCast (box ), @ptrCast (@alignCast (tab_bar )), @ptrCast (@alignCast (self .headerbar .asWidget ()))),
339
-
340
- .bottom = > c .gtk_box_append (
341
- @ptrCast (box ),
342
- @ptrCast (@alignCast (tab_bar )),
343
- ),
344
- .hidden = > unreachable ,
345
- }
346
- c .adw_tab_bar_set_view (tab_bar , adw .tab_view );
347
-
348
- if (! app .config .@"gtk-wide-tabs" ) c .adw_tab_bar_set_expand_tabs (tab_bar , 0 );
349
- },
350
369
351
- .gtk = > {},
352
- }
370
+ c .gtk_widget_add_css_class (@ptrCast (@alignCast (tab_bar )), "inline" );
353
371
354
- // The box is our main child
355
- if (! adwaita .versionAtLeast (1 , 4 , 0 ) and adwaita .enabled (& self .app .config )) {
356
372
c .adw_application_window_set_content (
357
373
@ptrCast (gtk_window ),
358
374
box ,
359
375
);
360
- } else {
361
- c .gtk_window_set_titlebar (gtk_window , self .headerbar .asWidget ());
362
- c .gtk_window_set_child (gtk_window , box );
363
376
}
364
377
}
365
378
0 commit comments