[fix] fix system tray icon display issue

This commit is contained in:
dijunkun
2026-04-14 01:54:03 +08:00
parent 3e95a7ba29
commit 21425c7132
2 changed files with 22 additions and 7 deletions

View File

@@ -1,2 +1,2 @@
// Application icon (IDI_ICON1 = 1, which is the default app icon resource ID) // Application icon resource; load by the resource name IDI_ICON1.
IDI_ICON1 ICON "..\\..\\icons\\windows\\crossdesk.ico" IDI_ICON1 ICON "..\\..\\icons\\windows\\crossdesk.ico"

View File

@@ -7,8 +7,8 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#endif #endif
#include <cstdlib>
#include <cmath> #include <cmath>
#include <cstdlib>
#include <cstring> #include <cstring>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
@@ -28,6 +28,7 @@
#include "screen_capturer_factory.h" #include "screen_capturer_factory.h"
#include "version_checker.h" #include "version_checker.h"
#if defined(__APPLE__) #if defined(__APPLE__)
#include "window_util_mac.h" #include "window_util_mac.h"
#endif #endif
@@ -63,6 +64,19 @@ bool CanReadFontFile(const char* font_path) {
return font_file.good(); return font_file.good();
} }
#if _WIN32
HICON LoadTrayIcon() {
HMODULE module = GetModuleHandleW(nullptr);
HICON icon = reinterpret_cast<HICON>(
LoadImageW(module, L"IDI_ICON1", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE));
if (icon) {
return icon;
}
return LoadIconW(nullptr, IDI_APPLICATION);
}
#endif
#if defined(__linux__) && !defined(__APPLE__) #if defined(__linux__) && !defined(__APPLE__)
inline bool X11GetDisplayAndWindow(SDL_Window* window, Display** display_out, inline bool X11GetDisplayAndWindow(SDL_Window* window, Display** display_out,
::Window* x11_window_out) { ::Window* x11_window_out) {
@@ -975,8 +989,9 @@ void Render::UpdateInteractions() {
screen_capturer_is_started_ && !start_mouse_controller_ && screen_capturer_is_started_ && !start_mouse_controller_ &&
mouse_controller_is_started_; mouse_controller_is_started_;
if (stop_wayland_mouse_before_screen) { if (stop_wayland_mouse_before_screen) {
LOG_INFO("Stopping Wayland mouse controller before screen capturer to " LOG_INFO(
"cleanly release the shared portal session"); "Stopping Wayland mouse controller before screen capturer to "
"cleanly release the shared portal session");
StopMouseController(); StopMouseController();
mouse_controller_is_started_ = false; mouse_controller_is_started_ = false;
} }
@@ -1087,8 +1102,7 @@ int Render::CreateMainWindow() {
HWND main_hwnd = (HWND)SDL_GetPointerProperty( HWND main_hwnd = (HWND)SDL_GetPointerProperty(
props, SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL); props, SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
HICON tray_icon = (HICON)LoadImageW(NULL, L"crossdesk.ico", IMAGE_ICON, 0, 0, HICON tray_icon = LoadTrayIcon();
LR_LOADFROMFILE | LR_DEFAULTSIZE);
tray_ = std::make_unique<WinTray>(main_hwnd, tray_icon, L"CrossDesk", tray_ = std::make_unique<WinTray>(main_hwnd, tray_icon, L"CrossDesk",
localization_language_index_); localization_language_index_);
#endif #endif
@@ -2311,7 +2325,8 @@ void Render::UpdateRenderRect() {
rect_f.h = render_area_width * video_ratio_reverse; rect_f.h = render_area_width * video_ratio_reverse;
} else if (render_area_width > render_area_height * video_ratio) { } else if (render_area_width > render_area_height * video_ratio) {
rect_f.x = rect_f.x =
std::abs(render_area_width - render_area_height * video_ratio) / 2.0f + std::abs(render_area_width - render_area_height * video_ratio) /
2.0f +
props->render_window_x_; props->render_window_x_;
rect_f.y = props->render_window_y_; rect_f.y = props->render_window_y_;
rect_f.w = render_area_height * video_ratio; rect_f.w = render_area_height * video_ratio;