kranewl

A wlroots-based dynamic Wayland compositor, written in C++, configurable with Lua
git clone git://git.deurzen.net/kranewl
Log | Files | Refs | LICENSE

commit 78d93d18a1e9ff994e014e80b8a151630b52f20c
parent ace8d7044def758884407d576fa731b8f7d0c8c2
Author: deurzen <m.deurzen@tum.de>
Date:   Sun, 22 May 2022 13:17:40 +0200

fixes output_destroy segfault

Diffstat:
Minclude/kranewl/model.hh | 2+-
Minclude/kranewl/server.hh | 4++--
Minclude/kranewl/tree/output.hh | 3+--
Minclude/kranewl/tree/root.hh | 4+---
Minclude/version.hh | 4++--
Msrc/kranewl/model.cc | 6++----
Msrc/kranewl/server.cc | 61++++++++++++++++++++++++++++---------------------------------
Msrc/kranewl/tree/output.cc | 22+++++++++-------------
Msrc/kranewl/tree/root.cc | 7++-----
9 files changed, 48 insertions(+), 65 deletions(-)

diff --git a/include/kranewl/model.hh b/include/kranewl/model.hh @@ -29,7 +29,7 @@ public: void register_keyboard(Keyboard_ptr); void unregister_keyboard(Keyboard_ptr); - Output_ptr create_output(struct wlr_output*, struct wlr_scene_output*, bool = false); + Output_ptr create_output(struct wlr_output*, struct wlr_scene_output*); void register_output(Output_ptr); void unregister_output(Output_ptr); diff --git a/include/kranewl/server.hh b/include/kranewl/server.hh @@ -63,17 +63,17 @@ public: struct wl_event_loop* mp_event_loop; struct wlr_backend* mp_backend; - struct wlr_backend* mp_headless_backend; struct wlr_renderer* mp_renderer; struct wlr_allocator* mp_allocator; struct wlr_compositor* mp_compositor; struct wlr_data_device_manager* mp_data_device_manager; + struct wlr_output_layout* mp_output_layout; struct wlr_scene* mp_scene; #ifdef XWAYLAND struct wlr_xwayland* mp_xwayland; #endif - Root m_root; + /* Root m_root; */ Seat m_seat; private: diff --git a/include/kranewl/tree/output.hh b/include/kranewl/tree/output.hh @@ -20,8 +20,7 @@ public: Server_ptr, Model_ptr, struct wlr_output*, - struct wlr_scene_output*, - bool fallback = false + struct wlr_scene_output* ); ~Output(); diff --git a/include/kranewl/tree/root.hh b/include/kranewl/tree/root.hh @@ -7,7 +7,6 @@ extern "C" { #include <wayland-server-core.h> -#include <wlr/backend.h> } typedef class Server* Server_ptr; @@ -15,7 +14,7 @@ typedef class Model* Model_ptr; typedef class Root final : public Node { public: - Root(Server_ptr, Model_ptr, struct wlr_output_layout*, Output_ptr); + Root(Server_ptr, Model_ptr, struct wlr_output_layout*); ~Root(); static void handle_output_layout_change(struct wl_listener*, void*); @@ -37,7 +36,6 @@ public: Cycle<Output_ptr> m_outputs; Cycle<Container_ptr> m_scratchpad; - Output_ptr mp_fallback_output; Container_ptr mp_fullscreen_global; }* Root_ptr; diff --git a/include/version.hh b/include/version.hh @@ -1 +1 @@ -#define VERSION "master/2fd6f35+" -\ No newline at end of file +#define VERSION "master/ace8d70+" +\ No newline at end of file diff --git a/src/kranewl/model.cc b/src/kranewl/model.cc @@ -98,8 +98,7 @@ Model::register_server(Server_ptr server) Output_ptr Model::create_output( struct wlr_output* wlr_output, - struct wlr_scene_output* wlr_scene_output, - bool fallback + struct wlr_scene_output* wlr_scene_output ) { TRACE(); @@ -108,8 +107,7 @@ Model::create_output( mp_server, this, wlr_output, - wlr_scene_output, - fallback + wlr_scene_output ); register_output(output); diff --git a/src/kranewl/server.cc b/src/kranewl/server.cc @@ -20,7 +20,6 @@ #define static extern "C" { #include <wlr/backend.h> -#include <wlr/backend/headless.h> #include <wlr/backend/multi.h> #include <wlr/render/allocator.h> #include <wlr/render/wlr_renderer.h> @@ -81,7 +80,6 @@ Server::Server(Model_ptr model) mp_display(wl_display_create()), mp_event_loop(wl_display_get_event_loop(mp_display)), mp_backend(wlr_backend_autocreate(mp_display)), - mp_headless_backend(wlr_headless_backend_create(mp_display)), mp_renderer([](struct wl_display* display, struct wlr_backend* backend) { struct wlr_renderer* renderer = wlr_renderer_autocreate(backend); wlr_renderer_init_wl_display(renderer, display); @@ -91,27 +89,31 @@ Server::Server(Model_ptr model) mp_allocator(wlr_allocator_autocreate(mp_backend, mp_renderer)), mp_compositor(wlr_compositor_create(mp_display, mp_renderer)), mp_data_device_manager(wlr_data_device_manager_create(mp_display)), - mp_scene(wlr_scene_create()), - m_root([this](struct wl_display* display) { - struct wlr_output_layout* wlr_output_layout = wlr_output_layout_create(); - wlr_xdg_output_manager_v1_create(display, wlr_output_layout); - - struct wlr_output* wlr_output = - wlr_headless_add_output(mp_headless_backend, 800, 600); - wlr_output_set_name(wlr_output, "FALLBACK"); - - return Root( - this, - mp_model, - wlr_output_layout, - mp_model->create_output( - wlr_output, - wlr_scene_output_create(mp_scene, wlr_output), - true - ) - ); - }(mp_display)), - m_seat(this, mp_model, wlr_seat_create(mp_display, "seat0"), wlr_cursor_create()), + mp_output_layout([this]() { + struct wlr_output_layout* output_layout = wlr_output_layout_create(); + /* wlr_xdg_output_manager_v1_create(mp_display, output_layout); */ + return output_layout; + }()), + mp_scene([this]() { + struct wlr_scene* scene = wlr_scene_create(); + wlr_scene_attach_output_layout(scene, mp_output_layout); + return scene; + }()), + /* m_root([this](struct wl_display* display) { */ + /* struct wlr_output_layout* wlr_output_layout = wlr_output_layout_create(); */ + /* wlr_xdg_output_manager_v1_create(display, wlr_output_layout); */ + + /* return Root( */ + /* this, */ + /* mp_model, */ + /* wlr_output_layout */ + /* ); */ + /* }(mp_display)), */ + m_seat([this]() { + struct wlr_cursor* cursor = wlr_cursor_create(); + wlr_cursor_attach_output_layout(cursor, mp_output_layout); + return Seat{this, mp_model, wlr_seat_create(mp_display, "seat0"), cursor}; + }()), #ifdef XWAYLAND mp_xwayland(wlr_xwayland_create(mp_display, mp_compositor, 1)), #endif @@ -131,6 +133,7 @@ Server::Server(Model_ptr model) mp_virtual_pointer_manager(wlr_virtual_pointer_manager_v1_create(mp_display)), mp_virtual_keyboard_manager(wlr_virtual_keyboard_manager_v1_create(mp_display)), ml_new_output({ .notify = Server::handle_new_output }), + ml_output_layout_change({ .notify = Root::handle_output_layout_change }), ml_output_manager_apply({ .notify = Server::handle_output_manager_apply }), ml_output_manager_test({ .notify = Server::handle_output_manager_test }), ml_new_xdg_surface({ .notify = Server::handle_new_xdg_surface }), @@ -151,30 +154,26 @@ Server::Server(Model_ptr model) if (m_socket.empty()) { wlr_backend_destroy(mp_backend); - wlr_backend_destroy(mp_headless_backend); wl_display_destroy(mp_display); std::exit(1); spdlog::critical("Could not set up server socket"); return; } - wlr_multi_backend_add(mp_backend, mp_headless_backend); wlr_export_dmabuf_manager_v1_create(mp_display); wlr_screencopy_manager_v1_create(mp_display); wlr_data_control_manager_v1_create(mp_display); wlr_gamma_control_manager_v1_create(mp_display); wlr_primary_selection_v1_device_manager_create(mp_display); - wlr_scene_attach_output_layout(mp_scene, m_root.mp_output_layout); - wlr_cursor_attach_output_layout(m_seat.mp_cursor, m_root.mp_output_layout); wlr_xcursor_manager_load(mp_cursor_manager, 1); - wlr_scene_set_presentation(mp_scene, wlr_presentation_create(mp_display, mp_backend)); wlr_server_decoration_manager_set_default_mode( mp_server_decoration_manager, WLR_SERVER_DECORATION_MANAGER_MODE_SERVER ); wl_signal_add(&mp_backend->events.new_output, &ml_new_output); + wl_signal_add(&mp_output_layout->events.change, &ml_output_layout_change); wl_signal_add(&mp_layer_shell->events.new_surface, &ml_new_layer_shell_surface); wl_signal_add(&mp_xdg_shell->events.new_surface, &ml_new_xdg_surface); wl_signal_add(&mp_idle_inhibit_manager->events.new_inhibitor, &ml_idle_inhibitor_create); @@ -203,7 +202,6 @@ Server::Server(Model_ptr model) if (!wlr_backend_start(mp_backend)) { wlr_backend_destroy(mp_backend); - wlr_backend_destroy(mp_headless_backend); wl_display_destroy(mp_display); spdlog::critical("Could not start backend"); std::exit(1); @@ -240,9 +238,6 @@ Server::handle_new_output(struct wl_listener* listener, void* data) Server_ptr server = wl_container_of(listener, server, ml_new_output); struct wlr_output* wlr_output = reinterpret_cast<struct wlr_output*>(data); - if (wlr_output == server->m_root.mp_fallback_output->mp_wlr_output) - return; - if (!wlr_output_init_render(wlr_output, server->mp_allocator, server->mp_renderer)) { spdlog::error("Could not initialize rendering to output"); spdlog::warn("Ignoring output " + std::string(wlr_output->name)); @@ -264,7 +259,7 @@ Server::handle_new_output(struct wl_listener* listener, void* data) ); wlr_output->data = output; - wlr_output_layout_add_auto(server->m_root.mp_output_layout, wlr_output); + wlr_output_layout_add_auto(server->mp_output_layout, wlr_output); } void diff --git a/src/kranewl/tree/output.cc b/src/kranewl/tree/output.cc @@ -22,8 +22,7 @@ Output::Output( Server_ptr server, Model_ptr model, struct wlr_output* wlr_output, - struct wlr_scene_output* wlr_scene_output, - bool fallback + struct wlr_scene_output* wlr_scene_output ) : Node(this), mp_context(nullptr), @@ -41,15 +40,12 @@ Output::Output( TRACE(); wl_signal_add(&mp_wlr_output->events.destroy, &ml_destroy); + wl_signal_add(&mp_wlr_output->events.frame, &ml_frame); + wl_signal_add(&mp_wlr_output->events.present, &ml_present); + wl_signal_add(&mp_wlr_output->events.mode, &ml_mode); + wl_signal_add(&mp_wlr_output->events.commit, &ml_commit); - if (fallback) { - wl_signal_add(&mp_wlr_output->events.frame, &ml_frame); - wl_signal_add(&mp_wlr_output->events.present, &ml_present); - wl_signal_add(&mp_wlr_output->events.mode, &ml_mode); - wl_signal_add(&mp_wlr_output->events.commit, &ml_commit); - - wl_signal_init(&m_events.disable); - } + wl_signal_init(&m_events.disable); } Output::~Output() @@ -86,15 +82,15 @@ Output::handle_destroy(struct wl_listener*, void* data) struct wlr_output* wlr_output = reinterpret_cast<struct wlr_output*>(data); Output_ptr output = reinterpret_cast<Output_ptr>(wlr_output->data); - wlr_output_layout_remove(output->mp_server->m_root.mp_output_layout, output->mp_wlr_output); - wlr_scene_output_destroy(output->mp_wlr_scene_output); - wl_list_remove(&output->ml_frame.link); wl_list_remove(&output->ml_destroy.link); wl_list_remove(&output->ml_present.link); wl_list_remove(&output->ml_mode.link); wl_list_remove(&output->ml_commit.link); + wlr_scene_output_destroy(output->mp_wlr_scene_output); + wlr_output_layout_remove(output->mp_server->mp_output_layout, output->mp_wlr_output); + output->mp_model->unregister_output(output); } diff --git a/src/kranewl/tree/root.cc b/src/kranewl/tree/root.cc @@ -10,8 +10,7 @@ extern "C" { Root::Root( Server_ptr server, Model_ptr model, - struct wlr_output_layout* wlr_output_layout, - Output_ptr fallback_output + struct wlr_output_layout* wlr_output_layout ) : Node(this), mp_server(server), @@ -19,13 +18,11 @@ Root::Root( mp_output_layout(wlr_output_layout), ml_output_layout_change({ .notify = Root::handle_output_layout_change }), m_outputs({}, true), - m_scratchpad({}, true), - mp_fallback_output(fallback_output) + m_scratchpad({}, true) { TRACE(); wl_signal_add(&mp_output_layout->events.change, &ml_output_layout_change); - wl_signal_init(&m_events.new_node); }