This commit is contained in:
jgcodes2020 2024-01-28 11:30:10 -08:00 committed by GitHub
commit 952789e2c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 257 additions and 20 deletions

4
.gitignore vendored
View File

@ -102,3 +102,7 @@ tests/triangle-vulkan
tests/window
tests/windows
# IDE caches
.cache/
.idea/
.vscode/

View File

@ -525,6 +525,7 @@ GLFWbool _glfwConnectCocoa(int platformID, _GLFWplatform* platform)
_glfwGetGammaRampCocoa,
_glfwSetGammaRampCocoa,
_glfwCreateWindowCocoa,
_glfwAttachWindowCocoa,
_glfwDestroyWindowCocoa,
_glfwSetWindowTitleCocoa,
_glfwSetWindowIconCocoa,
@ -694,4 +695,3 @@ void _glfwTerminateCocoa(void)
}
#endif // _GLFW_COCOA

View File

@ -215,6 +215,7 @@ int _glfwInitCocoa(void);
void _glfwTerminateCocoa(void);
GLFWbool _glfwCreateWindowCocoa(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
GLFWbool _glfwAttachWindowCocoa(_GLFWwindow* window, intptr_t native, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
void _glfwDestroyWindowCocoa(_GLFWwindow* window);
void _glfwSetWindowTitleCocoa(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconCocoa(_GLFWwindow* window, int count, const GLFWimage* images);
@ -299,4 +300,3 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig);
void _glfwDestroyContextNSGL(_GLFWwindow* window);

View File

@ -988,6 +988,15 @@ GLFWbool _glfwCreateWindowCocoa(_GLFWwindow* window,
} // autoreleasepool
}
GLFWbool _glfwAttachWindowCocoa(_GLFWwindow* window,
intptr_t native,
const _GLFWwndconfig* wndconfig,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig) {
_glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa window attachment is not implemented");
return GLFW_FALSE;
}
void _glfwDestroyWindowCocoa(_GLFWwindow* window)
{
@autoreleasepool {
@ -2055,4 +2064,3 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle)
}
#endif // _GLFW_COCOA

View File

@ -532,6 +532,7 @@ struct _GLFWwindow
GLFWbool focusOnShow;
GLFWbool mousePassthrough;
GLFWbool shouldClose;
GLFWbool external;
void* userPointer;
GLFWbool doublebuffer;
GLFWvidmode videoMode;
@ -706,6 +707,7 @@ struct _GLFWplatform
void (*setGammaRamp)(_GLFWmonitor*,const GLFWgammaramp*);
// window
GLFWbool (*createWindow)(_GLFWwindow*,const _GLFWwndconfig*,const _GLFWctxconfig*,const _GLFWfbconfig*);
GLFWbool (*attachWindow)(_GLFWwindow*, intptr_t, const _GLFWwndconfig*,const _GLFWctxconfig*,const _GLFWfbconfig*);
void (*destroyWindow)(_GLFWwindow*);
void (*setWindowTitle)(_GLFWwindow*,const char*);
void (*setWindowIcon)(_GLFWwindow*,int,const GLFWimage*);

View File

@ -69,6 +69,7 @@ GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform)
_glfwGetGammaRampNull,
_glfwSetGammaRampNull,
_glfwCreateWindowNull,
_glfwAttachWindowNull,
_glfwDestroyWindowNull,
_glfwSetWindowTitleNull,
_glfwSetWindowIconNull,
@ -261,4 +262,3 @@ void _glfwTerminateNull(void)
_glfwTerminateOSMesa();
_glfwTerminateEGL();
}

View File

@ -210,6 +210,7 @@ GLFWbool _glfwGetGammaRampNull(_GLFWmonitor* monitor, GLFWgammaramp* ramp);
void _glfwSetGammaRampNull(_GLFWmonitor* monitor, const GLFWgammaramp* ramp);
GLFWbool _glfwCreateWindowNull(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
GLFWbool _glfwAttachWindowNull(_GLFWwindow* window, intptr_t native, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
void _glfwDestroyWindowNull(_GLFWwindow* window);
void _glfwSetWindowTitleNull(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconNull(_GLFWwindow* window, int count, const GLFWimage* images);
@ -269,4 +270,3 @@ GLFWbool _glfwGetPhysicalDevicePresentationSupportNull(VkInstance instance, VkPh
VkResult _glfwCreateWindowSurfaceNull(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
void _glfwPollMonitorsNull(void);

View File

@ -104,6 +104,39 @@ static int createNativeWindow(_GLFWwindow* window,
return GLFW_TRUE;
}
static int attachNativeWindow(_GLFWwindow* window,
intptr_t native,
const _GLFWwndconfig* wndconfig,
const _GLFWfbconfig* fbconfig)
{
if (window->monitor)
fitToMonitor(window);
else
{
if (wndconfig->xpos == GLFW_ANY_POSITION && wndconfig->ypos == GLFW_ANY_POSITION)
{
window->null.xpos = 17;
window->null.ypos = 17;
}
else
{
window->null.xpos = wndconfig->xpos;
window->null.ypos = wndconfig->ypos;
}
window->null.width = wndconfig->width;
window->null.height = wndconfig->height;
}
window->null.visible = wndconfig->visible;
window->null.decorated = wndconfig->decorated;
window->null.maximized = wndconfig->maximized;
window->null.floating = wndconfig->floating;
window->null.transparent = fbconfig->transparent;
window->null.opacity = 1.f;
return GLFW_TRUE;
}
//////////////////////////////////////////////////////////////////////////
@ -164,6 +197,61 @@ GLFWbool _glfwCreateWindowNull(_GLFWwindow* window,
return GLFW_TRUE;
}
GLFWbool _glfwAttachWindowNull(_GLFWwindow* window,
intptr_t native,
const _GLFWwndconfig* wndconfig,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig)
{
if (!attachNativeWindow(window, native, wndconfig, fbconfig))
return GLFW_FALSE;
if (ctxconfig->client != GLFW_NO_API)
{
if (ctxconfig->source == GLFW_NATIVE_CONTEXT_API ||
ctxconfig->source == GLFW_OSMESA_CONTEXT_API)
{
if (!_glfwInitOSMesa())
return GLFW_FALSE;
if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig))
return GLFW_FALSE;
}
else if (ctxconfig->source == GLFW_EGL_CONTEXT_API)
{
if (!_glfwInitEGL())
return GLFW_FALSE;
if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig))
return GLFW_FALSE;
}
if (!_glfwRefreshContextAttribs(window, ctxconfig))
return GLFW_FALSE;
}
if (wndconfig->mousePassthrough)
_glfwSetWindowMousePassthroughNull(window, GLFW_TRUE);
if (window->monitor)
{
_glfwShowWindowNull(window);
_glfwFocusWindowNull(window);
acquireMonitor(window);
if (wndconfig->centerCursor)
_glfwCenterCursorInContentArea(window);
}
else
{
if (wndconfig->visible)
{
_glfwShowWindowNull(window);
if (wndconfig->focused)
_glfwFocusWindowNull(window);
}
}
return GLFW_TRUE;
}
void _glfwDestroyWindowNull(_GLFWwindow* window)
{
@ -715,4 +803,3 @@ VkResult _glfwCreateWindowSurfaceNull(VkInstance instance,
// This seems like the most appropriate error to return here
return VK_ERROR_EXTENSION_NOT_PRESENT;
}

View File

@ -672,6 +672,7 @@ GLFWbool _glfwConnectWin32(int platformID, _GLFWplatform* platform)
_glfwGetGammaRampWin32,
_glfwSetGammaRampWin32,
_glfwCreateWindowWin32,
_glfwAttachWindowWin32,
_glfwDestroyWindowWin32,
_glfwSetWindowTitleWin32,
_glfwSetWindowIconWin32,
@ -777,4 +778,3 @@ void _glfwTerminateWin32(void)
}
#endif // _GLFW_WIN32

View File

@ -544,6 +544,7 @@ void _glfwRestoreVideoModeWin32(_GLFWmonitor* monitor);
void _glfwGetHMONITORContentScaleWin32(HMONITOR handle, float* xscale, float* yscale);
GLFWbool _glfwCreateWindowWin32(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
GLFWbool _glfwAttachWindowWin32(_GLFWwindow* window, intptr_t native, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
void _glfwDestroyWindowWin32(_GLFWwindow* window);
void _glfwSetWindowTitleWin32(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconWin32(_GLFWwindow* window, int count, const GLFWimage* images);
@ -625,4 +626,3 @@ void _glfwTerminateWGL(void);
GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig);

View File

@ -1524,6 +1524,11 @@ GLFWbool _glfwCreateWindowWin32(_GLFWwindow* window,
return GLFW_TRUE;
}
GLFWbool _glfwAttachWindowWin32(_GLFWwindow* window, intptr_t native, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig) {
_glfwInputError(GLFW_PLATFORM_ERROR, "Win32 window attachment is not implemented");
return GLFW_FALSE;
}
void _glfwDestroyWindowWin32(_GLFWwindow* window)
{
if (window->monitor)
@ -2542,4 +2547,3 @@ GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle)
}
#endif // _GLFW_WIN32

View File

@ -252,8 +252,55 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
return (GLFWwindow*) window;
}
void glfwDefaultWindowHints(void)
{
GLFWAPI GLFWwindow* glfwAttachWindow(intptr_t nativeWindow, GLFWwindow* share) {
_GLFWfbconfig fbconfig;
_GLFWctxconfig ctxconfig;
_GLFWwndconfig wndconfig;
_GLFWwindow* window;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
fbconfig = _glfw.hints.framebuffer;
ctxconfig = _glfw.hints.context;
wndconfig = _glfw.hints.window;
ctxconfig.share = (_GLFWwindow*) share;
if (ctxconfig.share)
{
if (ctxconfig.client == GLFW_NO_API ||
ctxconfig.share->context.client == GLFW_NO_API)
{
_glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
return NULL;
}
}
if (!_glfwIsValidContextConfig(&ctxconfig))
return NULL;
window = calloc(1, sizeof(_GLFWwindow));
window->next = _glfw.windowListHead;
_glfw.windowListHead = window;
window->autoIconify = wndconfig.autoIconify;
window->cursorMode = GLFW_CURSOR_NORMAL;
window->external = GLFW_TRUE;
window->minwidth = GLFW_DONT_CARE;
window->minheight = GLFW_DONT_CARE;
window->maxwidth = GLFW_DONT_CARE;
window->maxheight = GLFW_DONT_CARE;
window->numer = GLFW_DONT_CARE;
window->denom = GLFW_DONT_CARE;
if (!_glfw.platform.attachWindow(window, nativeWindow, &wndconfig, &ctxconfig, &fbconfig))
return NULL;
return (GLFWwindow*) window;
}
void glfwDefaultWindowHints(void) {
_GLFW_REQUIRE_INIT();
// The default is OpenGL with minimum version 1.0
@ -1150,4 +1197,3 @@ GLFWAPI void glfwPostEmptyEvent(void)
_GLFW_REQUIRE_INIT();
_glfw.platform.postEmptyEvent();
}

View File

@ -443,6 +443,7 @@ GLFWbool _glfwConnectWayland(int platformID, _GLFWplatform* platform)
_glfwGetGammaRampWayland,
_glfwSetGammaRampWayland,
_glfwCreateWindowWayland,
_glfwAttachWindowWayland,
_glfwDestroyWindowWayland,
_glfwSetWindowTitleWayland,
_glfwSetWindowIconWayland,
@ -946,4 +947,3 @@ void _glfwTerminateWayland(void)
}
#endif // _GLFW_WAYLAND

View File

@ -610,6 +610,7 @@ int _glfwInitWayland(void);
void _glfwTerminateWayland(void);
GLFWbool _glfwCreateWindowWayland(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
GLFWbool _glfwAttachWindowWayland(_GLFWwindow* window, intptr_t native, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
void _glfwDestroyWindowWayland(_GLFWwindow* window);
void _glfwSetWindowTitleWayland(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconWayland(_GLFWwindow* window, int count, const GLFWimage* images);

View File

@ -967,6 +967,38 @@ static GLFWbool createNativeSurface(_GLFWwindow* window,
return GLFW_TRUE;
}
static GLFWbool attachNativeSurface(_GLFWwindow* window,
intptr_t native,
const _GLFWwndconfig* wndconfig,
const _GLFWfbconfig* fbconfig) {
if (!native)
{
_glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: supplied wl_surface is null");
return GLFW_FALSE;
}
window->wl.surface = (struct wl_surface*) native;
wl_proxy_set_tag((struct wl_proxy*) window->wl.surface, &_glfw.wl.tag);
wl_surface_add_listener(window->wl.surface,
&surfaceListener,
window);
window->wl.width = wndconfig->width;
window->wl.height = wndconfig->height;
window->wl.contentScale = 1;
window->wl.title = _glfw_strdup(wndconfig->title);
window->wl.appId = _glfw_strdup(wndconfig->wl.appId);
window->wl.maximized = wndconfig->maximized;
window->wl.transparent = fbconfig->transparent;
if (!window->wl.transparent)
setContentAreaOpaque(window);
return GLFW_TRUE;
}
static void setCursorImage(_GLFWwindow* window,
_GLFWcursorWayland* cursorWayland)
{
@ -2046,7 +2078,8 @@ GLFWbool _glfwCreateWindowWayland(_GLFWwindow* window,
if (wndconfig->mousePassthrough)
_glfwSetWindowMousePassthroughWayland(window, GLFW_TRUE);
if (window->monitor || wndconfig->visible)
// don't
if (!window->external && (window->monitor || wndconfig->visible))
{
if (!createShellObjects(window))
return GLFW_FALSE;
@ -2055,6 +2088,52 @@ GLFWbool _glfwCreateWindowWayland(_GLFWwindow* window,
return GLFW_TRUE;
}
GLFWbool _glfwAttachWindowWayland(_GLFWwindow* window,
intptr_t native,
const _GLFWwndconfig* wndconfig,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig) {
if (!attachNativeSurface(window, native, wndconfig, fbconfig))
return GLFW_FALSE;
if (ctxconfig->client != GLFW_NO_API)
{
if (ctxconfig->source == GLFW_EGL_CONTEXT_API ||
ctxconfig->source == GLFW_NATIVE_CONTEXT_API)
{
window->wl.egl.window = wl_egl_window_create(window->wl.surface,
wndconfig->width,
wndconfig->height);
if (!window->wl.egl.window)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Wayland: Failed to create EGL window");
return GLFW_FALSE;
}
if (!_glfwInitEGL())
return GLFW_FALSE;
if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig))
return GLFW_FALSE;
}
else if (ctxconfig->source == GLFW_OSMESA_CONTEXT_API)
{
if (!_glfwInitOSMesa())
return GLFW_FALSE;
if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig))
return GLFW_FALSE;
}
if (!_glfwRefreshContextAttribs(window, ctxconfig))
return GLFW_FALSE;
}
if (wndconfig->mousePassthrough)
_glfwSetWindowMousePassthroughWayland(window, GLFW_TRUE);
return GLFW_TRUE;
}
void _glfwDestroyWindowWayland(_GLFWwindow* window)
{
if (window == _glfw.wl.pointerFocus)
@ -2324,7 +2403,7 @@ void _glfwMaximizeWindowWayland(_GLFWwindow* window)
void _glfwShowWindowWayland(_GLFWwindow* window)
{
if (!window->wl.libdecor.frame && !window->wl.xdg.toplevel)
if (!window->external && (!window->wl.libdecor.frame && !window->wl.xdg.toplevel))
{
// NOTE: The XDG surface and role are created here so command-line applications
// with off-screen windows do not appear in for example the Unity dock
@ -3173,4 +3252,3 @@ GLFWAPI struct wl_surface* glfwGetWaylandWindow(GLFWwindow* handle)
}
#endif // _GLFW_WAYLAND

View File

@ -1204,6 +1204,7 @@ GLFWbool _glfwConnectX11(int platformID, _GLFWplatform* platform)
_glfwGetGammaRampX11,
_glfwSetGammaRampX11,
_glfwCreateWindowX11,
_glfwAttachWindowX11,
_glfwDestroyWindowX11,
_glfwSetWindowTitleX11,
_glfwSetWindowIconX11,
@ -1653,4 +1654,3 @@ void _glfwTerminateX11(void)
}
#endif // _GLFW_X11

View File

@ -615,4 +615,3 @@ GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* handle)
}
#endif // _GLFW_X11

View File

@ -902,6 +902,7 @@ int _glfwInitX11(void);
void _glfwTerminateX11(void);
GLFWbool _glfwCreateWindowX11(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
GLFWbool _glfwAttachWindowX11(_GLFWwindow* window, intptr_t native, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
void _glfwDestroyWindowX11(_GLFWwindow* window);
void _glfwSetWindowTitleX11(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconX11(_GLFWwindow* window, int count, const GLFWimage* images);
@ -1001,4 +1002,3 @@ GLFWbool _glfwChooseVisualGLX(const _GLFWwndconfig* wndconfig,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig,
Visual** visual, int* depth);

View File

@ -2042,6 +2042,15 @@ GLFWbool _glfwCreateWindowX11(_GLFWwindow* window,
return GLFW_TRUE;
}
GLFWbool _glfwAttachWindowX11(_GLFWwindow* window,
intptr_t native,
const _GLFWwndconfig* wndconfig,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig) {
_glfwInputError(GLFW_PLATFORM_ERROR, "X11 window attachment is not implemented");
return GLFW_FALSE;
}
void _glfwDestroyWindowX11(_GLFWwindow* window)
{
if (_glfw.x11.disabledCursorWindow == window)
@ -3350,4 +3359,3 @@ GLFWAPI const char* glfwGetX11SelectionString(void)
}
#endif // _GLFW_X11