mirror of
https://github.com/glfw/glfw.git
synced 2026-09-22 08:50:15 +00:00
Add glfwGetWindowOpacity and glfwSetWindowOpacity
This adds support for setting the opacity of the whole window, including any decorations. Fixes #1089.
This commit is contained in:
+32
-5
@@ -2449,11 +2449,7 @@ int _glfwPlatformFramebufferTransparent(_GLFWwindow* window)
|
||||
if (!window->x11.transparent)
|
||||
return GLFW_FALSE;
|
||||
|
||||
// Check whether a compositing manager is running
|
||||
char name[32];
|
||||
snprintf(name, sizeof(name), "_NET_WM_CM_S%u", _glfw.x11.screen);
|
||||
const Atom selection = XInternAtom(_glfw.x11.display, name, False);
|
||||
return XGetSelectionOwner(_glfw.x11.display, selection) != None;
|
||||
return XGetSelectionOwner(_glfw.x11.display, _glfw.x11.NET_WM_CM_Sx) != None;
|
||||
}
|
||||
|
||||
void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled)
|
||||
@@ -2559,6 +2555,37 @@ void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled)
|
||||
XFlush(_glfw.x11.display);
|
||||
}
|
||||
|
||||
float _glfwPlatformGetWindowOpacity(_GLFWwindow* window)
|
||||
{
|
||||
float opacity = 1.f;
|
||||
|
||||
if (XGetSelectionOwner(_glfw.x11.display, _glfw.x11.NET_WM_CM_Sx))
|
||||
{
|
||||
CARD32* value = NULL;
|
||||
|
||||
if (_glfwGetWindowPropertyX11(window->x11.handle,
|
||||
_glfw.x11.NET_WM_WINDOW_OPACITY,
|
||||
XA_CARDINAL,
|
||||
(unsigned char**) &value))
|
||||
{
|
||||
opacity = (float) (*value / (double) 0xffffffffu);
|
||||
}
|
||||
|
||||
if (value)
|
||||
XFree(value);
|
||||
}
|
||||
|
||||
return opacity;
|
||||
}
|
||||
|
||||
void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
|
||||
{
|
||||
const CARD32 value = (CARD32) (0xffffffffu * (double) opacity);
|
||||
XChangeProperty(_glfw.x11.display, window->x11.handle,
|
||||
_glfw.x11.NET_WM_WINDOW_OPACITY, XA_CARDINAL, 32,
|
||||
PropModeReplace, (unsigned char*) &value, 1);
|
||||
}
|
||||
|
||||
void _glfwPlatformPollEvents(void)
|
||||
{
|
||||
_GLFWwindow* window;
|
||||
|
||||
Reference in New Issue
Block a user