-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wayland): add Wayland support (#51)
* fix(wayland) Rebase master to get the latest changes * chore(wayland) adjust example code * chore(wayland) align with driver, wait only if the cycle was fully completed * feat(wayland) Simplify CMakeLists file Use external scripts to obtain the selected backend in lv_conf.h Generate wayland protocol via a shell script instead of CMake * fix(wayland) - Remove test script * doc(wayland) Update documentation Remove the step that tells to edit the CMakeLists.txt file and manually enable the option to select the backend * feat(wayland) Move wayland display init and runloop to a separate file Solve merge conflit with the main branch * fix(wayland) Re-apply the delay timer execution only until the next timer fires up * fix(wayland) adjust CI * fix(wayland) fix CI
- Loading branch information
Showing
9 changed files
with
306 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,67 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
project(lvgl) | ||
|
||
set(CMAKE_C_STANDARD 99)#C99 # lvgl officially support C99 and above | ||
set(CMAKE_CXX_STANDARD 17)#C17 | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
foreach(BACKEND_NAME "SDL" "LINUX_DRM" "LINUX_FBDEV" "X11" "WAYLAND") | ||
execute_process(COMMAND "scripts/backend_conf.sh" ${BACKEND_NAME} OUTPUT_VARIABLE IS_BACKEND_ENABLED) | ||
set("LV_USE_${BACKEND_NAME}" ${IS_BACKEND_ENABLED}) | ||
endforeach() | ||
|
||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) | ||
# Uncomment if the program needs debugging | ||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb") | ||
|
||
set(CMAKE_C_STANDARD 99) # LVGL officially supports C99 and above | ||
set(CMAKE_CXX_STANDARD 17) #C17 | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) | ||
add_subdirectory(lvgl) | ||
add_executable(main main.c mouse_cursor_icon.c) | ||
target_include_directories(lvgl PUBLIC ${PROJECT_SOURCE_DIR}) | ||
|
||
find_package(PkgConfig REQUIRED) # We use the platform independent pkg-config to find all the libs | ||
pkg_check_modules(LIBDRM REQUIRED libdrm) | ||
pkg_check_modules(SDL2 REQUIRED sdl2) | ||
pkg_check_modules(SDL2_image REQUIRED SDL2_image) | ||
if (LV_USE_LINUX_DRM) | ||
|
||
target_include_directories(lvgl PUBLIC ${PROJECT_SOURCE_DIR}) | ||
target_include_directories(lvgl PRIVATE ${SDL2_INCLUDE_DIRS}) | ||
target_include_directories(lvgl PRIVATE ${SDL2_IMAGE_INCLUDE_DIRS}) | ||
target_include_directories(lvgl PRIVATE ${LIBDRM_INCLUDE_DIRS}) | ||
|
||
target_link_libraries(main PRIVATE lvgl) # Add '-static' if you want a standalone binary | ||
target_link_libraries(main PRIVATE lvgl::examples) | ||
target_link_libraries(main PRIVATE lvgl::demos) | ||
target_link_libraries(main PRIVATE lvgl::thorvg) | ||
target_link_libraries(main PRIVATE ${SDL2_LIBRARIES}) | ||
target_link_libraries(main PRIVATE ${SDL2_IMAGE_LIBRARIES}) | ||
target_link_libraries(main PRIVATE ${LIBDRM_LIBRARIES}) | ||
target_link_libraries(main PRIVATE m) | ||
target_link_libraries(main PRIVATE pthread) | ||
|
||
add_custom_target(run COMMAND ${EXECUTABLE_OUTPUT_PATH}/main DEPENDS main) | ||
find_package(PkgConfig REQUIRED) | ||
pkg_check_modules(LIBDRM REQUIRED libdrm) | ||
|
||
target_include_directories(lvgl PUBLIC ${LIBDRM_INCLUDE_DIRS}) | ||
add_executable(lvglsim main.c mouse_cursor_icon.c) | ||
target_link_libraries(lvglsim lvgl lvgl::examples lvgl::demos lvgl::thorvg ${LIBDRM_LIBRARIES} m pthread) | ||
|
||
elseif (LV_USE_SDL) | ||
|
||
find_package(PkgConfig REQUIRED) | ||
pkg_check_modules(SDL2 REQUIRED sdl2) | ||
pkg_check_modules(SDL2_image REQUIRED SDL2_image) | ||
|
||
target_include_directories(lvgl PRIVATE ${SDL2_INCLUDE_DIRS}) | ||
target_include_directories(lvgl PRIVATE ${SDL2_IMAGE_INCLUDE_DIRS}) | ||
add_executable(lvglsim main.c mouse_cursor_icon.c) | ||
target_link_libraries(lvglsim lvgl lvgl::examples lvgl::demos lvgl::thorvg ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} m pthread) | ||
|
||
elseif (LV_USE_WAYLAND) | ||
|
||
find_package(PkgConfig REQUIRED) | ||
pkg_check_modules(wayland-client REQUIRED wayland-client) | ||
pkg_check_modules(wayland-cursor REQUIRED wayland-cursor) | ||
pkg_check_modules(xkbcommon REQUIRED xkbcommon) | ||
|
||
# Wayland protocols | ||
pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols>=1.25) | ||
pkg_get_variable(WAYLAND_PROTOCOLS_BASE wayland-protocols pkgdatadir) | ||
|
||
execute_process(COMMAND "scripts/gen_wl_protocols.sh" OUTPUT_VARIABLE WAYLAND_PROTOCOLS_SRC) | ||
|
||
target_include_directories(lvgl PRIVATE ${PROJECT_SOURCE_DIR} | ||
"${PROJECT_SOURCE_DIR}/wl_protocols") | ||
add_executable(lvglsim main.c ${WAYLAND_PROTOCOLS_SRC} | ||
mouse_cursor_icon.c backends/wayland.c) | ||
target_compile_definitions(lvglsim PRIVATE LV_CONF_INCLUDE_SIMPLE) | ||
target_link_libraries(lvglsim lvgl lvgl::examples lvgl::demos lvgl::thorvg m | ||
wayland-client wayland-cursor xkbcommon) | ||
|
||
else() | ||
|
||
# No specific build steps required for FBDEV | ||
add_executable(lvglsim main.c mouse_cursor_icon.c) | ||
target_link_libraries(lvglsim lvgl lvgl::examples lvgl::demos lvgl::thorvg m pthread) | ||
endif() | ||
|
||
add_custom_target (run COMMAND ${EXECUTABLE_OUTPUT_PATH}/lvglsim DEPENDS lvglsim) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
/* Enters the run loop of the selected backend */ | ||
void lv_linux_run_loop(void); | ||
|
||
/* Initializes the display */ | ||
void lv_linux_disp_init(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
|
||
/* Settings defined in main.c */ | ||
|
||
extern uint16_t window_width; | ||
extern uint16_t window_height; | ||
|
||
extern bool fullscreen; | ||
extern bool maximize; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
|
||
#include "lvgl/lvgl.h" | ||
#include "settings.h" | ||
|
||
/* Currently, the wayland driver calls lv_timer_handler internaly */ | ||
void lv_linux_run_loop(void) | ||
{ | ||
|
||
bool completed; | ||
|
||
/* Handle LVGL tasks */ | ||
while (1) { | ||
|
||
completed = lv_wayland_timer_handler(); | ||
|
||
if (completed) { | ||
/* wait only if the cycle was completed */ | ||
usleep(LV_DEF_REFR_PERIOD * 1000); | ||
} | ||
|
||
/* Run until the last window closes */ | ||
if (!lv_wayland_window_is_open(NULL)) { | ||
break; | ||
} | ||
} | ||
|
||
} | ||
|
||
void lv_linux_disp_init(void) | ||
{ | ||
lv_display_t *disp; | ||
lv_group_t *g; | ||
|
||
disp = lv_wayland_window_create(window_width, window_height, | ||
"LVGL Simulator", NULL); | ||
|
||
if (fullscreen) { | ||
lv_wayland_window_set_fullscreen(disp, fullscreen); | ||
} else if (maximize) { | ||
lv_wayland_window_set_maximized(disp, maximize); | ||
} | ||
|
||
g = lv_group_create(); | ||
lv_group_set_default(g); | ||
lv_indev_set_group(lv_wayland_get_keyboard(disp), g); | ||
lv_indev_set_group(lv_wayland_get_pointeraxis(disp), g); | ||
|
||
} |
Oops, something went wrong.