diff --git a/input.h b/input.h --- a/input.h +++ b/input.h @@ -218,6 +218,7 @@ } bool hasAlphaNumericKeyboard(); + bool hasTabletModeSwitch(); void startInteractiveWindowSelection(std::function callback, const QByteArray &cursorName); void startInteractivePositionSelection(std::function callback); @@ -265,6 +266,7 @@ void keyStateChanged(quint32 keyCode, InputRedirection::KeyboardKeyState state); void hasAlphaNumericKeyboardChanged(bool set); + void hasTabletModeSwitchChanged(bool set); private: void setupLibInput(); diff --git a/input.cpp b/input.cpp --- a/input.cpp +++ b/input.cpp @@ -1807,6 +1807,14 @@ emit hasAlphaNumericKeyboardChanged(set); } ); + connect(conn, &LibInput::Connection::hasTabletModeSwitchChanged, this, + [this] (bool set) { + if (m_libInput->isSuspended()) { + return; + } + emit hasTabletModeSwitchChanged(set); + } + ); connect(conn, &LibInput::Connection::hasPointerChanged, this, [this, s] (bool set) { if (m_libInput->isSuspended()) { @@ -1879,6 +1887,16 @@ return true; } +bool InputRedirection::hasTabletModeSwitch() +{ +#if HAVE_INPUT + if (m_libInput) { + return m_libInput->hasTabletModeSwitch(); + } +#endif + return false; +} + void InputRedirection::setupLibInputWithScreens() { #if HAVE_INPUT diff --git a/libinput/connection.h b/libinput/connection.h --- a/libinput/connection.h +++ b/libinput/connection.h @@ -75,6 +75,9 @@ bool hasPointer() const { return m_pointer > 0; } + bool hasTabletModeSwitch() const { + return m_tabletModeSwitch > 0; + } bool isSuspended() const; @@ -111,6 +114,7 @@ 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); @@ -144,10 +148,12 @@ 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; diff --git a/libinput/connection.cpp b/libinput/connection.cpp --- a/libinput/connection.cpp +++ b/libinput/connection.cpp @@ -225,6 +225,7 @@ m_alphaNumericKeyboardBeforeSuspend = hasAlphaNumericKeyboard(); m_pointerBeforeSuspend = hasPointer(); m_touchBeforeSuspend = hasTouch(); + m_tabletModeSwitchBeforeSuspend = hasTabletModeSwitch(); m_input->suspend(); handleEvent(); } @@ -280,6 +281,12 @@ emit hasTouchChanged(true); } } + if (device->isTabletModeSwitch()) { + m_tabletModeSwitch++; + if (m_tabletModeSwitch == 1) { + emit hasTabletModeSwitchChanged(true); + } + } applyDeviceConfig(device); applyScreenToDevice(device); @@ -323,6 +330,12 @@ emit hasTouchChanged(false); } } + if (device->isTabletModeSwitch()) { + m_tabletModeSwitch--; + if (m_tabletModeSwitch == 0) { + emit hasTabletModeSwitchChanged(false); + } + } device->deleteLater(); break; } @@ -494,6 +507,9 @@ if (m_touchBeforeSuspend && !m_touch) { emit hasTouchChanged(false); } + if (m_tabletModeSwitchBeforeSuspend && !m_tabletModeSwitch) { + emit hasTabletModeSwitchChanged(false); + } wasSuspended = false; } } diff --git a/tabletmodemanager.h b/tabletmodemanager.h --- a/tabletmodemanager.h +++ b/tabletmodemanager.h @@ -33,17 +33,25 @@ { 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; + + bool isTabletModeAvailable() const; + void setTabletModeAvailable(bool available); + bool isTablet() const; void setIsTablet(bool tablet); Q_SIGNALS: + void tabletModeAvailableChanged(bool available); void tabletModeChanged(bool tabletMode); private: + bool m_tabletModeAvailable = false; bool m_isTabletMode = false; TabletModeInputEventSpy *m_spy; KWIN_SINGLETON_VARIABLE(TabletModeManager, s_manager) diff --git a/tabletmodemanager.cpp b/tabletmodemanager.cpp --- a/tabletmodemanager.cpp +++ b/tabletmodemanager.cpp @@ -80,6 +80,24 @@ this, QDBusConnection::ExportAllProperties | QDBusConnection::ExportAllSignals ); + + connect(input(), &InputRedirection::hasTabletModeSwitchChanged, this, &TabletModeManager::tabletModeAvailableChanged); +} + +void TabletModeManager::setTabletModeAvailable(bool available) +{ + //TODO: we need to access to libinput::connection from here + if (m_tabletModeAvailable == available) { + return; + } + + m_tabletModeAvailable = available; + emit tabletModeAvailableChanged(available); +} + +bool TabletModeManager::isTabletModeAvailable() const +{ + return input()->hasTabletModeSwitch(); } bool TabletModeManager::isTablet() const