Skip to content

Commit f1da01c

Browse files
zorowkzorowk
authored andcommitted
feat: apply libinput accel config for pointer/touchpad devices
Add libinput accel speed/profile dconfig options and wire them into input device setup. Apply settings on device hotplug and config changes, and reuse a helper to update all current devices. Log: apply libinput accel config Influence: pointer, touchpad, virtual input
1 parent 971a7d1 commit f1da01c

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

misc/dconfig/org.deepin.dde.treeland.user.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,17 @@
443443
"permissions": "readonly",
444444
"visibility": "private"
445445
},
446+
"inputAccelProfile": {
447+
"value": 2,
448+
"serial": 0,
449+
"flags": ["global"],
450+
"name": "Libinput Accel Profile",
451+
"name[zh_CN]": "Libinput 加速曲线",
452+
"description": "Pointer acceleration profile, enum value of libinput_config_accel_profile",
453+
"description[zh_CN]": "指针加速曲线,对应 libinput_config_accel_profile 枚举值",
454+
"permissions": "readwrite",
455+
"visibility": "public"
456+
},
446457
"wallpaperConfig": {
447458
"value": "",
448459
"serial": 0,

src/input/inputdevice.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// Copyright (C) 2024-2025 UnionTech Software Technology Co., Ltd.
1+
// Copyright (C) 2024-2026 UnionTech Software Technology Co., Ltd.
22
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
33

4+
#include "helper.h"
45
#include "inputdevice.h"
56
#include "common/treelandlogging.h"
7+
#include "treelanduserconfig.hpp"
68

79
#include <winputdevice.h>
810

@@ -13,6 +15,7 @@
1315
#include <QLoggingCategory>
1416
#include <QPointer>
1517

18+
1619
QW_USE_NAMESPACE
1720

1821
#define MIN_SWIPE_FINGERS 3
@@ -351,14 +354,32 @@ InputDevice *InputDevice::instance()
351354
return m_instance;
352355
}
353356

354-
bool InputDevice::initTouchPad(WInputDevice *device)
357+
void InputDevice::initDevice(WInputDevice *device)
355358
{
356-
if (device->handle()->is_libinput()
357-
&& device->qtDevice()->type() == QInputDevice::DeviceType::TouchPad) {
359+
if (!device || !device->handle() || !device->handle()->is_libinput()) {
360+
return;
361+
}
362+
363+
auto deviceType = device->qtDevice()->type();
364+
if (deviceType == QInputDevice::DeviceType::TouchPad) {
358365
configTapEnabled(libinput_device_handle(device->handle()), LIBINPUT_CONFIG_TAP_ENABLED);
359-
return true;
360366
}
361-
return false;
367+
368+
if (deviceType == QInputDevice::DeviceType::TouchPad ||
369+
deviceType == QInputDevice::DeviceType::Mouse) {
370+
auto config = Helper::instance()->config();
371+
auto applyAccelProfile = [device, config]() {
372+
auto deviceType = device->qtDevice()->type();
373+
if (deviceType == QInputDevice::DeviceType::Mouse ||
374+
deviceType == QInputDevice::DeviceType::TouchPad) {
375+
configAccelProfile(libinput_device_handle(device->handle()),
376+
static_cast<libinput_config_accel_profile>(config->inputAccelProfile()));
377+
}
378+
};
379+
380+
connect(config, &TreelandUserConfig::inputAccelProfileChanged, this, applyAccelProfile);
381+
connect(config, &TreelandUserConfig::configInitializeSucceed, this, applyAccelProfile);
382+
}
362383
}
363384

364385
[[maybe_unused]] SwipeGesture* InputDevice::registerTouchpadSwipe(const SwipeFeedBack &feed_back)

src/input/inputdevice.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2024-2025 UnionTech Software Technology Co., Ltd.
1+
// Copyright (C) 2024-2026 UnionTech Software Technology Co., Ltd.
22
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
33

44
#pragma once
@@ -40,7 +40,7 @@ class InputDevice : public QObject
4040
InputDevice(const InputDevice &) = delete;
4141
InputDevice &operator=(const InputDevice &) = delete;
4242

43-
bool initTouchPad(WInputDevice *device);
43+
void initDevice(WInputDevice *device);
4444

4545
SwipeGesture* registerTouchpadSwipe(const SwipeFeedBack &feed_back);
4646
HoldGesture* registerTouchpadHold(const HoldFeedBack &feed);

src/seat/helper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ void Helper::init(Treeland::Treeland *treeland)
11871187
m_backend = m_server->attach<WBackend>();
11881188
connect(m_backend, &WBackend::inputAdded, this, [this](WInputDevice *device) {
11891189
m_seat->attachInputDevice(device);
1190-
InputDevice::instance()->initTouchPad(device);
1190+
InputDevice::instance()->initDevice(device);
11911191
});
11921192

11931193
connect(m_backend, &WBackend::inputRemoved, this, [this](WInputDevice *device) {

0 commit comments

Comments
 (0)