[vlc-devel] [PATCH 3/3] Added focus events

Rémi Denis-Courmont remi at remlab.net
Sat Mar 9 09:20:30 CET 2013


Le mardi 5 mars 2013 04:25:27, Vinicius Steffens Pazzini a écrit :
> ---
>  modules/gui/qt4/main_interface.cpp |   61
> +++++++++++++++++++++++++++++++++++- modules/gui/qt4/main_interface.hpp | 
>   4 +++
>  2 files changed, 64 insertions(+), 1 deletion(-)
> 
> diff --git a/modules/gui/qt4/main_interface.cpp
> b/modules/gui/qt4/main_interface.cpp index d6a8590..5c44cbd 100644
> --- a/modules/gui/qt4/main_interface.cpp
> +++ b/modules/gui/qt4/main_interface.cpp
> @@ -63,6 +63,8 @@
>  #include <vlc_keys.h>                       /* Wheel event */
>  #include <vlc_vout_display.h>               /* vout_thread_t and VOUT_
> events */
> 
> +#include <iostream>
> +
>  // #define DEBUG_INTF
> 
>  /* Callback prototypes */
> @@ -136,6 +138,9 @@ MainInterface::MainInterface( intf_thread_t *_p_intf )
> : QVLCMW( _p_intf ) /* */
>      b_pauseOnMinimize = var_InheritBool( p_intf, "qt-pause-minimized" );
> 
> +    b_pauseOnLoseFocus = var_InheritBool( p_intf, "qt-pause-lose-focus" );
> +    b_muteOnLoseFocus = var_InheritBool( p_intf, "qt-mute-lose-focus" );
> +
>      /* Set the other interface settings */
>      settings = getSettings();
> 
> @@ -1217,6 +1222,60 @@ void MainInterface::updateSystrayTooltipStatus( int
> i_status ) VLCMenuBar::updateSystrayMenu( this, p_intf );
>  }
> 
> +void MainInterface::focusInEvent(QFocusEvent *event)
> +{
> +	if (event->reason() == Qt::ActiveWindowFocusReason)
> +	{
> +		if( THEMIM->getIM()->playingStatus() == PAUSE_S &&
> +			b_pauseOnLoseFocus && b_playingInFocus)
> +		{
> +			THEMIM->play();

You CANNOT do that. There are other components in the code base that might 
pause the stream in certain circumstances, such as aout_PolicyReport().
Blindly resuming playback would screw them up.

> +		}
> +		/*
> +		if ( THEMIM->isMuted() ){
> +			b_mutedInFocus = false;
> +		}else{
> +			b_mutedInFocus = true;
> +		}*/
> +		if ( !b_mutedInFocus && b_muteOnLoseFocus )
> +		{
> +			THEMIM->toggleMute();

Same problem with mute.

> +		}
> +    }
> +    QWidget::focusInEvent(event);
> +}
> +
> +void MainInterface::focusOutEvent(QFocusEvent *event)
> +{
> +	if (event->reason() == Qt::ActiveWindowFocusReason)
> +    {
> +
> +		if( THEMIM->getIM()->playingStatus() == PLAYING_S &&
> +			THEMIM->getIM()->hasVideo() && !THEMIM->getIM()-
>hasVisualisation() &&
> +			b_pauseOnLoseFocus )
> +		{
> +			THEMIM->pause();
> +			b_playingInFocus = true;
> +		} else {
> +			b_playingInFocus = false;
> +		}
> +
> +		if ( THEMIM->isMuted() ){
> +			b_mutedInFocus = true;
> +		}else{
> +			b_mutedInFocus = false;
> +		}
> +
> +		if ( !b_mutedInFocus && b_muteOnLoseFocus )
> +		{
> +			//std::cout << "OI" << std::endl;
> +			THEMIM->toggleMute();
> +			b_mutedInFocus = false;
> +		}
> +    }
> +    QWidget::focusOutEvent(event);
> +}
> +
>  void MainInterface::changeEvent(QEvent *event)
>  {
>      if( event->type() == QEvent::WindowStateChange )
> @@ -1228,7 +1287,7 @@ void MainInterface::changeEvent(QEvent *event)
>          if( newState & Qt::WindowMinimized )
>          {
>              b_hasPausedWhenMinimized = false;
> -
> +
>              if( THEMIM->getIM()->playingStatus() == PLAYING_S &&
>                  THEMIM->getIM()->hasVideo() &&
> !THEMIM->getIM()->hasVisualisation() && b_pauseOnMinimize )
> diff --git a/modules/gui/qt4/main_interface.hpp
> b/modules/gui/qt4/main_interface.hpp index 0f11d10..a3cdf63 100644
> --- a/modules/gui/qt4/main_interface.hpp
> +++ b/modules/gui/qt4/main_interface.hpp
> @@ -96,6 +96,10 @@ protected:
>  #ifdef WIN32
>      virtual bool winEvent( MSG *, long * );
>  #endif
> +
> +    virtual void focusInEvent(QFocusEvent *);
> +    virtual void focusOutEvent(QFocusEvent *);
> +
>      virtual void changeEvent( QEvent * );
>      virtual void dropEvent( QDropEvent *);
>      virtual void dragEnterEvent( QDragEnterEvent * );

-- 
Rémi Denis-Courmont
http://www.remlab.net/



More information about the vlc-devel mailing list