From 6826c6cd616b5910f1d89b9f06249d787ca566bb Mon Sep 17 00:00:00 2001 From: Joel Winarske Date: Fri, 3 May 2024 09:10:01 -0700 Subject: [PATCH] Dynamic Config Refactor -generate wayland-protocols.h by CMake -remove std::optional usage in registrar; depend on nullptr -simplify Registrar Signed-off-by: Joel Winarske --- .../wayland-protocols.h.in | 55 ++-- cmake/wayland.cmake | 26 +- examples/CMakeLists.txt | 25 +- examples/agl-simple-shm.cc | 2 - examples/simple-egl.cc | 8 +- examples/simple-ext-protocol.cc | 41 +-- examples/simple-shm.cc | 2 - src/CMakeLists.txt | 27 +- src/command.cc | 11 +- src/command.h | 2 +- src/seat/keyboard.cc | 7 +- src/seat/pointer.cc | 6 +- src/seat/pointer.h | 6 +- src/seat/seat.cc | 4 +- src/seat/seat.h | 4 +- src/window/anonymous_file.cc | 9 +- src/window/buffer.h | 2 +- src/window/egl.cc | 4 +- src/window/feedback.cc | 2 +- src/window/window.cc | 51 ++-- src/window/window.h | 8 +- src/window/xdg_toplevel.cc | 8 +- src/window/xdg_toplevel.h | 10 +- src/window_manager/agl_shell.cc | 7 +- src/window_manager/output.cc | 7 +- src/window_manager/output.h | 6 +- src/window_manager/registrar.cc | 282 +++++++++--------- src/window_manager/registrar.h | 178 +++++------ src/window_manager/window_manager.h | 2 +- src/window_manager/xdg_output.cc | 13 + src/window_manager/xdg_output.h | 18 +- src/window_manager/xdg_window_manager.cc | 9 +- 32 files changed, 372 insertions(+), 470 deletions(-) rename include/wayland-protocols.h => cmake/wayland-protocols.h.in (57%) diff --git a/include/wayland-protocols.h b/cmake/wayland-protocols.h.in similarity index 57% rename from include/wayland-protocols.h rename to cmake/wayland-protocols.h.in index 78caf88..e14b398 100644 --- a/include/wayland-protocols.h +++ b/cmake/wayland-protocols.h.in @@ -19,33 +19,50 @@ #include -#if defined(ENABLE_XDG_CLIENT) - +#cmakedefine01 ENABLE_XDG_CLIENT +#cmakedefine01 ENABLE_AGL_SHELL_CLIENT +#cmakedefine01 ENABLE_IVI_SHELL_CLIENT +#cmakedefine01 ENABLE_DRM_LEASE_CLIENT + +#cmakedefine01 HAS_WAYLAND_PROTOCOL_XDG_SHELL +#cmakedefine01 HAS_WAYLAND_PROTOCOL_AGL_SHELL +#cmakedefine01 HAS_WAYLAND_PROTOCOL_AGL_SHELL_DESKTOP +#cmakedefine01 HAS_WAYLAND_PROTOCOL_AGL_SCREENSHOOTER +#cmakedefine01 HAS_WAYLAND_PROTOCOL_DRM_LEASE_V1 +#cmakedefine01 HAS_WAYLAND_PROTOCOL_PRESENTATION_TIME +#cmakedefine01 HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1 +#cmakedefine01 HAS_WAYLAND_PROTOCOL_VIEWPORTER +#cmakedefine01 HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1 +#cmakedefine01 HAS_WAYLAND_PROTOCOL_XDG_OUTPUT_UNSTABLE_V1 +#cmakedefine01 HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1 +#cmakedefine01 HAS_WAYLAND_PROTOCOL_LINUX_DMABUF_V1GLOBAL + +#cmakedefine01 HAVE_MEMFD_CREATE +#cmakedefine01 HAVE_POSIX_FALLOCATE +#cmakedefine01 HAVE_MKOSTEMP + + +#if ENABLE_XDG_CLIENT #include "xdg-shell-client-protocol.h" - #endif -#if defined(ENABLE_AGL_SHELL_CLIENT) +#if ENABLE_AGL_SHELL_CLIENT #include "agl-shell-client-protocol.h" #include "agl-shell-desktop-client-protocol.h" #include "agl-screenshooter-client-protocol.h" #endif -#if defined(ENABLE_IVI_SHELL_CLIENT) +#if ENABLE_IVI_SHELL_CLIENT #include "ivi-wm-client-protocol.h" #include "ivi-application-client-protocol.h" #endif -#if defined(HAS_WAYLAND_PROTOCOL_DRM_LEASE_V1) - +#if HAS_WAYLAND_PROTOCOL_DRM_LEASE_V1 #include "drm-lease-v1-client-protocol.h" - #endif -#if defined(HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1) - +#if HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1 #include "xdg-decoration-unstable-v1-client-protocol.h" - #else struct zxdg_decoration_manager_v1; struct zxdg_toplevel_decoration_v1; @@ -53,36 +70,28 @@ struct zxdg_toplevel_decoration_v1; #include "presentation-time-client-protocol.h" -#if defined(HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1) - +#if HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1 #include "fractional-scale-v1-client-protocol.h" - #else struct wp_fractional_scale_manager_v1; struct wp_fractional_scale_v1; #endif -#if defined(HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1) - +#if HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1 #include "tearing-control-v1-client-protocol.h" - #else struct wp_tearing_control_manager_v1; #endif -#if defined(HAS_WAYLAND_PROTOCOL_VIEWPORTER) - +#if HAS_WAYLAND_PROTOCOL_VIEWPORTER #include "viewporter-client-protocol.h" - #else struct wp_viewporter; struct wp_viewport; #endif -#if defined(HAS_WAYLAND_PROTOCOL_XDG_OUTPUT_UNSTABLE_V1) - +#if HAS_WAYLAND_PROTOCOL_XDG_OUTPUT_UNSTABLE_V1 #include "xdg-output-unstable-v1-client-protocol.h" - #else struct zxdg_output_manager_v1; struct zxdg_output_v1; diff --git a/cmake/wayland.cmake b/cmake/wayland.cmake index f75046c..93957c7 100644 --- a/cmake/wayland.cmake +++ b/cmake/wayland.cmake @@ -26,6 +26,11 @@ option(ENABLE_DRM_LEASE_CLIENT "Enable DRM Lease Client" OFF) find_package(PkgConfig REQUIRED) pkg_check_modules(WAYLAND REQUIRED IMPORTED_TARGET wayland-client wayland-egl wayland-cursor xkbcommon) +include(CheckFunctionExists) +check_function_exists(memfd_create HAVE_MEMFD_CREATE) +check_function_exists(posix_fallocate HAVE_POSIX_FALLOCATE) +check_function_exists(mkostemp HAVE_MKOSTEMP) + set(MIN_PROTOCOL_VER 1.13) if (ENABLE_DRM_LEASE) set(MIN_PROTOCOL_VER 1.22) @@ -64,7 +69,6 @@ macro(add_protocol protocol_file) endmacro() set(WAYLAND_PROTOCOL_SOURCES) -set(LIST_WAYLAND_PROTOCOLS) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/protocols) include_directories(${CMAKE_CURRENT_BINARY_DIR}/protocols) @@ -115,27 +119,11 @@ if (EXT_PROTOCOL) endforeach () endif () -message(STATUS "WAYLAND_PROTOCOL_SOURCES: ${WAYLAND_PROTOCOL_SOURCES}") +configure_file(cmake/wayland-protocols.h.in ${CMAKE_CURRENT_BINARY_DIR}/protocols/wayland-protocols.h) + add_library(wayland-gen STATIC ${WAYLAND_PROTOCOL_SOURCES}) target_link_libraries(wayland-gen PUBLIC PkgConfig::WAYLAND) -if (ENABLE_XDG_CLIENT) - target_compile_definitions(wayland-gen PUBLIC ENABLE_XDG_CLIENT) -endif () -if (ENABLE_AGL_SHELL_CLIENT) - target_compile_definitions(wayland-gen PUBLIC ENABLE_AGL_SHELL_CLIENT) -endif () -if (ENABLE_IVI_SHELL_CLIENT) - target_compile_definitions(wayland-gen PUBLIC ENABLE_IVI_SHELL_CLIENT) -endif () -if (ENABLE_DRM_LEASE_CLIENT) - target_compile_definitions(wayland-gen PUBLIC ENABLE_DRM_LEASE_CLIENT) -endif () - -string(REPLACE ";" " " WAYLAND_PROTOCOL_DEFINES "${LIST_WAYLAND_PROTOCOLS}" GLOBAL) -message(STATUS "DEFINITIONS: ${WAYLAND_PROTOCOL_DEFINES}") -target_compile_definitions(wayland-gen PUBLIC ${WAYLAND_PROTOCOL_DEFINES}) - if (IPO_SUPPORT_RESULT) set_property(TARGET wayland-gen PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) endif () diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 16a7f2f..e8d2a69 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -49,10 +49,10 @@ if (ENABLE_XDG_CLIENT) add_sanitizers(simple-shm) + # + # presentation-shm + # if (FALSE) - # - # presentation-shm - # add_executable(presentation-shm presentation-shm.cc) target_include_directories(presentation-shm PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src) @@ -81,20 +81,19 @@ if (ENABLE_XDG_CLIENT) add_sanitizers(simple-ext-protocol) endif () -endif () - -if (ENABLE_AGL_SHELL_CLIENT) # # agl-simple-shm # - add_executable(agl-simple-shm agl-simple-shm.cc) - target_include_directories(agl-simple-shm PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src) + if (ENABLE_AGL_SHELL_CLIENT) + add_executable(agl-simple-shm agl-simple-shm.cc) + target_include_directories(agl-simple-shm PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src) - target_link_libraries(agl-simple-shm PRIVATE waypp wayland-gen cxxopts::cxxopts) + target_link_libraries(agl-simple-shm PRIVATE waypp wayland-gen cxxopts::cxxopts) - if (IPO_SUPPORT_RESULT) - set_property(TARGET agl-simple-shm PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) - endif () + if (IPO_SUPPORT_RESULT) + set_property(TARGET agl-simple-shm PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) + endif () - add_sanitizers(agl-simple-shm) + add_sanitizers(agl-simple-shm) + endif () endif () diff --git a/examples/agl-simple-shm.cc b/examples/agl-simple-shm.cc index 6819f87..fca165b 100644 --- a/examples/agl-simple-shm.cc +++ b/examples/agl-simple-shm.cc @@ -111,8 +111,6 @@ static void paint_pixels(void *image, int padding, int width, int height, uint32 void draw_frame(void *data, const uint32_t time) { auto window = static_cast(data); - window->prune_old_released_buffers(); - auto buffer = window->next_buffer(); if (!buffer) { spdlog::error("Failed to acquire a buffer"); diff --git a/examples/simple-egl.cc b/examples/simple-egl.cc index 994a9f6..f8b9ca1 100644 --- a/examples/simple-egl.cc +++ b/examples/simple-egl.cc @@ -152,10 +152,12 @@ void initialize_scene(Window *window) { GLint status; glGetProgramiv(program, GL_LINK_STATUS, &status); if (!status) { - char log[1000]; GLsizei len; - glGetProgramInfoLog(program, 1000, &len, log); - fprintf(stderr, "Error: linking:\n%.*s\n", len, log); + auto buf = std::make_unique(1024); + glGetProgramInfoLog(program, 1024, &len, buf.get()); + std::string res{buf.get(), static_cast(len)}; + buf.reset(); + spdlog::error("Error: linking:\n{}", res.c_str()); exit(1); } diff --git a/examples/simple-ext-protocol.cc b/examples/simple-ext-protocol.cc index 4d4327d..58ed833 100644 --- a/examples/simple-ext-protocol.cc +++ b/examples/simple-ext-protocol.cc @@ -64,14 +64,14 @@ void handle_signal(int signal) { static void paint_pixels(void *image, int padding, int width, int height, uint32_t time) { - const int halfh = padding + (height - padding * 2) / 2; - const int halfw = padding + (width - padding * 2) / 2; + const int half_height = padding + (height - padding * 2) / 2; + const int half_width = padding + (width - padding * 2) / 2; int ir, or_; auto *pixel = static_cast(image); int y; /* squared radii thresholds */ - or_ = (halfw < halfh ? halfw : halfh) - 8; + or_ = (half_width < half_height ? half_width : half_height) - 8; ir = or_ - 32; or_ *= or_; ir *= ir; @@ -79,14 +79,14 @@ paint_pixels(void *image, int padding, int width, int height, uint32_t time) { pixel += padding * width; for (y = padding; y < height - padding; y++) { int x; - int y2 = (y - halfh) * (y - halfh); + int y2 = (y - half_height) * (y - half_height); pixel += padding; for (x = padding; x < width - padding; x++) { uint32_t v; /* squared distance from center */ - int r2 = (x - halfw) * (x - halfw) + y2; + int r2 = (x - half_width) * (x - half_width) + y2; if (r2 < ir) v = (static_cast(r2 / 32) + time / 64) * 0x0080401; @@ -110,8 +110,6 @@ paint_pixels(void *image, int padding, int width, int height, uint32_t time) { void draw_frame(void *data, const uint32_t time) { auto window = static_cast(data); - window->prune_old_released_buffers(); - auto buffer = window->next_buffer(); if (!buffer) { spdlog::error("Failed to acquire a buffer"); @@ -126,7 +124,7 @@ void draw_frame(void *data, const uint32_t time) { buffer->set_busy(); } -static void handle_interface1_add(void * /* data */, +static void handle_interface1_add(Registrar * /* data */, struct wl_registry * /* registry */, uint32_t name, const char *interface, @@ -134,37 +132,18 @@ static void handle_interface1_add(void * /* data */, spdlog::info("handle_interface1_add: name: {}, interface: {}, version: {}", name, interface, version); } -static void handle_interface1_remove(void * /* data */, +static void handle_interface1_remove(Registrar * /* data */, struct wl_registry * /* registry */, uint32_t id) { spdlog::info("handle_interface1_remove: id: {}", id); } -static void handle_interface2_add(void * /* data */, - struct wl_registry * /* registry */, - uint32_t name, - const char *interface, - uint32_t version) { - spdlog::info("handle_interface2_add: name: {}, interface: {}, version: {}", name, interface, version); -} - -static void handle_interface2_remove(void * /* data */, - struct wl_registry * /* registry */, - uint32_t id) { - spdlog::info("handle_interface2_remove: id: {}", id); -} - static constexpr -std::array ext_interfaces{{ +std::array ext_interfaces{{ { - "zxdg_output_manager_v1", + "wl_drm", handle_interface1_add, handle_interface1_remove, - }, - { - "wl_drm", - handle_interface2_add, - handle_interface2_remove, } }}; @@ -193,7 +172,7 @@ int main(int argc, char **argv) { .tearing = result["tearing"].as(), }; - XdgWindowManager wm = XdgWindowManager(ext_interfaces.size(), + XdgWindowManager wm = XdgWindowManager(false, ext_interfaces.size(), ext_interfaces.data() ); spdlog::info("XDG Window Manager Version: {}", wm.get_version()); diff --git a/examples/simple-shm.cc b/examples/simple-shm.cc index efb55cb..b0c3fb9 100644 --- a/examples/simple-shm.cc +++ b/examples/simple-shm.cc @@ -110,8 +110,6 @@ static void paint_pixels(void *image, int padding, int width, int height, uint32 void draw_frame(void *data, const uint32_t time) { auto window = static_cast(data); - window->prune_old_released_buffers(); - auto buffer = window->next_buffer(); if (!buffer) { spdlog::error("Failed to acquire a buffer"); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 79692df..5095de9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,20 +18,6 @@ find_package(PkgConfig REQUIRED) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) find_package(OpenGL REQUIRED COMPONENTS EGL) -include(CheckFunctionExists) -check_function_exists(memfd_create HAVE_MEMFD_CREATE) -check_function_exists(posix_fallocate HAVE_POSIX_FALLOCATE) -check_function_exists(mkostemp HAVE_MKOSTEMP) -if (HAVE_MEMFD_CREATE) - add_compile_definitions(HAVE_MEMFD_CREATE) -endif () -if (HAVE_POSIX_FALLOCATE) - add_compile_definitions(HAVE_POSIX_FALLOCATE) -endif () -if (HAVE_MKOSTEMP) - add_compile_definitions(HAVE_MKOSTEMP) -endif () - set(WINDOW_MANAGER_SRC window_manager/output.cc window_manager/registrar.cc @@ -40,9 +26,7 @@ set(WINDOW_MANAGER_SRC ) if (ENABLE_AGL_SHELL_CLIENT) -list(APPEND WINDOW_MANAGER_SRC - window_manager/agl_shell.cc -) + list(APPEND WINDOW_MANAGER_SRC window_manager/agl_shell.cc) endif () set(SEAT_SRC @@ -74,16 +58,13 @@ if (ENABLE_XDG_CLIENT) window_manager/xdg_window_manager.cc) endif () if (ENABLE_AGL_CLIENT) - target_sources(waypp PRIVATE - window_manager/agl_shell.cc) + target_sources(waypp PRIVATE window_manager/agl_shell.cc) endif () if (ENABLE_IVI_SHELL_CLIENT) - target_sources(waypp PRIVATE - window_manager/ivi_window_manager.cc) + target_sources(waypp PRIVATE window_manager/ivi_window_manager.cc) endif () if (ENABLE_DRM_LEASE_CLIENT) - target_sources(waypp PRIVATE - window_manager/drm_lease_device_v1.cc) + target_sources(waypp PRIVATE window_manager/drm_lease_device_v1.cc) endif () target_include_directories(waypp PUBLIC .) diff --git a/src/command.cc b/src/command.cc index bebaff2..726548c 100644 --- a/src/command.cc +++ b/src/command.cc @@ -19,8 +19,8 @@ #include "logging.h" bool Command::Execute(const char *cmd, std::string &result) { - const auto fp = popen(cmd, "r"); - if (fp == nullptr) { + auto fp = popen(cmd, "r"); + if (!fp) { spdlog::error("[ExecuteCommand] Failed to Execute Command: ({}) {}", errno, strerror(errno)); spdlog::error("Failed to Execute Command: {}", cmd); @@ -29,14 +29,15 @@ bool Command::Execute(const char *cmd, std::string &result) { SPDLOG_TRACE("[Command] Execute: {}", cmd); - auto buf = std::make_unique(PATH_MAX); - while (fgets(&buf[0], PATH_MAX, fp) != nullptr) { + auto buf = std::make_unique(1024); + while (fgets(&buf[0], 1024, fp) != nullptr) { result.append(&buf[0]); } + buf.reset(); SPDLOG_TRACE("[Command] Execute Result: [{}] {}", result.size(), result); - const auto status = pclose(fp); + auto status = pclose(fp); if (status == -1) { spdlog::error("[ExecuteCommand] Failed to Close Pipe: ({}) {}", errno, strerror(errno)); diff --git a/src/command.h b/src/command.h index 81b83e6..5894662 100644 --- a/src/command.h +++ b/src/command.h @@ -28,5 +28,5 @@ class Command { * @relation * internal */ - static bool Execute(const char* cmd, std::string &result); + static bool Execute(const char *cmd, std::string &result); }; diff --git a/src/seat/keyboard.cc b/src/seat/keyboard.cc index d82e32a..99bfc09 100644 --- a/src/seat/keyboard.cc +++ b/src/seat/keyboard.cc @@ -62,7 +62,7 @@ Keyboard::~Keyboard() { xkb_state_unref(xkb_state_); } if (xkb_keymap_) { - xkb_keymap_unref(xkb_keymap_);; + xkb_keymap_unref(xkb_keymap_); } if (xkb_context_) { xkb_context_unref(xkb_context_); @@ -87,10 +87,9 @@ void Keyboard::handle_keymap(void *data, char *keymap_string; /// From version 7 onwards, the fd must be mapped with MAP_PRIVATE by the recipient, as MAP_SHARED may fail. - if (wl_keyboard_get_version(wl_keyboard) >= 7 ) { + if (wl_keyboard_get_version(wl_keyboard) >= 7) { keymap_string = static_cast(mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd, 0)); - } - else { + } else { keymap_string = static_cast(mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0)); } xkb_keymap_unref(obj->xkb_keymap_); diff --git a/src/seat/pointer.cc b/src/seat/pointer.cc index b2472f3..99487d3 100644 --- a/src/seat/pointer.cc +++ b/src/seat/pointer.cc @@ -29,7 +29,7 @@ * * The Pointer class is responsible for handling Wayland pointer events and managing the cursor. */ -Pointer::Pointer(wl_pointer *pointer, struct wl_compositor *wl_compositor, const std::optional &wl_shm, +Pointer::Pointer(wl_pointer *pointer, struct wl_compositor *wl_compositor, struct wl_shm *wl_shm, bool disable_cursor, int size) : wl_pointer_(pointer), wl_shm_(wl_shm), disable_cursor_(disable_cursor), size_(size) { SPDLOG_DEBUG("Pointer"); @@ -307,12 +307,12 @@ void Pointer::set_cursor(uint32_t serial, const char *cursor_name, const char *t return; } - if (!wl_shm_.has_value()) { + if (!wl_shm_) { return; } if (!theme_) { - theme_ = wl_cursor_theme_load(theme_name, size_, wl_shm_.value()); + theme_ = wl_cursor_theme_load(theme_name, size_, wl_shm_); if (!theme_) { spdlog::error("[Pointer] unable to load {} theme", theme_name == nullptr ? "default" : theme_name); return; diff --git a/src/seat/pointer.h b/src/seat/pointer.h index f806571..a017e6d 100644 --- a/src/seat/pointer.h +++ b/src/seat/pointer.h @@ -82,7 +82,7 @@ class PointerObserver { class Pointer { public: explicit Pointer(struct wl_pointer *pointer, struct wl_compositor *wl_compositor, - const std::optional &wl_shm, + struct wl_shm *wl_shm, bool disable_cursor, int size = 24); @@ -98,7 +98,7 @@ class Pointer { static std::string get_cursor_theme(); - static std::vector get_available_cursors(const char* theme_name = nullptr); + static std::vector get_available_cursors(const char *theme_name = nullptr); void set_cursor(uint32_t serial, const char *cursor_name = "right_ptr", const char *theme_name = nullptr); @@ -114,7 +114,7 @@ class Pointer { std::list observers_{}; struct wl_surface *wl_surface_cursor_; struct wl_cursor_theme *theme_{}; - const std::optional &wl_shm_; + struct wl_shm *wl_shm_; bool disable_cursor_; int size_; diff --git a/src/seat/seat.cc b/src/seat/seat.cc index e8624aa..f5a8cb2 100644 --- a/src/seat/seat.cc +++ b/src/seat/seat.cc @@ -25,14 +25,14 @@ * The Seat class provides a representation of a seat in a Wayland compositor. It is used to handle input events from * devices such as keyboards, pointers, and touchscreens. */ -Seat::Seat(struct wl_seat *seat, const std::optional &wl_shm, struct wl_compositor *wl_compositor, +Seat::Seat(struct wl_seat *seat, struct wl_shm *wl_shm, struct wl_compositor *wl_compositor, bool disable_cursor) : wl_seat_(seat), wl_shm_(wl_shm), wl_compositor_(wl_compositor), disable_cursor_(disable_cursor) { wl_seat_add_listener(seat, &listener_, this); } Seat::~Seat() { - if(wl_seat_) { + if (wl_seat_) { wl_seat_destroy(wl_seat_); } } diff --git a/src/seat/seat.h b/src/seat/seat.h index eb5851d..6ab04e3 100644 --- a/src/seat/seat.h +++ b/src/seat/seat.h @@ -49,7 +49,7 @@ class SeatObserver { class Seat { public: - explicit Seat(struct wl_seat *seat, const std::optional &wl_shm, + explicit Seat(struct wl_seat *seat, struct wl_shm *wl_shm, struct wl_compositor *wl_compositor, bool disable_cursor = false); ~Seat(); @@ -81,7 +81,7 @@ class Seat { struct wl_seat *wl_seat_; uint32_t capabilities_{}; std::string name_; - const std::optional &wl_shm_; + struct wl_shm *wl_shm_; struct wl_compositor *wl_compositor_; bool disable_cursor_; diff --git a/src/window/anonymous_file.cc b/src/window/anonymous_file.cc index 9e99571..f1b781b 100644 --- a/src/window/anonymous_file.cc +++ b/src/window/anonymous_file.cc @@ -34,9 +34,11 @@ #include #include +#include "wayland-protocols.h" #include "logging.h" #if !defined(HAVE_MKOSTEMP) + int os_fd_set_cloexec(int fd) { int flags; @@ -62,12 +64,13 @@ set_cloexec_or_close(int fd) { } return fd; } + #endif static int create_tmpfile_cloexec(char *tmpname) { int fd; -#if defined(HAVE_MKOSTEMP) +#if HAVE_MKOSTEMP fd = mkostemp(tmpname, O_CLOEXEC); if (fd >= 0) unlink(tmpname); @@ -114,7 +117,7 @@ int AnonymousFile::create(off_t size) { int fd; int ret; -#if defined(HAVE_MEMFD_CREATE) +#if HAVE_MEMFD_CREATE fd = memfd_create("waypp-shared", MFD_CLOEXEC | MFD_ALLOW_SEALING); if (fd >= 0) { /* We can add this seal before calling posix_fallocate(), as @@ -142,7 +145,7 @@ int AnonymousFile::create(off_t size) { return -1; } -#if defined(HAVE_POSIX_FALLOCATE) +#if HAVE_POSIX_FALLOCATE do { ret = posix_fallocate(fd, 0, size); } while (ret == EINTR); diff --git a/src/window/buffer.h b/src/window/buffer.h index c1c30e5..2de0cc8 100644 --- a/src/window/buffer.h +++ b/src/window/buffer.h @@ -22,7 +22,7 @@ class Buffer { public: - Buffer(struct wl_shm *wl_shm); + explicit Buffer(struct wl_shm *wl_shm); ~Buffer(); diff --git a/src/window/egl.cc b/src/window/egl.cc index 605e4b8..a65e7d4 100644 --- a/src/window/egl.cc +++ b/src/window/egl.cc @@ -172,7 +172,7 @@ void Egl::swap_buffers() { } void Egl::get_buffer_age(EGLint &buffer_age) { - if(pfSwapBufferWithDamage_) { + if (pfSwapBufferWithDamage_) { eglQuerySurface(dpy_, egl_surface_, EGL_BUFFER_AGE_EXT, &buffer_age); return; } @@ -180,7 +180,7 @@ void Egl::get_buffer_age(EGLint &buffer_age) { } void Egl::swap_buffers_with_damage(const EGLint *rects, EGLint n_rects) { - if(pfSwapBufferWithDamage_) { + if (pfSwapBufferWithDamage_) { pfSwapBufferWithDamage_(dpy_, egl_surface_, rects, n_rects); } } diff --git a/src/window/feedback.cc b/src/window/feedback.cc index 109d6fc..0744dc2 100644 --- a/src/window/feedback.cc +++ b/src/window/feedback.cc @@ -7,7 +7,7 @@ unsigned Feedback::sequence_ = 0; Feedback::Feedback(struct wp_presentation *wp_presentation, clockid_t clock_id, struct wl_surface *wl_surface, uint32_t time, FeedbackObserver *observer) - : clock_id_(clock_id), observer_(observer) { + : wp_presentation_(wp_presentation), clock_id_(clock_id), observer_(observer) { clock_gettime(clock_id_, &committed_); frame_stamp_ = time; diff --git a/src/window/window.cc b/src/window/window.cc index dde8bf3..4573a25 100644 --- a/src/window/window.cc +++ b/src/window/window.cc @@ -44,7 +44,7 @@ Window::Window(WindowManager *wm, const char *name, int buffer_count, uint32_t b } buffers_.reserve(static_cast(buffer_count)); for (int i = 0; i < buffer_count_; i++) { - auto buffer = std::make_unique(wm_->get_shm().value()); + auto buffer = std::make_unique(wm_->get_shm()); buffer->create_shm_buffer(width, height, buffer_format_); buffers_.push_back(std::move(buffer)); } @@ -62,25 +62,25 @@ Window::Window(WindowManager *wm, const char *name, int buffer_count, uint32_t b egl_->set_swap_interval(swap_interval); } - if (wm->get_viewporter().has_value()) { -#if defined(HAS_WAYLAND_PROTOCOL_VIEWPORTER) - viewport_ = wp_viewporter_get_viewport(wm->get_viewporter().value(), wl_surface_); + if (wm->get_viewporter()) { +#if HAS_WAYLAND_PROTOCOL_VIEWPORTER + viewport_ = wp_viewporter_get_viewport(wm->get_viewporter(), wl_surface_); #endif } - if (wm->get_fractional_scale_manager().has_value()) { -#if defined(HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1) + if (wm->get_fractional_scale_manager()) { +#if HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1 fractional_scale_ = wp_fractional_scale_manager_v1_get_fractional_scale( - wm->get_fractional_scale_manager().value(), + wm->get_fractional_scale_manager(), wl_surface_); wp_fractional_scale_v1_add_listener(fractional_scale_, &fractional_scale_listener_, this); #endif } - if (wm->get_tearing_control_manager().has_value()) { -#if defined(HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1) + if (wm->get_tearing_control_manager()) { +#if HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1 tearing_control_ = wp_tearing_control_manager_v1_get_tearing_control( - wm->get_tearing_control_manager().value(), wl_surface_); + wm->get_tearing_control_manager(), wl_surface_); if (tearing) { SPDLOG_DEBUG("[Surface] Set Presentation Hint: ASYNC"); wp_tearing_control_v1_set_presentation_hint(tearing_control_, @@ -98,12 +98,12 @@ Window::Window(WindowManager *wm, const char *name, int buffer_count, uint32_t b Window::~Window() { if (viewport_) { -#if defined(HAS_WAYLAND_PROTOCOL_VIEWPORTER) +#if HAS_WAYLAND_PROTOCOL_VIEWPORTER wp_viewport_destroy(viewport_); #endif } if (fractional_scale_) { -#if defined(HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1) +#if HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1 wp_fractional_scale_v1_destroy(fractional_scale_); #endif } @@ -220,7 +220,7 @@ void Window::update_buffer_geometry() { void Window::handle_preferred_scale(void *data, struct wp_fractional_scale_v1 *wp_fractional_scale_v1, uint32_t scale) { - SPDLOG_DEBUG("[Window] handle_preferred_scale()"); + SPDLOG_TRACE("[Window] handle_preferred_scale()"); auto *w = static_cast(data); if (w->fractional_scale_ != wp_fractional_scale_v1) { return; @@ -232,25 +232,23 @@ void Window::handle_preferred_scale(void *data, void Window::handle_surface_enter(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output) { - SPDLOG_DEBUG("[Window] handle_surface_enter()"); auto obj = static_cast(data); if (obj->wl_surface_ != wl_surface) { return; } - SPDLOG_DEBUG("handle_surface_enter: {} [{}]", fmt::ptr(wl_output), obj->name_); + SPDLOG_TRACE("handle_surface_enter: {} [{}]", fmt::ptr(wl_output), obj->name_); obj->wl_output_ = wl_output; } void Window::handle_surface_leave(void *data, struct wl_surface *wl_surface, struct wl_output *output) { - SPDLOG_DEBUG("[Window] handle_surface_leave()"); auto obj = static_cast(data); if (obj->wl_surface_ != wl_surface) { return; } #if !defined(NDEBUG) - SPDLOG_DEBUG("handle_surface_leave: {} [{}]", fmt::ptr(output), obj->name_); + SPDLOG_TRACE("handle_surface_leave: {} [{}]", fmt::ptr(output), obj->name_); #else (void)output; #endif @@ -265,7 +263,7 @@ void Window::handle_surface_leave(void *data, * @note This function assumes that the surface has been initialized properly. */ void Window::start_frame_callbacks() { - SPDLOG_DEBUG("[Window] start_frame_callbacks"); + SPDLOG_TRACE("[Window] start_frame_callbacks"); handle_frame_callback(this, nullptr, 0); } @@ -274,7 +272,7 @@ void Window::start_frame_callbacks() { * This function is intended to be called from outside the Window class. */ void Window::stop_frame_callbacks() { - SPDLOG_DEBUG("[Window] stop_frame_callbacks"); + SPDLOG_TRACE("[Window] stop_frame_callbacks"); if (wl_callback_) { wl_callback_destroy(wl_callback_); wl_callback_ = nullptr; @@ -408,21 +406,6 @@ Buffer *Window::pick_free_buffer() { return res; } -void Window::prune_old_released_buffers() { -#if 0 - long i = 0; - for (auto &b: buffers_) { - if (!b->is_busy() && - b->get_width() != window_size_.width || - b->get_height() != window_size_.height) { - b.reset(); - buffers_.erase(buffers_.begin() + i); - } - i++; - } -#endif -} - Buffer *Window::next_buffer() { auto buffer = pick_free_buffer(); diff --git a/src/window/window.h b/src/window/window.h index aa7839d..261f38b 100644 --- a/src/window/window.h +++ b/src/window/window.h @@ -112,8 +112,6 @@ class Window { Buffer *pick_free_buffer(); - void prune_old_released_buffers(); - [[nodiscard]] size_t get_num_buffers() const { return buffers_.size(); } [[nodiscard]] const std::vector> &get_buffers() const { return buffers_; } @@ -222,11 +220,11 @@ class Window { static constexpr struct wl_surface_listener surface_listener_ = { .enter = handle_surface_enter, .leave = handle_surface_leave -#if defined(WL_SURFACE_PREFERRED_BUFFER_SCALE_SINCE_VERSION) +#if WL_SURFACE_PREFERRED_BUFFER_SCALE_SINCE_VERSION , .preferred_buffer_scale = handle_preferred_buffer_scale #endif -#if defined(WL_SURFACE_PREFERRED_BUFFER_TRANSFORM_SINCE_VERSION) +#if WL_SURFACE_PREFERRED_BUFFER_TRANSFORM_SINCE_VERSION , .preferred_buffer_transform = handle_preferred_buffer_transform, #endif @@ -240,7 +238,7 @@ class Window { struct wp_fractional_scale_v1 *wp_fractional_scale_v1, uint32_t scale); -#if defined(HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1) +#if HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1 static constexpr struct wp_fractional_scale_v1_listener fractional_scale_listener_ = { .preferred_scale = handle_preferred_scale, }; diff --git a/src/window/xdg_toplevel.cc b/src/window/xdg_toplevel.cc index 5e4eca8..8d95c0e 100644 --- a/src/window/xdg_toplevel.cc +++ b/src/window/xdg_toplevel.cc @@ -37,7 +37,7 @@ XdgTopLevel::XdgTopLevel(WindowManager *wm, const char *title, const char *app_i app_id_(app_id) { auto xwm = reinterpret_cast(wm_); auto xdg_wm_base = xwm->get_xdg_wm_base(); - if (!xdg_wm_base.has_value()) { + if (!xdg_wm_base) { spdlog::critical("xdg_wm_base is not available"); exit(EXIT_FAILURE); } @@ -45,7 +45,7 @@ XdgTopLevel::XdgTopLevel(WindowManager *wm, const char *title, const char *app_i window_size_.width = width; window_size_.height = height; - xdg_surface_ = xdg_wm_base_get_xdg_surface(xdg_wm_base.value(), wl_surface_); + xdg_surface_ = xdg_wm_base_get_xdg_surface(xdg_wm_base, wl_surface_); xdg_surface_add_listener(xdg_surface_, &xdg_surface_listener_, this); xdg_toplevel_ = xdg_surface_get_toplevel(xdg_surface_); @@ -206,7 +206,7 @@ void XdgTopLevel::handle_xdg_toplevel_close( * @param width * @param height */ -#if defined(XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION) +#if XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION void XdgTopLevel::handle_xdg_toplevel_configure_bounds(void *data, struct xdg_toplevel *xdg_toplevel, @@ -229,7 +229,7 @@ void XdgTopLevel::handle_xdg_toplevel_configure_bounds(void *data, * @param xdg_toplevel * @param capabilities */ -#if defined(XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION) +#if XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION void XdgTopLevel::handle_xdg_toplevel_wm_capabilities(void *data, struct xdg_toplevel *xdg_toplevel, diff --git a/src/window/xdg_toplevel.h b/src/window/xdg_toplevel.h index 59b8281..e1145cc 100644 --- a/src/window/xdg_toplevel.h +++ b/src/window/xdg_toplevel.h @@ -55,7 +55,7 @@ class XdgTopLevel : public Window { void set_title(const char *title) { xdg_toplevel_set_title(xdg_toplevel_, title); } - struct wl_surface* get_surface() const { return wl_surface_; } + struct wl_surface *get_surface() const { return wl_surface_; } [[nodiscard]] bool get_fullscreen() const { return fullscreen_; } @@ -113,7 +113,7 @@ class XdgTopLevel : public Window { void *data, struct xdg_toplevel *xdg_toplevel); -#if defined(XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION) +#if XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION static void handle_xdg_toplevel_configure_bounds(void *data, struct xdg_toplevel *xdg_toplevel, @@ -121,7 +121,7 @@ class XdgTopLevel : public Window { int32_t height); #endif -#if defined(XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION) +#if XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION static void handle_xdg_toplevel_wm_capabilities(void *data, struct xdg_toplevel *xdg_toplevel, @@ -132,11 +132,11 @@ class XdgTopLevel : public Window { static constexpr struct xdg_toplevel_listener xdg_toplevel_listener_ = { .configure = handle_xdg_toplevel_configure, .close = handle_xdg_toplevel_close -#if defined(XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION) +#if XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION , .configure_bounds = handle_xdg_toplevel_configure_bounds #endif -#if defined(XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION) +#if XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION , .wm_capabilities = handle_xdg_toplevel_wm_capabilities #endif diff --git a/src/window_manager/agl_shell.cc b/src/window_manager/agl_shell.cc index 7930aa1..f7c1e80 100644 --- a/src/window_manager/agl_shell.cc +++ b/src/window_manager/agl_shell.cc @@ -36,12 +36,11 @@ AglShell::AglShell(bool disable_cursor, unsigned long ext_interface_count, display_name), wait_for_bound_(true), bound_ok_(false) { - auto agl_shell = get_agl_shell(); - if (!agl_shell.has_value()) { + agl_shell_ = get_agl_shell(); + if (!agl_shell_) { spdlog::critical("{} is required.", agl_shell_interface.name); exit(EXIT_FAILURE); } - agl_shell_ = agl_shell.value(); agl_shell_add_listener(agl_shell_, &agl_shell_listener_, this); @@ -74,7 +73,7 @@ void AglShell::handle_bound_ok(void *data, } struct wl_output *AglShell::find_output_by_name(const std::string &output_name) { - for (auto &it: output_.outputs) { + for (auto &it: get_outputs()) { if (it.second->get_name() == output_name) { return it.first; } diff --git a/src/window_manager/output.cc b/src/window_manager/output.cc index 4783987..8dd2cd0 100644 --- a/src/window_manager/output.cc +++ b/src/window_manager/output.cc @@ -169,10 +169,11 @@ std::string Output::transform_to_string(enum wl_output_transform transform) { void Output::print() { spdlog::info("Output"); -#if defined(WL_OUTPUT_NAME_SINCE_VERSION) + spdlog::info("\tDone: {}", output_.done); +#if WL_OUTPUT_NAME_SINCE_VERSION spdlog::info("\tName: {}", output_.name); #endif -#if defined(WL_OUTPUT_DESCRIPTION_SINCE_VERSION) +#if WL_OUTPUT_DESCRIPTION_SINCE_VERSION spdlog::info("\tDescription: {}", output_.description); #endif spdlog::info("\tMode"); @@ -192,7 +193,7 @@ void Output::print() { spdlog::info("\t\tSubpixel: {}", output_.geometry.subpixel); spdlog::info("\t\tTransform: {}", transform_to_string(output_.geometry.transform)); spdlog::info("\t\tx: {}, y: {}", output_.geometry.x, output_.geometry.y); -#if defined(WL_OUTPUT_SCALE_SINCE_VERSION) +#if WL_OUTPUT_SCALE_SINCE_VERSION spdlog::info("\tScaling factor: {}", output_.factor); #endif } diff --git a/src/window_manager/output.h b/src/window_manager/output.h index 3e6273f..db665f5 100644 --- a/src/window_manager/output.h +++ b/src/window_manager/output.h @@ -119,15 +119,15 @@ class Output { handle_geometry, handle_mode, handle_done -#if defined(WL_OUTPUT_SCALE_SINCE_VERSION) +#if WL_OUTPUT_SCALE_SINCE_VERSION , handle_scale #endif -#if defined(WL_OUTPUT_NAME_SINCE_VERSION) +#if WL_OUTPUT_NAME_SINCE_VERSION , handle_name #endif -#if defined(WL_OUTPUT_DESCRIPTION_SINCE_VERSION) +#if WL_OUTPUT_DESCRIPTION_SINCE_VERSION , handle_desc #endif diff --git a/src/window_manager/registrar.cc b/src/window_manager/registrar.cc index fdc3fcb..5825815 100644 --- a/src/window_manager/registrar.cc +++ b/src/window_manager/registrar.cc @@ -39,44 +39,44 @@ Registrar::Registrar(struct wl_display *wl_display, {wl_shm_interface.name, handle_interface_shm}, {wl_seat_interface.name, handle_interface_seat}, {wl_output_interface.name, handle_interface_output} -#if defined(ENABLE_XDG_CLIENT) +#if ENABLE_XDG_CLIENT , {xdg_wm_base_interface.name, handle_interface_xdg_wm_base} #endif -#if defined(ENABLE_AGL_SHELL_CLIENT) +#if ENABLE_AGL_SHELL_CLIENT , {agl_shell_interface.name, handle_interface_agl_shell} #endif -#if defined(ENABLE_IVI_SHELL_CLIENT) +#if ENABLE_IVI_SHELL_CLIENT , {ivi_wm_interface.name, handle_interface_ivi_wm} #endif -#if defined(ENABLE_DRM_LEASE_CLIENT) +#if ENABLE_DRM_LEASE_CLIENT . {wp_drm_lease_device_v1_interface.name, handle_interface_drm_lease_device_v1} #endif -#if defined(HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1) +#if HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1 , {zxdg_decoration_manager_v1_interface.name, handle_interface_zxdg_decoration}, {zxdg_toplevel_decoration_v1_interface.name, handle_interface_zxdg_toplevel_decoration} #endif -#if defined(HAS_WAYLAND_PROTOCOL_PRESENTATION_TIME) +#if HAS_WAYLAND_PROTOCOL_PRESENTATION_TIME , {wp_presentation_interface.name, handle_interface_presentation} #endif -#if defined(HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1) +#if HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1 , {wp_tearing_control_manager_v1_interface.name, handle_interface_tearing_control_manager} #endif -#if defined(HAS_WAYLAND_PROTOCOL_VIEWPORTER) +#if HAS_WAYLAND_PROTOCOL_VIEWPORTER , {wp_viewporter_interface.name, handle_interface_viewporter} #endif -#if defined(HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1) +#if HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1 , {wp_fractional_scale_manager_v1_interface.name, handle_interface_fractional_scale_manager} #endif -#if defined(HAS_WAYLAND_PROTOCOL_XDG_OUTPUT_UNSTABLE_V1) +#if HAS_WAYLAND_PROTOCOL_XDG_OUTPUT_UNSTABLE_V1 , {zxdg_output_manager_v1_interface.name, handle_interface_xdg_output_unstable_v1} #endif @@ -97,31 +97,31 @@ Registrar::Registrar(struct wl_display *wl_display, Registrar::~Registrar() { SPDLOG_TRACE("++Registrar::~Registrar()"); - output_.outputs.clear(); - seat_.seats.clear(); + outputs_.clear(); + seats_.clear(); - if (shm_.wl_shm.has_value()) { - wl_shm_destroy(shm_.wl_shm.value()); - shm_.formats.clear(); + if (wl_shm_) { + wl_shm_destroy(wl_shm_); + wl_shm_formats_.clear(); } - if (compositor_.wl_compositor) { - wl_compositor_destroy(compositor_.wl_compositor); + if (wl_compositor_) { + wl_compositor_destroy(wl_compositor_); } - if (sub_compositor_.wl_subcompositor.has_value()) { - wl_subcompositor_destroy(sub_compositor_.wl_subcompositor.value()); + if (wl_subcompositor_) { + wl_subcompositor_destroy(wl_subcompositor_); } -#if defined(ENABLE_AGL_SHELL_CLIENT) - if (agl_shell_.agl_shell.has_value()) { - agl_shell_destroy(agl_shell_.agl_shell.value()); +#if ENABLE_AGL_SHELL_CLIENT + if (agl_shell_) { + agl_shell_destroy(agl_shell_); } #endif -#if defined(ENABLE_XDG_CLIENT) - if (xdg_wm_base_.xdg_wm_base.has_value()) { - xdg_wm_base_destroy(xdg_wm_base_.xdg_wm_base.value()); +#if ENABLE_XDG_CLIENT + if (xdg_wm_base_) { + xdg_wm_base_destroy(xdg_wm_base_); } #endif @@ -129,33 +129,33 @@ Registrar::~Registrar() { wp_presentation_destroy(presentation_time_.wp_presentation); } -#if defined(HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1) - if (xdg_decoration_manager_.zxdg_toplevel_decoration_v1.has_value()) { - zxdg_toplevel_decoration_v1_destroy(xdg_decoration_manager_.zxdg_toplevel_decoration_v1.value()); +#if HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1 + if (zxdg_toplevel_decoration_v1_) { + zxdg_toplevel_decoration_v1_destroy(zxdg_toplevel_decoration_v1_); } #endif -#if defined(HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1) - if (xdg_decoration_manager_.zxdg_decoration_manager_v1.has_value()) { - zxdg_decoration_manager_v1_destroy(xdg_decoration_manager_.zxdg_decoration_manager_v1.value()); +#if HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1 + if (zxdg_decoration_manager_v1_) { + zxdg_decoration_manager_v1_destroy(zxdg_decoration_manager_v1_); } #endif -#if defined(HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1) - if (tearing_manager_.wp_tearing_control_manager.has_value()) { - wp_tearing_control_manager_v1_destroy(tearing_manager_.wp_tearing_control_manager.value()); +#if HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1 + if (wp_tearing_control_manager_) { + wp_tearing_control_manager_v1_destroy(wp_tearing_control_manager_); } #endif -#if defined(HAS_WAYLAND_PROTOCOL_VIEWPORTER) - if (viewporter_.wp_viewporter.has_value()) { - wp_viewporter_destroy(viewporter_.wp_viewporter.value()); +#if HAS_WAYLAND_PROTOCOL_VIEWPORTER + if (wp_viewporter_) { + wp_viewporter_destroy(wp_viewporter_); } #endif -#if defined(HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1) - if (fractional_scale_manager_.fractional_scale_manager.has_value()) { - wp_fractional_scale_manager_v1_destroy(fractional_scale_manager_.fractional_scale_manager.value()); +#if HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1 + if (fractional_scale_manager_) { + wp_fractional_scale_manager_v1_destroy(fractional_scale_manager_); } #endif @@ -171,11 +171,11 @@ void Registrar::registry_handle_global(void *data, const char *interface, uint32_t version) { SPDLOG_TRACE("++Registrar::registry_handle_global()\t\n\t{}: {}", interface, version); - auto r = static_cast(data); - auto found = (*r->registrar_global_).find(interface); - if (found != (*r->registrar_global_).end()) { + auto registrar = static_cast(data); + auto found = (*registrar->registrar_global_).find(interface); + if (found != (*registrar->registrar_global_).end()) { // Execute the process function for the found interface. - found->second(data, registry, name, interface, version); + found->second(registrar, registry, name, interface, version); } SPDLOG_TRACE("--Registrar::registry_handle_global()"); } @@ -184,17 +184,17 @@ void Registrar::registry_handle_global_remove(void *data, struct wl_registry *reg, uint32_t id) { SPDLOG_TRACE("++Registrar::registry_handle_global_remove()"); - auto r = static_cast(data); + auto registrar = static_cast(data); - auto found = (*r->registrar_global_remove_).find(id); - if (found != (*r->registrar_global_remove_).end()) { - found->second(data, reg, id); // Execute the process function for the found interface. + auto found = (*registrar->registrar_global_remove_).find(id); + if (found != (*registrar->registrar_global_remove_).end()) { + found->second(registrar, reg, id); // Execute the process function for the found interface. } SPDLOG_TRACE("--Registrar::registry_handle_global_remove()"); } enum wl_output_transform Registrar::get_output_buffer_transform(struct wl_output *wl_output) { - for (auto &output: output_.outputs) { + for (auto &output: outputs_) { if (wl_output == output.first) { output.second->print(); return output.second->get_transform(); @@ -206,7 +206,7 @@ enum wl_output_transform Registrar::get_output_buffer_transform(struct wl_output int32_t Registrar::get_output_buffer_scale(struct wl_output *wl_output) { int32_t scale = 1; - for (auto &output: output_.outputs) { + for (auto &output: outputs_) { if (wl_output == output.first) { scale = output.second->get_scale_factor(); break; @@ -218,10 +218,10 @@ int32_t Registrar::get_output_buffer_scale(struct wl_output *wl_output) { void Registrar::shm_format(void *data, struct wl_shm *wl_shm, uint32_t format) { SPDLOG_TRACE("++Registrar::shm_format()"); auto obj = static_cast(data); - if (obj->shm_.wl_shm != wl_shm) { + if (obj->wl_shm_ != wl_shm) { return; } - obj->shm_.formats.push_back(format); + obj->wl_shm_formats_.push_back(format); SPDLOG_TRACE("--Registrar::shm_format()"); } @@ -447,159 +447,149 @@ const char *Registrar::shm_format_to_text(enum wl_shm_format format) { return "UNKNOWN"; } -void Registrar::handle_interface_compositor(void *data, +void Registrar::handle_interface_compositor(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - auto r = static_cast(data); - r->compositor_.wl_compositor = static_cast( + r->wl_compositor_ = static_cast( wl_registry_bind(registry, name, &wl_compositor_interface, - std::min(static_cast(r->compositor_.min_version), version))); - spdlog::debug("{}: {}", interface, wl_compositor_get_version(r->compositor_.wl_compositor)); + std::min(static_cast(kWlCompositorMinVersion), version))); + spdlog::debug("{}: {}", interface, wl_compositor_get_version(r->wl_compositor_)); } -void Registrar::handle_interface_subcompositor(void *data, +void Registrar::handle_interface_subcompositor(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - auto r = static_cast(data); - r->sub_compositor_.wl_subcompositor = static_cast( + r->wl_subcompositor_ = static_cast( wl_registry_bind(registry, name, &wl_subcompositor_interface, - std::min(static_cast(r->sub_compositor_.min_version), version))); - spdlog::debug("{}: {}", interface, wl_subcompositor_get_version(r->sub_compositor_.wl_subcompositor.value())); + std::min(kWlSubcompositorMinVersion, version))); + spdlog::debug("{}: {}", interface, wl_subcompositor_get_version(r->wl_subcompositor_)); } -void Registrar::handle_interface_shm(void *data, +void Registrar::handle_interface_shm(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - auto r = static_cast(data); - r->shm_.wl_shm = static_cast( + r->wl_shm_ = static_cast( wl_registry_bind(registry, name, &wl_shm_interface, - std::min(static_cast(r->shm_.min_version), version))); - wl_shm_add_listener(r->shm_.wl_shm.value(), &shm_listener_, r); - spdlog::debug("{}: {}", interface, wl_shm_get_version(r->shm_.wl_shm.value())); + std::min(kWlShmMinVersion, version))); + wl_shm_add_listener(r->wl_shm_, &shm_listener_, r); + spdlog::debug("{}: {}", interface, wl_shm_get_version(r->wl_shm_)); } -void Registrar::handle_interface_seat(void *data, +void Registrar::handle_interface_seat(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - auto r = static_cast(data); auto wl_seat = static_cast( wl_registry_bind(registry, name, &wl_seat_interface, - std::min(static_cast(r->seat_.min_version), version))); - r->seat_.seats[wl_seat] = std::make_unique(wl_seat, r->get_shm(), r->get_compositor(), r->disable_cursor_); + std::min(kWlSeatMinVersion, version))); + r->seats_[wl_seat] = std::make_unique(wl_seat, r->get_shm(), r->get_compositor(), r->disable_cursor_); spdlog::debug("{}: {}", interface, wl_seat_get_version(wl_seat)); } -void Registrar::handle_interface_output(void *data, +void Registrar::handle_interface_output(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - auto r = static_cast(data); auto wl_output = static_cast( wl_registry_bind(registry, name, &wl_output_interface, - std::min(static_cast(r->output_.min_version), version))); - r->output_.outputs[wl_output] = std::make_unique(wl_output, r->zxdg_output_manager_v1_); + std::min(kWlOutputMinVersion, version))); + r->outputs_[wl_output] = std::make_unique(wl_output, r->zxdg_output_manager_v1_); spdlog::debug("{}: {}", interface, wl_output_get_version(wl_output)); } -#if defined(ENABLE_XDG_CLIENT) +#if ENABLE_XDG_CLIENT -void Registrar::handle_interface_xdg_wm_base(void *data, +void Registrar::handle_interface_xdg_wm_base(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - auto r = static_cast(data); - r->xdg_wm_base_.xdg_wm_base = static_cast( + r->xdg_wm_base_ = static_cast( wl_registry_bind(registry, name, &xdg_wm_base_interface, - std::min(static_cast(r->xdg_wm_base_.min_version), version))); - spdlog::debug("{}: {}", interface, xdg_wm_base_get_version(r->xdg_wm_base_.xdg_wm_base.value())); + std::min(kXdgWmBaseMinVersion, version))); + spdlog::debug("{}: {}", interface, xdg_wm_base_get_version(r->xdg_wm_base_)); } #endif -#if defined(ENABLE_AGL_SHELL_CLIENT) +#if ENABLE_AGL_SHELL_CLIENT -void Registrar::handle_interface_agl_shell(void *data, +void Registrar::handle_interface_agl_shell(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - auto r = static_cast(data); - r->agl_shell_.agl_shell = static_cast( - wl_registry_bind(registry, name, &agl_shell_interface, - std::min(static_cast(r->agl_shell_.min_version), version))); - spdlog::debug("{}: {}", interface, agl_shell_get_version(r->agl_shell_.agl_shell.value())); + r->agl_shell_ = static_cast(wl_registry_bind(registry, name, &agl_shell_interface, + std::min(kAglShellMinVersion, version))); + spdlog::debug("{}: {}", interface, agl_shell_get_version(r->agl_shell_)); } #endif -#if defined(ENABLE_IVI_SHELL_CLIENT) -void Registrar::handle_interface_ivi_wm(void *data, +#if ENABLE_IVI_SHELL_CLIENT +void Registrar::handle_interface_ivi_wm(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - auto r = static_cast(data); r->ivi_wm_.ivi_wm = static_cast( wl_registry_bind(registry, name, &ivi_wm_interface, - std::min(static_cast(r->ivi_wm_.min_version), version))); + std::min(kIviWmMinVersion, version))); spdlog::debug("{}: {}", interface, ivi_wm_get_version(r->ivi_wm_.ivi_wm.value())); } #endif -#if defined(HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1) -void Registrar::handle_interface_zxdg_decoration(void *data, +#if HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1 + +void Registrar::handle_interface_zxdg_decoration(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - auto r = static_cast(data); - r->xdg_decoration_manager_.zxdg_decoration_manager_v1 = static_cast( + r->zxdg_decoration_manager_v1_ = static_cast( wl_registry_bind(registry, name, &zxdg_decoration_manager_v1_interface, - std::min(static_cast(r->xdg_decoration_manager_.min_version), - version))); + std::min(kXdgDecorationManagerMinVersion, version))); spdlog::debug("{}: {}", interface, zxdg_decoration_manager_v1_get_version( - r->xdg_decoration_manager_.zxdg_decoration_manager_v1.value())); + r->zxdg_decoration_manager_v1_)); } -void Registrar::handle_interface_zxdg_toplevel_decoration(void *data, +void Registrar::handle_interface_zxdg_toplevel_decoration(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - auto r = static_cast(data); - r->xdg_decoration_manager_.zxdg_toplevel_decoration_v1 = static_cast( + r->zxdg_toplevel_decoration_v1_ = static_cast( wl_registry_bind(registry, name, &zxdg_toplevel_decoration_v1_interface, - std::min(static_cast(r->xdg_decoration_manager_.min_version), - version))); + std::min(kXdgDecorationManagerMinVersion, version))); spdlog::debug("{}: {}", interface, zxdg_toplevel_decoration_v1_get_version( - r->xdg_decoration_manager_.zxdg_toplevel_decoration_v1.value())); + r->zxdg_toplevel_decoration_v1_)); } + #endif -#if defined(HAS_WAYLAND_PROTOCOL_XDG_OUTPUT_UNSTABLE_V1) -void Registrar::handle_interface_xdg_output_unstable_v1(void *data, - struct wl_registry *registry, - uint32_t name, - const char *interface, - uint32_t version) { - auto r = static_cast(data); +#if HAS_WAYLAND_PROTOCOL_XDG_OUTPUT_UNSTABLE_V1 + +void Registrar::handle_interface_xdg_output_unstable_v1(Registrar *r, + struct wl_registry *registry, + uint32_t name, + const char *interface, + uint32_t version) { r->zxdg_output_manager_v1_ = static_cast( wl_registry_bind(registry, name, &zxdg_output_manager_v1_interface, std::min(kXdgOutputManagerMinVersion, version))); spdlog::debug("{}: {}", interface, zxdg_output_manager_v1_get_version( r->zxdg_output_manager_v1_)); } + #endif void Registrar::handle_presentation_clock_id(void *data, @@ -612,94 +602,90 @@ void Registrar::handle_presentation_clock_id(void *data, r->presentation_time_.clk_id = static_cast(clk_id); } -void Registrar::handle_interface_presentation(void *data, +void Registrar::handle_interface_presentation(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - auto r = static_cast(data); r->presentation_time_.wp_presentation = static_cast( wl_registry_bind(registry, name, &wp_presentation_interface, - std::min(static_cast(r->presentation_time_.min_version), version))); - wp_presentation_add_listener(r->presentation_time_.wp_presentation, &presentation_listener_, data); + std::min(kPresentationTimeMinVersion, version))); + wp_presentation_add_listener(r->presentation_time_.wp_presentation, &presentation_listener_, r); spdlog::debug("{}: {}", interface, wp_presentation_get_version(r->presentation_time_.wp_presentation)); } std::optional Registrar::get_seat(wl_seat *seat) const { if (seat) { - auto it = seat_.seats.find(seat); - if (it != seat_.seats.end()) { + auto it = seats_.find(seat); + if (it != seats_.end()) { return it->second.get(); } } else { /// If seat is nullptr, return first available - for (auto const &it: seat_.seats) { + for (auto const &it: seats_) { return it.second.get(); } } return {}; } -#if defined(HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1) -void Registrar::handle_interface_tearing_control_manager(void *data, +#if HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1 + +void Registrar::handle_interface_tearing_control_manager(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - auto r = static_cast(data); - r->tearing_manager_.wp_tearing_control_manager = static_cast( + r->wp_tearing_control_manager_ = static_cast( wl_registry_bind(registry, name, &wp_tearing_control_manager_v1_interface, - std::min(static_cast(r->tearing_manager_.min_version), - version))); + std::min(kTearingControlManagerMinVersion, version))); spdlog::debug("{}: {}", interface, wp_tearing_control_manager_v1_get_version( - r->tearing_manager_.wp_tearing_control_manager.value())); + r->wp_tearing_control_manager_)); } + #endif -#if defined(HAS_WAYLAND_PROTOCOL_VIEWPORTER) -void Registrar::handle_interface_viewporter(void *data, +#if HAS_WAYLAND_PROTOCOL_VIEWPORTER + +void Registrar::handle_interface_viewporter(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - auto r = static_cast(data); - r->viewporter_.wp_viewporter = static_cast( + r->wp_viewporter_ = static_cast( wl_registry_bind(registry, name, &wp_viewporter_interface, - std::min(static_cast(r->viewporter_.min_version), version))); - spdlog::debug("{}: {}", interface, wp_viewporter_get_version(r->viewporter_.wp_viewporter.value())); + std::min(kViewporterMinVersion, version))); + spdlog::debug("{}: {}", interface, wp_viewporter_get_version(r->wp_viewporter_)); } + #endif -#if defined(HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1) -void Registrar::handle_interface_fractional_scale_manager(void *data, +#if HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1 + +void Registrar::handle_interface_fractional_scale_manager(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - auto r = static_cast(data); - r->fractional_scale_manager_.fractional_scale_manager = static_cast( + r->fractional_scale_manager_ = static_cast( wl_registry_bind(registry, name, &wp_fractional_scale_manager_v1_interface, - std::min(static_cast(r->fractional_scale_manager_.min_version), - version))); + std::min(kFractionalScaleManagerMinVersion, version))); spdlog::debug("{}: {}", interface, wp_fractional_scale_manager_v1_get_version( - r->fractional_scale_manager_.fractional_scale_manager.value())); + r->fractional_scale_manager_)); } -#endif -#if defined(ENABLE_DRM_LEASE_CLIENT) +#endif -void Registrar::handle_interface_drm_lease_device_v1(void *data, +#if ENABLE_DRM_LEASE_CLIENT +void Registrar::handle_interface_drm_lease_device_v1(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - auto r = static_cast(data); auto wp_drm_lease_device_v1 = static_cast( - wl_registry_bind(registry, name, &wp_drm_lease_device_v1_interface, - std::min(static_cast(r->drm_lease_device_v1_.min_version), version))); - r->drm_lease_device_v1_.drm_lease_device_v1 = std::make_unique(wp_drm_lease_device_v1); + wl_registry_bind(registry, name, &wp_drm_lease_device_v1_interface, std::min(kDrmLeaseDeviceV1MinVersion, version))); + r->drm_lease_device_v1_ = std::make_unique(wp_drm_lease_device_v1); spdlog::debug("{}: {}", interface, wp_drm_lease_device_v1_get_version(wp_drm_lease_device_v1)); } - #endif diff --git a/src/window_manager/registrar.h b/src/window_manager/registrar.h index f0914dd..620b097 100644 --- a/src/window_manager/registrar.h +++ b/src/window_manager/registrar.h @@ -29,7 +29,7 @@ #include "wayland-protocols.h" #include "seat/seat.h" -#if defined(ENABLE_DRM_LEASE_CLIENT) +#if ENABLE_DRM_LEASE_CLIENT #include "drm_lease_device_v1.h" #endif @@ -38,14 +38,14 @@ class WindowManager; class Registrar { public: typedef void (*RegistrarGlobalCallback)( - void *data, + Registrar *registrar, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); typedef void (*RegistrarGlobalRemoveCallback)( - void *data, + Registrar *registrar, struct wl_registry *registry, uint32_t id); @@ -64,10 +64,10 @@ class Registrar { // Returns if shared memory has a specific format. [[nodiscard]] std::optional shm_has_format(enum wl_shm_format format) const { - if (!shm_.wl_shm.has_value()) { + if (!wl_shm_) { return {}; } - if (std::find(shm_.formats.begin(), shm_.formats.end(), format) != shm_.formats.end()) { + if (std::find(wl_shm_formats_.begin(), wl_shm_formats_.end(), format) != wl_shm_formats_.end()) { return true; } return false; @@ -80,43 +80,39 @@ class Registrar { [[nodiscard]] struct wl_registry *get_registry() const { return wl_registry_; } // Returns the compositor. - [[nodiscard]] struct wl_compositor *get_compositor() const { return compositor_.wl_compositor; } + [[nodiscard]] struct wl_compositor *get_compositor() const { return wl_compositor_; } // Returns the subcompositor if available. - [[nodiscard]] std::optional - get_subcompositor() const { return sub_compositor_.wl_subcompositor; } + [[nodiscard]] struct wl_subcompositor *get_subcompositor() const { return wl_subcompositor_; } // Returns the shm if it exists. - [[nodiscard]] const std::optional &get_shm() const { return shm_.wl_shm; } + [[nodiscard]] struct wl_shm *get_shm() const { return wl_shm_; } // Returns the xdg surface manager base if it exists. - [[nodiscard]] std::optional get_xdg_wm_base() const { return xdg_wm_base_.xdg_wm_base; } + [[nodiscard]] struct xdg_wm_base *get_xdg_wm_base() const { return xdg_wm_base_; } // Returns the AGL Shell if it exists. - [[nodiscard]] std::optional get_agl_shell() const { return agl_shell_.agl_shell; } + [[nodiscard]] struct agl_shell *get_agl_shell() const { return agl_shell_; } // Returns the ivi surface manager if it exists. - [[nodiscard]] std::optional get_ivi_wm() const { return ivi_wm_.ivi_wm; } + [[nodiscard]] struct ivi_wm *get_ivi_wm() const { return ivi_wm_; } [[nodiscard]] struct wp_presentation * get_presentation_time_wp_presentation() const { return presentation_time_.wp_presentation; } [[nodiscard]] clockid_t get_presentation_time_clk_id() const { return presentation_time_.clk_id; } - [[nodiscard]] std::optional - get_tearing_control_manager() const { return tearing_manager_.wp_tearing_control_manager; } + [[nodiscard]] struct wp_tearing_control_manager_v1 * + get_tearing_control_manager() const { return wp_tearing_control_manager_; } - [[nodiscard]] std::optional - get_viewporter() const { return viewporter_.wp_viewporter; } + [[nodiscard]] struct wp_viewporter *get_viewporter() const { return wp_viewporter_; } - [[nodiscard]] std::optional - get_fractional_scale_manager() const { return fractional_scale_manager_.fractional_scale_manager; } + [[nodiscard]] struct wp_fractional_scale_manager_v1 * + get_fractional_scale_manager() const { return fractional_scale_manager_; } - [[nodiscard]] std::optional - get_xdg_output_manager() const { return zxdg_output_manager_v1_; } + [[nodiscard]] struct zxdg_output_manager_v1 *get_xdg_output_manager() const { return zxdg_output_manager_v1_; } - [[nodiscard]] const std::map> & - get_outputs() const { return output_.outputs; } + [[nodiscard]] const std::map> &get_outputs() const { return outputs_; } enum wl_output_transform get_output_buffer_transform(struct wl_output *wl_output); @@ -141,77 +137,36 @@ class Registrar { struct wl_display *wl_display_; struct wl_registry *wl_registry_; - struct { - uint32_t min_version = kWlSeatMinVersion; - std::map> seats; - } seat_; - - struct { - uint32_t min_version = kWlShmMinVersion; - std::optional wl_shm; - std::vector formats; - } shm_; - - struct { - uint32_t min_version = kWlCompositorMinVersion; - struct wl_compositor *wl_compositor{}; - } compositor_; - - struct { - uint32_t min_version = kWlSubcompositorMinVersion; - std::optional wl_subcompositor; - } sub_compositor_; + std::map> seats_; - struct { - uint32_t min_version = kXdgWmBaseMinVersion; - std::optional xdg_wm_base; - } xdg_wm_base_; - - struct { - uint32_t min_version = kAglShellMinVersion; - std::optional agl_shell; - } agl_shell_; + std::vector wl_shm_formats_{}; - struct { - uint32_t min_version = kIviWmMinVersion; - std::optional 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 defined(ENABLE_DRM_LEASE_CLIENT) - struct { - uint32_t min_version = kDrmLeaseDeviceV1MinVersion; - std::unique_ptr drm_lease_device_v1; - } drm_lease_device_v1_; +#if ENABLE_DRM_LEASE_CLIENT + std::unique_ptr drm_lease_device_v1_; #endif - struct { - uint32_t min_version = kXdgDecorationManagerMinVersion; - std::optional zxdg_decoration_manager_v1; - std::optional zxdg_toplevel_decoration_v1; - } xdg_decoration_manager_; + struct zxdg_decoration_manager_v1 *zxdg_decoration_manager_v1_{}; + struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1_{}; struct { - uint32_t min_version = kPresentationTimeMinVersion; struct wp_presentation *wp_presentation; clockid_t clk_id; } presentation_time_; - struct { - uint32_t min_version = kTearingControlManagerMinVersion; - std::optional wp_tearing_control_manager; - } tearing_manager_; + struct wp_tearing_control_manager_v1 *wp_tearing_control_manager_{}; - struct { - uint32_t min_version = kViewporterMinVersion; - std::optional wp_viewporter; - } viewporter_; + struct wp_viewporter *wp_viewporter_{}; - struct { - uint32_t min_version = kFractionalScaleManagerMinVersion; - std::optional fractional_scale_manager; - } fractional_scale_manager_; + struct wp_fractional_scale_manager_v1 *fractional_scale_manager_{}; - struct zxdg_output_manager_v1 * zxdg_output_manager_v1_{}; + struct zxdg_output_manager_v1 *zxdg_output_manager_v1_{}; std::mutex registrar_global_mutex_; std::mutex registrar_global_remove_mutex_; @@ -242,39 +197,39 @@ class Registrar { .format = shm_format, }; - static void handle_interface_compositor(void *data, + static void handle_interface_compositor(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); - static void handle_interface_subcompositor(void *data, + static void handle_interface_subcompositor(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); - static void handle_interface_shm(void *data, + static void handle_interface_shm(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); - static void handle_interface_seat(void *data, + static void handle_interface_seat(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); - static void handle_interface_output(void *data, + static void handle_interface_output(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); -#if defined(ENABLE_XDG_CLIENT) +#if ENABLE_XDG_CLIENT - static void handle_interface_xdg_wm_base(void *data, + static void handle_interface_xdg_wm_base(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, @@ -282,9 +237,9 @@ class Registrar { #endif -#if defined(ENABLE_AGL_SHELL_CLIENT) +#if ENABLE_AGL_SHELL_CLIENT - static void handle_interface_agl_shell(void *data, + static void handle_interface_agl_shell(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, @@ -292,17 +247,17 @@ class Registrar { #endif -#if defined(ENABLE_IVI_SHELL_CLIENT) - static void handle_interface_ivi_wm(void *data, +#if ENABLE_IVI_SHELL_CLIENT + static void handle_interface_ivi_wm(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); #endif -#if defined(ENABLE_DRM_LEASE_CLIENT) +#if ENABLE_DRM_LEASE_CLIENT - static void handle_interface_drm_lease_device_v1(void *data, + static void handle_interface_drm_lease_device_v1(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, @@ -310,18 +265,20 @@ class Registrar { #endif -#if defined(HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1) - static void handle_interface_zxdg_decoration(void *data, +#if HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1 + + static void handle_interface_zxdg_decoration(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); - static void handle_interface_zxdg_toplevel_decoration(void *data, + static void handle_interface_zxdg_toplevel_decoration(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); + #endif static void handle_presentation_clock_id(void *data, struct wp_presentation *presentation, uint32_t clk_id); @@ -330,47 +287,52 @@ class Registrar { handle_presentation_clock_id }; - static void handle_interface_presentation(void *data, + static void handle_interface_presentation(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); -#if defined(HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1) - static void handle_interface_tearing_control_manager(void *data, +#if HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1 + + static void handle_interface_tearing_control_manager(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); + #endif -#if defined(HAS_WAYLAND_PROTOCOL_VIEWPORTER) - static void handle_interface_viewporter(void *data, +#if HAS_WAYLAND_PROTOCOL_VIEWPORTER + + static void handle_interface_viewporter(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); + #endif -#if defined(HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1) - static void handle_interface_fractional_scale_manager(void *data, +#if HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1 + + static void handle_interface_fractional_scale_manager(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); + #endif -#if defined(HAS_WAYLAND_PROTOCOL_XDG_OUTPUT_UNSTABLE_V1) - static void handle_interface_xdg_output_unstable_v1(void *data, +#if HAS_WAYLAND_PROTOCOL_XDG_OUTPUT_UNSTABLE_V1 + + static void handle_interface_xdg_output_unstable_v1(Registrar *r, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); + #endif protected: - struct { - uint32_t min_version = kWlOutputMinVersion; - std::map> outputs; - } output_; + std::map> outputs_; }; diff --git a/src/window_manager/window_manager.h b/src/window_manager/window_manager.h index 6d97bbd..f40f96f 100644 --- a/src/window_manager/window_manager.h +++ b/src/window_manager/window_manager.h @@ -47,7 +47,7 @@ class WindowManager : public Registrar { [[nodiscard]] int display_dispatch() const; - [[nodiscard]] bool has_subcompositor() const { return sub_compositor_.wl_subcompositor.has_value(); } + [[nodiscard]] bool has_subcompositor() const { return wl_subcompositor_; } void register_task_observer(WindowManagerObserver *observer) { observers_.push_back(observer); diff --git a/src/window_manager/xdg_output.cc b/src/window_manager/xdg_output.cc index a198a55..ff111ca 100644 --- a/src/window_manager/xdg_output.cc +++ b/src/window_manager/xdg_output.cc @@ -83,3 +83,16 @@ void XdgOutput::handle_description(void *data, struct zxdg_output_v1 *zxdg_outpu spdlog::debug("XdgOutput::handle_description: {}", description); obj->output_.description = description; } + +void XdgOutput::print() { + spdlog::info("XDG Output"); + spdlog::info("\tDone: {}", output_.done); + spdlog::info("\tName: {}", output_.name); + spdlog::info("\tDescription: {}", output_.description); + spdlog::info("\tlogical_position"); + spdlog::info("\t\tx: {}", output_.logical_position.x); + spdlog::info("\t\ty: {}", output_.logical_position.y); + spdlog::info("\tlogical_size"); + spdlog::info("\t\tx: {}", output_.logical_size.width); + spdlog::info("\t\ty: {}", output_.logical_size.height); +} diff --git a/src/window_manager/xdg_output.h b/src/window_manager/xdg_output.h index 262c75b..90ff327 100644 --- a/src/window_manager/xdg_output.h +++ b/src/window_manager/xdg_output.h @@ -28,19 +28,23 @@ class XdgOutput { ~XdgOutput(); - int get_logical_position_x() const { return output_.logical_position.x; } + [[nodiscard]] int get_logical_position_x() const { return output_.logical_position.x; } - int get_logical_position_y() const { return output_.logical_position.y; } + [[nodiscard]] int get_logical_position_y() const { return output_.logical_position.y; } - int get_logical_size_width() const { return output_.logical_size.width; } + [[nodiscard]] int get_logical_size_width() const { return output_.logical_size.width; } - int get_logical_size_height() const { return output_.logical_size.height; } + [[nodiscard]] int get_logical_size_height() const { return output_.logical_size.height; } - const std::string &get_name() const { return output_.name; } + [[nodiscard]] const std::string &get_name() const { return output_.name; } - const std::string &get_description() const { return output_.description; } + [[nodiscard]] const std::string &get_description() const { return output_.description; } - bool is_origin() const { return (output_.logical_position.x == 0 && output_.logical_position.y == 0); } + [[nodiscard]] bool is_origin() const { + return (output_.logical_position.x == 0 && output_.logical_position.y == 0); + } + + void print(); // Disallow copy and assign. XdgOutput(const XdgOutput &) = delete; diff --git a/src/window_manager/xdg_window_manager.cc b/src/window_manager/xdg_window_manager.cc index d1c06ac..a0ebd0d 100644 --- a/src/window_manager/xdg_window_manager.cc +++ b/src/window_manager/xdg_window_manager.cc @@ -36,14 +36,13 @@ XdgWindowManager::XdgWindowManager(bool disable_cursor, const unsigned long ext_ ext_interface_data, context, display_name) { SPDLOG_TRACE("++XdgWindowManager::XdgWindowManager()"); - auto xdg_wm_base = get_xdg_wm_base(); - if (!xdg_wm_base.has_value()) { + xdg_wm_base_ = get_xdg_wm_base(); + if (!xdg_wm_base_) { spdlog::critical("XDG Window Manager is not supported."); exit(EXIT_FAILURE); } - xdg_wm_base_ = xdg_wm_base.value(); - xdg_wm_base_add_listener(xdg_wm_base.value(), &xdg_wm_base_listener_, this); + xdg_wm_base_add_listener(xdg_wm_base_, &xdg_wm_base_listener_, this); SPDLOG_TRACE("--XdgWindowManager::XdgWindowManager()"); } @@ -69,7 +68,7 @@ void XdgWindowManager::xdg_wm_base_ping(void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial) { auto wm = static_cast(data); - if (wm->get_xdg_wm_base().value() != xdg_wm_base) { + if (wm->get_xdg_wm_base() != xdg_wm_base) { SPDLOG_CRITICAL("wm->get_xdg_wm_base().value() != xdg_wm_base"); return; }