compile on windows again
This commit is contained in:
1 parent
d4cafefb87
commit
7128e3e7cc
2 files changed
+34
-31
No files matched your search
@@ -1,6 +1,7 @@
|
||||
//! The connection to the GUI subsystem
|
||||
use super::EventHandle;
|
||||
use super::{HWindow, WindowInner};
|
||||
use crate::connection::ConnectionOps;
|
||||
use failure::Fallible;
|
||||
use promise::{BasicExecutor, SpawnFunc};
|
||||
use std::cell::RefCell;
|
||||
@@ -17,10 +18,6 @@ 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>>,
|
||||
event_handle: EventHandle,
|
||||
@@ -58,38 +55,14 @@ pub struct Connection {
|
||||
pub(crate) windows: Mutex<HashMap<HWindow, Rc<RefCell<WindowInner>>>>,
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
fn new() -> Self {
|
||||
let event_handle = SPAWN_QUEUE.event_handle.0;
|
||||
Self {
|
||||
event_handle,
|
||||
windows: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init() -> Fallible<Rc<Self>> {
|
||||
let conn = Rc::new(Self::new());
|
||||
CONN.with(|m| *m.borrow_mut() = Some(Rc::clone(&conn)));
|
||||
Ok(conn)
|
||||
}
|
||||
|
||||
pub fn terminate_message_loop(&self) {
|
||||
impl ConnectionOps for Connection {
|
||||
fn terminate_message_loop(&self) {
|
||||
unsafe {
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_message_loop(&self) -> Fallible<()> {
|
||||
fn run_message_loop(&self) -> Fallible<()> {
|
||||
let mut msg: MSG = unsafe { std::mem::zeroed() };
|
||||
loop {
|
||||
SPAWN_QUEUE.run();
|
||||
@@ -114,6 +87,24 @@ impl Connection {
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_task<F: std::future::Future<Output = ()> + 'static>(&self, future: F) {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn wake_task_by_id(slot: usize) {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
pub(crate) fn create_new() -> Fallible<Self> {
|
||||
let event_handle = SPAWN_QUEUE.event_handle.0;
|
||||
Ok(Self {
|
||||
event_handle,
|
||||
windows: Mutex::new(HashMap::new()),
|
||||
})
|
||||
}
|
||||
|
||||
fn wait_message(&self) {
|
||||
unsafe {
|
||||
MsgWaitForMultipleObjects(1, &self.event_handle, 0, INFINITE, QS_ALLEVENTS);
|
||||
|
||||
@@ -2,12 +2,14 @@ use super::gdi::*;
|
||||
use super::*;
|
||||
use crate::bitmaps::*;
|
||||
use crate::color::Color;
|
||||
use crate::connection::ConnectionOps;
|
||||
use crate::{
|
||||
Dimensions, KeyCode, KeyEvent, Modifiers, MouseButtons, MouseCursor, MouseEvent,
|
||||
MouseEventKind, MousePress, Operator, PaintContext, WindowCallbacks, WindowOps, WindowOpsMut,
|
||||
};
|
||||
use failure::Fallible;
|
||||
use promise::Future;
|
||||
use std::any::Any;
|
||||
use std::cell::RefCell;
|
||||
use std::io::Error as IoError;
|
||||
use std::ptr::{null, null_mut};
|
||||
@@ -248,6 +250,16 @@ 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.hwnd);
|
||||
func(inner.callbacks.as_any(), &window);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Set up bidirectional pointers:
|
||||
|
||||
Reference in new issue
Block a user