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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
/*
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)
{
ui.setupUi(this);
devices = TouchpadDevice::enumerate_from_udev();
for (const TouchpadDevice& device : devices)
{
ui.devicesComboBox->addItem(device.name());
}
initControls();
connect(ui.devicesComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, [this] (int/* index*/) { initControls(); }); // update GUI on device change
connect(ui.tappingEnabledCheckBox, &QAbstractButton::clicked, this, &TouchpadConfig::settingsChanged);
connect(ui.naturalScrollingEnabledCheckBox, &QAbstractButton::clicked, this, &TouchpadConfig::settingsChanged);
connect(ui.tapToDragEnabledCheckBox, &QAbstractButton::clicked, this, &TouchpadConfig::settingsChanged);
connect(ui.accelSpeedDoubleSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &TouchpadConfig::settingsChanged);
connect(ui.noScrollingRadioButton, &QAbstractButton::clicked, this, &TouchpadConfig::settingsChanged);
connect(ui.twoFingerScrollingRadioButton, &QAbstractButton::clicked, this, &TouchpadConfig::settingsChanged);
connect(ui.edgeScrollingRadioButton, &QAbstractButton::clicked, this, &TouchpadConfig::settingsChanged);
connect(ui.buttonScrollingRadioButton, &QAbstractButton::clicked, this, &TouchpadConfig::settingsChanged);
}
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()
{
int curDevice = ui.devicesComboBox->currentIndex();
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);
// prevent setAccelSpeed() from being called because the device may have changed
ui.accelSpeedDoubleSpinBox->blockSignals(true);
ui.accelSpeedDoubleSpinBox->setValue(accelSpeed);
ui.accelSpeedDoubleSpinBox->blockSignals(false);
} 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::applyConfig()
{
int curDevice = ui.devicesComboBox->currentIndex();
if (curDevice < 0) {
return;
}
bool acceptSetting = false;
TouchpadDevice& device = devices[curDevice];
bool enable = ui.tappingEnabledCheckBox->checkState() == Qt::Checked;
if (enable != (device.tappingEnabled() > 0))
{
device.setTappingEnabled(enable);
acceptSetting = true;
}
enable = ui.naturalScrollingEnabledCheckBox->checkState() == Qt::Checked;
if (enable != (device.naturalScrollingEnabled() > 0))
{
device.setNaturalScrollingEnabled(enable);
acceptSetting = true;
}
enable = ui.tapToDragEnabledCheckBox->checkState() == Qt::Checked;
if (enable != (device.tapToDragEnabled() > 0))
{
device.setTapToDragEnabled(enable);
acceptSetting = true;
}
float accelSpeed = static_cast<float>(ui.accelSpeedDoubleSpinBox->value());
if (accelSpeed != device.accelSpeed())
{
device.setAccelSpeed(accelSpeed);
acceptSetting = true;
}
// these radio buttons are auto-exclusive
ScrollingMethod m = NONE;
if (ui.noScrollingRadioButton->isChecked())
m = NONE;
else if (ui.twoFingerScrollingRadioButton->isChecked())
m = TWO_FINGER;
else if (ui.edgeScrollingRadioButton->isChecked())
m = EDGE;
else if (ui.buttonScrollingRadioButton->isChecked())
m = BUTTON;
if (m != device.scrollingMethodEnabled())
{
device.setScrollingMethodEnabled(m);
acceptSetting = true;
}
if (acceptSetting)
accept();
}
|