mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 22:31:30 +11:00
Add phases to wheel events.
Needed for apps to support overscroll on the Mac.
This commit is contained in:
parent
2638db665a
commit
7886ff9acd
|
@ -42,10 +42,10 @@ use std::sync::Mutex;
|
|||
use std::ascii::AsciiExt;
|
||||
use std::ops::Deref;
|
||||
|
||||
use events::Event::{Awakened, MouseInput, MouseMoved, ReceivedCharacter, KeyboardInput, MouseWheel, Closed, Focused, TouchpadPressure};
|
||||
use events::ElementState::{Pressed, Released};
|
||||
use events::MouseButton;
|
||||
use events;
|
||||
use events::Event::{Awakened, MouseInput, MouseMoved, ReceivedCharacter, KeyboardInput};
|
||||
use events::Event::{MouseWheel, Closed, Focused, TouchpadPressure};
|
||||
use events::{self, MouseButton, TouchPhase};
|
||||
|
||||
pub use self::monitor::{MonitorId, get_available_monitors, get_primary_monitor};
|
||||
pub use self::headless::HeadlessContext;
|
||||
|
@ -891,7 +891,12 @@ unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option<Event> {
|
|||
LineDelta(scale_factor * nsevent.scrollingDeltaX() as f32,
|
||||
scale_factor * nsevent.scrollingDeltaY() as f32)
|
||||
};
|
||||
Some(MouseWheel(delta))
|
||||
let phase = match nsevent.phase() {
|
||||
NSEventPhaseMayBegin | NSEventPhaseBegan => TouchPhase::Started,
|
||||
NSEventPhaseEnded => TouchPhase::Ended,
|
||||
_ => TouchPhase::Moved,
|
||||
};
|
||||
Some(MouseWheel(delta, phase))
|
||||
},
|
||||
NSEventTypePressure => {
|
||||
Some(TouchpadPressure(nsevent.pressure(), nsevent.stage()))
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use TouchPhase;
|
||||
use Event as GlutinEvent;
|
||||
use ElementState;
|
||||
use MouseButton;
|
||||
|
@ -98,7 +99,8 @@ pub fn translate_event(
|
|||
WlPointerAxis::HorizontalScroll => {
|
||||
MouseScrollDelta::PixelDelta(0.0, amplitude as f32)
|
||||
}
|
||||
}
|
||||
},
|
||||
TouchPhase::Moved
|
||||
), surface))
|
||||
} else {
|
||||
None
|
||||
|
@ -107,4 +109,4 @@ pub fn translate_event(
|
|||
},
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,12 +134,13 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
|
|||
winapi::WM_MOUSEWHEEL => {
|
||||
use events::Event::MouseWheel;
|
||||
use events::MouseScrollDelta::LineDelta;
|
||||
use events::TouchPhase;
|
||||
|
||||
let value = (wparam >> 16) as i16;
|
||||
let value = value as i32;
|
||||
let value = value as f32 / winapi::WHEEL_DELTA as f32;
|
||||
|
||||
send_event(window, MouseWheel(LineDelta(0.0, value)));
|
||||
send_event(window, MouseWheel(LineDelta(0.0, value), TouchPhase::Moved));
|
||||
|
||||
0
|
||||
},
|
||||
|
|
|
@ -201,7 +201,7 @@ impl XInputEventHandler {
|
|||
} else {
|
||||
-1.0
|
||||
};
|
||||
Some(MouseWheel(LineDelta(0.0, delta)))
|
||||
Some(MouseWheel(LineDelta(0.0, delta), TouchPhase::Moved))
|
||||
} else {
|
||||
// emulated button event from a touch/smooth-scroll
|
||||
// event. Ignore these events and handle scrolling
|
||||
|
@ -235,7 +235,8 @@ impl XInputEventHandler {
|
|||
}
|
||||
|
||||
if scroll_delta.0.abs() > 0.0 || scroll_delta.1.abs() > 0.0 {
|
||||
Some(MouseWheel(LineDelta(scroll_delta.0 as f32, scroll_delta.1 as f32)))
|
||||
Some(MouseWheel(LineDelta(scroll_delta.0 as f32, scroll_delta.1 as f32),
|
||||
TouchPhase::Moved))
|
||||
} else {
|
||||
let new_cursor_pos = (event_data.event_x, event_data.event_y);
|
||||
if new_cursor_pos != self.current_state.cursor_pos {
|
||||
|
|
|
@ -31,7 +31,7 @@ pub enum Event {
|
|||
MouseMoved((i32, i32)),
|
||||
|
||||
/// A mouse wheel movement or touchpad scroll occurred.
|
||||
MouseWheel(MouseScrollDelta),
|
||||
MouseWheel(MouseScrollDelta, TouchPhase),
|
||||
|
||||
/// An event from the mouse has been received.
|
||||
MouseInput(ElementState, MouseButton),
|
||||
|
|
Loading…
Reference in a new issue