From 67afe678167ebac4f6287748e033e5a3440d082e Mon Sep 17 00:00:00 2001 From: Werick da Silva Santana <86405438+werickdasilva@users.noreply.github.com> Date: Mon, 29 Jul 2024 06:12:01 -0300 Subject: [PATCH] masonry: add pressure sensitivity to the pen's touch on the screen (#453) device test * huion kamvas 13 tablet windows 10 platform --- masonry/src/event.rs | 4 +++- masonry/src/event_loop_runner.rs | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/masonry/src/event.rs b/masonry/src/event.rs index ec006bb9d..309ad9c0c 100644 --- a/masonry/src/event.rs +++ b/masonry/src/event.rs @@ -10,7 +10,7 @@ use crate::WidgetId; use std::{collections::HashSet, path::PathBuf}; -use winit::event::{Ime, KeyEvent, Modifiers}; +use winit::event::{Force, Ime, KeyEvent, Modifiers}; use winit::keyboard::ModifiersState; // TODO - Occluded(bool) event @@ -95,6 +95,7 @@ pub struct PointerState { pub mods: Modifiers, pub count: u8, pub focus: bool, + pub force: Option, } #[derive(Debug, Clone)] @@ -351,6 +352,7 @@ impl PointerState { mods: Default::default(), count: 0, focus: false, + force: None, } } } diff --git a/masonry/src/event_loop_runner.rs b/masonry/src/event_loop_runner.rs index 57349fb14..04b55ae70 100644 --- a/masonry/src/event_loop_runner.rs +++ b/masonry/src/event_loop_runner.rs @@ -497,12 +497,16 @@ impl MasonryState<'_> { )); } WinitWindowEvent::Touch(winit::event::Touch { - location, phase, .. + location, + phase, + force, + .. }) => { // FIXME: This is naïve and should be refined for actual use. // It will also interact with gesture discrimination. self.pointer_state.physical_position = location; self.pointer_state.position = location.to_logical(window.scale_factor()); + self.pointer_state.force = force; match phase { winit::event::TouchPhase::Started => { self.render_root