]> git.sesse.net Git - vlc/commitdiff
Add an option to pause the playback on minimizing the window. http://trac.videolan...
authorJakub Wieczorek <fawek@fawek.net>
Sat, 25 Dec 2010 22:08:23 +0000 (23:08 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Sun, 26 Dec 2010 12:29:53 +0000 (13:29 +0100)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/gui/qt4/input_manager.cpp
modules/gui/qt4/input_manager.hpp
modules/gui/qt4/main_interface.cpp
modules/gui/qt4/main_interface.hpp
modules/gui/qt4/qt4.cpp

index 539279ca6aad755150f96144cf36ff15f703c5a2..749ec5ad7aa46d580eee3f6fc631b7eb2691e8f2 100644 (file)
@@ -514,6 +514,23 @@ bool InputManager::hasAudio()
     return false;
 }
 
+bool InputManager::hasVisualisation()
+{
+    if( !p_input )
+        return false;
+
+    aout_instance_t *aout = input_GetAout( p_input );
+    if( !aout )
+        return false;
+
+    char *visual = var_InheritString( aout, "visual" );
+    if( !visual )
+        return false;
+
+    free( visual );
+    return true;
+}
+
 void InputManager::UpdateTeletext()
 {
     if( hasInput() )
index e56eca5a2bc240a878fc7b1602f5b9be14780a06..fde6ae04ee64010c2fc1342aab45cd9f657c2103 100644 (file)
@@ -133,6 +133,7 @@ public:
     int playingStatus();
     bool hasAudio();
     bool hasVideo() { return hasInput() && b_video; }
+    bool hasVisualisation();
     void requestArtUpdate();
 
     QString getName() { return oldName; }
index 4444ad1f95e8931ee9252e7c6eb872506b73a43c..139ce17f5566df66efd3080df411caf8f267a4fb 100644 (file)
@@ -259,6 +259,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /* Switch to minimal view if needed, must be called after the show() */
     if( b_minimalView )
         toggleMinimalView( true );
+
+    b_hasPausedWhenMinimized = false;
 }
 
 MainInterface::~MainInterface()
@@ -1090,6 +1092,39 @@ void MainInterface::updateSystrayTooltipStatus( int i_status )
 }
 #endif
 
+void MainInterface::changeEvent(QEvent *event)
+{
+    if( event->type() == QEvent::WindowStateChange )
+    {
+        QWindowStateChangeEvent *windowStateChangeEvent = static_cast<QWindowStateChangeEvent*>(event);
+        Qt::WindowStates newState = windowState();
+        Qt::WindowStates oldState = windowStateChangeEvent->oldState();
+
+        if( newState & Qt::WindowMinimized )
+        {
+            b_hasPausedWhenMinimized = false;
+
+            if( THEMIM->getIM()->playingStatus() == PLAYING_S &&
+                THEMIM->getIM()->hasVideo() &&
+                !THEMIM->getIM()->hasVisualisation() &&
+                var_InheritBool( p_intf, "qt-pause-minimized" ) )
+            {
+                b_hasPausedWhenMinimized = true;
+                THEMIM->pause();
+            }
+        }
+        else if( oldState & Qt::WindowMinimized && !( newState & Qt::WindowMinimized ) )
+        {
+            if( b_hasPausedWhenMinimized )
+            {
+                THEMIM->play();
+            }
+        }
+    }
+
+    QWidget::changeEvent(event);
+}
+
 /************************************************************************
  * D&D Events
  ************************************************************************/
index 4f7304e81ef08bd41715029548e0ac0ee0e589f2..11afb399b254316e03a5e37126c2fae6e6d19741 100644 (file)
@@ -93,6 +93,7 @@ protected:
 #ifdef WIN32
     virtual bool winEvent( MSG *, long * );
 #endif
+    virtual void changeEvent( QEvent * );
     virtual void dropEvent( QDropEvent *);
     virtual void dragEnterEvent( QDragEnterEvent * );
     virtual void dragMoveEvent( QDragMoveEvent * );
@@ -168,6 +169,7 @@ private:
 //    bool                 b_visualSelectorEnabled;
     bool                 b_plDocked;            ///< Is the playlist docked ?
 
+    bool                 b_hasPausedWhenMinimized;
 
 #ifdef WIN32
     HIMAGELIST himl;
index 64cc3487bd0a7dc86db5a573095e4535171a3919..ecfb7691b34842ff06b2d95e10110c1a4918c12d 100644 (file)
@@ -178,6 +178,11 @@ static void ShowDialog   ( intf_thread_t *, int, int, intf_dialog_args_t * );
     "keyboard will always change your system volume. With this option unchecked, the "  \
     "volume buttons will change VLC's volume when VLC is selected and change the "      \
     "system volume when VLC is not selected." )
+
+#define QT_PAUSE_MINIMIZED_TEXT N_( "Pause the video playback when minimized" )
+#define QT_PAUSE_MINIMIZED_LONGTEXT N_( \
+    "With this option enabled, the playback will be automatically paused when minimizing the window." )
+
 /**********************************************************************/
 vlc_module_begin ()
     set_shortname( "Qt" )
@@ -263,6 +268,9 @@ vlc_module_begin ()
               false                                /* advanced mode only */)
 #endif
 
+    add_bool( "qt-pause-minimized", true, QT_PAUSE_MINIMIZED_TEXT,
+              QT_PAUSE_MINIMIZED_LONGTEXT, false )
+
     add_obsolete_bool( "qt-blingbling" ) /* Suppressed since 1.0.0 */
     add_obsolete_integer( "qt-display-mode" ) /* Suppressed since 1.1.0 */