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"
2018-02-03 11:34:13 +02:00
2018-12-02 02:05:52 +02:00
// local
2018-11-29 21:30:00 +02:00
# include "positioner.h"
2018-03-28 20:39:52 +03:00
# include "screenedgeghostwindow.h"
2018-12-06 12:15:58 +02:00
# include "view.h"
2018-12-06 14:35:34 +02:00
# include "../lattecorona.h"
2018-02-03 11:34:13 +02:00
# include "../layoutmanager.h"
2018-08-02 14:23:01 +03:00
# include "../screenpool.h"
2018-12-02 01:29:18 +02:00
# include "../wm/windowinfowrap.h"
2018-12-07 18:55:35 +02:00
# include "../../liblatte2/extras.h"
2016-12-25 09:25:27 +02:00
2018-12-02 02:05:52 +02:00
// Qt
# include <QDebug>
// KDE
2018-03-28 20:39:52 +03:00
# include <KWayland/Client/plasmashell.h>
# include <KWayland/Client/surface.h>
2016-12-29 00:40:35 -05:00
namespace Latte {
2018-12-09 00:29:35 +02:00
namespace ViewPart {
2016-12-25 09:25:27 +02:00
2018-12-20 18:59:38 +02:00
//! BEGIN: VisiblityManager implementation
VisibilityManager : : VisibilityManager ( PlasmaQuick : : ContainmentView * view )
: QObject ( view )
2016-12-29 00:40:35 -05:00
{
2018-12-20 18:59:38 +02:00
qDebug ( ) < < " VisibilityManager creating... " ;
2018-12-06 12:51:15 +02:00
m_latteView = qobject_cast < Latte : : View * > ( view ) ;
2018-12-06 14:35:34 +02:00
m_corona = qobject_cast < Latte : : Corona * > ( view - > corona ( ) ) ;
wm = m_corona - > wm ( ) ;
2017-01-16 14:07:49 -05:00
2018-12-06 12:51:15 +02:00
if ( m_latteView ) {
2018-12-20 18:59:38 +02:00
connect ( m_latteView , & Latte : : View : : absGeometryChanged , this , & VisibilityManager : : setViewGeometry ) ;
connect ( m_latteView , & Latte : : View : : eventTriggered , this , & VisibilityManager : : viewEventManager ) ;
2016-12-30 13:46:56 +02:00
}
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
if ( m_corona ) {
connect ( this , & VisibilityManager : : modeChanged , m_corona , & Plasma : : Corona : : availableScreenRectChanged ) ;
}
m_timerStartUp . setInterval ( 5000 ) ;
m_timerStartUp . setSingleShot ( true ) ;
m_timerShow . setSingleShot ( true ) ;
m_timerHide . setSingleShot ( true ) ;
2019-02-07 20:24:52 +02:00
2018-12-20 18:59:38 +02:00
connect ( & m_timerShow , & QTimer : : timeout , this , [ & ] ( ) {
if ( m_isHidden ) {
2017-01-28 19:34:03 +02:00
// qDebug() << "must be shown";
2018-12-20 18:59:38 +02:00
emit mustBeShown ( ) ;
2017-01-02 01:04:10 -05:00
}
} ) ;
2018-12-20 18:59:38 +02:00
connect ( & m_timerHide , & QTimer : : timeout , this , [ & ] ( ) {
if ( ! m_blockHiding & & ! m_isHidden & & ! dragEnter ) {
2017-01-28 19:34:03 +02:00
// qDebug() << "must be hide";
2018-12-20 18:59:38 +02:00
emit mustBeHide ( ) ;
2017-01-02 01:04:10 -05:00
}
} ) ;
2018-12-20 18:59:38 +02:00
wm - > setViewExtraFlags ( * m_latteView ) ;
wm - > addView ( m_latteView - > 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
2018-12-20 18:59:38 +02:00
VisibilityManager : : ~ VisibilityManager ( )
2016-12-25 09:25:27 +02:00
{
2018-12-20 18:59:38 +02:00
qDebug ( ) < < " VisibilityManager deleting... " ;
wm - > removeViewStruts ( * m_latteView ) ;
wm - > removeView ( m_latteView - > winId ( ) ) ;
2018-03-28 20:39:52 +03:00
if ( edgeGhostWindow ) {
edgeGhostWindow - > deleteLater ( ) ;
}
2016-12-25 09:25:27 +02:00
}
2018-12-20 18:59:38 +02:00
Types : : Visibility VisibilityManager : : mode ( ) const
2016-12-25 09:25:27 +02:00
{
2018-12-20 18:59:38 +02:00
return m_mode ;
}
void VisibilityManager : : setMode ( Latte : : Types : : Visibility mode )
{
if ( m_mode = = mode )
2016-12-30 02:17:38 -05:00
return ;
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
Q_ASSERT_X ( m_mode ! = Types : : None , staticMetaObject . className ( ) , " set visibility to Types::None " ) ;
2017-02-26 18:43:48 -05:00
2016-12-30 02:17:38 -05:00
// clear mode
for ( auto & c : connections ) {
disconnect ( c ) ;
}
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
if ( m_mode = = Types : : AlwaysVisible ) {
wm - > removeViewStruts ( * m_latteView ) ;
2017-03-12 04:01:27 -05:00
} else {
connections [ 3 ] = connect ( wm , & WindowSystem : : currentDesktopChanged
2017-03-12 15:14:30 -05:00
, this , [ & ] {
2017-03-12 04:01:27 -05:00
if ( raiseOnDesktopChange )
2018-12-06 16:17:35 +02:00
raiseViewTemporarily ( ) ;
2017-03-12 04:01:27 -05:00
} ) ;
connections [ 4 ] = connect ( wm , & WindowSystem : : currentActivityChanged
2017-03-12 15:14:30 -05:00
, this , [ & ] ( ) {
if ( raiseOnActivityChange )
2018-12-06 16:17:35 +02:00
raiseViewTemporarily ( ) ;
2017-03-12 15:14:30 -05:00
else
updateHiddenState ( ) ;
2017-03-12 04:01:27 -05:00
} ) ;
}
2018-12-20 18:59:38 +02:00
m_timerShow . stop ( ) ;
m_timerHide . stop ( ) ;
m_mode = mode ;
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
switch ( m_mode ) {
2018-12-07 18:55:35 +02:00
case Types : : AlwaysVisible : {
2018-03-28 20:39:52 +03:00
//set wayland visibility mode
2018-12-06 12:51:15 +02:00
if ( m_latteView - > surface ( ) ) {
m_latteView - > surface ( ) - > setPanelBehavior ( KWayland : : Client : : PlasmaShellSurface : : PanelBehavior : : WindowsGoBelow ) ;
2018-03-28 20:39:52 +03:00
}
2018-12-20 18:59:38 +02:00
if ( m_latteView - > containment ( ) & & ! m_latteView - > inEditMode ( ) & & m_latteView - > screen ( ) ) {
2018-01-13 20:00:03 +02:00
updateStrutsBasedOnLayoutsAndActivities ( ) ;
2017-03-23 00:03:45 -05:00
}
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
connections [ 0 ] = connect ( m_latteView - > containment ( ) , & Plasma : : Containment : : locationChanged
2017-01-16 13:24:46 -05:00
, this , [ & ] ( ) {
2018-12-06 12:51:15 +02:00
if ( m_latteView - > inEditMode ( ) )
2018-12-20 18:59:38 +02:00
wm - > removeViewStruts ( * m_latteView ) ;
2017-01-13 16:33:42 -05:00
} ) ;
2018-12-06 12:51:15 +02:00
connections [ 1 ] = connect ( m_latteView , & Latte : : View : : inEditModeChanged
2018-02-12 16:11:33 +02:00
, this , [ & ] ( ) {
2018-12-20 18:59:38 +02:00
if ( ! m_latteView - > inEditMode ( ) & & ! m_latteView - > positioner ( ) - > inLocationChangeAnimation ( ) & & m_latteView - > screen ( ) )
wm - > setViewStruts ( * m_latteView , m_viewGeometry , m_latteView - > containment ( ) - > location ( ) ) ;
2017-01-13 16:33:42 -05:00
} ) ;
2018-01-13 19:27:32 +02:00
2018-12-07 18:55:35 +02:00
if ( m_corona & & m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Types : : MultipleLayouts ) {
2018-12-06 14:35:34 +02:00
connections [ 2 ] = connect ( m_corona - > activitiesConsumer ( ) , & KActivities : : Consumer : : currentActivityChanged , this , [ & ] ( ) {
2018-01-13 20:00:03 +02:00
updateStrutsBasedOnLayoutsAndActivities ( ) ;
2018-01-13 19:27:32 +02:00
} ) ;
2018-12-06 12:51:15 +02:00
connections [ 3 ] = connect ( m_latteView , & Latte : : View : : activitiesChanged , this , [ & ] ( ) {
2018-01-14 13:21:11 +02:00
updateStrutsBasedOnLayoutsAndActivities ( ) ;
} ) ;
2018-01-13 19:27:32 +02:00
}
2018-12-06 16:17:35 +02:00
raiseView ( true ) ;
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
2018-12-07 18:55:35 +02:00
case Types : : AutoHide : {
2018-03-28 20:39:52 +03:00
//set wayland visibility mode
2018-12-06 12:51:15 +02:00
if ( m_latteView - > surface ( ) ) {
m_latteView - > surface ( ) - > setPanelBehavior ( KWayland : : Client : : PlasmaShellSurface : : PanelBehavior : : AutoHide ) ;
2018-03-28 20:39:52 +03:00
}
2018-12-20 18:59:38 +02:00
raiseView ( m_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
2018-12-07 18:55:35 +02:00
case Types : : DodgeActive : {
2018-03-28 20:39:52 +03:00
//set wayland visibility mode
2018-12-06 12:51:15 +02:00
if ( m_latteView - > surface ( ) ) {
m_latteView - > surface ( ) - > setPanelBehavior ( KWayland : : Client : : PlasmaShellSurface : : PanelBehavior : : AutoHide ) ;
2018-03-28 20:39:52 +03:00
}
2017-03-12 04:01:27 -05:00
connections [ 0 ] = connect ( wm , & WindowSystem : : activeWindowChanged
2018-12-20 18:59:38 +02:00
, this , & VisibilityManager : : dodgeActive ) ;
2017-03-12 04:01:27 -05:00
connections [ 1 ] = connect ( wm , & WindowSystem : : windowChanged
2018-12-20 18:59:38 +02:00
, this , & VisibilityManager : : dodgeActive ) ;
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
2018-12-07 18:55:35 +02:00
case Types : : DodgeMaximized : {
2018-03-28 20:39:52 +03:00
//set wayland visibility mode
2018-12-06 12:51:15 +02:00
if ( m_latteView - > surface ( ) ) {
m_latteView - > surface ( ) - > setPanelBehavior ( KWayland : : Client : : PlasmaShellSurface : : PanelBehavior : : AutoHide ) ;
2018-03-28 20:39:52 +03:00
}
2017-03-12 04:01:27 -05:00
connections [ 0 ] = connect ( wm , & WindowSystem : : activeWindowChanged
2018-12-20 18:59:38 +02:00
, this , & VisibilityManager : : dodgeMaximized ) ;
2017-03-12 04:01:27 -05:00
connections [ 1 ] = connect ( wm , & WindowSystem : : windowChanged
2018-12-20 18:59:38 +02:00
, this , & VisibilityManager : : dodgeMaximized ) ;
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
2018-12-07 18:55:35 +02:00
case Types : : DodgeAllWindows : {
2018-03-28 20:39:52 +03:00
//set wayland visibility mode
2018-12-06 12:51:15 +02:00
if ( m_latteView - > surface ( ) ) {
m_latteView - > surface ( ) - > setPanelBehavior ( KWayland : : Client : : PlasmaShellSurface : : PanelBehavior : : AutoHide ) ;
2018-03-28 20:39:52 +03:00
}
2019-02-07 20:24:52 +02:00
connections [ 0 ] = connect ( this , & VisibilityManager : : containsMouseChanged
, this , & VisibilityManager : : dodgeAllWindows ) ;
2017-01-16 14:07:49 -05:00
2019-02-07 20:24:52 +02:00
connections [ 1 ] = connect ( m_latteView - > windowsTracker ( ) , & WindowsTracker : : existsWindowTouchingChanged
, this , & VisibilityManager : : dodgeAllWindows ) ;
2016-12-30 02:24:04 -05:00
}
2017-02-12 03:01:12 -05:00
break ;
2017-06-04 02:43:52 +03:00
2018-12-07 18:55:35 +02:00
case Types : : WindowsGoBelow :
2018-03-28 20:39:52 +03:00
//set wayland visibility mode
2018-12-06 12:51:15 +02:00
if ( m_latteView - > surface ( ) ) {
m_latteView - > surface ( ) - > setPanelBehavior ( KWayland : : Client : : PlasmaShellSurface : : PanelBehavior : : WindowsGoBelow ) ;
2018-03-28 20:39:52 +03:00
}
2017-06-08 17:10:49 -05:00
break ;
default :
break ;
2016-12-30 02:17:38 -05:00
}
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
m_latteView - > containment ( ) - > config ( ) . writeEntry ( " visibility " , static_cast < int > ( m_mode ) ) ;
2017-03-12 04:01:27 -05:00
2018-03-28 20:39:52 +03:00
updateKWinEdgesSupport ( ) ;
2018-12-20 18:59:38 +02:00
emit modeChanged ( ) ;
2017-03-12 04:01:27 -05:00
}
2018-12-20 18:59:38 +02:00
void VisibilityManager : : updateStrutsBasedOnLayoutsAndActivities ( )
2018-01-13 20:00:03 +02:00
{
2018-12-07 18:55:35 +02:00
bool multipleLayoutsAndCurrent = ( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Types : : MultipleLayouts
2018-12-06 12:51:15 +02:00
& & m_latteView - > managedLayout ( ) & & ! m_latteView - > positioner ( ) - > inLocationChangeAnimation ( )
2018-12-06 14:35:34 +02:00
& & m_latteView - > managedLayout ( ) - > name ( ) = = m_corona - > layoutManager ( ) - > currentLayoutName ( ) ) ;
2018-01-13 20:00:03 +02:00
2018-12-07 18:55:35 +02:00
if ( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Types : : SingleLayout | | multipleLayoutsAndCurrent ) {
2018-12-20 18:59:38 +02:00
wm - > setViewStruts ( * m_latteView , m_viewGeometry , m_latteView - > location ( ) ) ;
2018-01-13 20:00:03 +02:00
} else {
2018-12-20 18:59:38 +02:00
wm - > removeViewStruts ( * m_latteView ) ;
2018-01-13 20:00:03 +02:00
}
}
2018-12-20 18:59:38 +02:00
bool VisibilityManager : : raiseOnDesktop ( ) const
{
return raiseOnDesktopChange ;
}
void VisibilityManager : : setRaiseOnDesktop ( bool enable )
2017-03-12 04:01:27 -05:00
{
if ( enable = = raiseOnDesktopChange )
return ;
raiseOnDesktopChange = enable ;
2018-12-20 18:59:38 +02:00
emit raiseOnDesktopChanged ( ) ;
2017-03-12 04:01:27 -05:00
}
2018-12-20 18:59:38 +02:00
bool VisibilityManager : : raiseOnActivity ( ) const
{
return raiseOnActivityChange ;
}
void VisibilityManager : : setRaiseOnActivity ( bool enable )
2017-03-12 04:01:27 -05:00
{
if ( enable = = raiseOnActivityChange )
return ;
raiseOnActivityChange = enable ;
2018-12-20 18:59:38 +02:00
emit raiseOnActivityChanged ( ) ;
}
bool VisibilityManager : : isHidden ( ) const
{
return m_isHidden ;
2016-12-25 09:25:27 +02:00
}
2018-12-20 18:59:38 +02:00
void VisibilityManager : : setIsHidden ( bool isHidden )
2016-12-25 09:25:27 +02:00
{
2018-12-20 18:59:38 +02:00
if ( m_isHidden = = isHidden )
2016-12-30 02:17:38 -05:00
return ;
2017-01-16 14:07:49 -05:00
2018-12-26 17:53:17 +02:00
if ( m_blockHiding & & isHidden ) {
2017-01-02 03:06:47 -05:00
qWarning ( ) < < " isHidden property is blocked, ignoring update " ;
return ;
}
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
m_isHidden = isHidden ;
2018-03-28 20:39:52 +03:00
2019-02-24 19:09:48 +02:00
updateGhostWindowState ( ) ;
2018-03-28 20:39:52 +03:00
2018-12-20 18:59:38 +02:00
emit isHiddenChanged ( ) ;
2016-12-29 00:40:35 -05:00
}
2016-12-25 09:25:27 +02:00
2018-12-20 18:59:38 +02:00
bool VisibilityManager : : blockHiding ( ) const
2017-01-02 03:06:47 -05:00
{
2018-12-20 18:59:38 +02:00
return m_blockHiding ;
}
void VisibilityManager : : setBlockHiding ( bool blockHiding )
{
if ( m_blockHiding = = blockHiding ) {
2017-01-02 03:06:47 -05:00
return ;
2018-12-20 18:59:38 +02:00
}
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
m_blockHiding = blockHiding ;
2017-01-28 19:34:03 +02:00
// qDebug() << "blockHiding:" << blockHiding;
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
if ( m_blockHiding ) {
m_timerHide . stop ( ) ;
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
if ( m_isHidden ) {
emit mustBeShown ( ) ;
2017-01-03 19:52:31 -05:00
}
2017-01-02 03:06:47 -05:00
} else {
updateHiddenState ( ) ;
}
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
emit blockHidingChanged ( ) ;
}
int VisibilityManager : : timerShow ( ) const
{
return m_timerShow . interval ( ) ;
}
void VisibilityManager : : setTimerShow ( int msec )
{
m_timerShow . setInterval ( msec ) ;
emit timerShowChanged ( ) ;
}
int VisibilityManager : : timerHide ( ) const
{
return m_timerHide . interval ( ) ;
2017-01-02 03:06:47 -05:00
}
2018-12-20 18:59:38 +02:00
void VisibilityManager : : setTimerHide ( int msec )
2016-12-25 09:25:27 +02:00
{
2018-12-20 18:59:38 +02:00
m_timerHide . setInterval ( msec ) ;
emit timerHideChanged ( ) ;
2016-12-25 09:25:27 +02:00
}
2018-12-20 18:59:38 +02:00
bool VisibilityManager : : supportsKWinEdges ( ) const
2016-12-25 09:25:27 +02:00
{
2018-12-20 18:59:38 +02:00
return ( edgeGhostWindow ! = nullptr ) ;
2016-12-25 09:25:27 +02:00
}
2019-02-24 19:09:48 +02:00
void VisibilityManager : : updateGhostWindowState ( )
{
if ( supportsKWinEdges ( ) ) {
bool inCurrentLayout = ( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Types : : SingleLayout | |
( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Types : : MultipleLayouts
& & m_latteView - > managedLayout ( ) & & ! m_latteView - > positioner ( ) - > inLocationChangeAnimation ( )
& & m_latteView - > managedLayout ( ) - > name ( ) = = m_corona - > layoutManager ( ) - > currentLayoutName ( ) ) ) ;
if ( inCurrentLayout ) {
wm - > setEdgeStateFor ( edgeGhostWindow , m_isHidden ) ;
} else {
wm - > setEdgeStateFor ( edgeGhostWindow , false ) ;
}
}
}
2018-12-20 18:59:38 +02:00
void VisibilityManager : : raiseView ( bool raise )
2016-12-25 09:25:27 +02:00
{
2018-12-20 18:59:38 +02:00
if ( m_blockHiding )
2017-03-12 12:16:23 -05:00
return ;
2016-12-29 00:40:35 -05:00
if ( raise ) {
2018-12-20 18:59:38 +02:00
m_timerHide . stop ( ) ;
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
if ( ! m_timerShow . isActive ( ) ) {
m_timerShow . start ( ) ;
2016-12-30 13:46:56 +02:00
}
2017-03-12 12:16:23 -05:00
} else if ( ! dragEnter ) {
2018-12-20 18:59:38 +02:00
m_timerShow . stop ( ) ;
2017-01-16 14:07:49 -05:00
2017-02-12 03:01:12 -05:00
if ( hideNow ) {
hideNow = false ;
2018-12-20 18:59:38 +02:00
emit mustBeHide ( ) ;
} else if ( ! m_timerHide . isActive ( ) ) {
m_timerHide . start ( ) ;
2018-11-13 19:06:33 +02:00
}
2016-12-29 00:40:35 -05:00
}
2016-12-25 09:25:27 +02:00
}
2018-12-20 18:59:38 +02:00
void VisibilityManager : : raiseViewTemporarily ( )
2017-02-12 03:01:12 -05:00
{
2017-03-12 04:01:27 -05:00
if ( raiseTemporarily )
2017-02-12 03:01:12 -05:00
return ;
raiseTemporarily = true ;
2018-12-20 18:59:38 +02:00
m_timerHide . stop ( ) ;
m_timerShow . stop ( ) ;
2017-02-12 03:01:12 -05:00
2018-12-20 18:59:38 +02:00
if ( m_isHidden )
emit mustBeShown ( ) ;
2017-02-12 03:01:12 -05:00
2018-12-20 18:59:38 +02:00
QTimer : : singleShot ( qBound ( 1800 , 2 * m_timerHide . interval ( ) , 3000 ) , this , [ & ] ( ) {
2017-03-07 23:26:09 +02:00
raiseTemporarily = false ;
hideNow = true ;
updateHiddenState ( ) ;
2017-02-12 03:01:12 -05:00
} ) ;
}
2018-12-20 18:59:38 +02:00
void VisibilityManager : : updateHiddenState ( )
2017-01-02 03:06:47 -05:00
{
2017-01-03 12:36:40 -05:00
if ( dragEnter )
return ;
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
switch ( m_mode ) {
2018-12-07 18:55:35 +02:00
case Types : : AutoHide :
2018-12-20 18:59:38 +02:00
raiseView ( m_containsMouse ) ;
2017-01-02 03:06:47 -05:00
break ;
2017-01-16 14:07:49 -05:00
2018-12-07 18:55:35 +02:00
case Types : : DodgeActive :
2017-01-02 03:06:47 -05:00
dodgeActive ( wm - > activeWindow ( ) ) ;
break ;
2017-01-16 14:07:49 -05:00
2018-12-07 18:55:35 +02:00
case Types : : DodgeMaximized :
2017-01-02 03:06:47 -05:00
dodgeMaximized ( wm - > activeWindow ( ) ) ;
break ;
2017-01-16 14:07:49 -05:00
2018-12-07 18:55:35 +02:00
case Types : : DodgeAllWindows :
2019-02-07 20:24:52 +02:00
dodgeAllWindows ( ) ;
2017-01-02 03:06:47 -05:00
break ;
2017-08-13 13:00:46 +03:00
2017-06-08 17:10:49 -05:00
default :
break ;
2017-01-02 03:06:47 -05:00
}
}
2018-12-20 18:59:38 +02:00
void VisibilityManager : : setViewGeometry ( const QRect & geometry )
2016-12-25 09:25:27 +02:00
{
2018-12-20 18:59:38 +02:00
if ( ! m_latteView - > containment ( ) )
2016-12-30 02:17:38 -05:00
return ;
2017-01-16 14:07:49 -05:00
2018-12-06 16:17:35 +02:00
m_viewGeometry = geometry ;
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
if ( m_mode = = Types : : AlwaysVisible & & ! m_latteView - > inEditMode ( ) & & m_latteView - > screen ( ) ) {
2018-01-13 20:00:03 +02:00
updateStrutsBasedOnLayoutsAndActivities ( ) ;
2016-12-30 02:17:38 -05:00
}
2016-12-25 09:25:27 +02:00
}
2018-12-20 18:59:38 +02:00
void VisibilityManager : : applyActivitiesToHiddenWindows ( const QStringList & activities )
2018-03-28 20:39:52 +03:00
{
if ( edgeGhostWindow ) {
wm - > setWindowOnActivities ( * edgeGhostWindow , activities ) ;
}
}
2019-02-07 19:32:29 +02:00
void VisibilityManager : : activeWindowDraggingStarted ( )
{
setContainsMouse ( false ) ;
updateHiddenState ( ) ;
}
2018-12-20 18:59:38 +02:00
void VisibilityManager : : dodgeActive ( WindowId wid )
2016-12-25 09:25:27 +02:00
{
2017-02-12 03:01:12 -05:00
if ( raiseTemporarily )
return ;
2018-12-06 16:17:35 +02:00
//!don't send false raiseView signal when containing mouse
2018-12-20 18:59:38 +02:00
if ( m_containsMouse ) {
2018-12-06 16:17:35 +02:00
raiseView ( true ) ;
2017-08-13 13:24:32 +03:00
return ;
}
2016-12-30 02:17:38 -05:00
auto winfo = wm - > requestInfo ( wid ) ;
2017-01-16 14:07:49 -05:00
2018-09-01 17:45:08 +03:00
if ( ! winfo . isValid ( ) | | ! winfo . isActive ( ) ) {
2017-03-12 04:01:27 -05:00
winfo = wm - > requestInfo ( wm - > activeWindow ( ) ) ;
2018-08-31 15:27:21 +03:00
if ( ! winfo . isValid ( ) ) {
2019-01-01 11:19:44 +02:00
//! very rare case that window manager doesn't have any active window at all
2018-12-06 16:17:35 +02:00
raiseView ( true ) ;
2018-08-31 15:27:21 +03:00
return ;
}
2017-01-02 01:04:10 -05:00
}
2017-01-16 14:07:49 -05:00
2018-12-06 16:17:35 +02:00
//! don't send false raiseView signal when containing mouse, // Johan comment
2019-01-01 11:19:44 +02:00
//! I don't know why that wasn't winfo.wid() //active window, but just wid//the window that made the call
2018-08-31 16:49:47 +03:00
if ( wm - > isOnCurrentDesktop ( winfo . wid ( ) ) & & wm - > isOnCurrentActivity ( winfo . wid ( ) ) ) {
2018-09-01 17:45:08 +03:00
bool overlaps { intersects ( winfo ) } ;
2018-12-06 16:17:35 +02:00
raiseView ( ! overlaps ) ;
2017-08-13 13:00:46 +03:00
}
2016-12-25 09:25:27 +02:00
}
2018-12-20 18:59:38 +02:00
void VisibilityManager : : dodgeMaximized ( WindowId wid )
2016-12-25 09:25:27 +02:00
{
2017-02-12 03:01:12 -05:00
if ( raiseTemporarily )
return ;
2018-12-06 16:17:35 +02:00
//!don't send false raiseView signal when containing mouse
2018-12-20 18:59:38 +02:00
if ( m_containsMouse ) {
2018-12-06 16:17:35 +02:00
raiseView ( true ) ;
2017-08-13 13:24:32 +03:00
return ;
}
2016-12-30 02:17:38 -05:00
auto winfo = wm - > requestInfo ( wid ) ;
2017-01-16 14:07:49 -05:00
2018-09-01 17:45:08 +03:00
if ( ! winfo . isValid ( ) | | ! winfo . isActive ( ) ) {
2017-03-12 04:01:27 -05:00
winfo = wm - > requestInfo ( wm - > activeWindow ( ) ) ;
2018-08-31 15:27:21 +03:00
if ( ! winfo . isValid ( ) ) {
2019-01-01 11:19:44 +02:00
//! very rare case that window manager doesn't have any active window at all
2018-12-06 16:17:35 +02:00
raiseView ( true ) ;
2018-08-31 15:27:21 +03:00
return ;
}
2017-01-02 01:04:10 -05:00
}
2017-01-16 14:07:49 -05:00
2018-09-01 17:45:08 +03:00
auto intersectsMaxVert = [ & ] ( ) noexcept - > bool {
2018-03-08 18:08:55 +02:00
return ( ( winfo . isMaxVert ( )
2018-12-20 18:59:38 +02:00
| | ( m_latteView - > screen ( ) & & m_latteView - > screen ( ) - > availableSize ( ) . height ( ) < = winfo . geometry ( ) . height ( ) ) )
2018-03-08 18:08:55 +02:00
& & intersects ( winfo ) ) ;
2017-03-23 22:15:04 -05:00
} ;
2018-09-01 17:45:08 +03:00
auto intersectsMaxHoriz = [ & ] ( ) noexcept - > bool {
2018-03-08 18:08:55 +02:00
return ( ( winfo . isMaxHoriz ( )
2018-12-20 18:59:38 +02:00
| | ( m_latteView - > screen ( ) & & m_latteView - > screen ( ) - > availableSize ( ) . width ( ) < = winfo . geometry ( ) . width ( ) ) )
2018-03-08 18:08:55 +02:00
& & intersects ( winfo ) ) ;
2017-03-23 22:15:04 -05:00
} ;
2018-12-06 16:17:35 +02:00
//! don't send false raiseView signal when containing mouse, // Johan comment
2019-01-01 11:19:44 +02:00
//! I don't know why that wasn't winfo.wid() //active window, but just wid//the window that made the call
2018-08-31 16:49:47 +03:00
if ( wm - > isOnCurrentDesktop ( winfo . wid ( ) ) & & wm - > isOnCurrentActivity ( winfo . wid ( ) ) ) {
2018-12-20 18:59:38 +02:00
bool overlapsMaximized { m_latteView - > formFactor ( ) = = Plasma : : Types : : Vertical ? intersectsMaxHoriz ( ) : intersectsMaxVert ( ) } ;
2018-12-06 16:17:35 +02:00
raiseView ( ! overlapsMaximized ) ;
2018-08-31 16:49:47 +03:00
}
2016-12-25 09:25:27 +02:00
}
2019-02-07 20:24:52 +02:00
void VisibilityManager : : dodgeAllWindows ( )
2016-12-25 09:25:27 +02:00
{
2017-02-12 03:01:12 -05:00
if ( raiseTemporarily )
return ;
2018-12-20 18:59:38 +02:00
if ( m_containsMouse ) {
2018-12-06 16:17:35 +02:00
raiseView ( true ) ;
2017-08-13 13:24:32 +03:00
}
2019-02-07 20:24:52 +02:00
bool windowIntersects { m_latteView - > windowsTracker ( ) - > activeWindowTouching ( ) | | m_latteView - > windowsTracker ( ) - > existsWindowTouching ( ) } ;
2017-01-16 14:07:49 -05:00
2019-02-07 20:24:52 +02:00
raiseView ( ! windowIntersects ) ;
2016-12-25 09:25:27 +02:00
}
2018-12-20 18:59:38 +02:00
bool VisibilityManager : : intersects ( const WindowInfoWrap & winfo )
2016-12-25 09:25:27 +02:00
{
2017-03-23 22:06:59 -05:00
return ( ! winfo . isMinimized ( )
2019-01-19 18:55:19 +02:00
& & wm - > isOnCurrentDesktop ( winfo . wid ( ) )
& & wm - > isOnCurrentActivity ( winfo . wid ( ) )
2018-12-06 16:17:35 +02:00
& & winfo . geometry ( ) . intersects ( m_viewGeometry )
2017-03-23 22:06:59 -05:00
& & ! winfo . isShaded ( ) ) ;
2016-12-25 09:25:27 +02:00
}
2018-12-20 18:59:38 +02:00
void VisibilityManager : : saveConfig ( )
2016-12-25 09:25:27 +02:00
{
2018-12-20 18:59:38 +02:00
if ( ! m_latteView - > containment ( ) )
2016-12-30 02:17:38 -05:00
return ;
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
auto config = m_latteView - > containment ( ) - > config ( ) ;
2017-04-02 00:23:47 -05:00
2018-03-28 20:39:52 +03:00
config . writeEntry ( " enableKWinEdges " , enableKWinEdgesFromUser ) ;
2018-12-20 18:59:38 +02:00
config . writeEntry ( " timerShow " , m_timerShow . interval ( ) ) ;
config . writeEntry ( " timerHide " , m_timerHide . interval ( ) ) ;
2017-03-12 12:05:02 -05:00
config . writeEntry ( " raiseOnDesktopChange " , raiseOnDesktopChange ) ;
config . writeEntry ( " raiseOnActivityChange " , raiseOnActivityChange ) ;
2018-03-28 20:39:52 +03:00
2018-12-20 18:59:38 +02:00
m_latteView - > containment ( ) - > configNeedsSaving ( ) ;
2016-12-25 09:25:27 +02:00
}
2018-12-20 18:59:38 +02:00
void VisibilityManager : : restoreConfig ( )
2016-12-25 09:25:27 +02:00
{
2018-12-20 18:59:38 +02:00
if ( ! m_latteView | | ! m_latteView - > containment ( ) ) {
2016-12-30 02:24:04 -05:00
return ;
2018-12-20 18:59:38 +02:00
}
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
auto config = m_latteView - > containment ( ) - > config ( ) ;
m_timerShow . setInterval ( config . readEntry ( " timerShow " , 0 ) ) ;
m_timerHide . setInterval ( config . readEntry ( " timerHide " , 700 ) ) ;
emit timerShowChanged ( ) ;
emit timerHideChanged ( ) ;
2017-02-11 00:55:22 -05:00
2018-03-28 20:39:52 +03:00
enableKWinEdgesFromUser = config . readEntry ( " enableKWinEdges " , true ) ;
2018-12-20 18:59:38 +02:00
emit enableKWinEdgesChanged ( ) ;
2018-03-28 20:39:52 +03:00
2017-03-25 16:17:41 -05:00
setRaiseOnDesktop ( config . readEntry ( " raiseOnDesktopChange " , false ) ) ;
setRaiseOnActivity ( config . readEntry ( " raiseOnActivityChange " , false ) ) ;
2018-12-20 18:59:38 +02:00
auto storedMode = static_cast < Types : : Visibility > ( m_latteView - > containment ( ) - > config ( ) . readEntry ( " visibility " , static_cast < int > ( Types : : DodgeActive ) ) ) ;
2017-04-02 00:23:47 -05:00
2018-12-20 18:59:38 +02:00
if ( storedMode = = Types : : AlwaysVisible ) {
qDebug ( ) < < " Loading visibility mode: Always Visible , on startup... " ;
2018-12-07 18:55:35 +02:00
setMode ( Types : : AlwaysVisible ) ;
2017-02-12 03:01:12 -05:00
} else {
2018-12-20 18:59:38 +02:00
connect ( & m_timerStartUp , & QTimer : : timeout , this , [ & ] ( ) {
auto fMode = static_cast < Types : : Visibility > ( m_latteView - > containment ( ) - > config ( ) . readEntry ( " visibility " , static_cast < int > ( Types : : DodgeActive ) ) ) ;
qDebug ( ) < < " Loading visibility mode: " < < fMode < < " on startup... " ;
setMode ( fMode ) ;
2017-02-11 00:55:22 -05:00
} ) ;
2018-12-20 18:59:38 +02:00
connect ( m_latteView - > containment ( ) , & Plasma : : Containment : : userConfiguringChanged
2017-06-04 02:43:52 +03:00
, this , [ & ] ( bool configuring ) {
2018-12-20 18:59:38 +02:00
if ( configuring & & m_timerStartUp . isActive ( ) )
m_timerStartUp . start ( 100 ) ;
2017-04-02 04:24:49 -05:00
} ) ;
2018-12-20 18:59:38 +02:00
m_timerStartUp . start ( ) ;
2017-02-11 00:55:22 -05:00
}
2017-03-12 04:01:27 -05:00
2018-12-20 18:59:38 +02:00
connect ( m_latteView - > containment ( ) , & Plasma : : Containment : : userConfiguringChanged
2017-03-12 15:14:30 -05:00
, this , [ & ] ( bool configuring ) {
2018-12-20 18:59:38 +02:00
if ( ! configuring ) {
2017-03-12 13:30:54 -05:00
saveConfig ( ) ;
2018-12-20 18:59:38 +02:00
}
2017-03-12 04:01:27 -05:00
} ) ;
2016-12-25 09:25:27 +02:00
}
2018-12-20 18:59:38 +02:00
bool VisibilityManager : : containsMouse ( ) const
2016-12-25 09:25:27 +02:00
{
2018-12-20 18:59:38 +02:00
return m_containsMouse ;
}
void VisibilityManager : : setContainsMouse ( bool contains )
{
if ( m_containsMouse = = contains ) {
2018-11-13 19:06:33 +02:00
return ;
}
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
m_containsMouse = contains ;
emit containsMouseChanged ( ) ;
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
if ( contains & & m_mode ! = Types : : AlwaysVisible ) {
2018-12-06 16:17:35 +02:00
raiseView ( true ) ;
2018-11-13 19:06:33 +02:00
}
}
2017-01-16 14:07:49 -05:00
2018-12-20 18:59:38 +02:00
void VisibilityManager : : viewEventManager ( QEvent * ev )
2018-11-13 19:06:33 +02:00
{
switch ( ev - > type ( ) ) {
case QEvent : : Enter :
setContainsMouse ( true ) ;
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 :
2018-11-13 19:06:33 +02:00
setContainsMouse ( false ) ;
2017-01-05 17:48:27 +02:00
updateHiddenState ( ) ;
2018-11-13 19:06:33 +02:00
2017-01-05 17:48:27 +02:00
break ;
2017-01-16 14:07:49 -05:00
2017-01-05 17:48:27 +02:00
case QEvent : : DragEnter :
dragEnter = true ;
2017-03-12 15:14:30 -05:00
2018-12-20 18:59:38 +02:00
if ( m_isHidden )
emit mustBeShown ( ) ;
2017-03-12 13:09:38 -05:00
2017-01-05 17:48:27 +02:00
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 :
2018-12-20 18:59:38 +02:00
wm - > setViewExtraFlags ( * m_latteView ) ;
2017-01-03 12:36:40 -05:00
break ;
2017-06-08 17:10:49 -05:00
default :
break ;
2016-12-25 09:25:27 +02:00
}
}
2017-12-24 20:54:45 +02:00
2018-03-28 20:39:52 +03:00
//! KWin Edges Support functions
2018-12-20 18:59:38 +02:00
bool VisibilityManager : : enableKWinEdges ( ) const
{
return enableKWinEdgesFromUser ;
}
void VisibilityManager : : setEnableKWinEdges ( bool enable )
2018-03-28 20:39:52 +03:00
{
if ( enableKWinEdgesFromUser = = enable ) {
return ;
}
enableKWinEdgesFromUser = enable ;
2018-12-20 18:59:38 +02:00
emit enableKWinEdgesChanged ( ) ;
2018-03-28 20:39:52 +03:00
updateKWinEdgesSupport ( ) ;
}
2018-12-20 18:59:38 +02:00
void VisibilityManager : : updateKWinEdgesSupport ( )
2018-03-28 20:39:52 +03:00
{
2018-12-20 18:59:38 +02:00
if ( m_mode = = Types : : AutoHide
| | m_mode = = Types : : DodgeActive
| | m_mode = = Types : : DodgeAllWindows
| | m_mode = = Types : : DodgeMaximized ) {
2018-03-28 20:39:52 +03:00
if ( enableKWinEdgesFromUser ) {
createEdgeGhostWindow ( ) ;
} else if ( ! enableKWinEdgesFromUser ) {
deleteEdgeGhostWindow ( ) ;
}
2018-12-20 18:59:38 +02:00
} else if ( m_mode = = Types : : AlwaysVisible
| | m_mode = = Types : : WindowsGoBelow ) {
2018-03-28 20:39:52 +03:00
deleteEdgeGhostWindow ( ) ;
}
}
2018-12-20 18:59:38 +02:00
void VisibilityManager : : createEdgeGhostWindow ( )
2018-03-28 20:39:52 +03:00
{
if ( ! edgeGhostWindow ) {
2018-12-09 00:29:35 +02:00
edgeGhostWindow = new ScreenEdgeGhostWindow ( m_latteView ) ;
2018-03-28 20:39:52 +03:00
2018-12-06 16:09:42 +02:00
wm - > setViewExtraFlags ( * edgeGhostWindow ) ;
2018-03-28 20:39:52 +03:00
2018-12-09 00:29:35 +02:00
connect ( edgeGhostWindow , & ScreenEdgeGhostWindow : : containsMouseChanged , this , [ = ] ( bool contains ) {
2018-11-13 19:06:33 +02:00
if ( contains ) {
2019-02-24 19:09:48 +02:00
raiseView ( true ) ;
} else {
m_timerShow . stop ( ) ;
updateGhostWindowState ( ) ;
2018-11-13 19:06:33 +02:00
}
2018-03-28 20:39:52 +03:00
} ) ;
connectionsKWinEdges [ 0 ] = connect ( wm , & WindowSystem : : currentActivityChanged ,
this , [ & ] ( ) {
2018-12-07 18:55:35 +02:00
bool inCurrentLayout = ( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Types : : SingleLayout | |
( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Types : : MultipleLayouts
2018-12-06 12:51:15 +02:00
& & m_latteView - > managedLayout ( ) & & ! m_latteView - > positioner ( ) - > inLocationChangeAnimation ( )
2018-12-06 14:35:34 +02:00
& & m_latteView - > managedLayout ( ) - > name ( ) = = m_corona - > layoutManager ( ) - > currentLayoutName ( ) ) ) ;
2018-03-28 20:39:52 +03:00
if ( edgeGhostWindow ) {
if ( inCurrentLayout ) {
2018-12-20 18:59:38 +02:00
wm - > setEdgeStateFor ( edgeGhostWindow , m_isHidden ) ;
2018-03-28 20:39:52 +03:00
} else {
wm - > setEdgeStateFor ( edgeGhostWindow , false ) ;
}
}
} ) ;
2018-12-20 18:59:38 +02:00
emit supportsKWinEdgesChanged ( ) ;
2018-03-28 20:39:52 +03:00
}
}
2018-12-20 18:59:38 +02:00
void VisibilityManager : : deleteEdgeGhostWindow ( )
2018-03-28 20:39:52 +03:00
{
if ( edgeGhostWindow ) {
edgeGhostWindow - > deleteLater ( ) ;
edgeGhostWindow = nullptr ;
for ( auto & c : connectionsKWinEdges ) {
disconnect ( c ) ;
}
2018-12-20 18:59:38 +02:00
emit supportsKWinEdgesChanged ( ) ;
2018-03-28 20:39:52 +03:00
}
}
2018-10-28 10:03:22 +02:00
2016-12-29 00:40:35 -05:00
//! END: VisibilityManager implementation
2018-10-28 10:03:22 +02:00
2016-12-25 09:25:27 +02:00
}
2018-12-09 00:29:35 +02:00
}