18 #include <SDL2/SDL_syswm.h>
36 Shell_NotifyIcon(NIM_DELETE,
nid);
50 if (event.syswm.msg->msg.win.lParam == NIN_BALLOONUSERCLICK) {
53 }
else if (event.syswm.msg->msg.win.lParam == NIN_BALLOONTIMEOUT) {
68 else if (event.syswm.msg->msg.win.lParam == 0x0200 && !
message_reset) {
76 const HMODULE wesnoth_exe = GetModuleHandle(
nullptr);
77 if (wesnoth_exe ==
nullptr) {
81 const HRSRC group_icon_info = FindResource(wesnoth_exe, TEXT(
"WESNOTH_ICON"), RT_GROUP_ICON);
82 if (group_icon_info ==
nullptr) {
86 HGLOBAL hGlobal = LoadResource(wesnoth_exe, group_icon_info);
87 if (hGlobal ==
nullptr) {
91 const PBYTE group_icon_res =
static_cast<PBYTE
>(LockResource(hGlobal));
92 if (group_icon_res ==
nullptr) {
96 const int nID = LookupIconIdFromDirectoryEx(group_icon_res, TRUE, 32, 32, LR_DEFAULTCOLOR);
101 const HRSRC icon_info = FindResource(wesnoth_exe, MAKEINTRESOURCE(nID), MAKEINTRESOURCE(3));
102 if (icon_info ==
nullptr) {
106 hGlobal = LoadResource(wesnoth_exe, icon_info);
107 if (hGlobal ==
nullptr) {
111 const PBYTE icon_res =
static_cast<PBYTE
>(LockResource(hGlobal));
112 if (icon_res ==
nullptr) {
116 const HICON icon = CreateIconFromResource(icon_res, SizeofResource(wesnoth_exe, icon_info), TRUE, 0x00030000);
117 if (icon ==
nullptr) {
122 if (window ==
nullptr) {
129 nid =
new NOTIFYICONDATA;
130 memset(
nid, 0,
sizeof(*
nid));
131 nid->cbSize = NOTIFYICONDATA_V2_SIZE;
133 nid->uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
134 nid->dwInfoFlags = NIIF_USER;
135 nid->uVersion = NOTIFYICON_VERSION;
139 nid->hBalloonIcon = icon;
140 lstrcpyW(
nid->szTip, wtip.c_str());
143 return Shell_NotifyIcon(NIM_ADD,
nid) != FALSE;
151 nid->uFlags |= NIF_INFO;
156 return Shell_NotifyIcon(NIM_MODIFY,
nid) != FALSE;
161 static const int ELIPSIS_LENGTH = 3;
174 SDL_SysWMinfo wmInfo;
175 SDL_VERSION(&wmInfo.version);
178 if (!window || SDL_GetWindowWMInfo (window, &wmInfo) != SDL_TRUE) {
182 return wmInfo.info.win.window;
188 if (window ==
nullptr) {
192 if (IsIconic(window)) {
193 ShowWindow(window, SW_RESTORE);
195 SetForegroundWindow(window);
200 std::u16string u16_string = unicode_cast<std::u16string>(
string);
201 if(u16_string.size() > maxlength) {
202 if((u16_string[maxlength-1] & 0xDC00) == 0xD800)
203 u16_string.resize(maxlength - 1);
205 u16_string.resize(maxlength);
207 return std::wstring(u16_string.begin(), u16_string.end());
214 const bool tray_icon_exist =
nid !=
nullptr;
215 if (!tray_icon_exist) {
217 if (!tray_icon_created) {
218 const bool memory_allocated =
nid !=
nullptr;
219 if (memory_allocated) {
static bool set_tray_message(const std::string &title, const std::string &message)
static bool create_tray_icon()
static bool show(std::string title, std::string message)
Displays a tray notification.
static const unsigned int WM_TRAYNOTIFY
static void destroy_tray_icon()
static std::wstring string_to_wstring(const std::string &string, std::size_t maxlength)
static const std::size_t MAX_MESSAGE_LENGTH
static void handle_system_event(const SDL_Event &event)
Frees resources when a notification disappears, switches user to the wesnoth window if the notificati...
static NOTIFYICONDATA * nid
static void switch_to_wesnoth_window()
static void adjust_length(std::string &title, std::string &message)
static bool message_reset
static const std::size_t MAX_TITLE_LENGTH
static HWND get_window_handle()
static std::string _(const char *str)
void ellipsis_truncate(std::string &str, const std::size_t size)
Truncates a string to a given utf-8 character count and then appends an ellipsis.
SDL_Window * get_window()
Contains a wrapper class for the SDL_Window class.