Skip to content

Commit 81c677f

Browse files
committed
Feature: #183 custom window shader & #193 --no-fading-destroyed-argb
- Add --glx-fshader-win, which specifies a custom fragment shader for painting windows. compton-default-fshader-win.glsl is the shader with default behavior, and compton-fake-transparency-fshader-win.glsl provides a template of fake transparency. (#183) - Add --force-win-blend to force all windows to be painted with blending. - Add --no-fading-destroyed-argb, as a workaround of bugs in some WMs. (#193)
1 parent bb55706 commit 81c677f

7 files changed

+384
-100
lines changed

compton-default-fshader-win.glsl

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
uniform float opacity;
2+
uniform bool invert_color;
3+
uniform sampler2D tex;
4+
5+
void main() {
6+
vec4 c = texture2D(tex, gl_TexCoord[0]);
7+
if (invert_color)
8+
c = vec4(vec3(c.a, c.a, c.a) - vec3(c), c.a);
9+
c *= opacity;
10+
gl_FragColor = c;
11+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
uniform float opacity;
2+
uniform bool invert_color;
3+
uniform sampler2D tex;
4+
5+
void main() {
6+
vec4 c = texture2D(tex, gl_TexCoord[0]);
7+
{
8+
// Change vec4(1.0, 1.0, 1.0, 1.0) to your desired color
9+
vec4 vdiff = abs(vec4(1.0, 1.0, 1.0, 1.0) - c);
10+
float diff = max(max(max(vdiff.r, vdiff.g), vdiff.b), vdiff.a);
11+
// Change 0.8 to your desired opacity
12+
if (diff < 0.001)
13+
c *= 0.8;
14+
}
15+
if (invert_color)
16+
c = vec4(vec3(c.a, c.a, c.a) - vec3(c), c.a);
17+
c *= opacity;
18+
gl_FragColor = c;
19+
}

compton.sample.conf

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ fading = true;
4848
fade-in-step = 0.03;
4949
fade-out-step = 0.03;
5050
# no-fading-openclose = true;
51+
# no-fading-destroyed-argb = true;
5152
fade-exclude = [ ];
5253

5354
# Other
@@ -84,5 +85,5 @@ glx-swap-method = "undefined";
8485
# Window type settings
8586
wintypes:
8687
{
87-
tooltip = { fade = true; shadow = false; opacity = 0.75; focus = true; };
88+
tooltip = { fade = true; shadow = true; opacity = 0.75; focus = true; };
8889
};

src/common.h

+69-7
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,25 @@ typedef struct {
469469
/// Height of the textures.
470470
int height;
471471
} glx_blur_cache_t;
472+
473+
typedef struct {
474+
/// GLSL program.
475+
GLuint prog;
476+
/// Location of uniform "opacity" in window GLSL program.
477+
GLint unifm_opacity;
478+
/// Location of uniform "invert_color" in blur GLSL program.
479+
GLint unifm_invert_color;
480+
/// Location of uniform "tex" in window GLSL program.
481+
GLint unifm_tex;
482+
} glx_prog_main_t;
483+
484+
#define GLX_PROG_MAIN_INIT { \
485+
.prog = 0, \
486+
.unifm_opacity = -1, \
487+
.unifm_invert_color = -1, \
488+
.unifm_tex = -1, \
489+
}
490+
472491
#endif
473492

474493
typedef struct {
@@ -536,17 +555,21 @@ typedef struct _options_t {
536555
int glx_swap_method;
537556
/// Whether to use GL_EXT_gpu_shader4 to (hopefully) accelerates blurring.
538557
bool glx_use_gpushader4;
539-
/// Whether to try to detect WM windows and mark them as focused.
540-
bool mark_wmwin_focused;
541-
/// Whether to mark override-redirect windows as focused.
542-
bool mark_ovredir_focused;
558+
/// Custom fragment shader for painting windows, as a string.
559+
char *glx_fshader_win_str;
560+
#ifdef CONFIG_VSYNC_OPENGL_GLSL
561+
/// Custom GLX program used for painting window.
562+
glx_prog_main_t glx_prog_win;
563+
#endif
543564
/// Whether to fork to background.
544565
bool fork_after_register;
545566
/// Whether to detect rounded corners.
546567
bool detect_rounded_corners;
547568
/// Whether to paint on X Composite overlay window instead of root
548569
/// window.
549570
bool paint_on_overlay;
571+
/// Force painting of window content with blending.
572+
bool force_win_blend;
550573
/// Resize damage for a specific number of pixels.
551574
int resize_damage;
552575
/// Whether to unredirect all windows if a full-screen opaque window
@@ -622,6 +645,8 @@ typedef struct _options_t {
622645
time_ms_t fade_delta;
623646
/// Whether to disable fading on window open/close.
624647
bool no_fading_openclose;
648+
/// Whether to disable fading on ARGB managed destroyed windows.
649+
bool no_fading_destroyed_argb;
625650
/// Fading blacklist. A linked list of conditions.
626651
c2_lptr_t *fade_blacklist;
627652

@@ -672,6 +697,10 @@ typedef struct _options_t {
672697
// === Focus related ===
673698
/// Consider windows of specific types to be always focused.
674699
bool wintype_focus[NUM_WINTYPES];
700+
/// Whether to try to detect WM windows and mark them as focused.
701+
bool mark_wmwin_focused;
702+
/// Whether to mark override-redirect windows as focused.
703+
bool mark_ovredir_focused;
675704
/// Whether to use EWMH _NET_ACTIVE_WINDOW to find active window.
676705
bool use_ewmh_active_win;
677706
/// A list of windows always to be considered focused.
@@ -1965,6 +1994,14 @@ win_is_fullscreen(session_t *ps, const win *w) {
19651994
&& (!w->bounding_shaped || w->rounded_corners);
19661995
}
19671996

1997+
/**
1998+
* Check if a window will be painted solid.
1999+
*/
2000+
static inline bool
2001+
win_is_solid(session_t *ps, const win *w) {
2002+
return WMODE_SOLID == w->mode && !ps->o.force_win_blend;
2003+
}
2004+
19682005
/**
19692006
* Determine if a window has a specific property.
19702007
*
@@ -2073,6 +2110,13 @@ glx_on_root_change(session_t *ps);
20732110
bool
20742111
glx_init_blur(session_t *ps);
20752112

2113+
#ifdef CONFIG_VSYNC_OPENGL_GLSL
2114+
bool
2115+
glx_load_prog_main(session_t *ps,
2116+
const char *vshader_str, const char *fshader_str,
2117+
glx_prog_main_t *pprogram);
2118+
#endif
2119+
20762120
bool
20772121
glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, Pixmap pixmap,
20782122
unsigned width, unsigned height, unsigned depth);
@@ -2108,10 +2152,24 @@ glx_dim_dst(session_t *ps, int dx, int dy, int width, int height, float z,
21082152
GLfloat factor, XserverRegion reg_tgt, const reg_data_t *pcache_reg);
21092153

21102154
bool
2111-
glx_render(session_t *ps, const glx_texture_t *ptex,
2155+
glx_render_(session_t *ps, const glx_texture_t *ptex,
21122156
int x, int y, int dx, int dy, int width, int height, int z,
2113-
double opacity, bool neg,
2114-
XserverRegion reg_tgt, const reg_data_t *pcache_reg);
2157+
double opacity, bool argb, bool neg,
2158+
XserverRegion reg_tgt, const reg_data_t *pcache_reg
2159+
#ifdef CONFIG_VSYNC_OPENGL_GLSL
2160+
, const glx_prog_main_t *pprogram
2161+
#endif
2162+
);
2163+
2164+
#ifdef CONFIG_VSYNC_OPENGL_GLSL
2165+
#define \
2166+
glx_render(ps, ptex, x, y, dx, dy, width, height, z, opacity, argb, neg, reg_tgt, pcache_reg, pprogram) \
2167+
glx_render_(ps, ptex, x, y, dx, dy, width, height, z, opacity, argb, neg, reg_tgt, pcache_reg, pprogram)
2168+
#else
2169+
#define \
2170+
glx_render(ps, ptex, x, y, dx, dy, width, height, z, opacity, argb, neg, reg_tgt, pcache_reg, pprogram) \
2171+
glx_render_(ps, ptex, x, y, dx, dy, width, height, z, opacity, argb, neg, reg_tgt, pcache_reg)
2172+
#endif
21152173

21162174
void
21172175
glx_swap_copysubbuffermesa(session_t *ps, XserverRegion reg);
@@ -2122,6 +2180,10 @@ glx_create_shader(GLenum shader_type, const char *shader_str);
21222180

21232181
GLuint
21242182
glx_create_program(const GLuint * const shaders, int nshaders);
2183+
2184+
GLuint
2185+
glx_create_program_from_str(const char *vert_shader_str,
2186+
const char *frag_shader_str);
21252187
#endif
21262188

21272189
/**

0 commit comments

Comments
 (0)