Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to upstream winit #679

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ raw-window-handle = "0.6.0"
wgpu = { version = "22.0.0" }
parking_lot = { version = "0.12.1" }
swash = { version = "0.1.17" }
muda = { version = "0.15.3" }
winit = { git = "https://github.com/rust-windowing/winit", rev = "3a60cbaba5fd96d9244a1f316ae562d7032b2b98" }

[dependencies]
slotmap = "1.0.7"
Expand Down Expand Up @@ -61,13 +63,14 @@ floem_vello_renderer ={ path = "vello", version = "0.1.0", optional = true}
floem_vger_renderer ={ path = "vger", version = "0.1.0", optional = true}
floem_tiny_skia_renderer = { path = "tiny_skia", version = "0.1.0" }
floem_reactive = { path = "reactive", version = "0.1.0" }
floem-winit = { git = "https://github.com/lapce/winit", rev = "c8d3b8fd6fa4ffd5e0f99be78aacddcf6de57bcd", features = ["rwh_05"] }
floem-editor-core = { path = "editor-core", version = "0.1.0", optional = true }
copypasta = { version = "0.10.0", default-features = false, features = ["wayland", "x11"] }
parking_lot = { workspace = true }
image = { workspace = true }
im = { workspace = true }
wgpu = { workspace = true }
muda = { workspace = true }
winit = { workspace = true }
futures = { version = "0.3.30", optional = true }
crossbeam = "0.8"

Expand All @@ -86,7 +89,7 @@ vger = ["dep:floem_vger_renderer"]

# TODO: this is only winit and the editor serde, there are other dependencies that still depend on
# serde
serde = ["floem-winit/serde", "dep:serde"]
serde = ["winit/serde", "dep:serde"]
editor = ["floem-editor-core", "dep:lapce-xi-rope", "dep:strum", "dep:strum_macros", "dep:downcast-rs"]

# Image support
Expand Down
3 changes: 2 additions & 1 deletion reactive/src/get_update_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::marker::PhantomData;

use crate::{read::SignalTrack, RwSignal, SignalGet, SignalUpdate, SignalWith};

pub struct GetUpdateFn<T, O, GF: Fn(&T) -> O + Clone + 'static, UF: Fn(&O) -> T + 'static> {
pub struct GetUpdateFn<T: 'static, O, GF: Fn(&T) -> O + Clone + 'static, UF: Fn(&O) -> T + 'static>
{
signal: RwSignal<T>,
getter: RwSignal<Box<GF>>,
setter: RwSignal<Box<UF>>,
Expand Down
12 changes: 6 additions & 6 deletions reactive/src/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ use crate::{
/// It will act like a Signal when the value is different with the computed value
/// from last run, i.e., it will trigger a effect run when you Get() it whenever the
/// computed value changes to a different value.
pub struct Memo<T> {
pub struct Memo<T: 'static> {
getter: ReadSignal<T>,
ty: PhantomData<T>,
}

impl<T> Copy for Memo<T> {}
impl<T: 'static> Copy for Memo<T> {}

impl<T> Clone for Memo<T> {
impl<T: 'static> Clone for Memo<T> {
fn clone(&self) -> Self {
*self
}
}

impl<T: Clone> SignalGet<T> for Memo<T> {
impl<T: 'static + Clone> SignalGet<T> for Memo<T> {
fn id(&self) -> crate::id::Id {
self.getter.id
}
}

impl<T> SignalWith<T> for Memo<T> {
impl<T: 'static> SignalWith<T> for Memo<T> {
fn id(&self) -> crate::id::Id {
self.getter.id
}
}
impl<T> SignalTrack<T> for Memo<T> {
impl<T: 'static> SignalTrack<T> for Memo<T> {
fn id(&self) -> crate::id::Id {
self.getter.id
}
Expand Down
30 changes: 15 additions & 15 deletions reactive/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ use crate::{
};

/// A read write Signal which can act as both a Getter and a Setter
pub struct RwSignal<T> {
pub struct RwSignal<T: 'static> {
pub(crate) id: Id,
pub(crate) ty: PhantomData<T>,
}

impl<T> Copy for RwSignal<T> {}
impl<T: 'static> Copy for RwSignal<T> {}

impl<T> Clone for RwSignal<T> {
impl<T: 'static> Clone for RwSignal<T> {
fn clone(&self) -> Self {
*self
}
}

impl<T> Eq for RwSignal<T> {}
impl<T: 'static> Eq for RwSignal<T> {}

impl<T> PartialEq for RwSignal<T> {
impl<T: 'static> PartialEq for RwSignal<T> {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}

impl<T> fmt::Debug for RwSignal<T> {
impl<T: 'static> fmt::Debug for RwSignal<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut s = f.debug_struct("RwSignal");
s.field("id", &self.id);
Expand All @@ -47,7 +47,7 @@ impl<T> fmt::Debug for RwSignal<T> {
}
}

impl<T> RwSignal<T> {
impl<T: 'static> RwSignal<T> {
/// Create a Getter of this Signal
pub fn read_only(&self) -> ReadSignal<T> {
ReadSignal {
Expand Down Expand Up @@ -93,14 +93,14 @@ where
}

/// A getter only Signal
pub struct ReadSignal<T> {
pub struct ReadSignal<T: 'static> {
pub(crate) id: Id,
pub(crate) ty: PhantomData<T>,
}

impl<T> Copy for ReadSignal<T> {}
impl<T: 'static> Copy for ReadSignal<T> {}

impl<T> Clone for ReadSignal<T> {
impl<T: 'static> Clone for ReadSignal<T> {
fn clone(&self) -> Self {
*self
}
Expand All @@ -115,22 +115,22 @@ impl<T> PartialEq for ReadSignal<T> {
}

/// A setter only Signal
pub struct WriteSignal<T> {
pub struct WriteSignal<T: 'static> {
pub(crate) id: Id,
pub(crate) ty: PhantomData<T>,
}

impl<T> Copy for WriteSignal<T> {}
impl<T: 'static> Copy for WriteSignal<T> {}

impl<T> Clone for WriteSignal<T> {
impl<T: 'static> Clone for WriteSignal<T> {
fn clone(&self) -> Self {
*self
}
}

impl<T> Eq for WriteSignal<T> {}
impl<T: Send + Sync> Eq for WriteSignal<T> {}

impl<T> PartialEq for WriteSignal<T> {
impl<T: Send + Sync> PartialEq for WriteSignal<T> {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
Expand Down
2 changes: 1 addition & 1 deletion renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ resvg = { workspace = true }
swash = { workspace = true }

cosmic-text = { version = "0.12.1", features = ["shape-run-cache"] }
floem-winit = { git = "https://github.com/lapce/winit", rev = "c8d3b8fd6fa4ffd5e0f99be78aacddcf6de57bcd", features = ["rwh_05"] }

winit = { workspace = true }
wgpu = { workspace = true }
crossbeam = { version = "0.8" }
futures = "0.3.26"
Expand Down
4 changes: 2 additions & 2 deletions renderer/src/gpu_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{future::Future, sync::Arc};
use crossbeam::channel::{self, Receiver};
use wgpu::Backends;

use floem_winit::window::{Window, WindowId};
use winit::window::{Window, WindowId};

/// The acquired GPU resources needed for rendering with wgpu.
pub struct GpuResources {
Expand Down Expand Up @@ -45,7 +45,7 @@ impl GpuResources {
/// - `window`: The window to associate with the created surface.
pub fn request<F: Fn(WindowId) + 'static>(
on_result: F,
window: Arc<Window>,
window: Arc<dyn Window>,
) -> Receiver<Result<Self, GpuResourceError>> {
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: wgpu::util::backend_bits_from_env().unwrap_or(Backends::all()),
Expand Down
11 changes: 7 additions & 4 deletions src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use std::sync::atomic::AtomicU64;

use floem_reactive::SignalWith;
use floem_winit::window::ResizeDirection;
use peniko::kurbo::{Point, Size, Vec2};
use winit::window::ResizeDirection;

#[cfg(not(target_arch = "wasm32"))]
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -80,7 +80,7 @@ pub fn inspect() {

pub(crate) struct Timer {
pub(crate) token: TimerToken,
pub(crate) action: Box<dyn FnOnce(TimerToken)>,
pub(crate) action: Box<dyn FnOnce(TimerToken) + Send + Sync>,
pub(crate) deadline: Instant,
}

Expand Down Expand Up @@ -116,7 +116,10 @@ impl TimerToken {
}

/// Execute a callback after a specified duration
pub fn exec_after(duration: Duration, action: impl FnOnce(TimerToken) + 'static) -> TimerToken {
pub fn exec_after(
duration: Duration,
action: impl FnOnce(TimerToken) + 'static + Send + Sync,
) -> TimerToken {
let view = get_current_view();
let action = move |token| {
let current_view = get_current_view();
Expand All @@ -143,7 +146,7 @@ pub fn exec_after(duration: Duration, action: impl FnOnce(TimerToken) + 'static)
pub fn debounce_action<T, F>(signal: impl SignalWith<T> + 'static, duration: Duration, action: F)
where
T: std::hash::Hash + 'static,
F: Fn() + Clone + 'static,
F: Fn() + Clone + 'static + Send + Sync,
{
crate::reactive::create_stateful_updater(
move |prev_opt: Option<(u64, Option<TimerToken>)>| {
Expand Down
4 changes: 2 additions & 2 deletions src/animate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::{
ViewId,
};

use std::any::Any;
use std::rc::Rc;
use std::{any::Any, sync::Arc};

use floem_reactive::{create_updater, RwSignal, SignalGet, Trigger};
use smallvec::{smallvec, SmallVec};
Expand All @@ -24,7 +24,7 @@ use web_time::{Duration, Instant};
#[derive(Clone, Debug)]
pub struct KeyFrameProp {
// the style prop value. This will either come from an animation frameor it will be pulled from the computed style
val: Rc<dyn Any>,
val: Arc<dyn Any>,
// the frame id
id: u16,
/// This easing will be used while animating towards this keyframe. while this prop is the lower one this easing function will not be used.
Expand Down
Loading
Loading