UI code for supporting workspace drags
Not used yet.
This commit is contained in:
parent
9b12e76765
commit
ca5db9cc8e
3 changed files with 88 additions and 18 deletions
41
src/dnd.rs
41
src/dnd.rs
|
|
@ -10,7 +10,6 @@ use crate::backend::{ZcosmicToplevelHandleV1, ZcosmicWorkspaceHandleV1};
|
|||
|
||||
// Include `pid` in mime. Want to drag between our surfaces, but not another
|
||||
// process, if we use Wayland object ids.
|
||||
#[allow(dead_code)]
|
||||
static WORKSPACE_MIME: LazyLock<String> =
|
||||
LazyLock::new(|| format!("text/x.cosmic-workspace-id-{}", std::process::id()));
|
||||
|
||||
|
|
@ -59,11 +58,47 @@ impl TryFrom<(Vec<u8>, std::string::String)> for DragToplevel {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DragWorkspace {}
|
||||
|
||||
impl AsMimeTypes for DragWorkspace {
|
||||
fn available(&self) -> Cow<'static, [String]> {
|
||||
vec![WORKSPACE_MIME.clone()].into()
|
||||
}
|
||||
|
||||
fn as_bytes(&self, mime_type: &str) -> Option<Cow<'static, [u8]>> {
|
||||
if mime_type == *WORKSPACE_MIME {
|
||||
Some(Vec::new().into())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl cosmic::iced::clipboard::mime::AllowedMimeTypes for DragWorkspace {
|
||||
fn allowed() -> Cow<'static, [String]> {
|
||||
vec![WORKSPACE_MIME.clone()].into()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<(Vec<u8>, std::string::String)> for DragWorkspace {
|
||||
type Error = ();
|
||||
fn try_from((_bytes, mime_type): (Vec<u8>, String)) -> Result<Self, ()> {
|
||||
if mime_type == *WORKSPACE_MIME {
|
||||
Ok(Self {})
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[repr(u8)]
|
||||
pub enum DropTarget {
|
||||
WorkspaceSidebarEntry(ZcosmicWorkspaceHandleV1, wl_output::WlOutput),
|
||||
OutputToplevels(ZcosmicWorkspaceHandleV1, wl_output::WlOutput),
|
||||
#[allow(dead_code)]
|
||||
WorkspacesBar(wl_output::WlOutput),
|
||||
}
|
||||
|
||||
impl DropTarget {
|
||||
|
|
@ -81,6 +116,10 @@ impl DropTarget {
|
|||
let id = output.id().protocol_id();
|
||||
(u64::from(discriminant) << 32) | u64::from(id)
|
||||
}
|
||||
Self::WorkspacesBar(output) => {
|
||||
let id = output.id().protocol_id();
|
||||
(u64::from(discriminant) << 32) | u64::from(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue