Skip to content
Extraits de code Groupes Projets
Vérifiée Valider e878b899 rédigé par Elliu's avatar Elliu
Parcourir les fichiers

Show mpv on launch: use QT keypress to pass commands to mpv

parent 7e66352d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!186Add the Qt window module as an alternative to the SDL2 module
......@@ -4,4 +4,6 @@ MainWindow::MainWindow(struct module_qt_window_s *qt_window, QWidget *parent)
: QMainWindow(parent)
{
qt_window->mpv_widget = new MpvWidget(qt_window->queue, qt_window->db, this);
setCentralWidget(qt_window->mpv_widget);
setFocusPolicy(Qt::StrongFocus);
}
......@@ -3,6 +3,8 @@
#include <stdexcept>
#include <QtGui/QOpenGLContext>
#include <QtCore/QMetaObject>
#include <QApplication>
#include <QKeyEvent>
#include "qthelper.hh"
#include "../mpv.h"
......@@ -28,15 +30,11 @@ MpvWidget::MpvWidget(struct queue *queue, lkt_db *db, QWidget *parent)
, m_queue(queue)
, m_db(db)
{
setFocusPolicy(Qt::StrongFocus);
mpv = mpv_create();
if (!mpv)
throw std::runtime_error("could not create mpv context");
mpv_set_option_string(mpv, "input-default-bindings", "yes");
mpv_set_option_string(mpv, "input-vo-keyboard", "yes");
int val = 1;
mpv_set_option(mpv, "osc", MPV_FORMAT_FLAG, &val);
setFocusPolicy(Qt::StrongFocus);
mpv_set_option_string(mpv, "terminal", "yes");
mpv_set_option_string(mpv, "msg-level", "all=v");
......@@ -122,9 +120,14 @@ MpvWidget::on_mpv_events()
void
MpvWidget::handle_mpv_event(mpv_event *event)
{
size_t ao_volume;
mpv_event_property *prop;
(void)ao_volume;
(void)prop;
switch (event->event_id) {
case MPV_EVENT_PROPERTY_CHANGE: {
mpv_event_property *prop = static_cast<mpv_event_property *>(event->data);
prop = static_cast<mpv_event_property *>(event->data);
if (strcmp(prop->name, "time-pos") == 0) {
if (prop->format == MPV_FORMAT_DOUBLE) {
double time = *static_cast<double *>(prop->data);
......@@ -246,3 +249,60 @@ MpvWidget::toggle_pause()
{
return true;
}
#define MPV_SEND_COMMAND_ASYNC( ... ) \
{ \
const char *cmd_seek[] = { __VA_ARGS__ }; \
mpv_command_async(mpv, 0, cmd_seek); \
break; \
}
void
MpvWidget::keyPressEvent(QKeyEvent* event)
{
switch(event->modifiers()){
case Qt::ShiftModifier:
switch(event->key()){
case Qt::Key_J:
MPV_SEND_COMMAND_ASYNC("cycle", "sub", NULL);
}
break;
default:
switch(event->key()){
/* Playback */
case Qt::Key_Space:
lmpv_toggle_pause(mpv);
break;
case Qt::Key_Left:
MPV_SEND_COMMAND_ASYNC("osd-msg-bar", "seek", "-5", "relative", NULL);
case Qt::Key_Right:
MPV_SEND_COMMAND_ASYNC("osd-msg-bar", "seek", "+5", "relative", NULL);
case Qt::Key_Down:
MPV_SEND_COMMAND_ASYNC("osd-msg-bar", "seek", "-60", "relative", NULL);
case Qt::Key_Up:
MPV_SEND_COMMAND_ASYNC("osd-msg-bar", "seek", "+60", "relative", NULL);
case Qt::Key_O:
MPV_SEND_COMMAND_ASYNC("osd-msg-bar", "show-progress", NULL);
case Qt::Key_L:
MPV_SEND_COMMAND_ASYNC("ab-loop", NULL);
/* Track management */
case Qt::Key_NumberSign:
MPV_SEND_COMMAND_ASYNC("cycle", "audio", NULL);
case Qt::Key_J:
MPV_SEND_COMMAND_ASYNC("cycle", "sub", "down", NULL);
case Qt::Key_Underscore:
MPV_SEND_COMMAND_ASYNC("cycle", "video", NULL);
/* Misc */
case Qt::Key_I:
MPV_SEND_COMMAND_ASYNC("script-binding", "stats/display-stats", NULL);
default:
break;
}
return QOpenGLWidget::keyPressEvent(event);
}
}
......@@ -37,6 +37,9 @@ private:
struct queue *m_queue;
lkt_db *m_db;
protected:
void keyPressEvent(QKeyEvent* event);
public:
bool get_elapsed(int *);
bool get_duration(int *);
......
......@@ -15,6 +15,7 @@ ___create_mpv_widget(struct poller_thread_arg *arg)
QApplication a(argc, nullptr);
setlocale(LC_NUMERIC, "C");
qt_window->main_window = new MainWindow(qt_window);
qt_window->main_window->show();
a.exec();
return nullptr;
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter