Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
winit: Add stub implementation for delayed invocation API
Browse files Browse the repository at this point in the history
  • Loading branch information
yvt committed Nov 12, 2019
1 parent e2cf991 commit 7f233fd
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
7 changes: 4 additions & 3 deletions tcw3/pal/src/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cfg_if! {
if #[cfg(feature = "macos_winit")] {
mod winitwindow;
pub use self::winitwindow::HWnd;
pub use super::winit::HInvokeCore as HInvoke;

use super::winit::{WinitEnv, WinitWmCore};
static WINIT_ENV: WinitEnv<Wm, winitwindow::WndContent> = WinitEnv::new();
Expand Down Expand Up @@ -144,14 +145,14 @@ impl iface::Wm for Wm {
}

#[cfg(feature = "macos_winit")]
fn invoke_after(self, delay: Range<Duration>, f: impl FnOnce(Self) + 'static) {
fn invoke_after(self, delay: Range<Duration>, f: impl FnOnce(Self) + 'static) -> Self::HInvoke {
self.winit_wm()
.invoke_after(delay, move |winit_wm| f(winit_wm.wm()));
.invoke_after(delay, move |winit_wm| f(winit_wm.wm()))
}

#[cfg(feature = "macos_winit")]
fn cancel_invoke(self, hinv: &Self::HInvoke) {
self.winit_wm().cancel_invoke(delay, hinv);
self.winit_wm().cancel_invoke(hinv);
}

#[cfg(feature = "macos_winit")]
Expand Down
15 changes: 13 additions & 2 deletions tcw3/pal/src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
//! - Cairo for 2D drawing (WIP)
//! - FreeType/Pango/fontconfig for text rendering (WIP).
//!
use std::marker::PhantomData;
use std::{marker::PhantomData, ops::Range, time::Duration};

use super::{
iface,
prelude::MtLazyStatic,
winit::{HWndCore, WinitEnv, WinitWm, WinitWmCore},
winit::{HInvokeCore, HWndCore, WinitEnv, WinitWm, WinitWmCore},
};

// Define a global instance of `WinitEnv`.
Expand All @@ -26,6 +26,7 @@ pub type LayerAttrs = iface::LayerAttrs<Bitmap, HLayer>;
pub type CharStyleAttrs = iface::CharStyleAttrs<CharStyle>;

pub type HWnd = HWndCore;
pub type HInvoke = HInvokeCore;

mod bitmap;
mod comp;
Expand Down Expand Up @@ -89,6 +90,7 @@ impl WinitWm for Wm {
impl iface::Wm for Wm {
type HWnd = HWnd;
type HLayer = HLayer;
type HInvoke = HInvoke;
type Bitmap = Bitmap;

unsafe fn global_unchecked() -> Wm {
Expand All @@ -110,6 +112,15 @@ impl iface::Wm for Wm {
.invoke(move |winit_wm| f(winit_wm.wm()));
}

fn invoke_after(self, delay: Range<Duration>, f: impl FnOnce(Self) + 'static) -> Self::HInvoke {
self.winit_wm_core()
.invoke_after(delay, move |winit_wm| f(winit_wm.wm()))
}

fn cancel_invoke(self, hinv: &Self::HInvoke) {
self.winit_wm_core().cancel_invoke(hinv);
}

fn enter_main_loop(self) -> ! {
WINIT_ENV.wm_with_wm(self).enter_main_loop();
}
Expand Down
6 changes: 6 additions & 0 deletions tcw3/pal/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ pub trait WinitWm: Wm {
fn init(self) {}
}

/// The invocation handle type used by `WinitWmCore`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct HInvokeCore {
_ptr: PoolPtr,
}

/// The window handle type used by `WinitWmCore`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct HWndCore {
Expand Down
18 changes: 17 additions & 1 deletion tcw3/pal/src/winit/wm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ use owning_ref::OwningRef;
use std::{
cell::{Cell, RefCell},
collections::LinkedList,
ops::Range,
ptr::NonNull,
sync::Mutex,
time::Duration,
};
use winit::event_loop::{ControlFlow, EventLoop, EventLoopProxy, EventLoopWindowTarget};

use super::super::MtSticky;
use super::{MtData, UserEvent, WinitEnv, WinitWm, WinitWmCore, WndContent};
use super::{HInvokeCore, MtData, UserEvent, WinitEnv, WinitWm, WinitWmCore, WndContent};

impl<TWM: WinitWm, TWC: WndContent<Wm = TWM>> WinitEnv<TWM, TWC> {
pub const fn new() -> Self {
Expand Down Expand Up @@ -270,4 +272,18 @@ impl<TWM: WinitWm, TWC: WndContent<Wm = TWM>> WinitWmCore<TWM, TWC> {
.borrow_mut()
.push_back(Box::new(cb));
}

pub fn invoke_after(
&self,
delay: Range<Duration>,
f: impl FnOnce(Self) + 'static,
) -> HInvokeCore {
let _ = (delay, f);
unimplemented!()
}

pub fn cancel_invoke(&self, hinv: &HInvokeCore) {
let _ = hinv;
unimplemented!()
}
}

0 comments on commit 7f233fd

Please sign in to comment.