[kwin_wayland] Keep the size in Surface
Technically the Surface itself does not have a size, it's the ShellSurface or the size of the FullScreenShell's Output. But it simplifies a lot if we keep track of the size in the Surface as that way we can hide the fact which kind of Shell is used. The user of the Surface must connect either the FullscreenShell's Output or the ShellSurface to set the size on the Surface.
This commit is contained in:
parent
9bde3bf0ce
commit
e11df5b4f5
3 changed files with 25 additions and 0 deletions
|
@ -118,6 +118,15 @@ void TestWaylandSurface::testStaticAccessor()
|
|||
QCOMPARE(KWin::Wayland::Surface::all().first(), s1);
|
||||
QCOMPARE(KWin::Wayland::Surface::get(*s1), s1);
|
||||
|
||||
QVERIFY(!s1->size().isValid());
|
||||
QSignalSpy sizeChangedSpy(s1, SIGNAL(sizeChanged(QSize)));
|
||||
QVERIFY(sizeChangedSpy.isValid());
|
||||
const QSize testSize(200, 300);
|
||||
s1->setSize(testSize);
|
||||
QCOMPARE(s1->size(), testSize);
|
||||
QCOMPARE(sizeChangedSpy.count(), 1);
|
||||
QCOMPARE(sizeChangedSpy.first().first().toSize(), testSize);
|
||||
|
||||
// add another surface
|
||||
KWin::Wayland::Surface *s2 = compositor.createSurface();
|
||||
QCOMPARE(KWin::Wayland::Surface::all().count(), 2);
|
||||
|
|
|
@ -125,6 +125,15 @@ void Surface::attachBuffer(wl_buffer *buffer, const QPoint &offset)
|
|||
wl_surface_attach(m_surface, buffer, offset.x(), offset.y());
|
||||
}
|
||||
|
||||
void Surface::setSize(const QSize &size)
|
||||
{
|
||||
if (m_size == size) {
|
||||
return;
|
||||
}
|
||||
m_size = size;
|
||||
emit sizeChanged(m_size);
|
||||
}
|
||||
|
||||
Surface *Surface::get(wl_surface *native)
|
||||
{
|
||||
auto it = std::find_if(s_surfaces.constBegin(), s_surfaces.constEnd(),
|
||||
|
|
|
@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
#include <QObject>
|
||||
#include <QPoint>
|
||||
#include <QSize>
|
||||
|
||||
#include <wayland-client-protocol.h>
|
||||
|
||||
|
@ -52,6 +53,10 @@ public:
|
|||
void damage(const QRect &rect);
|
||||
void damage(const QRegion ®ion);
|
||||
void attachBuffer(wl_buffer *buffer, const QPoint &offset = QPoint());
|
||||
void setSize(const QSize &size);
|
||||
const QSize &size() const {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
operator wl_surface*() {
|
||||
return m_surface;
|
||||
|
@ -67,6 +72,7 @@ public:
|
|||
|
||||
Q_SIGNALS:
|
||||
void frameRendered();
|
||||
void sizeChanged(const QSize&);
|
||||
|
||||
private:
|
||||
void handleFrameCallback();
|
||||
|
@ -74,6 +80,7 @@ private:
|
|||
static QList<Surface*> s_surfaces;
|
||||
wl_surface *m_surface;
|
||||
bool m_frameCallbackInstalled;
|
||||
QSize m_size;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue