From 28fb4c22f0b3bc64b74d63105854269b9f55aa8a Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Wed, 6 Jan 2021 14:55:42 +0100 Subject: [PATCH] MOD: Add a way not to force the X11 gpu context for libmpv --- inc/lektor/config.def | 1 + src/module/mpv.c | 35 +++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/inc/lektor/config.def b/inc/lektor/config.def index e32c0f78..3f222fd4 100644 --- a/inc/lektor/config.def +++ b/inc/lektor/config.def @@ -38,6 +38,7 @@ value("def_repeat", "false") value("font_size", "20") value("font_name", "Hack Nerd Font") value("msg_duration", "4") +value_opt("force_x11", "1") /* Force libmpv to use x11, may segfault on some PCs... */ /* To place hooks, when some things are done in lektor. The default value 'none' is here so that nothing happens. Like any module, the value can point to a module or a function in the internal diff --git a/src/module/mpv.c b/src/module/mpv.c index 67735f98..4d6da5ae 100644 --- a/src/module/mpv.c +++ b/src/module/mpv.c @@ -29,27 +29,38 @@ lmpv_prepare(volatile sqlite3 *db) RETURN_UNLESS(ctx, "Failed to create context", NULL); char _opt[LKT_LINE_MAX]; -#define MPV_SET_OPTION(opt, value) \ - if ((status = mpv_set_option_string(ctx, opt, value)) < 0) { \ - LOG_ERROR("WINDOW", "Failed to set %s to %s: %s", \ - opt, value, mpv_error_string(status)); \ - return NULL; \ +#define MPV_SET_OPTION(opt, value) \ + if ((status = mpv_set_option_string(ctx, opt, value)) < 0) { \ + LOG_ERROR("WINDOW", "Failed to set %s to %s: %s", \ + opt, value, mpv_error_string(status)); \ + return NULL; \ } -#define MPV_SET_FROM_INI(opt, section, key) \ - if (!database_config_get_text(db, section, key, _opt, LKT_LINE_MAX)) { \ - LOG_WARN("WINDOW", "Failed to get option " \ - key " in section " section); \ - return ctx; \ - } \ +#define MPV_SET_FROM_INI(opt, section, key) \ + if (!database_config_get_text(db, section, key, _opt, LKT_LINE_MAX)) { \ + LOG_WARN("WINDOW", "Failed to get option " \ + key " in section " section); \ + return ctx; \ + } \ MPV_SET_OPTION(opt, _opt); +#define MPV_SET_OPTION_COND(opt, value, ini_section, ini_option, def) ({ \ + int ___cond; \ + if (!database_config_get_int(db, ini_section, ini_option, &___cond)) { \ + LOG_WARN("WINDOW", "Using default value '" #def "' because [" \ + #ini_section "->" #ini_option "] was not present in ini " \ + "config file"); \ + ___cond = (def); \ + } \ + if (___cond) \ + MPV_SET_OPTION(opt, value); \ + }) MPV_SET_OPTION("input-default-bindings", "yes"); MPV_SET_OPTION("input-vo-keyboard", "yes"); MPV_SET_OPTION("replaygain", "track"); - MPV_SET_OPTION("gpu-context", "x11"); /* Wayland you sucks */ MPV_SET_OPTION("demuxer-readahead-secs", "5.0"); MPV_SET_OPTION("demuxer-max-bytes", "100M"); MPV_SET_OPTION("hwdec", "yes"); + MPV_SET_OPTION_COND("gpu-context", "x11", "player", "force_x11", 1); /* Wayland you sucks */ MPV_SET_FROM_INI("osd-font-size", "player", "font_size"); MPV_SET_FROM_INI("osd-font", "player", "font_name"); MPV_SET_FROM_INI("osd-duration", "player", "msg_duration"); -- GitLab