2023-11-16 20:09:10 -08:00
|
|
|
use cosmic::{
|
2025-01-24 14:28:42 -08:00
|
|
|
cctk::{
|
|
|
|
|
cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1,
|
|
|
|
|
wayland_client::protocol::wl_output,
|
|
|
|
|
},
|
2023-11-16 20:09:10 -08:00
|
|
|
iced::{
|
|
|
|
|
self,
|
2023-12-13 15:54:33 -08:00
|
|
|
advanced::layout::flex::Axis,
|
2025-03-18 13:29:26 -07:00
|
|
|
clipboard::mime::AllowedMimeTypes,
|
2023-11-16 20:09:10 -08:00
|
|
|
widget::{column, row},
|
2025-04-09 13:40:08 +02:00
|
|
|
Border, Length,
|
2023-11-16 20:09:10 -08:00
|
|
|
},
|
2024-12-23 01:54:51 +01:00
|
|
|
iced_core::{text::Wrapping, Shadow},
|
2024-10-18 13:13:53 -07:00
|
|
|
iced_winit::platform_specific::wayland::subsurface_widget::Subsurface,
|
2024-12-23 01:54:51 +01:00
|
|
|
widget, Apply,
|
2023-11-16 20:09:10 -08:00
|
|
|
};
|
2024-02-07 19:52:33 -08:00
|
|
|
use cosmic_comp_config::workspace::WorkspaceLayout;
|
2025-01-24 14:28:42 -08:00
|
|
|
use std::collections::HashMap;
|
2023-11-16 19:25:28 -08:00
|
|
|
|
2024-04-23 13:44:59 -07:00
|
|
|
use crate::{
|
|
|
|
|
backend::{self, CaptureImage},
|
2025-02-10 12:02:36 -08:00
|
|
|
dnd::{DragSurface, DragToplevel, DragWorkspace, DropTarget},
|
2025-01-24 14:28:42 -08:00
|
|
|
App, LayerSurface, Msg, Toplevel, Workspace,
|
2024-04-23 13:44:59 -07:00
|
|
|
};
|
2023-11-16 19:25:28 -08:00
|
|
|
|
2025-03-18 13:29:26 -07:00
|
|
|
fn dnd_destination_for_target<'a, T>(
|
2025-01-24 14:09:17 -08:00
|
|
|
target: DropTarget,
|
|
|
|
|
child: cosmic::Element<'a, Msg>,
|
2025-03-18 13:29:26 -07:00
|
|
|
on_finish: impl Fn(T) -> Msg + 'static,
|
|
|
|
|
) -> cosmic::Element<'a, Msg>
|
|
|
|
|
where
|
|
|
|
|
T: AllowedMimeTypes,
|
|
|
|
|
{
|
2025-02-10 12:02:36 -08:00
|
|
|
let target2 = target.clone();
|
|
|
|
|
cosmic::widget::dnd_destination::dnd_destination_for_data(
|
|
|
|
|
child,
|
2025-03-18 13:29:26 -07:00
|
|
|
move |data: Option<T>, _action| match data {
|
|
|
|
|
Some(data) => on_finish(data),
|
2025-02-10 12:02:36 -08:00
|
|
|
None => Msg::Ignore,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
.drag_id(target.drag_id())
|
|
|
|
|
.on_enter(move |actions, mime, pos| Msg::DndEnter(target.clone(), actions, mime, pos))
|
|
|
|
|
.on_leave(move || Msg::DndLeave(target2.clone()))
|
|
|
|
|
.into()
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-16 19:25:28 -08:00
|
|
|
pub(crate) fn layer_surface<'a>(
|
|
|
|
|
app: &'a App,
|
|
|
|
|
surface: &'a LayerSurface,
|
|
|
|
|
) -> cosmic::Element<'a, Msg> {
|
2023-12-15 15:46:41 -08:00
|
|
|
let mut drop_target = None;
|
2025-01-24 14:09:17 -08:00
|
|
|
if let Some(DropTarget::WorkspaceSidebarEntry(workspace, output)) = &app.drop_target {
|
2023-12-15 15:46:41 -08:00
|
|
|
if output == &surface.output {
|
|
|
|
|
drop_target = Some(workspace);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-19 12:05:35 -07:00
|
|
|
let mut drag_toplevel = None;
|
2025-01-24 14:41:36 -08:00
|
|
|
if let Some((DragSurface::Toplevel(handle), _)) = &app.drag_surface {
|
2024-04-24 12:46:57 -07:00
|
|
|
drag_toplevel = Some(handle);
|
2024-04-19 12:05:35 -07:00
|
|
|
}
|
2023-11-17 14:56:37 -08:00
|
|
|
let layout = app.conf.workspace_config.workspace_layout;
|
|
|
|
|
let sidebar = workspaces_sidebar(
|
2025-01-24 15:30:15 -08:00
|
|
|
app.workspaces_for_output(&surface.output),
|
2023-11-17 14:56:37 -08:00
|
|
|
&surface.output,
|
|
|
|
|
layout,
|
2023-12-15 15:46:41 -08:00
|
|
|
drop_target,
|
2023-11-17 14:56:37 -08:00
|
|
|
);
|
2023-12-06 10:03:39 -08:00
|
|
|
let toplevels = toplevel_previews(
|
|
|
|
|
app.toplevels.iter().filter(|i| {
|
|
|
|
|
if !i.info.output.contains(&surface.output) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-11-16 19:25:28 -08:00
|
|
|
|
2023-12-06 10:03:39 -08:00
|
|
|
i.info.workspace.iter().any(|workspace| {
|
|
|
|
|
app.workspace_for_handle(workspace)
|
|
|
|
|
.map_or(false, |x| x.is_active)
|
|
|
|
|
})
|
|
|
|
|
}),
|
2023-12-18 19:59:09 -08:00
|
|
|
layout,
|
2024-04-19 12:05:35 -07:00
|
|
|
drag_toplevel,
|
2023-12-06 10:03:39 -08:00
|
|
|
);
|
2025-01-24 14:54:29 -08:00
|
|
|
// TODO multiple active workspaces? Not currently supported by cosmic.
|
|
|
|
|
let first_active_workspace = app
|
2025-01-24 15:30:15 -08:00
|
|
|
.workspaces_for_output(&surface.output)
|
|
|
|
|
.find(|w| w.is_active);
|
2025-01-24 14:54:29 -08:00
|
|
|
let toplevels = if let Some(workspace) = first_active_workspace {
|
2025-03-18 13:29:26 -07:00
|
|
|
dnd_destination_for_target(
|
2025-01-24 14:54:29 -08:00
|
|
|
DropTarget::OutputToplevels(workspace.handle.clone(), surface.output.clone()),
|
|
|
|
|
toplevels,
|
2025-03-18 13:29:26 -07:00
|
|
|
Msg::DndToplevelDrop,
|
2025-01-24 14:54:29 -08:00
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
// Shouldn't happen, but no drag destination if no active workspace found for output
|
|
|
|
|
cosmic::Element::from(toplevels)
|
|
|
|
|
};
|
2023-12-13 17:58:38 -08:00
|
|
|
let container = match layout {
|
2024-03-18 17:57:18 -07:00
|
|
|
WorkspaceLayout::Vertical => widget::layer_container(
|
2023-11-21 16:15:02 -05:00
|
|
|
row![sidebar, toplevels]
|
|
|
|
|
.spacing(12)
|
2025-04-09 13:40:08 +02:00
|
|
|
.height(Length::Fill)
|
|
|
|
|
.width(Length::Fill),
|
2023-11-21 16:15:02 -05:00
|
|
|
),
|
2024-03-18 17:57:18 -07:00
|
|
|
WorkspaceLayout::Horizontal => widget::layer_container(
|
2023-11-21 16:15:02 -05:00
|
|
|
column![sidebar, toplevels]
|
|
|
|
|
.spacing(12)
|
2025-04-09 13:40:08 +02:00
|
|
|
.height(Length::Fill)
|
|
|
|
|
.width(Length::Fill),
|
2023-11-21 16:15:02 -05:00
|
|
|
),
|
2023-12-13 17:58:38 -08:00
|
|
|
};
|
2025-01-24 15:35:45 -08:00
|
|
|
let output = surface.output.clone();
|
|
|
|
|
widget::mouse_area(container)
|
|
|
|
|
.on_scroll(move |delta| Msg::OnScroll(output.clone(), delta))
|
|
|
|
|
.into()
|
2023-11-16 19:25:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn close_button(on_press: Msg) -> cosmic::Element<'static, Msg> {
|
2024-12-23 01:54:51 +01:00
|
|
|
widget::button::custom(widget::icon::from_name("window-close-symbolic").size(16))
|
|
|
|
|
.class(cosmic::theme::Button::Destructive)
|
|
|
|
|
.on_press(on_press)
|
|
|
|
|
.into()
|
2023-11-16 19:25:28 -08:00
|
|
|
}
|
|
|
|
|
|
2024-04-25 14:10:09 -07:00
|
|
|
fn workspace_item_appearance(
|
|
|
|
|
theme: &cosmic::Theme,
|
|
|
|
|
is_active: bool,
|
|
|
|
|
hovered: bool,
|
2024-10-18 13:13:53 -07:00
|
|
|
) -> cosmic::widget::button::Style {
|
2024-04-25 14:10:09 -07:00
|
|
|
let cosmic = theme.cosmic();
|
2024-10-18 13:13:53 -07:00
|
|
|
let mut appearance = cosmic::widget::button::Style::new();
|
2024-12-23 01:54:51 +01:00
|
|
|
appearance.border_radius = cosmic
|
|
|
|
|
.corner_radii
|
|
|
|
|
.radius_s
|
|
|
|
|
.map(|x| if x < 4.0 { x } else { x + 4.0 })
|
|
|
|
|
.into();
|
2024-04-25 14:10:09 -07:00
|
|
|
if is_active {
|
2024-12-23 01:54:51 +01:00
|
|
|
appearance.border_width = 4.0;
|
2024-04-25 14:10:09 -07:00
|
|
|
appearance.border_color = cosmic.accent.base.into();
|
|
|
|
|
}
|
|
|
|
|
if hovered {
|
|
|
|
|
appearance.background = Some(iced::Background::Color(cosmic.button.base.into()));
|
|
|
|
|
}
|
|
|
|
|
appearance
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 18:41:34 -07:00
|
|
|
fn workspace_item<'a>(
|
2023-11-16 19:25:28 -08:00
|
|
|
workspace: &'a Workspace,
|
2025-01-29 15:09:07 -08:00
|
|
|
_output: &wl_output::WlOutput,
|
2025-04-09 13:40:08 +02:00
|
|
|
layout: WorkspaceLayout,
|
2024-05-01 12:14:46 -07:00
|
|
|
is_drop_target: bool,
|
2025-02-10 12:02:36 -08:00
|
|
|
) -> cosmic::Element<'static, Msg> {
|
2025-04-09 13:40:08 +02:00
|
|
|
let (image, image_height) = if let Some(img) = workspace.img.as_ref() {
|
|
|
|
|
let is_rotated = matches!(
|
|
|
|
|
img.transform,
|
|
|
|
|
wl_output::Transform::_90
|
|
|
|
|
| wl_output::Transform::_270
|
|
|
|
|
| wl_output::Transform::Flipped90
|
|
|
|
|
| wl_output::Transform::Flipped270
|
|
|
|
|
);
|
|
|
|
|
let (effective_width, effective_height) = if is_rotated {
|
|
|
|
|
// If rotated, swap width and height
|
|
|
|
|
(img.height, img.width)
|
|
|
|
|
} else {
|
|
|
|
|
(img.width, img.height)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let fixed_size = 126.0;
|
|
|
|
|
if effective_width > effective_height {
|
|
|
|
|
(
|
|
|
|
|
// Landscape: fix height
|
|
|
|
|
widget::container(capture_image(Some(img), 1.0)).max_height(fixed_size),
|
|
|
|
|
fixed_size,
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
(
|
|
|
|
|
// Portrait: fix width
|
|
|
|
|
widget::container(capture_image(Some(img), 1.0)).max_width(fixed_size),
|
|
|
|
|
fixed_size * effective_height as f32 / effective_width as f32,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
(
|
|
|
|
|
widget::container(capture_image(None, 1.0))
|
|
|
|
|
.max_width(224.0)
|
|
|
|
|
.max_height(126.0),
|
|
|
|
|
126.0,
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let workspace_name = widget::text::body(fl!(
|
|
|
|
|
"workspace",
|
|
|
|
|
HashMap::from([("number", &workspace.name)])
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
// Needed to prevent text getting pushed out when scaling on Vertical layout
|
|
|
|
|
let content = match layout {
|
|
|
|
|
WorkspaceLayout::Horizontal => column![image, workspace_name]
|
|
|
|
|
.align_x(iced::Alignment::Center)
|
|
|
|
|
.spacing(4)
|
|
|
|
|
.apply(widget::container),
|
|
|
|
|
WorkspaceLayout::Vertical => column![image.height(Length::Fill), workspace_name]
|
|
|
|
|
.align_x(iced::Alignment::Center)
|
|
|
|
|
.spacing(4)
|
|
|
|
|
.apply(widget::container)
|
|
|
|
|
.max_height(image_height + 21.0 + 4.0), // text height + spacing
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-25 14:10:09 -07:00
|
|
|
let is_active = workspace.is_active;
|
2024-12-23 01:54:51 +01:00
|
|
|
// TODO editable name?
|
2025-04-09 13:40:08 +02:00
|
|
|
widget::button::custom(content)
|
|
|
|
|
.selected(workspace.is_active)
|
|
|
|
|
.class(cosmic::theme::Button::Custom {
|
|
|
|
|
active: Box::new(move |_focused, theme| {
|
|
|
|
|
workspace_item_appearance(theme, is_active, is_drop_target)
|
|
|
|
|
}),
|
|
|
|
|
disabled: Box::new(|_theme| unreachable!()),
|
|
|
|
|
hovered: Box::new(move |_focused, theme| {
|
|
|
|
|
workspace_item_appearance(theme, is_active, true)
|
|
|
|
|
}),
|
|
|
|
|
pressed: Box::new(move |_focused, theme| {
|
|
|
|
|
workspace_item_appearance(theme, is_active, true)
|
|
|
|
|
}),
|
|
|
|
|
})
|
|
|
|
|
.on_press(Msg::ActivateWorkspace(workspace.handle.clone()))
|
|
|
|
|
.padding(8)
|
|
|
|
|
.into()
|
2023-11-16 19:25:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn workspace_sidebar_entry<'a>(
|
|
|
|
|
workspace: &'a Workspace,
|
|
|
|
|
output: &'a wl_output::WlOutput,
|
2025-04-09 13:40:08 +02:00
|
|
|
layout: WorkspaceLayout,
|
2024-05-01 12:14:46 -07:00
|
|
|
is_drop_target: bool,
|
2023-11-16 19:25:28 -08:00
|
|
|
) -> cosmic::Element<'a, Msg> {
|
2023-12-15 15:46:41 -08:00
|
|
|
/* XXX
|
|
|
|
|
let mouse_interaction = if is_drop_target {
|
|
|
|
|
iced::mouse::Interaction::Crosshair
|
|
|
|
|
} else {
|
|
|
|
|
iced::mouse::Interaction::Idle
|
|
|
|
|
};
|
|
|
|
|
*/
|
2025-04-09 13:40:08 +02:00
|
|
|
let item = workspace_item(workspace, output, layout, is_drop_target);
|
2023-12-06 10:51:55 -08:00
|
|
|
/* TODO allow moving workspaces (needs compositor support)
|
2025-02-10 12:02:36 -08:00
|
|
|
let workspace_clone = workspace.clone(); // TODO avoid clone
|
|
|
|
|
let output_clone = output.clone();
|
|
|
|
|
let source = cosmic::widget::dnd_source(item)
|
|
|
|
|
.drag_threshold(5.)
|
|
|
|
|
.drag_content(|| DragWorkspace {})
|
|
|
|
|
.drag_icon(move |offset| {
|
|
|
|
|
(
|
|
|
|
|
workspace_item(&workspace_clone, &output_clone, false).map(|_| ()),
|
|
|
|
|
cosmic::iced_core::widget::tree::State::None,
|
|
|
|
|
-offset,
|
2023-11-16 19:25:28 -08:00
|
|
|
)
|
|
|
|
|
})
|
2025-02-10 12:02:36 -08:00
|
|
|
.on_start(Some(Msg::StartDrag(DragSurface::Workspace(
|
|
|
|
|
workspace.handle.clone(),
|
|
|
|
|
))))
|
|
|
|
|
.on_finish(Some(Msg::SourceFinished))
|
|
|
|
|
.on_cancel(Some(Msg::SourceFinished))
|
|
|
|
|
.into();
|
2023-12-06 10:51:55 -08:00
|
|
|
*/
|
2023-12-15 15:46:41 -08:00
|
|
|
//crate::widgets::mouse_interaction_wrapper(
|
|
|
|
|
// mouse_interaction,
|
2025-03-18 13:29:26 -07:00
|
|
|
dnd_destination_for_target(
|
2025-01-24 14:09:17 -08:00
|
|
|
DropTarget::WorkspaceSidebarEntry(workspace.handle.clone(), output.clone()),
|
2025-02-10 12:02:36 -08:00
|
|
|
item,
|
2025-03-18 13:29:26 -07:00
|
|
|
Msg::DndToplevelDrop,
|
2024-10-18 13:13:53 -07:00
|
|
|
)
|
2023-11-16 19:25:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn workspaces_sidebar<'a>(
|
|
|
|
|
workspaces: impl Iterator<Item = &'a Workspace>,
|
|
|
|
|
output: &'a wl_output::WlOutput,
|
2023-11-17 14:56:37 -08:00
|
|
|
layout: WorkspaceLayout,
|
2025-02-20 14:28:56 -08:00
|
|
|
drop_target: Option<&backend::ExtWorkspaceHandleV1>,
|
2023-11-16 19:25:28 -08:00
|
|
|
) -> cosmic::Element<'a, Msg> {
|
2023-12-14 16:29:45 -08:00
|
|
|
let sidebar_entries = workspaces
|
2025-04-09 13:40:08 +02:00
|
|
|
.map(|w| workspace_sidebar_entry(w, output, layout, drop_target == Some(&w.handle)))
|
2023-11-17 14:56:37 -08:00
|
|
|
.collect();
|
2025-04-09 13:40:08 +02:00
|
|
|
let (axis, width, height) = match layout {
|
|
|
|
|
WorkspaceLayout::Vertical => (Axis::Vertical, Length::Shrink, Length::Fill),
|
|
|
|
|
WorkspaceLayout::Horizontal => (Axis::Horizontal, Length::Fill, Length::Shrink),
|
2023-11-17 14:56:37 -08:00
|
|
|
};
|
2023-12-14 16:46:49 -08:00
|
|
|
let sidebar_entries_container =
|
2024-12-23 01:54:51 +01:00
|
|
|
widget::container(crate::widgets::workspace_bar(sidebar_entries, axis)).padding(8.0);
|
|
|
|
|
|
2024-02-07 19:52:33 -08:00
|
|
|
widget::container(
|
|
|
|
|
widget::container(sidebar_entries_container)
|
|
|
|
|
.width(width)
|
|
|
|
|
.height(height)
|
2024-10-18 13:13:53 -07:00
|
|
|
.class(cosmic::theme::Container::custom(|theme| {
|
|
|
|
|
cosmic::iced::widget::container::Style {
|
2024-02-07 19:52:33 -08:00
|
|
|
text_color: Some(theme.cosmic().on_bg_color().into()),
|
|
|
|
|
icon_color: Some(theme.cosmic().on_bg_color().into()),
|
|
|
|
|
background: Some(iced::Color::from(theme.cosmic().background.base).into()),
|
|
|
|
|
border: Border {
|
2024-12-23 01:54:51 +01:00
|
|
|
radius: theme
|
|
|
|
|
.cosmic()
|
|
|
|
|
.radius_s()
|
|
|
|
|
.map(|x| if x < 4.0 { x } else { x + 8.0 })
|
|
|
|
|
.into(),
|
|
|
|
|
..Default::default()
|
2024-02-07 19:52:33 -08:00
|
|
|
},
|
|
|
|
|
shadow: Shadow::default(),
|
|
|
|
|
}
|
|
|
|
|
})),
|
|
|
|
|
)
|
2024-12-23 01:54:51 +01:00
|
|
|
.padding(8)
|
2023-12-14 16:46:49 -08:00
|
|
|
.into()
|
2023-11-16 19:25:28 -08:00
|
|
|
}
|
|
|
|
|
|
2024-10-18 13:13:53 -07:00
|
|
|
fn toplevel_preview(toplevel: &Toplevel, is_being_dragged: bool) -> cosmic::Element<'static, Msg> {
|
2024-12-23 01:54:51 +01:00
|
|
|
let cosmic::cosmic_theme::Spacing {
|
|
|
|
|
space_xxs, space_s, ..
|
|
|
|
|
} = cosmic::theme::active().cosmic().spacing;
|
|
|
|
|
|
|
|
|
|
let label = widget::text::body(toplevel.info.title.clone()).wrapping(Wrapping::None);
|
2023-12-18 19:41:30 -08:00
|
|
|
let label = if let Some(icon) = &toplevel.icon {
|
2024-12-23 01:54:51 +01:00
|
|
|
row![
|
|
|
|
|
widget::icon(widget::icon::from_path(icon.clone())).size(24),
|
|
|
|
|
label
|
|
|
|
|
]
|
|
|
|
|
.spacing(4)
|
2023-12-18 19:41:30 -08:00
|
|
|
} else {
|
|
|
|
|
row![label]
|
|
|
|
|
}
|
2024-12-23 01:54:51 +01:00
|
|
|
.align_y(iced::Alignment::Center);
|
2024-06-12 09:40:13 -07:00
|
|
|
let alpha = if is_being_dragged { 0.5 } else { 1.0 };
|
2024-04-25 14:17:43 -07:00
|
|
|
crate::widgets::toplevel_item(
|
2024-01-19 14:42:06 -08:00
|
|
|
vec![
|
2024-12-23 01:54:51 +01:00
|
|
|
row![
|
|
|
|
|
widget::button::custom(label)
|
|
|
|
|
.on_press(Msg::ActivateToplevel(toplevel.handle.clone()))
|
|
|
|
|
.class(cosmic::theme::Button::Icon)
|
|
|
|
|
.padding([space_xxs, space_s])
|
|
|
|
|
.apply(widget::container)
|
|
|
|
|
.class(cosmic::theme::Container::custom(|theme| {
|
|
|
|
|
cosmic::iced::widget::container::Style {
|
|
|
|
|
background: Some(
|
|
|
|
|
iced::Color::from(theme.cosmic().background.component.base).into(),
|
|
|
|
|
),
|
|
|
|
|
border: Border {
|
|
|
|
|
color: theme.cosmic().bg_divider().into(),
|
|
|
|
|
width: 1.0,
|
|
|
|
|
radius: theme.cosmic().radius_xl().into(),
|
|
|
|
|
},
|
|
|
|
|
..Default::default()
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
.apply(widget::container)
|
2025-04-09 13:40:08 +02:00
|
|
|
.width(Length::FillPortion(5)),
|
|
|
|
|
widget::horizontal_space().width(Length::Fixed(8.0)),
|
2024-12-23 01:54:51 +01:00
|
|
|
close_button(Msg::CloseToplevel(toplevel.handle.clone()))
|
|
|
|
|
]
|
|
|
|
|
.padding([0, 0, 4, 0])
|
|
|
|
|
.align_y(iced::Alignment::Center)
|
|
|
|
|
.into(),
|
2024-10-18 13:13:53 -07:00
|
|
|
widget::button::custom(capture_image(toplevel.img.as_ref(), alpha))
|
2024-01-19 14:42:06 -08:00
|
|
|
.selected(
|
|
|
|
|
toplevel
|
|
|
|
|
.info
|
|
|
|
|
.state
|
|
|
|
|
.contains(&zcosmic_toplevel_handle_v1::State::Activated),
|
|
|
|
|
)
|
2024-10-18 13:13:53 -07:00
|
|
|
.class(cosmic::theme::Button::Image)
|
2024-01-19 14:42:06 -08:00
|
|
|
.on_press(Msg::ActivateToplevel(toplevel.handle.clone()))
|
|
|
|
|
.into(),
|
|
|
|
|
],
|
|
|
|
|
Axis::Vertical,
|
|
|
|
|
)
|
|
|
|
|
//.spacing(4)
|
|
|
|
|
//.align_items(iced::Alignment::Center)
|
2025-04-09 13:40:08 +02:00
|
|
|
//.width(Length::Fill)
|
2023-11-16 19:25:28 -08:00
|
|
|
.into()
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-06 10:03:39 -08:00
|
|
|
fn toplevel_previews_entry<'a>(
|
|
|
|
|
toplevel: &'a Toplevel,
|
2024-04-19 12:05:35 -07:00
|
|
|
is_being_dragged: bool,
|
2023-12-06 10:03:39 -08:00
|
|
|
) -> cosmic::Element<'a, Msg> {
|
2024-04-19 12:05:35 -07:00
|
|
|
// Dragged window still takes up space until moved, but isn't rendered while drag surface is
|
|
|
|
|
// shown.
|
2024-06-12 09:40:13 -07:00
|
|
|
let preview = crate::widgets::visibility_wrapper(
|
|
|
|
|
toplevel_preview(toplevel, is_being_dragged),
|
|
|
|
|
!is_being_dragged,
|
|
|
|
|
);
|
2024-10-18 13:13:53 -07:00
|
|
|
let toplevel2 = toplevel.clone();
|
|
|
|
|
cosmic::widget::dnd_source::<_, DragToplevel>(preview)
|
|
|
|
|
.drag_threshold(5.)
|
|
|
|
|
.drag_content(|| DragToplevel {})
|
|
|
|
|
// XXX State?
|
|
|
|
|
.drag_icon(move |offset| {
|
|
|
|
|
(
|
|
|
|
|
toplevel_preview(&toplevel2, true).map(|_| ()),
|
|
|
|
|
cosmic::iced_core::widget::tree::State::None,
|
|
|
|
|
-offset,
|
2023-12-06 10:03:39 -08:00
|
|
|
)
|
|
|
|
|
})
|
2024-10-18 13:13:53 -07:00
|
|
|
.on_start(Some(Msg::StartDrag(
|
|
|
|
|
//size,
|
2025-01-24 14:41:36 -08:00
|
|
|
DragSurface::Toplevel(toplevel.handle.clone()),
|
2024-10-18 13:13:53 -07:00
|
|
|
)))
|
|
|
|
|
.on_finish(Some(Msg::SourceFinished))
|
|
|
|
|
.on_cancel(Some(Msg::SourceFinished))
|
2023-12-06 10:03:39 -08:00
|
|
|
.into()
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-16 19:25:28 -08:00
|
|
|
fn toplevel_previews<'a>(
|
|
|
|
|
toplevels: impl Iterator<Item = &'a Toplevel>,
|
2023-12-18 19:59:09 -08:00
|
|
|
layout: WorkspaceLayout,
|
2025-02-10 14:33:51 -08:00
|
|
|
drag_toplevel: Option<&'a backend::ExtForeignToplevelHandleV1>,
|
2023-11-16 19:25:28 -08:00
|
|
|
) -> cosmic::Element<'a, Msg> {
|
2023-12-18 19:59:09 -08:00
|
|
|
let (width, height) = match layout {
|
2025-04-09 13:40:08 +02:00
|
|
|
WorkspaceLayout::Vertical => (Length::FillPortion(4), Length::Fill),
|
|
|
|
|
WorkspaceLayout::Horizontal => (Length::Fill, Length::FillPortion(4)),
|
2023-12-18 19:59:09 -08:00
|
|
|
};
|
2024-01-19 14:42:06 -08:00
|
|
|
let entries = toplevels
|
2025-01-24 14:41:36 -08:00
|
|
|
.map(|t| toplevel_previews_entry(t, drag_toplevel == Some(&t.handle)))
|
2024-01-19 14:42:06 -08:00
|
|
|
.collect();
|
2024-01-19 15:32:54 -08:00
|
|
|
//row(entries)
|
2025-01-23 20:02:16 -08:00
|
|
|
widget::mouse_area(
|
|
|
|
|
widget::container(crate::widgets::toplevels(entries))
|
|
|
|
|
.align_x(iced::alignment::Horizontal::Center)
|
|
|
|
|
.width(width)
|
|
|
|
|
.height(height)
|
|
|
|
|
//.spacing(16)
|
|
|
|
|
.padding(12),
|
|
|
|
|
)
|
|
|
|
|
.on_press(Msg::Close)
|
|
|
|
|
//.align_items(iced::Alignment::Center)
|
|
|
|
|
.into()
|
2023-11-16 19:25:28 -08:00
|
|
|
}
|
2023-11-16 19:38:42 -08:00
|
|
|
|
2024-10-18 13:13:53 -07:00
|
|
|
fn capture_image(image: Option<&CaptureImage>, alpha: f32) -> cosmic::Element<'static, Msg> {
|
2023-11-16 19:38:42 -08:00
|
|
|
if let Some(image) = image {
|
2024-04-01 15:13:51 -07:00
|
|
|
#[cfg(feature = "no-subsurfaces")]
|
|
|
|
|
{
|
2025-01-15 10:18:50 -08:00
|
|
|
// TODO alpha, transform
|
2024-04-01 15:13:51 -07:00
|
|
|
widget::Image::new(image.image.clone()).into()
|
|
|
|
|
}
|
|
|
|
|
#[cfg(not(feature = "no-subsurfaces"))]
|
|
|
|
|
{
|
2025-01-15 10:18:50 -08:00
|
|
|
Subsurface::new(image.wl_buffer.clone())
|
|
|
|
|
.alpha(alpha)
|
|
|
|
|
.transform(image.transform)
|
|
|
|
|
.into()
|
2024-04-01 15:13:51 -07:00
|
|
|
}
|
2023-11-16 19:38:42 -08:00
|
|
|
} else {
|
2024-10-18 13:13:53 -07:00
|
|
|
widget::Image::new(widget::image::Handle::from_rgba(1, 1, vec![0, 0, 0, 255])).into()
|
2023-11-16 19:38:42 -08:00
|
|
|
}
|
|
|
|
|
}
|