Commit 43b78e40 authored by Xaver Hugl's avatar Xaver Hugl
Browse files

screens: move singleton to Workspace

parent 9439e771
......@@ -195,7 +195,7 @@ void PlasmaSurfaceTest::testOSDPlacement()
QCOMPARE(window->frameGeometry(), QRect(1280 / 2 - 100 / 2, 2 * 1024 / 3 - 50 / 2, 100, 50));
// change the screen size
QSignalSpy screensChangedSpy(screens(), &Screens::changed);
QSignalSpy screensChangedSpy(workspace()->screens(), &Screens::changed);
QVERIFY(screensChangedSpy.isValid());
const QVector<QRect> geometries{QRect(0, 0, 1280, 1024), QRect(1280, 0, 1280, 1024)};
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs",
......
......@@ -56,7 +56,7 @@ static PlatformCursorImage loadReferenceThemeCursor(const QByteArray &name)
{
const Cursor *pointerCursor = Cursors::self()->mouse();
const KXcursorTheme theme(pointerCursor->themeName(), pointerCursor->themeSize(), screens()->maxScale());
const KXcursorTheme theme(pointerCursor->themeName(), pointerCursor->themeSize(), workspace()->screens()->maxScale());
if (theme.isEmpty()) {
return PlatformCursorImage();
}
......@@ -390,7 +390,7 @@ void PointerInputTest::testUpdateFocusAfterScreenChange()
QVERIFY(!window->frameGeometry().contains(Cursors::self()->mouse()->pos()));
QVERIFY(leftSpy.wait());
QSignalSpy screensChangedSpy(screens(), &Screens::changed);
QSignalSpy screensChangedSpy(workspace()->screens(), &Screens::changed);
QVERIFY(screensChangedSpy.isValid());
// now let's remove the screen containing the cursor
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs",
......
......@@ -88,7 +88,7 @@ void ScreenChangesTest::testScreenAddRemove()
outputAnnouncedSpy.clear();
// let's announce a new output
QSignalSpy screensChangedSpy(screens(), &Screens::changed);
QSignalSpy screensChangedSpy(workspace()->screens(), &Screens::changed);
QVERIFY(screensChangedSpy.isValid());
const QVector<QRect> geometries{QRect(0, 0, 1280, 1024), QRect(1280, 0, 1280, 1024)};
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs",
......
......@@ -108,7 +108,7 @@ void ScreensTest::testSize_data()
void ScreensTest::testSize()
{
QSignalSpy sizeChangedSpy(screens(), &Screens::sizeChanged);
QSignalSpy sizeChangedSpy(workspace()->screens(), &Screens::sizeChanged);
QVERIFY(sizeChangedSpy.isValid());
QFETCH(QVector<QRect>, geometries);
......@@ -116,25 +116,25 @@ void ScreensTest::testSize()
Q_ARG(int, geometries.count()), Q_ARG(QVector<QRect>, geometries));
QVERIFY(sizeChangedSpy.wait());
QTEST(screens()->size(), "expectedSize");
QTEST(workspace()->screens()->size(), "expectedSize");
}
void ScreensTest::testCount()
{
QSignalSpy countChangedSpy(screens(), &Screens::countChanged);
QSignalSpy countChangedSpy(workspace()->screens(), &Screens::countChanged);
QVERIFY(countChangedSpy.isValid());
// the test environments has two outputs
QCOMPARE(screens()->count(), 2);
QCOMPARE(workspace()->screens()->count(), 2);
// change to one screen
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::QueuedConnection, Q_ARG(int, 1));
QVERIFY(countChangedSpy.wait());
QCOMPARE(countChangedSpy.count(), 1);
QCOMPARE(screens()->count(), 1);
QCOMPARE(workspace()->screens()->count(), 1);
// setting the same geometries shouldn't emit the signal, but we should get a changed signal
QSignalSpy changedSpy(screens(), &Screens::changed);
QSignalSpy changedSpy(workspace()->screens(), &Screens::changed);
QVERIFY(changedSpy.isValid());
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::QueuedConnection, Q_ARG(int, 1));
QVERIFY(changedSpy.wait());
......@@ -179,7 +179,7 @@ void ScreensTest::testCurrentWithFollowsMouse_data()
void ScreensTest::testCurrentWithFollowsMouse()
{
QSignalSpy changedSpy(screens(), &Screens::changed);
QSignalSpy changedSpy(workspace()->screens(), &Screens::changed);
QVERIFY(changedSpy.isValid());
// Enable "active screen follows mouse"
......@@ -216,7 +216,7 @@ void ScreensTest::testCurrentPoint_data()
void ScreensTest::testCurrentPoint()
{
QSignalSpy changedSpy(screens(), &KWin::Screens::changed);
QSignalSpy changedSpy(workspace()->screens(), &KWin::Screens::changed);
QVERIFY(changedSpy.isValid());
QFETCH(QVector<QRect>, geometries);
......
......@@ -66,7 +66,7 @@ void EffectsHandlerImplX11::doStartMouseInterception(Qt::CursorShape shape)
// NOTE: it is intended to not perform an XPointerGrab on X11. See documentation in kwineffects.h
// The mouse grab is implemented by using a full screen input only window
if (!m_mouseInterceptionWindow.isValid()) {
const QSize &s = Screens::self()->size();
const QSize &s = workspace()->screens()->size();
const QRect geo(0, 0, s.width(), s.height());
const uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
const uint32_t values[] = {
......
......@@ -15,6 +15,7 @@
#include "screens.h"
#include "softwarevsyncmonitor.h"
#include "surfaceitem_x11.h"
#include "workspace.h"
#include "x11_standalone_logging.h"
#include "x11_standalone_platform.h"
......@@ -57,7 +58,7 @@ EglBackend::EglBackend(Display *display, X11StandalonePlatform *backend)
m_vsyncMonitor->setRefreshRate(backend->renderLoop()->refreshRate());
connect(m_vsyncMonitor.get(), &VsyncMonitor::vblankOccurred, this, &EglBackend::vblank);
connect(screens(), &Screens::sizeChanged, this, &EglBackend::screenGeometryChanged);
connect(workspace()->screens(), &Screens::sizeChanged, this, &EglBackend::screenGeometryChanged);
}
EglBackend::~EglBackend()
......@@ -106,7 +107,7 @@ void EglBackend::init()
return;
}
m_fbo = std::make_unique<GLFramebuffer>(0, screens()->size());
m_fbo = std::make_unique<GLFramebuffer>(0, workspace()->screens()->size());
kwinApp()->platform()->setSceneEglDisplay(shareDisplay);
kwinApp()->platform()->setSceneEglGlobalShareContext(shareContext);
......@@ -115,11 +116,11 @@ void EglBackend::init()
void EglBackend::screenGeometryChanged()
{
overlayWindow()->resize(screens()->size());
overlayWindow()->resize(workspace()->screens()->size());
// The back buffer contents are now undefined
m_bufferAge = 0;
m_fbo = std::make_unique<GLFramebuffer>(0, screens()->size());
m_fbo = std::make_unique<GLFramebuffer>(0, workspace()->screens()->size());
}
OutputLayerBeginFrameInfo EglBackend::beginFrame()
......@@ -159,7 +160,7 @@ void EglBackend::present(Output *output)
QRegion effectiveRenderedRegion = m_lastRenderedRegion;
if (!GLPlatform::instance()->isGLES()) {
const QRegion displayRegion(screens()->geometry());
const QRegion displayRegion(workspace()->screens()->geometry());
if (!supportsBufferAge() && options->glPreferBufferSwap() == Options::CopyFrontBuffer && m_lastRenderedRegion != displayRegion) {
glReadBuffer(GL_FRONT);
copyPixels(displayRegion - m_lastRenderedRegion);
......@@ -171,7 +172,7 @@ void EglBackend::present(Output *output)
// Pop the default render target from the render target stack.
GLFramebuffer::popFramebuffer();
presentSurface(surface(), effectiveRenderedRegion, screens()->geometry());
presentSurface(surface(), effectiveRenderedRegion, workspace()->screens()->geometry());
if (overlayWindow() && overlayWindow()->window()) { // show the window only after the first pass,
overlayWindow()->show(); // since that pass may take long
......
......@@ -31,6 +31,7 @@
#include "screens.h"
#include "surfaceitem_x11.h"
#include "utils/xcbutils.h"
#include "workspace.h"
// kwin libs
#include <kwinglplatform.h>
#include <kwinglutils.h>
......@@ -136,7 +137,7 @@ GlxBackend::GlxBackend(Display *display, X11StandalonePlatform *backend)
// by Mesa when using DRI2.
QOpenGLContext::supportsThreadedOpenGL();
connect(screens(), &Screens::sizeChanged, this, &GlxBackend::screenGeometryChanged);
connect(workspace()->screens(), &Screens::sizeChanged, this, &GlxBackend::screenGeometryChanged);
}
GlxBackend::~GlxBackend()
......@@ -226,7 +227,7 @@ void GlxBackend::init()
glPlatform->printResults();
initGL(&getProcAddress);
m_fbo = std::make_unique<GLFramebuffer>(0, screens()->size());
m_fbo = std::make_unique<GLFramebuffer>(0, workspace()->screens()->size());
bool supportsSwapEvent = false;
......@@ -455,7 +456,7 @@ bool GlxBackend::initBuffer()
xcb_colormap_t colormap = xcb_generate_id(c);
xcb_create_colormap(c, false, colormap, rootWindow(), visual);
const QSize size = screens()->size();
const QSize size = workspace()->screens()->size();
window = xcb_generate_id(c);
xcb_create_window(c, visualDepth(visual), window, overlayWindow()->window(),
......@@ -731,7 +732,7 @@ void GlxBackend::setSwapInterval(int interval)
void GlxBackend::present(const QRegion &damage)
{
const QSize &screenSize = screens()->size();
const QSize &screenSize = workspace()->screens()->size();
const QRegion displayRegion(0, 0, screenSize.width(), screenSize.height());
const bool fullRepaint = supportsBufferAge() || (damage == displayRegion);
......@@ -760,7 +761,7 @@ void GlxBackend::present(const QRegion &damage)
void GlxBackend::screenGeometryChanged()
{
const QSize size = screens()->size();
const QSize size = workspace()->screens()->size();
doneCurrent();
XMoveResizeWindow(display(), window, 0, 0, size.width(), size.height());
......@@ -814,7 +815,7 @@ void GlxBackend::present(Output *output)
m_vsyncMonitor->arm();
}
const QRegion displayRegion(screens()->geometry());
const QRegion displayRegion(workspace()->screens()->geometry());
QRegion effectiveRenderedRegion = m_lastRenderedRegion;
if (!supportsBufferAge() && options->glPreferBufferSwap() == Options::CopyFrontBuffer && m_lastRenderedRegion != displayRegion) {
......
......@@ -15,6 +15,7 @@
#include "screens.h"
#include "utils/common.h"
#include "utils/xcbutils.h"
#include "workspace.h"
#include <QVector>
......@@ -57,7 +58,7 @@ bool OverlayWindowX11::create()
if (m_window == XCB_WINDOW_NONE) {
return false;
}
resize(screens()->size());
resize(workspace()->screens()->size());
return true;
#else
return false;
......@@ -70,7 +71,7 @@ void OverlayWindowX11::setup(xcb_window_t window)
Q_ASSERT(Xcb::Extensions::self()->isShapeInputAvailable());
setNoneBackgroundPixmap(m_window);
m_shape = QRegion();
const QSize &s = screens()->size();
const QSize &s = workspace()->screens()->size();
setShape(QRect(0, 0, s.width(), s.height()));
if (window != XCB_WINDOW_NONE) {
setNoneBackgroundPixmap(window);
......@@ -107,7 +108,7 @@ void OverlayWindowX11::hide()
Q_ASSERT(m_window != XCB_WINDOW_NONE);
xcb_unmap_window(connection(), m_window);
m_shown = false;
const QSize &s = screens()->size();
const QSize &s = workspace()->screens()->size();
setShape(QRect(0, 0, s.width(), s.height()));
}
......@@ -151,7 +152,7 @@ void OverlayWindowX11::destroy()
return;
}
// reset the overlay shape
const QSize &s = screens()->size();
const QSize &s = workspace()->screens()->size();
xcb_rectangle_t rec = {0, 0, static_cast<uint16_t>(s.width()), static_cast<uint16_t>(s.height())};
xcb_shape_rectangles(connection(), XCB_SHAPE_SO_SET, XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED, m_window, 0, 0, 1, &rec);
xcb_shape_rectangles(connection(), XCB_SHAPE_SO_SET, XCB_SHAPE_SK_INPUT, XCB_CLIP_ORDERING_UNSORTED, m_window, 0, 0, 1, &rec);
......
......@@ -29,6 +29,7 @@
#include "wayland/outputchangeset_v2.h"
#include "wayland/outputconfiguration_v2_interface.h"
#include "wayland_server.h"
#include "workspace.h"
#include <KCoreAddons>
......@@ -190,7 +191,7 @@ void Platform::requestOutputsChange(KWaylandServer::OutputConfigurationV2Interfa
setPrimaryOutput(defaultPrimaryOutput);
}
}
Q_EMIT screens()->changed();
Q_EMIT workspace()->screens()->changed();
config->setApplied();
} else {
qCDebug(KWIN_CORE) << "Applying config failed";
......
......@@ -14,6 +14,7 @@
#include "screens.h"
#include "surfaceitem.h"
#include "utils/common.h"
#include "workspace.h"
#include <QElapsedTimer>
......@@ -46,7 +47,7 @@ void OpenGLBackend::setFailed(const QString &reason)
void OpenGLBackend::copyPixels(const QRegion &region)
{
const int height = screens()->size().height();
const int height = workspace()->screens()->size().height();
for (const QRect &r : region) {
const int x0 = r.x();
const int y0 = height - r.y() - r.height();
......
......@@ -142,7 +142,7 @@ void PointerInputRedirection::init()
});
Q_EMIT m_cursor->changed();
connect(screens(), &Screens::changed, this, &PointerInputRedirection::updateAfterScreenChange);
connect(workspace()->screens(), &Screens::changed, this, &PointerInputRedirection::updateAfterScreenChange);
#if KWIN_BUILD_SCREENLOCKER
if (waylandServer()->hasScreenLockerIntegration()) {
connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged, this, [this]() {
......@@ -1248,7 +1248,7 @@ WaylandCursorImage::WaylandCursorImage(QObject *parent)
Cursor *pointerCursor = Cursors::self()->mouse();
connect(pointerCursor, &Cursor::themeChanged, this, &WaylandCursorImage::invalidateCursorTheme);
connect(screens(), &Screens::maxScaleChanged, this, &WaylandCursorImage::invalidateCursorTheme);
connect(workspace()->screens(), &Screens::maxScaleChanged, this, &WaylandCursorImage::invalidateCursorTheme);
}
bool WaylandCursorImage::ensureCursorTheme()
......@@ -1258,7 +1258,7 @@ bool WaylandCursorImage::ensureCursorTheme()
}
const Cursor *pointerCursor = Cursors::self()->mouse();
const qreal targetDevicePixelRatio = screens()->maxScale();
const qreal targetDevicePixelRatio = workspace()->screens()->maxScale();
m_cursorTheme = KXcursorTheme(pointerCursor->themeName(), pointerCursor->themeSize(), targetDevicePixelRatio);
if (!m_cursorTheme.isEmpty()) {
......
......@@ -21,28 +21,14 @@
namespace KWin
{
Screens *Screens::s_self = nullptr;
Screens *Screens::create(QObject *parent)
{
Q_ASSERT(!s_self);
s_self = new Screens(parent);
return s_self;
}
Screens::Screens(QObject *parent)
: QObject(parent)
, m_count(0)
Screens::Screens()
: m_count(0)
, m_maxScale(1.0)
{
connect(kwinApp()->platform(), &Platform::screensQueried, this, &Screens::updateCount);
connect(kwinApp()->platform(), &Platform::screensQueried, this, &Screens::changed);
}
Screens::~Screens()
{
s_self = nullptr;
}
void Screens::init()
{
updateCount();
......@@ -112,4 +98,19 @@ Output *Screens::findOutput(int screen) const
return workspace()->outputs().value(screen);
}
int Screens::count() const
{
return m_count;
}
QSize Screens::size() const
{
return m_boundingSize;
}
QRect Screens::geometry() const
{
return QRect(QPoint(0, 0), size());
}
} // namespace
......@@ -32,7 +32,7 @@ class KWIN_EXPORT Screens : public QObject
Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged)
public:
~Screens() override;
explicit Screens();
void init();
......@@ -103,30 +103,7 @@ private:
int m_count;
QSize m_boundingSize;
qreal m_maxScale;
KWIN_SINGLETON(Screens)
};
inline int Screens::count() const
{
return m_count;
}
inline QSize Screens::size() const
{
return m_boundingSize;
}
inline QRect Screens::geometry() const
{
return QRect(QPoint(0, 0), size());
}
inline Screens *screens()
{
return Screens::self();
}
}
#endif // KWIN_SCREENS_H
......@@ -324,7 +324,7 @@ AbstractLevel *AbstractLevel::create(const QList<ClientModel::LevelRestriction>
#endif
}
case ClientModel::ScreenRestriction:
for (int i = 0; i < screens()->count(); ++i) {
for (int i = 0; i < workspace()->screens()->count(); ++i) {
AbstractLevel *childLevel = create(childRestrictions, childrenRestrictions, model, currentLevel);
if (!childLevel) {
continue;
......@@ -398,7 +398,7 @@ ForkLevel::ForkLevel(const QList<ClientModel::LevelRestriction> &childRestrictio
, m_childRestrictions(childRestrictions)
{
connect(VirtualDesktopManager::self(), &VirtualDesktopManager::countChanged, this, &ForkLevel::desktopCountChanged);
connect(screens(), &Screens::countChanged, this, &ForkLevel::screenCountChanged);
connect(workspace()->screens(), &Screens::countChanged, this, &ForkLevel::screenCountChanged);
#if KWIN_BUILD_ACTIVITIES
if (Activities *activities = Workspace::self()->activities()) {
connect(activities, &Activities::added, this, &ForkLevel::activityAdded);
......
......@@ -34,7 +34,7 @@ SwitcherItem::SwitcherItem(QObject *parent)
setCurrentIndex(tabBox->currentIndex().row());
}
});
connect(screens(), &Screens::changed, this, &SwitcherItem::screenGeometryChanged);
connect(workspace()->screens(), &Screens::changed, this, &SwitcherItem::screenGeometryChanged);
connect(Compositor::self(), &Compositor::compositingToggled, this, &SwitcherItem::compositingChanged);
}
......
......@@ -47,7 +47,7 @@ WaylandWindow::WaylandWindow(SurfaceInterface *surface)
this, &WaylandWindow::updateClientOutputs);
connect(this, &WaylandWindow::desktopFileNameChanged,
this, &WaylandWindow::updateIcon);
connect(screens(), &Screens::changed, this, &WaylandWindow::updateClientOutputs);
connect(workspace()->screens(), &Screens::changed, this, &WaylandWindow::updateClientOutputs);
connect(surface->client(), &ClientConnection::aboutToBeDestroyed,
this, &WaylandWindow::destroyWindow);
......
......@@ -80,7 +80,7 @@ Window::Window()
#endif
, m_colorScheme(QStringLiteral("kdeglobals"))
{
connect(screens(), &Screens::changed, this, &Window::screenChanged);
connect(workspace()->screens(), &Screens::changed, this, &Window::screenChanged);
connect(this, &Window::bufferGeometryChanged, this, &Window::inputTransformationChanged);
// Only for compatibility reasons, drop in the next major release.
......
......@@ -157,7 +157,7 @@ Workspace::Workspace()
m_rulebook = std::make_unique<RuleBook>();
m_rulebook->load();
Screens::create(this);
m_screens = std::make_unique<Screens>();
m_screenEdges = std::make_unique<ScreenEdges>();
// VirtualDesktopManager needs to be created prior to init shortcuts
......@@ -217,8 +217,7 @@ void Workspace::init()
}
}
Screens *screens = Screens::self();
screens->init();
m_screens->init();
// create VirtualDesktopManager and perform dependency injection
VirtualDesktopManager *vds = VirtualDesktopManager::self();
......@@ -2862,6 +2861,11 @@ ScreenEdges *Workspace::screenEdges() const
return m_screenEdges.get();
}
Screens *Workspace::screens() const
{
return m_screens.get();
}
#if KWIN_BUILD_ACTIVITIES
Activities *Workspace::activities() const
{
......
......@@ -65,6 +65,7 @@ enum class Predicate;
class Outline;
class RuleBook;
class ScreenEdges;
class Screens;
#if KWIN_BUILD_ACTIVITIES
class Activities;
#endif
......@@ -443,6 +444,7 @@ public:
Placement *placement() const;
RuleBook *rulebook() const;
ScreenEdges *screenEdges() const;
Screens *screens() const;
#if KWIN_BUILD_ACTIVITIES
Activities *activities() const;
#endif
......@@ -721,6 +723,7 @@ private:
std::unique_ptr<Placement> m_placement;
std::unique_ptr<RuleBook> m_rulebook;
std::unique_ptr<ScreenEdges> m_screenEdges;
std::unique_ptr<Screens> m_screens;
#if KWIN_BUILD_ACTIVITIES
std::unique_ptr<Activities> m_activities;
#endif
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment