diff --git a/src/module/qt_window/mainwindow.cc b/src/module/qt_window/mainwindow.cc index ddffabfe7dbf1d3d78e457b2271bd2c7b9216d6b..ee6902346b5276acc668f7beb77d77917c1fdf68 100644 --- a/src/module/qt_window/mainwindow.cc +++ b/src/module/qt_window/mainwindow.cc @@ -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); } diff --git a/src/module/qt_window/mpvwidget.cc b/src/module/qt_window/mpvwidget.cc index 8c695f5e8b9cf2ae5af573b4279bedb339d7ea19..4207e156b7d5ecd5bb6aeabf7da268ea7bba9079 100644 --- a/src/module/qt_window/mpvwidget.cc +++ b/src/module/qt_window/mpvwidget.cc @@ -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); + } +} diff --git a/src/module/qt_window/mpvwidget.hh b/src/module/qt_window/mpvwidget.hh index f38d8b6d3dbe7462fa82856e1544c869fd81ec2c..00355bccf0b04831a98aa5fbe26a706f9de48f27 100644 --- a/src/module/qt_window/mpvwidget.hh +++ b/src/module/qt_window/mpvwidget.hh @@ -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 *); diff --git a/src/module/qt_window/mpvwidget_interface.cc b/src/module/qt_window/mpvwidget_interface.cc index e048844ed011087105e4a7623b4436d082fc2633..491fd7eae1c50e0922af4e9b51f9fb93d1af627a 100644 --- a/src/module/qt_window/mpvwidget_interface.cc +++ b/src/module/qt_window/mpvwidget_interface.cc @@ -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; }