From 40a176ef83a69e03fb1699f8545e6196f17f6f19 Mon Sep 17 00:00:00 2001 From: pit-ray Date: Mon, 12 Feb 2024 22:29:24 +0900 Subject: [PATCH] Support MinGW --- .github/workflows/coveralls.yml | 57 +++++++++++++++++++++++++++++ .github/workflows/mingw.yml | 61 +++++++++++++++++++++++++++++++ .gitignore | 1 + demo/CMakeLists.txt | 63 +++++++++++++++++++++++++++------ demo/demo.cpp | 3 +- docs/index.html | 2 +- include/fluent_tray.hpp | 26 +++++++++----- 7 files changed, 191 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/coveralls.yml create mode 100644 .github/workflows/mingw.yml diff --git a/.github/workflows/coveralls.yml b/.github/workflows/coveralls.yml new file mode 100644 index 0000000..4530736 --- /dev/null +++ b/.github/workflows/coveralls.yml @@ -0,0 +1,57 @@ +name: Coveralls + +on: + push: + branches: [ main ] + tags: + - v*.*.* + - test* + paths: + - '!README.md' + - '!CONTRIBUTING.md' + - '!docs/**' + - 'include/**' + - 'demo/**' + - '.github/**' + - 'tests/**' + + pull_request: + branches: [ main ] + paths: + - '!README.md' + - '!CONTRIBUTING.md' + - '!docs/**' + - 'include/**' + - 'demo/**' + - '.github/**' + - 'tests/**' + +env: + BUILD_TYPE: Debug + +jobs: + Windows: + runs-on: windows-2022 + + defaults: + run: + shell: powershell + + steps: + - uses: actions/checkout@v2 + + - uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + + - name: Coveralls GitHub Action + uses: coverallsapp/github-action@v2.2.3 + + - name: Configure CMake + run: cmake -B build_test tests + + - name: Build + run: cmake --build build_test --config ${{env.BUILD_TYPE}} + + - name: Test + run: ctest -C ${{env.BUILD_TYPE}} --test-dir build_test --output-on-failure diff --git a/.github/workflows/mingw.yml b/.github/workflows/mingw.yml new file mode 100644 index 0000000..7442999 --- /dev/null +++ b/.github/workflows/mingw.yml @@ -0,0 +1,61 @@ +name: MinGW + +on: + push: + branches: + - main + tags: + - v*.*.* + paths: + - '!README.md' + - '!CONTRIBUTING.md' + - '!docs/**' + - 'include/**' + - 'demo/**' + - '.github/**' + - 'tests/**' + + pull_request: + branches: + - main + paths: + - '!README.md' + - '!CONTRIBUTING.md' + - '!docs/**' + - 'include/**' + - 'demo/**' + - '.github/**' + - 'tests/**' + + +jobs: + x64: + runs-on: windows-2022 + + defaults: + run: + shell: bash + + steps: + - uses: actions/checkout@v2 + + - name: Setup Dependencies + shell: powershell + run: | + choco install -y 7zip.install + curl.exe -OL https://github.com/niXman/mingw-builds-binaries/releases/download/13.2.0-rt_v11-rev0/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0.7z + 7z x x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0.7z + + - name: Configure CMake + run: | + cmake -B build_mingw -DCMAKE_BUILD_TYPE=Debug -G "MinGW Makefiles" -DCCACHE_ENABLE=OFF demo + env: + CC: ${{github.workspace}}/mingw64/bin/gcc.exe + CXX: ${{github.workspace}}/mingw64/bin/g++.exe + + - name: Build + run: | + cmake --build build_mingw --config Debug + env: + CC: ${{github.workspace}}/mingw64/bin/gcc.exe + CXX: ${{github.workspace}}/mingw64/bin/g++.exe diff --git a/.gitignore b/.gitignore index 5bccf3d..825e592 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build build_test +build_mingw .vscode .vimspector.json diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt index 256bc6a..2d6a140 100644 --- a/demo/CMakeLists.txt +++ b/demo/CMakeLists.txt @@ -1,15 +1,58 @@ cmake_minimum_required(VERSION 3.6.0) project(fluent-tray-demo VERSION 1.0) -add_compile_options( - /W4 - /std:c11 - # /MT - /D_UNICODE - /DUNICODE - /utf-8 - /DEBUG - /DDEBUG -) +if(${MSVC}) + add_compile_options( + /W4 + /std:c11 + # /MT + /D_UNICODE + /DUNICODE + /utf-8 + /DEBUG + /DDEBUG + ) +else() + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_EXTENSIONS OFF) + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + + set(CMAKE_CXX_FLAGS + -static + -std=c++17 + -lstdc++ + -lstdc++fs + -lgcc + -Wall + -Wextra + -Wcast-align + -Wno-unknown-pragmas + -Wcast-qual + -Wctor-dtor-privacy + -Wdelete-non-virtual-dtor + -Wdouble-promotion + -Weffc++ + -Wold-style-cast + -Woverloaded-virtual + -Wreorder + -Wshadow + -Wsuggest-override + -Wuseless-cast + -fdiagnostics-color + -DUNICODE + -D_UNICODE + -DWINVER=0x0A00 + -D_WIN32_WINNT=0x0A00 + --coverage + ) + list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS) + string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g3 -DDEBUG") + set(CMAKE_SH "CMAKE_SH-NOTFOUND") +endif() + include_directories(../include) add_executable(${PROJECT_NAME} demo.cpp) diff --git a/demo/demo.cpp b/demo/demo.cpp index 9b5bf6e..e831624 100644 --- a/demo/demo.cpp +++ b/demo/demo.cpp @@ -7,10 +7,9 @@ int main() { using namespace fluent_tray ; FluentTray tray{} ; - BYTE opacity = 240 ; if(!tray.create_tray( "demo", "demo/assets/icon.ico", - 5, 5, 10, 5, opacity, true)) { + 5, 5, 10, 5, 240, true)) { return 1 ; } diff --git a/docs/index.html b/docs/index.html index fb7c422..4ed867a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -88,7 +88,7 @@

fluent-tray

Coverity Scan Build Status

-

+

Concept

fluent-tray provides a simple system tray icon and menu to easily create resident applications that do not require complex windows. Since only the native API is used, all you have to do is include a single header file.

diff --git a/include/fluent_tray.hpp b/include/fluent_tray.hpp index 6909ba7..c381517 100644 --- a/include/fluent_tray.hpp +++ b/include/fluent_tray.hpp @@ -12,7 +12,11 @@ #if defined(_MSC_VER) && _MSC_VER >= 1500 #pragma warning(disable : 4005) +#endif + #include + +#if defined(_MSC_VER) && _MSC_VER >= 1500 #pragma warning(default : 4005) #endif @@ -655,9 +659,9 @@ namespace fluent_tray std::wstring app_name_ ; + HINSTANCE hinstance_ ; HWND hwnd_ ; bool visible_ ; - HINSTANCE hinstance_ ; NOTIFYICONDATAW icon_data_ ; TrayStatus status_ ; @@ -686,7 +690,7 @@ namespace fluent_tray : menus_(), mouse_is_over_(), app_name_(), - hinstance_(reinterpret_cast(GetModuleHandle(NULL))), + hinstance_(GetModuleHandle(NULL)), hwnd_(NULL), visible_(false), icon_data_(), @@ -800,6 +804,7 @@ namespace fluent_tray // Set rounded window for Windows 11 only. if(round_corner) { +#if defined(_MSC_VER) && _MSC_VER >= 1500 using RtlGetVersionType = NTSTATUS (WINAPI*)(PRTL_OSVERSIONINFOW) ; const auto hmodule = LoadLibraryW(L"ntdll.dll") ; if(!hmodule) { @@ -835,6 +840,7 @@ namespace fluent_tray return false ; } } +#endif // defined(_MSC_VER) && _MSC_VER >= 1500 } if(!change_icon(icon_path)) { @@ -1040,9 +1046,11 @@ namespace fluent_tray return false ; } - for(LONG i = 0 ; i < menus_.size() ; i ++) { + for(std::size_t i = 0 ; i < menus_.size() ; i ++) { auto& menu = menus_[i] ; - auto y = menu_y_margin_ + i * (menu_height + menu_y_margin_) ; + auto y = \ + menu_y_margin_ + + static_cast(i) * (menu_height + menu_y_margin_) ; if(!SetWindowPos( menu.window_handle(), HWND_TOP, menu_x_margin_, y, @@ -1178,11 +1186,11 @@ namespace fluent_tray auto dst = logfont.lfFaceName ; if(font_name_wide.size() < LF_FACESIZE) { - std::memcpy(dst, font_name_wide.c_str(), sizeof(WCHAR) * font_name_wide.length()) ; + std::wmemcpy(dst, font_name_wide.c_str(), sizeof(WCHAR) * font_name_wide.length()) ; dst[font_name_wide.size()] = L'\0' ; } else { - std::memcpy(dst, font_name_wide.c_str(), sizeof(WCHAR) * (LF_FACESIZE - 1)) ; + std::wmemcpy(dst, font_name_wide.c_str(), sizeof(WCHAR) * (LF_FACESIZE - 1)) ; dst[LF_FACESIZE - 1] = L'\0' ; } } @@ -1329,15 +1337,15 @@ namespace fluent_tray UINT msg, WPARAM wparam, LPARAM lparam) { - auto get_instance = [hwnd]() { + auto get_instance = [hwnd]() -> FluentTray* { auto upper_addr = GetWindowLongW(hwnd, 0) ; if(!upper_addr) { - return reinterpret_cast(nullptr) ; + return nullptr ; } auto lower_addr = GetWindowLongW(hwnd, sizeof(LONG)) ; if(!lower_addr) { - return reinterpret_cast(nullptr) ; + return nullptr ; } FluentTray* self ;