patch: linux set clipboard

Signed-off-by: 蔡略 <cailue@bupt.edu.cn>
This commit is contained in:
蔡略 2023-09-09 09:47:27 +08:00
parent af131cd1e5
commit e5bcfeaad5
2 changed files with 27 additions and 2 deletions

View File

@ -555,6 +555,16 @@ impl FuseServer {
return;
}
// get files and directory path right in root of FUSE fs
pub fn list_root(&self) -> Vec<PathBuf> {
let files = self.files.read();
let mut paths = Vec::new();
for file in files.iter().filter(|f| f.parent == Some(FUSE_ROOT_ID)) {
paths.push(PathBuf::from(&file.name));
}
paths
}
/// gc filesystem
fn gc_files(&self) {
{

View File

@ -362,6 +362,13 @@ impl ClipboardContext {
})
}
/// set clipboard data from file list
pub fn set_clipboard(&self, paths: &[PathBuf]) -> Result<(), CliprdrError> {
let prefix = self.fuse_mount_point.clone();
let paths: Vec<PathBuf> = paths.iter().cloned().map(|p| prefix.join(p)).collect();
self.clipboard.set_file_list(&paths)
}
pub fn listen_clipboard(&self) -> Result<(), CliprdrError> {
while let Ok(v) = self.clipboard.wait_file_list() {
let filtered: Vec<_> = v
@ -663,8 +670,16 @@ impl ClipboardContext {
}
Ok(())
}
ClipboardFile::FormatDataResponse { .. }
| ClipboardFile::FileContentsResponse { .. } => {
ClipboardFile::FormatDataResponse { .. } => {
// we don't know its corresponding request, no resend can be performed
self.fuse_server.recv(conn_id, msg);
let paths = self.fuse_server.list_root();
self.set_clipboard(&paths)?;
Ok(())
}
ClipboardFile::FileContentsResponse { .. } => {
// we don't know its corresponding request, no resend can be performed
self.fuse_server.recv(conn_id, msg);
Ok(())
}