File: input-wayland-device.cpp

package info (click to toggle)
ukui-settings-daemon 4.0.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,324 kB
  • sloc: cpp: 39,120; ansic: 3,240; xml: 1,570; sh: 88; makefile: 4
file content (179 lines) | stat: -rw-r--r-- 5,370 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
 * -*- coding: utf-8 -*-
 *
 * Copyright (C) 2023 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: sundagao <sundagao@kylinos.cn>
 */
#include "input-wayland-device.h"
#include "input-gsettings.h"
#include "input-device-function.h"
#include <QDBusConnection>

extern "C" {
#include "clib-syslog.h"
}
//外部全局变量,在input-device-funtion.cpp 定义
extern const DeviceFunctionMap deviceFuncMap;

InputWaylandDevice::InputWaylandDevice(QVariant deviceId, DeviceType type, QString deviceName, QObject *parent)
    : InputDevice(deviceId, type, deviceName, parent)
{
    m_interface = new QDBusInterface(QStringLiteral(KDE_KWIN_SERVICE),
                                     QStringLiteral(KDE_KWIN_OBJECT_PATH) + m_deviceId.toString(),
                                     QStringLiteral(KDE_KWIN_INTERFACE),
                                     QDBusConnection::sessionBus(), this);
    if (!m_interface->isValid()) {
        m_interface = new QDBusInterface(QStringLiteral(UKUI_KWIN_SERVICE),
                                         QStringLiteral(UKUI_KWIN_OBJECT_PATH) + m_deviceId.toString(),
                                         QStringLiteral(UKUI_KWIN_INTERFACE),
                                         QDBusConnection::sessionBus(), this);
    }

    initDeviceProperty();
}

void InputWaylandDevice::disable()
{
    setProperty("enabled", false);
}

void InputWaylandDevice::enable()
{
    setProperty("enabled", true);
}

void InputWaylandDevice::setEnable(QVariant value)
{
    setProperty("enabled", value);
}

void InputWaylandDevice::setLeftMode(QVariant value)
{
    setProperty("leftHanded", value);
}

void InputWaylandDevice::setNaturalScroll(QVariant value)
{
    setProperty("naturalScroll", value);
}

void InputWaylandDevice::setTapclick(QVariant value)
{
    setProperty("tapToClick", value);
}

void InputWaylandDevice::setTapDrag(QVariant value)
{
    setProperty("tapAndDrag", value);
}

void InputWaylandDevice::setDisableTyping(QVariant value)
{
    setProperty("disableWhileTyping", value);
}

void InputWaylandDevice::setAccelSpeed(QVariant value)
{
    setProperty("pointerAccelerationProfileAdaptive", value);
    setProperty("pointerAccelerationProfileFlat", !value.toBool());
}

void InputWaylandDevice::setAcceleration(QVariant value)
{
    double acceleration = value.toDouble();
    if (acceleration <= 1.0) {
        acceleration = 1.0;
    } else if (acceleration >= 8.0) {
        acceleration = 8.0;
    }
    acceleration = (acceleration - 1.0) * 2.0 / 7.0 - 1;
    setProperty("pointerAcceleration", acceleration);
}

void InputWaylandDevice::setMiddleButtonEmulation(QVariant value)
{
    setProperty("middleButtonEmulation", value);

}

void InputWaylandDevice::setScrolling(QVariant value)
{
    Q_UNUSED(value)
    bool edgeScroll = getGsettingsValue(KEY_VERT_EDGE_SCROLL).toBool();
    bool twoFingerScroll = getGsettingsValue(KEY_VERT_TWO_FINGER_SCROLL).toBool();
    USD_LOG(LOG_DEBUG,"setScrolling edgeScroll: %d twoFingerScroll: %d",edgeScroll, twoFingerScroll );
    setProperty("scrollEdge", edgeScroll);
    setProperty("scrollTwoFinger", twoFingerScroll);
}

void InputWaylandDevice::setDisableTpMoPresent(QVariant mousePresent)
{
    QVariant value = getGsettingsValue(KEY_TOUCHPAD_DISBLE_O_E_MOUSE);
    if (value.toBool() && mousePresent.toBool()) {
        setEnable(false);
    } else {
        setEnable(true);
    }
}

void InputWaylandDevice::setWheelSpeed(QVariant value)
{
    if (isMouse()) {
        setProperty("scrollFactor", value);
    }
}

QVariant InputWaylandDevice::getProductId()
{
    return getProperty("product");
}

void InputWaylandDevice::setProperty(const char *prop, QVariant value)
{
    if (m_interface->isValid()) {
        USD_LOG(LOG_DEBUG,"set prop %s",prop);
        m_interface->setProperty(prop, value);
    } else {
        USD_LOG(LOG_WARNING,"wayland device interface is not valid .");
    }
}

QVariant InputWaylandDevice::getProperty(const char *prop)
{
    return m_interface->property(prop);
}

void InputWaylandDevice::initDeviceProperty()
{
    //新增设备时初始化属性列表,根据gsetings 配置设置属性。
    QList<QString> keys = InputGsettings::instance()->getGsettingsKeys(m_type);
    if (keys.isEmpty()) {
        USD_LOG(LOG_DEBUG,"get gsettings keys is empty .");
        return;
    }
    for (const QString& key : keys) {
        QVariant value = getGsettingsValue(key);
        if (key == QStringLiteral(KEY_MOUSE_LOCATE_POINTER)) {
            InputDeviceFunction::setLocatePointer(value);
        } else {
            auto func = deviceFuncMap.value(key);
            if (func) {
                func(value,this);
            }
        }
    }
}