117 lines
3.8 KiB
Diff
117 lines
3.8 KiB
Diff
Measure mouse movement from the last real position in the wx frontend.
|
|
|
|
The panel computed each step as the distance from the window centre and then
|
|
warped the pointer back there, assuming the warp always succeeds. Under
|
|
Wayland clients may not move the pointer, so the warp is ignored, every step
|
|
is counted again from the centre, and the emulated cursor accelerates and
|
|
keeps drifting the same way after the hand turns back.
|
|
|
|
Movement is now taken between consecutive pointer positions. A warp is only
|
|
trusted once an event arrives right on the centre; if none does after a few
|
|
events, warping stops for good. On X11 nothing changes apart from warping
|
|
less often; under Wayland the pointer follows the hand but stops at the edge
|
|
of the window while captured.
|
|
|
|
diff --git a/wx/np2panel.cpp b/wx/np2panel.cpp
|
|
index bddbfd9..49e7997 100644
|
|
--- a/wx/np2panel.cpp
|
|
+++ b/wx/np2panel.cpp
|
|
@@ -34,6 +34,10 @@ Np2Panel::Np2Panel(wxWindow *parent)
|
|
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
|
wxWANTS_CHARS | wxTAB_TRAVERSAL)
|
|
, m_mouseCaptured(false)
|
|
+ , m_lastValid(false)
|
|
+ , m_warpPending(false)
|
|
+ , m_warpWait(0)
|
|
+ , m_warpWorks(true)
|
|
{
|
|
SetBackgroundStyle(wxBG_STYLE_PAINT);
|
|
SetBackgroundColour(*wxBLACK);
|
|
@@ -189,17 +193,49 @@ void Np2Panel::OnMouseMove(wxMouseEvent &evt)
|
|
{
|
|
if (!m_mouseCaptured) { evt.Skip(); return; }
|
|
|
|
- wxPoint pos = evt.GetPosition();
|
|
- int cx = GetClientSize().x / 2;
|
|
- int cy = GetClientSize().y / 2;
|
|
+ const wxPoint pos = evt.GetPosition();
|
|
+ const wxSize size = GetClientSize();
|
|
+ const wxPoint centre(size.x / 2, size.y / 2);
|
|
+
|
|
+ /* A warp that went through shows up as an event right on the centre. Until
|
|
+ * then, movement is measured from the last real position, so a warp that
|
|
+ * is still in flight or was refused costs nothing. Wayland refuses every
|
|
+ * one, as clients may not move the pointer; after a few events without the
|
|
+ * centre, stop trying. */
|
|
+ if (m_warpPending) {
|
|
+ if (pos == centre) {
|
|
+ m_warpPending = false;
|
|
+ m_lastMousePos = centre;
|
|
+ m_lastValid = true;
|
|
+ return;
|
|
+ }
|
|
+ if (--m_warpWait <= 0) {
|
|
+ m_warpPending = false;
|
|
+ m_warpWorks = false;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (!m_lastValid) {
|
|
+ m_lastMousePos = pos;
|
|
+ m_lastValid = true;
|
|
+ }
|
|
+
|
|
int dx = pos.x - m_lastMousePos.x;
|
|
int dy = pos.y - m_lastMousePos.y;
|
|
+ m_lastMousePos = pos;
|
|
|
|
if (dx || dy) {
|
|
mousemng_onmove(dx, dy);
|
|
- /* warp cursor back to center to allow unlimited movement */
|
|
- WarpPointer(cx, cy);
|
|
- m_lastMousePos = wxPoint(cx, cy);
|
|
+ }
|
|
+
|
|
+ /* Warp back to the centre once the pointer leaves the middle half of the
|
|
+ * panel, so it doesn't stop at the edge of the window. Without warping it
|
|
+ * does, but movement still follows the hand. */
|
|
+ if (m_warpWorks && !m_warpPending
|
|
+ && (abs(pos.x - centre.x) > size.x / 4 || abs(pos.y - centre.y) > size.y / 4)) {
|
|
+ WarpPointer(centre.x, centre.y);
|
|
+ m_warpPending = true;
|
|
+ m_warpWait = 8;
|
|
}
|
|
}
|
|
|
|
@@ -247,8 +283,14 @@ void Np2Panel::CaptureMouse(void)
|
|
m_mouseCaptured = true;
|
|
int cx = GetClientSize().x / 2;
|
|
int cy = GetClientSize().y / 2;
|
|
- m_lastMousePos = wxPoint(cx, cy);
|
|
- WarpPointer(cx, cy);
|
|
+ /* The first motion event sets the starting point; the warp below
|
|
+ * may not happen. */
|
|
+ m_lastValid = false;
|
|
+ if (m_warpWorks) {
|
|
+ WarpPointer(cx, cy);
|
|
+ m_warpPending = true;
|
|
+ m_warpWait = 8;
|
|
+ }
|
|
wxPanel::CaptureMouse();
|
|
SetCursor(wxCursor(wxCURSOR_BLANK));
|
|
mousemng_hidecursor();
|
|
diff --git a/wx/np2panel.h b/wx/np2panel.h
|
|
index 2737469..a8eba2a 100644
|
|
--- a/wx/np2panel.h
|
|
+++ b/wx/np2panel.h
|
|
@@ -28,6 +28,10 @@ private:
|
|
wxBitmap m_bitmap;
|
|
bool m_mouseCaptured;
|
|
wxPoint m_lastMousePos;
|
|
+ bool m_lastValid;
|
|
+ bool m_warpPending;
|
|
+ int m_warpWait;
|
|
+ bool m_warpWorks;
|
|
|
|
void OnPaint(wxPaintEvent &evt);
|
|
void OnSize(wxSizeEvent &evt);
|