From eeb632ed0e9922d64cfdcdea5d305c714124066b Mon Sep 17 00:00:00 2001 From: Roman Pytkov Date: Sun, 16 Nov 2025 17:52:09 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=81=D1=82=D1=80=D1=83=D0=BA?= =?UTF-8?q?=D1=82=D1=83=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wayland/CMakeLists.txt | 43 ++++++++++++++++++++++++-------- wayland/{ => include}/input.h | 0 wayland/{ => include}/registry.h | 0 wayland/{ => include}/window.h | 18 ++++++------- wayland/{ => src}/asm.asm | 2 +- wayland/{ => src}/c.c | 20 +-------------- wayland/{ => src}/input.c | 0 wayland/{ => src}/registry.c | 0 wayland/{ => src}/window.c | 0 9 files changed, 43 insertions(+), 40 deletions(-) rename wayland/{ => include}/input.h (100%) rename wayland/{ => include}/registry.h (100%) rename wayland/{ => include}/window.h (69%) rename wayland/{ => src}/asm.asm (92%) rename wayland/{ => src}/c.c (58%) rename wayland/{ => src}/input.c (100%) rename wayland/{ => src}/registry.c (100%) rename wayland/{ => src}/window.c (100%) diff --git a/wayland/CMakeLists.txt b/wayland/CMakeLists.txt index b111557..531db98 100644 --- a/wayland/CMakeLists.txt +++ b/wayland/CMakeLists.txt @@ -24,32 +24,53 @@ set(PROTOCOL_XML ${WAYLAND_PROTOCOLS_DIR}/stable/xdg-shell/xdg-shell.xml) # Генерируем заголовочный файл протокола add_custom_command( - OUTPUT xdg-shell-client-protocol.h - COMMAND ${WAYLAND_SCANNER} client-header ${PROTOCOL_XML} xdg-shell-client-protocol.h + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protocol.h + COMMAND ${WAYLAND_SCANNER} client-header ${PROTOCOL_XML} ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protocol.h DEPENDS ${PROTOCOL_XML} ) # Генерируем исходный файл протокола add_custom_command( - OUTPUT xdg-shell-client-protocol.c - COMMAND ${WAYLAND_SCANNER} private-code ${PROTOCOL_XML} xdg-shell-client-protocol.c + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protocol.c + COMMAND ${WAYLAND_SCANNER} private-code ${PROTOCOL_XML} ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protocol.c DEPENDS ${PROTOCOL_XML} ) # Цель для генерации протокола -add_custom_target(generate-xdg-shell DEPENDS xdg-shell-client-protocol.h xdg-shell-client-protocol.c) +add_custom_target(generate-xdg-shell DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protocol.h ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protocol.c) # Создаем исполняемый файл из ассемблерного, C и сгенерированного кода -add_executable(wayland asm.asm c.c input.c registry.c window.c xdg-shell-client-protocol.c) +file(GLOB_RECURSE WAYLAND_SOURCES CONFIGURE_DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/src/*.asm" +) -# Зависимость от генерации протокола +# Append the generated XDG C source (will be created in the binary dir) +list(APPEND WAYLAND_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protocol.c) + +# Create executable from collected sources +add_executable(wayland ${WAYLAND_SOURCES}) + +# Ensure generated files are produced before building the target add_dependencies(wayland generate-xdg-shell) +# Include headers and binary dir where generated headers are written +target_include_directories(wayland PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_BINARY_DIR} + ${WAYLAND_CLIENT_INCLUDE_DIRS} + ${XKBCOMMON_INCLUDE_DIRS} +) + pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client) -target_link_libraries(wayland ${WAYLAND_CLIENT_LIBRARIES}) -target_include_directories(wayland PRIVATE ${WAYLAND_CLIENT_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) +set(WAYLAND_CLIENT_LIBRARIES ${WAYLAND_CLIENT_LIBRARIES}) +set(WAYLAND_CLIENT_INCLUDE_DIRS ${WAYLAND_CLIENT_INCLUDE_DIRS}) # xkbcommon for keyboard layout handling pkg_check_modules(XKBCOMMON REQUIRED xkbcommon) -target_include_directories(wayland PRIVATE ${XKBCOMMON_INCLUDE_DIRS}) -target_link_libraries(wayland ${XKBCOMMON_LIBRARIES}) \ No newline at end of file +set(XKBCOMMON_LIBRARIES ${XKBCOMMON_LIBRARIES}) +set(XKBCOMMON_INCLUDE_DIRS ${XKBCOMMON_INCLUDE_DIRS}) + +# Link to system libraries +target_link_libraries(wayland PRIVATE ${WAYLAND_CLIENT_LIBRARIES} ${XKBCOMMON_LIBRARIES}) \ No newline at end of file diff --git a/wayland/input.h b/wayland/include/input.h similarity index 100% rename from wayland/input.h rename to wayland/include/input.h diff --git a/wayland/registry.h b/wayland/include/registry.h similarity index 100% rename from wayland/registry.h rename to wayland/include/registry.h diff --git a/wayland/window.h b/wayland/include/window.h similarity index 69% rename from wayland/window.h rename to wayland/include/window.h index a87e947..3ff1a27 100644 --- a/wayland/window.h +++ b/wayland/include/window.h @@ -5,15 +5,15 @@ /* Data for a single Wayland window (one surface) */ struct wayland_window { - struct wl_surface *wl_surface; - struct wl_buffer *buffer; - struct xdg_surface *xdg_surface; - struct xdg_toplevel *xdg_toplevel; - uint8_t *data; - int16_t width; - int16_t height; - int need_close; - uint8_t color; + struct wl_surface *wl_surface; + struct wl_buffer *buffer; + struct xdg_surface *xdg_surface; + struct xdg_toplevel *xdg_toplevel; + uint8_t *data; + int16_t width; + int16_t height; + int need_close; + uint8_t color; }; /* Initialize windowing for the given window structure. Caller provides the struct (on stack or heap) */ diff --git a/wayland/asm.asm b/wayland/src/asm.asm similarity index 92% rename from wayland/asm.asm rename to wayland/src/asm.asm index 65e38cd..b00e969 100644 --- a/wayland/asm.asm +++ b/wayland/src/asm.asm @@ -6,4 +6,4 @@ main: enter 0, 0 call run_wayland leave - ret \ No newline at end of file + ret diff --git a/wayland/c.c b/wayland/src/c.c similarity index 58% rename from wayland/c.c rename to wayland/src/c.c index 8423ecd..2bb1b28 100644 --- a/wayland/c.c +++ b/wayland/src/c.c @@ -10,24 +10,6 @@ #include "window.h" #include "registry.h" -// core is now split into modules: registry, input and window - -// resize, draw and frame callbacks moved to `window.c` - -/* Input, window and registry logic has been moved into separate modules. - * This file now wires them together and runs the main loop. */ - -/* Window events moved to `window.c` */ - -/* frame callback now in `window.c` */ - -/* ping/pong moved to `window.c` */ -// Функция для прослушивания глобальных объектов -/* registry listener moved to `registry.c` */ - -// No registry functions here; they are implemented in `registry.c`. - -/* listeners implemented in modules */ int32_t run_wayland() { @@ -53,4 +35,4 @@ int32_t run_wayland() input_cleanup(); wl_display_disconnect(display); return 0; -} \ No newline at end of file +} diff --git a/wayland/input.c b/wayland/src/input.c similarity index 100% rename from wayland/input.c rename to wayland/src/input.c diff --git a/wayland/registry.c b/wayland/src/registry.c similarity index 100% rename from wayland/registry.c rename to wayland/src/registry.c diff --git a/wayland/window.c b/wayland/src/window.c similarity index 100% rename from wayland/window.c rename to wayland/src/window.c