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},
},
theme,
widget::{Icon, icon::from_name, text},
widget::{Icon, WindowControlsPosition, icon::from_name, text},
};
#[derive(Clone, Copy)]
@ -185,32 +185,47 @@ impl<Message: TabMessage + 'static> Tab<Message> {
close_button = close_button.on_press(close_message);
}
let items = vec![
widget::rule::vertical(4).class(self.rule_theme).into(),
self.app_icon
.clone()
.apply(widget::container)
.width(Length::Shrink)
.padding([2, 4])
.center_y(Length::Fill)
.into(),
text::body(self.title)
.font(self.font)
.wrapping(Wrapping::None)
.shaping(Shaping::Advanced)
.ellipsize(Ellipsize::End(EllipsizeHeightLimit::Lines(1)))
.align_y(alignment::Vertical::Center)
.height(Length::Fill)
.width(Length::Fill)
.into(),
close_button
.apply(widget::container)
.width(Length::Shrink)
.padding([2, 4])
.center_y(Length::Fill)
.align_x(alignment::Horizontal::Right)
.into(),
];
let controls_position = cosmic::config::window_controls_position();
let rule: cosmic::Element<'a, Message> =
widget::rule::vertical(4).class(self.rule_theme).into();
let app_icon: cosmic::Element<'a, Message> = self
.app_icon
.clone()
.apply(widget::container)
.width(Length::Shrink)
.padding([2, 4])
.center_y(Length::Fill)
.into();
let title: cosmic::Element<'a, Message> = text::body(self.title)
.font(self.font)
.wrapping(Wrapping::None)
.shaping(Shaping::Advanced)
.ellipsize(Ellipsize::End(EllipsizeHeightLimit::Lines(1)))
.align_y(alignment::Vertical::Center)
.height(Length::Fill)
.width(Length::Fill)
.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 {
id: self.id,