diff --git a/input.cpp b/input.cpp index 8a506725bf..d21923cc4d 100644 --- a/input.cpp +++ b/input.cpp @@ -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] { diff --git a/input.h b/input.h index d24829db71..b68b8abcc8 100644 --- a/input.h +++ b/input.h @@ -25,6 +25,8 @@ along with this program. If not, see . #include #include +#include + class KGlobalAccelInterface; class QKeySequence; class QMouseEvent; @@ -212,6 +214,7 @@ private: LibInput::Connection *m_libInput = nullptr; QVector m_filters; + KSharedConfigPtr m_inputConfig; KWIN_SINGLETON(InputRedirection) friend InputRedirection *input(); diff --git a/libinput/connection.cpp b/libinput/connection.cpp index f0cc3642e7..8c8550d00c 100644 --- a/libinput/connection.cpp +++ b/libinput/connection.cpp @@ -25,6 +25,8 @@ along with this program. If not, see . #include "../udev.h" #include "libinput_logging.h" +#include + #include #include #include @@ -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); + } + } + } +} + } } diff --git a/libinput/connection.h b/libinput/connection.h index b9133aba8e..6dd420c501 100644 --- a/libinput/connection.h +++ b/libinput/connection.h @@ -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 m_eventQueue; bool wasSuspended = false; QVector m_devices; + KSharedConfigPtr m_config; KWIN_SINGLETON(Connection) static QThread *s_thread; diff --git a/libinput/device.cpp b/libinput/device.cpp index 34d2b3055a..a47349b9f7 100644 --- a/libinput/device.cpp +++ b/libinput/device.cpp @@ -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(); + } + } +} + } } diff --git a/libinput/device.h b/libinput/device.h index d9a80e4331..e9494896a8 100644 --- a/libinput/device.h +++ b/libinput/device.h @@ -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; }; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e5f199937a..ae094588e3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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()