Merge pull request #18 from andraantariksa/dummy-platform

Add dummy platform 🌮
This commit is contained in:
Héctor Ramón 2022-01-27 17:02:30 +07:00 committed by GitHub
commit f27a89054e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 16 deletions

View file

@ -14,3 +14,7 @@ jobs:
- uses: actions/checkout@master
- name: Run tests
run: cargo test --verbose
- name: Add Wasm target
run: rustup target add wasm32-unknown-unknown
- name: Run tests on Wasm
run: cargo build --verbose --target wasm32-unknown-unknown

View file

@ -13,6 +13,7 @@ categories = ["gui"]
[dependencies]
raw-window-handle = "0.3"
thiserror = "1.0"
[target.'cfg(windows)'.dependencies]
clipboard-win = { version = "4.0", features = ["std"] }

View file

@ -26,6 +26,24 @@ mod platform;
#[path = "platform/android.rs"]
mod platform;
#[cfg(not(any(
all(
unix,
not(any(
target_os = "macos",
target_os = "ios",
target_os = "android",
target_os = "emscripten"
))
),
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "android"
)))]
#[path = "platform/dummy.rs"]
mod platform;
use raw_window_handle::HasRawWindowHandle;
use std::error::Error;

30
src/platform/dummy.rs Normal file
View file

@ -0,0 +1,30 @@
use crate::ClipboardProvider;
use raw_window_handle::HasRawWindowHandle;
struct Dummy;
pub fn connect<W: HasRawWindowHandle>(
_window: &W,
) -> Result<Box<dyn ClipboardProvider>, Box<dyn std::error::Error>> {
Ok(Box::new(Dummy))
}
impl ClipboardProvider for Dummy {
fn read(&self) -> Result<String, Box<dyn std::error::Error>> {
Err(Box::new(Error::Unimplemented))
}
fn write(
&mut self,
_contents: String,
) -> Result<(), Box<dyn std::error::Error>> {
Err(Box::new(Error::Unimplemented))
}
}
#[derive(Debug, Clone, Copy, thiserror::Error)]
enum Error {
#[error("unimplemented")]
Unimplemented,
}

View file

@ -360,23 +360,28 @@ impl Worker {
if event.target == self.context.atoms.targets {
let data = [self.context.atoms.targets, target];
self.context.connection.change_property32(
xproto::PropMode::REPLACE,
event.requestor,
event.property,
xproto::AtomEnum::ATOM,
&data,
)
.expect("Change property");
self.context
.connection
.change_property32(
xproto::PropMode::REPLACE,
event.requestor,
event.property,
xproto::AtomEnum::ATOM,
&data,
)
.expect("Change property");
} else {
let _ = self.context.connection.change_property8(
xproto::PropMode::REPLACE,
event.requestor,
event.property,
target,
value,
)
.expect("Change property");
let _ = self
.context
.connection
.change_property8(
xproto::PropMode::REPLACE,
event.requestor,
event.property,
target,
value,
)
.expect("Change property");
}
let _ = xproto::send_event(