diff options
author | Tor Lillqvist <tml@novell.com> | 2007-04-30 07:27:22 +0000 |
---|---|---|
committer | Tor Lillqvist <tml@src.gnome.org> | 2007-04-30 07:27:22 +0000 |
commit | b18f04427015628110e6c78201635b611e7674f5 (patch) | |
tree | f2b1058d3832d6289c2d966b81eb7c020665e114 | |
parent | 10862a344aa8fb44e6045343ddf65eb0d14cc1b2 (diff) | |
download | gtk+-b18f04427015628110e6c78201635b611e7674f5.tar.gz |
Add functionality to set overall opacity of a top-level window. (#405316)
2007-04-30 Tor Lillqvist <tml@novell.com>
Add functionality to set overall opacity of a top-level
window. (#405316)
* gdk/gdk.symbols: Add gdk_window_set_opacity.
* gdk/x11/gdkwindow-x11.c
* gdk/win32/gdkwindow-win32.c: Implement
gdk_window_set_opacity(). On X11 use the _NET_WM_WINDOW_OPACITY
property. On Win32 use SetLayeredWindowAttributes(LWA_ALPHA).
* gdk/gdkwindow.h: Declare gdk_window_set_opacity().
* gdk/x11/gdkscreen-x11.c (gdk_screen_get_rgba_colormap): Document
that this is not implemented in the Windows backend. Add reference
to gdk_window_set_opacity().
svn path=/trunk/; revision=17730
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | gdk/gdk.symbols | 1 | ||||
-rw-r--r-- | gdk/gdkwindow.h | 3 | ||||
-rw-r--r-- | gdk/win32/gdkwindow-win32.c | 30 | ||||
-rw-r--r-- | gdk/x11/gdkscreen-x11.c | 7 | ||||
-rw-r--r-- | gdk/x11/gdkwindow-x11.c | 49 |
6 files changed, 106 insertions, 2 deletions
@@ -1,3 +1,21 @@ +2007-04-30 Tor Lillqvist <tml@novell.com> + + Add functionality to set overall opacity of a top-level + window. (#405316) + + * gdk/gdk.symbols: Add gdk_window_set_opacity. + + * gdk/x11/gdkwindow-x11.c + * gdk/win32/gdkwindow-win32.c: Implement + gdk_window_set_opacity(). On X11 use the _NET_WM_WINDOW_OPACITY + property. On Win32 use SetLayeredWindowAttributes(LWA_ALPHA). + + * gdk/gdkwindow.h: Declare gdk_window_set_opacity(). + + * gdk/x11/gdkscreen-x11.c (gdk_screen_get_rgba_colormap): Document + that this is not implemented in the Windows backend. Add reference + to gdk_window_set_opacity(). + 2007-04-30 Matthias Clasen <mclasen@redhat.com> * gtk/gtk.symbols: diff --git a/gdk/gdk.symbols b/gdk/gdk.symbols index b064cc7f50..ae34586541 100644 --- a/gdk/gdk.symbols +++ b/gdk/gdk.symbols @@ -740,6 +740,7 @@ gdk_window_set_icon_list gdk_window_set_icon gdk_window_set_icon_name gdk_window_beep +gdk_window_set_opacity gdk_window_iconify gdk_window_deiconify gdk_window_stick diff --git a/gdk/gdkwindow.h b/gdk/gdkwindow.h index 325c4b3d88..9ff3a09fca 100644 --- a/gdk/gdkwindow.h +++ b/gdk/gdkwindow.h @@ -569,7 +569,8 @@ void gdk_window_set_keep_above (GdkWindow *window, gboolean setting); void gdk_window_set_keep_below (GdkWindow *window, gboolean setting); - +void gdk_window_set_opacity (GdkWindow *window, + gdouble opacity); void gdk_window_register_dnd (GdkWindow *window); void gdk_window_begin_resize_drag (GdkWindow *window, diff --git a/gdk/win32/gdkwindow-win32.c b/gdk/win32/gdkwindow-win32.c index 9d029619ab..75d944d2d7 100644 --- a/gdk/win32/gdkwindow-win32.c +++ b/gdk/win32/gdkwindow-win32.c @@ -3399,3 +3399,33 @@ gdk_window_beep (GdkWindow *window) { gdk_display_beep (_gdk_display); } + +void +gdk_window_set_opacity (GdkWindow *window, + gdouble opacity) +{ + LONG exstyle; + + g_return_if_fail (GDK_IS_WINDOW (window)); + g_return_if_fail (WINDOW_IS_TOPLEVEL (window)); + + if (GDK_WINDOW_DESTROYED (window)) + return; + + if (opacity < 0) + opacity = 0; + else if (opacity > 1) + opacity = 1; + + exstyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE); + + if (!(exstyle & WS_EX_LAYERED)) + API_CALL (SetWindowLong, (GDK_WINDOW_HWND (window), + GWL_EXSTYLE, + exstyle | WS_EX_LAYERED)); + + API_CALL (SetLayeredWindowAttributes, (GDK_WINDOW_HWND (window), + 0, + opacity * 0xff, + LWA_ALPHA)); +} diff --git a/gdk/x11/gdkscreen-x11.c b/gdk/x11/gdkscreen-x11.c index f5e08d87ae..624870f850 100644 --- a/gdk/x11/gdkscreen-x11.c +++ b/gdk/x11/gdkscreen-x11.c @@ -382,7 +382,12 @@ gdk_screen_get_monitor_geometry (GdkScreen *screen, * when displaying the window on the screen: in particular, for * X an appropriate windowing manager and compositing manager * must be running to provide appropriate display. - * + * + * This functionality is not implemented in the Windows backend. + * + * For setting an overall opacity for a top-level window, see + * gdk_window_set_opacity(). + * Return value: a colormap to use for windows with an alpha channel * or %NULL if the capability is not available. * diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c index fe5a0976f3..621d3245dd 100644 --- a/gdk/x11/gdkwindow-x11.c +++ b/gdk/x11/gdkwindow-x11.c @@ -6402,5 +6402,54 @@ gdk_window_beep (GdkWindow *window) gdk_display_beep (display); } +/** + * gdk_window_set_opacity: + * @window a top-level #GdkWindow + * @opacity: opacity + * + * Request the windowing system to make @window partially transparent, + * with opacity 0 being fully transparent and 1 fully opaque. (Values + * of the opacity parameter are clamped to the [0,1] range.) On X11 + * this works only on X screens with a compositing manager running. + * + * For setting up per-pixel alpha, see gdk_screen_get_rgba_colormap(). + * + * Since: 2.12 + */ +void +gdk_window_set_opacity (GdkWindow *window, + gdouble opacity) +{ + GdkDisplay *display; + guint32 cardinal; + + g_return_if_fail (GDK_IS_WINDOW (window)); + g_return_if_fail (WINDOW_IS_TOPLEVEL (window)); + + if (GDK_WINDOW_DESTROYED (window)) + return; + + display = gdk_drawable_get_display (window); + + if (opacity < 0) + opacity = 0; + else if (opacity > 1) + opacity = 1; + + cardinal = opacity * 0xffffffff; + + if (cardinal == 0xffffffff) + XDeleteProperty (GDK_DISPLAY_XDISPLAY (display), + GDK_WINDOW_XID (window), + gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY")); + else + XChangeProperty (GDK_DISPLAY_XDISPLAY (display), + GDK_WINDOW_XID (window), + gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_OPACITY"), + XA_CARDINAL, 32, + PropModeReplace, + (guchar *) cardinal, 1); +} + #define __GDK_WINDOW_X11_C__ #include "gdkaliasdef.c" |