Skip to content

Commit

Permalink
input: add flip_x and flip_y for touchpad (#9481)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnyyxxxx authored Mar 3, 2025
1 parent f1ef724 commit d7e7a29
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/config/ConfigDescriptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,18 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = {
.type = CONFIG_OPTION_BOOL,
.data = SConfigOptionDescription::SBoolData{false},
},
SConfigOptionDescription{
.value = "input:touchpad:flip_x",
.description = "Inverts the horizontal movement of the touchpad",
.type = CONFIG_OPTION_BOOL,
.data = SConfigOptionDescription::SBoolData{false},
},
SConfigOptionDescription{
.value = "input:touchpad:flip_y",
.description = "Inverts the vertical movement of the touchpad",
.type = CONFIG_OPTION_BOOL,
.data = SConfigOptionDescription::SBoolData{false},
},

/*
* input:touchdevice:
Expand Down
4 changes: 4 additions & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,8 @@ CConfigManager::CConfigManager() {
registerConfigVar("input:touchpad:tap-and-drag", Hyprlang::INT{1});
registerConfigVar("input:touchpad:drag_lock", Hyprlang::INT{0});
registerConfigVar("input:touchpad:scroll_factor", {1.f});
registerConfigVar("input:touchpad:flip_x", Hyprlang::INT{0});
registerConfigVar("input:touchpad:flip_y", Hyprlang::INT{0});
registerConfigVar("input:touchdevice:transform", Hyprlang::INT{0});
registerConfigVar("input:touchdevice:output", {"[[Auto]]"});
registerConfigVar("input:touchdevice:enabled", Hyprlang::INT{1});
Expand Down Expand Up @@ -731,6 +733,8 @@ CConfigManager::CConfigManager() {
m_pConfig->addSpecialConfigValue("device", "relative_input", Hyprlang::INT{0}); // only for tablets
m_pConfig->addSpecialConfigValue("device", "active_area_position", Hyprlang::VEC2{0, 0}); // only for tablets
m_pConfig->addSpecialConfigValue("device", "active_area_size", Hyprlang::VEC2{0, 0}); // only for tablets
m_pConfig->addSpecialConfigValue("device", "flip_x", Hyprlang::INT{0}); // only for touchpads
m_pConfig->addSpecialConfigValue("device", "flip_y", Hyprlang::INT{0}); // only for touchpads

// keywords
m_pConfig->registerHandler(&::handleExec, "exec", {false});
Expand Down
9 changes: 6 additions & 3 deletions src/devices/IPointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class IPointer : public IHID {
virtual SP<Aquamarine::IPointer> aq() = 0;

struct SMotionEvent {
uint32_t timeMs = 0;
Vector2D delta, unaccel;
bool mouse = false;
uint32_t timeMs = 0;
Vector2D delta, unaccel;
bool mouse = false;
SP<IPointer> device;
};

struct SMotionAbsoluteEvent {
Expand Down Expand Up @@ -109,6 +110,8 @@ class IPointer : public IHID {

bool connected = false; // means connected to the cursor
std::string boundOutput = "";
bool flipX = false; // decide to invert horizontal movement
bool flipY = false; // decide to invert vertical movement

WP<IPointer> self;
};
1 change: 1 addition & 0 deletions src/devices/Mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CMouse::CMouse(SP<Aquamarine::IPointer> mouse_) : mouse(mouse_) {
.delta = E.delta,
.unaccel = E.unaccel,
.mouse = true,
.device = self.lock(),
});
});

Expand Down
6 changes: 5 additions & 1 deletion src/devices/VirtualPointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ CVirtualPointer::CVirtualPointer(SP<CVirtualPointerV1Resource> resource) : point
events.destroy.emit();
});

listeners.motion = pointer->events.move.registerListener([this](std::any d) { pointerEvents.motion.emit(d); });
listeners.motion = pointer->events.move.registerListener([this](std::any d) {
auto E = std::any_cast<SMotionEvent>(d);
E.device = self.lock();
pointerEvents.motion.emit(E);
});
listeners.motionAbsolute = pointer->events.warp.registerListener([this](std::any d) {
// we need to unpack the event and add our device here because it's required to calculate the position correctly
auto E = std::any_cast<SMotionAbsoluteEvent>(d);
Expand Down
25 changes: 21 additions & 4 deletions src/managers/input/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,28 @@ CInputManager::~CInputManager() {
void CInputManager::onMouseMoved(IPointer::SMotionEvent e) {
static auto PNOACCEL = CConfigValue<Hyprlang::INT>("input:force_no_accel");

const auto DELTA = *PNOACCEL == 1 ? e.unaccel : e.delta;
Vector2D delta = e.delta;
Vector2D unaccel = e.unaccel;

if (!e.mouse && e.device) {
if (e.device->flipX) {
delta.x = -delta.x;
unaccel.x = -unaccel.x;
}
if (e.device->flipY) {
delta.y = -delta.y;
unaccel.y = -unaccel.y;
}
}

const auto DELTA = *PNOACCEL == 1 ? unaccel : delta;

if (g_pSeatManager->isPointerFrameSkipped)
g_pPointerManager->storeMovement((uint64_t)e.timeMs, DELTA, e.unaccel);
g_pPointerManager->storeMovement((uint64_t)e.timeMs, DELTA, unaccel);
else
g_pPointerManager->setStoredMovement((uint64_t)e.timeMs, DELTA, e.unaccel);
g_pPointerManager->setStoredMovement((uint64_t)e.timeMs, DELTA, unaccel);

PROTO::relativePointer->sendRelativeMotion((uint64_t)e.timeMs * 1000, DELTA, e.unaccel);
PROTO::relativePointer->sendRelativeMotion((uint64_t)e.timeMs * 1000, DELTA, unaccel);

if (e.mouse)
recheckMouseWarpOnMouseInput();
Expand Down Expand Up @@ -1180,6 +1194,9 @@ void CInputManager::setPointerConfigs() {
const auto LIBINPUTSENS = std::clamp(g_pConfigManager->getDeviceFloat(devname, "sensitivity", "input:sensitivity"), -1.f, 1.f);
libinput_device_config_accel_set_speed(LIBINPUTDEV, LIBINPUTSENS);

m->flipX = g_pConfigManager->getDeviceInt(devname, "flip_x", "input:touchpad:flip_x") != 0;
m->flipY = g_pConfigManager->getDeviceInt(devname, "flip_y", "input:touchpad:flip_y") != 0;

const auto ACCELPROFILE = g_pConfigManager->getDeviceString(devname, "accel_profile", "input:accel_profile");
const auto SCROLLPOINTS = g_pConfigManager->getDeviceString(devname, "scroll_points", "input:scroll_points");

Expand Down
1 change: 1 addition & 0 deletions src/protocols/VirtualPointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP<CZwlrVirtualPointerV1> r
.timeMs = timeMs,
.delta = {wl_fixed_to_double(dx), wl_fixed_to_double(dy)},
.unaccel = {wl_fixed_to_double(dx), wl_fixed_to_double(dy)},
.device = nullptr,
});
});

Expand Down

0 comments on commit d7e7a29

Please sign in to comment.