2017-02-24 20:58:21 +02:00
/*
* Copyright 2016 Marco Martin < mart @ kde . org >
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation ; either version 2 , or
* ( at your option ) any later version .
*
* This program 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 Library General Public
* License along with this program ; if not , write to the
* Free Software Foundation , Inc . ,
* 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*/
# ifndef SCREENPOOL_H
# define SCREENPOOL_H
2021-02-17 12:02:52 +02:00
// local
# include "data/screendata.h"
2018-12-02 02:05:52 +02:00
// Qt
2017-02-24 20:58:21 +02:00
# include <QObject>
# include <QHash>
2017-06-11 23:55:34 +03:00
# include <QScreen>
2017-02-24 20:58:21 +02:00
# include <QString>
# include <QTimer>
2017-02-26 02:43:41 +02:00
# include <QAbstractNativeEventFilter>
2017-02-24 20:58:21 +02:00
2018-12-02 02:05:52 +02:00
// KDE
2017-02-24 20:58:21 +02:00
# include <KConfigGroup>
# include <KSharedConfig>
2018-02-03 11:34:13 +02:00
namespace Latte {
2018-07-03 22:15:45 +03:00
class ScreenPool : public QObject , public QAbstractNativeEventFilter
{
2017-02-24 20:58:21 +02:00
Q_OBJECT
public :
2021-03-20 18:57:28 +02:00
static const int FIRSTSCREENID = 10 ;
2017-02-24 20:58:21 +02:00
ScreenPool ( KSharedConfig : : Ptr config , QObject * parent = nullptr ) ;
void load ( ) ;
~ ScreenPool ( ) override ;
2021-02-17 12:24:36 +02:00
bool hasScreenId ( int screenId ) const ;
bool isScreenActive ( int screenId ) const ;
2018-01-08 19:21:34 +02:00
int primaryScreenId ( ) const ;
2021-02-17 14:20:44 +02:00
void insertScreenMapping ( const QString & connector ) ;
2017-06-26 23:24:27 +03:00
void reload ( QString path ) ;
2017-02-24 20:58:21 +02:00
int id ( const QString & connector ) const ;
QString connector ( int id ) const ;
2019-07-14 13:59:02 +03:00
QString reportHtml ( const QList < int > & assignedScreens ) const ;
2019-07-13 17:00:02 +03:00
2017-06-11 23:55:34 +03:00
QScreen * screenForId ( int id ) ;
2021-04-04 12:25:20 +03:00
Latte : : Data : : ScreensTable screensTable ( ) ;
2017-02-26 02:43:41 +02:00
signals :
void primaryPoolChanged ( ) ;
protected :
2017-03-12 15:14:30 -05:00
bool nativeEventFilter ( const QByteArray & eventType , void * message , long * result ) Q_DECL_OVERRIDE ;
2017-02-26 02:43:41 +02:00
2021-02-17 14:20:44 +02:00
int firstAvailableId ( ) const ;
private slots :
2021-02-17 15:12:27 +02:00
void updateScreenGeometry ( const QScreen * screen ) ;
void onScreenAdded ( const QScreen * screen ) ;
void onScreenRemoved ( const QScreen * screen ) ;
2021-02-17 14:20:44 +02:00
2017-02-24 20:58:21 +02:00
private :
void save ( ) ;
2021-02-17 15:12:27 +02:00
void updateScreenGeometry ( const int & screenId , const QRect & screenGeometry ) ;
private :
2021-02-17 12:02:52 +02:00
Latte : : Data : : ScreensTable m_screensTable ;
2017-02-24 20:58:21 +02:00
KConfigGroup m_configGroup ;
2021-02-17 12:14:46 +02:00
//! used to workaround a bug under X11 when primary screen changes and no screenChanged signal is emitted
QString m_lastPrimaryConnector ;
2021-02-17 12:24:36 +02:00
2017-02-24 20:58:21 +02:00
QTimer m_configSaveTimer ;
} ;
2018-02-03 11:34:13 +02:00
}
2017-02-24 20:58:21 +02:00
# endif // SCREENPOOL_H