[libinput] Support for left-handed pointer

Summary:
The configuration file kcminput, group Mouse is parsed to decide whether
pointer devices should be in left handed mode. The config is applied
whenever a new device is added.

In addition the Connection listens to KGlobalSettings for a mouse
settings changed signal which might be emitted by the mouse KCM.

When such a signal is emitted, all pointer devices are reconfigured.

This allows to change the mouse handed settings on Wayland.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1543
icc-effect-5.14.5
Martin Gräßlin 2016-05-06 09:53:36 +02:00
parent 568a036762
commit 254573bee1
7 changed files with 68 additions and 2 deletions

View File

@ -788,6 +788,7 @@ InputRedirection::InputRedirection(QObject *parent)
}
);
}
m_inputConfig = KSharedConfig::openConfig(QStringLiteral("kcminputrc"));
}
#endif
connect(kwinApp(), &Application::workspaceCreated, this, &InputRedirection::setupWorkspace);
@ -913,7 +914,8 @@ void InputRedirection::reconfigure()
{
#if HAVE_INPUT
if (Application::usesLibinput()) {
const auto config = KSharedConfig::openConfig(QStringLiteral("kcminputrc"))->group(QStringLiteral("keyboard"));
m_inputConfig->reparseConfiguration();
const auto config = m_inputConfig->group(QStringLiteral("keyboard"));
const int delay = config.readEntry("RepeatDelay", 660);
const int rate = config.readEntry("RepeatRate", 25);
const bool enabled = config.readEntry("KeyboardRepeating", 0) == 0;
@ -944,6 +946,7 @@ void InputRedirection::setupLibInput()
LibInput::Connection *conn = LibInput::Connection::create(this);
m_libInput = conn;
if (conn) {
conn->setInputConfig(m_inputConfig);
conn->setup();
connect(conn, &LibInput::Connection::eventsRead, this,
[this] {

View File

@ -25,6 +25,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QPoint>
#include <config-kwin.h>
#include <KSharedConfig>
class KGlobalAccelInterface;
class QKeySequence;
class QMouseEvent;
@ -212,6 +214,7 @@ private:
LibInput::Connection *m_libInput = nullptr;
QVector<InputEventFilter*> m_filters;
KSharedConfigPtr m_inputConfig;
KWIN_SINGLETON(InputRedirection)
friend InputRedirection *input();

View File

@ -25,6 +25,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "../udev.h"
#include "libinput_logging.h"
#include <KConfigGroup>
#include <QMutexLocker>
#include <QSocketNotifier>
#include <QThread>
@ -88,6 +90,9 @@ Connection::Connection(Context *input, QObject *parent)
, m_mutex(QMutex::Recursive)
{
Q_ASSERT(m_input);
// need to connect to KGlobalSettings as the mouse KCM does not emit a dedicated signal
QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KGlobalSettings"), QStringLiteral("org.kde.KGlobalSettings"),
QStringLiteral("notifyChange"), this, SLOT(slotKGlobalSettingsNotifyChange(int,int)));
}
Connection::~Connection()
@ -181,6 +186,7 @@ void Connection::processEvents()
emit hasTouchChanged(true);
}
}
applyDeviceConfig(device);
emit deviceAdded(device);
break;
}
@ -333,5 +339,24 @@ bool Connection::isSuspended() const
return s_context->isSuspended();
}
void Connection::applyDeviceConfig(Device *device)
{
if (device->isPointer()) {
device->setLeftHanded(m_config->group("Mouse").readEntry("MouseButtonMapping", "RightHanded") == QLatin1String("LeftHanded"));
}
}
void Connection::slotKGlobalSettingsNotifyChange(int type, int arg)
{
if (type == 3 /**SettingsChanged**/ && arg == 0 /** SETTINGS_MOUSE **/) {
m_config->reparseConfiguration();
for (auto it = m_devices.constBegin(), end = m_devices.constEnd(); it != end; ++it) {
if ((*it)->isPointer()) {
applyDeviceConfig(*it);
}
}
}
}
}
}

View File

@ -46,6 +46,10 @@ class Connection : public QObject
public:
~Connection();
void setInputConfig(const KSharedConfigPtr &config) {
m_config = config;
}
void setup();
/**
* Sets the screen @p size. This is needed for mapping absolute pointer events to
@ -94,10 +98,12 @@ Q_SIGNALS:
private Q_SLOTS:
void doSetup();
void slotKGlobalSettingsNotifyChange(int type, int arg);
private:
Connection(Context *input, QObject *parent = nullptr);
void handleEvent();
void applyDeviceConfig(Device *device);
Context *m_input;
QSocketNotifier *m_notifier;
QSize m_size;
@ -111,6 +117,7 @@ private:
QVector<Event*> m_eventQueue;
bool wasSuspended = false;
QVector<Device*> m_devices;
KSharedConfigPtr m_config;
KWIN_SINGLETON(Connection)
static QThread *s_thread;

View File

@ -80,6 +80,7 @@ Device::Device(libinput_device *device, QObject *parent)
, m_supportsCalibrationMatrix(libinput_device_config_calibration_has_matrix(m_device))
, m_supportsDisableEvents(libinput_device_config_send_events_get_modes(m_device) & LIBINPUT_CONFIG_SEND_EVENTS_DISABLED)
, m_supportsDisableEventsOnExternalMouse(libinput_device_config_send_events_get_modes(m_device) & LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE)
, m_leftHanded(m_supportsLeftHanded ? libinput_device_config_left_handed_get(m_device) : false)
{
libinput_device_ref(m_device);
@ -124,5 +125,18 @@ Device::~Device()
libinput_device_unref(m_device);
}
void Device::setLeftHanded(bool set)
{
if (!m_supportsLeftHanded) {
return;
}
if (libinput_device_config_left_handed_set(m_device, set) == LIBINPUT_CONFIG_STATUS_SUCCESS) {
if (m_leftHanded != set) {
m_leftHanded = set;
emit leftHandedChanged();
}
}
}
}
}

View File

@ -55,6 +55,7 @@ class Device : public QObject
Q_PROPERTY(bool supportsCalibrationMatrix READ supportsCalibrationMatrix CONSTANT)
Q_PROPERTY(bool supportsDisableEvents READ supportsDisableEvents CONSTANT)
Q_PROPERTY(bool supportsDisableEventsOnExternalMouse READ supportsDisableEventsOnExternalMouse CONSTANT)
Q_PROPERTY(bool leftHanded READ isLeftHanded WRITE setLeftHanded NOTIFY leftHandedChanged)
public:
explicit Device(libinput_device *device, QObject *parent = nullptr);
virtual ~Device();
@ -126,10 +127,22 @@ public:
return m_supportsDisableEventsOnExternalMouse;
}
bool isLeftHanded() const {
return m_leftHanded;
}
/**
* Sets the Device to left handed mode if @p set is @c true.
* If @p set is @c false the device is set to right handed mode
**/
void setLeftHanded(bool set);
libinput_device *device() const {
return m_device;
}
Q_SIGNALS:
void leftHandedChanged();
private:
libinput_device *m_device;
bool m_keyboard;
@ -154,6 +167,7 @@ private:
bool m_supportsCalibrationMatrix;
bool m_supportsDisableEvents;
bool m_supportsDisableEventsOnExternalMouse;
bool m_leftHanded;
};
}

View File

@ -30,5 +30,5 @@ if (HAVE_INPUT)
${KWIN_SOURCE_DIR}/udev.cpp
)
add_executable(libinputtest ${libinputtest_SRCS})
target_link_libraries(libinputtest Qt5::Core Qt5::DBus Libinput::Libinput ${UDEV_LIBS} KF5::WindowSystem)
target_link_libraries(libinputtest Qt5::Core Qt5::DBus Libinput::Libinput ${UDEV_LIBS} KF5::ConfigCore KF5::WindowSystem)
endif()