Use counting instead of OR'ing the buttons together in UIKeyEventCollector this should preserve the order of events
This commit is contained in:
parent
de3d2f7617
commit
bf4501edc7
4 changed files with 53 additions and 15 deletions
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "ui_key_event_collector.hpp"
|
||||
|
||||
#include "log.hpp"
|
||||
#include "uinput.hpp"
|
||||
|
||||
UIKeyEventCollector::UIKeyEventCollector(UInput& uinput, uint32_t device_id, int type, int code) :
|
||||
|
@ -30,25 +31,49 @@ UIKeyEventCollector::UIKeyEventCollector(UInput& uinput, uint32_t device_id, int
|
|||
UIEventEmitterPtr
|
||||
UIKeyEventCollector::create_emitter()
|
||||
{
|
||||
UIKeyEventEmitterPtr emitter(new UIKeyEventEmitter);
|
||||
UIKeyEventEmitterPtr emitter(new UIKeyEventEmitter(*this));
|
||||
m_emitters.push_back(emitter);
|
||||
return m_emitters.back();
|
||||
}
|
||||
|
||||
void
|
||||
UIKeyEventCollector::sync()
|
||||
UIKeyEventCollector::send(int value)
|
||||
{
|
||||
int value = 0;
|
||||
for(Emitters::iterator i = m_emitters.begin(); i != m_emitters.end(); ++i)
|
||||
{
|
||||
value = value || (*i)->get_value();
|
||||
}
|
||||
assert(value == 0 || value == 1);
|
||||
|
||||
if (value != m_value)
|
||||
if (value)
|
||||
{
|
||||
m_value = value;
|
||||
m_uinput.send(get_device_id(), get_type(), get_code(), m_value);
|
||||
if (m_value >= static_cast<int>(m_emitters.size()))
|
||||
{
|
||||
log_error("got press event while all emitter where already pressed");
|
||||
}
|
||||
|
||||
m_value += 1;
|
||||
|
||||
if (m_value == 1)
|
||||
{
|
||||
m_uinput.send(get_device_id(), get_type(), get_code(), m_value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_value <= 0)
|
||||
{
|
||||
log_error("got release event while collector was in release state");
|
||||
}
|
||||
|
||||
m_value -= 1;
|
||||
|
||||
if (m_value == 0)
|
||||
{
|
||||
m_uinput.send(get_device_id(), get_type(), get_code(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
UIKeyEventCollector::sync()
|
||||
{
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -29,13 +29,14 @@ class UIKeyEventCollector : public UIEventCollector
|
|||
private:
|
||||
typedef std::vector<UIKeyEventEmitterPtr> Emitters;
|
||||
Emitters m_emitters;
|
||||
|
||||
|
||||
int m_value;
|
||||
|
||||
public:
|
||||
UIKeyEventCollector(UInput& uinput, uint32_t device_id, int type, int code);
|
||||
|
||||
UIEventEmitterPtr create_emitter();
|
||||
void send(int value);
|
||||
void sync();
|
||||
|
||||
private:
|
||||
|
|
|
@ -18,7 +18,10 @@
|
|||
|
||||
#include "ui_key_event_emitter.hpp"
|
||||
|
||||
UIKeyEventEmitter::UIKeyEventEmitter() :
|
||||
#include "ui_key_event_collector.hpp"
|
||||
|
||||
UIKeyEventEmitter::UIKeyEventEmitter(UIKeyEventCollector& collector) :
|
||||
m_collector(collector),
|
||||
m_value(0)
|
||||
{
|
||||
}
|
||||
|
@ -26,7 +29,13 @@ UIKeyEventEmitter::UIKeyEventEmitter() :
|
|||
void
|
||||
UIKeyEventEmitter::send(int value)
|
||||
{
|
||||
m_value = value;
|
||||
assert(value == 0 || value == 1);
|
||||
|
||||
if (m_value != value)
|
||||
{
|
||||
m_value = value;
|
||||
m_collector.send(m_value);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -21,13 +21,16 @@
|
|||
|
||||
#include "ui_event_emitter.hpp"
|
||||
|
||||
class UIKeyEventCollector;
|
||||
|
||||
class UIKeyEventEmitter : public UIEventEmitter
|
||||
{
|
||||
private:
|
||||
int m_value;
|
||||
UIKeyEventCollector& m_collector;
|
||||
bool m_value;
|
||||
|
||||
public:
|
||||
UIKeyEventEmitter();
|
||||
UIKeyEventEmitter(UIKeyEventCollector& collector);
|
||||
|
||||
void send(int value);
|
||||
int get_value() const;
|
||||
|
|
Loading…
Add table
Reference in a new issue