refactor: KeyMap EType => enum class KeyType
This commit is contained in:
parent
902f5823f2
commit
283e0c6367
8 changed files with 19 additions and 18 deletions
|
|
@ -1228,7 +1228,7 @@ bool KeyMap::KeyItem::operator==(const KeyItem &x) const
|
||||||
// KeyMap::Keystroke
|
// KeyMap::Keystroke
|
||||||
//
|
//
|
||||||
|
|
||||||
KeyMap::Keystroke::Keystroke(KeyButton button, bool press, bool repeat, uint32_t data) : m_type(kButton)
|
KeyMap::Keystroke::Keystroke(KeyButton button, bool press, bool repeat, uint32_t data) : m_type(KeyType::Button)
|
||||||
{
|
{
|
||||||
m_data.m_button.m_button = button;
|
m_data.m_button.m_button = button;
|
||||||
m_data.m_button.m_press = press;
|
m_data.m_button.m_press = press;
|
||||||
|
|
@ -1236,7 +1236,7 @@ KeyMap::Keystroke::Keystroke(KeyButton button, bool press, bool repeat, uint32_t
|
||||||
m_data.m_button.m_client = data;
|
m_data.m_button.m_client = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyMap::Keystroke::Keystroke(int32_t group, bool absolute, bool restore) : m_type(kGroup)
|
KeyMap::Keystroke::Keystroke(int32_t group, bool absolute, bool restore) : m_type(KeyType::Group)
|
||||||
{
|
{
|
||||||
m_data.m_group.m_group = group;
|
m_data.m_group.m_group = group;
|
||||||
m_data.m_group.m_absolute = absolute;
|
m_data.m_group.m_absolute = absolute;
|
||||||
|
|
|
||||||
|
|
@ -71,10 +71,10 @@ public:
|
||||||
class Keystroke
|
class Keystroke
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum EType
|
enum class KeyType
|
||||||
{
|
{
|
||||||
kButton, //!< Synthesize button
|
Button, //!< Synthesize button
|
||||||
kGroup //!< Set new group
|
Group //!< Set new group
|
||||||
};
|
};
|
||||||
|
|
||||||
Keystroke(KeyButton, bool press, bool repeat, uint32_t clientData);
|
Keystroke(KeyButton, bool press, bool repeat, uint32_t clientData);
|
||||||
|
|
@ -103,7 +103,7 @@ public:
|
||||||
Group m_group;
|
Group m_group;
|
||||||
};
|
};
|
||||||
|
|
||||||
EType m_type{};
|
KeyType m_type{};
|
||||||
Data m_data{};
|
Data m_data{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -874,7 +874,7 @@ bool KeyState::fakeKeyRepeat(KeyID id, KeyModifierMask mask, int32_t count, KeyB
|
||||||
// replace key up with previous KeyButton but leave key down
|
// replace key up with previous KeyButton but leave key down
|
||||||
// alone so it uses the new KeyButton.
|
// alone so it uses the new KeyButton.
|
||||||
for (auto &key : keys) {
|
for (auto &key : keys) {
|
||||||
if (key.m_type == Keystroke::kButton && key.m_data.m_button.m_button == localID) {
|
if (key.m_type == Keystroke::KeyType::Button && key.m_data.m_button.m_button == localID) {
|
||||||
key.m_data.m_button.m_button = oldLocalID;
|
key.m_data.m_button.m_button = oldLocalID;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1067,20 +1067,21 @@ void KeyState::fakeKeys(const Keystrokes &keys, uint32_t count)
|
||||||
// generate key events
|
// generate key events
|
||||||
LOG((CLOG_DEBUG1 "keystrokes:"));
|
LOG((CLOG_DEBUG1 "keystrokes:"));
|
||||||
for (auto k = keys.begin(); k != keys.end();) {
|
for (auto k = keys.begin(); k != keys.end();) {
|
||||||
if (k->m_type == Keystroke::kButton && k->m_data.m_button.m_repeat) {
|
if (k->m_type == Keystroke::KeyType::Button && k->m_data.m_button.m_repeat) {
|
||||||
// repeat from here up to but not including the next key
|
// repeat from here up to but not including the next key
|
||||||
// with m_repeat == false count times.
|
// with m_repeat == false count times.
|
||||||
Keystrokes::const_iterator start = k;
|
Keystrokes::const_iterator start = k;
|
||||||
while (count-- > 0) {
|
while (count-- > 0) {
|
||||||
// send repeating events
|
// send repeating events
|
||||||
for (k = start; k != keys.end() && k->m_type == Keystroke::kButton && k->m_data.m_button.m_repeat; ++k) {
|
for (k = start; k != keys.end() && k->m_type == Keystroke::KeyType::Button && k->m_data.m_button.m_repeat;
|
||||||
|
++k) {
|
||||||
fakeKey(*k);
|
fakeKey(*k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// note -- k is now on the first non-repeat key after the
|
// note -- k is now on the first non-repeat key after the
|
||||||
// repeat keys, exactly where we'd like to continue from.
|
// repeat keys, exactly where we'd like to continue from.
|
||||||
} else if (k->m_type != Keystroke::kGroup || (!k->m_data.m_group.m_restore && m_isLangSyncEnabled)) {
|
} else if (k->m_type != Keystroke::KeyType::Group || (!k->m_data.m_group.m_restore && m_isLangSyncEnabled)) {
|
||||||
// send event
|
// send event
|
||||||
fakeKey(*k);
|
fakeKey(*k);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ void EiKeyState::getKeyMap(deskflow::KeyMap &keyMap)
|
||||||
void EiKeyState::fakeKey(const Keystroke &keystroke)
|
void EiKeyState::fakeKey(const Keystroke &keystroke)
|
||||||
{
|
{
|
||||||
switch (keystroke.m_type) {
|
switch (keystroke.m_type) {
|
||||||
case Keystroke::kButton:
|
case Keystroke::KeyType::Button:
|
||||||
LOG_DEBUG1(
|
LOG_DEBUG1(
|
||||||
"fake key: %03x (%08x) %s", keystroke.m_data.m_button.m_button, keystroke.m_data.m_button.m_client,
|
"fake key: %03x (%08x) %s", keystroke.m_data.m_button.m_button, keystroke.m_data.m_button.m_client,
|
||||||
keystroke.m_data.m_button.m_press ? "down" : "up"
|
keystroke.m_data.m_button.m_press ? "down" : "up"
|
||||||
|
|
|
||||||
|
|
@ -1163,7 +1163,7 @@ void MSWindowsKeyState::getKeyMap(deskflow::KeyMap &keyMap)
|
||||||
void MSWindowsKeyState::fakeKey(const Keystroke &keystroke)
|
void MSWindowsKeyState::fakeKey(const Keystroke &keystroke)
|
||||||
{
|
{
|
||||||
switch (keystroke.m_type) {
|
switch (keystroke.m_type) {
|
||||||
case Keystroke::kButton: {
|
case Keystroke::KeyType::Button: {
|
||||||
LOG(
|
LOG(
|
||||||
(CLOG_DEBUG1 " %03x (%08x) %s", keystroke.m_data.m_button.m_button, keystroke.m_data.m_button.m_client,
|
(CLOG_DEBUG1 " %03x (%08x) %s", keystroke.m_data.m_button.m_button, keystroke.m_data.m_button.m_client,
|
||||||
keystroke.m_data.m_button.m_press ? "down" : "up")
|
keystroke.m_data.m_button.m_press ? "down" : "up")
|
||||||
|
|
@ -1201,7 +1201,7 @@ void MSWindowsKeyState::fakeKey(const Keystroke &keystroke)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Keystroke::kGroup:
|
case Keystroke::KeyType::Group:
|
||||||
// we don't restore the group. we'd like to but we can't be
|
// we don't restore the group. we'd like to but we can't be
|
||||||
// sure the restoring group change will be processed after the
|
// sure the restoring group change will be processed after the
|
||||||
// key events.
|
// key events.
|
||||||
|
|
|
||||||
|
|
@ -594,7 +594,7 @@ void OSXKeyState::postKeyboardKey(CGKeyCode virtualKey, bool keyDown)
|
||||||
void OSXKeyState::fakeKey(const Keystroke &keystroke)
|
void OSXKeyState::fakeKey(const Keystroke &keystroke)
|
||||||
{
|
{
|
||||||
switch (keystroke.m_type) {
|
switch (keystroke.m_type) {
|
||||||
case Keystroke::kButton: {
|
case Keystroke::KeyType::Button: {
|
||||||
bool keyDown = keystroke.m_data.m_button.m_press;
|
bool keyDown = keystroke.m_data.m_button.m_press;
|
||||||
uint32_t client = keystroke.m_data.m_button.m_client;
|
uint32_t client = keystroke.m_data.m_button.m_client;
|
||||||
KeyButton button = keystroke.m_data.m_button.m_button;
|
KeyButton button = keystroke.m_data.m_button.m_button;
|
||||||
|
|
@ -614,7 +614,7 @@ void OSXKeyState::fakeKey(const Keystroke &keystroke)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Keystroke::kGroup: {
|
case Keystroke::KeyType::Group: {
|
||||||
int32_t group = keystroke.m_data.m_group.m_group;
|
int32_t group = keystroke.m_data.m_group.m_group;
|
||||||
if (!keystroke.m_data.m_group.m_restore) {
|
if (!keystroke.m_data.m_group.m_restore) {
|
||||||
if (keystroke.m_data.m_group.m_absolute) {
|
if (keystroke.m_data.m_group.m_absolute) {
|
||||||
|
|
|
||||||
|
|
@ -265,7 +265,7 @@ bool XWindowsKeyState::setCurrentLanguageWithDBus(int32_t group) const
|
||||||
void XWindowsKeyState::fakeKey(const Keystroke &keystroke)
|
void XWindowsKeyState::fakeKey(const Keystroke &keystroke)
|
||||||
{
|
{
|
||||||
switch (keystroke.m_type) {
|
switch (keystroke.m_type) {
|
||||||
case Keystroke::kButton:
|
case Keystroke::KeyType::Button:
|
||||||
if (keystroke.m_data.m_button.m_repeat) {
|
if (keystroke.m_data.m_button.m_repeat) {
|
||||||
int c = keystroke.m_data.m_button.m_button;
|
int c = keystroke.m_data.m_button.m_button;
|
||||||
int i = (c >> 3);
|
int i = (c >> 3);
|
||||||
|
|
@ -281,7 +281,7 @@ void XWindowsKeyState::fakeKey(const Keystroke &keystroke)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Keystroke::kGroup:
|
case Keystroke::KeyType::Group:
|
||||||
if (keystroke.m_data.m_group.m_restore) {
|
if (keystroke.m_data.m_group.m_restore) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -290,7 +290,7 @@ TEST(KeyStateTests, fakeKeyRepeat_validKey_returnsTrue)
|
||||||
MockEventQueue eventQueue;
|
MockEventQueue eventQueue;
|
||||||
KeyStateImpl keyState(eventQueue, keyMap);
|
KeyStateImpl keyState(eventQueue, keyMap);
|
||||||
s_stubKeyItem.m_client = 0;
|
s_stubKeyItem.m_client = 0;
|
||||||
s_stubKeystroke.m_type = deskflow::KeyMap::Keystroke::kButton;
|
s_stubKeystroke.m_type = deskflow::KeyMap::Keystroke::KeyType::Button;
|
||||||
s_stubKeystroke.m_data.m_button.m_button = 2;
|
s_stubKeystroke.m_data.m_button.m_button = 2;
|
||||||
|
|
||||||
// set the button to 1 for fakeKeyDown call
|
// set the button to 1 for fakeKeyDown call
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue