From 1847cd5f02b4ecc8d94b187821066e98dcea2a48 Mon Sep 17 00:00:00 2001 From: Jerry Date: Tue, 23 Jan 2024 10:39:39 +0800 Subject: [PATCH] resolve github #8 --- CMakeLists.txt | 24 ++++++++++++++++++++++-- drm.c | 16 +++++++++++++++- kmsvnc.c | 2 ++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4440bc2..026e894 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,21 +13,41 @@ pkg_search_module(XKBCOMMON REQUIRED xkbcommon) pkg_search_module(LIBVA REQUIRED libva) pkg_search_module(LIBVA_DRM REQUIRED libva-drm) +add_executable(kmsvnc) +set(kmsvnc_SOURCES kmsvnc.c drm.c input.c keymap.c va.c drm_master.c) + include(CheckIncludeFiles) CHECK_INCLUDE_FILES("linux/uinput.h;linux/dma-buf.h" HAVE_LINUX_API_HEADERS) IF(NOT HAVE_LINUX_API_HEADERS) message(FATAL_ERROR "linux-api-headers not found") ENDIF() -add_executable(kmsvnc kmsvnc.c drm.c input.c keymap.c va.c drm_master.c) +include(CheckSymbolExists) +check_symbol_exists(SYS_pidfd_getfd "sys/syscall.h" HAVE_PIDFD_GETFD_SYSCALL) +IF(NOT HAVE_PIDFD_GETFD_SYSCALL) + message(WARNING "pidfd_getfd syscall not found, the --screen-blank options will be disabled") + target_compile_options(kmsvnc PUBLIC -DDISABLE_KMSVNC_SCREEN_BLANK) + list(REMOVE_ITEM kmsvnc_SOURCES drm_master.c) +ENDIF() + + +target_sources(kmsvnc PUBLIC + ${kmsvnc_SOURCES} +) target_include_directories(kmsvnc PUBLIC ${LIBDRM_INCLUDEDIR} - ${LIBDRM_INCLUDEDIR}/libdrm ${LIBVNCSERVER_INCLUDEDIR} ${XKBCOMMON_INCLUDEDIR} ${LIBVA_INCLUDEDIR} ${LIBVA_DRM_INCLUDEDIR} ) +target_compile_options(kmsvnc PUBLIC + ${LIBDRM_CFLAGS} + ${LIBVNCSERVER_CFLAGS} + ${XKBCOMMON_CFLAGS} + ${LIBVA_CFLAGS} + ${LIBVA_DRM_CFLAGS} +) target_link_libraries(kmsvnc PUBLIC m ${LIBDRM_LIBRARIES} diff --git a/drm.c b/drm.c index d472633..e48501b 100644 --- a/drm.c +++ b/drm.c @@ -10,7 +10,15 @@ #include "drm.h" #include "va.h" -#include "drm_master.h" + +#ifndef DISABLE_KMSVNC_SCREEN_BLANK + #include "drm_master.h" +#endif + +#ifndef fourcc_mod_is_vendor + #define fourcc_mod_is_vendor(modifier, vendor) \ + (fourcc_mod_get_vendor(modifier) == DRM_FORMAT_MOD_VENDOR_## vendor) +#endif extern struct kmsvnc_data *kmsvnc; @@ -165,6 +173,7 @@ void drm_sync_noop(int drmfd) void drm_cleanup() { if (kmsvnc->drm) { +#ifndef DISABLE_KMSVNC_SCREEN_BLANK if (kmsvnc->drm->gamma && kmsvnc->drm->gamma->size && kmsvnc->drm->gamma->red && kmsvnc->drm->gamma->green && kmsvnc->drm->gamma->blue) { if (drmModeCrtcSetGamma(kmsvnc->drm->drm_master_fd ?: kmsvnc->drm->drm_fd, kmsvnc->drm->plane->crtc_id, kmsvnc->drm->gamma->size, kmsvnc->drm->gamma->red, kmsvnc->drm->gamma->green, kmsvnc->drm->gamma->blue)) perror("Failed to restore gamma"); } @@ -176,6 +185,7 @@ void drm_cleanup() { free(kmsvnc->drm->gamma); kmsvnc->drm->gamma = NULL; } +#endif if (kmsvnc->drm->drm_ver) { drmFreeVersion(kmsvnc->drm->drm_ver); kmsvnc->drm->drm_ver = NULL; @@ -487,6 +497,7 @@ int drm_open() { if (!kmsvnc->screen_blank && drmIsMaster(drm->drm_fd)) { if (drmDropMaster(drm->drm_fd)) fprintf(stderr, "Failed to drop master"); } +#ifndef DISABLE_KMSVNC_SCREEN_BLANK if (kmsvnc->screen_blank && !drmIsMaster(drm->drm_fd)) { drm->drm_master_fd = drm_get_master_fd(); drm->drm_master_fd = drm->drm_master_fd > 0 ? drm->drm_master_fd : 0; @@ -494,6 +505,7 @@ int drm_open() { fprintf(stderr, "not master client, master fd %d\n", drm->drm_master_fd); } } +#endif drm->drm_ver = drmGetVersion(drm->drm_fd); printf("drm driver is %s\n", drm->drm_ver->name); @@ -506,6 +518,7 @@ int drm_open() { if (drm_refresh_planes(1)) return 1; +#ifndef DISABLE_KMSVNC_SCREEN_BLANK if (kmsvnc->screen_blank) { drm->gamma = malloc(sizeof(struct kmsvnc_drm_gamma_data)); if (!drm->gamma) KMSVNC_FATAL("memory allocation error at %s:%d\n", __FILE__, __LINE__); @@ -565,6 +578,7 @@ int drm_open() { target_crtc = NULL; } } +#endif drm->mfb = drmModeGetFB2(drm->drm_fd, drm->plane->fb_id); if (!drm->mfb) { diff --git a/kmsvnc.c b/kmsvnc.c index 5b738b3..ef1a1a0 100644 --- a/kmsvnc.c +++ b/kmsvnc.c @@ -241,8 +241,10 @@ static struct argp_option kmsvnc_main_options[] = { {"input-height", 0xff07, "0", 0, "Explicitly set input height"}, {"input-offx", 0xff08, "0", 0, "Set input offset of x axis on a multi display system"}, {"input-offy", 0xff09, "0", 0, "Set input offset of y axis on a multi display system"}, +#ifndef DISABLE_KMSVNC_SCREEN_BLANK {"screen-blank", 0xff0a, 0, OPTION_ARG_OPTIONAL, "Blank screen with gamma set on crtc"}, {"screen-blank-restore-linear", 0xff0b, 0, OPTION_ARG_OPTIONAL, "Restore linear values on exit in case of messed up gamma"}, +#endif {"wakeup", 'w', 0, OPTION_ARG_OPTIONAL, "Move mouse to wake the system up before start"}, {"disable-input", 'i', 0, OPTION_ARG_OPTIONAL, "Disable uinput"}, {"desktop-name", 'n', "kmsvnc", 0, "Specify vnc desktop name"},