Use unordered_map for keydown to allow codes above 255 (#248)

- Adds internal support for 32bit key codes, required for proper keyboard input on Linux
- Use gdk_keyval_name to get key name on Linux
This commit is contained in:
SSimco 2022-09-18 18:07:26 -07:00 committed by GitHub
parent 5e968eff4f
commit 9f02733a0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 143 additions and 83 deletions

View file

@ -41,14 +41,48 @@ struct WindowInfo
std::atomic_bool has_screenshot_request;
std::atomic_bool is_fullscreen;
std::atomic_bool keydown[256]{};
void set_keystate(uint32 keycode, bool state)
{
const std::lock_guard<std::mutex> lock(keycode_mutex);
m_keydown[keycode] = state;
};
bool get_keystate(uint32 keycode)
{
const std::lock_guard<std::mutex> lock(keycode_mutex);
auto result = m_keydown.find(keycode);
if (result == m_keydown.end())
return false;
return result->second;
}
void get_keystates(std::unordered_map<uint32, bool>& buttons_out)
{
const std::lock_guard<std::mutex> lock(keycode_mutex);
for (auto&& button : m_keydown)
{
buttons_out[button.first] = button.second;
}
}
void set_keystatesdown()
{
const std::lock_guard<std::mutex> lock(keycode_mutex);
std::for_each(m_keydown.begin(), m_keydown.end(), [](std::pair<const uint32, bool>& el){ el.second = false; });
}
template <typename fn>
void iter_keystates(fn f)
{
const std::lock_guard<std::mutex> lock(keycode_mutex);
std::for_each(m_keydown.cbegin(), m_keydown.cend(), f);
}
WindowHandleInfo window_main;
WindowHandleInfo window_pad;
// canvas
WindowHandleInfo canvas_main;
WindowHandleInfo canvas_pad;
private:
std::mutex keycode_mutex;
// m_keydown keys must be valid ImGuiKey values
std::unordered_map<uint32, bool> m_keydown;
};
void gui_create();
@ -68,6 +102,9 @@ bool gui_isFullScreen();
void gui_initHandleContextFromWxWidgetsWindow(WindowHandleInfo& handleInfoOut, class wxWindow* wxw);
#if BOOST_OS_LINUX
std::string gui_gtkRawKeyCodeToString(uint32 keyCode);
#endif
/*
* Returns true if a screenshot request is queued
* Once this function has returned true, it will reset back to