x11 thread workaround

This commit is contained in:
2025-07-31 14:36:21 +02:00
parent 24df0fc825
commit e1004ff196

View File

@@ -9,31 +9,33 @@
int main() {
EventLoop loop;
SfmlSurface surface(&loop);
surface.set_window<GridWindow<SfmlSurface, BwPixel, 2, 2>>();
GridWindow<SfmlSurface, BwPixel, 2, 2>* window =
static_cast<GridWindow<SfmlSurface, BwPixel, 2, 2>*>(surface.get_window());
window->set_window<TextWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, std::string>>(0, 0, &loop, "hello");
window->set_window<TextWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, std::string>>(0, 1, &loop, "hello1");
window->set_window<GridWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, 2, 2>>(1, 0);
GridWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, 2, 2>* window2 =
static_cast<GridWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, 2, 2>*>(
window->get_subsurface(1, 0).get_window());
window->set_window<TextWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, std::string>>(1, 1, &loop, "hello3");
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, BwPixel>, BwPixel, std::string>>(
0, 0, &loop, "hello2");
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, BwPixel>, BwPixel, std::string>>(
0, 1, &loop, "hello4");
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, BwPixel>, BwPixel, std::string>>(
1, 0, &loop, "hello5");
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, 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<SfmlSurface, BwPixel, 2, 2>>();
GridWindow<SfmlSurface, BwPixel, 2, 2>* window =
static_cast<GridWindow<SfmlSurface, BwPixel, 2, 2>*>(surface.get_window());
window->set_window<TextWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, std::string>>(0, 0, &loop, "hello");
window->set_window<TextWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, std::string>>(0, 1, &loop, "hello1");
window->set_window<GridWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, 2, 2>>(1, 0);
GridWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, 2, 2>* window2 =
static_cast<GridWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, 2, 2>*>(
window->get_subsurface(1, 0).get_window());
window->set_window<TextWindow<SubSurface<SfmlSurface, BwPixel>, BwPixel, std::string>>(1, 1, &loop, "hello3");
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, BwPixel>, BwPixel, std::string>>(
0, 0, &loop, "hello2");
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, BwPixel>, BwPixel, std::string>>(
0, 1, &loop, "hello4");
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, BwPixel>, BwPixel, std::string>>(
1, 0, &loop, "hello5");
window2->set_window<TextWindow<SubSurface<SubSurface<SfmlSurface, BwPixel>, 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<sf::Event::Closed>()) {
surface._sf_window.close();
surface_ptr->_sf_window.close();
loop.push(LoopQuitEvent{});
}
if (event->is<sf::Event::Resized>()) {
auto newSize = event->getIf<sf::Event::Resized>()->size;
surface.push(SurfaceResizeEvent{newSize.x, newSize.y});
surface_ptr->push(SurfaceResizeEvent{newSize.x, newSize.y});
}
if (event->is<sf::Event::KeyPressed>()) {
auto key = event->getIf<sf::Event::KeyPressed>();
surface.push(KeyboardEvent{static_cast<Key>(key->code)});
surface_ptr->push(KeyboardEvent{static_cast<Key>(key->code)});
}
}
}