Commit 34f564f6 authored by Ludovic Fauvet's avatar Ludovic Fauvet Committed by Jean-Baptiste Kempf

Qt: rework of the fullscreen controller

- fix the logic
- simplify
- repair the ability to save the state and position
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
(cherry picked from commit 6e71a9b9f6506d1f0c01c62504c4218d93c37512)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent eb311d3b
...@@ -761,42 +761,66 @@ FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i, QWi ...@@ -761,42 +761,66 @@ FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i, QWi
this, setVoutList( vout_thread_t **, int ) ); this, setVoutList( vout_thread_t **, int ) );
/* First Move */ /* First Move */
QRect rect1 = getSettings()->value( "FullScreen/screen" ).toRect(); previousPosition = getSettings()->value( "FullScreen/pos" ).toPoint();
QPoint pos1 = getSettings()->value( "FullScreen/pos" ).toPoint(); screenRes = getSettings()->value( "FullScreen/screen" ).toRect();
int number = var_InheritInteger( p_intf, "qt-fullscreen-screennumber" ); isWideFSC = getSettings()->value( "FullScreen/wide" ).toBool();
if( number == -1 || number > QApplication::desktop()->numScreens() ) i_screennumber = var_InheritInteger( p_intf, "qt-fullscreen-screennumber" );
number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
QRect rect = QApplication::desktop()->screenGeometry( number );
if( rect == rect1 && rect.contains( pos1, true ) )
{
move( pos1 );
screenRes = QApplication::desktop()->screenGeometry(number);
}
else
{
centerFSC( number );
}
} }
FullscreenControllerWidget::~FullscreenControllerWidget() FullscreenControllerWidget::~FullscreenControllerWidget()
{ {
QPoint pos1 = pos(); getSettings()->setValue( "FullScreen/pos", previousPosition );
QRect rect1 = QApplication::desktop()->screenGeometry( pos1 ); getSettings()->setValue( "FullScreen/screen", screenRes );
getSettings()->setValue( "FullScreen/pos", pos1 ); getSettings()->setValue( "FullScreen/wide", isWideFSC );
getSettings()->setValue( "FullScreen/screen", rect1 );
setVoutList( NULL, 0 ); setVoutList( NULL, 0 );
vlc_mutex_destroy( &lock ); vlc_mutex_destroy( &lock );
} }
void FullscreenControllerWidget::restoreFSC()
{
if( !isWideFSC )
{
/* Restore half-bar and re-centre if needed */
setMinimumWidth( FSC_WIDTH );
adjustSize();
QRect currentRes = QApplication::desktop()->screenGeometry( targetScreen() );
if( currentRes == screenRes &&
QApplication::desktop()->screen()->geometry().contains( previousPosition, true ) )
{
/* Restore to the last known position */
move( previousPosition );
}
else
{
/* FSC is out of screen or screen resolution changed */
msg_Dbg( p_intf, "Recentering the Fullscreen Controller" );
centerFSC( targetScreen() );
screenRes = currentRes;
previousPosition = pos();
}
}
else
{
/* Dock at the bottom of the screen */
updateFullwidthGeometry( targetScreen() );
}
#ifdef Q_WS_X11
// Tell kwin that we do not want a shadow around the fscontroller
setMask( QRegion( 0, 0, width(), height() ) );
#endif
}
void FullscreenControllerWidget::centerFSC( int number ) void FullscreenControllerWidget::centerFSC( int number )
{ {
screenRes = QApplication::desktop()->screenGeometry(number); QRect currentRes = QApplication::desktop()->screenGeometry( number );
/* screen has changed, calculate new position */ /* screen has changed, calculate new position */
QPoint pos = QPoint( screenRes.x() + (screenRes.width() / 2) - (width() / 2), QPoint pos = QPoint( currentRes.x() + (currentRes.width() / 2) - (width() / 2),
screenRes.y() + screenRes.height() - height()); currentRes.y() + currentRes.height() - height());
move( pos ); move( pos );
} }
...@@ -805,34 +829,12 @@ void FullscreenControllerWidget::centerFSC( int number ) ...@@ -805,34 +829,12 @@ void FullscreenControllerWidget::centerFSC( int number )
*/ */
void FullscreenControllerWidget::showFSC() void FullscreenControllerWidget::showFSC()
{ {
int number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi ); restoreFSC();
if( number != i_screennumber ||
screenRes != QApplication::desktop()->screenGeometry(number) )
{
i_screennumber = number;
if( !isWideFSC )
{
centerFSC( number );
msg_Dbg( p_intf, "Recentering the Fullscreen Controller" );
}
else
{
updateFullwidthGeometry( number );
}
}
adjustSize();
#if HAVE_TRANSPARENCY #if HAVE_TRANSPARENCY
setWindowOpacity( f_opacity ); setWindowOpacity( f_opacity );
#endif #endif
#ifdef Q_WS_X11
// Tell kwin that we do not want a shadow around the fscontroller
setMask( QRegion( 0, 0, width(), height() ) );
#endif
show(); show();
} }
...@@ -888,30 +890,25 @@ void FullscreenControllerWidget::slowHideFSC() ...@@ -888,30 +890,25 @@ void FullscreenControllerWidget::slowHideFSC()
void FullscreenControllerWidget::updateFullwidthGeometry( int number ) void FullscreenControllerWidget::updateFullwidthGeometry( int number )
{ {
QRect screenGeometry = QApplication::desktop()->screenGeometry( i_screennumber ); QRect screenGeometry = QApplication::desktop()->screenGeometry( number );
setMinimumWidth( screenGeometry.width() ); setMinimumWidth( screenGeometry.width() );
setGeometry( screenGeometry.x(), screenGeometry.y() + screenGeometry.height() - FSC_HEIGHT, screenGeometry.width(), FSC_HEIGHT ); setGeometry( screenGeometry.x(), screenGeometry.y() + screenGeometry.height() - FSC_HEIGHT, screenGeometry.width(), FSC_HEIGHT );
}
void FullscreenControllerWidget::toggleFullwidth() {
if( !isWideFSC ) {
/* Dock at the bottom of the screen */
updateFullwidthGeometry( i_screennumber );
} else {
/* Restore half-bar and re-centre */
setMinimumWidth( FSC_WIDTH );
centerFSC( i_screennumber );
}
adjustSize(); adjustSize();
}
#ifdef Q_WS_X11 void FullscreenControllerWidget::toggleFullwidth()
// Update the mask to reflect the geometry change {
setMask( QRegion( 0, 0, width(), height() ) );
#endif
/* Toggle isWideFSC switch */ /* Toggle isWideFSC switch */
isWideFSC = !isWideFSC; isWideFSC = !isWideFSC;
restoreFSC();
}
int FullscreenControllerWidget::targetScreen()
{
if( i_screennumber == -1 || i_screennumber > QApplication::desktop()->numScreens() )
return QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
return i_screennumber;
} }
/** /**
...@@ -1004,6 +1001,9 @@ void FullscreenControllerWidget::mouseReleaseEvent( QMouseEvent *event ) ...@@ -1004,6 +1001,9 @@ void FullscreenControllerWidget::mouseReleaseEvent( QMouseEvent *event )
i_mouse_last_x = -1; i_mouse_last_x = -1;
i_mouse_last_y = -1; i_mouse_last_y = -1;
event->accept(); event->accept();
// Save the new FSC position
previousPosition = pos();
} }
/** /**
......
...@@ -261,6 +261,7 @@ public: ...@@ -261,6 +261,7 @@ public:
void mouseChanged( vout_thread_t *, int i_mousex, int i_mousey ); void mouseChanged( vout_thread_t *, int i_mousex, int i_mousey );
void toggleFullwidth(); void toggleFullwidth();
void updateFullwidthGeometry( int number ); void updateFullwidthGeometry( int number );
int targetScreen();
signals: signals:
void keyPressed( QKeyEvent * ); void keyPressed( QKeyEvent * );
...@@ -285,6 +286,7 @@ private slots: ...@@ -285,6 +286,7 @@ private slots:
void planHideFSC(); void planHideFSC();
void hideFSC() { hide(); } void hideFSC() { hide(); }
void slowHideFSC(); void slowHideFSC();
void restoreFSC();
void centerFSC( int ); void centerFSC( int );
private: private:
...@@ -300,6 +302,8 @@ private: ...@@ -300,6 +302,8 @@ private:
bool b_mouse_over; bool b_mouse_over;
int i_screennumber; int i_screennumber;
QRect screenRes; QRect screenRes;
QRect previousScreenRes;
QPoint previousPosition;
/* List of vouts currently tracked */ /* List of vouts currently tracked */
QList<vout_thread_t *> vout; QList<vout_thread_t *> vout;
......
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