From a5ad73fa036df621359026fbf9592a0bbbdf3888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sun, 26 Oct 2025 11:08:36 +0100 Subject: [PATCH] sidebar: Show dot for unread rooms --- src/session_view/sidebar/room_row.blp | 47 ++++++++++++++++++------ src/session_view/sidebar/room_row.rs | 9 +++-- src/session_view/sidebar/section_row.blp | 10 ++--- src/session_view/sidebar/section_row.rs | 11 ++---- 4 files changed, 50 insertions(+), 27 deletions(-) diff --git a/src/session_view/sidebar/room_row.blp b/src/session_view/sidebar/room_row.blp index 1986c434..59652d6d 100644 --- a/src/session_view/sidebar/room_row.blp +++ b/src/session_view/sidebar/room_row.blp @@ -24,17 +24,42 @@ template $SidebarRoomRow: Adw.Bin { } [end] - Gtk.Label notification_count { - hexpand: true; - halign: end; - valign: center; - yalign: 1.0; - visible: bind template.room as <$Room>.has-notifications; - label: bind template.room as <$Room>.notification-count; - - styles [ - "notification-count", - ] + Gtk.Stack { + visible: bind $logical_or(template.room as <$Room>.has-notifications, $invert_boolean(template.room as <$Room>.is-read) as ) as ; + visible-child-name: bind $ternary_string(template.room as <$Room>.has-notifications, "count", "dot") as ; + + Gtk.StackPage { + name: "dot"; + + child: Gtk.Image { + halign: end; + icon-name: "dot-symbolic"; + + styles [ + "dimmed", + ] + + accessibility { + label: "Unread messages"; + } + }; + } + + Gtk.StackPage { + name: "count"; + + child: Gtk.Label notification_count { + hexpand: true; + halign: end; + valign: center; + yalign: 1.0; + label: bind template.room as <$Room>.notification-count; + + styles [ + "notification-count", + ] + }; + } } } } diff --git a/src/session_view/sidebar/room_row.rs b/src/session_view/sidebar/room_row.rs index 485b2667..9e6446ae 100644 --- a/src/session_view/sidebar/room_row.rs +++ b/src/session_view/sidebar/room_row.rs @@ -7,7 +7,7 @@ use crate::{ i18n::{gettext_f, ngettext_f}, prelude::*, session::{HighlightFlags, Room, RoomCategory}, - utils::BoundObject, + utils::{BoundObject, TemplateCallbacks}, }; mod imp { @@ -21,9 +21,6 @@ mod imp { #[template(resource = "/org/gnome/Fractal/ui/session_view/sidebar/room_row.ui")] #[properties(wrapper_type = super::SidebarRoomRow)] pub struct SidebarRoomRow { - /// The room represented by this row. - #[property(get, set = Self::set_room, explicit_notify, nullable)] - room: BoundObject, #[template_child] avatar: TemplateChild, #[template_child] @@ -33,6 +30,9 @@ mod imp { #[template_child] notification_count: TemplateChild, direct_icon: RefCell>, + /// The room represented by this row. + #[property(get, set = Self::set_room, explicit_notify, nullable)] + room: BoundObject, } #[glib::object_subclass] @@ -43,6 +43,7 @@ mod imp { fn class_init(klass: &mut Self::Class) { Self::bind_template(klass); + TemplateCallbacks::bind_template_callbacks(klass); klass.set_css_name("room"); klass.set_accessible_role(gtk::AccessibleRole::Group); diff --git a/src/session_view/sidebar/section_row.blp b/src/session_view/sidebar/section_row.blp index 9e6f59a1..71798475 100644 --- a/src/session_view/sidebar/section_row.blp +++ b/src/session_view/sidebar/section_row.blp @@ -19,14 +19,14 @@ template $SidebarSectionRow: Adw.Bin { } [end] - Gtk.Stack notification_status { + Gtk.Stack { visible: bind $invert_boolean($logical_or(template.section as <$SidebarSection>.is-expanded, template.section as <$SidebarSection>.is-read) as ) as ; - visible-child-name: bind $ternary_string(template.section as <$SidebarSection>.has-notifications, "notification-count", "highlight-dot") as ; + visible-child-name: bind $ternary_string(template.section as <$SidebarSection>.has-notifications, "count", "dot") as ; Gtk.StackPage { - name: "highlight-dot"; + name: "dot"; - child: Gtk.Image highlight_dot { + child: Gtk.Image { halign: end; icon-name: "dot-symbolic"; @@ -41,7 +41,7 @@ template $SidebarSectionRow: Adw.Bin { } Gtk.StackPage { - name: "notification-count"; + name: "count"; child: Gtk.Label notification_count { hexpand: true; diff --git a/src/session_view/sidebar/section_row.rs b/src/session_view/sidebar/section_row.rs index 743240b0..49f399e9 100644 --- a/src/session_view/sidebar/section_row.rs +++ b/src/session_view/sidebar/section_row.rs @@ -21,6 +21,10 @@ mod imp { #[template(resource = "/org/gnome/Fractal/ui/session_view/sidebar/section_row.ui")] #[properties(wrapper_type = super::SidebarSectionRow)] pub struct SidebarSectionRow { + #[template_child] + pub(super) display_name: TemplateChild, + #[template_child] + notification_count: TemplateChild, /// The section of this row. #[property(get, set = Self::set_section, explicit_notify, nullable)] section: BoundObject, @@ -37,13 +41,6 @@ mod imp { /// This will change the label according to the action that can be /// performed when dropping a room with the given category. show_label_for_room_category: Cell>, - /// The label showing the category name. - #[template_child] - pub(super) display_name: TemplateChild, - #[template_child] - notification_status: TemplateChild, - #[template_child] - notification_count: TemplateChild, } #[glib::object_subclass]