Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed trackpad bug #106

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading