[vlc-devel] [PATCH] Optional pause when window inactive.

sanjeev mk sanjeevmk4890 at gmail.com
Wed Sep 14 08:02:52 CEST 2011


Starting a new thread because this is a different patch and the previous
thread had become pretty long.

As discussed previously in the thread "Pause when window inactive", one of
the users suggested the idea of having the 'Pause when window inactive'
feature as a Preference option, if there are significant number of users who
want it.

The patch posted here, adds the option of pausing when the window becomes
inactive (off by default) , to the Interface panel of Simple Preferences
(directly above the 'Pause playback when minimized' checkbox). The GUI part
has been implemented exactly as done with 'Pause when minimized'.

To summarize, this patch gives the option of pausing when the window becomes
inactive. The option is turned OFF by default. If the user turns this ON
this option in Simple Preferences (enables it), then the video playback will
be automatically paused if the user switches to some other window using
Alt+Tab or any other means of going to another window. If VLC doesn't have
keyboard attention/ user attention, the video playback will be paused, with
this option enabled.

Note - Audio playback is NOT paused.
The patch:
----------------------------------------------------------------------------------------

diff --git a/modules/gui/qt4/components/simple_preferences.cpp
b/modules/gui/qt4/components/simple_preferences.cpp
index dfe1376..f268929 100644
--- a/modules/gui/qt4/components/simple_preferences.cpp
+++ b/modules/gui/qt4/components/simple_preferences.cpp
@@ -580,6 +580,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf,
QWidget *_parent,
             CONNECT( ui.systrayBox, toggled( bool ), ui.sysPop, setEnabled(
bool ) );
             ui.sysPop->setEnabled( ui.systrayBox->isChecked() );

+            CONFIG_BOOL( "qt-pause-inactive", pauseInactiveBox );
             CONFIG_BOOL( "qt-pause-minimized", pauseMinimizedBox );
             CONFIG_BOOL( "playlist-tree", treePlaylist );
             CONFIG_BOOL( "play-and-pause", playPauseBox );
diff --git a/modules/gui/qt4/main_interface.cpp
b/modules/gui/qt4/main_interface.cpp
index 193bf7f..1c47c2b 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -1145,7 +1145,30 @@ void MainInterface::changeEvent(QEvent *event)
         }
     }

-    QWidget::changeEvent(event);
+ else if( (event->type() == QEvent::ActivationChange) )
+ {
+ if( THEMIM->getIM()->playingStatus() == PLAYING_S &&
+ THEMIM->getIM()->hasVideo() &&
+ !THEMIM->getIM()->hasVisualisation() &&
+ var_InheritBool( p_intf, "qt-pause-inactive" ) )
+ {
+ b_hasPausedWhenInactive=true;
+ THEMIM->pause();
+ }
+ else if(THEMIM->getIM()->playingStatus() == PAUSE_S &&
+ THEMIM->getIM()->hasVideo() &&
+ !THEMIM->getIM()->hasVisualisation() &&
+ var_InheritBool( p_intf, "qt-pause-inactive" ) )
+ {
+ if(b_hasPausedWhenInactive)
+ {
+ b_hasPausedWhenInactive=false;
+ THEMIM->play();
+ }
+ }
+ }
+
+ QWidget::changeEvent(event);
 }

 /************************************************************************
diff --git a/modules/gui/qt4/main_interface.hpp
b/modules/gui/qt4/main_interface.hpp
index cfac21f..dfd0935 100644
--- a/modules/gui/qt4/main_interface.hpp
+++ b/modules/gui/qt4/main_interface.hpp
@@ -168,6 +168,7 @@ private:
 //    bool                 b_visualSelectorEnabled;
     bool                 b_plDocked;            ///< Is the playlist docked
?

+ bool b_hasPausedWhenInactive;
     bool                 b_hasPausedWhenMinimized;
     bool                 b_statusbarVisible;

diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index 8f3cd21..83de6f3 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -185,6 +185,10 @@ static void ShowDialog   ( intf_thread_t *, int, int,
intf_dialog_args_t * );
 #define QT_PAUSE_MINIMIZED_LONGTEXT N_( \
     "With this option enabled, the playback will be automatically paused
when minimizing the window." )

+#define QT_PAUSE_INACTIVE_TEXT N_( "Pause the video playback when window
inactive." )
+#define QT_PAUSE_INACTIVE_LONGTEXT N_( \
+    "With this option enabled, the playback will be automatically paused
when window becomes inactive." )
+
 #define ICONCHANGE_TEXT N_( "Allow automatic icon changes")
 #define ICONCHANGE_LONGTEXT N_( \
     "This option allows the interface to change its icon on various
occasions.")
@@ -211,7 +215,8 @@ vlc_module_begin ()
               MINIMIZED_LONGTEXT, true)
     add_bool( "qt-pause-minimized", true, QT_PAUSE_MINIMIZED_TEXT,
               QT_PAUSE_MINIMIZED_LONGTEXT, false )
-
+ add_bool( "qt-pause-inactive", false, QT_PAUSE_INACTIVE_TEXT,
+              QT_PAUSE_INACTIVE_LONGTEXT, true )
     add_float_with_range( "qt-opacity", 1., 0.1, 1., OPACITY_TEXT,
                           OPACITY_LONGTEXT, false )
     add_float_with_range( "qt-fs-opacity", 0.8, 0.1, 1., OPACITY_FS_TEXT,

-- 
Regards,
Sanjeev M K
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20110914/33cde148/attachment.html>
-------------- next part --------------
diff --git a/modules/gui/qt4/components/simple_preferences.cpp b/modules/gui/qt4/components/simple_preferences.cpp
index dfe1376..f268929 100644
--- a/modules/gui/qt4/components/simple_preferences.cpp
+++ b/modules/gui/qt4/components/simple_preferences.cpp
@@ -580,6 +580,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
             CONNECT( ui.systrayBox, toggled( bool ), ui.sysPop, setEnabled( bool ) );
             ui.sysPop->setEnabled( ui.systrayBox->isChecked() );
 
+            CONFIG_BOOL( "qt-pause-inactive", pauseInactiveBox );
             CONFIG_BOOL( "qt-pause-minimized", pauseMinimizedBox );
             CONFIG_BOOL( "playlist-tree", treePlaylist );
             CONFIG_BOOL( "play-and-pause", playPauseBox );
diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 193bf7f..1c47c2b 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -1145,7 +1145,30 @@ void MainInterface::changeEvent(QEvent *event)
         }
     }
 
-    QWidget::changeEvent(event);
+	else if( (event->type() == QEvent::ActivationChange) )
+	{
+		if( THEMIM->getIM()->playingStatus() == PLAYING_S &&
+			THEMIM->getIM()->hasVideo() &&
+			!THEMIM->getIM()->hasVisualisation() &&
+			var_InheritBool( p_intf, "qt-pause-inactive" ) )
+			{
+				b_hasPausedWhenInactive=true;
+				THEMIM->pause();
+			}
+		else if(THEMIM->getIM()->playingStatus() == PAUSE_S &&
+				THEMIM->getIM()->hasVideo() &&
+				!THEMIM->getIM()->hasVisualisation() &&
+				var_InheritBool( p_intf, "qt-pause-inactive" ) )
+			{
+				if(b_hasPausedWhenInactive)
+				{
+					b_hasPausedWhenInactive=false;
+					THEMIM->play();
+				}
+			}
+	}
+
+	QWidget::changeEvent(event);
 }
 
 /************************************************************************
diff --git a/modules/gui/qt4/main_interface.hpp b/modules/gui/qt4/main_interface.hpp
index cfac21f..dfd0935 100644
--- a/modules/gui/qt4/main_interface.hpp
+++ b/modules/gui/qt4/main_interface.hpp
@@ -168,6 +168,7 @@ private:
 //    bool                 b_visualSelectorEnabled;
     bool                 b_plDocked;            ///< Is the playlist docked ?
 
+	bool				 b_hasPausedWhenInactive;
     bool                 b_hasPausedWhenMinimized;
     bool                 b_statusbarVisible;
 
diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index 8f3cd21..83de6f3 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -185,6 +185,10 @@ static void ShowDialog   ( intf_thread_t *, int, int, intf_dialog_args_t * );
 #define QT_PAUSE_MINIMIZED_LONGTEXT N_( \
     "With this option enabled, the playback will be automatically paused when minimizing the window." )
 
+#define QT_PAUSE_INACTIVE_TEXT N_( "Pause the video playback when window inactive." )
+#define QT_PAUSE_INACTIVE_LONGTEXT N_( \
+    "With this option enabled, the playback will be automatically paused when window becomes inactive." )
+
 #define ICONCHANGE_TEXT N_( "Allow automatic icon changes")
 #define ICONCHANGE_LONGTEXT N_( \
     "This option allows the interface to change its icon on various occasions.")
@@ -211,7 +215,8 @@ vlc_module_begin ()
               MINIMIZED_LONGTEXT, true)
     add_bool( "qt-pause-minimized", true, QT_PAUSE_MINIMIZED_TEXT,
               QT_PAUSE_MINIMIZED_LONGTEXT, false )
-
+	add_bool( "qt-pause-inactive", false, QT_PAUSE_INACTIVE_TEXT,
+              QT_PAUSE_INACTIVE_LONGTEXT, true )
     add_float_with_range( "qt-opacity", 1., 0.1, 1., OPACITY_TEXT,
                           OPACITY_LONGTEXT, false )
     add_float_with_range( "qt-fs-opacity", 0.8, 0.1, 1., OPACITY_FS_TEXT,


More information about the vlc-devel mailing list