1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-20 11:17:15 +03:00

spawning async tasks now impl on all platforms

This commit is contained in:
Wez Furlong 2019-08-18 09:14:30 -07:00
parent 3d379791c8
commit f793b36ff0
7 changed files with 37 additions and 28 deletions

View File

@ -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);
}));
}
}

View File

@ -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<HashMap<HWindow, Rc<RefCell<WindowInner>>>>,
tasks: Tasks,
}
impl ConnectionOps for Connection {
@ -53,11 +53,15 @@ impl ConnectionOps for Connection {
}
fn spawn_task<F: std::future::Future<Output = ()> + '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(),
})
}

View File

@ -28,7 +28,7 @@ unsafe impl Sync for HWindow {}
pub(crate) struct WindowInner {
/// Non-owning reference to the window handle
hwnd: HWindow,
callbacks: Box<WindowCallbacks>,
callbacks: Box<dyn WindowCallbacks>,
}
#[derive(Debug, Clone)]
@ -158,7 +158,7 @@ impl Window {
name: &str,
width: usize,
height: usize,
callbacks: Box<WindowCallbacks>,
callbacks: Box<dyn WindowCallbacks>,
) -> Fallible<Window> {
let inner = Rc::new(RefCell::new(WindowInner {
hwnd: HWindow(null_mut()),

View File

@ -22,7 +22,7 @@ pub struct Context {
}
impl Context {
pub fn new(conn: &Rc<Connection>, d: &Drawable) -> Context {
pub fn new(conn: &Rc<Connection>, 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,

View File

@ -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<HashMap<xcb::xproto::Window, Arc<Mutex<WindowInner>>>>,
should_terminate: RefCell<bool>,
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<F: std::future::Future<Output = ()> + '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)

View File

@ -63,7 +63,7 @@ impl Rect {
pub(crate) struct WindowInner {
window_id: xcb::xproto::Window,
conn: Rc<Connection>,
callbacks: Box<WindowCallbacks>,
callbacks: Box<dyn WindowCallbacks>,
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<WindowCallbacks>,
callbacks: Box<dyn WindowCallbacks>,
) -> Fallible<Window> {
let conn = Connection::get().ok_or_else(|| {
failure::err_msg(

View File

@ -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")))]