diff --git a/external/sdl/CMakeLists.txt b/external/sdl/CMakeLists.txt index c5658e48..4a7b1e5b 100644 --- a/external/sdl/CMakeLists.txt +++ b/external/sdl/CMakeLists.txt @@ -9,7 +9,8 @@ if (NOT TARGET SDL3::SDL3) set(SDL_DISABLE_ANDROID_JAR OFF CACHE INTERNAL "") FetchContent_Declare(SDL3 - GIT_REPOSITORY https://github.com/libsdl-org/SDL + #GIT_REPOSITORY https://github.com/libsdl-org/SDL + GIT_REPOSITORY https://github.com/Semphriss/SDL #GIT_TAG 0429f5d6a36fc35b551bcc2acd4a40c2db6dab82 # tip when looking #GIT_TAG 14f584a94bfd49cf1524db75bf3c419fdf9436cd # tip 26-04-2024 #GIT_TAG 06d6f2cb2518622593570985589700910cf4399f # 13-05-2024 - before @@ -25,7 +26,8 @@ if (NOT TARGET SDL3::SDL3) #GIT_TAG 6e885d96193a4b0096fe7fed6d4e6c3e5f247283 # tip 09-09-2024 #GIT_TAG 9dd8859240703d886941733ad32c1dc6f50d64f0 # tip 19-09-2024 #GIT_TAG afdf325fb4090e93a124519d1a3bc1fbe0ba9025 # bad - GIT_TAG e292d1f5ace469f718d7b6b4dec8c28e37dcaa0e # tip 05-10-2024 (3.1.3) + #GIT_TAG e292d1f5ace469f718d7b6b4dec8c28e37dcaa0e # tip 05-10-2024 (3.1.3) + GIT_TAG c523f0bcfeb5700ee233b7fae3c2b036822b8627 FIND_PACKAGE_ARGS # for the future ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6636b62b..50a9f118 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -66,6 +66,9 @@ target_sources(tomato PUBLIC ./sdl_clipboard_utils.hpp ./sdl_clipboard_utils.cpp + ./sys_tray.hpp + ./sys_tray.cpp + ./chat_gui/theme.hpp ./chat_gui/theme.cpp ./chat_gui/icons/direct.hpp diff --git a/src/main_screen.hpp b/src/main_screen.hpp index 7519d61d..e87bd0d9 100644 --- a/src/main_screen.hpp +++ b/src/main_screen.hpp @@ -29,6 +29,8 @@ #include "./tox_avatar_loader.hpp" #include "./message_image_loader.hpp" +#include "./sys_tray.hpp" + #include "./chat_gui4.hpp" #include "./chat_gui/settings_window.hpp" #include "./object_store_ui.hpp" @@ -91,6 +93,8 @@ struct MainScreen final : public Screen { MessageImageLoader mil; TextureCache msg_tc; + SystemTray st; + ChatGui4 cg; SettingsWindow sw; ObjectStoreUI osui; diff --git a/src/sys_tray.cpp b/src/sys_tray.cpp new file mode 100644 index 00000000..2d4a9bd3 --- /dev/null +++ b/src/sys_tray.cpp @@ -0,0 +1,52 @@ +#include "./sys_tray.hpp" + +#include "./image_loader_sdl_image.hpp" + +#include +#include +#include +#include +#include + +SystemTray::SystemTray(void) { + std::cout << "adding sys tray\n"; + + std::ifstream file("../res/icon/tomato_v1_256.png"); + file.seekg(0, std::ios::end); + size_t file_size = file.tellg(); + file.seekg(0, std::ios::beg); + std::vector data(file_size); + file.read(reinterpret_cast(data.data()), file_size); + file.close(); + + std::cout << "tray icon file size: " << file_size << "\n"; + + ImageLoaderSDLImage il; + auto image = il.loadFromMemoryRGBA(data.data(), data.size()); + std::unique_ptr surf = { + SDL_CreateSurfaceFrom( + image.width, image.height, + SDL_PIXELFORMAT_RGBA32, + (void*)image.frames.at(0).data.data(), + 4*image.width + ), + &SDL_DestroySurface + }; + + std::cout << "tray dims " << image.width << "x" << image.height << "\n"; + + + // different icons? + _tray = SDL_CreateTray(surf.get(), "tomato"); + if (_tray == nullptr) { + std::cerr << "failed to create SystemTray!!\n"; + } +} + +SystemTray::~SystemTray(void) { + if (_tray != nullptr) { + SDL_DestroyTray(_tray); + _tray = nullptr; + } +} + diff --git a/src/sys_tray.hpp b/src/sys_tray.hpp new file mode 100644 index 00000000..73f05eef --- /dev/null +++ b/src/sys_tray.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include + +class SystemTray { + SDL_Tray* _tray {nullptr}; + + public: + SystemTray(void); + ~SystemTray(void); +}; +