Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dnut committed Apr 14, 2022
1 parent 7729092 commit ca31566
Show file tree
Hide file tree
Showing 9 changed files with 2,075 additions and 0 deletions.
1,548 changes: 1,548 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "wayland-clipboard-sync"
version = "0.1.0"
edition = "2021"


[features]
backtrace = []

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
wayland-client = "0.29.4"
# wl-clipboard-rs = { path = "../wl-clipboard-rs" } #"0.6.0"
# wl-clipboard-rs = "0.4.1"
wl-clipboard-rs = { git = "https://github.com/dnut/wl-clipboard-rs", branch = "reap-zombie-cat" }
cli-clipboard = "0.2.0"
arboard = "2.0.0"
x11-clipboard = "0.5.3"
terminal-clipboard = "0.3.1"
nix = "0.23.1"
anyhow = "1.0.44"
thiserror = "1.0"
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Wayland Clipboard Sync

Synchronizes the clipboard across multiple wayland instances running on the same machine.
18 changes: 18 additions & 0 deletions daemon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

root=/home/drew/mine/code/wayland-clipboard-sync
name=clipsync

tmux new -s "$name" "
bash --init-file <(echo '
source ~/.bashrc
cd /home/drew/mine/code/wayland-clipboard-sync
./run.sh
')
" || (
tmux send-keys -t "$name" \
'C-c' Enter '# ...joined existing session' \
Enter '# attempted to kill ./run.sh, now restarting...' \
Enter "$root/run.sh" Enter
tmux attach -t "$name"
)
6 changes: 6 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cargo build \
&& while true; do target/debug/wayland-clipboard-sync; done \
&& (echo; echo service exited)
|| (echo; echo service failed, exiting...)
64 changes: 64 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use std::error::Error as StdError;
use std::fmt::{Debug, Display};

pub type MyResult<T> = Result<T, MyError>;

#[derive(thiserror::Error, Debug)]
pub enum MyError {
#[error("{0}")]
Generic(#[from] Box<dyn StdError>),

#[error("failed to get wlr clipboard: {0}")]
WlcrsPaste(#[from] wl_clipboard_rs::paste::Error),

#[error("failed to set wlr clipboard: {0}")]
WlcrsCopy(#[from] wl_clipboard_rs::copy::Error),

#[error("{0}")]
Io(#[from] std::io::Error),

#[error("{0}")]
TerminalClipboard(#[from] StandardizedError<terminal_clipboard::ClipboardError>),

#[error("{0}")]
Arboard(#[from] arboard::Error),
}

#[derive(Debug)]
pub struct StandardizedError<E: Debug> {
pub inner: E,
}

impl<E: Debug> Display for StandardizedError<E> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.inner.fmt(f)
}
}

impl<E: Debug> StdError for StandardizedError<E> {}

pub trait Standardize<T, E: Sized + Debug>: Sized {
fn standardize(self) -> Result<T, StandardizedError<E>>;
}

impl<T, E: Sized + Debug> Standardize<T, E> for Result<T, E> {
fn standardize(self) -> Result<T, StandardizedError<E>> {
match self {
Ok(ok) => Ok(ok),
Err(err) => Err(StandardizedError { inner: err }),
}
}
}

pub trait Generify<T, E: 'static + StdError> {
fn generify(self) -> Result<T, MyError>;
}

impl<T, E: 'static + StdError> Generify<T, E> for Result<T, E> {
fn generify(self) -> Result<T, MyError> {
match self {
Ok(ok) => Ok(ok),
Err(err) => Err(MyError::Generic(Box::new(err))),
}
}
}
Loading

0 comments on commit ca31566

Please sign in to comment.