From ef4d722b76c716ced202603233db2ae4ad4b27e2 Mon Sep 17 00:00:00 2001 From: Andreas <37029098+ws909@users.noreply.github.com> Date: Wed, 8 Mar 2023 14:10:00 +0100 Subject: [PATCH 1/2] Merge(#3): Finalized progress API --- CMakeLists.txt | 10 +------- CONTRIBUTORS.md | 1 + README.md | 2 +- docs/window.dox | 20 +++++++-------- include/GLFW/glfw3.h | 58 +++++++++++++++++++++++--------------------- src/cocoa_init.m | 2 +- src/cocoa_platform.h | 2 +- src/cocoa_window.m | 34 +++++++++++++------------- src/internal.h | 2 +- src/null_init.c | 2 +- src/null_platform.h | 2 +- src/null_window.c | 2 +- src/posix_dbus.c | 4 +-- src/posix_dbus.h | 3 +-- src/win32_init.c | 2 +- src/win32_platform.h | 2 +- src/win32_window.c | 32 ++++++++++++------------ src/window.c | 12 ++++----- src/wl_init.c | 2 +- src/wl_platform.h | 2 +- src/wl_window.c | 4 +-- src/x11_init.c | 2 +- src/x11_platform.h | 2 +- src/x11_window.c | 4 +-- tests/window.c | 16 ++++++------ 25 files changed, 109 insertions(+), 115 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5e538bf..dd256a0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,12 +2,6 @@ cmake_minimum_required(VERSION 3.4...3.20 FATAL_ERROR) project(GLFW VERSION 3.4.0 LANGUAGES C) -set(CMAKE_LEGACY_CYGWIN_WIN32 OFF) - -if (POLICY CMP0054) - cmake_policy(SET CMP0054 NEW) -endif() - if (POLICY CMP0069) cmake_policy(SET CMP0069 NEW) endif() @@ -18,9 +12,7 @@ endif() set_property(GLOBAL PROPERTY USE_FOLDERS ON) -if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - set(GLFW_STANDALONE TRUE) -endif() +string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} GLFW_STANDALONE) option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ${GLFW_STANDALONE}) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 60898844..aed07b27 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -189,6 +189,7 @@ video tutorials. - pthom - Martin Pulec - Guillaume Racicot + - Juan Ramos - Christian Rauch - Philip Rideout - Eddie Ringle diff --git a/README.md b/README.md index 96e92609..e9a2c79a 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ information on what to include when reporting a bug. ## Changelog - - Added `glfwSetWindowTaskbarProgress` allowing to display progress on the taskbar (#2286,#1183) + - Added `glfwSetWindowProgressIndicator` for displaying progress on the dock or taskbar (#2286,#1183) - Added `GLFW_PLATFORM` init hint for runtime platform selection (#1958) - Added `GLFW_ANY_PLATFORM`, `GLFW_PLATFORM_WIN32`, `GLFW_PLATFORM_COCOA`, `GLFW_PLATFORM_WAYLAND`, `GLFW_PLATFORM_X11` and `GLFW_PLATFORM_NULL` symbols to diff --git a/docs/window.dox b/docs/window.dox index 56a6d708..2fdaf521 100644 --- a/docs/window.dox +++ b/docs/window.dox @@ -1159,21 +1159,21 @@ not supported, the application as a whole. Once the user has given it attention, the system will automatically end the request. -@subsection window_taskbar_progress Window taskbar progress +@subsection window_progress_indicator Window progress indicator -If you wish to display the progress of some action on the taskbar, you can -do this with @ref glfwSetWindowTaskbarProgress. +If you wish to display the progress of some action on the Dock icon or task bar, you can +do this with @ref glfwSetWindowProgressIndicator. @code -glfwSetWindowTaskbarProgress(window, GLFW_TASKBAR_PROGRESS_NORMAL, 50); +glfwSetWindowProgressIndicator(window, GLFW_PROGRESS_INDICATOR_NORMAL, 0.5); @endcode -There are different taskbar progress states available for you to use: - - @ref GLFW_TASKBAR_PROGRESS_DISABLED - - @ref GLFW_TASKBAR_PROGRESS_INDETERMINATE - - @ref GLFW_TASKBAR_PROGRESS_NORMAL - - @ref GLFW_TASKBAR_PROGRESS_ERROR - - @ref GLFW_TASKBAR_PROGRESS_PAUSED +There are different progress states available for you to use: + - @ref GLFW_PROGRESS_INDICATOR_DISABLED + - @ref GLFW_PROGRESS_INDICATOR_INDETERMINATE + - @ref GLFW_PROGRESS_INDICATOR_NORMAL + - @ref GLFW_PROGRESS_INDICATOR_ERROR + - @ref GLFW_PROGRESS_INDICATOR_PAUSED The last argument is the progress percentage to display. It has a valid range of 0.0 to 1.0. diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index ca8796b2..b45e1d2e 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -1278,51 +1278,51 @@ extern "C" { * * Disable the progress bar. * - * Used by @ref window_taskbar_progress. + * Used by @ref window_progress_indicator. */ -#define GLFW_TASKBAR_PROGRESS_DISABLED 0 +#define GLFW_PROGRESS_INDICATOR_DISABLED 0 /*! @brief Display the progress bar in an indeterminate state. * * Display the progress bar in an indeterminate state. * * @remark @win32 This displays the progress bar animation cycling repeatedly. * - * @remark @x11 @wayland This behaves like @ref GLFW_TASKBAR_PROGRESS_NORMAL. + * @remark @x11 @wayland This behaves like @ref GLFW_PROGRESS_INDICATOR_NORMAL. * * @remark @macos This displays a standard indeterminate `NSProgressIndicator`. * - * Used by @ref window_taskbar_progress. + * Used by @ref window_progress_indicator. */ -#define GLFW_TASKBAR_PROGRESS_INDETERMINATE 1 +#define GLFW_PROGRESS_INDICATOR_INDETERMINATE 1 /*! @brief Display the normal progress bar. * * Display the normal progress bar. * - * Used by @ref window_taskbar_progress. + * Used by @ref window_progress_indicator. */ -#define GLFW_TASKBAR_PROGRESS_NORMAL 2 +#define GLFW_PROGRESS_INDICATOR_NORMAL 2 /*! @brief Display the progress bar in an error state. * * Display the progress bar in an error state. * * @remark @win32 This displays a red progress bar. * - * @remark @x11 @wayland @macos This behaves like @ref GLFW_TASKBAR_PROGRESS_NORMAL. + * @remark @x11 @wayland @macos This behaves like @ref GLFW_PROGRESS_INDICATOR_NORMAL. * - * Used by @ref window_taskbar_progress. + * Used by @ref window_progress_indicator. */ -#define GLFW_TASKBAR_PROGRESS_ERROR 3 +#define GLFW_PROGRESS_INDICATOR_ERROR 3 /*! @brief Display the progress bar in a paused state. * * Display the progress bar in a paused state. * * @remark @win32 This displays a yellow progress bar. * - * @remark @x11 @wayland @macos This behaves like @ref GLFW_TASKBAR_PROGRESS_NORMAL. + * @remark @x11 @wayland @macos This behaves like @ref GLFW_PROGRESS_INDICATOR_NORMAL. * - * Used by @ref window_taskbar_progress. + * Used by @ref window_progress_indicator. */ -#define GLFW_TASKBAR_PROGRESS_PAUSED 4 +#define GLFW_PROGRESS_INDICATOR_PAUSED 4 /*! @} */ #define GLFW_CONNECTED 0x00040001 @@ -3357,43 +3357,45 @@ GLFWAPI void glfwSetWindowTitle(GLFWwindow* window, const char* title); */ GLFWAPI void glfwSetWindowIcon(GLFWwindow* window, int count, const GLFWimage* images); -/*! @brief Sets the taskbar progress for the specified window. +/*! @brief Sets the dock or taskbar progress indicator for the specified window. * - * This function sets the taskbar progress of the specified window. + * This function sets the dock or taskbar progress indicator of the specified window. * - * @param[in] window The window whose taskbar progress to set. - * @param[in] progressState State of the progress to be displayed in the taskbar. Valid values are: - * @ref GLFW_TASKBAR_PROGRESS_DISABLED, @ref GLFW_TASKBAR_PROGRESS_INDETERMINATE, - * @ref GLFW_TASKBAR_PROGRESS_NORMAL, @ref GLFW_TASKBAR_PROGRESS_ERROR - * and @ref GLFW_TASKBAR_PROGRESS_PAUSED. + * @param[in] window The window whose progress to set. + * @param[in] progressState The state of the progress to be displayed in the dock + * or taskbar. Valid values are: @ref GLFW_PROGRESS_INDICATOR_DISABLED, + * @ref GLFW_PROGRESS_INDICATOR_INDETERMINATE, @ref GLFW_PROGRESS_INDICATOR_NORMAL, + * @ref GLFW_PROGRESS_INDICATOR_ERROR and @ref GLFW_PROGRESS_INDICATOR_PAUSED. * @param[in] value The amount of completed progress to set. Valid range is 0.0 to 1.0. - * This is ignored if progressState is set to @ref GLFW_TASKBAR_PROGRESS_DISABLED. + * This is ignored if progressState is set to @ref GLFW_PROGRESS_INDICATOR_DISABLED. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_VALUE, @ref GLFW_INVALID_ENUM, @ref GLFW_PLATFORM_ERROR, * @ref GLFW_FEATURE_UNIMPLEMENTED and @ref GLFW_FEATURE_UNAVAILABLE (see remarks). * - * @remark @win32 On Windows Vista and earlier, this function will emit @ref GLFW_FEATURE_UNAVAILABLE. + * @remark @win32 On Windows Vista and earlier, this function will emit + * @ref GLFW_FEATURE_UNAVAILABLE. * * @remark @macos There exists only one Dock icon progress bar, and this * displays the combined values of all the windows. * * @remark @x11 @wayland Requires a valid application desktop file with the same name * as the compiled executable. Due to limitations in the Unity Launcher API - * @ref GLFW_TASKBAR_PROGRESS_INDETERMINATE, @ref GLFW_TASKBAR_PROGRESS_ERROR and @ref GLFW_TASKBAR_PROGRESS_PAUSED - * have the same behaviour as @ref GLFW_TASKBAR_PROGRESS_NORMAL. The Unity Launcher API is only known - * to be supported on the Unity and KDE desktop environments, on other desktop environments this - * function may do nothing. + * @ref GLFW_PROGRESS_INDICATOR_INDETERMINATE, @ref GLFW_PROGRESS_INDICATOR_ERROR + * and @ref GLFW_PROGRESS_INDICATOR_PAUSED have the same behaviour as + * @ref GLFW_PROGRESS_INDICATOR_NORMAL. The Unity Launcher API is only known + * to be supported on the Unity and KDE desktop environments; on other desktop + * environments this function may do nothing. * * @thread_safety This function must only be called from the main thread. * - * @sa @ref window_taskbar_progress + * @sa @ref window_progress_indicator * * @since Added in version 3.4. * * @ingroup window */ -GLFWAPI void glfwSetWindowTaskbarProgress(GLFWwindow* window, int progressState, double value); +GLFWAPI void glfwSetWindowProgressIndicator(GLFWwindow* window, int progressState, double value); /*! @brief Retrieves the position of the content area of the specified window. * diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 5d199170..bcb6a4a6 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -528,7 +528,7 @@ GLFWbool _glfwConnectCocoa(int platformID, _GLFWplatform* platform) _glfwDestroyWindowCocoa, _glfwSetWindowTitleCocoa, _glfwSetWindowIconCocoa, - _glfwSetWindowTaskbarProgressCocoa, + _glfwSetWindowProgressIndicatorCocoa, _glfwGetWindowPosCocoa, _glfwSetWindowPosCocoa, _glfwGetWindowSizeCocoa, diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index aeda201b..e7938b5a 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -230,7 +230,7 @@ GLFWbool _glfwCreateWindowCocoa(_GLFWwindow* window, const _GLFWwndconfig* wndco void _glfwDestroyWindowCocoa(_GLFWwindow* window); void _glfwSetWindowTitleCocoa(_GLFWwindow* window, const char* title); void _glfwSetWindowIconCocoa(_GLFWwindow* window, int count, const GLFWimage* images); -void _glfwSetWindowTaskbarProgressCocoa(_GLFWwindow* window, int progressState, double value); +void _glfwSetWindowProgressIndicatorCocoa(_GLFWwindow* window, int progressState, double value); void _glfwGetWindowPosCocoa(_GLFWwindow* window, int* xpos, int* ypos); void _glfwSetWindowPosCocoa(_GLFWwindow* window, int xpos, int ypos); void _glfwGetWindowSizeCocoa(_GLFWwindow* window, int* width, int* height); diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 7ec251e0..a921c12f 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -248,7 +248,7 @@ static void setDockProgressIndicator(int progressState, double value) // 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) + // if (progressState == GLFW_PROGRESS_INDICATOR_INDETERMINATE) // [progressIndicator setDoubleValue:0.75]; // else // [progressIndicator setDoubleValue:0.25]; @@ -268,8 +268,8 @@ static void setDockProgressIndicator(int progressState, double value) indicator = createProgressIndicator(dockTile); } - [indicator setIndeterminate:progressState == GLFW_TASKBAR_PROGRESS_INDETERMINATE]; - [indicator setHidden:progressState == GLFW_TASKBAR_PROGRESS_DISABLED]; + [indicator setIndeterminate:progressState == GLFW_PROGRESS_INDICATOR_INDETERMINATE]; + [indicator setHidden:progressState == GLFW_PROGRESS_INDICATOR_DISABLED]; [indicator setDoubleValue:value]; [dockTile display]; @@ -1064,7 +1064,7 @@ void _glfwDestroyWindowCocoa(_GLFWwindow* window) { @autoreleasepool { - _glfwSetWindowTaskbarProgressCocoa(window, GLFW_TASKBAR_PROGRESS_DISABLED, 0.0); + _glfwSetWindowProgressIndicatorCocoa(window, GLFW_PROGRESS_INDICATOR_DISABLED, 0.0); if (_glfw.ns.disabledCursorWindow == window) _glfw.ns.disabledCursorWindow = NULL; @@ -1111,10 +1111,10 @@ void _glfwSetWindowIconCocoa(_GLFWwindow* window, "Cocoa: Regular windows do not have icons on macOS"); } -void _glfwSetWindowTaskbarProgressCocoa(_GLFWwindow* window, int progressState, double value) +void _glfwSetWindowProgressIndicatorCocoa(_GLFWwindow* window, int progressState, double value) { - if (progressState == GLFW_TASKBAR_PROGRESS_ERROR || progressState == GLFW_TASKBAR_PROGRESS_PAUSED) - progressState = GLFW_TASKBAR_PROGRESS_NORMAL; + if (progressState == GLFW_PROGRESS_INDICATOR_ERROR || progressState == GLFW_PROGRESS_INDICATOR_PAUSED) + progressState = GLFW_PROGRESS_INDICATOR_NORMAL; const int oldState = window->ns.dockProgressIndicator.state; const int state = progressState; @@ -1123,8 +1123,8 @@ void _glfwSetWindowTaskbarProgressCocoa(_GLFWwindow* window, int progressState, if (oldState == state) { - if (state == GLFW_TASKBAR_PROGRESS_DISABLED || - state == GLFW_TASKBAR_PROGRESS_INDETERMINATE || + if (state == GLFW_PROGRESS_INDICATOR_DISABLED || + state == GLFW_PROGRESS_INDICATOR_INDETERMINATE || oldValue == value) return; } @@ -1132,36 +1132,36 @@ void _glfwSetWindowTaskbarProgressCocoa(_GLFWwindow* window, int progressState, if (oldState != state) { // Reset - if (oldState == GLFW_TASKBAR_PROGRESS_INDETERMINATE) + if (oldState == GLFW_PROGRESS_INDICATOR_INDETERMINATE) --_glfw.ns.dockProgressIndicator.indeterminateCount; - if (oldState != GLFW_TASKBAR_PROGRESS_DISABLED) + if (oldState != GLFW_PROGRESS_INDICATOR_DISABLED) { --_glfw.ns.dockProgressIndicator.windowCount; _glfw.ns.dockProgressIndicator.totalValue -= oldValue; } // Set - if (state == GLFW_TASKBAR_PROGRESS_INDETERMINATE) + if (state == GLFW_PROGRESS_INDICATOR_INDETERMINATE) ++_glfw.ns.dockProgressIndicator.indeterminateCount; - if (state != GLFW_TASKBAR_PROGRESS_DISABLED) + if (state != GLFW_PROGRESS_INDICATOR_DISABLED) { ++_glfw.ns.dockProgressIndicator.windowCount; _glfw.ns.dockProgressIndicator.totalValue += value; } } - else if (state != GLFW_TASKBAR_PROGRESS_DISABLED) + else if (state != GLFW_PROGRESS_INDICATOR_DISABLED) _glfw.ns.dockProgressIndicator.totalValue += (value - oldValue); if (_glfw.ns.dockProgressIndicator.windowCount > _glfw.ns.dockProgressIndicator.indeterminateCount) { const double finalValue = _glfw.ns.dockProgressIndicator.totalValue / _glfw.ns.dockProgressIndicator.windowCount; - setDockProgressIndicator(GLFW_TASKBAR_PROGRESS_NORMAL, finalValue); + setDockProgressIndicator(GLFW_PROGRESS_INDICATOR_NORMAL, finalValue); } else if (_glfw.ns.dockProgressIndicator.indeterminateCount > 0) - setDockProgressIndicator(GLFW_TASKBAR_PROGRESS_INDETERMINATE, 0.0f); + setDockProgressIndicator(GLFW_PROGRESS_INDICATOR_INDETERMINATE, 0.0f); else - setDockProgressIndicator(GLFW_TASKBAR_PROGRESS_DISABLED, 0.0f); + setDockProgressIndicator(GLFW_PROGRESS_INDICATOR_DISABLED, 0.0f); window->ns.dockProgressIndicator.state = state; window->ns.dockProgressIndicator.value = value; diff --git a/src/internal.h b/src/internal.h index 3766294b..c5955284 100644 --- a/src/internal.h +++ b/src/internal.h @@ -706,7 +706,7 @@ struct _GLFWplatform void (*destroyWindow)(_GLFWwindow*); void (*setWindowTitle)(_GLFWwindow*,const char*); void (*setWindowIcon)(_GLFWwindow*,int,const GLFWimage*); - void (*setWindowTaskbarProgress)(_GLFWwindow*,const int,double); + void (*setWindowProgressIndicator)(_GLFWwindow*,const int,double); void (*getWindowPos)(_GLFWwindow*,int*,int*); void (*setWindowPos)(_GLFWwindow*,int,int); void (*getWindowSize)(_GLFWwindow*,int*,int*); diff --git a/src/null_init.c b/src/null_init.c index d3d8c8cb..3887827f 100644 --- a/src/null_init.c +++ b/src/null_init.c @@ -73,7 +73,7 @@ GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform) _glfwDestroyWindowNull, _glfwSetWindowTitleNull, _glfwSetWindowIconNull, - _glfwSetWindowTaskbarProgressNull, + _glfwSetWindowProgressIndicatorNull, _glfwGetWindowPosNull, _glfwSetWindowPosNull, _glfwGetWindowSizeNull, diff --git a/src/null_platform.h b/src/null_platform.h index c430eb37..d930fdb7 100644 --- a/src/null_platform.h +++ b/src/null_platform.h @@ -89,7 +89,7 @@ GLFWbool _glfwCreateWindowNull(_GLFWwindow* window, const _GLFWwndconfig* wndcon void _glfwDestroyWindowNull(_GLFWwindow* window); void _glfwSetWindowTitleNull(_GLFWwindow* window, const char* title); void _glfwSetWindowIconNull(_GLFWwindow* window, int count, const GLFWimage* images); -void _glfwSetWindowTaskbarProgressNull(_GLFWwindow* window, int progressState, double value); +void _glfwSetWindowProgressIndicatorNull(_GLFWwindow* window, int progressState, double value); 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 _glfwSetWindowPosNull(_GLFWwindow* window, int xpos, int ypos); diff --git a/src/null_window.c b/src/null_window.c index 812c7ab3..bab4cf9c 100644 --- a/src/null_window.c +++ b/src/null_window.c @@ -187,7 +187,7 @@ void _glfwSetWindowIconNull(_GLFWwindow* window, int count, const GLFWimage* ima { } -void _glfwSetWindowTaskbarProgressNull(_GLFWwindow* window, int progressState, double value) +void _glfwSetWindowProgressIndicatorNull(_GLFWwindow* window, int progressState, double value) { } diff --git a/src/posix_dbus.c b/src/posix_dbus.c index dff557a9..648cac23 100644 --- a/src/posix_dbus.c +++ b/src/posix_dbus.c @@ -1,7 +1,7 @@ //======================================================================== // GLFW 3.4 POSIX - www.glfw.org //------------------------------------------------------------------------ -// Copyright (c) 2022 Camilla Löwy +// Copyright (c) 2023 Camilla Löwy // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages @@ -110,7 +110,7 @@ void _glfwInitDBusPOSIX(void) { //Window NULL is safe here because it won't get //used inside the SetWindowTaskbarProgress function - _glfw.platform.setWindowTaskbarProgress(NULL, GLFW_TASKBAR_PROGRESS_DISABLED, 0); + _glfw.platform.setWindowProgressIndicator(NULL, GLFW_PROGRESS_INDICATOR_DISABLED, 0); } } diff --git a/src/posix_dbus.h b/src/posix_dbus.h index 82d81bbb..6408b804 100644 --- a/src/posix_dbus.h +++ b/src/posix_dbus.h @@ -1,8 +1,7 @@ //======================================================================== // GLFW 3.4 POSIX - www.glfw.org //------------------------------------------------------------------------ -// Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2017 Camilla Löwy +// Copyright (c) 2023 Camilla Löwy // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages diff --git a/src/win32_init.c b/src/win32_init.c index 8c097b10..895d4735 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -638,7 +638,7 @@ GLFWbool _glfwConnectWin32(int platformID, _GLFWplatform* platform) _glfwDestroyWindowWin32, _glfwSetWindowTitleWin32, _glfwSetWindowIconWin32, - _glfwSetWindowTaskbarProgressWin32, + _glfwSetWindowProgressIndicatorWin32, _glfwGetWindowPosWin32, _glfwSetWindowPosWin32, _glfwGetWindowSizeWin32, diff --git a/src/win32_platform.h b/src/win32_platform.h index f78a4861..834b9cc0 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -618,7 +618,7 @@ GLFWbool _glfwCreateWindowWin32(_GLFWwindow* window, const _GLFWwndconfig* wndco void _glfwDestroyWindowWin32(_GLFWwindow* window); void _glfwSetWindowTitleWin32(_GLFWwindow* window, const char* title); void _glfwSetWindowIconWin32(_GLFWwindow* window, int count, const GLFWimage* images); -void _glfwSetWindowTaskbarProgressWin32(_GLFWwindow* window, int progressState, double value); +void _glfwSetWindowProgressIndicatorWin32(_GLFWwindow* window, int progressState, double value); void _glfwGetWindowPosWin32(_GLFWwindow* window, int* xpos, int* ypos); void _glfwSetWindowPosWin32(_GLFWwindow* window, int xpos, int ypos); void _glfwGetWindowSizeWin32(_GLFWwindow* window, int* width, int* height); diff --git a/src/win32_window.c b/src/win32_window.c index 96278971..41f5fb52 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1596,7 +1596,7 @@ void _glfwSetWindowIconWin32(_GLFWwindow* window, int count, const GLFWimage* im } } -void _glfwSetWindowTaskbarProgressWin32(_GLFWwindow* window, int progressState, double value) +void _glfwSetWindowProgressIndicatorWin32(_GLFWwindow* window, int progressState, double value) { HRESULT res = S_OK; int winProgressState = 0; @@ -1620,22 +1620,22 @@ void _glfwSetWindowTaskbarProgressWin32(_GLFWwindow* window, int progressState, switch(progressState) { - case 1: - winProgressState = TBPF_INDETERMINATE; - break; - case 2: - winProgressState = TBPF_NORMAL; - break; - case 3: - winProgressState = TBPF_ERROR; - break; - case 4: - winProgressState = TBPF_PAUSED; - break; + case GLFW_PROGRESS_INDICATOR_INDETERMINATE: + winProgressState = TBPF_INDETERMINATE; + break; + case GLFW_PROGRESS_INDICATOR_NORMAL: + winProgressState = TBPF_NORMAL; + break; + case GLFW_PROGRESS_INDICATOR_ERROR: + winProgressState = TBPF_ERROR; + break; + case GLFW_PROGRESS_INDICATOR_PAUSED: + winProgressState = TBPF_PAUSED; + break; - default: - winProgressState = TBPF_NOPROGRESS; - break; + default: + winProgressState = TBPF_NOPROGRESS; + break; } res = window->win32.taskbarList->lpVtbl->SetProgressState(window->win32.taskbarList, window->win32.handle, winProgressState); diff --git a/src/window.c b/src/window.c index c7aca29d..4b7a7ffb 100644 --- a/src/window.c +++ b/src/window.c @@ -558,7 +558,7 @@ GLFWAPI void glfwSetWindowIcon(GLFWwindow* handle, _glfw.platform.setWindowIcon(window, count, images); } -GLFWAPI void glfwSetWindowTaskbarProgress(GLFWwindow* handle, int progressState, double value) +GLFWAPI void glfwSetWindowProgressIndicator(GLFWwindow* handle, int progressState, double value) { _GLFWwindow* window = (_GLFWwindow*) handle; @@ -568,19 +568,19 @@ GLFWAPI void glfwSetWindowTaskbarProgress(GLFWwindow* handle, int progressState, if (value < 0.0 || value > 1.0) { - _glfwInputError(GLFW_INVALID_VALUE, "Invalid progress amount for window taskbar progress"); + _glfwInputError(GLFW_INVALID_VALUE, "Invalid progress amount for window progress indicator"); return; } - if (progressState != GLFW_TASKBAR_PROGRESS_DISABLED && progressState != GLFW_TASKBAR_PROGRESS_INDETERMINATE && - progressState != GLFW_TASKBAR_PROGRESS_NORMAL && progressState != GLFW_TASKBAR_PROGRESS_ERROR && - progressState != GLFW_TASKBAR_PROGRESS_PAUSED) + if (progressState != GLFW_PROGRESS_INDICATOR_DISABLED && progressState != GLFW_PROGRESS_INDICATOR_INDETERMINATE && + progressState != GLFW_PROGRESS_INDICATOR_NORMAL && progressState != GLFW_PROGRESS_INDICATOR_ERROR && + progressState != GLFW_PROGRESS_INDICATOR_PAUSED) { _glfwInputError(GLFW_INVALID_ENUM, "Invalid progress state 0x%08X", progressState); return; } - _glfw.platform.setWindowTaskbarProgress(window, progressState, value); + _glfw.platform.setWindowProgressIndicator(window, progressState, value); } GLFWAPI void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos) diff --git a/src/wl_init.c b/src/wl_init.c index 4687b0e8..8fedafe2 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -419,7 +419,7 @@ GLFWbool _glfwConnectWayland(int platformID, _GLFWplatform* platform) _glfwDestroyWindowWayland, _glfwSetWindowTitleWayland, _glfwSetWindowIconWayland, - _glfwSetWindowTaskbarProgressWayland, + _glfwSetWindowProgressIndicatorWayland, _glfwGetWindowPosWayland, _glfwSetWindowPosWayland, _glfwGetWindowSizeWayland, diff --git a/src/wl_platform.h b/src/wl_platform.h index 918f232d..76aa82f7 100644 --- a/src/wl_platform.h +++ b/src/wl_platform.h @@ -446,7 +446,7 @@ GLFWbool _glfwCreateWindowWayland(_GLFWwindow* window, const _GLFWwndconfig* wnd void _glfwDestroyWindowWayland(_GLFWwindow* window); void _glfwSetWindowTitleWayland(_GLFWwindow* window, const char* title); void _glfwSetWindowIconWayland(_GLFWwindow* window, int count, const GLFWimage* images); -void _glfwSetWindowTaskbarProgressWayland(_GLFWwindow* window, int progressState, double value); +void _glfwSetWindowProgressIndicatorWayland(_GLFWwindow* window, int progressState, double value); void _glfwGetWindowPosWayland(_GLFWwindow* window, int* xpos, int* ypos); void _glfwSetWindowPosWayland(_GLFWwindow* window, int xpos, int ypos); void _glfwGetWindowSizeWayland(_GLFWwindow* window, int* width, int* height); diff --git a/src/wl_window.c b/src/wl_window.c index a4460e93..0a144c85 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1902,11 +1902,11 @@ void _glfwSetWindowIconWayland(_GLFWwindow* window, "Wayland: The platform does not support setting the window icon"); } -void _glfwSetWindowTaskbarProgressWayland(_GLFWwindow* window, const int progressState, double value) +void _glfwSetWindowProgressIndicatorWayland(_GLFWwindow* window, const int progressState, double value) { (void)window; - const dbus_bool_t progressVisible = (progressState != GLFW_TASKBAR_PROGRESS_DISABLED); + const dbus_bool_t progressVisible = (progressState != GLFW_PROGRESS_INDICATOR_DISABLED); _glfwUpdateTaskbarProgressDBusPOSIX(progressVisible, value); } diff --git a/src/x11_init.c b/src/x11_init.c index 3a5c71bf..22696f0a 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -1209,7 +1209,7 @@ GLFWbool _glfwConnectX11(int platformID, _GLFWplatform* platform) _glfwDestroyWindowX11, _glfwSetWindowTitleX11, _glfwSetWindowIconX11, - _glfwSetWindowTaskbarProgressX11, + _glfwSetWindowProgressIndicatorX11, _glfwGetWindowPosX11, _glfwSetWindowPosX11, _glfwGetWindowSizeX11, diff --git a/src/x11_platform.h b/src/x11_platform.h index 96280653..cdf37adc 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -905,7 +905,7 @@ GLFWbool _glfwCreateWindowX11(_GLFWwindow* window, const _GLFWwndconfig* wndconf void _glfwDestroyWindowX11(_GLFWwindow* window); void _glfwSetWindowTitleX11(_GLFWwindow* window, const char* title); void _glfwSetWindowIconX11(_GLFWwindow* window, int count, const GLFWimage* images); -void _glfwSetWindowTaskbarProgressX11(_GLFWwindow* window, int progressState, double value); +void _glfwSetWindowProgressIndicatorX11(_GLFWwindow* window, int progressState, double value); void _glfwGetWindowPosX11(_GLFWwindow* window, int* xpos, int* ypos); void _glfwSetWindowPosX11(_GLFWwindow* window, int xpos, int ypos); void _glfwGetWindowSizeX11(_GLFWwindow* window, int* width, int* height); diff --git a/src/x11_window.c b/src/x11_window.c index 6c2297ef..84b03cce 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -2152,11 +2152,11 @@ void _glfwSetWindowIconX11(_GLFWwindow* window, int count, const GLFWimage* imag XFlush(_glfw.x11.display); } -void _glfwSetWindowTaskbarProgressX11(_GLFWwindow* window, int progressState, double value) +void _glfwSetWindowProgressIndicatorX11(_GLFWwindow* window, int progressState, double value) { (void)window; - const dbus_bool_t progressVisible = (progressState != GLFW_TASKBAR_PROGRESS_DISABLED); + const dbus_bool_t progressVisible = (progressState != GLFW_PROGRESS_INDICATOR_DISABLED); _glfwUpdateTaskbarProgressDBusPOSIX(progressVisible, value); } diff --git a/tests/window.c b/tests/window.c index f36a1dda..bfde8b51 100644 --- a/tests/window.c +++ b/tests/window.c @@ -414,26 +414,26 @@ int main(int argc, char** argv) nk_layout_row_dynamic(nk, 30, 1); - nk_label(nk, "Taskbar Progress", NK_TEXT_CENTERED); + nk_label(nk, "Window Progress indicator", NK_TEXT_CENTERED); nk_layout_row_dynamic(nk, 30, 5); - static int state = GLFW_TASKBAR_PROGRESS_DISABLED; + static int state = GLFW_PROGRESS_INDICATOR_DISABLED; static float progress = 0; if(nk_button_label(nk, "No progress")) - glfwSetWindowTaskbarProgress(window, state = GLFW_TASKBAR_PROGRESS_DISABLED, (double) progress); + glfwSetWindowProgressIndicator(window, state = GLFW_PROGRESS_INDICATOR_DISABLED, (double) progress); if (nk_button_label(nk, "Indeterminate")) - glfwSetWindowTaskbarProgress(window, state = GLFW_TASKBAR_PROGRESS_INDETERMINATE, (double) progress); + glfwSetWindowProgressIndicator(window, state = GLFW_PROGRESS_INDICATOR_INDETERMINATE, (double) progress); if (nk_button_label(nk, "Normal")) - glfwSetWindowTaskbarProgress(window, state = GLFW_TASKBAR_PROGRESS_NORMAL, (double) progress); + glfwSetWindowProgressIndicator(window, state = GLFW_PROGRESS_INDICATOR_NORMAL, (double) progress); if (nk_button_label(nk, "Error")) - glfwSetWindowTaskbarProgress(window, state = GLFW_TASKBAR_PROGRESS_ERROR, (double) progress); + glfwSetWindowProgressIndicator(window, state = GLFW_PROGRESS_INDICATOR_ERROR, (double) progress); if (nk_button_label(nk, "Paused")) - glfwSetWindowTaskbarProgress(window, state = GLFW_TASKBAR_PROGRESS_PAUSED, (double) progress); + glfwSetWindowProgressIndicator(window, state = GLFW_PROGRESS_INDICATOR_PAUSED, (double) progress); nk_label(nk, "Progress: ", NK_TEXT_ALIGN_LEFT); if (nk_slider_float(nk, 0.0f, &progress, 1.0f, 0.05f)) - glfwSetWindowTaskbarProgress(window, state, (double) progress); + glfwSetWindowProgressIndicator(window, state, (double) progress); } nk_end(nk); From 589e6b78d9d7c5ef55f46b68d8953f4857025870 Mon Sep 17 00:00:00 2001 From: GamesTrap Date: Wed, 8 Mar 2023 14:47:40 +0100 Subject: [PATCH 2/2] Added DBus pointer checks --- src/posix_dbus.c | 131 ++++++++++++++++++++++++++--------------------- src/wl_window.c | 8 +++ src/x11_window.c | 8 +++ 3 files changed, 88 insertions(+), 59 deletions(-) diff --git a/src/posix_dbus.c b/src/posix_dbus.c index 648cac23..12ca1d8a 100644 --- a/src/posix_dbus.c +++ b/src/posix_dbus.c @@ -41,77 +41,90 @@ void _glfwInitDBusPOSIX(void) _glfw.dbus.connection = NULL; _glfw.dbus.handle = _glfwPlatformLoadModule("libdbus-1.so.3"); - if (_glfw.dbus.handle) - { - _glfw.dbus.error_init = (PFN_dbus_error_init) - _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_error_init"); - _glfw.dbus.error_is_set = (PFN_dbus_error_is_set) - _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_error_is_set"); - _glfw.dbus.error_free = (PFN_dbus_error_free) - _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_error_free"); - _glfw.dbus.connection_unref = (PFN_dbus_connection_unref) - _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_connection_unref"); - _glfw.dbus.connection_send = (PFN_dbus_connection_send) - _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_connection_send"); - _glfw.dbus.connection_flush = (PFN_dbus_connection_flush) - _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_connection_flush"); - _glfw.dbus.bus_request_name = (PFN_dbus_bus_request_name) - _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_bus_request_name"); - _glfw.dbus.bus_get = (PFN_dbus_bus_get) - _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_bus_get"); - _glfw.dbus.message_unref = (PFN_dbus_message_unref) - _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_unref"); - _glfw.dbus.message_new_signal = (PFN_dbus_message_new_signal) - _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_new_signal"); - _glfw.dbus.message_iter_init_append = (PFN_dbus_message_iter_init_append) - _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_init_append"); - _glfw.dbus.message_iter_append_basic = (PFN_dbus_message_iter_append_basic) - _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_append_basic"); - _glfw.dbus.message_iter_open_container = (PFN_dbus_message_iter_open_container) - _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_open_container"); - _glfw.dbus.message_iter_close_container = (PFN_dbus_message_iter_close_container) - _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_close_container"); + if (!_glfw.dbus.handle) + return; - //Initialize DBus connection - dbus_error_init(&_glfw.dbus.error); - _glfw.dbus.connection = dbus_bus_get(DBUS_BUS_SESSION, &_glfw.dbus.error); + _glfw.dbus.error_init = (PFN_dbus_error_init) + _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_error_init"); + _glfw.dbus.error_is_set = (PFN_dbus_error_is_set) + _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_error_is_set"); + _glfw.dbus.error_free = (PFN_dbus_error_free) + _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_error_free"); + _glfw.dbus.connection_unref = (PFN_dbus_connection_unref) + _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_connection_unref"); + _glfw.dbus.connection_send = (PFN_dbus_connection_send) + _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_connection_send"); + _glfw.dbus.connection_flush = (PFN_dbus_connection_flush) + _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_connection_flush"); + _glfw.dbus.bus_request_name = (PFN_dbus_bus_request_name) + _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_bus_request_name"); + _glfw.dbus.bus_get = (PFN_dbus_bus_get) + _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_bus_get"); + _glfw.dbus.message_unref = (PFN_dbus_message_unref) + _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_unref"); + _glfw.dbus.message_new_signal = (PFN_dbus_message_new_signal) + _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_new_signal"); + _glfw.dbus.message_iter_init_append = (PFN_dbus_message_iter_init_append) + _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_init_append"); + _glfw.dbus.message_iter_append_basic = (PFN_dbus_message_iter_append_basic) + _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_append_basic"); + _glfw.dbus.message_iter_open_container = (PFN_dbus_message_iter_open_container) + _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_open_container"); + _glfw.dbus.message_iter_close_container = (PFN_dbus_message_iter_close_container) + _glfwPlatformGetModuleSymbol(_glfw.dbus.handle, "dbus_message_iter_close_container"); + + if (!_glfw.dbus.error_init || + !_glfw.dbus.error_is_set || + !_glfw.dbus.error_free || + !_glfw.dbus.connection_unref || + !_glfw.dbus.connection_send || + !_glfw.dbus.connection_flush || + !_glfw.dbus.bus_request_name || + !_glfw.dbus.bus_get || + !_glfw.dbus.message_unref || + !_glfw.dbus.message_new_signal || + !_glfw.dbus.message_iter_init_append || + !_glfw.dbus.message_iter_append_basic || + !_glfw.dbus.message_iter_open_container || + !_glfw.dbus.message_iter_close_container) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "POSIX: Failed to load DBus entry points"); + return; + } + + //Initialize DBus connection + dbus_error_init(&_glfw.dbus.error); + _glfw.dbus.connection = dbus_bus_get(DBUS_BUS_SESSION, &_glfw.dbus.error); + + //Check for errors + if(dbus_error_is_set(&_glfw.dbus.error) || !_glfw.dbus.connection) + { + if(dbus_error_is_set(&_glfw.dbus.error)) + dbus_error_free(&_glfw.dbus.error); + + _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to connect to DBus"); + + dbus_connection_unref(_glfw.dbus.connection); + _glfw.dbus.connection = NULL; + } + else + { + //Request name + const int res = dbus_bus_request_name(_glfw.dbus.connection, "org.glfw", DBUS_NAME_FLAG_REPLACE_EXISTING, &_glfw.dbus.error); //Check for errors - if(dbus_error_is_set(&_glfw.dbus.error) || !_glfw.dbus.connection) + if(dbus_error_is_set(&_glfw.dbus.error) || res != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { if(dbus_error_is_set(&_glfw.dbus.error)) dbus_error_free(&_glfw.dbus.error); - _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to connect to DBus"); - - dbus_connection_unref(_glfw.dbus.connection); - _glfw.dbus.connection = NULL; - } - else - { - //Request name - const int res = dbus_bus_request_name(_glfw.dbus.connection, "org.glfw", DBUS_NAME_FLAG_REPLACE_EXISTING, &_glfw.dbus.error); - - //Check for errors - if(dbus_error_is_set(&_glfw.dbus.error) || res != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) - { - if(dbus_error_is_set(&_glfw.dbus.error)) - dbus_error_free(&_glfw.dbus.error); - - _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to request DBus name"); + _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to request DBus name"); dbus_connection_unref(_glfw.dbus.connection); _glfw.dbus.connection = NULL; - } } } - - if(_glfw.dbus.connection) - { - //Window NULL is safe here because it won't get - //used inside the SetWindowTaskbarProgress function - _glfw.platform.setWindowProgressIndicator(NULL, GLFW_PROGRESS_INDICATOR_DISABLED, 0); - } } void _glfwTerminateDBusPOSIX(void) diff --git a/src/wl_window.c b/src/wl_window.c index 0a144c85..e2b173c0 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1843,6 +1843,14 @@ GLFWbool _glfwCreateWindowWayland(_GLFWwindow* window, return GLFW_FALSE; } + //Reset progress state as it gets saved between application runs + if(_glfw.dbus.connection) + { + //Window NULL is safe here because it won't get + //used inside the SetWindowTaskbarProgress function + _glfwSetWindowProgressIndicatorWayland(NULL, GLFW_PROGRESS_INDICATOR_DISABLED, 0.0); + } + return GLFW_TRUE; } diff --git a/src/x11_window.c b/src/x11_window.c index 84b03cce..08524c06 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -2040,6 +2040,14 @@ GLFWbool _glfwCreateWindowX11(_GLFWwindow* window, } } + //Reset progress state as it gets saved between application runs + if(_glfw.dbus.connection) + { + //Window NULL is safe here because it won't get + //used inside the SetWindowTaskbarProgress function + _glfwSetWindowProgressIndicatorX11(NULL, GLFW_PROGRESS_INDICATOR_DISABLED, 0.0); + } + XFlush(_glfw.x11.display); return GLFW_TRUE; }