Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
include:
- os: macos-latest
shell: "bash"
qt_version: ''
qt_version: '6'
- os: ubuntu-latest
shell: "bash"
qt_version: '5'
Expand All @@ -61,7 +61,7 @@ jobs:
qt_version: '6'
- os: windows-latest
shell: "msys2 {0}"
qt_version: ''
qt_version: '6'
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
Expand Down Expand Up @@ -118,6 +118,8 @@ jobs:
"imagemagick"
"ninja"
"node"
"qtbase"
"qtsvg"
)
brew install "${dependencies[@]}"

Expand Down Expand Up @@ -171,6 +173,8 @@ jobs:
mingw-w64-ucrt-x86_64-ninja
mingw-w64-ucrt-x86_64-nodejs
mingw-w64-ucrt-x86_64-toolchain
mingw-w64-ucrt-x86_64-qt6-base
mingw-w64-ucrt-x86_64-qt6-svg

- name: Setup python
id: setup-python
Expand Down Expand Up @@ -250,7 +254,6 @@ jobs:

- name: Run tests
id: test
# TODO: tests randomly hang on Linux, https://github.com/LizardByte/tray/issues/45
timeout-minutes: 3
working-directory: build/tests
env:
Expand Down
File renamed without changes.
132 changes: 56 additions & 76 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,68 +33,58 @@ option(BUILD_EXAMPLE "Build example app" ${TRAY_IS_TOP_LEVEL})
set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

find_package(PkgConfig)

file(GLOB TRAY_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.h"
)

set(TRAY_ICON_ICO "${CMAKE_CURRENT_SOURCE_DIR}/icons/icon.ico")
set(TRAY_ICON_PNG "${CMAKE_CURRENT_SOURCE_DIR}/icons/icon.png")
set(TRAY_ICON_SVG "${CMAKE_CURRENT_SOURCE_DIR}/icons/icon.svg")
set(TRAY_ICON_FILES
"${TRAY_ICON_ICO}"
"${TRAY_ICON_PNG}"
"${TRAY_ICON_SVG}"
)

set(_TRAY_ICON_ICO "${TRAY_ICON_ICO}" CACHE INTERNAL "Default tray ICO icon path")
set(_TRAY_ICON_PNG "${TRAY_ICON_PNG}" CACHE INTERNAL "Default tray PNG icon path")
set(_TRAY_ICON_SVG "${TRAY_ICON_SVG}" CACHE INTERNAL "Default tray SVG icon path")
if(TRAY_IS_TOP_LEVEL)
set(TRAY_ICON_ICO "${CMAKE_CURRENT_SOURCE_DIR}/icons/icon.ico")
set(TRAY_ICON_PNG "${CMAKE_CURRENT_SOURCE_DIR}/icons/icon.png")
set(TRAY_ICON_SVG "${CMAKE_CURRENT_SOURCE_DIR}/icons/icon.svg")
set(TRAY_ICON2_ICO "${CMAKE_CURRENT_SOURCE_DIR}/icons/icon2.ico")
set(TRAY_ICON2_PNG "${CMAKE_CURRENT_SOURCE_DIR}/icons/icon2.png")
set(TRAY_ICON2_SVG "${CMAKE_CURRENT_SOURCE_DIR}/icons/icon2.svg")
set(TRAY_ICON_FILES
"${TRAY_ICON_ICO}"
"${TRAY_ICON_PNG}"
"${TRAY_ICON_SVG}"
"${TRAY_ICON2_ICO}"
"${TRAY_ICON2_PNG}"
"${TRAY_ICON2_SVG}"
)

set(_TRAY_ICON_ICO "${TRAY_ICON_ICO}" CACHE INTERNAL "Default tray ICO icon path")
set(_TRAY_ICON_PNG "${TRAY_ICON_PNG}" CACHE INTERNAL "Default tray PNG icon path")
set(_TRAY_ICON_SVG "${TRAY_ICON_SVG}" CACHE INTERNAL "Default tray SVG icon path")

# Copy default tray icon files into the output directory of the specified target.
function(tray_copy_default_icons target_name)
if(NOT TARGET "${target_name}")
message(FATAL_ERROR "tray_copy_default_icons expected an existing target: ${target_name}")
endif()

# Copy default tray icon files into the output directory of the specified target.
function(tray_copy_default_icons target_name)
if(NOT TARGET "${target_name}")
message(FATAL_ERROR "tray_copy_default_icons expected an existing target: ${target_name}")
endif()
foreach(icon_file IN LISTS TRAY_ICON_FILES)
add_custom_command(TARGET "${target_name}" POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${icon_file}"
"$<TARGET_FILE_DIR:${target_name}>"
COMMENT "Copying ${icon_file} to $<TARGET_FILE_DIR:${target_name}>")
endforeach()
endfunction()
endif()

foreach(icon_file IN LISTS TRAY_ICON_FILES)
add_custom_command(TARGET "${target_name}" POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${icon_file}"
"$<TARGET_FILE_DIR:${target_name}>"
COMMENT "Copying ${icon_file} to $<TARGET_FILE_DIR:${target_name}>")
endforeach()
endfunction()

if(WIN32)
list(APPEND TRAY_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/tray_windows.c")
find_package(Qt6 COMPONENTS Widgets Svg)
if(Qt6_FOUND)
set(TRAY_QT_VERSION 6)
else()
if(UNIX)
if(APPLE)
find_library(COCOA Cocoa REQUIRED)
list(APPEND TRAY_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/tray_darwin.m")
else()
find_package(LibNotify REQUIRED)
find_package(Qt6 COMPONENTS Widgets Svg)
if(Qt6_FOUND)
set(TRAY_QT_VERSION 6)
else()
find_package(Qt5 REQUIRED COMPONENTS Widgets Svg)
set(TRAY_QT_VERSION 5)
endif()
set(TRAY_QT_VERSION # cmake-lint: disable=C0103
"${TRAY_QT_VERSION}"
CACHE INTERNAL "Qt major version selected by tray"
)
set(CMAKE_AUTOMOC ON)
list(APPEND TRAY_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/src/tray_linux.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/QtTrayMenu.cpp"
)
endif()
endif()
find_package(Qt5 REQUIRED COMPONENTS Widgets Svg)
set(TRAY_QT_VERSION 5)
endif()
set(CMAKE_AUTOMOC ON)
list(APPEND TRAY_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/src/tray_qt.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/QtTrayMenu.cpp"
)

add_library(${PROJECT_NAME} STATIC ${TRAY_SOURCES})
set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99)
Expand All @@ -104,32 +94,23 @@ target_include_directories(${PROJECT_NAME}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>)

if(WIN32)
if(MSVC)
list(APPEND TRAY_COMPILE_OPTIONS "/MT$<$<CONFIG:Debug>:d>")
endif()
if(WIN32 AND MSVC)
list(APPEND TRAY_COMPILE_OPTIONS "/MT$<$<CONFIG:Debug>:d>")
endif()

if(TRAY_QT_VERSION EQUAL 6)
list(APPEND TRAY_EXTERNAL_LIBRARIES Qt6::Widgets Qt6::Svg)
else()
if(UNIX)
if(APPLE)
list(APPEND TRAY_EXTERNAL_LIBRARIES ${COCOA})
else()
if(TRAY_QT_VERSION EQUAL 6)
list(APPEND TRAY_EXTERNAL_LIBRARIES Qt6::Widgets Qt6::Svg)
else()
list(APPEND TRAY_EXTERNAL_LIBRARIES Qt5::Widgets Qt5::Svg)
endif()
list(APPEND TRAY_LIBNOTIFY=1)
list(APPEND TRAY_EXTERNAL_LIBRARIES ${LIBNOTIFY_LIBRARIES})

include_directories(SYSTEM ${LIBNOTIFY_INCLUDE_DIRS})
link_directories(${LIBNOTIFY_LIBRARY_DIRS})
endif()
endif()
list(APPEND TRAY_EXTERNAL_LIBRARIES Qt5::Widgets Qt5::Svg)
endif()

if(TRAY_COMPILE_DEFINITIONS)
target_compile_definitions(${PROJECT_NAME} PRIVATE ${TRAY_COMPILE_DEFINITIONS})
endif()

add_library(tray::tray ALIAS ${PROJECT_NAME})

if(BUILD_EXAMPLE)
if(TRAY_IS_TOP_LEVEL AND BUILD_EXAMPLE)
add_executable(tray_example "${CMAKE_CURRENT_SOURCE_DIR}/src/example.c")
target_link_libraries(tray_example tray::tray)
tray_copy_default_icons(tray_example)
Expand All @@ -142,7 +123,6 @@ if(TRAY_IS_TOP_LEVEL)
endif()

target_compile_options(${PROJECT_NAME} PRIVATE ${TRAY_COMPILE_OPTIONS})
target_link_directories(${PROJECT_NAME} PRIVATE ${TRAY_EXTERNAL_DIRECTORIES})
target_link_libraries(${PROJECT_NAME} PRIVATE ${TRAY_EXTERNAL_LIBRARIES})

#
Expand Down
55 changes: 42 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

## About

Cross-platform, super tiny C99 implementation of a system tray icon with a popup menu and notifications.
Cross-platform C++17 Qt-backed system tray icon with a popup menu and notifications.

The code is C++ friendly and will compile fine in C++98 and up. This is a fork of
This is a fork of
[dmikushin/tray](https://github.com/dmikushin/tray) and is intended to add additional features required for our own
[Sunshine](https://github.com/LizardByte/Sunshine) project.

Expand All @@ -19,6 +19,7 @@ This fork adds the following features:
- code coverage
- refactored code, e.g., moved source code into the `src` directory
- doxygen documentation and readthedocs configuration
- all platforms use QT-based implementation

## Screenshots

Expand All @@ -32,46 +33,62 @@ This fork adds the following features:

## Supported platforms

* Linux/Qt (Qt5 or Qt6 Widgets)
* Windows XP or newer (shellapi.h)
* MacOS (Cocoa/AppKit)
* Linux
* macOS
* Windows

## Prerequisites

* CMake
* [Ninja](https://ninja-build.org/), to have the same build commands on all platforms.
* C++17 compiler
* Qt5 or Qt6 Widgets and Svg modules

### Linux Dependencies
### Platform Dependencies

Install either Qt6 _or_ Qt5 as well as libnotify development packages. The Linux backend requires libnotify and Qt Widgets+Svg modules.
Install either Qt6 _or_ Qt5.

<div class="tabbed">

- <b class="tab-title">Arch</b>
```bash
# Qt6
sudo pacman -S qt6-base qt6-svg libnotify
sudo pacman -S qt6-base qt6-svg

# Qt5
sudo pacman -S qt5-base qt5-svg libnotify
sudo pacman -S qt5-base qt5-svg
```

- <b class="tab-title">Debian/Ubuntu</b>
```bash
# Qt6
sudo apt install qt6-base-dev qt6-svg-dev libnotify-dev
sudo apt install qt6-base-dev qt6-svg-dev

# Qt5
sudo apt install qtbase5-dev libqt5svg5-dev libnotify-dev
sudo apt install qtbase5-dev libqt5svg5-dev
```

- <b class="tab-title">Fedora</b>
```bash
# Qt6
sudo dnf install qt6-qtbase-devel qt6-qtsvg-devel libnotify-devel
sudo dnf install qt6-qtbase-devel qt6-qtsvg-devel

# Qt5
sudo dnf install qt5-qtbase-devel qt5-qtsvg-devel libnotify-devel
sudo dnf install qt5-qtbase-devel qt5-qtsvg-devel
```

- <b class="tab-title">macOS</b>
```bash
brew install cmake ninja qtbase qtsvg
```

- <b class="tab-title">Windows (MSYS2 UCRT64)</b>
```bash
pacman -S mingw-w64-ucrt-x86_64-cmake \
mingw-w64-ucrt-x86_64-ninja \
mingw-w64-ucrt-x86_64-toolchain \
mingw-w64-ucrt-x86_64-qt6-base \
mingw-w64-ucrt-x86_64-qt6-svg
```

</div>
Expand Down Expand Up @@ -110,6 +127,18 @@ Execute the `tests` application:
./build/tests/test_tray
```

## Icon formats

The `icon` and `notification_icon` fields can be a path to an image file or an icon theme name. Relative file paths
are resolved from the process working directory, so applications should copy or install icon files where the running
process can find them.

SVG, ICO, PNG, and Qt theme icon names are supported.

For the most predictable cross-platform behavior, use SVG or PNG files for both tray and notification icons. ICO is
supported by the Qt-backed paths tested by this project.
Qt theme icons should be passed as icon name strings, such as `mail-message-new`.

## API

Tray structure defines an icon and a menu.
Expand Down
55 changes: 0 additions & 55 deletions cmake/FindLibNotify.cmake

This file was deleted.

3 changes: 1 addition & 2 deletions docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
# project metadata
DOCSET_BUNDLE_ID = dev.lizardbyte.tray
DOCSET_PUBLISHER_ID = dev.lizardbyte.tray.documentation
PROJECT_BRIEF = "Cross-platform, super tiny C99 implementation of a system tray icon with a popup menu and notifications."
PROJECT_BRIEF = "Cross-platform C++17 Qt-backed system tray icon with a popup menu and notifications."
PROJECT_NAME = tray

# project specific settings
DOT_GRAPH_MAX_NODES = 50
IMAGE_PATH = ../docs/images
INCLUDE_PATH =
PREDEFINED += TRAY_WINAPI

# files and directories to process
USE_MDFILE_AS_MAINPAGE = ../README.md
Expand Down
Binary file modified icons/icon.ico
Binary file not shown.
Binary file modified icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon2.ico
Binary file not shown.
Binary file added icons/icon2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading