Skip to content

Commit a6bff21

Browse files
authored
Update to glutin 0.22.0 and winit 0.20.0 release (#268)
Thanks to @mwkroening (#317) and @martijnberger (#323) for helping fix this update. * Update to glutin 0.22.0 and winit 0.20.0 release, removing alpha pinning * scale_factor() replaces hidpi_factor() * Listen for ScaleFactorChanged, separate from Resized event * Fix getting physical size of window * Fix logical mouse event coordinates
1 parent a42d9a6 commit a6bff21

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

Cargo.lock

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ opt-level = 1
2121
cfg-if = "0.1.9"
2222
wasm-bindgen = "0.2.44"
2323
sha-1 = "0.8.2"
24-
glutin = "=0.22.0-alpha5"
24+
glutin = "0.22.0"
2525
byteorder = "1.3.4"
2626
serde = "1.0.104"
2727
serde_json = "1.0.55"
@@ -45,7 +45,7 @@ reqwest = { version = "0.10.6", features = [ "blocking" ]}
4545

4646
[target.'cfg(target_arch = "wasm32")'.dependencies]
4747
stdweb = "0.4.20"
48-
winit = { version = "=0.20.0-alpha6", features = [ "stdweb" ]}
48+
winit = { version = "0.20.0", features = [ "stdweb" ]}
4949

5050
[dependencies.steven_gl]
5151
path = "./gl"

src/main.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ fn main2() {
276276
}
277277

278278
let textures = renderer.get_textures();
279-
let dpi_factor = window.window().current_monitor().hidpi_factor();
279+
let dpi_factor = window.window().current_monitor().scale_factor();
280280
let default_protocol_version = protocol::versions::protocol_name_to_protocol_version(
281281
opt.default_protocol_version.unwrap_or("".to_string()));
282282
let mut game = Game {
@@ -322,8 +322,9 @@ fn main2() {
322322
let diff = now.duration_since(last_frame);
323323
last_frame = now;
324324
let delta = (diff.subsec_nanos() as f64) / frame_time;
325-
let (width, height) = window.window().inner_size().into();
326-
let (physical_width, physical_height) = window.window().inner_size().to_physical(game.dpi_factor).into();
325+
let physical_size = window.window().inner_size();
326+
let (physical_width, physical_height) = physical_size.into();
327+
let (width, height) = physical_size.to_logical::<f64>(game.dpi_factor).into();
327328

328329
let version = {
329330
let try_res = game.resource_manager.try_write();
@@ -436,10 +437,12 @@ fn handle_window_event<T>(window: &mut glutin::WindowedContext<glutin::PossiblyC
436437

437438
Event::WindowEvent{event, ..} => match event {
438439
WindowEvent::CloseRequested => game.should_close = true,
439-
WindowEvent::Resized(logical_size) => {
440-
game.dpi_factor = window.window().hidpi_factor();
441-
window.resize(logical_size.to_physical(game.dpi_factor));
440+
WindowEvent::Resized(physical_size) => {
441+
window.resize(physical_size);
442442
},
443+
WindowEvent::ScaleFactorChanged{scale_factor, ..} => {
444+
game.dpi_factor = scale_factor;
445+
}
443446

444447
WindowEvent::ReceivedCharacter(codepoint) => {
445448
if !game.focused {
@@ -450,7 +453,7 @@ fn handle_window_event<T>(window: &mut glutin::WindowedContext<glutin::PossiblyC
450453
WindowEvent::MouseInput{state, button, ..} => {
451454
match (state, button) {
452455
(ElementState::Released, MouseButton::Left) => {
453-
let (width, height) = window.window().inner_size().into();
456+
let (width, height) = window.window().inner_size().to_logical::<f64>(game.dpi_factor).into();
454457

455458
if game.server.is_connected() && !game.focused && !game.screen_sys.is_current_closable() {
456459
game.focused = true;
@@ -478,7 +481,7 @@ fn handle_window_event<T>(window: &mut glutin::WindowedContext<glutin::PossiblyC
478481
game.last_mouse_y = y;
479482

480483
if !game.focused {
481-
let (width, height) = window.window().inner_size().into();
484+
let (width, height) = window.window().inner_size().to_logical::<f64>(game.dpi_factor).into();
482485
ui_container.hover_at(game, x, y, width, height);
483486
}
484487
},

0 commit comments

Comments
 (0)