integrate _glfwGetWindowIsFullscreenX11 with platform idiom

This commit is contained in:
Mike Interlandi 2025-02-03 11:57:46 -05:00
parent 618532218e
commit bb4ba846da
6 changed files with 47 additions and 20 deletions

View file

@ -747,7 +747,7 @@ struct _GLFWplatform
void (*setWindowFloating)(_GLFWwindow*,GLFWbool);
void (*setWindowOpacity)(_GLFWwindow*,float);
void (*setWindowMousePassthrough)(_GLFWwindow*,GLFWbool);
void (*getWindowIsFullscreen) (_GLFWwindow*);
GLFWbool (*getWindowIsFullscreen) (_GLFWwindow*);
void (*pollEvents)(void);
void (*waitEvents)(void);
void (*waitEventsTimeout)(double);

View file

@ -173,10 +173,6 @@ void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor)
window->monitor = monitor;
}
GLFWbool _glfwWindowGetIsFullscreen(_GLFWwindow* window) {
return _glfwGetIsWindowFullscreenX11(window);
}
//////////////////////////////////////////////////////////////////////////
////// GLFW public API //////
//////////////////////////////////////////////////////////////////////////
@ -905,7 +901,7 @@ GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib)
case GLFW_MOUSE_PASSTHROUGH:
return window->mousePassthrough;
case GLFW_FULLSCREEN:
return _glfwWindowGetIsFullscreen(window);
return _glfw.platform.getWindowIsFullscreen(window);
case GLFW_TRANSPARENT_FRAMEBUFFER:
return _glfw.platform.framebufferTransparent(window);
case GLFW_RESIZABLE:

View file

@ -1237,6 +1237,7 @@ GLFWbool _glfwConnectX11(int platformID, _GLFWplatform* platform)
.setWindowFloating = _glfwSetWindowFloatingX11,
.setWindowOpacity = _glfwSetWindowOpacityX11,
.setWindowMousePassthrough = _glfwSetWindowMousePassthroughX11,
.getWindowIsFullscreen = _glfwGetWindowIsFullscreenX11,
.pollEvents = _glfwPollEventsX11,
.waitEvents = _glfwWaitEventsX11,
.waitEventsTimeout = _glfwWaitEventsTimeoutX11,

View file

@ -934,7 +934,7 @@ void _glfwSetWindowFloatingX11(_GLFWwindow* window, GLFWbool enabled);
float _glfwGetWindowOpacityX11(_GLFWwindow* window);
void _glfwSetWindowOpacityX11(_GLFWwindow* window, float opacity);
void _glfwSetWindowMousePassthroughX11(_GLFWwindow* window, GLFWbool enabled);
GLFWbool _glfwGetIsWindowFullscreenX11(_GLFWwindow* window);
GLFWbool _glfwGetWindowIsFullscreenX11(_GLFWwindow* window);
void _glfwSetRawMouseMotionX11(_GLFWwindow *window, GLFWbool enabled);
GLFWbool _glfwRawMouseMotionSupportedX11(void);

View file

@ -26,7 +26,9 @@
//========================================================================
#include "internal.h"
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#if defined(_GLFW_X11)
@ -2730,25 +2732,44 @@ void _glfwSetWindowMousePassthroughX11(_GLFWwindow* window, GLFWbool enabled)
}
}
GLFWbool _glfwGetIsWindowFullscreenX11(_GLFWwindow* window)
GLFWbool _glfwGetWindowIsFullscreenX11(_GLFWwindow* window)
{
Atom atom = XInternAtom(_glfw.x11.display, "_NET_WM_STATE_FULLSCREEN", 0);
Atom wm_state = XInternAtom(_glfw.x11.display, "_NET_WM_STATE", True);
Atom wm_state_fullscreen = XInternAtom(_glfw.x11.display, "_NET_WM_STATE_FULLSCREEN", True);
unsigned char prop[32] = {};
XGetWindowProperty(
Atom type = XA_ATOM;
int format;
size_t nItems;
size_t bytesAfterReturn;
Atom* prop;
int result = XGetWindowProperty(
_glfw.x11.display,
window->x11.handle,
atom,
wm_state,
0,
1, // 32 bits
0,
NULL,
NULL,
NULL,
NULL,
NULL,
(unsigned char**)&prop
~0L,
False,
AnyPropertyType,
&type,
&format,
&nItems,
&bytesAfterReturn,
(unsigned char**)&prop
);
assert(result == Success);
GLFWbool isFullscreen = 0;
for (int i = 0; i < nItems; i++) {
if (prop[i] == wm_state_fullscreen) {
isFullscreen = 1;
}
}
XFree(prop);
return isFullscreen;
}
float _glfwGetWindowOpacityX11(_GLFWwindow* window)

View file

@ -190,6 +190,15 @@ int main(int argc, char** argv)
glfwSetWindowAttrib(window, GLFW_MOUSE_PASSTHROUGH, false);
}
if (nk_button_label(nk, "Is window fullscreen?")) {
int fullscreen = glfwGetWindowAttrib(window, GLFW_FULLSCREEN);
if (fullscreen) {
nk_label(nk, "Yes", NK_TEXT_CENTERED);
} else {
nk_label(nk, "No", NK_TEXT_CENTERED);
}
}
nk_label(nk, "Press Enter in a text field to set value", NK_TEXT_CENTERED);
nk_flags events;