diff --git a/window/src/os/macos/connection.rs b/window/src/os/macos/connection.rs index 212fb4915..3a5653cdd 100644 --- a/window/src/os/macos/connection.rs +++ b/window/src/os/macos/connection.rs @@ -61,13 +61,6 @@ impl Connection { } })); } - - pub(crate) fn wake_task_by_id(slot: usize) { - SpawnQueueExecutor {}.execute(Box::new(move || { - let conn = Connection::get().unwrap(); - conn.tasks.poll_by_slot(slot); - })); - } } impl ConnectionOps for Connection { @@ -89,4 +82,11 @@ impl ConnectionOps for Connection { let id = self.tasks.add_task(Task(Box::pin(future))); Self::wake_task_by_id(id); } + + fn wake_task_by_id(slot: usize) { + SpawnQueueExecutor {}.execute(Box::new(move || { + let conn = Connection::get().unwrap(); + conn.tasks.poll_by_slot(slot); + })); + } } diff --git a/window/src/os/windows/connection.rs b/window/src/os/windows/connection.rs index 24db342a9..19019638b 100644 --- a/window/src/os/windows/connection.rs +++ b/window/src/os/windows/connection.rs @@ -1,16 +1,15 @@ //! The connection to the GUI subsystem -use super::EventHandle; use super::{HWindow, WindowInner}; use crate::connection::ConnectionOps; use crate::spawn::*; +use crate::tasks::{Task, Tasks}; use failure::Fallible; -use promise::{BasicExecutor, SpawnFunc}; +use promise::BasicExecutor; use std::cell::RefCell; use std::collections::HashMap; -use std::collections::VecDeque; use std::ptr::null_mut; use std::rc::Rc; -use std::sync::{Arc, Mutex}; +use std::sync::Mutex; use winapi::um::winbase::INFINITE; use winapi::um::winnt::HANDLE; use winapi::um::winuser::*; @@ -18,6 +17,7 @@ use winapi::um::winuser::*; pub struct Connection { event_handle: HANDLE, pub(crate) windows: Mutex>>>, + tasks: Tasks, } impl ConnectionOps for Connection { @@ -53,11 +53,15 @@ impl ConnectionOps for Connection { } fn spawn_task + 'static>(&self, future: F) { - unimplemented!(); + let id = self.tasks.add_task(Task(Box::pin(future))); + Self::wake_task_by_id(id); } fn wake_task_by_id(slot: usize) { - unimplemented!(); + SpawnQueueExecutor {}.execute(Box::new(move || { + let conn = Connection::get().unwrap(); + conn.tasks.poll_by_slot(slot); + })); } } @@ -67,6 +71,7 @@ impl Connection { Ok(Self { event_handle, windows: Mutex::new(HashMap::new()), + tasks: Default::default(), }) } diff --git a/window/src/os/windows/window.rs b/window/src/os/windows/window.rs index 6feeddfc1..6c36b4b46 100644 --- a/window/src/os/windows/window.rs +++ b/window/src/os/windows/window.rs @@ -28,7 +28,7 @@ unsafe impl Sync for HWindow {} pub(crate) struct WindowInner { /// Non-owning reference to the window handle hwnd: HWindow, - callbacks: Box, + callbacks: Box, } #[derive(Debug, Clone)] @@ -158,7 +158,7 @@ impl Window { name: &str, width: usize, height: usize, - callbacks: Box, + callbacks: Box, ) -> Fallible { let inner = Rc::new(RefCell::new(WindowInner { hwnd: HWindow(null_mut()), diff --git a/window/src/os/x11/bitmap.rs b/window/src/os/x11/bitmap.rs index 859d4c745..9b03a8395 100644 --- a/window/src/os/x11/bitmap.rs +++ b/window/src/os/x11/bitmap.rs @@ -22,7 +22,7 @@ pub struct Context { } impl Context { - pub fn new(conn: &Rc, d: &Drawable) -> Context { + pub fn new(conn: &Rc, d: &dyn Drawable) -> Context { let gc_id = conn.conn().generate_id(); let drawable = d.as_drawable(); xcb::create_gc(conn.conn(), gc_id, drawable, &[]); @@ -37,10 +37,10 @@ impl Context { /// defined in this context. pub fn copy_area( &self, - src: &Drawable, + src: &dyn Drawable, src_x: i16, src_y: i16, - dest: &Drawable, + dest: &dyn Drawable, dest_x: i16, dest_y: i16, width: u16, diff --git a/window/src/os/x11/connection.rs b/window/src/os/x11/connection.rs index 734e97eb9..5772916a7 100644 --- a/window/src/os/x11/connection.rs +++ b/window/src/os/x11/connection.rs @@ -1,16 +1,14 @@ use super::keyboard::Keyboard; use crate::connection::ConnectionOps; use crate::spawn::*; +use crate::tasks::{Task, Tasks}; use crate::WindowInner; use failure::Fallible; -use filedescriptor::{FileDescriptor, Pipe}; use mio::unix::EventedFd; use mio::{Evented, Events, Poll, PollOpt, Ready, Token}; -use promise::{BasicExecutor, SpawnFunc}; +use promise::BasicExecutor; use std::cell::RefCell; use std::collections::HashMap; -use std::collections::VecDeque; -use std::io::{Read, Write}; use std::os::unix::io::AsRawFd; use std::sync::{Arc, Mutex}; use std::time::{Duration, Instant}; @@ -33,6 +31,7 @@ pub struct Connection { pub(crate) windows: RefCell>>>, should_terminate: RefCell, pub(crate) shm_available: bool, + tasks: Tasks, } impl std::ops::Deref for Connection { @@ -143,11 +142,15 @@ fn server_supports_shm() -> bool { impl ConnectionOps for Connection { fn spawn_task + 'static>(&self, future: F) { - unimplemented!(); + let id = self.tasks.add_task(Task(Box::pin(future))); + Self::wake_task_by_id(id); } fn wake_task_by_id(slot: usize) { - unimplemented!(); + SpawnQueueExecutor {}.execute(Box::new(move || { + let conn = Connection::get().unwrap(); + conn.tasks.poll_by_slot(slot); + })); } fn terminate_message_loop(&self) { @@ -331,6 +334,7 @@ impl Connection { windows: RefCell::new(HashMap::new()), should_terminate: RefCell::new(false), shm_available, + tasks: Default::default(), }; Ok(conn) diff --git a/window/src/os/x11/window.rs b/window/src/os/x11/window.rs index d5c14f4ad..c460da143 100644 --- a/window/src/os/x11/window.rs +++ b/window/src/os/x11/window.rs @@ -63,7 +63,7 @@ impl Rect { pub(crate) struct WindowInner { window_id: xcb::xproto::Window, conn: Rc, - callbacks: Box, + callbacks: Box, window_context: Context, width: u16, height: u16, @@ -80,7 +80,7 @@ impl Drop for WindowInner { } struct X11GraphicsContext<'a> { - buffer: &'a mut BitmapImage, + buffer: &'a mut dyn BitmapImage, } impl<'a> PaintContext for X11GraphicsContext<'a> { @@ -409,7 +409,7 @@ impl Window { name: &str, width: usize, height: usize, - callbacks: Box, + callbacks: Box, ) -> Fallible { let conn = Connection::get().ok_or_else(|| { failure::err_msg( diff --git a/window/src/spawn.rs b/window/src/spawn.rs index 3f707aa70..3bb22664e 100644 --- a/window/src/spawn.rs +++ b/window/src/spawn.rs @@ -6,7 +6,7 @@ use filedescriptor::{FileDescriptor, Pipe}; #[cfg(all(unix, not(target_os = "macos")))] use mio::unix::EventedFd; #[cfg(all(unix, not(target_os = "macos")))] -use mio::{Evented, Events, Poll, PollOpt, Ready, Token}; +use mio::{Evented, Poll, PollOpt, Ready, Token}; use promise::{BasicExecutor, SpawnFunc}; use std::collections::VecDeque; #[cfg(all(unix, not(target_os = "macos")))]