A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
/*
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2018 Marco Martin <mart@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
|
|
|
|
*/
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
|
|
|
|
#include "tabletmodemanager.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "input_event.h"
|
|
|
|
#include "input_event_spy.h"
|
|
|
|
|
|
|
|
#include "libinput/device.h"
|
2019-03-22 17:29:15 +00:00
|
|
|
#include "libinput/connection.h"
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
|
2019-03-22 17:29:15 +00:00
|
|
|
#include <QTimer>
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
#include <QDBusConnection>
|
|
|
|
|
2020-08-21 10:32:04 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
|
|
|
|
KWIN_SINGLETON_FACTORY_VARIABLE(TabletModeManager, s_manager)
|
|
|
|
|
2019-03-22 17:29:15 +00:00
|
|
|
class TabletModeSwitchEventSpy : public QObject, public InputEventSpy
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-03-22 17:29:15 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
|
|
|
|
private:
|
2019-03-22 17:29:15 +00:00
|
|
|
TabletModeManager * const m_parent;
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-03-22 17:29:15 +00:00
|
|
|
class TabletModeTouchpadRemovedSpy : public QObject
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
{
|
2019-03-22 17:29:15 +00:00
|
|
|
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();
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 17:29:15 +00:00
|
|
|
void refresh(LibInput::Device* d) {
|
|
|
|
if (!d->isTouch() && !d->isPointer())
|
|
|
|
return;
|
|
|
|
check();
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 17:29:15 +00:00
|
|
|
void check() {
|
|
|
|
if (!LibInput::Connection::self()) {
|
|
|
|
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);
|
|
|
|
}
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
|
2019-03-22 17:29:15 +00:00
|
|
|
private:
|
|
|
|
TabletModeManager * const m_parent;
|
|
|
|
};
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
|
|
|
|
TabletModeManager::TabletModeManager(QObject *parent)
|
2019-03-22 17:29:15 +00:00
|
|
|
: QObject(parent)
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
{
|
2019-03-22 17:29:15 +00:00
|
|
|
if (input()->hasTabletModeSwitch()) {
|
|
|
|
input()->installInputEventSpy(new TabletModeSwitchEventSpy(this));
|
|
|
|
} else {
|
|
|
|
hasTabletModeInputChanged(false);
|
|
|
|
}
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
|
|
|
|
QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/kde/KWin"),
|
|
|
|
QStringLiteral("org.kde.KWin.TabletModeManager"),
|
|
|
|
this,
|
|
|
|
QDBusConnection::ExportAllProperties | QDBusConnection::ExportAllSignals
|
|
|
|
);
|
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
2018-01-24 10:36:56 +00:00
|
|
|
|
2020-03-11 07:13:10 +00:00
|
|
|
connect(input(), &InputRedirection::hasTabletModeSwitchChanged, this, &TabletModeManager::hasTabletModeInputChanged);
|
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
2018-01-24 10:36:56 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 17:29:15 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
2018-01-24 10:36:56 +00:00
|
|
|
bool TabletModeManager::isTabletModeAvailable() const
|
|
|
|
{
|
2019-03-22 17:29:15 +00:00
|
|
|
return m_detecting;
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TabletModeManager::isTablet() const
|
|
|
|
{
|
|
|
|
return m_isTabletMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabletModeManager::setIsTablet(bool tablet)
|
|
|
|
{
|
|
|
|
if (m_isTabletMode == tablet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_isTabletMode = tablet;
|
|
|
|
emit tabletModeChanged(tablet);
|
|
|
|
}
|
2019-03-22 17:29:15 +00:00
|
|
|
|
|
|
|
void KWin::TabletModeManager::setTabletModeAvailable(bool detecting)
|
|
|
|
{
|
|
|
|
if (m_detecting != detecting) {
|
|
|
|
m_detecting = detecting;
|
2020-11-18 14:08:54 +00:00
|
|
|
emit tabletModeAvailableChanged(detecting);
|
2019-03-22 17:29:15 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-21 10:32:04 +00:00
|
|
|
|
|
|
|
} // namespace KWin
|