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();
109 return m_constrained;
124 m_stateRequested =
true;
126 m_surface->requestState(
state);
127 }
else if (m_state !=
state) {
129 Q_EMIT stateChanged(m_state);
138 Q_EMIT closeRequested();
146 m_surface->activate();
148 Q_EMIT emptyWindowActivated();
152void Window::setSurface(lomiriapi::MirSurfaceInterface *surface)
154 DEBUG_MSG <<
"(" <<
surface <<
")";
156 disconnect(m_surface, 0,
this, 0);
162 connect(
surface, &lomiriapi::MirSurfaceInterface::focusRequested,
this, [
this]() {
166 connect(
surface, &lomiriapi::MirSurfaceInterface::closeRequested,
this, &Window::closeRequested);
168 connect(
surface, &lomiriapi::MirSurfaceInterface::positionChanged,
this, [
this]() {
172 connect(
surface, &lomiriapi::MirSurfaceInterface::stateChanged,
this, [
this]() {
176 connect(
surface, &lomiriapi::MirSurfaceInterface::focusedChanged,
this, [
this]() {
180 connect(
surface, &lomiriapi::MirSurfaceInterface::allowClientResizeChanged,
this, [
this]() {
181 if (m_surface->allowClientResize() != m_allowClientResize) {
182 m_allowClientResize = m_surface->allowClientResize();
183 Q_EMIT allowClientResizeChanged(m_allowClientResize);
187 connect(
surface, &lomiriapi::MirSurfaceInterface::liveChanged,
this, &Window::liveChanged);
189 connect(
surface, &QObject::destroyed,
this, [
this]() {
194 if (m_surface->focused()) {
195 WARNING_MSG <<
"Initial surface is focused!";
200 m_surface->activate();
202 if (m_positionRequested) {
203 m_surface->setRequestedPosition(m_requestedPosition);
205 if (m_stateRequested && m_surface->state() == Mir::RestoredState) {
206 m_surface->requestState(m_state);
208 m_surface->setAllowClientResize(m_allowClientResize);
216 Q_EMIT surfaceChanged(
surface);
219void Window::updatePosition()
221 if (m_surface->position() != m_position) {
222 m_position = m_surface->position();
223 Q_EMIT positionChanged(m_position);
227void Window::updateState()
229 if (m_surface->state() != m_state) {
230 m_state = m_surface->state();
231 Q_EMIT stateChanged(m_state);
235void Window::updateFocused()
237 if (m_surface->focused() != m_focused) {
238 m_focused = m_surface->focused();
239 Q_EMIT focusedChanged(m_focused);
243void Window::setFocused(
bool value)
245 if (value != m_focused) {
246 DEBUG_MSG <<
"(" << value <<
")";
248 Q_EMIT focusedChanged(m_focused);
250 Q_ASSERT(!m_surface);
254void Window::setConstrained(
bool value)
256 if (value != m_constrained) {
257 DEBUG_MSG <<
"(" << value <<
")";
258 m_constrained = value;
259 Q_EMIT constrainedChanged(m_constrained);
263QString Window::toString()
const
267 QTextStream stream(&result);
268 stream <<
"Window["<<(
void*)
this<<
", id="<<
id()<<
", ";
270 stream <<
"MirSurface["<<(
void*)
surface()<<
",\""<<
surface()->name()<<
"\"]";
279QDebug operator<<(QDebug dbg,
const Window *window)
281 QDebugStateSaver saver(dbg);
285 dbg << qPrintable(window->toString());
287 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.
bool constrained
Whether the surface has been constrained in screen bounds already.
void activate()
Focuses and raises the window.
Mir::State state
State of the surface.