-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
2,075 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))), | ||
} | ||
} | ||
} |
Oops, something went wrong.