|
| 1 | +# SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 | + |
| 5 | +# Shortcut Manager Plugin for deepin-service-manager |
| 6 | +cmake_minimum_required(VERSION 3.16) |
| 7 | + |
| 8 | +set(PLUGIN_NAME plugin-dde-shortcut) |
| 9 | + |
| 10 | +set(CMAKE_CXX_STANDARD 17) |
| 11 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 12 | +set(CMAKE_AUTOMOC ON) |
| 13 | + |
| 14 | +find_package(Qt6 REQUIRED COMPONENTS Core DBus Gui WaylandClient) |
| 15 | +find_package(Dtk6 REQUIRED COMPONENTS Core DConfig) |
| 16 | +find_package(PkgConfig REQUIRED) |
| 17 | +find_package(TreelandProtocols REQUIRED) |
| 18 | + |
| 19 | +pkg_check_modules(XCB REQUIRED xcb xcb-keysyms xcb-xtest) |
| 20 | +pkg_check_modules(X11 REQUIRED x11) |
| 21 | +pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client) |
| 22 | + |
| 23 | +# Set source file path (using sources from plugin directory) |
| 24 | +set(SHORTCUT_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) |
| 25 | + |
| 26 | +# Common sources shared between plugin and debug binary |
| 27 | +set(SHORTCUT_COMMON_SOURCES |
| 28 | + ${SHORTCUT_SRC_DIR}/core/shortcutmanager.cpp |
| 29 | + ${SHORTCUT_SRC_DIR}/core/keybindingmanager.cpp |
| 30 | + ${SHORTCUT_SRC_DIR}/core/gesturemanager.cpp |
| 31 | + ${SHORTCUT_SRC_DIR}/core/qkeysequenceconverter.cpp |
| 32 | + ${SHORTCUT_SRC_DIR}/core/actionexecutor.cpp |
| 33 | + ${SHORTCUT_SRC_DIR}/core/translationmanager.cpp |
| 34 | + ${SHORTCUT_SRC_DIR}/config/configloader.cpp |
| 35 | + ${SHORTCUT_SRC_DIR}/backend/abstractkeyhandler.h |
| 36 | + ${SHORTCUT_SRC_DIR}/backend/abstractgesturehandler.h |
| 37 | + ${SHORTCUT_SRC_DIR}/backend/specialkeyhandler.cpp |
| 38 | + ${SHORTCUT_SRC_DIR}/backend/x11/x11keyhandler.cpp |
| 39 | + ${SHORTCUT_SRC_DIR}/backend/x11/x11helper.cpp |
| 40 | + ${SHORTCUT_SRC_DIR}/backend/x11/modifierkeymonitor.cpp |
| 41 | + ${SHORTCUT_SRC_DIR}/backend/wayland/treelandshortcutwrapper.cpp |
| 42 | + ${SHORTCUT_SRC_DIR}/backend/wayland/waylandkeyhandler.cpp |
| 43 | + ${SHORTCUT_SRC_DIR}/backend/wayland/waylandgesturehandler.cpp |
| 44 | +) |
| 45 | + |
| 46 | +# Plugin sources (plugin-specific + common) |
| 47 | +set(PLUGIN_SOURCES |
| 48 | + plugin.cpp |
| 49 | + pluginshortcutmanager.cpp |
| 50 | + pluginshortcutmanager.h |
| 51 | + ${SHORTCUT_COMMON_SOURCES} |
| 52 | +) |
| 53 | + |
| 54 | +# Create plugin library |
| 55 | +add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SOURCES}) |
| 56 | + |
| 57 | +# Wayland Protocol Generation |
| 58 | +qt6_generate_wayland_protocol_client_sources( |
| 59 | + ${PLUGIN_NAME} |
| 60 | + FILES |
| 61 | + ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-shortcut-manager-v2.xml |
| 62 | +) |
| 63 | + |
| 64 | +# Add generated protocol files |
| 65 | +target_sources(${PLUGIN_NAME} PRIVATE |
| 66 | + ${CMAKE_CURRENT_BINARY_DIR}/wayland-treeland-shortcut-manager-v2-protocol.c |
| 67 | +) |
| 68 | + |
| 69 | +target_link_libraries(${PLUGIN_NAME} PRIVATE |
| 70 | + Qt6::Core |
| 71 | + Qt6::DBus |
| 72 | + Qt6::Gui |
| 73 | + Qt6::WaylandClient |
| 74 | + Dtk6::Core |
| 75 | + ${XCB_LIBRARIES} |
| 76 | + ${X11_LIBRARIES} |
| 77 | + ${WAYLAND_CLIENT_LIBRARIES} |
| 78 | +) |
| 79 | + |
| 80 | +target_include_directories(${PLUGIN_NAME} PRIVATE |
| 81 | + ${CMAKE_CURRENT_SOURCE_DIR} |
| 82 | + ${SHORTCUT_SRC_DIR} |
| 83 | + ${XCB_INCLUDE_DIRS} |
| 84 | + ${X11_INCLUDE_DIRS} |
| 85 | + ${WAYLAND_CLIENT_INCLUDE_DIRS} |
| 86 | +) |
| 87 | + |
| 88 | +# Install plugin |
| 89 | +install(TARGETS ${PLUGIN_NAME} |
| 90 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/deepin-service-manager) |
| 91 | + |
| 92 | +# Install configuration files |
| 93 | +install(FILES plugin-dde-shortcut.json |
| 94 | + DESTINATION share/deepin-service-manager/user) |
| 95 | + |
| 96 | +# Install DConfig configuration files |
| 97 | +# Shortcut configs use org.deepin.shortcut.json; gesture configs use org.deepin.gesture.json |
| 98 | +file(GLOB SHORTCUT_CONFIG_SUBDIRS |
| 99 | + "${CMAKE_CURRENT_SOURCE_DIR}/configs/org.deepin.dde.keybinding.shortcut.*" |
| 100 | +) |
| 101 | +file(GLOB GESTURE_CONFIG_SUBDIRS |
| 102 | + "${CMAKE_CURRENT_SOURCE_DIR}/configs/org.deepin.dde.keybinding.gesture.*" |
| 103 | +) |
| 104 | + |
| 105 | +# Install JSON config file for each subdirectory |
| 106 | +# Note: BASE must be the absolute path to the configs directory so that |
| 107 | +# dtk_add_config_meta_files can correctly calculate the relative path of subdirectories |
| 108 | +foreach(SUBDIR_PATH ${SHORTCUT_CONFIG_SUBDIRS}) |
| 109 | + dtk_add_config_meta_files( |
| 110 | + APPID "org.deepin.dde.keybinding" |
| 111 | + BASE "${CMAKE_CURRENT_SOURCE_DIR}/configs" |
| 112 | + FILES "${SUBDIR_PATH}/org.deepin.shortcut.json" |
| 113 | + ) |
| 114 | +endforeach() |
| 115 | + |
| 116 | +foreach(SUBDIR_PATH ${GESTURE_CONFIG_SUBDIRS}) |
| 117 | + dtk_add_config_meta_files( |
| 118 | + APPID "org.deepin.dde.keybinding" |
| 119 | + BASE "${CMAKE_CURRENT_SOURCE_DIR}/configs" |
| 120 | + FILES "${SUBDIR_PATH}/org.deepin.gesture.json" |
| 121 | + ) |
| 122 | +endforeach() |
| 123 | + |
| 124 | +install(FILES configs/org.deepin.dde.keybinding.ini |
| 125 | + DESTINATION share/deepin/org.deepin.dde.keybinding) |
| 126 | + |
| 127 | +# ============ i18n Translation Support ============ |
| 128 | +# Install i18n extraction tool |
| 129 | +install(PROGRAMS tools/extract_shortcuts_i18n.py |
| 130 | + DESTINATION bin |
| 131 | + RENAME extract_shortcuts_i18n) |
| 132 | + |
| 133 | +# Install CMake helper module |
| 134 | +install(FILES cmake/DdeShortcutI18n.cmake |
| 135 | + DESTINATION lib/${CMAKE_LIBRARY_ARCHITECTURE}/cmake/DdeShortcutI18n |
| 136 | + RENAME DdeShortcutI18nConfig.cmake) |
| 137 | + |
| 138 | +# i18n integration |
| 139 | +find_package(Qt6 REQUIRED COMPONENTS LinguistTools) |
| 140 | +include(cmake/DdeShortcutI18n.cmake) |
| 141 | + |
| 142 | +set(I18N_LANGUAGES |
| 143 | + "zh_CN" "zh_HK" "zh_TW" "en" "ast" "az" "bg" "bo" "ca" "cs" "da" |
| 144 | + "de" "el" "es" "et" "eu" "fa" "fi" "fr" "gl" "he" "hi" "hr" "hu" |
| 145 | + "hy" "id" "it" "ja" "ka" "kk" "ko" "ky" "lt" "lv" "ms" "nb" "ne" |
| 146 | + "nl" "pa" "pl" "pt_BR" "pt" "ro" "ru" "sk" "sl" "sq" "sr" "sv" "th" |
| 147 | + "tr" "ug" "uk" "vi" |
| 148 | +) |
| 149 | + |
| 150 | +dde_shortcut_add_translations( |
| 151 | + APP_ID "org.deepin.dde.keybinding" |
| 152 | + CONFIG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/configs" |
| 153 | + LANGUAGES ${I18N_LANGUAGES} |
| 154 | +) |
| 155 | + |
| 156 | +# subdirectory |
| 157 | +add_subdirectory(tools) |
| 158 | +add_subdirectory(dde-app-shortcuts) |
| 159 | + |
| 160 | +# ============ Debug Standalone Binary (Optional) ============ |
| 161 | +option(BUILD_SHORTCUT_DEBUG_BINARY "Build standalone debug binary for dde-shortcut" ON) |
| 162 | + |
| 163 | +if(BUILD_SHORTCUT_DEBUG_BINARY) |
| 164 | + message(STATUS "Building standalone debug binary: dde-shortcut-debug") |
| 165 | + |
| 166 | + # Create standalone executable (reuse common sources) |
| 167 | + add_executable(dde-shortcut-debug |
| 168 | + ${SHORTCUT_SRC_DIR}/main.cpp |
| 169 | + ${SHORTCUT_COMMON_SOURCES} |
| 170 | + # Reuse Wayland protocol files generated for plugin |
| 171 | + ${CMAKE_CURRENT_BINARY_DIR}/wayland-treeland-shortcut-manager-v2-protocol.c |
| 172 | + ${CMAKE_CURRENT_BINARY_DIR}/qwayland-treeland-shortcut-manager-v2.cpp |
| 173 | + ) |
| 174 | + |
| 175 | + # Enable AUTOMOC for debug binary |
| 176 | + set_target_properties(dde-shortcut-debug PROPERTIES AUTOMOC ON) |
| 177 | + |
| 178 | + # Add dependency on plugin to ensure protocol files are generated first |
| 179 | + add_dependencies(dde-shortcut-debug ${PLUGIN_NAME}) |
| 180 | + |
| 181 | + target_link_libraries(dde-shortcut-debug PRIVATE |
| 182 | + Qt6::Core |
| 183 | + Qt6::DBus |
| 184 | + Qt6::Gui |
| 185 | + Qt6::WaylandClient |
| 186 | + Dtk6::Core |
| 187 | + ${XCB_LIBRARIES} |
| 188 | + ${X11_LIBRARIES} |
| 189 | + ${WAYLAND_CLIENT_LIBRARIES} |
| 190 | + xcb-xtest # Explicitly link xcb-xtest |
| 191 | + ) |
| 192 | + |
| 193 | + target_include_directories(dde-shortcut-debug PRIVATE |
| 194 | + ${CMAKE_CURRENT_SOURCE_DIR} |
| 195 | + ${SHORTCUT_SRC_DIR} |
| 196 | + ${CMAKE_CURRENT_BINARY_DIR} # For generated Wayland headers |
| 197 | + ${XCB_INCLUDE_DIRS} |
| 198 | + ${X11_INCLUDE_DIRS} |
| 199 | + ${WAYLAND_CLIENT_INCLUDE_DIRS} |
| 200 | + ) |
| 201 | +endif() |
0 commit comments