Lomiri
Loading...
Searching...
No Matches
TopLevelWindowModel Class Reference

A model of top-level surfaces. More...

#include <plugins/WindowManager/TopLevelWindowModel.h>

Public Types

enum  Roles { WindowRole = Qt::UserRole , ApplicationRole = Qt::UserRole + 1 }
 The Roles supported by the model. More...

Signals

void countChanged ()
void inputMethodSurfaceChanged (lomiri::shell::application::MirSurfaceInterface *inputMethodSurface)
void focusedWindowChanged (Window *focusedWindow)
void listChanged ()
 Emitted when the list changes.
void closedAllWindows ()
void rootFocusChanged ()

Public Member Functions

 TopLevelWindowModel (Workspace *workspace)
int rowCount (const QModelIndex &parent=QModelIndex()) const override
QVariant data (const QModelIndex &index, int role) const override
QHash< int, QByteArray > roleNames () const override
lomiri::shell::application::MirSurfaceInterface * inputMethodSurface () const
WindowfocusedWindow () const
int nextId () const
Q_INVOKABLE lomiri::shell::application::MirSurfaceInterface * surfaceAt (int index) const
 Returns the surface at the given index.
Q_INVOKABLE WindowwindowAt (int index) const
 Returns the window at the given index.
Q_INVOKABLE lomiri::shell::application::ApplicationInfoInterface * applicationAt (int index) const
 Returns the application at the given index.
Q_INVOKABLE int idAt (int index) const
 Returns the unique id of the element at the given index.
Q_INVOKABLE int indexForId (int id) const
 Returns the index where the row with the given id is located.
Q_INVOKABLE void raiseId (int id)
 Raises the row with the given id to the top of the window stack (index == count-1).
Q_INVOKABLE void closeAllWindows ()
 Closes all windows, emits closedAllWindows when done.
Q_INVOKABLE void pendingActivation ()
 Sets pending activation flag.
void setApplicationManager (lomiri::shell::application::ApplicationManagerInterface *)
void setSurfaceManager (lomiri::shell::application::SurfaceManagerInterface *)
void setRootFocus (bool focus)
bool rootFocus ()

Properties

int count
 Number of top-level surfaces in this model.
lomiri::shell::application::MirSurfaceInterface * inputMethodSurface
 The input method surface, if any.
WindowfocusedWindow
 The currently focused window, if any.
int nextId
bool rootFocus
 Sets whether a user Window or "nothing" should be focused.

Detailed Description

A model of top-level surfaces.

It's an abstraction of top-level application windows.

When an entry first appears, it normaly doesn't have a surface yet, meaning that the application is still starting up. A shell should then display a splash screen or saved screenshot of the application until its surface comes up.

As applications can have multiple surfaces and you can also have entries without surfaces at all, the only way to unambiguously refer to an entry in this model is through its id.

Definition at line 59 of file TopLevelWindowModel.h.

Member Enumeration Documentation

◆ Roles

The Roles supported by the model.

WindowRole - A Window. ApplicationRole - An ApplicationInfoInterface

Definition at line 116 of file TopLevelWindowModel.h.

116 {
117 WindowRole = Qt::UserRole,
118 ApplicationRole = Qt::UserRole + 1,
119 };

Constructor & Destructor Documentation

◆ TopLevelWindowModel()

TopLevelWindowModel::TopLevelWindowModel ( Workspace * workspace)

Definition at line 43 of file TopLevelWindowModel.cpp.

44 : m_nullWindow(createWindow(nullptr)),
45 m_workspace(workspace),
46 m_surfaceManagerBusy(false)
47{
48 connect(WindowManagerObjects::instance(), &WindowManagerObjects::applicationManagerChanged,
49 this, &TopLevelWindowModel::setApplicationManager);
50 connect(WindowManagerObjects::instance(), &WindowManagerObjects::surfaceManagerChanged,
51 this, &TopLevelWindowModel::setSurfaceManager);
52
53 setApplicationManager(WindowManagerObjects::instance()->applicationManager());
54 setSurfaceManager(WindowManagerObjects::instance()->surfaceManager());
55
56 connect(m_nullWindow, &Window::focusedChanged, this, [this] {
57 Q_EMIT rootFocusChanged();
58 });
59}

◆ ~TopLevelWindowModel()

TopLevelWindowModel::~TopLevelWindowModel ( )

Definition at line 61 of file TopLevelWindowModel.cpp.

62{
63}

Member Function Documentation

◆ applicationAt()

lomiriapi::ApplicationInfoInterface * TopLevelWindowModel::applicationAt ( int index) const

Returns the application at the given index.

Definition at line 703 of file TopLevelWindowModel.cpp.

704{
705 if (index >=0 && index < m_windowModel.count()) {
706 return m_windowModel[index].application;
707 } else {
708 return nullptr;
709 }
710}

◆ closeAllWindows()

void TopLevelWindowModel::closeAllWindows ( )

Closes all windows, emits closedAllWindows when done.

Definition at line 892 of file TopLevelWindowModel.cpp.

893{
894 m_closingAllApps = true;
895 for (auto win : m_windowModel) {
896 win.window->close();
897 }
898
899 // This is done after the for loop in the unlikely event that
900 // an app starts in between this
901 if (m_windowModel.isEmpty()) {
902 Q_EMIT closedAllWindows();
903 }
904}

◆ data()

QVariant TopLevelWindowModel::data ( const QModelIndex & index,
int role ) const
override

Definition at line 630 of file TopLevelWindowModel.cpp.

631{
632 if (index.row() < 0 || index.row() >= m_windowModel.size())
633 return QVariant();
634
635 if (role == WindowRole) {
636 Window *window = m_windowModel.at(index.row()).window;
637 return QVariant::fromValue(window);
638 } else if (role == ApplicationRole) {
639 return QVariant::fromValue(m_windowModel.at(index.row()).application);
640 } else {
641 return QVariant();
642 }
643}

◆ focusedWindow()

Window * TopLevelWindowModel::focusedWindow ( ) const

Definition at line 778 of file TopLevelWindowModel.cpp.

779{
780 return m_focusedWindow;
781}

◆ idAt()

int TopLevelWindowModel::idAt ( int index) const

Returns the unique id of the element at the given index.

Definition at line 712 of file TopLevelWindowModel.cpp.

713{
714 if (index >=0 && index < m_windowModel.count()) {
715 return m_windowModel[index].window->id();
716 } else {
717 return 0;
718 }
719}

◆ indexForId()

int TopLevelWindowModel::indexForId ( int id) const

Returns the index where the row with the given id is located.

Returns -1 if there's no row with the given id.

Definition at line 675 of file TopLevelWindowModel.cpp.

676{
677 for (int i = 0; i < m_windowModel.count(); ++i) {
678 if (m_windowModel[i].window->id() == id) {
679 return i;
680 }
681 }
682 return -1;
683}

◆ inputMethodSurface()

lomiriapi::MirSurfaceInterface * TopLevelWindowModel::inputMethodSurface ( ) const

Definition at line 773 of file TopLevelWindowModel.cpp.

774{
775 return m_inputMethodWindow ? m_inputMethodWindow->surface() : nullptr;
776}

◆ listChanged

void TopLevelWindowModel::listChanged ( )
signal

Emitted when the list changes.

Emitted when model gains an element, loses an element or when elements exchange positions.

◆ nextId()

int TopLevelWindowModel::nextId ( ) const
inline

Definition at line 139 of file TopLevelWindowModel.h.

139{ return m_nextId.loadRelaxed(); }

◆ pendingActivation()

void TopLevelWindowModel::pendingActivation ( )

Sets pending activation flag.

Definition at line 944 of file TopLevelWindowModel.cpp.

945{
946 m_pendingActivation = true;
947}

◆ raiseId()

void TopLevelWindowModel::raiseId ( int id)

Raises the row with the given id to the top of the window stack (index == count-1).

Definition at line 721 of file TopLevelWindowModel.cpp.

722{
723 if (m_modelState == IdleState) {
724 DEBUG_MSG << "(id=" << id << ") - do it now.";
725 doRaiseId(id);
726 } else {
727 DEBUG_MSG << "(id=" << id << ") - Model busy (modelState=" << m_modelState << "). Try again in the next event loop.";
728 // The model has just signalled some change. If we have a Repeater responding to this update, it will get nuts
729 // if we perform yet another model change straight away.
730 //
731 // A bad sympton of this problem is a Repeater.itemAt(index) call returning null event though Repeater.count says
732 // the index is definitely within bounds.
733 QMetaObject::invokeMethod(this, "raiseId", Qt::QueuedConnection, Q_ARG(int, id));
734 }
735}

◆ roleNames()

QHash< int, QByteArray > TopLevelWindowModel::roleNames ( ) const
inlineoverride

Definition at line 127 of file TopLevelWindowModel.h.

127 {
128 QHash<int, QByteArray> roleNames { {WindowRole, "window"},
129 {ApplicationRole, "application"} };
130 return roleNames;
131 }

◆ rowCount()

int TopLevelWindowModel::rowCount ( const QModelIndex & parent = QModelIndex()) const
override

Definition at line 625 of file TopLevelWindowModel.cpp.

626{
627 return m_windowModel.count();
628}

◆ setApplicationManager()

void TopLevelWindowModel::setApplicationManager ( lomiri::shell::application::ApplicationManagerInterface * )

Definition at line 65 of file TopLevelWindowModel.cpp.

66{
67 if (m_applicationManager == value) {
68 return;
69 }
70
71 DEBUG_MSG << "(" << value << ")";
72
73 Q_ASSERT(m_modelState == IdleState);
74 m_modelState = ResettingState;
75
76 beginResetModel();
77
78 if (m_applicationManager) {
79 disconnect(m_applicationManager, 0, this, 0);
80 }
81
82 m_applicationManager = value;
83
84 if (m_applicationManager) {
85 connect(m_applicationManager, &QAbstractItemModel::rowsInserted,
86 this, [this](const QModelIndex &/*parent*/, int first, int last) {
87 if (!m_workspace || !m_workspace->isActive())
88 return;
89
90 for (int i = first; i <= last; ++i) {
91 auto application = m_applicationManager->get(i);
92 addApplication(application);
93 }
94 });
95
96 connect(m_applicationManager, &QAbstractItemModel::rowsAboutToBeRemoved,
97 this, [this](const QModelIndex &/*parent*/, int first, int last) {
98 for (int i = first; i <= last; ++i) {
99 auto application = m_applicationManager->get(i);
100 removeApplication(application);
101 }
102 });
103 }
104
105 refreshWindows();
106
107 endResetModel();
108 m_modelState = IdleState;
109}

◆ setRootFocus()

void TopLevelWindowModel::setRootFocus ( bool focus)

Definition at line 911 of file TopLevelWindowModel.cpp.

912{
913 DEBUG_MSG << "(" << focus << "), surfaceManagerBusy is " << m_surfaceManagerBusy;
914
915 if (m_surfaceManagerBusy) {
916 // Something else is probably being focused already, let's not add to
917 // the noise.
918 return;
919 }
920
921 if (focus) {
922 // Give focus back to previous focused window, only if null window is focused.
923 // If null window is not focused, a different app had taken the focus and we
924 // should repect that, or if a pendingActivation is going on.
925 if (m_previousWindow && !m_previousWindow->focused() && !m_pendingActivation &&
926 m_nullWindow == m_focusedWindow && m_previousWindow != m_nullWindow) {
927 m_previousWindow->activate();
928 } else if (!m_pendingActivation) {
929 // The previous window does not exist any more, focus top window.
930 activateTopMostWindowWithoutId(-1);
931 }
932 } else {
933 if (!m_nullWindow->focused()) {
934 m_nullWindow->activate();
935 }
936 }
937}

◆ setSurfaceManager()

void TopLevelWindowModel::setSurfaceManager ( lomiri::shell::application::SurfaceManagerInterface * )

Definition at line 111 of file TopLevelWindowModel.cpp.

112{
113 if (surfaceManager == m_surfaceManager) {
114 return;
115 }
116
117 DEBUG_MSG << "(" << surfaceManager << ")";
118
119 Q_ASSERT(m_modelState == IdleState);
120 m_modelState = ResettingState;
121
122 beginResetModel();
123
124 if (m_surfaceManager) {
125 disconnect(m_surfaceManager, 0, this, 0);
126 }
127
128 m_surfaceManager = surfaceManager;
129
130 if (m_surfaceManager) {
131 connect(m_surfaceManager, &lomiriapi::SurfaceManagerInterface::surfacesAddedToWorkspace, this, &TopLevelWindowModel::onSurfacesAddedToWorkspace);
132 connect(m_surfaceManager, &lomiriapi::SurfaceManagerInterface::surfacesRaised, this, &TopLevelWindowModel::onSurfacesRaised);
133 connect(m_surfaceManager, &lomiriapi::SurfaceManagerInterface::surfaceRemoved, this, &TopLevelWindowModel::onSurfaceDestroyed);
134 connect(m_surfaceManager, &lomiriapi::SurfaceManagerInterface::modificationsStarted, this, &TopLevelWindowModel::onModificationsStarted);
135 connect(m_surfaceManager, &lomiriapi::SurfaceManagerInterface::modificationsEnded, this, &TopLevelWindowModel::onModificationsEnded);
136 }
137
138 refreshWindows();
139
140 endResetModel();
141 m_modelState = IdleState;
142}

◆ surfaceAt()

lomiriapi::MirSurfaceInterface * TopLevelWindowModel::surfaceAt ( int index) const

Returns the surface at the given index.

It will be a nullptr if the application is still starting up and thus hasn't yet created and drawn into a surface.

Same as windowAt(index).surface()

Definition at line 694 of file TopLevelWindowModel.cpp.

695{
696 if (index >=0 && index < m_windowModel.count()) {
697 return m_windowModel[index].window->surface();
698 } else {
699 return nullptr;
700 }
701}

◆ windowAt()

Window * TopLevelWindowModel::windowAt ( int index) const

Returns the window at the given index.

Will always be valid

Definition at line 685 of file TopLevelWindowModel.cpp.

686{
687 if (index >=0 && index < m_windowModel.count()) {
688 return m_windowModel[index].window;
689 } else {
690 return nullptr;
691 }
692}

Property Documentation

◆ count

int TopLevelWindowModel::count
read

Number of top-level surfaces in this model.

This is the same as rowCount, added in order to keep compatibility with QML ListModels.

Definition at line 68 of file TopLevelWindowModel.h.

◆ focusedWindow

Window* TopLevelWindowModel::focusedWindow
read

The currently focused window, if any.

Definition at line 80 of file TopLevelWindowModel.h.

◆ inputMethodSurface

lomiri::shell::application::MirSurfaceInterface* TopLevelWindowModel::inputMethodSurface
read

The input method surface, if any.

The surface of a onscreen keyboard (akak "virtual keyboard") would be kept here and not in the model itself.

Definition at line 75 of file TopLevelWindowModel.h.

◆ nextId

int TopLevelWindowModel::nextId
read

The id to be used on the next entry created Useful for tests

Definition at line 86 of file TopLevelWindowModel.h.

◆ rootFocus

bool TopLevelWindowModel::rootFocus
readwrite

Sets whether a user Window or "nothing" should be focused.

This implementation of TLWM must have something focused. However, the user may wish to have nothing in some cases - for example, when they minimize all their windows on the desktop or unfocus the app they're using by clicking the background or indicators.

Unsetting rootFocus effectively focuses "nothing" by setting up a Window that has no displayable Surfaces and bringing it into focus.

Setting rootFocus attempts to focus the Window which was focused last - unless another app is attempting to gain focus (as determined by pendingActivation) and that's why we got rootFocus.

If the previously-focused Window was closed before rootFocus was set, the next available window will be focused.

Definition at line 107 of file TopLevelWindowModel.h.


The documentation for this class was generated from the following files: