From d21aef7768f0b13798847106fd30a9cf9484322f Mon Sep 17 00:00:00 2001 From: Luo Yi Date: Fri, 14 Oct 2022 22:46:43 +0800 Subject: [PATCH] Reset blend string for Shell.GLSLEffect GLSLEffect change default blend string from Cogl.OffscreenEffect, it will make window become grey when try to change it's opacity. Also this commit can fix #67, when using gnome-screenshots or builtin tools to teke screenshots, it will not have transparent part. --- src/effect/rounded_corners_effect.ts | 11 ++++++++++- src/effect/shader/rounded_corners.frag | 11 ++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/effect/rounded_corners_effect.ts b/src/effect/rounded_corners_effect.ts index d5a6d01..c219aa3 100644 --- a/src/effect/rounded_corners_effect.ts +++ b/src/effect/rounded_corners_effect.ts @@ -8,8 +8,9 @@ import * as types from '@me/utils/types' // types import { Me } from '@global' +import { PaintContext, PaintNode } from '@gi/Clutter' -// -------------------------------------------------------------- [end imports] +// --------------------------------------------------------------- [end imports] // Load fragment shader of rounded corners effect. const { declarations, code } = loadShader ( @@ -65,6 +66,14 @@ export const RoundedCornersEffect = registerClass ( this._init_uniforms () } + vfunc_paint_target (node: PaintNode, ctx: PaintContext) { + // Reset to default blend string. + this.get_pipeline ()?.set_blend ( + 'RGBA = ADD(SRC_COLOR, DST_COLOR*(1-SRC_COLOR[A]))' + ) + super.vfunc_paint_target (node, ctx) + } + /** * Used to update uniform variants of shader * @param corners_cfg - Rounded corners settings of window diff --git a/src/effect/shader/rounded_corners.frag b/src/effect/shader/rounded_corners.frag index 3efb000..da9a0e1 100644 --- a/src/effect/shader/rounded_corners.frag +++ b/src/effect/shader/rounded_corners.frag @@ -97,20 +97,13 @@ void main() { float outer_alpha = rounded_rect_coverage(texture_coord, bounds, radius, exponent); // Clip window corners first - cogl_color_out.a *= outer_alpha; + cogl_color_out *= outer_alpha; // Draw border later if(border_width > 0.9 || border_width < -0.9) { float inner_alpha = rounded_rect_coverage(texture_coord, inner_bounds, inner_radius, exponent); float border_alpha = clamp(abs(outer_alpha - inner_alpha), 0.0, 1.0); - if (border_width > 0.9) { - // If border is drawing inside window, mix color of window - cogl_color_out = mix(cogl_color_out, vec4(border_color.rgb, 1.0), border_alpha * border_color.a); - cogl_color_out.a *= outer_alpha; - } else { - // If border is drawing outside window, just draw border - cogl_color_out = mix(cogl_color_out, border_color, border_alpha); - } + cogl_color_out = mix(cogl_color_out, vec4(border_color.rgb, 1.0), border_alpha * border_color.a); } }