Skip to content

Commit

Permalink
Feature: yshui#183 custom window shader & yshui#193 --no-fading-destr…
Browse files Browse the repository at this point in the history
…oyed-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. (yshui#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.
  (yshui#193)
  • Loading branch information
richardgv committed May 16, 2014
1 parent bb55706 commit 81c677f
Show file tree
Hide file tree
Showing 7 changed files with 384 additions and 100 deletions.
11 changes: 11 additions & 0 deletions compton-default-fshader-win.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
uniform float opacity;
uniform bool invert_color;
uniform sampler2D tex;

void main() {
vec4 c = texture2D(tex, gl_TexCoord[0]);
if (invert_color)
c = vec4(vec3(c.a, c.a, c.a) - vec3(c), c.a);
c *= opacity;
gl_FragColor = c;
}
19 changes: 19 additions & 0 deletions compton-fake-transparency-fshader-win.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
uniform float opacity;
uniform bool invert_color;
uniform sampler2D tex;

void main() {
vec4 c = texture2D(tex, gl_TexCoord[0]);
{
// Change vec4(1.0, 1.0, 1.0, 1.0) to your desired color
vec4 vdiff = abs(vec4(1.0, 1.0, 1.0, 1.0) - c);
float diff = max(max(max(vdiff.r, vdiff.g), vdiff.b), vdiff.a);
// Change 0.8 to your desired opacity
if (diff < 0.001)
c *= 0.8;
}
if (invert_color)
c = vec4(vec3(c.a, c.a, c.a) - vec3(c), c.a);
c *= opacity;
gl_FragColor = c;
}
3 changes: 2 additions & 1 deletion compton.sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fading = true;
fade-in-step = 0.03;
fade-out-step = 0.03;
# no-fading-openclose = true;
# no-fading-destroyed-argb = true;
fade-exclude = [ ];

# Other
Expand Down Expand Up @@ -84,5 +85,5 @@ glx-swap-method = "undefined";
# Window type settings
wintypes:
{
tooltip = { fade = true; shadow = false; opacity = 0.75; focus = true; };
tooltip = { fade = true; shadow = true; opacity = 0.75; focus = true; };
};
76 changes: 69 additions & 7 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,25 @@ typedef struct {
/// Height of the textures.
int height;
} glx_blur_cache_t;

typedef struct {
/// GLSL program.
GLuint prog;
/// Location of uniform "opacity" in window GLSL program.
GLint unifm_opacity;
/// Location of uniform "invert_color" in blur GLSL program.
GLint unifm_invert_color;
/// Location of uniform "tex" in window GLSL program.
GLint unifm_tex;
} glx_prog_main_t;

#define GLX_PROG_MAIN_INIT { \
.prog = 0, \
.unifm_opacity = -1, \
.unifm_invert_color = -1, \
.unifm_tex = -1, \
}

#endif

typedef struct {
Expand Down Expand Up @@ -536,17 +555,21 @@ typedef struct _options_t {
int glx_swap_method;
/// Whether to use GL_EXT_gpu_shader4 to (hopefully) accelerates blurring.
bool glx_use_gpushader4;
/// Whether to try to detect WM windows and mark them as focused.
bool mark_wmwin_focused;
/// Whether to mark override-redirect windows as focused.
bool mark_ovredir_focused;
/// Custom fragment shader for painting windows, as a string.
char *glx_fshader_win_str;
#ifdef CONFIG_VSYNC_OPENGL_GLSL
/// Custom GLX program used for painting window.
glx_prog_main_t glx_prog_win;
#endif
/// Whether to fork to background.
bool fork_after_register;
/// Whether to detect rounded corners.
bool detect_rounded_corners;
/// Whether to paint on X Composite overlay window instead of root
/// window.
bool paint_on_overlay;
/// Force painting of window content with blending.
bool force_win_blend;
/// Resize damage for a specific number of pixels.
int resize_damage;
/// Whether to unredirect all windows if a full-screen opaque window
Expand Down Expand Up @@ -622,6 +645,8 @@ typedef struct _options_t {
time_ms_t fade_delta;
/// Whether to disable fading on window open/close.
bool no_fading_openclose;
/// Whether to disable fading on ARGB managed destroyed windows.
bool no_fading_destroyed_argb;
/// Fading blacklist. A linked list of conditions.
c2_lptr_t *fade_blacklist;

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

/**
* Check if a window will be painted solid.
*/
static inline bool
win_is_solid(session_t *ps, const win *w) {
return WMODE_SOLID == w->mode && !ps->o.force_win_blend;
}

/**
* Determine if a window has a specific property.
*
Expand Down Expand Up @@ -2073,6 +2110,13 @@ glx_on_root_change(session_t *ps);
bool
glx_init_blur(session_t *ps);

#ifdef CONFIG_VSYNC_OPENGL_GLSL
bool
glx_load_prog_main(session_t *ps,
const char *vshader_str, const char *fshader_str,
glx_prog_main_t *pprogram);
#endif

bool
glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, Pixmap pixmap,
unsigned width, unsigned height, unsigned depth);
Expand Down Expand Up @@ -2108,10 +2152,24 @@ glx_dim_dst(session_t *ps, int dx, int dy, int width, int height, float z,
GLfloat factor, XserverRegion reg_tgt, const reg_data_t *pcache_reg);

bool
glx_render(session_t *ps, const glx_texture_t *ptex,
glx_render_(session_t *ps, const glx_texture_t *ptex,
int x, int y, int dx, int dy, int width, int height, int z,
double opacity, bool neg,
XserverRegion reg_tgt, const reg_data_t *pcache_reg);
double opacity, bool argb, bool neg,
XserverRegion reg_tgt, const reg_data_t *pcache_reg
#ifdef CONFIG_VSYNC_OPENGL_GLSL
, const glx_prog_main_t *pprogram
#endif
);

#ifdef CONFIG_VSYNC_OPENGL_GLSL
#define \
glx_render(ps, ptex, x, y, dx, dy, width, height, z, opacity, argb, neg, reg_tgt, pcache_reg, pprogram) \
glx_render_(ps, ptex, x, y, dx, dy, width, height, z, opacity, argb, neg, reg_tgt, pcache_reg, pprogram)
#else
#define \
glx_render(ps, ptex, x, y, dx, dy, width, height, z, opacity, argb, neg, reg_tgt, pcache_reg, pprogram) \
glx_render_(ps, ptex, x, y, dx, dy, width, height, z, opacity, argb, neg, reg_tgt, pcache_reg)
#endif

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

GLuint
glx_create_program(const GLuint * const shaders, int nshaders);

GLuint
glx_create_program_from_str(const char *vert_shader_str,
const char *frag_shader_str);
#endif

/**
Expand Down
Loading

0 comments on commit 81c677f

Please sign in to comment.