Skip to content

Commit

Permalink
Allow dropping window onto toplevel list area
Browse files Browse the repository at this point in the history
Fixes #53.
  • Loading branch information
ids1024 committed Jan 24, 2025
1 parent 6838bd6 commit 88b35e3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/dnd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ impl TryFrom<(Vec<u8>, std::string::String)> for DragToplevel {
#[repr(u8)]
pub enum DropTarget {
WorkspaceSidebarEntry(ZcosmicWorkspaceHandleV1, wl_output::WlOutput),
OutputToplevels(ZcosmicWorkspaceHandleV1, wl_output::WlOutput),
}

impl DropTarget {
Expand All @@ -76,6 +77,10 @@ impl DropTarget {
let id = workspace.id().protocol_id();
(u64::from(discriminant) << 32) | u64::from(id)
}
Self::OutputToplevels(_workspace, output) => {
let id = output.id().protocol_id();
(u64::from(discriminant) << 32) | u64::from(id)
}
}
}
}
20 changes: 12 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,18 @@ impl Application for App {
}
Msg::DndWorkspaceDrop(_toplevel) => {
if let Some((DragSurface::Toplevel(handle), _)) = &self.drag_surface {
if let Some(DropTarget::WorkspaceSidebarEntry(workspace, output)) =
self.drop_target.take()
{
self.send_wayland_cmd(backend::Cmd::MoveToplevelToWorkspace(
handle.clone(),
workspace,
output,
));
match self.drop_target.take() {
Some(
DropTarget::WorkspaceSidebarEntry(workspace, output)
| DropTarget::OutputToplevels(workspace, output),
) => {
self.send_wayland_cmd(backend::Cmd::MoveToplevelToWorkspace(
handle.clone(),
workspace,
output,
));
}
None => {}
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ pub(crate) fn layer_surface<'a>(
layout,
drag_toplevel,
);
// TODO multiple active workspaces? Not currently supported by cosmic.
let first_active_workspace = app
.workspaces
.iter()
.find(|i| i.outputs.contains(&surface.output) && i.is_active);
let toplevels = if let Some(workspace) = first_active_workspace {
toplevel_dnd_destination(
DropTarget::OutputToplevels(workspace.handle.clone(), surface.output.clone()),
toplevels,
)
} else {
// Shouldn't happen, but no drag destination if no active workspace found for output
cosmic::Element::from(toplevels)
};
let container = match layout {
WorkspaceLayout::Vertical => widget::layer_container(
row![sidebar, toplevels]
Expand Down

0 comments on commit 88b35e3

Please sign in to comment.