Skip to content

Commit

Permalink
Merge branch 'use_mce' into 'master'
Browse files Browse the repository at this point in the history
[maliit-framework] Use mce for keyboard state. Fixes JB#48910

See merge request mer-core/maliit-framework!11
  • Loading branch information
pvuorela committed Feb 12, 2020
2 parents a1c3c44 + 019ea75 commit d36c726
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 27 deletions.
78 changes: 63 additions & 15 deletions maliit-framework/src/mimhwkeyboardtracker.cpp
Expand Up @@ -17,10 +17,20 @@
// This file is based on mkeyboardstatetracker.cpp from libmeegotouch

#include <QSocketNotifier>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusPendingCall>
#include <QDBusPendingReply>
#include <QDebug>

#include <libudev.h>
#include <linux/input.h>

#ifdef HAVE_MCE
#include <mce/dbus-names.h> // from mce-dev
#include <mce/mode-names.h> // from mce-dev
#endif

#include "mimhwkeyboardtracker.h"
#include "mimhwkeyboardtracker_p.h"

Expand All @@ -34,17 +44,30 @@ namespace {
}

MImHwKeyboardTrackerPrivate::MImHwKeyboardTrackerPrivate(MImHwKeyboardTracker *q_ptr) :
#ifdef HAVE_CONTEXTSUBSCRIBER
keyboardOpenProperty(),
#elif defined(Q_WS_MAEMO_5)
#if defined(Q_WS_MAEMO_5)
keyboardOpenConf("/system/osso/af/slide-open"),
#else
#elif HAVE_UDEV
evdevTabletModePending(-1),
evdevTabletMode(0),
#endif
present(false)
{
#ifdef HAVE_CONTEXTSUBSCRIBER
#ifdef HAVE_MCE
present = true; // includes external, always true
keyboardOpened = false;

QDBusMessage message = QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF,
MCE_HARDWARE_KEYBOARD_STATE_GET);
QDBusPendingCall call = QDBusConnection::systemBus().asyncCall(message);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call);
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
this, SLOT(handleMceKeyboardReply(QDBusPendingCallWatcher*)));

QDBusConnection::systemBus().connect(MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
MCE_HARDWARE_KEYBOARD_STATE_SIG,
this, SLOT(mceKeyboardStateChanged(QString)));

#elif defined(HAVE_CONTEXTSUBSCRIBER)
keyboardOpenProperty.reset(new ContextProperty(keyboardOpen));
keyboardOpenProperty->waitForSubscription(true);
present = true; // assume keyboard present as context property currently includes also external keyboards
Expand All @@ -59,17 +82,16 @@ MImHwKeyboardTrackerPrivate::MImHwKeyboardTrackerPrivate(MImHwKeyboardTracker *q
QObject::connect(&keyboardOpenConf, SIGNAL(valueChanged()),
q_ptr, SIGNAL(stateChanged()));
#else
Q_UNUSED(q_ptr);
QObject::connect(this, SIGNAL(stateChanged()),
q_ptr, SIGNAL(stateChanged()));

detectEvdev();
#endif

QObject::connect(this, SIGNAL(stateChanged()),
q_ptr, SIGNAL(stateChanged()));
}

#ifdef HAVE_UDEV
void MImHwKeyboardTrackerPrivate::detectEvdev()
{
#ifndef HAVE_CONTEXTSUBSCRIBER
// Use udev to enumerate all input devices, using evdev on each device to
// find the first device offering a SW_TABLET_MODE switch. If found, this
// switch is used to determine keyboard presence.
Expand Down Expand Up @@ -107,12 +129,10 @@ void MImHwKeyboardTrackerPrivate::detectEvdev()
}
udev_enumerate_unref(enumerate);
udev_unref(udev);
#endif
}

void MImHwKeyboardTrackerPrivate::evdevEvent()
{
#ifndef HAVE_CONTEXTSUBSCRIBER
// Parse the evdev event and look for SW_TABLET_MODE status.

struct input_event ev;
Expand All @@ -130,14 +150,12 @@ void MImHwKeyboardTrackerPrivate::evdevEvent()
evdevTabletModePending = -1;
Q_EMIT stateChanged();
}
#endif
}

void MImHwKeyboardTrackerPrivate::tryEvdevDevice(const char *device)
{
Q_UNUSED(device);

#ifndef HAVE_CONTEXTSUBSCRIBER
QFile *qfile = new QFile(this);
unsigned char evbits[BITS2BYTES(EV_MAX)];
int fd;
Expand Down Expand Up @@ -191,8 +209,36 @@ void MImHwKeyboardTrackerPrivate::tryEvdevDevice(const char *device)
return;

evdevTabletMode = TEST_BIT(SW_TABLET_MODE, state);
}
#endif

#ifdef HAVE_MCE
void MImHwKeyboardTrackerPrivate::mceKeyboardStateChanged(const QString &value)
{
bool available = value == QLatin1String("available");
if (available != keyboardOpened) {
keyboardOpened = available;
Q_EMIT stateChanged();
}
}

void MImHwKeyboardTrackerPrivate::handleMceKeyboardReply(QDBusPendingCallWatcher *call)
{
call->deleteLater();
QDBusPendingReply<> reply = *call;
if (reply.isError()) {
qWarning() << "Unable to get MCE keyboard state";
} else {
QList<QVariant> arguments = reply.reply().arguments();
if (arguments.size() != 1) {
qWarning() << "Invalid return MCE value";
return;
}
QString value = arguments.at(0).toString();
mceKeyboardStateChanged(value);
}
}
#endif

MImHwKeyboardTrackerPrivate::~MImHwKeyboardTrackerPrivate()
{
Expand Down Expand Up @@ -223,7 +269,9 @@ bool MImHwKeyboardTracker::isOpen() const
return false;
}

#ifdef HAVE_CONTEXTSUBSCRIBER
#ifdef HAVE_MCE
return d->keyboardOpened;
#elif defined(HAVE_CONTEXTSUBSCRIBER)
return d->keyboardOpenProperty->value().toBool();
#elif defined(Q_WS_MAEMO_5)
return d->keyboardOpenConf.value().toBool();
Expand Down
29 changes: 20 additions & 9 deletions maliit-framework/src/mimhwkeyboardtracker_p.h
Expand Up @@ -18,14 +18,13 @@
#define MIMHWKEYBOARDTRACKER_P_H

#include <QFile>
#include <QScopedPointer>
#include <QDBusPendingCallWatcher>

#include "mimsettings.h"

#ifdef HAVE_CONTEXTSUBSCRIBER
#include <QScopedPointer>
#include <contextproperty.h>
#else
# ifdef Q_WS_MAEMO_5
# include "mimsettings.h"
# endif
#endif

class MImHwKeyboardTracker;
Expand All @@ -39,23 +38,35 @@ class MImHwKeyboardTrackerPrivate
explicit MImHwKeyboardTrackerPrivate(MImHwKeyboardTracker *q_ptr);
~MImHwKeyboardTrackerPrivate();

#ifdef HAVE_UDEV
void detectEvdev();
void tryEvdevDevice(const char *device);
QFile *evdevFile;
int evdevTabletModePending;
bool evdevTabletMode;
#endif

#ifdef HAVE_MCE
bool keyboardOpened;
#endif

#ifdef HAVE_CONTEXTSUBSCRIBER
QScopedPointer<ContextProperty> keyboardOpenProperty;
#elif defined(Q_WS_MAEMO_5)
MImSettings keyboardOpenConf;
#endif

QFile *evdevFile;
int evdevTabletModePending;
bool evdevTabletMode;

bool present;

public Q_SLOTS:
#ifdef HAVE_UDEV
void evdevEvent();
#endif

#ifdef HAVE_MCE
void mceKeyboardStateChanged(const QString &value);
void handleMceKeyboardReply(QDBusPendingCallWatcher*);
#endif

Q_SIGNALS:
void stateChanged();
Expand Down
6 changes: 5 additions & 1 deletion maliit-framework/src/src.pro
Expand Up @@ -115,12 +115,16 @@ QUICK_SOURCES += \
SERVER_HEADERS_PRIVATE += mimhwkeyboardtracker_p.h
SERVER_SOURCES += mimhwkeyboardtracker.cpp

enable-contextkit {
enable-mce {
PKGCONFIG += mce
DEFINES += HAVE_MCE
} else:enable-contextkit {
PKGCONFIG += contextsubscriber-1.0
DEFINES += HAVE_CONTEXTSUBSCRIBER
} else {
# libudev needed by non-contextkit MImHwKeyboardTracker
PKGCONFIG += libudev
DEFINES += HAVE_UDEV
}
} else {
SERVER_SOURCES += mimhwkeyboardtracker_stub.cpp
Expand Down
4 changes: 2 additions & 2 deletions rpm/maliit-framework-wayland.spec
Expand Up @@ -17,9 +17,9 @@ BuildRequires: pkgconfig(Qt5DBus)
BuildRequires: pkgconfig(Qt5Quick)
BuildRequires: pkgconfig(Qt5Test)
BuildRequires: pkgconfig(libudev)
BuildRequires: pkgconfig(mce)
BuildRequires: fdupes
BuildRequires: pkgconfig(qt5-boostable)
BuildRequires: pkgconfig(contextkit-statefs)
Requires: mapplauncherd-qt5
Provides: maliit-framework
Conflicts: maliit-framework-x11
Expand Down Expand Up @@ -87,7 +87,7 @@ pushd maliit-framework
CONFIG+=qt5-inputcontext \
CONFIG+=lipstick \
CONFIG+=noxcb \
CONFIG+=enable-contextkit
CONFIG+=enable-mce

make %{?jobs:-j%jobs}
popd
Expand Down

0 comments on commit d36c726

Please sign in to comment.