Fix drag and drop; send command to compositor if supported

This commit is contained in:
Ian Douglas Scott 2023-12-11 14:06:41 -08:00
parent c1e74747f3
commit 89021e3b8b
4 changed files with 634 additions and 45 deletions

653
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -11,8 +11,11 @@ cosmic-comp-config = { git = "https://github.com/pop-os/cosmic-comp" }
env_logger = "0.10.0"
futures-channel = "0.3.25"
gbm = "0.14.0"
libcosmic = { git = "https://github.com/pop-os/libcosmic", default-features = false, features = ["tokio", "wayland", "single-instance"] }
cosmic-config = { git = "https://github.com/pop-os/libcosmic" }
#libcosmic = { git = "https://github.com/pop-os/libcosmic", default-features = false, features = ["tokio", "wayland", "single-instance"] }
#cosmic-config = { git = "https://github.com/pop-os/libcosmic" }
libcosmic = { path = "../libcosmic", default-features = false, features = ["tokio", "wayland", "single-instance"] }
cosmic-config = { path = "../libcosmic/cosmic-config" }
memmap2 = "0.9.0"
tokio = "1.23.0"
wayland-protocols = "0.31.0"

View file

@ -114,6 +114,7 @@ enum Msg {
DndWorkspaceLeave,
DndWorkspaceDrop,
DndWorkspaceData(String, Vec<u8>),
SourceFinished,
}
#[derive(Debug)]
@ -339,6 +340,7 @@ impl Application for App {
fn update(&mut self, message: Msg) -> Command<cosmic::app::Message<Msg>> {
match message {
Msg::SourceFinished => {}
Msg::WaylandEvent(evt) => match evt {
WaylandEvent::Output(evt, output) => {
// TODO: Less hacky way to get connection from iced-sctk
@ -532,8 +534,9 @@ impl Application for App {
}
}
Msg::DndWorkspaceLeave => {
self.drop_target = None;
return accept_mime_type(None);
// XXX Doesn't work since leave for a widget may come after enter for another
// self.drop_target = None;
// return accept_mime_type(None);
}
Msg::DndWorkspaceDrop => {
return request_dnd_data(TOPLEVEL_MIME.to_string());
@ -548,7 +551,15 @@ impl Application for App {
if let Some(toplevel) = self.toplevels.iter().find(|t| &t.handle == handle)
{
if let Some(drop_target) = &self.drop_target {
dbg!(drop_target, toplevel);
if let Some(toplevel_manager) = self.toplevel_manager.as_ref() {
if toplevel_manager.version() >= 2 {
toplevel_manager.move_to_workspace(
handle,
&drop_target.0,
&drop_target.1,
);
}
}
}
}
}

View file

@ -166,6 +166,8 @@ fn toplevel_previews_entry<'a>(
},
)
})
.on_finished(Msg::SourceFinished)
.on_cancelled(Msg::SourceFinished)
.into()
}