Created
November 23, 2018 02:30
-
-
Save ayosec/ff2c55ab382c147a65137c5a2706a705 to your computer and use it in GitHub Desktop.
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
extern crate gtk; | |
extern crate gdk; | |
use gtk::prelude::*; | |
use gdk::Atom; | |
use gtk::*; | |
use std::sync::atomic::{AtomicUsize, Ordering}; | |
fn main() { | |
if gtk::init().is_err() { | |
println!("Failed to initialize GTK."); | |
return; | |
} | |
let counter = AtomicUsize::new(0); | |
let atom = Atom::intern("CLIPBOARD"); | |
let clipboard = Clipboard::get(&atom); | |
let target = TargetEntry::new("UTF8_STRING", TargetFlags::all(), 0); | |
clipboard.set_with_data(&[target], move |_, sd, _| { | |
let count = counter.fetch_add(1, Ordering::Relaxed); | |
sd.set_text(&format!("count = {}", count)); | |
println!("Set data to {}", count); | |
}); | |
println!("Clipboard configured"); | |
gtk::main(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment