style(clipboard): fix formatting
This commit is contained in:
parent
9e3742f273
commit
9202c1189c
|
@ -19,7 +19,10 @@
|
|||
|
||||
mod ffi;
|
||||
|
||||
use std::{ffi::{CStr, CString}, path::PathBuf};
|
||||
use std::{
|
||||
ffi::{CStr, CString},
|
||||
path::PathBuf,
|
||||
};
|
||||
|
||||
use crate::Clipboard;
|
||||
use anyhow::Result;
|
||||
|
|
|
@ -81,15 +81,17 @@ pub fn get_clipboard(_: ClipboardOptions) -> Result<Box<dyn Clipboard>> {
|
|||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "wayland")]
|
||||
pub fn get_clipboard(options: ClipboardOptions) -> Result<Box<dyn Clipboard>> {
|
||||
// TODO: On some Wayland compositors (currently sway), the "wlr-data-control" protocol
|
||||
// TODO: On some Wayland compositors (currently sway), the "wlr-data-control" protocol
|
||||
// could enable the use of a much more efficient implementation relying on the "wl-clipboard-rs" crate.
|
||||
// Useful links: https://github.com/YaLTeR/wl-clipboard-rs/issues/8
|
||||
//
|
||||
// We could even decide the correct implementation at runtime by checking if the
|
||||
// We could even decide the correct implementation at runtime by checking if the
|
||||
// required protocol is available, if so use the efficient implementation
|
||||
// instead of the fallback one, which calls the wl-copy and wl-paste binaries, and is thus
|
||||
// less efficient
|
||||
// less efficient
|
||||
|
||||
info!("using WaylandFallbackClipboard");
|
||||
Ok(Box::new(wayland::fallback::WaylandFallbackClipboard::new(options)?))
|
||||
}
|
||||
Ok(Box::new(wayland::fallback::WaylandFallbackClipboard::new(
|
||||
options,
|
||||
)?))
|
||||
}
|
||||
|
|
|
@ -122,21 +122,31 @@ impl Clipboard for WaylandFallbackClipboard {
|
|||
let mut data = Vec::new();
|
||||
file.read_to_end(&mut data)?;
|
||||
|
||||
self.invoke_command_with_timeout(&mut Command::new("wl-copy").arg("--type").arg("image/png"), &data, "wl-copy")
|
||||
self.invoke_command_with_timeout(
|
||||
&mut Command::new("wl-copy").arg("--type").arg("image/png"),
|
||||
&data,
|
||||
"wl-copy",
|
||||
)
|
||||
}
|
||||
|
||||
fn set_html(&self, html: &str, _fallback_text: Option<&str>) -> anyhow::Result<()> {
|
||||
self.invoke_command_with_timeout(&mut Command::new("wl-copy").arg("--type").arg("text/html"), html.as_bytes(), "wl-copy")
|
||||
self.invoke_command_with_timeout(
|
||||
&mut Command::new("wl-copy").arg("--type").arg("text/html"),
|
||||
html.as_bytes(),
|
||||
"wl-copy",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl WaylandFallbackClipboard {
|
||||
fn invoke_command_with_timeout(&self, command: &mut Command, data: &[u8], name: &str) -> Result<()> {
|
||||
fn invoke_command_with_timeout(
|
||||
&self,
|
||||
command: &mut Command,
|
||||
data: &[u8],
|
||||
name: &str,
|
||||
) -> Result<()> {
|
||||
let timeout = std::time::Duration::from_millis(self.command_timeout);
|
||||
match command
|
||||
.stdin(Stdio::piped())
|
||||
.spawn()
|
||||
{
|
||||
match command.stdin(Stdio::piped()).spawn() {
|
||||
Ok(mut child) => {
|
||||
if let Some(stdin) = child.stdin.as_mut() {
|
||||
stdin.write_all(data)?;
|
||||
|
|
|
@ -17,4 +17,4 @@
|
|||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
pub(crate) mod fallback;
|
||||
pub(crate) mod fallback;
|
||||
|
|
|
@ -17,4 +17,4 @@
|
|||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
pub(crate) mod native;
|
||||
pub(crate) mod native;
|
||||
|
|
|
@ -17,7 +17,11 @@
|
|||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use std::{ffi::{CStr, CString}, io::Read, path::PathBuf};
|
||||
use std::{
|
||||
ffi::{CStr, CString},
|
||||
io::Read,
|
||||
path::PathBuf,
|
||||
};
|
||||
|
||||
use crate::Clipboard;
|
||||
use anyhow::Result;
|
||||
|
@ -67,9 +71,7 @@ impl Clipboard for X11NativeClipboard {
|
|||
let mut data = Vec::new();
|
||||
file.read_to_end(&mut data)?;
|
||||
|
||||
let native_result = unsafe {
|
||||
ffi::clipboard_x11_set_image(data.as_ptr(), data.len() as i32)
|
||||
};
|
||||
let native_result = unsafe { ffi::clipboard_x11_set_image(data.as_ptr(), data.len() as i32) };
|
||||
|
||||
if native_result > 0 {
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue
Block a user