Skip to content

Commit

Permalink
Merge pull request #106 from paxo-phone/fix/keyboard-trackpad
Browse files Browse the repository at this point in the history
Fixed trackpad bug
  • Loading branch information
paxo-rch authored Sep 6, 2024
2 parents c740d55 + bd232a0 commit 0bdd4af
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/gui/src/elements/Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <iostream>
#include <graphics.hpp>
#include <libsystem.hpp>
#include <Surface.hpp>

#include "Box.hpp"
Expand Down Expand Up @@ -472,7 +473,11 @@ namespace gui::elements {
const bool wasTrackpadActive = isTrackpadActive();

// Check if finger is on screen
if ((rawTouchX != -1 && rawTouchY != -1) && isPointInTrackpad(m_lastTouchX, m_lastTouchY)) {
if ((rawTouchX != -1 && rawTouchY != -1) && isPointInTrackpad(originTouchX, originTouchY)) {
// libsystem::log("[TRACKPAD] Raw Touch : " + std::to_string(rawTouchX) + ", " + std::to_string(rawTouchY) + ".");
// libsystem::log("[TRACKPAD] Last Touch : " + std::to_string(m_lastTouchX) + ", " + std::to_string(m_lastTouchY) + ".");
// libsystem::log("[TRACKPAD] Origin Touch : " + std::to_string(originTouchX) + ", " + std::to_string(originTouchY) + ".");

if (m_trackpadTicks < UINT8_MAX) {
m_trackpadTicks++;
}
Expand All @@ -481,19 +486,24 @@ namespace gui::elements {
if (m_trackpadTicks == 10) {
// Do once, only when trackpad was just enabled

// libsystem::log("[TRACKPAD] Reset.");

m_trackpadActiveBox->enable();

m_trackpadLastDeltaX = 0;

localGraphicalUpdate();
}

const int32_t deltaX = rawTouchX - m_lastTouchX;
const int32_t deltaX = rawTouchX - originTouchX;
std::string deltaXString = std::to_string(deltaX);

constexpr int32_t stepsByChar = 8;
const int32_t toMove = (deltaX - m_trackpadLastDeltaX) / stepsByChar;

// libsystem::log("[TRACKPAD] Delta X : " + std::to_string(deltaX) + ".");
// libsystem::log("[TRACKPAD] To Move : " + std::to_string(toMove) + ".");

if (toMove > 0) {
for (int i = 0; i < toMove; i++) {
m_label->setCursorIndex(static_cast<int16_t>(m_label->getCursorIndex() + 1));
Expand All @@ -509,7 +519,7 @@ namespace gui::elements {
// m_trackpadActiveBox->forceUpdate();
}

m_trackpadLastDeltaX += toMove * 10;
m_trackpadLastDeltaX += toMove * stepsByChar;
}
} else {
m_trackpadTicks = 0;
Expand Down Expand Up @@ -539,6 +549,9 @@ namespace gui::elements {
void Keyboard::addChar(const char value) {
m_buffer.insert(m_label->getCursorIndex(), 1, value);

// Update cursor position
// TODO: Remove m_buffer and use only label ?
m_label->setText(m_buffer);
m_label->setCursorIndex(m_label->getCursorIndex() + 1);
}

Expand Down

0 comments on commit 0bdd4af

Please sign in to comment.