mirror of
https://github.com/icewind1991/clipboard-sync
synced 2026-06-03 10:24:06 +02:00
better wayland detection
This commit is contained in:
parent
9dedd0af6a
commit
0e92b41ab4
2 changed files with 15 additions and 8 deletions
|
|
@ -56,7 +56,7 @@ fn main() {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
const HUNDRED_MS: Duration = Duration::from_millis(100);
|
||||
const HUNDRED_MS: Duration = Duration::from_millis(500);
|
||||
|
||||
fn clipboard_thread(
|
||||
session: String,
|
||||
|
|
@ -66,11 +66,6 @@ fn clipboard_thread(
|
|||
thread::spawn(move || {
|
||||
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);
|
||||
|
||||
// we need to do the listen after returning the closure for the websocket
|
||||
|
|
@ -83,7 +78,13 @@ fn clipboard_thread(
|
|||
);
|
||||
loop {
|
||||
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();
|
||||
if *clip != new_clipboard && new_clipboard != "" {
|
||||
send_to_server(
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use std::io::Read;
|
|||
use wl_clipboard_rs::{
|
||||
copy::{self, copy, Options, Source},
|
||||
paste::{get_contents, ClipboardType, MimeType, Seat},
|
||||
utils::{is_primary_selection_supported, PrimarySelectionCheckError},
|
||||
};
|
||||
|
||||
pub enum ClipboardHandler {
|
||||
|
|
@ -17,7 +18,12 @@ pub enum ClipboardHandler {
|
|||
impl ClipboardHandler {
|
||||
#[cfg(all(unix, not(any(target_os = "macos", target_os = "android"))))]
|
||||
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")))))]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue