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