2017-01-03 01:05:30 +03:00
/*
* Copyright 2016 Smith AR < audoban @ openmailbox . org >
* Michail Vourlakos < mvourlakos @ gmail . com >
*
* This file is part of Latte - Dock
*
* Latte - Dock is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation ; either version 2 of
* the License , or ( at your option ) any later version .
*
* Latte - Dock is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2016-12-25 10:25:27 +03:00
# include "visibilitymanager.h"
2016-12-29 08:40:35 +03:00
# include "visibilitymanager_p.h"
2016-12-30 10:17:38 +03:00
# include "windowinfowrap.h"
2016-12-31 00:27:39 +03:00
# include "dockview.h"
2017-03-08 00:26:09 +03:00
# include "dockcorona.h"
2016-12-30 10:17:38 +03:00
# include "../liblattedock/extras.h"
2016-12-25 10:25:27 +03:00
2017-01-02 09:04:10 +03:00
# include <QDebug>
2016-12-31 03:26:48 +03:00
2016-12-29 08:40:35 +03:00
namespace Latte {
2016-12-25 10:25:27 +03:00
2016-12-29 08:40:35 +03:00
//! BEGIN: VisiblityManagerPrivate implementation
VisibilityManagerPrivate : : VisibilityManagerPrivate ( PlasmaQuick : : ContainmentView * view , VisibilityManager * q )
2017-03-13 04:52:31 +03:00
: QObject ( nullptr ) , q ( q ) , view ( view ) , wm ( & WindowSystem : : self ( ) )
2016-12-29 08:40:35 +03:00
{
2016-12-31 00:27:39 +03:00
DockView * dockView = qobject_cast < DockView * > ( view ) ;
2017-01-16 22:07:49 +03:00
2016-12-30 14:46:56 +03:00
if ( dockView ) {
2016-12-31 00:27:39 +03:00
connect ( dockView , & DockView : : eventTriggered , this , & VisibilityManagerPrivate : : event ) ;
2017-02-11 06:12:17 +03:00
connect ( dockView , & DockView : : absGeometryChanged , this , & VisibilityManagerPrivate : : setDockGeometry ) ;
2016-12-30 14:46:56 +03:00
}
2017-01-16 22:07:49 +03:00
2016-12-30 10:17:38 +03:00
timerCheckWindows . setInterval ( 350 ) ;
timerCheckWindows . setSingleShot ( true ) ;
timerShow . setSingleShot ( true ) ;
timerHide . setSingleShot ( true ) ;
connect ( & timerCheckWindows , & QTimer : : timeout , this , & VisibilityManagerPrivate : : checkAllWindows ) ;
2017-01-02 09:04:10 +03:00
connect ( & timerShow , & QTimer : : timeout , this , [ this ] ( ) {
if ( isHidden ) {
2017-01-28 20:34:03 +03:00
// qDebug() << "must be shown";
2017-03-12 21:09:38 +03:00
emit this - > q - > mustBeShown ( VisibilityManager : : QPrivateSignal { } ) ;
2017-01-02 09:04:10 +03:00
}
} ) ;
connect ( & timerHide , & QTimer : : timeout , this , [ this ] ( ) {
2017-01-03 20:36:40 +03:00
if ( ! blockHiding & & ! isHidden & & ! dragEnter ) {
2017-01-28 20:34:03 +03:00
// qDebug() << "must be hide";
2017-03-12 21:09:38 +03:00
emit this - > q - > mustBeHide ( VisibilityManager : : QPrivateSignal { } ) ;
2017-01-02 09:04:10 +03:00
}
} ) ;
2017-02-25 05:40:47 +03:00
wm - > setDockExtraFlags ( * view ) ;
wm - > addDock ( view - > winId ( ) ) ;
2017-02-27 02:43:48 +03:00
restoreConfig ( ) ;
2016-12-29 08:40:35 +03:00
}
2016-12-25 10:25:27 +03:00
2016-12-29 08:40:35 +03:00
VisibilityManagerPrivate : : ~ VisibilityManagerPrivate ( )
2016-12-25 10:25:27 +03:00
{
2017-03-13 04:52:31 +03:00
qDebug ( ) < < " VisibilityManagerPrivate deleting... " ;
2017-02-25 05:40:47 +03:00
wm - > removeDockStruts ( view - > winId ( ) ) ;
wm - > removeDock ( view - > winId ( ) ) ;
2016-12-25 10:25:27 +03:00
}
2016-12-30 10:17:38 +03:00
inline void VisibilityManagerPrivate : : setMode ( Dock : : Visibility mode )
2016-12-25 10:25:27 +03:00
{
2016-12-30 10:17:38 +03:00
if ( this - > mode = = mode )
return ;
2017-01-16 22:07:49 +03:00
2017-02-27 02:43:48 +03:00
Q_ASSERT_X ( mode ! = Dock : : None , q - > staticMetaObject . className ( ) , " set visibility to Dock::None " ) ;
2016-12-30 10:17:38 +03:00
// clear mode
for ( auto & c : connections ) {
disconnect ( c ) ;
}
2017-01-16 22:07:49 +03:00
2017-03-12 12:01:27 +03:00
if ( this - > mode = = Dock : : AlwaysVisible ) {
wm - > removeDockStruts ( view - > winId ( ) ) ;
} else {
connections [ 3 ] = connect ( wm , & WindowSystem : : currentDesktopChanged
2017-03-12 23:14:30 +03:00
, this , [ & ] {
2017-03-12 12:01:27 +03:00
if ( raiseOnDesktopChange )
raiseDockTemporarily ( ) ;
} ) ;
connections [ 4 ] = connect ( wm , & WindowSystem : : currentActivityChanged
2017-03-12 23:14:30 +03:00
, this , [ & ] ( ) {
if ( raiseOnActivityChange )
raiseDockTemporarily ( ) ;
else
updateHiddenState ( ) ;
2017-03-12 12:01:27 +03:00
} ) ;
}
2016-12-30 10:17:38 +03:00
timerShow . stop ( ) ;
timerHide . stop ( ) ;
timerCheckWindows . stop ( ) ;
this - > mode = mode ;
2017-01-16 22:07:49 +03:00
2016-12-30 10:17:38 +03:00
switch ( this - > mode ) {
2016-12-30 10:24:04 +03:00
case Dock : : AlwaysVisible : {
2017-01-14 00:33:42 +03:00
if ( view - > containment ( ) & & ! view - > containment ( ) - > isUserConfiguring ( ) )
2017-02-25 05:40:47 +03:00
wm - > setDockStruts ( view - > winId ( ) , dockGeometry , view - > location ( ) ) ;
2017-01-16 22:07:49 +03:00
2017-01-14 00:33:42 +03:00
connections [ 0 ] = connect ( view - > containment ( ) , & Plasma : : Containment : : locationChanged
2017-01-16 21:24:46 +03:00
, this , [ & ] ( ) {
2017-01-14 00:33:42 +03:00
if ( view - > containment ( ) - > isUserConfiguring ( ) )
2017-02-25 05:40:47 +03:00
wm - > removeDockStruts ( view - > winId ( ) ) ;
2017-01-14 00:33:42 +03:00
} ) ;
connections [ 1 ] = connect ( view - > containment ( ) , & Plasma : : Containment : : userConfiguringChanged
2017-01-16 21:24:46 +03:00
, this , [ & ] ( bool configuring ) {
2017-01-14 00:33:42 +03:00
if ( ! configuring )
2017-02-25 05:40:47 +03:00
wm - > setDockStruts ( view - > winId ( ) , dockGeometry , view - > containment ( ) - > location ( ) ) ;
2017-01-14 00:33:42 +03:00
} ) ;
2016-12-30 10:24:04 +03:00
raiseDock ( true ) ;
}
2016-12-30 10:17:38 +03:00
break ;
2017-01-16 22:07:49 +03:00
2016-12-30 10:24:04 +03:00
case Dock : : AutoHide : {
2017-01-02 09:04:10 +03:00
raiseDock ( containsMouse ) ;
2016-12-30 10:24:04 +03:00
}
2016-12-30 10:17:38 +03:00
break ;
2017-01-16 22:07:49 +03:00
2016-12-30 10:24:04 +03:00
case Dock : : DodgeActive : {
2017-03-12 12:01:27 +03:00
connections [ 0 ] = connect ( wm , & WindowSystem : : activeWindowChanged
2016-12-30 10:24:04 +03:00
, this , & VisibilityManagerPrivate : : dodgeActive ) ;
2017-03-12 12:01:27 +03:00
connections [ 1 ] = connect ( wm , & WindowSystem : : windowChanged
2016-12-30 10:24:04 +03:00
, this , & VisibilityManagerPrivate : : dodgeActive ) ;
dodgeActive ( wm - > activeWindow ( ) ) ;
2016-12-30 10:17:38 +03:00
}
2016-12-30 10:24:04 +03:00
break ;
2017-01-16 22:07:49 +03:00
2016-12-30 10:24:04 +03:00
case Dock : : DodgeMaximized : {
2017-03-12 12:01:27 +03:00
connections [ 0 ] = connect ( wm , & WindowSystem : : activeWindowChanged
2016-12-30 10:24:04 +03:00
, this , & VisibilityManagerPrivate : : dodgeMaximized ) ;
2017-03-12 12:01:27 +03:00
connections [ 1 ] = connect ( wm , & WindowSystem : : windowChanged
2017-03-12 23:14:30 +03:00
, this , & VisibilityManagerPrivate : : dodgeMaximized ) ;
2017-01-02 09:04:10 +03:00
dodgeMaximized ( wm - > activeWindow ( ) ) ;
2016-12-30 10:24:04 +03:00
}
break ;
2017-01-16 22:07:49 +03:00
2016-12-30 10:24:04 +03:00
case Dock : : DodgeAllWindows : {
for ( const auto & wid : wm - > windows ( ) ) {
windows . insert ( { wid , wm - > requestInfo ( wid ) } ) ;
}
2017-01-16 22:07:49 +03:00
2017-03-12 12:01:27 +03:00
connections [ 0 ] = connect ( wm , & WindowSystem : : windowChanged
2016-12-30 10:24:04 +03:00
, this , & VisibilityManagerPrivate : : dodgeWindows ) ;
2017-03-12 12:01:27 +03:00
connections [ 1 ] = connect ( wm , & WindowSystem : : windowRemoved
2016-12-30 10:24:04 +03:00
, this , [ & ] ( WId wid ) {
2016-12-30 10:17:38 +03:00
windows . erase ( wid ) ;
timerCheckWindows . start ( ) ;
2016-12-30 10:24:04 +03:00
} ) ;
2017-03-12 12:01:27 +03:00
connections [ 2 ] = connect ( wm , & WindowSystem : : windowAdded
2016-12-30 10:24:04 +03:00
, this , [ & ] ( WId wid ) {
2016-12-30 10:17:38 +03:00
windows . insert ( { wid , wm - > requestInfo ( wid ) } ) ;
timerCheckWindows . start ( ) ;
2016-12-30 10:24:04 +03:00
} ) ;
2017-02-12 11:01:12 +03:00
2017-01-02 09:04:10 +03:00
timerCheckWindows . start ( ) ;
2016-12-30 10:24:04 +03:00
}
2017-02-12 11:01:12 +03:00
break ;
2016-12-30 10:17:38 +03:00
}
2017-01-16 22:07:49 +03:00
2017-03-12 12:01:27 +03:00
2016-12-30 22:03:46 +03:00
emit q - > modeChanged ( ) ;
2017-03-12 12:01:27 +03:00
}
void VisibilityManagerPrivate : : setRaiseOnDesktop ( bool enable )
{
if ( enable = = raiseOnDesktopChange )
return ;
raiseOnDesktopChange = enable ;
emit q - > raiseOnDesktopChanged ( ) ;
}
void VisibilityManagerPrivate : : setRaiseOnActivity ( bool enable )
{
if ( enable = = raiseOnActivityChange )
return ;
raiseOnActivityChange = enable ;
emit q - > raiseOnActivityChanged ( ) ;
2016-12-25 10:25:27 +03:00
}
2016-12-30 10:17:38 +03:00
inline void VisibilityManagerPrivate : : setIsHidden ( bool isHidden )
2016-12-25 10:25:27 +03:00
{
2016-12-30 10:17:38 +03:00
if ( this - > isHidden = = isHidden )
return ;
2017-01-16 22:07:49 +03:00
2017-01-02 11:06:47 +03:00
if ( blockHiding ) {
qWarning ( ) < < " isHidden property is blocked, ignoring update " ;
return ;
}
2017-01-16 22:07:49 +03:00
2016-12-30 10:17:38 +03:00
this - > isHidden = isHidden ;
emit q - > isHiddenChanged ( ) ;
2016-12-29 08:40:35 +03:00
}
2016-12-25 10:25:27 +03:00
2017-01-02 11:06:47 +03:00
void VisibilityManagerPrivate : : setBlockHiding ( bool blockHiding )
{
if ( this - > blockHiding = = blockHiding )
return ;
2017-01-16 22:07:49 +03:00
2017-01-02 11:06:47 +03:00
this - > blockHiding = blockHiding ;
2017-01-28 20:34:03 +03:00
// qDebug() << "blockHiding:" << blockHiding;
2017-01-16 22:07:49 +03:00
2017-01-02 11:06:47 +03:00
if ( this - > blockHiding ) {
timerHide . stop ( ) ;
2017-01-16 22:07:49 +03:00
2017-01-04 03:52:31 +03:00
if ( isHidden ) {
2017-01-02 11:06:47 +03:00
isHidden = false ;
2017-01-04 03:52:31 +03:00
emit q - > isHiddenChanged ( ) ;
2017-03-12 21:09:38 +03:00
emit q - > mustBeShown ( VisibilityManager : : QPrivateSignal { } ) ;
2017-01-04 03:52:31 +03:00
}
2017-01-02 11:06:47 +03:00
} else {
updateHiddenState ( ) ;
}
2017-01-16 22:07:49 +03:00
2017-01-02 11:06:47 +03:00
emit q - > blockHidingChanged ( ) ;
}
2016-12-30 10:17:38 +03:00
inline void VisibilityManagerPrivate : : setTimerShow ( int msec )
2016-12-25 10:25:27 +03:00
{
2016-12-30 10:17:38 +03:00
timerShow . setInterval ( msec ) ;
emit q - > timerShowChanged ( ) ;
2016-12-25 10:25:27 +03:00
}
2016-12-30 10:17:38 +03:00
inline void VisibilityManagerPrivate : : setTimerHide ( int msec )
2016-12-25 10:25:27 +03:00
{
2016-12-30 10:17:38 +03:00
timerHide . setInterval ( msec ) ;
emit q - > timerHideChanged ( ) ;
2016-12-25 10:25:27 +03:00
}
2016-12-30 10:17:38 +03:00
inline void VisibilityManagerPrivate : : raiseDock ( bool raise )
2016-12-25 10:25:27 +03:00
{
2017-03-12 20:16:23 +03:00
if ( blockHiding )
return ;
2016-12-29 08:40:35 +03:00
if ( raise ) {
timerHide . stop ( ) ;
2017-01-16 22:07:49 +03:00
2016-12-30 21:24:21 +03:00
if ( ! timerShow . isActive ( ) ) {
2016-12-29 08:40:35 +03:00
timerShow . start ( ) ;
2016-12-30 14:46:56 +03:00
}
2017-03-12 20:16:23 +03:00
} else if ( ! dragEnter ) {
2016-12-29 08:40:35 +03:00
timerShow . stop ( ) ;
2017-01-16 22:07:49 +03:00
2017-02-12 11:01:12 +03:00
if ( hideNow ) {
hideNow = false ;
2017-03-12 21:09:38 +03:00
emit q - > mustBeHide ( VisibilityManager : : QPrivateSignal { } ) ;
2017-02-12 11:01:12 +03:00
} else if ( ! timerHide . isActive ( ) )
2016-12-29 08:40:35 +03:00
timerHide . start ( ) ;
}
2016-12-25 10:25:27 +03:00
}
2017-02-12 11:01:12 +03:00
void VisibilityManagerPrivate : : raiseDockTemporarily ( )
{
2017-03-12 12:01:27 +03:00
if ( raiseTemporarily )
2017-02-12 11:01:12 +03:00
return ;
raiseTemporarily = true ;
timerHide . stop ( ) ;
timerShow . stop ( ) ;
if ( isHidden )
2017-03-12 21:09:38 +03:00
emit q - > mustBeShown ( VisibilityManager : : QPrivateSignal { } ) ;
2017-02-12 11:01:12 +03:00
2017-03-12 14:21:34 +03:00
QTimer : : singleShot ( qBound ( 1800 , 2 * timerHide . interval ( ) , 3000 ) , this , [ & ] ( ) {
2017-03-08 00:26:09 +03:00
raiseTemporarily = false ;
hideNow = true ;
updateHiddenState ( ) ;
2017-02-12 11:01:12 +03:00
} ) ;
}
2017-01-02 11:06:47 +03:00
void VisibilityManagerPrivate : : updateHiddenState ( )
{
2017-01-03 20:36:40 +03:00
if ( dragEnter )
return ;
2017-01-16 22:07:49 +03:00
2017-01-02 11:06:47 +03:00
switch ( mode ) {
case Dock : : AutoHide :
2017-01-03 20:36:40 +03:00
raiseDock ( containsMouse ) ;
2017-01-02 11:06:47 +03:00
break ;
2017-01-16 22:07:49 +03:00
2017-01-02 11:06:47 +03:00
case Dock : : DodgeActive :
dodgeActive ( wm - > activeWindow ( ) ) ;
break ;
2017-01-16 22:07:49 +03:00
2017-01-02 11:06:47 +03:00
case Dock : : DodgeMaximized :
dodgeMaximized ( wm - > activeWindow ( ) ) ;
break ;
2017-01-16 22:07:49 +03:00
2017-01-02 11:06:47 +03:00
case Dock : : DodgeAllWindows :
dodgeWindows ( wm - > activeWindow ( ) ) ;
break ;
}
}
2017-02-11 06:12:17 +03:00
inline void VisibilityManagerPrivate : : setDockGeometry ( const QRect & geometry )
2016-12-25 10:25:27 +03:00
{
2017-02-11 06:12:17 +03:00
if ( ! view - > containment ( ) | | this - > dockGeometry = = geometry )
2016-12-30 10:17:38 +03:00
return ;
2017-01-16 22:07:49 +03:00
2017-02-11 06:12:17 +03:00
this - > dockGeometry = geometry ;
2017-01-16 22:07:49 +03:00
2017-01-14 01:01:30 +03:00
if ( mode = = Dock : : AlwaysVisible & & ! view - > containment ( ) - > isUserConfiguring ( ) ) {
2017-02-25 05:40:47 +03:00
wm - > setDockStruts ( view - > winId ( ) , this - > dockGeometry , view - > containment ( ) - > location ( ) ) ;
2016-12-30 10:17:38 +03:00
}
2016-12-25 10:25:27 +03:00
}
2016-12-30 10:17:38 +03:00
void VisibilityManagerPrivate : : dodgeActive ( WId wid )
2016-12-25 10:25:27 +03:00
{
2017-02-12 11:01:12 +03:00
if ( raiseTemporarily )
return ;
2016-12-30 10:17:38 +03:00
auto winfo = wm - > requestInfo ( wid ) ;
2017-01-16 22:07:49 +03:00
2017-01-02 09:04:10 +03:00
if ( ! winfo . isValid ( ) )
2016-12-30 10:17:38 +03:00
return ;
2017-01-16 22:07:49 +03:00
2017-01-02 09:04:10 +03:00
if ( ! winfo . isActive ( ) ) {
if ( winfo . isPlasmaDesktop ( ) )
raiseDock ( true ) ;
2017-01-16 22:07:49 +03:00
2017-03-12 12:01:27 +03:00
winfo = wm - > requestInfo ( wm - > activeWindow ( ) ) ;
2017-01-02 09:04:10 +03:00
}
2017-01-16 22:07:49 +03:00
2017-03-12 12:01:27 +03:00
if ( wm - > isOnCurrentDesktop ( wid ) )
raiseDock ( ! intersects ( winfo ) ) ;
2016-12-25 10:25:27 +03:00
}
2016-12-30 10:17:38 +03:00
void VisibilityManagerPrivate : : dodgeMaximized ( WId wid )
2016-12-25 10:25:27 +03:00
{
2017-02-12 11:01:12 +03:00
if ( raiseTemporarily )
return ;
2016-12-30 10:17:38 +03:00
auto winfo = wm - > requestInfo ( wid ) ;
2017-01-16 22:07:49 +03:00
2017-01-02 09:04:10 +03:00
if ( ! winfo . isValid ( ) )
2016-12-30 10:17:38 +03:00
return ;
2017-01-16 22:07:49 +03:00
2017-01-02 09:04:10 +03:00
if ( ! winfo . isActive ( ) ) {
if ( winfo . isPlasmaDesktop ( ) )
raiseDock ( true ) ;
2017-01-16 22:07:49 +03:00
2017-03-12 12:01:27 +03:00
winfo = wm - > requestInfo ( wm - > activeWindow ( ) ) ;
2017-01-02 09:04:10 +03:00
}
2017-01-16 22:07:49 +03:00
2017-03-12 12:01:27 +03:00
if ( wm - > isOnCurrentDesktop ( wid ) & & ! winfo . isMinimized ( ) )
raiseDock ( ! ( view - > formFactor ( ) = = Plasma : : Types : : Vertical
2017-03-12 23:14:30 +03:00
? winfo . isMaxHoriz ( ) : winfo . isMaxVert ( ) ) ) ;
2016-12-25 10:25:27 +03:00
}
2016-12-30 10:17:38 +03:00
void VisibilityManagerPrivate : : dodgeWindows ( WId wid )
2016-12-25 10:25:27 +03:00
{
2017-02-12 11:01:12 +03:00
if ( raiseTemporarily )
return ;
2017-01-02 09:04:10 +03:00
if ( windows . find ( wid ) = = std : : end ( windows ) )
return ;
2017-01-16 22:07:49 +03:00
2016-12-30 10:17:38 +03:00
auto winfo = wm - > requestInfo ( wid ) ;
2017-01-02 09:04:10 +03:00
windows [ wid ] = winfo ;
2017-01-16 22:07:49 +03:00
2017-01-02 09:04:10 +03:00
if ( ! winfo . isValid ( ) | | ! wm - > isOnCurrentDesktop ( wid ) )
2016-12-30 10:17:38 +03:00
return ;
2017-01-16 22:07:49 +03:00
2016-12-30 10:17:38 +03:00
if ( intersects ( winfo ) )
raiseDock ( false ) ;
else
timerCheckWindows . start ( ) ;
2016-12-25 10:25:27 +03:00
}
2016-12-29 08:40:35 +03:00
void VisibilityManagerPrivate : : checkAllWindows ( )
2016-12-25 10:25:27 +03:00
{
2017-02-12 11:01:12 +03:00
if ( raiseTemporarily )
return ;
2016-12-30 10:17:38 +03:00
bool raise { true } ;
2017-01-16 22:07:49 +03:00
2016-12-30 10:17:38 +03:00
for ( const auto & winfo : windows ) {
//! std::pair<WId, WindowInfoWrap>
2017-01-02 09:04:10 +03:00
if ( ! std : : get < 1 > ( winfo ) . isValid ( ) | | ! wm - > isOnCurrentDesktop ( std : : get < 0 > ( winfo ) ) )
2016-12-30 10:17:38 +03:00
continue ;
2017-01-16 22:07:49 +03:00
2016-12-30 10:17:38 +03:00
if ( std : : get < 1 > ( winfo ) . isFullscreen ( ) ) {
raise = false ;
break ;
} else if ( intersects ( std : : get < 1 > ( winfo ) ) ) {
raise = false ;
break ;
}
}
2017-01-16 22:07:49 +03:00
2016-12-30 10:17:38 +03:00
raiseDock ( raise ) ;
2016-12-25 10:25:27 +03:00
}
2016-12-30 10:17:38 +03:00
inline bool VisibilityManagerPrivate : : intersects ( const WindowInfoWrap & winfo )
2016-12-25 10:25:27 +03:00
{
2017-02-11 06:12:17 +03:00
return ! winfo . isMinimized ( ) & & winfo . geometry ( ) . intersects ( dockGeometry ) ;
2016-12-25 10:25:27 +03:00
}
2016-12-30 10:17:38 +03:00
inline void VisibilityManagerPrivate : : saveConfig ( )
2016-12-25 10:25:27 +03:00
{
2016-12-30 10:17:38 +03:00
if ( ! view - > containment ( ) )
return ;
2017-01-16 22:07:49 +03:00
2016-12-30 10:17:38 +03:00
auto config = view - > containment ( ) - > config ( ) ;
config . writeEntry ( " visibility " , static_cast < int > ( mode ) ) ;
config . writeEntry ( " timerShow " , timerShow . interval ( ) ) ;
config . writeEntry ( " timerHide " , timerHide . interval ( ) ) ;
2017-03-12 20:05:02 +03:00
config . writeEntry ( " raiseOnDesktopChange " , raiseOnDesktopChange ) ;
config . writeEntry ( " raiseOnActivityChange " , raiseOnActivityChange ) ;
2016-12-30 10:17:38 +03:00
view - > containment ( ) - > configNeedsSaving ( ) ;
2016-12-25 10:25:27 +03:00
}
2016-12-30 10:17:38 +03:00
inline void VisibilityManagerPrivate : : restoreConfig ( )
2016-12-25 10:25:27 +03:00
{
2016-12-30 10:17:38 +03:00
if ( ! view - > containment ( ) )
2016-12-30 10:24:04 +03:00
return ;
2017-01-16 22:07:49 +03:00
2016-12-30 10:24:04 +03:00
auto config = view - > containment ( ) - > config ( ) ;
2017-01-12 14:53:06 +03:00
timerShow . setInterval ( config . readEntry ( " timerShow " , 200 ) ) ;
timerHide . setInterval ( config . readEntry ( " timerHide " , 700 ) ) ;
2017-01-03 20:01:29 +03:00
auto mode = static_cast < Dock : : Visibility > ( config . readEntry ( " visibility " , static_cast < int > ( Dock : : DodgeActive ) ) ) ;
2016-12-30 22:33:42 +03:00
emit q - > timerShowChanged ( ) ;
emit q - > timerHideChanged ( ) ;
2017-02-11 08:55:22 +03:00
2017-02-12 11:01:12 +03:00
if ( mode = = Dock : : AlwaysVisible ) {
2017-03-12 23:14:30 +03:00
setMode ( mode ) ;
2017-02-12 11:01:12 +03:00
} else {
2017-03-12 23:14:30 +03:00
QTimer : : singleShot ( 5000 , this , [ & , mode ] ( ) {
2017-02-11 08:55:22 +03:00
setMode ( mode ) ;
} ) ;
2017-03-12 12:01:27 +03:00
setRaiseOnDesktop ( config . readEntry ( " raiseOnDesktopChange " , false ) ) ;
setRaiseOnActivity ( config . readEntry ( " raiseOnActivityChange " , false ) ) ;
2017-02-11 08:55:22 +03:00
}
2017-03-12 12:01:27 +03:00
qDebug ( ) < < config . entryMap ( ) ;
connect ( view - > containment ( ) , & Plasma : : Containment : : userConfiguringChanged
2017-03-12 23:14:30 +03:00
, this , [ & ] ( bool configuring ) {
2017-03-12 21:30:54 +03:00
if ( ! configuring )
saveConfig ( ) ;
2017-03-12 12:01:27 +03:00
} ) ;
2016-12-25 10:25:27 +03:00
}
2016-12-29 08:40:35 +03:00
bool VisibilityManagerPrivate : : event ( QEvent * ev )
2016-12-25 10:25:27 +03:00
{
2017-01-03 20:36:40 +03:00
switch ( ev - > type ( ) ) {
2017-01-05 18:48:27 +03:00
case QEvent : : Enter :
if ( containsMouse )
break ;
2017-01-16 22:07:49 +03:00
2017-01-05 18:48:27 +03:00
containsMouse = true ;
emit q - > containsMouseChanged ( ) ;
2017-01-16 22:07:49 +03:00
2017-01-05 18:48:27 +03:00
if ( mode ! = Dock : : AlwaysVisible )
raiseDock ( true ) ;
2017-01-16 22:07:49 +03:00
2017-01-03 20:36:40 +03:00
break ;
2017-01-16 22:07:49 +03:00
2017-01-05 18:48:27 +03:00
case QEvent : : Leave :
if ( ! containsMouse )
break ;
2017-01-16 22:07:49 +03:00
2017-01-05 18:48:27 +03:00
containsMouse = false ;
emit q - > containsMouseChanged ( ) ;
updateHiddenState ( ) ;
break ;
2017-01-16 22:07:49 +03:00
2017-01-05 18:48:27 +03:00
case QEvent : : DragEnter :
dragEnter = true ;
2017-03-12 23:14:30 +03:00
2017-03-12 21:09:38 +03:00
if ( isHidden )
emit q - > mustBeShown ( VisibilityManager : : QPrivateSignal { } ) ;
2017-01-05 18:48:27 +03:00
break ;
2017-01-16 22:07:49 +03:00
2017-01-05 18:48:27 +03:00
case QEvent : : DragLeave :
case QEvent : : Drop :
dragEnter = false ;
updateHiddenState ( ) ;
break ;
2017-01-16 22:07:49 +03:00
2017-01-05 18:48:27 +03:00
case QEvent : : Show :
2017-02-25 05:40:47 +03:00
wm - > setDockExtraFlags ( * view ) ;
2017-01-03 20:36:40 +03:00
break ;
2016-12-25 10:25:27 +03:00
}
2017-01-16 22:07:49 +03:00
2016-12-25 10:25:27 +03:00
}
2017-01-13 02:53:59 +03:00
//! END: VisibilityManagerPrivate implementation
2016-12-29 08:40:35 +03:00
//! BEGIN: VisiblityManager implementation
VisibilityManager : : VisibilityManager ( PlasmaQuick : : ContainmentView * view )
: d ( new VisibilityManagerPrivate ( view , this ) )
2016-12-25 10:25:27 +03:00
{
}
2016-12-29 08:40:35 +03:00
VisibilityManager : : ~ VisibilityManager ( )
2016-12-25 10:25:27 +03:00
{
2017-03-12 20:05:02 +03:00
qDebug ( ) < < " VisibilityManager deleting... " ;
delete d ;
2016-12-25 10:25:27 +03:00
}
2016-12-29 08:40:35 +03:00
Dock : : Visibility VisibilityManager : : mode ( ) const
2016-12-25 10:25:27 +03:00
{
2016-12-29 08:40:35 +03:00
return d - > mode ;
2016-12-25 10:25:27 +03:00
}
2016-12-29 08:40:35 +03:00
void VisibilityManager : : setMode ( Dock : : Visibility mode )
2016-12-25 10:25:27 +03:00
{
2016-12-29 08:40:35 +03:00
d - > setMode ( mode ) ;
}
2016-12-25 10:25:27 +03:00
2017-03-12 12:01:27 +03:00
bool VisibilityManager : : raiseOnDesktop ( ) const
{
return d - > raiseOnDesktopChange ;
}
void VisibilityManager : : setRaiseOnDesktop ( bool enable )
{
d - > setRaiseOnDesktop ( enable ) ;
}
bool VisibilityManager : : raiseOnActivity ( ) const
{
return d - > raiseOnActivityChange ;
}
void VisibilityManager : : setRaiseOnActivity ( bool enable )
{
d - > setRaiseOnActivity ( enable ) ;
}
2016-12-29 08:40:35 +03:00
bool VisibilityManager : : isHidden ( ) const
2016-12-25 10:25:27 +03:00
{
2016-12-29 08:40:35 +03:00
return d - > isHidden ;
2016-12-25 10:25:27 +03:00
}
2016-12-30 10:17:38 +03:00
void VisibilityManager : : setIsHidden ( bool isHidden )
2016-12-25 10:25:27 +03:00
{
2016-12-29 08:40:35 +03:00
d - > setIsHidden ( isHidden ) ;
2016-12-25 10:25:27 +03:00
}
2017-01-02 11:06:47 +03:00
bool VisibilityManager : : blockHiding ( ) const
{
return d - > blockHiding ;
}
void VisibilityManager : : setBlockHiding ( bool blockHiding )
{
d - > setBlockHiding ( blockHiding ) ;
}
2016-12-29 08:40:35 +03:00
bool VisibilityManager : : containsMouse ( ) const
2016-12-25 10:25:27 +03:00
{
2016-12-29 08:40:35 +03:00
return d - > containsMouse ;
2016-12-25 10:25:27 +03:00
}
2016-12-29 08:40:35 +03:00
int VisibilityManager : : timerShow ( ) const
2016-12-25 10:25:27 +03:00
{
2016-12-29 08:40:35 +03:00
return d - > timerShow . interval ( ) ;
2016-12-25 10:25:27 +03:00
}
2016-12-29 08:40:35 +03:00
void VisibilityManager : : setTimerShow ( int msec )
2016-12-25 10:25:27 +03:00
{
2016-12-29 08:40:35 +03:00
d - > setTimerShow ( msec ) ;
2016-12-25 10:25:27 +03:00
}
2016-12-29 08:40:35 +03:00
int VisibilityManager : : timerHide ( ) const
2016-12-25 10:25:27 +03:00
{
2016-12-29 08:40:35 +03:00
return d - > timerHide . interval ( ) ;
2016-12-25 10:25:27 +03:00
}
2016-12-29 08:40:35 +03:00
void VisibilityManager : : setTimerHide ( int msec )
2016-12-25 10:25:27 +03:00
{
2016-12-29 08:40:35 +03:00
d - > setTimerHide ( msec ) ;
2016-12-25 10:25:27 +03:00
}
2016-12-29 08:40:35 +03:00
//! END: VisibilityManager implementation
2016-12-25 10:25:27 +03:00
}