diff --git a/input.h b/input.h --- a/input.h +++ b/input.h @@ -25,6 +25,8 @@ #include #include +#include + class KGlobalAccelInterface; class QKeySequence; class QMouseEvent; @@ -212,6 +214,7 @@ LibInput::Connection *m_libInput = nullptr; QVector m_filters; + KSharedConfigPtr m_inputConfig; KWIN_SINGLETON(InputRedirection) friend InputRedirection *input(); diff --git a/input.cpp b/input.cpp --- a/input.cpp +++ b/input.cpp @@ -788,6 +788,7 @@ } ); } + m_inputConfig = KSharedConfig::openConfig(QStringLiteral("kcminputrc")); } #endif connect(kwinApp(), &Application::workspaceCreated, this, &InputRedirection::setupWorkspace); @@ -913,7 +914,8 @@ { #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 @@ 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] { diff --git a/libinput/connection.h b/libinput/connection.h --- a/libinput/connection.h +++ b/libinput/connection.h @@ -46,6 +46,10 @@ 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 @@ 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 @@ QVector m_eventQueue; bool wasSuspended = false; QVector m_devices; + KSharedConfigPtr m_config; KWIN_SINGLETON(Connection) static QThread *s_thread; diff --git a/libinput/connection.cpp b/libinput/connection.cpp --- a/libinput/connection.cpp +++ b/libinput/connection.cpp @@ -25,6 +25,8 @@ #include "../udev.h" #include "libinput_logging.h" +#include + #include #include #include @@ -88,6 +90,9 @@ , 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 @@ emit hasTouchChanged(true); } } + applyDeviceConfig(device); emit deviceAdded(device); break; } @@ -333,5 +339,29 @@ return s_context->isSuspended(); } +void Connection::applyDeviceConfig(Device *device) +{ + if (device->isPointer()) { + const KConfigGroup group = m_config->group("Mouse"); + if (group.hasKey("MouseButtonMapping")) { + device->setLeftHanded(group.readEntry("MouseButtonMapping", "RightHanded") == QLatin1String("LeftHanded")); + } else { + device->setLeftHanded(false); + } + } +} + +void Connection::slotKGlobalSettingsNotifyChange(int type, int arg) +{ + if (type == 3 /**SettingsChanged**/ && arg == 0 /** SETTINGS_MOUSE **/) { + m_config->reparseConfiguration(); + for (auto it = m_devices.constBegin(); it != m_devices.constEnd(); ++it) { + if ((*it)->isPointer()) { + applyDeviceConfig(*it); + } + } + } +} + } } diff --git a/libinput/device.h b/libinput/device.h --- a/libinput/device.h +++ b/libinput/device.h @@ -55,6 +55,7 @@ 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 @@ 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 @@ bool m_supportsCalibrationMatrix; bool m_supportsDisableEvents; bool m_supportsDisableEventsOnExternalMouse; + bool m_leftHanded; }; } diff --git a/libinput/device.cpp b/libinput/device.cpp --- a/libinput/device.cpp +++ b/libinput/device.cpp @@ -80,6 +80,7 @@ , 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,16 @@ 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) { + m_leftHanded = set; + emit leftHandedChanged(); + } +} + } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -30,5 +30,5 @@ ${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()