diff --git a/src/main.rs b/src/main.rs index 87bc263..cfd956c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -659,28 +659,8 @@ impl Application for App { } if let Some((drag_id, drag_surface, size)) = &self.drag_surface { if drag_id == &id { - match drag_surface { - DragSurface::Workspace { handle, output } => { - if let Some(workspace) = - self.workspaces.iter().find(|x| &x.handle == handle) - { - let item = view::workspace_item(workspace, output, false); - return widget::container(item) - .height(iced::Length::Fixed(size.height)) - .width(iced::Length::Fixed(size.width)) - .into(); - } - } - DragSurface::Toplevel { handle, .. } => { - if let Some(toplevel) = self.toplevels.iter().find(|x| &x.handle == handle) - { - let item = view::toplevel_preview(toplevel, true); - return widget::container(item) - .height(iced::Length::Fixed(size.height)) - .width(iced::Length::Fixed(size.width)) - .into(); - } - } + if let Some(element) = view::drag_surface(self, drag_surface, *size) { + return element; } } } diff --git a/src/view/mod.rs b/src/view/mod.rs index d8d071b..37ab618 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -8,7 +8,7 @@ use cosmic::{ self, advanced::layout::flex::Axis, widget::{column, row}, - Border, + Border, Size, }, iced_core::Shadow, iced_sctk::subsurface_widget::Subsurface, @@ -83,6 +83,38 @@ pub(crate) fn layer_surface<'a>( crate::widgets::image_bg(container, bg).into() } +pub(crate) fn drag_surface<'a>( + app: &'a App, + drag_surface: &DragSurface, + size: Size, +) -> Option> { + match drag_surface { + DragSurface::Workspace { handle, output } => { + if let Some(workspace) = app.workspaces.iter().find(|x| &x.handle == handle) { + let item = workspace_item(workspace, output, false); + return Some( + widget::container(item) + .height(iced::Length::Fixed(size.height)) + .width(iced::Length::Fixed(size.width)) + .into(), + ); + } + } + DragSurface::Toplevel { handle, .. } => { + if let Some(toplevel) = app.toplevels.iter().find(|x| &x.handle == handle) { + let item = toplevel_preview(toplevel, true); + return Some( + widget::container(item) + .height(iced::Length::Fixed(size.height)) + .width(iced::Length::Fixed(size.width)) + .into(), + ); + } + } + } + None +} + fn close_button(on_press: Msg) -> cosmic::Element<'static, Msg> { widget::container( widget::button(widget::icon::from_name("window-close-symbolic").size(16)) @@ -112,7 +144,7 @@ fn workspace_item_appearance( appearance } -pub(crate) fn workspace_item<'a>( +fn workspace_item<'a>( workspace: &'a Workspace, output: &wl_output::WlOutput, is_drop_target: bool, @@ -255,10 +287,7 @@ fn workspaces_sidebar<'a>( .into() } -pub(crate) fn toplevel_preview( - toplevel: &Toplevel, - is_being_dragged: bool, -) -> cosmic::Element { +fn toplevel_preview(toplevel: &Toplevel, is_being_dragged: bool) -> cosmic::Element { let label = widget::text(&toplevel.info.title); let label = if let Some(icon) = &toplevel.icon { row![widget::icon(widget::icon::from_path(icon.clone())), label].spacing(4)