1
0
Fork 0
mirror of https://github.com/icewind1991/clipboard-sync synced 2026-06-03 18:34:07 +02:00

better wayland detection

This commit is contained in:
Robin Appelman 2020-03-17 19:05:41 +01:00
commit 0e92b41ab4
2 changed files with 15 additions and 8 deletions

View file

@ -56,7 +56,7 @@ fn main() {
.unwrap(); .unwrap();
} }
const HUNDRED_MS: Duration = Duration::from_millis(100); const HUNDRED_MS: Duration = Duration::from_millis(500);
fn clipboard_thread( fn clipboard_thread(
session: String, session: String,
@ -66,11 +66,6 @@ fn clipboard_thread(
thread::spawn(move || { thread::spawn(move || {
let mut ctx: ClipboardHandler = ClipboardHandler::new().unwrap(); let mut ctx: ClipboardHandler = ClipboardHandler::new().unwrap();
{
let mut clip = current_clipboard.lock().unwrap();
*clip = ctx.get_contents().unwrap_or_default();
}
thread::sleep(HUNDRED_MS); thread::sleep(HUNDRED_MS);
// we need to do the listen after returning the closure for the websocket // we need to do the listen after returning the closure for the websocket
@ -83,7 +78,13 @@ fn clipboard_thread(
); );
loop { loop {
thread::sleep(HUNDRED_MS); thread::sleep(HUNDRED_MS);
let new_clipboard = ctx.get_contents().unwrap_or_default(); let new_clipboard = match ctx.get_contents() {
Ok(content) => content,
Err(e) => {
eprintln!("{}", e);
continue;
}
};
let mut clip = current_clipboard.lock().unwrap(); let mut clip = current_clipboard.lock().unwrap();
if *clip != new_clipboard && new_clipboard != "" { if *clip != new_clipboard && new_clipboard != "" {
send_to_server( send_to_server(

View file

@ -7,6 +7,7 @@ use std::io::Read;
use wl_clipboard_rs::{ use wl_clipboard_rs::{
copy::{self, copy, Options, Source}, copy::{self, copy, Options, Source},
paste::{get_contents, ClipboardType, MimeType, Seat}, paste::{get_contents, ClipboardType, MimeType, Seat},
utils::{is_primary_selection_supported, PrimarySelectionCheckError},
}; };
pub enum ClipboardHandler { pub enum ClipboardHandler {
@ -17,7 +18,12 @@ pub enum ClipboardHandler {
impl ClipboardHandler { impl ClipboardHandler {
#[cfg(all(unix, not(any(target_os = "macos", target_os = "android"))))] #[cfg(all(unix, not(any(target_os = "macos", target_os = "android"))))]
fn is_wayland() -> bool { fn is_wayland() -> bool {
get_contents(ClipboardType::Regular, Seat::Unspecified, MimeType::Text).is_ok() match is_primary_selection_supported() {
Ok(_) => true,
Err(PrimarySelectionCheckError::NoSeats) => true,
Err(PrimarySelectionCheckError::MissingProtocol { .. }) => true,
Err(_) => false,
}
} }
#[cfg(not(all(unix, not(any(target_os = "macos", target_os = "android")))))] #[cfg(not(all(unix, not(any(target_os = "macos", target_os = "android")))))]