Skip to content

Commit

Permalink
src/gui/widgets/mpv/mpvwidget: set mpv options from command line
Browse files Browse the repository at this point in the history
Call mpv_set_option_string for every top level option passed to mpv from
the commandline. Previously options were only loaded per file, but this
makes top-level options persistent. This fixes some compatability issues
with third-party software such as the jellyfin-mpv-shim.

Related #217
  • Loading branch information
ripose-jp committed Jul 9, 2024
1 parent f32b249 commit ad5a107
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 7 deletions.
68 changes: 61 additions & 7 deletions src/gui/widgets/mpv/mpvwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,66 @@ void MpvWidget::initTimer()
m_cursorTimer->forceTimeout();
}

void MpvWidget::initOptions()
{
/* Hardcoded options */
mpv_set_option_string(m_mpv, "config", "yes");
mpv_set_option_string(m_mpv, "input-default-bindings", "yes");
mpv_set_option_string(m_mpv, "keep-open", "yes");
mpv_set_option_string(m_mpv, "screenshot-directory", "~~desktop/");
mpv_set_option_string(m_mpv, "terminal", "yes");
mpv_set_option_string(m_mpv, "vo", "libmpv");
mpv_set_option_string(m_mpv, "ytdl", "yes");

/* Commandline options */
QStringList args = QApplication::arguments();
for (qsizetype i = 0; i < args.size(); ++i)
{
/* Skip non-options */
if (!args[i].startsWith("--"))
{
continue;
}

/* Skip per file options */
if (args[i] == "--{")
{
qsizetype depth = 1;
++i;
while (i < args.size() && depth > 0)
{
if (args[i] == "--{")
{
++depth;
}
else if (args[i] == "--}")
{
--depth;
}
++i;
}
continue;
}

QString arg = args[i].last(args[i].size() - 2);
if (arg.startsWith("no-"))
{
arg = arg.last(arg.size() - 3)
.append("=no");
}

qsizetype sepIndex = arg.indexOf('=');
if (sepIndex == -1)
{
continue;
}

QByteArray option = arg.first(sepIndex).toUtf8();
QByteArray value = arg.mid(sepIndex + 1).toUtf8();
mpv_set_option_string(m_mpv, option, value);
}
}

/* End Initialization Functions */
/* Begin OpenGL Functions */

Expand Down Expand Up @@ -503,13 +563,7 @@ void MpvWidget::initializeGL()
);

/* Initialize the mpv context */
mpv_set_option_string(m_mpv, "config", "yes");
mpv_set_option_string(m_mpv, "input-default-bindings", "yes");
mpv_set_option_string(m_mpv, "keep-open", "yes");
mpv_set_option_string(m_mpv, "screenshot-directory", "~~desktop/");
mpv_set_option_string(m_mpv, "terminal", "yes");
mpv_set_option_string(m_mpv, "vo", "libmpv");
mpv_set_option_string(m_mpv, "ytdl", "yes");
initOptions();

QByteArray configDir = DirectoryUtils::getConfigDir().toUtf8();
mpv_set_option_string(m_mpv, "config-dir", configDir);
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/mpv/mpvwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ private Q_SLOTS:
*/
void initTimer();

/**
* Initializes mpv options from the command line.
*/
void initOptions();

/**
* Shows the cursor over this widget.
*/
Expand Down

0 comments on commit ad5a107

Please sign in to comment.