Activate workspace only if capability is present

Potentially relevant on compositors not advertising this, or if a
compositor wanted to advertise `Activate` support for some but not all
workspaces. This will be more relevant with other capabilities.
This commit is contained in:
Ian Douglas Scott 2025-04-21 13:20:42 -07:00
parent 655621fde0
commit 7037cd3d05

View file

@ -2,6 +2,7 @@ use cosmic::{
cctk::{ cctk::{
cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1, cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1,
wayland_client::protocol::wl_output, wayland_client::protocol::wl_output,
wayland_protocols::ext::workspace::v1::client::ext_workspace_handle_v1,
}, },
iced::{ iced::{
self, self,
@ -207,13 +208,15 @@ fn workspace_item(
let is_active = workspace.is_active(); let is_active = workspace.is_active();
// TODO editable name? // TODO editable name?
widget::button::custom(content) let mut button = widget::button::custom(content)
.selected(workspace.is_active()) .selected(workspace.is_active())
.class(cosmic::theme::Button::Custom { .class(cosmic::theme::Button::Custom {
active: Box::new(move |_focused, theme| { active: Box::new(move |_focused, theme| {
workspace_item_appearance(theme, is_active, is_drop_target) workspace_item_appearance(theme, is_active, is_drop_target)
}), }),
disabled: Box::new(|_theme| unreachable!()), disabled: Box::new(move |theme| {
workspace_item_appearance(theme, is_active, is_drop_target)
}),
hovered: Box::new(move |_focused, theme| { hovered: Box::new(move |_focused, theme| {
workspace_item_appearance(theme, is_active, true) workspace_item_appearance(theme, is_active, true)
}), }),
@ -221,9 +224,15 @@ fn workspace_item(
workspace_item_appearance(theme, is_active, true) workspace_item_appearance(theme, is_active, true)
}), }),
}) })
.on_press(Msg::ActivateWorkspace(workspace.handle().clone())) .padding(8);
.padding(8) if workspace
.into() .info
.capabilities
.contains(ext_workspace_handle_v1::WorkspaceCapabilities::Activate)
{
button = button.on_press(Msg::ActivateWorkspace(workspace.handle().clone()));
}
button.into()
} }
fn workspace_sidebar_entry<'a>( fn workspace_sidebar_entry<'a>(