From 3ad3ebae953c22ce4c3145431351a3192b2c70a4 Mon Sep 17 00:00:00 2001 From: Richard Grenville Date: Sat, 30 Mar 2013 11:46:32 +0800 Subject: Feature #4: Default active window opacity - Add default active window opacity (--active-opacity). (#4) - Add win_focusin and win_focusout D-Bus signals. --- common.h | 8 ++++++++ compton.c | 30 +++++++++++++++++++++++++++++- dbus.c | 18 ++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/common.h b/common.h index e2af50f08..a3435d430 100644 --- a/common.h +++ b/common.h @@ -424,6 +424,8 @@ typedef struct { /// 32-bit integer with the format of _NET_WM_OPACITY. 0 stands for /// not enabled, default. opacity_t inactive_opacity; + /// Default opacity for inactive windows. + opacity_t active_opacity; /// Whether inactive_opacity overrides the opacity set by window /// attributes. bool inactive_opacity_override; @@ -1711,6 +1713,12 @@ cdbus_ev_win_mapped(session_t *ps, win *w); void cdbus_ev_win_unmapped(session_t *ps, win *w); + +void +cdbus_ev_win_focusout(session_t *ps, win *w); + +void +cdbus_ev_win_focusin(session_t *ps, win *w); //!@} /** @name DBus hooks diff --git a/compton.c b/compton.c index 8fae58ce5..981ee0c68 100644 --- a/compton.c +++ b/compton.c @@ -2153,6 +2153,10 @@ calc_opacity(session_t *ps, win *w) { && (OPAQUE == opacity || ps->o.inactive_opacity_override)) { opacity = ps->o.inactive_opacity; } + + // Respect active_opacity only when the window is physically focused + if (OPAQUE == opacity && ps->o.active_opacity && w->focused_real) + opacity = ps->o.active_opacity; } w->opacity_tgt = opacity; @@ -3136,6 +3140,16 @@ win_set_focused(session_t *ps, win *w, bool focused) { // Update everything related to conditions win_on_factor_change(ps, w); + +#ifdef CONFIG_DBUS + // Send D-Bus signal + if (ps->o.dbus) { + if (w->focused_real) + cdbus_ev_win_focusin(ps, w); + else + cdbus_ev_win_focusout(ps, w); + } +#endif } } /** @@ -4095,6 +4109,8 @@ usage(void) { " Inactive opacity set by -i overrides value of _NET_WM_OPACITY.\n" "--inactive-dim value\n" " Dim inactive windows. (0.0 - 1.0, defaults to 0)\n" + "--active-opacity opacity\n" + " Default opacity for active windows. (0.0 - 1.0)\n" "--mark-wmwin-focused\n" " Try to detect WM windows and mark them as active.\n" "--shadow-exclude condition\n" @@ -4520,6 +4536,9 @@ parse_config(session_t *ps, struct options_tmp *pcfgtmp) { // -i (inactive_opacity) if (config_lookup_float(&cfg, "inactive-opacity", &dval)) ps->o.inactive_opacity = normalize_d(dval) * OPAQUE; + // --active_opacity + if (config_lookup_float(&cfg, "active-opacity", &dval)) + ps->o.active_opacity = normalize_d(dval) * OPAQUE; // -e (frame_opacity) config_lookup_float(&cfg, "frame-opacity", &ps->o.frame_opacity); // -z (clear_shadow) @@ -4682,6 +4701,7 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) { { "benchmark-wid", required_argument, NULL, 294 }, { "glx-use-copysubbuffermesa", no_argument, NULL, 295 }, { "blur-background-exclude", required_argument, NULL, 296 }, + { "active-opacity", required_argument, NULL, 297 }, // Must terminate with a NULL entry { NULL, 0, NULL, 0 }, }; @@ -4968,6 +4988,10 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) { // --blur-background-exclude condlst_add(ps, &ps->o.blur_background_blacklist, optarg); break; + case 297: + // --active-opacity + ps->o.active_opacity = (normalize_d(atof(optarg)) * OPAQUE); + break; default: usage(); break; @@ -4993,6 +5017,9 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) { if (OPAQUE == ps->o.inactive_opacity) { ps->o.inactive_opacity = 0; } + if (OPAQUE == ps->o.active_opacity) { + ps->o.active_opacity = 0; + } if (shadow_enable) wintype_arr_enable(ps->o.wintype_shadow); ps->o.wintype_shadow[WINTYPE_DESKTOP] = false; @@ -5018,7 +5045,7 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) { // Other variables determined by options // Determine whether we need to track focus changes - if (ps->o.inactive_opacity || ps->o.inactive_dim) { + if (ps->o.inactive_opacity || ps->o.active_opacity || ps->o.inactive_dim) { ps->o.track_focus = true; } @@ -5840,6 +5867,7 @@ session_init(session_t *ps_old, int argc, char **argv) { .wintype_opacity = { 0.0 }, .inactive_opacity = 0, .inactive_opacity_override = false, + .active_opacity = 0, .frame_opacity = 0.0, .detect_client_opacity = false, .alpha_step = 0.03, diff --git a/dbus.c b/dbus.c index 48f847caf..5a1a3e344 100644 --- a/dbus.c +++ b/dbus.c @@ -1033,6 +1033,12 @@ cdbus_process_introspect(session_t *ps, DBusMessage *msg) { " \n" " \n" " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" " \n" " \n" "\n"; @@ -1069,4 +1075,16 @@ cdbus_ev_win_unmapped(session_t *ps, win *w) { if (ps->dbus_conn) cdbus_signal_wid(ps, "win_unmapped", w->id); } + +void +cdbus_ev_win_focusout(session_t *ps, win *w) { + if (ps->dbus_conn) + cdbus_signal_wid(ps, "win_focusout", w->id); +} + +void +cdbus_ev_win_focusin(session_t *ps, win *w) { + if (ps->dbus_conn) + cdbus_signal_wid(ps, "win_focusin", w->id); +} //!@} -- cgit v1.2.1