2017-01-02 17:05:30 -05: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 09:25:27 +02:00
# include "visibilitymanager.h"
2016-12-29 00:40:35 -05:00
# include "visibilitymanager_p.h"
2016-12-30 02:17:38 -05:00
# include "windowinfowrap.h"
2016-12-30 16:27:39 -05:00
# include "dockview.h"
2016-12-30 02:17:38 -05:00
# include "../liblattedock/extras.h"
2016-12-25 09:25:27 +02:00
2017-01-02 01:04:10 -05:00
# include <QDebug>
2016-12-30 19:26:48 -05:00
2016-12-29 00:40:35 -05:00
namespace Latte {
2016-12-25 09:25:27 +02:00
2016-12-29 00:40:35 -05:00
//! BEGIN: VisiblityManagerPrivate implementation
VisibilityManagerPrivate : : VisibilityManagerPrivate ( PlasmaQuick : : ContainmentView * view , VisibilityManager * q )
2017-02-24 21:40:47 -05:00
: QObject ( q ) , q ( q ) , view ( view ) , wm ( & AbstractWindowInterface : : self ( ) )
2016-12-29 00:40:35 -05:00
{
2016-12-30 16:27:39 -05:00
DockView * dockView = qobject_cast < DockView * > ( view ) ;
2017-01-16 14:07:49 -05:00
2016-12-30 13:46:56 +02:00
if ( dockView ) {
2016-12-30 16:27:39 -05:00
connect ( dockView , & DockView : : eventTriggered , this , & VisibilityManagerPrivate : : event ) ;
2017-02-10 22:12:17 -05:00
connect ( dockView , & DockView : : absGeometryChanged , this , & VisibilityManagerPrivate : : setDockGeometry ) ;
2016-12-30 13:46:56 +02:00
}
2017-01-16 14:07:49 -05:00
2016-12-30 02:17:38 -05:00
timerCheckWindows . setInterval ( 350 ) ;
timerCheckWindows . setSingleShot ( true ) ;
timerShow . setSingleShot ( true ) ;
timerHide . setSingleShot ( true ) ;
connect ( & timerCheckWindows , & QTimer : : timeout , this , & VisibilityManagerPrivate : : checkAllWindows ) ;
2017-01-02 01:04:10 -05:00
connect ( & timerShow , & QTimer : : timeout , this , [ this ] ( ) {
if ( isHidden ) {
2017-01-28 19:34:03 +02:00
// qDebug() << "must be shown";
2017-01-02 01:04:10 -05:00
emit this - > q - > mustBeShown ( ) ;
}
} ) ;
connect ( & timerHide , & QTimer : : timeout , this , [ this ] ( ) {
2017-01-03 12:36:40 -05:00
if ( ! blockHiding & & ! isHidden & & ! dragEnter ) {
2017-01-28 19:34:03 +02:00
// qDebug() << "must be hide";
2017-01-02 01:04:10 -05:00
emit this - > q - > mustBeHide ( ) ;
}
} ) ;
2017-02-24 21:40:47 -05:00
wm - > setDockExtraFlags ( * view ) ;
wm - > addDock ( view - > winId ( ) ) ;
2017-02-26 18:43:48 -05:00
restoreConfig ( ) ;
2016-12-29 00:40:35 -05:00
}
2016-12-25 09:25:27 +02:00
2016-12-29 00:40:35 -05:00
VisibilityManagerPrivate : : ~ VisibilityManagerPrivate ( )
2016-12-25 09:25:27 +02:00
{
2017-02-24 21:40:47 -05:00
wm - > removeDockStruts ( view - > winId ( ) ) ;
wm - > removeDock ( view - > winId ( ) ) ;
2016-12-25 09:25:27 +02:00
}
2016-12-30 02:17:38 -05:00
inline void VisibilityManagerPrivate : : setMode ( Dock : : Visibility mode )
2016-12-25 09:25:27 +02:00
{
2016-12-30 02:17:38 -05:00
if ( this - > mode = = mode )
return ;
2017-01-16 14:07:49 -05:00
2017-02-26 18:43:48 -05:00
Q_ASSERT_X ( mode ! = Dock : : None , q - > staticMetaObject . className ( ) , " set visibility to Dock::None " ) ;
2016-12-30 02:17:38 -05:00
// clear mode
if ( this - > mode = = Dock : : AlwaysVisible )
2017-02-24 21:40:47 -05:00
wm - > removeDockStruts ( view - > winId ( ) ) ;
2017-01-16 14:07:49 -05:00
2016-12-30 02:17:38 -05:00
for ( auto & c : connections ) {
disconnect ( c ) ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 02:17:38 -05:00
timerShow . stop ( ) ;
timerHide . stop ( ) ;
timerCheckWindows . stop ( ) ;
this - > mode = mode ;
2017-01-16 14:07:49 -05:00
2016-12-30 02:17:38 -05:00
switch ( this - > mode ) {
2016-12-30 02:24:04 -05:00
case Dock : : AlwaysVisible : {
2017-01-13 16:33:42 -05:00
if ( view - > containment ( ) & & ! view - > containment ( ) - > isUserConfiguring ( ) )
2017-02-24 21:40:47 -05:00
wm - > setDockStruts ( view - > winId ( ) , dockGeometry , view - > location ( ) ) ;
2017-01-16 14:07:49 -05:00
2017-01-13 16:33:42 -05:00
connections [ 0 ] = connect ( view - > containment ( ) , & Plasma : : Containment : : locationChanged
2017-01-16 13:24:46 -05:00
, this , [ & ] ( ) {
2017-01-13 16:33:42 -05:00
if ( view - > containment ( ) - > isUserConfiguring ( ) )
2017-02-24 21:40:47 -05:00
wm - > removeDockStruts ( view - > winId ( ) ) ;
2017-01-13 16:33:42 -05:00
} ) ;
connections [ 1 ] = connect ( view - > containment ( ) , & Plasma : : Containment : : userConfiguringChanged
2017-01-16 13:24:46 -05:00
, this , [ & ] ( bool configuring ) {
2017-01-13 16:33:42 -05:00
if ( ! configuring )
2017-02-24 21:40:47 -05:00
wm - > setDockStruts ( view - > winId ( ) , dockGeometry , view - > containment ( ) - > location ( ) ) ;
2017-01-13 16:33:42 -05:00
} ) ;
2016-12-30 02:24:04 -05:00
raiseDock ( true ) ;
}
2016-12-30 02:17:38 -05:00
break ;
2017-01-16 14:07:49 -05:00
2016-12-30 02:24:04 -05:00
case Dock : : AutoHide : {
2017-02-24 21:40:47 -05:00
connections [ 0 ] = connect ( wm , & AbstractWindowInterface : : currentDesktopChanged
2017-02-12 03:01:12 -05:00
, this , & VisibilityManagerPrivate : : raiseDockTemporarily ) ;
2017-02-24 21:40:47 -05:00
connections [ 1 ] = connect ( wm , & AbstractWindowInterface : : currentActivityChanged
2017-02-12 03:01:12 -05:00
, this , & VisibilityManagerPrivate : : raiseDockTemporarily ) ;
2017-01-02 01:04:10 -05:00
raiseDock ( containsMouse ) ;
2016-12-30 02:24:04 -05:00
}
2016-12-30 02:17:38 -05:00
break ;
2017-01-16 14:07:49 -05:00
2016-12-30 02:24:04 -05:00
case Dock : : DodgeActive : {
2017-02-24 21:40:47 -05:00
connections [ 0 ] = connect ( wm , & AbstractWindowInterface : : activeWindowChanged
2016-12-30 02:24:04 -05:00
, this , & VisibilityManagerPrivate : : dodgeActive ) ;
2017-02-24 21:40:47 -05:00
connections [ 1 ] = connect ( wm , & AbstractWindowInterface : : windowChanged
2016-12-30 02:24:04 -05:00
, this , & VisibilityManagerPrivate : : dodgeActive ) ;
2017-02-24 21:40:47 -05:00
connections [ 2 ] = connect ( wm , & AbstractWindowInterface : : currentDesktopChanged
2017-02-12 03:01:12 -05:00
, this , & VisibilityManagerPrivate : : raiseDockTemporarily ) ;
2017-02-24 21:40:47 -05:00
connections [ 3 ] = connect ( wm , & AbstractWindowInterface : : currentActivityChanged
2017-02-12 03:01:12 -05:00
, this , & VisibilityManagerPrivate : : raiseDockTemporarily ) ;
2016-12-30 02:24:04 -05:00
dodgeActive ( wm - > activeWindow ( ) ) ;
2016-12-30 02:17:38 -05:00
}
2016-12-30 02:24:04 -05:00
break ;
2017-01-16 14:07:49 -05:00
2016-12-30 02:24:04 -05:00
case Dock : : DodgeMaximized : {
2017-02-24 21:40:47 -05:00
connections [ 0 ] = connect ( wm , & AbstractWindowInterface : : activeWindowChanged
2017-01-02 01:04:10 -05:00
, this , & VisibilityManagerPrivate : : dodgeMaximized ) ;
2017-02-24 21:40:47 -05:00
connections [ 1 ] = connect ( wm , & AbstractWindowInterface : : windowChanged
2016-12-30 02:24:04 -05:00
, this , & VisibilityManagerPrivate : : dodgeMaximized ) ;
2017-02-24 21:40:47 -05:00
connections [ 2 ] = connect ( wm , & AbstractWindowInterface : : currentDesktopChanged
2017-02-12 03:01:12 -05:00
, this , & VisibilityManagerPrivate : : raiseDockTemporarily ) ;
2017-02-24 21:40:47 -05:00
connections [ 3 ] = connect ( wm , & AbstractWindowInterface : : currentActivityChanged
2017-02-12 03:01:12 -05:00
, this , & VisibilityManagerPrivate : : raiseDockTemporarily ) ;
2017-01-02 01:04:10 -05:00
dodgeMaximized ( wm - > activeWindow ( ) ) ;
2016-12-30 02:24:04 -05:00
}
break ;
2017-01-16 14:07:49 -05:00
2016-12-30 02:24:04 -05:00
case Dock : : DodgeAllWindows : {
for ( const auto & wid : wm - > windows ( ) ) {
windows . insert ( { wid , wm - > requestInfo ( wid ) } ) ;
}
2017-01-16 14:07:49 -05:00
2017-02-24 21:40:47 -05:00
connections [ 0 ] = connect ( wm , & AbstractWindowInterface : : windowChanged
2016-12-30 02:24:04 -05:00
, this , & VisibilityManagerPrivate : : dodgeWindows ) ;
2017-02-24 21:40:47 -05:00
connections [ 1 ] = connect ( wm , & AbstractWindowInterface : : windowRemoved
2016-12-30 02:24:04 -05:00
, this , [ & ] ( WId wid ) {
2016-12-30 02:17:38 -05:00
windows . erase ( wid ) ;
timerCheckWindows . start ( ) ;
2016-12-30 02:24:04 -05:00
} ) ;
2017-02-24 21:40:47 -05:00
connections [ 2 ] = connect ( wm , & AbstractWindowInterface : : windowAdded
2016-12-30 02:24:04 -05:00
, this , [ & ] ( WId wid ) {
2016-12-30 02:17:38 -05:00
windows . insert ( { wid , wm - > requestInfo ( wid ) } ) ;
timerCheckWindows . start ( ) ;
2016-12-30 02:24:04 -05:00
} ) ;
2017-02-24 21:40:47 -05:00
connections [ 3 ] = connect ( wm , & AbstractWindowInterface : : currentDesktopChanged
2017-02-12 03:01:12 -05:00
, this , & VisibilityManagerPrivate : : raiseDockTemporarily ) ;
2017-02-24 21:40:47 -05:00
connections [ 4 ] = connect ( wm , & AbstractWindowInterface : : currentActivityChanged
2017-02-12 03:01:12 -05:00
, this , & VisibilityManagerPrivate : : raiseDockTemporarily ) ;
2017-01-02 01:04:10 -05:00
timerCheckWindows . start ( ) ;
2016-12-30 02:24:04 -05:00
}
2017-02-12 03:01:12 -05:00
break ;
2016-12-30 02:17:38 -05:00
}
2017-01-16 14:07:49 -05:00
2016-12-30 14:03:46 -05:00
emit q - > modeChanged ( ) ;
2017-02-26 18:43:48 -05:00
saveConfig ( ) ;
2016-12-25 09:25:27 +02:00
}
2016-12-30 02:17:38 -05:00
inline void VisibilityManagerPrivate : : setIsHidden ( bool isHidden )
2016-12-25 09:25:27 +02:00
{
2016-12-30 02:17:38 -05:00
if ( this - > isHidden = = isHidden )
return ;
2017-01-16 14:07:49 -05:00
2017-01-02 03:06:47 -05:00
if ( blockHiding ) {
qWarning ( ) < < " isHidden property is blocked, ignoring update " ;
return ;
}
2017-01-16 14:07:49 -05:00
2016-12-30 02:17:38 -05:00
this - > isHidden = isHidden ;
emit q - > isHiddenChanged ( ) ;
2016-12-29 00:40:35 -05:00
}
2016-12-25 09:25:27 +02:00
2017-01-02 03:06:47 -05:00
void VisibilityManagerPrivate : : setBlockHiding ( bool blockHiding )
{
if ( this - > blockHiding = = blockHiding )
return ;
2017-01-16 14:07:49 -05:00
2017-01-02 03:06:47 -05:00
this - > blockHiding = blockHiding ;
2017-01-28 19:34:03 +02:00
// qDebug() << "blockHiding:" << blockHiding;
2017-01-16 14:07:49 -05:00
2017-01-02 03:06:47 -05:00
if ( this - > blockHiding ) {
timerHide . stop ( ) ;
2017-01-16 14:07:49 -05:00
2017-01-03 19:52:31 -05:00
if ( isHidden ) {
2017-01-02 03:06:47 -05:00
isHidden = false ;
2017-01-03 19:52:31 -05:00
emit q - > isHiddenChanged ( ) ;
emit q - > mustBeShown ( ) ;
}
2017-01-02 03:06:47 -05:00
} else {
updateHiddenState ( ) ;
}
2017-01-16 14:07:49 -05:00
2017-01-02 03:06:47 -05:00
emit q - > blockHidingChanged ( ) ;
}
2016-12-30 02:17:38 -05:00
inline void VisibilityManagerPrivate : : setTimerShow ( int msec )
2016-12-25 09:25:27 +02:00
{
2016-12-30 02:17:38 -05:00
timerShow . setInterval ( msec ) ;
saveConfig ( ) ;
emit q - > timerShowChanged ( ) ;
2016-12-25 09:25:27 +02:00
}
2016-12-30 02:17:38 -05:00
inline void VisibilityManagerPrivate : : setTimerHide ( int msec )
2016-12-25 09:25:27 +02:00
{
2016-12-30 02:17:38 -05:00
timerHide . setInterval ( msec ) ;
saveConfig ( ) ;
emit q - > timerHideChanged ( ) ;
2016-12-25 09:25:27 +02:00
}
2016-12-30 02:17:38 -05:00
inline void VisibilityManagerPrivate : : raiseDock ( bool raise )
2016-12-25 09:25:27 +02:00
{
2016-12-29 00:40:35 -05:00
if ( raise ) {
timerHide . stop ( ) ;
2017-01-16 14:07:49 -05:00
2016-12-30 20:24:21 +02:00
if ( ! timerShow . isActive ( ) ) {
2016-12-29 00:40:35 -05:00
timerShow . start ( ) ;
2016-12-30 13:46:56 +02:00
}
2017-01-03 12:36:40 -05:00
} else if ( ! blockHiding & & ! dragEnter ) {
2016-12-29 00:40:35 -05:00
timerShow . stop ( ) ;
2017-01-16 14:07:49 -05:00
2017-02-12 03:01:12 -05:00
if ( hideNow ) {
hideNow = false ;
emit q - > mustBeHide ( ) ;
} else if ( ! timerHide . isActive ( ) )
2016-12-29 00:40:35 -05:00
timerHide . start ( ) ;
}
2016-12-25 09:25:27 +02:00
}
2017-02-12 03:01:12 -05:00
void VisibilityManagerPrivate : : raiseDockTemporarily ( )
{
if ( raiseTemporarily )
return ;
raiseTemporarily = true ;
timerHide . stop ( ) ;
timerShow . stop ( ) ;
if ( isHidden )
emit q - > mustBeShown ( ) ;
QTimer : : singleShot ( 1800 , this , [ & ] ( ) {
raiseTemporarily = false ;
hideNow = true ;
updateHiddenState ( ) ;
} ) ;
}
2017-01-02 03:06:47 -05:00
void VisibilityManagerPrivate : : updateHiddenState ( )
{
2017-01-03 12:36:40 -05:00
if ( dragEnter )
return ;
2017-01-16 14:07:49 -05:00
2017-01-02 03:06:47 -05:00
switch ( mode ) {
case Dock : : AutoHide :
2017-01-03 12:36:40 -05:00
raiseDock ( containsMouse ) ;
2017-01-02 03:06:47 -05:00
break ;
2017-01-16 14:07:49 -05:00
2017-01-02 03:06:47 -05:00
case Dock : : DodgeActive :
dodgeActive ( wm - > activeWindow ( ) ) ;
break ;
2017-01-16 14:07:49 -05:00
2017-01-02 03:06:47 -05:00
case Dock : : DodgeMaximized :
dodgeMaximized ( wm - > activeWindow ( ) ) ;
break ;
2017-01-16 14:07:49 -05:00
2017-01-02 03:06:47 -05:00
case Dock : : DodgeAllWindows :
dodgeWindows ( wm - > activeWindow ( ) ) ;
break ;
}
}
2017-02-10 22:12:17 -05:00
inline void VisibilityManagerPrivate : : setDockGeometry ( const QRect & geometry )
2016-12-25 09:25:27 +02:00
{
2017-02-10 22:12:17 -05:00
if ( ! view - > containment ( ) | | this - > dockGeometry = = geometry )
2016-12-30 02:17:38 -05:00
return ;
2017-01-16 14:07:49 -05:00
2017-02-10 22:12:17 -05:00
this - > dockGeometry = geometry ;
2017-01-16 14:07:49 -05:00
2017-01-13 17:01:30 -05:00
if ( mode = = Dock : : AlwaysVisible & & ! view - > containment ( ) - > isUserConfiguring ( ) ) {
2017-02-24 21:40:47 -05:00
wm - > setDockStruts ( view - > winId ( ) , this - > dockGeometry , view - > containment ( ) - > location ( ) ) ;
2016-12-30 02:17:38 -05:00
}
2016-12-25 09:25:27 +02:00
}
2016-12-30 02:17:38 -05:00
void VisibilityManagerPrivate : : dodgeActive ( WId wid )
2016-12-25 09:25:27 +02:00
{
2017-02-12 03:01:12 -05:00
if ( raiseTemporarily )
return ;
2016-12-30 02:17:38 -05:00
auto winfo = wm - > requestInfo ( wid ) ;
2017-01-16 14:07:49 -05:00
2017-01-02 01:04:10 -05:00
if ( ! winfo . isValid ( ) )
2016-12-30 02:17:38 -05:00
return ;
2017-01-16 14:07:49 -05:00
2017-01-02 01:04:10 -05:00
if ( ! winfo . isActive ( ) ) {
if ( winfo . isPlasmaDesktop ( ) )
raiseDock ( true ) ;
2017-01-16 14:07:49 -05:00
2017-01-02 01:04:10 -05:00
return ;
}
2017-01-16 14:07:49 -05:00
2017-01-02 01:04:10 -05:00
raiseDock ( wm - > isOnCurrentDesktop ( wid ) & & ! intersects ( winfo ) ) ;
2016-12-25 09:25:27 +02:00
}
2016-12-30 02:17:38 -05:00
void VisibilityManagerPrivate : : dodgeMaximized ( WId wid )
2016-12-25 09:25:27 +02:00
{
2017-02-12 03:01:12 -05:00
if ( raiseTemporarily )
return ;
2016-12-30 02:17:38 -05:00
auto winfo = wm - > requestInfo ( wid ) ;
2017-01-16 14:07:49 -05:00
2017-01-02 01:04:10 -05:00
if ( ! winfo . isValid ( ) )
2016-12-30 02:17:38 -05:00
return ;
2017-01-16 14:07:49 -05:00
2017-01-02 01:04:10 -05:00
if ( ! winfo . isActive ( ) ) {
if ( winfo . isPlasmaDesktop ( ) )
raiseDock ( true ) ;
2017-01-16 14:07:49 -05:00
2017-01-02 01:04:10 -05:00
return ;
}
2017-01-16 14:07:49 -05:00
2017-01-02 01:04:10 -05:00
raiseDock ( wm - > isOnCurrentDesktop ( wid ) & & ! winfo . isMaximized ( ) ) ;
2016-12-25 09:25:27 +02:00
}
2016-12-30 02:17:38 -05:00
void VisibilityManagerPrivate : : dodgeWindows ( WId wid )
2016-12-25 09:25:27 +02:00
{
2017-02-12 03:01:12 -05:00
if ( raiseTemporarily )
return ;
2017-01-02 01:04:10 -05:00
if ( windows . find ( wid ) = = std : : end ( windows ) )
return ;
2017-01-16 14:07:49 -05:00
2016-12-30 02:17:38 -05:00
auto winfo = wm - > requestInfo ( wid ) ;
2017-01-02 01:04:10 -05:00
windows [ wid ] = winfo ;
2017-01-16 14:07:49 -05:00
2017-01-02 01:04:10 -05:00
if ( ! winfo . isValid ( ) | | ! wm - > isOnCurrentDesktop ( wid ) )
2016-12-30 02:17:38 -05:00
return ;
2017-01-16 14:07:49 -05:00
2016-12-30 02:17:38 -05:00
if ( intersects ( winfo ) )
raiseDock ( false ) ;
else
timerCheckWindows . start ( ) ;
2016-12-25 09:25:27 +02:00
}
2016-12-29 00:40:35 -05:00
void VisibilityManagerPrivate : : checkAllWindows ( )
2016-12-25 09:25:27 +02:00
{
2017-02-12 03:01:12 -05:00
if ( raiseTemporarily )
return ;
2016-12-30 02:17:38 -05:00
bool raise { true } ;
2017-01-16 14:07:49 -05:00
2016-12-30 02:17:38 -05:00
for ( const auto & winfo : windows ) {
//! std::pair<WId, WindowInfoWrap>
2017-01-02 01:04:10 -05:00
if ( ! std : : get < 1 > ( winfo ) . isValid ( ) | | ! wm - > isOnCurrentDesktop ( std : : get < 0 > ( winfo ) ) )
2016-12-30 02:17:38 -05:00
continue ;
2017-01-16 14:07:49 -05:00
2016-12-30 02:17:38 -05:00
if ( std : : get < 1 > ( winfo ) . isFullscreen ( ) ) {
raise = false ;
break ;
} else if ( intersects ( std : : get < 1 > ( winfo ) ) ) {
raise = false ;
break ;
}
}
2017-01-16 14:07:49 -05:00
2016-12-30 02:17:38 -05:00
raiseDock ( raise ) ;
2016-12-25 09:25:27 +02:00
}
2016-12-30 02:17:38 -05:00
inline bool VisibilityManagerPrivate : : intersects ( const WindowInfoWrap & winfo )
2016-12-25 09:25:27 +02:00
{
2017-02-10 22:12:17 -05:00
return ! winfo . isMinimized ( ) & & winfo . geometry ( ) . intersects ( dockGeometry ) ;
2016-12-25 09:25:27 +02:00
}
2016-12-30 02:17:38 -05:00
inline void VisibilityManagerPrivate : : saveConfig ( )
2016-12-25 09:25:27 +02:00
{
2016-12-30 02:17:38 -05:00
if ( ! view - > containment ( ) )
return ;
2017-01-16 14:07:49 -05:00
2016-12-30 02:17:38 -05:00
auto config = view - > containment ( ) - > config ( ) ;
config . writeEntry ( " visibility " , static_cast < int > ( mode ) ) ;
config . writeEntry ( " timerShow " , timerShow . interval ( ) ) ;
config . writeEntry ( " timerHide " , timerHide . interval ( ) ) ;
view - > containment ( ) - > configNeedsSaving ( ) ;
2016-12-25 09:25:27 +02:00
}
2016-12-30 02:17:38 -05:00
inline void VisibilityManagerPrivate : : restoreConfig ( )
2016-12-25 09:25:27 +02:00
{
2016-12-30 02:17:38 -05:00
if ( ! view - > containment ( ) )
2016-12-30 02:24:04 -05:00
return ;
2017-01-16 14:07:49 -05:00
2016-12-30 02:24:04 -05:00
auto config = view - > containment ( ) - > config ( ) ;
2017-01-12 13:53:06 +02:00
timerShow . setInterval ( config . readEntry ( " timerShow " , 200 ) ) ;
timerHide . setInterval ( config . readEntry ( " timerHide " , 700 ) ) ;
2017-01-03 12:01:29 -05:00
auto mode = static_cast < Dock : : Visibility > ( config . readEntry ( " visibility " , static_cast < int > ( Dock : : DodgeActive ) ) ) ;
2016-12-30 14:33:42 -05:00
emit q - > timerShowChanged ( ) ;
emit q - > timerHideChanged ( ) ;
2017-02-11 00:55:22 -05:00
2017-02-12 03:01:12 -05:00
if ( mode = = Dock : : AlwaysVisible ) {
setMode ( mode ) ;
} else {
2017-02-26 18:43:48 -05:00
QTimer : : singleShot ( 3000 , this , [ & , mode ] ( ) {
2017-02-11 00:55:22 -05:00
setMode ( mode ) ;
} ) ;
}
2016-12-25 09:25:27 +02:00
}
2016-12-29 00:40:35 -05:00
bool VisibilityManagerPrivate : : event ( QEvent * ev )
2016-12-25 09:25:27 +02:00
{
2017-01-03 12:36:40 -05:00
switch ( ev - > type ( ) ) {
2017-01-05 17:48:27 +02:00
case QEvent : : Enter :
if ( containsMouse )
break ;
2017-01-16 14:07:49 -05:00
2017-01-05 17:48:27 +02:00
containsMouse = true ;
emit q - > containsMouseChanged ( ) ;
2017-01-16 14:07:49 -05:00
2017-01-05 17:48:27 +02:00
if ( mode ! = Dock : : AlwaysVisible )
raiseDock ( true ) ;
2017-01-16 14:07:49 -05:00
2017-01-03 12:36:40 -05:00
break ;
2017-01-16 14:07:49 -05:00
2017-01-05 17:48:27 +02:00
case QEvent : : Leave :
if ( ! containsMouse )
break ;
2017-01-16 14:07:49 -05:00
2017-01-05 17:48:27 +02:00
containsMouse = false ;
emit q - > containsMouseChanged ( ) ;
updateHiddenState ( ) ;
break ;
2017-01-16 14:07:49 -05:00
2017-01-05 17:48:27 +02:00
case QEvent : : DragEnter :
dragEnter = true ;
emit q - > mustBeShown ( ) ;
break ;
2017-01-16 14:07:49 -05:00
2017-01-05 17:48:27 +02:00
case QEvent : : DragLeave :
case QEvent : : Drop :
dragEnter = false ;
updateHiddenState ( ) ;
break ;
2017-01-16 14:07:49 -05:00
2017-01-05 17:48:27 +02:00
case QEvent : : Show :
2017-02-24 21:40:47 -05:00
wm - > setDockExtraFlags ( * view ) ;
2017-01-05 17:48:27 +02:00
restoreConfig ( ) ;
2017-01-03 12:36:40 -05:00
break ;
2016-12-25 09:25:27 +02:00
}
2017-01-16 14:07:49 -05:00
2016-12-29 00:40:35 -05:00
return QObject : : event ( ev ) ;
2016-12-25 09:25:27 +02:00
}
2017-01-12 18:53:59 -05:00
//! END: VisibilityManagerPrivate implementation
2016-12-29 00:40:35 -05:00
//! BEGIN: VisiblityManager implementation
VisibilityManager : : VisibilityManager ( PlasmaQuick : : ContainmentView * view )
: d ( new VisibilityManagerPrivate ( view , this ) )
2016-12-25 09:25:27 +02:00
{
}
2016-12-29 00:40:35 -05:00
VisibilityManager : : ~ VisibilityManager ( )
2016-12-25 09:25:27 +02:00
{
}
2016-12-29 00:40:35 -05:00
Dock : : Visibility VisibilityManager : : mode ( ) const
2016-12-25 09:25:27 +02:00
{
2016-12-29 00:40:35 -05:00
return d - > mode ;
2016-12-25 09:25:27 +02:00
}
2016-12-29 00:40:35 -05:00
void VisibilityManager : : setMode ( Dock : : Visibility mode )
2016-12-25 09:25:27 +02:00
{
2016-12-29 00:40:35 -05:00
d - > setMode ( mode ) ;
}
2016-12-25 09:25:27 +02:00
2016-12-29 00:40:35 -05:00
bool VisibilityManager : : isHidden ( ) const
2016-12-25 09:25:27 +02:00
{
2016-12-29 00:40:35 -05:00
return d - > isHidden ;
2016-12-25 09:25:27 +02:00
}
2016-12-30 02:17:38 -05:00
void VisibilityManager : : setIsHidden ( bool isHidden )
2016-12-25 09:25:27 +02:00
{
2016-12-29 00:40:35 -05:00
d - > setIsHidden ( isHidden ) ;
2016-12-25 09:25:27 +02:00
}
2017-01-02 03:06:47 -05:00
bool VisibilityManager : : blockHiding ( ) const
{
return d - > blockHiding ;
}
void VisibilityManager : : setBlockHiding ( bool blockHiding )
{
d - > setBlockHiding ( blockHiding ) ;
}
2016-12-29 00:40:35 -05:00
bool VisibilityManager : : containsMouse ( ) const
2016-12-25 09:25:27 +02:00
{
2016-12-29 00:40:35 -05:00
return d - > containsMouse ;
2016-12-25 09:25:27 +02:00
}
2016-12-29 00:40:35 -05:00
int VisibilityManager : : timerShow ( ) const
2016-12-25 09:25:27 +02:00
{
2016-12-29 00:40:35 -05:00
return d - > timerShow . interval ( ) ;
2016-12-25 09:25:27 +02:00
}
2016-12-29 00:40:35 -05:00
void VisibilityManager : : setTimerShow ( int msec )
2016-12-25 09:25:27 +02:00
{
2016-12-29 00:40:35 -05:00
d - > setTimerShow ( msec ) ;
2016-12-25 09:25:27 +02:00
}
2016-12-29 00:40:35 -05:00
int VisibilityManager : : timerHide ( ) const
2016-12-25 09:25:27 +02:00
{
2016-12-29 00:40:35 -05:00
return d - > timerHide . interval ( ) ;
2016-12-25 09:25:27 +02:00
}
2016-12-29 00:40:35 -05:00
void VisibilityManager : : setTimerHide ( int msec )
2016-12-25 09:25:27 +02:00
{
2016-12-29 00:40:35 -05:00
d - > setTimerHide ( msec ) ;
2016-12-25 09:25:27 +02:00
}
2016-12-29 00:40:35 -05:00
//! END: VisibilityManager implementation
2016-12-25 09:25:27 +02:00
}