From bf58c953a9b0196bbd9433695f5919bd991a4f79 Mon Sep 17 00:00:00 2001 From: Joel Winarske Date: Mon, 6 May 2024 11:40:47 -0700 Subject: [PATCH] Move display connection external Signed-off-by: Joel Winarske --- CMakeLists.txt | 2 +- cmake/context.cmake | 6 ++ cmake/options.cmake | 7 +++ cmake/wayland.cmake | 5 +- examples/agl-capture.cc | 16 +++++- examples/agl-simple-shm.cc | 14 ++++- examples/gl-shadertoy/shadertoy.cc | 11 +++- examples/presentation-shm.cc | 12 +++- examples/simple-egl.cc | 11 +++- examples/simple-ext-protocol.cc | 11 +++- examples/simple-shm.cc | 15 ++++- examples/vk-shadertoy/app.cc | 13 ++++- examples/vk-shadertoy/app.h | 1 + include/config.h | 3 - src/CMakeLists.txt | 6 +- src/logging.cc | 2 + src/seat/keyboard.cc | 3 +- src/seat/seat.h | 6 +- src/window_manager/agl_shell.cc | 73 +++++++++++++----------- src/window_manager/agl_shell.h | 33 ++++++----- src/window_manager/registrar.h | 16 +++--- src/window_manager/window_manager.cc | 29 +++------- src/window_manager/window_manager.h | 14 +++-- src/window_manager/xdg_window_manager.cc | 66 +++++++++++++-------- src/window_manager/xdg_window_manager.h | 6 +- 25 files changed, 253 insertions(+), 128 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d5f8fb..f27f252 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ if (NOT CMAKE_BUILD_TYPE) endif () list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_DIR}/third_party/sanitizers-cmake/cmake) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/third_party/sanitizers-cmake/cmake) if (NOT BUILD_NUMBER) set(BUILD_NUMBER 0) diff --git a/cmake/context.cmake b/cmake/context.cmake index 918404c..4b4b59a 100644 --- a/cmake/context.cmake +++ b/cmake/context.cmake @@ -14,6 +14,12 @@ # limitations under the License. # +if (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + set(BUILD_STANDALONE ON) +else() + set(BUILD_STANDALONE OFF) +endif() + # # Branch # diff --git a/cmake/options.cmake b/cmake/options.cmake index 92d4b01..3db3c77 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -14,6 +14,13 @@ # limitations under the License. # +# +# Configure options +# +option(ENABLE_XDG_CLIENT "Enable XDG Client" ON) +option(ENABLE_AGL_CLIENT "Enable AGL Shell" OFF) +option(ENABLE_IVI_SHELL_CLIENT "Enable IVI Shell Client" OFF) +option(ENABLE_DRM_LEASE_CLIENT "Enable DRM Lease Client" OFF) # # Link Time Optimization diff --git a/cmake/wayland.cmake b/cmake/wayland.cmake index 80067df..95f7313 100644 --- a/cmake/wayland.cmake +++ b/cmake/wayland.cmake @@ -71,7 +71,6 @@ endmacro() set(WAYLAND_PROTOCOL_SOURCES) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/protocols) -include_directories(${CMAKE_CURRENT_BINARY_DIR}/protocols) add_protocol(${WAYLAND_PROTOCOLS_BASE}/stable/xdg-shell/xdg-shell.xml) add_protocol(${CMAKE_CURRENT_SOURCE_DIR}/third_party/agl/protocol/agl-shell.xml) @@ -121,6 +120,10 @@ configure_file(cmake/wayland-protocols.h.in ${CMAKE_CURRENT_BINARY_DIR}/protocol add_library(wayland-gen STATIC ${WAYLAND_PROTOCOL_SOURCES}) target_link_libraries(wayland-gen PUBLIC PkgConfig::WAYLAND) +target_include_directories(wayland-gen PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_BINARY_DIR}/protocols +) if (IPO_SUPPORT_RESULT) set_property(TARGET wayland-gen PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) diff --git a/examples/agl-capture.cc b/examples/agl-capture.cc index a8fc84e..8090f45 100644 --- a/examples/agl-capture.cc +++ b/examples/agl-capture.cc @@ -46,7 +46,13 @@ class App : public WestonCaptureObserver { public: explicit App(const Configuration &config) : logging_(std::make_unique()), weston_capture_v1_(nullptr) { - agl_shell_ = std::make_unique(false); + display_ = wl_display_connect(nullptr); + if (!display_) { + spdlog::critical("Unable to connect to Wayland socket."); + exit(EXIT_FAILURE); + } + + agl_shell_ = std::make_unique(display_, false); auto d = agl_shell_->get_display(); // required when not creating a window @@ -141,7 +147,12 @@ class App : public WestonCaptureObserver { spdlog::debug("failed: {}", msg); } - ~App() override = default; + ~App() override { + if (display_) { + wl_display_flush(display_); + wl_display_disconnect(display_); + } + }; bool run() { /// display_dispatch is blocking @@ -149,6 +160,7 @@ class App : public WestonCaptureObserver { } private: + struct wl_display *display_; std::unique_ptr logging_; std::unique_ptr agl_shell_; std::list> weston_capture_list_; diff --git a/examples/agl-simple-shm.cc b/examples/agl-simple-shm.cc index d1a9b5b..bb09d82 100644 --- a/examples/agl-simple-shm.cc +++ b/examples/agl-simple-shm.cc @@ -130,7 +130,13 @@ class App : public PointerObserver, public KeyboardObserver, public SeatObserver explicit App(const Configuration &config) : logging_(std::make_unique()), gen_(rd_()) { - agl_shell_ = std::make_unique(config.disable_cursor); + display_ = wl_display_connect(nullptr); + if (!display_) { + spdlog::critical("Unable to connect to Wayland socket."); + exit(EXIT_FAILURE); + } + + agl_shell_ = std::make_unique(display_, config.disable_cursor); spdlog::info("AGL Shell Version: {}", agl_shell_->get_version()); auto seat = agl_shell_->get_seat(); if (seat.has_value()) { @@ -165,6 +171,11 @@ class App : public PointerObserver, public KeyboardObserver, public SeatObserver ~App() override { toplevel_->stop_frame_callbacks(); + + if (display_) { + wl_display_flush(display_); + wl_display_disconnect(display_); + } } bool run() { @@ -301,6 +312,7 @@ class App : public PointerObserver, public KeyboardObserver, public SeatObserver } private: + struct wl_display *display_; std::unique_ptr logging_; std::unique_ptr agl_shell_; struct wl_output *output_; diff --git a/examples/gl-shadertoy/shadertoy.cc b/examples/gl-shadertoy/shadertoy.cc index df76035..3ecd876 100644 --- a/examples/gl-shadertoy/shadertoy.cc +++ b/examples/gl-shadertoy/shadertoy.cc @@ -329,6 +329,12 @@ int main(int argc, char **argv) { auto logging = std::make_unique(); + auto display = wl_display_connect(nullptr); + if (!display) { + spdlog::critical("Unable to connect to Wayland socket."); + exit(EXIT_FAILURE); + } + std::signal(SIGINT, handle_signal); cxxopts::Options options("toy-shader", "Toy Shader"); @@ -364,7 +370,7 @@ int main(int argc, char **argv) { auto keyboard_handler = std::make_unique(); - XdgWindowManager wm; + XdgWindowManager wm(display); auto seat = wm.get_seat(); if (seat.has_value()) { auto keyboard = seat.value()->get_keyboard(); @@ -396,5 +402,8 @@ int main(int argc, char **argv) { top_level->stop_frame_callbacks(); + wl_display_flush(display); + wl_display_disconnect(display); + return EXIT_SUCCESS; } diff --git a/examples/presentation-shm.cc b/examples/presentation-shm.cc index 2bfe5da..d020fcf 100644 --- a/examples/presentation-shm.cc +++ b/examples/presentation-shm.cc @@ -64,6 +64,7 @@ struct Feedback { }; struct Context { + struct wl_display *display; std::unique_ptr wm; Configuration config; XdgTopLevel *toplevel; @@ -280,7 +281,13 @@ int main(int argc, char **argv) { ctx->config.refresh_nsec = kNanoSecondPerSecond / 60; - ctx->wm = std::make_unique(); + ctx->display = wl_display_connect(nullptr); + if (!ctx->display) { + spdlog::critical("Unable to connect to Wayland socket."); + exit(EXIT_FAILURE); + } + + ctx->wm = std::make_unique(ctx->display); spdlog::info("XDG Window Manager Version: {}", ctx->wm->get_version()); @@ -335,5 +342,8 @@ int main(int argc, char **argv) { ctx->toplevel->stop_frame_callbacks(); + wl_display_flush(ctx->display); + wl_display_disconnect(ctx->display); + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/examples/simple-egl.cc b/examples/simple-egl.cc index a13e4b7..290bee0 100644 --- a/examples/simple-egl.cc +++ b/examples/simple-egl.cc @@ -453,6 +453,12 @@ int main(int argc, char **argv) { auto logging = std::make_unique(); + auto display = wl_display_connect(nullptr); + if (!display) { + spdlog::critical("Unable to connect to Wayland socket."); + exit(EXIT_FAILURE); + } + std::signal(SIGINT, handle_signal); cxxopts::Options options("simple-egl", "Weston simple-egl example"); @@ -502,7 +508,7 @@ int main(int argc, char **argv) { auto keyboard_handler = std::make_unique(); - XdgWindowManager wm; + XdgWindowManager wm(display); auto seat = wm.get_seat(); if (seat.has_value()) { auto keyboard = seat.value()->get_keyboard(); @@ -533,5 +539,8 @@ int main(int argc, char **argv) { top_level->stop_frame_callbacks(); + wl_display_flush(display); + wl_display_disconnect(display); + return EXIT_SUCCESS; } diff --git a/examples/simple-ext-protocol.cc b/examples/simple-ext-protocol.cc index 164bb71..ca404e4 100644 --- a/examples/simple-ext-protocol.cc +++ b/examples/simple-ext-protocol.cc @@ -151,6 +151,12 @@ int main(int argc, char **argv) { auto logging = std::make_unique(); + auto display = wl_display_connect(nullptr); + if (!display) { + spdlog::critical("Unable to connect to Wayland socket."); + exit(EXIT_FAILURE); + } + std::signal(SIGINT, handle_signal); cxxopts::Options options("simple-shm", "Weston simple-shm example"); @@ -172,7 +178,7 @@ int main(int argc, char **argv) { .tearing = result["tearing"].as(), }; - XdgWindowManager wm = XdgWindowManager(false, ext_interfaces.size(), + XdgWindowManager wm = XdgWindowManager(display, false, ext_interfaces.size(), ext_interfaces.data() ); spdlog::info("XDG Window Manager Version: {}", wm.get_version()); @@ -199,5 +205,8 @@ int main(int argc, char **argv) { top_level->stop_frame_callbacks(); + wl_display_flush(display); + wl_display_disconnect(display); + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/examples/simple-shm.cc b/examples/simple-shm.cc index 30c094b..cdaa5aa 100644 --- a/examples/simple-shm.cc +++ b/examples/simple-shm.cc @@ -28,6 +28,7 @@ #include +#include #include "window/xdg_toplevel.h" #include "logging.h" @@ -129,7 +130,13 @@ class App : public PointerObserver, public KeyboardObserver, public SeatObserver explicit App(const Configuration &config) : logging_(std::make_unique()), gen_(rd_()) { - wm_ = std::make_unique(config.disable_cursor); + wl_display_ = wl_display_connect(nullptr); + if (!wl_display_) { + spdlog::critical("Unable to connect to Wayland socket."); + exit(EXIT_FAILURE); + } + + wm_ = std::make_unique(wl_display_, config.disable_cursor); auto seat = wm_->get_seat(); if (seat.has_value()) { seat.value()->register_observer(this); @@ -158,6 +165,11 @@ class App : public PointerObserver, public KeyboardObserver, public SeatObserver ~App() override { toplevel_->stop_frame_callbacks(); + + if (wl_display_) { + wl_display_flush(wl_display_); + wl_display_disconnect(wl_display_); + } } bool run() { @@ -294,6 +306,7 @@ class App : public PointerObserver, public KeyboardObserver, public SeatObserver } private: + struct wl_display *wl_display_; std::unique_ptr logging_; std::unique_ptr wm_; XdgTopLevel *toplevel_; diff --git a/examples/vk-shadertoy/app.cc b/examples/vk-shadertoy/app.cc index 366f44f..8ac7856 100644 --- a/examples/vk-shadertoy/app.cc +++ b/examples/vk-shadertoy/app.cc @@ -35,12 +35,18 @@ App::App(const Configuration &config) : handlers_(std::make_unique()), spdlog::info("{}", kAppTitle); + display_ = wl_display_connect(nullptr); + if (!display_) { + spdlog::critical("Unable to connect to Wayland socket."); + exit(EXIT_FAILURE); + } + std::thread t1([&] { backend_ = std::make_unique(kAppId, config.debug_enable); }); std::thread t2([&] { - wm_ = std::make_unique(config.disable_cursor); + wm_ = std::make_unique(display_, config.disable_cursor); auto seat = wm_->get_seat(); if (seat.has_value()) { seat.value()->register_observer(handlers_.get()); @@ -66,7 +72,8 @@ App::App(const Configuration &config) : handlers_(std::make_unique()), t1.join(); t2.join(); - backend_->CreateSurface(wm_->get_display(), toplevel_->get_surface(), config.width, config.height, kOffscreenBuffers); + backend_->CreateSurface(wm_->get_display(), toplevel_->get_surface(), config.width, config.height, + kOffscreenBuffers); /// paint padding toplevel_->set_surface_damage(0, 0, config.width, config.height); @@ -75,6 +82,8 @@ App::App(const Configuration &config) : handlers_(std::make_unique()), App::~App() { toplevel_->stop_frame_callbacks(); + wl_display_flush(display_); + wl_display_flush(display_); } bool App::run() { diff --git a/examples/vk-shadertoy/app.h b/examples/vk-shadertoy/app.h index 550f954..3d10bcc 100644 --- a/examples/vk-shadertoy/app.h +++ b/examples/vk-shadertoy/app.h @@ -50,6 +50,7 @@ class App { bool run(); private: + struct wl_display *display_; std::unique_ptr logging_; std::unique_ptr handlers_; std::unique_ptr wm_; diff --git a/include/config.h b/include/config.h index 835dc1f..1be9b2d 100644 --- a/include/config.h +++ b/include/config.h @@ -37,8 +37,5 @@ static constexpr uint32_t kFractionalScaleManagerMinVersion = UINT32_C(1); static constexpr uint32_t kXdgDecorationManagerMinVersion = UINT32_C(1); static constexpr uint32_t kWestonCaptureV1MinVersion = UINT32_C(1); -/// Logging Constants -static constexpr int64_t kLogFlushInterval = INT64_C(5); - #endif // INCLUDE_CONFIG_H_ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2939dcd..ba3774c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,9 +47,13 @@ add_library(waypp ${SEAT_SRC} ${WINDOW_SRC} command.cc - logging.cc ) +if (BUILD_STANDALONE) + target_sources(waypp PRIVATE + logging.cc) +endif () + if (ENABLE_XDG_CLIENT) target_sources(waypp PRIVATE window/xdg_toplevel.cc diff --git a/src/logging.cc b/src/logging.cc index cae13fd..e830109 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -18,6 +18,8 @@ #include "config.h" +static constexpr int32_t kLogFlushInterval = INT32_C(5); + Logging::Logging() { console_sink_ = std::make_shared(); logger_ = std::make_shared("waypp", console_sink_); diff --git a/src/seat/keyboard.cc b/src/seat/keyboard.cc index 9389ea5..fb468dd 100644 --- a/src/seat/keyboard.cc +++ b/src/seat/keyboard.cc @@ -97,8 +97,7 @@ void Keyboard::handle_keymap(void *data, close(fd); xkb_state_unref(obj->xkb_state_); obj->xkb_state_ = xkb_state_new(obj->xkb_keymap_); - } - else { + } else { spdlog::warn("Usage without libxkbcommon is currently not supported."); } diff --git a/src/seat/seat.h b/src/seat/seat.h index 6ab04e3..c417fcb 100644 --- a/src/seat/seat.h +++ b/src/seat/seat.h @@ -49,8 +49,10 @@ class SeatObserver { class Seat { public: - explicit Seat(struct wl_seat *seat, struct wl_shm *wl_shm, - struct wl_compositor *wl_compositor, bool disable_cursor = false); + explicit Seat(struct wl_seat *seat, + struct wl_shm *wl_shm, + struct wl_compositor *wl_compositor, + bool disable_cursor = false); ~Seat(); diff --git a/src/window_manager/agl_shell.cc b/src/window_manager/agl_shell.cc index 8cd664e..a25bd1b 100644 --- a/src/window_manager/agl_shell.cc +++ b/src/window_manager/agl_shell.cc @@ -21,24 +21,26 @@ #include "logging.h" - /** * @class AglShell * * @brief AglShell represents a Shell for a Wayland-based display. * - * The AglShell class is responsible for managing application windows using the XDG Shell protocol. + * The AglShell class is responsible for managing application windows using the + * XDG Shell protocol. */ -AglShell::AglShell(bool disable_cursor, unsigned long ext_interface_count, +AglShell::AglShell(struct wl_display *display, + bool disable_cursor, + unsigned long ext_interface_count, const Registrar::RegistrarCallback *ext_interface_data, - GMainContext *context, - const char *display_name) : XdgWindowManager( - disable_cursor, ext_interface_count, - ext_interface_data, - context, - display_name), - wait_for_bound_(true), - bound_ok_(false) { + GMainContext *context) + : XdgWindowManager(display, + disable_cursor, + ext_interface_count, + ext_interface_data, + context), + wait_for_bound_(true), + bound_ok_(false) { agl_shell_ = get_agl_shell(); if (!agl_shell_) { spdlog::critical("{} is required.", agl_shell_interface.name); @@ -62,8 +64,7 @@ AglShell::AglShell(bool disable_cursor, unsigned long ext_interface_count, AglShell::~AglShell() = default; -void AglShell::handle_bound_ok(void *data, - struct agl_shell *agl_shell) { +void AglShell::handle_bound_ok(void *data, struct agl_shell *agl_shell) { auto *obj = static_cast(data); if (obj->agl_shell_ != agl_shell) { return; @@ -76,14 +77,15 @@ void AglShell::handle_bound_ok(void *data, } void AglShell::activate_app(const std::string &app_id) { - SPDLOG_DEBUG("[AGL] activate_app: {}", app_id); struct wl_output *wl_output{}; - auto it = std::find_if(std::begin(pending_app_list_), - std::end(pending_app_list_), - [&](const std::pair &p) { return p.first == app_id; }); + auto it = + std::find_if(std::begin(pending_app_list_), std::end(pending_app_list_), + [&](const std::pair &p) { + return p.first == app_id; + }); if (it != pending_app_list_.end()) { SPDLOG_DEBUG("[AGL] pending: {}", app_id); @@ -106,8 +108,7 @@ void AglShell::activate_app(const std::string &app_id) { } void AglShell::deactivate_app(const std::string &app_id) { - auto it = std::find_if(std::begin(apps_stack_), - std::end(apps_stack_), + auto it = std::find_if(std::begin(apps_stack_), std::end(apps_stack_), [&](const std::string &app) { return app == app_id; }); if (it != apps_stack_.end()) { @@ -125,8 +126,7 @@ void AglShell::add_app_to_stack(const std::string &app_id) { } } -void AglShell::handle_bound_fail(void *data, - struct agl_shell *agl_shell) { +void AglShell::handle_bound_fail(void *data, struct agl_shell *agl_shell) { auto *obj = static_cast(data); if (obj->agl_shell_ != agl_shell) { return; @@ -177,7 +177,8 @@ void AglShell::handle_app_on_output(void *data, return; } - SPDLOG_DEBUG("[AGL] app_on_output: app_id: {}, output name: {}", app_id, output_name); + SPDLOG_DEBUG("[AGL] app_on_output: app_id: {}, output name: {}", app_id, + output_name); // a couple of use-cases, if there is no app_id in the app_list then it // means this is a request to map the application, from the start to a @@ -192,7 +193,8 @@ void AglShell::handle_app_on_output(void *data, // // finally if the outputs are identical probably that's a user-error - // but the compositor won't activate it again, so we don't handle that. - obj->pending_app_list_.emplace_back(std::move(std::pair(app_id, output_name))); + obj->pending_app_list_.emplace_back( + std::move(std::pair(app_id, output_name))); auto iter = obj->apps_stack_.begin(); while (iter != obj->apps_stack_.end()) { @@ -205,8 +207,10 @@ void AglShell::handle_app_on_output(void *data, } } -void AglShell::set_background(struct wl_surface *wl_surface, struct wl_output *wl_output) const { - SPDLOG_DEBUG("[AGL] Set Background: surface: {}, output: {}", fmt::ptr(wl_surface), fmt::ptr(wl_output)); +void AglShell::set_background(struct wl_surface *wl_surface, + struct wl_output *wl_output) const { + SPDLOG_DEBUG("[AGL] Set Background: surface: {}, output: {}", + fmt::ptr(wl_surface), fmt::ptr(wl_output)); agl_shell_set_background(agl_shell_, wl_surface, wl_output); } @@ -224,9 +228,11 @@ std::string AglShell::edge_to_string(const enum agl_shell_edge mode) { return {}; } -void -AglShell::set_panel(struct wl_surface *wl_surface, struct wl_output *wl_output, const enum agl_shell_edge mode) const { - SPDLOG_DEBUG("[AGL] Set Panel: surface: {}, output: {}, mode: {}", fmt::ptr(wl_surface), fmt::ptr(wl_output), +void AglShell::set_panel(struct wl_surface *wl_surface, + struct wl_output *wl_output, + const enum agl_shell_edge mode) const { + SPDLOG_DEBUG("[AGL] Set Panel: surface: {}, output: {}, mode: {}", + fmt::ptr(wl_surface), fmt::ptr(wl_output), edge_to_string(mode).c_str()); agl_shell_set_panel(agl_shell_, wl_surface, wl_output, mode); } @@ -236,12 +242,13 @@ void AglShell::set_activate_region(struct wl_output *wl_output, uint32_t y, uint32_t width, uint32_t height) const { - SPDLOG_DEBUG("[AGL] Set Activate Region: output: {}, x: {}, y: {}, width: {}, height: {}", fmt::ptr(wl_output), - x, y, width, height); + SPDLOG_DEBUG( + "[AGL] Set Activate Region: output: {}, x: {}, y: {}, width: {}, height: " + "{}", + fmt::ptr(wl_output), x, y, width, height); agl_shell_set_activate_region( - agl_shell_, wl_output, static_cast(x), - static_cast(y), static_cast(width), - static_cast(height)); + agl_shell_, wl_output, static_cast(x), static_cast(y), + static_cast(width), static_cast(height)); } void AglShell::ready() const { diff --git a/src/window_manager/agl_shell.h b/src/window_manager/agl_shell.h index 648ce89..1b620a4 100644 --- a/src/window_manager/agl_shell.h +++ b/src/window_manager/agl_shell.h @@ -22,15 +22,16 @@ #include "registrar.h" #include "xdg_window_manager.h" - class XdgWindowManager; class AglShell : public XdgWindowManager { public: - explicit AglShell(bool disable_cursor = false, unsigned long ext_interface_count = 0, - const Registrar::RegistrarCallback *ext_interface_data = nullptr, - GMainContext *context = nullptr, - const char *display_name = nullptr); + explicit AglShell( + struct wl_display *display, + bool disable_cursor = false, + unsigned long ext_interface_count = 0, + const Registrar::RegistrarCallback *ext_interface_data = nullptr, + GMainContext *context = nullptr); ~AglShell(); @@ -40,16 +41,23 @@ class AglShell : public XdgWindowManager { void deactivate_app(const std::string &app_id); - void set_background(struct wl_surface *wl_surface, struct wl_output *wl_output) const; + void set_background(struct wl_surface *wl_surface, + struct wl_output *wl_output) const; - void set_panel(struct wl_surface *wl_surface, struct wl_output *wl_output, enum agl_shell_edge mode) const; + void set_panel(struct wl_surface *wl_surface, + struct wl_output *wl_output, + enum agl_shell_edge mode) const; - void set_activate_region(struct wl_output *wl_output, uint32_t x, uint32_t y, uint32_t width, + void set_activate_region(struct wl_output *wl_output, + uint32_t x, + uint32_t y, + uint32_t width, uint32_t height) const; void ready() const; - void process_app_status_event(const char *app_id, const std::string &event_type); + void process_app_status_event(const char *app_id, + const std::string &event_type); static std::string edge_to_string(const enum agl_shell_edge mode); @@ -74,8 +82,7 @@ class AglShell : public XdgWindowManager { * event before continuing further. * @since 2 */ - static void handle_bound_ok(void *data, - struct agl_shell *agl_shell); + static void handle_bound_ok(void *data, struct agl_shell *agl_shell); /** * event sent if binding was nok @@ -85,8 +92,7 @@ class AglShell : public XdgWindowManager { * continuing further. * @since 2 */ - static void handle_bound_fail(void *data, - struct agl_shell *agl_shell); + static void handle_bound_fail(void *data, struct agl_shell *agl_shell); /** * event sent when an application suffered state modification @@ -118,7 +124,6 @@ class AglShell : public XdgWindowManager { const char *app_id, const char *output_name); - void add_app_to_stack(const std::string &app_id); static constexpr struct agl_shell_listener agl_shell_listener_ = { diff --git a/src/window_manager/registrar.h b/src/window_manager/registrar.h index 0cba407..1aae2e2 100644 --- a/src/window_manager/registrar.h +++ b/src/window_manager/registrar.h @@ -139,12 +139,12 @@ class Registrar { std::vector wl_shm_formats_{}; - struct wl_compositor *wl_compositor_; - struct wl_shm *wl_shm_; - struct wl_subcompositor *wl_subcompositor_; - struct xdg_wm_base *xdg_wm_base_; - struct agl_shell *agl_shell_; - struct ivi_wm *ivi_wm_; + struct wl_compositor *wl_compositor_{}; + struct wl_shm *wl_shm_{}; + struct wl_subcompositor *wl_subcompositor_{}; + struct xdg_wm_base *xdg_wm_base_{}; + struct agl_shell *agl_shell_{}; + struct ivi_wm *ivi_wm_{}; #if ENABLE_DRM_LEASE_CLIENT std::unique_ptr drm_lease_device_v1_; @@ -156,7 +156,7 @@ class Registrar { struct { struct wp_presentation *wp_presentation; clockid_t clk_id; - } presentation_time_; + } presentation_time_{}; struct wp_tearing_control_manager_v1 *wp_tearing_control_manager_{}; struct wp_viewporter *wp_viewporter_{}; @@ -181,7 +181,7 @@ class Registrar { static constexpr const wl_registry_listener listener_ = { .global = registry_handle_global, - .global_remove = registry_handle_global_remove, + .global_remove = nullptr, }; // Handles shm format events. diff --git a/src/window_manager/window_manager.cc b/src/window_manager/window_manager.cc index 35e1090..6a0fd0b 100644 --- a/src/window_manager/window_manager.cc +++ b/src/window_manager/window_manager.cc @@ -35,16 +35,16 @@ class Registrar; * @see Window * @see XdgWm */ -WindowManager::WindowManager(bool disable_cursor, +WindowManager::WindowManager(struct wl_display *display, bool disable_cursor, const unsigned long ext_interface_count, const Registrar::RegistrarCallback *ext_interface_data, - GMainContext *context, - const char *display_name) : Registrar(get_display(display_name), - ext_interface_count, - ext_interface_data, - disable_cursor), - context_(context), - outputs_(get_outputs()) { + GMainContext *context) : Registrar(display, + ext_interface_count, + ext_interface_data, + disable_cursor), + wl_display_(display), + context_(context), + outputs_(get_outputs()) { SPDLOG_TRACE("++WindowManager::WindowManager()"); SPDLOG_TRACE("--WindowManager::WindowManager()"); } @@ -57,22 +57,9 @@ WindowManager::WindowManager(bool disable_cursor, */ WindowManager::~WindowManager() { SPDLOG_TRACE("++WindowManager::~WindowManager()"); -// wl_display_flush(wl_display_); -// wl_display_disconnect(wl_display_); SPDLOG_TRACE("--WindowManager::~WindowManager()"); } -struct wl_display *WindowManager::get_display(const char *name) { - SPDLOG_TRACE("++WindowManager::get_display()"); - wl_display_ = (wl_display_connect(name)); - if (wl_display_ == nullptr) { - spdlog::critical("Failed to connect to Wayland display. {}", strerror(errno)); - exit(EXIT_FAILURE); - } - SPDLOG_TRACE("--WindowManager::get_display()"); - return wl_display_; -} - /** * @brief Dispatches events from the Wayland display. * diff --git a/src/window_manager/window_manager.h b/src/window_manager/window_manager.h index 592d0f0..e96bd4b 100644 --- a/src/window_manager/window_manager.h +++ b/src/window_manager/window_manager.h @@ -25,10 +25,12 @@ class Registrar; class WindowManager : public Registrar { public: - explicit WindowManager(bool disable_cursor = false, unsigned long ext_interface_count = 0, - const Registrar::RegistrarCallback *ext_interface_data = nullptr, - GMainContext *context = nullptr, - const char *display_name = nullptr); + explicit WindowManager( + struct wl_display *display, + bool disable_cursor = false, + unsigned long ext_interface_count = 0, + const Registrar::RegistrarCallback *ext_interface_data = nullptr, + GMainContext *context = nullptr); ~WindowManager(); @@ -38,7 +40,9 @@ class WindowManager : public Registrar { [[maybe_unused]] [[nodiscard]] int dispatch(int timeout) const; - [[nodiscard]] int dispatch_pending() const { return wl_display_dispatch_pending(wl_display_); } + [[nodiscard]] int dispatch_pending() const { + return wl_display_dispatch_pending(wl_display_); + } [[nodiscard]] int display_dispatch() const; diff --git a/src/window_manager/xdg_window_manager.cc b/src/window_manager/xdg_window_manager.cc index 5234345..5eb45a8 100644 --- a/src/window_manager/xdg_window_manager.cc +++ b/src/window_manager/xdg_window_manager.cc @@ -19,22 +19,26 @@ #include "logging.h" #include "window/xdg_toplevel.h" - /** * @class XdgWindowManager * * @brief XdgWm represents a surface manager for a Wayland-based display. * - * The XdgWm class is responsible for managing application windows using the XDG Shell protocol. + * The XdgWm class is responsible for managing application windows using the XDG + * Shell protocol. */ -XdgWindowManager::XdgWindowManager(bool disable_cursor, const unsigned long ext_interface_count, - const Registrar::RegistrarCallback *ext_interface_data, - GMainContext *context, - const char *display_name) : WindowManager(disable_cursor, - ext_interface_count, - ext_interface_data, - context, display_name) { +XdgWindowManager::XdgWindowManager( + struct wl_display *display, + bool disable_cursor, + const unsigned long ext_interface_count, + const Registrar::RegistrarCallback *ext_interface_data, + GMainContext *context) + : WindowManager(display, + disable_cursor, + ext_interface_count, + ext_interface_data, + context) { SPDLOG_TRACE("++XdgWindowManager::XdgWindowManager()"); xdg_wm_base_ = get_xdg_wm_base(); if (!xdg_wm_base_) { @@ -51,10 +55,12 @@ XdgWindowManager::XdgWindowManager(bool disable_cursor, const unsigned long ext_ * * @brief The XdgWm class represents a Wayland shell surface manager. * - * The XdgWm class manages the creation, destruction, configuration, and behavior of a Wayland shell surface manager. + * The XdgWm class manages the creation, destruction, configuration, and + * behavior of a Wayland shell surface manager. * - * It is responsible for handling interactions with the Wayland registry, creating and destroying the surface manager base, - * surface, and toplevel objects, and implementing the necessary event handling functions. + * It is responsible for handling interactions with the Wayland registry, + * creating and destroying the surface manager base, surface, and toplevel + * objects, and implementing the necessary event handling functions. */ XdgWindowManager::~XdgWindowManager() = default; @@ -76,19 +82,31 @@ void XdgWindowManager::xdg_wm_base_ping(void *data, xdg_wm_base_pong(xdg_wm_base, serial); } -XdgTopLevel * -XdgWindowManager::create_top_level(const char *title, const char *app_id, int width, int height, int buffer_count, - uint32_t buffer_format, bool fullscreen, bool maximized, bool fullscreen_ratio, - bool tearing, const std::function &frame_callback, - const int32_t *context_attribs, size_t context_attribs_size, - const int32_t *config_attribs, size_t config_attribs_size, - enum Egl::api type, int buffer_bpp, int swap_interval) { +XdgTopLevel *XdgWindowManager::create_top_level( + const char *title, + const char *app_id, + int width, + int height, + int buffer_count, + uint32_t buffer_format, + bool fullscreen, + bool maximized, + bool fullscreen_ratio, + bool tearing, + const std::function &frame_callback, + const int32_t *context_attribs, + size_t context_attribs_size, + const int32_t *config_attribs, + size_t config_attribs_size, + enum Egl::api type, + int buffer_bpp, + int swap_interval) { auto wm = reinterpret_cast(this); - xdg_top_level_ = std::make_unique(wm, title, app_id, width, height, buffer_count, buffer_format, - fullscreen, maximized, fullscreen_ratio, tearing, - frame_callback, buffer_bpp, swap_interval, - context_attribs, context_attribs_size, - config_attribs, config_attribs_size, type); + xdg_top_level_ = std::make_unique( + wm, title, app_id, width, height, buffer_count, buffer_format, fullscreen, + maximized, fullscreen_ratio, tearing, frame_callback, buffer_bpp, + swap_interval, context_attribs, context_attribs_size, config_attribs, + config_attribs_size, type); return xdg_top_level_.get(); } diff --git a/src/window_manager/xdg_window_manager.h b/src/window_manager/xdg_window_manager.h index 555909a..189ed61 100644 --- a/src/window_manager/xdg_window_manager.h +++ b/src/window_manager/xdg_window_manager.h @@ -30,10 +30,10 @@ class XdgTopLevel; class XdgWindowManager : public WindowManager { public: - explicit XdgWindowManager(bool disable_cursor = false, unsigned long ext_interface_count = 0, + explicit XdgWindowManager(struct wl_display *display, bool disable_cursor = false, + unsigned long ext_interface_count = 0, const Registrar::RegistrarCallback *ext_interface_data = nullptr, - GMainContext *context = nullptr, - const char *display_name = nullptr); + GMainContext *context = nullptr); ~XdgWindowManager();