Merge lp:~gerboland/miral/add-interactivity-to-WM into lp:miral

Proposed by Gerry Boland
Status: Merged
Merged at revision: 271
Proposed branch: lp:~gerboland/miral/add-interactivity-to-WM
Merge into: lp:miral
Diff against target: 2067 lines (+752/-431)
22 files modified
miral-qt/demos/qml-demo-shell/windowModel.qml (+104/-25)
miral-qt/src/common/windowcontrollerinterface.h (+53/-0)
miral-qt/src/common/windowmodelinterface.h (+36/-30)
miral-qt/src/modules/Unity/Application/mirsurface.cpp (+152/-124)
miral-qt/src/modules/Unity/Application/mirsurface.h (+12/-30)
miral-qt/src/modules/Unity/Application/mirsurfaceinterface.h (+1/-7)
miral-qt/src/modules/Unity/Application/mirsurfacemanager.cpp (+54/-54)
miral-qt/src/modules/Unity/Application/windowmodel.cpp (+43/-29)
miral-qt/src/modules/Unity/Application/windowmodel.h (+9/-2)
miral-qt/src/platforms/mirserver/CMakeLists.txt (+2/-0)
miral-qt/src/platforms/mirserver/mirserver.cpp (+3/-4)
miral-qt/src/platforms/mirserver/mirserver.h (+4/-2)
miral-qt/src/platforms/mirserver/qmirserver.cpp (+2/-2)
miral-qt/src/platforms/mirserver/windowcontroller.cpp (+85/-0)
miral-qt/src/platforms/mirserver/windowcontroller.h (+51/-0)
miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp (+48/-20)
miral-qt/src/platforms/mirserver/windowmanagementpolicy.h (+13/-8)
miral-qt/src/platforms/mirserver/windowmodel.cpp (+10/-26)
miral-qt/tests/framework/fake_mirsurface.cpp (+6/-4)
miral-qt/tests/framework/fake_mirsurface.h (+5/-10)
miral-qt/tests/modules/SurfaceManager/CMakeLists.txt (+3/-1)
miral-qt/tests/modules/SurfaceManager/mirsurface_test.cpp (+56/-53)
To merge this branch: bzr merge lp:~gerboland/miral/add-interactivity-to-WM
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
Review via email: mp+302531@code.launchpad.net

Commit message

[miral-qt] Refactor out MirSurfaceManager and replace with qtmir::WindowModel. Add WindowController which enables window move & resize.

- MirSurfaceManager managed lifetimes of MirSurfaces. With MirAL, this responsibility must move to the WindowModel. Will fully remove MirSurfaceManager in a later MP (commented out for now).
- WindowController allows shell to control the window manager
- MirSurface refactored to wrap miral::WindowInfo which has nearly all the info it needs, and given access to the WindowController.
- redid the signal/slot interface between mirserver::WindowModel and qtmir::WindowModel to reduce the amount of traffic and better reflect the miral API.
- mir::shell::Shell no longer exported in the top-level MirServer class.

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

With Vivid+Overlay/clang I need:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
Q_DECLARE_OPERATORS_FOR_FLAGS(DirtyStates)
#pragma clang diagnostic pop

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

/home/alan/display_server/miral/miral-qt/tests/modules/Application/application_test.cpp:287:35: error: allocating an object of abstract class type 'qtmir::FakeMirSurface'
    FakeMirSurface *surface = new FakeMirSurface;
                                  ^
/home/alan/display_server/miral/miral-qt/src/modules/Unity/Application/mirsurfaceinterface.h:52:18: note: unimplemented pure virtual method 'requestPosition' in 'FakeMirSurface'
    virtual void requestPosition(const QPoint newPosition) = 0;
                 ^
/home/alan/display_server/miral/miral-qt/src/modules/Unity/Application/mirsurfaceinterface.h:121:18: note: unimplemented pure virtual method 'setShellChrome' in 'FakeMirSurface'
    virtual void setShellChrome(Mir::ShellChrome shellChrome) = 0;
                 ^

review: Needs Fixing
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Possibly not new with this MP, but after starting "qml-demo-shell --x11-displays 648x480" and running mir_demo_client_egltriangle to try move/resize the server crashed when I closed the client.

Revision history for this message
Gerry Boland (gerboland) wrote :

That's what I get for leaving NO_TESTS=1 set!

I've made whatever tests that should be workable compile - they fail still. Other tests I've not updated until the functionality they rely on has been restored.

On your crash find, I cannot reproduce it here. Could you grab me a backtrace?

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Crash seems fairly consistent. If it matters, this is g++/yakkety:

Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00007fdbe02508fb in qtmir::MirSurface::updateTexture (this=0x55d46b5f13a0)
    at /home/alan/display_server/miral0/miral-qt/src/modules/Unity/Application/mirsurface.cpp:406
406 auto renderables = window->generate_renderables(userId);
[Current thread is 1 (Thread 0x7fdbce4d5700 (LWP 9694))]
(gdb) bt
#0 0x00007fdbe02508fb in qtmir::MirSurface::updateTexture (this=0x55d46b5f13a0)
    at /home/alan/display_server/miral0/miral-qt/src/modules/Unity/Application/mirsurface.cpp:406
#1 0x00007fdbe025bf81 in qtmir::MirSurfaceItem::updatePaintNode (
    this=0x55d46b418ac0, oldNode=0x7fdbc4569bd0)
    at /home/alan/display_server/miral0/miral-qt/src/modules/Unity/Application/mirsurfaceitem.cpp:226
#2 0x00007fdc011132c8 in QQuickWindowPrivate::updateDirtyNode(QQuickItem*) ()
   from /usr/lib/x86_64-linux-gnu/libQt5Quick.so.5
#3 0x00007fdc01113b3b in QQuickWindowPrivate::updateDirtyNodes() ()
   from /usr/lib/x86_64-linux-gnu/libQt5Quick.so.5
#4 0x00007fdc01113cb0 in QQuickWindowPrivate::syncSceneGraph() ()
   from /usr/lib/x86_64-linux-gnu/libQt5Quick.so.5
#5 0x00007fdc010e4d53 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Quick.so.5
#6 0x00007fdc010e5f95 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Quick.so.5
#7 0x00007fdc010eb07c in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Quick.so.5
#8 0x00007fdc001d77be in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#9 0x00007fdbff2ab70a in start_thread (arg=0x7fdbce4d5700) at pthread_create.c:333
#10 0x00007fdbff8d06ad in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

On balance I think it better to land this "wiring" than to try to perfect it first.

~~~~

+#include "miral/window_info.h"

Once MirAL supports everything we need we intend to separate the Qt use of MirAL from the project. So I'd be inclined to use <> includes for miral headers.

~~~~

I see this a few times: "static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);" but I don't see why you use the cast operator. Ideally we don't want Qt to use mir::xxx::Yyy, so is this just a tag to review later?

review: Approve
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> With Vivid+Overlay/clang I need:
>
> #pragma clang diagnostic push
> #pragma clang diagnostic ignored "-Wunused-function"
> Q_DECLARE_OPERATORS_FOR_FLAGS(DirtyStates)
> #pragma clang diagnostic pop

Oh g++ errors on these. We need something like:

#if defined(__clang__)

review: Needs Fixing
266. By Gerry Boland

ifdef the clang workaround

Revision history for this message
Gerry Boland (gerboland) wrote :

Done. Your g++/clang++ are more fussy than mine on xenial!

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-function"
+Q_DECLARE_OPERATORS_FOR_FLAGS(DirtyStates)
+#pragma clang diagnostic pop
+#endif

Do you really mean we only need Q_DECLARE_OPERATORS_FOR_FLAGS() with clang? Maybe we just don't need it?

review: Needs Fixing
267. By Gerry Boland

The | operator for QFlags not actually needed - yet! Remove, add back only when I need it

Revision history for this message
Gerry Boland (gerboland) wrote :

> +#if defined(__clang__)
> +#pragma clang diagnostic push
> +#pragma clang diagnostic ignored "-Wunused-function"
> +Q_DECLARE_OPERATORS_FOR_FLAGS(DirtyStates)
> +#pragma clang diagnostic pop
> +#endif
>
> Do you really mean we only need Q_DECLARE_OPERATORS_FOR_FLAGS() with clang?
> Maybe we just don't need it?

Quite right, it's not needed until I start combining flags with the | operator. I've removed it entirely

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

There's an orphaned comment but WTF

review: Approve
268. By Gerry Boland

remove defunkt comment

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'miral-qt/demos/qml-demo-shell/windowModel.qml'
--- miral-qt/demos/qml-demo-shell/windowModel.qml 2016-07-27 12:37:01 +0000
+++ miral-qt/demos/qml-demo-shell/windowModel.qml 2016-08-12 12:04:26 +0000
@@ -2,37 +2,116 @@
2import Unity.Application 0.12import Unity.Application 0.1
33
4FocusScope {4FocusScope {
5 id: root
5 focus: true6 focus: true
67
7 WindowModel {8 WindowModel {
8 id: windowModel;9 id: windowModel;
9 }10 }
1011
11 Repeater {12 Item {
12 anchors.fill: parent13 id: windowViewContainer
13 model: windowModel14 anchors.fill: parent
1415
15 delegate: MirSurfaceItem {16 Repeater {
16 id: surfaceItem17 model: windowModel
17 surface: model.surface18
18 consumesInput: true // QUESTION: why is this non-default?19 delegate: MirSurfaceItem {
19 x: surface.position.x20 id: surfaceItem
20 y: surface.position.y21 surface: model.surface
21 width: surface.size.width22 consumesInput: true // QUESTION: why is this non-default?
22 height: surface.size.height23 x: surface.position.x
23 focus: surface.focused24 y: surface.position.y
2425 width: surface.size.width
25 Rectangle {26 height: surface.size.height
26 anchors { top: parent.bottom; right: parent.right }27 focus: surface.focused
27 width: childrenRect.width28
28 height: childrenRect.height29 Rectangle {
29 color: surface.focused ? "red" : "lightsteelblue"30 anchors { top: parent.bottom; right: parent.right }
30 opacity: 0.831 width: childrenRect.width
31 Text {32 height: childrenRect.height
32 text: surface.position.x + "," + surface.position.y + " " + surface.size.width + "x" + surface.size.height33 color: surface.focused ? "red" : "lightsteelblue"
33 font.pixelSize: 1034 opacity: 0.8
34 }35 Text {
35 }36 text: surface.position.x + "," + surface.position.y + " " + surface.size.width + "x" + surface.size.height
37 font.pixelSize: 10
38 }
39 }
40 }
41 }
42 }
43
44 Button {
45 anchors { right: parent.right; bottom: parent.bottom }
46 height: 30
47 width: 80
48 text: "Quit"
49 onClicked: Qt.quit()
50 }
51
52 Text {
53 anchors { left: parent.left; bottom: parent.bottom }
54 text: "Move window: Ctrl+click\n
55Resize window: Ctrl+Right click"
56 }
57
58 MouseArea {
59 anchors.fill: parent
60 acceptedButtons: Qt.LeftButton | Qt.RightButton
61 property variant window: null
62 property int initialWindowXPosition
63 property int initialWindowYPosition
64 property int initialWindowWidth
65 property int initialWindowHeight
66 property int initialMouseXPosition
67 property int initialMouseYPosition
68 property var action
69
70 function moveWindowBy(window, delta) {
71 window.surface.requestPosition(Qt.point(initialWindowXPosition + delta.x,
72 initialWindowYPosition + delta.y))
73 }
74 function resizeWindowBy(window, delta) {
75 window.surface.resize(Qt.size(initialWindowWidth + delta.x,
76 initialWindowHeight + delta.y))
77 }
78
79 onPressed: {
80 if (mouse.modifiers & Qt.ControlModifier) {
81 window = windowViewContainer.childAt(mouse.x, mouse.y)
82 if (!window) return;
83
84 if (mouse.button == Qt.LeftButton) {
85 initialWindowXPosition = window.surface.position.x
86 initialWindowYPosition = window.surface.position.y
87 action = moveWindowBy
88 } else if (mouse.button == Qt.RightButton) {
89 initialWindowHeight = window.surface.size.height
90 initialWindowWidth = window.surface.size.width
91 action = resizeWindowBy
92 }
93 initialMouseXPosition = mouse.x
94 initialMouseYPosition = mouse.y
95 } else {
96 mouse.accepted = false
97 }
98 }
99
100 onPositionChanged: {
101 if (!window) {
102 mouse.accepted = false
103 return
104 }
105 action(window, Qt.point(mouse.x - initialMouseXPosition, mouse.y - initialMouseYPosition))
106 }
107
108 onReleased: {
109 if (!window) {
110 mouse.accepted = false
111 return
112 }
113 action(window, Qt.point(mouse.x - initialMouseXPosition, mouse.y - initialMouseYPosition))
114 window = null;
36 }115 }
37 }116 }
38}117}
39118
=== added file 'miral-qt/src/common/windowcontrollerinterface.h'
--- miral-qt/src/common/windowcontrollerinterface.h 1970-01-01 00:00:00 +0000
+++ miral-qt/src/common/windowcontrollerinterface.h 2016-08-12 12:04:26 +0000
@@ -0,0 +1,53 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef WINDOWCONTROLLERINTERFACE_H
18#define WINDOWCONTROLLERINTERFACE_H
19
20#include "miral/window.h"
21
22#include "mir_toolkit/event.h"
23
24#include <QPoint>
25#include <QSize>
26
27namespace qtmir {
28
29class MirSurface;
30
31class WindowControllerInterface {
32public:
33 WindowControllerInterface() = default;
34 virtual ~WindowControllerInterface() = default;
35
36 // focus() asks Mir to bring particular window to the front and recommend to shell that it be focused
37 virtual void focus (const miral::Window &window) = 0;
38 // setActiveFocus() is how shell notifies Mir/application that a window actually has input focus
39 virtual void setActiveFocus(const miral::Window &window, const bool activeFocus) = 0;
40
41 virtual void resize(const miral::Window &window, const QSize &size) = 0;
42 virtual void move (const miral::Window &window, const QPoint &topLeft) = 0;
43
44 virtual void setState(const miral::Window &window, const MirSurfaceState state) = 0;
45
46 virtual void deliverKeyboardEvent(const miral::Window &window, const MirKeyboardEvent *event) = 0;
47 virtual void deliverTouchEvent (const miral::Window &window, const MirTouchEvent *event) = 0;
48 virtual void deliverPointerEvent (const miral::Window &window, const MirPointerEvent *event) = 0;
49};
50
51} // namespace qtmir
52
53#endif // WINDOWCONTROLLERINTERFACE_H
054
=== modified file 'miral-qt/src/common/windowmodelinterface.h'
--- miral-qt/src/common/windowmodelinterface.h 2016-07-27 17:41:48 +0000
+++ miral-qt/src/common/windowmodelinterface.h 2016-08-12 12:04:26 +0000
@@ -22,35 +22,39 @@
22#include <QPoint>22#include <QPoint>
23#include <QVector>23#include <QVector>
2424
25#include <mir/scene/surface.h>25#include "miral/window_info.h"
2626
27namespace qtmir {27namespace qtmir {
2828
29// miral::WindowInfo contains all the metadata the WindowManager{,Policy} needs. However the29// miral::WindowInfo missing a default constructor, needed by MOC. Need to wrap it instead
30// WindowModel only needs a read-only subset of this data, which is what the struct is for.30class WindowInfo {
31struct WindowInfo {31public:
32 QSize size;32 WindowInfo() = default;
33 QPoint position;33 WindowInfo(const miral::WindowInfo &windowInfo)
34 bool focused;34 : window(windowInfo.window())
35 const std::shared_ptr<mir::scene::Surface> surface;35 , name(windowInfo.name())
3636 , type(windowInfo.type())
37 enum class DirtyStates {37 , state(windowInfo.state())
38 Size = 1,38 , restoreRect(windowInfo.restore_rect())
39 Position = 2,39 , parent(windowInfo.parent())
40 Focus = 440 , children(windowInfo.children())
41 };41 , minWidth(windowInfo.min_width())
42};42 , minHeight(windowInfo.min_height())
4343 , maxWidth(windowInfo.max_width())
44// We assign each Window with an index which corresponds to the position it has in the window stack.44 , maxHeight(windowInfo.max_height())
45struct NumberedWindow {45 {}
46 unsigned int index;46
47 WindowInfo windowInfo;47 miral::Window window;
48};48 mir::optional_value<std::string> name;
4949 MirSurfaceType type;
50struct DirtiedWindow {50 MirSurfaceState state;
51 unsigned int index;51 mir::geometry::Rectangle restoreRect;
52 WindowInfo windowInfo;52 miral::Window parent;
53 WindowInfo::DirtyStates dirtyWindowInfo;53 std::vector<miral::Window> children;
54 mir::geometry::Width minWidth;
55 mir::geometry::Height minHeight;
56 mir::geometry::Width maxWidth;
57 mir::geometry::Height maxHeight;
54};58};
5559
5660
@@ -62,9 +66,12 @@
62 virtual ~WindowModelInterface() = default;66 virtual ~WindowModelInterface() = default;
6367
64Q_SIGNALS:68Q_SIGNALS:
65 void windowAdded(const qtmir::NumberedWindow);69 void windowAdded(const qtmir::WindowInfo, const unsigned int index);
66 void windowRemoved(const unsigned int index);70 void windowRemoved(const unsigned int index);
67 void windowChanged(const qtmir::DirtiedWindow);71 void windowMoved(const QPoint topLeft, const unsigned int index);
72 void windowResized(const QSize size, const unsigned int index);
73 void windowFocused(const unsigned int index);
74 void windowInfoChanged(const qtmir::WindowInfo, const unsigned int index);
6875
69private:76private:
70 Q_DISABLE_COPY(WindowModelInterface)77 Q_DISABLE_COPY(WindowModelInterface)
@@ -72,7 +79,6 @@
7279
73} // namespace qtmir80} // namespace qtmir
7481
75Q_DECLARE_METATYPE(qtmir::NumberedWindow)82Q_DECLARE_METATYPE(qtmir::WindowInfo)
76Q_DECLARE_METATYPE(qtmir::DirtiedWindow)
7783
78#endif // WINDOWMODELINTERFACE_H84#endif // WINDOWMODELINTERFACE_H
7985
=== modified file 'miral-qt/src/modules/Unity/Application/mirsurface.cpp'
--- miral-qt/src/modules/Unity/Application/mirsurface.cpp 2016-07-27 12:42:21 +0000
+++ miral-qt/src/modules/Unity/Application/mirsurface.cpp 2016-08-12 12:04:26 +0000
@@ -177,34 +177,38 @@
177 return ev;177 return ev;
178}178}
179179
180enum class DirtyState {
181 Clean = 0,
182 Name = 1 << 1,
183 Type = 1 << 2,
184 State = 1 << 3,
185 RestoreRect = 1 << 4,
186 Children = 1 << 5,
187 MinSize = 1 << 6,
188 MaxSize = 1 << 7,
189};
190Q_DECLARE_FLAGS(DirtyStates, DirtyState)
191
180} // namespace {192} // namespace {
181193
182MirSurface::MirSurface(std::shared_ptr<mir::scene::Surface> surface,194MirSurface::MirSurface(WindowInfo windowInfo,
183 SessionInterface* session,195 WindowControllerInterface* controller,
184 mir::shell::Shell* shell,196 std::shared_ptr<SurfaceObserver> observer)
185 std::shared_ptr<SurfaceObserver> observer,
186 const CreationHints &creationHints)
187 : MirSurfaceInterface()197 : MirSurfaceInterface()
188 , m_surface(surface)198 , m_windowInfo(windowInfo)
189 , m_session(session)199 , m_controller(controller)
190 , m_shell(shell)
191 , m_firstFrameDrawn(false)200 , m_firstFrameDrawn(false)
192 , m_orientationAngle(Mir::Angle0)201 , m_orientationAngle(Mir::Angle0)
193 , m_textureUpdated(false)202 , m_textureUpdated(false)
194 , m_currentFrameNumber(0)203 , m_currentFrameNumber(0)
195 , m_live(true)204 , m_live(true)
205 , m_position(toQPoint(windowInfo.window.top_left()))
206 , m_size(toQSize(windowInfo.window.size()))
196 , m_shellChrome(Mir::NormalChrome)207 , m_shellChrome(Mir::NormalChrome)
197{208{
198 DEBUG_MSG << "()";209 DEBUG_MSG << "()";
199210
200 m_position = toQPoint(surface->top_left());211 //m_shellChrome = creationHints.shellChrome; TODO - where will this come from now?
201 m_minimumWidth = creationHints.minWidth;
202 m_minimumHeight = creationHints.minHeight;
203 m_maximumWidth = creationHints.maxWidth;
204 m_maximumHeight = creationHints.maxHeight;
205 m_widthIncrement = creationHints.widthIncrement;
206 m_heightIncrement = creationHints.heightIncrement;
207 m_shellChrome = creationHints.shellChrome;
208212
209 m_surfaceObserver = observer;213 m_surfaceObserver = observer;
210 if (observer) {214 if (observer) {
@@ -212,12 +216,6 @@
212 connect(observer.get(), &SurfaceObserver::attributeChanged, this, &MirSurface::onAttributeChanged);216 connect(observer.get(), &SurfaceObserver::attributeChanged, this, &MirSurface::onAttributeChanged);
213 connect(observer.get(), &SurfaceObserver::nameChanged, this, &MirSurface::nameChanged);217 connect(observer.get(), &SurfaceObserver::nameChanged, this, &MirSurface::nameChanged);
214 connect(observer.get(), &SurfaceObserver::cursorChanged, this, &MirSurface::setCursor);218 connect(observer.get(), &SurfaceObserver::cursorChanged, this, &MirSurface::setCursor);
215 connect(observer.get(), &SurfaceObserver::minimumWidthChanged, this, &MirSurface::setMinimumWidth);
216 connect(observer.get(), &SurfaceObserver::minimumHeightChanged, this, &MirSurface::setMinimumHeight);
217 connect(observer.get(), &SurfaceObserver::maximumWidthChanged, this, &MirSurface::setMaximumWidth);
218 connect(observer.get(), &SurfaceObserver::maximumHeightChanged, this, &MirSurface::setMaximumHeight);
219 connect(observer.get(), &SurfaceObserver::widthIncrementChanged, this, &MirSurface::setWidthIncrement);
220 connect(observer.get(), &SurfaceObserver::heightIncrementChanged, this, &MirSurface::setHeightIncrement);
221 connect(observer.get(), &SurfaceObserver::shellChromeChanged, this, [&](MirShellChrome shell_chrome) {219 connect(observer.get(), &SurfaceObserver::shellChromeChanged, this, [&](MirShellChrome shell_chrome) {
222 setShellChrome(static_cast<Mir::ShellChrome>(shell_chrome));220 setShellChrome(static_cast<Mir::ShellChrome>(shell_chrome));
223 });221 });
@@ -225,7 +223,7 @@
225 observer->setListener(this);223 observer->setListener(this);
226 }224 }
227225
228 connect(session, &QObject::destroyed, this, &MirSurface::onSessionDestroyed);226 //connect(session, &QObject::destroyed, this, &MirSurface::onSessionDestroyed); // TODO try using Shared pointer for lifecycle
229227
230 connect(&m_frameDropperTimer, &QTimer::timeout,228 connect(&m_frameDropperTimer, &QTimer::timeout,
231 this, &MirSurface::dropPendingBuffer);229 this, &MirSurface::dropPendingBuffer);
@@ -256,7 +254,8 @@
256 Q_ASSERT(m_views.isEmpty());254 Q_ASSERT(m_views.isEmpty());
257255
258 QMutexLocker locker(&m_mutex);256 QMutexLocker locker(&m_mutex);
259 m_surface->remove_observer(m_surfaceObserver);257// auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);
258// window->remove_observer(m_surfaceObserver); // FIXME - window null at this stage!
260259
261 delete m_closeTimer;260 delete m_closeTimer;
262261
@@ -298,7 +297,7 @@
298297
299Mir::Type MirSurface::type() const298Mir::Type MirSurface::type() const
300{299{
301 switch (m_surface->type()) {300 switch (m_windowInfo.type) {
302 case mir_surface_type_normal:301 case mir_surface_type_normal:
303 return Mir::NormalType;302 return Mir::NormalType;
304303
@@ -337,7 +336,8 @@
337336
338 const void* const userId = (void*)123; // TODO: Multimonitor support337 const void* const userId = (void*)123; // TODO: Multimonitor support
339338
340 int framesPending = m_surface->buffers_ready_for_compositor(userId);339 auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);
340 int framesPending = window->buffers_ready_for_compositor(userId);
341 if (framesPending > 0) {341 if (framesPending > 0) {
342 m_textureUpdated = false;342 m_textureUpdated = false;
343343
@@ -398,10 +398,11 @@
398 }398 }
399399
400 const void* const userId = (void*)123;400 const void* const userId = (void*)123;
401 auto renderables = m_surface->generate_renderables(userId);401 auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);
402 auto renderables = window->generate_renderables(userId);
402403
403 if (renderables.size() > 0 &&404 if (renderables.size() > 0 &&
404 (m_surface->buffers_ready_for_compositor(userId) > 0 || !texture->hasBuffer())405 (window->buffers_ready_for_compositor(userId) > 0 || !texture->hasBuffer())
405 ) {406 ) {
406 // Avoid holding two buffers for the compositor at the same time. Thus free the current407 // Avoid holding two buffers for the compositor at the same time. Thus free the current
407 // before acquiring the next408 // before acquiring the next
@@ -409,7 +410,7 @@
409 texture->setBuffer(renderables[0]->buffer());410 texture->setBuffer(renderables[0]->buffer());
410 ++m_currentFrameNumber;411 ++m_currentFrameNumber;
411412
412 if (texture->textureSize() != m_size) {413 if (texture->textureSize() != size()) {
413 m_size = texture->textureSize();414 m_size = texture->textureSize();
414 QMetaObject::invokeMethod(this, "emitSizeChanged", Qt::QueuedConnection);415 QMetaObject::invokeMethod(this, "emitSizeChanged", Qt::QueuedConnection);
415 }416 }
@@ -417,7 +418,7 @@
417 m_textureUpdated = true;418 m_textureUpdated = true;
418 }419 }
419420
420 if (m_surface->buffers_ready_for_compositor(userId) > 0) {421 if (window->buffers_ready_for_compositor(userId) > 0) {
421 // restart the frame dropper to give MirSurfaceItems enough time to render the next frame.422 // restart the frame dropper to give MirSurfaceItems enough time to render the next frame.
422 // queued since the timer lives in a different thread423 // queued since the timer lives in a different thread
423 QMetaObject::invokeMethod(&m_frameDropperTimer, "start", Qt::QueuedConnection);424 QMetaObject::invokeMethod(&m_frameDropperTimer, "start", Qt::QueuedConnection);
@@ -436,7 +437,8 @@
436{437{
437 QMutexLocker locker(&m_mutex);438 QMutexLocker locker(&m_mutex);
438 const void* const userId = (void*)123;439 const void* const userId = (void*)123;
439 return m_surface->buffers_ready_for_compositor(userId);440 auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);
441 return window->buffers_ready_for_compositor(userId);
440}442}
441443
442void MirSurface::setFocused(bool value)444void MirSurface::setFocused(bool value)
@@ -479,10 +481,10 @@
479481
480 if (m_activelyFocusedViews.isEmpty()) {482 if (m_activelyFocusedViews.isEmpty()) {
481 DEBUG_MSG << "() unfocused";483 DEBUG_MSG << "() unfocused";
482 m_shell->set_surface_attribute(m_session->session(), m_surface, mir_surface_attrib_focus, mir_surface_unfocused);484 m_controller->setActiveFocus(m_windowInfo.window, false);
483 } else {485 } else {
484 DEBUG_MSG << "() focused";486 DEBUG_MSG << "() focused";
485 m_shell->set_surface_attribute(m_session->session(), m_surface, mir_surface_attrib_focus, mir_surface_focused);487 m_controller->setActiveFocus(m_windowInfo.window, true);
486 }488 }
487489
488 m_neverSetSurfaceFocus = false;490 m_neverSetSurfaceFocus = false;
@@ -500,22 +502,21 @@
500 Q_EMIT closeRequested();502 Q_EMIT closeRequested();
501 m_closeTimer->start();503 m_closeTimer->start();
502504
503 if (m_surface) {505 if (m_windowInfo.window) {
504 m_surface->request_client_surface_close();506 auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);
507 window->request_client_surface_close();
505 }508 }
506}509}
507510
508void MirSurface::resize(int width, int height)511void MirSurface::resize(int width, int height)
509{512{
510 int mirWidth = m_surface->size().width.as_int();513 auto const &window = m_windowInfo.window;
511 int mirHeight = m_surface->size().height.as_int();
512514
513 bool mirSizeIsDifferent = width != mirWidth || height != mirHeight;515 bool mirSizeIsDifferent = width != m_size.width() || height != m_size.height();
514516
515 if (clientIsRunning() && mirSizeIsDifferent) {517 if (clientIsRunning() && mirSizeIsDifferent) {
516 mir::geometry::Size newMirSize(width, height);518 m_controller->resize(window, QSize(width, height));
517 m_surface->resize(newMirSize);519 DEBUG_MSG << " old (" << m_size.width() << "," << m_size.height() << ")"
518 DEBUG_MSG << " old (" << mirWidth << "," << mirHeight << ")"
519 << ", new (" << width << "," << height << ")";520 << ", new (" << width << "," << height << ")";
520 }521 }
521}522}
@@ -525,6 +526,27 @@
525 return m_position;526 return m_position;
526}527}
527528
529void MirSurface::setPosition(const QPoint newPosition)
530{
531 if (m_position != newPosition) {
532 m_position = newPosition;
533 Q_EMIT positionChanged(newPosition);
534 }
535}
536
537void MirSurface::requestPosition(const QPoint newPosition)
538{
539 m_controller->move(m_windowInfo.window, newPosition);
540}
541
542void MirSurface::setSize(const QSize newSize)
543{
544 if (m_size != newSize) {
545 m_size = newSize;
546 Q_EMIT sizeChanged(newSize);
547 }
548}
549
528QSize MirSurface::size() const550QSize MirSurface::size() const
529{551{
530 return m_size;552 return m_size;
@@ -532,7 +554,7 @@
532554
533Mir::State MirSurface::state() const555Mir::State MirSurface::state() const
534{556{
535 switch (m_surface->state()) {557 switch (m_windowInfo.state) {
536 case mir_surface_state_unknown:558 case mir_surface_state_unknown:
537 return Mir::UnknownState;559 return Mir::UnknownState;
538 case mir_surface_state_restored:560 case mir_surface_state_restored:
@@ -587,8 +609,9 @@
587 return;609 return;
588 }610 }
589611
590 if (m_surface) {612 if (m_windowInfo.window) {
591 m_surface->set_orientation(mirOrientation);613 auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);
614 window->set_orientation(mirOrientation);
592 }615 }
593616
594 Q_EMIT orientationAngleChanged(angle);617 Q_EMIT orientationAngleChanged(angle);
@@ -596,12 +619,15 @@
596619
597QString MirSurface::name() const620QString MirSurface::name() const
598{621{
599 return QString::fromStdString(m_surface->name());622 if (!m_windowInfo.name.is_set()) {
623 return QStringLiteral();
624 }
625 return QString::fromStdString(m_windowInfo.name.value());
600}626}
601627
602void MirSurface::setState(Mir::State qmlState)628void MirSurface::setState(Mir::State qmlState)
603{629{
604 int mirState;630 MirSurfaceState mirState;
605631
606 switch (qmlState) {632 switch (qmlState) {
607 default:633 default:
@@ -638,7 +664,7 @@
638 break;664 break;
639 }665 }
640666
641 m_shell->set_surface_attribute(m_session->session(), m_surface, mir_surface_attrib_state, mirState);667 m_controller->setState(m_windowInfo.window, mirState);
642}668}
643669
644void MirSurface::setLive(bool value)670void MirSurface::setLive(bool value)
@@ -660,69 +686,79 @@
660686
661bool MirSurface::visible() const687bool MirSurface::visible() const
662{688{
663 return m_surface->query(mir_surface_attrib_visibility) == mir_surface_visibility_exposed;689 //return m_windowInfo->query(mir_surface_attrib_visibility) == mir_surface_visibility_exposed;
690 return true; //FIXME
664}691}
665692#include <mir_toolkit/event.h>
666void MirSurface::mousePressEvent(QMouseEvent *event)693void MirSurface::mousePressEvent(QMouseEvent *event)
667{694{
668 auto ev = makeMirEvent(event, mir_pointer_action_button_down);695 auto ev = makeMirEvent(event, mir_pointer_action_button_down);
669 m_surface->consume(ev.get());696 auto ev1 = reinterpret_cast<MirPointerEvent const*>(ev.get());
697 m_controller->deliverPointerEvent(m_windowInfo.window, ev1);
670 event->accept();698 event->accept();
671}699}
672700
673void MirSurface::mouseMoveEvent(QMouseEvent *event)701void MirSurface::mouseMoveEvent(QMouseEvent *event)
674{702{
675 auto ev = makeMirEvent(event, mir_pointer_action_motion);703 auto ev = makeMirEvent(event, mir_pointer_action_motion);
676 m_surface->consume(ev.get());704 auto ev1 = reinterpret_cast<MirPointerEvent const*>(ev.get());
705 m_controller->deliverPointerEvent(m_windowInfo.window, ev1);
677 event->accept();706 event->accept();
678}707}
679708
680void MirSurface::mouseReleaseEvent(QMouseEvent *event)709void MirSurface::mouseReleaseEvent(QMouseEvent *event)
681{710{
682 auto ev = makeMirEvent(event, mir_pointer_action_button_up);711 auto ev = makeMirEvent(event, mir_pointer_action_button_up);
683 m_surface->consume(ev.get());712 auto ev1 = reinterpret_cast<MirPointerEvent const*>(ev.get());
713 m_controller->deliverPointerEvent(m_windowInfo.window, ev1);
684 event->accept();714 event->accept();
685}715}
686716
687void MirSurface::hoverEnterEvent(QHoverEvent *event)717void MirSurface::hoverEnterEvent(QHoverEvent *event)
688{718{
689 auto ev = makeMirEvent(event, mir_pointer_action_enter);719 auto ev = makeMirEvent(event, mir_pointer_action_enter);
690 m_surface->consume(ev.get());720 auto ev1 = reinterpret_cast<MirPointerEvent const*>(ev.get());
721 m_controller->deliverPointerEvent(m_windowInfo.window, ev1);
691 event->accept();722 event->accept();
692}723}
693724
694void MirSurface::hoverLeaveEvent(QHoverEvent *event)725void MirSurface::hoverLeaveEvent(QHoverEvent *event)
695{726{
696 auto ev = makeMirEvent(event, mir_pointer_action_leave);727 auto ev = makeMirEvent(event, mir_pointer_action_leave);
697 m_surface->consume(ev.get());728 auto ev1 = reinterpret_cast<MirPointerEvent const*>(ev.get());
729 m_controller->deliverPointerEvent(m_windowInfo.window, ev1);
698 event->accept();730 event->accept();
699}731}
700732
701void MirSurface::hoverMoveEvent(QHoverEvent *event)733void MirSurface::hoverMoveEvent(QHoverEvent *event)
702{734{
703 auto ev = makeMirEvent(event, mir_pointer_action_motion);735 auto ev = makeMirEvent(event, mir_pointer_action_motion);
704 m_surface->consume(ev.get());736 auto ev1 = reinterpret_cast<MirPointerEvent const*>(ev.get());
737 m_controller->deliverPointerEvent(m_windowInfo.window, ev1);
705 event->accept();738 event->accept();
706}739}
707740
708void MirSurface::wheelEvent(QWheelEvent *event)741void MirSurface::wheelEvent(QWheelEvent *event)
709{742{
710 auto ev = makeMirEvent(event);743 auto ev = makeMirEvent(event);
711 m_surface->consume(ev.get());744 auto ev1 = reinterpret_cast<MirPointerEvent const*>(ev.get());
745 m_controller->deliverPointerEvent(m_windowInfo.window, ev1);
712 event->accept();746 event->accept();
713}747}
714748
715void MirSurface::keyPressEvent(QKeyEvent *qtEvent)749void MirSurface::keyPressEvent(QKeyEvent *qtEvent)
716{750{
717 auto ev = makeMirEvent(qtEvent);751 auto ev = makeMirEvent(qtEvent);
718 m_surface->consume(ev.get());752 auto ev1 = reinterpret_cast<MirKeyboardEvent const*>(ev.get());
753 m_controller->deliverKeyboardEvent(m_windowInfo.window, ev1);
719 qtEvent->accept();754 qtEvent->accept();
720}755}
721756
722void MirSurface::keyReleaseEvent(QKeyEvent *qtEvent)757void MirSurface::keyReleaseEvent(QKeyEvent *qtEvent)
723{758{
724 auto ev = makeMirEvent(qtEvent);759 auto ev = makeMirEvent(qtEvent);
725 m_surface->consume(ev.get());760 auto ev1 = reinterpret_cast<MirKeyboardEvent const*>(ev.get());
761 m_controller->deliverKeyboardEvent(m_windowInfo.window, ev1);
726 qtEvent->accept();762 qtEvent->accept();
727}763}
728764
@@ -732,7 +768,8 @@
732 ulong timestamp)768 ulong timestamp)
733{769{
734 auto ev = makeMirEvent(mods, touchPoints, touchPointStates, timestamp);770 auto ev = makeMirEvent(mods, touchPoints, touchPointStates, timestamp);
735 m_surface->consume(ev.get());771 auto ev1 = reinterpret_cast<MirTouchEvent const*>(ev.get());
772 m_controller->deliverTouchEvent(m_windowInfo.window, ev1);
736}773}
737774
738bool MirSurface::clientIsRunning() const775bool MirSurface::clientIsRunning() const
@@ -865,7 +902,9 @@
865 return;902 return;
866 }903 }
867904
868 m_surface->set_keymap(MirInputDeviceId(), "", layout.toStdString(), variant.toStdString(), "");905 auto const &window = static_cast<std::shared_ptr<mir::scene::Surface>>(m_windowInfo.window);
906
907 window->set_keymap(MirInputDeviceId(), "", layout.toStdString(), variant.toStdString(), "");
869}908}
870909
871QCursor MirSurface::cursor() const910QCursor MirSurface::cursor() const
@@ -905,6 +944,52 @@
905 return result;944 return result;
906}945}
907946
947void MirSurface::updateWindowInfo(const WindowInfo &windowInfo)
948{
949 qDebug() << "MirSurface::updateWindowInfo";
950 // Need to compare the new windowInfo instance with the existing one to figure out what changed
951 DirtyStates dirt = DirtyState::Clean;
952
953 if (windowInfo.name != m_windowInfo.name) {
954 dirt &= DirtyState::Name; qDebug("Name changed");
955 }
956 if (windowInfo.type != m_windowInfo.type) {
957 dirt &= DirtyState::Type; qDebug("Type changed");
958 }
959 if (windowInfo.state != m_windowInfo.state) {
960 dirt &= DirtyState::State; qDebug("State changed");
961 }
962 if (windowInfo.restoreRect != m_windowInfo.restoreRect) {
963 dirt &= DirtyState::RestoreRect; qDebug("RestoreRect changed");
964 }
965 if (windowInfo.children != m_windowInfo.children) {
966 dirt &= DirtyState::Children; qDebug("Children changed");
967 }
968 if (windowInfo.minWidth != m_windowInfo.minWidth
969 && windowInfo.minHeight != m_windowInfo.minHeight) {
970 dirt &= DirtyState::MinSize; qDebug("MinSize changed");
971 }
972 if (windowInfo.maxWidth != m_windowInfo.maxWidth
973 && windowInfo.maxHeight != m_windowInfo.maxHeight) {
974 dirt &= DirtyState::MaxSize; qDebug("MaxHeight changed");
975 }
976
977 if (dirt | DirtyState::Clean) {
978 return;
979 }
980 m_windowInfo = windowInfo;
981
982 if (dirt | DirtyState::Name) {
983 Q_EMIT nameChanged(name());
984 }
985 if (dirt | DirtyState::Type) {
986 Q_EMIT typeChanged(type());
987 }
988 if (dirt | DirtyState::State) {
989 Q_EMIT stateChanged(state());
990 }
991}
992
908void MirSurface::setCursor(const QCursor &cursor)993void MirSurface::setCursor(const QCursor &cursor)
909{994{
910 DEBUG_MSG << "(" << qtCursorShapeToStr(cursor.shape()) << ")";995 DEBUG_MSG << "(" << qtCursorShapeToStr(cursor.shape()) << ")";
@@ -915,80 +1000,32 @@
9151000
916int MirSurface::minimumWidth() const1001int MirSurface::minimumWidth() const
917{1002{
918 return m_minimumWidth;1003 return m_windowInfo.minWidth.as_int();
919}1004}
9201005
921int MirSurface::minimumHeight() const1006int MirSurface::minimumHeight() const
922{1007{
923 return m_minimumHeight;1008 return m_windowInfo.minHeight.as_int();
924}1009}
9251010
926int MirSurface::maximumWidth() const1011int MirSurface::maximumWidth() const
927{1012{
928 return m_maximumWidth;1013 return m_windowInfo.maxWidth.as_int();
929}1014}
9301015
931int MirSurface::maximumHeight() const1016int MirSurface::maximumHeight() const
932{1017{
933 return m_maximumHeight;1018 return m_windowInfo.maxHeight.as_int();
934}1019}
9351020
936int MirSurface::widthIncrement() const1021int MirSurface::widthIncrement() const
937{1022{
938 return m_widthIncrement;1023 return 0; //TODO
939}1024}
9401025
941int MirSurface::heightIncrement() const1026int MirSurface::heightIncrement() const
942{1027{
943 return m_heightIncrement;1028 return 0; //TODO
944}
945
946void MirSurface::setMinimumWidth(int value)
947{
948 if (value != m_minimumWidth) {
949 m_minimumWidth = value;
950 Q_EMIT minimumWidthChanged(value);
951 }
952}
953
954void MirSurface::setMinimumHeight(int value)
955{
956 if (value != m_minimumHeight) {
957 m_minimumHeight = value;
958 Q_EMIT minimumHeightChanged(value);
959 }
960}
961
962void MirSurface::setMaximumWidth(int value)
963{
964 if (value != m_maximumWidth) {
965 m_maximumWidth = value;
966 Q_EMIT maximumWidthChanged(value);
967 }
968}
969
970void MirSurface::setMaximumHeight(int value)
971{
972 if (value != m_maximumHeight) {
973 m_maximumHeight = value;
974 Q_EMIT maximumHeightChanged(value);
975 }
976}
977
978void MirSurface::setWidthIncrement(int value)
979{
980 if (value != m_widthIncrement) {
981 m_widthIncrement = value;
982 Q_EMIT widthIncrementChanged(value);
983 }
984}
985
986void MirSurface::setHeightIncrement(int value)
987{
988 if (value != m_heightIncrement) {
989 m_heightIncrement = value;
990 Q_EMIT heightIncrementChanged(value);
991 }
992}1029}
9931030
994bool MirSurface::focused() const1031bool MirSurface::focused() const
@@ -1021,16 +1058,7 @@
10211058
1022 m_closingState = CloseOverdue;1059 m_closingState = CloseOverdue;
10231060
1024 m_session->session()->destroy_surface(m_surface);1061 //m_session->session()->destroy_surface(m_windowInfo); TODO use WindowManagerTools::ask_client_to_close(window)
1025}
1026
1027void MirSurface::setPosition(const QPoint newPosition)
1028{
1029 if (m_position == newPosition) {
1030 return;
1031 }
1032 m_position = newPosition;
1033 Q_EMIT positionChanged(m_position);
1034}1062}
10351063
1036void MirSurface::setCloseTimer(AbstractTimer *timer)1064void MirSurface::setCloseTimer(AbstractTimer *timer)
10371065
=== modified file 'miral-qt/src/modules/Unity/Application/mirsurface.h'
--- miral-qt/src/modules/Unity/Application/mirsurface.h 2016-07-27 12:05:20 +0000
+++ miral-qt/src/modules/Unity/Application/mirsurface.h 2016-08-12 12:04:26 +0000
@@ -31,17 +31,11 @@
3131
32#include "mirbuffersgtexture.h"32#include "mirbuffersgtexture.h"
33#include "session.h"33#include "session.h"
3434#include "windowcontrollerinterface.h"
35// mirserver35#include "windowmodelinterface.h"
36#include "creationhints.h"
37
38// mir36// mir
39#include <mir_toolkit/common.h>37#include <mir_toolkit/common.h>
4038
41namespace mir {
42namespace shell { class Shell; }
43namespace scene {class Surface; }
44}
4539
46class SurfaceObserver;40class SurfaceObserver;
4741
@@ -54,11 +48,9 @@
54 Q_OBJECT48 Q_OBJECT
5549
56public:50public:
57 MirSurface(std::shared_ptr<mir::scene::Surface> surface,51 MirSurface(WindowInfo windowInfo,
58 SessionInterface* session,52 WindowControllerInterface *controller,
59 mir::shell::Shell *shell,53 std::shared_ptr<SurfaceObserver> observer);
60 std::shared_ptr<SurfaceObserver> observer,
61 const CreationHints &);
62 virtual ~MirSurface();54 virtual ~MirSurface();
6355
64 ////56 ////
@@ -70,10 +62,10 @@
7062
71 QSize size() const override;63 QSize size() const override;
72 void resize(int width, int height) override;64 void resize(int width, int height) override;
73 void resize(const QSize &size) override { resize(size.width(), size.height()); }65 Q_INVOKABLE void resize(const QSize &size) override { resize(size.width(), size.height()); }
7466
75 QPoint position() const override;67 QPoint position() const override;
76 void setPosition(const QPoint newPosition) override;68 Q_INVOKABLE void requestPosition(const QPoint newPosition) override;
7769
78 Mir::State state() const override;70 Mir::State state() const override;
79 void setState(Mir::State qmlState) override;71 void setState(Mir::State qmlState) override;
@@ -159,6 +151,9 @@
159151
160 ////152 ////
161 // Own API153 // Own API
154 void setPosition(const QPoint newPosition);
155 void setSize(const QSize newSize);
156 void updateWindowInfo(const WindowInfo &windowInfo);
162157
163 // useful for tests158 // useful for tests
164 void setCloseTimer(AbstractTimer *timer);159 void setCloseTimer(AbstractTimer *timer);
@@ -166,12 +161,6 @@
166public Q_SLOTS:161public Q_SLOTS:
167 void onCompositorSwappedBuffers() override;162 void onCompositorSwappedBuffers() override;
168163
169 void setMinimumWidth(int) override;
170 void setMinimumHeight(int) override;
171 void setMaximumWidth(int) override;
172 void setMaximumHeight(int) override;
173 void setWidthIncrement(int) override;
174 void setHeightIncrement(int) override;
175 void setShellChrome(Mir::ShellChrome shellChrome) override;164 void setShellChrome(Mir::ShellChrome shellChrome) override;
176165
177private Q_SLOTS:166private Q_SLOTS:
@@ -191,9 +180,9 @@
191 void applyKeymap();180 void applyKeymap();
192 void updateActiveFocus();181 void updateActiveFocus();
193182
194 std::shared_ptr<mir::scene::Surface> m_surface;183 WindowInfo m_windowInfo;
195 QPointer<SessionInterface> m_session;184 QPointer<SessionInterface> m_session;
196 mir::shell::Shell *const m_shell;185 WindowControllerInterface *const m_controller;
197 bool m_firstFrameDrawn;186 bool m_firstFrameDrawn;
198187
199 //FIXME - have to save the state as Mir has no getter for it (bug:1357429)188 //FIXME - have to save the state as Mir has no getter for it (bug:1357429)
@@ -226,13 +215,6 @@
226 QCursor m_cursor;215 QCursor m_cursor;
227 Mir::ShellChrome m_shellChrome;216 Mir::ShellChrome m_shellChrome;
228217
229 int m_minimumWidth{0};
230 int m_minimumHeight{0};
231 int m_maximumWidth{0};
232 int m_maximumHeight{0};
233 int m_widthIncrement{0};
234 int m_heightIncrement{0};
235
236 QRect m_inputBounds;218 QRect m_inputBounds;
237219
238 bool m_focused{false};220 bool m_focused{false};
239221
=== modified file 'miral-qt/src/modules/Unity/Application/mirsurfaceinterface.h'
--- miral-qt/src/modules/Unity/Application/mirsurfaceinterface.h 2016-07-27 12:05:20 +0000
+++ miral-qt/src/modules/Unity/Application/mirsurfaceinterface.h 2016-08-12 12:04:26 +0000
@@ -49,7 +49,7 @@
49 virtual ~MirSurfaceInterface() {}49 virtual ~MirSurfaceInterface() {}
5050
51 virtual QPoint position() const = 0;51 virtual QPoint position() const = 0;
52 virtual void setPosition(const QPoint newPosition) = 0;52 virtual void requestPosition(const QPoint newPosition) = 0;
5353
54 virtual void setLive(bool value) = 0;54 virtual void setLive(bool value) = 0;
5555
@@ -118,12 +118,6 @@
118public Q_SLOTS:118public Q_SLOTS:
119 virtual void onCompositorSwappedBuffers() = 0;119 virtual void onCompositorSwappedBuffers() = 0;
120120
121 virtual void setMinimumWidth(int) = 0;
122 virtual void setMinimumHeight(int) = 0;
123 virtual void setMaximumWidth(int) = 0;
124 virtual void setMaximumHeight(int) = 0;
125 virtual void setWidthIncrement(int) = 0;
126 virtual void setHeightIncrement(int) = 0;
127 virtual void setShellChrome(Mir::ShellChrome shellChrome) = 0;121 virtual void setShellChrome(Mir::ShellChrome shellChrome) = 0;
128122
129Q_SIGNALS:123Q_SIGNALS:
130124
=== modified file 'miral-qt/src/modules/Unity/Application/mirsurfacemanager.cpp'
--- miral-qt/src/modules/Unity/Application/mirsurfacemanager.cpp 2016-06-01 22:06:51 +0000
+++ miral-qt/src/modules/Unity/Application/mirsurfacemanager.cpp 2016-08-12 12:04:26 +0000
@@ -97,45 +97,45 @@
9797
98void MirSurfaceManager::onSessionCreatedSurface(const mir::scene::Session *mirSession,98void MirSurfaceManager::onSessionCreatedSurface(const mir::scene::Session *mirSession,
99 const std::shared_ptr<mir::scene::Surface> &surface,99 const std::shared_ptr<mir::scene::Surface> &surface,
100 const std::shared_ptr<SurfaceObserver> &observer,100 const std::shared_ptr<SurfaceObserver> &/*observer*/,
101 qtmir::CreationHints creationHints)101 qtmir::CreationHints creationHints)
102{102{
103 qCDebug(QTMIR_SURFACES) << "MirSurfaceManager::onSessionCreatedSurface - mirSession=" << mirSession103 qCDebug(QTMIR_SURFACES) << "MirSurfaceManager::onSessionCreatedSurface - mirSession=" << mirSession
104 << "surface=" << surface.get() << "surface.name=" << surface->name().c_str()104 << "surface=" << surface.get() << "surface.name=" << surface->name().c_str()
105 << "creationHints=" << creationHints.toString();105 << "creationHints=" << creationHints.toString();
106106
107 SessionInterface* session = m_sessionManager->findSession(mirSession);107// SessionInterface* session = m_sessionManager->findSession(mirSession);
108 auto qmlSurface = new MirSurface(surface, session, m_shell, observer, creationHints);108// auto qmlSurface = new MirSurface(surface, session, m_shell, observer, creationHints);
109 {109// {
110 QMutexLocker lock(&m_mutex);110// QMutexLocker lock(&m_mutex);
111 m_mirSurfaceToQmlSurfaceHash.insert(surface.get(), qmlSurface);111// m_mirSurfaceToQmlSurfaceHash.insert(surface.get(), qmlSurface);
112 }112// }
113113
114 if (session)114// if (session)
115 session->registerSurface(qmlSurface);115// session->registerSurface(qmlSurface);
116116
117 if (qmlSurface->type() == Mir::InputMethodType) {117// if (qmlSurface->type() == Mir::InputMethodType) {
118 m_inputMethodSurface = qmlSurface;118// m_inputMethodSurface = qmlSurface;
119 Q_EMIT inputMethodSurfaceChanged();119// Q_EMIT inputMethodSurfaceChanged();
120 }120// }
121121
122 // Only notify QML of surface creation once it has drawn its first frame.122// // Only notify QML of surface creation once it has drawn its first frame.
123 connect(qmlSurface, &MirSurfaceInterface::firstFrameDrawn, this, [=]() {123// connect(qmlSurface, &MirSurfaceInterface::firstFrameDrawn, this, [=]() {
124 tracepoint(qtmir, firstFrameDrawn);124// tracepoint(qtmir, firstFrameDrawn);
125 Q_EMIT surfaceCreated(qmlSurface);125// Q_EMIT surfaceCreated(qmlSurface);
126 });126// });
127127
128 // clean up after MirSurface is destroyed128// // clean up after MirSurface is destroyed
129 connect(qmlSurface, &QObject::destroyed, this, [&](QObject *obj) {129// connect(qmlSurface, &QObject::destroyed, this, [&](QObject *obj) {
130 auto qmlSurface = static_cast<MirSurfaceInterface*>(obj);130// auto qmlSurface = static_cast<MirSurfaceInterface*>(obj);
131 {131// {
132 QMutexLocker lock(&m_mutex);132// QMutexLocker lock(&m_mutex);
133 m_mirSurfaceToQmlSurfaceHash.remove(m_mirSurfaceToQmlSurfaceHash.key(qmlSurface));133// m_mirSurfaceToQmlSurfaceHash.remove(m_mirSurfaceToQmlSurfaceHash.key(qmlSurface));
134 }134// }
135135
136 tracepoint(qtmir, surfaceDestroyed);136// tracepoint(qtmir, surfaceDestroyed);
137 });137// });
138 tracepoint(qtmir, surfaceCreated);138// tracepoint(qtmir, surfaceCreated);
139}139}
140140
141void MirSurfaceManager::onSessionDestroyingSurface(const mir::scene::Session *session,141void MirSurfaceManager::onSessionDestroyingSurface(const mir::scene::Session *session,
@@ -144,27 +144,27 @@
144 qCDebug(QTMIR_SURFACES) << "MirSurfaceManager::onSessionDestroyingSurface - session=" << session144 qCDebug(QTMIR_SURFACES) << "MirSurfaceManager::onSessionDestroyingSurface - session=" << session
145 << "surface=" << surface.get() << "surface.name=" << surface->name().c_str();145 << "surface=" << surface.get() << "surface.name=" << surface->name().c_str();
146146
147 MirSurfaceInterface* qmlSurface = nullptr;147// MirSurfaceInterface* qmlSurface = nullptr;
148 {148// {
149 QMutexLocker lock(&m_mutex);149// QMutexLocker lock(&m_mutex);
150 auto it = m_mirSurfaceToQmlSurfaceHash.find(surface.get());150// auto it = m_mirSurfaceToQmlSurfaceHash.find(surface.get());
151 if (it != m_mirSurfaceToQmlSurfaceHash.end()) {151// if (it != m_mirSurfaceToQmlSurfaceHash.end()) {
152 qmlSurface = it.value();152// qmlSurface = it.value();
153 m_mirSurfaceToQmlSurfaceHash.erase(it);153// m_mirSurfaceToQmlSurfaceHash.erase(it);
154 } else {154// } else {
155 qCritical() << "MirSurfaceManager::onSessionDestroyingSurface: unable to find MirSurface corresponding"155// qCritical() << "MirSurfaceManager::onSessionDestroyingSurface: unable to find MirSurface corresponding"
156 << "to surface=" << surface.get() << "surface.name=" << surface->name().c_str();156// << "to surface=" << surface.get() << "surface.name=" << surface->name().c_str();
157 return;157// return;
158 }158// }
159 }159// }
160160
161 if (qmlSurface->type() == Mir::InputMethodType) {161// if (qmlSurface->type() == Mir::InputMethodType) {
162 m_inputMethodSurface = nullptr;162// m_inputMethodSurface = nullptr;
163 Q_EMIT inputMethodSurfaceChanged();163// Q_EMIT inputMethodSurfaceChanged();
164 }164// }
165165
166 qmlSurface->setLive(false);166// qmlSurface->setLive(false);
167 Q_EMIT surfaceDestroyed(qmlSurface);167// Q_EMIT surfaceDestroyed(qmlSurface);
168}168}
169169
170MirSurfaceInterface* MirSurfaceManager::inputMethodSurface() const170MirSurfaceInterface* MirSurfaceManager::inputMethodSurface() const
171171
=== modified file 'miral-qt/src/modules/Unity/Application/windowmodel.cpp'
--- miral-qt/src/modules/Unity/Application/windowmodel.cpp 2016-07-27 12:05:20 +0000
+++ miral-qt/src/modules/Unity/Application/windowmodel.cpp 2016-08-12 12:04:26 +0000
@@ -31,8 +31,8 @@
31using namespace qtmir;31using namespace qtmir;
3232
33WindowModel::WindowModel()33WindowModel::WindowModel()
34 : m_focusedWindow(nullptr)
34{35{
35
36 auto nativeInterface = dynamic_cast<NativeInterface*>(QGuiApplication::platformNativeInterface());36 auto nativeInterface = dynamic_cast<NativeInterface*>(QGuiApplication::platformNativeInterface());
3737
38 if (!nativeInterface) {38 if (!nativeInterface) {
@@ -40,10 +40,14 @@
40 }40 }
4141
42 auto windowModel = static_cast<WindowModelInterface*>(nativeInterface->nativeResourceForIntegration("WindowModel"));42 auto windowModel = static_cast<WindowModelInterface*>(nativeInterface->nativeResourceForIntegration("WindowModel"));
43 m_windowController = static_cast<WindowControllerInterface*>(nativeInterface->nativeResourceForIntegration("WindowController"));
4344
44 connect(windowModel, &WindowModelInterface::windowAdded, this, &WindowModel::onWindowAdded);45 connect(windowModel, &WindowModelInterface::windowAdded, this, &WindowModel::onWindowAdded);
45 connect(windowModel, &WindowModelInterface::windowRemoved, this, &WindowModel::onWindowRemoved);46 connect(windowModel, &WindowModelInterface::windowRemoved, this, &WindowModel::onWindowRemoved);
46 connect(windowModel, &WindowModelInterface::windowChanged, this, &WindowModel::onWindowChanged);47 connect(windowModel, &WindowModelInterface::windowMoved, this, &WindowModel::onWindowMoved);
48 connect(windowModel, &WindowModelInterface::windowResized, this, &WindowModel::onWindowResized);
49 connect(windowModel, &WindowModelInterface::windowFocused, this, &WindowModel::onWindowFocused);
50 connect(windowModel, &WindowModelInterface::windowInfoChanged, this, &WindowModel::onWindowInfoChanged);
47}51}
4852
49QHash<int, QByteArray> WindowModel::roleNames() const53QHash<int, QByteArray> WindowModel::roleNames() const
@@ -53,17 +57,18 @@
53 return roleNames;57 return roleNames;
54}58}
5559
56void WindowModel::onWindowAdded(const NumberedWindow window)60void WindowModel::onWindowAdded(const WindowInfo windowInfo, const unsigned int index)
57{61{
58 qDebug() << "Window Added!" << window.index;62 qDebug() << "Window Added!" << index;
59 std::shared_ptr<SurfaceObserver> surfaceObserver = std::make_shared<SurfaceObserver>();63 std::shared_ptr<SurfaceObserver> surfaceObserver = std::make_shared<SurfaceObserver>();
60 const auto &surface = window.windowInfo.surface;64
65 const auto &surface = static_cast<std::shared_ptr<mir::scene::Surface>>(windowInfo.window);
61 SurfaceObserver::registerObserverForSurface(surfaceObserver.get(), surface.get());66 SurfaceObserver::registerObserverForSurface(surfaceObserver.get(), surface.get());
62 surface->add_observer(surfaceObserver);67 surface->add_observer(surfaceObserver);
6368
64 auto mirSurface = new MirSurface(surface, nullptr, nullptr, surfaceObserver, CreationHints());69 auto mirSurface = new MirSurface(windowInfo, m_windowController, surfaceObserver);
65 beginInsertRows(QModelIndex(), window.index, window.index);70 beginInsertRows(QModelIndex(), index, index);
66 m_windowModel.insert(window.index, mirSurface);71 m_windowModel.insert(index, mirSurface);
67 endInsertRows();72 endInsertRows();
68 Q_EMIT countChanged();73 Q_EMIT countChanged();
69}74}
@@ -77,25 +82,34 @@
77 Q_EMIT countChanged();82 Q_EMIT countChanged();
78}83}
7984
80void WindowModel::onWindowChanged(const DirtiedWindow window)85void WindowModel::onWindowMoved(const QPoint topLeft, const unsigned int index)
81{86{
82 qDebug() << "Window Change!" << window.index;87 auto mirSurface = static_cast<MirSurface *>(m_windowModel.value(index));
83 auto mirSurface = m_windowModel.value(window.index);88 mirSurface->setPosition(topLeft);
8489}
85 switch(window.dirtyWindowInfo) {90
86 case WindowInfo::DirtyStates::Size: {91void WindowModel::onWindowResized(const QSize size, const unsigned int index)
87 qDebug() << "size";92{
88 // Do nothing yet, it gets new size from swapped buffer for now93 auto mirSurface = static_cast<MirSurface *>(m_windowModel.value(index));
89 }94 mirSurface->setSize(size);
90 case WindowInfo::DirtyStates::Position:95}
91 qDebug() << "position";96
92 mirSurface->setPosition(window.windowInfo.position);97void WindowModel::onWindowFocused(const unsigned int index)
93 case WindowInfo::DirtyStates::Focus:98{
94 qDebug() << "focus";99 auto mirSurface = static_cast<MirSurface *>(m_windowModel.value(index));
95 mirSurface->setFocused(window.windowInfo.focused);100 if (m_focusedWindow && m_focusedWindow != mirSurface) {
96 }101 m_focusedWindow->setFocused(false);
97102 }
98 QModelIndex row = index(window.index);103 mirSurface->setFocused(true);
104 m_focusedWindow = mirSurface;
105}
106
107void WindowModel::onWindowInfoChanged(const WindowInfo windowInfo, const unsigned int pos)
108{
109 auto mirSurface = static_cast<MirSurface *>(m_windowModel.value(pos));
110 mirSurface->updateWindowInfo(windowInfo);
111
112 QModelIndex row = index(pos);
99 Q_EMIT dataChanged(row, row, QVector<int>() << SurfaceRole);113 Q_EMIT dataChanged(row, row, QVector<int>() << SurfaceRole);
100}114}
101115
102116
=== modified file 'miral-qt/src/modules/Unity/Application/windowmodel.h'
--- miral-qt/src/modules/Unity/Application/windowmodel.h 2016-07-27 11:48:55 +0000
+++ miral-qt/src/modules/Unity/Application/windowmodel.h 2016-08-12 12:04:26 +0000
@@ -24,6 +24,8 @@
2424
25namespace qtmir {25namespace qtmir {
2626
27class WindowControllerInterface;
28
27class WindowModel : public QAbstractListModel29class WindowModel : public QAbstractListModel
28{30{
29 Q_OBJECT31 Q_OBJECT
@@ -49,12 +51,17 @@
49 void countChanged();51 void countChanged();
5052
51private Q_SLOTS:53private Q_SLOTS:
52 void onWindowAdded(const NumberedWindow);54 void onWindowAdded(const WindowInfo windowInfo, const unsigned int index);
53 void onWindowRemoved(const unsigned int index);55 void onWindowRemoved(const unsigned int index);
54 void onWindowChanged(const DirtiedWindow);56 void onWindowMoved(const QPoint topLeft, const unsigned int index);
57 void onWindowResized(const QSize size, const unsigned int index);
58 void onWindowFocused(const unsigned int index);
59 void onWindowInfoChanged(const WindowInfo windowInfo, const unsigned int index);
5560
56private:61private:
57 QVector<MirSurfaceInterface *> m_windowModel;62 QVector<MirSurfaceInterface *> m_windowModel;
63 WindowControllerInterface *m_windowController;
64 MirSurfaceInterface* m_focusedWindow;
58};65};
5966
60} // namespace qtmir67} // namespace qtmir
6168
=== modified file 'miral-qt/src/platforms/mirserver/CMakeLists.txt'
--- miral-qt/src/platforms/mirserver/CMakeLists.txt 2016-07-28 13:37:17 +0000
+++ miral-qt/src/platforms/mirserver/CMakeLists.txt 2016-08-12 12:04:26 +0000
@@ -79,12 +79,14 @@
79 ubuntutheme.cpp79 ubuntutheme.cpp
80 clipboard.cpp80 clipboard.cpp
81 creationhints.cpp81 creationhints.cpp
82 windowcontroller.cpp
82 windowmanagementpolicy.cpp83 windowmanagementpolicy.cpp
83 windowmodel.cpp84 windowmodel.cpp
84 tracepoints.c85 tracepoints.c
85# We need to run moc on these headers86# We need to run moc on these headers
86 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h87 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
87 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirMousePointerInterface.h88 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirMousePointerInterface.h
89 ${MIRAL_QT_SOURCE_DIR}/src/common/windowcontrollerinterface.h
88 ${MIRAL_QT_SOURCE_DIR}/src/common/windowmodelinterface.h90 ${MIRAL_QT_SOURCE_DIR}/src/common/windowmodelinterface.h
89 )91 )
9092
9193
=== modified file 'miral-qt/src/platforms/mirserver/mirserver.cpp'
--- miral-qt/src/platforms/mirserver/mirserver.cpp 2016-07-28 13:37:17 +0000
+++ miral-qt/src/platforms/mirserver/mirserver.cpp 2016-08-12 12:04:26 +0000
@@ -192,7 +192,7 @@
192192
193UsingQtMirWindowManager::UsingQtMirWindowManager(const QSharedPointer<ScreensModel> &model)193UsingQtMirWindowManager::UsingQtMirWindowManager(const QSharedPointer<ScreensModel> &model)
194 : m_screensModel(model)194 : m_screensModel(model)
195 , m_policy(miral::set_window_managment_policy<WindowManagementPolicy>(m_windowModel, m_screensModel))195 , m_policy(miral::set_window_managment_policy<WindowManagementPolicy>(m_windowModel, m_windowController, m_screensModel))
196{196{
197}197}
198198
@@ -206,10 +206,9 @@
206 return &m_windowModel;206 return &m_windowModel;
207}207}
208208
209mir::shell::Shell *MirServer::shell()209qtmir::WindowControllerInterface *UsingQtMirWindowManager::windowController()
210{210{
211 std::weak_ptr<mir::shell::Shell> m_shell = the_shell();211 return &m_windowController;
212 return m_shell.lock().get();
213}212}
214213
215QSharedPointer<ScreensModel> MirServer::screensModel() const214QSharedPointer<ScreensModel> MirServer::screensModel() const
216215
=== modified file 'miral-qt/src/platforms/mirserver/mirserver.h'
--- miral-qt/src/platforms/mirserver/mirserver.h 2016-07-28 13:37:17 +0000
+++ miral-qt/src/platforms/mirserver/mirserver.h 2016-08-12 12:04:26 +0000
@@ -22,6 +22,7 @@
22#include <mir/server.h>22#include <mir/server.h>
23#include "miral/set_window_managment_policy.h"23#include "miral/set_window_managment_policy.h"
24#include "windowmodel.h"24#include "windowmodel.h"
25#include "windowcontroller.h"
2526
26class QtEventFeeder;27class QtEventFeeder;
27class MirDisplayConfigurationPolicy;28class MirDisplayConfigurationPolicy;
@@ -70,10 +71,12 @@
70 UsingQtMirWindowManager(const QSharedPointer<ScreensModel> &model);71 UsingQtMirWindowManager(const QSharedPointer<ScreensModel> &model);
71 void operator()(mir::Server& server);72 void operator()(mir::Server& server);
72 qtmir::WindowModelInterface *windowModel();73 qtmir::WindowModelInterface *windowModel();
74 qtmir::WindowControllerInterface *windowController();
7375
74private:76private:
75 const QSharedPointer<ScreensModel> &m_screensModel;77 const QSharedPointer<ScreensModel> &m_screensModel;
76 miral::SetWindowManagmentPolicy m_policy;78 miral::SetWindowManagmentPolicy m_policy;
79 qtmir::WindowController m_windowController;
77 qtmir::WindowModel m_windowModel;80 qtmir::WindowModel m_windowModel;
78};81};
7982
@@ -92,7 +95,6 @@
9295
93 Q_PROPERTY(SessionAuthorizer* sessionAuthorizer READ sessionAuthorizer CONSTANT)96 Q_PROPERTY(SessionAuthorizer* sessionAuthorizer READ sessionAuthorizer CONSTANT)
94 Q_PROPERTY(SessionListener* sessionListener READ sessionListener CONSTANT)97 Q_PROPERTY(SessionListener* sessionListener READ sessionListener CONSTANT)
95 Q_PROPERTY(mir::shell::Shell* shell READ shell CONSTANT)
96 Q_PROPERTY(PromptSessionListener* promptSessionListener READ promptSessionListener CONSTANT)98 Q_PROPERTY(PromptSessionListener* promptSessionListener READ promptSessionListener CONSTANT)
9799
98public:100public:
@@ -115,7 +117,7 @@
115 using UsingQtMirSessionListener::sessionListener;117 using UsingQtMirSessionListener::sessionListener;
116 using UsingQtMirPromptSessionListener::promptSessionListener;118 using UsingQtMirPromptSessionListener::promptSessionListener;
117 using UsingQtMirWindowManager::windowModel;119 using UsingQtMirWindowManager::windowModel;
118 mir::shell::Shell *shell();120 using UsingQtMirWindowManager::windowController;
119121
120 QSharedPointer<ScreensModel> screensModel() const;122 QSharedPointer<ScreensModel> screensModel() const;
121123
122124
=== modified file 'miral-qt/src/platforms/mirserver/qmirserver.cpp'
--- miral-qt/src/platforms/mirserver/qmirserver.cpp 2016-07-28 13:37:17 +0000
+++ miral-qt/src/platforms/mirserver/qmirserver.cpp 2016-08-12 12:04:26 +0000
@@ -113,12 +113,12 @@
113 if (d->server) {113 if (d->server) {
114 if (resource == "SessionAuthorizer")114 if (resource == "SessionAuthorizer")
115 result = d->server->sessionAuthorizer();115 result = d->server->sessionAuthorizer();
116 else if (resource == "Shell")
117 result = d->server->shell();
118 else if (resource == "SessionListener")116 else if (resource == "SessionListener")
119 result = d->server->sessionListener();117 result = d->server->sessionListener();
120 else if (resource == "PromptSessionListener")118 else if (resource == "PromptSessionListener")
121 result = d->server->promptSessionListener();119 result = d->server->promptSessionListener();
120 else if (resource == "WindowController")
121 result = d->server->windowController();
122 else if (resource == "WindowModel")122 else if (resource == "WindowModel")
123 result = d->server->windowModel();123 result = d->server->windowModel();
124 else if (resource == "ScreensController")124 else if (resource == "ScreensController")
125125
=== added file 'miral-qt/src/platforms/mirserver/windowcontroller.cpp'
--- miral-qt/src/platforms/mirserver/windowcontroller.cpp 1970-01-01 00:00:00 +0000
+++ miral-qt/src/platforms/mirserver/windowcontroller.cpp 2016-08-12 12:04:26 +0000
@@ -0,0 +1,85 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "windowcontroller.h"
18
19#include "windowmanagementpolicy.h"
20#include "mirqtconversion.h"
21
22using namespace qtmir;
23
24
25WindowController::WindowController()
26 : m_policy(nullptr)
27{
28}
29
30void WindowController::focus(const miral::Window &window)
31{
32 if (m_policy) {
33 m_policy->focus(window);
34 }
35}
36
37void WindowController::resize(const miral::Window &window, const QSize &size)
38{
39 if (m_policy) {
40 m_policy->resize(window, toMirSize(size));
41 }
42}
43
44void WindowController::move(const miral::Window &window, const QPoint &topLeft)
45{
46 if (m_policy) {
47 m_policy->move(window, toMirPoint(topLeft));
48 }
49}
50
51void WindowController::setActiveFocus(const miral::Window &/*window*/, const bool /*activeFocus*/)
52{
53
54}
55
56void WindowController::setState(const miral::Window &/*window*/, const MirSurfaceState /*state*/)
57{
58
59}
60
61void WindowController::deliverKeyboardEvent(const miral::Window &window, const MirKeyboardEvent *event)
62{
63 if (m_policy) {
64 m_policy->deliver_keyboard_event(event, window);
65 }
66}
67
68void WindowController::deliverTouchEvent(const miral::Window &window, const MirTouchEvent *event)
69{
70 if (m_policy) {
71 m_policy->deliver_touch_event(event, window);
72 }
73}
74
75void WindowController::deliverPointerEvent(const miral::Window &window, const MirPointerEvent *event)
76{
77 if (m_policy) {
78 m_policy->deliver_pointer_event(event, window);
79 }
80}
81
82void WindowController::setPolicy(WindowManagementPolicy * const policy)
83{
84 m_policy = policy;
85}
086
=== added file 'miral-qt/src/platforms/mirserver/windowcontroller.h'
--- miral-qt/src/platforms/mirserver/windowcontroller.h 1970-01-01 00:00:00 +0000
+++ miral-qt/src/platforms/mirserver/windowcontroller.h 2016-08-12 12:04:26 +0000
@@ -0,0 +1,51 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef WINDOWCONTROLLER_H
18#define WINDOWCONTROLLER_H
19
20#include "windowcontrollerinterface.h"
21
22class WindowManagementPolicy;
23
24namespace qtmir {
25
26class WindowController : public WindowControllerInterface
27{
28public:
29 WindowController();
30 virtual ~WindowController() = default;
31
32 void focus (const miral::Window &window) override;
33 void resize(const miral::Window &window, const QSize &size) override;
34 void move (const miral::Window &window, const QPoint &topLeft) override;
35
36 void setActiveFocus(const miral::Window &window, const bool activeFocus) override;
37 void setState(const miral::Window &window, const MirSurfaceState state) override;
38
39 void deliverKeyboardEvent(const miral::Window &window, const MirKeyboardEvent *event) override;
40 void deliverTouchEvent (const miral::Window &window, const MirTouchEvent *event) override;
41 void deliverPointerEvent (const miral::Window &window, const MirPointerEvent *event) override;
42
43 void setPolicy(WindowManagementPolicy *policy);
44
45protected:
46 WindowManagementPolicy *m_policy;
47};
48
49} // namespace qtmir
50
51#endif // WINDOWCONTROLLER_H
052
=== modified file 'miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp'
--- miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp 2016-08-10 11:48:02 +0000
+++ miral-qt/src/platforms/mirserver/windowmanagementpolicy.cpp 2016-08-12 12:04:26 +0000
@@ -26,12 +26,14 @@
2626
27WindowManagementPolicy::WindowManagementPolicy(const miral::WindowManagerTools &tools,27WindowManagementPolicy::WindowManagementPolicy(const miral::WindowManagerTools &tools,
28 qtmir::WindowModel &windowModel,28 qtmir::WindowModel &windowModel,
29 qtmir::WindowController &windowController,
29 const QSharedPointer<ScreensModel> screensModel)30 const QSharedPointer<ScreensModel> screensModel)
30 : CanonicalWindowManagerPolicy(tools)31 : CanonicalWindowManagerPolicy(tools)
31 , m_tools(tools)32 , m_tools(tools)
32 , m_windowModel(windowModel)33 , m_windowModel(windowModel)
33 , m_eventFeeder(new QtEventFeeder(screensModel))34 , m_eventFeeder(new QtEventFeeder(screensModel))
34{35{
36 windowController.setPolicy(this);
35}37}
3638
37/* Following are hooks to allow custom policy be imposed */39/* Following are hooks to allow custom policy be imposed */
@@ -46,7 +48,7 @@
4648
47void WindowManagementPolicy::handle_window_ready(miral::WindowInfo &windowInfo)49void WindowManagementPolicy::handle_window_ready(miral::WindowInfo &windowInfo)
48{50{
49 qDebug("Window ready");51 qDebug("Window Ready");
50 m_tools.select_active_window(windowInfo.window());52 m_tools.select_active_window(windowInfo.window());
51}53}
5254
@@ -85,6 +87,7 @@
8587
86void WindowManagementPolicy::advise_new_window(const miral::WindowInfo &windowInfo)88void WindowManagementPolicy::advise_new_window(const miral::WindowInfo &windowInfo)
87{89{
90 // TODO: attach surface observer here
88 m_windowModel.addWindow(windowInfo);91 m_windowModel.addWindow(windowInfo);
89}92}
9093
@@ -115,13 +118,13 @@
115118
116void WindowManagementPolicy::advise_move_to(const miral::WindowInfo &windowInfo, Point topLeft)119void WindowManagementPolicy::advise_move_to(const miral::WindowInfo &windowInfo, Point topLeft)
117{120{
118 qDebug("Window move");121 qDebug("Window Moved to (%d, %d)", topLeft.x.as_int(), topLeft.y.as_int());
119 m_windowModel.moveWindow(windowInfo, topLeft);122 m_windowModel.moveWindow(windowInfo, topLeft);
120}123}
121124
122void WindowManagementPolicy::advise_resize(const miral::WindowInfo &windowInfo, const Size &newSize)125void WindowManagementPolicy::advise_resize(const miral::WindowInfo &windowInfo, const Size &newSize)
123{126{
124 qDebug("Window Resize");127 qDebug("Window Resized to %dx%d", newSize.width.as_int(), newSize.height.as_int());
125 m_windowModel.resizeWindow(windowInfo, newSize);128 m_windowModel.resizeWindow(windowInfo, newSize);
126}129}
127130
@@ -147,35 +150,60 @@
147150
148/* Following methods all called from the Qt GUI thread to deliver events to clients */151/* Following methods all called from the Qt GUI thread to deliver events to clients */
149void WindowManagementPolicy::deliver_keyboard_event(const MirKeyboardEvent *event,152void WindowManagementPolicy::deliver_keyboard_event(const MirKeyboardEvent *event,
150 const std::shared_ptr<mir::scene::Surface> &surface)153 const miral::Window &window)
151{154{
152 m_tools.invoke_under_lock([&surface, this]() {155 m_tools.invoke_under_lock([&window, this]() {
153 auto windowInfo = m_tools.info_for(surface);156 m_tools.select_active_window(window);
154 m_tools.select_active_window(windowInfo.window());
155 });157 });
156 auto e = reinterpret_cast<MirEvent const*>(event); // naughty158 auto e = reinterpret_cast<MirEvent const*>(event); // naughty
157 surface->consume(e);159
160 if (auto surface = std::weak_ptr<mir::scene::Surface>(window).lock()) {
161 surface->consume(e);
162 }
158}163}
159164
160void WindowManagementPolicy::deliver_touch_event(const MirTouchEvent *event,165void WindowManagementPolicy::deliver_touch_event(const MirTouchEvent *event,
161 const std::shared_ptr<mir::scene::Surface> &surface)166 const miral::Window &window)
162{167{
163 m_tools.invoke_under_lock([&surface, this]() {168 m_tools.invoke_under_lock([&window, this]() {
164 auto windowInfo = m_tools.info_for(surface);169 m_tools.select_active_window(window);
165 m_tools.select_active_window(windowInfo.window());
166 });170 });
167 auto e = reinterpret_cast<MirEvent const*>(event); // naughty171 auto e = reinterpret_cast<MirEvent const*>(event); // naughty
168 surface->consume(e);172
173 if (auto surface = std::weak_ptr<mir::scene::Surface>(window).lock()) {
174 surface->consume(e);
175 }
169}176}
170177
171void WindowManagementPolicy::deliver_pointer_event(const MirPointerEvent *event,178void WindowManagementPolicy::deliver_pointer_event(const MirPointerEvent *event,
172 const std::shared_ptr<mir::scene::Surface> &surface)179 const miral::Window &window)
173{180{
174 m_tools.invoke_under_lock([&surface, this]() {181 m_tools.invoke_under_lock([&window, this]() {
175 auto windowInfo = m_tools.info_for(surface);182 m_tools.select_active_window(window);
176 m_tools.select_active_window(windowInfo.window());
177 });183 });
178 auto e = reinterpret_cast<MirEvent const*>(event); // naughty184 auto e = reinterpret_cast<MirEvent const*>(event); // naughty
179 surface->consume(e);185
180}186 if (auto surface = std::weak_ptr<mir::scene::Surface>(window).lock()) {
181187 surface->consume(e);
188 }
189}
190
191/* Methods to allow Shell to request changes to the window stack */
192void WindowManagementPolicy::focus(const miral::Window &window)
193{
194 m_tools.select_active_window(window);
195}
196
197void WindowManagementPolicy::resize(const miral::Window &window, const Size size)
198{
199 miral::WindowSpecification modifications;
200 modifications.size() = size;
201 m_tools.modify_window(m_tools.info_for(window), modifications);
202}
203
204void WindowManagementPolicy::move(const miral::Window &window, const Point topLeft)
205{
206 miral::WindowSpecification modifications;
207 modifications.top_left() = topLeft;
208 m_tools.modify_window(m_tools.info_for(window), modifications);
209}
182210
=== modified file 'miral-qt/src/platforms/mirserver/windowmanagementpolicy.h'
--- miral-qt/src/platforms/mirserver/windowmanagementpolicy.h 2016-08-10 11:48:02 +0000
+++ miral-qt/src/platforms/mirserver/windowmanagementpolicy.h 2016-08-12 12:04:26 +0000
@@ -20,9 +20,9 @@
20#include "miral/canonical_window_manager.h"20#include "miral/canonical_window_manager.h"
2121
22#include "qteventfeeder.h"22#include "qteventfeeder.h"
23#include "windowcontroller.h"
23#include "windowmodel.h"24#include "windowmodel.h"
2425
25#include <QObject>
26#include <QScopedPointer>26#include <QScopedPointer>
27#include <QSize>27#include <QSize>
2828
@@ -30,11 +30,12 @@
3030
31class ScreensModel;31class ScreensModel;
3232
33class WindowManagementPolicy : public QObject, public miral::CanonicalWindowManagerPolicy33class WindowManagementPolicy : public miral::CanonicalWindowManagerPolicy
34{34{
35public:35public:
36 WindowManagementPolicy(const miral::WindowManagerTools &tools,36 WindowManagementPolicy(const miral::WindowManagerTools &tools,
37 qtmir::WindowModel &windowModel,37 qtmir::WindowModel &windowModel,
38 qtmir::WindowController &windowController,
38 const QSharedPointer<ScreensModel> screensModel);39 const QSharedPointer<ScreensModel> screensModel);
3940
40 // From WindowManagementPolicy41 // From WindowManagementPolicy
@@ -65,12 +66,16 @@
65 void advise_move_to(const miral::WindowInfo &windowInfo, Point topLeft) override;66 void advise_move_to(const miral::WindowInfo &windowInfo, Point topLeft) override;
66 void advise_resize(const miral::WindowInfo &info, const Size &newSize) override;67 void advise_resize(const miral::WindowInfo &info, const Size &newSize) override;
67 void advise_delete_window(const miral::WindowInfo &windowInfo) override;68 void advise_delete_window(const miral::WindowInfo &windowInfo) override;
68 void advise_raise(std::vector<miral::Window> const& windows) override;69 void advise_raise(const std::vector<miral::Window> &windows) override;
6970
70 // Exposing some tools71 // Methods for consumption by WindowControllerInterface
71 void deliver_keyboard_event(const MirKeyboardEvent *event, const std::shared_ptr<mir::scene::Surface> &surface);72 void deliver_keyboard_event(const MirKeyboardEvent *event, const miral::Window &window);
72 void deliver_touch_event(const MirTouchEvent *event, const std::shared_ptr<mir::scene::Surface> &surface);73 void deliver_touch_event (const MirTouchEvent *event, const miral::Window &window);
73 void deliver_pointer_event(const MirPointerEvent *event, const std::shared_ptr<mir::scene::Surface> &surface);74 void deliver_pointer_event (const MirPointerEvent *event, const miral::Window &window);
75
76 void focus (const miral::Window &window);
77 void resize(const miral::Window &window, const Size size);
78 void move (const miral::Window &window, const Point topLeft);
7479
75Q_SIGNALS:80Q_SIGNALS:
7681
7782
=== modified file 'miral-qt/src/platforms/mirserver/windowmodel.cpp'
--- miral-qt/src/platforms/mirserver/windowmodel.cpp 2016-08-05 09:54:43 +0000
+++ miral-qt/src/platforms/mirserver/windowmodel.cpp 2016-08-12 12:04:26 +0000
@@ -32,8 +32,7 @@
32WindowModel::WindowModel()32WindowModel::WindowModel()
33{33{
34 qDebug("WindowModel::WindowModel");34 qDebug("WindowModel::WindowModel");
35 qRegisterMetaType<qtmir::NumberedWindow>();35 qRegisterMetaType<qtmir::WindowInfo>();
36 qRegisterMetaType<qtmir::DirtiedWindow>();
37}36}
3837
39WindowModel::~WindowModel()38WindowModel::~WindowModel()
@@ -47,12 +46,7 @@
47 auto stackPosition = static_cast<unsigned int>(m_windowStack.count());46 auto stackPosition = static_cast<unsigned int>(m_windowStack.count());
48 m_windowStack.push_back(windowInfo.window()); // ASSUMPTION: Mir should tell us where in stack47 m_windowStack.push_back(windowInfo.window()); // ASSUMPTION: Mir should tell us where in stack
4948
50 QSize size = toQSize(windowInfo.window().size());49 Q_EMIT windowAdded(windowInfo, stackPosition);
51 QPoint position = toQPoint(windowInfo.window().top_left());
52
53 WindowInfo info{ size, position, false, windowInfo.window() };
54 NumberedWindow window{ stackPosition, info };
55 Q_EMIT windowAdded(window);
56}50}
5751
58void WindowModel::removeWindow(const miral::WindowInfo &windowInfo)52void WindowModel::removeWindow(const miral::WindowInfo &windowInfo)
@@ -76,13 +70,11 @@
76 return;70 return;
77 }71 }
78 auto upos = static_cast<unsigned int>(pos);72 auto upos = static_cast<unsigned int>(pos);
79 m_focusedWindowIndex = upos;
80 QSize size = toQSize(windowInfo.window().size());
81 QPoint position = toQPoint(windowInfo.window().top_left());
8273
83 WindowInfo info{ size, position, focus, windowInfo.window() };74 if (focus && m_focusedWindowIndex != upos) {
84 DirtiedWindow window{ upos, info, WindowInfo::DirtyStates::Focus};75 m_focusedWindowIndex = upos;
85 Q_EMIT windowChanged(window);76 Q_EMIT windowFocused(upos);
77 }
86}78}
8779
88void WindowModel::moveWindow(const miral::WindowInfo &windowInfo, mir::geometry::Point topLeft)80void WindowModel::moveWindow(const miral::WindowInfo &windowInfo, mir::geometry::Point topLeft)
@@ -93,13 +85,9 @@
93 return;85 return;
94 }86 }
95 auto upos = static_cast<unsigned int>(pos);87 auto upos = static_cast<unsigned int>(pos);
96 const bool focused = (m_focusedWindowIndex == upos);
97 QSize size = toQSize(windowInfo.window().size());
98 QPoint position = toQPoint(topLeft);
9988
100 WindowInfo info{ size, position, focused, windowInfo.window() };89 // Note: windowInfo.window() is in the state before the move
101 DirtiedWindow window{ upos, info, WindowInfo::DirtyStates::Position};90 Q_EMIT windowMoved(toQPoint(topLeft), upos);
102 Q_EMIT windowChanged(window);
103}91}
10492
105void WindowModel::resizeWindow(const miral::WindowInfo &windowInfo, mir::geometry::Size newSize)93void WindowModel::resizeWindow(const miral::WindowInfo &windowInfo, mir::geometry::Size newSize)
@@ -110,13 +98,9 @@
110 return;98 return;
111 }99 }
112 auto upos = static_cast<unsigned int>(pos);100 auto upos = static_cast<unsigned int>(pos);
113 const bool focused = (m_focusedWindowIndex == upos);
114 QSize size = toQSize(newSize);
115 QPoint position = toQPoint(windowInfo.window().top_left());
116101
117 WindowInfo info{ size, position, focused, windowInfo.window() };102 // Note: windowInfo.window() is in the state before the resize
118 DirtiedWindow window{ upos, info, WindowInfo::DirtyStates::Size};103 Q_EMIT windowResized(toQSize(newSize), upos);
119 Q_EMIT windowChanged(window);
120}104}
121105
122void WindowModel::raiseWindows(const std::vector<miral::Window> &/*windows*/)106void WindowModel::raiseWindows(const std::vector<miral::Window> &/*windows*/)
123107
=== modified file 'miral-qt/tests/framework/fake_mirsurface.cpp'
--- miral-qt/tests/framework/fake_mirsurface.cpp 2016-07-27 12:05:20 +0000
+++ miral-qt/tests/framework/fake_mirsurface.cpp 2016-08-12 12:04:26 +0000
@@ -58,11 +58,11 @@
5858
59QPoint FakeMirSurface::position() const { return m_position; }59QPoint FakeMirSurface::position() const { return m_position; }
6060
61void FakeMirSurface::setPosition(const QPoint position)61void FakeMirSurface::requestPosition(const QPoint newPosition)
62{62{
63 if (m_position != position) {63 if (m_position != newPosition) {
64 m_position = position;64 m_position = newPosition;
65 Q_EMIT positionChanged(position);65 Q_EMIT positionChanged(newPosition);
66 }66 }
67}67}
6868
@@ -192,6 +192,8 @@
192192
193void FakeMirSurface::onCompositorSwappedBuffers() {}193void FakeMirSurface::onCompositorSwappedBuffers() {}
194194
195void FakeMirSurface::setShellChrome(Mir::ShellChrome /*shellChrome*/) {}
196
195void FakeMirSurface::drawFirstFrame()197void FakeMirSurface::drawFirstFrame()
196{198{
197 if (!m_isFirstFrameDrawn) {199 if (!m_isFirstFrameDrawn) {
198200
=== modified file 'miral-qt/tests/framework/fake_mirsurface.h'
--- miral-qt/tests/framework/fake_mirsurface.h 2016-07-27 12:05:20 +0000
+++ miral-qt/tests/framework/fake_mirsurface.h 2016-08-12 12:04:26 +0000
@@ -54,8 +54,6 @@
54 Mir::Type type() const override;54 Mir::Type type() const override;
55 QString name() const override;55 QString name() const override;
56 QSize size() const override;56 QSize size() const override;
57 QPoint position() const override;
58 void setPosition(const QPoint position) override;
59 void resize(int width, int height) override;57 void resize(int width, int height) override;
60 void resize(const QSize &size) override;58 void resize(const QSize &size) override;
61 Mir::State state() const override;59 Mir::State state() const override;
@@ -93,6 +91,9 @@
93 ////91 ////
94 // qtmir.MirSurfaceInterface92 // qtmir.MirSurfaceInterface
9593
94 QPoint position() const override;
95 void requestPosition(const QPoint newPosition) override;
96
96 bool isFirstFrameDrawn() const override;97 bool isFirstFrameDrawn() const override;
97 void stopFrameDropper() override;98 void stopFrameDropper() override;
98 void startFrameDropper() override;99 void startFrameDropper() override;
@@ -112,7 +113,7 @@
112113
113 void setFocused(bool focus) override;114 void setFocused(bool focus) override;
114115
115 void setViewActiveFocus(qintptr, bool) override {};116 void setViewActiveFocus(qintptr, bool) override {}
116 bool activeFocus() const override { return false; }117 bool activeFocus() const override { return false; }
117118
118 void mousePressEvent(QMouseEvent *) override;119 void mousePressEvent(QMouseEvent *) override;
@@ -141,13 +142,7 @@
141public Q_SLOTS:142public Q_SLOTS:
142 void onCompositorSwappedBuffers() override;143 void onCompositorSwappedBuffers() override;
143144
144 void setMinimumWidth(int) {}145 void setShellChrome(Mir::ShellChrome shellChrome) override;
145 void setMinimumHeight(int) {}
146 void setMaximumWidth(int) {}
147 void setMaximumHeight(int) {}
148 void setWidthIncrement(int) {}
149 void setHeightIncrement(int) {}
150 void setShellChrome(Mir::ShellChrome) override {}
151146
152 ////147 ////
153 // Test API from now on148 // Test API from now on
154149
=== modified file 'miral-qt/tests/modules/SurfaceManager/CMakeLists.txt'
--- miral-qt/tests/modules/SurfaceManager/CMakeLists.txt 2016-06-07 20:32:04 +0000
+++ miral-qt/tests/modules/SurfaceManager/CMakeLists.txt 2016-08-12 12:04:26 +0000
@@ -1,14 +1,16 @@
1set(1set(
2 MIR_SURFACE_MANAGER_TEST_SOURCES2 MIR_SURFACE_MANAGER_TEST_SOURCES
3 mirsurfaceitem_test.cpp3# mirsurfaceitem_test.cpp #FIXME - reinstate these tests when functionality there
4 mirsurface_test.cpp4 mirsurface_test.cpp
5 ${MIRAL_QT_SOURCE_DIR}/src/common/debughelpers.cpp5 ${MIRAL_QT_SOURCE_DIR}/src/common/debughelpers.cpp
6)6)
77
8include_directories(8include_directories(
9 ${MIRAL_QT_SOURCE_DIR}/src/common
9 ${MIRAL_QT_SOURCE_DIR}/src/modules10 ${MIRAL_QT_SOURCE_DIR}/src/modules
10 ${MIRAL_QT_SOURCE_DIR}/src/platforms/mirserver11 ${MIRAL_QT_SOURCE_DIR}/src/platforms/mirserver
11 ${MIRAL_QT_SOURCE_DIR}/tests/framework12 ${MIRAL_QT_SOURCE_DIR}/tests/framework
13 ${CMAKE_SOURCE_DIR}/include/miral #FIXME
12 ${MIRSERVER_INCLUDE_DIRS}14 ${MIRSERVER_INCLUDE_DIRS}
13 ${Qt5Quick_PRIVATE_INCLUDE_DIRS}15 ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
14)16)
1517
=== modified file 'miral-qt/tests/modules/SurfaceManager/mirsurface_test.cpp'
--- miral-qt/tests/modules/SurfaceManager/mirsurface_test.cpp 2016-06-07 20:32:04 +0000
+++ miral-qt/tests/modules/SurfaceManager/mirsurface_test.cpp 2016-08-12 12:04:26 +0000
@@ -24,22 +24,24 @@
24#include <QTest>24#include <QTest>
25#include <QSignalSpy>25#include <QSignalSpy>
2626
27// src/common
28#include "windowmodelinterface.h"
29
27// the test subject30// the test subject
28#include <Unity/Application/mirsurface.h>31#include <Unity/Application/mirsurface.h>
2932
30#include <Unity/Application/timer.h>33#include <Unity/Application/timer.h>
3134
32// tests/framework35// tests/framework
33#include <fake_session.h>
34#include <mock_mir_session.h>36#include <mock_mir_session.h>
35#include <mock_shell.h>
36#include <mock_surface.h>37#include <mock_surface.h>
3738
38// tests/modules/common39// tests/modules/common
39#include <surfaceobserver.h>40#include <surfaceobserver.h>
4041
41// mirserver42// miral
42#include <creationhints.h>43#include "window.h"
44#include "window_info.h"
4345
44using namespace qtmir;46using namespace qtmir;
4547
@@ -54,8 +56,6 @@
54 // We don't want the logging spam cluttering the test results56 // We don't want the logging spam cluttering the test results
55 QLoggingCategory::setFilterRules(QStringLiteral("qtmir.surfaces=false"));57 QLoggingCategory::setFilterRules(QStringLiteral("qtmir.surfaces=false"));
56 }58 }
57
58 NiceMock<mir::shell::MockShell> m_mockShell;
59};59};
6060
61TEST_F(MirSurfaceTest, UpdateTextureBeforeDraw)61TEST_F(MirSurfaceTest, UpdateTextureBeforeDraw)
@@ -64,22 +64,23 @@
64 char* argv[0];64 char* argv[0];
65 QCoreApplication qtApp(argc, argv); // app for deleteLater event65 QCoreApplication qtApp(argc, argv); // app for deleteLater event
6666
67 auto fakeSession = new FakeSession();67 auto const fakeSession = std::make_shared<ms::MockSession>();
68 auto mockSurface = std::make_shared<NiceMock<ms::MockSurface>>();68 auto mockSurface = std::make_shared<NiceMock<ms::MockSurface>>();
69 miral::Window mockWindow(fakeSession, mockSurface);
70 miral::WindowInfo mockWindowInfo(mockWindow, {});
71 QScopedPointer<WindowInfo> windowInfo(new WindowInfo(mockWindowInfo));
72
69 auto surfaceObserver = std::make_shared<SurfaceObserver>();73 auto surfaceObserver = std::make_shared<SurfaceObserver>();
7074
71 EXPECT_CALL(*mockSurface.get(),buffers_ready_for_compositor(_))75 EXPECT_CALL(*mockSurface.get(),buffers_ready_for_compositor(_))
72 .WillRepeatedly(Return(1));76 .WillRepeatedly(Return(1));
7377
74 MirSurface *surface = new MirSurface(mockSurface, fakeSession, &m_mockShell, surfaceObserver, CreationHints());78 MirSurface surface(mockWindowInfo, nullptr, surfaceObserver);
75 surfaceObserver->frame_posted(1, mir::geometry::Size{1,1});79 surfaceObserver->frame_posted(1, mir::geometry::Size{1,1});
7680
77 QSignalSpy spyFrameDropped(surface, SIGNAL(frameDropped()));81 QSignalSpy spyFrameDropped(&surface, SIGNAL(frameDropped()));
78 QTest::qWait(300);82 QTest::qWait(300);
79 ASSERT_TRUE(spyFrameDropped.count() > 0);83 ASSERT_TRUE(spyFrameDropped.count() > 0);
80
81 delete fakeSession;
82 delete surface;
83}84}
8485
8586
@@ -89,28 +90,31 @@
89 char* argv[0];90 char* argv[0];
90 QCoreApplication qtApp(argc, argv); // app for deleteLater event91 QCoreApplication qtApp(argc, argv); // app for deleteLater event
9192
92 auto fakeSession = new FakeSession();93 auto const fakeSession = std::make_shared<NiceMock<ms::MockSession>>();
93 auto mockSurface = std::make_shared<NiceMock<ms::MockSurface>>();94 auto mockSurface = std::make_shared<NiceMock<ms::MockSurface>>();
9495 miral::Window mockWindow(fakeSession, mockSurface);
95 MirSurface *surface = new MirSurface(mockSurface, fakeSession, &m_mockShell, nullptr, CreationHints());96 miral::WindowInfo mockWindowInfo(mockWindow, {});
97 QScopedPointer<WindowInfo> windowInfo(new WindowInfo(mockWindowInfo));
98 auto surfaceObserver = std::make_shared<SurfaceObserver>();
99
100 MirSurface surface(mockWindowInfo, nullptr, surfaceObserver);
101
96 bool surfaceDeleted = false;102 bool surfaceDeleted = false;
97 QObject::connect(surface, &QObject::destroyed, surface, [&surfaceDeleted](){ surfaceDeleted = true; });103 QObject::connect(&surface, &QObject::destroyed, &surface, [&surfaceDeleted](){ surfaceDeleted = true; });
98104
99 qintptr view1 = (qintptr)1;105 qintptr view1 = (qintptr)1;
100 qintptr view2 = (qintptr)2;106 qintptr view2 = (qintptr)2;
101107
102 surface->registerView(view1);108 surface.registerView(view1);
103 surface->registerView(view2);109 surface.registerView(view2);
104 surface->setLive(false);110 surface.setLive(false);
105 EXPECT_FALSE(surfaceDeleted);111 EXPECT_FALSE(surfaceDeleted);
106112
107 surface->unregisterView(view1);113 surface.unregisterView(view1);
108 surface->unregisterView(view2);114 surface.unregisterView(view2);
109115
110 QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);116 QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
111 EXPECT_TRUE(surfaceDeleted);117 EXPECT_TRUE(surfaceDeleted);
112
113 delete fakeSession;
114}118}
115119
116120
@@ -120,62 +124,63 @@
120 char* argv[0];124 char* argv[0];
121 QCoreApplication qtApp(argc, argv); // app for deleteLater event125 QCoreApplication qtApp(argc, argv); // app for deleteLater event
122126
123 auto fakeSession = new FakeSession();127 auto const fakeSession = std::make_shared<ms::MockSession>();
124 auto mockSurface = std::make_shared<NiceMock<ms::MockSurface>>();128 auto mockSurface = std::make_shared<NiceMock<ms::MockSurface>>();
125129 miral::Window mockWindow(fakeSession, mockSurface);
126 MirSurface *surface = new MirSurface(mockSurface, fakeSession, &m_mockShell, nullptr, CreationHints());130 miral::WindowInfo mockWindowInfo(mockWindow, {});
131 QScopedPointer<WindowInfo> windowInfo(new WindowInfo(mockWindowInfo));
132 auto surfaceObserver = std::make_shared<SurfaceObserver>();
133
134 MirSurface surface(mockWindowInfo, nullptr, surfaceObserver);
135
127 bool surfaceDeleted = false;136 bool surfaceDeleted = false;
128 QObject::connect(surface, &QObject::destroyed, surface, [&surfaceDeleted](){ surfaceDeleted = true; });137 QObject::connect(&surface, &QObject::destroyed, &surface, [&surfaceDeleted](){ surfaceDeleted = true; });
129138
130 qintptr view1 = (qintptr)1;139 qintptr view1 = (qintptr)1;
131 qintptr view2 = (qintptr)2;140 qintptr view2 = (qintptr)2;
132141
133 surface->registerView(view1);142 surface.registerView(view1);
134 surface->registerView(view2);143 surface.registerView(view2);
135144
136 surface->unregisterView(view1);145 surface.unregisterView(view1);
137 surface->unregisterView(view2);146 surface.unregisterView(view2);
138147
139 QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);148 QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
140 EXPECT_FALSE(surfaceDeleted);149 EXPECT_FALSE(surfaceDeleted);
141
142 delete fakeSession;
143 delete surface;
144}150}
145151
146/*152/*
147 * Test that a surface whose client fails to comply with a close request will eventually get destroyed.153 * Test that a surface whose client fails to comply with a close request will eventually get destroyed.
148 */154 */
149TEST_F(MirSurfaceTest, failedSurfaceCloseEventualyDestroysSurface)155TEST_F(MirSurfaceTest, failedSurfaceCloseEventuallyDestroysSurface)
150{156{
151 const pid_t pid = 1234;
152 const char appId[] = "test-app";
153
154 int argc = 0;157 int argc = 0;
155 char* argv[0];158 char* argv[0];
156 QCoreApplication qtApp(argc, argv); // app for deleteLater event159 QCoreApplication qtApp(argc, argv); // app for deleteLater event
157160
158 auto fakeSession = new FakeSession();161 auto const mockSession = std::make_shared<NiceMock<ms::MockSession>>();
159 auto mirSession = std::make_shared<mir::scene::MockSession>(appId, pid);
160 fakeSession->setSession(mirSession);
161
162 auto mockSurface = std::make_shared<NiceMock<ms::MockSurface>>();162 auto mockSurface = std::make_shared<NiceMock<ms::MockSurface>>();
163163 miral::Window mockWindow(mockSession, mockSurface);
164 MirSurface *surface = new MirSurface(mockSurface, fakeSession, &m_mockShell, nullptr, CreationHints());164 miral::WindowInfo mockWindowInfo(mockWindow, {});
165 QScopedPointer<WindowInfo> windowInfo(new WindowInfo(mockWindowInfo));
166 auto surfaceObserver = std::make_shared<SurfaceObserver>();
167
168 MirSurface surface(mockWindowInfo, nullptr, surfaceObserver);
169
165 bool surfaceDeleted = false;170 bool surfaceDeleted = false;
166 QObject::connect(surface, &QObject::destroyed, surface, [&surfaceDeleted](){ surfaceDeleted = true; });171 QObject::connect(&surface, &QObject::destroyed, &surface, [&surfaceDeleted](){ surfaceDeleted = true; });
167172
168 QSharedPointer<FakeTimeSource> fakeTimeSource(new FakeTimeSource);173 QSharedPointer<FakeTimeSource> fakeTimeSource(new FakeTimeSource);
169 QPointer<FakeTimer> fakeTimer(new FakeTimer(fakeTimeSource));174 QPointer<FakeTimer> fakeTimer(new FakeTimer(fakeTimeSource));
170 surface->setCloseTimer(fakeTimer.data()); // surface takes ownership of the timer175 surface.setCloseTimer(fakeTimer.data()); // surface takes ownership of the timer
171176
172 qintptr view = (qintptr)1;177 qintptr view = (qintptr)1;
173 surface->registerView(view);178 surface.registerView(view);
174179
175 EXPECT_CALL(*mirSession.get(), destroy_surface(An<const std::weak_ptr<mir::scene::Surface> &>()))180 EXPECT_CALL(*mockSession.get(), destroy_surface(An<const std::weak_ptr<ms::Surface> &>()))
176 .Times(1);181 .Times(1);
177182
178 surface->close();183 surface.close();
179184
180 if (fakeTimer->isRunning()) {185 if (fakeTimer->isRunning()) {
181 // Simulate that closeTimer has timed out.186 // Simulate that closeTimer has timed out.
@@ -184,8 +189,6 @@
184 }189 }
185190
186 // clean up191 // clean up
187 surface->setLive(false);192 surface.setLive(false);
188 surface->unregisterView(view);193 surface.unregisterView(view);
189 delete surface;
190 delete fakeSession;
191}194}

Subscribers

People subscribed via source and target branches