mirror of
https://github.com/servo/servo.git
synced 2025-06-08 08:33:26 +00:00
Properly send TouchEvents to Servo
This commit is contained in:
parent
6e3c131139
commit
171e826180
3 changed files with 85 additions and 20 deletions
|
@ -62,6 +62,12 @@ public:
|
||||||
void MouseUp(float x, float y, capi::CMouseButton b) {
|
void MouseUp(float x, float y, capi::CMouseButton b) {
|
||||||
capi::mouse_up(x, y, b);
|
capi::mouse_up(x, y, b);
|
||||||
}
|
}
|
||||||
|
void TouchDown(float x, float y, int32_t id) { capi::touch_down(x, y, id); }
|
||||||
|
void TouchUp(float x, float y, int32_t id) { capi::touch_up(x, y, id); }
|
||||||
|
void TouchMove(float x, float y, int32_t id) { capi::touch_move(x, y, id); }
|
||||||
|
void TouchCancel(float x, float y, int32_t id) {
|
||||||
|
capi::touch_cancel(x, y, id);
|
||||||
|
}
|
||||||
void MouseMove(float x, float y) { capi::mouse_move(x, y); }
|
void MouseMove(float x, float y) { capi::mouse_move(x, y); }
|
||||||
|
|
||||||
void Reload() { capi::reload(); }
|
void Reload() { capi::reload(); }
|
||||||
|
|
|
@ -9,6 +9,7 @@ using namespace winrt::Windows::UI::Xaml;
|
||||||
using namespace winrt::Windows::UI::Core;
|
using namespace winrt::Windows::UI::Core;
|
||||||
using namespace winrt::Windows::Foundation;
|
using namespace winrt::Windows::Foundation;
|
||||||
using namespace winrt::Windows::System;
|
using namespace winrt::Windows::System;
|
||||||
|
using namespace winrt::Windows::Devices::Input;
|
||||||
using namespace concurrency;
|
using namespace concurrency;
|
||||||
using namespace winrt::servo;
|
using namespace winrt::servo;
|
||||||
|
|
||||||
|
@ -38,13 +39,15 @@ void ServoControl::OnLoaded(IInspectable const &, RoutedEventArgs const &) {
|
||||||
auto panel = Panel();
|
auto panel = Panel();
|
||||||
panel.Tapped(std::bind(&ServoControl::OnSurfaceTapped, this, _1, _2));
|
panel.Tapped(std::bind(&ServoControl::OnSurfaceTapped, this, _1, _2));
|
||||||
panel.PointerPressed(
|
panel.PointerPressed(
|
||||||
std::bind(&ServoControl::OnSurfacePointerPressed, this, _1, _2));
|
std::bind(&ServoControl::OnSurfacePointerPressed, this, _1, _2, true));
|
||||||
panel.PointerReleased(
|
panel.PointerReleased(
|
||||||
std::bind(&ServoControl::OnSurfacePointerPressed, this, _1, _2));
|
std::bind(&ServoControl::OnSurfacePointerPressed, this, _1, _2, false));
|
||||||
panel.PointerCanceled(
|
panel.PointerCanceled(
|
||||||
std::bind(&ServoControl::OnSurfacePointerCanceled, this, _1, _2));
|
std::bind(&ServoControl::OnSurfacePointerCanceled, this, _1, _2));
|
||||||
|
panel.PointerExited(
|
||||||
|
std::bind(&ServoControl::OnSurfacePointerExited, this, _1, _2));
|
||||||
panel.PointerCaptureLost(
|
panel.PointerCaptureLost(
|
||||||
std::bind(&ServoControl::OnSurfacePointerCanceled, this, _1, _2));
|
std::bind(&ServoControl::OnSurfacePointerLost, this, _1, _2));
|
||||||
panel.PointerMoved(
|
panel.PointerMoved(
|
||||||
std::bind(&ServoControl::OnSurfacePointerMoved, this, _1, _2));
|
std::bind(&ServoControl::OnSurfacePointerMoved, this, _1, _2));
|
||||||
panel.PointerWheelChanged(
|
panel.PointerWheelChanged(
|
||||||
|
@ -105,17 +108,19 @@ void ServoControl::OnSurfaceManipulationDelta(
|
||||||
|
|
||||||
void ServoControl::OnSurfaceTapped(IInspectable const &,
|
void ServoControl::OnSurfaceTapped(IInspectable const &,
|
||||||
Input::TappedRoutedEventArgs const &e) {
|
Input::TappedRoutedEventArgs const &e) {
|
||||||
auto coords = e.GetPosition(Panel());
|
if (e.PointerDeviceType() == PointerDeviceType::Mouse) {
|
||||||
auto x = coords.X * mDPI;
|
auto coords = e.GetPosition(Panel());
|
||||||
auto y = coords.Y * mDPI;
|
auto x = coords.X * mDPI;
|
||||||
RunOnGLThread([=] { mServo->Click(x, y); });
|
auto y = coords.Y * mDPI;
|
||||||
|
RunOnGLThread([=] { mServo->Click(x, y); });
|
||||||
|
}
|
||||||
e.Handled(true);
|
e.Handled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoControl::OnSurfacePointerPressed(
|
void ServoControl::OnSurfacePointerPressed(
|
||||||
IInspectable const &, Input::PointerRoutedEventArgs const &e) {
|
IInspectable const &, Input::PointerRoutedEventArgs const &e, bool down) {
|
||||||
if (e.Pointer().PointerDeviceType() ==
|
auto ty = e.Pointer().PointerDeviceType();
|
||||||
Windows::Devices::Input::PointerDeviceType::Mouse) {
|
if (ty == PointerDeviceType::Mouse) {
|
||||||
auto point = e.GetCurrentPoint(Panel());
|
auto point = e.GetCurrentPoint(Panel());
|
||||||
|
|
||||||
auto x = point.Position().X * mDPI;
|
auto x = point.Position().X * mDPI;
|
||||||
|
@ -144,30 +149,76 @@ void ServoControl::OnSurfacePointerPressed(
|
||||||
}
|
}
|
||||||
|
|
||||||
mPressedMouseButton = button;
|
mPressedMouseButton = button;
|
||||||
|
} else if (ty == PointerDeviceType::Touch) {
|
||||||
|
auto point = e.GetCurrentPoint(Panel());
|
||||||
|
|
||||||
|
auto x = point.Position().X * mDPI;
|
||||||
|
auto y = point.Position().Y * mDPI;
|
||||||
|
|
||||||
|
if (down) {
|
||||||
|
RunOnGLThread([=] { mServo->TouchDown(x, y, point.PointerId()); });
|
||||||
|
} else {
|
||||||
|
RunOnGLThread([=] { mServo->TouchUp(x, y, point.PointerId()); });
|
||||||
|
}
|
||||||
|
e.Handled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoControl::OnSurfacePointerCanceled(
|
void ServoControl::OnSurfacePointerCanceled(
|
||||||
IInspectable const &, Input::PointerRoutedEventArgs const &e) {
|
IInspectable const &, Input::PointerRoutedEventArgs const &e) {
|
||||||
mPressedMouseButton = {};
|
e.Handled(true);
|
||||||
|
auto ty = e.Pointer().PointerDeviceType();
|
||||||
|
if (ty == PointerDeviceType::Mouse) {
|
||||||
|
mPressedMouseButton = {};
|
||||||
|
} else if (ty == PointerDeviceType::Touch) {
|
||||||
|
auto point = e.GetCurrentPoint(Panel());
|
||||||
|
auto x = point.Position().X * mDPI;
|
||||||
|
auto y = point.Position().Y * mDPI;
|
||||||
|
RunOnGLThread([=] { mServo->TouchCancel(x, y, point.PointerId()); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoControl::OnSurfacePointerExited(
|
||||||
|
IInspectable const &, Input::PointerRoutedEventArgs const &e) {
|
||||||
|
e.Handled(true);
|
||||||
|
auto ty = e.Pointer().PointerDeviceType();
|
||||||
|
if (ty == PointerDeviceType::Touch) {
|
||||||
|
auto point = e.GetCurrentPoint(Panel());
|
||||||
|
auto x = point.Position().X * mDPI;
|
||||||
|
auto y = point.Position().Y * mDPI;
|
||||||
|
RunOnGLThread([=] { mServo->TouchCancel(x, y, point.PointerId()); });
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServoControl::OnSurfacePointerLost(
|
||||||
|
IInspectable const &, Input::PointerRoutedEventArgs const &e) {
|
||||||
|
// According to the documentation:
|
||||||
|
// https://docs.microsoft.com/en-us/windows/uwp/design/input/handle-pointer-input#handle-pointer-events
|
||||||
|
// we should cancel the event on PointLost. But we keep getting
|
||||||
|
// PointerMoved events after PointerLost. Servo doesn't like getting events
|
||||||
|
// from a pointer id that has been canceled. So we do nothing.
|
||||||
|
e.Handled(true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoControl::OnSurfacePointerMoved(
|
void ServoControl::OnSurfacePointerMoved(
|
||||||
IInspectable const &, Input::PointerRoutedEventArgs const &e) {
|
IInspectable const &, Input::PointerRoutedEventArgs const &e) {
|
||||||
if (e.Pointer().PointerDeviceType() ==
|
auto ty = e.Pointer().PointerDeviceType();
|
||||||
Windows::Devices::Input::PointerDeviceType::Mouse) {
|
auto point = e.GetCurrentPoint(Panel());
|
||||||
auto point = e.GetCurrentPoint(Panel());
|
auto x = point.Position().X * mDPI;
|
||||||
auto x = point.Position().X * mDPI;
|
auto y = point.Position().Y * mDPI;
|
||||||
auto y = point.Position().Y * mDPI;
|
if (ty == PointerDeviceType::Touch && point.IsInContact()) {
|
||||||
e.Handled(true);
|
RunOnGLThread([=] { mServo->TouchMove(x, y, point.PointerId()); });
|
||||||
|
} else {
|
||||||
RunOnGLThread([=] { mServo->MouseMove(x, y); });
|
RunOnGLThread([=] { mServo->MouseMove(x, y); });
|
||||||
}
|
}
|
||||||
|
e.Handled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServoControl::OnSurfaceWheelChanged(
|
void ServoControl::OnSurfaceWheelChanged(
|
||||||
IInspectable const &, Input::PointerRoutedEventArgs const &e) {
|
IInspectable const &, Input::PointerRoutedEventArgs const &e) {
|
||||||
if (e.Pointer().PointerDeviceType() ==
|
if (e.Pointer().PointerDeviceType() == PointerDeviceType::Mouse) {
|
||||||
Windows::Devices::Input::PointerDeviceType::Mouse) {
|
|
||||||
auto point = e.GetCurrentPoint(Panel());
|
auto point = e.GetCurrentPoint(Panel());
|
||||||
auto x = point.Position().X * mDPI;
|
auto x = point.Position().X * mDPI;
|
||||||
auto y = point.Position().Y * mDPI;
|
auto y = point.Position().Y * mDPI;
|
||||||
|
|
|
@ -115,12 +115,20 @@ private:
|
||||||
|
|
||||||
void OnSurfacePointerPressed(
|
void OnSurfacePointerPressed(
|
||||||
IInspectable const &,
|
IInspectable const &,
|
||||||
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);
|
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &, bool);
|
||||||
|
|
||||||
void OnSurfacePointerCanceled(
|
void OnSurfacePointerCanceled(
|
||||||
IInspectable const &,
|
IInspectable const &,
|
||||||
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);
|
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);
|
||||||
|
|
||||||
|
void OnSurfacePointerExited(
|
||||||
|
IInspectable const &,
|
||||||
|
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);
|
||||||
|
|
||||||
|
void OnSurfacePointerLost(
|
||||||
|
IInspectable const &,
|
||||||
|
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);
|
||||||
|
|
||||||
void OnSurfacePointerMoved(
|
void OnSurfacePointerMoved(
|
||||||
IInspectable const &,
|
IInspectable const &,
|
||||||
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);
|
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue