This source file includes following definitions.
- UpdateModifier
- UpdateModifierLock
- UpdateFlags
- GetModifierFlags
#include "ui/events/ozone/evdev/event_modifiers_evdev.h"
#include <linux/input.h>
#include "ui/events/event.h"
namespace ui {
namespace {
static const int kEventFlagFromModifiers[] = {
EF_NONE,
EF_CAPS_LOCK_DOWN,
EF_SHIFT_DOWN,
EF_CONTROL_DOWN,
EF_ALT_DOWN,
EF_LEFT_MOUSE_BUTTON,
EF_MIDDLE_MOUSE_BUTTON,
EF_RIGHT_MOUSE_BUTTON,
EF_COMMAND_DOWN,
EF_ALTGR_DOWN,
};
}
EventModifiersEvdev::EventModifiersEvdev()
: modifier_flags_locked_(0), modifier_flags_(0) {
memset(modifiers_down_, 0, sizeof(modifiers_down_));
}
EventModifiersEvdev::~EventModifiersEvdev() {}
void EventModifiersEvdev::UpdateModifier(unsigned int modifier, bool down) {
CHECK_LT(modifier, EVDEV_NUM_MODIFIERS);
if (down) {
modifiers_down_[modifier]++;
} else {
if (modifiers_down_[modifier])
modifiers_down_[modifier]--;
}
UpdateFlags(modifier);
}
void EventModifiersEvdev::UpdateModifierLock(unsigned int modifier, bool down) {
CHECK_LT(modifier, EVDEV_NUM_MODIFIERS);
if (down)
modifier_flags_locked_ ^= kEventFlagFromModifiers[modifier];
UpdateFlags(modifier);
}
void EventModifiersEvdev::UpdateFlags(unsigned int modifier) {
int mask = kEventFlagFromModifiers[modifier];
bool down = modifiers_down_[modifier];
bool locked = (modifier_flags_locked_ & mask);
if (down != locked)
modifier_flags_ |= mask;
else
modifier_flags_ &= ~mask;
}
int EventModifiersEvdev::GetModifierFlags() { return modifier_flags_; }
}