From 58ec4760a50f99981574d01b2e636e81729ea870 Mon Sep 17 00:00:00 2001 From: Imbris Date: Fri, 18 Dec 2020 23:07:38 -0500 Subject: [PATCH] Move to WindowEvent from DeviceEvent for zooming --- CHANGELOG.md | 1 + voxygen/src/window.rs | 39 +++++++++++++++++---------------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e2970b08f..ad15edfbf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 a projectile in very specific circumstances - Fixed a bug where buff/debuff UI elements would flicker when you had more than one of them active at the same time +- Made zooming work on wayland ## [0.8.0] - 2020-11-28 diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index 664ab3f735..0f09c0bee5 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -891,28 +891,6 @@ impl Window { self.events.push(Event::CursorMove(delta)); } }, - DeviceEvent::MouseWheel { delta, .. } if self.cursor_grabbed && self.focused => { - self.events.push(Event::Zoom({ - // Since scrolling apparently acts different depending on platform - #[cfg(target_os = "windows")] - const PLATFORM_FACTOR: f32 = -4.0; - #[cfg(not(target_os = "windows"))] - const PLATFORM_FACTOR: f32 = 1.0; - - let y = match delta { - winit::event::MouseScrollDelta::LineDelta(_x, y) => y, - // TODO: Check to see if there is a better way to find the "line - // height" than just hardcoding 16.0 pixels. Alternately we could - // get rid of this and have the user set zoom sensitivity, since - // it's unlikely people would expect a configuration file to work - // across operating systems. - winit::event::MouseScrollDelta::PixelDelta(pos) => (pos.y / 16.0) as f32, - }; - y * (self.zoom_sensitivity as f32 / 100.0) - * if self.zoom_inversion { -1.0 } else { 1.0 } - * PLATFORM_FACTOR - })) - }, _ => {}, } } @@ -1047,6 +1025,23 @@ impl Window { WindowEvent::CursorMoved { position, .. } => { self.cursor_position = position; }, + WindowEvent::MouseWheel { delta, .. } if self.cursor_grabbed && self.focused => { + const DIFFERENCE_FROM_DEVICE_EVENT_ON_X11: f32 = -15.0; + self.events.push(Event::Zoom({ + let y = match delta { + winit::event::MouseScrollDelta::LineDelta(_x, y) => y, + // TODO: Check to see if there is a better way to find the "line + // height" than just hardcoding 16.0 pixels. Alternately we could + // get rid of this and have the user set zoom sensitivity, since + // it's unlikely people would expect a configuration file to work + // across operating systems. + winit::event::MouseScrollDelta::PixelDelta(pos) => (pos.y / 16.0) as f32, + }; + y * (self.zoom_sensitivity as f32 / 100.0) + * if self.zoom_inversion { -1.0 } else { 1.0 } + * DIFFERENCE_FROM_DEVICE_EVENT_ON_X11 + })) + }, _ => {}, } }