[wayland] Add a base implementation for Screens in a basic setup

X11, Wayland, virtual, Framebuffer and hwcomposer have extremely
similar screens implementations. Let's add a base implementation
for them as a BasicScreens.
This commit is contained in:
Martin Gräßlin 2015-11-17 10:32:06 +01:00
parent cab25fc13f
commit fb4d59abb7
4 changed files with 84 additions and 0 deletions

View file

@ -330,4 +330,9 @@ EGLContext AbstractBackend::sceneEglContext() const
return EGL_NO_CONTEXT;
}
QSize AbstractBackend::screenSize() const
{
return QSize();
}
}

View file

@ -60,6 +60,14 @@ public:
**/
virtual EGLContext sceneEglContext() const;
/**
* Implementing subclasses should provide a size in case the backend represents
* a basic screen and uses the BasicScreens.
*
* Base implementation returns an invalid size.
**/
virtual QSize screenSize() const;
bool usesSoftwareCursor() const {
return m_softWareCursor;
}
@ -114,6 +122,10 @@ Q_SIGNALS:
void initFailed();
void cursorChanged();
void readyChanged(bool);
/**
* Emitted by backends using a one screen (nested window) approach and when the size of that changes.
**/
void screenSizeChanged();
protected:
explicit AbstractBackend(QObject *parent = nullptr);

View file

@ -184,4 +184,50 @@ int Screens::intersecting(const QRect &r) const
return cnt;
}
BasicScreens::BasicScreens(AbstractBackend *backend, QObject *parent)
: Screens(parent)
, m_backend(backend)
{
}
BasicScreens::~BasicScreens() = default;
void BasicScreens::init()
{
KWin::Screens::init();
#ifndef KWIN_UNIT_TEST
connect(m_backend, &AbstractBackend::screenSizeChanged,
this, &BasicScreens::startChangedTimer);
#endif
updateCount();
emit changed();
}
QRect BasicScreens::geometry(int screen) const
{
if (screen == 0) {
return QRect(QPoint(0, 0), size(screen));
}
return QRect();
}
QSize BasicScreens::size(int screen) const
{
if (screen == 0) {
return m_backend->screenSize();
}
return QSize();
}
void BasicScreens::updateCount()
{
setCount(1);
}
int BasicScreens::number(const QPoint &pos) const
{
Q_UNUSED(pos)
return 0;
}
} // namespace

View file

@ -33,6 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
class AbstractClient;
class AbstractBackend;
class KWIN_EXPORT Screens : public QObject
{
@ -148,6 +149,26 @@ private:
KWIN_SINGLETON(Screens)
};
/**
* @brief A base implementation for backends with just a (nested) window
**/
class KWIN_EXPORT BasicScreens : public Screens
{
Q_OBJECT
public:
BasicScreens(AbstractBackend *backend, QObject *parent = nullptr);
virtual ~BasicScreens();
void init() override;
QRect geometry(int screen) const override;
int number(const QPoint &pos) const override;
QSize size(int screen) const override;
void updateCount() override;
private:
AbstractBackend *m_backend;
};
inline
void Screens::setConfig(KSharedConfig::Ptr config)
{