move paste over to GuiSender

This commit is contained in:
Wez Furlong committed 2018-03-03 11:07:27 -08:00
1 parent 00b45ce350
commit ebc4eaab36
6 files changed
+38 -26

No files matched your search

+2 -2
View File
@@ -11,7 +11,7 @@ mod x11;
#[cfg(all(unix, not(target_os = "macos")))]
pub use self::x11::Clipboard;
use wakeup::Wakeup;
use wakeup::GuiSender;
/// A fragment of the clipboard data received from another
/// app during paste.
@@ -28,7 +28,7 @@ pub enum Paste {
/// Abstracts away system specific clipboard implementation details.
pub trait ClipboardImpl {
fn new(wakeup: Wakeup, window_id: WindowId) -> Result<Self, Error>
fn new(wakeup: GuiSender<WindowId>, window_id: WindowId) -> Result<Self, Error>
where
Self: Sized;
fn set_clipboard(&self, text: Option<String>) -> Result<(), Error>;
+2 -2
View File
@@ -2,7 +2,7 @@ use clipboard::{ClipboardImpl, Paste};
use failure::Error;
use glium::glutin::WindowId;
use std::sync::mpsc::{channel, Receiver, Sender};
use wakeup::Wakeup;
use wakeup::GuiSender;
/// A no-op clipboard implementation
#[allow(dead_code)]
@@ -12,7 +12,7 @@ pub struct NoClipboard {
}
impl ClipboardImpl for NoClipboard {
fn new(_wakeup: Wakeup, _window_id: WindowId) -> Result<Self, Error> {
fn new(_wakeup: GuiSender<WindowId>, _window_id: WindowId) -> Result<Self, Error> {
let (sender, receiver) = channel();
Ok(Self { sender, receiver })
}
+6 -6
View File
@@ -10,7 +10,7 @@ use std::os::unix::io::AsRawFd;
use std::sync::mpsc::{channel, Receiver, Sender, TryRecvError};
use std::thread::{self, JoinHandle};
use std::time::Duration;
use wakeup::{Wakeup, WakeupMsg};
use wakeup::GuiSender;
use xcb;
use xcb_util;
@@ -42,7 +42,7 @@ struct Inner {
atom_xsel_data: xcb::Atom,
atom_targets: xcb::Atom,
atom_clipboard: xcb::Atom,
wakeup: Wakeup,
wakeup: GuiSender<WindowId>,
wakeup_window_id: WindowId,
}
@@ -50,7 +50,7 @@ impl Inner {
fn new(
receiver: MioReceiver<ClipRequest>,
sender: Sender<Paste>,
wakeup: Wakeup,
wakeup: GuiSender<WindowId>,
wakeup_window_id: WindowId,
) -> Result<Self, Error> {
let (conn, screen) = xcb::Connection::connect(None)?;
@@ -113,11 +113,11 @@ impl Inner {
fn send(&mut self, packet: Paste) -> Result<(), Error> {
match self.sender.send(packet) {
Ok(_) => {
self.wakeup.send(WakeupMsg::Paste(self.wakeup_window_id))?;
self.wakeup.send(self.wakeup_window_id)?;
Ok(())
}
Err(err) => {
self.wakeup.send(WakeupMsg::Paste(self.wakeup_window_id))?;
self.wakeup.send(self.wakeup_window_id)?;
bail!("clipboard: error sending to channel: {:?}", err);
}
}
@@ -401,7 +401,7 @@ pub struct Clipboard {
impl ClipboardImpl for Clipboard {
/// Create a new clipboard instance. `ping` is
fn new(wakeup: Wakeup, window_id: WindowId) -> Result<Self, Error> {
fn new(wakeup: GuiSender<WindowId>, window_id: WindowId) -> Result<Self, Error> {
let (sender_clip, receiver_clip) = mio_channel();
let (sender_paste, receiver_paste) = channel();
let clip_thread = thread::spawn(move || {
+4 -4
View File
@@ -5,7 +5,7 @@ use clipboard::{Clipboard, ClipboardImpl, Paste};
use failure::Error;
use font::FontConfiguration;
use glium::{self, glutin};
use glium::glutin::{ElementState, MouseCursor};
use glium::glutin::{ElementState, MouseCursor, WindowId};
use opengl::render::Renderer;
use opengl::textureatlas::OutOfTextureSpace;
use pty::MasterPty;
@@ -19,7 +19,7 @@ use term::{MouseButton, MouseEventKind};
use term::KeyCode;
use term::KeyModifiers;
use term::hyperlink::Hyperlink;
use wakeup::Wakeup;
use wakeup::GuiSender;
#[derive(Debug, Fail)]
pub enum SessionTerminated {
@@ -83,7 +83,7 @@ pub struct TerminalWindow {
impl TerminalWindow {
pub fn new(
event_loop: &glutin::EventsLoop,
wakeup: Wakeup,
paster: GuiSender<WindowId>,
width: u16,
height: u16,
terminal: Terminal,
@@ -114,7 +114,7 @@ impl TerminalWindow {
let host = Host {
display,
pty,
clipboard: Clipboard::new(wakeup, window_id)?,
clipboard: Clipboard::new(paster, window_id)?,
};
host.display.gl_window().set_cursor(MouseCursor::Text);
+23 -10
View File
@@ -57,7 +57,7 @@ mod opengl;
mod clipboard;
mod wakeup;
use wakeup::{Wakeup, WakeupMsg};
use wakeup::{GuiSender, Wakeup, WakeupMsg};
mod gliumwindows;
mod font;
@@ -90,11 +90,12 @@ struct GuiEventLoop {
windows_by_id: RefCell<HashMap<WindowId, gliumwindows::TerminalWindow>>,
windows_by_fd: RefCell<HashMap<RawFd, WindowId>>,
wakeup_receiver: std::sync::mpsc::Receiver<WakeupMsg>,
wakeup: Wakeup,
terminate: RefCell<bool>,
core: futurecore::Core,
poll: remotemio::IOMgr,
poll_rx: Receiver<remotemio::Notification>,
paster: GuiSender<WindowId>,
paster_rx: Receiver<WindowId>,
}
impl GuiEventLoop {
@@ -104,6 +105,7 @@ impl GuiEventLoop {
let (wakeup_receiver, wakeup) = Wakeup::new(event_loop.create_proxy());
let (wake_tx, poll_rx) = wakeup::channel(event_loop.create_proxy());
let (paster, paster_rx) = wakeup::channel(event_loop.create_proxy());
let poll = remotemio::IOMgr::new(Duration::from_millis(50), wake_tx);
sigchld::activate(wakeup.clone())?;
@@ -112,9 +114,10 @@ impl GuiEventLoop {
core,
poll,
poll_rx,
paster,
paster_rx,
event_loop: RefCell::new(event_loop),
wakeup_receiver,
wakeup,
windows_by_id: RefCell::new(HashMap::new()),
windows_by_fd: RefCell::new(HashMap::new()),
terminate: RefCell::new(false),
@@ -227,6 +230,21 @@ impl GuiEventLoop {
}
}
fn process_paste_wakeups(&self) -> Result<(), Error> {
loop {
match self.paster_rx.try_recv() {
Ok(window_id) => {
self.windows_by_id
.borrow_mut()
.get_mut(&window_id)
.map(|w| w.process_clipboard());
}
Err(TryRecvError::Empty) => return Ok(()),
Err(err) => bail!("paster_rx disconnected {:?}", err),
}
}
}
fn process_wakeups(&self, dead_windows: &mut HashSet<WindowId>) -> Result<(), Error> {
loop {
match self.wakeup_receiver.try_recv() {
@@ -241,12 +259,6 @@ impl GuiEventLoop {
}
}
}
Ok(WakeupMsg::Paste(window_id)) => {
self.windows_by_id
.borrow_mut()
.get_mut(&window_id)
.map(|w| w.process_clipboard());
}
Err(_) => return Ok(()),
}
}
@@ -276,6 +288,7 @@ impl GuiEventLoop {
let mut dead_windows = HashSet::new();
self.process_wakeups(&mut dead_windows)?;
self.process_wakeups_new()?;
self.process_paste_wakeups()?;
self.run_event_loop(&mut dead_windows)?;
for window_id in dead_windows {
@@ -308,7 +321,7 @@ fn run_glium(
let window = gliumwindows::TerminalWindow::new(
&*event_loop.event_loop.borrow_mut(),
event_loop.wakeup.clone(),
event_loop.paster.clone(),
initial_pixel_width,
initial_pixel_height,
terminal,
+1 -2
View File
@@ -1,11 +1,10 @@
use failure::Error;
use glium::glutin::{EventsLoopProxy, WindowId};
use glium::glutin::EventsLoopProxy;
use std::sync::mpsc::{self, Receiver, Sender};
#[derive(Debug)]
pub enum WakeupMsg {
SigChld,
Paste(WindowId),
}
#[derive(Clone)]