Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

__Compton__ is a compositor for X, and a fork of __xcompmgr-dana__.

This branch includes a new blur method: The multi-pass **dual kawase blur**!
Use it with the `--blur-method kawase` and `--blur-strength LEVEL` options.
Only works with the `glx` backend!

I was frustrated by the low amount of standalone lightweight compositors.
Compton was forked from Dana Jansens' fork of xcompmgr and refactored. I fixed
whatever bug I found, and added features I wanted. Things seem stable, but don't
Expand Down
2 changes: 2 additions & 0 deletions compton.sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ alpha-step = 0.06;
# inactive-dim-fixed = true;
# blur-background = true;
# blur-background-frame = true;
blur-method = "kawase";
# blur-strength = 15;
blur-kern = "3x3box";
# blur-kern = "5,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1";
# blur-background-fixed = true;
Expand Down
10 changes: 10 additions & 0 deletions man/compton.1.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,17 @@ OPTIONS
*--blur-background-fixed*::
Use fixed blur strength rather than adjusting according to window opacity.

*--blur-method* 'ALGORITHM'::
Specify the algorithm for background blur. It is either one of: `convolution` (default), `kawase`.
+
Note: `kawase` only works with the `glx` backend.

*--blur-strength* 'LEVEL'::
Only valid for *--blur-method kawase*!
The strength of the kawase blur as an integer between 1 and 20. Defaults to 5.

*--blur-kern* 'MATRIX'::
Only valid for *--blur-method convolution*!
Specify the blur convolution kernel, with the following format:
+
----
Expand Down
89 changes: 82 additions & 7 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
#define CGLX_MAX_BUFFER_AGE 5

/// @brief Maximum passes for blur.
#define MAX_BLUR_PASS 5
#define MAX_BLUR_PASS 6

// Window flags

Expand Down Expand Up @@ -352,6 +352,13 @@ typedef enum {
NUM_VSYNC,
} vsync_t;

/// Possible background blur algorithms.
enum blur_method {
BLRMTHD_CONV,
BLRMTHD_KAWASE,
NUM_BLRMTHD,
};

/// @brief Possible backends of compton.
enum backend {
BKEND_XRENDER,
Expand Down Expand Up @@ -467,19 +474,25 @@ typedef struct {
GLuint frag_shader;
/// GLSL program for blur.
GLuint prog;
/// Location of uniform "offset_x" in blur GLSL program.
/// Location of uniform "offset_x" in conv-blur GLSL program.
GLint unifm_offset_x;
/// Location of uniform "offset_y" in blur GLSL program.
/// Location of uniform "offset_y" in conv-blur GLSL program.
GLint unifm_offset_y;
/// Location of uniform "factor_center" in blur GLSL program.
/// Location of uniform "factor_center" in conv-blur GLSL program.
GLint unifm_factor_center;
/// Location of uniform "offset" in kawase-blur GLSL program.
GLint unifm_offset;
/// Location of uniform "halfpixel" in kawase-blur GLSL program.
GLint unifm_halfpixel;
/// Location of uniform "fulltex" in kawase-blur GLSL program.
GLint unifm_fulltex;
} glx_blur_pass_t;

typedef struct {
/// Framebuffer used for blurring.
GLuint fbo;
/// Textures used for blurring.
GLuint textures[2];
GLuint textures[MAX_BLUR_PASS];
/// Width of the textures.
int width;
/// Height of the textures.
Expand Down Expand Up @@ -538,6 +551,11 @@ struct _timeout_t;

struct _win;

typedef struct {
int iterations;
float offset;
} blur_strength_t;

typedef struct _c2_lptr c2_lptr_t;

/// Structure representing all options.
Expand Down Expand Up @@ -707,8 +725,12 @@ typedef struct _options_t {
bool blur_background_fixed;
/// Background blur blacklist. A linked list of conditions.
c2_lptr_t *blur_background_blacklist;
/// Blur method.
enum blur_method blur_method;
/// Blur convolution kernel.
XFixed *blur_kerns[MAX_BLUR_PASS];
/// Blur strength.
blur_strength_t blur_strength;
/// How much to dim an inactive window. 0.0 - 1.0, 0 to disable.
double inactive_dim;
/// Whether to use fixed inactive dim opacity, instead of deciding
Expand Down Expand Up @@ -1263,6 +1285,7 @@ typedef enum {
extern const char * const WINTYPES[NUM_WINTYPES];
extern const char * const VSYNC_STRS[NUM_VSYNC + 1];
extern const char * const BACKEND_STRS[NUM_BKEND + 1];
extern const char * const BLUR_METHOD_STRS[NUM_BLRMTHD + 1];
extern session_t *ps_g;

// == Debugging code ==
Expand Down Expand Up @@ -1668,6 +1691,58 @@ parse_vsync(session_t *ps, const char *str) {
return false;
}

/**
* Parse a blur_method option argument.
*/
static inline bool
parse_blur_method(session_t *ps, const char *str) {
for (enum blur_method i = 0; BLUR_METHOD_STRS[i]; ++i)
if (!strcasecmp(str, BLUR_METHOD_STRS[i])) {
ps->o.blur_method = i;
return true;
}

printf_errf("(\"%s\"): Invalid blur_method argument.", str);
return false;
}

/**
* Parse a blur_strength option argument.
*/
static inline bool
parse_blur_strength(session_t *ps, const int level) {
static const blur_strength_t values[20] = {
{ .iterations = 1, .offset = 1.5 }, // 1
{ .iterations = 1, .offset = 2.0 }, // 2
{ .iterations = 2, .offset = 2.5 }, // 3
{ .iterations = 2, .offset = 3.0 }, // 4
{ .iterations = 3, .offset = 2.75 }, // 5
{ .iterations = 3, .offset = 3.5 }, // 6
{ .iterations = 3, .offset = 4.25 }, // 7
{ .iterations = 3, .offset = 5.0 }, // 8
{ .iterations = 4, .offset = 3.71429 }, // 9
{ .iterations = 4, .offset = 4.42857 }, // 10
{ .iterations = 4, .offset = 5.14286 }, // 11
{ .iterations = 4, .offset = 5.85714 }, // 12
{ .iterations = 4, .offset = 6.57143 }, // 13
{ .iterations = 4, .offset = 7.28571 }, // 14
{ .iterations = 4, .offset = 8.0 }, // 15
{ .iterations = 5, .offset = 6.0 }, // 16
{ .iterations = 5, .offset = 7.0 }, // 17
{ .iterations = 5, .offset = 8.0 }, // 18
{ .iterations = 5, .offset = 9.0 }, // 19
{ .iterations = 5, .offset = 10.0 }, // 20
};

if (level < 1 || level > 20) {
printf_errf("(\"%d\"): Invalid blur_strength argument. Needs to be a number between 1 and 20.", level);
return false;
}

ps->o.blur_strength = values[level - 1];
return true;
}

/**
* Parse a backend option argument.
*/
Expand Down Expand Up @@ -2276,8 +2351,8 @@ free_glx_fbo(session_t *ps, GLuint *pfbo) {
*/
static inline void
free_glx_bc_resize(session_t *ps, glx_blur_cache_t *pbc) {
free_texture_r(ps, &pbc->textures[0]);
free_texture_r(ps, &pbc->textures[1]);
for (int i = 0; i < MAX_BLUR_PASS; i++)
free_texture_r(ps, &pbc->textures[i]);
pbc->width = 0;
pbc->height = 0;
}
Expand Down
46 changes: 45 additions & 1 deletion src/compton.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ const char * const VSYNC_STRS[NUM_VSYNC + 1] = {
NULL
};

/// Names of blur_methods.
const char * const BLUR_METHOD_STRS[NUM_BLRMTHD + 1] = {
"convolution", // BLRMTHD_CONV
"kawase", // BLRMTHD_KAWASE
NULL
};

/// Names of backends.
const char * const BACKEND_STRS[NUM_BKEND + 1] = {
"xrender", // BKEND_XRENDER
Expand Down Expand Up @@ -4699,7 +4706,16 @@ usage(int ret) {
" Use fixed blur strength instead of adjusting according to window\n"
" opacity.\n"
"\n"
"--blur-method algorithm\n"
" Specify the algorithm for background blur. It is either one of:\n"
" convolution (default), kawase\n"
"\n"
"--blur-strength level\n"
" Only valid for '--blur-method kawase'!\n"
" The strength of the kawase blur as an integer between 1 and 20. Defaults to 5.\n"
"\n"
"--blur-kern matrix\n"
" Only valid for '--blur-method convolution'!\n"
" Specify the blur convolution kernel, with the following format:\n"
" WIDTH,HEIGHT,ELE1,ELE2,ELE3,ELE4,ELE5...\n"
" The element in the center must not be included, it will be forever\n"
Expand Down Expand Up @@ -5618,6 +5634,14 @@ parse_config(session_t *ps, struct options_tmp *pcfgtmp) {
// --blur-background-fixed
lcfg_lookup_bool(&cfg, "blur-background-fixed",
&ps->o.blur_background_fixed);
// --blur-method
if (config_lookup_string(&cfg, "blur-method", &sval)
&& !parse_blur_method(ps, sval))
exit(1);
// --blur-strength
if (lcfg_lookup_int(&cfg, "blur-strength", &ival)
&& !parse_blur_strength(ps, ival))
exit(1);
// --blur-kern
if (config_lookup_string(&cfg, "blur-kern", &sval)
&& !parse_conv_kern_lst(ps, sval, ps->o.blur_kerns, MAX_BLUR_PASS))
Expand Down Expand Up @@ -5756,6 +5780,8 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
{ "version", no_argument, NULL, 318 },
{ "no-x-selection", no_argument, NULL, 319 },
{ "no-name-pixmap", no_argument, NULL, 320 },
{ "blur-method", required_argument, NULL, 321 },
{ "blur-strength", required_argument, NULL, 322 },
{ "reredir-on-root-change", no_argument, NULL, 731 },
{ "glx-reinit-on-root-change", no_argument, NULL, 732 },
// Must terminate with a NULL entry
Expand Down Expand Up @@ -6027,6 +6053,16 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
ps->o.glx_fshader_win_str = mstrcpy(optarg);
break;
P_CASEBOOL(319, no_x_selection);
case 321:
// --blur-method
if (!parse_blur_method(ps, optarg))
exit(1);
break;
case 322:
// --blur-strength
if (!parse_blur_strength(ps, strtol(optarg, NULL, 0)))
exit(1);
break;
P_CASEBOOL(731, reredir_on_root_change);
P_CASEBOOL(732, glx_reinit_on_root_change);
default:
Expand Down Expand Up @@ -6091,8 +6127,14 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
ps->o.track_leader = true;
}

// Blur method kawase is not compatible with the xrender backend
if (ps->o.backend != BKEND_GLX && ps->o.blur_method == BLRMTHD_KAWASE) {
printf_errf("(): Blur method 'kawase' is incompatible with the XRender backend. Fall back to default.\n");
ps->o.blur_method = BLRMTHD_CONV;
}

// Fill default blur kernel
if (ps->o.blur_background && !ps->o.blur_kerns[0]) {
if (ps->o.blur_background && (BLRMTHD_CONV == ps->o.blur_method) && !ps->o.blur_kerns[0]) {
// Convolution filter parameter (box blur)
// gaussian or binomial filters are definitely superior, yet looks
// like they aren't supported as of xorg-server-1.13.0
Expand Down Expand Up @@ -7031,7 +7073,9 @@ session_init(session_t *ps_old, int argc, char **argv) {
.blur_background_frame = false,
.blur_background_fixed = false,
.blur_background_blacklist = NULL,
.blur_method = BLRMTHD_CONV,
.blur_kerns = { NULL },
.blur_strength = { .iterations = 3, .offset = 2.75 },
.inactive_dim = 0.0,
.inactive_dim_fixed = false,
.invert_color_list = NULL,
Expand Down
Loading