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-28 10:45:21 +03:00
# include "abstractwindowinterface.h"
2018-12-02 03:05:52 +03:00
2019-05-11 21:10:02 +03:00
// local
2019-05-31 14:52:16 +03:00
# include "tracker/schemes.h"
2019-06-04 20:08:30 +03:00
# include "tracker/trackerwindows.h"
2019-05-11 21:10:02 +03:00
# include "../lattecorona.h"
2019-06-10 17:30:25 +03:00
// KDE
# include <KActivities/Controller>
2016-12-30 10:13:33 +03:00
2016-12-28 10:45:21 +03:00
namespace Latte {
2019-05-11 15:43:10 +03:00
namespace WindowSystem {
2016-12-28 10:45:21 +03:00
2017-02-25 05:40:47 +03:00
AbstractWindowInterface : : AbstractWindowInterface ( QObject * parent )
: QObject ( parent )
2016-12-28 10:45:21 +03:00
{
2019-06-08 00:31:30 +03:00
m_activities = new KActivities : : Consumer ( this ) ;
m_currentActivity = m_activities - > currentActivity ( ) ;
2019-05-11 21:10:02 +03:00
m_corona = qobject_cast < Latte : : Corona * > ( parent ) ;
2019-05-31 14:52:16 +03:00
m_windowsTracker = new Tracker : : Windows ( this ) ;
m_schemesTracker = new Tracker : : Schemes ( this ) ;
2019-05-27 20:09:48 +03:00
2019-06-01 01:20:54 +03:00
rulesConfig = KSharedConfig : : openConfig ( QStringLiteral ( " taskmanagerrulesrc " ) ) ;
2019-05-27 20:09:48 +03:00
m_windowWaitingTimer . setInterval ( 150 ) ;
m_windowWaitingTimer . setSingleShot ( true ) ;
connect ( & m_windowWaitingTimer , & QTimer : : timeout , this , [ & ] ( ) {
WindowId wid = m_windowChangedWaiting ;
m_windowChangedWaiting = QVariant ( ) ;
emit windowChanged ( wid ) ;
} ) ;
2019-07-11 12:51:39 +03:00
// connect(this, &AbstractWindowInterface::windowChanged, this, [&](WindowId wid) {
// qDebug() << "WINDOW CHANGED ::: " << wid;
// });
2019-06-08 00:31:30 +03:00
connect ( m_activities . data ( ) , & KActivities : : Consumer : : currentActivityChanged , this , [ & ] ( const QString & id ) {
m_currentActivity = id ;
emit currentActivityChanged ( ) ;
} ) ;
2016-12-28 10:45:21 +03:00
}
AbstractWindowInterface : : ~ AbstractWindowInterface ( )
{
2019-05-27 20:09:48 +03:00
m_windowWaitingTimer . stop ( ) ;
2019-05-12 02:17:22 +03:00
m_schemesTracker - > deleteLater ( ) ;
2019-05-11 21:10:02 +03:00
m_windowsTracker - > deleteLater ( ) ;
2016-12-28 10:45:21 +03:00
}
2019-06-08 00:31:30 +03:00
QString AbstractWindowInterface : : currentDesktop ( ) const
{
return m_currentDesktop ;
}
QString AbstractWindowInterface : : currentActivity ( ) const
{
return m_currentActivity ;
}
2019-05-11 21:10:02 +03:00
Latte : : Corona * AbstractWindowInterface : : corona ( )
{
return m_corona ;
}
2019-05-31 14:52:16 +03:00
Tracker : : Schemes * AbstractWindowInterface : : schemesTracker ( )
2018-10-14 13:54:09 +03:00
{
2019-05-12 02:17:22 +03:00
return m_schemesTracker ;
2018-10-14 13:54:09 +03:00
}
2019-06-01 02:43:30 +03:00
Tracker : : Windows * AbstractWindowInterface : : windowsTracker ( ) const
2019-05-11 21:10:02 +03:00
{
return m_windowsTracker ;
}
2019-06-10 17:30:25 +03:00
//! Activities switching
void AbstractWindowInterface : : switchToNextActivity ( )
{
QStringList runningActivities = m_activities - > activities ( KActivities : : Info : : State : : Running ) ;
if ( runningActivities . count ( ) < = 1 ) {
return ;
}
int curPos = runningActivities . indexOf ( m_currentActivity ) ;
int nextPos = curPos + 1 ;
if ( curPos = = runningActivities . count ( ) - 1 ) {
nextPos = 0 ;
}
KActivities : : Controller activitiesController ;
activitiesController . setCurrentActivity ( runningActivities . at ( nextPos ) ) ;
}
void AbstractWindowInterface : : switchToPreviousActivity ( )
{
QStringList runningActivities = m_activities - > activities ( KActivities : : Info : : State : : Running ) ;
if ( runningActivities . count ( ) < = 1 ) {
return ;
}
int curPos = runningActivities . indexOf ( m_currentActivity ) ;
int nextPos = curPos - 1 ;
if ( curPos = = 0 ) {
nextPos = runningActivities . count ( ) - 1 ;
}
KActivities : : Controller activitiesController ;
activitiesController . setCurrentActivity ( runningActivities . at ( nextPos ) ) ;
}
//! Delay window changed trigerring
2019-05-27 20:09:48 +03:00
void AbstractWindowInterface : : considerWindowChanged ( WindowId wid )
{
//! Consider if the windowChanged signal should be sent DIRECTLY or WAIT
if ( m_windowChangedWaiting = = wid & & m_windowWaitingTimer . isActive ( ) ) {
//! window should be sent later
m_windowWaitingTimer . start ( ) ;
return ;
}
if ( m_windowChangedWaiting ! = wid & & ! m_windowWaitingTimer . isActive ( ) ) {
//! window should be sent later
m_windowChangedWaiting = wid ;
m_windowWaitingTimer . start ( ) ;
}
if ( m_windowChangedWaiting ! = wid & & m_windowWaitingTimer . isActive ( ) ) {
m_windowWaitingTimer . stop ( ) ;
//! sent previous waiting window
2019-06-10 17:30:25 +03:00
emit windowChanged ( m_windowChangedWaiting ) ;
2019-05-27 20:09:48 +03:00
//! retrigger waiting for the upcoming window
m_windowChangedWaiting = wid ;
m_windowWaitingTimer . start ( ) ;
}
}
2016-12-28 10:45:21 +03:00
}
2019-05-11 15:43:10 +03:00
}
2017-02-25 05:40:47 +03:00