Qt-interest Archive, March 2007
Qtopia Core keyboard handler trouble
Message 1 in thread
Hi All!
I tried to write input plugin for some device and met a trouble. My driver
monitors /dev/input/event0 device, and sends events when some button is
pressed. But my test application doesn't receives any event. Any ideas?
The plugin code is following:
--------------------- NeurosHandler.hpp ------------------------
#ifndef __XITEX__NEUROS_OSD__NEUROS_HANDLER_HPP
#define __XITEX__NUEROS_OSD__NEUROS_HANDLER_HPP
#include <QWSKeyboardHandler>
#include <memory>
#include "NeurosHandlerImp.hpp"
class QString;
class NeurosHandler : public QWSKeyboardHandler
{
public:
NeurosHandler(QString const & device)
: pImpl_(new NeurosHandlerImp(this, device))
{
};
virtual ~NeurosHandler() {};
private:
std::auto_ptr<NeurosHandlerImp> pImpl_;
};
#endif
---------------- END of NeurosHandler.hpp -------------------------
------------------------ NeurosHandlerImp.hpp ---------------------
#ifndef __XITEX__NEUROS_OSD__NEUROS_HANDLER_IMP_HPP
#define __XITEX__NEUROS_OSD__NEUROS_HANDLER_IMP_HPP
#include <QObject>
class QSocketNotifier;
class QFile;
class QString;
class NeurosHandler;
struct input_event;
struct TranslatedKeyEvent
{
explicit TranslatedKeyEvent(input_event const & event);
int unicode_;
int keyCode_;
bool isPress_;
bool autoRepeat_;
private:
static const int unknownCode = 0xffff;
};
class NeurosHandlerImp : public QObject
{
Q_OBJECT
public:
NeurosHandlerImp(NeurosHandler * handler, QString const & device);
~NeurosHandlerImp() {};
private slots:
void ReadKeys();
private:
NeurosHandler * handler_;
QFile * device_;
QSocketNotifier * notifier_;
};
#endif
---------------------- END of NeurosHandlerImp.hpp -----------------------
---------------------- NeurosHandlerImp.cpp -----------------------
#include "NeurosHandlerImp.hpp"
#include "NeurosHandler.hpp"
#include <QSocketNotifier>
#include <QString>
#include <QFile>
#include <QWSServer>
#include <linux/input.h>
#include <QtDebug>
TranslatedKeyEvent::TranslatedKeyEvent(input_event const & event)
: unicode_(0),
keyCode_(0),
isPress_(event.value == 1),
autoRepeat_(event.value == 2)
{
switch(event.code)
{
case KEY_LEFT:
unicode_ = 0xffff;
keyCode_ = Qt::Key_Left;
break;
case KEY_RIGHT:
unicode_ = 0xffff;
keyCode_ = Qt::Key_Right;
break;
case KEY_UP:
unicode_ = 0xffff;
keyCode_ = Qt::Key_Up;
break;
case KEY_DOWN:
unicode_ = 0xffff;
keyCode_ = Qt::Key_Down;
break;
case KEY_ENTER:
unicode_ = 'a';
keyCode_ = Qt::Key_A;
break;
default:
break;
};
};
NeurosHandlerImp::NeurosHandlerImp(NeurosHandler * handler, QString const &
device)
: QObject(),
handler_(handler),
device_(NULL),
notifier_(NULL)
{
device_ = new QFile(device.isEmpty() ? "/dev/input/event0" : device,
this); // Dirty hack!
if (!device_->open(QIODevice::ReadOnly))
{
qCritical("Cannot open device: Error %i", device_->error());
};
notifier_ = new QSocketNotifier(device_->handle(), QSocketNotifier::Read,
this);
connect(notifier_, SIGNAL(activated(int)), this, SLOT(ReadKeys()));
qDebug()<<"NeurosHandlerImp created!";
};
void NeurosHandlerImp::ReadKeys()
{
struct input_event event;
const int eventSize(sizeof(struct input_event));
while(device_->isReadable())
{
if(device_->read(reinterpret_cast<char *>(&event), eventSize) !=
eventSize)
{
qCritical("Partial event was read!");
return ;
};
if(event.type != EV_KEY)
{
// We should handle only key events
continue ;
};
TranslatedKeyEvent translatedEvent(event);
handler_->processKeyEvent(translatedEvent.unicode_,
translatedEvent.keyCode_, 0, translatedEvent.isPress_,
translatedEvent.autoRepeat_);
};
};
---------------------- END of NeurosHandlerImp.cpp -----------------------
---------------------- NeurosRemotePlugin.hpp -----------------------
#ifndef __XITEX__NEUROS_OSD__NEUROS_REMOTE_PLUGIN_HPP
#define __XITEX__NEUROS_OSD__NEUROS_REMOTE_PLUGIN_HPP
#include <QKbdDriverPlugin>
class NeurosRemotePlugin : public QKbdDriverPlugin
{
Q_OBJECT
public:
NeurosRemotePlugin(QObject * parent = NULL);
virtual ~NeurosRemotePlugin();
virtual QStringList keys() const;
virtual QWSKeyboardHandler * create(const QString & driver, const QString
& device);
virtual QWSKeyboardHandler * create(const QString & name);
};
#endif
---------------------- END of NeurosRemotePlugin.hpp -----------------------
---------------------- NeurosRemotePlugin.cpp -----------------------
#include "NeurosRemotePlugin.hpp"
#include "NeurosHandler.hpp"
#include <QtDebug>
NeurosRemotePlugin::NeurosRemotePlugin(QObject * parent)
: QKbdDriverPlugin(parent)
{
};
NeurosRemotePlugin::~NeurosRemotePlugin()
{
};
QStringList NeurosRemotePlugin::keys() const
{
return QStringList() << QLatin1String("neuros");
};
QWSKeyboardHandler * NeurosRemotePlugin::create(const QString & name, const
QString & device)
{
if(name == "neuros")
{
return new NeurosHandler(device);
};
return NULL;
};
QWSKeyboardHandler * NeurosRemotePlugin::create(const QString & device)
{
return create(device, "");
};
Q_EXPORT_PLUGIN2(remoteinput, NeurosRemotePlugin)
---------------------- END of NeurosRemotePlugin.cpp -----------------------
---------------------- plugin.pro ---------------------------------------
CONFIG += qt release plugin
QT += gui
TEMPLATE = lib
TARGET = remoteinput
HEADERS += NeurosRemotePlugin.hpp
HEADERS += NeurosHandler.hpp
HEADERS += NeurosHandlerImp.hpp
SOURCES += NeurosRemotePlugin.cpp
SOURCES += NeurosHandlerImp.cpp
-------------------- END of plugin.pro ---------------------------------
--
[ signature omitted ]
Message 2 in thread
Hi,
Did you
export QWS_KEYBOARD=NeurosHandler
?
Gleb Golubitsky wrote:
> Hi All!
[snip]
--
[ signature omitted ]
Message 3 in thread
Yes, i did. I've already found the root of evil=). QIODevice::isReadable()
blocks when it's called for device file where is nothing to read. So, i
changed QFile to usual POSIX open(), read(), close() calls and it works.
Thanks 2 all!
WBR, Gleb.
Lorn Potter wrote:
> Hi,
> Did you
> export QWS_KEYBOARD=NeurosHandler
> Gleb Golubitsky wrote:
> > Hi All!
>
> [snip]
--
[ signature omitted ]