Реструктуризация проекта

This commit is contained in:
2025-11-16 17:52:09 +03:00
parent 1f700295ff
commit eeb632ed0e
9 changed files with 43 additions and 40 deletions

View File

@@ -24,32 +24,53 @@ set(PROTOCOL_XML ${WAYLAND_PROTOCOLS_DIR}/stable/xdg-shell/xdg-shell.xml)
# Генерируем заголовочный файл протокола # Генерируем заголовочный файл протокола
add_custom_command( add_custom_command(
OUTPUT xdg-shell-client-protocol.h OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protocol.h
COMMAND ${WAYLAND_SCANNER} client-header ${PROTOCOL_XML} xdg-shell-client-protocol.h COMMAND ${WAYLAND_SCANNER} client-header ${PROTOCOL_XML} ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protocol.h
DEPENDS ${PROTOCOL_XML} DEPENDS ${PROTOCOL_XML}
) )
# Генерируем исходный файл протокола # Генерируем исходный файл протокола
add_custom_command( add_custom_command(
OUTPUT xdg-shell-client-protocol.c OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protocol.c
COMMAND ${WAYLAND_SCANNER} private-code ${PROTOCOL_XML} xdg-shell-client-protocol.c COMMAND ${WAYLAND_SCANNER} private-code ${PROTOCOL_XML} ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protocol.c
DEPENDS ${PROTOCOL_XML} 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 и сгенерированного кода # Создаем исполняемый файл из ассемблерного, 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) 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) pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client)
target_link_libraries(wayland ${WAYLAND_CLIENT_LIBRARIES}) set(WAYLAND_CLIENT_LIBRARIES ${WAYLAND_CLIENT_LIBRARIES})
target_include_directories(wayland PRIVATE ${WAYLAND_CLIENT_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) set(WAYLAND_CLIENT_INCLUDE_DIRS ${WAYLAND_CLIENT_INCLUDE_DIRS})
# xkbcommon for keyboard layout handling # xkbcommon for keyboard layout handling
pkg_check_modules(XKBCOMMON REQUIRED xkbcommon) pkg_check_modules(XKBCOMMON REQUIRED xkbcommon)
target_include_directories(wayland PRIVATE ${XKBCOMMON_INCLUDE_DIRS}) set(XKBCOMMON_LIBRARIES ${XKBCOMMON_LIBRARIES})
target_link_libraries(wayland ${XKBCOMMON_LIBRARIES}) set(XKBCOMMON_INCLUDE_DIRS ${XKBCOMMON_INCLUDE_DIRS})
# Link to system libraries
target_link_libraries(wayland PRIVATE ${WAYLAND_CLIENT_LIBRARIES} ${XKBCOMMON_LIBRARIES})

View File

@@ -5,15 +5,15 @@
/* Data for a single Wayland window (one surface) */ /* Data for a single Wayland window (one surface) */
struct wayland_window { struct wayland_window {
struct wl_surface *wl_surface; struct wl_surface *wl_surface;
struct wl_buffer *buffer; struct wl_buffer *buffer;
struct xdg_surface *xdg_surface; struct xdg_surface *xdg_surface;
struct xdg_toplevel *xdg_toplevel; struct xdg_toplevel *xdg_toplevel;
uint8_t *data; uint8_t *data;
int16_t width; int16_t width;
int16_t height; int16_t height;
int need_close; int need_close;
uint8_t color; uint8_t color;
}; };
/* Initialize windowing for the given window structure. Caller provides the struct (on stack or heap) */ /* Initialize windowing for the given window structure. Caller provides the struct (on stack or heap) */

View File

@@ -6,4 +6,4 @@ main:
enter 0, 0 enter 0, 0
call run_wayland call run_wayland
leave leave
ret ret

View File

@@ -10,24 +10,6 @@
#include "window.h" #include "window.h"
#include "registry.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() int32_t run_wayland()
{ {
@@ -53,4 +35,4 @@ int32_t run_wayland()
input_cleanup(); input_cleanup();
wl_display_disconnect(display); wl_display_disconnect(display);
return 0; return 0;
} }