Replace xcb with x11rb in clipboard_x11

This commit is contained in:
Héctor Ramón Jiménez 2021-02-11 22:35:53 +01:00
parent cf01306fc2
commit 3277d91321
4 changed files with 104 additions and 145 deletions

View file

@ -1,59 +1,17 @@
use std::error::Error as StdError;
use std::fmt;
use std::sync::mpsc::SendError;
use xcb::base::{ConnError, GenericError};
use xcb::Atom;
use x11rb::errors::{ConnectError, ConnectionError, ReplyError};
use x11rb::protocol::xproto::Atom;
#[must_use]
#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
Set(SendError<Atom>),
XcbConn(ConnError),
XcbGeneric(GenericError),
#[error("connection failed: {0}")]
ConnectionFailed(#[from] ConnectError),
#[error("connection errored: {0}")]
ConnectionErrored(#[from] ConnectionError),
#[error("reply failed: {0}")]
ReplyError(#[from] ReplyError),
#[error("timeout")]
Timeout,
Owner,
#[error("unexpected type: {0}")]
UnexpectedType(Atom),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::Set(e) => write!(f, "XCB - couldn't set atom: {:?}", e),
Error::XcbConn(e) => write!(f, "XCB connection error: {:?}", e),
Error::XcbGeneric(e) => write!(f, "XCB generic error: {:?}", e),
Error::Timeout => write!(f, "Selection timed out"),
Error::Owner => {
write!(f, "Failed to set new owner of XCB selection")
}
Error::UnexpectedType(target) => {
write!(f, "Unexpected Reply type: {}", target)
}
}
}
}
impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
use self::Error::*;
match self {
Set(e) => Some(e),
XcbConn(e) => Some(e),
XcbGeneric(e) => Some(e),
Timeout | Owner | UnexpectedType(_) => None,
}
}
}
macro_rules! define_from {
( $item:ident from $err:ty ) => {
impl From<$err> for Error {
fn from(err: $err) -> Error {
Error::$item(err)
}
}
};
}
define_from!(Set from SendError<Atom>);
define_from!(XcbConn from ConnError);
define_from!(XcbGeneric from GenericError);