1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

keyboard: use std::array, default init, + KbButton

This commit is contained in:
Megamouse 2022-04-04 21:04:04 +02:00
parent 43d26fa6b6
commit abf80cc112
3 changed files with 36 additions and 34 deletions

View File

@ -98,7 +98,7 @@ error_code cellKbClearBuf(u32 port_no)
for (int i = 0; i < CELL_KB_MAX_KEYCODES; i++) for (int i = 0; i < CELL_KB_MAX_KEYCODES; i++)
{ {
current_data.keycode[i] = { 0, 0 }; current_data.buttons[i] = KbButton(CELL_KEYC_NO_EVENT, 0, false);
} }
return CELL_OK; return CELL_OK;
@ -312,7 +312,7 @@ error_code cellKbRead(u32 port_no, vm::ptr<CellKbData> data)
{ {
for (s32 i = 0; i < current_data.len; i++) for (s32 i = 0; i < current_data.len; i++)
{ {
data->keycode[i] = current_data.keycode[i].first; data->keycode[i] = current_data.buttons[i].m_keyCode;
} }
KbConfig& current_config = handler.GetConfig(port_no); KbConfig& current_config = handler.GetConfig(port_no);

View File

@ -71,7 +71,7 @@ void KeyboardHandlerBase::Key(u32 code, bool pressed)
if (pressed) if (pressed)
{ {
if (data.len == 1 && data.keycode[0].first == CELL_KEYC_NO_EVENT) if (data.len == 1 && data.buttons[0].m_keyCode == CELL_KEYC_NO_EVENT)
{ {
data.len = 0; data.len = 0;
} }
@ -83,11 +83,11 @@ void KeyboardHandlerBase::Key(u32 code, bool pressed)
if (config.read_mode == CELL_KB_RMODE_INPUTCHAR) if (config.read_mode == CELL_KB_RMODE_INPUTCHAR)
{ {
data.keycode[0] = { CELL_KEYC_NO_EVENT, button.m_outKeyCode }; data.buttons[0] = KbButton(CELL_KEYC_NO_EVENT, button.m_outKeyCode, true);
} }
else else
{ {
data.keycode[data.len % CELL_KB_MAX_KEYCODES] = { CELL_KEYC_NO_EVENT, button.m_outKeyCode }; data.buttons[data.len % CELL_KB_MAX_KEYCODES] = KbButton(CELL_KEYC_NO_EVENT, button.m_outKeyCode, true);
} }
} }
else else
@ -101,11 +101,11 @@ void KeyboardHandlerBase::Key(u32 code, bool pressed)
if (config.read_mode == CELL_KB_RMODE_INPUTCHAR) if (config.read_mode == CELL_KB_RMODE_INPUTCHAR)
{ {
data.keycode[0] = { kcode, 0 }; data.buttons[0] = KbButton(kcode, button.m_outKeyCode, true);
} }
else else
{ {
data.keycode[data.len % CELL_KB_MAX_KEYCODES] = { kcode, 0 }; data.buttons[data.len % CELL_KB_MAX_KEYCODES] = KbButton(kcode, button.m_outKeyCode, true);
} }
} }
@ -122,7 +122,7 @@ void KeyboardHandlerBase::Key(u32 code, bool pressed)
// Needed to indicate key releases. Without this you have to tap another key before using the same key again // Needed to indicate key releases. Without this you have to tap another key before using the same key again
if (config.read_mode == CELL_KB_RMODE_INPUTCHAR) if (config.read_mode == CELL_KB_RMODE_INPUTCHAR)
{ {
data.keycode[0] = { CELL_KEYC_NO_EVENT, 0 }; data.buttons[0] = KbButton(CELL_KEYC_NO_EVENT, button.m_outKeyCode, false);
data.len = 1; data.len = 1;
} }
else else
@ -131,7 +131,7 @@ void KeyboardHandlerBase::Key(u32 code, bool pressed)
for (s32 i = 0; i < data.len; i++) for (s32 i = 0; i < data.len; i++)
{ {
if (data.keycode[i].first == kcode && (!is_meta_key || data.keycode[i].second == button.m_outKeyCode)) if (data.buttons[i].m_keyCode == kcode && (!is_meta_key || data.buttons[i].m_outKeyCode == button.m_outKeyCode))
{ {
index = i; index = i;
break; break;
@ -140,12 +140,12 @@ void KeyboardHandlerBase::Key(u32 code, bool pressed)
for (s32 i = index; i < data.len - 1; i++) for (s32 i = index; i < data.len - 1; i++)
{ {
data.keycode[i] = data.keycode[i + 1]; data.buttons[i] = data.buttons[i + 1];
} }
if (data.len <= 1) if (data.len <= 1)
{ {
data.keycode[0] = { CELL_KEYC_NO_EVENT, 0 }; data.buttons[0] = KbButton(CELL_KEYC_NO_EVENT, button.m_outKeyCode, false);
} }
data.len = std::max(1, data.len - 1); data.len = std::max(1, data.len - 1);
@ -177,9 +177,9 @@ void KeyboardHandlerBase::SetIntercepted(bool intercepted)
keyboard.m_data.mkey = 0; keyboard.m_data.mkey = 0;
keyboard.m_data.len = 0; keyboard.m_data.len = 0;
for (auto& keycode : keyboard.m_data.keycode) for (auto& button : keyboard.m_data.buttons)
{ {
keycode.first = CELL_KEYC_NO_EVENT; button.m_keyCode = CELL_KEYC_NO_EVENT;
} }
} }
} }

View File

@ -24,10 +24,25 @@ enum QtKeys
struct KbInfo struct KbInfo
{ {
u32 max_connect; u32 max_connect = 0;
u32 now_connect; u32 now_connect = 0;
u32 info; u32 info = 0;
u8 status[CELL_KB_MAX_KEYBOARDS]; std::array<u8, CELL_KB_MAX_KEYBOARDS> status{};
};
struct KbButton
{
u32 m_keyCode = 0;
u32 m_outKeyCode = 0;
bool m_pressed = false;
KbButton() = default;
KbButton(u32 keyCode, u32 outKeyCode, bool pressed = false)
: m_keyCode(keyCode)
, m_outKeyCode(outKeyCode)
, m_pressed(pressed)
{
}
}; };
struct KbData struct KbData
@ -35,7 +50,7 @@ struct KbData
u32 led; // Active led lights u32 led; // Active led lights
u32 mkey; // Active key modifiers u32 mkey; // Active key modifiers
s32 len; // Number of key codes (0 means no data available) s32 len; // Number of key codes (0 means no data available)
std::pair<u16, u32> keycode[CELL_KB_MAX_KEYCODES]; std::array<KbButton, CELL_KB_MAX_KEYCODES> buttons{};
KbData() KbData()
: led(0) : led(0)
@ -59,24 +74,11 @@ struct KbConfig
} }
}; };
struct KbButton
{
u32 m_keyCode;
u32 m_outKeyCode;
bool m_pressed = false;
KbButton(u32 keyCode, u32 outKeyCode)
: m_keyCode(keyCode)
, m_outKeyCode(outKeyCode)
{
}
};
struct Keyboard struct Keyboard
{ {
bool m_key_repeat = false; bool m_key_repeat = false;
KbData m_data; KbData m_data{};
KbConfig m_config; KbConfig m_config{};
std::vector<KbButton> m_buttons; std::vector<KbButton> m_buttons;
Keyboard() Keyboard()
@ -109,6 +111,6 @@ public:
protected: protected:
void ReleaseAllKeys(); void ReleaseAllKeys();
KbInfo m_info; KbInfo m_info{};
std::vector<Keyboard> m_keyboards; std::vector<Keyboard> m_keyboards;
}; };