Unify opacity_prop and opacity_prop_client

Also keep track of whether opacity prop is present on the window
This commit is contained in:
Yuxuan Shui 2018-08-11 13:22:49 -04:00
parent a1afb76c44
commit 91ca387723
4 changed files with 37 additions and 30 deletions

View File

@ -1162,12 +1162,11 @@ typedef struct _win {
opacity_t opacity;
/// Target window opacity.
opacity_t opacity_tgt;
/// true if window (or client window, for broken window managers
/// not transferring client window's _NET_WM_OPACITY value) has opacity prop
bool has_opacity_prop;
/// Cached value of opacity window attribute.
opacity_t opacity_prop;
/// Cached value of opacity window attribute on client window. For
/// broken window managers not transferring client window's
/// _NET_WM_OPACITY value
opacity_t opacity_prop_client;
/// Last window opacity value we set.
opacity_t opacity_set;

View File

@ -2312,19 +2312,22 @@ unmap_win(session_t *ps, win *w) {
#endif
}
static opacity_t
wid_get_opacity_prop(session_t *ps, Window wid, opacity_t def) {
opacity_t val = def;
static bool
wid_get_opacity_prop(session_t *ps, Window wid, opacity_t def, opacity_t *out) {
bool ret = false;
*out = def;
winprop_t prop = wid_get_prop(ps, wid, ps->atom_opacity, 1L,
XA_CARDINAL, 32);
if (prop.nitems)
val = *prop.data.p32;
if (prop.nitems) {
*out = *prop.data.p32;
ret = true;
}
free_winprop(&prop);
return val;
return ret;
}
static double
@ -2374,8 +2377,7 @@ calc_opacity(session_t *ps, win *w) {
opacity = 0;
else {
// Try obeying opacity property and window type opacity firstly
if (OPAQUE == (opacity = w->opacity_prop)
&& OPAQUE == (opacity = w->opacity_prop_client)) {
if (OPAQUE == (opacity = w->opacity_prop)) {
opacity = ps->o.wintype_opacity[w->window_type] * OPAQUE;
}
@ -2870,8 +2872,8 @@ add_win(session_t *ps, Window id, Window prev) {
.opacity = 0,
.opacity_tgt = 0,
.has_opacity_prop = false,
.opacity_prop = OPAQUE,
.opacity_prop_client = OPAQUE,
.opacity_set = OPAQUE,
.fade = false,
@ -4201,14 +4203,9 @@ ev_property_notify(session_t *ps, XPropertyEvent *ev) {
// If _NET_WM_OPACITY changes
if (ev->atom == ps->atom_opacity) {
win *w = NULL;
if ((w = find_win(ps, ev->window)))
w->opacity_prop = wid_get_opacity_prop(ps, w->id, OPAQUE);
else if (ps->o.detect_client_opacity
&& (w = find_toplevel(ps, ev->window)))
w->opacity_prop_client = wid_get_opacity_prop(ps, w->client_win,
OPAQUE);
win *w = find_win(ps, ev->window) ?: find_toplevel(ps, ev->window);
if (w) {
win_update_opacity_prop(ps, w);
w->flags |= WFLAG_OPCT_CHANGE;
}
}
@ -7777,3 +7774,5 @@ main(int argc, char **argv) {
return 0;
}
// vim: set et sw=2 :

View File

@ -783,21 +783,29 @@ unmap_callback(session_t *ps, win *w);
static void
unmap_win(session_t *ps, win *w);
static opacity_t
wid_get_opacity_prop(session_t *ps, Window wid, opacity_t def);
static bool
wid_get_opacity_prop(session_t *ps, Window wid, opacity_t def, opacity_t *out);
/**
* Reread opacity property of a window.
*/
static inline void
win_update_opacity_prop(session_t *ps, win *w) {
w->opacity_prop = wid_get_opacity_prop(ps, w->id, OPAQUE);
if (!ps->o.detect_client_opacity || !w->client_win
|| w->id == w->client_win)
w->opacity_prop_client = OPAQUE;
else
w->opacity_prop_client = wid_get_opacity_prop(ps, w->client_win,
OPAQUE);
// get frame opacity first
w->has_opacity_prop =
wid_get_opacity_prop(ps, w->id, OPAQUE, &w->opacity_prop);
if (w->has_opacity_prop)
// opacity found
return;
if (ps->o.detect_client_opacity && w->client_win && w->id == w->client_win)
// checking client opacity not allowed
return;
// get client opacity
w->has_opacity_prop =
wid_get_opacity_prop(ps, w->client_win, OPAQUE, &w->opacity_prop);
}
static double
@ -1351,3 +1359,5 @@ session_run(session_t *ps);
static void
reset_enable(int __attribute__((unused)) signum);
// vim: set et sw=2 :

View File

@ -719,7 +719,6 @@ cdbus_process_win_get(session_t *ps, DBusMessage *msg) {
cdbus_m_win_get_do(opacity, cdbus_reply_uint32);
cdbus_m_win_get_do(opacity_tgt, cdbus_reply_uint32);
cdbus_m_win_get_do(opacity_prop, cdbus_reply_uint32);
cdbus_m_win_get_do(opacity_prop_client, cdbus_reply_uint32);
cdbus_m_win_get_do(opacity_set, cdbus_reply_uint32);
cdbus_m_win_get_do(frame_opacity, cdbus_reply_double);