Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
Mir 0.30 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
mariogrip committed Feb 18, 2018
1 parent 54f2615 commit b092933
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 11 deletions.
104 changes: 93 additions & 11 deletions src/modules/Unity/Application/mirsurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ qint64 msecsSinceReference()

} // namespace {


class MirSurface::SurfaceObserverImpl : public SurfaceObserver, public mir::scene::SurfaceObserver
{
public:
Expand All @@ -87,6 +86,35 @@ class MirSurface::SurfaceObserverImpl : public SurfaceObserver, public mir::scen

void setListener(QObject *listener);

#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 30, 0)
void attrib_changed(mir::scene::Surface const*, MirWindowAttrib, int) override;
void resized_to(mir::scene::Surface const*, mir::geometry::Size const&) override;
void moved_to(mir::scene::Surface const*, mir::geometry::Point const&) override {}
void hidden_set_to(mir::scene::Surface const*, bool) override {}

// Get new frame notifications from Mir, called from a Mir thread.
void frame_posted(mir::scene::Surface const*, int frames_available, mir::geometry::Size const& size ) override;

void alpha_set_to(mir::scene::Surface const*, float) override {}
void transformation_set_to(mir::scene::Surface const*, glm::mat4 const&) override {}
void reception_mode_set_to(mir::scene::Surface const*, mir::input::InputReceptionMode) override {}
void cursor_image_set_to(mir::scene::Surface const*, mir::graphics::CursorImage const&) override;
void orientation_set_to(mir::scene::Surface const*, MirOrientation) override {}
void client_surface_close_requested(mir::scene::Surface const*) override {}
void keymap_changed(mir::scene::Surface const*, MirInputDeviceId, std::string const&, std::string const&,
std::string const&, std::string const&) override {}
void renamed(mir::scene::Surface const*, char const * name) override;
void cursor_image_removed(mir::scene::Surface const*) override;

#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 25, 0)
void placed_relative(mir::scene::Surface const*, mir::geometry::Rectangle const& placement) override;
#endif

#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 27, 0)
void input_consumed(mir::scene::Surface const*, MirEvent const* event) override;
void start_drag_and_drop(mir::scene::Surface const*, std::vector<uint8_t> const& handle) override;
#endif
#else
void attrib_changed(MirWindowAttrib, int) override;
void resized_to(mir::geometry::Size const&) override;
void moved_to(mir::geometry::Point const&) override {}
Expand Down Expand Up @@ -114,6 +142,7 @@ class MirSurface::SurfaceObserverImpl : public SurfaceObserver, public mir::scen
void input_consumed(MirEvent const* event) override;
void start_drag_and_drop(std::vector<uint8_t> const& handle) override;
#endif
#endif

private:
QCursor createQCursorFromMirCursorImage(const mir::graphics::CursorImage &cursorImage);
Expand Down Expand Up @@ -1198,7 +1227,59 @@ void MirSurface::SurfaceObserverImpl::setListener(QObject *listener)
Q_EMIT framesPosted();
}
}
#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 30, 0)
void MirSurface::SurfaceObserverImpl::frame_posted(mir::scene::Surface const*, int /*frames_available*/, mir::geometry::Size const& /*size*/)
{
m_framesPosted = true;
if (m_listener) {
Q_EMIT framesPosted();
}
}

void MirSurface::SurfaceObserverImpl::renamed(mir::scene::Surface const*, char const * name)
{
Q_EMIT nameChanged(QString::fromUtf8(name));
}

void MirSurface::SurfaceObserverImpl::cursor_image_removed(mir::scene::Surface const*)
{
Q_EMIT cursorChanged(QCursor());
}

#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 25, 0)
void MirSurface::SurfaceObserverImpl::placed_relative(mir::scene::Surface const*, mir::geometry::Rectangle const& /*placement*/)
{
}
#endif

void MirSurface::SurfaceObserverImpl::attrib_changed(mir::scene::Surface const*, MirWindowAttrib attribute, int value)
{
if (m_listener) {
Q_EMIT attributeChanged(attribute, value);
}
}

void MirSurface::SurfaceObserverImpl::resized_to(mir::scene::Surface const*, mir::geometry::Size const&size)
{
Q_EMIT resized(QSize(size.width.as_int(), size.height.as_int()));
}

void MirSurface::SurfaceObserverImpl::cursor_image_set_to(mir::scene::Surface const*, const mir::graphics::CursorImage &cursorImage)
{
QCursor qcursor = createQCursorFromMirCursorImage(cursorImage);
Q_EMIT cursorChanged(qcursor);
}

#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 27, 0)
void MirSurface::SurfaceObserverImpl::input_consumed(mir::scene::Surface const*, MirEvent const* /*event*/)
{
}

void MirSurface::SurfaceObserverImpl::start_drag_and_drop(mir::scene::Surface const*, std::vector<uint8_t> const& /*handle*/)
{
}
#endif
#else
void MirSurface::SurfaceObserverImpl::frame_posted(int /*frames_available*/, mir::geometry::Size const& /*size*/)
{
m_framesPosted = true;
Expand Down Expand Up @@ -1241,6 +1322,17 @@ void MirSurface::SurfaceObserverImpl::cursor_image_set_to(const mir::graphics::C
Q_EMIT cursorChanged(qcursor);
}

#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 27, 0)
void MirSurface::SurfaceObserverImpl::input_consumed(MirEvent const* /*event*/)
{
}

void MirSurface::SurfaceObserverImpl::start_drag_and_drop(std::vector<uint8_t> const& /*handle*/)
{
}
#endif
#endif

QCursor MirSurface::SurfaceObserverImpl::createQCursorFromMirCursorImage(const mir::graphics::CursorImage &cursorImage) {
if (cursorImage.as_argb_8888() == nullptr) {
// Must be a named cursor
Expand Down Expand Up @@ -1273,16 +1365,6 @@ QCursor MirSurface::SurfaceObserverImpl::createQCursorFromMirCursorImage(const m
}
}

#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 27, 0)
void MirSurface::SurfaceObserverImpl::input_consumed(MirEvent const* /*event*/)
{
}

void MirSurface::SurfaceObserverImpl::start_drag_and_drop(std::vector<uint8_t> const& /*handle*/)
{
}
#endif

void MirSurface::requestFocus()
{
INFO_MSG << "()";
Expand Down
5 changes: 5 additions & 0 deletions src/platforms/mirserver/surfaceobserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <mir_toolkit/common.h>
#include <mir/geometry/size.h>
#include <mir/version.h>

namespace mir {
namespace scene {
Expand All @@ -39,7 +40,11 @@ class SurfaceObserver : public QObject
public:
virtual ~SurfaceObserver();

#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 30, 0)
virtual void frame_posted(mir::scene::Surface const*, int frames_available, mir::geometry::Size const& size ) = 0;
#else
virtual void frame_posted(int frames_available, mir::geometry::Size const& size ) = 0;
#endif

void notifySurfaceModifications(const miral::WindowSpecification&);

Expand Down
5 changes: 5 additions & 0 deletions tests/modules/WindowManager/mirsurface_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct MirEvent {}; // otherwise won't compile otherwise due to incomplete type

// mir
#include <mir/scene/surface_creation_parameters.h>
#include <mir/version.h>

// miral
#include <miral/window.h>
Expand Down Expand Up @@ -103,7 +104,11 @@ TEST_F(MirSurfaceTest, UpdateTextureBeforeDraw)
.WillRepeatedly(Return(std::make_shared<mir::graphics::StubBuffer>()));

MirSurface surface(mockWindowInfo, nullptr);
#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 30, 0)
surface.surfaceObserver()->frame_posted(NULL, 1, mir::geometry::Size{1,1});
#else
surface.surfaceObserver()->frame_posted(1, mir::geometry::Size{1,1});
#endif

QSignalSpy spyFrameDropped(&surface, SIGNAL(frameDropped()));
QTest::qWait(300);
Expand Down

0 comments on commit b092933

Please sign in to comment.