├── .clang-format ├── .clang-tidy ├── .cmake-format.py ├── .codespellrc ├── .github └── workflows │ ├── build-external.yml │ ├── build.yml │ ├── dependency-bump.yml │ └── linters.yml ├── .gitignore ├── .gitreview ├── .krazy ├── .markdownlint.jsonc ├── .pre-commit-config.yaml ├── CMakeLists.txt ├── CMakePresets.json ├── CMakeUserPresets-example.json ├── ChangeLog ├── LICENSE.txt ├── LICENSES ├── Apache-2.0.txt ├── BSD-3-Clause.txt └── MIT.txt ├── README.md ├── REUSE.toml ├── appveyor.yml ├── cmake ├── CheckAtomic.cmake ├── CodeCoverage.cmake ├── ECM │ ├── find-modules │ │ ├── ECMFindModuleHelpersStub.cmake │ │ ├── FindWayland.cmake │ │ ├── FindWaylandProtocols.cmake │ │ ├── FindWaylandScanner.cmake │ │ ├── FindXCB.cmake │ │ └── FindXKB.cmake │ └── modules │ │ ├── ECMEnableSanitizers.cmake │ │ └── ECMFindModuleHelpers.cmake ├── FindMosquitto.cmake ├── FindWhereami.cmake └── dependencies.cmake ├── examples ├── CMakeLists.txt ├── filesystem │ ├── CMakeLists.txt │ ├── android │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── app │ │ │ ├── .gitignore │ │ │ ├── build.gradle.kts │ │ │ ├── proguard-rules.pro │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── .gitignore │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── assets │ │ │ │ ├── .gitignore │ │ │ │ └── android_robot.png │ │ │ │ └── res │ │ │ │ ├── drawable │ │ │ │ ├── ic_launcher_background.xml │ │ │ │ └── ic_launcher_foreground.xml │ │ │ │ ├── mipmap-anydpi │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── values-night │ │ │ │ └── themes.xml │ │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ └── themes.xml │ │ │ │ └── xml │ │ │ │ ├── backup_rules.xml │ │ │ │ └── data_extraction_rules.xml │ │ ├── build.gradle.kts │ │ ├── gradle.properties │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle.kts │ ├── assets │ │ └── text │ │ │ └── asset_text.txt │ └── filesystem.cpp ├── gui_window │ ├── CMakeLists.txt │ ├── android │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── app │ │ │ ├── .gitignore │ │ │ ├── build.gradle.kts │ │ │ ├── proguard-rules.pro │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── .gitignore │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── assets │ │ │ │ ├── .gitignore │ │ │ │ └── android_robot.png │ │ │ │ └── res │ │ │ │ ├── drawable │ │ │ │ ├── ic_launcher_background.xml │ │ │ │ └── ic_launcher_foreground.xml │ │ │ │ ├── mipmap-anydpi │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── values-night │ │ │ │ └── themes.xml │ │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ └── themes.xml │ │ │ │ └── xml │ │ │ │ ├── backup_rules.xml │ │ │ │ └── data_extraction_rules.xml │ │ ├── build.gradle.kts │ │ ├── gradle.properties │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle.kts │ └── gui_window.cpp └── mqtt_client │ ├── CMakeLists.txt │ └── mqtt_client.cpp ├── src ├── KDFoundation │ ├── CMakeLists.txt │ ├── cmake │ │ └── KDFoundationConfig.cmake.in │ ├── config.h │ ├── constexpr_sort.h │ ├── core_application.cpp │ ├── core_application.h │ ├── destruction_helpers.h │ ├── event.cpp │ ├── event.h │ ├── event_queue.h │ ├── event_receiver.cpp │ ├── event_receiver.h │ ├── file_descriptor_notifier.cpp │ ├── file_descriptor_notifier.h │ ├── formatters.h │ ├── hashutils.h │ ├── kdfoundation_global.h │ ├── logging.h │ ├── object.cpp │ ├── object.h │ ├── platform │ │ ├── abstract_platform_event_loop.cpp │ │ ├── abstract_platform_event_loop.h │ │ ├── abstract_platform_integration.h │ │ ├── abstract_platform_timer.h │ │ ├── linux │ │ │ ├── linux_platform_event_loop.cpp │ │ │ ├── linux_platform_event_loop.h │ │ │ ├── linux_platform_integration.cpp │ │ │ ├── linux_platform_integration.h │ │ │ ├── linux_platform_timer.cpp │ │ │ └── linux_platform_timer.h │ │ ├── macos │ │ │ ├── macos_platform_event_loop.h │ │ │ ├── macos_platform_event_loop.mm │ │ │ ├── macos_platform_integration.h │ │ │ ├── macos_platform_integration.mm │ │ │ ├── macos_platform_timer.h │ │ │ └── macos_platform_timer.mm │ │ └── win32 │ │ │ ├── win32_platform_event_loop.cpp │ │ │ ├── win32_platform_event_loop.h │ │ │ ├── win32_platform_integration.cpp │ │ │ ├── win32_platform_integration.h │ │ │ ├── win32_platform_timer.cpp │ │ │ └── win32_platform_timer.h │ ├── postman.cpp │ ├── postman.h │ ├── timer.cpp │ ├── timer.h │ ├── utils.h │ └── vector_helper.h ├── KDGui │ ├── CMakeLists.txt │ ├── abstract_clipboard.h │ ├── abstract_gui_platform_integration.h │ ├── abstract_platform_window.cpp │ ├── abstract_platform_window.h │ ├── cmake │ │ └── KDGuiConfig.cmake.in │ ├── config.h │ ├── gui_application.cpp │ ├── gui_application.h │ ├── gui_events.h │ ├── kdgui_global.h │ ├── kdgui_keys.h │ ├── platform │ │ ├── android │ │ │ ├── android_keyboard_map.cpp │ │ │ ├── android_keyboard_map.h │ │ │ ├── android_platform_event_loop.cpp │ │ │ ├── android_platform_event_loop.h │ │ │ ├── android_platform_integration.cpp │ │ │ ├── android_platform_integration.h │ │ │ ├── android_platform_window.cpp │ │ │ └── android_platform_window.h │ │ ├── cocoa │ │ │ ├── cocoa_platform_integration.h │ │ │ ├── cocoa_platform_integration.mm │ │ │ ├── cocoa_platform_integration_impl.h │ │ │ ├── cocoa_platform_integration_impl.mm │ │ │ ├── cocoa_platform_window.h │ │ │ └── cocoa_platform_window.mm │ │ ├── linux │ │ │ ├── common │ │ │ │ ├── linux_xkb.cpp │ │ │ │ ├── linux_xkb.h │ │ │ │ ├── linux_xkb_keyboard_map.cpp │ │ │ │ └── linux_xkb_keyboard_map.h │ │ │ ├── wayland │ │ │ │ ├── linux_wayland_clipboard.cpp │ │ │ │ ├── linux_wayland_clipboard.h │ │ │ │ ├── linux_wayland_platform_event_loop.cpp │ │ │ │ ├── linux_wayland_platform_event_loop.h │ │ │ │ ├── linux_wayland_platform_input.cpp │ │ │ │ ├── linux_wayland_platform_input.h │ │ │ │ ├── linux_wayland_platform_integration.cpp │ │ │ │ ├── linux_wayland_platform_integration.h │ │ │ │ ├── linux_wayland_platform_output.cpp │ │ │ │ ├── linux_wayland_platform_output.h │ │ │ │ ├── linux_wayland_platform_window.cpp │ │ │ │ └── linux_wayland_platform_window.h │ │ │ └── xcb │ │ │ │ ├── linux_xcb_clipboard.cpp │ │ │ │ ├── linux_xcb_clipboard.h │ │ │ │ ├── linux_xcb_platform_event_loop.cpp │ │ │ │ ├── linux_xcb_platform_event_loop.h │ │ │ │ ├── linux_xcb_platform_integration.cpp │ │ │ │ ├── linux_xcb_platform_integration.h │ │ │ │ ├── linux_xcb_platform_window.cpp │ │ │ │ ├── linux_xcb_platform_window.h │ │ │ │ ├── linux_xkb_keyboard.cpp │ │ │ │ └── linux_xkb_keyboard.h │ │ └── win32 │ │ │ ├── win32_gui_platform_integration.cpp │ │ │ ├── win32_gui_platform_integration.h │ │ │ ├── win32_keyboard_map.cpp │ │ │ ├── win32_keyboard_map.h │ │ │ ├── win32_platform_window.cpp │ │ │ ├── win32_platform_window.h │ │ │ ├── win32_utils.cpp │ │ │ └── win32_utils.h │ ├── position.h │ ├── window.cpp │ └── window.h ├── KDMqtt │ ├── CMakeLists.txt │ ├── cmake │ │ └── KDMqttConfig.cmake.in │ ├── kdmqtt_global.h │ ├── mosquitto_wrapper.h │ ├── mqtt.cpp │ └── mqtt.h └── KDUtils │ ├── CMakeLists.txt │ ├── bytearray.cpp │ ├── bytearray.h │ ├── cmake │ └── KDUtilsConfig.cmake.in │ ├── color.h │ ├── dir.cpp │ ├── dir.h │ ├── elapsedtimer.cpp │ ├── elapsedtimer.h │ ├── file.cpp │ ├── file.h │ ├── file_mapper.cpp │ ├── file_mapper.h │ ├── flags.h │ ├── kdutils_global.h │ ├── logging.cpp │ ├── logging.h │ ├── platform │ └── android │ │ ├── android_file.cpp │ │ └── android_file.h │ ├── tailwind_colors.h │ ├── url.cpp │ └── url.h └── tests ├── CMakeLists.txt └── auto ├── foundation ├── CMakeLists.txt ├── common │ └── signal_spy.h ├── constexpr_sort │ ├── CMakeLists.txt │ └── tst_constexpr_sort.cpp ├── core_application │ ├── CMakeLists.txt │ └── tst_core_application.cpp ├── destruction_helper │ ├── CMakeLists.txt │ └── tst_destruction_helper.cpp ├── event │ ├── CMakeLists.txt │ └── tst_event.cpp ├── event_queue │ ├── CMakeLists.txt │ └── tst_event_queue.cpp ├── linux_platform_event_loop │ ├── CMakeLists.txt │ └── tst_linux_platform_event_loop.cpp ├── macos_platform_event_loop │ ├── CMakeLists.txt │ └── tst_macos_platform_event_loop.cpp ├── object │ ├── CMakeLists.txt │ └── tst_object.cpp └── win32_platform_event_loop │ ├── CMakeLists.txt │ └── tst_win32_platform_event_loop.cpp ├── gui ├── CMakeLists.txt ├── linux_xcb_platform_window │ ├── CMakeLists.txt │ └── tst_linux_xcb_platform_window.cpp ├── position │ ├── CMakeLists.txt │ └── tst_position.cpp └── window │ ├── CMakeLists.txt │ └── tst_window.cpp ├── mqtt ├── CMakeLists.txt └── tst_mqtt.cpp └── utils ├── CMakeLists.txt ├── bytearray ├── CMakeLists.txt └── tst_bytearray.cpp ├── color ├── CMakeLists.txt └── tst_color.cpp ├── dir ├── CMakeLists.txt └── tst_dir.cpp ├── elapsedtimer ├── CMakeLists.txt └── tst_elapsedtimer.cpp ├── file ├── CMakeLists.txt └── tst_file.cpp ├── flags ├── CMakeLists.txt └── tst_flags.cpp ├── signal ├── CMakeLists.txt └── tst_signal.cpp ├── tailwind_colors ├── CMakeLists.txt └── tst_tailwind_colors.cpp └── url ├── CMakeLists.txt └── tst_url.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: WebKit 3 | Standard: Cpp11 4 | SortIncludes: false 5 | 6 | ColumnLimit: 0 7 | ContinuationIndentWidth: 8 8 | 9 | FixNamespaceComments: true 10 | NamespaceIndentation: None 11 | AlignAfterOpenBracket: true 12 | 13 | PointerBindsToType: false 14 | SpaceAfterTemplateKeyword: false 15 | 16 | AllowShortFunctionsOnASingleLine: Inline 17 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 18 | AlwaysBreakTemplateDeclarations: true 19 | BreakBeforeBinaryOperators: None 20 | 21 | SpaceBeforeCpp11BracedList: false 22 | BreakBeforeBraces: Custom 23 | BraceWrapping: 24 | AfterClass: true 25 | AfterControlStatement: false 26 | AfterEnum: false 27 | AfterFunction: true 28 | AfterNamespace: false 29 | AfterObjCDeclaration: false 30 | AfterStruct: false 31 | AfterUnion: false 32 | BeforeCatch: false 33 | BeforeElse: false 34 | IndentBraces: false 35 | 36 | CommentPragmas: '/\*(.+\n.+)+\*/' 37 | AttributeMacros: [KDFOUNDATION_API, KDGUI_API, KDUTILS_API] 38 | -------------------------------------------------------------------------------- /.clang-tidy: -------------------------------------------------------------------------------- 1 | --- 2 | Checks: '*, 3 | clang-analyzer-*, 4 | clang-diagnostic-*, 5 | -abseil-*, 6 | -altera-*, 7 | -android-*, 8 | -bugprone-suspicious-include, 9 | -clang-analyzer-alpha.core.CastToStruct, 10 | -clang-analyzer-alpha.deadcode.UnreachableCode, 11 | -clang-analyzer-alpha*, 12 | -clang-analyzer-core.CallAndMessage, 13 | -clang-analyzer-core.NonNullParamChecker, 14 | -clang-analyzer-cplusplus.NewDeleteLeaks, 15 | -clang-analyzer-optin.core.EnumCastOutOfRange, 16 | -clang-diagnostic-gnu-zero-variadic-macro-arguments, 17 | -cppcoreguidelines-*, 18 | -fuchsia-*, 19 | -google-*, 20 | -hicpp-*, 21 | -llvm-*, 22 | -llvm-include-order, 23 | -llvm-namespace-comment, 24 | -llvmlibc-*, 25 | -misc-include-cleaner, 26 | -misc-no-recursion, 27 | -misc-non-private-member-variables-in-classes, 28 | -modernize-loop-convert, 29 | -modernize-pass-by-value, 30 | -modernize-raw-string-literal, 31 | -modernize-return-braced-init-list, 32 | -modernize-use-bool-literals, 33 | -modernize-use-default-member-init, 34 | -modernize-use-default, 35 | -modernize-use-emplace, 36 | -modernize-use-equals-default, 37 | -modernize-use-override, 38 | -modernize-use-trailing-return-type, 39 | -modernize-use-using, 40 | -readability-braces-around-statements, 41 | -readability-else-after-return, 42 | -readability-function-cognitive-complexity, 43 | -readability-identifier-length, 44 | -readability-implicit-bool-cast, 45 | -readability-implicit-bool-conversion, 46 | -readability-magic-numbers, 47 | -readability-named-parameter, 48 | -readability-qualified-auto, 49 | -readability-uppercase-literal-suffix, 50 | -readabilty-namespace-comments' 51 | WarningsAsErrors: '' 52 | HeaderFilterRegex: '' 53 | CheckOptions: 54 | - key: cert-oop11-cpp.UseCERTSemantics 55 | value: '1' 56 | - key: modernize-loop-convert.MaxCopySize 57 | value: '16' 58 | - key: modernize-loop-convert.MinConfidence 59 | value: reasonable 60 | - key: modernize-loop-convert.NamingStyle 61 | value: CamelCase 62 | - key: modernize-pass-by-value.IncludeStyle 63 | value: llvm 64 | - key: modernize-replace-auto-ptr.IncludeStyle 65 | value: llvm 66 | - key: modernize-use-nullptr.NullMacros 67 | value: 'NULL' 68 | - key: readability-braces-around-statements.ShortStatementLines 69 | value: '3' 70 | - key: bugprone-easily-swappable-parameters.IgnoredParameterNames 71 | value: 'x;y' 72 | ... 73 | -------------------------------------------------------------------------------- /.codespellrc: -------------------------------------------------------------------------------- 1 | [codespell] 2 | skip = ./build-*,.git 3 | interactive = 3 4 | #ignore camelCase, regardless. also mixed case words with correct spelling 5 | ignore-regex = \b([a-z]+[A-Z0-9][a-z0-9]*|te|fo)\b 6 | -------------------------------------------------------------------------------- /.github/workflows/build-external.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | # Test on macOS with some dependencies provided externally by Homebrew. 6 | # Both to validate the CMake setup for using system dependencies and to have early warning 7 | # about incompatible changes in some fast-moving external libraries. 8 | name: Build against external 3rdparty 9 | 10 | on: 11 | push: 12 | branches: 13 | - main 14 | pull_request: 15 | branches: 16 | - main 17 | 18 | jobs: 19 | build: 20 | runs-on: ${{ matrix.os }} 21 | strategy: 22 | fail-fast: true 23 | matrix: 24 | os: 25 | - macos-latest 26 | shared: 27 | - ON 28 | - OFF 29 | 30 | steps: 31 | - name: Checkout sources 32 | uses: actions/checkout@v4 33 | 34 | - name: Install dependencies 35 | run: | 36 | brew tap KDAB/tap 37 | brew install fmt spdlog KDBindings mosquitto 38 | 39 | - name: Configure project 40 | run: > 41 | cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Debug -G Ninja 42 | -DKDUTILS_BUILD_TESTS=ON 43 | -DBUILD_SHARED_LIBS=${{ matrix.shared }} 44 | 45 | - name: Check if external dependencies were used 46 | run: | 47 | ! grep -q "KDBindings_DIR-NOTFOUND" ./build/CMakeCache.txt 48 | ! grep -q "spdlog_DIR-NOTFOUND" ./build/CMakeCache.txt 49 | ! grep -q "fmt_DIR-NOTFOUND" ./build/CMakeCache.txt 50 | 51 | - name: Build Project 52 | run: cmake --build ./build 53 | 54 | - name: Run tests 55 | run: ctest --test-dir ./build --output-on-failure 56 | -------------------------------------------------------------------------------- /.github/workflows/dependency-bump.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | on: 6 | workflow_dispatch: 7 | inputs: 8 | dependency: 9 | type: choice 10 | description: "Select an option" 11 | options: # 12 | - "Only print current and available versions" # don't change this one 13 | - spdlog 14 | - fmt 15 | - KDBindings 16 | - doctest 17 | 18 | name: bump dependencies 19 | 20 | env: 21 | PROJECT_NAME: KDUtils 22 | 23 | jobs: 24 | dependency-bump: 25 | runs-on: ubuntu-24.04 26 | steps: 27 | - name: Checkout sources 28 | uses: actions/checkout@v4 29 | 30 | - name: Checkout ci-release-tools 31 | run: | 32 | git clone https://github.com/KDABLabs/ci-release-tools.git 33 | 34 | - name: Configure Git committer 35 | run: | 36 | git config --global user.name "KDAB GitHub Actions" 37 | git config --global user.email "gh@kdab" 38 | 39 | - name: Print current and available versions 40 | if: inputs.dependency == 'Only print current and available versions' 41 | run: | 42 | python3 ./ci-release-tools/src/update_dependencies.py --print-dependency-versions --proj-name ${{ env.PROJECT_NAME }} --repo-path . 43 | env: 44 | GH_TOKEN: ${{ github.token }} 45 | 46 | - name: Bump dependency 47 | if: inputs.dependency != 'Only print current and available versions' 48 | run: | 49 | python3 ./ci-release-tools/src/update_dependencies.py --update-dependency ${{inputs.dependency}} --proj-name ${{ env.PROJECT_NAME }} --repo-path . --owner ${{ github.repository_owner }} 50 | env: 51 | GH_TOKEN: ${{ github.token }} 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .cache/ 2 | build/* 3 | CMakeUserPresets.json 4 | 5 | .vs/ 6 | .vscode/ 7 | .idea/ 8 | compile_commands.json 9 | out/ 10 | .DS_Store 11 | -------------------------------------------------------------------------------- /.gitreview: -------------------------------------------------------------------------------- 1 | [gerrit] 2 | host=codereview.kdab.com 3 | port=29418 4 | project=kdab/kdutils 5 | -------------------------------------------------------------------------------- /.krazy: -------------------------------------------------------------------------------- 1 | CHECKSETS c++ 2 | 3 | #KDAB-specific checks 4 | EXTRA kdabcopyright-reuse,kdabcontactus,fosslicense-reuse 5 | 6 | #exclude checks now being done by clazy or clang-tools 7 | EXCLUDE strings,explicit,normalize,passbyvalue,operators,nullstrcompare,nullstrassign,doublequote_chars,qobject,sigsandslots,staticobjects,dpointer 8 | #more to exclude 9 | EXCLUDE qminmax,captruefalse,typedefs,inline,constref,insecurenet 10 | EXCLUDE style 11 | 12 | SKIP .cmake-format.py 13 | #no need to check 3rdparty stuff 14 | SKIP /3rdparty/ 15 | #skip borrowed cmake code 16 | SKIP /cmake/CodeCoverage.cmake 17 | SKIP /cmake/ECM 18 | SKIP /tests/auto/gui/window/tst_window.cpp 19 | -------------------------------------------------------------------------------- /.markdownlint.jsonc: -------------------------------------------------------------------------------- 1 | { 2 | "default": true, 3 | "MD007": { 4 | "indent": 2, 5 | "start_indented": false 6 | }, 7 | "MD013": { 8 | "line_length": 100, 9 | "tables": false, 10 | "code_blocks": false 11 | }, 12 | "MD029": { 13 | "style": "ordered" 14 | }, 15 | "MD033": false 16 | } 17 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # See https://pre-commit.com for more information 2 | # See https://pre-commit.com/hooks.html for more hooks 3 | 4 | exclude: ^(cmake/ECM|cmake/CodeCoverage.cmake|cmake/CheckAtomic.cmake|.cmake-format.py) 5 | repos: 6 | - repo: https://github.com/pre-commit/pre-commit-hooks 7 | rev: v5.0.0 8 | hooks: 9 | - id: trailing-whitespace 10 | - id: end-of-file-fixer 11 | - id: check-added-large-files 12 | - id: check-case-conflict 13 | - id: check-yaml 14 | args: [--allow-multiple-documents] 15 | - id: check-json 16 | - repo: https://github.com/pre-commit/mirrors-clang-format 17 | rev: v20.1.0 18 | hooks: 19 | - id: clang-format 20 | - repo: https://github.com/codespell-project/codespell 21 | rev: v2.4.1 22 | hooks: 23 | - id: codespell 24 | - repo: https://github.com/cheshirekow/cmake-format-precommit 25 | rev: v0.6.13 26 | hooks: 27 | - id: cmake-lint 28 | - id: cmake-format 29 | - repo: https://github.com/DavidAnson/markdownlint-cli2 30 | rev: v0.17.2 31 | hooks: 32 | - id: markdownlint-cli2 33 | exclude: ^(3rdParty/|common/ui/resources/licenses/) 34 | files: \.(md|mdown|markdown)$ 35 | - repo: https://github.com/fsfe/reuse-tool 36 | rev: v5.0.2 37 | hooks: 38 | - id: reuse 39 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | * v1.0.0 (NOT RELEASED YET) 2 | - Initial Release 3 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | License 2 | ======= 3 | KDUtils is Copyright 2025 Klarälvdalens Datakonsult AB (KDAB), 4 | and is available under the terms of the MIT license. 5 | 6 | See REUSE.toml for licenses of included 3rdparty code. 7 | 8 | See the full license text in the LICENSES folder. 9 | -------------------------------------------------------------------------------- /LICENSES/BSD-3-Clause.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) . 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | 7 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | 9 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12 | -------------------------------------------------------------------------------- /LICENSES/MIT.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /REUSE.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | SPDX-PackageName = "KDUtils" 3 | SPDX-PackageSupplier = "Paul Lemire " 4 | SPDX-PackageDownloadLocation = "https://github.com/KDAB/KDUtils" 5 | 6 | #misc source code 7 | [[annotations]] 8 | path = ["CMakePresets.json", "CMakeUserPresets-example.json"] 9 | precedence = "aggregate" 10 | SPDX-FileCopyrightText = "Klarälvdalens Datakonsult AB, a KDAB Group company " 11 | SPDX-License-Identifier = "MIT" 12 | 13 | #misc documentation 14 | [[annotations]] 15 | path = ["ChangeLog", "README.md"] 16 | precedence = "aggregate" 17 | SPDX-FileCopyrightText = "Klarälvdalens Datakonsult AB, a KDAB Group company " 18 | SPDX-License-Identifier = "MIT" 19 | 20 | #misc config files 21 | [[annotations]] 22 | path = [".pre-commit-config.yaml", ".codespellrc", ".krazy", ".cmake-format.py", ".clang-format", ".clang-tidy", "**.gitignore", ".gitreview", ".markdownlint.jsonc", "appveyor.yml", "REUSE.toml"] 23 | precedence = "aggregate" 24 | SPDX-FileCopyrightText = "Klarälvdalens Datakonsult AB, a KDAB Group company " 25 | SPDX-License-Identifier = "BSD-3-Clause" 26 | 27 | #android build system files 28 | [[annotations]] 29 | path = ["**gradle-wrapper.jar", "**gradle-wrapper.properties", "**gradlew*"] 30 | precedence = "aggregate" 31 | SPDX-FileCopyrightText = "Gradle, Inc." 32 | SPDX-License-Identifier = "Apache-2.0" 33 | 34 | #artwork 35 | [[annotations]] 36 | path = ["**.webp", "**.png", "**ic_launcher*.xml"] 37 | precedence = "aggregate" 38 | SPDX-FileCopyrightText = "2025 Klarälvdalens Datakonsult AB, a KDAB Group company " 39 | SPDX-License-Identifier = "MIT" 40 | 41 | #example assets 42 | [[annotations]] 43 | path = ["examples/filesystem/assets/text**"] 44 | precedence = "aggregate" 45 | SPDX-FileCopyrightText = "2025 Klarälvdalens Datakonsult AB, a KDAB Group company " 46 | SPDX-License-Identifier = "MIT" 47 | 48 | #3rdparty 49 | [[annotations]] 50 | path = "cmake/CodeCoverage.cmake" 51 | precedence = "aggregate" 52 | SPDX-FileCopyrightText = "Copyright (c) 2012 - 2017, Lars Bilke" 53 | SPDX-License-Identifier = "BSD-3-Clause" 54 | 55 | [[annotations]] 56 | path = ["cmake/ECM/modules/**", "cmake/ECM/find-modules/**"] 57 | precedence = "aggregate" 58 | SPDX-FileCopyrightText = "The KDE Project" 59 | SPDX-License-Identifier = "BSD-3-Clause" 60 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | #---------------------------------# 2 | # general configuration # 3 | #---------------------------------# 4 | 5 | # version format 6 | version: 1.0.{build}-{branch} 7 | 8 | # branches to build 9 | branches: 10 | except: 11 | - gh-pages 12 | 13 | # Do not build on tags (GitHub and BitBucket) 14 | skip_tags: false 15 | 16 | #---------------------------------# 17 | # environment configuration # 18 | #---------------------------------# 19 | 20 | # Build worker image 21 | image: 22 | - Ubuntu 23 | - macos 24 | - Visual Studio 2019 25 | 26 | # scripts that are called at very beginning, before repo cloning 27 | init: 28 | - git config --global core.autocrlf input 29 | 30 | #---------------------------------# 31 | # build configuration # 32 | #---------------------------------# 33 | 34 | # build platform, i.e. x86, x64, Any CPU. This setting is optional. 35 | platform: 36 | - x64 37 | 38 | # build Configuration, i.e. Debug, Release, etc. 39 | configuration: 40 | - Debug 41 | 42 | install: 43 | - sh: if [ "`uname -s`" = "Darwin" ]; then brew install ninja; fi 44 | 45 | before_build: 46 | - cmd: call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" 47 | 48 | build_script: 49 | - mkdir build 50 | - cd build 51 | - cmake --preset=debug -DKDUTILS_CODE_COVERAGE=False -B . .. 52 | - cmake --build . 53 | - ctest --test-dir . 54 | 55 | # to disable automatic builds 56 | #build: off 57 | 58 | #---------------------------------# 59 | # tests configuration # 60 | #---------------------------------# 61 | 62 | # to disable automatic tests 63 | test: off 64 | 65 | 66 | #---------------------------------# 67 | # deployment configuration # 68 | #---------------------------------# 69 | 70 | deploy: off 71 | 72 | #---------------------------------# 73 | # notifications # 74 | #---------------------------------# 75 | notifications: 76 | # Email 77 | - provider: Email 78 | to: 79 | - allen.winter@kdab.com 80 | on_build_success: false 81 | on_build_failure: true 82 | -------------------------------------------------------------------------------- /cmake/ECM/find-modules/ECMFindModuleHelpersStub.cmake: -------------------------------------------------------------------------------- 1 | include(${CMAKE_CURRENT_LIST_DIR}/../modules/ECMFindModuleHelpers.cmake) 2 | -------------------------------------------------------------------------------- /cmake/ECM/find-modules/FindWaylandProtocols.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2019 Vlad Zahorodnii 2 | # 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | #[=======================================================================[.rst: 6 | FindWaylandProtocols 7 | -------------------- 8 | 9 | Try to find wayland-protocols on a Unix system. 10 | 11 | This will define the following variables: 12 | 13 | ``WaylandProtocols_FOUND`` 14 | True if (the requested version of) wayland-protocols is available 15 | ``WaylandProtocols_VERSION`` 16 | The version of wayland-protocols 17 | ``WaylandProtocols_DATADIR`` 18 | The wayland protocols data directory 19 | #]=======================================================================] 20 | 21 | find_package(PkgConfig QUIET) 22 | pkg_check_modules(PKG_wayland_protocols QUIET wayland-protocols) 23 | 24 | set(WaylandProtocols_VERSION ${PKG_wayland_protocols_VERSION}) 25 | pkg_get_variable(WaylandProtocols_DATADIR wayland-protocols pkgdatadir) 26 | 27 | include(FindPackageHandleStandardArgs) 28 | find_package_handle_standard_args(WaylandProtocols 29 | FOUND_VAR WaylandProtocols_FOUND 30 | REQUIRED_VARS WaylandProtocols_DATADIR 31 | VERSION_VAR WaylandProtocols_VERSION 32 | ) 33 | 34 | include(FeatureSummary) 35 | set_package_properties(WaylandProtocols PROPERTIES 36 | DESCRIPTION "Specifications of extended Wayland protocols" 37 | URL "https://wayland.freedesktop.org/" 38 | ) 39 | -------------------------------------------------------------------------------- /cmake/FindMosquitto.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Marco Thaller 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | find_file( 12 | MOSQUITTO_HEADER 13 | NAMES mosquitto.h 14 | PATHS /usr/include 15 | /usr/local/include 16 | /usr/local/opt/mosquitto/include 17 | $ENV{PROGRAMFILES}/mosquitto/devel 18 | $ENV{PROGRAMFILES\(X86\)}/mosquitto/devel 19 | ) 20 | 21 | if(UNIX) 22 | find_library( 23 | MOSQUITTO_LIBRARY 24 | NAMES mosquitto 25 | PATHS /usr/lib /usr/local/lib /usr/local/opt/mosquitto/lib 26 | ) 27 | 28 | if(MOSQUITTO_HEADER AND MOSQUITTO_LIBRARY) 29 | set(Mosquitto_FOUND TRUE) 30 | endif() 31 | endif() 32 | 33 | if(WIN32) 34 | find_file( 35 | MOSQUITTO_DLL 36 | NAMES mosquitto.dll 37 | PATHS $ENV{PROGRAMFILES}/mosquitto $ENV{PROGRAMFILES\(X86\)}/mosquitto 38 | ) 39 | 40 | find_library( 41 | MOSQUITTO_LIBRARY 42 | NAMES mosquitto 43 | PATHS $ENV{PROGRAMFILES}/mosquitto/devel $ENV{PROGRAMFILES\(X86\)}/mosquitto/devel 44 | ) 45 | 46 | file(GLOB MOSQUITTO_RUNTIME_DLLS "$ENV{PROGRAMFILES}/mosquitto/*.dll" "$ENV{PROGRAMFILES\(X86\)}/mosquitto/*.dll") 47 | 48 | if(MOSQUITTO_HEADER 49 | AND MOSQUITTO_DLL 50 | AND MOSQUITTO_LIBRARY 51 | ) 52 | set(Mosquitto_FOUND TRUE) 53 | endif() 54 | endif() 55 | 56 | if(Mosquitto_FOUND) 57 | cmake_path(GET MOSQUITTO_HEADER PARENT_PATH MOSQUITTO_INCLUDE_DIRECTORY) 58 | 59 | add_library(Mosquitto::Mosquitto SHARED IMPORTED) 60 | 61 | if(UNIX) 62 | set_target_properties( 63 | Mosquitto::Mosquitto PROPERTIES IMPORTED_LOCATION "${MOSQUITTO_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES 64 | "${MOSQUITTO_INCLUDE_DIRECTORY}" 65 | ) 66 | endif() 67 | 68 | if(WIN32) 69 | set_target_properties( 70 | Mosquitto::Mosquitto 71 | PROPERTIES IMPORTED_IMPLIB "${MOSQUITTO_LIBRARY}" 72 | IMPORTED_LOCATION "${MOSQUITTO_DLL}" 73 | INTERFACE_INCLUDE_DIRECTORIES "${MOSQUITTO_INCLUDE_DIRECTORY}" 74 | ) 75 | endif() 76 | endif() 77 | -------------------------------------------------------------------------------- /cmake/FindWhereami.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Nicolas Guichard 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | find_library(WHEREAMI_LIB whereami) 12 | find_file(WHEREAMI_HEADER whereami.h) 13 | if(WHEREAMI_LIB AND WHEREAMI_HEADER) 14 | cmake_path(GET WHEREAMI_HEADER PARENT_PATH WHEREAMI_INCLUDE_DIRECTORIES) 15 | 16 | add_library(whereami::whereami UNKNOWN IMPORTED) 17 | set_target_properties( 18 | whereami::whereami PROPERTIES IMPORTED_LOCATION ${WHEREAMI_LIB} INTERFACE_INCLUDE_DIRECTORIES 19 | ${WHEREAMI_INCLUDE_DIRECTORIES} 20 | ) 21 | set(Whereami_FOUND TRUE) 22 | endif() 23 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # 5 | # SPDX-License-Identifier: MIT 6 | # 7 | # Contact KDAB at for commercial licensing options. 8 | # 9 | 10 | add_subdirectory(filesystem) 11 | add_subdirectory(gui_window) 12 | 13 | if(KDUTILS_BUILD_MQTT_SUPPORT) 14 | file(DOWNLOAD https://test.mosquitto.org/ssl/mosquitto.org.crt ${CMAKE_BINARY_DIR}/mosquitto.org.crt) 15 | add_subdirectory(mqtt_client) 16 | endif() 17 | -------------------------------------------------------------------------------- /examples/filesystem/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # 5 | # SPDX-License-Identifier: MIT 6 | # 7 | # Contact KDAB at for commercial licensing options. 8 | # 9 | 10 | project(filesystem_example LANGUAGES CXX) 11 | 12 | add_executable( 13 | ${PROJECT_NAME} 14 | filesystem.cpp 15 | ) 16 | 17 | add_custom_command( 18 | TARGET ${PROJECT_NAME} 19 | POST_BUILD 20 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/assets 21 | $/../assets 22 | COMMENT "Copying assets from ${CMAKE_CURRENT_SOURCE_DIR}/assets" 23 | ) 24 | 25 | target_link_libraries( 26 | ${PROJECT_NAME} KDGui 27 | ) 28 | -------------------------------------------------------------------------------- /examples/filesystem/android/.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle 2 | /.idea 3 | /local.properties 4 | -------------------------------------------------------------------------------- /examples/filesystem/android/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # 5 | # SPDX-License-Identifier: MIT 6 | # 7 | # Contact KDAB at for commercial licensing options. 8 | # 9 | 10 | cmake_minimum_required(VERSION 3.18.1) 11 | 12 | file(TO_CMAKE_PATH "${ANDROID_NDK}" ANDROID_NDK_PATH) 13 | 14 | set(APP_GLUE_DIR ${ANDROID_NDK_PATH}/sources/android/native_app_glue) 15 | include_directories(${APP_GLUE_DIR}) 16 | add_library( 17 | app-glue STATIC 18 | ${APP_GLUE_DIR}/android_native_app_glue.c 19 | ) 20 | 21 | set(CMAKE_CXX_STANDARD 20) 22 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 23 | 24 | include(FetchContent) 25 | 26 | if(NOT KDUtils_FOUND) 27 | message(STATUS "KDUtils was not found. Fetching from git") 28 | set(FETCHCONTENT_SOURCE_DIR_KDUTILS ${CMAKE_CURRENT_SOURCE_DIR}/../../..) 29 | FetchContent_Declare( 30 | KDUtils 31 | GIT_REPOSITORY https://github.com/KDAB/KDUtils.git 32 | GIT_TAG main 33 | ) 34 | 35 | option(KDUTILS_BUILD_TESTS "Build the tests" OFF) 36 | 37 | FetchContent_MakeAvailable(KDUtils) 38 | endif() 39 | 40 | project("filesystem") 41 | 42 | set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) 43 | set(CMAKE_FIND_DEBUG_MODE TRUE) 44 | 45 | add_library( 46 | # Sets the name of the library. 47 | filesystem 48 | # Sets the library as a shared library. 49 | SHARED 50 | # Provides a relative path to your source file(s). 51 | ../filesystem.cpp 52 | ) 53 | 54 | target_compile_definitions(filesystem PRIVATE PLATFORM_ANDROID) 55 | 56 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -DVK_USE_PLATFORM_ANDROID_KHR") 57 | 58 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate") 59 | 60 | target_link_libraries( 61 | filesystem 62 | nativewindow 63 | app-glue 64 | log 65 | android 66 | KDFoundation 67 | KDGui 68 | KDUtils 69 | spdlog 70 | ) 71 | -------------------------------------------------------------------------------- /examples/filesystem/android/app/.gitignore: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # 5 | # SPDX-License-Identifier: BSD-3-Clause 6 | # 7 | # Contact KDAB at for commercial licensing options. 8 | # 9 | /build 10 | /.cxx 11 | -------------------------------------------------------------------------------- /examples/filesystem/android/app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | 6 | SPDX-License-Identifier: MIT 7 | 8 | Contact KDAB at for commercial licensing options. 9 | */ 10 | plugins { 11 | id("com.android.application") 12 | } 13 | 14 | android { 15 | namespace = "com.kdab.filesystem" 16 | compileSdk = 34 17 | 18 | defaultConfig { 19 | ndk { 20 | abiFilters += mutableSetOf("arm64-v8a") 21 | } 22 | applicationId = "com.kdab.filesystem" 23 | minSdk = 32 24 | targetSdk = 32 25 | versionCode = 1 26 | versionName = "1.0" 27 | 28 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 29 | } 30 | 31 | buildTypes { 32 | release { 33 | isMinifyEnabled = false 34 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 35 | } 36 | } 37 | compileOptions { 38 | sourceCompatibility = JavaVersion.VERSION_1_8 39 | targetCompatibility = JavaVersion.VERSION_1_8 40 | } 41 | buildFeatures { 42 | prefab = true 43 | } 44 | externalNativeBuild { 45 | cmake { 46 | path = file("../CMakeLists.txt") 47 | version = "3.22.1" 48 | } 49 | } 50 | ndkVersion = "26.1.10909125" 51 | } 52 | 53 | dependencies { 54 | 55 | implementation("androidx.appcompat:appcompat:1.6.1") 56 | implementation("com.google.android.material:material:1.11.0") 57 | implementation("androidx.games:games-activity:1.2.2") 58 | testImplementation("junit:junit:4.13.2") 59 | androidTestImplementation("androidx.test.ext:junit:1.1.5") 60 | androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") 61 | } 62 | 63 | 64 | // Task to copy files from outer project to android asset folders 65 | 66 | // Task to copy text files 67 | tasks.register("copyText") { 68 | from("../../assets/text") 69 | into("src/main/assets/text") 70 | } 71 | 72 | // Ensure the copy task runs before the build task 73 | tasks.named("preBuild") { 74 | dependsOn("copyText") 75 | } 76 | -------------------------------------------------------------------------------- /examples/filesystem/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # 5 | # SPDX-License-Identifier: MIT 6 | # 7 | # Contact KDAB at for commercial licensing options. 8 | # 9 | # Add project specific ProGuard rules here. 10 | # You can control the set of applied configuration files using the 11 | # proguardFiles setting in build.gradle. 12 | # 13 | # For more details, see 14 | # http://developer.android.com/guide/developing/tools/proguard.html 15 | 16 | # If your project uses WebView with JS, uncomment the following 17 | # and specify the fully qualified class name to the JavaScript interface 18 | # class: 19 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 20 | # public *; 21 | #} 22 | 23 | # Uncomment this to preserve the line number information for 24 | # debugging stack traces. 25 | #-keepattributes SourceFile,LineNumberTable 26 | 27 | # If you keep the line number information, uncomment this to 28 | # hide the original source file name. 29 | #-renamesourcefileattribute SourceFile 30 | -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/.gitignore: -------------------------------------------------------------------------------- 1 | /shaders/ 2 | -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 10 | 12 | 13 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/assets/.gitignore: -------------------------------------------------------------------------------- 1 | /text/ 2 | -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/assets/android_robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/filesystem/android/app/src/main/assets/android_robot.png -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | 31 | -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/mipmap-anydpi/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/filesystem/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/filesystem/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/filesystem/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/filesystem/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/filesystem/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/filesystem/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/filesystem/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/filesystem/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/filesystem/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/filesystem/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 25 | 26 | -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | #FFBB86FC 12 | #FF6200EE 13 | #FF3700B3 14 | #FF03DAC5 15 | #FF018786 16 | #FF000000 17 | #FFFFFFFF 18 | 19 | -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 10 | KDUtils Filesystem Example 11 | 12 | -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 11 | 24 | 25 | -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/xml/backup_rules.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 21 | 22 | -------------------------------------------------------------------------------- /examples/filesystem/android/app/src/main/res/xml/data_extraction_rules.xml: -------------------------------------------------------------------------------- 1 | 14 | 15 | 16 | 20 | 21 | 27 | 28 | -------------------------------------------------------------------------------- /examples/filesystem/android/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | 6 | SPDX-License-Identifier: MIT 7 | 8 | Contact KDAB at for commercial licensing options. 9 | */ 10 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 11 | plugins { 12 | id("com.android.application") version "8.7.3" apply false 13 | } 14 | -------------------------------------------------------------------------------- /examples/filesystem/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # 5 | # SPDX-License-Identifier: MIT 6 | # 7 | # Contact KDAB at for commercial licensing options. 8 | # 9 | # Project-wide Gradle settings. 10 | # IDE (e.g. Android Studio) users: 11 | # Gradle settings configured through the IDE *will override* 12 | # any settings specified in this file. 13 | # For more details on how to configure your build environment visit 14 | # http://www.gradle.org/docs/current/userguide/build_environment.html 15 | # Specifies the JVM arguments used for the daemon process. 16 | # The setting is particularly useful for tweaking memory settings. 17 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 18 | # When configured, Gradle will run in incubating parallel mode. 19 | # This option should only be used with decoupled projects. More details, visit 20 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 21 | # org.gradle.parallel=true 22 | # AndroidX package structure to make it clearer which packages are bundled with the 23 | # Android operating system, and which are packaged with your app's APK 24 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 25 | android.useAndroidX=true 26 | # Enables namespacing of each library's R class so that its R class includes only the 27 | # resources declared in the library itself and none from the library's dependencies, 28 | # thereby reducing the size of the R class for that library 29 | android.nonTransitiveRClass=true 30 | -------------------------------------------------------------------------------- /examples/filesystem/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /examples/filesystem/android/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | 6 | SPDX-License-Identifier: MIT 7 | 8 | Contact KDAB at for commercial licensing options. 9 | */ 10 | pluginManagement { 11 | repositories { 12 | google() 13 | mavenCentral() 14 | gradlePluginPortal() 15 | } 16 | } 17 | dependencyResolutionManagement { 18 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 19 | repositories { 20 | google() 21 | mavenCentral() 22 | } 23 | } 24 | 25 | rootProject.name = "filesystem" 26 | include(":app") 27 | -------------------------------------------------------------------------------- /examples/filesystem/assets/text/asset_text.txt: -------------------------------------------------------------------------------- 1 | This text originally came from the file asset_text.txt 2 | -------------------------------------------------------------------------------- /examples/gui_window/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # 5 | # SPDX-License-Identifier: MIT 6 | # 7 | # Contact KDAB at for commercial licensing options. 8 | # 9 | 10 | project(gui_window_example LANGUAGES CXX) 11 | 12 | add_executable( 13 | ${PROJECT_NAME} 14 | gui_window.cpp 15 | ) 16 | 17 | target_link_libraries( 18 | ${PROJECT_NAME} KDGui 19 | ) 20 | -------------------------------------------------------------------------------- /examples/gui_window/android/.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle 2 | /.idea 3 | /local.properties 4 | -------------------------------------------------------------------------------- /examples/gui_window/android/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # 5 | # SPDX-License-Identifier: MIT 6 | # 7 | # Contact KDAB at for commercial licensing options. 8 | # 9 | cmake_minimum_required(VERSION 3.18.1) 10 | 11 | file(TO_CMAKE_PATH "${ANDROID_NDK}" ANDROID_NDK_PATH) 12 | 13 | set(APP_GLUE_DIR ${ANDROID_NDK_PATH}/sources/android/native_app_glue) 14 | include_directories(${APP_GLUE_DIR}) 15 | add_library( 16 | app-glue STATIC 17 | ${APP_GLUE_DIR}/android_native_app_glue.c 18 | ) 19 | 20 | set(CMAKE_CXX_STANDARD 20) 21 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 22 | 23 | include(FetchContent) 24 | 25 | if(NOT KDUtils_FOUND) 26 | message(STATUS "KDUtils was not found. Fetching from git") 27 | set(FETCHCONTENT_SOURCE_DIR_KDUTILS ${CMAKE_CURRENT_SOURCE_DIR}/../../..) 28 | FetchContent_Declare( 29 | KDUtils 30 | GIT_REPOSITORY https://github.com/KDAB/KDUtils.git 31 | GIT_TAG main 32 | ) 33 | 34 | option(KDUTILS_BUILD_TESTS "Build the tests" OFF) 35 | 36 | FetchContent_MakeAvailable(KDUtils) 37 | endif() 38 | 39 | project("gui_window") 40 | 41 | set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) 42 | set(CMAKE_FIND_DEBUG_MODE TRUE) 43 | 44 | add_library( 45 | # Sets the name of the library. 46 | gui_window 47 | # Sets the library as a shared library. 48 | SHARED 49 | # Provides a relative path to your source file(s). 50 | ../gui_window.cpp 51 | ) 52 | 53 | target_include_directories( 54 | gui_window 55 | PRIVATE "../" 56 | ) 57 | 58 | target_compile_definitions(gui_window PRIVATE PLATFORM_ANDROID) 59 | 60 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -DVK_USE_PLATFORM_ANDROID_KHR") 61 | 62 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate") 63 | 64 | target_link_libraries( 65 | # Specifies the target library. 66 | gui_window 67 | vulkan 68 | nativewindow 69 | app-glue 70 | log 71 | android 72 | KDFoundation 73 | KDGui 74 | KDUtils 75 | spdlog 76 | ) 77 | -------------------------------------------------------------------------------- /examples/gui_window/android/app/.gitignore: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # 5 | # SPDX-License-Identifier: BSD-3-Clause 6 | # 7 | # Contact KDAB at for commercial licensing options. 8 | # 9 | /build 10 | /.cxx 11 | -------------------------------------------------------------------------------- /examples/gui_window/android/app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | 6 | SPDX-License-Identifier: MIT 7 | 8 | Contact KDAB at for commercial licensing options. 9 | */ 10 | plugins { 11 | id("com.android.application") 12 | } 13 | 14 | android { 15 | namespace = "com.kdab.gui_window" 16 | compileSdk = 34 17 | 18 | defaultConfig { 19 | ndk { 20 | abiFilters += mutableSetOf("arm64-v8a") 21 | } 22 | applicationId = "com.kdab.gui_window" 23 | minSdk = 32 24 | targetSdk = 32 25 | versionCode = 1 26 | versionName = "1.0" 27 | 28 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 29 | } 30 | 31 | buildTypes { 32 | release { 33 | isMinifyEnabled = false 34 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 35 | } 36 | } 37 | compileOptions { 38 | sourceCompatibility = JavaVersion.VERSION_1_8 39 | targetCompatibility = JavaVersion.VERSION_1_8 40 | } 41 | buildFeatures { 42 | prefab = true 43 | } 44 | externalNativeBuild { 45 | cmake { 46 | path = file("../CMakeLists.txt") 47 | version = "3.22.1" 48 | } 49 | } 50 | ndkVersion = "26.1.10909125" 51 | } 52 | 53 | dependencies { 54 | 55 | implementation("androidx.appcompat:appcompat:1.6.1") 56 | implementation("com.google.android.material:material:1.11.0") 57 | implementation("androidx.games:games-activity:1.2.2") 58 | testImplementation("junit:junit:4.13.2") 59 | androidTestImplementation("androidx.test.ext:junit:1.1.5") 60 | androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") 61 | } 62 | -------------------------------------------------------------------------------- /examples/gui_window/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # 5 | # SPDX-License-Identifier: MIT 6 | # 7 | # Contact KDAB at for commercial licensing options. 8 | # 9 | # Add project specific ProGuard rules here. 10 | # You can control the set of applied configuration files using the 11 | # proguardFiles setting in build.gradle. 12 | # 13 | # For more details, see 14 | # http://developer.android.com/guide/developing/tools/proguard.html 15 | 16 | # If your project uses WebView with JS, uncomment the following 17 | # and specify the fully qualified class name to the JavaScript interface 18 | # class: 19 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 20 | # public *; 21 | #} 22 | 23 | # Uncomment this to preserve the line number information for 24 | # debugging stack traces. 25 | #-keepattributes SourceFile,LineNumberTable 26 | 27 | # If you keep the line number information, uncomment this to 28 | # hide the original source file name. 29 | #-renamesourcefileattribute SourceFile 30 | -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/.gitignore: -------------------------------------------------------------------------------- 1 | /shaders/ 2 | -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 10 | 12 | 13 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/assets/.gitignore: -------------------------------------------------------------------------------- 1 | /fonts/ 2 | /shaders/ 3 | /textures/ 4 | -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/assets/android_robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/gui_window/android/app/src/main/assets/android_robot.png -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | 31 | -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/mipmap-anydpi/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/gui_window/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/gui_window/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/gui_window/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/gui_window/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/gui_window/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/gui_window/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/gui_window/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/gui_window/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/gui_window/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDAB/KDUtils/406dd6c5243fc0fc6bf61f60e719dd6cefea4224/examples/gui_window/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 25 | 26 | -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | #FFBB86FC 12 | #FF6200EE 13 | #FF3700B3 14 | #FF03DAC5 15 | #FF018786 16 | #FF000000 17 | #FFFFFFFF 18 | 19 | -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 10 | KDUtils Gui Window 11 | 12 | -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 11 | 24 | 25 | -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/xml/backup_rules.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 21 | 22 | -------------------------------------------------------------------------------- /examples/gui_window/android/app/src/main/res/xml/data_extraction_rules.xml: -------------------------------------------------------------------------------- 1 | 14 | 15 | 16 | 20 | 21 | 27 | 28 | -------------------------------------------------------------------------------- /examples/gui_window/android/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | 6 | SPDX-License-Identifier: MIT 7 | 8 | Contact KDAB at for commercial licensing options. 9 | */ 10 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 11 | plugins { 12 | id("com.android.application") version "8.7.3" apply false 13 | } 14 | -------------------------------------------------------------------------------- /examples/gui_window/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # 5 | # SPDX-License-Identifier: MIT 6 | # 7 | # Contact KDAB at for commercial licensing options. 8 | # 9 | # Project-wide Gradle settings. 10 | # IDE (e.g. Android Studio) users: 11 | # Gradle settings configured through the IDE *will override* 12 | # any settings specified in this file. 13 | # For more details on how to configure your build environment visit 14 | # http://www.gradle.org/docs/current/userguide/build_environment.html 15 | # Specifies the JVM arguments used for the daemon process. 16 | # The setting is particularly useful for tweaking memory settings. 17 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 18 | # When configured, Gradle will run in incubating parallel mode. 19 | # This option should only be used with decoupled projects. More details, visit 20 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 21 | # org.gradle.parallel=true 22 | # AndroidX package structure to make it clearer which packages are bundled with the 23 | # Android operating system, and which are packaged with your app's APK 24 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 25 | android.useAndroidX=true 26 | # Enables namespacing of each library's R class so that its R class includes only the 27 | # resources declared in the library itself and none from the library's dependencies, 28 | # thereby reducing the size of the R class for that library 29 | android.nonTransitiveRClass=true 30 | -------------------------------------------------------------------------------- /examples/gui_window/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /examples/gui_window/android/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | 6 | SPDX-License-Identifier: MIT 7 | 8 | Contact KDAB at for commercial licensing options. 9 | */ 10 | pluginManagement { 11 | repositories { 12 | google() 13 | mavenCentral() 14 | gradlePluginPortal() 15 | } 16 | } 17 | dependencyResolutionManagement { 18 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 19 | repositories { 20 | google() 21 | mavenCentral() 22 | } 23 | } 24 | 25 | rootProject.name = "gui_window" 26 | include(":app") 27 | -------------------------------------------------------------------------------- /examples/gui_window/gui_window.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Miłosz Kosobucki 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | class ExampleWindow : public KDGui::Window 18 | { 19 | void mouseMoveEvent(KDGui::MouseMoveEvent *ev) override 20 | { 21 | SPDLOG_INFO("{}() buttons = {} at pos = ({}, {})", 22 | __FUNCTION__, 23 | ev->buttons().toInt(), 24 | ev->xPos(), 25 | ev->yPos()); 26 | } 27 | 28 | void mousePressEvent(KDGui::MousePressEvent *ev) override 29 | { 30 | SPDLOG_INFO("{}() buttons = {} at pos = ({}, {})", 31 | __FUNCTION__, 32 | ev->buttons().toInt(), 33 | ev->xPos(), 34 | ev->yPos()); 35 | } 36 | 37 | void mouseReleaseEvent(KDGui::MouseReleaseEvent *ev) override 38 | { 39 | SPDLOG_INFO("{}() buttons = {} at pos = ({}, {})", 40 | __FUNCTION__, 41 | ev->buttons().toInt(), 42 | ev->xPos(), 43 | ev->yPos()); 44 | } 45 | 46 | void mouseWheelEvent(KDGui::MouseWheelEvent *ev) override 47 | { 48 | SPDLOG_INFO("{}() xDelta = {} yDelta = {}", 49 | __FUNCTION__, 50 | ev->xDelta(), 51 | ev->yDelta()); 52 | } 53 | 54 | void keyPressEvent(KDGui::KeyPressEvent *ev) override 55 | { 56 | SPDLOG_INFO("{}() key = {}", __FUNCTION__, static_cast(ev->key())); 57 | } 58 | 59 | void keyReleaseEvent(KDGui::KeyReleaseEvent *ev) override 60 | { 61 | SPDLOG_INFO("{}() key = {}", __FUNCTION__, static_cast(ev->key())); 62 | } 63 | }; 64 | 65 | int main() // NOLINT(bugprone-exception-escape) 66 | { 67 | KDGui::GuiApplication app; 68 | app.applicationName = "KDGui window example"; 69 | 70 | ExampleWindow w; 71 | w.title = app.applicationName(); 72 | w.visible = true; 73 | 74 | std::ignore = w.visible.valueChanged().connect([&app](bool visible) { 75 | if (!visible) { 76 | app.quit(); 77 | } 78 | }); 79 | 80 | app.exec(); 81 | } 82 | -------------------------------------------------------------------------------- /examples/mqtt_client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Marco Thaller 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | project(mqtt_client_example LANGUAGES CXX) 12 | 13 | add_executable( 14 | ${PROJECT_NAME} 15 | mqtt_client.cpp 16 | ) 17 | 18 | target_link_libraries( 19 | ${PROJECT_NAME} KDMqtt 20 | ) 21 | 22 | add_custom_command( 23 | TARGET ${PROJECT_NAME} 24 | POST_BUILD 25 | COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_BINARY_DIR}/mosquitto.org.crt" 26 | $ 27 | COMMENT "Copy mosquitto.org.cert next to binary." 28 | ) 29 | 30 | if(WIN32) 31 | if(Mosquitto_FOUND AND MOSQUITTO_RUNTIME_DLLS) 32 | foreach(MOSQUITTO_RUNTIME_DLL ${MOSQUITTO_RUNTIME_DLLS}) 33 | add_custom_command( 34 | TARGET ${PROJECT_NAME} 35 | POST_BUILD 36 | COMMAND ${CMAKE_COMMAND} -E copy_if_different "${MOSQUITTO_RUNTIME_DLL}" 37 | $ 38 | COMMENT "Copy mosquitto DLLs next to binary." 39 | ) 40 | endforeach() 41 | endif() 42 | endif() 43 | -------------------------------------------------------------------------------- /src/KDFoundation/cmake/KDFoundationConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | include(CMakeFindDependencyMacro) 12 | find_dependency(KDUtils) 13 | find_dependency(KDBindings) 14 | 15 | include("${CMAKE_CURRENT_LIST_DIR}/KDFoundationConfigTargets.cmake") 16 | -------------------------------------------------------------------------------- /src/KDFoundation/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | // clang-format off 15 | #define KD_@PLATFORM_NAME@ 16 | // clang-format on 17 | -------------------------------------------------------------------------------- /src/KDFoundation/event.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include "event.h" 13 | 14 | using namespace KDFoundation; 15 | 16 | Event::~Event() 17 | { 18 | } 19 | -------------------------------------------------------------------------------- /src/KDFoundation/event_receiver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Marco Thaller 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include "event_receiver.h" 13 | #include "core_application.h" 14 | 15 | using namespace KDFoundation; 16 | 17 | EventReceiver::~EventReceiver() noexcept 18 | { 19 | if (CoreApplication::instance() != nullptr) 20 | CoreApplication::instance()->removeAllEventsTargeting(*this); 21 | } 22 | -------------------------------------------------------------------------------- /src/KDFoundation/event_receiver.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | namespace KDFoundation { 17 | 18 | class Event; 19 | 20 | class KDFOUNDATION_API EventReceiver 21 | { 22 | public: 23 | virtual ~EventReceiver() noexcept; 24 | 25 | virtual void event(EventReceiver *target, Event *ev) { }; 26 | }; 27 | 28 | } // namespace KDFoundation 29 | -------------------------------------------------------------------------------- /src/KDFoundation/file_descriptor_notifier.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | #include 19 | 20 | using namespace KDFoundation; 21 | 22 | FileDescriptorNotifier::FileDescriptorNotifier(int fd, NotificationType type) 23 | : m_fd{ fd } 24 | , m_type{ type } 25 | { 26 | assert(m_fd >= 0); 27 | 28 | // TODO: Handle this on other threads by getting the event loop from 29 | // some thread local storage. 30 | // Get hold of the event loop from the application 31 | auto app = CoreApplication::instance(); 32 | if (!app) { 33 | SPDLOG_WARN("No application object exists yet. The notifier for fd {} will not be registered", m_fd); 34 | return; 35 | } 36 | 37 | auto eventLoop = app->eventLoop(); 38 | if (eventLoop) 39 | eventLoop->registerNotifier(this); 40 | } 41 | 42 | FileDescriptorNotifier::~FileDescriptorNotifier() 43 | { 44 | auto app = CoreApplication::instance(); 45 | if (!app) { 46 | SPDLOG_WARN("No application object exists yet we still have a notifier for fd {} alive", m_fd); 47 | return; 48 | } 49 | 50 | auto eventLoop = app->eventLoop(); 51 | if (eventLoop) 52 | eventLoop->unregisterNotifier(this); 53 | } 54 | 55 | void FileDescriptorNotifier::event(EventReceiver *target, Event *ev) 56 | { 57 | if (ev->type() == Event::Type::Notifier) { 58 | triggered.emit(m_fd); 59 | ev->setAccepted(true); 60 | } 61 | 62 | Object::event(target, ev); 63 | } 64 | -------------------------------------------------------------------------------- /src/KDFoundation/file_descriptor_notifier.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | 21 | namespace KDFoundation { 22 | 23 | /// @brief Get async notifications about activity on file descriptors 24 | /// 25 | /// @warning On Windows, the write notification is edge triggered meaning that 26 | /// it will be raised only if the internal socket buffer is fully filled, not 27 | /// after every successful write. This means that socket should be written to 28 | /// until WSAEWOULDBLOCK is returned from the send-type operation running on the 29 | /// socket to receive next write notification. 30 | class KDFOUNDATION_API FileDescriptorNotifier : public Object 31 | { 32 | public: 33 | enum class NotificationType : uint8_t { 34 | Read = 0, 35 | Write = 1, 36 | Exception = 2 37 | }; 38 | 39 | explicit FileDescriptorNotifier(int fd, NotificationType type); 40 | ~FileDescriptorNotifier(); 41 | 42 | KDBindings::Signal triggered; 43 | 44 | int fileDescriptor() const 45 | { 46 | return m_fd; 47 | } 48 | NotificationType type() const { return m_type; } 49 | 50 | protected: 51 | void event(EventReceiver *target, Event *ev) override; 52 | 53 | private: 54 | int m_fd; 55 | NotificationType m_type; 56 | }; 57 | 58 | } // namespace KDFoundation 59 | -------------------------------------------------------------------------------- /src/KDFoundation/hashutils.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | 17 | namespace KDFoundation { 18 | 19 | template 20 | inline void hash_combine(uint64_t &seed, const T &v) 21 | { 22 | std::hash hasher; 23 | seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); 24 | } 25 | 26 | } // namespace KDFoundation 27 | -------------------------------------------------------------------------------- /src/KDFoundation/kdfoundation_global.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | 17 | #define KDFOUNDATION_API KDFOUNDATION_EXPORT 18 | -------------------------------------------------------------------------------- /src/KDFoundation/logging.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | // TODO: Remove once downstream libs are ported to use KDUtils::Logger 13 | #pragma once 14 | 15 | #pragma warning("This header is deprecated, logging.h is now under ") 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | #ifdef ANDROID 23 | #include 24 | #endif 25 | 26 | namespace KDFoundation { 27 | 28 | enum class LogLevel : std::uint8_t { 29 | Trace = 0, 30 | Debug, 31 | Info, 32 | Warning, 33 | Error, 34 | Critical 35 | }; 36 | 37 | inline std::shared_ptr createLogger(const std::string &name) 38 | { 39 | #ifdef ANDROID 40 | return spdlog::android_logger_mt(name, "serenity"); 41 | #else 42 | return spdlog::stdout_color_mt(name); 43 | #endif 44 | } 45 | 46 | } // namespace KDFoundation 47 | -------------------------------------------------------------------------------- /src/KDFoundation/platform/abstract_platform_event_loop.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Miłosz Kosobucki 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include 13 | 14 | namespace KDFoundation { 15 | 16 | /** 17 | * KDUtils-specific connection evaluator that wakes up the owning event loop when slot invocation is 18 | * enqueued via the loop's connection evaluator. 19 | */ 20 | class ConnectionEvaluator final : public KDBindings::ConnectionEvaluator 21 | { 22 | public: 23 | ConnectionEvaluator(AbstractPlatformEventLoop *eventLoop) 24 | : m_eventLoop(eventLoop) { } 25 | 26 | void setEventLoop(AbstractPlatformEventLoop *eventLoop) 27 | { 28 | this->m_eventLoop = eventLoop; 29 | } 30 | 31 | protected: 32 | void onInvocationAdded() override 33 | { 34 | if (m_eventLoop) { 35 | m_eventLoop->wakeUp(); 36 | } 37 | } 38 | 39 | private: 40 | AbstractPlatformEventLoop *m_eventLoop = nullptr; 41 | }; 42 | } // namespace KDFoundation 43 | 44 | using namespace KDFoundation; 45 | 46 | KDFoundation::AbstractPlatformEventLoop::AbstractPlatformEventLoop() 47 | : m_connectionEvaluator(new ConnectionEvaluator(this)) 48 | { 49 | } 50 | 51 | AbstractPlatformEventLoop::~AbstractPlatformEventLoop() 52 | { 53 | // Make sure that any remaining references to our connection evaluator aren't referring to a dead 54 | // event loop object. 55 | if (m_connectionEvaluator) { 56 | std::static_pointer_cast(m_connectionEvaluator)->setEventLoop(nullptr); 57 | } 58 | } 59 | 60 | void KDFoundation::AbstractPlatformEventLoop::waitForEvents(int timeout) 61 | { 62 | waitForEventsImpl(timeout); 63 | 64 | // Possibly we woke up because of deferred slot invocation was posted. Let's (possibly) 65 | // execute them while we're at it. 66 | if (m_connectionEvaluator) { 67 | m_connectionEvaluator->evaluateDeferredConnections(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/KDFoundation/platform/abstract_platform_event_loop.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | namespace KDFoundation { 22 | 23 | class Postman; 24 | class FileDescriptorNotifier; 25 | class AbstractPlatformTimer; 26 | class Timer; 27 | 28 | class KDFOUNDATION_API AbstractPlatformEventLoop 29 | { 30 | public: 31 | AbstractPlatformEventLoop(); 32 | virtual ~AbstractPlatformEventLoop(); 33 | 34 | void setPostman(Postman *postman) { m_postman = postman; } 35 | Postman *postman() { return m_postman; } 36 | 37 | // timeout in msecs 38 | // -1 means wait forever 39 | // 0 means do not wait (i.e. poll) 40 | // +ve number, wait for up to timeout msecs 41 | void waitForEvents(int timeout); 42 | 43 | // Kick the event loop out of waiting 44 | virtual void wakeUp() = 0; 45 | 46 | virtual bool registerNotifier(FileDescriptorNotifier *notifier) = 0; 47 | virtual bool unregisterNotifier(FileDescriptorNotifier *notifier) = 0; 48 | 49 | std::unique_ptr createPlatformTimer(Timer *timer) 50 | { 51 | return createPlatformTimerImpl(timer); 52 | } 53 | std::shared_ptr connectionEvaluator() 54 | { 55 | return m_connectionEvaluator; 56 | } 57 | 58 | protected: 59 | virtual std::unique_ptr createPlatformTimerImpl(Timer *timer) = 0; 60 | virtual void waitForEventsImpl(int timeout) = 0; 61 | 62 | Postman *m_postman{ nullptr }; 63 | std::shared_ptr m_connectionEvaluator; 64 | }; 65 | 66 | } // namespace KDFoundation 67 | -------------------------------------------------------------------------------- /src/KDFoundation/platform/abstract_platform_integration.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | 21 | namespace KDFoundation { 22 | 23 | class CoreApplication; 24 | 25 | enum class StandardDir { 26 | Application, // Directory containing the application executable 27 | ApplicationData, // Directory containing data files specific to this application 28 | ApplicationDataLocal, // Directory containing local or internal data files specific to this application 29 | Assets // Directory containing assets bundled with the application package 30 | }; 31 | 32 | class KDFOUNDATION_API AbstractPlatformIntegration 33 | { 34 | public: 35 | virtual ~AbstractPlatformIntegration() { } 36 | 37 | virtual void init() { } 38 | std::unique_ptr createPlatformEventLoop() 39 | { 40 | return std::unique_ptr(this->createPlatformEventLoopImpl()); 41 | } 42 | 43 | // Return a directory, at one of the standard directory locations 44 | virtual KDUtils::Dir standardDir(const CoreApplication &app, StandardDir type) const = 0; 45 | 46 | private: 47 | virtual AbstractPlatformEventLoop *createPlatformEventLoopImpl() = 0; 48 | }; 49 | 50 | } // namespace KDFoundation 51 | -------------------------------------------------------------------------------- /src/KDFoundation/platform/abstract_platform_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | namespace KDFoundation { 17 | 18 | class KDFOUNDATION_API AbstractPlatformTimer 19 | { 20 | public: 21 | virtual ~AbstractPlatformTimer() { } 22 | }; 23 | 24 | } // namespace KDFoundation 25 | -------------------------------------------------------------------------------- /src/KDFoundation/platform/linux/linux_platform_integration.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include 13 | 14 | #include 15 | 16 | using namespace KDFoundation; 17 | 18 | LinuxPlatformIntegration::LinuxPlatformIntegration() 19 | { 20 | } 21 | 22 | LinuxPlatformIntegration::~LinuxPlatformIntegration() 23 | { 24 | } 25 | 26 | LinuxPlatformEventLoop *LinuxPlatformIntegration::createPlatformEventLoopImpl() 27 | { 28 | return new LinuxPlatformEventLoop(); 29 | } 30 | 31 | KDUtils::Dir LinuxPlatformIntegration::standardDir(const CoreApplication &app, KDFoundation::StandardDir type) const 32 | { 33 | switch (type) { 34 | case StandardDir::Application: 35 | return KDUtils::Dir::applicationDir(); 36 | case StandardDir::ApplicationData: 37 | case StandardDir::ApplicationDataLocal: 38 | return KDUtils::Dir(linuxAppDataPath(app)); 39 | case StandardDir::Assets: 40 | return KDUtils::Dir(KDUtils::Dir::applicationDir().parent().absoluteFilePath("assets")); 41 | default: 42 | SPDLOG_WARN("Unsupported standard directory requested"); 43 | return {}; 44 | } 45 | } 46 | 47 | std::string KDFoundation::LinuxPlatformIntegration::linuxAppDataPath(const CoreApplication &app) 48 | { 49 | auto homePath = secure_getenv("HOME"); 50 | auto appDataPath = std::string(homePath ? homePath : "") + "/.local/share"; 51 | 52 | auto appName = app.applicationName(); 53 | if (appName.empty()) { 54 | SPDLOG_CRITICAL("Application name is required to be set in order to generate an Application Data directory path"); 55 | return {}; 56 | } 57 | 58 | const auto orgName = app.organizationName(); 59 | if (orgName.empty()) { 60 | SPDLOG_WARN("No Organization name - using only Application name for the directory"); 61 | } else { 62 | appDataPath += "/" + orgName; 63 | } 64 | 65 | return appDataPath + "/" + appName; 66 | } 67 | -------------------------------------------------------------------------------- /src/KDFoundation/platform/linux/linux_platform_integration.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | 17 | namespace KDFoundation { 18 | 19 | class KDFOUNDATION_API LinuxPlatformIntegration : public AbstractPlatformIntegration 20 | { 21 | public: 22 | LinuxPlatformIntegration(); 23 | ~LinuxPlatformIntegration() override; 24 | 25 | KDUtils::Dir standardDir(const CoreApplication &app, StandardDir type) const override; 26 | 27 | static std::string linuxAppDataPath(const CoreApplication &app); 28 | 29 | private: 30 | LinuxPlatformEventLoop *createPlatformEventLoopImpl() override; 31 | }; 32 | 33 | } // namespace KDFoundation 34 | -------------------------------------------------------------------------------- /src/KDFoundation/platform/linux/linux_platform_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | namespace KDFoundation { 22 | 23 | class Timer; 24 | 25 | class KDFOUNDATION_API LinuxPlatformTimer : public AbstractPlatformTimer 26 | { 27 | public: 28 | LinuxPlatformTimer(Timer *timer); 29 | ~LinuxPlatformTimer() override; 30 | 31 | private: 32 | void arm(std::chrono::microseconds us); 33 | void disarm(); 34 | 35 | struct FdCloser { 36 | ~FdCloser(); 37 | int fd; 38 | } m_fdCloser; 39 | FileDescriptorNotifier m_notifier; 40 | KDBindings::ScopedConnection m_notifierConnection; 41 | KDBindings::ScopedConnection m_timerRunningConnection; 42 | KDBindings::ScopedConnection m_timerIntervalConnection; 43 | }; 44 | 45 | } // namespace KDFoundation 46 | -------------------------------------------------------------------------------- /src/KDFoundation/platform/macos/macos_platform_event_loop.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | namespace KDFoundation { 20 | 21 | class MacOSPlatformTimer; 22 | 23 | class KDFOUNDATION_API MacOSPlatformEventLoop : public AbstractPlatformEventLoop 24 | { 25 | public: 26 | MacOSPlatformEventLoop(); 27 | ~MacOSPlatformEventLoop() override; 28 | 29 | MacOSPlatformEventLoop(MacOSPlatformEventLoop const &other) = delete; 30 | MacOSPlatformEventLoop &operator=(MacOSPlatformEventLoop const &other) = delete; 31 | MacOSPlatformEventLoop(MacOSPlatformEventLoop &&other) = delete; 32 | MacOSPlatformEventLoop &operator=(MacOSPlatformEventLoop &&other) = delete; 33 | 34 | void wakeUp() override; 35 | 36 | bool registerNotifier(FileDescriptorNotifier *notifier) override; 37 | bool unregisterNotifier(FileDescriptorNotifier *notifier) override; 38 | 39 | static void postEmptyEvent(); 40 | 41 | private: 42 | void waitForEventsImpl(int timeout) override; 43 | std::unique_ptr createPlatformTimerImpl(Timer *timer) override; 44 | 45 | std::unordered_map timerMap; 46 | friend class MacOSPlatformTimer; 47 | }; 48 | 49 | } // namespace KDFoundation 50 | -------------------------------------------------------------------------------- /src/KDFoundation/platform/macos/macos_platform_integration.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | namespace KDFoundation { 19 | 20 | class KDFOUNDATION_API MacOSPlatformIntegration : public AbstractPlatformIntegration 21 | { 22 | public: 23 | MacOSPlatformIntegration(); 24 | ~MacOSPlatformIntegration() override; 25 | 26 | KDUtils::Dir standardDir(const CoreApplication &app, StandardDir type) const override; 27 | 28 | static std::string macAppDataPath(const CoreApplication &app); 29 | 30 | private: 31 | MacOSPlatformEventLoop *createPlatformEventLoopImpl() override; 32 | }; 33 | 34 | } // namespace KDFoundation 35 | -------------------------------------------------------------------------------- /src/KDFoundation/platform/macos/macos_platform_integration.mm: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include "macos_platform_integration.h" 13 | 14 | #include 15 | 16 | using namespace KDFoundation; 17 | 18 | MacOSPlatformIntegration::MacOSPlatformIntegration() = default; 19 | 20 | MacOSPlatformIntegration::~MacOSPlatformIntegration() = default; 21 | 22 | MacOSPlatformEventLoop *MacOSPlatformIntegration::createPlatformEventLoopImpl() 23 | { 24 | return new MacOSPlatformEventLoop; 25 | } 26 | 27 | KDUtils::Dir MacOSPlatformIntegration::standardDir(const CoreApplication &app, KDFoundation::StandardDir type) const 28 | { 29 | switch (type) { 30 | case StandardDir::Application: 31 | return KDUtils::Dir::applicationDir(); 32 | case StandardDir::ApplicationData: 33 | case StandardDir::ApplicationDataLocal: 34 | return KDUtils::Dir(KDFoundation::MacOSPlatformIntegration::macAppDataPath(app)); 35 | case StandardDir::Assets: 36 | return KDUtils::Dir(KDUtils::Dir::applicationDir().parent().absoluteFilePath("assets")); 37 | default: 38 | SPDLOG_WARN("Unsupported standard directory requested"); 39 | return {}; 40 | } 41 | } 42 | 43 | std::string KDFoundation::MacOSPlatformIntegration::macAppDataPath(const CoreApplication &app) 44 | { 45 | // NOLINTNEXTLINE(concurrency-mt-unsafe) - there is no secure_getenv on MacOS 46 | auto homePath = std::getenv("HOME"); 47 | auto appDataPath = std::string(homePath ? homePath : "") + "/Library/Application Support"; 48 | 49 | auto appName = app.applicationName(); 50 | if (appName.empty()) { 51 | SPDLOG_CRITICAL("Application name is required to be set in order to generate an Application Data directory path"); 52 | return {}; 53 | } 54 | 55 | const auto orgName = app.organizationName(); 56 | if (orgName.empty()) { 57 | SPDLOG_WARN("No Organization name - using only Application name for the directory"); 58 | } else { 59 | appDataPath += "/" + orgName; 60 | } 61 | 62 | return appDataPath + "/" + appName; 63 | } 64 | -------------------------------------------------------------------------------- /src/KDFoundation/platform/macos/macos_platform_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | 21 | namespace KDFoundation { 22 | 23 | class Timer; 24 | 25 | class KDFOUNDATION_API MacOSPlatformTimer : public AbstractPlatformTimer 26 | { 27 | public: 28 | explicit MacOSPlatformTimer(Timer *timer); 29 | ~MacOSPlatformTimer() override; 30 | 31 | private: 32 | void arm(std::chrono::microseconds us); 33 | void disarm(); 34 | static void timerFired(CFRunLoopTimerRef timer, void *info); 35 | Timer *const m_handler; 36 | CFRunLoopTimerRef cfTimer; 37 | }; 38 | 39 | } // namespace KDFoundation 40 | -------------------------------------------------------------------------------- /src/KDFoundation/platform/win32/win32_platform_event_loop.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | namespace KDFoundation { 23 | 24 | class FileDescriptorNotifier; 25 | class Win32PlatformTimer; 26 | 27 | class KDFOUNDATION_API Win32PlatformEventLoop : public AbstractPlatformEventLoop 28 | { 29 | public: 30 | Win32PlatformEventLoop(); 31 | ~Win32PlatformEventLoop() override; 32 | 33 | Win32PlatformEventLoop(Win32PlatformEventLoop const &other) = delete; 34 | Win32PlatformEventLoop &operator=(Win32PlatformEventLoop const &other) = delete; 35 | Win32PlatformEventLoop(Win32PlatformEventLoop &&other) = delete; 36 | Win32PlatformEventLoop &operator=(Win32PlatformEventLoop &&other) = delete; 37 | 38 | void wakeUp() override; 39 | 40 | bool registerNotifier(FileDescriptorNotifier *notifier) override; 41 | bool unregisterNotifier(FileDescriptorNotifier *notifier) override; 42 | 43 | std::unordered_map timers; 44 | 45 | private: 46 | void waitForEventsImpl(int timeout) override; 47 | std::unique_ptr createPlatformTimerImpl(Timer *timer) override; 48 | 49 | struct NotifierSet { 50 | std::array events{ nullptr, nullptr, nullptr }; 51 | bool isEmpty() const 52 | { 53 | return events[0] == nullptr && events[1] == nullptr && events[2] == nullptr; 54 | } 55 | }; 56 | std::unordered_map m_notifiers; 57 | 58 | static LRESULT CALLBACK messageWindowProc(HWND, UINT, WPARAM, LPARAM); 59 | void handleSocketMessage(WPARAM wParam, LPARAM lParam); 60 | bool registerWithWSAAsyncSelect(int fd, const NotifierSet ¬ifiers) const; 61 | 62 | HANDLE m_wakeUpEvent; 63 | HWND m_msgWindow = 0; 64 | }; 65 | 66 | } // namespace KDFoundation 67 | -------------------------------------------------------------------------------- /src/KDFoundation/platform/win32/win32_platform_integration.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | namespace KDFoundation { 19 | 20 | class KDFOUNDATION_API Win32PlatformIntegration : public AbstractPlatformIntegration 21 | { 22 | public: 23 | Win32PlatformIntegration(); 24 | ~Win32PlatformIntegration() override; 25 | 26 | KDUtils::Dir standardDir(const CoreApplication &app, StandardDir type) const override; 27 | 28 | static std::string windowsAppDataPath(const CoreApplication &app, bool local); 29 | 30 | private: 31 | Win32PlatformEventLoop *createPlatformEventLoopImpl() override; 32 | }; 33 | 34 | } // namespace KDFoundation 35 | -------------------------------------------------------------------------------- /src/KDFoundation/platform/win32/win32_platform_timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include "KDFoundation/core_application.h" 18 | #include "KDFoundation/timer.h" 19 | 20 | using namespace KDFoundation; 21 | 22 | inline Win32PlatformEventLoop *eventLoop() 23 | { 24 | return static_cast(CoreApplication::instance()->eventLoop()); 25 | } 26 | 27 | Win32PlatformTimer::Win32PlatformTimer(Timer *timer) 28 | : m_timer(timer) 29 | { 30 | m_timerRunningConnection = timer->running.valueChanged().connect([this, timer](bool running) { 31 | if (running) { 32 | arm(timer->interval.get()); 33 | } else { 34 | disarm(); 35 | } 36 | }); 37 | m_timerIntervalConnection = timer->interval.valueChanged().connect([this, timer]() { 38 | if (timer->running.get()) { 39 | arm(timer->interval.get()); 40 | } 41 | }); 42 | } 43 | 44 | Win32PlatformTimer::~Win32PlatformTimer() 45 | { 46 | if (m_id != 0) { 47 | disarm(); 48 | } 49 | } 50 | 51 | // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) 52 | void Win32PlatformTimer::callback(HWND /*hwnd*/, UINT /*uMsg*/, UINT_PTR timerId, DWORD /*dwTime*/) 53 | { 54 | auto timer = eventLoop()->timers[timerId]; 55 | assert(timer); 56 | 57 | timer->m_timer->timeout.emit(); 58 | } 59 | 60 | void Win32PlatformTimer::arm(std::chrono::microseconds us) 61 | { 62 | auto msecs = us.count() / 1000; 63 | if (m_id == 0) { 64 | m_id = SetTimer(nullptr, 0, UINT(msecs), callback); 65 | if (m_id) { 66 | eventLoop()->timers[m_id] = this; 67 | } 68 | } else { 69 | SetTimer(nullptr, m_id, UINT(msecs), callback); 70 | } 71 | } 72 | 73 | void Win32PlatformTimer::disarm() 74 | { 75 | assert(m_id != 0); 76 | 77 | eventLoop()->timers.erase(m_id); 78 | KillTimer(nullptr, m_id); 79 | m_id = 0; 80 | } 81 | -------------------------------------------------------------------------------- /src/KDFoundation/platform/win32/win32_platform_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | #include 17 | #undef max 18 | 19 | #include 20 | 21 | namespace KDFoundation { 22 | 23 | class Timer; 24 | 25 | class KDFOUNDATION_API Win32PlatformTimer : public AbstractPlatformTimer 26 | { 27 | public: 28 | Win32PlatformTimer(Timer *timer); 29 | ~Win32PlatformTimer() override; 30 | 31 | private: 32 | void arm(std::chrono::microseconds us); 33 | void disarm(); 34 | static void callback(HWND hwnd, UINT uMsg, UINT_PTR timerId, DWORD dwTime); 35 | 36 | Timer *m_timer; 37 | KDBindings::ScopedConnection m_timerRunningConnection; 38 | KDBindings::ScopedConnection m_timerIntervalConnection; 39 | uintptr_t m_id{ 0 }; 40 | }; 41 | 42 | } // namespace KDFoundation 43 | -------------------------------------------------------------------------------- /src/KDFoundation/postman.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include "postman.h" 13 | #include "object.h" 14 | 15 | #include 16 | 17 | using namespace KDFoundation; 18 | 19 | void Postman::deliverEvent(EventReceiver *target, Event *event) 20 | { 21 | // Give the registered event filters first chance to handle the event 22 | for (const auto &filter : m_filters) { 23 | filter->event(target, event); 24 | if (event->isAccepted()) 25 | return; 26 | } 27 | 28 | // TODO: Add support for trickle-down and bubble-up based upon event type 29 | target->event(target, event); 30 | } 31 | 32 | void Postman::addFilter(Object *filter) 33 | { 34 | assert(filter != nullptr); 35 | m_filters.push_back(filter); 36 | } 37 | 38 | void Postman::removeFilter(Object *filter) 39 | { 40 | auto it = std::find(m_filters.begin(), m_filters.end(), filter); 41 | if (it != m_filters.end()) 42 | m_filters.erase(it); 43 | } 44 | -------------------------------------------------------------------------------- /src/KDFoundation/postman.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include "KDFoundation/event_receiver.h" 15 | #include 16 | 17 | #include 18 | 19 | namespace KDFoundation { 20 | 21 | class Event; 22 | class Object; 23 | 24 | class KDFOUNDATION_API Postman 25 | { 26 | public: 27 | void deliverEvent(EventReceiver *target, Event *event); 28 | 29 | void addFilter(Object *filter); 30 | void removeFilter(Object *filter); 31 | const std::vector &filters() const { return m_filters; } 32 | 33 | private: 34 | std::vector m_filters; 35 | }; 36 | 37 | } // namespace KDFoundation 38 | -------------------------------------------------------------------------------- /src/KDFoundation/timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include "timer.h" 13 | 14 | #include "core_application.h" 15 | #include "platform/abstract_platform_integration.h" 16 | #include "platform/abstract_platform_timer.h" 17 | 18 | using namespace KDFoundation; 19 | 20 | Timer::Timer() 21 | : m_platformTimer(CoreApplication::instance()->eventLoop()->createPlatformTimer(this)) 22 | { 23 | } 24 | 25 | Timer::~Timer() 26 | { 27 | } 28 | -------------------------------------------------------------------------------- /src/KDFoundation/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #include 17 | 18 | #include 19 | 20 | namespace KDFoundation { 21 | 22 | class AbstractPlatformTimer; 23 | 24 | class KDFOUNDATION_API Timer 25 | { 26 | public: 27 | explicit Timer(); 28 | ~Timer(); 29 | 30 | KDBindings::Signal<> timeout; 31 | 32 | KDBindings::Property running{ false }; 33 | KDBindings::Property interval{}; 34 | 35 | private: 36 | std::unique_ptr m_platformTimer; 37 | }; 38 | 39 | } // namespace KDFoundation 40 | -------------------------------------------------------------------------------- /src/KDFoundation/vector_helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace KDFoundation { 20 | 21 | template 22 | inline void moveAtEnd(std::vector &destination, std::vector &&source) 23 | { 24 | destination.insert(destination.end(), 25 | std::make_move_iterator(source.begin()), 26 | std::make_move_iterator(source.end())); 27 | } 28 | 29 | template 30 | inline T moveAndClear(T &data) 31 | { 32 | T ret(std::move(data)); 33 | data.clear(); 34 | return ret; 35 | } 36 | 37 | template 38 | inline void append(std::vector &destination, const U &source) 39 | { 40 | destination.insert(destination.end(), 41 | source.cbegin(), 42 | source.cend()); 43 | } 44 | 45 | template 46 | inline bool contains(const std::vector &destination, const U &element) noexcept 47 | { 48 | return std::find(destination.begin(), destination.end(), element) != destination.end(); 49 | } 50 | 51 | template 52 | inline void deleteAll(ForwardIterator begin, ForwardIterator end) 53 | { 54 | while (begin != end) { 55 | delete *begin; 56 | ++begin; 57 | } 58 | } 59 | 60 | template 61 | inline void deleteAll(const Container &c) 62 | { 63 | deleteAll(c.begin(), c.end()); 64 | } 65 | 66 | template 67 | inline size_t indexOf(const std::vector &destination, const T &element) 68 | { 69 | auto it = std::find(destination.cbegin(), destination.cend(), element); 70 | if (it == destination.cend()) { 71 | return -1; 72 | } 73 | return std::distance(destination.cbegin(), it); 74 | } 75 | 76 | } // namespace KDFoundation 77 | -------------------------------------------------------------------------------- /src/KDGui/abstract_clipboard.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Joshua Goins 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace KDGui { 19 | 20 | class AbstractGuiPlatformIntegration; 21 | 22 | class AbstractClipboard : public KDFoundation::Object 23 | { 24 | public: 25 | virtual std::string text() = 0; 26 | virtual void setText(std::string_view text) = 0; 27 | }; 28 | 29 | } // namespace KDGui 30 | -------------------------------------------------------------------------------- /src/KDGui/abstract_gui_platform_integration.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace KDGui { 19 | 20 | class Window; 21 | class AbstractClipboard; 22 | 23 | class AbstractGuiPlatformIntegration : public KDFoundation::AbstractPlatformIntegration 24 | { 25 | public: 26 | std::unique_ptr createPlatformWindow(Window *window) 27 | { 28 | return std::unique_ptr(this->createPlatformWindowImpl(window)); 29 | } 30 | 31 | virtual AbstractClipboard *clipboard() = 0; 32 | 33 | private: 34 | virtual AbstractPlatformWindow *createPlatformWindowImpl(Window *window) = 0; 35 | }; 36 | 37 | } // namespace KDGui 38 | -------------------------------------------------------------------------------- /src/KDGui/abstract_platform_window.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include 13 | #include "window.h" 14 | 15 | #include 16 | 17 | using namespace KDGui; 18 | 19 | AbstractPlatformWindow::AbstractPlatformWindow(Window *window, AbstractPlatformWindow::Type type) 20 | : m_window{ window } 21 | , m_type(type) 22 | { 23 | assert(window); 24 | m_titleChangedConnection = window->title.valueChanged().connect(&AbstractPlatformWindow::setTitle, this); 25 | } 26 | 27 | AbstractPlatformWindow::Type AbstractPlatformWindow::type() const 28 | { 29 | return m_type; 30 | } 31 | -------------------------------------------------------------------------------- /src/KDGui/cmake/KDGuiConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | include(CMakeFindDependencyMacro) 12 | find_dependency(KDFoundation) 13 | 14 | include("${CMAKE_CURRENT_LIST_DIR}/KDGuiConfigTargets.cmake") 15 | -------------------------------------------------------------------------------- /src/KDGui/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Joshua Goins 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | // clang-format off 15 | #cmakedefine KDGUI_PLATFORM_ANDROID 16 | #cmakedefine KDGUI_PLATFORM_COCOA 17 | #cmakedefine KDGUI_PLATFORM_XCB 18 | #cmakedefine KDGUI_PLATFORM_WAYLAND 19 | #cmakedefine KDGUI_PLATFORM_WIN32 20 | // clang-format on 21 | -------------------------------------------------------------------------------- /src/KDGui/gui_application.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include "gui_application.h" 13 | #if defined(PLATFORM_LINUX) 14 | #include 15 | #if defined(PLATFORM_WAYLAND) 16 | #include 17 | #endif 18 | #elif defined(PLATFORM_WIN32) 19 | #include 20 | #elif defined(PLATFORM_MACOS) 21 | #include 22 | #elif defined(ANDROID) 23 | #include 24 | #endif 25 | 26 | #include 27 | 28 | using namespace KDGui; 29 | 30 | namespace { 31 | #if defined(PLATFORM_LINUX) 32 | std::unique_ptr createLinuxIntegration() 33 | { 34 | bool prefersXcb = false; 35 | 36 | // TODO(doc): document this behavior 37 | if (const char *preferredPlatform = std::getenv("KDGUI_PLATFORM")) { // NOLINT(concurrency-mt-unsafe) 38 | prefersXcb = std::string_view{ preferredPlatform } == "xcb"; // NOLINT(clang-analyzer-deadcode.DeadStores) 39 | } 40 | 41 | #if defined(PLATFORM_WAYLAND) 42 | if (LinuxWaylandPlatformIntegration::checkAvailable() && !prefersXcb) 43 | return std::make_unique(); 44 | else 45 | #endif 46 | return std::make_unique(); 47 | } 48 | #endif 49 | 50 | std::unique_ptr createPlatformIntegration() 51 | { 52 | #if defined(ANDROID) 53 | return std::make_unique(); 54 | #elif defined(PLATFORM_LINUX) 55 | return createLinuxIntegration(); 56 | #elif defined(PLATFORM_WIN32) 57 | return std::make_unique(); 58 | #elif defined(PLATFORM_MACOS) 59 | return std::make_unique(); 60 | #endif 61 | return {}; 62 | } 63 | } // namespace 64 | 65 | GuiApplication::GuiApplication(std::unique_ptr &&platformIntegration) 66 | : CoreApplication(platformIntegration ? std::move(platformIntegration) : createPlatformIntegration()) 67 | { 68 | } 69 | -------------------------------------------------------------------------------- /src/KDGui/gui_application.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | namespace KDGui { 20 | 21 | class KDGUI_API GuiApplication : public KDFoundation::CoreApplication 22 | { 23 | public: 24 | /// @warning if you want to use custom loggers (@see KDUtils::logger::setLoggerFactory ) you 25 | // should call it *before* creation of both this class and any platform integration. 26 | GuiApplication(std::unique_ptr &&platformIntegration = {}); 27 | 28 | static inline GuiApplication *instance() { return static_cast(ms_application); } 29 | 30 | AbstractGuiPlatformIntegration *guiPlatformIntegration() 31 | { 32 | return dynamic_cast(platformIntegration()); 33 | } 34 | }; 35 | 36 | } // namespace KDGui 37 | -------------------------------------------------------------------------------- /src/KDGui/kdgui_global.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #define KDGUI_API KDGUI_EXPORT 17 | -------------------------------------------------------------------------------- /src/KDGui/platform/android/android_keyboard_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Alstair Baxter 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | namespace KDGui { 17 | 18 | Key androidKeyCodeToKey(unsigned keyCode); 19 | 20 | KeyboardModifiers androidKeyMetaToModifiers(int32_t keyMeta); 21 | 22 | } // namespace KDGui 23 | -------------------------------------------------------------------------------- /src/KDGui/platform/android/android_platform_event_loop.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: BogDan Vatra 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | struct android_app; 25 | struct android_poll_source; 26 | struct AInputEvent; 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | namespace KDGui { 32 | 33 | class AndroidPlatformIntegration; 34 | class KDGUI_API AndroidPlatformEventLoop : public KDFoundation::AbstractPlatformEventLoop 35 | { 36 | public: 37 | AndroidPlatformEventLoop(AndroidPlatformIntegration *androidPlatformInitegration); 38 | 39 | // Kick the event loop out of waiting 40 | void wakeUp() override; 41 | 42 | bool registerNotifier(KDFoundation::FileDescriptorNotifier *notifier) override; 43 | 44 | bool unregisterNotifier(KDFoundation::FileDescriptorNotifier *notifier) override; 45 | 46 | AndroidPlatformIntegration *androidPlatformIntegration(); 47 | 48 | protected: 49 | void waitForEventsImpl(int timeout) override; 50 | std::unique_ptr createPlatformTimerImpl(KDFoundation::Timer *timer) final; 51 | 52 | private: 53 | static int ALooperCallback(int fd, int events, void *data); 54 | struct NotifierSet { 55 | int androidEvents() const; 56 | 57 | std::array events{ nullptr, nullptr, nullptr }; 58 | 59 | bool isEmpty() const; 60 | }; 61 | static void androidHandleCmd(android_app *app, int32_t cmd); 62 | static int32_t androidHandleInputEvent(struct android_app *app, AInputEvent *event); 63 | 64 | private: 65 | std::unordered_map m_notifiers; 66 | AndroidPlatformIntegration *m_androidPlatformInitegration; 67 | }; 68 | 69 | } // namespace KDGui 70 | -------------------------------------------------------------------------------- /src/KDGui/platform/android/android_platform_integration.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: BogDan Vatra 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | struct android_app; 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | namespace KDGui { 29 | 30 | class KDGUI_API AndroidPlatformIntegration : public AbstractGuiPlatformIntegration 31 | { 32 | public: 33 | AndroidPlatformIntegration(); 34 | void handleWindowResize(); 35 | void registerPlatformWindow(AbstractPlatformWindow *window); 36 | void unregisterPlatformWindow(AbstractPlatformWindow *window); 37 | void handleKeyEvent(int32_t action, int32_t code, int32_t meta, int64_t time); 38 | void handleTouchEvent(int32_t action, int64_t xPos, int64_t yPos, int64_t time); 39 | 40 | AbstractClipboard *clipboard() override 41 | { 42 | // TODO(android): Implement clipboard 43 | return nullptr; 44 | } 45 | 46 | KDUtils::Dir standardDir(const KDFoundation::CoreApplication &app, KDFoundation::StandardDir type) const override; 47 | 48 | static android_app *s_androidApp; 49 | 50 | private: 51 | KDFoundation::AbstractPlatformEventLoop *createPlatformEventLoopImpl() override; 52 | AbstractPlatformWindow *createPlatformWindowImpl(Window *window) override; 53 | 54 | private: 55 | std::unordered_set m_windows; 56 | }; 57 | 58 | } // namespace KDGui 59 | -------------------------------------------------------------------------------- /src/KDGui/platform/android/android_platform_window.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: BogDan Vatra 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | struct ANativeWindow; 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | namespace KDGui { 28 | 29 | class AndroidPlatformIntegration; 30 | 31 | class KDGUI_API AndroidPlatformWindow : public AbstractPlatformWindow 32 | { 33 | public: 34 | AndroidPlatformWindow(AndroidPlatformIntegration *androidPlatformIntegration, Window *window); 35 | bool create() final; 36 | bool destroy() final; 37 | bool isCreated() final; 38 | void map() final; 39 | void unmap() final; 40 | 41 | void disableCursor() final; 42 | void enableCursor() final; 43 | 44 | void enableRawMouseInput() final; 45 | void disableRawMouseInput() final; 46 | 47 | void grabMouse() final; 48 | void releaseMouse() final; 49 | 50 | void setTitle(const std::string &title) final; 51 | void setSize(uint32_t width, uint32_t height) final; 52 | 53 | void handleResize(uint32_t width, uint32_t height) final; 54 | void handleMousePress(uint32_t timestamp, MouseButton button, int16_t xPos, int16_t yPos) final; 55 | void handleMouseRelease(uint32_t timestamp, MouseButton button, int16_t xPos, int16_t yPos) final; 56 | void handleMouseMove(uint32_t timestamp, MouseButton button, int64_t xPos, int64_t yPos) final; 57 | void handleMouseWheel(uint32_t timestamp, int32_t xDelta, int32_t yDelta) final; 58 | void handleKeyPress(uint32_t timestamp, uint8_t nativeKeyCode, Key key, KeyboardModifiers modifiers) final; 59 | void handleKeyRelease(uint32_t timestamp, uint8_t nativeKeyCode, Key key, KeyboardModifiers modifiers) final; 60 | void handleTextInput(const std::string &str) final; 61 | 62 | ANativeWindow *nativeWindow(); 63 | 64 | private: 65 | std::string m_title; 66 | AndroidPlatformIntegration *m_androidPlatformIntegrationSerenity; 67 | MouseButtons m_mouseButtons{ MouseButton::NoButton }; 68 | }; 69 | 70 | } // namespace KDGui 71 | -------------------------------------------------------------------------------- /src/KDGui/platform/cocoa/cocoa_platform_integration.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | 17 | namespace KDGui { 18 | class CocoaPlatformIntegrationImpl; 19 | class Window; 20 | 21 | class KDGUI_API CocoaPlatformIntegration : public AbstractGuiPlatformIntegration 22 | { 23 | public: 24 | CocoaPlatformIntegration(); 25 | ~CocoaPlatformIntegration() override; 26 | 27 | AbstractClipboard *clipboard() override 28 | { 29 | // TODO(cocoa): Implement clipboard 30 | return nullptr; 31 | } 32 | 33 | KDUtils::Dir standardDir(const KDFoundation::CoreApplication &app, KDFoundation::StandardDir type) const override; 34 | 35 | private: 36 | KDFoundation::AbstractPlatformEventLoop *createPlatformEventLoopImpl() override; 37 | AbstractPlatformWindow *createPlatformWindowImpl(Window *window) override; 38 | 39 | std::unique_ptr m_impl; 40 | }; 41 | 42 | } // namespace KDGui 43 | -------------------------------------------------------------------------------- /src/KDGui/platform/cocoa/cocoa_platform_integration.mm: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include "cocoa_platform_integration.h" 13 | #include "cocoa_platform_integration_impl.h" 14 | 15 | #include 16 | #include 17 | 18 | using namespace KDGui; 19 | using namespace KDFoundation; 20 | 21 | CocoaPlatformIntegration::CocoaPlatformIntegration() 22 | : m_impl(new CocoaPlatformIntegrationImpl) 23 | { 24 | } 25 | 26 | CocoaPlatformIntegration::~CocoaPlatformIntegration() = default; 27 | 28 | KDFoundation::AbstractPlatformEventLoop *CocoaPlatformIntegration::createPlatformEventLoopImpl() 29 | { 30 | return m_impl->createPlatformEventLoop(); 31 | } 32 | 33 | AbstractPlatformWindow *CocoaPlatformIntegration::createPlatformWindowImpl(Window *window) 34 | { 35 | return m_impl->createPlatformWindow(window); 36 | } 37 | 38 | KDUtils::Dir CocoaPlatformIntegration::standardDir(const KDFoundation::CoreApplication &app, KDFoundation::StandardDir type) const 39 | { 40 | switch (type) { 41 | case StandardDir::Application: 42 | return KDUtils::Dir(KDUtils::Dir::applicationDir().path()); 43 | case StandardDir::ApplicationData: 44 | case StandardDir::ApplicationDataLocal: 45 | return KDUtils::Dir(KDFoundation::MacOSPlatformIntegration::macAppDataPath(app)); 46 | case StandardDir::Assets: 47 | return KDUtils::Dir(KDUtils::Dir::applicationDir().parent().absoluteFilePath("assets")); 48 | default: 49 | SPDLOG_WARN("Unsupported standard directory requested"); 50 | return {}; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/KDGui/platform/cocoa/cocoa_platform_integration_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | namespace KDFoundation { 16 | class AbstractPlatformEventLoop; 17 | } 18 | 19 | namespace KDGui { 20 | 21 | class Window; 22 | class AbstractPlatformWindow; 23 | 24 | class CocoaPlatformIntegrationImpl 25 | { 26 | public: 27 | CocoaPlatformIntegrationImpl(); 28 | ~CocoaPlatformIntegrationImpl(); 29 | 30 | KDFoundation::AbstractPlatformEventLoop *createPlatformEventLoop(); 31 | AbstractPlatformWindow *createPlatformWindow(Window *window); 32 | 33 | private: 34 | id m_delegate = nil; 35 | }; 36 | 37 | } // namespace KDGui 38 | -------------------------------------------------------------------------------- /src/KDGui/platform/linux/common/linux_xkb.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include "linux_xkb.h" 13 | 14 | #include 15 | 16 | using namespace KDGui; 17 | 18 | KeyboardModifiers xkb::modifierState(xkb_state *state) 19 | { 20 | KeyboardModifiers modifiers{ Mod_NoModifiers }; 21 | 22 | if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_SHIFT, XKB_STATE_MODS_EFFECTIVE) == 1) 23 | modifiers |= Mod_Shift; 24 | if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) == 1) 25 | modifiers |= Mod_Control; 26 | if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_ALT, XKB_STATE_MODS_EFFECTIVE) == 1) 27 | modifiers |= Mod_Alt; 28 | if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_LOGO, XKB_STATE_MODS_EFFECTIVE) == 1) 29 | modifiers |= Mod_Logo; 30 | if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS, XKB_STATE_MODS_EFFECTIVE) == 1) 31 | modifiers |= Mod_CapsLock; 32 | if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_NUM, XKB_STATE_MODS_EFFECTIVE) == 1) 33 | modifiers |= Mod_NumLock; 34 | 35 | return modifiers; 36 | } 37 | -------------------------------------------------------------------------------- /src/KDGui/platform/linux/common/linux_xkb.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | struct xkb_state; 17 | 18 | namespace KDGui::xkb { 19 | 20 | KeyboardModifiers modifierState(xkb_state *state); 21 | 22 | } // namespace KDGui::xkb 23 | -------------------------------------------------------------------------------- /src/KDGui/platform/linux/common/linux_xkb_keyboard_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace KDGui::xkb { 19 | 20 | Key keysymToKey(xkb_keysym_t keysym); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/KDGui/platform/linux/wayland/linux_wayland_clipboard.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Joshua Goins 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | struct wl_surface; 20 | struct wl_seat; 21 | struct wl_data_device; 22 | struct wl_data_offer; 23 | using wl_fixed_t = int32_t; 24 | 25 | namespace KDGui { 26 | 27 | class LinuxWaylandPlatformIntegration; 28 | 29 | class LinuxWaylandClipboard : public AbstractClipboard 30 | { 31 | public: 32 | LinuxWaylandClipboard(KDGui::LinuxWaylandPlatformIntegration *integration); 33 | 34 | void initializeDataDevice(wl_seat *seat); 35 | 36 | std::string text() override; 37 | void setText(std::string_view text) override; 38 | 39 | private: 40 | void dataOffer(wl_data_device *data_device, wl_data_offer *offer); 41 | void dragEnter(wl_data_device *wl_data_device, uint32_t serial, wl_surface *surface, wl_fixed_t x, wl_fixed_t y, wl_data_offer *id); 42 | void dragLeave(wl_data_device *wl_data_device); 43 | void dragMotion(wl_data_device *wl_data_device, uint32_t time, wl_fixed_t x, wl_fixed_t y); 44 | void dragDrop(wl_data_device *wl_data_device); 45 | void newSelection(wl_data_device *wl_data_device, wl_data_offer *id); 46 | 47 | wl_data_device *m_dataDevice{ nullptr }; 48 | wl_data_offer *m_dataOffer{ nullptr }; 49 | KDGui::LinuxWaylandPlatformIntegration *m_integration{ nullptr }; 50 | }; 51 | 52 | } // namespace KDGui 53 | -------------------------------------------------------------------------------- /src/KDGui/platform/linux/wayland/linux_wayland_platform_event_loop.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include "linux_wayland_platform_event_loop.h" 13 | #include "linux_wayland_platform_integration.h" 14 | 15 | #include 16 | 17 | using namespace KDGui; 18 | using namespace KDFoundation; 19 | 20 | LinuxWaylandPlatformEventLoop::LinuxWaylandPlatformEventLoop(LinuxWaylandPlatformIntegration *platformIntegration) 21 | : m_logger{ platformIntegration->logger() } 22 | , m_platformIntegration{ platformIntegration } 23 | { 24 | } 25 | 26 | void LinuxWaylandPlatformEventLoop::init() 27 | { 28 | const int fd = wl_display_get_fd(m_platformIntegration->display()); 29 | registerFileDescriptor(fd, FileDescriptorNotifier::NotificationType::Read); 30 | } 31 | 32 | LinuxWaylandPlatformEventLoop::~LinuxWaylandPlatformEventLoop() 33 | { 34 | } 35 | 36 | void LinuxWaylandPlatformEventLoop::waitForEventsImpl(int timeout) 37 | { 38 | auto dpy = m_platformIntegration->display(); 39 | auto queue = m_platformIntegration->queue(); 40 | 41 | wl_display_flush(dpy); 42 | while (wl_display_prepare_read_queue(dpy, queue) != 0) { 43 | wl_display_dispatch_queue_pending(dpy, queue); 44 | } 45 | 46 | // Call the base class to do the actual multiplexing 47 | LinuxPlatformEventLoop::waitForEventsImpl(timeout); 48 | 49 | const int fd = wl_display_get_fd(dpy); 50 | if (epollEventFromFdPlusType(fd, FileDescriptorNotifier::NotificationType::Read)) { 51 | wl_display_read_events(dpy); 52 | wl_display_dispatch_queue_pending(dpy, queue); 53 | } else { 54 | wl_display_cancel_read(dpy); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/KDGui/platform/linux/wayland/linux_wayland_platform_event_loop.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #include 17 | 18 | #include 19 | 20 | namespace KDGui { 21 | 22 | class LinuxWaylandPlatformIntegration; 23 | 24 | class LinuxWaylandPlatformEventLoop : public KDFoundation::LinuxPlatformEventLoop 25 | { 26 | public: 27 | explicit LinuxWaylandPlatformEventLoop(LinuxWaylandPlatformIntegration *platformIntegration); 28 | ~LinuxWaylandPlatformEventLoop(); 29 | 30 | void init(); 31 | void waitForEventsImpl(int timeout) override; 32 | 33 | private: 34 | std::shared_ptr m_logger; 35 | LinuxWaylandPlatformIntegration *m_platformIntegration; 36 | }; 37 | 38 | } // namespace KDGui 39 | -------------------------------------------------------------------------------- /src/KDGui/platform/linux/wayland/linux_wayland_platform_output.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | using namespace KDGui; 18 | 19 | // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) 20 | LinuxWaylandPlatformOutput::LinuxWaylandPlatformOutput(wl_output *output, uint32_t version, uint32_t id) 21 | : m_output(output) 22 | , m_version(version) 23 | , m_outputId(id) 24 | { 25 | static const wl_output_listener listener = { 26 | wrapWlCallback<&LinuxWaylandPlatformOutput::geometry>, 27 | wrapWlCallback<&LinuxWaylandPlatformOutput::mode>, 28 | wrapWlCallback<&LinuxWaylandPlatformOutput::done>, 29 | wrapWlCallback<&LinuxWaylandPlatformOutput::scale> 30 | }; 31 | wl_output_add_listener(output, &listener, this); 32 | } 33 | 34 | LinuxWaylandPlatformOutput::~LinuxWaylandPlatformOutput() 35 | { 36 | if (m_version >= WL_OUTPUT_RELEASE_SINCE_VERSION) { 37 | wl_output_release(m_output); 38 | } else { 39 | wl_output_destroy(m_output); 40 | } 41 | } 42 | 43 | LinuxWaylandPlatformOutput *LinuxWaylandPlatformOutput::fromOutput(wl_output *output) 44 | { 45 | return static_cast(wl_output_get_user_data(output)); 46 | } 47 | 48 | // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) 49 | void LinuxWaylandPlatformOutput::geometry(wl_output * /*output*/, int32_t /*x*/, int32_t /*y*/, int32_t /*physicalWidth*/, int32_t /*physicalHeight*/, 50 | int32_t /*subpixel*/, const char *make, const char *model, int32_t /*transform*/) 51 | { 52 | m_make = make; 53 | m_model = model; 54 | } 55 | 56 | // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) 57 | void LinuxWaylandPlatformOutput::mode(wl_output *output, uint32_t flags, int32_t width, int32_t height, int32_t refreshRate) 58 | { 59 | } 60 | 61 | void LinuxWaylandPlatformOutput::done(wl_output *output) 62 | { 63 | } 64 | 65 | void LinuxWaylandPlatformOutput::scale(wl_output * /*output*/, int32_t factor) 66 | { 67 | m_scaleFactor = factor; 68 | } 69 | -------------------------------------------------------------------------------- /src/KDGui/platform/linux/wayland/linux_wayland_platform_output.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | 17 | struct wl_output; 18 | 19 | namespace KDGui { 20 | 21 | class LinuxWaylandPlatformOutput 22 | { 23 | public: 24 | static constexpr uint32_t supportedVersion = 3; 25 | 26 | explicit LinuxWaylandPlatformOutput(wl_output *output, uint32_t version, uint32_t id); 27 | LinuxWaylandPlatformOutput(const LinuxWaylandPlatformOutput &) = delete; 28 | ~LinuxWaylandPlatformOutput(); 29 | 30 | static LinuxWaylandPlatformOutput *fromOutput(wl_output *output); 31 | 32 | uint32_t outputId() const { return m_outputId; } 33 | int scaleFactor() const { return m_scaleFactor; } 34 | 35 | private: 36 | void geometry(wl_output *output, int32_t x, int32_t y, int32_t physicalWidth, int32_t physicalHeight, 37 | int32_t subpixel, const char *make, const char *model, int32_t transform); 38 | void mode(wl_output *output, uint32_t flags, int32_t width, int32_t height, int32_t refreshRate); 39 | void done(wl_output *output); 40 | void scale(wl_output *output, int32_t factor); 41 | 42 | wl_output *m_output; 43 | uint32_t m_version; 44 | uint32_t m_outputId; 45 | int m_scaleFactor{ 1 }; 46 | std::string m_make; 47 | std::string m_model; 48 | }; 49 | 50 | } // namespace KDGui 51 | -------------------------------------------------------------------------------- /src/KDGui/platform/linux/xcb/linux_xcb_clipboard.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Joshua Goins 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | 21 | namespace KDGui { 22 | 23 | class LinuxXcbPlatformIntegration; 24 | 25 | class LinuxXcbClipboard : public AbstractClipboard 26 | { 27 | public: 28 | LinuxXcbClipboard(KDGui::LinuxXcbPlatformIntegration *integration); 29 | ~LinuxXcbClipboard(); 30 | 31 | std::string text() override; 32 | void setText(std::string_view text) override; 33 | 34 | private: 35 | KDGui::LinuxXcbPlatformIntegration *m_integration{ nullptr }; 36 | xcb_atom_t m_clipboard, m_utf8; 37 | uint32_t m_window; 38 | }; 39 | 40 | } // namespace KDGui 41 | -------------------------------------------------------------------------------- /src/KDGui/platform/linux/xcb/linux_xcb_platform_event_loop.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #include 17 | 18 | #include 19 | 20 | namespace KDFoundation { 21 | class FileDescriptorNotifier; 22 | } 23 | 24 | namespace KDGui { 25 | 26 | class LinuxXcbPlatformIntegration; 27 | class LinuxXkbKeyboard; 28 | 29 | class LinuxXcbPlatformEventLoop : public KDFoundation::LinuxPlatformEventLoop 30 | { 31 | public: 32 | explicit LinuxXcbPlatformEventLoop(LinuxXcbPlatformIntegration *platformIntegration); 33 | ~LinuxXcbPlatformEventLoop(); 34 | 35 | void waitForEventsImpl(int timeout) override; 36 | 37 | private: 38 | void processXcbEvents(); 39 | 40 | std::shared_ptr m_logger; 41 | LinuxXcbPlatformIntegration *m_platformIntegration; 42 | LinuxXkbKeyboard *m_keyboard{ nullptr }; 43 | std::unique_ptr m_xcbNotifier; 44 | bool m_xcbEventsPending{ false }; 45 | }; 46 | 47 | } // namespace KDGui 48 | -------------------------------------------------------------------------------- /src/KDGui/platform/linux/xcb/linux_xcb_platform_integration.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include 24 | 25 | namespace KDGui { 26 | 27 | class LinuxXkbKeyboard; 28 | 29 | class KDGUI_API LinuxXcbPlatformIntegration : public AbstractGuiPlatformIntegration 30 | { 31 | public: 32 | LinuxXcbPlatformIntegration(); 33 | ~LinuxXcbPlatformIntegration() override; 34 | 35 | AbstractClipboard *clipboard() override; 36 | 37 | std::shared_ptr logger() { return m_logger; } 38 | 39 | LinuxXkbKeyboard *keyboard(); 40 | 41 | xcb_connection_t *connection() { return m_connection; } 42 | xcb_screen_t *screen() { return m_screen; } 43 | 44 | void registerWindowForEvents(xcb_window_t xcbWindow, LinuxXcbPlatformWindow *window) 45 | { 46 | m_windows.insert({ xcbWindow, window }); 47 | } 48 | void unregisterWindowForEvents(xcb_window_t xcbWindow) { m_windows.erase(xcbWindow); } 49 | LinuxXcbPlatformWindow *window(xcb_window_t xcbWindow) const; 50 | 51 | KDUtils::Dir standardDir(const KDFoundation::CoreApplication &app, KDFoundation::StandardDir type) const override; 52 | 53 | private: 54 | LinuxXcbPlatformEventLoop *createPlatformEventLoopImpl() override; 55 | LinuxXcbPlatformWindow *createPlatformWindowImpl(Window *window) override; 56 | 57 | bool initializeXkbExtension(); 58 | static void dumpScreenInfo(xcb_screen_t *screen); 59 | 60 | std::shared_ptr m_logger; 61 | xcb_connection_t *m_connection{ nullptr }; 62 | xcb_screen_t *m_screen{ nullptr }; 63 | std::unique_ptr m_keyboard; 64 | std::map m_windows; 65 | std::unique_ptr m_clipboard; 66 | }; 67 | 68 | } // namespace KDGui 69 | -------------------------------------------------------------------------------- /src/KDGui/platform/linux/xcb/linux_xkb_keyboard.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | namespace KDGui { 24 | 25 | class LinuxXcbPlatformIntegration; 26 | 27 | class LinuxXkbKeyboard 28 | { 29 | public: 30 | explicit LinuxXkbKeyboard(LinuxXcbPlatformIntegration *platformIntegration); 31 | ~LinuxXkbKeyboard(); 32 | 33 | void handleKeyPress(xcb_key_press_event_t *ev); 34 | void handleKeyRelease(xcb_key_release_event_t *ev); 35 | 36 | private: 37 | void registerForEvents(); 38 | 39 | struct XkbContextDeleter { 40 | void operator()(xkb_context *context) const { return xkb_context_unref(context); } 41 | }; 42 | using ScopedXkbContext = std::unique_ptr; 43 | 44 | struct XkbKeymapDeleter { 45 | void operator()(xkb_keymap *keymap) const { return xkb_keymap_unref(keymap); } 46 | }; 47 | using ScopedXkbKeymap = std::unique_ptr; 48 | 49 | struct XkbStateDeleter { 50 | void operator()(xkb_state *state) const { return xkb_state_unref(state); } 51 | }; 52 | using ScopedXkbState = std::unique_ptr; 53 | 54 | std::shared_ptr m_logger; 55 | LinuxXcbPlatformIntegration *m_platformIntegration{ nullptr }; 56 | ScopedXkbContext m_context; 57 | ScopedXkbKeymap m_keymap; 58 | ScopedXkbState m_state; 59 | int32_t m_deviceId; 60 | }; 61 | 62 | } // namespace KDGui 63 | -------------------------------------------------------------------------------- /src/KDGui/platform/win32/win32_gui_platform_integration.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include "win32_platform_window.h" 19 | 20 | #include 21 | 22 | namespace KDGui { 23 | 24 | class Win32GuiPlatformIntegration : public AbstractGuiPlatformIntegration 25 | { 26 | public: 27 | Win32GuiPlatformIntegration(); 28 | ~Win32GuiPlatformIntegration() override; 29 | 30 | std::shared_ptr logger() { return m_logger; } 31 | 32 | bool registerWindowClass(const std::wstring &className, unsigned style, WNDPROC windowProc); 33 | 34 | AbstractClipboard *clipboard() override 35 | { 36 | // TODO(win32): Implement clipboard 37 | return nullptr; 38 | } 39 | 40 | KDUtils::Dir standardDir(const KDFoundation::CoreApplication &app, KDFoundation::StandardDir type) const override; 41 | 42 | private: 43 | KDFoundation::Win32PlatformEventLoop *createPlatformEventLoopImpl() override; 44 | Win32PlatformWindow *createPlatformWindowImpl(Window *window) override; 45 | 46 | void unregisterWindowClasses(); 47 | 48 | std::shared_ptr m_logger; 49 | std::set m_windowClasses; 50 | }; 51 | 52 | } // namespace KDGui 53 | -------------------------------------------------------------------------------- /src/KDGui/platform/win32/win32_keyboard_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | namespace KDGui { 17 | 18 | Key windowsScanCodeToKey(unsigned scanCode); 19 | } 20 | -------------------------------------------------------------------------------- /src/KDGui/platform/win32/win32_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include "win32_utils.h" 13 | 14 | #include 15 | 16 | namespace KDGui { 17 | 18 | std::string windowsErrorMessage(unsigned long errorCode) 19 | { 20 | char *messageBuffer = nullptr; 21 | auto length = FormatMessageA( 22 | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 23 | nullptr, errorCode, 0, reinterpret_cast(&messageBuffer), 0, nullptr); 24 | if (!length) 25 | return "Unknown error " + std::to_string(errorCode); 26 | auto result = std::string(messageBuffer); 27 | LocalFree(messageBuffer); 28 | return result; 29 | } 30 | 31 | std::wstring utf8StringToWide(std::string_view source) 32 | { 33 | const auto count = MultiByteToWideChar(CP_UTF8, 0, source.data(), static_cast(source.size()), nullptr, 0); 34 | if (!count) { 35 | SPDLOG_WARN("Failed to convert string from UTF-8"); 36 | return {}; 37 | } 38 | 39 | std::wstring result(count, 0); 40 | if (!MultiByteToWideChar(CP_UTF8, 0, source.data(), static_cast(source.size()), result.data(), count)) { 41 | SPDLOG_WARN("Failed to convert string from UTF-8"); 42 | return {}; 43 | } 44 | 45 | return result; 46 | } 47 | 48 | std::string wideStringToUtf8(std::wstring_view source) 49 | { 50 | const auto count = WideCharToMultiByte(CP_UTF8, 0, source.data(), static_cast(source.size()), nullptr, 0, nullptr, nullptr); 51 | if (!count) { 52 | SPDLOG_WARN("Failed to convert string to UTF-8"); 53 | return {}; 54 | } 55 | 56 | std::string result(count, 0); 57 | if (!WideCharToMultiByte(CP_UTF8, 0, source.data(), static_cast(source.size()), result.data(), count, nullptr, nullptr)) { 58 | SPDLOG_WARN("Failed to convert string to UTF-8"); 59 | return {}; 60 | } 61 | 62 | return result; 63 | } 64 | 65 | } // namespace KDGui 66 | -------------------------------------------------------------------------------- /src/KDGui/platform/win32/win32_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | namespace KDGui { 20 | 21 | std::string windowsErrorMessage(unsigned long errorCode); 22 | 23 | std::wstring utf8StringToWide(std::string_view source); 24 | std::string wideStringToUtf8(std::wstring_view source); 25 | } // namespace KDGui 26 | -------------------------------------------------------------------------------- /src/KDGui/position.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace KDGui { 19 | 20 | class KDGUI_API Position 21 | { 22 | public: 23 | int64_t x; 24 | int64_t y; 25 | 26 | Position(int64_t _x = 0, int64_t _y = 0) 27 | : x(_x), y(_y) { } 28 | 29 | bool operator==(const Position &other) const { return x == other.x && y == other.y; } 30 | bool operator!=(const Position &other) const { return !(*this == other); } 31 | Position &operator+=(const Position &other) 32 | { 33 | x += other.x; 34 | y += other.y; 35 | return *this; 36 | } 37 | Position &operator/=(int64_t v) 38 | { 39 | x /= v; 40 | y /= v; 41 | return *this; 42 | } 43 | Position &operator*=(int64_t v) 44 | { 45 | x *= v; 46 | y *= v; 47 | return *this; 48 | } 49 | }; 50 | 51 | inline Position operator+(const Position &a, const Position &b) 52 | { 53 | return Position(a.x + b.x, a.y + b.y); 54 | } 55 | inline Position operator-(const Position &a, const Position &b) 56 | { 57 | return Position(a.x - b.x, a.y - b.y); 58 | } 59 | inline Position operator/(const Position &a, int64_t v) 60 | { 61 | return Position(a.x / v, a.y / v); 62 | } 63 | 64 | } // namespace KDGui 65 | -------------------------------------------------------------------------------- /src/KDMqtt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Marco Thaller 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | set(SOURCES mqtt.cpp) 12 | 13 | set(HEADERS mosquitto_wrapper.h mqtt.h) 14 | 15 | add_library( 16 | KDMqtt 17 | ${SOURCES} ${HEADERS} 18 | ) 19 | 20 | add_library( 21 | KDUtils::KDMqtt ALIAS KDMqtt 22 | ) 23 | 24 | target_link_libraries( 25 | KDMqtt 26 | PUBLIC KDUtils::KDFoundation Mosquitto::Mosquitto 27 | ) 28 | 29 | target_include_directories( 30 | KDMqtt 31 | PRIVATE $ 32 | ) 33 | 34 | # 35 | # Logging configuration 36 | # 37 | # Compile out some of the SPDLOG macros based on build type 38 | target_compile_definitions( 39 | KDMqtt PRIVATE SPDLOG_ACTIVE_LEVEL=$,SPDLOG_LEVEL_TRACE,SPDLOG_LEVEL_WARN> 40 | ) 41 | target_link_libraries( 42 | KDMqtt 43 | PRIVATE spdlog::spdlog 44 | ) 45 | 46 | generate_export_header(KDMqtt BASE_NAME kdmqtt) 47 | configure_file(${CMAKE_CURRENT_BINARY_DIR}/kdmqtt_export.h ${CMAKE_BINARY_DIR}/include/KDMqtt/kdmqtt_export.h) 48 | install( 49 | FILES ${CMAKE_CURRENT_BINARY_DIR}/kdmqtt_export.h 50 | DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/KDMqtt 51 | ) 52 | 53 | foreach(file ${HEADERS}) 54 | get_filename_component(dir ${file} DIRECTORY) 55 | install(FILES ${file} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/KDMqtt/${dir}) 56 | endforeach() 57 | 58 | set(project_config_in "${CMAKE_CURRENT_LIST_DIR}/cmake/KDMqttConfig.cmake.in") 59 | set(project_config_out "${CMAKE_CURRENT_BINARY_DIR}/KDMqttConfig.cmake") 60 | 61 | install( 62 | TARGETS KDMqtt 63 | EXPORT KDMqtt 64 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 65 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 66 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 67 | ) 68 | 69 | install( 70 | EXPORT KDMqtt 71 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/KDMqtt 72 | NAMESPACE KDUtils:: 73 | FILE KDMqttConfigTargets.cmake 74 | ) 75 | include(CMakePackageConfigHelpers) 76 | configure_file("${project_config_in}" "${project_config_out}" @ONLY) 77 | install( 78 | FILES "${project_config_out}" 79 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/KDMqtt 80 | ) 81 | install( 82 | FILES ${HEADERS} 83 | DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/KDMqtt 84 | ) 85 | -------------------------------------------------------------------------------- /src/KDMqtt/cmake/KDMqttConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Marco Thaller 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | include(CMakeFindDependencyMacro) 12 | find_dependency(KDFoundation) 13 | find_dependency(mosquitto) 14 | 15 | include("${CMAKE_CURRENT_LIST_DIR}/KDMqttConfigTargets.cmake") 16 | -------------------------------------------------------------------------------- /src/KDMqtt/kdmqtt_global.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Marco Thaller 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #define KDMQTT_API KDMQTT_EXPORT 17 | -------------------------------------------------------------------------------- /src/KDUtils/cmake/KDUtilsConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | include(CMakeFindDependencyMacro) 12 | find_dependency(spdlog) 13 | 14 | include("${CMAKE_CURRENT_LIST_DIR}/KDUtilsConfigTargets.cmake") 15 | -------------------------------------------------------------------------------- /src/KDUtils/dir.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #ifndef KDUTILS_DIR_H 13 | #define KDUTILS_DIR_H 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace KDUtils { 21 | 22 | class KDUTILS_API Dir 23 | { 24 | public: 25 | Dir(); 26 | Dir(const char *path, StorageType type = StorageType::Normal); 27 | Dir(const std::string &path, StorageType type = StorageType::Normal); 28 | Dir(const std::filesystem::path &path, StorageType type = StorageType::Normal); 29 | 30 | bool exists() const; 31 | 32 | struct MkDirOptions { 33 | bool createParentDirectories{ false }; 34 | }; 35 | bool mkdir(const MkDirOptions &options = { false }); 36 | bool rmdir(); 37 | 38 | std::string path() const; 39 | std::string dirName() const; 40 | std::string absoluteFilePath(const std::string &file) const; 41 | StorageType type() const; 42 | 43 | File file(const std::string &fileName) const; 44 | 45 | Dir parent() const; 46 | bool hasParent() const; 47 | 48 | // Returns a directory based on a relative path from this directory, preserving the storage type 49 | Dir relativeDir(const std::string &relativePath) const; 50 | 51 | static Dir applicationDir(); 52 | static std::string fromNativeSeparators(const std::string &path); 53 | 54 | bool operator==(const Dir &other) const; 55 | 56 | private: 57 | std::filesystem::path m_path; 58 | StorageType m_type = StorageType::Normal; 59 | }; 60 | 61 | } // namespace KDUtils 62 | 63 | #endif // KUESA_COREUTILS_DIR_H 64 | -------------------------------------------------------------------------------- /src/KDUtils/elapsedtimer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include "elapsedtimer.h" 13 | 14 | namespace KDUtils { 15 | 16 | ElapsedTimer::ElapsedTimer() = default; 17 | 18 | ElapsedTimer::NsecDuration ElapsedTimer::elapsed() const 19 | { 20 | const TimePoint now = Clock::now(); 21 | return now - m_startTimePoint; 22 | } 23 | 24 | int64_t ElapsedTimer::nsecElapsed() const 25 | { 26 | return elapsed().count(); 27 | } 28 | 29 | int64_t ElapsedTimer::msecElapsed() const 30 | { 31 | return std::chrono::duration_cast(elapsed()).count(); 32 | } 33 | 34 | ElapsedTimer::NsecDuration ElapsedTimer::restart() 35 | { 36 | const NsecDuration lastElapsed = elapsed(); 37 | start(); 38 | return lastElapsed; 39 | } 40 | 41 | void ElapsedTimer::start() 42 | { 43 | m_startTimePoint = Clock::now(); 44 | } 45 | 46 | } // namespace KDUtils 47 | -------------------------------------------------------------------------------- /src/KDUtils/elapsedtimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #ifndef KDUTILS_ELAPSEDTIMER_H 13 | #define KDUTILS_ELAPSEDTIMER_H 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | namespace KDUtils { 20 | 21 | class KDUTILS_API ElapsedTimer 22 | { 23 | public: 24 | using Clock = std::chrono::high_resolution_clock; 25 | using TimePoint = std::chrono::time_point; 26 | using NsecDuration = std::chrono::duration; 27 | using MsecDuration = std::chrono::duration; 28 | 29 | ElapsedTimer(); 30 | 31 | NsecDuration elapsed() const; 32 | int64_t msecElapsed() const; 33 | int64_t nsecElapsed() const; // Compatibility with Qt API 34 | 35 | NsecDuration restart(); 36 | void start(); 37 | 38 | private: 39 | TimePoint m_startTimePoint = Clock::now(); 40 | }; 41 | 42 | } // namespace KDUtils 43 | 44 | #endif // KUESA_COREUTILS_ELAPSEDTIMER_H 45 | -------------------------------------------------------------------------------- /src/KDUtils/file.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace KDUtils { 19 | 20 | // Some platforms have special requirements for accessing some file types 21 | // such as assets and shared data directories on Android. 22 | // For Desktop platforms, type should always be Normal. 23 | enum class StorageType { 24 | Normal, // Files that can be accessed normally using the c++ standard library 25 | Asset, // Files that must be accessed from an application's embedded assets 26 | }; 27 | 28 | struct PlatformFileData; 29 | 30 | class KDUTILS_API File 31 | { 32 | public: 33 | File(const std::string &path, StorageType type = StorageType::Normal); 34 | ~File(); 35 | 36 | // Can't be copied 37 | File(File &) = delete; 38 | File &operator=(File &) = delete; 39 | 40 | bool exists() const; 41 | static bool exists(const std::string &path, StorageType type = StorageType::Normal); 42 | 43 | bool open(std::ios_base::openmode mode); 44 | bool isOpen() const; 45 | void flush(); 46 | void close(); 47 | bool remove(); 48 | 49 | ByteArray readAll(); 50 | void write(const ByteArray &data); 51 | std::string fileName() const; 52 | const std::string &path() const; 53 | StorageType type() const; 54 | 55 | std::uintmax_t size() const; 56 | static std::uintmax_t size(const std::string &path, StorageType type = StorageType::Normal); 57 | 58 | private: 59 | std::string m_path; 60 | std::unique_ptr m_data; 61 | StorageType m_type = StorageType::Normal; 62 | }; 63 | 64 | } // namespace KDUtils 65 | -------------------------------------------------------------------------------- /src/KDUtils/file_mapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | #ifndef KDUTILS_FILE_MAPPER_H 12 | #define KDUTILS_FILE_MAPPER_H 13 | #include 14 | #include 15 | 16 | namespace KDUtils { 17 | /// Provides memory mapping from a file. 18 | class KDUTILS_API FileMapper 19 | { 20 | public: 21 | struct Map; 22 | 23 | FileMapper(File &&); 24 | ~FileMapper(); 25 | // can be moved 26 | FileMapper(FileMapper &&) = default; 27 | FileMapper &operator=(FileMapper &&) = default; 28 | // cannot be copied 29 | FileMapper(FileMapper &) = delete; 30 | FileMapper &operator=(FileMapper &) = delete; 31 | 32 | /// Produces a pointer to read-only mapped data. Becomes invalid when the FileMapper is destroyed. 33 | /// Closes and makes invalid any existing mappings. 34 | /// @arg offset: the start of the mapping relative to the beginning of the file, in bytes. 35 | /// @arg length: the number of bytes after the start of the mapping to map 36 | /// @return: the pointer to the mapped data or nullptr on failure. 37 | const uint8_t *map(std::uintmax_t offset = 0, std::uintmax_t length = 0) const; 38 | 39 | /// Produces a pointer to writable mapped data. Becomes invalid when the FileMapper is destroyed. 40 | /// Closes and makes invalid any existing mappings. 41 | /// @arg offset: the start of the mapping relative to the beginning of the file, in bytes. 42 | /// @arg length: the number of bytes after the start of the mapping to map 43 | /// @return: the pointer to the mapped data or nullptr on failure. 44 | uint8_t *map(std::uintmax_t offset = 0, std::uintmax_t length = 0); 45 | 46 | /// Closes the existing mapping. 47 | /// @arg mapping: The memory acquired with `map`. 48 | /// May also be nullptr. 49 | /// @return: true on success, false on IO failure or invalid pointer. 50 | bool unmap(const uint8_t *mapping); 51 | 52 | const std::string &path() const; 53 | 54 | /// Returns the size of the *mapping*. May differ from the size of the file. 55 | std::uintmax_t size() const; 56 | 57 | private: 58 | std::string m_path; 59 | std::unique_ptr m_map; 60 | }; 61 | } // namespace KDUtils 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/KDUtils/kdutils_global.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Mike Krus 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | 16 | #define KDUTILS_API KDUTILS_EXPORT 17 | 18 | #define KD_UNUSED(x) (void)x; 19 | -------------------------------------------------------------------------------- /src/KDUtils/logging.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | 6 | SPDX-License-Identifier: MIT 7 | 8 | Contact KDAB at for commercial licensing options. 9 | */ 10 | 11 | #include "logging.h" 12 | #if defined(ANDROID) 13 | #include 14 | #elif defined(_WIN32) 15 | #include 16 | #endif 17 | 18 | namespace KDUtils { 19 | 20 | Logger::LoggerFactoryFunction Logger::ms_loggerFactory = {}; 21 | 22 | std::shared_ptr Logger::logger(const std::string &name, spdlog::level::level_enum defaultLevel) 23 | { 24 | std::shared_ptr logger; 25 | if (ms_loggerFactory) { 26 | // Use the factory set by the application which should check 27 | // its own spdlog registry first before creating a new logger. 28 | logger = ms_loggerFactory(name, defaultLevel); 29 | } else { 30 | // No factory set, use the spdlog registry from KDUtils 31 | logger = spdlog::get(name); 32 | if (!logger) { 33 | #if defined(ANDROID) 34 | logger = spdlog::android_logger_mt(name, name); 35 | #elif defined(_WIN32) 36 | // Create both msvc_sink and stdout_color_sink 37 | auto msvc_sink = std::make_shared(); 38 | auto console_sink = std::make_shared(); 39 | logger = std::make_shared(name, spdlog::sinks_init_list{ msvc_sink, console_sink }); 40 | #else 41 | logger = spdlog::stdout_color_mt(name); 42 | #endif 43 | logger->set_level(defaultLevel); 44 | } 45 | } 46 | return logger; 47 | } 48 | 49 | void Logger::setLoggerFactory(const LoggerFactoryFunction &factory) 50 | { 51 | ms_loggerFactory = factory; 52 | } 53 | 54 | Logger::LoggerFactoryFunction Logger::loggerFactory() 55 | { 56 | return ms_loggerFactory; 57 | } 58 | 59 | } // namespace KDUtils 60 | -------------------------------------------------------------------------------- /src/KDUtils/logging.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | 6 | SPDX-License-Identifier: MIT 7 | 8 | Contact KDAB at for commercial licensing options. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | namespace KDUtils { 21 | 22 | class KDUTILS_API Logger 23 | { 24 | public: 25 | static std::shared_ptr logger(const std::string &name, spdlog::level::level_enum defaultLevel = spdlog::level::warn); 26 | 27 | using LoggerFactoryFunction = std::function(const std::string &, spdlog::level::level_enum)>; 28 | 29 | static void setLoggerFactory(const LoggerFactoryFunction &factory); 30 | static LoggerFactoryFunction loggerFactory(); 31 | 32 | private: 33 | static LoggerFactoryFunction ms_loggerFactory; 34 | }; 35 | 36 | } // namespace KDUtils 37 | -------------------------------------------------------------------------------- /src/KDUtils/platform/android/android_file.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | 6 | SPDX-License-Identifier: MIT 7 | 8 | Contact KDAB at for commercial licensing options. 9 | */ 10 | #pragma once 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace KDUtils { 17 | 18 | KDUTILS_API void setAssetManager(AAssetManager *assetManager); 19 | KDUTILS_API AAssetManager *assetManager(); 20 | 21 | } // namespace KDUtils 22 | -------------------------------------------------------------------------------- /src/KDUtils/url.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include "url.h" 13 | #include "dir.h" 14 | #include 15 | 16 | using namespace std::string_literals; 17 | 18 | namespace KDUtils { 19 | 20 | Url::Url(const std::string &url) 21 | : m_url(url) 22 | { 23 | const std::regex rexExp(u8"(?:([^\\/]{2,})?:(?:\\/\\/)?)?(.*\\/)*(.+\\..+)?"s); 24 | std::smatch match; 25 | const bool hasMatch = std::regex_match(m_url, match, rexExp); 26 | if (hasMatch) { 27 | m_scheme = match[1].str(); 28 | m_path = match[2].str(); 29 | m_fileName = match[3].str(); 30 | } 31 | } 32 | 33 | bool Url::isLocalFile() const 34 | { 35 | return m_scheme.rfind(u8"file"s, 0) == 0; 36 | } 37 | 38 | std::string Url::toLocalFile() const 39 | { 40 | if (!isLocalFile()) 41 | return {}; 42 | return m_path + m_fileName; 43 | } 44 | 45 | std::string Url::scheme() const 46 | { 47 | return m_scheme; 48 | } 49 | 50 | std::string Url::fileName() const 51 | { 52 | return m_fileName; 53 | } 54 | 55 | std::string Url::path() const 56 | { 57 | return m_path; 58 | } 59 | 60 | std::string Url::url() const 61 | { 62 | return m_url; 63 | } 64 | 65 | Url Url::fromLocalFile(const std::string &url) 66 | { 67 | std::string path = Dir::fromNativeSeparators(url); 68 | Url u(path); 69 | // If url has a scheme, we return it 70 | if (!u.scheme().empty()) 71 | return u; 72 | // Do we hold a path? 73 | if (u.path().empty()) 74 | return Url(std::string("file:") + path); 75 | const bool isWindowsPath = path.size() > 1 && path[1] == ':' && path[0] != '/'; 76 | if (isWindowsPath) 77 | path.insert(path.begin(), '/'); 78 | return Url(std::string("file://") + path); 79 | } 80 | 81 | bool operator==(const Url &a, const Url &b) 82 | { 83 | return a.url() == b.url(); 84 | } 85 | 86 | bool operator!=(const Url &a, const Url &b) 87 | { 88 | return !(a == b); 89 | } 90 | 91 | } // namespace KDUtils 92 | -------------------------------------------------------------------------------- /src/KDUtils/url.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #ifndef KDUTILS_URL_H 13 | #define KDUTILS_URL_H 14 | 15 | #include 16 | #include 17 | 18 | namespace KDUtils { 19 | 20 | class KDUTILS_API Url 21 | { 22 | public: 23 | Url() = default; 24 | explicit Url(const std::string &url); 25 | 26 | bool isLocalFile() const; 27 | std::string toLocalFile() const; 28 | std::string scheme() const; 29 | std::string fileName() const; 30 | std::string path() const; 31 | std::string url() const; 32 | bool empty() const { return m_url.empty(); } 33 | bool isEmpty() const { return empty(); } 34 | 35 | static Url fromLocalFile(const std::string &url); 36 | 37 | private: 38 | std::string m_url; 39 | std::string m_fileName; 40 | std::string m_scheme; 41 | std::string m_path; 42 | }; 43 | 44 | KDUTILS_API bool operator==(const Url &a, const Url &b); 45 | KDUTILS_API bool operator!=(const Url &a, const Url &b); 46 | 47 | } // namespace KDUtils 48 | 49 | #endif // KUESA_COREUTILS_URL_H 50 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | # doctest library 12 | find_package(doctest QUIET) 13 | if(TARGET doctest::doctest) 14 | # Apply https://github.com/doctest/doctest/pull/812 15 | # to be able to #include instead of #include 16 | get_target_property(DOCTEST_INTERFACE_INCLUDE_DIRECTORIES doctest::doctest INTERFACE_INCLUDE_DIRECTORIES) 17 | target_include_directories( 18 | doctest::doctest SYSTEM 19 | INTERFACE "${DOCTEST_INTERFACE_INCLUDE_DIRECTORIES};${DOCTEST_INTERFACE_INCLUDE_DIRECTORIES}/doctest" 20 | ) 21 | else() 22 | fetchcontent_declare( 23 | doctest 24 | GIT_REPOSITORY https://github.com/doctest/doctest.git 25 | GIT_TAG 3a01ec37828affe4c9650004edb5b304fb9d5b75 # dev branch commit with CMake compatibility fix 26 | ) 27 | fetchcontent_makeavailable(doctest) 28 | 29 | list(APPEND CMAKE_MODULE_PATH ${doctest_SOURCE_DIR}/scripts/cmake) 30 | 31 | target_include_directories( 32 | doctest SYSTEM INTERFACE $ 33 | $ 34 | ) 35 | 36 | # Copy all include directories to SYSTEM property so we don't get warnings from doctest 37 | #TODO(cmake >=3.25): remove these two lines and add SYSTEM to doctest's FetchContent_Declare 38 | get_target_property(DOCTEST_IID doctest INTERFACE_INCLUDE_DIRECTORIES) 39 | set_target_properties(doctest PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${DOCTEST_IID}") 40 | 41 | if(APPLE) 42 | target_compile_options(doctest INTERFACE -Wno-deprecated-declarations) 43 | endif() 44 | 45 | install(DIRECTORY ${doctest_SOURCE_DIR}/doctest/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/KDUtils/doctest) 46 | endif() 47 | 48 | add_subdirectory(auto/utils) 49 | add_subdirectory(auto/foundation) 50 | add_subdirectory(auto/gui) 51 | if(KDUTILS_BUILD_MQTT_SUPPORT) 52 | add_subdirectory(auto/mqtt) 53 | endif() 54 | -------------------------------------------------------------------------------- /tests/auto/foundation/common/signal_spy.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | template 20 | class SignalSpy 21 | { 22 | public: 23 | template 24 | explicit SignalSpy(Signal &s) 25 | { 26 | m_connection = s.connect([this](Args... args) { 27 | callback(args...); 28 | }); 29 | } 30 | 31 | bool isValid() const 32 | { 33 | return true; 34 | } 35 | 36 | std::tuple &args() 37 | { 38 | return m_args; 39 | } 40 | 41 | void clear() 42 | { 43 | m_args = {}; 44 | m_count = 0; 45 | } 46 | 47 | uint32_t count() const 48 | { 49 | return m_count; 50 | } 51 | 52 | using milliseconds = std::chrono::duration; 53 | 54 | bool wait(milliseconds timeout = milliseconds(5000)) 55 | { 56 | milliseconds elapsed; 57 | const auto step = milliseconds({ timeout / 5 }); 58 | const uint32_t refCount = m_count; 59 | while (elapsed < timeout) { 60 | std::this_thread::sleep_for(step); 61 | if (m_count > refCount) 62 | return true; 63 | elapsed += step; 64 | } 65 | return false; 66 | } 67 | 68 | private: 69 | void callback(Args... args) 70 | { 71 | m_args = std::make_tuple(args...); 72 | ++m_count; 73 | } 74 | 75 | uint32_t m_count = 0; 76 | std::tuple m_args; 77 | KDBindings::ScopedConnection m_connection; 78 | }; 79 | -------------------------------------------------------------------------------- /tests/auto/foundation/constexpr_sort/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | project( 12 | test-core-constexpr-sort 13 | VERSION 0.1 14 | LANGUAGES CXX 15 | ) 16 | 17 | add_core_test(${PROJECT_NAME} tst_constexpr_sort.cpp) 18 | -------------------------------------------------------------------------------- /tests/auto/foundation/constexpr_sort/tst_constexpr_sort.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include 13 | 14 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 15 | #include 16 | 17 | using namespace KDFoundation; 18 | 19 | TEST_CASE("Simple type") 20 | { 21 | SUBCASE("can create a sorted array of integers") 22 | { 23 | constexpr auto a = KDFoundation::sort(std::array{ 2, 5, 1, 8, 4 }); 24 | 25 | constexpr std::array expectedResult{ 1, 2, 4, 5, 8 }; 26 | for (auto i = 0; i < a.size(); ++i) 27 | REQUIRE(expectedResult[i] == a[i]); 28 | } 29 | } 30 | 31 | struct Entry { 32 | uint32_t x; 33 | uint32_t y; 34 | 35 | constexpr bool operator<(Entry const &other) const noexcept 36 | { 37 | return x < other.x; 38 | } 39 | 40 | bool operator==(Entry const &other) const noexcept 41 | { 42 | return x == other.x && y == other.y; 43 | } 44 | }; 45 | 46 | TEST_CASE("Struct") 47 | { 48 | SUBCASE("can create a sorted array of structs") 49 | { 50 | constexpr auto a = KDFoundation::sort( 51 | std::array{ 52 | Entry{ 4, 11 }, 53 | Entry{ 1, 2 }, 54 | Entry{ 5, 14 }, 55 | Entry{ 3, 8 }, 56 | Entry{ 2, 5 } }); 57 | 58 | constexpr std::array expectedResult{ 59 | Entry{ 1, 2 }, 60 | Entry{ 2, 5 }, 61 | Entry{ 3, 8 }, 62 | Entry{ 4, 11 }, 63 | Entry{ 5, 14 } 64 | }; 65 | 66 | for (auto i = 0; i < a.size(); ++i) 67 | REQUIRE(expectedResult[i] == a[i]); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/auto/foundation/core_application/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | project( 12 | test-core-core-application 13 | VERSION 0.1 14 | LANGUAGES CXX 15 | ) 16 | 17 | add_core_test(${PROJECT_NAME} tst_core_application.cpp) 18 | -------------------------------------------------------------------------------- /tests/auto/foundation/destruction_helper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | project( 12 | test-core-destruction-helper 13 | VERSION 0.1 14 | LANGUAGES CXX 15 | ) 16 | 17 | add_core_test(${PROJECT_NAME} tst_destruction_helper.cpp) 18 | -------------------------------------------------------------------------------- /tests/auto/foundation/event/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | project( 12 | test-core-event 13 | VERSION 0.1 14 | LANGUAGES CXX 15 | ) 16 | 17 | add_core_test(${PROJECT_NAME} tst_event.cpp) 18 | -------------------------------------------------------------------------------- /tests/auto/foundation/event_queue/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | project( 12 | test-core-event-queue 13 | VERSION 0.1 14 | LANGUAGES CXX 15 | ) 16 | 17 | add_core_test(${PROJECT_NAME} tst_event_queue.cpp) 18 | -------------------------------------------------------------------------------- /tests/auto/foundation/linux_platform_event_loop/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | project( 12 | test-core-linux-platform-event-loop 13 | VERSION 0.1 14 | LANGUAGES CXX 15 | ) 16 | 17 | add_core_test(${PROJECT_NAME} tst_linux_platform_event_loop.cpp) 18 | -------------------------------------------------------------------------------- /tests/auto/foundation/macos_platform_event_loop/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | project( 12 | test-core-macos-platform-event-loop 13 | VERSION 0.1 14 | LANGUAGES CXX 15 | ) 16 | 17 | add_executable( 18 | ${PROJECT_NAME} 19 | tst_macos_platform_event_loop.cpp 20 | ) 21 | 22 | target_link_libraries( 23 | ${PROJECT_NAME} KDFoundation doctest::doctest 24 | ) 25 | 26 | add_test(NAME ${PROJECT_NAME} COMMAND $) 27 | -------------------------------------------------------------------------------- /tests/auto/foundation/object/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | project( 12 | test-core-object 13 | VERSION 0.1 14 | LANGUAGES CXX 15 | ) 16 | 17 | add_core_test(${PROJECT_NAME} tst_object.cpp) 18 | -------------------------------------------------------------------------------- /tests/auto/foundation/win32_platform_event_loop/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | project( 12 | test-core-win32-platform-event-loop 13 | VERSION 0.1 14 | LANGUAGES CXX 15 | ) 16 | 17 | add_executable( 18 | ${PROJECT_NAME} 19 | tst_win32_platform_event_loop.cpp 20 | ) 21 | 22 | target_link_libraries( 23 | ${PROJECT_NAME} KDFoundation doctest::doctest ws2_32 24 | ) 25 | 26 | add_test(NAME ${PROJECT_NAME} COMMAND $) 27 | set_tests_properties(${PROJECT_NAME} PROPERTIES LABELS "Core") 28 | -------------------------------------------------------------------------------- /tests/auto/gui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | project(KDGui-Tests) 12 | 13 | include_directories(../KDFoundation/common) 14 | 15 | add_subdirectory(position) 16 | add_subdirectory(window) 17 | 18 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") 19 | add_subdirectory(linux_xcb_platform_window) 20 | endif() 21 | 22 | add_feature_info(KDGui-Tests ON "Build KDGui Tests") 23 | 24 | if(KDUTILS_CODE_COVERAGE) 25 | setup_target_for_coverage_gcovr_html( 26 | NAME 27 | gui_coverage 28 | BASE_DIRECTORY 29 | ${CMAKE_SOURCE_DIR} 30 | EXECUTABLE 31 | ctest 32 | -L 33 | "Gui" 34 | EXCLUDE 35 | "${CMAKE_BINARY_DIR}/_deps/*" 36 | "${CMAKE_BINARY_DIR}/src/*" 37 | "${CMAKE_SOURCE_DIR}/src/utils/*" 38 | "${CMAKE_SOURCE_DIR}/src/foundation/*" 39 | "${CMAKE_SOURCE_DIR}/src/3rdparty/*" 40 | ) 41 | add_feature_info(Gui-Coverage ON "Generate Code Coverage - ninja gui_coverage") 42 | endif() 43 | -------------------------------------------------------------------------------- /tests/auto/gui/linux_xcb_platform_window/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | project( 12 | test-gui-linux-xcb-platform-window 13 | VERSION 0.1 14 | LANGUAGES CXX 15 | ) 16 | 17 | add_executable( 18 | ${PROJECT_NAME} 19 | tst_linux_xcb_platform_window.cpp 20 | ) 21 | 22 | target_link_libraries( 23 | ${PROJECT_NAME} KDGui doctest::doctest 24 | ) 25 | 26 | add_test(NAME ${PROJECT_NAME} COMMAND $) 27 | set_tests_properties(${PROJECT_NAME} PROPERTIES LABELS "Gui") 28 | -------------------------------------------------------------------------------- /tests/auto/gui/linux_xcb_platform_window/tst_linux_xcb_platform_window.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Paul Lemire 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 19 | #include 20 | 21 | using namespace KDGui; 22 | 23 | static_assert(std::is_destructible{}); 24 | static_assert(!std::is_default_constructible{}); 25 | static_assert(!std::is_copy_constructible{}); 26 | static_assert(!std::is_copy_assignable{}); 27 | static_assert(std::is_nothrow_move_constructible{}); 28 | static_assert(std::is_nothrow_move_assignable{}); 29 | 30 | TEST_CASE("Creation") 31 | { 32 | spdlog::set_level(spdlog::level::debug); 33 | 34 | SUBCASE("can create a linux platform window") 35 | { 36 | auto w = std::make_unique(); 37 | auto platformIntegration = std::make_unique(); 38 | auto platformWindow = std::make_unique(platformIntegration.get(), w.get()); 39 | REQUIRE(platformWindow->window() == w.get()); 40 | REQUIRE(platformWindow->type() == AbstractPlatformWindow::Type::XCB); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/auto/gui/position/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Joshua Goins 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | project( 12 | test-gui-position 13 | VERSION 0.1 14 | LANGUAGES CXX 15 | ) 16 | 17 | add_executable( 18 | ${PROJECT_NAME} 19 | tst_position.cpp 20 | ) 21 | 22 | target_link_libraries( 23 | ${PROJECT_NAME} KDGui doctest::doctest 24 | ) 25 | 26 | add_test(NAME ${PROJECT_NAME} COMMAND $) 27 | set_tests_properties(${PROJECT_NAME} PROPERTIES LABELS "Gui") 28 | -------------------------------------------------------------------------------- /tests/auto/gui/position/tst_position.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Joshua Goins 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 16 | #include 17 | 18 | using namespace KDGui; 19 | 20 | TEST_SUITE("Position") 21 | { 22 | TEST_CASE("Constructor") 23 | { 24 | const Position pos{ 1, 2 }; 25 | REQUIRE_EQ(pos.x, 1); 26 | REQUIRE_EQ(pos.y, 2); 27 | } 28 | TEST_CASE("Equality") 29 | { 30 | const Position a{ 0, 2 }; 31 | const Position b{ 3, 4 }; 32 | const Position c{ 0, 0 }; 33 | 34 | REQUIRE(a == a); 35 | REQUIRE(a != b); 36 | REQUIRE(a != c); 37 | } 38 | TEST_CASE("Math Operators") 39 | { 40 | const Position a{ 1, 2 }; 41 | const Position b{ 3, 4 }; 42 | 43 | REQUIRE_EQ(a + b, Position(4, 6)); 44 | REQUIRE_EQ(a - b, Position(-2, -2)); 45 | REQUIRE_EQ(a / int64_t{ 2 }, Position(0, 1)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/auto/gui/window/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | project( 12 | test-gui-window 13 | VERSION 0.1 14 | LANGUAGES CXX 15 | ) 16 | 17 | add_executable( 18 | ${PROJECT_NAME} 19 | tst_window.cpp 20 | ) 21 | 22 | target_link_libraries( 23 | ${PROJECT_NAME} KDGui doctest::doctest 24 | ) 25 | 26 | add_test(NAME ${PROJECT_NAME} COMMAND $) 27 | set_tests_properties(${PROJECT_NAME} PROPERTIES LABELS "Gui") 28 | -------------------------------------------------------------------------------- /tests/auto/mqtt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Marco Thaller 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | project(KDMqtt-Tests) 12 | 13 | include_directories(../KDFoundation/common) 14 | 15 | file(DOWNLOAD https://raw.githubusercontent.com/eranpeer/FakeIt/refs/tags/2.4.1/single_header/doctest/fakeit.hpp 16 | "${CMAKE_BINARY_DIR}/tests/auto/fakeit.h" 17 | EXPECTED_HASH SHA256=09be612875c0dd0c0692256739eb859e66f6e82c1f1082d50eacb670f471f63b 18 | ) 19 | 20 | project( 21 | test-mqtt 22 | VERSION 0.1 23 | LANGUAGES CXX 24 | ) 25 | 26 | add_executable( 27 | ${PROJECT_NAME} 28 | tst_mqtt.cpp 29 | ) 30 | 31 | target_include_directories( 32 | ${PROJECT_NAME} 33 | PRIVATE ${CMAKE_SOURCE_DIR}/tests/auto/foundation/common ${CMAKE_BINARY_DIR}/tests/auto 34 | ) 35 | 36 | target_link_libraries( 37 | ${PROJECT_NAME} KDMqtt doctest::doctest 38 | ) 39 | 40 | add_test(NAME ${PROJECT_NAME} COMMAND $) 41 | set_tests_properties(${PROJECT_NAME} PROPERTIES LABELS "Mqtt") 42 | 43 | add_feature_info(KDMqtt-Test ON "Build KDMqtt Tests") 44 | 45 | if(KDUTILS_CODE_COVERAGE) 46 | setup_target_for_coverage_gcovr_html( 47 | NAME 48 | mqtt_coverage 49 | BASE_DIRECTORY 50 | ${CMAKE_SOURCE_DIR} 51 | EXECUTABLE 52 | ctest 53 | -L 54 | "Mqtt" 55 | EXCLUDE 56 | "${CMAKE_BINARY_DIR}/_deps/*" 57 | "${CMAKE_BINARY_DIR}/src/*" 58 | "${CMAKE_SOURCE_DIR}/src/utils/*" 59 | "${CMAKE_SOURCE_DIR}/src/foundation/*" 60 | "${CMAKE_SOURCE_DIR}/src/3rdparty/*" 61 | ) 62 | add_feature_info(Mqtt-Coverage ON "Generate Code Coverage - ninja mqtt_coverage") 63 | endif() 64 | -------------------------------------------------------------------------------- /tests/auto/utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | add_feature_info(KDUtils-Test ON "Build KDUtils Tests") 12 | 13 | include(doctest) 14 | 15 | add_subdirectory(bytearray) 16 | add_subdirectory(color) 17 | add_subdirectory(file) 18 | add_subdirectory(dir) 19 | add_subdirectory(elapsedtimer) 20 | add_subdirectory(flags) 21 | add_subdirectory(signal) 22 | add_subdirectory(url) 23 | add_subdirectory(tailwind_colors) 24 | 25 | if(KDUTILS_CODE_COVERAGE) 26 | include(${PROJECT_SOURCE_DIR}/cmake/CodeCoverage.cmake) 27 | setup_target_for_coverage_gcovr_html( 28 | NAME 29 | KDUtils_coverage 30 | EXECUTABLE 31 | ctest 32 | -L 33 | "KDUtils" 34 | EXCLUDE 35 | "${CMAKE_BINARY_DIR}/_deps/*" 36 | "${CMAKE_BINARY_DIR}/src/*" 37 | ) 38 | endif() 39 | -------------------------------------------------------------------------------- /tests/auto/utils/bytearray/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | add_executable( 12 | tst_bytearray 13 | tst_bytearray.cpp 14 | ) 15 | target_link_libraries( 16 | tst_bytearray 17 | PRIVATE KDUtils doctest::doctest 18 | ) 19 | doctest_discover_tests( 20 | tst_bytearray 21 | ADD_LABELS 22 | 1 23 | PROPERTIES 24 | LABELS 25 | "KDUtils" 26 | ) 27 | -------------------------------------------------------------------------------- /tests/auto/utils/color/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Joshua Goins 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | add_executable( 12 | tst_color 13 | tst_color.cpp 14 | ) 15 | target_link_libraries( 16 | tst_color 17 | PRIVATE KDUtils doctest::doctest 18 | ) 19 | doctest_discover_tests( 20 | tst_color 21 | ADD_LABELS 22 | 1 23 | PROPERTIES 24 | LABELS 25 | "KDUtils" 26 | ) 27 | -------------------------------------------------------------------------------- /tests/auto/utils/color/tst_color.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Joshua Goins 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 16 | #include 17 | 18 | TEST_SUITE("ColorUtils") 19 | { 20 | TEST_CASE("Hexadecimal RGB Conversion") 21 | { 22 | constexpr auto rgb = KDUtils::hexToRgb>("#e2e8f0"); 23 | REQUIRE(rgb[0] == doctest::Approx(226.0f / 255.0f)); 24 | REQUIRE(rgb[1] == doctest::Approx(232.0f / 255.0f)); 25 | REQUIRE(rgb[2] == doctest::Approx(240.0f / 255.0f)); 26 | } 27 | TEST_CASE("Hexadecimal RGBA Conversion") 28 | { 29 | constexpr auto rgba = KDUtils::hexToRgba>("#e2e8f0", 0.75f); 30 | REQUIRE(rgba[0] == doctest::Approx(226.0f / 255.0f)); 31 | REQUIRE(rgba[1] == doctest::Approx(232.0f / 255.0f)); 32 | REQUIRE(rgba[2] == doctest::Approx(240.0f / 255.0f)); 33 | REQUIRE(rgba[3] == doctest::Approx(0.75f)); 34 | } 35 | TEST_CASE("Too long hexadecimal string") 36 | { 37 | CHECK_THROWS_WITH_AS((KDUtils::hexToRgb>("#e2e8f018711")), "Length of hexadecimal string must be 7 characters", std::runtime_error); 38 | } 39 | TEST_CASE("Hexadecimal missing a #") 40 | { 41 | CHECK_THROWS_WITH_AS((KDUtils::hexToRgb>("e2e8f0")), "Missing hashtag at start of hexadecimal string", std::runtime_error); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/auto/utils/dir/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | add_executable( 12 | tst_dir 13 | tst_dir.cpp 14 | ) 15 | target_link_libraries( 16 | tst_dir 17 | PRIVATE KDUtils doctest::doctest 18 | ) 19 | get_filename_component(ASSETS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../assets/ ABSOLUTE) 20 | target_compile_definitions( 21 | tst_dir PRIVATE TST_DIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" EXECUTABLE_DIR="$" 22 | ) 23 | doctest_discover_tests( 24 | tst_dir 25 | ADD_LABELS 26 | 1 27 | PROPERTIES 28 | LABELS 29 | "KDUtils" 30 | ) 31 | -------------------------------------------------------------------------------- /tests/auto/utils/elapsedtimer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | add_executable( 12 | tst_elapsedtimer 13 | tst_elapsedtimer.cpp 14 | ) 15 | target_link_libraries( 16 | tst_elapsedtimer 17 | PRIVATE KDUtils doctest::doctest 18 | ) 19 | get_filename_component(ASSETS_ELAPSEDTIMER ../assets/ ABSOLUTE) 20 | target_compile_definitions(tst_elapsedtimer PRIVATE ASSETS="${ASSETS_ELAPSEDTIMER}/") 21 | doctest_discover_tests( 22 | tst_elapsedtimer 23 | ADD_LABELS 24 | 1 25 | PROPERTIES 26 | LABELS 27 | "KDUtils" 28 | ) 29 | -------------------------------------------------------------------------------- /tests/auto/utils/file/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | add_executable( 12 | tst_file 13 | tst_file.cpp 14 | ) 15 | target_link_libraries( 16 | tst_file 17 | PRIVATE KDUtils doctest::doctest 18 | ) 19 | get_filename_component(ASSETS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../assets/ ABSOLUTE) 20 | target_compile_definitions(tst_file PRIVATE ASSETS="${ASSETS_DIR}/" TST_DIR="${CMAKE_CURRENT_SOURCE_DIR}/") 21 | doctest_discover_tests( 22 | tst_file 23 | ADD_LABELS 24 | 1 25 | PROPERTIES 26 | LABELS 27 | "KDUtils" 28 | ) 29 | -------------------------------------------------------------------------------- /tests/auto/utils/flags/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | add_executable( 12 | tst_flags 13 | tst_flags.cpp 14 | ) 15 | target_link_libraries( 16 | tst_flags 17 | PRIVATE KDUtils doctest::doctest 18 | ) 19 | doctest_discover_tests( 20 | tst_flags 21 | ADD_LABELS 22 | 1 23 | PROPERTIES 24 | LABELS 25 | "KDUtils" 26 | ) 27 | -------------------------------------------------------------------------------- /tests/auto/utils/signal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Shivam Kunwar 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | add_executable( 12 | tst_signal 13 | tst_signal.cpp 14 | ) 15 | target_link_libraries( 16 | tst_signal 17 | PRIVATE KDUtils KDUtils::KDFoundation doctest::doctest 18 | ) 19 | doctest_discover_tests( 20 | tst_signal 21 | ADD_LABELS 22 | 1 23 | PROPERTIES 24 | LABELS 25 | "KDUtils" 26 | ) 27 | -------------------------------------------------------------------------------- /tests/auto/utils/tailwind_colors/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Joshua Goins 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | add_executable( 12 | tst_tailwind_colors 13 | tst_tailwind_colors.cpp 14 | ) 15 | target_link_libraries( 16 | tst_tailwind_colors 17 | PRIVATE KDUtils doctest::doctest 18 | ) 19 | doctest_discover_tests( 20 | tst_tailwind_colors 21 | ADD_LABELS 22 | 1 23 | PROPERTIES 24 | LABELS 25 | "KDUtils" 26 | ) 27 | -------------------------------------------------------------------------------- /tests/auto/utils/tailwind_colors/tst_tailwind_colors.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of KDUtils. 3 | 4 | SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 5 | Author: Joshua Goins 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | Contact KDAB at for commercial licensing options. 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 16 | #include 17 | 18 | TEST_SUITE("Tailwind Color Utils") 19 | { 20 | TEST_CASE("RGB color") 21 | { 22 | constexpr auto rgb = KDUtils::tailwindColorToRgb>(KDUtils::TailwindColor::Amber100); 23 | REQUIRE(rgb[0] == doctest::Approx(0.996078f)); 24 | REQUIRE(rgb[1] == doctest::Approx(0.952941f)); 25 | REQUIRE(rgb[2] == doctest::Approx(0.780392)); 26 | } 27 | TEST_CASE("RGBA color") 28 | { 29 | constexpr auto rgb = KDUtils::tailwindColorToRgba>(KDUtils::TailwindColor::Blue100, 0.75f); 30 | REQUIRE(rgb[0] == doctest::Approx(0.858824f)); 31 | REQUIRE(rgb[1] == doctest::Approx(0.917657f)); 32 | REQUIRE(rgb[2] == doctest::Approx(0.996078f)); 33 | REQUIRE(rgb[3] == doctest::Approx(0.75f)); 34 | } 35 | TEST_CASE("Invalid color") 36 | { 37 | CHECK_THROWS_WITH_AS((KDUtils::tailwindColorToRgb>((KDUtils::TailwindColor)600)), "Invalid Tailwind color", std::runtime_error); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/auto/utils/url/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of KDUtils. 2 | # 3 | # SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company 4 | # Author: Paul Lemire 5 | # 6 | # SPDX-License-Identifier: MIT 7 | # 8 | # Contact KDAB at for commercial licensing options. 9 | # 10 | 11 | add_executable( 12 | tst_url 13 | tst_url.cpp 14 | ) 15 | target_link_libraries( 16 | tst_url 17 | PRIVATE KDUtils doctest::doctest 18 | ) 19 | get_filename_component(ASSETS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../assets/ ABSOLUTE) 20 | target_compile_definitions(tst_url PRIVATE ASSETS="${ASSETS_DIR}/") 21 | doctest_discover_tests( 22 | tst_url 23 | ADD_LABELS 24 | 1 25 | PROPERTIES 26 | LABELS 27 | "KDUtils" 28 | ) 29 | --------------------------------------------------------------------------------