Skip to content

Commit

Permalink
Reset blend string for Shell.GLSLEffect
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yilozt committed Oct 15, 2022
1 parent acfa989 commit d21aef7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 10 additions & 1 deletion src/effect/rounded_corners_effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions src/effect/shader/rounded_corners.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit d21aef7

Please sign in to comment.