stack tabs: follow WindowControlsPosition for the close button

The window stack tabs build their own Tab widget rather than using
libcosmic segmented_button, so they kept the close button on the right
even with macOS-style controls enabled.

Order the tab items from the configured position: close first when
Start, last when End, with the container alignment following.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lionel DARNIS 2026-08-19 21:18:39 +02:00
parent 7187efd58f
commit b45d12edef

View file

@ -13,7 +13,7 @@ use cosmic::{
widget::{self, container::draw_background, rule::FillMode, scrollable::AbsoluteOffset}, widget::{self, container::draw_background, rule::FillMode, scrollable::AbsoluteOffset},
}, },
theme, theme,
widget::{Icon, icon::from_name, text}, widget::{Icon, WindowControlsPosition, icon::from_name, text},
}; };
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
@ -185,32 +185,47 @@ impl<Message: TabMessage + 'static> Tab<Message> {
close_button = close_button.on_press(close_message); close_button = close_button.on_press(close_message);
} }
let items = vec![ let controls_position = cosmic::config::window_controls_position();
widget::rule::vertical(4).class(self.rule_theme).into(),
self.app_icon let rule: cosmic::Element<'a, Message> =
.clone() widget::rule::vertical(4).class(self.rule_theme).into();
.apply(widget::container)
.width(Length::Shrink) let app_icon: cosmic::Element<'a, Message> = self
.padding([2, 4]) .app_icon
.center_y(Length::Fill) .clone()
.into(), .apply(widget::container)
text::body(self.title) .width(Length::Shrink)
.font(self.font) .padding([2, 4])
.wrapping(Wrapping::None) .center_y(Length::Fill)
.shaping(Shaping::Advanced) .into();
.ellipsize(Ellipsize::End(EllipsizeHeightLimit::Lines(1)))
.align_y(alignment::Vertical::Center) let title: cosmic::Element<'a, Message> = text::body(self.title)
.height(Length::Fill) .font(self.font)
.width(Length::Fill) .wrapping(Wrapping::None)
.into(), .shaping(Shaping::Advanced)
close_button .ellipsize(Ellipsize::End(EllipsizeHeightLimit::Lines(1)))
.apply(widget::container) .align_y(alignment::Vertical::Center)
.width(Length::Shrink) .height(Length::Fill)
.padding([2, 4]) .width(Length::Fill)
.center_y(Length::Fill) .into();
.align_x(alignment::Horizontal::Right)
.into(), let close: cosmic::Element<'a, Message> = close_button
]; .apply(widget::container)
.width(Length::Shrink)
.padding([2, 4])
.center_y(Length::Fill)
.align_x(match controls_position {
WindowControlsPosition::Start => alignment::Horizontal::Left,
WindowControlsPosition::End => alignment::Horizontal::Right,
})
.into();
// With macOS-style controls the close button leads the tab contents,
// mirroring the window buttons in the header bar.
let items = match controls_position {
WindowControlsPosition::Start => vec![rule, close, app_icon, title],
WindowControlsPosition::End => vec![rule, app_icon, title, close],
};
TabInternal { TabInternal {
id: self.id, id: self.id,