Verified Commit ed7204c4 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

0.3.24 - add clipboard functions

parent 6a443176
[package]
name = "orbclient"
version = "0.3.23"
version = "0.3.24"
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
description = "The Orbital Client Library"
documentation = "https://docs.rs/orbclient"
......
......@@ -3,7 +3,7 @@ extern crate syscall;
use std::cell::Cell;
use std::fs::File;
use std::io::{Read, Write};
use std::os::unix::io::{AsRawFd, RawFd};
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
use std::{env, mem, slice, thread};
use color::Color;
......@@ -164,6 +164,24 @@ impl Window {
}
}
pub fn clipboard(&self) -> String {
let mut text = String::new();
let window_fd = self.file.as_raw_fd();
if let Ok(clipboard_fd) = syscall::dup(window_fd as usize, b"clipboard") {
let mut clipboard_file = unsafe { File::from_raw_fd(clipboard_fd as RawFd) };
let _ = clipboard_file.read_to_string(&mut text);
}
text
}
pub fn set_clipboard(&mut self, text: &str) {
let window_fd = self.file.as_raw_fd();
if let Ok(clipboard_fd) = syscall::dup(window_fd as usize, b"clipboard") {
let mut clipboard_file = unsafe { File::from_raw_fd(clipboard_fd as RawFd) };
let _ = clipboard_file.write(text.as_bytes());
}
}
// TODO: Replace with smarter mechanism, maybe a move event?
pub fn sync_path(&mut self) {
let mut buf: [u8; 4096] = [0; 4096];
......
......@@ -175,6 +175,14 @@ impl Window {
}
}
pub fn clipboard(&self) -> String {
unsafe { &*VIDEO_CTX }.clipboard().clipboard_text().unwrap()
}
pub fn set_clipboard(&mut self, text: &str) {
unsafe { &*VIDEO_CTX }.clipboard().set_clipboard_text(text).unwrap();
}
pub fn sync_path(&mut self) {
let window = self.inner.window();
let pos = window.position();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment