Use Adw.HeaderBar for CSD header bars

This allows showing the correct buttons with 'show-start-title-buttons'
and 'show-end-title-buttons' properties when folding.
This commit is contained in:
Teemu Ikonen 2022-09-12 23:10:35 +03:00 committed by Marvin W
parent 2741bf21ae
commit ba9462503c
No known key found for this signature in database
GPG key ID: 072E9235DB996F2A
4 changed files with 7 additions and 4 deletions

View file

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<interface> <interface>
<requires lib="gtk" version="4.0"/> <requires lib="gtk" version="4.0"/>
<object class="GtkHeaderBar" id="header_bar"> <requires lib="adw" version="1.0"/>
<object class="AdwHeaderBar" id="header_bar">
<property name="hexpand">False</property> <property name="hexpand">False</property>
<style> <style>
<class name="dino-left"/> <class name="dino-left"/>

View file

@ -15,12 +15,12 @@ public class ConversationListTitlebar : Gtk.Box {
} }
} }
public static HeaderBar get_conversation_list_titlebar_csd() { public static Adw.HeaderBar get_conversation_list_titlebar_csd() {
Builder builder = new Builder.from_resource("/im/dino/Dino/conversation_list_titlebar_csd.ui"); Builder builder = new Builder.from_resource("/im/dino/Dino/conversation_list_titlebar_csd.ui");
MenuButton add_button = (MenuButton) builder.get_object("add_button"); MenuButton add_button = (MenuButton) builder.get_object("add_button");
MenuButton menu_button = (MenuButton) builder.get_object("menu_button"); MenuButton menu_button = (MenuButton) builder.get_object("menu_button");
create_add_menu(add_button, menu_button); create_add_menu(add_button, menu_button);
return (HeaderBar) builder.get_object("header_bar"); return (Adw.HeaderBar) builder.get_object("header_bar");
} }
private static void create_add_menu(MenuButton add_button, MenuButton menu_button) { private static void create_add_menu(MenuButton add_button, MenuButton menu_button) {

View file

@ -68,7 +68,7 @@ public class ConversationTitlebarCsd : ConversationTitlebar, Object {
public new string? title { get { return title_label.label; } set { title_label.label = value; } } public new string? title { get { return title_label.label; } set { title_label.label = value; } }
public new string? subtitle { get { return subtitle_label.label; } set { subtitle_label.label = value; subtitle_label.visible = (value != null); } } public new string? subtitle { get { return subtitle_label.label; } set { subtitle_label.label = value; subtitle_label.visible = (value != null); } }
public HeaderBar header_bar = new HeaderBar(); public Adw.HeaderBar header_bar = new Adw.HeaderBar();
private Label title_label = new Label("") { ellipsize=EllipsizeMode.END }; private Label title_label = new Label("") { ellipsize=EllipsizeMode.END };
private Label subtitle_label = new Label("") { ellipsize=EllipsizeMode.END, visible=false }; private Label subtitle_label = new Label("") { ellipsize=EllipsizeMode.END, visible=false };

View file

@ -84,6 +84,8 @@ public class MainWindow : Adw.Window {
if (Util.use_csd()) { if (Util.use_csd()) {
conversation_list_titlebar = get_conversation_list_titlebar_csd(); conversation_list_titlebar = get_conversation_list_titlebar_csd();
conversation_titlebar = new ConversationTitlebarCsd(); conversation_titlebar = new ConversationTitlebarCsd();
paned.bind_property("folded", conversation_list_titlebar, "show-end-title-buttons", BindingFlags.SYNC_CREATE);
paned.bind_property("folded", conversation_titlebar.get_widget(), "show-start-title-buttons", BindingFlags.SYNC_CREATE);
} else { } else {
Label title_label = new Label("Dino"); Label title_label = new Label("Dino");
HeaderBar titlebar = new HeaderBar() { title_widget=title_label, show_title_buttons=true }; HeaderBar titlebar = new HeaderBar() { title_widget=title_label, show_title_buttons=true };