Compare commits

...

1 Commits

Author SHA1 Message Date
a6df1ecf8e
wip sys tray 2024-10-14 10:16:35 +02:00
5 changed files with 75 additions and 2 deletions

View File

@ -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
)

View File

@ -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

View File

@ -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<void*, Message3Handle, MessageImageLoader> msg_tc;
SystemTray st;
ChatGui4 cg;
SettingsWindow sw;
ObjectStoreUI osui;

52
src/sys_tray.cpp Normal file
View File

@ -0,0 +1,52 @@
#include "./sys_tray.hpp"
#include "./image_loader_sdl_image.hpp"
#include <cstdint>
#include <fstream>
#include <ios>
#include <memory>
#include <iostream>
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<uint8_t> data(file_size);
file.read(reinterpret_cast<char*>(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<SDL_Surface, decltype(&SDL_DestroySurface)> 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;
}
}

12
src/sys_tray.hpp Normal file
View File

@ -0,0 +1,12 @@
#pragma once
#include <SDL3/SDL.h>
class SystemTray {
SDL_Tray* _tray {nullptr};
public:
SystemTray(void);
~SystemTray(void);
};