Skip to content

Commit 796e2c6

Browse files
committed
Bug fix #149: --opacity-rule misbehaves on 32-bit systems & others
- Fix a bug that --opacity-rule misbehaves with a value higher than 50% on 32-bit systems. Thanks to mrinx for reporting. (#149) - Fix a bug that opacity-rule in configuration file does not work.
1 parent fc8ec88 commit 796e2c6

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

compton.sample.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ blur-kern = "3x3box"
3131
# blur-kern = "5,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1"
3232
# blur-background-fixed = true;
3333
blur-background-exclude = [ "window_type = 'dock'", "window_type = 'desktop'" ];
34-
opacity-rule = [ ]
34+
# opacity-rule = [ "80:class_g = 'URxvt'" ];
3535

3636
# Fading
3737
fading = true;

src/compton.c

+23-4
Original file line numberDiff line numberDiff line change
@@ -2469,7 +2469,7 @@ static void
24692469
win_update_opacity_rule(session_t *ps, win *w) {
24702470
// If long is 32-bit, unfortunately there's no way could we express "unset",
24712471
// so we just entirely don't distinguish "unset" and OPAQUE
2472-
long opacity = OPAQUE;
2472+
opacity_t opacity = OPAQUE;
24732473
void *val = NULL;
24742474
if (c2_matchd(ps, w, ps->o.opacity_rules, &w->cache_oparule, &val))
24752475
opacity = ((double) (long) val) / 100.0 * OPAQUE;
@@ -5029,9 +5029,8 @@ parse_cfg_condlst(session_t *ps, const config_t *pcfg, c2_lptr_t **pcondlst,
50295029
// Parse an array of options
50305030
if (config_setting_is_array(setting)) {
50315031
int i = config_setting_length(setting);
5032-
while (i--) {
5032+
while (i--)
50335033
condlst_add(ps, pcondlst, config_setting_get_string_elem(setting, i));
5034-
}
50355034
}
50365035
// Treat it as a single pattern if it's a string
50375036
else if (CONFIG_TYPE_STRING == config_setting_type(setting)) {
@@ -5040,6 +5039,26 @@ parse_cfg_condlst(session_t *ps, const config_t *pcfg, c2_lptr_t **pcondlst,
50405039
}
50415040
}
50425041

5042+
/**
5043+
* Parse an opacity rule list in configuration file.
5044+
*/
5045+
static inline void
5046+
parse_cfg_condlst_opct(session_t *ps, const config_t *pcfg, const char *name) {
5047+
config_setting_t *setting = config_lookup(pcfg, name);
5048+
if (setting) {
5049+
// Parse an array of options
5050+
if (config_setting_is_array(setting)) {
5051+
int i = config_setting_length(setting);
5052+
while (i--)
5053+
parse_rule_opacity(ps, config_setting_get_string_elem(setting, i));
5054+
}
5055+
// Treat it as a single pattern if it's a string
5056+
else if (CONFIG_TYPE_STRING == config_setting_type(setting)) {
5057+
parse_rule_opacity(ps, config_setting_get_string(setting));
5058+
}
5059+
}
5060+
}
5061+
50435062
/**
50445063
* Parse a configuration file from default location.
50455064
*/
@@ -5213,7 +5232,7 @@ parse_config(session_t *ps, struct options_tmp *pcfgtmp) {
52135232
// --blur-background-exclude
52145233
parse_cfg_condlst(ps, &cfg, &ps->o.blur_background_blacklist, "blur-background-exclude");
52155234
// --opacity-rule
5216-
parse_cfg_condlst(ps, &cfg, &ps->o.opacity_rules, "opacity-rule");
5235+
parse_cfg_condlst_opct(ps, &cfg, "opacity-rule");
52175236
// --unredir-if-possible-exclude
52185237
parse_cfg_condlst(ps, &cfg, &ps->o.unredir_if_possible_blacklist, "unredir-if-possible-exclude");
52195238
// --blur-background

src/compton.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,10 @@ win_has_frame(const win *w) {
476476
}
477477

478478
static inline void
479-
wid_set_opacity_prop(session_t *ps, Window wid, long val) {
479+
wid_set_opacity_prop(session_t *ps, Window wid, opacity_t val) {
480+
const unsigned long v = val;
480481
XChangeProperty(ps->dpy, wid, ps->atom_opacity, XA_CARDINAL, 32,
481-
PropModeReplace, (unsigned char *) &val, 1);
482+
PropModeReplace, (unsigned char *) &v, 1);
482483
}
483484

484485
static inline void

0 commit comments

Comments
 (0)