From e1004ff196ef8b8043bafda5433f7b8fd209a5dc Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Thu, 31 Jul 2025 14:36:21 +0200 Subject: [PATCH] x11 thread workaround --- Firmware/sdk/sfml-port/src/main.cpp | 56 +++++++++++++++-------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/Firmware/sdk/sfml-port/src/main.cpp b/Firmware/sdk/sfml-port/src/main.cpp index 2630b7f..3716963 100644 --- a/Firmware/sdk/sfml-port/src/main.cpp +++ b/Firmware/sdk/sfml-port/src/main.cpp @@ -9,31 +9,33 @@ int main() { EventLoop loop; - SfmlSurface surface(&loop); - - surface.set_window>(); - - GridWindow* window = - static_cast*>(surface.get_window()); - window->set_window, BwPixel, std::string>>(0, 0, &loop, "hello"); - window->set_window, BwPixel, std::string>>(0, 1, &loop, "hello1"); - window->set_window, BwPixel, 2, 2>>(1, 0); - GridWindow, BwPixel, 2, 2>* window2 = - static_cast, BwPixel, 2, 2>*>( - window->get_subsurface(1, 0).get_window()); - window->set_window, BwPixel, std::string>>(1, 1, &loop, "hello3"); - - window2->set_window, BwPixel>, BwPixel, std::string>>( - 0, 0, &loop, "hello2"); - window2->set_window, BwPixel>, BwPixel, std::string>>( - 0, 1, &loop, "hello4"); - window2->set_window, BwPixel>, BwPixel, std::string>>( - 1, 0, &loop, "hello5"); - window2->set_window, BwPixel>, BwPixel, std::string>>( - 1, 1, &loop, "hello6"); + SfmlSurface* surface_ptr; int i = 0; std::thread loop_thread{[&] { + SfmlSurface surface(&loop); + surface_ptr = &surface; + + surface.set_window>(); + + GridWindow* window = + static_cast*>(surface.get_window()); + window->set_window, BwPixel, std::string>>(0, 0, &loop, "hello"); + window->set_window, BwPixel, std::string>>(0, 1, &loop, "hello1"); + window->set_window, BwPixel, 2, 2>>(1, 0); + GridWindow, BwPixel, 2, 2>* window2 = + static_cast, BwPixel, 2, 2>*>( + window->get_subsurface(1, 0).get_window()); + window->set_window, BwPixel, std::string>>(1, 1, &loop, "hello3"); + + window2->set_window, BwPixel>, BwPixel, std::string>>( + 0, 0, &loop, "hello2"); + window2->set_window, BwPixel>, BwPixel, std::string>>( + 0, 1, &loop, "hello4"); + window2->set_window, BwPixel>, BwPixel, std::string>>( + 1, 0, &loop, "hello5"); + window2->set_window, BwPixel>, BwPixel, std::string>>( + 1, 1, &loop, "hello6"); loop.run([&] { surface._sf_window.clear(); surface._texture.update(surface._image); @@ -45,19 +47,19 @@ int main() { }); }}; - while (surface._sf_window.isOpen()) { - while (const std::optional event = surface._sf_window.pollEvent()) { + while (surface_ptr->_sf_window.isOpen()) { + while (const std::optional event = surface_ptr->_sf_window.pollEvent()) { if (event->is()) { - surface._sf_window.close(); + surface_ptr->_sf_window.close(); loop.push(LoopQuitEvent{}); } if (event->is()) { auto newSize = event->getIf()->size; - surface.push(SurfaceResizeEvent{newSize.x, newSize.y}); + surface_ptr->push(SurfaceResizeEvent{newSize.x, newSize.y}); } if (event->is()) { auto key = event->getIf(); - surface.push(KeyboardEvent{static_cast(key->code)}); + surface_ptr->push(KeyboardEvent{static_cast(key->code)}); } } }