20#include <lomiri/shell/application/MirSurfaceInterface.h>
25namespace lomiriapi = lomiri::shell::application;
27Q_LOGGING_CATEGORY(LOMIRI_WINDOW,
"lomiri.window", QtWarningMsg)
29#define DEBUG_MSG qCDebug(LOMIRI_WINDOW).nospace() << qPrintable(toString()) << "::" << __func__
30#define WARNING_MSG qCWarning(LOMIRI_WINDOW).nospace() << qPrintable(toString()) << "::" << __func__
32Window::Window(
int id, QObject *parent)
37 QQmlEngine::setObjectOwnership(
this, QQmlEngine::CppOwnership);
52 return m_requestedPosition;
55void Window::setRequestedPosition(
const QPoint &value)
57 m_positionRequested =
true;
58 if (value != m_requestedPosition) {
59 m_requestedPosition = value;
60 Q_EMIT requestedPositionChanged(m_requestedPosition);
62 m_surface->setRequestedPosition(value);
65 m_position = m_requestedPosition;
66 Q_EMIT positionChanged(m_position);
73 return m_allowClientResize;
76void Window::setAllowClientResize(
bool value)
78 if (value != m_allowClientResize) {
79 DEBUG_MSG <<
"("<<value<<
")";
80 m_allowClientResize = value;
82 m_surface->setAllowClientResize(value);
84 Q_EMIT allowClientResizeChanged(m_allowClientResize);
101 return m_surface->confinesMousePointer();
119 m_stateRequested =
true;
121 m_surface->requestState(
state);
122 }
else if (m_state !=
state) {
124 Q_EMIT stateChanged(m_state);
133 Q_EMIT closeRequested();
141 m_surface->activate();
143 Q_EMIT emptyWindowActivated();
147void Window::setSurface(lomiriapi::MirSurfaceInterface *surface)
149 DEBUG_MSG <<
"(" <<
surface <<
")";
151 disconnect(m_surface, 0,
this, 0);
157 connect(
surface, &lomiriapi::MirSurfaceInterface::focusRequested,
this, [
this]() {
161 connect(
surface, &lomiriapi::MirSurfaceInterface::closeRequested,
this, &Window::closeRequested);
163 connect(
surface, &lomiriapi::MirSurfaceInterface::positionChanged,
this, [
this]() {
167 connect(
surface, &lomiriapi::MirSurfaceInterface::stateChanged,
this, [
this]() {
171 connect(
surface, &lomiriapi::MirSurfaceInterface::focusedChanged,
this, [
this]() {
175 connect(
surface, &lomiriapi::MirSurfaceInterface::allowClientResizeChanged,
this, [
this]() {
176 if (m_surface->allowClientResize() != m_allowClientResize) {
177 m_allowClientResize = m_surface->allowClientResize();
178 Q_EMIT allowClientResizeChanged(m_allowClientResize);
182 connect(
surface, &lomiriapi::MirSurfaceInterface::liveChanged,
this, &Window::liveChanged);
184 connect(
surface, &QObject::destroyed,
this, [
this]() {
189 if (m_surface->focused()) {
190 WARNING_MSG <<
"Initial surface is focused!";
195 m_surface->activate();
197 if (m_positionRequested) {
198 m_surface->setRequestedPosition(m_requestedPosition);
200 if (m_stateRequested && m_surface->state() == Mir::RestoredState) {
201 m_surface->requestState(m_state);
203 m_surface->setAllowClientResize(m_allowClientResize);
211 Q_EMIT surfaceChanged(
surface);
214void Window::updatePosition()
216 if (m_surface->position() != m_position) {
217 m_position = m_surface->position();
218 Q_EMIT positionChanged(m_position);
222void Window::updateState()
224 if (m_surface->state() != m_state) {
225 m_state = m_surface->state();
226 Q_EMIT stateChanged(m_state);
230void Window::updateFocused()
232 if (m_surface->focused() != m_focused) {
233 m_focused = m_surface->focused();
234 Q_EMIT focusedChanged(m_focused);
238void Window::setFocused(
bool value)
240 if (value != m_focused) {
241 DEBUG_MSG <<
"(" << value <<
")";
243 Q_EMIT focusedChanged(m_focused);
245 Q_ASSERT(!m_surface);
249QString Window::toString()
const
253 QTextStream stream(&result);
254 stream <<
"Window["<<(
void*)
this<<
", id="<<
id()<<
", ";
256 stream <<
"MirSurface["<<(
void*)
surface()<<
",\""<<
surface()->name()<<
"\"]";
265QDebug operator<<(QDebug dbg,
const Window *window)
267 QDebugStateSaver saver(dbg);
271 dbg << qPrintable(window->toString());
273 dbg << (
void*)(window);
A slightly higher concept than MirSurface.
bool allowClientResize
Whether to comply to resize requests coming from the client side.
void requestState(Mir::State state)
Requests a change to the specified state.
int id
A unique identifier for this window. Useful for telling windows apart in a list model as they get mov...
void focusRequested()
Emitted when focus for this window is requested by an external party.
void close()
Sends a close request.
lomiri::shell::application::MirSurfaceInterface * surface
Surface backing up this window It might be null if a surface hasn't been created yet (application is ...
QPoint requestedPosition
Requested position of the current surface buffer, in pixels.
bool confinesMousePointer
Whether the surface wants to confine the mouse pointer within its boundaries.
QPoint position
Position of the current surface buffer, in pixels.
bool focused
Whether the surface is focused.
void activate()
Focuses and raises the window.
Mir::State state
State of the surface.