Commit 87b688da authored by Marco Martin's avatar Marco Martin
Browse files

Expose if the tablet mode switch is available

Summary:
expose in the libinput wrapper a property that tells whether
a tablet mode switch input device is present on the machine,
expose it trough dbus

Test Plan:
still not complete, I need a way to either access the connection
from TabletModeManager or setting to TabletModeManager from input.cpp

Reviewers: #kwin, #plasma, graesslin

Reviewed By: #kwin, #plasma, graesslin

Subscribers: graesslin, ngraham, davidedmundson, plasma-devel, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D9944
parent df28de87
......@@ -1807,6 +1807,14 @@ void InputRedirection::setupLibInput()
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 @@ bool InputRedirection::hasAlphaNumericKeyboard()
return true;
}
bool InputRedirection::hasTabletModeSwitch()
{
#if HAVE_INPUT
if (m_libInput) {
return m_libInput->hasTabletModeSwitch();
}
#endif
return false;
}
void InputRedirection::setupLibInputWithScreens()
{
#if HAVE_INPUT
......
......@@ -218,6 +218,7 @@ public:
}
bool hasAlphaNumericKeyboard();
bool hasTabletModeSwitch();
void startInteractiveWindowSelection(std::function<void(KWin::Toplevel*)> callback, const QByteArray &cursorName);
void startInteractivePositionSelection(std::function<void(const QPoint &)> callback);
......@@ -265,6 +266,7 @@ Q_SIGNALS:
void keyStateChanged(quint32 keyCode, InputRedirection::KeyboardKeyState state);
void hasAlphaNumericKeyboardChanged(bool set);
void hasTabletModeSwitchChanged(bool set);
private:
void setupLibInput();
......
......@@ -225,6 +225,7 @@ void Connection::deactivate()
m_alphaNumericKeyboardBeforeSuspend = hasAlphaNumericKeyboard();
m_pointerBeforeSuspend = hasPointer();
m_touchBeforeSuspend = hasTouch();
m_tabletModeSwitchBeforeSuspend = hasTabletModeSwitch();
m_input->suspend();
handleEvent();
}
......@@ -280,6 +281,12 @@ void Connection::processEvents()
emit hasTouchChanged(true);
}
}
if (device->isTabletModeSwitch()) {
m_tabletModeSwitch++;
if (m_tabletModeSwitch == 1) {
emit hasTabletModeSwitchChanged(true);
}
}
applyDeviceConfig(device);
applyScreenToDevice(device);
......@@ -323,6 +330,12 @@ void Connection::processEvents()
emit hasTouchChanged(false);
}
}
if (device->isTabletModeSwitch()) {
m_tabletModeSwitch--;
if (m_tabletModeSwitch == 0) {
emit hasTabletModeSwitchChanged(false);
}
}
device->deleteLater();
break;
}
......@@ -492,6 +505,9 @@ void Connection::processEvents()
if (m_touchBeforeSuspend && !m_touch) {
emit hasTouchChanged(false);
}
if (m_tabletModeSwitchBeforeSuspend && !m_tabletModeSwitch) {
emit hasTabletModeSwitchChanged(false);
}
wasSuspended = false;
}
}
......
......@@ -75,6 +75,9 @@ public:
bool hasPointer() const {
return m_pointer > 0;
}
bool hasTabletModeSwitch() const {
return m_tabletModeSwitch > 0;
}
bool isSuspended() const;
......@@ -111,6 +114,7 @@ Q_SIGNALS:
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 @@ private:
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<Event*> m_eventQueue;
bool wasSuspended = false;
......
......@@ -80,6 +80,13 @@ TabletModeManager::TabletModeManager(QObject *parent)
this,
QDBusConnection::ExportAllProperties | QDBusConnection::ExportAllSignals
);
connect(input(), &InputRedirection::hasTabletModeSwitchChanged, this, &TabletModeManager::tabletModeAvailableChanged);
}
bool TabletModeManager::isTabletModeAvailable() const
{
return input()->hasTabletModeSwitch();
}
bool TabletModeManager::isTablet() const
......
......@@ -33,17 +33,24 @@ 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;
bool isTabletModeAvailable() const;
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)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment