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; opacity_t opacity;
/// Target window opacity. /// Target window opacity.
opacity_t opacity_tgt; 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. /// Cached value of opacity window attribute.
opacity_t opacity_prop; 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. /// Last window opacity value we set.
opacity_t opacity_set; opacity_t opacity_set;

View File

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

View File

@ -783,21 +783,29 @@ unmap_callback(session_t *ps, win *w);
static void static void
unmap_win(session_t *ps, win *w); unmap_win(session_t *ps, win *w);
static opacity_t static bool
wid_get_opacity_prop(session_t *ps, Window wid, opacity_t def); wid_get_opacity_prop(session_t *ps, Window wid, opacity_t def, opacity_t *out);
/** /**
* Reread opacity property of a window. * Reread opacity property of a window.
*/ */
static inline void static inline void
win_update_opacity_prop(session_t *ps, win *w) { win_update_opacity_prop(session_t *ps, win *w) {
w->opacity_prop = wid_get_opacity_prop(ps, w->id, OPAQUE); // get frame opacity first
if (!ps->o.detect_client_opacity || !w->client_win w->has_opacity_prop =
|| w->id == w->client_win) wid_get_opacity_prop(ps, w->id, OPAQUE, &w->opacity_prop);
w->opacity_prop_client = OPAQUE;
else if (w->has_opacity_prop)
w->opacity_prop_client = wid_get_opacity_prop(ps, w->client_win, // opacity found
OPAQUE); 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 static double
@ -1351,3 +1359,5 @@ session_run(session_t *ps);
static void static void
reset_enable(int __attribute__((unused)) signum); 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, cdbus_reply_uint32);
cdbus_m_win_get_do(opacity_tgt, 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, 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(opacity_set, cdbus_reply_uint32);
cdbus_m_win_get_do(frame_opacity, cdbus_reply_double); cdbus_m_win_get_do(frame_opacity, cdbus_reply_double);