Skip to content

Commit

Permalink
Update to to winit 0.28 (emilk#2654)
Browse files Browse the repository at this point in the history
* Update to winit 0.28

Mac trackpads pinch gestures will now generate `egui::Event::Zoom`

* Update accesskit_winit

* Try to get Android CI green

* Fix wayland compilation

* Add comment about android-activity

* Update changelogs

* Fix call to register_xlib_error_hook
  • Loading branch information
emilk authored and lictex committed Feb 5, 2023
1 parent dd448aa commit 590dba6
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 252 deletions.
377 changes: 150 additions & 227 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/eframe/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ NOTE: [`egui-winit`](../egui-winit/CHANGELOG.md), [`egui_glium`](../egui_glium/C

#### Desktop/Native:
* `eframe::run_native` now returns a `Result` ([#2433](https://github.com/emilk/egui/pull/2433)).
* Update to `winit` 0.28, adding support for mac trackpad zoom ([#2654](https://github.com/emilk/egui/pull/2654)).

#### Web:
* Prevent ctrl-P/cmd-P from opening the print dialog ([#2598](https://github.com/emilk/egui/pull/2598)).
Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ egui-winit = { version = "0.20.0", path = "../egui-winit", default-features = fa
"links",
] }
raw-window-handle = { version = "0.5.0" }
winit = "0.27.2"
winit = "0.28"

# optional native:
dark-light = { version = "1.0", optional = true }
Expand Down
19 changes: 16 additions & 3 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ pub fn build_window<E>(

let mut window_builder = winit::window::WindowBuilder::new()
.with_title(title)
.with_always_on_top(*always_on_top)
.with_decorations(*decorated)
.with_fullscreen(fullscreen.then(|| winit::window::Fullscreen::Borderless(None)))
.with_maximized(*maximized)
Expand Down Expand Up @@ -143,7 +142,16 @@ pub fn build_window<E>(
}
}

window_builder.build(event_loop)
let window = window_builder.build(event_loop)?;

use winit::window::WindowLevel;
window.set_window_level(if *always_on_top {
WindowLevel::AlwaysOnTop
} else {
WindowLevel::Normal
});

Ok(window)
}

fn largest_monitor_point_size<E>(event_loop: &EventLoopWindowTarget<E>) -> egui::Vec2 {
Expand Down Expand Up @@ -235,7 +243,12 @@ pub fn handle_app_output(
}

if let Some(always_on_top) = always_on_top {
window.set_always_on_top(always_on_top);
use winit::window::WindowLevel;
window.set_window_level(if always_on_top {
WindowLevel::AlwaysOnTop
} else {
WindowLevel::Normal
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ mod glow_integration {
// try egl and fallback to x11 glx
#[cfg(target_os = "linux")]
let preference = glutin::display::DisplayApiPreference::EglThenGlx(Box::new(
winit::platform::unix::register_xlib_error_hook,
winit::platform::x11::register_xlib_error_hook,
));
#[cfg(target_os = "macos")]
let preference = glutin::display::DisplayApiPreference::Cgl;
Expand Down
2 changes: 1 addition & 1 deletion crates/egui-wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ wgpu = "0.15.0"
## Enable this when generating docs.
document-features = { version = "0.2", optional = true }

winit = { version = "0.27.2", optional = true }
winit = { version = "0.28", optional = true }

# Native:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
1 change: 1 addition & 0 deletions crates/egui-winit/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to the `egui-winit` integration will be noted in this file.


## Unreleased
* Update to `winit` 0.28, adding support for mac trackpad zoom ([#2654](https://github.com/emilk/egui/pull/2654)).
* Remove the `screen_reader` feature. Use the `accesskit` feature flag instead ([#2669](https://github.com/emilk/egui/pull/2669)).


Expand Down
12 changes: 8 additions & 4 deletions crates/egui-winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ instant = { version = "0.1", features = [
"wasm-bindgen",
] } # We use instant so we can (maybe) compile for web
tracing = { version = "0.1", default-features = false, features = ["std"] }
winit = { version = "0.27.2", default-features = false }
winit = { version = "0.28", default-features = false }

#! ### Optional dependencies

# feature accesskit
accesskit_winit = { version = "0.9.0", optional = true }

## Enable this when generating docs.
document-features = { version = "0.2", optional = true }

# feature accesskit
accesskit_winit = { version = "0.8.1", optional = true }

puffin = { version = "0.14", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] }

Expand All @@ -70,3 +70,7 @@ smithay-clipboard = { version = "0.6.3", optional = true }

[target.'cfg(not(target_os = "android"))'.dependencies]
arboard = { version = "3.2", optional = true, default-features = false }

[target.'cfg(target_os = "android")'.dependencies]
# TODO(emilk): this is probably not the right place for specifying native-activity, but we need to do it somewhere for the CI
android-activity = { version = "0.4", features = ["native-activity"] }
36 changes: 22 additions & 14 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ pub use window_settings::WindowSettings;

use winit::event_loop::EventLoopWindowTarget;

#[cfg(feature = "wayland")]
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
use winit::platform::unix::EventLoopWindowTargetExtUnix;

pub fn native_pixels_per_point(window: &winit::window::Window) -> f32 {
window.scale_factor() as f32
}
Expand Down Expand Up @@ -377,8 +367,9 @@ impl State {
consumed: false,
}
}
WindowEvent::AxisMotion { .. }
| WindowEvent::CloseRequested

// Things that may require repaint:
WindowEvent::CloseRequested
| WindowEvent::CursorEntered { .. }
| WindowEvent::Destroyed
| WindowEvent::Occluded(_)
Expand All @@ -388,10 +379,26 @@ impl State {
repaint: true,
consumed: false,
},
WindowEvent::Moved(_) => EventResponse {
repaint: false, // moving a window doesn't warrant a repaint

// Things we completely ignore:
WindowEvent::AxisMotion { .. }
| WindowEvent::Moved(_)
| WindowEvent::SmartMagnify { .. }
| WindowEvent::TouchpadRotate { .. } => EventResponse {
repaint: false,
consumed: false,
},

WindowEvent::TouchpadMagnify { delta, .. } => {
// Positive delta values indicate magnification (zooming in).
// Negative delta values indicate shrinking (zooming out).
let zoom_factor = (*delta as f32).exp();
self.egui_input.events.push(egui::Event::Zoom(zoom_factor));
EventResponse {
repaint: true,
consumed: egui_ctx.wants_pointer_input(),
}
}
}
}

Expand Down Expand Up @@ -871,6 +878,7 @@ fn wayland_display<T>(_event_loop: &EventLoopWindowTarget<T>) -> Option<*mut c_v
target_os = "openbsd"
))]
{
use winit::platform::wayland::EventLoopWindowTargetExtWayland as _;
return _event_loop.wayland_display();
}

Expand Down
2 changes: 1 addition & 1 deletion crates/egui_glow/examples/pure_glow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl GlutinWindowContext {
// try egl and fallback to x11 glx
#[cfg(target_os = "linux")]
let preference = glutin::display::DisplayApiPreference::EglThenGlx(Box::new(
winit::platform::unix::register_xlib_error_hook,
winit::platform::x11::register_xlib_error_hook,
));
#[cfg(target_os = "macos")]
let preference = glutin::display::DisplayApiPreference::Cgl;
Expand Down

0 comments on commit 590dba6

Please sign in to comment.