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 use raw-window-handle v0.6 #2943

Closed
wants to merge 12 commits into from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- On macOS, add tabbing APIs on `WindowExtMacOS` and `EventLoopWindowTargetExtMacOS`.
- **Breaking:** Rename `Window::set_inner_size` to `Window::request_inner_size` and indicate if the size was applied immediately.
- On X11, fix false positive flagging of key repeats when pressing different keys with no release between presses.
- Port types to use `raw-window-handle` v0.6. `raw-window-handle` v0.5 is still supported.
- Implement `PartialOrd` and `Ord` for `KeyCode` and `NativeKeyCode`.
- On Web, implement `WindowEvent::Occluded`.
- On Web, fix touch location to be as accurate as mouse position.
Expand Down
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ cursor-icon = "1.0.0"
log = "0.4"
mint = { version = "0.5.6", optional = true }
once_cell = "1.12"
raw_window_handle = { package = "raw-window-handle", version = "0.5", features = ["std"] }
raw_window_handle = { package = "raw-window-handle", version = "0.6", features = ["std"] }
raw_window_handle_05 = { package = "raw-window-handle", version = "0.5" }
madsmtm marked this conversation as resolved.
Show resolved Hide resolved
serde = { version = "1", optional = true, features = ["serde_derive"] }
smol_str = "0.2.0"

Expand Down Expand Up @@ -206,3 +207,7 @@ web-sys = { version = "0.3.22", features = ['CanvasRenderingContext2d'] }
members = [
"run-wasm",
]

[patch.crates-io]
softbuffer = { git = "https://github.com/rust-windowing/softbuffer.git", branch = "notgull/rwh-v0.6" }
raw_window_handle = { package = "raw-window-handle", git = "https://github.com/rust-windowing/raw-window-handle.git", branch = "notgull/next" }
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ skip = [
{ name = "num_enum"}, # See above ^, waiting for release
{ name = "num_enum_derive"},# See above ^, waiting for release
{ name = "miniz_oxide"}, # https://github.com/rust-lang/flate2-rs/issues/340
{ name = "raw-window-handle" }, # https://github.com/rust-windowing/raw-window-handle/issues/125, slow transition
{ name = "redox_syscall" }, # https://gitlab.redox-os.org/redox-os/orbclient/-/issues/46
]
skip-tree = []
Expand Down
21 changes: 12 additions & 9 deletions examples/child_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod fill;
#[cfg(any(x11_platform, macos_platform, windows_platform))]
fn main() -> Result<(), impl std::error::Error> {
use std::collections::HashMap;
use std::rc::Rc;

use raw_window_handle::HasRawWindowHandle;
use winit::{
Expand All @@ -17,17 +18,17 @@ fn main() -> Result<(), impl std::error::Error> {
fn spawn_child_window(
parent: &Window,
event_loop: &EventLoopWindowTarget<()>,
windows: &mut HashMap<WindowId, Window>,
windows: &mut HashMap<WindowId, Rc<Window>>,
) {
let parent = parent.raw_window_handle();
let parent = parent.raw_window_handle().unwrap();
let mut builder = WindowBuilder::new()
.with_title("child window")
.with_inner_size(LogicalSize::new(200.0f32, 200.0f32))
.with_position(Position::Logical(LogicalPosition::new(0.0, 0.0)))
.with_visible(true);
// `with_parent_window` is unsafe. Parent window must be a valid window.
builder = unsafe { builder.with_parent_window(Some(parent)) };
let child_window = builder.build(event_loop).unwrap();
let child_window = Rc::new(builder.build(event_loop).unwrap());

let id = child_window.id();
windows.insert(id, child_window);
Expand All @@ -37,12 +38,14 @@ fn main() -> Result<(), impl std::error::Error> {
let mut windows = HashMap::new();

let event_loop: EventLoop<()> = EventLoop::new();
let parent_window = WindowBuilder::new()
.with_title("parent window")
.with_position(Position::Logical(LogicalPosition::new(0.0, 0.0)))
.with_inner_size(LogicalSize::new(640.0f32, 480.0f32))
.build(&event_loop)
.unwrap();
let parent_window = Rc::new(
madsmtm marked this conversation as resolved.
Show resolved Hide resolved
WindowBuilder::new()
.with_title("parent window")
.with_position(Position::Logical(LogicalPosition::new(0.0, 0.0)))
.with_inner_size(LogicalSize::new(640.0f32, 480.0f32))
.build(&event_loop)
.unwrap(),
);

println!("parent window: {parent_window:?})");

Expand Down
13 changes: 9 additions & 4 deletions examples/control_flow.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(clippy::single_match)]

use std::rc::Rc;
use std::thread;
#[cfg(not(wasm_platform))]
use std::time;
Expand Down Expand Up @@ -37,10 +38,14 @@ fn main() -> Result<(), impl std::error::Error> {
println!("Press 'Esc' to close the window.");

let event_loop = EventLoop::new();
let window = WindowBuilder::new()
.with_title("Press 1, 2, 3 to change control flow mode. Press R to toggle redraw requests.")
.build(&event_loop)
.unwrap();
let window = Rc::new(
WindowBuilder::new()
.with_title(
"Press 1, 2, 3 to change control flow mode. Press R to toggle redraw requests.",
)
.build(&event_loop)
.unwrap(),
);

let mut mode = Mode::Wait;
let mut request_redraw = false;
Expand Down
3 changes: 2 additions & 1 deletion examples/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use std::rc::Rc;
use winit::{
event::{ElementState, Event, KeyEvent, WindowEvent},
event_loop::EventLoop,
Expand All @@ -14,7 +15,7 @@ fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

let window = WindowBuilder::new().build(&event_loop).unwrap();
let window = Rc::new(WindowBuilder::new().build(&event_loop).unwrap());
window.set_title("A fantastic window!");

let mut cursor_idx = 0;
Expand Down
11 changes: 7 additions & 4 deletions examples/cursor_grab.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use std::rc::Rc;
use winit::{
event::{DeviceEvent, ElementState, Event, KeyEvent, WindowEvent},
event_loop::EventLoop,
Expand All @@ -15,10 +16,12 @@ fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

let window = WindowBuilder::new()
.with_title("Super Cursor Grab'n'Hide Simulator 9000")
.build(&event_loop)
.unwrap();
let window = Rc::new(
WindowBuilder::new()
.with_title("Super Cursor Grab'n'Hide Simulator 9000")
.build(&event_loop)
.unwrap(),
);

let mut modifiers = ModifiersState::default();

Expand Down
11 changes: 7 additions & 4 deletions examples/custom_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#[cfg(not(wasm_platform))]
fn main() -> Result<(), impl std::error::Error> {
use simple_logger::SimpleLogger;
use std::rc::Rc;
use winit::{
event::{Event, WindowEvent},
event_loop::EventLoopBuilder,
Expand All @@ -20,10 +21,12 @@ fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoopBuilder::<CustomEvent>::with_user_event().build();

let window = WindowBuilder::new()
.with_title("A fantastic window!")
.build(&event_loop)
.unwrap();
let window = Rc::new(
WindowBuilder::new()
.with_title("A fantastic window!")
.build(&event_loop)
.unwrap(),
);

// `EventLoopProxy` allows you to dispatch custom events to the main Winit event
// loop from any thread.
Expand Down
5 changes: 3 additions & 2 deletions examples/drag_window.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use std::rc::Rc;
use winit::{
event::{ElementState, Event, KeyEvent, MouseButton, StartCause, WindowEvent},
event_loop::EventLoop,
Expand All @@ -15,8 +16,8 @@ fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

let window_1 = WindowBuilder::new().build(&event_loop).unwrap();
let window_2 = WindowBuilder::new().build(&event_loop).unwrap();
let window_1 = Rc::new(WindowBuilder::new().build(&event_loop).unwrap());
let window_2 = Rc::new(WindowBuilder::new().build(&event_loop).unwrap());

let mut switched = false;
let mut entered_id = window_2.id();
Expand Down
11 changes: 7 additions & 4 deletions examples/fullscreen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use std::rc::Rc;
use winit::dpi::PhysicalSize;
use winit::event::{ElementState, Event, KeyEvent, WindowEvent};
use winit::event_loop::EventLoop;
Expand All @@ -22,10 +23,12 @@ fn main() -> Result<(), impl std::error::Error> {
let mut with_min_size = false;
let mut with_max_size = false;

let window = WindowBuilder::new()
.with_title("Hello world!")
.build(&event_loop)
.unwrap();
let window = Rc::new(
WindowBuilder::new()
.with_title("Hello world!")
.build(&event_loop)
.unwrap(),
);

let mut monitor_index = 0;
let mut monitor = event_loop
Expand Down
11 changes: 7 additions & 4 deletions examples/handling_close.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use std::rc::Rc;
use winit::{
event::{ElementState, Event, KeyEvent, WindowEvent},
event_loop::EventLoop,
Expand All @@ -15,10 +16,12 @@ fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

let window = WindowBuilder::new()
.with_title("Your faithful window")
.build(&event_loop)
.unwrap();
let window = Rc::new(
WindowBuilder::new()
.with_title("Your faithful window")
.build(&event_loop)
.unwrap(),
);

let mut close_requested = false;

Expand Down
11 changes: 7 additions & 4 deletions examples/ime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use log::LevelFilter;
use simple_logger::SimpleLogger;
use std::rc::Rc;
use winit::{
dpi::{PhysicalPosition, PhysicalSize},
event::{ElementState, Event, Ime, WindowEvent},
Expand All @@ -26,10 +27,12 @@ fn main() -> Result<(), impl std::error::Error> {

let event_loop = EventLoop::new();

let window = WindowBuilder::new()
.with_inner_size(winit::dpi::LogicalSize::new(256f64, 128f64))
.build(&event_loop)
.unwrap();
let window = Rc::new(
WindowBuilder::new()
.with_inner_size(winit::dpi::LogicalSize::new(256f64, 128f64))
.build(&event_loop)
.unwrap(),
);

let mut ime_purpose = ImePurpose::Normal;
let mut ime_allowed = true;
Expand Down
12 changes: 8 additions & 4 deletions examples/key_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ fn main() {

#[cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))]
fn main() -> Result<(), impl std::error::Error> {
use std::rc::Rc;

#[path = "util/fill.rs"]
mod fill;

simple_logger::SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

let window = WindowBuilder::new()
.with_inner_size(LogicalSize::new(400.0, 200.0))
.build(&event_loop)
.unwrap();
let window = Rc::new(
WindowBuilder::new()
.with_inner_size(LogicalSize::new(400.0, 200.0))
.build(&event_loop)
.unwrap(),
);

let mut modifiers = ModifiersState::default();

Expand Down
11 changes: 7 additions & 4 deletions examples/mouse_wheel.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use std::rc::Rc;
use winit::{
event::{Event, WindowEvent},
event_loop::EventLoop,
Expand All @@ -14,10 +15,12 @@ fn main() -> Result<(), impl std::error::Error> {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

let window = WindowBuilder::new()
.with_title("Mouse Wheel events")
.build(&event_loop)
.unwrap();
let window = Rc::new(
WindowBuilder::new()
.with_title("Mouse Wheel events")
.build(&event_loop)
.unwrap(),
);

println!(
r"
Expand Down
17 changes: 12 additions & 5 deletions examples/multithreaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

#[cfg(not(wasm_platform))]
fn main() -> Result<(), impl std::error::Error> {
use std::{collections::HashMap, sync::mpsc, thread, time::Duration};
use std::{
collections::HashMap,
sync::{mpsc, Arc},
thread,
time::Duration,
};

use simple_logger::SimpleLogger;
use winit::{
Expand All @@ -20,10 +25,12 @@ fn main() -> Result<(), impl std::error::Error> {
let event_loop = EventLoop::new();
let mut window_senders = HashMap::with_capacity(WINDOW_COUNT);
for _ in 0..WINDOW_COUNT {
let window = WindowBuilder::new()
.with_inner_size(WINDOW_SIZE)
.build(&event_loop)
.unwrap();
let window = Arc::new(
WindowBuilder::new()
.with_inner_size(WINDOW_SIZE)
.build(&event_loop)
.unwrap(),
);

let mut video_modes: Vec<_> = window.current_monitor().unwrap().video_modes().collect();
let mut video_mode_id = 0usize;
Expand Down
5 changes: 3 additions & 2 deletions examples/multiwindow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::single_match)]

use std::collections::HashMap;
use std::rc::Rc;

use simple_logger::SimpleLogger;
use winit::{
Expand All @@ -19,7 +20,7 @@ fn main() -> Result<(), impl std::error::Error> {

let mut windows = HashMap::new();
for _ in 0..3 {
let window = Window::new(&event_loop).unwrap();
let window = Rc::new(Window::new(&event_loop).unwrap());
println!("Opened a new window: {:?}", window.id());
windows.insert(window.id(), window);
}
Expand Down Expand Up @@ -52,7 +53,7 @@ fn main() -> Result<(), impl std::error::Error> {
is_synthetic: false,
..
} if matches!(c.as_ref(), "n" | "N") => {
let window = Window::new(event_loop).unwrap();
let window = Rc::new(Window::new(event_loop).unwrap());
println!("Opened a new window: {:?}", window.id());
windows.insert(window.id(), window);
}
Expand Down
Loading