on fe95219 help sign in
160 lines 4.8 kB history raw
1/*
2 * Copyright (C) 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 */
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>
27namespace unity {
28 namespace shell {
29 namespace application {
30 class MirSurfaceInterface;
31 }
32 }
35Q_DECLARE_LOGGING_CATEGORY(UNITY_WINDOW)
37/**
38 @brief A slightly higher concept than MirSurface
40 A Window exists before its MirSurface gets created (for splashscreen purposes)
41 and might also hang around after the backing surface is gone (In case the application
42 was killed to free up memory, as it should still remain in the window list since the user
43 did not explicitly close it).
44 */
45class Window : public QObject
47 Q_OBJECT
49 /**
50 * @brief Position of the current surface buffer, in pixels.
51 */
52 Q_PROPERTY(QPoint position READ position NOTIFY positionChanged)
54 /**
55 * @brief Requested position of the current surface buffer, in pixels.
56 */
57 Q_PROPERTY(QPoint requestedPosition READ requestedPosition WRITE setRequestedPosition NOTIFY requestedPositionChanged)
59 /**
60 * @brief State of the surface
61 */
62 Q_PROPERTY(Mir::State state READ state NOTIFY stateChanged)
64 /**
65 * @brief Whether the surface is focused
66 *
67 * It will be true if this surface is MirFocusControllerInterface::focusedSurface
68 */
69 Q_PROPERTY(bool focused READ focused NOTIFY focusedChanged)
71 /**
72 * @brief Whether the surface wants to confine the mouse pointer within its boundaries
73 *
74 * If true, the surface doesn't want the mouse pointer to leave its boundaries while it's focused.
75 */
76 Q_PROPERTY(bool confinesMousePointer READ confinesMousePointer NOTIFY confinesMousePointerChanged)
78 /**
79 * @brief A unique identifier for this window.
80 * Useful for telling windows apart in a list model as they get moved around
81 */
82 Q_PROPERTY(int id READ id CONSTANT)
84 /**
85 * @brief Surface backing up this window
86 * It might be null if a surface hasn't been created yet (application is starting up) or if
87 * the corresponding application has been killed (but can still get restarted to continue from
88 * where it left)
89 */
90 Q_PROPERTY(unity::shell::application::MirSurfaceInterface* surface READ surface NOTIFY surfaceChanged)
92public:
93 Window(int id, QObject *parent = nullptr);
94 virtual ~Window();
95 QPoint position() const;
96 QPoint requestedPosition() const;
97 void setRequestedPosition(const QPoint &);
98 Mir::State state() const;
99 bool focused() const;
100 bool confinesMousePointer() const;
101 int id() const;
102 unity::shell::application::MirSurfaceInterface* surface() const;
104 void setSurface(unity::shell::application::MirSurfaceInterface *surface);
105 void setFocused(bool value);
107 QString toString() const;
109public Q_SLOTS:
110 /**
111 * @brief Requests a change to the specified state
112 */
113 void requestState(Mir::State state);
115 /**
116 * @brief Sends a close request
117 *
118 */
119 void close();
121 /**
122 * @brief Focuses and raises the window
123 */
124 void activate();
126Q_SIGNALS:
127 void closeRequested();
128 void emptyWindowActivated();
130 void positionChanged(QPoint position);
131 void requestedPositionChanged(QPoint position);
132 void stateChanged(Mir::State value);
133 void focusedChanged(bool value);
134 void confinesMousePointerChanged(bool value);
135 void surfaceChanged(unity::shell::application::MirSurfaceInterface *surface);
137 /**
138 * @brief Emitted when focus for this window is requested by an external party
139 */
140 void focusRequested();
142private:
143 void updatePosition();
144 void updateState();
145 void updateFocused();
147 QPoint m_position;
148 QPoint m_requestedPosition;
149 bool m_positionRequested{false};
150 bool m_focused{false};
151 int m_id;
152 Mir::State m_state{Mir::RestoredState};
153 bool m_stateRequested{false};
154 unity::shell::application::MirSurfaceInterface *m_surface{nullptr};
155};
157QDebug operator<<(QDebug dbg, const Window *window);
159Q_DECLARE_METATYPE(Window*)
160#endif // UNITY_WINDOW_H