Skip to content

Commit 5146065

Browse files
committed
emsc key events
1 parent 6b49c75 commit 5146065

4 files changed

Lines changed: 40 additions & 4 deletions

File tree

build/emscripten/conanfile.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[requires]
2-
ruis/[>=0.5.278]@cppfw/main
3-
ruis-render-opengles/[>=0.0.0]@cppfw/main
2+
ruis/[>=0.6.2]@cppfw/main
3+
ruis-render-opengles/[>=0.3.1]@cppfw/main
44

55
[generators]
66
AutotoolsDeps

src/ruisapp/glue/sdl/application.cxx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ app_window* application_glue::get_window(native_window::window_id_type id)
8888
return &i->second.get();
8989
}
9090

91+
app_window* application_glue::get_window()
92+
{
93+
if (this->windows.empty()) {
94+
return nullptr;
95+
}
96+
97+
return &this->windows.begin()->second.get();
98+
}
99+
91100
void application_glue::render()
92101
{
93102
for (auto& w : this->windows) {

src/ruisapp/glue/sdl/application.hxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ public:
9696

9797
app_window* get_window(native_window::window_id_type id);
9898

99+
// get first window if any exists
100+
app_window* get_window();
101+
99102
size_t get_num_windows() const noexcept
100103
{
101104
return this->windows.size();

src/ruisapp/glue/sdl/glue.cxx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,15 @@ void main_loop_iteration(void* user_data)
203203
case SDL_KEYDOWN:
204204
[[fallthrough]];
205205
case SDL_KEYUP:
206-
if (auto window = glue.get_window(e.key.windowID)) {
206+
// utki::logcat("SDL_KEYDOWN/UP event, windowID = ", e.key.windowID, '\n');
207+
#if CFG_OS_NAME == CFG_OS_NAME_EMSCRIPTEN
208+
// In Emscripten all key events are always sent to window with ID 0 (invalid id).
209+
// Since we have only one window in Emscripten, we can ignore the window ID.
210+
if (auto window = glue.get_window())
211+
#else
212+
if (auto window = glue.get_window(e.key.windowID))
213+
#endif
214+
{
207215
auto& win = *window;
208216

209217
auto key = sdl_scancode_to_ruis_key(e.key.keysym.scancode);
@@ -229,7 +237,23 @@ void main_loop_iteration(void* user_data)
229237
}
230238
break;
231239
case SDL_TEXTINPUT:
232-
if (auto window = glue.get_window(e.text.windowID)) {
240+
// utki::logcat("SDL_TEXTINPUT event, windowID = ", e.key.windowID, '\n');
241+
#if CFG_OS_NAME == CFG_OS_NAME_EMSCRIPTEN
242+
// In Emscripten all key events are always sent to window with ID 0 (invalid id).
243+
// Since we have only one window in Emscripten, we can ignore the window ID.
244+
if (auto window = glue.get_window())
245+
#else
246+
if (auto window = glue.get_window(e.text.windowID))
247+
#endif
248+
{
249+
// this assert is needed to prevent gcc compiler complaining about unused application_glue::get_window() function in non-Emscripten builds
250+
utki::assert(
251+
[&]() {
252+
return glue.get_window() != nullptr;
253+
},
254+
SL
255+
);
256+
233257
auto& win = *window;
234258

235259
struct sdl_input_string_provider : public ruis::gui::input_string_provider {

0 commit comments

Comments
 (0)