Created
April 4, 2011 11:58
-
-
Save je-so/901523 to your computer and use it in GitHub Desktop.
Xlib set transparency of top level window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Sets the transparency of the toplevel window. | |
* An alpha value of 1 draws the window opaque a value of 0 makes | |
* it totally translucent. | |
* If alpha is set to a value outside of [0..1] EINVAL is returned. */ | |
static int settransparency_helper(Display * display, Window win, double alpha) | |
{ | |
int err ; | |
if ( alpha < 0 | |
|| alpha > 1) { | |
LOG_DOUBLE(alpha) ; | |
err = EINVAL ; | |
goto ABBRUCH ; | |
} | |
uint32_t cardinal_alpha = (uint32_t) (alpha * (uint32_t)-1) ; | |
if (cardinal_alpha == (uint32_t)-1) { | |
XDeleteProperty( display, win, XInternAtom( display, "_NET_WM_WINDOW_OPACITY", 0)) ; | |
} else { | |
XChangeProperty( display, win, XInternAtom( display, "_NET_WM_WINDOW_OPACITY", 0), | |
XA_CARDINAL, 32, PropModeReplace, (uint8_t*) &cardinal_alpha, 1) ; | |
} | |
return 0 ; | |
ABBRUCH: | |
LOG_ABORT(err) ; | |
return err ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to create a X11 window with a transparent background?
===>
See https://gist.github.com/je-so/903479
===>
To be able to manage an alpha channel with X11 you have to use X11 extensions.
I'm using OpenGL to write to the alpha channel in this example but the initialization part of the code keeps the same.