Merge(#2): Updates the application badge API and implementations

This commit is contained in:
Jan Schürkamp 2023-03-06 15:48:38 +01:00 committed by GitHub
commit 2caed8f826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 120 additions and 21 deletions

View File

@ -3395,9 +3395,11 @@ GLFWAPI void glfwSetWindowIcon(GLFWwindow* window, int count, const GLFWimage* i
*/ */
GLFWAPI void glfwSetWindowTaskbarProgress(GLFWwindow* window, int progressState, double value); GLFWAPI void glfwSetWindowTaskbarProgress(GLFWwindow* window, int progressState, double value);
//Use count = GLFW_DONT_CARE to disable overlay/badge icon //Use count = 0 to disable overlay/badge icon
GLFWAPI void glfwSetWindowTaskbarBadge(GLFWwindow* window, int count); GLFWAPI void glfwSetWindowTaskbarBadge(GLFWwindow* window, int count);
GLFWAPI void glfwSetWindowTaskbarBadgeString(GLFWwindow* window, const char* string);
/*! @brief Retrieves the position of the content area of the specified window. /*! @brief Retrieves the position of the content area of the specified window.
* *
* This function retrieves the position, in screen coordinates, of the * This function retrieves the position, in screen coordinates, of the

View File

@ -530,6 +530,7 @@ GLFWbool _glfwConnectCocoa(int platformID, _GLFWplatform* platform)
_glfwSetWindowIconCocoa, _glfwSetWindowIconCocoa,
_glfwSetWindowTaskbarProgressCocoa, _glfwSetWindowTaskbarProgressCocoa,
_glfwSetWindowTaskbarBadgeCocoa, _glfwSetWindowTaskbarBadgeCocoa,
_glfwSetWindowTaskbarBadgeStringCocoa,
_glfwGetWindowPosCocoa, _glfwGetWindowPosCocoa,
_glfwSetWindowPosCocoa, _glfwSetWindowPosCocoa,
_glfwGetWindowSizeCocoa, _glfwGetWindowSizeCocoa,

View File

@ -232,6 +232,7 @@ void _glfwSetWindowTitleCocoa(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconCocoa(_GLFWwindow* window, int count, const GLFWimage* images); void _glfwSetWindowIconCocoa(_GLFWwindow* window, int count, const GLFWimage* images);
void _glfwSetWindowTaskbarProgressCocoa(_GLFWwindow* window, int progressState, double value); void _glfwSetWindowTaskbarProgressCocoa(_GLFWwindow* window, int progressState, double value);
void _glfwSetWindowTaskbarBadgeCocoa(_GLFWwindow* window, int count); void _glfwSetWindowTaskbarBadgeCocoa(_GLFWwindow* window, int count);
void _glfwSetWindowTaskbarBadgeStringCocoa(_GLFWwindow* window, const char* string);
void _glfwGetWindowPosCocoa(_GLFWwindow* window, int* xpos, int* ypos); void _glfwGetWindowPosCocoa(_GLFWwindow* window, int* xpos, int* ypos);
void _glfwSetWindowPosCocoa(_GLFWwindow* window, int xpos, int ypos); void _glfwSetWindowPosCocoa(_GLFWwindow* window, int xpos, int ypos);
void _glfwGetWindowSizeCocoa(_GLFWwindow* window, int* width, int* height); void _glfwGetWindowSizeCocoa(_GLFWwindow* window, int* width, int* height);

View File

@ -1169,8 +1169,47 @@ void _glfwSetWindowTaskbarProgressCocoa(_GLFWwindow* window, int progressState,
void _glfwSetWindowTaskbarBadgeCocoa(_GLFWwindow* window, int count) void _glfwSetWindowTaskbarBadgeCocoa(_GLFWwindow* window, int count)
{ {
_glfwInputError(GLFW_FEATURE_UNIMPLEMENTED, if (window != NULL)
"Cocoa: Setting the taskbar progress badge is not implemented"); {
_glfwInputError(GLFW_FEATURE_UNAVAILABLE,
"Cocoa: Cannot set a badge for a window. Pass NULL to set the Dock badge.");
return;
}
if (count == 0)
{
[NSApp dockTile].badgeLabel = nil;
return;
}
NSString* string;
if (count <= 9999)
string = [@(count) stringValue];
else
string = [[@(9999) stringValue] stringByAppendingString:@"+"];
[NSApp dockTile].badgeLabel = string;
}
void _glfwSetWindowTaskbarBadgeStringCocoa(_GLFWwindow* window, const char* string)
{
if (window != NULL)
{
_glfwInputError(GLFW_FEATURE_UNAVAILABLE,
"Cocoa: Cannot set a badge for a window. Pass NULL to set for the application.");
}
if (string == NULL)
{
[NSApp dockTile].badgeLabel = nil;
return;
}
NSString* nsString = [NSString stringWithCString:string
encoding:[NSString defaultCStringEncoding]];
[NSApp dockTile].badgeLabel = nsString;
} }
void _glfwGetWindowPosCocoa(_GLFWwindow* window, int* xpos, int* ypos) void _glfwGetWindowPosCocoa(_GLFWwindow* window, int* xpos, int* ypos)

View File

@ -708,6 +708,7 @@ struct _GLFWplatform
void (*setWindowIcon)(_GLFWwindow*,int,const GLFWimage*); void (*setWindowIcon)(_GLFWwindow*,int,const GLFWimage*);
void (*setWindowTaskbarProgress)(_GLFWwindow*,const int,double); void (*setWindowTaskbarProgress)(_GLFWwindow*,const int,double);
void (*setWindowTaskbarBadge)(_GLFWwindow*,int); void (*setWindowTaskbarBadge)(_GLFWwindow*,int);
void (*setWindowTaskbarBadgeString)(_GLFWwindow*,const char* string);
void (*getWindowPos)(_GLFWwindow*,int*,int*); void (*getWindowPos)(_GLFWwindow*,int*,int*);
void (*setWindowPos)(_GLFWwindow*,int,int); void (*setWindowPos)(_GLFWwindow*,int,int);
void (*getWindowSize)(_GLFWwindow*,int*,int*); void (*getWindowSize)(_GLFWwindow*,int*,int*);

View File

@ -75,6 +75,7 @@ GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform)
_glfwSetWindowIconNull, _glfwSetWindowIconNull,
_glfwSetWindowTaskbarProgressNull, _glfwSetWindowTaskbarProgressNull,
_glfwSetWindowTaskbarBadgeNull, _glfwSetWindowTaskbarBadgeNull,
_glfwSetWindowTaskbarBadgeStringNull,
_glfwGetWindowPosNull, _glfwGetWindowPosNull,
_glfwSetWindowPosNull, _glfwSetWindowPosNull,
_glfwGetWindowSizeNull, _glfwGetWindowSizeNull,

View File

@ -91,6 +91,7 @@ void _glfwSetWindowTitleNull(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconNull(_GLFWwindow* window, int count, const GLFWimage* images); void _glfwSetWindowIconNull(_GLFWwindow* window, int count, const GLFWimage* images);
void _glfwSetWindowTaskbarProgressNull(_GLFWwindow* window, int progressState, double value); void _glfwSetWindowTaskbarProgressNull(_GLFWwindow* window, int progressState, double value);
void _glfwSetWindowTaskbarBadgeNull(_GLFWwindow* window, int count); void _glfwSetWindowTaskbarBadgeNull(_GLFWwindow* window, int count);
void _glfwSetWindowTaskbarBadgeStringNull(_GLFWwindow* window, const char* string);
void _glfwSetWindowMonitorNull(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); void _glfwSetWindowMonitorNull(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate);
void _glfwGetWindowPosNull(_GLFWwindow* window, int* xpos, int* ypos); void _glfwGetWindowPosNull(_GLFWwindow* window, int* xpos, int* ypos);
void _glfwSetWindowPosNull(_GLFWwindow* window, int xpos, int ypos); void _glfwSetWindowPosNull(_GLFWwindow* window, int xpos, int ypos);

View File

@ -195,6 +195,10 @@ void _glfwSetWindowTaskbarBadgeNull(_GLFWwindow* window, int count)
{ {
} }
void _glfwSetWindowTaskbarBadgeStringNull(_GLFWwindow* window, const char* string)
{
}
void _glfwSetWindowMonitorNull(_GLFWwindow* window, void _glfwSetWindowMonitorNull(_GLFWwindow* window,
_GLFWmonitor* monitor, _GLFWmonitor* monitor,
int xpos, int ypos, int xpos, int ypos,

View File

@ -640,6 +640,7 @@ GLFWbool _glfwConnectWin32(int platformID, _GLFWplatform* platform)
_glfwSetWindowIconWin32, _glfwSetWindowIconWin32,
_glfwSetWindowTaskbarProgressWin32, _glfwSetWindowTaskbarProgressWin32,
_glfwSetWindowTaskbarBadgeWin32, _glfwSetWindowTaskbarBadgeWin32,
_glfwSetWindowTaskbarBadgeStringWin32,
_glfwGetWindowPosWin32, _glfwGetWindowPosWin32,
_glfwSetWindowPosWin32, _glfwSetWindowPosWin32,
_glfwGetWindowSizeWin32, _glfwGetWindowSizeWin32,

View File

@ -620,6 +620,7 @@ void _glfwSetWindowTitleWin32(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconWin32(_GLFWwindow* window, int count, const GLFWimage* images); void _glfwSetWindowIconWin32(_GLFWwindow* window, int count, const GLFWimage* images);
void _glfwSetWindowTaskbarProgressWin32(_GLFWwindow* window, int progressState, double value); void _glfwSetWindowTaskbarProgressWin32(_GLFWwindow* window, int progressState, double value);
void _glfwSetWindowTaskbarBadgeWin32(_GLFWwindow* window, int count); void _glfwSetWindowTaskbarBadgeWin32(_GLFWwindow* window, int count);
void _glfwSetWindowTaskbarBadgeStringWin32(_GLFWwindow* window, const char* string);
void _glfwGetWindowPosWin32(_GLFWwindow* window, int* xpos, int* ypos); void _glfwGetWindowPosWin32(_GLFWwindow* window, int* xpos, int* ypos);
void _glfwSetWindowPosWin32(_GLFWwindow* window, int xpos, int ypos); void _glfwSetWindowPosWin32(_GLFWwindow* window, int xpos, int ypos);
void _glfwGetWindowSizeWin32(_GLFWwindow* window, int* width, int* height); void _glfwGetWindowSizeWin32(_GLFWwindow* window, int* width, int* height);

View File

@ -1605,7 +1605,7 @@ void _glfwSetWindowTaskbarProgressWin32(_GLFWwindow* window, int progressState,
if(!IsWindows7OrGreater()) if(!IsWindows7OrGreater())
{ {
_glfwInputError(GLFW_FEATURE_UNAVAILABLE, "Win32: Taskbar progress is only supported on Windows 7 or newer"); _glfwInputError(GLFW_FEATURE_UNAVAILABLE, "Win32: Taskbar progress is only supported on Windows 7 and newer");
return; return;
} }
@ -1644,7 +1644,7 @@ void _glfwSetWindowTaskbarProgressWin32(_GLFWwindow* window, int progressState,
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, "Win32: Failed to set taskbar progress state"); _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, "Win32: Failed to set taskbar progress state");
} }
HICON GenerateBadgeIcon(HWND hWnd, int count) static HICON GenerateBadgeIcon(HWND hWnd, int count)
{ {
HDC hdc = NULL, hdcMem = NULL; HDC hdc = NULL, hdcMem = NULL;
HBITMAP hBitmap = NULL, hOldBitmap = NULL; HBITMAP hBitmap = NULL, hOldBitmap = NULL;
@ -1728,16 +1728,24 @@ void _glfwSetWindowTaskbarBadgeWin32(_GLFWwindow* window, int count)
HRESULT res = S_OK; HRESULT res = S_OK;
HICON icon = NULL; HICON icon = NULL;
if (window == NULL)
{
_glfwInputError(GLFW_FEATURE_UNAVAILABLE, "Win32: Taskbar badge requires a valid window handle");
return;
}
if (!IsWindows7OrGreater()) if (!IsWindows7OrGreater())
{ {
_glfwInputError(GLFW_FEATURE_UNAVAILABLE, "Win32: Taskbar badge is only supported on Windows 7 or newer"); _glfwInputError(GLFW_FEATURE_UNAVAILABLE, "Win32: Taskbar badge is only supported on Windows 7 and newer");
return; return;
} }
if (!window->win32.taskbarList) if (!window->win32.taskbarList)
return; return;
if (count != GLFW_DONT_CARE) count = min(count, 999);
if (count > 0)
{ {
icon = GenerateBadgeIcon(window->win32.handle, count); icon = GenerateBadgeIcon(window->win32.handle, count);
if (!icon) if (!icon)
@ -1747,6 +1755,7 @@ void _glfwSetWindowTaskbarBadgeWin32(_GLFWwindow* window, int count)
} }
} }
// TODO: should probably set the alt text too. Integer as text is better than nothing. Use the same string for the icon and alt text in the string version.
res = window->win32.taskbarList->lpVtbl->SetOverlayIcon(window->win32.taskbarList, window->win32.handle, icon, TEXT("")); res = window->win32.taskbarList->lpVtbl->SetOverlayIcon(window->win32.taskbarList, window->win32.handle, icon, TEXT(""));
if(icon) if(icon)
@ -1759,6 +1768,12 @@ void _glfwSetWindowTaskbarBadgeWin32(_GLFWwindow* window, int count)
} }
} }
void _glfwSetWindowTaskbarBadgeStringWin32(_GLFWwindow* window, const char* string)
{
_glfwInputError(GLFW_FEATURE_UNIMPLEMENTED,
"Win32: I'm sure GamesTrap will find a way to write non-integer strings with GDI too. :)");
}
void _glfwGetWindowPosWin32(_GLFWwindow* window, int* xpos, int* ypos) void _glfwGetWindowPosWin32(_GLFWwindow* window, int* xpos, int* ypos)
{ {
POINT pos = { 0, 0 }; POINT pos = { 0, 0 };

View File

@ -587,11 +587,9 @@ GLFWAPI void glfwSetWindowTaskbarBadge(GLFWwindow* handle, int count)
{ {
_GLFWwindow* window = (_GLFWwindow*)handle; _GLFWwindow* window = (_GLFWwindow*)handle;
assert(window != NULL);
_GLFW_REQUIRE_INIT(); _GLFW_REQUIRE_INIT();
if (count != GLFW_DONT_CARE && (count < 0 || count > 999)) if (count < 0)
{ {
_glfwInputError(GLFW_INVALID_VALUE, "Invalid badge count %d", count); _glfwInputError(GLFW_INVALID_VALUE, "Invalid badge count %d", count);
return; return;
@ -600,6 +598,15 @@ GLFWAPI void glfwSetWindowTaskbarBadge(GLFWwindow* handle, int count)
_glfw.platform.setWindowTaskbarBadge(window, count); _glfw.platform.setWindowTaskbarBadge(window, count);
} }
GLFWAPI void glfwSetWindowTaskbarBadgeString(GLFWwindow* handle, const char* string)
{
_GLFWwindow* window = (_GLFWwindow*)handle;
_GLFW_REQUIRE_INIT();
_glfw.platform.setWindowTaskbarBadgeString(window, string);
}
GLFWAPI void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos) GLFWAPI void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;

View File

@ -421,6 +421,7 @@ GLFWbool _glfwConnectWayland(int platformID, _GLFWplatform* platform)
_glfwSetWindowIconWayland, _glfwSetWindowIconWayland,
_glfwSetWindowTaskbarProgressWayland, _glfwSetWindowTaskbarProgressWayland,
_glfwSetWindowTaskbarBadgeWayland, _glfwSetWindowTaskbarBadgeWayland,
_glfwSetWindowTaskbarBadgeStringWayland,
_glfwGetWindowPosWayland, _glfwGetWindowPosWayland,
_glfwSetWindowPosWayland, _glfwSetWindowPosWayland,
_glfwGetWindowSizeWayland, _glfwGetWindowSizeWayland,

View File

@ -448,6 +448,7 @@ void _glfwSetWindowTitleWayland(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconWayland(_GLFWwindow* window, int count, const GLFWimage* images); void _glfwSetWindowIconWayland(_GLFWwindow* window, int count, const GLFWimage* images);
void _glfwSetWindowTaskbarProgressWayland(_GLFWwindow* window, int progressState, double value); void _glfwSetWindowTaskbarProgressWayland(_GLFWwindow* window, int progressState, double value);
void _glfwSetWindowTaskbarBadgeWayland(_GLFWwindow* window, int count); void _glfwSetWindowTaskbarBadgeWayland(_GLFWwindow* window, int count);
void _glfwSetWindowTaskbarBadgeStringWayland(_GLFWwindow* window, const char* string);
void _glfwGetWindowPosWayland(_GLFWwindow* window, int* xpos, int* ypos); void _glfwGetWindowPosWayland(_GLFWwindow* window, int* xpos, int* ypos);
void _glfwSetWindowPosWayland(_GLFWwindow* window, int xpos, int ypos); void _glfwSetWindowPosWayland(_GLFWwindow* window, int xpos, int ypos);
void _glfwGetWindowSizeWayland(_GLFWwindow* window, int* width, int* height); void _glfwGetWindowSizeWayland(_GLFWwindow* window, int* width, int* height);

View File

@ -1913,13 +1913,24 @@ void _glfwSetWindowTaskbarProgressWayland(_GLFWwindow* window, const int progres
void _glfwSetWindowTaskbarBadgeWayland(_GLFWwindow* window, int count) void _glfwSetWindowTaskbarBadgeWayland(_GLFWwindow* window, int count)
{ {
(void)window; if (window != NULL)
{
_glfwInputError(GLFW_FEATURE_UNAVAILABLE,
"Wayland: Cannot set a badge for a window. Pass NULL to set the application's shared badge.");
return;
}
const dbus_bool_t badgeVisible = (count != GLFW_DONT_CARE); const dbus_bool_t badgeVisible = (count > 0);
_glfwUpdateTaskbarBadgeDBusPOSIX(badgeVisible, count); _glfwUpdateTaskbarBadgeDBusPOSIX(badgeVisible, count);
} }
void _glfwSetWindowTaskbarBadgeStringWayland(_GLFWwindow* window, const char* string)
{
_glfwInputError(GLFW_FEATURE_UNAVAILABLE,
"Wayland: Unable to set a string badge. Only integer badges are supported.");
}
void _glfwGetWindowPosWayland(_GLFWwindow* window, int* xpos, int* ypos) void _glfwGetWindowPosWayland(_GLFWwindow* window, int* xpos, int* ypos)
{ {
// A Wayland client is not aware of its position, so just warn and leave it // A Wayland client is not aware of its position, so just warn and leave it

View File

@ -1211,6 +1211,7 @@ GLFWbool _glfwConnectX11(int platformID, _GLFWplatform* platform)
_glfwSetWindowIconX11, _glfwSetWindowIconX11,
_glfwSetWindowTaskbarProgressX11, _glfwSetWindowTaskbarProgressX11,
_glfwSetWindowTaskbarBadgeX11, _glfwSetWindowTaskbarBadgeX11,
_glfwSetWindowTaskbarBadgeStringX11,
_glfwGetWindowPosX11, _glfwGetWindowPosX11,
_glfwSetWindowPosX11, _glfwSetWindowPosX11,
_glfwGetWindowSizeX11, _glfwGetWindowSizeX11,

View File

@ -907,6 +907,7 @@ void _glfwSetWindowTitleX11(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconX11(_GLFWwindow* window, int count, const GLFWimage* images); void _glfwSetWindowIconX11(_GLFWwindow* window, int count, const GLFWimage* images);
void _glfwSetWindowTaskbarProgressX11(_GLFWwindow* window, int progressState, double value); void _glfwSetWindowTaskbarProgressX11(_GLFWwindow* window, int progressState, double value);
void _glfwSetWindowTaskbarBadgeX11(_GLFWwindow* window, int count); void _glfwSetWindowTaskbarBadgeX11(_GLFWwindow* window, int count);
void _glfwSetWindowTaskbarBadgeStringX11(_GLFWwindow* window, const char* string);
void _glfwGetWindowPosX11(_GLFWwindow* window, int* xpos, int* ypos); void _glfwGetWindowPosX11(_GLFWwindow* window, int* xpos, int* ypos);
void _glfwSetWindowPosX11(_GLFWwindow* window, int xpos, int ypos); void _glfwSetWindowPosX11(_GLFWwindow* window, int xpos, int ypos);
void _glfwGetWindowSizeX11(_GLFWwindow* window, int* width, int* height); void _glfwGetWindowSizeX11(_GLFWwindow* window, int* width, int* height);

View File

@ -2163,13 +2163,24 @@ void _glfwSetWindowTaskbarProgressX11(_GLFWwindow* window, int progressState, do
void _glfwSetWindowTaskbarBadgeX11(_GLFWwindow* window, int count) void _glfwSetWindowTaskbarBadgeX11(_GLFWwindow* window, int count)
{ {
(void)window; if (window != NULL)
{
_glfwInputError(GLFW_FEATURE_UNAVAILABLE,
"X11: Cannot set a badge for a window. Pass NULL to set the application's shared badge.");
return;
}
const dbus_bool_t badgeVisible = (count != GLFW_DONT_CARE); const dbus_bool_t badgeVisible = (count > 0);
_glfwUpdateTaskbarBadgeDBusPOSIX(badgeVisible, count); _glfwUpdateTaskbarBadgeDBusPOSIX(badgeVisible, count);
} }
void _glfwSetWindowTaskbarBadgeStringX11(_GLFWwindow* window, const char* string)
{
_glfwInputError(GLFW_FEATURE_UNAVAILABLE,
"X11: Unable to set a string badge. Only integer badges are supported.");
}
void _glfwGetWindowPosX11(_GLFWwindow* window, int* xpos, int* ypos) void _glfwGetWindowPosX11(_GLFWwindow* window, int* xpos, int* ypos)
{ {
Window dummy; Window dummy;

View File

@ -443,17 +443,16 @@ int main(int argc, char** argv)
nk_label(nk, "Taskbar Badge", NK_TEXT_CENTERED); nk_label(nk, "Taskbar Badge", NK_TEXT_CENTERED);
static int enableBadge = false;
static int badgeCount = 0; static int badgeCount = 0;
nk_layout_row_begin(nk, NK_DYNAMIC, 30, 3); nk_layout_row_begin(nk, NK_DYNAMIC, 30, 3);
nk_layout_row_push(nk, 1.0f / 3.f); nk_layout_row_push(nk, 1.0f / 3.f);
if (nk_checkbox_label(nk, "Enable Badge", &enableBadge))
glfwSetWindowTaskbarBadge(window, enableBadge ? badgeCount : GLFW_DONT_CARE);
nk_layout_row_push(nk, 1.0f / 3.f);
nk_labelf(nk, NK_TEXT_LEFT, "Badge count: %d", badgeCount); nk_labelf(nk, NK_TEXT_LEFT, "Badge count: %d", badgeCount);
nk_layout_row_push(nk, 2.f / 3.f); nk_layout_row_push(nk, 2.f / 3.f);
if (nk_slider_int(nk, 0, &badgeCount, 99, 1)) if (nk_slider_int(nk, 0, &badgeCount, 10000, 1))
glfwSetWindowTaskbarBadge(window, enableBadge ? badgeCount : GLFW_DONT_CARE); {
glfwSetWindowTaskbarBadge(window, badgeCount);
glfwSetWindowTaskbarBadge(NULL, badgeCount);
}
nk_layout_row_end(nk); nk_layout_row_end(nk);
} }
nk_end(nk); nk_end(nk);