Skip to content

Commit

Permalink
Support MinGW
Browse files Browse the repository at this point in the history
  • Loading branch information
pit-ray committed Feb 12, 2024
1 parent ef29054 commit 40a176e
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 22 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]

- 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
61 changes: 61 additions & 0 deletions .github/workflows/mingw.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build
build_test
build_mingw
.vscode
.vimspector.json
63 changes: 53 additions & 10 deletions demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 1 addition & 2 deletions demo/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
}

Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ <h1>fluent-tray</h1>
<p align="center"></p>
<p><a href="https://scan.coverity.com/projects/pit-ray-fluent-tray"><img src="https://img.shields.io/coverity/scan/pit-ray-fluent-tray?style=flat-square" alt="Coverity Scan Build Status" class="inline"/></a> <a href="https://www.codacy.com/gh/pit-ray/fluent-tray/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=pit-ray/fluent-tray&amp;utm_campaign=Badge_Grade"><img src="https://img.shields.io/codacy/grade/8f2e6f2826904efd82019f5888574327?style=flat-square" alt="" class="inline"/></a> <a href="https://github.com/pit-ray/fluent-tray/actions/workflows/codeql.yml"><img src="https://img.shields.io/github/actions/workflow/status/pit-ray/fluent-tray/codeql.yml?branch=main&amp;label=CodeQL&amp;logo=github&amp;style=flat-square" alt="" class="inline"/></a> <br />
<br />
<a href="https://github.com/pit-ray/fluent-tray/actions/workflows/coverity.yml"><img src="https://img.shields.io/github/actions/workflow/status/pit-ray/fluent-tray/coverity.yml?branch=main&amp;label=cov-build&amp;logo=github&amp;style=flat-square" alt="" class="inline"/></a> <a href="https://github.com/pit-ray/fluent-tray/actions/workflows/msvc.yml"><img src="https://img.shields.io/github/actions/workflow/status/pit-ray/fluent-tray/windows.yml?branch=main&amp;label=Windows&amp;logo=github&amp;style=flat-square" alt="" class="inline"/></a> </p>
<a href="https://github.com/pit-ray/fluent-tray/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/pit-ray/fluent-tray/test.yml?branch=main&amp;label=test&amp;logo=github&amp;style=flat-square" alt="" class="inline"/></a> <a href="https://github.com/pit-ray/fluent-tray/actions/workflows/coverity.yml"><img src="https://img.shields.io/github/actions/workflow/status/pit-ray/fluent-tray/coverity.yml?branch=main&amp;label=cov-build&amp;logo=github&amp;style=flat-square" alt="" class="inline"/></a> <a href="https://github.com/pit-ray/fluent-tray/actions/workflows/windows.yml"><img src="https://img.shields.io/github/actions/workflow/status/pit-ray/fluent-tray/windows.yml?branch=main&amp;label=Windows&amp;logo=github&amp;style=flat-square" alt="" class="inline"/></a> </p>
<h2><a class="anchor" id="autotoc_md0"></a>
Concept</h2>
<p>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.</p>
Expand Down
26 changes: 17 additions & 9 deletions include/fluent_tray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

#if defined(_MSC_VER) && _MSC_VER >= 1500
#pragma warning(disable : 4005)
#endif

#include <ntstatus.h>

#if defined(_MSC_VER) && _MSC_VER >= 1500
#pragma warning(default : 4005)
#endif

Expand Down Expand Up @@ -655,9 +659,9 @@ namespace fluent_tray

std::wstring app_name_ ;

HINSTANCE hinstance_ ;
HWND hwnd_ ;
bool visible_ ;
HINSTANCE hinstance_ ;
NOTIFYICONDATAW icon_data_ ;

TrayStatus status_ ;
Expand Down Expand Up @@ -686,7 +690,7 @@ namespace fluent_tray
: menus_(),
mouse_is_over_(),
app_name_(),
hinstance_(reinterpret_cast<HINSTANCE>(GetModuleHandle(NULL))),
hinstance_(GetModuleHandle(NULL)),
hwnd_(NULL),
visible_(false),
icon_data_(),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -835,6 +840,7 @@ namespace fluent_tray
return false ;
}
}
#endif // defined(_MSC_VER) && _MSC_VER >= 1500
}

if(!change_icon(icon_path)) {
Expand Down Expand Up @@ -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<LONG>(i) * (menu_height + menu_y_margin_) ;
if(!SetWindowPos(
menu.window_handle(), HWND_TOP,
menu_x_margin_, y,
Expand Down Expand Up @@ -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' ;
}
}
Expand Down Expand Up @@ -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<FluentTray*>(nullptr) ;
return nullptr ;
}

auto lower_addr = GetWindowLongW(hwnd, sizeof(LONG)) ;
if(!lower_addr) {
return reinterpret_cast<FluentTray*>(nullptr) ;
return nullptr ;
}

FluentTray* self ;
Expand Down

0 comments on commit 40a176e

Please sign in to comment.