make the basic example build again on x11

This commit is contained in:
Wez Furlong committed 2019-09-15 19:09:08 -07:00
1 parent cabb9d155c
commit d4cafefb87
4 files changed
+28 -19

No files matched your search

+1
View File
@@ -27,4 +27,5 @@ pub trait ConnectionOps {
fn terminate_message_loop(&self);
fn run_message_loop(&self) -> Fallible<()>;
fn spawn_task<F: std::future::Future<Output = ()> + 'static>(&self, future: F);
fn wake_task_by_id(slot: usize);
}
+15 -19
View File
@@ -1,4 +1,5 @@
use super::keyboard::Keyboard;
use crate::connection::ConnectionOps;
use crate::WindowInner;
use failure::Fallible;
use filedescriptor::{FileDescriptor, Pipe};
@@ -10,7 +11,6 @@ use std::collections::HashMap;
use std::collections::VecDeque;
use std::io::{Read, Write};
use std::os::unix::io::AsRawFd;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
use xcb_util::ffi::keysyms::{xcb_key_symbols_alloc, xcb_key_symbols_free, xcb_key_symbols_t};
@@ -18,9 +18,6 @@ use xcb_util::ffi::keysyms::{xcb_key_symbols_alloc, xcb_key_symbols_free, xcb_ke
lazy_static::lazy_static! {
static ref SPAWN_QUEUE: Arc<SpawnQueue> = Arc::new(SpawnQueue::new().expect("failed to create SpawnQueue"));
}
thread_local! {
static CONN: RefCell<Option<Rc<Connection>>> = RefCell::new(None);
}
struct SpawnQueue {
spawned_funcs: Mutex<VecDeque<SpawnFunc>>,
@@ -204,22 +201,20 @@ fn server_supports_shm() -> bool {
}
}
impl Connection {
pub fn get() -> Option<Rc<Self>> {
let mut res = None;
CONN.with(|m| {
if let Some(mux) = &*m.borrow() {
res = Some(Rc::clone(mux));
}
});
res
impl ConnectionOps for Connection {
fn spawn_task<F: std::future::Future<Output = ()> + 'static>(&self, future: F) {
unimplemented!();
}
pub fn terminate_message_loop(&self) {
fn wake_task_by_id(slot: usize) {
unimplemented!();
}
fn terminate_message_loop(&self) {
*self.should_terminate.borrow_mut() = true;
}
pub fn run_message_loop(&self) -> Fallible<()> {
fn run_message_loop(&self) -> Fallible<()> {
self.conn.flush();
const TOK_XCB: usize = 0xffff_fffc;
@@ -280,7 +275,9 @@ impl Connection {
Ok(())
}
}
impl Connection {
fn process_queued_xcb(&self) -> Fallible<()> {
match self.conn.poll_for_event() {
None => match self.conn.has_error() {
@@ -338,7 +335,7 @@ impl Connection {
Ok(())
}
pub fn init() -> Fallible<Rc<Connection>> {
pub(crate) fn create_new() -> Fallible<Connection> {
let display = unsafe { x11::xlib::XOpenDisplay(std::ptr::null()) };
if display.is_null() {
failure::bail!("failed to open display");
@@ -377,7 +374,7 @@ impl Connection {
let cursor_font_name = "cursor";
xcb::open_font_checked(&conn, cursor_font_id, cursor_font_name);
let conn = Rc::new(Connection {
let conn = Connection {
display,
conn,
cursor_font_id,
@@ -394,9 +391,8 @@ impl Connection {
windows: RefCell::new(HashMap::new()),
should_terminate: RefCell::new(false),
shm_available,
});
};
CONN.with(|m| *m.borrow_mut() = Some(Rc::clone(&conn)));
Ok(conn)
}
+11
View File
@@ -1,10 +1,12 @@
use super::*;
use crate::bitmaps::*;
use crate::connection::ConnectionOps;
use crate::{
Color, Dimensions, KeyEvent, MouseButtons, MouseCursor, MouseEvent, MouseEventKind, MousePress,
Operator, PaintContext, WindowCallbacks, WindowOps, WindowOpsMut,
};
use failure::Fallible;
use std::any::Any;
use std::collections::VecDeque;
use std::convert::TryInto;
use std::rc::Rc;
@@ -538,4 +540,13 @@ impl WindowOps for Window {
let title = title.to_owned();
Connection::with_window_inner(self.0, move |inner| inner.set_title(&title));
}
fn apply<F: Send + 'static + Fn(&mut dyn Any, &dyn WindowOps)>(&self, func: F)
where
Self: Sized,
{
Connection::with_window_inner(self.0, move |inner| {
let window = Window(inner.window_id);
func(inner.callbacks.as_any(), &window);
});
}
}
+1
View File
@@ -1,3 +1,4 @@
use crate::connection::ConnectionOps;
use crate::Connection;
use std::cell::{Cell, RefCell};
use std::future::Future;