on bionic help sign in
176 lines 5.3 kB history raw
1/*
2 * Copyright (C) 2016-2017 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 */
17#ifndef UNITY_WINDOW_H
18#define UNITY_WINDOW_H
20#include <QLoggingCategory>
21#include <QObject>
22#include <QPoint>
24// Unity API
25#include <unity/shell/application/Mir.h>
27#include "WindowManagerGlobal.h"
29namespace unity {
30 namespace shell {
31 namespace application {
32 class MirSurfaceInterface;
33 }
34 }
37Q_DECLARE_LOGGING_CATEGORY(UNITY_WINDOW)
39/**
40 @brief A slightly higher concept than MirSurface
42 A Window exists before its MirSurface gets created (for splashscreen purposes)
43 and might also hang around after the backing surface is gone (In case the application
44 was killed to free up memory, as it should still remain in the window list since the user
45 did not explicitly close it).
46 */
47class WINDOWMANAGERQML_EXPORT Window : public QObject
49 Q_OBJECT
51 /**
52 * @brief Position of the current surface buffer, in pixels.
53 */
54 Q_PROPERTY(QPoint position READ position NOTIFY positionChanged)
56 /**
57 * @brief Requested position of the current surface buffer, in pixels.
58 */
59 Q_PROPERTY(QPoint requestedPosition READ requestedPosition WRITE setRequestedPosition NOTIFY requestedPositionChanged)
61 /**
62 * @brief State of the surface
63 */
64 Q_PROPERTY(Mir::State state READ state NOTIFY stateChanged)
66 /**
67 * @brief Whether the surface is focused
68 *
69 * It will be true if this surface is MirFocusControllerInterface::focusedSurface
70 */
71 Q_PROPERTY(bool focused READ focused NOTIFY focusedChanged)
73 /**
74 * @brief Whether the surface wants to confine the mouse pointer within its boundaries
75 *
76 * If true, the surface doesn't want the mouse pointer to leave its boundaries while it's focused.
77 */
78 Q_PROPERTY(bool confinesMousePointer READ confinesMousePointer NOTIFY confinesMousePointerChanged)
80 /**
81 * @brief A unique identifier for this window.
82 * Useful for telling windows apart in a list model as they get moved around
83 */
84 Q_PROPERTY(int id READ id CONSTANT)
86 /**
87 * @brief Surface backing up this window
88 * It might be null if a surface hasn't been created yet (application is starting up) or if
89 * the corresponding application has been killed (but can still get restarted to continue from
90 * where it left)
91 */
92 Q_PROPERTY(unity::shell::application::MirSurfaceInterface* surface READ surface NOTIFY surfaceChanged)
94 /**
95 * @brief Whether to comply to resize requests coming from the client side
96 *
97 * It's true by default
98 */
99 Q_PROPERTY(bool allowClientResize READ allowClientResize WRITE setAllowClientResize NOTIFY allowClientResizeChanged)
101public:
102 Window(int id, QObject *parent = nullptr);
103 virtual ~Window();
104 QPoint position() const;
105 QPoint requestedPosition() const;
106 void setRequestedPosition(const QPoint &);
107 Mir::State state() const;
108 bool focused() const;
109 bool confinesMousePointer() const;
110 int id() const;
111 unity::shell::application::MirSurfaceInterface* surface() const;
113 void setSurface(unity::shell::application::MirSurfaceInterface *surface);
114 void setFocused(bool value);
116 bool allowClientResize() const;
117 void setAllowClientResize(bool);
119 QString toString() const;
121public Q_SLOTS:
122 /**
123 * @brief Requests a change to the specified state
124 */
125 void requestState(Mir::State state);
127 /**
128 * @brief Sends a close request
129 *
130 */
131 void close();
133 /**
134 * @brief Focuses and raises the window
135 */
136 void activate();
138Q_SIGNALS:
139 void closeRequested();
140 void emptyWindowActivated();
142 void positionChanged(QPoint position);
143 void requestedPositionChanged(QPoint position);
144 void stateChanged(Mir::State value);
145 void focusedChanged(bool value);
146 void confinesMousePointerChanged(bool value);
147 void surfaceChanged(unity::shell::application::MirSurfaceInterface *surface);
148 void allowClientResizeChanged(bool value);
149 void liveChanged(bool value);
151 /**
152 * @brief Emitted when focus for this window is requested by an external party
153 */
154 void focusRequested();
156private:
157 void updatePosition();
158 void updateState();
159 void updateFocused();
161 QPoint m_position;
162 QPoint m_requestedPosition;
163 bool m_positionRequested{false};
164 bool m_focused{false};
165 int m_id;
166 Mir::State m_state{Mir::RestoredState};
167 bool m_stateRequested{false};
168 unity::shell::application::MirSurfaceInterface *m_surface{nullptr};
170 bool m_allowClientResize{true};
171};
173QDebug operator<<(QDebug dbg, const Window *window);
175Q_DECLARE_METATYPE(Window*)
176#endif // UNITY_WINDOW_H