Commit c26bdee6 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt4: Simplified/fixed qt4 fullscreen implementation

This is a merge+manual adaptations of numerous commits on Qt4

(cherry picked from commit 99b7cf3c3f0d554bf3175082a32722e78bb0f4e8)
(cherry picked from commit 7e26f748884c337eeafdd55c403c5ebce7e90f80)
(cherry picked from commit 8abd25d4f52c23e6c19f40740e3aaafc385c0e73)
(cherry picked from commit a736053c00778ca35f8653713517558e1e710aea)
(cherry picked from commit 312d9c3fc4dee049bf25288d7a3f519003c817b4)
(cherry picked from commit 6fac93217a965a843046e4c0c814cc161a4e0cc8)
(cherry picked from commit df261c30a4ec89baee1c7b3a1152b846d0bc80a7)
(cherry picked from commit a70095543572745dca9b9ef1c776ed751e76d936)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 42bd98c6
......@@ -53,29 +53,11 @@
#ifdef Q_WS_X11
# include <X11/Xlib.h>
# include <qx11info_x11.h>
static void videoSync( void )
{
/* Make sure the X server has processed all requests.
* This protects other threads using distinct connections from getting
* the video widget window in an inconsistent states. */
XSync( QX11Info::display(), False );
}
#else
# define videoSync() (void)0
#endif
#include <math.h>
#include <assert.h>
class ReparentableWidget : public QWidget
{
private:
VideoWidget *owner;
public:
ReparentableWidget( VideoWidget *owner ) : owner( owner )
{}
};
/**********************************************************************
* Video Widget. A simple frame on which video is drawn
* This class handles resize issues
......@@ -84,7 +66,6 @@ public:
VideoWidget::VideoWidget( intf_thread_t *_p_i )
: QFrame( NULL )
, p_intf( _p_i )
, reparentable( NULL )
{
/* Set the policy to expand in both directions */
// setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
......@@ -92,12 +73,23 @@ VideoWidget::VideoWidget( intf_thread_t *_p_i )
layout = new QHBoxLayout( this );
layout->setContentsMargins( 0, 0, 0, 0 );
setLayout( layout );
stable = NULL;
}
VideoWidget::~VideoWidget()
{
/* Ensure we are not leaking the video output. This would crash. */
assert( reparentable == NULL );
assert( !stable );
}
void VideoWidget::sync( void )
{
#ifdef Q_WS_X11
/* Make sure the X server has processed all requests.
* This protects other threads using distinct connections from getting
* the video widget window in an inconsistent states. */
XSync( QX11Info::display(), False );
#endif
}
/**
......@@ -109,7 +101,7 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
{
msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
if( reparentable != NULL )
if( stable )
{
msg_Dbg( p_intf, "embedded video already in use" );
return NULL;
......@@ -120,20 +112,10 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
*pi_height = size().height();
}
/* The Qt4 UI needs a fixed a widget ("this"), so that the parent layout is
* not messed up when we the video is reparented. Hence, we create an extra
* reparentable widget, that will be within the VideoWidget in windowed
* mode, and within the root window (NULL parent) in full-screen mode.
*/
reparentable = new ReparentableWidget( this );
reparentable->installEventFilter(this );
QLayout *innerLayout = new QHBoxLayout( reparentable );
innerLayout->setContentsMargins( 0, 0, 0, 0 );
/* The owner of the video window needs a stable handle (WinId). Reparenting
* in Qt4-X11 changes the WinId of the widget, so we need to create another
* dummy widget that stays within the reparentable widget. */
QWidget *stable = new QWidget();
stable = new QWidget();
QPalette plt = palette();
plt.setColor( QPalette::Window, Qt::black );
stable->setPalette( plt );
......@@ -147,9 +129,7 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
stable->setAttribute( Qt::WA_PaintOnScreen, true );
#endif
innerLayout->addWidget( stable );
layout->addWidget( reparentable );
layout->addWidget( stable );
#ifdef Q_WS_X11
/* HACK: Only one X11 client can subscribe to mouse button press events.
......@@ -163,7 +143,7 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
attr.your_event_mask &= ~(ButtonPressMask|ButtonReleaseMask);
XSelectInput( dpy, w, attr.your_event_mask );
#endif
videoSync();
sync();
#ifndef NDEBUG
msg_Dbg( p_intf, "embedded video ready (handle %p)",
(void *)stable->winId() );
......@@ -176,8 +156,6 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
Parent has to care about resizing itself */
void VideoWidget::SetSizing( unsigned int w, unsigned int h )
{
if (reparentable->windowState() & Qt::WindowFullScreen )
return;
if( !isVisible() ) show();
resize( w, h );
emit sizeChanged( w, h );
......@@ -188,96 +166,22 @@ void VideoWidget::SetSizing( unsigned int w, unsigned int h )
*/
if( size().width() == w && size().height() == h )
updateGeometry();
videoSync();
}
void VideoWidget::SetFullScreen( bool b_fs )
{
const Qt::WindowStates curstate = reparentable->windowState();
Qt::WindowStates newstate = curstate;
Qt::WindowFlags newflags = reparentable->windowFlags();
if( b_fs )
{
newstate |= Qt::WindowFullScreen;
newflags |= Qt::WindowStaysOnTopHint;
}
else
{
newstate &= ~Qt::WindowFullScreen;
newflags &= ~Qt::WindowStaysOnTopHint;
}
if( newstate == curstate )
return; /* no changes needed */
if( b_fs )
{ /* Go full-screen */
int numscreen = var_InheritInteger( p_intf, "qt-fullscreen-screennumber" );
/* if user hasn't defined screennumber, or screennumber that is bigger
* than current number of screens, take screennumber where current interface
* is
*/
if( numscreen == -1 || numscreen > QApplication::desktop()->numScreens() )
numscreen = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
QRect screenres = QApplication::desktop()->screenGeometry( numscreen );
/* To be sure window is on proper-screen in xinerama */
if( !screenres.contains( reparentable->pos() ) )
{
msg_Dbg( p_intf, "Moving video to correct screen");
reparentable->move( QPoint( screenres.x(), screenres.y() ) );
}
reparentable->setParent( NULL, newflags );
reparentable->setWindowState( newstate );
reparentable->show();
}
else
{ /* Go windowed */
reparentable->setWindowFlags( newflags );
reparentable->setWindowState( newstate );
layout->addWidget( reparentable );
}
videoSync();
sync();
}
void VideoWidget::release( void )
{
msg_Dbg( p_intf, "Video is not needed anymore" );
//layout->removeWidget( reparentable );
reparentable->deleteLater();
reparentable = NULL;
assert( stable );
layout->removeWidget( stable );
stable->deleteLater();
stable = NULL;
updateGeometry();
hide();
}
#undef KeyPress
bool VideoWidget::eventFilter(QObject *obj, QEvent *event)
{
if( obj == reparentable )
{
if (event->type() == QEvent::Close)
{
THEDP->quit();
return true;
}
else if( event->type() == QEvent::KeyPress )
{
emit keyPressed( static_cast<QKeyEvent *>(event) );
return true;
}
else if( event->type() == QEvent::Wheel )
{
int i_vlckey = qtWheelEventToVLCKey( static_cast<QWheelEvent *>(event) );
var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
return true;
}
}
return false;
}
/**********************************************************************
* Background Widget. Show a simple image background. Currently,
* it's album art if present or cone.
......
......@@ -46,14 +46,11 @@ class QPixmap;
class QHBoxLayout;
class QMenu;
class QSlider;
class ReparentableWidget;
/******************** Video Widget ****************/
class VideoWidget : public QFrame
{
Q_OBJECT
friend class ReparentableWidget;
public:
VideoWidget( intf_thread_t * );
virtual ~VideoWidget();
......@@ -61,6 +58,7 @@ public:
WId request( int *, int *, unsigned int *, unsigned int *, bool );
void release( void );
int control( void *, int, va_list );
void sync( void );
protected:
virtual QPaintEngine *paintEngine() const
......@@ -71,16 +69,13 @@ protected:
private:
intf_thread_t *p_intf;
QWidget *reparentable;
QWidget *stable;
QLayout *layout;
virtual bool eventFilter ( QObject * watched, QEvent * event );
signals:
void keyPressed( QKeyEvent * );
void sizeChanged( int, int );
public slots:
void SetSizing( unsigned int, unsigned int );
void SetFullScreen( bool );
};
/******************** Background Widget ****************/
......
......@@ -110,7 +110,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
b_autoresize = var_InheritBool( p_intf, "qt-video-autoresize" );
/* Are we in the enhanced always-video mode or not ? */
i_visualmode = var_InheritBool( p_intf, "qt-minimal-view" );
b_minimalView = var_InheritBool( p_intf, "qt-minimal-view" );
/* Do we want anoying popups or not */
b_notificationEnabled = var_InheritBool( p_intf, "qt-notification" );
......@@ -198,26 +198,27 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
/* END CONNECTS ON IM */
/* VideoWidget connects for asynchronous calls */
b_videoFullScreen = false;
b_videoOnTop = false;
connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
Qt::BlockingQueuedConnection );
connect( this, SIGNAL(askReleaseVideo( void )),
this, SLOT(releaseVideoSlot( void )),
Qt::BlockingQueuedConnection );
CONNECT( this, askVideoOnTop(bool), this, setVideoOnTop(bool));
if( videoWidget )
{
if( b_autoresize )
{
CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
videoWidget, SetSizing( unsigned int, unsigned int ) );
this, setVideoSize( unsigned int, unsigned int ) );
CONNECT( videoWidget, sizeChanged( int, int ),
this, resizeStack( int, int ) );
}
CONNECT( this, askVideoSetFullScreen( bool ),
videoWidget, SetFullScreen( bool ) );
CONNECT( videoWidget, keyPressed( QKeyEvent * ),
this, handleKeyPress( QKeyEvent * ) );
this, setVideoFullScreen( bool ) );
}
CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
......@@ -243,6 +244,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
QVLCTools::restoreWidgetPosition( settings, this, QSize(400, 100) );
settings->endGroup();
b_interfaceFullScreen = isFullScreen();
/* Final sizing and showing */
setVisible( !b_hideAfterCreation );
......@@ -250,7 +253,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
menuBar()->sizeHint().width() ) + 30 );
/* Switch to minimal view if needed, must be called after the show() */
if( i_visualmode )
if( b_minimalView )
toggleMinimalView( true );
}
......@@ -531,21 +534,6 @@ void MainInterface::toggleFSC()
* Video Handling
****************************************************************************/
/* This event is used to deal with the fullscreen and always on top
issue conflict (bug in wx) */
class SetVideoOnTopQtEvent : public QEvent
{
public:
SetVideoOnTopQtEvent( bool _onTop ) :
QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
{}
bool OnTop() const { return onTop; }
private:
bool onTop;
};
/**
* NOTE:
* You must not change the state of this object or other Qt4 UI objects,
......@@ -588,13 +576,14 @@ void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
void MainInterface::releaseVideo( void )
{
emit askReleaseVideo();
QApplication::postEvent( this, new SetVideoOnTopQtEvent( false ) );
}
/* Function that is CONNECTED to the previous emit */
void MainInterface::releaseVideoSlot( void )
{
videoWidget->release();
setVideoOnTop( false );
setVideoFullScreen( false );
if( stackCentralW->currentWidget() == videoWidget )
restoreStackOldWidget();
......@@ -603,6 +592,66 @@ void MainInterface::releaseVideoSlot( void )
stackCentralOldWidget = bgWidget;
}
void MainInterface::setVideoSize( unsigned int w, unsigned int h )
{
if( !isFullScreen() && !isMaximized() )
videoWidget->SetSizing( w, h );
}
void MainInterface::setVideoFullScreen( bool fs )
{
b_videoFullScreen = fs;
if( fs )
{
int numscreen = var_InheritInteger( p_intf, "qt-fullscreen-screennumber" );
/* if user hasn't defined screennumber, or screennumber that is bigger
* than current number of screens, take screennumber where current interface
* is
*/
if( numscreen == -1 || numscreen > QApplication::desktop()->numScreens() )
numscreen = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
QRect screenres = QApplication::desktop()->screenGeometry( numscreen );
/* To be sure window is on proper-screen in xinerama */
if( !screenres.contains( pos() ) )
{
msg_Dbg( p_intf, "Moving video to correct screen");
move( QPoint( screenres.x(), screenres.y() ) );
}
setMinimalView( true );
setInterfaceFullScreen( true );
}
else
{
/* TODO do we want to restore screen and position ? (when
* qt-fullscreen-screennumber is forced) */
setMinimalView( b_minimalView );
setInterfaceFullScreen( b_interfaceFullScreen );
}
videoWidget->sync();
}
/* Slot to change the video always-on-top flag.
* Emit askVideoOnTop() to invoke this from other thread. */
void MainInterface::setVideoOnTop( bool on_top )
{
b_videoOnTop = on_top;
Qt::WindowFlags oldflags = windowFlags(), newflags;
if( b_videoOnTop )
newflags = oldflags | Qt::WindowStaysOnTopHint;
else
newflags = oldflags & ~Qt::WindowStaysOnTopHint;
if( newflags != oldflags )
{
setWindowFlags( newflags );
show(); /* necessary to apply window flags */
}
}
/* Asynchronous call from WindowControl function */
int MainInterface::controlVideo( int i_query, va_list args )
{
......@@ -612,8 +661,7 @@ int MainInterface::controlVideo( int i_query, va_list args )
{
unsigned int i_width = va_arg( args, unsigned int );
unsigned int i_height = va_arg( args, unsigned int );
if( isFullScreen() || isMaximized() )
showNormal();
emit askVideoToResize( i_width, i_height );
return VLC_SUCCESS;
}
......@@ -621,12 +669,14 @@ int MainInterface::controlVideo( int i_query, va_list args )
{
unsigned i_arg = va_arg( args, unsigned );
unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
QApplication::postEvent( this, new SetVideoOnTopQtEvent( on_top ) );
emit askVideoOnTop( on_top != 0 );
return VLC_SUCCESS;
}
case VOUT_WINDOW_SET_FULLSCREEN:
{
bool b_fs = va_arg( args, int );
emit askVideoSetFullScreen( b_fs );
return VLC_SUCCESS;
}
......@@ -726,12 +776,20 @@ void MainInterface::dockPlaylist( bool p_docked )
playlistVisible = true;
}
void MainInterface::setMinimalView( bool b_minimal )
{
menuBar()->setVisible( !b_minimal );
controls->setVisible( !b_minimal );
statusBar()->setVisible( !b_minimal );
inputC->setVisible( !b_minimal );
}
/*
If b_switch is false, then we are normalView
If b_minimal is false, then we are normalView
*/
void MainInterface::toggleMinimalView( bool b_switch )
void MainInterface::toggleMinimalView( bool b_minimal )
{
if( i_visualmode == 0 && b_autoresize ) /* Normal mode */
if( !b_minimalView && b_autoresize ) /* Normal mode */
{
if( stackCentralW->currentWidget() == bgWidget )
{
......@@ -741,13 +799,11 @@ void MainInterface::toggleMinimalView( bool b_switch )
}
}
}
b_minimalView = b_minimal;
if( !b_videoFullScreen )
setMinimalView( b_minimalView );
menuBar()->setVisible( !b_switch );
controls->setVisible( !b_switch );
statusBar()->setVisible( !b_switch );
inputC->setVisible( !b_switch );
emit minimalViewToggled( b_switch );
emit minimalViewToggled( b_minimalView );
}
/* toggling advanced controls buttons */
......@@ -1035,19 +1091,6 @@ void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
/************************************************************************
* Events stuff
************************************************************************/
void MainInterface::customEvent( QEvent *event )
{
if ( event->type() == (int)SetVideoOnTopEvent_Type )
{
SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
if( p_event->OnTop() )
setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
else
setWindowFlags( windowFlags() & ~Qt::WindowStaysOnTopHint );
show(); /* necessary to apply window flags */
}
}
void MainInterface::keyPressEvent( QKeyEvent *e )
{
handleKeyPress( e );
......@@ -1055,10 +1098,9 @@ void MainInterface::keyPressEvent( QKeyEvent *e )
void MainInterface::handleKeyPress( QKeyEvent *e )
{
if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
&& !menuBar()->isVisible() )
if( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H ) )
{
toggleMinimalView( false );
toggleMinimalView( !b_minimalView );
e->accept();
}
......@@ -1086,18 +1128,19 @@ void MainInterface::closeEvent( QCloseEvent *e )
THEDP->quit();
}
void MainInterface::toggleFullScreen()
void MainInterface::setInterfaceFullScreen( bool fs )
{
if( isFullScreen() )
{
showNormal();
emit fullscreenInterfaceToggled( false );
}
else
{
if( fs )
showFullScreen();
emit fullscreenInterfaceToggled( true );
}
else
showNormal();
}
void MainInterface::toggleInterfaceFullScreen()
{
b_interfaceFullScreen = !b_interfaceFullScreen;
if( !b_videoFullScreen )
setInterfaceFullScreen( b_interfaceFullScreen );
emit fullscreenInterfaceToggled( b_interfaceFullScreen );
}
/*****************************************************************************
......
......@@ -86,6 +86,7 @@ public:
#endif
int getControlsVisibilityStatus();
bool isPlDocked() { return ( b_plDocked != false ); }
bool isInterfaceFullScreen() { return b_interfaceFullScreen; }
protected:
void dropEventPlay( QDropEvent *, bool);
......@@ -97,7 +98,6 @@ protected:
virtual void dragMoveEvent( QDragMoveEvent * );
virtual void dragLeaveEvent( QDragLeaveEvent * );
virtual void closeEvent( QCloseEvent *);
virtual void customEvent( QEvent *);
virtual void keyPressEvent( QKeyEvent *);
virtual void wheelEvent( QWheelEvent * );
......@@ -117,6 +117,10 @@ private:
void showVideo();
void restoreStackOldWidget();
/* */
void setMinimalView( bool );
void setInterfaceFullScreen( bool );
/* */
QSettings *settings;
#ifndef HAVE_MAEMO
......@@ -151,8 +155,11 @@ private:
bool b_notificationEnabled; /// Systray Notifications
bool b_autoresize; ///< persistent resizeable window
bool b_videoEmbedded; ///< Want an external Video Window
bool b_videoFullScreen; ///< --fullscreen
bool b_videoOnTop; ///< --video-on-top
bool b_hideAfterCreation;
int i_visualmode; ///< Visual Mode
bool b_minimalView; ///< Minimal video
bool b_interfaceFullScreen;
/* States */
bool playlistVisible; ///< Is the playlist visible ?
......@@ -176,7 +183,7 @@ public slots:
void toggleUpdateSystrayMenu();
#endif
void toggleAdvancedButtons();
void toggleFullScreen();
void toggleInterfaceFullScreen();
void toggleFSC();
void popupMenu( const QPoint& );
......@@ -209,12 +216,15 @@ private slots:
void resizeStack( int w, int h ) {
if( !isFullScreen() && !isMaximized() )
if( i_visualmode == 1 ) resize( w, h ); /* Oh yes, it shouldn't
if( b_minimalView ) resize( w, h ); /* Oh yes, it shouldn't
be possible that size() - stackCentralW->size() < 0
since stackCentralW is contained in the QMW... */
else resize( size() - stackCentralW->size() + QSize( w, h ) );
debug(); }
void setVideoSize( unsigned int, unsigned int );
void setVideoFullScreen( bool );
void setVideoOnTop( bool );
signals:
void askGetVideo( WId *p_id, int *pi_x, int *pi_y,
......@@ -222,6 +232,7 @@ signals:
void askReleaseVideo( );
void askVideoToResize( unsigned int, unsigned int );
void askVideoSetFullScreen( bool );
void askVideoOnTop( bool );
void minimalViewToggled( bool );
void fullscreenInterfaceToggled( bool );
......
......@@ -465,9 +465,9 @@ QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface
/* FullScreen View */
action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
SLOT( toggleFullScreen() ), QString( "F11" ) );
SLOT( toggleInterfaceFullScreen() ), QString( "F11" ) );
action->setCheckable( true );
action->setChecked( mi->isFullScreen() );
action->setChecked( mi->isInterfaceFullScreen() );
CONNECT( mi, fullscreenInterfaceToggled( bool ),
action, setChecked( bool ) );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment