diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 4bf47ded..56c9c54f 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -1230,6 +1230,9 @@ GLFWAPI void glfwWindowHint(int target, int hint); * windowed mode. * @param[in] share The window whose context to share resources with, or `NULL` * to not share resources. + * @param[in] make this window parent to new one, new window will be always on top another. Pass `NULL` + * to not make new window a child one. + * @return The handle of the created window, or `NULL` if an error occurred. * * @remarks **Windows:** Window creation will fail if the Microsoft GDI @@ -1258,7 +1261,7 @@ GLFWAPI void glfwWindowHint(int target, int hint); * * @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, GLFWwindow* share, GLFWwindow* parent); /*! @brief Destroys the specified window and its context. * diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 81701941..016d12cd 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -844,7 +844,8 @@ static GLboolean initializeAppKit(void) // Create the Cocoa window // static GLboolean createWindow(_GLFWwindow* window, - const _GLFWwndconfig* wndconfig) + const _GLFWwndconfig* wndconfig, + _GLFWwindow* parent) { unsigned int styleMask = 0; @@ -904,7 +905,8 @@ static GLboolean createWindow(_GLFWwindow* window, int _glfwPlatformCreateWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, - const _GLFWfbconfig* fbconfig) + const _GLFWfbconfig* fbconfig, + _GLFWwindow* parent) { if (!initializeAppKit()) return GL_FALSE; @@ -938,7 +940,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (!createWindow(window, wndconfig)) return GL_FALSE; - if (!_glfwCreateContext(window, wndconfig, fbconfig)) + if (!_glfwCreateContext(window, wndconfig, fbconfig, parent)) return GL_FALSE; [window->nsgl.context setView:window->ns.view]; diff --git a/src/internal.h b/src/internal.h index 357277eb..f6cc13b2 100644 --- a/src/internal.h +++ b/src/internal.h @@ -453,7 +453,8 @@ void _glfwPlatformSetTime(double time); */ int _glfwPlatformCreateWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, - const _GLFWfbconfig* fbconfig); + const _GLFWfbconfig* fbconfig, + _GLFWwindow* parent); /*! @ingroup platform */ diff --git a/src/win32_window.c b/src/win32_window.c index 21690d3f..2a1ba6f8 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -789,7 +789,8 @@ static ATOM registerWindowClass(void) // static int createWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, - const _GLFWfbconfig* fbconfig) + const _GLFWfbconfig* fbconfig, + _GLFWwindow* parent ) { int xpos, ypos, fullWidth, fullHeight; WCHAR* wideTitle; @@ -842,7 +843,7 @@ static int createWindow(_GLFWwindow* window, window->win32.dwStyle, xpos, ypos, fullWidth, fullHeight, - NULL, // No parent window + parent ? parent->win32.handle : NULL, // No parent window NULL, // No window menu GetModuleHandle(NULL), window); // Pass object to WM_CREATE @@ -881,7 +882,8 @@ static void destroyWindow(_GLFWwindow* window) int _glfwPlatformCreateWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, - const _GLFWfbconfig* fbconfig) + const _GLFWfbconfig* fbconfig, + _GLFWwindow* parent) { int status; @@ -892,7 +894,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, return GL_FALSE; } - if (!createWindow(window, wndconfig, fbconfig)) + if (!createWindow(window, wndconfig, fbconfig, parent )) return GL_FALSE; status = _glfwAnalyzeContext(window, wndconfig, fbconfig); @@ -927,7 +929,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, destroyWindow(window); // ...and then create them again, this time with better APIs - if (!createWindow(window, wndconfig, fbconfig)) + if (!createWindow(window, wndconfig, fbconfig, parent)) return GL_FALSE; } diff --git a/src/window.c b/src/window.c index de75952b..f82542f7 100644 --- a/src/window.c +++ b/src/window.c @@ -143,12 +143,13 @@ void _glfwInputWindowCloseRequest(_GLFWwindow* window) GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, - GLFWwindow* share) + GLFWwindow* share, + GLFWwindow* parent ) { _GLFWfbconfig fbconfig; _GLFWwndconfig wndconfig; - _GLFWwindow* window; - _GLFWwindow* previous; + _GLFWwindow* window = NULL; + _GLFWwindow* previous = NULL; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); @@ -222,7 +223,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, previous = (_GLFWwindow*) glfwGetCurrentContext(); // Open the actual window and create its context - if (!_glfwPlatformCreateWindow(window, &wndconfig, &fbconfig)) + if (!_glfwPlatformCreateWindow(window, &wndconfig, &fbconfig, (_GLFWwindow*)parent )) { glfwDestroyWindow((GLFWwindow*) window); glfwMakeContextCurrent((GLFWwindow*) previous); diff --git a/src/x11_window.c b/src/x11_window.c index 115ab1df..d3c8d4b1 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -100,7 +100,8 @@ static int translateChar(XKeyEvent* event) // Create the X11 window (and its colormap) // static GLboolean createWindow(_GLFWwindow* window, - const _GLFWwndconfig* wndconfig) + const _GLFWwndconfig* wndconfig, + _GLFWwindow* parent ) { unsigned long wamask; XSetWindowAttributes wa; @@ -139,7 +140,7 @@ static GLboolean createWindow(_GLFWwindow* window, _glfwGrabXErrorHandler(); window->x11.handle = XCreateWindow(_glfw.x11.display, - _glfw.x11.root, + parent ? parent->x11.handle , _glfw.x11.root, 0, 0, wndconfig->width, wndconfig->height, 0, // Border width @@ -936,12 +937,13 @@ unsigned long _glfwGetWindowProperty(Window window, int _glfwPlatformCreateWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, - const _GLFWfbconfig* fbconfig) + const _GLFWfbconfig* fbconfig, + _GLFWwindow* parent ) { if (!_glfwCreateContext(window, wndconfig, fbconfig)) return GL_FALSE; - if (!createWindow(window, wndconfig)) + if (!createWindow(window, wndconfig, parent)) return GL_FALSE; if (wndconfig->monitor)