-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable graceful shutdown on linux (#13)
* Enable graceful shutdown on linux * Re-implement raw x11 poll for event
- Loading branch information
Showing
4 changed files
with
143 additions
and
32 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
@@ -1,26 +1,29 @@ | ||
use std::time; | ||
use clipboard_master::{Master, ClipboardHandler, CallbackResult}; | ||
|
||
pub struct Handler; | ||
|
||
impl ClipboardHandler for Handler { | ||
fn on_clipboard_change(&mut self) -> CallbackResult { | ||
println!("CHANGE"); | ||
CallbackResult::Next | ||
} | ||
} | ||
|
||
//TODO: Make shutdown work on Linux | ||
//This is currently difficult due to buggy x11-clipboard lib | ||
#[cfg(not(target_arch = "linux"))] | ||
#[test] | ||
fn should_shutdown_successfully() { | ||
const TIMEOUT: time::Duration = time::Duration::from_secs(5); | ||
let mut master = Master::new(Handler).expect("To create master"); | ||
let shutdown = master.shutdown_channel(); | ||
std::thread::spawn(move || { | ||
std::thread::sleep(core::time::Duration::from_secs(5)); | ||
std::thread::sleep(TIMEOUT); | ||
println!("signal"); | ||
shutdown.signal(); | ||
}); | ||
|
||
println!("RUN"); | ||
let now = time::Instant::now(); | ||
master.run().expect("to finish"); | ||
assert!(now.elapsed() >= (TIMEOUT - time::Duration::from_millis(500))); | ||
assert!(now.elapsed() <= (TIMEOUT + time::Duration::from_millis(500))); | ||
} |