Add touchpad option

pull/28/head
reionwong 5 years ago
parent 9281ff14a3
commit b959614f49

@ -51,6 +51,7 @@ set(SRCS
src/datetime/timezonedata.h
src/datetime/timezonemap.cpp
src/datetime/timedated_interface.cpp
src/touchpad.cpp
)
set(RESOURCES

@ -17,6 +17,7 @@
#include "language.h"
#include "password.h"
#include "powermanager.h"
#include "touchpad.h"
#include "cursor/cursorthememodel.h"
#include "cursor/mouse.h"
@ -75,6 +76,8 @@ Application::Application(int &argc, char **argv)
qmlRegisterType<Mouse>(uri, 1, 0, "Mouse");
qmlRegisterType<Time>(uri, 1, 0, "Time");
qmlRegisterType<TimeZoneMap>(uri, 1, 0, "TimeZoneMap");
qmlRegisterType<Touchpad>(uri, 1, 0, "Touchpad");
qmlRegisterSingletonType<Password>(uri, 1, 0, "Password", passwordSingleton);
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)

@ -0,0 +1,7 @@
<svg width="16" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g transform="matrix(.03125 0 0 .03125 0 1.6406)" fill="#fff">
<path d="m271 317v90h181c33.086 0 60-26.914 60-60v-30z"/>
<path d="m512 287v-227c0-33.086-26.914-60-60-60h-392c-33.086 0-60 26.914-60 60v227z"/>
<path d="m241 317h-241v30c0 33.086 26.914 60 60 60h181z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 365 B

@ -148,6 +148,15 @@ Item {
category: qsTr("System")
}
ListElement {
title: qsTr("Touchpad")
name: "touchpad"
page: "qrc:/qml/Touchpad/Main.qml"
iconSource: "touchpad.svg"
iconColor: "#999999"
category: qsTr("System")
}
// ListElement {
// title: qsTr("Application")
// name: "application"
@ -377,4 +386,13 @@ Item {
removeItem("wlan")
}
}
Touchpad {
id: _touchPad
Component.onCompleted: {
if (!_touchPad.available)
removeItem("touchpad")
}
}
}

@ -0,0 +1,136 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: revenmartin <revenmartin@gmail.com>
*
* 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/>.
*/
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import FishUI 1.0 as FishUI
import Cutefish.Settings 1.0
import "../"
ItemPage {
headerTitle: qsTr("Touchpad")
Touchpad {
id: touchpad
Component.onCompleted: {
accelSpeedSlider.load()
}
}
Scrollable {
anchors.fill: parent
contentHeight: layout.implicitHeight
ColumnLayout {
id: layout
anchors.fill: parent
RoundedItem {
GridLayout {
columns: 2
rowSpacing: FishUI.Units.largeSpacing * 2
Label {
text: qsTr("Enable")
Layout.fillWidth: true
}
Switch {
id: _enableSwitch
Layout.fillHeight: true
Layout.alignment: Qt.AlignRight
Component.onCompleted: {
checked = touchpad.enabled
}
onCheckedChanged: touchpad.enabled = checked
}
Label {
visible: _enableSwitch.checked
text: qsTr("Tap to click")
Layout.fillWidth: true
}
Switch {
visible: _enableSwitch.checked
Layout.fillHeight: true
onCheckedChanged: touchpad.tapToClick = checked
Layout.alignment: Qt.AlignRight
Component.onCompleted: {
checked = touchpad.tapToClick
}
}
Label {
visible: _enableSwitch.checked
text: qsTr("Pointer acceleration")
}
Slider {
id: accelSpeedSlider
visible: _enableSwitch.checked
Layout.fillWidth: true
from: 1
to: 11
stepSize: 1
property int accelSpeedValue: 0 // [-100, 100]
function load() {
accelSpeedValue = Math.round(touchpad.pointerAcceleration * 100)
// convert libinput pointer acceleration range [-1, 1] to slider range [1, 11]
value = Math.round(6 + touchpad.pointerAcceleration / 0.2)
}
function onAccelSpeedChanged(val) {
// check slider
if (val !== accelSpeedSlider.accelSpeedValue) {
accelSpeedSlider.accelSpeedValue = val
accelSpeedSlider.value = Math.round(6 + (val / 100) / 0.2)
}
// check libinput accelspeed
if ((val / 100) != touchpad.pointerAcceleration) {
touchpad.pointerAcceleration = val / 100
}
}
onMoved: {
if (touchpad != undefined) {
// convert slider range [1, 11] to accelSpeedValue range [-100, 100]
accelSpeedValue = Math.round(((value - 6) * 0.2) * 100)
onAccelSpeedChanged(accelSpeedValue)
}
}
}
}
}
Item {
height: FishUI.Units.smallSpacing
}
}
}
}

@ -116,5 +116,7 @@
<file>images/dark/world.svg</file>
<file>images/sidebar/dark/datetime.svg</file>
<file>qml/Update/Main.qml</file>
<file>qml/Touchpad/Main.qml</file>
<file>images/sidebar/dark/touchpad.svg</file>
</qresource>
</RCC>

@ -0,0 +1,55 @@
#include "touchpad.h"
Touchpad::Touchpad(QObject *parent)
: QObject(parent)
, m_iface("com.cutefish.Settings",
"/Touchpad",
"com.cutefish.Touchpad",
QDBusConnection::sessionBus(), this)
{
}
bool Touchpad::available() const
{
if (!m_iface.isValid())
return false;
return m_iface.property("available").toBool();
}
bool Touchpad::enabled() const
{
return m_iface.property("enabled").toBool();
}
void Touchpad::setEnabled(bool enabled)
{
m_iface.asyncCall("setEnabled", enabled);
emit enabledChanged();
}
bool Touchpad::tapToClick() const
{
return m_iface.property("tapToClick").toBool();
}
void Touchpad::setTapToClick(bool enabled)
{
m_iface.asyncCall("setTapToClick", enabled);
emit tapToClickChanged();
}
qreal Touchpad::pointerAcceleration() const
{
if (!m_iface.isValid())
return 0;
return m_iface.property("pointerAcceleration").toReal();
}
void Touchpad::setPointerAcceleration(qreal value)
{
m_iface.asyncCall("setPointerAcceleration", value);
emit pointerAccelerationChanged();
}

@ -0,0 +1,38 @@
#ifndef TOUCHPAD_H
#define TOUCHPAD_H
#include <QObject>
#include <QDBusInterface>
#include <QDBusPendingCall>
class Touchpad : public QObject
{
Q_OBJECT
Q_PROPERTY(bool available READ available CONSTANT)
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
Q_PROPERTY(bool tapToClick READ tapToClick WRITE setTapToClick NOTIFY tapToClickChanged)
Q_PROPERTY(qreal pointerAcceleration READ pointerAcceleration WRITE setPointerAcceleration NOTIFY pointerAccelerationChanged)
public:
explicit Touchpad(QObject *parent = nullptr);
bool available() const;
bool enabled() const;
void setEnabled(bool enabled);
bool tapToClick() const;
void setTapToClick(bool enabled);
qreal pointerAcceleration() const;
void setPointerAcceleration(qreal value);
signals:
void enabledChanged();
void tapToClickChanged();
void pointerAccelerationChanged();
private:
QDBusInterface m_iface;
};
#endif // TOUCHPAD_H
Loading…
Cancel
Save