From b24f27d2a738bf1ab536111ef0889ed10bd7cde2 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 5 Mar 2019 20:03:30 +0000 Subject: [PATCH] fix compilation with x11 --- src/guiloop/x11.rs | 30 +++++++++++++++++++++++++----- src/xwindows/xwin.rs | 4 ++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/guiloop/x11.rs b/src/guiloop/x11.rs index 39b67a4b0..095472109 100644 --- a/src/guiloop/x11.rs +++ b/src/guiloop/x11.rs @@ -15,6 +15,7 @@ use std::cell::RefCell; use std::collections::HashMap; use std::rc::Rc; use std::sync::mpsc::TryRecvError; +use std::sync::Arc; use std::time::{Duration, Instant}; use xcb; @@ -51,7 +52,6 @@ pub struct GuiEventLoop { mux: Rc, } -const TOK_PTY: usize = 0xffff_fffe; const TOK_XCB: usize = 0xffff_fffc; const TOK_GUI_EXEC: usize = 0xffff_fffd; @@ -61,15 +61,18 @@ pub struct X11GuiSystem { impl X11GuiSystem { pub fn try_new(mux: &Rc) -> Result, Error> { let event_loop = Rc::new(GuiEventLoop::new(mux)?); + X11_EVENT_LOOP.with(|f| *f.borrow_mut() = Some(Rc::clone(&event_loop))); Ok(Rc::new(Self { event_loop })) } } +thread_local! { + static X11_EVENT_LOOP: RefCell>> = RefCell::new(None); +} + impl super::GuiSystem for X11GuiSystem { - fn gui_executor(&self) -> Arc { - Arc::new(X11GuiExecutor { - tx: self.event_loop.gui_tx.clone(), - }) + fn gui_executor(&self) -> Box { + self.event_loop.gui_executor() } fn run_forever(&self) -> Result<(), Error> { @@ -114,6 +117,22 @@ impl GuiEventLoop { }) } + pub fn get() -> Option> { + let mut res = None; + X11_EVENT_LOOP.with(|f| { + if let Some(me) = &*f.borrow() { + res = Some(Rc::clone(me)); + } + }); + res + } + + fn gui_executor(&self) -> Box { + Box::new(X11GuiExecutor { + tx: self.gui_tx.clone(), + }) + } + pub fn register_tab(&self, tab: &Rc) -> Result<(), Error> { self.mux.add_tab(self.gui_executor(), tab) } @@ -186,6 +205,7 @@ impl GuiEventLoop { } }, ); + Ok(()) } fn do_spawn_new_window( diff --git a/src/xwindows/xwin.rs b/src/xwindows/xwin.rs index 56cf39c7b..caef83388 100644 --- a/src/xwindows/xwin.rs +++ b/src/xwindows/xwin.rs @@ -28,8 +28,8 @@ impl HostHelper for Host { &self, func: F, ) { - let window_id = self.host.window.window.window_id; - self.event_loop.with_window(window_id, func); + let window_id = self.window.window.window_id; + self.event_loop.with_window(window_id, func).ok(); } fn toggle_full_screen(&mut self) {}