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

Port To Winit #3676

Draft
wants to merge 10 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
703 changes: 580 additions & 123 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ tracing-wasm = "0.2.1"
console_error_panic_hook = "0.1.7"

# desktop
wry = { version = "0.45.0", default-features = false }
tao = { version = "0.30.8", features = ["rwh_05"] }
wry = { version = "0.48.1", default-features = false }
winit = { version = "0.30.8", features = ["rwh_05"] }
webbrowser = "1.0.1"
infer = "0.16.0"
dunce = "1.0.5"
Expand Down
6 changes: 4 additions & 2 deletions example-projects/file-explorer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
use std::env::current_dir;
use std::path::PathBuf;

use dioxus::desktop::{Config, WindowBuilder};
use dioxus::desktop::{Config, Window};
use dioxus::prelude::*;

fn main() {
dioxus::LaunchBuilder::desktop()
.with_cfg(Config::new().with_window(WindowBuilder::new().with_resizable(true)))
.with_cfg(
Config::new().with_window_attributes(Window::default_attributes().with_resizable(true)),
)
.launch(app)
}

Expand Down
6 changes: 3 additions & 3 deletions examples/calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const STYLE: Asset = asset!("/examples/assets/calculator.css");
fn main() {
dioxus::LaunchBuilder::desktop()
.with_cfg(desktop!({
use dioxus::desktop::{Config, LogicalSize, WindowBuilder};
Config::new().with_window(
WindowBuilder::default()
use dioxus::desktop::{Config, LogicalSize, Window};
Config::new().with_window_attributes(
Window::default_attributes()
.with_title("Calculator")
.with_inner_size(LogicalSize::new(300.0, 525.0)),
)
Expand Down
8 changes: 4 additions & 4 deletions examples/calculator_mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
//! Generally, you'll want to split your state into several signals if you have a large application, but for small
//! applications, or focused components, this is a great way to manage state.

use dioxus::desktop::tao::dpi::LogicalSize;
use dioxus::desktop::{Config, WindowBuilder};
use dioxus::desktop::winit::dpi::LogicalSize;
use dioxus::desktop::{Config, Window};
use dioxus::html::input_data::keyboard_types::Key;
use dioxus::html::MouseEvent;
use dioxus::prelude::*;

fn main() {
dioxus::LaunchBuilder::desktop()
.with_cfg(
Config::new().with_window(
WindowBuilder::new()
Config::new().with_window_attributes(
Window::default_attributes()
.with_title("Calculator Demo")
.with_resizable(false)
.with_inner_size(LogicalSize::new(320.0, 530.0)),
Expand Down
4 changes: 2 additions & 2 deletions examples/crm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use dioxus::prelude::*;
fn main() {
dioxus::LaunchBuilder::new()
.with_cfg(desktop!({
use dioxus::desktop::{LogicalSize, WindowBuilder};
use dioxus::desktop::{LogicalSize, Window};
dioxus::desktop::Config::default()
.with_window(WindowBuilder::new().with_inner_size(LogicalSize::new(800, 600)))
.with_window_attributes(Window::default_attributes().with_inner_size(LogicalSize::new(800, 600)))
}))
.launch(|| {
rsx! {
Expand Down
14 changes: 7 additions & 7 deletions examples/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
//!
//! We also add a global shortcut to toggle the overlay on and off, so you could build a raycast-type app with this.

use dioxus::desktop::{
tao::dpi::PhysicalPosition, use_global_shortcut, LogicalSize, WindowBuilder,
};
use dioxus::desktop::{use_global_shortcut, winit::dpi::PhysicalPosition, LogicalSize, Window};
use dioxus::mobile::winit::window::WindowLevel;
use dioxus::mobile::WindowAttributes;
use dioxus::prelude::*;

fn main() {
Expand Down Expand Up @@ -47,15 +47,15 @@ fn app() -> Element {
}

fn make_config() -> dioxus::desktop::Config {
dioxus::desktop::Config::default().with_window(make_window())
dioxus::desktop::Config::default().with_window_attributes(make_window())
}

fn make_window() -> WindowBuilder {
WindowBuilder::new()
fn make_window() -> WindowAttributes {
Window::default_attributes()
.with_transparent(true)
.with_decorations(false)
.with_resizable(false)
.with_always_on_top(true)
.with_window_level(WindowLevel::AlwaysOnTop)
.with_position(PhysicalPosition::new(0, 0))
.with_max_inner_size(LogicalSize::new(100000, 50))
}
6 changes: 3 additions & 3 deletions examples/suspense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
//! We can achieve the majority of suspense functionality by composing "suspenseful"
//! primitives in our own custom components.

use dioxus::desktop::{Config, LogicalSize, WindowBuilder};
use dioxus::desktop::{Config, LogicalSize, Window};
use dioxus::prelude::*;

fn main() {
dioxus::LaunchBuilder::new()
.with_cfg(desktop! {
Config::new().with_window(
WindowBuilder::new()
Config::new().with_window_attributes(
Window::default_attributes()
.with_title("Doggo Fetcher")
.with_inner_size(LogicalSize::new(600.0, 800.0)),
)
Expand Down
25 changes: 15 additions & 10 deletions examples/wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
//! To use this feature set `with_as_child_window()` on your desktop config which will then let you

use dioxus::desktop::{
tao::{event::Event as WryEvent, window::WindowBuilder},
use_wry_event_handler, window, Config, DesktopContext,
use_wry_event_handler, window, winit::event::Event as WryEvent, Config, DesktopContext, Window,
};
use dioxus::prelude::*;

fn main() {
let config = Config::new()
.with_window(WindowBuilder::new().with_transparent(true))
.with_window_attributes(Window::default_attributes().with_transparent(true))
.with_as_child_window();

dioxus::LaunchBuilder::desktop()
Expand All @@ -37,9 +36,13 @@ fn app() -> Element {
});

use_wry_event_handler(move |event, _| {
use dioxus::desktop::tao::event::WindowEvent;
use dioxus::desktop::winit::event::WindowEvent;

if let WryEvent::RedrawRequested(_id) = event {
if let WryEvent::WindowEvent {
event: WindowEvent::RedrawRequested,
..
} = event
{
let resources = graphics_resources.read();
if let Some(resources) = resources.as_ref() {
resources.with_resources(|resources| resources.render());
Expand All @@ -52,11 +55,13 @@ fn app() -> Element {
} = event
{
let ctx = graphics_resources.value();
ctx.as_ref().unwrap().with_resources(|srcs| {
let mut cfg = srcs.config.clone();
cfg.width = new_size.width;
cfg.height = new_size.height;
srcs.surface.configure(&srcs.device, &cfg);
ctx.as_ref().map(|x| {
x.with_resources(|srcs| {
let mut cfg = srcs.config.clone();
cfg.width = new_size.width;
cfg.height = new_size.height;
srcs.surface.configure(&srcs.device, &cfg);
})
});
window().window.request_redraw();
}
Expand Down
13 changes: 9 additions & 4 deletions examples/window_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
//!
//! The entire featuresuite of wry and tao is available to you

use dioxus::desktop::{window, Config, WindowBuilder};
use dioxus::desktop::{window, Config, Window};
use dioxus::mobile::winit::window::WindowLevel;
use dioxus::prelude::*;

fn main() {
dioxus::LaunchBuilder::desktop()
.with_cfg(
Config::new().with_window(
WindowBuilder::new()
Config::new().with_window_attributes(
Window::default_attributes()
.with_title("Borderless Window")
.with_decorations(false),
),
Expand Down Expand Up @@ -93,7 +94,11 @@ fn SetOnTop() -> Element {
class: "inline-flex items-center text-white bg-green-500 border-0 py-1 px-3 hover:bg-green-700 rounded",
onmousedown: |evt| evt.stop_propagation(),
onclick: move |_| {
window().set_always_on_top(!always_on_top());
let window_level = match always_on_top() {
true => WindowLevel::AlwaysOnTop,
false => WindowLevel::Normal,
};
window().set_window_level(window_level);
always_on_top.toggle();
},
"Always On Top"
Expand Down
4 changes: 2 additions & 2 deletions examples/window_focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
//!
//! This lets you do things like backgrounding tasks, pausing animations, or changing the UI when the window is focused or not.

use dioxus::desktop::tao::event::Event as WryEvent;
use dioxus::desktop::tao::event::WindowEvent;
use dioxus::desktop::use_wry_event_handler;
use dioxus::desktop::winit::event::Event as WryEvent;
use dioxus::desktop::winit::event::WindowEvent;
use dioxus::desktop::{Config, WindowCloseBehaviour};
use dioxus::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ dioxus-hooks = { workspace = true }
futures-util = { workspace = true }
urlencoding = "2.1.2"
async-trait = "0.1.68"
tao = { workspace = true, features = ["rwh_05"] }
winit = { workspace = true, features = ["rwh_05"] }
once_cell = { workspace = true }
dioxus-history.workspace = true
base64.workspace = true
Expand Down
6 changes: 4 additions & 2 deletions packages/desktop/headless_tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use dioxus::prelude::*;
use dioxus_core::Element;

pub fn check_app_exits(app: fn() -> Element) {
use dioxus_desktop::tao::window::WindowBuilder;
use dioxus_desktop::Config;
use dioxus_desktop::Window;
// This is a deadman's switch to ensure that the app exits
let should_panic = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(true));
let should_panic_clone = should_panic.clone();
Expand All @@ -18,7 +18,9 @@ pub fn check_app_exits(app: fn() -> Element) {
});

dioxus::LaunchBuilder::desktop()
.with_cfg(Config::new().with_window(WindowBuilder::new().with_visible(false)))
.with_cfg(
Config::new().with_window_attributes(Window::default_attributes().with_visible(false)),
)
.launch(app);

// Stop deadman's switch
Expand Down
Loading