20 #include <unity/shell/application/MirSurfaceInterface.h> 23 #include <QTextStream> 27 Q_LOGGING_CATEGORY(UNITY_WINDOW,
"unity.window", QtWarningMsg)
29 #define DEBUG_MSG qCDebug(UNITY_WINDOW).nospace() << qPrintable(toString()) << "::" << __func__ 31 Window::Window(
int id, QObject *parent)
36 QQmlEngine::setObjectOwnership(
this, QQmlEngine::CppOwnership);
51 return m_requestedPosition;
54 void Window::setRequestedPosition(
const QPoint &value)
56 m_positionRequested =
true;
57 if (value != m_requestedPosition) {
58 m_requestedPosition = value;
59 Q_EMIT requestedPositionChanged(m_requestedPosition);
61 m_surface->setRequestedPosition(value);
64 m_position = m_requestedPosition;
65 Q_EMIT positionChanged(m_position);
72 return m_allowClientResize;
75 void Window::setAllowClientResize(
bool value)
77 if (value != m_allowClientResize) {
78 DEBUG_MSG <<
"("<<value<<
")";
79 m_allowClientResize = value;
81 m_surface->setAllowClientResize(value);
83 Q_EMIT allowClientResizeChanged(m_allowClientResize);
100 return m_surface->confinesMousePointer();
118 m_stateRequested =
true;
120 m_surface->requestState(state);
121 }
else if (m_state != state) {
123 Q_EMIT stateChanged(m_state);
132 Q_EMIT closeRequested();
140 m_surface->activate();
142 Q_EMIT emptyWindowActivated();
146 void Window::setSurface(unityapi::MirSurfaceInterface *surface)
148 DEBUG_MSG <<
"(" << surface <<
")";
150 disconnect(m_surface, 0,
this, 0);
156 connect(surface, &unityapi::MirSurfaceInterface::focusRequested,
this, [
this]() {
157 Q_EMIT focusRequested();
160 connect(surface, &unityapi::MirSurfaceInterface::closeRequested,
this, &Window::closeRequested);
162 connect(surface, &unityapi::MirSurfaceInterface::positionChanged,
this, [
this]() {
166 connect(surface, &unityapi::MirSurfaceInterface::stateChanged,
this, [
this]() {
170 connect(surface, &unityapi::MirSurfaceInterface::focusedChanged,
this, [
this]() {
174 connect(surface, &unityapi::MirSurfaceInterface::allowClientResizeChanged,
this, [
this]() {
175 if (m_surface->allowClientResize() != m_allowClientResize) {
176 m_allowClientResize = m_surface->allowClientResize();
177 Q_EMIT allowClientResizeChanged(m_allowClientResize);
181 connect(surface, &unityapi::MirSurfaceInterface::liveChanged,
this, &Window::liveChanged);
183 connect(surface, &QObject::destroyed,
this, [
this]() {
188 if (m_positionRequested) {
189 m_surface->setRequestedPosition(m_requestedPosition);
191 if (m_stateRequested && m_surface->state() == Mir::RestoredState) {
192 m_surface->requestState(m_state);
194 m_surface->setAllowClientResize(m_allowClientResize);
202 Q_EMIT surfaceChanged(surface);
205 void Window::updatePosition()
207 if (m_surface->position() != m_position) {
208 m_position = m_surface->position();
209 Q_EMIT positionChanged(m_position);
213 void Window::updateState()
215 if (m_surface->state() != m_state) {
216 m_state = m_surface->state();
217 Q_EMIT stateChanged(m_state);
221 void Window::updateFocused()
223 if (m_surface->focused() != m_focused) {
224 m_focused = m_surface->focused();
225 Q_EMIT focusedChanged(m_focused);
229 void Window::setFocused(
bool value)
231 if (value != m_focused) {
232 DEBUG_MSG <<
"(" << value <<
")";
234 Q_EMIT focusedChanged(m_focused);
236 Q_ASSERT(!m_surface);
240 QString Window::toString()
const 244 QTextStream stream(&result);
245 stream <<
"Window["<<(
void*)
this<<
", id="<<
id()<<
", ";
247 stream <<
"MirSurface["<<(
void*)surface()<<
",\""<<surface()->name()<<
"\"]";
256 QDebug operator<<(QDebug dbg,
const Window *window)
258 QDebugStateSaver saver(dbg);
262 dbg << qPrintable(window->toString());
264 dbg << (
void*)(window);
A slightly higher concept than MirSurface.
Mir::State state
State of the surface.
void activate()
Focuses and raises the window.
unity::shell::application::MirSurfaceInterface surface
Surface backing up this window It might be null if a surface hasn't been created yet (application is ...
bool focused
Whether the surface is focused.
void requestState(Mir::State state)
Requests a change to the specified state.
QPoint position
Position of the current surface buffer, in pixels.
int id
A unique identifier for this window. Useful for telling windows apart in a list model as they get mov...
QPoint requestedPosition
Requested position of the current surface buffer, in pixels.
bool allowClientResize
Whether to comply to resize requests coming from the client side.
void close()
Sends a close request.
bool confinesMousePointer
Whether the surface wants to confine the mouse pointer within its boundaries.