Skip to content

Commit

Permalink
Auto merge of #24597 - paulrouget:mouse, r=jdm
Browse files Browse the repository at this point in the history
UWP: More mouse events

Support more UWP Desktop events (mouse wheel, mouse move, etc).

This introduces a new issue, where the basic bbjs demo requires double click to select a color (unrelated to #24530 I believe). Filed #24596.

Next step is to properly fire touch events in HoloLens and only mouse events on Desktop (see #24587).
  • Loading branch information
bors-servo committed Nov 1, 2019
2 parents a355f41 + 112221f commit 48d918d
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 6 deletions.
8 changes: 4 additions & 4 deletions ports/libmlservo/src/lib.rs
Expand Up @@ -240,7 +240,7 @@ pub unsafe extern "C" fn move_servo(servo: *mut ServoInstance, x: f32, y: f32) {
match servo.scroll_state {
ScrollState::TriggerUp => {
servo.scroll_state = ScrollState::TriggerUp;
let _ = call(|s| s.move_mouse(x, y));
let _ = call(|s| s.mouse_move(x, y));
},
ScrollState::TriggerDown(start)
if (start - point).square_length() < DRAG_CUTOFF_SQUARED =>
Expand All @@ -249,14 +249,14 @@ pub unsafe extern "C" fn move_servo(servo: *mut ServoInstance, x: f32, y: f32) {
}
ScrollState::TriggerDown(start) => {
servo.scroll_state = ScrollState::TriggerDragging(start, point);
let _ = call(|s| s.move_mouse(x, y));
let _ = call(|s| s.mouse_move(x, y));
let delta = (point - start) * servo.scroll_scale;
let start = start.to_i32();
let _ = call(|s| s.scroll_start(delta.x, delta.y, start.x, start.y));
},
ScrollState::TriggerDragging(start, prev) => {
servo.scroll_state = ScrollState::TriggerDragging(start, point);
let _ = call(|s| s.move_mouse(x, y));
let _ = call(|s| s.mouse_move(x, y));
let delta = (point - prev) * servo.scroll_scale;
let start = start.to_i32();
let _ = call(|s| s.scroll(delta.x, delta.y, start.x, start.y));
Expand All @@ -279,7 +279,7 @@ pub unsafe extern "C" fn trigger_servo(servo: *mut ServoInstance, x: f32, y: f32
servo.scroll_state = ScrollState::TriggerUp;
let _ = call(|s| s.mouse_up(start.x, start.y, MouseButton::Left));
let _ = call(|s| s.click(start.x as f32, start.y as f32));
let _ = call(|s| s.move_mouse(start.x, start.y));
let _ = call(|s| s.mouse_move(start.x, start.y));
},
ScrollState::TriggerDragging(start, prev) if !down => {
servo.scroll_state = ScrollState::TriggerUp;
Expand Down
2 changes: 1 addition & 1 deletion ports/libsimpleservo/api/src/lib.rs
Expand Up @@ -397,7 +397,7 @@ impl ServoGlue {
}

/// Register a mouse movement.
pub fn move_mouse(&mut self, x: f32, y: f32) -> Result<(), &'static str> {
pub fn mouse_move(&mut self, x: f32, y: f32) -> Result<(), &'static str> {
let point = Point2D::new(x, y);
let event = WindowEvent::MouseWindowMoveEventClass(point);
self.process_event(event)
Expand Down
8 changes: 8 additions & 0 deletions ports/libsimpleservo/capi/src/lib.rs
Expand Up @@ -559,6 +559,14 @@ pub extern "C" fn pinchzoom_end(factor: f32, x: i32, y: i32) {
});
}

#[no_mangle]
pub extern "C" fn mouse_move(x: f32, y: f32) {
catch_any_panic(|| {
debug!("mouse_move");
call(|s| s.mouse_move(x, y));
});
}

#[no_mangle]
pub extern "C" fn mouse_down(x: f32, y: f32, button: CMouseButton) {
catch_any_panic(|| {
Expand Down
3 changes: 3 additions & 0 deletions support/hololens/ServoApp/ServoControl/Servo.h
Expand Up @@ -62,6 +62,9 @@ class Servo {
void MouseUp(float x, float y, capi::CMouseButton b) {
capi::mouse_up(x, y, b);
}
void MouseMove(float x, float y) {
capi::mouse_move(x, y);
}

void Reload() { capi::reload(); }
void Stop() { capi::stop(); }
Expand Down
37 changes: 36 additions & 1 deletion support/hololens/ServoApp/ServoControl/ServoControl.cpp
Expand Up @@ -41,6 +41,14 @@ void ServoControl::OnLoaded(IInspectable const &, RoutedEventArgs const &) {
std::bind(&ServoControl::OnSurfacePointerPressed, this, _1, _2));
panel.PointerReleased(
std::bind(&ServoControl::OnSurfacePointerPressed, this, _1, _2));
panel.PointerCanceled(
std::bind(&ServoControl::OnSurfacePointerCanceled, this, _1, _2));
panel.PointerCaptureLost(
std::bind(&ServoControl::OnSurfacePointerCanceled, this, _1, _2));
panel.PointerMoved(
std::bind(&ServoControl::OnSurfacePointerMoved, this, _1, _2));
panel.PointerWheelChanged(
std::bind(&ServoControl::OnSurfaceWheelChanged, this, _1, _2));
panel.ManipulationStarted(
[=](IInspectable const &,
Input::ManipulationStartedRoutedEventArgs const &e) {
Expand All @@ -63,7 +71,6 @@ void ServoControl::OnLoaded(IInspectable const &, RoutedEventArgs const &) {
}

Controls::SwapChainPanel ServoControl::Panel() {
// FIXME: is there a better way of doing this?
return GetTemplateChild(L"swapChainPanel").as<Controls::SwapChainPanel>();
}

Expand Down Expand Up @@ -140,6 +147,34 @@ void ServoControl::OnSurfacePointerPressed(
}
}

void ServoControl::OnSurfacePointerCanceled(
IInspectable const &, Input::PointerRoutedEventArgs const &e) {
mPressedMouseButton = {};
}

void ServoControl::OnSurfacePointerMoved(
IInspectable const &, Input::PointerRoutedEventArgs const &e) {
if (e.Pointer().PointerDeviceType() ==
Windows::Devices::Input::PointerDeviceType::Mouse) {
auto point = e.GetCurrentPoint(Panel());
auto x = point.Position().X * mDPI;
auto y = point.Position().Y * mDPI;
RunOnGLThread([=] { mServo->MouseMove(x, y); });
}
}

void ServoControl::OnSurfaceWheelChanged(
IInspectable const &, Input::PointerRoutedEventArgs const &e) {
if (e.Pointer().PointerDeviceType() ==
Windows::Devices::Input::PointerDeviceType::Mouse) {
auto point = e.GetCurrentPoint(Panel());
auto x = point.Position().X * mDPI;
auto y = point.Position().Y * mDPI;
auto delta = point.Properties().MouseWheelDelta() * mDPI;
RunOnGLThread([=] { mServo->Scroll(0, (float)delta, x, y); });
}
}

void ServoControl::OnSurfaceResized(IInspectable const &,
SizeChangedEventArgs const &e) {
auto size = e.NewSize();
Expand Down
12 changes: 12 additions & 0 deletions support/hololens/ServoApp/ServoControl/ServoControl.h
Expand Up @@ -125,6 +125,18 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
void OnSurfacePointerPressed(IInspectable const &,
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);

void OnSurfacePointerCanceled(
IInspectable const &,
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);

void OnSurfacePointerMoved(
IInspectable const &,
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);

void OnSurfaceWheelChanged(
IInspectable const &,
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);

void OnSurfaceManipulationDelta(
IInspectable const &,
Windows::UI::Xaml::Input::ManipulationDeltaRoutedEventArgs const &);
Expand Down

0 comments on commit 48d918d

Please sign in to comment.