Skip to content
Extraits de code Groupes Projets
Valider 45e0d2c4 rédigé par Elliu's avatar Elliu
Parcourir les fichiers

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

parent b8432e2f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline #2628 réussi
Ce commit fait partie de la requête de fusion !186. Les commentaires créés ici seront créés dans le contexte de cette requête de fusion.
...@@ -4,4 +4,6 @@ MainWindow::MainWindow(struct module_qt_window_s *qt_window, QWidget *parent) ...@@ -4,4 +4,6 @@ MainWindow::MainWindow(struct module_qt_window_s *qt_window, QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
{ {
qt_window->mpv_widget = new MpvWidget(qt_window->queue, qt_window->db, this); 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 @@ ...@@ -3,6 +3,8 @@
#include <stdexcept> #include <stdexcept>
#include <QtGui/QOpenGLContext> #include <QtGui/QOpenGLContext>
#include <QtCore/QMetaObject> #include <QtCore/QMetaObject>
#include <QApplication>
#include <QKeyEvent>
#include "qthelper.hh" #include "qthelper.hh"
#include "../mpv.h" #include "../mpv.h"
...@@ -28,15 +30,11 @@ MpvWidget::MpvWidget(struct queue *queue, lkt_db *db, QWidget *parent) ...@@ -28,15 +30,11 @@ MpvWidget::MpvWidget(struct queue *queue, lkt_db *db, QWidget *parent)
, m_queue(queue) , m_queue(queue)
, m_db(db) , m_db(db)
{ {
setFocusPolicy(Qt::StrongFocus);
mpv = mpv_create(); mpv = mpv_create();
if (!mpv) if (!mpv)
throw std::runtime_error("could not create mpv context"); throw std::runtime_error("could not create mpv context");
mpv_set_option_string(mpv, "input-default-bindings", "yes"); setFocusPolicy(Qt::StrongFocus);
mpv_set_option_string(mpv, "input-vo-keyboard", "yes");
int val = 1;
mpv_set_option(mpv, "osc", MPV_FORMAT_FLAG, &val);
mpv_set_option_string(mpv, "terminal", "yes"); mpv_set_option_string(mpv, "terminal", "yes");
mpv_set_option_string(mpv, "msg-level", "all=v"); mpv_set_option_string(mpv, "msg-level", "all=v");
...@@ -122,9 +120,14 @@ MpvWidget::on_mpv_events() ...@@ -122,9 +120,14 @@ MpvWidget::on_mpv_events()
void void
MpvWidget::handle_mpv_event(mpv_event *event) MpvWidget::handle_mpv_event(mpv_event *event)
{ {
size_t ao_volume;
mpv_event_property *prop;
(void)ao_volume;
(void)prop;
switch (event->event_id) { switch (event->event_id) {
case MPV_EVENT_PROPERTY_CHANGE: { 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 (strcmp(prop->name, "time-pos") == 0) {
if (prop->format == MPV_FORMAT_DOUBLE) { if (prop->format == MPV_FORMAT_DOUBLE) {
double time = *static_cast<double *>(prop->data); double time = *static_cast<double *>(prop->data);
...@@ -246,3 +249,60 @@ MpvWidget::toggle_pause() ...@@ -246,3 +249,60 @@ MpvWidget::toggle_pause()
{ {
return true; 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: ...@@ -37,6 +37,9 @@ private:
struct queue *m_queue; struct queue *m_queue;
lkt_db *m_db; lkt_db *m_db;
protected:
void keyPressEvent(QKeyEvent* event);
public: public:
bool get_elapsed(int *); bool get_elapsed(int *);
bool get_duration(int *); bool get_duration(int *);
......
...@@ -15,6 +15,7 @@ ___create_mpv_widget(struct poller_thread_arg *arg) ...@@ -15,6 +15,7 @@ ___create_mpv_widget(struct poller_thread_arg *arg)
QApplication a(argc, nullptr); QApplication a(argc, nullptr);
setlocale(LC_NUMERIC, "C"); setlocale(LC_NUMERIC, "C");
qt_window->main_window = new MainWindow(qt_window); qt_window->main_window = new MainWindow(qt_window);
qt_window->main_window->show();
a.exec(); a.exec();
return nullptr; 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