Skip to content

Commit

Permalink
Merge branch 'yshui:next' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
pijulius authored May 21, 2024
2 parents 17d048c + 9a83982 commit 3d0515d
Show file tree
Hide file tree
Showing 16 changed files with 258 additions and 89 deletions.
8 changes: 3 additions & 5 deletions src/backend/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,20 @@ struct backend_blit_args {
/// Scale factor for the horizontal and vertical direction (X for horizontal,
/// Y for vertical).
vec2 scale;
/// Corner radius of the source image. The corners of
/// Corner radius of the source image BEFORE scaling. The corners of
/// the source image will be rounded.
double corner_radius;
/// Effective size of the source image, set where the corners
/// Effective size of the source image BEFORE scaling, set where the corners
/// of the image are.
ivec2 effective_size;
/// Border width of the source image. This is used with
/// Border width of the source image BEFORE scaling. This is used with
/// `corner_radius` to create a border for the rounded corners.
/// Setting this has no effect if `corner_radius` is 0.
int border_width;
/// Whether the source image should be inverted.
bool color_inverted;
};

static const vec2 SCALE_IDENTITY = {1.0, 1.0};

enum backend_image_format {
/// A format that can be used for normal rendering, and binding
/// X pixmaps.
Expand Down
29 changes: 25 additions & 4 deletions src/backend/xrender/xrender.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ static bool xrender_blit(struct backend_base *base, ivec2 origin,
bool has_alpha = inner->has_alpha || args->opacity != 1;
auto const tmpw = to_u16_checked(inner->size.width);
auto const tmph = to_u16_checked(inner->size.height);
auto const tmpew = to_u16_checked(args->effective_size.width);
auto const tmpeh = to_u16_checked(args->effective_size.height);
auto const tmpew = to_u16_saturated(args->effective_size.width * args->scale.x);
auto const tmpeh = to_u16_saturated(args->effective_size.height * args->scale.y);
const xcb_render_color_t dim_color = {
.red = 0, .green = 0, .blue = 0, .alpha = (uint16_t)(0xffff * args->dim)};

Expand Down Expand Up @@ -346,8 +346,25 @@ static bool xrender_blit(struct backend_base *base, ivec2 origin,
auto tmp_pict = x_create_picture_with_pictfmt(
xd->base.c, inner->size.width, inner->size.height, pictfmt, depth, 0, NULL);

x_set_picture_clip_region(xd->base.c, tmp_pict, to_i16_checked(-origin.x),
to_i16_checked(-origin.y), args->target_mask);
vec2 inverse_scale = (vec2){
.x = 1.0 / args->scale.x,
.y = 1.0 / args->scale.y,
};
if (vec2_eq(args->scale, SCALE_IDENTITY)) {
x_set_picture_clip_region(
xd->base.c, tmp_pict, to_i16_checked(-origin.x),
to_i16_checked(-origin.y), args->target_mask);
} else {
// We need to scale the target_mask back so it's in the source's
// coordinate space.
scoped_region_t source_mask_region;
pixman_region32_init(&source_mask_region);
pixman_region32_copy(&source_mask_region, args->target_mask);
region_scale_ceil(&source_mask_region, origin, inverse_scale);
x_set_picture_clip_region(
xd->base.c, tmp_pict, to_i16_checked(-origin.x),
to_i16_checked(-origin.y), &source_mask_region);
}
// Copy source -> tmp
xcb_render_composite(xd->base.c->c, XCB_RENDER_PICT_OP_SRC, inner->pict,
XCB_NONE, tmp_pict, 0, 0, 0, 0, 0, 0, tmpw, tmph);
Expand Down Expand Up @@ -398,6 +415,10 @@ static bool xrender_blit(struct backend_base *base, ivec2 origin,
}

set_picture_scale(xd->base.c, tmp_pict, args->scale);
// Transformations don't affect the picture's clip region, so we need to
// set it again
x_set_picture_clip_region(xd->base.c, tmp_pict, to_i16_checked(-origin.x),
to_i16_checked(-origin.y), args->target_mask);

xcb_render_composite(xd->base.c->c, XCB_RENDER_PICT_OP_OVER, tmp_pict,
mask_pict, target->pict, 0, 0, mask_pict_dst_x,
Expand Down
7 changes: 3 additions & 4 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ void *parse_window_shader_prefix_with_cwd(const char *src, const char **end, voi
return parse_window_shader_prefix(src, end, cwd);
}

char *parse_config(options_t *opt, const char *config_file) {
bool parse_config(options_t *opt, const char *config_file) {
// clang-format off
*opt = (struct options){
.backend = BKEND_XRENDER,
Expand Down Expand Up @@ -712,7 +712,6 @@ char *parse_config(options_t *opt, const char *config_file) {
};
// clang-format on

char *ret = NULL;
ret = parse_config_libconfig(opt, config_file);
return ret;
list_init_head(&opt->included_config_files);
return parse_config_libconfig(opt, config_file);
}
18 changes: 13 additions & 5 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
#include <xcb/xcb.h>
#include <xcb/xfixes.h>

#include "uthash_extra.h"

#include <libconfig.h>

#include "compiler.h"
#include "kernel.h"
#include "list.h"
#include "log.h"
#include "region.h"
#include "types.h"
#include "win_defs.h"

Expand Down Expand Up @@ -149,8 +147,18 @@ struct debug_options {

extern struct debug_options global_debug_options;

struct included_config_file {
char *path;
struct list_node siblings;
};

/// Structure representing all options.
typedef struct options {
// === Config ===
/// Path to the config file
char *config_file_path;
/// List of config files included by the main config file
struct list_node included_config_files;
// === Debugging ===
bool monitor_repaint;
bool print_diagnostics;
Expand Down Expand Up @@ -378,13 +386,13 @@ char **xdg_config_dirs(void);
/// win_option_mask = whether option overrides for specific window type is set for given
/// options
/// hasneg = whether the convolution kernel has negative values
char *parse_config_libconfig(options_t *, const char *config_file);
bool parse_config_libconfig(options_t *, const char *config_file);

/// Parse a configuration file is that is enabled, also initialize the winopt_mask with
/// default values
/// Outputs and returns:
/// same as parse_config_libconfig
char *parse_config(options_t *, const char *config_file);
bool parse_config(options_t *, const char *config_file);

/**
* Parse a backend option argument.
Expand Down
50 changes: 29 additions & 21 deletions src/config_libconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "c2.h"
#include "common.h"
#include "config.h"
#include "err.h"
#include "log.h"
#include "script.h"
#include "string_utils.h"
Expand Down Expand Up @@ -543,14 +542,19 @@ void generate_fading_config(struct options *opt) {
}
}

static const char **resolve_include(config_t * /* cfg */, const char *include_dir,
const char *path, const char **err) {
static const char **
resolve_include(config_t *cfg, const char *include_dir, const char *path, const char **err) {
char *result = locate_auxiliary_file("include", path, include_dir);
if (result == NULL) {
*err = "Failed to locate included file";
return NULL;
}

struct options *opt = config_get_hook(cfg);
auto included = ccalloc(1, struct included_config_file);
included->path = strdup(result);
list_insert_after(&opt->included_config_files, &included->siblings);

log_debug("Resolved include file \"%s\" to \"%s\"", path, result);
const char **ret = ccalloc(2, const char *);
ret[0] = result;
Expand All @@ -561,9 +565,9 @@ static const char **resolve_include(config_t * /* cfg */, const char *include_di
/**
* Parse a configuration file from default location.
*
* Returns the actually config_file name
* Returns if config is successfully parsed.
*/
char *parse_config_libconfig(options_t *opt, const char *config_file) {
bool parse_config_libconfig(options_t *opt, const char *config_file) {

const char *deprecation_message =
"option has been deprecated. Please remove it from your configuration file. "
Expand All @@ -578,15 +582,17 @@ char *parse_config_libconfig(options_t *opt, const char *config_file) {
// libconfig manages string memory itself, so no need to manually free
// anything
const char *sval = NULL;
bool succeeded = false;

f = open_config_file(config_file, &path);
if (!f) {
free(path);
if (config_file) {
log_fatal("Failed to read configuration file \"%s\".", config_file);
return ERR_PTR(-1);
return false;
}
return NULL;
// No config file found, but that's OK.
return true;
}

config_init(&cfg);
Expand All @@ -601,6 +607,7 @@ char *parse_config_libconfig(options_t *opt, const char *config_file) {
config_set_include_dir(&cfg, parent);
}
config_set_include_func(&cfg, resolve_include);
config_set_hook(&cfg, opt);

free(abspath);
}
Expand All @@ -613,7 +620,7 @@ char *parse_config_libconfig(options_t *opt, const char *config_file) {
log_fatal("Error when reading configuration file \"%s\", line "
"%d: %s",
path, config_error_line(&cfg), config_error_text(&cfg));
goto err;
goto out;
}
}
config_set_auto_convert(&cfg, 1);
Expand Down Expand Up @@ -699,7 +706,7 @@ char *parse_config_libconfig(options_t *opt, const char *config_file) {
if (config_lookup_string(&cfg, "shadow-exclude-reg", &sval)) {
log_error("shadow-exclude-reg is deprecated. Please use "
"clip-shadow-above for more flexible shadow exclusion.");
goto err;
goto out;
}
// --inactive-opacity-override
lcfg_lookup_bool(&cfg, "inactive-opacity-override", &opt->inactive_opacity_override);
Expand Down Expand Up @@ -731,15 +738,15 @@ char *parse_config_libconfig(options_t *opt, const char *config_file) {
log_error("vsync option will take a boolean from now on. \"%s\" in "
"your configuration should be changed to \"%s\"",
sval, parsed_vsync ? "true" : "false");
goto err;
goto out;
}
lcfg_lookup_bool(&cfg, "vsync", &opt->vsync);
// --backend
if (config_lookup_string(&cfg, "backend", &sval)) {
opt->backend = parse_backend(sval);
if (opt->backend >= NUM_BKEND) {
log_fatal("Cannot parse backend");
goto err;
goto out;
}
}
// --log-level
Expand All @@ -762,7 +769,7 @@ char *parse_config_libconfig(options_t *opt, const char *config_file) {
// --sw-opti
if (lcfg_lookup_bool(&cfg, "sw-opti", &bval)) {
log_error("The sw-opti %s", deprecation_message);
goto err;
goto out;
}
// --use-ewmh-active-win
lcfg_lookup_bool(&cfg, "use-ewmh-active-win", &opt->use_ewmh_active_win);
Expand Down Expand Up @@ -807,15 +814,15 @@ char *parse_config_libconfig(options_t *opt, const char *config_file) {
!parse_cfg_condlst_with_prefix(
&opt->window_shader_fg_rules, &cfg, "window-shader-fg-rule",
parse_window_shader_prefix, free, (void *)config_get_include_dir(&cfg))) {
goto err;
goto out;
}

// --blur-method
if (config_lookup_string(&cfg, "blur-method", &sval)) {
int method = parse_blur_method(sval);
if (method >= BLUR_METHOD_INVALID) {
log_fatal("Invalid blur method %s", sval);
goto err;
goto out;
}
opt->blur_method = (enum blur_method)method;
}
Expand All @@ -840,7 +847,7 @@ char *parse_config_libconfig(options_t *opt, const char *config_file) {
opt->blur_kerns = parse_blur_kern_lst(sval, &opt->blur_kernel_count);
if (!opt->blur_kerns) {
log_fatal("Cannot parse \"blur-kern\"");
goto err;
goto out;
}
}
// --resize-damage
Expand Down Expand Up @@ -868,7 +875,7 @@ char *parse_config_libconfig(options_t *opt, const char *config_file) {
"\"%s\" should be %s.",
sval,
!should_remove ? "replaced by `use-damage = true`" : "removed");
goto err;
goto out;
}
// --use-damage
lcfg_lookup_bool(&cfg, "use-damage", &opt->use_damage);
Expand All @@ -891,7 +898,7 @@ char *parse_config_libconfig(options_t *opt, const char *config_file) {
if (config_lookup_bool(&cfg, "glx-use-gpushader4", &ival)) {
log_error("glx-use-gpushader4 has been removed, please remove it "
"from your config file");
goto err;
goto out;
}
// --xrender-sync-fence
lcfg_lookup_bool(&cfg, "xrender-sync-fence", &opt->xrender_sync_fence);
Expand Down Expand Up @@ -952,11 +959,12 @@ char *parse_config_libconfig(options_t *opt, const char *config_file) {
parse_animations(opt->animations, animations, &opt->number_of_scripts);
}

config_destroy(&cfg);
return path;
opt->config_file_path = path;
path = NULL;
succeeded = true;

err:
out:
config_destroy(&cfg);
free(path);
return ERR_PTR(-1);
return succeeded;
}
10 changes: 9 additions & 1 deletion src/diagnostic.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ void print_diagnostics(session_t *ps, const char *config_file, bool compositor_r
#ifdef __FAST_MATH__
printf("* Fast Math: Yes\n");
#endif
printf("* Config file used: %s\n", config_file ?: "None");
printf("* Config file specified: %s\n", config_file ?: "None");
printf("* Config file used: %s\n", ps->o.config_file_path ?: "None");
if (!list_is_empty(&ps->o.included_config_files)) {
printf("* Included config files:\n");
list_foreach(struct included_config_file, i, &ps->o.included_config_files,
siblings) {
printf(" - %s\n", i->path);
}
}
printf("\n### Drivers (inaccurate):\n\n");
print_drivers(ps->drivers);

Expand Down
6 changes: 1 addition & 5 deletions src/inspect.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,8 @@ int inspect_main(int argc, char **argv, const char *config_file) {

xcb_prefetch_extension_data(c.c, &xcb_shape_id);

char *config_file_to_free = NULL;
struct options options;
config_file = config_file_to_free = parse_config(&options, config_file);

if (IS_ERR(config_file_to_free)) {
if (!parse_config(&options, config_file)) {
return 1;
}

Expand Down Expand Up @@ -255,7 +252,6 @@ int inspect_main(int argc, char **argv, const char *config_file) {
free(w);

log_deinit_tls();
free(config_file_to_free);
c2_state_free(state);
destroy_atoms(atoms);
options_destroy(&options);
Expand Down
8 changes: 8 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ void options_destroy(struct options *options) {
c2_list_free(&options->window_shader_fg_rules, free);
c2_list_free(&options->transparent_clipping_blacklist, NULL);

free(options->config_file_path);
free(options->write_pid_path);
free(options->logpath);

Expand All @@ -954,6 +955,13 @@ void options_destroy(struct options *options) {
}
free(options->all_scripts);
memset(options->animations, 0, sizeof(options->animations));

list_foreach_safe(struct included_config_file, i, &options->included_config_files,
siblings) {
free(i->path);
list_remove(&i->siblings);
free(i);
}
}

// vim: set noet sw=8 ts=8 :
Loading

0 comments on commit 3d0515d

Please sign in to comment.