Skip to content

Commit

Permalink
Clean up the wintype option logic
Browse files Browse the repository at this point in the history
I just realized wintype option shadow and fade never worked. If you set
the global shadow option to true, wintype shadow option will have no effect.

Now the wintype options will properly override the global ones.

Also remove deprecated options from compton.sample.conf.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
  • Loading branch information
yshui committed Dec 4, 2018
1 parent a3f7531 commit f97cf48
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 85 deletions.
10 changes: 4 additions & 6 deletions compton.sample.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Shadow
shadow = true;
no-dnd-shadow = true;
no-dock-shadow = true;
clear-shadow = true;
shadow-radius = 7;
shadow-offset-x = -7;
shadow-offset-y = -7;
Expand All @@ -22,7 +19,6 @@ shadow-exclude = [
# xinerama-shadow-crop = true;

# Opacity
menu-opacity = 0.8;
inactive-opacity = 0.8;
# active-opacity = 0.8;
frame-opacity = 0.7;
Expand Down Expand Up @@ -59,8 +55,6 @@ detect-rounded-corners = true;
detect-client-opacity = true;
refresh-rate = 0;
vsync = "none";
dbe = false;
paint-on-overlay = true;
# sw-opti = true;
# unredir-if-possible = true;
# unredir-if-possible-delay = 5000;
Expand All @@ -83,4 +77,8 @@ glx-swap-method = "undefined";
wintypes:
{
tooltip = { fade = true; shadow = true; opacity = 0.75; focus = true; full-shadow = false; };
dock = { shadow = false; }
dnd = { shadow = false; }
popup_menu = { opacity = 0.8; }
dropdown_menu = { opacity = 0.8; }
};
31 changes: 22 additions & 9 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@

#define MAX_ALPHA (255)

#define ARR_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))

// === Includes ===

// For some special functions
Expand Down Expand Up @@ -435,6 +437,24 @@ typedef struct _latom {

#define REG_DATA_INIT { NULL, 0 }

typedef struct win_option_mask {
bool shadow: 1;
bool fade: 1;
bool focus: 1;
bool full_shadow: 1;
bool redir_ignore: 1;
bool opacity: 1;
} win_option_mask_t;

typedef struct win_option {
bool shadow;
bool fade;
bool focus;
bool full_shadow;
bool redir_ignore;
double opacity;
} win_option_t;

/// Structure representing all options.
typedef struct options_t {
// === Debugging ===
Expand Down Expand Up @@ -512,6 +532,8 @@ typedef struct options_t {
bool show_all_xerrors;
/// Whether to avoid acquiring X Selection.
bool no_x_selection;
/// Window type option override.
win_option_t wintype_option[NUM_WINTYPES];

// === VSync & software optimization ===
/// User-specified refresh rate.
Expand All @@ -527,9 +549,6 @@ typedef struct options_t {
bool vsync_use_glfinish;

// === Shadow ===
/// Enable/disable shadow for specific window types.
bool wintype_shadow[NUM_WINTYPES];
bool wintype_full_shadow[NUM_WINTYPES];
/// Red, green and blue tone of the shadow.
double shadow_red, shadow_green, shadow_blue;
int shadow_radius;
Expand All @@ -547,8 +566,6 @@ typedef struct options_t {
bool xinerama_shadow_crop;

// === Fading ===
/// Enable/disable fading for specific window types.
bool wintype_fade[NUM_WINTYPES];
/// How much to fade in in a single fading step.
opacity_t fade_in_step;
/// How much to fade out in a single fading step.
Expand All @@ -563,8 +580,6 @@ typedef struct options_t {
c2_lptr_t *fade_blacklist;

// === Opacity ===
/// Default opacity for specific window types
double wintype_opacity[NUM_WINTYPES];
/// Default opacity for inactive windows.
/// 32-bit integer with the format of _NET_WM_OPACITY. 0 stands for
/// not enabled, default.
Expand Down Expand Up @@ -605,8 +620,6 @@ typedef struct options_t {
c2_lptr_t *opacity_rules;

// === Focus related ===
/// Consider windows of specific types to be always focused.
bool wintype_focus[NUM_WINTYPES];
/// Whether to try to detect WM windows and mark them as focused.
bool mark_wmwin_focused;
/// Whether to mark override-redirect windows as focused.
Expand Down
68 changes: 27 additions & 41 deletions src/compton.c
Original file line number Diff line number Diff line change
Expand Up @@ -1904,7 +1904,7 @@ paint_all(session_t *ps, region_t *region, const region_t *region_real, win * co
// Mask out the body of the window from the shadow if needed
// Doing it here instead of in make_shadow() for saving GPU
// power and handling shaped windows (XXX unconfirmed)
if (!ps->o.wintype_full_shadow[w->window_type])
if (!ps->o.wintype_option[w->window_type].full_shadow)
pixman_region32_subtract(&reg_tmp, &reg_tmp, &bshape);

#ifdef CONFIG_XINERAMA
Expand Down Expand Up @@ -3920,7 +3920,7 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
{ NULL, 0, NULL, 0 },
};

int o = 0, longopt_idx = -1, i = 0;
int o = 0, longopt_idx = -1;

if (first_pass) {
// Pre-parse the commandline arguments to check for --config and invalid
Expand Down Expand Up @@ -3955,25 +3955,16 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
return;
}

struct options_tmp cfgtmp = {
.no_dock_shadow = false,
.no_dnd_shadow = false,
.menu_opacity = NAN,
};
bool shadow_enable = false, fading_enable = false;
char *lc_numeric_old = mstrcpy(setlocale(LC_NUMERIC, NULL));

for (i = 0; i < NUM_WINTYPES; ++i) {
ps->o.wintype_fade[i] = false;
ps->o.wintype_shadow[i] = false;
ps->o.wintype_opacity[i] = NAN;
}
win_option_mask_t winopt_mask[NUM_WINTYPES] = {{0}};

// Enforce LC_NUMERIC locale "C" here to make sure dots are recognized
// instead of commas in atof().
setlocale(LC_NUMERIC, "C");

parse_config(ps, &cfgtmp);
parse_config(ps, &shadow_enable, &fading_enable, winopt_mask);

// Parse commandline arguments. Range checking will be done later.

Expand Down Expand Up @@ -4012,13 +4003,20 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
shadow_enable = true;
break;
case 'C':
cfgtmp.no_dock_shadow = true;
winopt_mask[WINTYPE_DOCK].shadow = true;
ps->o.wintype_option[WINTYPE_DOCK].shadow = true;
break;
case 'G':
cfgtmp.no_dnd_shadow = true;
winopt_mask[WINTYPE_DND].shadow = true;
ps->o.wintype_option[WINTYPE_DND].shadow = true;
break;
case 'm':
cfgtmp.menu_opacity = atof(optarg);
case 'm':;
double tmp;
tmp = normalize_d(atof(optarg));
winopt_mask[WINTYPE_DROPDOWN_MENU].opacity = true;
winopt_mask[WINTYPE_POPUP_MENU].opacity = true;
ps->o.wintype_option[WINTYPE_POPUP_MENU].opacity = tmp;
ps->o.wintype_option[WINTYPE_DROPDOWN_MENU].opacity = tmp;
break;
case 'f':
case 'F':
Expand Down Expand Up @@ -4232,22 +4230,20 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
ps->o.inactive_dim = normalize_d(ps->o.inactive_dim);
ps->o.frame_opacity = normalize_d(ps->o.frame_opacity);
ps->o.shadow_opacity = normalize_d(ps->o.shadow_opacity);
cfgtmp.menu_opacity = normalize_d(cfgtmp.menu_opacity);
ps->o.refresh_rate = normalize_i_range(ps->o.refresh_rate, 0, 300);

if (shadow_enable)
wintype_arr_enable(ps->o.wintype_shadow);
ps->o.wintype_shadow[WINTYPE_DESKTOP] = false;
if (cfgtmp.no_dock_shadow)
ps->o.wintype_shadow[WINTYPE_DOCK] = false;
if (cfgtmp.no_dnd_shadow)
ps->o.wintype_shadow[WINTYPE_DND] = false;
if (fading_enable)
wintype_arr_enable(ps->o.wintype_fade);

if (!safe_isnan(cfgtmp.menu_opacity)) {
ps->o.wintype_opacity[WINTYPE_DROPDOWN_MENU] = cfgtmp.menu_opacity;
ps->o.wintype_opacity[WINTYPE_POPUP_MENU] = cfgtmp.menu_opacity;
// Apply default wintype options that are dependent on global options
for (int i = 0; i < NUM_WINTYPES; i++) {
auto wo = &ps->o.wintype_option[i];
auto mask = &winopt_mask[i];
if (!mask->shadow) {
wo->shadow = shadow_enable;
mask->shadow = true;
}
if (!mask->fade) {
wo->fade = fading_enable;
mask->fade = true;
}
}

// --blur-background-frame implies --blur-background
Expand Down Expand Up @@ -5064,8 +5060,6 @@ session_init(session_t *ps_old, int argc, char **argv) {
.vsync = VSYNC_NONE,
.vsync_aggressive = false,

.wintype_shadow = { false },
.wintype_full_shadow = { false },
.shadow_red = 0.0,
.shadow_green = 0.0,
.shadow_blue = 0.0,
Expand All @@ -5078,15 +5072,13 @@ session_init(session_t *ps_old, int argc, char **argv) {
.respect_prop_shadow = false,
.xinerama_shadow_crop = false,

.wintype_fade = { false },
.fade_in_step = 0.028 * OPAQUE,
.fade_out_step = 0.03 * OPAQUE,
.fade_delta = 10,
.no_fading_openclose = false,
.no_fading_destroyed_argb = false,
.fade_blacklist = NULL,

.wintype_opacity = { NAN },
.inactive_opacity = OPAQUE,
.inactive_opacity_override = false,
.active_opacity = OPAQUE,
Expand All @@ -5103,7 +5095,6 @@ session_init(session_t *ps_old, int argc, char **argv) {
.invert_color_list = NULL,
.opacity_rules = NULL,

.wintype_focus = { false },
.use_ewmh_active_win = false,
.focus_blacklist = NULL,
.detect_transient = false,
Expand Down Expand Up @@ -5203,11 +5194,6 @@ session_init(session_t *ps_old, int argc, char **argv) {
ps->ignore_tail = &ps->ignore_head;
gettimeofday(&ps->time_start, NULL);

wintype_arr_enable(ps->o.wintype_focus);
ps->o.wintype_focus[WINTYPE_UNKNOWN] = false;
ps->o.wintype_focus[WINTYPE_NORMAL] = false;
ps->o.wintype_focus[WINTYPE_UTILITY] = false;

// First pass
get_cfg(ps, argc, argv, true);

Expand Down
8 changes: 3 additions & 5 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ parse_cfg_condlst(session_t *ps, const config_t *pcfg, c2_lptr_t **pcondlst,
const char *name);

void
parse_config(session_t *ps, struct options_tmp *pcfgtmp);
parse_config(session_t *ps, bool *shadow_enable,
bool *fading_enable, win_option_mask_t *winopt_mask);
#else
static inline void parse_config(session_t *a, struct options_tmp *b) {
(void)a;
(void)b;
}
static inline void parse_config() {}
#endif
Loading

0 comments on commit f97cf48

Please sign in to comment.