diff --git a/libinput/connection.h b/libinput/connection.h index 44495ed19..b45beecae 100644 --- a/libinput/connection.h +++ b/libinput/connection.h @@ -1,172 +1,172 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2014 Martin Gräßlin 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, see . *********************************************************************/ #ifndef KWIN_LIBINPUT_CONNECTION_H #define KWIN_LIBINPUT_CONNECTION_H #include "../input.h" #include "../keyboard_input.h" #include #include #include #include #include #include #include class QSocketNotifier; class QThread; namespace KWin { namespace LibInput { class Event; class Device; class Context; -class Connection : public QObject +class KWIN_EXPORT Connection : public QObject { Q_OBJECT 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 * the screen data. **/ void setScreenSize(const QSize &size); void updateScreens(); bool hasKeyboard() const { return m_keyboard > 0; } bool hasAlphaNumericKeyboard() const { return m_alphaNumericKeyboard > 0; } bool hasTouch() const { return m_touch > 0; } bool hasPointer() const { return m_pointer > 0; } bool hasTabletModeSwitch() const { return m_tabletModeSwitch > 0; } bool isSuspended() const; void deactivate(); void processEvents(); void toggleTouchpads(); void enableTouchpads(); void disableTouchpads(); QVector devices() const { return m_devices; } QStringList devicesSysNames() const; void updateLEDs(KWin::Xkb::LEDs leds); static void createThread(); Q_SIGNALS: void keyChanged(quint32 key, KWin::InputRedirection::KeyboardKeyState, quint32 time, KWin::LibInput::Device *device); void pointerButtonChanged(quint32 button, KWin::InputRedirection::PointerButtonState state, quint32 time, KWin::LibInput::Device *device); void pointerMotionAbsolute(QPointF orig, QPointF screen, quint32 time, KWin::LibInput::Device *device); void pointerMotion(const QSizeF &delta, const QSizeF &deltaNonAccelerated, quint32 time, quint64 timeMicroseconds, KWin::LibInput::Device *device); void pointerAxisChanged(KWin::InputRedirection::PointerAxis axis, qreal delta, quint32 time, KWin::LibInput::Device *device); void touchFrame(KWin::LibInput::Device *device); void touchCanceled(KWin::LibInput::Device *device); void touchDown(qint32 id, const QPointF &absolutePos, quint32 time, KWin::LibInput::Device *device); void touchUp(qint32 id, quint32 time, KWin::LibInput::Device *device); void touchMotion(qint32 id, const QPointF &absolutePos, quint32 time, KWin::LibInput::Device *device); void hasKeyboardChanged(bool); void hasAlphaNumericKeyboardChanged(bool); void hasPointerChanged(bool); void hasTouchChanged(bool); void hasTabletModeSwitchChanged(bool); void deviceAdded(KWin::LibInput::Device *); void deviceRemoved(KWin::LibInput::Device *); void deviceAddedSysName(QString); void deviceRemovedSysName(QString); void swipeGestureBegin(int fingerCount, quint32 time, KWin::LibInput::Device *device); void swipeGestureUpdate(const QSizeF &delta, quint32 time, KWin::LibInput::Device *device); void swipeGestureEnd(quint32 time, KWin::LibInput::Device *device); void swipeGestureCancelled(quint32 time, KWin::LibInput::Device *device); void pinchGestureBegin(int fingerCount, quint32 time, KWin::LibInput::Device *device); void pinchGestureUpdate(qreal scale, qreal angleDelta, const QSizeF &delta, quint32 time, KWin::LibInput::Device *device); void pinchGestureEnd(quint32 time, KWin::LibInput::Device *device); void pinchGestureCancelled(quint32 time, KWin::LibInput::Device *device); void switchToggledOn(quint32 time, quint64 timeMicroseconds, KWin::LibInput::Device *device); void switchToggledOff(quint32 time, quint64 timeMicroseconds, KWin::LibInput::Device *device); void eventsRead(); private Q_SLOTS: void doSetup(); void slotKGlobalSettingsNotifyChange(int type, int arg); private: Connection(Context *input, QObject *parent = nullptr); void handleEvent(); void applyDeviceConfig(Device *device); void applyScreenToDevice(Device *device); Context *m_input; QSocketNotifier *m_notifier; QSize m_size; int m_keyboard = 0; int m_alphaNumericKeyboard = 0; int m_pointer = 0; int m_touch = 0; int m_tabletModeSwitch = 0; bool m_keyboardBeforeSuspend = false; bool m_alphaNumericKeyboardBeforeSuspend = false; bool m_pointerBeforeSuspend = false; bool m_touchBeforeSuspend = false; bool m_tabletModeSwitchBeforeSuspend = false; QMutex m_mutex; QVector m_eventQueue; bool wasSuspended = false; QVector m_devices; KSharedConfigPtr m_config; bool m_touchpadsEnabled = true; Xkb::LEDs m_leds; KWIN_SINGLETON(Connection) static QPointer s_thread; }; } } #endif diff --git a/libinput/device.h b/libinput/device.h index e325a2943..0c827ad2e 100644 --- a/libinput/device.h +++ b/libinput/device.h @@ -1,581 +1,582 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2016 Martin Gräßlin 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, see . *********************************************************************/ #ifndef KWIN_LIBINPUT_DEVICE_H #define KWIN_LIBINPUT_DEVICE_H #include #include #include #include #include #include +#include "kwin_export.h" struct libinput_device; namespace KWin { namespace LibInput { enum class ConfigKey; -class Device : public QObject +class KWIN_EXPORT Device : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.KWin.InputDevice") // // general Q_PROPERTY(bool keyboard READ isKeyboard CONSTANT) Q_PROPERTY(bool alphaNumericKeyboard READ isAlphaNumericKeyboard CONSTANT) Q_PROPERTY(bool pointer READ isPointer CONSTANT) Q_PROPERTY(bool touchpad READ isTouchpad CONSTANT) Q_PROPERTY(bool touch READ isTouch CONSTANT) Q_PROPERTY(bool tabletTool READ isTabletTool CONSTANT) Q_PROPERTY(bool tabletPad READ isTabletPad CONSTANT) Q_PROPERTY(bool gestureSupport READ supportsGesture CONSTANT) Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QString sysName READ sysName CONSTANT) Q_PROPERTY(QString outputName READ outputName CONSTANT) Q_PROPERTY(QSizeF size READ size CONSTANT) Q_PROPERTY(quint32 product READ product CONSTANT) Q_PROPERTY(quint32 vendor READ vendor CONSTANT) Q_PROPERTY(bool supportsDisableEvents READ supportsDisableEvents CONSTANT) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) // // advanced Q_PROPERTY(int supportedButtons READ supportedButtons CONSTANT) Q_PROPERTY(bool supportsCalibrationMatrix READ supportsCalibrationMatrix CONSTANT) Q_PROPERTY(bool supportsLeftHanded READ supportsLeftHanded CONSTANT) Q_PROPERTY(bool leftHandedEnabledByDefault READ leftHandedEnabledByDefault CONSTANT) Q_PROPERTY(bool leftHanded READ isLeftHanded WRITE setLeftHanded NOTIFY leftHandedChanged) Q_PROPERTY(bool supportsDisableEventsOnExternalMouse READ supportsDisableEventsOnExternalMouse CONSTANT) Q_PROPERTY(bool supportsDisableWhileTyping READ supportsDisableWhileTyping CONSTANT) Q_PROPERTY(bool disableWhileTypingEnabledByDefault READ disableWhileTypingEnabledByDefault CONSTANT) Q_PROPERTY(bool disableWhileTyping READ isDisableWhileTyping WRITE setDisableWhileTyping NOTIFY disableWhileTypingChanged) // // acceleration speed and profile Q_PROPERTY(bool supportsPointerAcceleration READ supportsPointerAcceleration CONSTANT) Q_PROPERTY(qreal defaultPointerAcceleration READ defaultPointerAcceleration CONSTANT) Q_PROPERTY(qreal pointerAcceleration READ pointerAcceleration WRITE setPointerAcceleration NOTIFY pointerAccelerationChanged) Q_PROPERTY(bool supportsPointerAccelerationProfileFlat READ supportsPointerAccelerationProfileFlat CONSTANT) Q_PROPERTY(bool defaultPointerAccelerationProfileFlat READ defaultPointerAccelerationProfileFlat CONSTANT) Q_PROPERTY(bool pointerAccelerationProfileFlat READ pointerAccelerationProfileFlat WRITE setPointerAccelerationProfileFlat NOTIFY pointerAccelerationProfileChanged) Q_PROPERTY(bool supportsPointerAccelerationProfileAdaptive READ supportsPointerAccelerationProfileAdaptive CONSTANT) Q_PROPERTY(bool defaultPointerAccelerationProfileAdaptive READ defaultPointerAccelerationProfileAdaptive CONSTANT) Q_PROPERTY(bool pointerAccelerationProfileAdaptive READ pointerAccelerationProfileAdaptive WRITE setPointerAccelerationProfileAdaptive NOTIFY pointerAccelerationProfileChanged) // // tapping Q_PROPERTY(int tapFingerCount READ tapFingerCount CONSTANT) Q_PROPERTY(bool tapToClickEnabledByDefault READ tapToClickEnabledByDefault CONSTANT) Q_PROPERTY(bool tapToClick READ isTapToClick WRITE setTapToClick NOTIFY tapToClickChanged) Q_PROPERTY(bool supportsLmrTapButtonMap READ supportsLmrTapButtonMap CONSTANT) Q_PROPERTY(bool lmrTapButtonMapEnabledByDefault READ lmrTapButtonMapEnabledByDefault CONSTANT) Q_PROPERTY(bool lmrTapButtonMap READ lmrTapButtonMap WRITE setLmrTapButtonMap NOTIFY tapButtonMapChanged) Q_PROPERTY(bool tapAndDragEnabledByDefault READ tapAndDragEnabledByDefault CONSTANT) Q_PROPERTY(bool tapAndDrag READ isTapAndDrag WRITE setTapAndDrag NOTIFY tapAndDragChanged) Q_PROPERTY(bool tapDragLockEnabledByDefault READ tapDragLockEnabledByDefault CONSTANT) Q_PROPERTY(bool tapDragLock READ isTapDragLock WRITE setTapDragLock NOTIFY tapDragLockChanged) Q_PROPERTY(bool supportsMiddleEmulation READ supportsMiddleEmulation CONSTANT) Q_PROPERTY(bool middleEmulationEnabledByDefault READ middleEmulationEnabledByDefault CONSTANT) Q_PROPERTY(bool middleEmulation READ isMiddleEmulation WRITE setMiddleEmulation NOTIFY middleEmulationChanged) // // scrolling Q_PROPERTY(bool supportsNaturalScroll READ supportsNaturalScroll CONSTANT) Q_PROPERTY(bool naturalScrollEnabledByDefault READ naturalScrollEnabledByDefault CONSTANT) Q_PROPERTY(bool naturalScroll READ isNaturalScroll WRITE setNaturalScroll NOTIFY naturalScrollChanged) Q_PROPERTY(bool supportsScrollTwoFinger READ supportsScrollTwoFinger CONSTANT) Q_PROPERTY(bool scrollTwoFingerEnabledByDefault READ scrollTwoFingerEnabledByDefault CONSTANT) Q_PROPERTY(bool scrollTwoFinger READ isScrollTwoFinger WRITE setScrollTwoFinger NOTIFY scrollMethodChanged) Q_PROPERTY(bool supportsScrollEdge READ supportsScrollEdge CONSTANT) Q_PROPERTY(bool scrollEdgeEnabledByDefault READ scrollEdgeEnabledByDefault CONSTANT) Q_PROPERTY(bool scrollEdge READ isScrollEdge WRITE setScrollEdge NOTIFY scrollMethodChanged) Q_PROPERTY(bool supportsScrollOnButtonDown READ supportsScrollOnButtonDown CONSTANT) Q_PROPERTY(bool scrollOnButtonDownEnabledByDefault READ scrollOnButtonDownEnabledByDefault CONSTANT) Q_PROPERTY(quint32 defaultScrollButton READ defaultScrollButton CONSTANT) Q_PROPERTY(bool scrollOnButtonDown READ isScrollOnButtonDown WRITE setScrollOnButtonDown NOTIFY scrollMethodChanged) Q_PROPERTY(quint32 scrollButton READ scrollButton WRITE setScrollButton NOTIFY scrollButtonChanged) // switches Q_PROPERTY(bool switchDevice READ isSwitch CONSTANT) Q_PROPERTY(bool lidSwitch READ isLidSwitch CONSTANT) Q_PROPERTY(bool tabletModeSwitch READ isTabletModeSwitch CONSTANT) // Click Methods Q_PROPERTY(bool supportsClickMethodAreas READ supportsClickMethodAreas CONSTANT) Q_PROPERTY(bool defaultClickMethodAreas READ defaultClickMethodAreas CONSTANT) Q_PROPERTY(bool clickMethodAreas READ isClickMethodAreas WRITE setClickMethodAreas NOTIFY clickMethodChanged) Q_PROPERTY(bool supportsClickMethodClickfinger READ supportsClickMethodClickfinger CONSTANT) Q_PROPERTY(bool defaultClickMethodClickfinger READ defaultClickMethodClickfinger CONSTANT) Q_PROPERTY(bool clickMethodClickfinger READ isClickMethodClickfinger WRITE setClickMethodClickfinger NOTIFY clickMethodChanged) public: explicit Device(libinput_device *device, QObject *parent = nullptr); virtual ~Device(); bool isKeyboard() const { return m_keyboard; } bool isAlphaNumericKeyboard() const { return m_alphaNumericKeyboard; } bool isPointer() const { return m_pointer; } bool isTouchpad() const{ return m_pointer && // ignore all combined devices. E.g. a touchpad on a keyboard we don't want to toggle // as that would result in the keyboard going off as well !(m_keyboard || m_touch || m_tabletPad || m_tabletTool) && // is this a touch pad? We don't really know, let's do some assumptions (m_tapFingerCount > 0 || m_supportsDisableWhileTyping || m_supportsDisableEventsOnExternalMouse); } bool isTouch() const { return m_touch; } bool isTabletTool() const { return m_tabletTool; } bool isTabletPad() const { return m_tabletPad; } bool supportsGesture() const { return m_supportsGesture; } QString name() const { return m_name; } QString sysName() const { return m_sysName; } QString outputName() const { return m_outputName; } QSizeF size() const { return m_size; } quint32 product() const { return m_product; } quint32 vendor() const { return m_vendor; } Qt::MouseButtons supportedButtons() const { return m_supportedButtons; } int tapFingerCount() const { return m_tapFingerCount; } bool tapToClickEnabledByDefault() const { return m_tapToClickEnabledByDefault; } bool isTapToClick() const { return m_tapToClick; } /** * Set the Device to tap to click if @p set is @c true. **/ void setTapToClick(bool set); bool tapAndDragEnabledByDefault() const { return m_tapAndDragEnabledByDefault; } bool isTapAndDrag() const { return m_tapAndDrag; } void setTapAndDrag(bool set); bool tapDragLockEnabledByDefault() const { return m_tapDragLockEnabledByDefault; } bool isTapDragLock() const { return m_tapDragLock; } void setTapDragLock(bool set); bool supportsDisableWhileTyping() const { return m_supportsDisableWhileTyping; } bool disableWhileTypingEnabledByDefault() const { return m_disableWhileTypingEnabledByDefault; } bool supportsPointerAcceleration() const { return m_supportsPointerAcceleration; } bool supportsLeftHanded() const { return m_supportsLeftHanded; } bool supportsCalibrationMatrix() const { return m_supportsCalibrationMatrix; } bool supportsDisableEvents() const { return m_supportsDisableEvents; } bool supportsDisableEventsOnExternalMouse() const { return m_supportsDisableEventsOnExternalMouse; } bool supportsMiddleEmulation() const { return m_supportsMiddleEmulation; } bool supportsNaturalScroll() const { return m_supportsNaturalScroll; } bool supportsScrollTwoFinger() const { return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_2FG); } bool supportsScrollEdge() const { return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_EDGE); } bool supportsScrollOnButtonDown() const { return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); } bool leftHandedEnabledByDefault() const { return m_leftHandedEnabledByDefault; } bool middleEmulationEnabledByDefault() const { return m_middleEmulationEnabledByDefault; } bool naturalScrollEnabledByDefault() const { return m_naturalScrollEnabledByDefault; } enum libinput_config_scroll_method defaultScrollMethod() const { return m_defaultScrollMethod; } quint32 defaultScrollMethodToInt() const { return (quint32) m_defaultScrollMethod; } bool scrollTwoFingerEnabledByDefault() const { return m_defaultScrollMethod == LIBINPUT_CONFIG_SCROLL_2FG; } bool scrollEdgeEnabledByDefault() const { return m_defaultScrollMethod == LIBINPUT_CONFIG_SCROLL_EDGE; } bool scrollOnButtonDownEnabledByDefault() const { return m_defaultScrollMethod == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; } bool supportsLmrTapButtonMap() const { return m_tapFingerCount > 1; } bool lmrTapButtonMapEnabledByDefault() const { return m_defaultTapButtonMap == LIBINPUT_CONFIG_TAP_MAP_LMR; } void setLmrTapButtonMap(bool set); bool lmrTapButtonMap() const { return m_tapButtonMap & LIBINPUT_CONFIG_TAP_MAP_LMR; } quint32 defaultScrollButton() const { return m_defaultScrollButton; } bool isMiddleEmulation() const { return m_middleEmulation; } void setMiddleEmulation(bool set); bool isNaturalScroll() const { return m_naturalScroll; } void setNaturalScroll(bool set); void setScrollMethod(bool set, enum libinput_config_scroll_method method); bool isScrollTwoFinger() const { return m_scrollMethod & LIBINPUT_CONFIG_SCROLL_2FG; } void setScrollTwoFinger(bool set) { setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_2FG); } bool isScrollEdge() const { return m_scrollMethod & LIBINPUT_CONFIG_SCROLL_EDGE; } void setScrollEdge(bool set) { setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_EDGE); } bool isScrollOnButtonDown() const { return m_scrollMethod & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; } void setScrollOnButtonDown(bool set) { setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN); } void activateScrollMethodFromInt(quint32 method) { setScrollMethod(true, (libinput_config_scroll_method) method); } quint32 scrollButton() const { return m_scrollButton; } void setScrollButton(quint32 button); void setDisableWhileTyping(bool set); bool isDisableWhileTyping() const { return m_disableWhileTyping; } 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); qreal defaultPointerAcceleration() const { return m_defaultPointerAcceleration; } qreal pointerAcceleration() const { return m_pointerAcceleration; } /** * @param acceleration mapped to range [-1,1] with -1 being the slowest, 1 being the fastest supported acceleration. **/ void setPointerAcceleration(qreal acceleration); void setPointerAccelerationFromString(QString acceleration) { setPointerAcceleration(acceleration.toDouble()); } QString defaultPointerAccelerationToString() const { return QString::number(m_pointerAcceleration, 'f', 3); } bool supportsPointerAccelerationProfileFlat() const { return (m_supportedPointerAccelerationProfiles & LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); } bool supportsPointerAccelerationProfileAdaptive() const { return (m_supportedPointerAccelerationProfiles & LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); } bool defaultPointerAccelerationProfileFlat() const { return (m_defaultPointerAccelerationProfile & LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); } bool defaultPointerAccelerationProfileAdaptive() const { return (m_defaultPointerAccelerationProfile & LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); } bool pointerAccelerationProfileFlat() const { return (m_pointerAccelerationProfile & LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); } bool pointerAccelerationProfileAdaptive() const { return (m_pointerAccelerationProfile & LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); } void setPointerAccelerationProfile(bool set, enum libinput_config_accel_profile profile); void setPointerAccelerationProfileFlat(bool set) { setPointerAccelerationProfile(set, LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); } void setPointerAccelerationProfileAdaptive(bool set) { setPointerAccelerationProfile(set, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); } void setPointerAccelerationProfileFromInt(quint32 profile) { setPointerAccelerationProfile(true, (libinput_config_accel_profile) profile); } quint32 defaultPointerAccelerationProfileToInt() const { return (quint32) m_defaultPointerAccelerationProfile; } bool supportsClickMethodAreas() const { return (m_supportedClickMethods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); } bool defaultClickMethodAreas() const { return (m_defaultClickMethod == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); } bool isClickMethodAreas() const { return (m_clickMethod == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); } bool supportsClickMethodClickfinger() const { return (m_supportedClickMethods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); } bool defaultClickMethodClickfinger() const { return (m_defaultClickMethod == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); } bool isClickMethodClickfinger() const { return (m_clickMethod == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); } void setClickMethod(bool set, enum libinput_config_click_method method); void setClickMethodAreas(bool set) { setClickMethod(set, LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); } void setClickMethodClickfinger(bool set) { setClickMethod(set, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); } void setClickMethodFromInt(quint32 method) { setClickMethod(true, (libinput_config_click_method) method); } quint32 defaultClickMethodToInt() const { return (quint32) m_defaultClickMethod; } bool isEnabled() const { return m_enabled; } void setEnabled(bool enabled); libinput_device *device() const { return m_device; } /** * Sets the @p config to load the Device configuration from and to store each * successful Device configuration. **/ void setConfig(const KConfigGroup &config) { m_config = config; } /** * The id of the screen in KWin identifiers. Set from KWin through setScreenId. **/ int screenId() const { return m_screenId; } /** * Sets the KWin screen id for the device **/ void setScreenId(int screenId) { m_screenId = screenId; } void setOrientation(Qt::ScreenOrientation orientation); /** * Loads the configuration and applies it to the Device **/ void loadConfiguration(); bool isSwitch() const { return m_switch; } bool isLidSwitch() const { return m_lidSwitch; } bool isTabletModeSwitch() const { return m_tabletSwitch; } /** * All created Devices **/ static QVector devices() { return s_devices; } /** * Gets the Device for @p native. @c null if there is no Device for @p native. **/ static Device *getDevice(libinput_device *native); Q_SIGNALS: void tapButtonMapChanged(); void leftHandedChanged(); void disableWhileTypingChanged(); void pointerAccelerationChanged(); void pointerAccelerationProfileChanged(); void enabledChanged(); void tapToClickChanged(); void tapAndDragChanged(); void tapDragLockChanged(); void middleEmulationChanged(); void naturalScrollChanged(); void scrollMethodChanged(); void scrollButtonChanged(); void clickMethodChanged(); private: template void writeEntry(const ConfigKey &key, const T &value); template void readEntry(const QByteArray &key, const Setter &s, const T &defaultValue = T()); libinput_device *m_device; bool m_keyboard; bool m_alphaNumericKeyboard = false; bool m_pointer; bool m_touch; bool m_tabletTool; bool m_tabletPad; bool m_supportsGesture; bool m_switch = false; bool m_lidSwitch = false; bool m_tabletSwitch = false; QString m_name; QString m_sysName; QString m_outputName; QSizeF m_size; quint32 m_product; quint32 m_vendor; Qt::MouseButtons m_supportedButtons = Qt::NoButton; int m_tapFingerCount; enum libinput_config_tap_button_map m_defaultTapButtonMap; enum libinput_config_tap_button_map m_tapButtonMap; bool m_tapToClickEnabledByDefault; bool m_tapToClick; bool m_tapAndDragEnabledByDefault; bool m_tapAndDrag; bool m_tapDragLockEnabledByDefault; bool m_tapDragLock; bool m_supportsDisableWhileTyping; bool m_supportsPointerAcceleration; bool m_supportsLeftHanded; bool m_supportsCalibrationMatrix; bool m_supportsDisableEvents; bool m_supportsDisableEventsOnExternalMouse; bool m_supportsMiddleEmulation; bool m_supportsNaturalScroll; quint32 m_supportedScrollMethods; bool m_supportsScrollEdge; bool m_supportsScrollOnButtonDown; bool m_leftHandedEnabledByDefault; bool m_middleEmulationEnabledByDefault; bool m_naturalScrollEnabledByDefault; enum libinput_config_scroll_method m_defaultScrollMethod; quint32 m_defaultScrollButton; bool m_disableWhileTypingEnabledByDefault; bool m_disableWhileTyping; bool m_middleEmulation; bool m_leftHanded; bool m_naturalScroll; enum libinput_config_scroll_method m_scrollMethod; quint32 m_scrollButton; qreal m_defaultPointerAcceleration; qreal m_pointerAcceleration; quint32 m_supportedPointerAccelerationProfiles; enum libinput_config_accel_profile m_defaultPointerAccelerationProfile; enum libinput_config_accel_profile m_pointerAccelerationProfile; bool m_enabled; KConfigGroup m_config; bool m_loading = false; int m_screenId = 0; Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation; QMatrix4x4 m_defaultCalibrationMatrix; quint32 m_supportedClickMethods; enum libinput_config_click_method m_defaultClickMethod; enum libinput_config_click_method m_clickMethod; static QVector s_devices; }; } } Q_DECLARE_METATYPE(KWin::LibInput::Device*) #endif diff --git a/tabletmodemanager.cpp b/tabletmodemanager.cpp index 977670609..09d7d9ed3 100644 --- a/tabletmodemanager.cpp +++ b/tabletmodemanager.cpp @@ -1,103 +1,170 @@ /* * Copyright 2018 Marco Martin * * 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) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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, see . * */ #include "tabletmodemanager.h" #include "input.h" #include "input_event.h" #include "input_event_spy.h" #include "libinput/device.h" +#include "libinput/connection.h" +#include #include using namespace KWin; KWIN_SINGLETON_FACTORY_VARIABLE(TabletModeManager, s_manager) -class KWin::TabletModeInputEventSpy : public InputEventSpy +class TabletModeSwitchEventSpy : public QObject, public InputEventSpy { public: - explicit TabletModeInputEventSpy(TabletModeManager *parent); + explicit TabletModeSwitchEventSpy(TabletModeManager *parent) + : QObject(parent) + , m_parent(parent) + { + } + + void switchEvent(SwitchEvent *event) override + { + if (!event->device()->isTabletModeSwitch()) { + return; + } + + switch (event->state()) { + case SwitchEvent::State::Off: + m_parent->setIsTablet(false); + break; + case SwitchEvent::State::On: + m_parent->setIsTablet(true); + break; + default: + Q_UNREACHABLE(); + } + } - void switchEvent(SwitchEvent *event) override; private: - TabletModeManager *m_parent; + TabletModeManager * const m_parent; }; -TabletModeInputEventSpy::TabletModeInputEventSpy(TabletModeManager *parent) - : m_parent(parent) -{ -} -void TabletModeInputEventSpy::switchEvent(SwitchEvent *event) +class TabletModeTouchpadRemovedSpy : public QObject { - if (!event->device()->isTabletModeSwitch()) { - return; +public: + explicit TabletModeTouchpadRemovedSpy(TabletModeManager *parent) + : QObject(parent) + , m_parent(parent) + { + auto c = LibInput::Connection::self(); + connect(c, &LibInput::Connection::deviceAdded, this, &TabletModeTouchpadRemovedSpy::refresh); + connect(c, &LibInput::Connection::deviceRemoved, this, &TabletModeTouchpadRemovedSpy::refresh); + + check(); } - switch (event->state()) { - case SwitchEvent::State::Off: - m_parent->setIsTablet(false); - break; - case SwitchEvent::State::On: - m_parent->setIsTablet(true); - break; - default: - Q_UNREACHABLE(); + void refresh(LibInput::Device* d) { + if (!d->isTouch() && !d->isPointer()) + return; + check(); } -} + void check() { + if (!LibInput::Connection::self()) { + qDebug() << "no libinput :("; + return; + } + const auto devices = LibInput::Connection::self()->devices(); + const bool hasTouch = std::any_of(devices.constBegin(), devices.constEnd(), [](LibInput::Device* device){ return device->isTouch(); }); + m_parent->setTabletModeAvailable(hasTouch); + + const bool hasPointer = std::any_of(devices.constBegin(), devices.constEnd(), [](LibInput::Device* device){ return device->isPointer(); }); + m_parent->setIsTablet(hasTouch && !hasPointer); + } +private: + TabletModeManager * const m_parent; +}; TabletModeManager::TabletModeManager(QObject *parent) - : QObject(parent), - m_spy(new TabletModeInputEventSpy(this)) + : QObject(parent) { - input()->installInputEventSpy(m_spy); + if (input()->hasTabletModeSwitch()) { + input()->installInputEventSpy(new TabletModeSwitchEventSpy(this)); + } else { + hasTabletModeInputChanged(false); + } QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/kde/KWin"), QStringLiteral("org.kde.KWin.TabletModeManager"), this, QDBusConnection::ExportAllProperties | QDBusConnection::ExportAllSignals ); connect(input(), &InputRedirection::hasTabletModeSwitchChanged, this, &TabletModeManager::tabletModeAvailableChanged); } +void KWin::TabletModeManager::hasTabletModeInputChanged(bool set) +{ + if (set) { + input()->installInputEventSpy(new TabletModeSwitchEventSpy(this)); + setTabletModeAvailable(true); + } else { + auto setupDetector = [this] { + auto spy = new TabletModeTouchpadRemovedSpy(this); + connect(input(), &InputRedirection::hasTabletModeSwitchChanged, spy, [spy](bool set){ + if (set) + spy->deleteLater(); + }); + }; + if (LibInput::Connection::self()) + setupDetector(); + else + QTimer::singleShot(2000, this, setupDetector); + } +} + bool TabletModeManager::isTabletModeAvailable() const { - return input()->hasTabletModeSwitch(); + return m_detecting; } bool TabletModeManager::isTablet() const { return m_isTabletMode; } void TabletModeManager::setIsTablet(bool tablet) { if (m_isTabletMode == tablet) { return; } m_isTabletMode = tablet; emit tabletModeChanged(tablet); } + +void KWin::TabletModeManager::setTabletModeAvailable(bool detecting) +{ + if (m_detecting != detecting) { + m_detecting = detecting; + tabletModeAvailableChanged(detecting); + } +} diff --git a/tabletmodemanager.h b/tabletmodemanager.h index 83ee27cfc..add1076cb 100644 --- a/tabletmodemanager.h +++ b/tabletmodemanager.h @@ -1,60 +1,61 @@ /* * Copyright 2018 Marco Martin * * 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) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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, see . * */ #ifndef KWIN_TABLETMODEMANAGER_H #define KWIN_TABLETMODEMANAGER_H #include #include namespace KWin { -class TabletModeInputEventSpy; - class TabletModeManager : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.KWin.TabletModeManager") //assuming such a switch is not pluggable for now Q_PROPERTY(bool tabletModeAvailable READ isTabletModeAvailable NOTIFY tabletModeAvailableChanged) Q_PROPERTY(bool tabletMode READ isTablet NOTIFY tabletModeChanged) public: ~TabletModeManager() = default; + void setTabletModeAvailable(bool detecting); bool isTabletModeAvailable() const; bool isTablet() const; void setIsTablet(bool tablet); Q_SIGNALS: void tabletModeAvailableChanged(bool available); void tabletModeChanged(bool tabletMode); private: + void hasTabletModeInputChanged(bool set); + bool m_tabletModeAvailable = false; bool m_isTabletMode = false; - TabletModeInputEventSpy *m_spy; + bool m_detecting = false; KWIN_SINGLETON_VARIABLE(TabletModeManager, s_manager) }; } #endif // KWIN_TABLETMODEMANAGER_H