diff --git a/backend/windows/taskbar_buttons.c b/backend/windows/taskbar_buttons.c index 9cc4c2b..0bb28dd 100644 --- a/backend/windows/taskbar_buttons.c +++ b/backend/windows/taskbar_buttons.c @@ -23,6 +23,22 @@ static HICON g_nextIcon; static HICON g_playIcon; static HICON g_pauseIcon; +static wchar_t g_tooltipPlay[64] = {0}; +static wchar_t g_tooltipPause[64] = {0}; +static wchar_t g_tooltipPrev[64] = {0}; +static wchar_t g_tooltipNext[64] = {0}; + +static void utf8_to_utf16(const char* utf8, wchar_t* utf16buf, size_t maxChars) { + MultiByteToWideChar(CP_UTF8, 0, utf8, -1, utf16buf, (int)maxChars); +} + +void set_tooltips_utf8(const char* prev, const char* next, const char* play, const char* pause) { + utf8_to_utf16(play, g_tooltipPlay, _countof(g_tooltipPlay)); + utf8_to_utf16(pause, g_tooltipPause, _countof(g_tooltipPause)); + utf8_to_utf16(prev, g_tooltipPrev, _countof(g_tooltipPrev)); + utf8_to_utf16(next, g_tooltipNext, _countof(g_tooltipNext)); +} + static HICON create_icon_from_bgra(const void *bgra, int width, int height) { HICON hIcon = NULL; @@ -86,7 +102,7 @@ LRESULT CALLBACK OverrideWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar if (g_taskbar && g_mainHWnd && g_playIcon && g_pauseIcon) { int playing = LOWORD(wParam) ? 1 : 0; g_thumbButtons[1].hIcon = playing ? g_pauseIcon : g_playIcon; - wcscpy_s(g_thumbButtons[1].szTip, ARRAYSIZE(g_thumbButtons[0].szTip), playing ? L"Pause" : L"Play"); + wcscpy_s(g_thumbButtons[1].szTip, ARRAYSIZE(g_thumbButtons[1].szTip), playing ? g_tooltipPause : g_tooltipPlay); g_taskbar->lpVtbl->ThumbBarUpdateButtons( g_taskbar, g_mainHWnd, @@ -129,7 +145,7 @@ int initialize_taskbar_buttons(void *hwndPtr, ThumbnailCallback cb) { g_thumbButtons[0].dwMask = THB_FLAGS | THB_TOOLTIP; g_thumbButtons[0].iId = 1; g_thumbButtons[0].dwFlags = THBF_ENABLED; - wcscpy_s(g_thumbButtons[0].szTip, ARRAYSIZE(g_thumbButtons[0].szTip), L"Previous"); + wcscpy_s(g_thumbButtons[0].szTip, ARRAYSIZE(g_thumbButtons[0].szTip), g_tooltipPrev); if (g_prevIcon) { g_thumbButtons[0].dwMask |= THB_ICON; g_thumbButtons[0].hIcon = g_prevIcon; @@ -138,7 +154,7 @@ int initialize_taskbar_buttons(void *hwndPtr, ThumbnailCallback cb) { g_thumbButtons[1].dwMask = THB_FLAGS | THB_TOOLTIP; g_thumbButtons[1].iId = 2; g_thumbButtons[1].dwFlags = THBF_ENABLED; - wcscpy_s(g_thumbButtons[1].szTip, ARRAYSIZE(g_thumbButtons[1].szTip), L"Play"); + wcscpy_s(g_thumbButtons[1].szTip, ARRAYSIZE(g_thumbButtons[1].szTip), g_tooltipPlay); if (g_playIcon) { g_thumbButtons[1].dwMask |= THB_ICON; g_thumbButtons[1].hIcon = g_playIcon; @@ -147,7 +163,7 @@ int initialize_taskbar_buttons(void *hwndPtr, ThumbnailCallback cb) { g_thumbButtons[2].dwMask = THB_FLAGS | THB_TOOLTIP; g_thumbButtons[2].iId = 3; g_thumbButtons[2].dwFlags = THBF_ENABLED; - wcscpy_s(g_thumbButtons[2].szTip, ARRAYSIZE(g_thumbButtons[2].szTip), L"Next"); + wcscpy_s(g_thumbButtons[2].szTip, ARRAYSIZE(g_thumbButtons[2].szTip), g_tooltipNext); if (g_nextIcon) { g_thumbButtons[2].dwMask |= THB_ICON; g_thumbButtons[2].hIcon = g_nextIcon; diff --git a/backend/windows/taskbar_buttons.go b/backend/windows/taskbar_buttons.go index f6c779b..782008e 100644 --- a/backend/windows/taskbar_buttons.go +++ b/backend/windows/taskbar_buttons.go @@ -4,6 +4,7 @@ package windows /* #cgo LDFLAGS: -lole32 +#include #include "taskbar_buttons.h" extern void goButtonClicked(int); @@ -31,6 +32,22 @@ func InitializeTaskbarIcons(prev, next, play, pause image.Image) error { return nil } +// SetTaskbarButtonToolTips should be called before InitializeTaskbarButtons to +// set the tool tips that will be used for the buttons +func SetTaskbarButtonToolTips(prev, next, play, pause string) error { + cPlay := C.CString(play) + defer C.free(unsafe.Pointer(cPlay)) + cPause := C.CString(pause) + defer C.free(unsafe.Pointer(cPause)) + cPrev := C.CString(prev) + defer C.free(unsafe.Pointer(cPrev)) + cNext := C.CString(next) + defer C.free(unsafe.Pointer(cNext)) + C.set_tooltips_utf8(cPrev, cNext, cPlay, cPause) + + return nil +} + func InitializeTaskbarButtons(hwnd uintptr, callback func(TaskbarButton)) error { gTaskbarButtonCallback = callback C.initialize_taskbar_buttons(unsafe.Pointer(hwnd), C.ThumbnailCallback(C.goButtonClicked)) diff --git a/backend/windows/taskbar_buttons.h b/backend/windows/taskbar_buttons.h index cac3202..f487117 100644 --- a/backend/windows/taskbar_buttons.h +++ b/backend/windows/taskbar_buttons.h @@ -6,6 +6,10 @@ extern "C" { typedef void (*ThumbnailCallback)(int buttonId); +// sets the tool tip strings for prev, next, play, and pause +// should be called before initialize_taskbar_buttons or they will not have tool tips +void set_tooltips_utf8(const char* prev, const char* next, const char* play, const char* pause); + // sets the icons that will be used for the buttons. // the arguments are pointers to BGRA pixel data, and the dimensions (w, h) of all 4 images. int initialize_taskbar_icons(const void *bgraPrev, const void *bgraNext, const void *bgraPlay, const void *bgraPause, int width, int height); diff --git a/backend/windows/taskbar_buttons_unsupported.go b/backend/windows/taskbar_buttons_unsupported.go index 9b1cf96..a83122a 100644 --- a/backend/windows/taskbar_buttons_unsupported.go +++ b/backend/windows/taskbar_buttons_unsupported.go @@ -13,6 +13,10 @@ func InitializeTaskbarButtons(hwnd uintptr, callback func(TaskbarButton)) error return err } +func SetTaskbarButtonToolTips(prev, next, play, pause string) error { + return err +} + func InitializeTaskbarIcons(prev, next, play, pause image.Image) error { return err } diff --git a/main.go b/main.go index c288ba2..2922325 100644 --- a/main.go +++ b/main.go @@ -83,6 +83,14 @@ func main() { if err := initWindowsTaskbarIcons(); err != nil { log.Printf("Error initializing taskbar thumbnail icons: %s", err.Error()) } + if err := windows.SetTaskbarButtonToolTips( + lang.L("Previous"), + lang.L("Next"), + lang.L("Play"), + lang.L("Pause"), + ); err != nil { + log.Printf("error initializing taskbar button tool tips: %s", err.Error()) + } } fyneApp := app.New()