client: rework and document opacity field

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-08-15 02:00:58 +02:00
parent 2dda972561
commit d975ee2ec1
3 changed files with 50 additions and 6 deletions

View File

@ -1155,9 +1155,14 @@ luaA_client_newindex(lua_State *L)
widget_invalidate_cache((*c)->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache((*c)->screen, WIDGET_CACHE_CLIENTS);
break; break;
case A_TK_OPACITY: case A_TK_OPACITY:
if(lua_isnil(L, 3))
window_opacity_set((*c)->win, -1);
else
{
d = luaL_checknumber(L, 3); d = luaL_checknumber(L, 3);
if(d == -1 || (d >= 0 && d <= 1)) if(d >= 0 && d <= 1)
window_trans_set((*c)->win, d); window_opacity_set((*c)->win, d);
}
break; break;
case A_TK_FLOATING: case A_TK_FLOATING:
client_setfloating(*c, luaA_checkboolean(L, 3)); client_setfloating(*c, luaA_checkboolean(L, 3));
@ -1245,6 +1250,7 @@ luaA_client_newindex(lua_State *L)
* \lfield titlebar The client titlebar. * \lfield titlebar The client titlebar.
* \lfield urgent The client urgent state. * \lfield urgent The client urgent state.
* \lfield focus The focused client. * \lfield focus The focused client.
* \lfield opacity The client opacity between 0 and 1.
*/ */
static int static int
luaA_client_index(lua_State *L) luaA_client_index(lua_State *L)
@ -1258,6 +1264,7 @@ luaA_client_index(lua_State *L)
xutil_class_hint_t hint; xutil_class_hint_t hint;
xcb_get_property_cookie_t prop_c; xcb_get_property_cookie_t prop_c;
xcb_get_property_reply_t *prop_r = NULL; xcb_get_property_reply_t *prop_r = NULL;
double d;
if((*c)->invalid) if((*c)->invalid)
luaL_error(L, "client is invalid\n"); luaL_error(L, "client is invalid\n");
@ -1321,6 +1328,12 @@ luaA_client_index(lua_State *L)
case A_TK_ICON_PATH: case A_TK_ICON_PATH:
lua_pushstring(L, (*c)->icon_path); lua_pushstring(L, (*c)->icon_path);
break; 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: case A_TK_FLOATING:
lua_pushboolean(L, (*c)->isfloating); lua_pushboolean(L, (*c)->isfloating);
break; break;

View File

@ -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 win The window.
* \param opacity Opacity of the window, between 0 and 1. * \param opacity Opacity of the window, between 0 and 1.
*/ */
void void
window_trans_set(xcb_window_t win, double opacity) window_opacity_set(xcb_window_t win, double opacity)
{ {
unsigned int real_opacity = 0xffffffff; unsigned int real_opacity = 0xffffffff;

View File

@ -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_configure(xcb_window_t, area_t, int);
void window_buttons_grab(xcb_window_t, xcb_window_t, button_t *); void window_buttons_grab(xcb_window_t, xcb_window_t, button_t *);
void window_root_buttons_grab(xcb_window_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 #endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80