Skip to content

Commit

Permalink
highgui Wayland xdg_shell
Browse files Browse the repository at this point in the history
-enable using -DWITH_WAYLAND=ON
-adapted from https://github.com/pfpacket/opencv-wayland
-using xdg_shell stable protocol
-overrides HAVE_QT if HAVE_WAYLAND and WITH_WAYLAND are set

Signed-off-by: Joel Winarske <[email protected]>

Co-authored-by: Ryo Munakata <[email protected]>
  • Loading branch information
2 people authored and Joel Winarske committed Jun 26, 2022
1 parent b19683e commit 0769bf4
Show file tree
Hide file tree
Showing 9 changed files with 2,566 additions and 1 deletion.
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ OCV_OPTION(WITH_GTK "Include GTK support" ON
OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF
VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID
VERIFY HAVE_GTK AND NOT HAVE_GTK3)
OCV_OPTION(WITH_WAYLAND "Include Wayland support" OFF
VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID
VERIFY HAVE_WAYLAND)
OCV_OPTION(WITH_IPP "Include Intel IPP support" (NOT MINGW AND NOT CV_DISABLE_OPTIMIZATION)
VISIBLE_IF (X86_64 OR X86) AND NOT WINRT AND NOT IOS
VERIFY HAVE_IPP)
Expand Down Expand Up @@ -1260,6 +1263,24 @@ endif(WIN32)
status("")
status(" GUI: " "${OPENCV_HIGHGUI_BUILTIN_BACKEND}")

if(WITH_WAYLAND OR HAVE_WAYLAND)
if(HAVE_WAYLAND_CLIENT)
status(" Wayland Client:" "YES (ver ${WAYLAND_CLIENT_VERSION})")
endif()
if(HAVE_WAYLAND_CURSOR)
status(" Wayland Cursor:" "YES (ver ${WAYLAND_CURSOR_VERSION})")
endif()
if(HAVE_WAYLAND_PROTOCOL)
status(" Wayland Protocol:" "YES (ver ${WAYLAND_PROTOCOL_VERSION})")
endif()
if(HAVE_WAYLAND_EGL)
status(" Wayland EGL:" "YES (ver ${WAYLAND_EGL_VERSION})")
endif()
if(HAVE_XKBCOMMON)
status(" Xkbcommon:" "YES (ver ${XKBCOMMON_VERSION})")
endif()
endif()

if(WITH_QT OR HAVE_QT)
if(HAVE_QT)
status(" QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")
Expand Down
1 change: 1 addition & 0 deletions modules/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ ocv_create_module(${extra_libs})
ocv_target_link_libraries(${the_module} PRIVATE
"${ZLIB_LIBRARIES}" "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}"
"${OPENGL_LIBRARIES}"
"${GLX_LIBRARIES}"
"${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}" "${HALIDE_LIBRARIES}"
"${ITT_LIBRARIES}"
"${OPENCV_HAL_LINKER_LIBS}"
Expand Down
26 changes: 25 additions & 1 deletion modules/highgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,31 @@ list(REMOVE_ITEM highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${n

set(OPENCV_HIGHGUI_BUILTIN_BACKEND "")

if(HAVE_QT)
if(WITH_WAYLAND AND HAVE_WAYLAND)
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "Wayland")
add_definitions(-DHAVE_WAYLAND)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

if (HAVE_WAYLAND_PROTOCOLS)
ocv_wayland_generate(
${WAYLAND_PROTOCOLS_BASE}/stable/xdg-shell/xdg-shell.xml
xdg-shell-client-protocol)
endif()

list(APPEND highgui_srcs
${CMAKE_CURRENT_LIST_DIR}/src/window_wayland.cpp
${WAYLAND_PROTOCOL_SOURCES}
)
list(APPEND HIGHGUI_LIBRARIES "${WAYLAND_CLIENT_LINK_LIBRARIES};${WAYLAND_CURSOR_LINK_LIBRARIES};${XKBCOMMON_LINK_LIBRARIES}")

if(HAVE_WAYLAND_EGL)
if(WAYLAND_EGL_LIBRARIES)
list(APPEND HIGHGUI_LIBRARIES "${WAYLAND_EGL_LIBRARIES}")
endif()
endif()

elseif(HAVE_QT)
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "QT${QT_VERSION_MAJOR}")
add_definitions(-DHAVE_QT)

Expand Down
35 changes: 35 additions & 0 deletions modules/highgui/cmake/detect_wayland.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# --- Wayland ---
macro(ocv_wayland_generate protocol_file output_file)
add_custom_command(OUTPUT ${output_file}.h
COMMAND ${WAYLAND_SCANNER_EXECUTABLE} client-header < ${protocol_file} > ${output_file}.h
DEPENDS ${protocol_file})
add_custom_command(OUTPUT ${output_file}.c
COMMAND ${WAYLAND_SCANNER_EXECUTABLE} private-code < ${protocol_file} > ${output_file}.c
DEPENDS ${protocol_file})
list(APPEND WAYLAND_PROTOCOL_SOURCES ${output_file}.h ${output_file}.c)
endmacro()

ocv_clear_vars(HAVE_WAYLAND_CLIENT HAVE_WAYLAND_CURSOR HAVE_XKBCOMMON HAVE_WAYLAND_PROTOCOLS)
if(WITH_WAYLAND)
ocv_check_modules(WAYLAND_CLIENT wayland-client)
if(WAYLAND_CLIENT_FOUND)
set(HAVE_WAYLAND_CLIENT ON)
endif()
ocv_check_modules(WAYLAND_CURSOR wayland-cursor)
if(WAYLAND_CURSOR_FOUND)
set(HAVE_WAYLAND_CURSOR ON)
endif()
ocv_check_modules(XKBCOMMON xkbcommon)
if(XKBCOMMON_FOUND)
set(HAVE_XKBCOMMON ON)
endif()
ocv_check_modules(WAYLAND_PROTOCOLS wayland-protocols>=1.13)
if(HAVE_WAYLAND_PROTOCOLS)
pkg_get_variable(WAYLAND_PROTOCOLS_BASE wayland-protocols pkgdatadir)
find_host_program(WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner REQUIRED)
endif()

if(HAVE_WAYLAND_CLIENT AND HAVE_WAYLAND_CURSOR AND HAVE_XKBCOMMON AND HAVE_WAYLAND_PROTOCOLS)
set(HAVE_WAYLAND TRUE)
endif()
endif()
1 change: 1 addition & 0 deletions modules/highgui/cmake/init.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ endmacro()

add_backend("gtk" WITH_GTK)
add_backend("win32ui" WITH_WIN32UI)
add_backend("wayland" WITH_WAYLAND)
# TODO cocoa
# TODO qt
# TODO opengl
Expand Down
1 change: 1 addition & 0 deletions modules/highgui/src/precomp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ void setWindowTitle_W32(const cv::String& name, const cv::String& title);
void setWindowTitle_GTK(const cv::String& name, const cv::String& title);
void setWindowTitle_QT(const cv::String& name, const cv::String& title);
void setWindowTitle_COCOA(const cv::String& name, const cv::String& title);
void setWindowTitle_WAYLAND(const cv::String& name, const cv::String& title);

int pollKey_W32();

Expand Down
3 changes: 3 additions & 0 deletions modules/highgui/src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ void cv::setWindowTitle(const String& winname, const String& title)
return setWindowTitle_QT(winname, title);
#elif defined (HAVE_COCOA)
return setWindowTitle_COCOA(winname, title);
#elif defined (HAVE_WAYLAND)
return setWindowTitle_WAYLAND(winname, title);
#else
CV_Error(Error::StsNotImplemented, "The function is not implemented. "
"Rebuild the library with Windows, GTK+ 2.x or Cocoa support. "
Expand Down Expand Up @@ -1226,6 +1228,7 @@ int cv::createButton(const String&, ButtonCallback, void*, int , bool )
#elif defined (HAVE_GTK) // see window_gtk.cpp
#elif defined (HAVE_COCOA) // see window_cocoa.mm
#elif defined (HAVE_QT) // see window_QT.cpp
#elif defined (HAVE_WAYLAND) // see window_wayland.cpp
#elif defined (WINRT) && !defined (WINRT_8_0) // see window_winrt.cpp

#else
Expand Down
Loading

0 comments on commit 0769bf4

Please sign in to comment.