Skip to content

Commit

Permalink
Touchpad settings (#109)
Browse files Browse the repository at this point in the history
* 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
Show file tree
Hide file tree
Showing 7 changed files with 905 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lxqt-config-input/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
project(lxqt-config-input)

find_package(X11 REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(XORG_LIBINPUT REQUIRED xorg-libinput)

include_directories(
${X11_INCLUDE_DIR}
${XORG_LIBINPUT_INCLUDE_DIRS}
"${CMAKE_CURRENT_SOURCE_DIR}/../liblxqt-config-cursor"
)

Expand All @@ -13,6 +16,7 @@ set(lxqt-config-input_HDRS
mouseconfig.h
keyboardlayoutconfig.h
selectkeyboardlayoutdialog.h
touchpadconfig.h
)

set(lxqt-config-input_SRCS
Expand All @@ -21,13 +25,16 @@ set(lxqt-config-input_SRCS
mouseconfig.cpp
keyboardlayoutconfig.cpp
selectkeyboardlayoutdialog.cpp
touchpadconfig.cpp
touchpaddevice.cpp
)

set(lxqt-config-input_UIS
mouseconfig.ui
keyboardconfig.ui
keyboardlayoutconfig.ui
selectkeyboardlayoutdialog.ui
touchpadconfig.ui
)

# Translations **********************************
Expand Down Expand Up @@ -62,8 +69,10 @@ target_link_libraries(lxqt-config-input
Qt5::Widgets
Qt5::X11Extras
${X11_LIBRARIES}
${X11_Xinput_LIB}
lxqt
lxqt-config-cursor
udev
)

set_target_properties(lxqt-config-input
Expand Down
17 changes: 17 additions & 0 deletions lxqt-config-input/lxqt-config-input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "keyboardconfig.h"
#include "../liblxqt-config-cursor/selectwnd.h"
#include "keyboardlayoutconfig.h"
#include "touchpadconfig.h"
#include "touchpaddevice.h"

int main(int argc, char** argv) {
LXQt::SingleApplication app(argc, argv);
Expand All @@ -39,6 +41,9 @@ int main(int argc, char** argv) {
app.setApplicationVersion(VERINFO);

dlgOptions.setCommandLine(&parser);
QCommandLineOption loadOption("load-touchpad",
app.tr("Load last touchpad settings."));
parser.addOption(loadOption);
parser.addVersionOption();
parser.addHelpOption();
parser.process(app);
Expand All @@ -48,6 +53,13 @@ int main(int argc, char** argv) {
if(configName.isEmpty())
configName = "session";
LXQt::Settings settings(configName);

bool loadLastTouchpadSettings = parser.isSet(loadOption);
if (loadLastTouchpadSettings) {
TouchpadDevice::loadSettings(&settings);
return 0;
}

LXQt::ConfigDialog dlg(QObject::tr("Keyboard and Mouse Settings"), &settings);
app.setActivationWindow(&dlg);

Expand All @@ -68,6 +80,11 @@ int main(int argc, char** argv) {
dlg.addPage(keyboardLayoutConfig, QObject::tr("Keyboard Layout"), "input-keyboard");
QObject::connect(&dlg, SIGNAL(reset()), keyboardLayoutConfig, SLOT(reset()));

TouchpadConfig* touchpadConfig = new TouchpadConfig(&settings, &dlg);
dlg.addPage(touchpadConfig, QObject::tr("Touchpad"), "input-tablet");
QObject::connect(&dlg, &LXQt::ConfigDialog::reset,
touchpadConfig, &TouchpadConfig::reset);

dlg.setWindowIcon(QIcon::fromTheme("input-keyboard"));

const QString initialPage = dlgOptions.page();
Expand Down
195 changes: 195 additions & 0 deletions lxqt-config-input/touchpadconfig.cpp
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();
}
59 changes: 59 additions & 0 deletions lxqt-config-input/touchpadconfig.h
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
Loading

0 comments on commit ee7b0fe

Please sign in to comment.