more infrastructure for wayland

This commit is contained in:
jgcodes2020 2023-10-24 11:56:27 -04:00
parent 4be2543f1e
commit edef7ff345
6 changed files with 90 additions and 9 deletions

4
.gitignore vendored
View File

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

View File

@ -707,7 +707,7 @@ struct _GLFWplatform
void (*setGammaRamp)(_GLFWmonitor*,const GLFWgammaramp*);
// window
GLFWbool (*createWindow)(_GLFWwindow*,const _GLFWwndconfig*,const _GLFWctxconfig*,const _GLFWfbconfig*);
GLFWbool (*attachWindow)(_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

@ -295,11 +295,12 @@ GLFWAPI GLFWwindow* glfwAttachWindow(intptr_t nativeWindow, GLFWwindow* share) {
window->numer = GLFW_DONT_CARE;
window->denom = GLFW_DONT_CARE;
// if (!_glfw.platform.attachWindow())
if (!_glfw.platform.attachWindow(window, nativeWindow, &wndconfig, &ctxconfig, &fbconfig))
return NULL;
}
void glfwDefaultWindowHints(void)
{
void glfwDefaultWindowHints(void) {
_GLFW_REQUIRE_INIT();
// The default is OpenGL with minimum version 1.0
@ -1196,4 +1197,3 @@ GLFWAPI void glfwPostEmptyEvent(void)
_GLFW_REQUIRE_INIT();
_glfw.platform.postEmptyEvent();
}

View File

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

View File

@ -608,6 +608,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

@ -966,6 +966,36 @@ 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);
}
static void setCursorImage(_GLFWwindow* window,
_GLFWcursorWayland* cursorWayland)
{
@ -2046,7 +2076,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 +2086,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 +2401,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 +3250,3 @@ GLFWAPI struct wl_surface* glfwGetWaylandWindow(GLFWwindow* handle)
}
#endif // _GLFW_WAYLAND