refactor: avoid breaking changes and update smithay-clipboard

This commit is contained in:
Ashley Wulber 2024-03-14 13:16:13 -04:00
parent 6c41143f5c
commit 886f430414
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
4 changed files with 37 additions and 37 deletions

View file

@ -67,51 +67,51 @@ impl Clipboard<platform::Clipboard> {
} }
pub fn read(&self) -> Result<String, Box<dyn Error>> { pub fn read(&self) -> Result<String, Box<dyn Error>> {
self.raw.read_text() self.raw.read()
} }
pub fn write(&mut self, contents: String) -> Result<(), Box<dyn Error>> { pub fn write(&mut self, contents: String) -> Result<(), Box<dyn Error>> {
self.raw.write_text(contents) self.raw.write(contents)
} }
} }
impl<C: ClipboardProvider> Clipboard<C> { impl<C: ClipboardProvider> Clipboard<C> {
pub fn read_primary(&self) -> Option<Result<String, Box<dyn Error>>> { pub fn read_primary(&self) -> Option<Result<String, Box<dyn Error>>> {
self.raw.read_primary_text() self.raw.read_primary()
} }
pub fn write_primary( pub fn write_primary(
&mut self, &mut self,
contents: String, contents: String,
) -> Option<Result<(), Box<dyn Error>>> { ) -> Option<Result<(), Box<dyn Error>>> {
self.raw.write_primary_text(contents) self.raw.write_primary(contents)
} }
} }
pub trait ClipboardProvider { pub trait ClipboardProvider {
fn read_text(&self) -> Result<String, Box<dyn Error>>; fn read(&self) -> Result<String, Box<dyn Error>>;
fn write_text(&mut self, contents: String) -> Result<(), Box<dyn Error>>; fn write(&mut self, contents: String) -> Result<(), Box<dyn Error>>;
fn read_primary_text(&self) -> Option<Result<String, Box<dyn Error>>> { fn read_primary(&self) -> Option<Result<String, Box<dyn Error>>> {
None None
} }
fn write_primary_text( fn write_primary(
&mut self, &mut self,
_contents: String, _contents: String,
) -> Option<Result<(), Box<dyn Error>>> { ) -> Option<Result<(), Box<dyn Error>>> {
None None
} }
fn read<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>> fn read_data<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
where where
ClipboardLoadData<T>: platform::InnerAllowedMimeTypes, ClipboardLoadData<T>: platform::InnerAllowedMimeTypes,
{ {
None None
} }
fn write<T: Send + Sync + 'static>( fn write_data<T: Send + Sync + 'static>(
&mut self, &mut self,
_contents: ClipboardStoreData<T>, _contents: ClipboardStoreData<T>,
) -> Option<Result<(), Box<dyn Error>>> ) -> Option<Result<(), Box<dyn Error>>>
@ -121,14 +121,14 @@ pub trait ClipboardProvider {
None None
} }
fn read_primary<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>> fn read_primary_data<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
where where
ClipboardLoadData<T>: platform::InnerAllowedMimeTypes, ClipboardLoadData<T>: platform::InnerAllowedMimeTypes,
{ {
None None
} }
fn write_primary<T: Send + Sync + 'static>( fn write_primary_data<T: Send + Sync + 'static>(
&mut self, &mut self,
_contents: ClipboardStoreData<T>, _contents: ClipboardStoreData<T>,
) -> Option<Result<(), Box<dyn Error>>> ) -> Option<Result<(), Box<dyn Error>>>

View file

@ -19,53 +19,53 @@ pub enum Clipboard {
} }
impl ClipboardProvider for Clipboard { impl ClipboardProvider for Clipboard {
fn read_text(&self) -> Result<String, Box<dyn Error>> { fn read(&self) -> Result<String, Box<dyn Error>> {
match self { match self {
Clipboard::Wayland(c) => c.read_text(), Clipboard::Wayland(c) => c.read(),
Clipboard::X11(c) => c.read().map_err(Box::from), Clipboard::X11(c) => c.read().map_err(Box::from),
} }
} }
fn write_text(&mut self, contents: String) -> Result<(), Box<dyn Error>> { fn write(&mut self, contents: String) -> Result<(), Box<dyn Error>> {
match self { match self {
Clipboard::Wayland(c) => c.write_text(contents), Clipboard::Wayland(c) => c.write(contents),
Clipboard::X11(c) => c.write(contents).map_err(Box::from), Clipboard::X11(c) => c.write(contents).map_err(Box::from),
} }
} }
fn read_primary_text(&self) -> Option<Result<String, Box<dyn Error>>> { fn read_primary(&self) -> Option<Result<String, Box<dyn Error>>> {
match self { match self {
Clipboard::Wayland(c) => Some(c.read_primary_text()), Clipboard::Wayland(c) => Some(c.read_primary()),
Clipboard::X11(c) => Some(c.read_primary().map_err(Box::from)), Clipboard::X11(c) => Some(c.read_primary().map_err(Box::from)),
} }
} }
fn write_primary_text( fn write_primary(
&mut self, &mut self,
contents: String, contents: String,
) -> Option<Result<(), Box<dyn Error>>> { ) -> Option<Result<(), Box<dyn Error>>> {
match self { match self {
Clipboard::Wayland(c) => Some(c.write_primary_text(contents)), Clipboard::Wayland(c) => Some(c.write_primary(contents)),
Clipboard::X11(c) => { Clipboard::X11(c) => {
Some(c.write_primary(contents).map_err(Box::from)) Some(c.write_primary(contents).map_err(Box::from))
} }
} }
} }
fn read<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>> fn read_data<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
where where
ClipboardLoadData<T>: InnerAllowedMimeTypes, ClipboardLoadData<T>: InnerAllowedMimeTypes,
{ {
match self { match self {
Clipboard::Wayland(c) => { Clipboard::Wayland(c) => {
let ret = c.read::<ClipboardLoadData<T>>(); let ret = c.read_data::<ClipboardLoadData<T>>();
Some(ret.map(|ret| ret.0)) Some(ret.map(|ret| ret.0))
} }
Clipboard::X11(_) => None, Clipboard::X11(_) => None,
} }
} }
fn write<T: Send + Sync + 'static>( fn write_data<T: Send + Sync + 'static>(
&mut self, &mut self,
contents: ClipboardStoreData<T>, contents: ClipboardStoreData<T>,
) -> Option<Result<(), Box<dyn Error>>> ) -> Option<Result<(), Box<dyn Error>>>
@ -74,26 +74,26 @@ impl ClipboardProvider for Clipboard {
{ {
match self { match self {
Clipboard::Wayland(c) => { Clipboard::Wayland(c) => {
Some(c.write::<ClipboardStoreData<T>>(contents)) Some(c.write_data::<ClipboardStoreData<T>>(contents))
} }
Clipboard::X11(_) => None, Clipboard::X11(_) => None,
} }
} }
fn read_primary<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>> fn read_primary_data<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
where where
ClipboardLoadData<T>: InnerAllowedMimeTypes, ClipboardLoadData<T>: InnerAllowedMimeTypes,
{ {
match self { match self {
Clipboard::Wayland(c) => { Clipboard::Wayland(c) => {
let ret = c.read_primary::<ClipboardLoadData<T>>(); let ret = c.read_primary_data::<ClipboardLoadData<T>>();
Some(ret.map(|ret| ret.0)) Some(ret.map(|ret| ret.0))
} }
Clipboard::X11(_) => None, Clipboard::X11(_) => None,
} }
} }
fn write_primary<T: Send + Sync + 'static>( fn write_primary_data<T: Send + Sync + 'static>(
&mut self, &mut self,
contents: ClipboardStoreData<T>, contents: ClipboardStoreData<T>,
) -> Option<Result<(), Box<dyn Error>>> ) -> Option<Result<(), Box<dyn Error>>>
@ -102,7 +102,7 @@ impl ClipboardProvider for Clipboard {
{ {
match self { match self {
Clipboard::Wayland(c) => { Clipboard::Wayland(c) => {
Some(c.write_primary::<ClipboardStoreData<T>>(contents)) Some(c.write_primary_data::<ClipboardStoreData<T>>(contents))
} }
Clipboard::X11(_) => None, Clipboard::X11(_) => None,
} }

View file

@ -10,5 +10,5 @@ documentation = "https://docs.rs/clipboard_wayland"
keywords = ["clipboard", "wayland"] keywords = ["clipboard", "wayland"]
[dependencies] [dependencies]
smithay-clipboard = { git = "https://github.com/wash2/smithay-clipboard", branch = "mime-types" } smithay-clipboard = { git = "https://github.com/pop-os/smithay-clipboard", tag = "pop-mime-types" }
# smithay-clipboard = { path = "../../smithay-clipboard" } # smithay-clipboard = { path = "../../smithay-clipboard" }

View file

@ -33,21 +33,21 @@ impl Clipboard {
Clipboard { context } Clipboard { context }
} }
pub fn read_text(&self) -> Result<String, Box<dyn Error>> { pub fn read(&self) -> Result<String, Box<dyn Error>> {
Ok(self.context.lock().unwrap().load_text()?) Ok(self.context.lock().unwrap().load_text()?)
} }
pub fn read_primary_text(&self) -> Result<String, Box<dyn Error>> { pub fn read_primary(&self) -> Result<String, Box<dyn Error>> {
Ok(self.context.lock().unwrap().load_primary_text()?) Ok(self.context.lock().unwrap().load_primary_text()?)
} }
pub fn write_text(&mut self, data: String) -> Result<(), Box<dyn Error>> { pub fn write(&mut self, data: String) -> Result<(), Box<dyn Error>> {
self.context.lock().unwrap().store_text(data); self.context.lock().unwrap().store_text(data);
Ok(()) Ok(())
} }
pub fn write_primary_text( pub fn write_primary(
&mut self, &mut self,
data: String, data: String,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
@ -56,7 +56,7 @@ impl Clipboard {
Ok(()) Ok(())
} }
pub fn write<T: AsMimeTypes + Send + Sync + 'static>( pub fn write_data<T: AsMimeTypes + Send + Sync + 'static>(
&mut self, &mut self,
data: T, data: T,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
@ -65,7 +65,7 @@ impl Clipboard {
Ok(()) Ok(())
} }
pub fn write_primary<T: AsMimeTypes + Send + Sync + 'static>( pub fn write_primary_data<T: AsMimeTypes + Send + Sync + 'static>(
&mut self, &mut self,
data: T, data: T,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
@ -74,13 +74,13 @@ impl Clipboard {
Ok(()) Ok(())
} }
pub fn read<T: AllowedMimeTypes + 'static>( pub fn read_data<T: AllowedMimeTypes + 'static>(
&self, &self,
) -> Result<T, Box<dyn Error>> { ) -> Result<T, Box<dyn Error>> {
Ok(self.context.lock().unwrap().load()?) Ok(self.context.lock().unwrap().load()?)
} }
pub fn read_primary<T: AllowedMimeTypes + 'static>( pub fn read_primary_data<T: AllowedMimeTypes + 'static>(
&self, &self,
) -> Result<T, Box<dyn Error>> { ) -> Result<T, Box<dyn Error>> {
Ok(self.context.lock().unwrap().load_primary()?) Ok(self.context.lock().unwrap().load_primary()?)