Skip to content

Commit

Permalink
fix bug when moving windows on android
Browse files Browse the repository at this point in the history
  • Loading branch information
SkullzOTS authored Jan 8, 2025
1 parent c491e8f commit e8a5371
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/framework/platform/androidwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,30 +247,51 @@ void AndroidWindow::processTextInput() {
}

void AndroidWindow::processFingerDownAndUp() {
static ticks_t lastPress = 0;

bool isTouchdown = m_currentEvent.type == TOUCH_DOWN;

Fw::MouseButton mouseButton = (m_currentEvent.type == TOUCH_UP && stdext::millis() > lastPress + 500 ) ?
Fw::MouseButton mouseButton = (m_currentEvent.type == TOUCH_UP && !m_isDragging && stdext::millis() > m_lastPress + 500) ?
Fw::MouseRightButton : Fw::MouseLeftButton;

m_inputEvent.reset();
m_inputEvent.type = (isTouchdown) ? Fw::MousePressInputEvent : Fw::MouseReleaseInputEvent;
m_inputEvent.mouseButton = mouseButton;
if(isTouchdown) {
lastPress = g_clock.millis();

if (isTouchdown) {
m_lastPress = g_clock.millis();
m_mouseButtonStates |= 1 << mouseButton;
} else {
} else if (m_currentEvent.type == TOUCH_UP) {
if (!m_isDragging) {
if (stdext::millis() > m_lastPress + 500) {
mouseButton = Fw::MouseRightButton;
m_inputEvent.mouseButton = mouseButton;
}
}
m_isDragging = false;
g_dispatcher.addEvent([this, mouseButton] { m_mouseButtonStates &= ~(1 << mouseButton); });
}

handleInputEvent();
}

void AndroidWindow::processFingerMotion() {
static Point lastMousePos(-1, -1);
static const int dragThreshold = 5;

m_inputEvent.reset();
m_inputEvent.type = Fw::MouseMoveInputEvent;

Point newMousePos(m_currentEvent.x / m_displayDensity, m_currentEvent.y / m_displayDensity);

if (lastMousePos.x != -1 && lastMousePos.y != -1) {
int dx = std::abs(newMousePos.x - lastMousePos.x);
int dy = std::abs(newMousePos.y - lastMousePos.y);

if (dx > dragThreshold || dy > dragThreshold) {
m_isDragging = true;
}
}
lastMousePos = newMousePos;

handleInputEvent();
}

Expand Down
3 changes: 3 additions & 0 deletions src/framework/platform/androidwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ class AndroidWindow : public PlatformWindow

std::queue<NativeEvent> m_events;
NativeEvent m_currentEvent;

ticks_t m_lastPress = 0;
bool m_isDragging = false;
};

extern "C" {
Expand Down

0 comments on commit e8a5371

Please sign in to comment.