-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Touchpad settings * Add some error checking and handle mice as well * lxqt-config-input: add --load-touchpad to load touchpad settings * lxqt-config-input: add autostart entry for loading touchpad settings * Check xorg-libinput headers in CMakeLists.txt * Add "tap to drag" * Use the same terms as mouse config to make translators' life easier * Update copyright lines * touchpad: acceleration speed
- Loading branch information
Chih-Hsuan Yen
committed
Dec 11, 2018
1 parent
0e92bb1
commit ee7b0fe
Showing
7 changed files
with
905 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
/* | ||
Copyright (C) 2016-2018 Chih-Hsuan Yen <yan12125@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 2 of the License, or | ||
(at your option) 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, write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#include "touchpadconfig.h" | ||
#include "touchpaddevice.h" | ||
|
||
#include <cmath> | ||
#include <QUrl> | ||
#include <LXQt/AutostartEntry> | ||
#include <LXQt/Settings> | ||
|
||
TouchpadConfig::TouchpadConfig(LXQt::Settings* _settings, QWidget* parent): | ||
QWidget(parent), | ||
settings(_settings), | ||
curDevice(-1) | ||
{ | ||
ui.setupUi(this); | ||
|
||
devices = TouchpadDevice::enumerate_from_udev(); | ||
for (const TouchpadDevice& device : devices) | ||
{ | ||
ui.devicesComboBox->addItem(device.name()); | ||
} | ||
if (devices.size()) | ||
{ | ||
curDevice = 0; | ||
} | ||
|
||
initControls(); | ||
|
||
connect(ui.tappingEnabledCheckBox, &QCheckBox::stateChanged, | ||
this, &TouchpadConfig::setTappingEnabled); | ||
connect(ui.naturalScrollingEnabledCheckBox, &QCheckBox::stateChanged, | ||
this, &TouchpadConfig::setNaturalScrollingEnabled); | ||
connect(ui.tapToDragEnabledCheckBox, &QCheckBox::stateChanged, | ||
this, &TouchpadConfig::setTapToDragEnabled); | ||
connect(ui.accelSpeedDoubleSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), | ||
this, [this] (double value) { setAccelSpeed(static_cast<float>(value)); }); | ||
connect(ui.twoFingerScrollingRadioButton, &QRadioButton::toggled, | ||
this, &TouchpadConfig::scrollingRadioButtonToggled); | ||
connect(ui.edgeScrollingRadioButton, &QRadioButton::toggled, | ||
this, &TouchpadConfig::scrollingRadioButtonToggled); | ||
connect(ui.buttonScrollingRadioButton, &QRadioButton::toggled, | ||
this, &TouchpadConfig::scrollingRadioButtonToggled); | ||
} | ||
|
||
TouchpadConfig::~TouchpadConfig() | ||
{ | ||
} | ||
|
||
void TouchpadConfig::initFeatureControl(QCheckBox* control, int featureEnabled) | ||
{ | ||
if (featureEnabled >= 0) | ||
{ | ||
control->setEnabled(true); | ||
control->setCheckState(featureEnabled ? Qt::Checked : Qt::Unchecked); | ||
} | ||
else | ||
{ | ||
control->setEnabled(false); | ||
} | ||
} | ||
|
||
void TouchpadConfig::initControls() | ||
{ | ||
if (curDevice < 0) { | ||
return; | ||
} | ||
|
||
const TouchpadDevice& device = devices[curDevice]; | ||
initFeatureControl(ui.tappingEnabledCheckBox, device.tappingEnabled()); | ||
initFeatureControl(ui.naturalScrollingEnabledCheckBox, device.naturalScrollingEnabled()); | ||
initFeatureControl(ui.tapToDragEnabledCheckBox, device.tapToDragEnabled()); | ||
|
||
float accelSpeed = device.accelSpeed(); | ||
if (!std::isnan(accelSpeed)) { | ||
ui.accelSpeedDoubleSpinBox->setEnabled(true); | ||
ui.accelSpeedDoubleSpinBox->setValue(accelSpeed); | ||
} else { | ||
ui.accelSpeedDoubleSpinBox->setEnabled(false); | ||
} | ||
|
||
int scrollMethodsAvailable = device.scrollMethodsAvailable(); | ||
ui.twoFingerScrollingRadioButton->setEnabled(scrollMethodsAvailable & TWO_FINGER); | ||
ui.edgeScrollingRadioButton->setEnabled(scrollMethodsAvailable & EDGE); | ||
ui.buttonScrollingRadioButton->setEnabled(scrollMethodsAvailable & BUTTON); | ||
|
||
ScrollingMethod scrollingMethodEnabled = device.scrollingMethodEnabled(); | ||
if (scrollingMethodEnabled == TWO_FINGER) | ||
{ | ||
ui.twoFingerScrollingRadioButton->setChecked(true); | ||
} | ||
else if (scrollingMethodEnabled == EDGE) | ||
{ | ||
ui.edgeScrollingRadioButton->setChecked(true); | ||
} | ||
else if (scrollingMethodEnabled == BUTTON) | ||
{ | ||
ui.buttonScrollingRadioButton->setChecked(true); | ||
} | ||
else | ||
{ | ||
ui.noScrollingRadioButton->setChecked(true); | ||
} | ||
} | ||
|
||
void TouchpadConfig::accept() | ||
{ | ||
for (const TouchpadDevice& device : devices) | ||
{ | ||
device.saveSettings(settings); | ||
} | ||
|
||
LXQt::AutostartEntry autoStart("lxqt-config-touchpad-autostart.desktop"); | ||
XdgDesktopFile desktopFile(XdgDesktopFile::ApplicationType, "lxqt-config-touchpad-autostart", "lxqt-config-input --load-touchpad"); | ||
desktopFile.setValue("OnlyShowIn", "LXQt"); | ||
desktopFile.setValue("Comment", "Autostart touchpad settings for lxqt-config-input"); | ||
autoStart.setFile(desktopFile); | ||
autoStart.commit(); | ||
} | ||
|
||
void TouchpadConfig::reset() | ||
{ | ||
for (TouchpadDevice& device : devices) | ||
{ | ||
device.setTappingEnabled(device.oldTappingEnabled()); | ||
device.setNaturalScrollingEnabled(device.oldNaturalScrollingEnabled()); | ||
device.setTapToDragEnabled(device.oldTapToDragEnabled()); | ||
device.setAccelSpeed(device.oldAccelSpeed()); | ||
device.setScrollingMethodEnabled(device.oldScrollingMethodEnabled()); | ||
} | ||
initControls(); | ||
accept(); | ||
} | ||
|
||
void TouchpadConfig::setTappingEnabled(int state) | ||
{ | ||
devices[curDevice].setTappingEnabled(state == Qt::Checked); | ||
accept(); | ||
} | ||
|
||
void TouchpadConfig::setNaturalScrollingEnabled(int state) | ||
{ | ||
devices[curDevice].setNaturalScrollingEnabled(state == Qt::Checked); | ||
accept(); | ||
} | ||
|
||
void TouchpadConfig::setTapToDragEnabled(int state) | ||
{ | ||
devices[curDevice].setTapToDragEnabled(state == Qt::Checked); | ||
accept(); | ||
} | ||
|
||
void TouchpadConfig::setAccelSpeed(float speed) | ||
{ | ||
devices[curDevice].setAccelSpeed(speed); | ||
accept(); | ||
} | ||
|
||
void TouchpadConfig::scrollingRadioButtonToggled() | ||
{ | ||
TouchpadDevice& device = devices[curDevice]; | ||
if (ui.noScrollingRadioButton->isChecked()) | ||
{ | ||
device.setScrollingMethodEnabled(NONE); | ||
} | ||
else if (ui.twoFingerScrollingRadioButton->isChecked()) | ||
{ | ||
device.setScrollingMethodEnabled(TWO_FINGER); | ||
} | ||
else if (ui.edgeScrollingRadioButton->isChecked()) | ||
{ | ||
device.setScrollingMethodEnabled(EDGE); | ||
} | ||
else if (ui.buttonScrollingRadioButton->isChecked()) | ||
{ | ||
device.setScrollingMethodEnabled(BUTTON); | ||
} | ||
accept(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
Copyright (C) 2016-2018 Chih-Hsuan Yen <yan12125@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 2 of the License, or | ||
(at your option) 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, write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#ifndef TOUCHPADCONFIG_H | ||
#define TOUCHPADCONFIG_H | ||
|
||
#include <QWidget> | ||
#include "ui_touchpadconfig.h" | ||
|
||
namespace LXQt | ||
{ | ||
class Settings; | ||
} | ||
|
||
class TouchpadDevice; | ||
|
||
class TouchpadConfig : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
TouchpadConfig(LXQt::Settings* _settings, QWidget* parent); | ||
virtual ~TouchpadConfig(); | ||
|
||
void accept(); | ||
public Q_SLOTS: | ||
void reset(); | ||
void scrollingRadioButtonToggled(); | ||
|
||
private: | ||
LXQt::Settings* settings; | ||
Ui::TouchpadConfig ui; | ||
QList<TouchpadDevice> devices; | ||
int curDevice; | ||
|
||
void initControls(); | ||
void initFeatureControl(QCheckBox* control, int featureEnabled); | ||
void setTappingEnabled(int state); | ||
void setNaturalScrollingEnabled(int state); | ||
void setTapToDragEnabled(int state); | ||
void setAccelSpeed(float speed); | ||
}; | ||
|
||
#endif |
Oops, something went wrong.