Merge pull request #48 from yshui/alpha-step

Support all alpha values
This commit is contained in:
yshui 2018-11-19 12:44:13 +00:00 committed by GitHub
commit b86f47e965
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 39 deletions

View File

@ -27,7 +27,6 @@ inactive-opacity = 0.8;
# active-opacity = 0.8; # active-opacity = 0.8;
frame-opacity = 0.7; frame-opacity = 0.7;
inactive-opacity-override = false; inactive-opacity-override = false;
alpha-step = 0.06;
# inactive-dim = 0.2; # inactive-dim = 0.2;
# inactive-dim-fixed = true; # inactive-dim-fixed = true;
# blur-background = true; # blur-background = true;

View File

@ -148,9 +148,6 @@ OPTIONS
*--vsync-aggressive*:: *--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. 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*:: *--dbe*::
Enable DBE painting mode, intended to use with VSync to (hopefully) eliminate tearing. Reported to have no effect, though. Enable DBE painting mode, intended to use with VSync to (hopefully) eliminate tearing. Reported to have no effect, though.

View File

@ -62,6 +62,8 @@
#define DEBUG_BACKTRACE 1 #define DEBUG_BACKTRACE 1
#endif #endif
#define MAX_ALPHA (255)
// === Includes === // === Includes ===
// For some special functions // For some special functions
@ -582,8 +584,6 @@ typedef struct options_t {
/// Whether to detect _NET_WM_OPACITY on client windows. Used on window /// Whether to detect _NET_WM_OPACITY on client windows. Used on window
/// managers that don't pass _NET_WM_OPACITY to frame windows. /// managers that don't pass _NET_WM_OPACITY to frame windows.
bool detect_client_opacity; bool detect_client_opacity;
/// Step for pregenerating alpha pictures. 0.01 - 1.0.
double alpha_step;
// === Other window processing === // === Other window processing ===
/// Whether to blur background of semi-transparent / ARGB windows. /// Whether to blur background of semi-transparent / ARGB windows.

View File

@ -324,12 +324,6 @@ resize_region(session_t *ps, region_t *region, short mod) {
free(newrects); 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 static inline void
__attribute__((nonnull(1, 2))) __attribute__((nonnull(1, 2)))
set_tgt_clip(session_t *ps, region_t *reg) { 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 + w->g.width < 1 || w->g.y + w->g.height < 1
|| w->g.x >= ps->root_width || w->g.y >= ps->root_height || 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) || ((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) || w->paint_excluded)
to_paint = false; to_paint = false;
//printf_errf("(): %s %d %d %d", w->name, to_paint, w->opacity, w->paint_excluded); //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_XRENDER:
case BKEND_XR_GLX_HYBRID: 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]; xcb_render_picture_t alpha_pict = ps->alpha_picts[alpha_step];
if (alpha_step != 0) { if (alpha_step != 0) {
int op = ((!argb && !alpha_pict) ? XCB_RENDER_PICT_OP_SRC: XCB_RENDER_PICT_OP_OVER); 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 // Next, we set the region of paint and highlight it
x_set_picture_clip_region(ps, new_pict, 0, 0, region_real); 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, 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, new_pict, 0, 0, 0, 0, 0, 0,
ps->root_width, ps->root_height); ps->root_width, ps->root_height);
@ -3502,10 +3496,6 @@ usage(int ret) {
" Attempt to send painting request before VBlank and do XFlush()\n" " Attempt to send painting request before VBlank and do XFlush()\n"
" during VBlank. This switch may be lifted out at any moment.\n" " during VBlank. This switch may be lifted out at any moment.\n"
"\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" "--paint-on-overlay\n"
" Painting on X Composite overlay window.\n" " Painting on X Composite overlay window.\n"
"\n" "\n"
@ -4109,13 +4099,15 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
break; break;
case 271: case 271:
// --alpha-step // --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; break;
case 272: case 272:
printf_errf("(): use of --dbe is deprecated"); printf_errf("(): use of --dbe is deprecated");
break; break;
case 273: 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; break;
P_CASEBOOL(274, sw_opti); P_CASEBOOL(274, sw_opti);
P_CASEBOOL(275, vsync_aggressive); 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); ps->o.shadow_opacity = normalize_d(ps->o.shadow_opacity);
cfgtmp.menu_opacity = normalize_d(cfgtmp.menu_opacity); cfgtmp.menu_opacity = normalize_d(cfgtmp.menu_opacity);
ps->o.refresh_rate = normalize_i_range(ps->o.refresh_rate, 0, 300); 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) if (shadow_enable)
wintype_arr_enable(ps->o.wintype_shadow); wintype_arr_enable(ps->o.wintype_shadow);
@ -4689,18 +4680,12 @@ vsync_deinit(session_t *ps) {
*/ */
static void static void
init_alpha_picts(session_t *ps) { init_alpha_picts(session_t *ps) {
int i; ps->alpha_picts = malloc(sizeof(xcb_render_picture_t) * (MAX_ALPHA+1));
int num = round(1.0 / ps->o.alpha_step) + 1;
ps->alpha_picts = malloc(sizeof(xcb_render_picture_t) * num); for (int i = 0; i <= MAX_ALPHA; ++i) {
double o = (double) i / MAX_ALPHA;
for (i = 0; i < num; ++i) { ps->alpha_picts[i] = solid_picture(ps, false, o, 0, 0, 0);
double o = i * ps->o.alpha_step; assert(ps->alpha_picts[i] != None);
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;
} }
} }
@ -5106,7 +5091,6 @@ session_init(session_t *ps_old, int argc, char **argv) {
.active_opacity = OPAQUE, .active_opacity = OPAQUE,
.frame_opacity = 1.0, .frame_opacity = 1.0,
.detect_client_opacity = false, .detect_client_opacity = false,
.alpha_step = 0.03,
.blur_background = false, .blur_background = false,
.blur_background_frame = false, .blur_background_frame = false,
@ -5635,8 +5619,7 @@ session_destroy(session_t *ps) {
// Free alpha_picts // Free alpha_picts
{ {
const int max = round(1.0 / ps->o.alpha_step) + 1; for (int i = 0; i <= MAX_ALPHA; ++i)
for (int i = 0; i < max; ++i)
free_picture(ps, &ps->alpha_picts[i]); free_picture(ps, &ps->alpha_picts[i]);
free(ps->alpha_picts); free(ps->alpha_picts);
ps->alpha_picts = NULL; ps->alpha_picts = NULL;

View File

@ -295,8 +295,6 @@ parse_config(session_t *ps, struct options_tmp *pcfgtmp) {
// --backend // --backend
if (config_lookup_string(&cfg, "backend", &sval) && !parse_backend(ps, sval)) if (config_lookup_string(&cfg, "backend", &sval) && !parse_backend(ps, sval))
exit(1); exit(1);
// --alpha-step
config_lookup_float(&cfg, "alpha-step", &ps->o.alpha_step);
// --sw-opti // --sw-opti
lcfg_lookup_bool(&cfg, "sw-opti", &ps->o.sw_opti); lcfg_lookup_bool(&cfg, "sw-opti", &ps->o.sw_opti);
// --use-ewmh-active-win // --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 " printf_errf("(): \"paint-on-overlay\" has been removed as an option, and "
"is enabled whenever possible"); "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 " 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) if (lcfg_lookup_bool(&cfg, "glx-use-copysubbuffermesa", &bval) && bval)
printf_errf("(): \"glx-use-copysubbuffermesa\" %s", deprecation_message); printf_errf("(): \"glx-use-copysubbuffermesa\" %s", deprecation_message);
if (lcfg_lookup_bool(&cfg, "glx-copy-from-front", &bval) && bval) if (lcfg_lookup_bool(&cfg, "glx-copy-from-front", &bval) && bval)