Simplify _glfwSetWindowTaskbarProgressCocoa

Fix merge issues
Rename taskbarState to progressState
Remove const qualifier from progressState parameter
This commit is contained in:
ws909 2023-03-02 15:51:10 +01:00
parent 0173252ee1
commit a9b36d48d7
15 changed files with 61 additions and 78 deletions

View File

@ -98,6 +98,7 @@ video tutorials.
- IntellectualKitty - IntellectualKitty
- Aaron Jacobs - Aaron Jacobs
- JannikGM - JannikGM
- Andreas O. Jansen
- Erik S. V. Jansson - Erik S. V. Jansson
- jjYBdx4IL - jjYBdx4IL
- Toni Jovanoski - Toni Jovanoski

View File

@ -3391,7 +3391,7 @@ GLFWAPI void glfwSetWindowIcon(GLFWwindow* window, int count, const GLFWimage* i
* *
* @ingroup window * @ingroup window
*/ */
GLFWAPI void glfwSetWindowTaskbarProgress(GLFWwindow* window, const int progressState, double value); GLFWAPI void glfwSetWindowTaskbarProgress(GLFWwindow* window, int progressState, double value);
/*! @brief Retrieves the position of the content area of the specified window. /*! @brief Retrieves the position of the content area of the specified window.
* *

View File

@ -650,6 +650,12 @@ void _glfwTerminateCocoa(void)
{ {
@autoreleasepool { @autoreleasepool {
if (_glfw.ns.dockProgressIndicator != nil)
{
[_glfw.ns.dockProgressIndicator removeFromSuperview];
[_glfw.ns.dockProgressIndicator release];
}
if (_glfw.ns.inputSource) if (_glfw.ns.inputSource)
{ {
CFRelease(_glfw.ns.inputSource); CFRelease(_glfw.ns.inputSource);

View File

@ -189,6 +189,8 @@ typedef struct _GLFWlibraryNS
PFN_LMGetKbdType GetKbdType; PFN_LMGetKbdType GetKbdType;
CFStringRef kPropertyUnicodeKeyLayoutData; CFStringRef kPropertyUnicodeKeyLayoutData;
} tis; } tis;
id dockProgressIndicator;
} _GLFWlibraryNS; } _GLFWlibraryNS;
// Cocoa-specific per-monitor data // Cocoa-specific per-monitor data
@ -218,7 +220,7 @@ GLFWbool _glfwCreateWindowCocoa(_GLFWwindow* window, const _GLFWwndconfig* wndco
void _glfwDestroyWindowCocoa(_GLFWwindow* window); void _glfwDestroyWindowCocoa(_GLFWwindow* window);
void _glfwSetWindowTitleCocoa(_GLFWwindow* window, const char* title); 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, const int taskbarState, double value); void _glfwSetWindowTaskbarProgressCocoa(_GLFWwindow* window, int progressState, double value);
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

@ -1032,77 +1032,58 @@ void _glfwSetWindowIconCocoa(_GLFWwindow* window,
"Cocoa: Regular windows do not have icons on macOS"); "Cocoa: Regular windows do not have icons on macOS");
} }
// TODO: potential enhancement: use float or double for higher precision than int.
// TODO: potential enhancement: also specify the source's weight. Used for calculating the combined progress.
// TODO: move static progressIndicator to _glfw.ns. Remove/release in glfwTerminate.
// TODO: allow multiple windows to set values. Use the combined progress for all of them; example: [35%, 70%, 90%] => 65%. // TODO: allow multiple windows to set values. Use the combined progress for all of them; example: [35%, 70%, 90%] => 65%.
// FIXME: Switching from INDETERMINATE to NORMAL, PAUSED or ERROR requires 2 invocations. // TODO: documentation remarks for MacOS
void _glfwSetWindowTaskbarProgressCocoa(_GLFWwindow* window, const int progressState, double value) void _glfwSetWindowTaskbarProgressCocoa(_GLFWwindow* window, int progressState, double value)
{ {
static NSProgressIndicator* progressIndicator; NSProgressIndicator* indicator = _glfw.ns.dockProgressIndicator;
_glfwInputError(GLFW_FEATURE_UNIMPLEMENTED,
"Cocoa: Window taskbar progress is not implemented");
NSDockTile* dockTile = [[NSApplication sharedApplication] dockTile]; NSDockTile* dockTile = [[NSApplication sharedApplication] dockTile];
if (progressIndicator == nil) if (indicator == nil)
{ {
if ([dockTile contentView] == nil) if ([dockTile contentView] == nil)
{ {
NSImageView *iconView = [[NSImageView alloc] init]; NSImageView *iconView = [[NSImageView alloc] init];
[iconView setImage:[[NSApplication sharedApplication] applicationIconImage]]; [iconView setImage:[[NSApplication sharedApplication] applicationIconImage]];
[dockTile setContentView:iconView]; [dockTile setContentView:iconView];
[iconView release];
} }
NSView* contentView = [dockTile contentView]; NSView* contentView = [dockTile contentView];
//progressIndicator = [[NSProgressIndicator alloc] init]; indicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, contentView.frame.size.width, 15.0f)];
progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, contentView.frame.size.width, 15.0f)]; [indicator setStyle:NSProgressIndicatorStyleBar];
[progressIndicator setStyle:NSProgressIndicatorStyleBar]; [indicator setControlSize:NSControlSizeLarge];
[progressIndicator setControlSize:NSControlSizeLarge]; [indicator setMinValue:0.0f];
[progressIndicator setMinValue:0.0f]; [indicator setMaxValue:1.0f];
[progressIndicator setMaxValue:100.0f];
[progressIndicator setAccessibilityLabel:@"LABEL"]; [contentView addSubview:indicator];
[progressIndicator setAccessibilityHelp:@"HELP"];
[progressIndicator setToolTip:@"TOOLTIP"];
[contentView addSubview:progressIndicator]; _glfw.ns.dockProgressIndicator = indicator;
/*
NSLayoutConstraint* constraint = [NSLayoutConstraint constraintWithItem:progressIndicator
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:contentView
attribute:NSLayoutAttributeWidth
multiplier:1.0f
constant:0.0f];
[contentView addConstraint:constraint];*/
[progressIndicator release];
} }
// FIXME: Switching from INDETERMINATE to NORMAL, PAUSED or ERROR requires 2 invocations in different frames.
// In MacOS 12 (and probably other versions), an indeterminate progress bar is rendered as a normal bar
// with 0.0 progress. So when calling [progressIndicator setIndeterminate:YES], the indicator actually
// sets its doubleValue to 0.0.
// The bug is caused by NSProgressIndicator not immediately updating its value when it's increasing.
// This code illustrates the exact same problem, but this time from NORMAL, PAUSED and ERROR to INDETERMINATE:
//
// if (progressState == GLFW_TASKBAR_PROGRESS_INDETERMINATE)
// [progressIndicator setDoubleValue:0.75];
// else
// [progressIndicator setDoubleValue:0.25];
//
// This is likely a bug in Cocoa.
//
// FIXME: Progress increments are delayed
// What this also means, is that each time the progress increments, the bar's progress will be 1 frame delayed,
// and only updated once a higher or similar value is again set the next frame.
switch (progressState)
{
case GLFW_TASKBAR_PROGRESS_DISABLED:
[progressIndicator setIndeterminate:NO];
[progressIndicator setHidden:YES];
break;
case GLFW_TASKBAR_PROGRESS_INDETERMINATE:
[progressIndicator setIndeterminate:YES];
[progressIndicator setHidden:NO];
break;
case GLFW_TASKBAR_PROGRESS_NORMAL:
case GLFW_TASKBAR_PROGRESS_PAUSED:
case GLFW_TASKBAR_PROGRESS_ERROR:
[progressIndicator setIndeterminate:NO];
[progressIndicator setHidden:NO];
break;
}
[progressIndicator setDoubleValue:value]; [indicator setIndeterminate:progressState == GLFW_TASKBAR_PROGRESS_INDETERMINATE];
[indicator setHidden:progressState == GLFW_TASKBAR_PROGRESS_DISABLED];
[indicator setDoubleValue:value];
[dockTile display]; [dockTile display];
} }

View File

@ -89,7 +89,7 @@ GLFWbool _glfwCreateWindowNull(_GLFWwindow* window, const _GLFWwndconfig* wndcon
void _glfwDestroyWindowNull(_GLFWwindow* window); void _glfwDestroyWindowNull(_GLFWwindow* window);
void _glfwSetWindowTitleNull(_GLFWwindow* window, const char* title); 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, const int taskbarState, double value); void _glfwSetWindowTaskbarProgressNull(_GLFWwindow* window, int progressState, double value);
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

@ -187,7 +187,7 @@ void _glfwSetWindowIconNull(_GLFWwindow* window, int count, const GLFWimage* ima
{ {
} }
void _glfwSetWindowTaskbarProgressNull(_GLFWwindow* window, const int progressState, double value) void _glfwSetWindowTaskbarProgressNull(_GLFWwindow* window, int progressState, double value)
{ {
} }

View File

@ -618,7 +618,7 @@ GLFWbool _glfwCreateWindowWin32(_GLFWwindow* window, const _GLFWwndconfig* wndco
void _glfwDestroyWindowWin32(_GLFWwindow* window); void _glfwDestroyWindowWin32(_GLFWwindow* window);
void _glfwSetWindowTitleWin32(_GLFWwindow* window, const char* title); 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, const int taskbarState, double value); void _glfwSetWindowTaskbarProgressWin32(_GLFWwindow* window, int progressState, double value);
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

@ -1596,7 +1596,7 @@ void _glfwSetWindowIconWin32(_GLFWwindow* window, int count, const GLFWimage* im
} }
} }
void _glfwSetWindowTaskbarProgressWin32(_GLFWwindow* window, const int progressState, double value) void _glfwSetWindowTaskbarProgressWin32(_GLFWwindow* window, int progressState, double value)
{ {
HRESULT res = S_OK; HRESULT res = S_OK;
int winProgressState = 0; int winProgressState = 0;

View File

@ -558,7 +558,7 @@ GLFWAPI void glfwSetWindowIcon(GLFWwindow* handle,
_glfw.platform.setWindowIcon(window, count, images); _glfw.platform.setWindowIcon(window, count, images);
} }
GLFWAPI void glfwSetWindowTaskbarProgress(GLFWwindow* handle, const int progressState, double value) GLFWAPI void glfwSetWindowTaskbarProgress(GLFWwindow* handle, int progressState, double value)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;

View File

@ -446,7 +446,7 @@ GLFWbool _glfwCreateWindowWayland(_GLFWwindow* window, const _GLFWwndconfig* wnd
void _glfwDestroyWindowWayland(_GLFWwindow* window); void _glfwDestroyWindowWayland(_GLFWwindow* window);
void _glfwSetWindowTitleWayland(_GLFWwindow* window, const char* title); 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, const int taskbarState, double value); void _glfwSetWindowTaskbarProgressWayland(_GLFWwindow* window, int progressState, double value);
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

@ -1902,11 +1902,11 @@ void _glfwSetWindowIconWayland(_GLFWwindow* window,
"Wayland: The platform does not support setting the window icon"); "Wayland: The platform does not support setting the window icon");
} }
void _glfwSetWindowTaskbarProgressWayland(_GLFWwindow* window, const int taskbarState, double value) void _glfwSetWindowTaskbarProgressWayland(_GLFWwindow* window, const int progressState, double value)
{ {
(void)window; (void)window;
const dbus_bool_t progressVisible = (taskbarState != GLFW_TASKBAR_PROGRESS_DISABLED); const dbus_bool_t progressVisible = (progressState != GLFW_TASKBAR_PROGRESS_DISABLED);
_glfwUpdateTaskbarProgressDBusPOSIX(progressVisible, value); _glfwUpdateTaskbarProgressDBusPOSIX(progressVisible, value);
} }

View File

@ -905,7 +905,7 @@ GLFWbool _glfwCreateWindowX11(_GLFWwindow* window, const _GLFWwndconfig* wndconf
void _glfwDestroyWindowX11(_GLFWwindow* window); void _glfwDestroyWindowX11(_GLFWwindow* window);
void _glfwSetWindowTitleX11(_GLFWwindow* window, const char* title); 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, const int taskbarState, double value); void _glfwSetWindowTaskbarProgressX11(_GLFWwindow* window, int progressState, double value);
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

@ -2152,11 +2152,11 @@ void _glfwSetWindowIconX11(_GLFWwindow* window, int count, const GLFWimage* imag
XFlush(_glfw.x11.display); XFlush(_glfw.x11.display);
} }
void _glfwSetWindowTaskbarProgressX11(_GLFWwindow* window, const int taskbarState, double value) void _glfwSetWindowTaskbarProgressX11(_GLFWwindow* window, int progressState, double value)
{ {
(void)window; (void)window;
const dbus_bool_t progressVisible = (taskbarState != GLFW_TASKBAR_PROGRESS_DISABLED); const dbus_bool_t progressVisible = (progressState != GLFW_TASKBAR_PROGRESS_DISABLED);
_glfwUpdateTaskbarProgressDBusPOSIX(progressVisible, value); _glfwUpdateTaskbarProgressDBusPOSIX(progressVisible, value);
} }

View File

@ -419,28 +419,21 @@ int main(int argc, char** argv)
nk_layout_row_dynamic(nk, 30, 5); nk_layout_row_dynamic(nk, 30, 5);
static int state = GLFW_TASKBAR_PROGRESS_DISABLED; static int state = GLFW_TASKBAR_PROGRESS_DISABLED;
static int progress = 0;
static float progress = 0; static float progress = 0;
if(nk_button_label(nk, "No progress")) if(nk_button_label(nk, "No progress"))
glfwSetWindowTaskbarProgress(window, state = GLFW_TASKBAR_PROGRESS_DISABLED, progress); glfwSetWindowTaskbarProgress(window, state = GLFW_TASKBAR_PROGRESS_DISABLED, (double) progress);
glfwSetWindowTaskbarProgress(window, GLFW_TASKBAR_PROGRESS_DISABLED, (double)progress);
if (nk_button_label(nk, "Indeterminate")) if (nk_button_label(nk, "Indeterminate"))
glfwSetWindowTaskbarProgress(window, state = GLFW_TASKBAR_PROGRESS_INDETERMINATE, progress); glfwSetWindowTaskbarProgress(window, state = GLFW_TASKBAR_PROGRESS_INDETERMINATE, (double) progress);
glfwSetWindowTaskbarProgress(window, GLFW_TASKBAR_PROGRESS_INDETERMINATE, (double)progress);
if (nk_button_label(nk, "Normal")) if (nk_button_label(nk, "Normal"))
glfwSetWindowTaskbarProgress(window, state = GLFW_TASKBAR_PROGRESS_NORMAL, progress); glfwSetWindowTaskbarProgress(window, state = GLFW_TASKBAR_PROGRESS_NORMAL, (double) progress);
glfwSetWindowTaskbarProgress(window, GLFW_TASKBAR_PROGRESS_NORMAL, (double)progress);
if (nk_button_label(nk, "Error")) if (nk_button_label(nk, "Error"))
glfwSetWindowTaskbarProgress(window, state = GLFW_TASKBAR_PROGRESS_ERROR, progress); glfwSetWindowTaskbarProgress(window, state = GLFW_TASKBAR_PROGRESS_ERROR, (double) progress);
glfwSetWindowTaskbarProgress(window, GLFW_TASKBAR_PROGRESS_ERROR, (double)progress);
if (nk_button_label(nk, "Paused")) if (nk_button_label(nk, "Paused"))
glfwSetWindowTaskbarProgress(window, state = GLFW_TASKBAR_PROGRESS_PAUSED, progress); glfwSetWindowTaskbarProgress(window, state = GLFW_TASKBAR_PROGRESS_PAUSED, (double) progress);
glfwSetWindowTaskbarProgress(window, GLFW_TASKBAR_PROGRESS_PAUSED, (double)progress);
nk_label(nk, "Progress: ", NK_TEXT_ALIGN_LEFT); nk_label(nk, "Progress: ", NK_TEXT_ALIGN_LEFT);
if (nk_slider_int(nk, 0, &progress, 100, 1)) if (nk_slider_float(nk, 0.0f, &progress, 1.0f, 0.05f))
glfwSetWindowTaskbarProgress(window, state, progress); glfwSetWindowTaskbarProgress(window, state, (double) progress);
nk_slider_float(nk, 0.0f, &progress, 1.0f, 0.05f);
} }
nk_end(nk); nk_end(nk);