From d9fb47a3a846464a5e7c4fa1c6674b97066721a2 Mon Sep 17 00:00:00 2001 From: chenyc Date: Sun, 12 Jun 2022 01:08:08 +0800 Subject: [PATCH 1/3] animation: add animation exclude --- src/config.c | 4 +++- src/config.h | 2 ++ src/config_libconfig.c | 2 ++ src/options.c | 8 ++++++++ src/picom.c | 1 + src/win.c | 23 +++++++++++++++++++---- src/win.h | 3 +++ 7 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/config.c b/src/config.c index 3225d8c49e..5b81e52226 100644 --- a/src/config.c +++ b/src/config.c @@ -610,7 +610,9 @@ char *parse_config(options_t *opt, const char *config_file, bool *shadow_enable, .track_leader = false, - .rounded_corners_blacklist = NULL + .rounded_corners_blacklist = NULL, + + .animation_blacklist = NULL }; // clang-format on diff --git a/src/config.h b/src/config.h index 234ccfd5fb..6336a532e4 100644 --- a/src/config.h +++ b/src/config.h @@ -199,6 +199,8 @@ typedef struct options { bool animation_clamping; /// TODO: window animation blacklist /// TODO: open/close animations + /// Animation blacklist. A linked list of conditions. + c2_lptr_t *animation_blacklist; // === Opacity === /// Default opacity for inactive windows. diff --git a/src/config_libconfig.c b/src/config_libconfig.c index 181c7a0aee..cc89da0ed7 100644 --- a/src/config_libconfig.c +++ b/src/config_libconfig.c @@ -558,6 +558,8 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad config_lookup_float(&cfg, "animation-dampening", &opt->animation_dampening); // --animation-clamping lcfg_lookup_bool(&cfg, "animation-clamping", &opt->animation_clamping); + // --animations-exclude + parse_cfg_condlst(&cfg, &opt->animation_blacklist, "animation-exclude"); // --focus-exclude parse_cfg_condlst(&cfg, &opt->focus_blacklist, "focus-exclude"); // --invert-color-include diff --git a/src/options.c b/src/options.c index 36f511c094..ff5ea8cb5c 100644 --- a/src/options.c +++ b/src/options.c @@ -98,6 +98,9 @@ static void usage(const char *argv0, int ret) { "--animation-clamping\n" " Whether to clamp animations (default: true)\n" "\n" + "--animation-exclude condition\n" + " Exclude conditions for animation.\n" + "\n" "-i opacity\n" " Opacity of inactive windows. (0.1 - 1.0)\n" "\n" @@ -924,6 +927,11 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable, } break; } + case 811: { + // --animation-exclude + condlst_add(&opt->animation_blacklist, optarg); + break; + } default: usage(argv[0], 1); break; #undef P_CASEBOOL } diff --git a/src/picom.c b/src/picom.c index 3467e24d44..7794961d08 100644 --- a/src/picom.c +++ b/src/picom.c @@ -1980,6 +1980,7 @@ static session_t *session_init(int argc, char **argv, Display *dpy, c2_list_postprocess(ps, ps->o.invert_color_list) && c2_list_postprocess(ps, ps->o.opacity_rules) && c2_list_postprocess(ps, ps->o.rounded_corners_blacklist) && + c2_list_postprocess(ps, ps->o.animation_blacklist) && c2_list_postprocess(ps, ps->o.focus_blacklist))) { log_error("Post-processing of conditionals failed, some of your rules " "might not work"); diff --git a/src/win.c b/src/win.c index 5ce9845532..3a9996dc50 100644 --- a/src/win.c +++ b/src/win.c @@ -552,11 +552,8 @@ void win_process_update_flags(session_t *ps, struct managed_win *w) { } // Ignore animations all together if set to none on window type basis - if (ps->o.wintype_option[w->window_type].animation == 0) { - w->g = w->pending_g; - // Update window geometry - } else if (ps->o.animations) { + if (win_should_animation(ps, w)) { if (!was_visible) { // Set window-open animation init_animation(ps, w); @@ -989,6 +986,24 @@ bool win_should_fade(session_t *ps, const struct managed_win *w) { return ps->o.wintype_option[w->window_type].fade; } +/** + * Determine if a window should animation. + */ +bool win_should_animation(session_t *ps, const struct managed_win *w) { + if (!ps->o.animations) { + return false; + } + if (ps->o.wintype_option[w->window_type].animation == 0) { + log_debug("Animation disabled by window_type"); + return false; + } + if (c2_match(ps, w, ps->o.animation_blacklist, NULL)) { + log_debug("Animation disabled by animation_exclude"); + return false; + } + return true; +} + /** * Reread _COMPTON_SHADOW property from a window. * diff --git a/src/win.h b/src/win.h index 432ff66ba4..4bd3efabdb 100644 --- a/src/win.h +++ b/src/win.h @@ -464,6 +464,9 @@ bool win_check_flags_all(struct managed_win *w, uint64_t flags); /// Mark properties as stale for a window void win_set_properties_stale(struct managed_win *w, const xcb_atom_t *prop, int nprops); +/// Determine if a window should animation +bool attr_pure win_should_animation(session_t *ps, const struct managed_win *w); + static inline attr_unused void win_set_property_stale(struct managed_win *w, xcb_atom_t prop) { return win_set_properties_stale(w, (xcb_atom_t[]){prop}, 1); } From aaa0fac57e0e0175736a5609a08c1a9c4dab2602 Mon Sep 17 00:00:00 2001 From: chenyc Date: Sun, 12 Jun 2022 01:40:53 +0800 Subject: [PATCH 2/3] animation: add animation_opacity_min, for reduce flicker --- src/backend/backend.c | 5 +++-- src/config.c | 1 + src/config.h | 2 ++ src/config_libconfig.c | 2 ++ src/options.c | 9 +++++++++ 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/backend/backend.c b/src/backend/backend.c index de3ba6f89f..1739c088a5 100644 --- a/src/backend/backend.c +++ b/src/backend/backend.c @@ -479,8 +479,9 @@ void paint_all_new(session_t *ps, struct managed_win *t, bool ignore_damage) { // Only animate opacity here if we are resizing // a transparent window + double animation_progress_opacity = w->animation_progress > ps->o.animation_opacity_min ? w->animation_progress : ps->o.animation_opacity_min; process_window_for_painting(ps, w, w->win_image, - w->opacity >= 1 ? 1.0 : w->animation_progress, + w->opacity >= 1 ? 1.0 : animation_progress_opacity, ®_bound, ®_visible, ®_paint, ®_paint_in_bound); @@ -489,7 +490,7 @@ void paint_all_new(session_t *ps, struct managed_win *t, bool ignore_damage) { // move so slightly they will keep flickering if (resizing) { process_window_for_painting(ps, w, w->old_win_image, - 1.0 - w->animation_progress, + 1.0 - animation_progress_opacity, ®_bound, ®_visible, ®_paint, ®_paint_in_bound); } diff --git a/src/config.c b/src/config.c index 5b81e52226..bd4b684d3c 100644 --- a/src/config.c +++ b/src/config.c @@ -580,6 +580,7 @@ char *parse_config(options_t *opt, const char *config_file, bool *shadow_enable, .animation_window_mass = 1.0, .animation_dampening = 25, .animation_clamping = true, + .animation_opacity_min = 0.0, .inactive_opacity = 1.0, .inactive_opacity_override = false, diff --git a/src/config.h b/src/config.h index 6336a532e4..97aafcd2b4 100644 --- a/src/config.h +++ b/src/config.h @@ -201,6 +201,8 @@ typedef struct options { /// TODO: open/close animations /// Animation blacklist. A linked list of conditions. c2_lptr_t *animation_blacklist; + /// moveing or resizing animation opacity minim, for reduce flicker + double animation_opacity_min; // === Opacity === /// Default opacity for inactive windows. diff --git a/src/config_libconfig.c b/src/config_libconfig.c index cc89da0ed7..787a5f51b7 100644 --- a/src/config_libconfig.c +++ b/src/config_libconfig.c @@ -560,6 +560,8 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad lcfg_lookup_bool(&cfg, "animation-clamping", &opt->animation_clamping); // --animations-exclude parse_cfg_condlst(&cfg, &opt->animation_blacklist, "animation-exclude"); + // --animation-opacity-min + config_lookup_float(&cfg, "animation-opacity-min", &opt->animation_opacity_min); // --focus-exclude parse_cfg_condlst(&cfg, &opt->focus_blacklist, "focus-exclude"); // --invert-color-include diff --git a/src/options.c b/src/options.c index ff5ea8cb5c..610abba7cb 100644 --- a/src/options.c +++ b/src/options.c @@ -98,6 +98,10 @@ static void usage(const char *argv0, int ret) { "--animation-clamping\n" " Whether to clamp animations (default: true)\n" "\n" + "--animation-opacity-min (default: 0.0).\n" + " Minim Opacity of animation processing.\n" + " If you hope disable animation opacity, you can set this parameter to 1.0.\n" + "\n" "--animation-exclude condition\n" " Exclude conditions for animation.\n" "\n" @@ -932,6 +936,11 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable, condlst_add(&opt->animation_blacklist, optarg); break; } + case 812: { + // --animation-opacity-min + opt->animation_opacity_min = atof(optarg); + break; + } default: usage(argv[0], 1); break; #undef P_CASEBOOL } From db16da3907b2ba540be5a53d0f0e28e2d3b5b705 Mon Sep 17 00:00:00 2001 From: chenyc Date: Sun, 12 Jun 2022 11:51:42 +0800 Subject: [PATCH 3/3] animation: Format some code and Modify some bad English --- src/backend/backend.c | 2 +- src/config.c | 1 - src/config.h | 1 - src/options.c | 3 +-- src/win.c | 6 +++--- src/win.h | 4 ++-- 6 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/backend/backend.c b/src/backend/backend.c index 1739c088a5..cdd8cb73c5 100644 --- a/src/backend/backend.c +++ b/src/backend/backend.c @@ -479,7 +479,7 @@ void paint_all_new(session_t *ps, struct managed_win *t, bool ignore_damage) { // Only animate opacity here if we are resizing // a transparent window - double animation_progress_opacity = w->animation_progress > ps->o.animation_opacity_min ? w->animation_progress : ps->o.animation_opacity_min; + double animation_progress_opacity = w->animation_progress < ps->o.animation_opacity_min ? ps->o.animation_opacity_min : w->animation_progress; process_window_for_painting(ps, w, w->win_image, w->opacity >= 1 ? 1.0 : animation_progress_opacity, ®_bound, ®_visible, diff --git a/src/config.c b/src/config.c index bd4b684d3c..aae357c3af 100644 --- a/src/config.c +++ b/src/config.c @@ -612,7 +612,6 @@ char *parse_config(options_t *opt, const char *config_file, bool *shadow_enable, .track_leader = false, .rounded_corners_blacklist = NULL, - .animation_blacklist = NULL }; // clang-format on diff --git a/src/config.h b/src/config.h index 97aafcd2b4..af53f19004 100644 --- a/src/config.h +++ b/src/config.h @@ -197,7 +197,6 @@ typedef struct options { double animation_dampening; /// Whether to clamp animations bool animation_clamping; - /// TODO: window animation blacklist /// TODO: open/close animations /// Animation blacklist. A linked list of conditions. c2_lptr_t *animation_blacklist; diff --git a/src/options.c b/src/options.c index 610abba7cb..b4052f5832 100644 --- a/src/options.c +++ b/src/options.c @@ -99,8 +99,7 @@ static void usage(const char *argv0, int ret) { " Whether to clamp animations (default: true)\n" "\n" "--animation-opacity-min (default: 0.0).\n" - " Minim Opacity of animation processing.\n" - " If you hope disable animation opacity, you can set this parameter to 1.0.\n" + " Minimum opacity for pixmap blending during window animation.\n" "\n" "--animation-exclude condition\n" " Exclude conditions for animation.\n" diff --git a/src/win.c b/src/win.c index 3a9996dc50..d71694e024 100644 --- a/src/win.c +++ b/src/win.c @@ -553,7 +553,7 @@ void win_process_update_flags(session_t *ps, struct managed_win *w) { // Ignore animations all together if set to none on window type basis // Update window geometry - if (win_should_animation(ps, w)) { + if (win_should_animate(ps, w)) { if (!was_visible) { // Set window-open animation init_animation(ps, w); @@ -987,9 +987,9 @@ bool win_should_fade(session_t *ps, const struct managed_win *w) { } /** - * Determine if a window should animation. + * Determine if a window should animate. */ -bool win_should_animation(session_t *ps, const struct managed_win *w) { +bool win_should_animate(session_t *ps, const struct managed_win *w) { if (!ps->o.animations) { return false; } diff --git a/src/win.h b/src/win.h index 4bd3efabdb..507fe71e95 100644 --- a/src/win.h +++ b/src/win.h @@ -464,8 +464,8 @@ bool win_check_flags_all(struct managed_win *w, uint64_t flags); /// Mark properties as stale for a window void win_set_properties_stale(struct managed_win *w, const xcb_atom_t *prop, int nprops); -/// Determine if a window should animation -bool attr_pure win_should_animation(session_t *ps, const struct managed_win *w); +/// Determine if a window should animate +bool attr_pure win_should_animate(session_t *ps, const struct managed_win *w); static inline attr_unused void win_set_property_stale(struct managed_win *w, xcb_atom_t prop) { return win_set_properties_stale(w, (xcb_atom_t[]){prop}, 1);