From d975ee2ec1a2491d07c72a91b855e4bfd5f28973 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 15 Aug 2008 02:00:58 +0200 Subject: [PATCH] client: rework and document opacity field Signed-off-by: Julien Danjou --- client.c | 19 ++++++++++++++++--- window.c | 34 ++++++++++++++++++++++++++++++++-- window.h | 3 ++- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/client.c b/client.c index 3db6c17b..d8fd37b3 100644 --- a/client.c +++ b/client.c @@ -1155,9 +1155,14 @@ luaA_client_newindex(lua_State *L) widget_invalidate_cache((*c)->screen, WIDGET_CACHE_CLIENTS); break; case A_TK_OPACITY: - d = luaL_checknumber(L, 3); - if(d == -1 || (d >= 0 && d <= 1)) - window_trans_set((*c)->win, d); + if(lua_isnil(L, 3)) + window_opacity_set((*c)->win, -1); + else + { + d = luaL_checknumber(L, 3); + if(d >= 0 && d <= 1) + window_opacity_set((*c)->win, d); + } break; case A_TK_FLOATING: client_setfloating(*c, luaA_checkboolean(L, 3)); @@ -1245,6 +1250,7 @@ luaA_client_newindex(lua_State *L) * \lfield titlebar The client titlebar. * \lfield urgent The client urgent state. * \lfield focus The focused client. + * \lfield opacity The client opacity between 0 and 1. */ static int luaA_client_index(lua_State *L) @@ -1258,6 +1264,7 @@ luaA_client_index(lua_State *L) xutil_class_hint_t hint; xcb_get_property_cookie_t prop_c; xcb_get_property_reply_t *prop_r = NULL; + double d; if((*c)->invalid) luaL_error(L, "client is invalid\n"); @@ -1321,6 +1328,12 @@ luaA_client_index(lua_State *L) case A_TK_ICON_PATH: lua_pushstring(L, (*c)->icon_path); break; + case A_TK_OPACITY: + if((d = window_opacity_get((*c)->win)) >= 0) + lua_pushnumber(L, d); + else + return 0; + break; case A_TK_FLOATING: lua_pushboolean(L, (*c)->isfloating); break; diff --git a/window.c b/window.c index 1d54c1af..e34554e3 100644 --- a/window.c +++ b/window.c @@ -153,12 +153,42 @@ window_root_buttons_grab(xcb_window_t root) } } -/** Set transparency of a window. +/** Get the opacity of a window. + * \param The window. + * \return The opacity, between 0 and 1 or -1 or no opacity set. + */ +double +window_opacity_get(xcb_window_t win) +{ + xcb_get_property_cookie_t prop_c; + xcb_get_property_reply_t *prop_r; + + prop_c = xcb_get_property_unchecked(globalconf.connection, false, win, + _NET_WM_WINDOW_OPACITY, CARDINAL, 0L, 1L); + + prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL); + + if(!prop_r || !prop_r->value_len || prop_r->format != 32) + goto bailout; + + if(prop_r->value_len) + { + unsigned int *data = xcb_get_property_value(prop_r); + printf("result %d\n", *data); + return (double) *data / (double) 0xffffffff; + } + + bailout: + p_delete(&prop_r); + return -1; +} + +/** Set opacity of a window. * \param win The window. * \param opacity Opacity of the window, between 0 and 1. */ void -window_trans_set(xcb_window_t win, double opacity) +window_opacity_set(xcb_window_t win, double opacity) { unsigned int real_opacity = 0xffffffff; diff --git a/window.h b/window.h index 96c28a3e..a2a34ef5 100644 --- a/window.h +++ b/window.h @@ -30,7 +30,8 @@ long window_state_get_reply(xcb_get_property_cookie_t); void window_configure(xcb_window_t, area_t, int); void window_buttons_grab(xcb_window_t, xcb_window_t, button_t *); void window_root_buttons_grab(xcb_window_t); -void window_trans_set(xcb_window_t, double); +double window_opacity_get(xcb_window_t); +void window_opacity_set(xcb_window_t, double); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 -- 2.11.4.GIT