inputmethod: Refactor VirtualKeyboardDBus to have its own InputMethpd
This way we can have it call methods directly instead of connecting to its signals.
This commit is contained in:
parent
63a7b25801
commit
4638f2f309
8 changed files with 84 additions and 88 deletions
|
@ -380,17 +380,6 @@ if (HAVE_GBM)
|
|||
ecm_mark_as_test(testGbmSurface)
|
||||
endif()
|
||||
|
||||
qt5_add_dbus_interfaces(DBUS_SRCS ${CMAKE_BINARY_DIR}/src/org.kde.kwin.VirtualKeyboard.xml)
|
||||
add_executable(testVirtualKeyboardDBus test_virtualkeyboard_dbus.cpp ../src/virtualkeyboard_dbus.cpp ${DBUS_SRCS})
|
||||
|
||||
target_link_libraries(testVirtualKeyboardDBus
|
||||
Qt::DBus
|
||||
Qt::Test
|
||||
)
|
||||
add_test(NAME kwin-testVirtualKeyboardDBus COMMAND testVirtualKeyboardDBus)
|
||||
ecm_mark_as_test(testVirtualKeyboardDBus)
|
||||
|
||||
|
||||
########################################################
|
||||
# Test FTrace
|
||||
########################################################
|
||||
|
|
|
@ -100,6 +100,9 @@ integrationTest(WAYLAND_ONLY NAME testInputMethod SRCS inputmethod_test.cpp)
|
|||
integrationTest(WAYLAND_ONLY NAME testScreens SRCS screens_test.cpp)
|
||||
integrationTest(WAYLAND_ONLY NAME testOutputManagement SRCS outputmanagement_test.cpp)
|
||||
|
||||
qt5_add_dbus_interfaces(DBUS_SRCS ${CMAKE_BINARY_DIR}/src/org.kde.kwin.VirtualKeyboard.xml)
|
||||
integrationTest(WAYLAND_ONLY NAME testVirtualKeyboardDBus SRCS test_virtualkeyboard_dbus.cpp ${DBUS_SRCS})
|
||||
|
||||
if (KWIN_BUILD_CMS)
|
||||
integrationTest(WAYLAND_ONLY NAME testNightColor SRCS nightcolor_test.cpp LIBS KWinNightColorPlugin)
|
||||
endif()
|
||||
|
|
|
@ -14,8 +14,14 @@
|
|||
|
||||
#include <virtualkeyboardinterface.h>
|
||||
#include "virtualkeyboard_dbus.h"
|
||||
#include "wayland_server.h"
|
||||
#include "kwin_wayland_test.h"
|
||||
|
||||
using KWin::VirtualKeyboardDBus;
|
||||
using namespace KWin;
|
||||
using namespace KWin::Test;
|
||||
|
||||
static const QString s_socketName = QStringLiteral("wayland_test_kwin_virtualkeyboarddbus-0");
|
||||
|
||||
class VirtualKeyboardDBusTest : public QObject
|
||||
{
|
||||
|
@ -25,16 +31,35 @@ private Q_SLOTS:
|
|||
void testEnabled();
|
||||
void testRequestEnabled_data();
|
||||
void testRequestEnabled();
|
||||
void cleanup();
|
||||
};
|
||||
|
||||
void VirtualKeyboardDBusTest::initTestCase()
|
||||
{
|
||||
QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kwin.testvirtualkeyboard"));
|
||||
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
||||
QVERIFY(applicationStartedSpy.isValid());
|
||||
QVERIFY(waylandServer()->init(s_socketName));
|
||||
|
||||
static_cast<WaylandTestApplication *>(kwinApp())->setInputMethodServerToStart("internal");
|
||||
kwinApp()->start();
|
||||
QVERIFY(applicationStartedSpy.wait());
|
||||
waylandServer()->initWorkspace();
|
||||
|
||||
QVERIFY(setupWaylandConnection(AdditionalWaylandInterface::Seat |
|
||||
AdditionalWaylandInterface::InputMethodV1 |
|
||||
AdditionalWaylandInterface::TextInputManagerV2 |
|
||||
AdditionalWaylandInterface::TextInputManagerV3));
|
||||
}
|
||||
|
||||
void VirtualKeyboardDBusTest::cleanup()
|
||||
{
|
||||
Test::destroyWaylandConnection();
|
||||
}
|
||||
|
||||
void VirtualKeyboardDBusTest::testEnabled()
|
||||
{
|
||||
VirtualKeyboardDBus dbus;
|
||||
VirtualKeyboardDBus dbus(KWin::InputMethod::self());
|
||||
OrgKdeKwinVirtualKeyboardInterface iface(QStringLiteral("org.kde.kwin.testvirtualkeyboard"), QStringLiteral("/VirtualKeyboard"), QDBusConnection::sessionBus());
|
||||
QSignalSpy helperChangedSpy(&iface, &OrgKdeKwinVirtualKeyboardInterface::enabledChanged);
|
||||
QVERIFY(helperChangedSpy.isValid());
|
||||
|
@ -74,8 +99,8 @@ void VirtualKeyboardDBusTest::testRequestEnabled_data()
|
|||
QTest::addColumn<QString>("method");
|
||||
QTest::addColumn<bool>("expectedResult");
|
||||
|
||||
QTest::newRow("enable") << QStringLiteral("requestEnabled") << true;
|
||||
QTest::newRow("disable") << QStringLiteral("requestEnabled") << false;
|
||||
QTest::newRow("enable") << QStringLiteral("setEnabled") << true;
|
||||
QTest::newRow("disable") << QStringLiteral("setEnabled") << false;
|
||||
}
|
||||
|
||||
void VirtualKeyboardDBusTest::testRequestEnabled()
|
||||
|
@ -83,20 +108,15 @@ void VirtualKeyboardDBusTest::testRequestEnabled()
|
|||
QFETCH(QString, method);
|
||||
QFETCH(bool, expectedResult);
|
||||
|
||||
VirtualKeyboardDBus dbus;
|
||||
dbus.setEnabled(!expectedResult);
|
||||
connect(&dbus, &VirtualKeyboardDBus::enableRequested, &dbus, &VirtualKeyboardDBus::setEnabled);
|
||||
VirtualKeyboardDBus dbus(KWin::InputMethod::self());
|
||||
QSignalSpy activateRequestedSpy(&dbus, &VirtualKeyboardDBus::enabledChanged);
|
||||
QVERIFY(activateRequestedSpy.isValid());
|
||||
OrgKdeKwinVirtualKeyboardInterface iface(QStringLiteral("org.kde.kwin.testvirtualkeyboard"), QStringLiteral("/VirtualKeyboard"), QDBusConnection::sessionBus());
|
||||
|
||||
auto pending = iface.requestEnabled(expectedResult);
|
||||
QVERIFY(!pending.isError());
|
||||
// activateRequestedSpy.wait();
|
||||
iface.setEnabled(expectedResult);
|
||||
QCOMPARE(activateRequestedSpy.count(), 1);
|
||||
QCOMPARE(dbus.isEnabled(), expectedResult);
|
||||
QCOMPARE(iface.enabled(), expectedResult);
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(VirtualKeyboardDBusTest)
|
||||
WAYLANDTEST_MAIN(VirtualKeyboardDBusTest)
|
||||
#include "test_virtualkeyboard_dbus.moc"
|
|
@ -264,7 +264,7 @@ if (KWIN_BUILD_TABBOX)
|
|||
target_link_libraries(kwin Qt::GuiPrivate)
|
||||
endif()
|
||||
|
||||
qt5_generate_dbus_interface(virtualkeyboard_dbus.h org.kde.kwin.VirtualKeyboard.xml OPTIONS -P -s -M)
|
||||
qt5_generate_dbus_interface(virtualkeyboard_dbus.h org.kde.kwin.VirtualKeyboard.xml OPTIONS -A)
|
||||
|
||||
generate_export_header(kwin EXPORT_FILE_NAME kwin_export.h)
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
#include "inputmethod.h"
|
||||
#include "abstract_client.h"
|
||||
#include "virtualkeyboard_dbus.h"
|
||||
#include "input.h"
|
||||
#include "keyboard_input.h"
|
||||
|
@ -79,13 +80,8 @@ void InputMethod::init()
|
|||
);
|
||||
connect(this, &InputMethod::enabledChanged, this, &InputMethod::updateSni);
|
||||
|
||||
auto dbus = new VirtualKeyboardDBus(this);
|
||||
new VirtualKeyboardDBus(this);
|
||||
qCDebug(KWIN_VIRTUALKEYBOARD) << "Registering the DBus interface";
|
||||
dbus->setEnabled(m_enabled);
|
||||
connect(dbus, &VirtualKeyboardDBus::enableRequested, this, &InputMethod::setEnabled);
|
||||
connect(dbus, &VirtualKeyboardDBus::hideRequested, this, &InputMethod::hide);
|
||||
connect(this, &InputMethod::visibleChanged, dbus, &VirtualKeyboardDBus::setActive);
|
||||
connect(this, &InputMethod::enabledChanged, dbus, &VirtualKeyboardDBus::setEnabled);
|
||||
connect(input(), &InputRedirection::keyStateChanged, this, &InputMethod::hide);
|
||||
|
||||
if (waylandServer()) {
|
||||
|
@ -116,36 +112,36 @@ void InputMethod::init()
|
|||
|
||||
void InputMethod::show()
|
||||
{
|
||||
setVisible(true);
|
||||
setActive(true);
|
||||
}
|
||||
|
||||
void InputMethod::hide()
|
||||
{
|
||||
setVisible(false);
|
||||
setActive(false);
|
||||
}
|
||||
|
||||
void InputMethod::setVisible(bool visible)
|
||||
void InputMethod::setActive(bool active)
|
||||
{
|
||||
if (m_visible) {
|
||||
if (m_active) {
|
||||
waylandServer()->inputMethod()->sendDeactivate();
|
||||
}
|
||||
|
||||
if (visible) {
|
||||
if (active) {
|
||||
if (!m_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
waylandServer()->inputMethod()->sendActivate();
|
||||
if (m_visible) {
|
||||
if (m_active) {
|
||||
adoptInputMethodContext();
|
||||
}
|
||||
} else {
|
||||
updateInputPanelState();
|
||||
}
|
||||
|
||||
if (m_visible != visible) {
|
||||
m_visible = visible;
|
||||
Q_EMIT visibleChanged(visible);
|
||||
if (m_active != active) {
|
||||
m_active = active;
|
||||
Q_EMIT activeChanged(active);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,7 +184,7 @@ void InputMethod::handleFocusedSurfaceChanged()
|
|||
}
|
||||
updateInputPanelState();
|
||||
} else {
|
||||
setVisible(false);
|
||||
setActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <kwinglobals.h>
|
||||
#include <kwin_export.h>
|
||||
|
||||
#include <abstract_client.h>
|
||||
#include <QPointer>
|
||||
#include <KWaylandServer/textinput_v2_interface.h>
|
||||
|
||||
class KStatusNotifierItem;
|
||||
|
@ -22,6 +22,8 @@ class KStatusNotifierItem;
|
|||
namespace KWin
|
||||
{
|
||||
|
||||
class AbstractClient;
|
||||
|
||||
/**
|
||||
* This class implements the zwp_input_method_unstable_v1, which is currently used to provide
|
||||
* the Virtual Keyboard using supported input method client (maliit-keyboard e.g.)
|
||||
|
@ -33,11 +35,19 @@ public:
|
|||
~InputMethod() override;
|
||||
|
||||
void init();
|
||||
void setEnabled(bool enable);
|
||||
bool isEnabled() const {
|
||||
return m_enabled;
|
||||
}
|
||||
bool isActive() const {
|
||||
return m_active;
|
||||
}
|
||||
void setActive(bool active);
|
||||
void hide();
|
||||
void show();
|
||||
|
||||
Q_SIGNALS:
|
||||
void visibleChanged(bool shown);
|
||||
void activeChanged(bool active);
|
||||
void enabledChanged(bool enabled);
|
||||
|
||||
private Q_SLOTS:
|
||||
|
@ -57,8 +67,6 @@ private Q_SLOTS:
|
|||
void setPreeditCursor(qint32 index);
|
||||
|
||||
private:
|
||||
void setVisible(bool shown);
|
||||
void setEnabled(bool enable);
|
||||
void updateSni();
|
||||
void updateInputPanelState();
|
||||
void adoptInputMethodContext();
|
||||
|
@ -70,7 +78,7 @@ private:
|
|||
} preedit;
|
||||
|
||||
bool m_enabled = false;
|
||||
bool m_visible = false;
|
||||
bool m_active = false;
|
||||
KStatusNotifierItem *m_sni = nullptr;
|
||||
QPointer<AbstractClient> m_inputClient;
|
||||
QPointer<AbstractClient> m_trackedClient;
|
||||
|
|
|
@ -12,52 +12,38 @@
|
|||
namespace KWin
|
||||
{
|
||||
|
||||
VirtualKeyboardDBus::VirtualKeyboardDBus(QObject *parent)
|
||||
VirtualKeyboardDBus::VirtualKeyboardDBus(InputMethod *parent)
|
||||
: QObject(parent)
|
||||
, m_inputMethod(parent)
|
||||
{
|
||||
QDBusConnection::sessionBus().registerObject(QStringLiteral("/VirtualKeyboard"), this,
|
||||
QDBusConnection::ExportAllProperties |
|
||||
QDBusConnection::ExportScriptableSignals | //qdbuscpp2xml doesn't support yet properties with NOTIFY
|
||||
QDBusConnection::ExportAllSlots);
|
||||
connect(parent, &InputMethod::activeChanged, this, &VirtualKeyboardDBus::activeChanged);
|
||||
connect(parent, &InputMethod::enabledChanged, this, &VirtualKeyboardDBus::enabledChanged);
|
||||
}
|
||||
|
||||
VirtualKeyboardDBus::~VirtualKeyboardDBus() = default;
|
||||
|
||||
bool VirtualKeyboardDBus::isActive() const
|
||||
{
|
||||
return m_active;
|
||||
}
|
||||
|
||||
void VirtualKeyboardDBus::requestEnabled(bool enabled)
|
||||
{
|
||||
emit enableRequested(enabled);
|
||||
}
|
||||
|
||||
void VirtualKeyboardDBus::setActive(bool active)
|
||||
{
|
||||
if (m_active != active) {
|
||||
m_active = active;
|
||||
Q_EMIT activeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void VirtualKeyboardDBus::hide()
|
||||
{
|
||||
Q_EMIT hideRequested();
|
||||
}
|
||||
|
||||
bool VirtualKeyboardDBus::isEnabled() const
|
||||
{
|
||||
return m_enabled;
|
||||
return m_inputMethod->isActive();
|
||||
}
|
||||
|
||||
void VirtualKeyboardDBus::setEnabled(bool enabled)
|
||||
{
|
||||
if (m_enabled == enabled) {
|
||||
return;
|
||||
}
|
||||
m_enabled = enabled;
|
||||
emit enabledChanged();
|
||||
m_inputMethod->setEnabled(enabled);
|
||||
}
|
||||
|
||||
void VirtualKeyboardDBus::setActive(bool active)
|
||||
{
|
||||
m_inputMethod->setActive(active);
|
||||
}
|
||||
|
||||
bool VirtualKeyboardDBus::isEnabled() const
|
||||
{
|
||||
return m_inputMethod->isEnabled();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,38 +9,32 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include "inputmethod.h"
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
class VirtualKeyboardDBus : public QObject
|
||||
class KWIN_EXPORT VirtualKeyboardDBus : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.VirtualKeyboard")
|
||||
Q_PROPERTY(bool enabled READ isEnabled NOTIFY enabledChanged)
|
||||
Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
|
||||
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
|
||||
Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
|
||||
public:
|
||||
explicit VirtualKeyboardDBus(QObject *parent = nullptr);
|
||||
explicit VirtualKeyboardDBus(InputMethod *inputMethod);
|
||||
~VirtualKeyboardDBus() override;
|
||||
bool isEnabled() const;
|
||||
void setEnabled(bool enabled);
|
||||
|
||||
void setActive(bool active);
|
||||
bool isActive() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void requestEnabled(bool enabled);
|
||||
void hide();
|
||||
void setEnabled(bool enabled);
|
||||
void setActive(bool active);
|
||||
|
||||
Q_SIGNALS:
|
||||
Q_SCRIPTABLE void enabledChanged();
|
||||
Q_SCRIPTABLE void activeChanged();
|
||||
void hideRequested();
|
||||
void enableRequested(bool requested);
|
||||
|
||||
private:
|
||||
bool m_enabled = false;
|
||||
bool m_active = false;
|
||||
InputMethod *const m_inputMethod;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue