diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 819d2cd6..673884ff 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -942,6 +942,17 @@ extern "C" { */ #define GLFW_CONTEXT_CREATION_API 0x0002200B + /*! @brief Window that will share context with new one + * + * Window shared context [window hint] + */ +#define GLFW_SHARE_CONTEXT 0x00000001 + /*! @brief Window that is parent in hierarchy to new one + * + * Parent window [window hint] + */ +#define GLFW_PARENT_WINDOW 0x00000002 + #define GLFW_COCOA_RETINA_FRAMEBUFFER 0x00023001 #define GLFW_COCOA_FRAME_AUTOSAVE 0x00023002 #define GLFW_COCOA_GRAPHICS_SWITCHING 0x00023003 @@ -2187,6 +2198,30 @@ GLFWAPI void glfwDefaultWindowHints(void); */ GLFWAPI void glfwWindowHint(int hint, int value); +/*! @brief Sets the specified window hint to the desired value. +* +* This function sets hints for the next call to @ref glfwCreateWindow. The +* hints, once set, retain their values until changed by a call to @ref +* glfwWindowHint or @ref glfwDefaultWindowHints, or until the library is +* terminated. +* +* @param[in] hint The [window hint](@ref window_hints) to set. +* @param[in] value The new value of the window hint. +* +* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref +* GLFW_INVALID_ENUM. +* +* @thread_safety This function must only be called from the main thread. +* +* @sa @ref window_hints +* @sa @ref glfwDefaultWindowHints +* +* @since Added in version 3.3. +* +* @ingroup window +*/ +GLFWAPI void glfwChildWindowHint( int hint, const GLFWwindow* value ); + /*! @brief Creates a window and its associated context. * * This function creates a window and its associated OpenGL or OpenGL ES @@ -2337,7 +2372,9 @@ GLFWAPI void glfwWindowHint(int hint, int value); * * @ingroup window */ -GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share); + + +GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor ); /*! @brief Destroys the specified window and its context. * diff --git a/src/internal.h b/src/internal.h index b9f55da7..d83bf5ae 100644 --- a/src/internal.h +++ b/src/internal.h @@ -304,6 +304,7 @@ struct _GLFWwndconfig GLFWbool floating; GLFWbool maximized; GLFWbool centerCursor; + const _GLFWwindow* parent; struct { GLFWbool retina; GLFWbool frame; @@ -328,7 +329,7 @@ struct _GLFWctxconfig int profile; int robustness; int release; - _GLFWwindow* share; + const _GLFWwindow* share; struct { GLFWbool offline; } nsgl; diff --git a/src/win32_window.c b/src/win32_window.c index 490a75d2..7de46e28 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1080,7 +1080,7 @@ static int createNativeWindow(_GLFWwindow* window, style, xpos, ypos, fullWidth, fullHeight, - NULL, // No parent window + wndconfig->parent ? wndconfig->parent->win32.handle : NULL, NULL, // No window menu GetModuleHandleW(NULL), NULL); diff --git a/src/window.c b/src/window.c index 57845579..201e9a8a 100644 --- a/src/window.c +++ b/src/window.c @@ -120,8 +120,7 @@ void _glfwInputWindowMonitorChange(_GLFWwindow* window, _GLFWmonitor* monitor) GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, - GLFWmonitor* monitor, - GLFWwindow* share) + GLFWmonitor* monitor ) { _GLFWfbconfig fbconfig; _GLFWctxconfig ctxconfig; @@ -151,7 +150,6 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, wndconfig.width = width; wndconfig.height = height; wndconfig.title = title; - ctxconfig.share = (_GLFWwindow*) share; if (ctxconfig.share) { @@ -243,6 +241,7 @@ void glfwDefaultWindowHints(void) _glfw.hints.context.source = GLFW_NATIVE_CONTEXT_API; _glfw.hints.context.major = 1; _glfw.hints.context.minor = 0; + _glfw.hints.context.share = NULL; // The default is a focused, visible, resizable window with decorations memset(&_glfw.hints.window, 0, sizeof(_glfw.hints.window)); @@ -251,6 +250,7 @@ void glfwDefaultWindowHints(void) _glfw.hints.window.decorated = GLFW_TRUE; _glfw.hints.window.focused = GLFW_TRUE; _glfw.hints.window.autoIconify = GLFW_TRUE; + _glfw.hints.window.parent = NULL; // The default is 24 bits of color, 24 bits of depth and 8 bits of stencil, // double buffered @@ -270,6 +270,24 @@ void glfwDefaultWindowHints(void) _glfw.hints.window.ns.retina = GLFW_TRUE; } +GLFWAPI void glfwChildWindowHint( int hint, const GLFWwindow* value ) +{ + _GLFW_REQUIRE_INIT(); + + switch( hint ) + { + case GLFW_SHARE_CONTEXT: + _glfw.hints.context.share = (const _GLFWwindow*)value; + return; + + case GLFW_PARENT_WINDOW: + _glfw.hints.window.parent = (const _GLFWwindow*)value; + return; + } + + _glfwInputError( GLFW_INVALID_ENUM, "Invalid window hint 0x%08X", hint ); +} + GLFWAPI void glfwWindowHint(int hint, int value) { _GLFW_REQUIRE_INIT();