diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 5e6fad42..bd8994ee 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -3241,6 +3241,26 @@ GLFWAPI int glfwWindowShouldClose(GLFWwindow* window); */ GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* window, int value); +/*! @brief Retrieves the title of the specified window. + * + * This function gets the window title, encoded as UTF-8, of the specified + * window. + * + * @param[in] window The window to query. + * @return A copy of the UTF-8 encoded window title, as set by glfwCreateWindow + * or glfwSetWindowTitle, or NULL if there is an error. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_title + * @sa @ref glfwSetWindowTitle + * + * @ingroup window + */ +GLFWAPI const char* glfwGetWindowTitle(GLFWwindow* window); + /*! @brief Sets the title of the specified window. * * This function sets the window title, encoded as UTF-8, of the specified diff --git a/src/internal.h b/src/internal.h index 1ab3dea8..b170cae9 100644 --- a/src/internal.h +++ b/src/internal.h @@ -531,6 +531,7 @@ struct _GLFWwindow GLFWvidmode videoMode; _GLFWmonitor* monitor; _GLFWcursor* cursor; + char* title; int minwidth, minheight; int maxwidth, maxheight; diff --git a/src/window.c b/src/window.c index 51903e63..4a6b88d6 100644 --- a/src/window.c +++ b/src/window.c @@ -173,6 +173,15 @@ void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor) window->monitor = monitor; } +// Notifies shared code that a window has new title +// +void _glfwInputWindowTitle(_GLFWwindow* window, const char* title) +{ + size_t size = strlen( title ) + 1; + window->title = _glfw_realloc(window->title, size); + memcpy( window->title, title, size ); +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW public API ////// ////////////////////////////////////////////////////////////////////////// @@ -242,6 +251,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, window->maxheight = GLFW_DONT_CARE; window->numer = GLFW_DONT_CARE; window->denom = GLFW_DONT_CARE; + _glfwInputWindowTitle(window, title); if (!_glfw.platform.createWindow(window, &wndconfig, &ctxconfig, &fbconfig)) { @@ -491,7 +501,7 @@ GLFWAPI void glfwDestroyWindow(GLFWwindow* handle) *prev = window->next; } - + _glfw_free(window->title); _glfw_free(window); } @@ -513,6 +523,16 @@ GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* handle, int value) window->shouldClose = value; } +GLFWAPI const char* glfwGetWindowTitle(GLFWwindow* handle) +{ + _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window != NULL); + + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + + return window->title; +} + GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title) { _GLFWwindow* window = (_GLFWwindow*) handle; @@ -520,6 +540,8 @@ GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title) assert(title != NULL); _GLFW_REQUIRE_INIT(); + + _glfwInputWindowTitle(window, title); _glfw.platform.setWindowTitle(window, title); }