Debian Codegraph @

tests/mocks/QtMir/Application/SurfaceManager.h

raw
1 /*
2 * Copyright (C) 2014-2016 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #ifndef SURFACEMANAGER_H
18 #define SURFACEMANAGER_H
19
20 #include <QObject>
21 #include <functional>
22
23 #include <lomiri/shell/application/SurfaceManagerInterface.h>
24 #include <miral/window.h>
25
26 #include "MirSurface.h"
27 #include "VirtualKeyboard.h"
28
29 class ApplicationInfo;
30
31 struct WindowWrapper {
32 miral::Window window;
33 std::shared_ptr<mir::scene::Surface> session{nullptr}; // Keeps the window surface alive.
34 bool operator==(const WindowWrapper& other) const { return window==other.window; }
35 };
36 uint qHash(const WindowWrapper &key, uint seed = 0);
37
38 class SurfaceManager : public lomiri::shell::application::SurfaceManagerInterface
39 {
40 Q_OBJECT
41 Q_PROPERTY(int newSurfaceMinimumWidth READ newSurfaceMinimumWidth WRITE setNewSurfaceMinimumWidth NOTIFY newSurfaceMinimumWidthChanged)
42 Q_PROPERTY(int newSurfaceMaximumWidth READ newSurfaceMaximumWidth WRITE setNewSurfaceMaximumWidth NOTIFY newSurfaceMaximumWidthChanged)
43 Q_PROPERTY(int newSurfaceMinimumHeight READ newSurfaceMinimumHeight WRITE setNewSurfaceMinimumHeight NOTIFY newSurfaceMinimumHeightChanged)
44 Q_PROPERTY(int newSurfaceMaximumHeight READ newSurfaceMaximumHeight WRITE setNewSurfaceMaximumHeight NOTIFY newSurfaceMaximumHeightChanged)
45 Q_PROPERTY(int newSurfaceWidthIncrement READ newSurfaceWidthIncrement WRITE setNewSurfaceWidthIncrement NOTIFY newSurfaceWidthIncrementChanged)
46 Q_PROPERTY(int newSurfaceHeightIncrement READ newSurfaceHeightIncrement WRITE setNewSurfaceHeightIncrement NOTIFY newSurfaceHeightIncrementChanged)
47
48 public:
49 explicit SurfaceManager(QObject *parent = 0);
50 virtual ~SurfaceManager();
51
52 static SurfaceManager *instance();
53
54 // SurfaceManagerInterface
55 void raise(lomiri::shell::application::MirSurfaceInterface *surface) override;
56 void activate(lomiri::shell::application::MirSurfaceInterface *surface) override;
57
58 void forEachSurfaceInWorkspace(const std::shared_ptr<miral::Workspace> &workspace,
59 const std::function<void(lomiri::shell::application::MirSurfaceInterface*)> &callback) override;
60 void moveSurfaceToWorkspace(lomiri::shell::application::MirSurfaceInterface* surface,
61 const std::shared_ptr<miral::Workspace> &workspace) override;
62 void moveWorkspaceContentToWorkspace(const std::shared_ptr<miral::Workspace> &to,
63 const std::shared_ptr<miral::Workspace> &from) override;
64
65 Q_INVOKABLE MirSurface* createSurface(const QString& name,
66 Mir::Type type,
67 Mir::State state,
68 MirSurface *parentSurface,
69 const QUrl &screenshot,
70 const QUrl &qmlFilePath = QUrl());
71
72
73 void notifySurfaceCreated(lomiri::shell::application::MirSurfaceInterface *);
74
75 int newSurfaceMinimumWidth() const { return m_newSurfaceMinimumWidth; }
76 void setNewSurfaceMinimumWidth(int value);
77
78 int newSurfaceMaximumWidth() const { return m_newSurfaceMaximumWidth; }
79 void setNewSurfaceMaximumWidth(int value);
80
81 int newSurfaceMinimumHeight() const { return m_newSurfaceMinimumHeight; }
82 void setNewSurfaceMinimumHeight(int value);
83
84 int newSurfaceMaximumHeight() const { return m_newSurfaceMaximumHeight; }
85 void setNewSurfaceMaximumHeight(int value);
86
87 int newSurfaceWidthIncrement() const { return m_newSurfaceWidthIncrement; }
88 void setNewSurfaceWidthIncrement(int);
89
90 int newSurfaceHeightIncrement() const { return m_newSurfaceHeightIncrement; }
91 void setNewSurfaceHeightIncrement(int);
92
93 public Q_SLOTS:
94 void createInputMethodSurface();
95 void releaseInputMethodSurface();
96
97 Q_SIGNALS:
98 void newSurfaceMinimumWidthChanged(int value);
99 void newSurfaceMaximumWidthChanged(int value);
100 void newSurfaceMinimumHeightChanged(int value);
101 void newSurfaceMaximumHeightChanged(int value);
102 void newSurfaceWidthIncrementChanged(int value);
103 void newSurfaceHeightIncrementChanged(int value);
104
105 private Q_SLOTS:
106 void onStateRequested(MirSurface *surface, Mir::State state);
107 void onSurfaceDestroyed(MirSurface *surface);
108
109 private:
110 void doRaise(lomiri::shell::application::MirSurfaceInterface *surface);
111 void focusFirstAvailableSurface();
112 void registerSurface(MirSurface *surface);
113 lomiri::shell::application::MirSurfaceInterface* surfaceFor(const miral::Window &window) const;
114 QVector<lomiri::shell::application::MirSurfaceInterface*> surfacesFor(const std::vector<miral::Window> &windows) const;
115 miral::Window windowFor(lomiri::shell::application::MirSurfaceInterface* surface) const;
116
117 static SurfaceManager *m_instance;
118
119 int m_newSurfaceMinimumWidth{0};
120 int m_newSurfaceMaximumWidth{0};
121 int m_newSurfaceMinimumHeight{0};
122 int m_newSurfaceMaximumHeight{0};
123 int m_newSurfaceWidthIncrement{1};
124 int m_newSurfaceHeightIncrement{1};
125
126 MirSurface *m_focusedSurface{nullptr};
127 bool m_underModification{false};
128
129 QList<MirSurface*> m_surfaces;
130
131 QHash<WindowWrapper, lomiri::shell::application::MirSurfaceInterface*> m_windowToSurface;
132 QHash<lomiri::shell::application::MirSurfaceInterface*, WindowWrapper> m_surfaceToWindow;
133
134 VirtualKeyboard *m_virtualKeyboard{nullptr};
135 };
136
137 #endif // SURFACEMANAGER_H