From 0a6f48dba236988a89ac764c652e38c6868ccb37 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sat, 10 Nov 2018 12:48:36 +0000 Subject: [PATCH] Support all alpha values Remove alpha_step, and support all 256 alpha values. 1 pixel pictures don't really use that many resources. Signed-off-by: Yuxuan Shui --- compton.sample.conf | 1 - man/compton.1.asciidoc | 3 --- src/common.h | 4 ++-- src/compton.c | 43 +++++++++++++----------------------------- src/config_libconfig.c | 8 +++++--- 5 files changed, 20 insertions(+), 39 deletions(-) diff --git a/compton.sample.conf b/compton.sample.conf index 18f61ff8..03b6b213 100644 --- a/compton.sample.conf +++ b/compton.sample.conf @@ -27,7 +27,6 @@ inactive-opacity = 0.8; # active-opacity = 0.8; frame-opacity = 0.7; inactive-opacity-override = false; -alpha-step = 0.06; # inactive-dim = 0.2; # inactive-dim-fixed = true; # blur-background = true; diff --git a/man/compton.1.asciidoc b/man/compton.1.asciidoc index d2cbb3b0..cfe91016 100644 --- a/man/compton.1.asciidoc +++ b/man/compton.1.asciidoc @@ -148,9 +148,6 @@ OPTIONS *--vsync-aggressive*:: Attempt to send painting request before VBlank and do XFlush() during VBlank. Reported to work pretty terribly. This switch may be lifted out at any moment. -*--alpha-step* 'VALUE':: - X Render backend: Step for pregenerating alpha pictures. (0.01 - 1.0, defaults to 0.03) - *--dbe*:: Enable DBE painting mode, intended to use with VSync to (hopefully) eliminate tearing. Reported to have no effect, though. diff --git a/src/common.h b/src/common.h index 058a6f68..f91e3a32 100644 --- a/src/common.h +++ b/src/common.h @@ -62,6 +62,8 @@ #define DEBUG_BACKTRACE 1 #endif +#define MAX_ALPHA (255) + // === Includes === // For some special functions @@ -582,8 +584,6 @@ typedef struct options_t { /// Whether to detect _NET_WM_OPACITY on client windows. Used on window /// managers that don't pass _NET_WM_OPACITY to frame windows. bool detect_client_opacity; - /// Step for pregenerating alpha pictures. 0.01 - 1.0. - double alpha_step; // === Other window processing === /// Whether to blur background of semi-transparent / ARGB windows. diff --git a/src/compton.c b/src/compton.c index 9b1b2b31..7d0c5b50 100644 --- a/src/compton.c +++ b/src/compton.c @@ -324,12 +324,6 @@ resize_region(session_t *ps, region_t *region, short mod) { free(newrects); } -static inline int -get_alpha_step(session_t *ps, opacity_t o) { - double d = ((double) o) / OPAQUE; - return (int)(round(normalize_d(d) / ps->o.alpha_step)); -} - static inline void __attribute__((nonnull(1, 2))) set_tgt_clip(session_t *ps, region_t *reg) { @@ -1288,7 +1282,7 @@ paint_preprocess(session_t *ps, win *list) { || w->g.x + w->g.width < 1 || w->g.y + w->g.height < 1 || w->g.x >= ps->root_width || w->g.y >= ps->root_height || ((w->a.map_state == XCB_MAP_STATE_UNMAPPED || w->destroyed) && !w->paint.pixmap) - || get_alpha_step(ps, w->opacity) == 0 + || (double) w->opacity / OPAQUE * MAX_ALPHA < 1 || w->paint_excluded) to_paint = false; //printf_errf("(): %s %d %d %d", w->name, to_paint, w->opacity, w->paint_excluded); @@ -1602,7 +1596,7 @@ render(session_t *ps, int x, int y, int dx, int dy, int wid, int hei, case BKEND_XRENDER: case BKEND_XR_GLX_HYBRID: { - int alpha_step = get_alpha_step(ps, opacity * OPAQUE); + int alpha_step = opacity * MAX_ALPHA; xcb_render_picture_t alpha_pict = ps->alpha_picts[alpha_step]; if (alpha_step != 0) { int op = ((!argb && !alpha_pict) ? XCB_RENDER_PICT_OP_SRC: XCB_RENDER_PICT_OP_OVER); @@ -2011,7 +2005,7 @@ paint_all(session_t *ps, region_t *region, const region_t *region_real, win * co // Next, we set the region of paint and highlight it x_set_picture_clip_region(ps, new_pict, 0, 0, region_real); xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_OVER, ps->white_picture, - ps->alpha_picts[(int)(0.5 / ps->o.alpha_step)], + ps->alpha_picts[MAX_ALPHA / 2], new_pict, 0, 0, 0, 0, 0, 0, ps->root_width, ps->root_height); @@ -3502,10 +3496,6 @@ usage(int ret) { " Attempt to send painting request before VBlank and do XFlush()\n" " during VBlank. This switch may be lifted out at any moment.\n" "\n" - "--alpha-step val\n" - " X Render backend: Step for pregenerating alpha pictures. \n" - " 0.01 - 1.0. Defaults to 0.03.\n" - "\n" "--paint-on-overlay\n" " Painting on X Composite overlay window.\n" "\n" @@ -4109,13 +4099,15 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) { break; case 271: // --alpha-step - ps->o.alpha_step = atof(optarg); + printf_errf("(): --alpha-step has been removed, compton now tries to make use" + " of all alpha values"); break; case 272: printf_errf("(): use of --dbe is deprecated"); break; case 273: - printf_errf("(): --paint-on-overlay is removed, and is enabled when possible"); + printf_errf("(): --paint-on-overlay has been removed, and is enabled when " + "possible"); break; P_CASEBOOL(274, sw_opti); P_CASEBOOL(275, vsync_aggressive); @@ -4255,7 +4247,6 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) { 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); - ps->o.alpha_step = normalize_d_range(ps->o.alpha_step, 0.01, 1.0); if (shadow_enable) wintype_arr_enable(ps->o.wintype_shadow); @@ -4689,18 +4680,12 @@ vsync_deinit(session_t *ps) { */ static void init_alpha_picts(session_t *ps) { - int i; - int num = round(1.0 / ps->o.alpha_step) + 1; + ps->alpha_picts = malloc(sizeof(xcb_render_picture_t) * (MAX_ALPHA+1)); - ps->alpha_picts = malloc(sizeof(xcb_render_picture_t) * num); - - for (i = 0; i < num; ++i) { - double o = i * ps->o.alpha_step; - if ((1.0 - o) > ps->o.alpha_step) { - ps->alpha_picts[i] = solid_picture(ps, false, o, 0, 0, 0); - assert(ps->alpha_picts[i] != None); - } else - ps->alpha_picts[i] = None; + for (int i = 0; i <= MAX_ALPHA; ++i) { + double o = (double) i / MAX_ALPHA; + ps->alpha_picts[i] = solid_picture(ps, false, o, 0, 0, 0); + assert(ps->alpha_picts[i] != None); } } @@ -5106,7 +5091,6 @@ session_init(session_t *ps_old, int argc, char **argv) { .active_opacity = OPAQUE, .frame_opacity = 1.0, .detect_client_opacity = false, - .alpha_step = 0.03, .blur_background = false, .blur_background_frame = false, @@ -5635,8 +5619,7 @@ session_destroy(session_t *ps) { // Free alpha_picts { - const int max = round(1.0 / ps->o.alpha_step) + 1; - for (int i = 0; i < max; ++i) + for (int i = 0; i <= MAX_ALPHA; ++i) free_picture(ps, &ps->alpha_picts[i]); free(ps->alpha_picts); ps->alpha_picts = NULL; diff --git a/src/config_libconfig.c b/src/config_libconfig.c index f29a8786..673b2e0b 100644 --- a/src/config_libconfig.c +++ b/src/config_libconfig.c @@ -295,8 +295,6 @@ parse_config(session_t *ps, struct options_tmp *pcfgtmp) { // --backend if (config_lookup_string(&cfg, "backend", &sval) && !parse_backend(ps, sval)) exit(1); - // --alpha-step - config_lookup_float(&cfg, "alpha-step", &ps->o.alpha_step); // --sw-opti lcfg_lookup_bool(&cfg, "sw-opti", &ps->o.sw_opti); // --use-ewmh-active-win @@ -365,8 +363,12 @@ parse_config(session_t *ps, struct options_tmp *pcfgtmp) { printf_errf("(): \"paint-on-overlay\" has been removed as an option, and " "is enabled whenever possible"); + if (config_lookup_float(&cfg, "alpha-step", &dval)) + printf_errf("(): \"alpha-step\" has been removed, compton now tries to make use" + " of all alpha values"); + const char *deprecation_message = "has been removed. If you encounter problems " - "without this feature, please feel free to open a bug report."; + "without this feature, please feel free to open a bug report"; if (lcfg_lookup_bool(&cfg, "glx-use-copysubbuffermesa", &bval) && bval) printf_errf("(): \"glx-use-copysubbuffermesa\" %s", deprecation_message); if (lcfg_lookup_bool(&cfg, "glx-copy-from-front", &bval) && bval)