From 5263f6598c2e2d596969dcac590dda7fc9758d41 Mon Sep 17 00:00:00 2001 From: Luflosi Date: Wed, 3 Jun 2020 20:04:54 +0200 Subject: [PATCH] Add feature available/implemented errors From upstream: https://github.com/glfw/glfw/commit/9a87c2a4b49808d3666c7b093b77e8512fa23908. --- glfw/cocoa_window.m | 5 ++- glfw/glfw3.h | 73 +++++++++++++++++++++++++++++++------------- glfw/init.c | 4 +++ glfw/wl_monitor.c | 4 +-- glfw/wl_window.c | 26 +++++++++------- kitty/glfw-wrapper.h | 27 ++++++++++++++++ 6 files changed, 104 insertions(+), 35 deletions(-) diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index 178ace68f..f32663600 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -1527,7 +1527,8 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window UNUSED, const char* title) void _glfwPlatformSetWindowIcon(_GLFWwindow* window UNUSED, int count UNUSED, const GLFWimage* images UNUSED) { - // Regular windows do not have icons + _glfwInputError(GLFW_FEATURE_UNAVAILABLE, + "Cocoa: Regular windows do not have icons on macOS"); } void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos) @@ -1865,6 +1866,8 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity) void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window UNUSED, bool enabled UNUSED) { + _glfwInputError(GLFW_FEATURE_UNIMPLEMENTED, + "Cocoa: Raw mouse motion not yet implemented"); } bool _glfwPlatformRawMouseMotionSupported(void) diff --git a/glfw/glfw3.h b/glfw/glfw3.h index 642109218..ae1a79bc5 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -821,6 +821,33 @@ extern "C" { * @analysis Application programmer error. Fix the offending call. */ #define GLFW_NO_WINDOW_CONTEXT 0x0001000A +/*! @brief The reuqested feature is not provided by the platform. + * + * The requested feature is not provided by the platform, so GLFW is unable to + * implement it. The documentation for each function notes if it could emit + * this error. + * + * @analysis Platform or platform version limitation. The error can be ignored + * unless the feature is critical to the application. + * + * @par + * A function call that emits this error has no effect other than the error and + * updating any existing out parameters. + */ +#define GLFW_FEATURE_UNAVAILABLE 0x0001000C +/*! @brief The requested feature is not implemented for the platform. + * + * The requested feature has not yet been implemented in GLFW for this platform. + * + * @analysis An incomplete implementation of GLFW for this platform, hopefully + * fixed in a future release. The error can be ignored unless the feature is + * critical to the application. + * + * @par + * A function call that emits this error has no effect other than the error and + * updating any existing out parameters. + */ +#define GLFW_FEATURE_UNIMPLEMENTED 0x0001000D /*! @} */ /*! @addtogroup window @@ -2867,21 +2894,21 @@ GLFWAPI void glfwSetWindowTitle(GLFWwindow* window, const char* title); * @param[in] images The images to create the icon from. This is ignored if * count is zero. * - * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref - * GLFW_PLATFORM_ERROR. + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks). * * @pointer_lifetime The specified image data is copied before this function * returns. * - * @remark @macos The GLFW window has no icon, as it is not a document - * window, so this function does nothing. The dock icon will be the same as + * @remark @macos Regular windows do not have icons on macOS. This function + * will emit @ref GLFW_FEATURE_UNAVAILABLE. The dock icon will be the same as * the application bundle's icon. For more information on bundles, see the * [Bundle Programming Guide](https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/) * in the Mac Developer Library. * * @remark @wayland There is no existing protocol to change an icon, the * window will thus inherit the one defined in the application's desktop file. - * This function always emits @ref GLFW_PLATFORM_ERROR. + * This function will emit @ref GLFW_FEATURE_UNAVAILABLE. * * @thread_safety This function must only be called from the main thread. * @@ -2907,12 +2934,12 @@ GLFWAPI void glfwSetWindowIcon(GLFWwindow* window, int count, const GLFWimage* i * @param[out] ypos Where to store the y-coordinate of the upper-left corner of * the content area, or `NULL`. * - * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref - * GLFW_PLATFORM_ERROR. + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks). * * @remark @wayland There is no way for an application to retrieve the global - * position of its windows, this function will always emit @ref - * GLFW_PLATFORM_ERROR. + * position of its windows. This function will emit @ref + * GLFW_FEATURE_UNAVAILABLE. * * @thread_safety This function must only be called from the main thread. * @@ -2941,12 +2968,12 @@ GLFWAPI void glfwGetWindowPos(GLFWwindow* window, int* xpos, int* ypos); * @param[in] xpos The x-coordinate of the upper-left corner of the content area. * @param[in] ypos The y-coordinate of the upper-left corner of the content area. * - * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref - * GLFW_PLATFORM_ERROR. + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks). * * @remark @wayland There is no way for an application to set the global - * position of its windows, this function will always emit @ref - * GLFW_PLATFORM_ERROR. + * position of its windows. This function will emit @ref + * GLFW_FEATURE_UNAVAILABLE. * * @thread_safety This function must only be called from the main thread. * @@ -3324,8 +3351,11 @@ GLFWAPI float glfwGetWindowOpacity(GLFWwindow* window); * @param[in] window The window to set the opacity for. * @param[in] opacity The desired opacity of the specified window. * - * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref - * GLFW_PLATFORM_ERROR. + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks). + * + * @remark @wayland There is no way to set an opacity factor for a window. + * This function will emit @ref GLFW_FEATURE_UNAVAILABLE. * * @thread_safety This function must only be called from the main thread. * @@ -3492,11 +3522,11 @@ GLFWAPI void glfwHideWindow(GLFWwindow* window); * * @param[in] window The window to give input focus. * - * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref - * GLFW_PLATFORM_ERROR. + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks). * - * @remark @wayland It is not possible for an application to bring its windows - * to front, this function will always emit @ref GLFW_PLATFORM_ERROR. + * @remark @wayland It is not possible for an application to set the input + * focus. This function will emit @ref GLFW_FEATURE_UNAVAILABLE. * * @thread_safety This function must only be called from the main thread. * @@ -4172,7 +4202,7 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode); * If the mode is `GLFW_RAW_MOUSE_MOTION`, the value must be either `GLFW_TRUE` * to enable raw (unscaled and unaccelerated) mouse motion when the cursor is * disabled, or `false` to disable it. If raw motion is not supported, - * attempting to set this will emit @ref GLFW_PLATFORM_ERROR. Call @ref + * attempting to set this will emit @ref GLFW_FEATURE_UNAVAILABLE. Call @ref * glfwRawMouseMotionSupported to check for support. * * @param[in] window The window whose input mode to set. @@ -4182,7 +4212,8 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode); * @param[in] value The new value of the specified input mode. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref - * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. + * GLFW_INVALID_ENUM, @ref GLFW_PLATFORM_ERROR and @ref + * GLFW_FEATURE_UNAVAILABLE (see above). * * @thread_safety This function must only be called from the main thread. * diff --git a/glfw/init.c b/glfw/init.c index dc15fcc96..b218de346 100644 --- a/glfw/init.c +++ b/glfw/init.c @@ -168,6 +168,10 @@ void _glfwInputError(int code, const char* format, ...) strcpy(description, "The requested format is unavailable"); else if (code == GLFW_NO_WINDOW_CONTEXT) strcpy(description, "The specified window has no context"); + else if (code == GLFW_FEATURE_UNAVAILABLE) + strcpy(description, "The requested feature cannot be implemented for this platform"); + else if (code == GLFW_FEATURE_UNIMPLEMENTED) + strcpy(description, "The requested feature has not yet been implemented for this platform"); else strcpy(description, "ERROR: UNKNOWN GLFW ERROR"); } diff --git a/glfw/wl_monitor.c b/glfw/wl_monitor.c index 99396f32b..5b3a7f149 100644 --- a/glfw/wl_monitor.c +++ b/glfw/wl_monitor.c @@ -202,7 +202,7 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) bool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor UNUSED, GLFWgammaramp* ramp UNUSED) { - _glfwInputError(GLFW_PLATFORM_ERROR, + _glfwInputError(GLFW_FEATURE_UNAVAILABLE, "Wayland: Gamma ramp access is not available"); return false; } @@ -210,7 +210,7 @@ bool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor UNUSED, GLFWgammaramp* ramp void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor UNUSED, const GLFWgammaramp* ramp UNUSED) { - _glfwInputError(GLFW_PLATFORM_ERROR, + _glfwInputError(GLFW_FEATURE_UNAVAILABLE, "Wayland: Gamma ramp access is not available"); } diff --git a/glfw/wl_window.c b/glfw/wl_window.c index 001b4c7c3..a05edde6e 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -995,8 +995,8 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) void _glfwPlatformSetWindowIcon(_GLFWwindow* window UNUSED, int count UNUSED, const GLFWimage* images UNUSED) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Wayland: Setting window icon not supported"); + _glfwInputError(GLFW_FEATURE_UNAVAILABLE, + "Wayland: The platform does not support setting the window icon"); } void _glfwPlatformGetWindowPos(_GLFWwindow* window UNUSED, int* xpos UNUSED, int* ypos UNUSED) @@ -1004,16 +1004,16 @@ void _glfwPlatformGetWindowPos(_GLFWwindow* window UNUSED, int* xpos UNUSED, int // A Wayland client is not aware of its position, so just warn and leave it // as (0, 0) - _glfwInputError(GLFW_PLATFORM_ERROR, - "Wayland: Window position retrieval not supported"); + _glfwInputError(GLFW_FEATURE_UNAVAILABLE, + "Wayland: The platform does not provide the window position"); } void _glfwPlatformSetWindowPos(_GLFWwindow* window UNUSED, int xpos UNUSED, int ypos UNUSED) { // A Wayland client can not set its position, so just warn - _glfwInputError(GLFW_PLATFORM_ERROR, - "Wayland: Window position setting not supported"); + _glfwInputError(GLFW_FEATURE_UNAVAILABLE, + "Wayland: The platform does not support setting the window position"); } void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height) @@ -1054,6 +1054,8 @@ void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window UNUSED, { // TODO: find out how to trigger a resize. // The actual limits are checked in the xdg_toplevel::configure handler. + _glfwInputError(GLFW_FEATURE_UNIMPLEMENTED, + "Wayland: Window aspect ratio not yet implemented"); } void _glfwPlatformSetWindowSizeIncrements(_GLFWwindow* window UNUSED, @@ -1158,7 +1160,7 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window UNUSED) // TODO static bool notified = false; if (!notified) { - _glfwInputError(GLFW_PLATFORM_ERROR, + _glfwInputError(GLFW_FEATURE_UNIMPLEMENTED, "Wayland: Window attention request not implemented yet"); notified = true; } @@ -1179,8 +1181,8 @@ int _glfwPlatformWindowBell(_GLFWwindow* window UNUSED) void _glfwPlatformFocusWindow(_GLFWwindow* window UNUSED) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Wayland: Focusing a window requires user interaction"); + _glfwInputError(GLFW_FEATURE_UNAVAILABLE, + "Wayland: The platform does not support setting the input focus"); } void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, @@ -1233,7 +1235,7 @@ int _glfwPlatformFramebufferTransparent(_GLFWwindow* window) void _glfwPlatformSetWindowResizable(_GLFWwindow* window UNUSED, bool enabled UNUSED) { // TODO - _glfwInputError(GLFW_PLATFORM_ERROR, + _glfwInputError(GLFW_FEATURE_UNIMPLEMENTED, "Wayland: Window attribute setting not implemented yet"); } @@ -1251,7 +1253,7 @@ void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, bool enabled) void _glfwPlatformSetWindowFloating(_GLFWwindow* window UNUSED, bool enabled UNUSED) { // TODO - _glfwInputError(GLFW_PLATFORM_ERROR, + _glfwInputError(GLFW_FEATURE_UNIMPLEMENTED, "Wayland: Window attribute setting not implemented yet"); } @@ -1262,6 +1264,8 @@ float _glfwPlatformGetWindowOpacity(_GLFWwindow* window UNUSED) void _glfwPlatformSetWindowOpacity(_GLFWwindow* window UNUSED, float opacity UNUSED) { + _glfwInputError(GLFW_FEATURE_UNAVAILABLE, + "Wayland: The platform does not support setting the window opacity"); } void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window UNUSED, bool enabled UNUSED) diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index e1a93c78d..1e1cdc0d0 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -569,6 +569,33 @@ * @analysis Application programmer error. Fix the offending call. */ #define GLFW_NO_WINDOW_CONTEXT 0x0001000A +/*! @brief The reuqested feature is not provided by the platform. + * + * The requested feature is not provided by the platform, so GLFW is unable to + * implement it. The documentation for each function notes if it could emit + * this error. + * + * @analysis Platform or platform version limitation. The error can be ignored + * unless the feature is critical to the application. + * + * @par + * A function call that emits this error has no effect other than the error and + * updating any existing out parameters. + */ +#define GLFW_FEATURE_UNAVAILABLE 0x0001000C +/*! @brief The requested feature is not implemented for the platform. + * + * The requested feature has not yet been implemented in GLFW for this platform. + * + * @analysis An incomplete implementation of GLFW for this platform, hopefully + * fixed in a future release. The error can be ignored unless the feature is + * critical to the application. + * + * @par + * A function call that emits this error has no effect other than the error and + * updating any existing out parameters. + */ +#define GLFW_FEATURE_UNIMPLEMENTED 0x0001000D /*! @} */ /*! @addtogroup window