From b51fccdbcee0098518935995f1038f13ea3055f4 Mon Sep 17 00:00:00 2001
From: salixor <salixor@pm.me>
Date: Fri, 6 Oct 2023 15:06:34 +0200
Subject: [PATCH] Make it possible to switch to fullscreen with F or double
 click (mpv default)

---
 src/module/qt_window/mpvwidget.cc | 26 ++++++++++++++++++++++++++
 src/module/qt_window/mpvwidget.hh |  3 +++
 2 files changed, 29 insertions(+)

diff --git a/src/module/qt_window/mpvwidget.cc b/src/module/qt_window/mpvwidget.cc
index 22c50cc8..c835cc82 100644
--- a/src/module/qt_window/mpvwidget.cc
+++ b/src/module/qt_window/mpvwidget.cc
@@ -113,6 +113,17 @@ MpvWidget::paintGL()
     mpv_render_context_render(mpv_gl, params);
 }
 
+void
+MpvWidget::toggle_fullscreen()
+{
+    if (window()->isFullScreen()) {
+        was_maximized ? window()->showMaximized() : window()->showNormal();
+    } else {
+        was_maximized = window()->isMaximized();
+        window()->showFullScreen();
+    }
+}
+
 void
 MpvWidget::on_mpv_events()
 {
@@ -396,12 +407,18 @@ MpvWidget::keyPressEvent(QKeyEvent *event)
         case Qt::Key_J: MPV_SEND_COMMAND_ASYNC("osd-msg", "cycle", "sub", "down", nullptr);
         case Qt::Key_Underscore: MPV_SEND_COMMAND_ASYNC("osd-msg", "cycle", "video", nullptr);
 
+        /* Window management */
+        case Qt::Key_F:
+            toggle_fullscreen();
+            break;
+
         /* Misc */
         case Qt::Key_I: MPV_SEND_COMMAND_ASYNC("script-binding", "stats/display-stats", nullptr);
         case Qt::Key_Delete:
             MPV_SEND_COMMAND_ASYNC("script-message", "osc-visibility",
                                    (m_oscVisible = !m_oscVisible) ? "always" : "never", nullptr);
         case Qt::Key_Z: MPV_SEND_COMMAND_ASYNC("osd-msg", "add", "sub-delay", "-0.1", nullptr);
+        case Qt::Key_X: MPV_SEND_COMMAND_ASYNC("osd-msg", "add", "sub-delay", "+0.1", nullptr);
         case Qt::Key_M: MPV_SEND_COMMAND_ASYNC("osd-msg", "cycle", "mute", nullptr);
 
         default: break;
@@ -409,3 +426,12 @@ MpvWidget::keyPressEvent(QKeyEvent *event)
         return QOpenGLWidget::keyPressEvent(event);
     }
 }
+
+void
+MpvWidget::mouseDoubleClickEvent(QMouseEvent *event)
+{
+    if (event->button() == Qt::LeftButton)
+    {
+        toggle_fullscreen();
+    }
+}
diff --git a/src/module/qt_window/mpvwidget.hh b/src/module/qt_window/mpvwidget.hh
index 31a5b1b7..48eb977a 100644
--- a/src/module/qt_window/mpvwidget.hh
+++ b/src/module/qt_window/mpvwidget.hh
@@ -33,6 +33,7 @@ public:
 
 private:
     enum { PLAY, PAUSE, STOP, NONSTOPPED } m_state = STOP;
+    bool was_maximized = false;
 
     queue *m_queue;
     lkt_db *m_db;
@@ -46,6 +47,7 @@ private:
 
 protected:
     void keyPressEvent(QKeyEvent *event);
+    void mouseDoubleClickEvent(QMouseEvent *event);
 
 public:
     bool get_elapsed(int *);
@@ -55,6 +57,7 @@ public:
     bool set_position(int);
     bool load_file(const char *);
     bool toggle_pause();
+    void toggle_fullscreen();
     bool stop();
 
 private:
-- 
GitLab