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

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

#include <plugins/WindowManager/TopLevelWindowModel.h>

Inherits QAbstractListModel.

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 691 of file TopLevelWindowModel.cpp.

692{
693 if (index >=0 && index < m_windowModel.count()) {
694 return m_windowModel[index].application;
695 } else {
696 return nullptr;
697 }
698}

◆ closeAllWindows()

void TopLevelWindowModel::closeAllWindows ( )

Closes all windows, emits closedAllWindows when done.

Definition at line 880 of file TopLevelWindowModel.cpp.

881{
882 m_closingAllApps = true;
883 for (auto win : m_windowModel) {
884 win.window->close();
885 }
886
887 // This is done after the for loop in the unlikely event that
888 // an app starts in between this
889 if (m_windowModel.isEmpty()) {
890 Q_EMIT closedAllWindows();
891 }
892}

◆ data()

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

Definition at line 618 of file TopLevelWindowModel.cpp.

619{
620 if (index.row() < 0 || index.row() >= m_windowModel.size())
621 return QVariant();
622
623 if (role == WindowRole) {
624 Window *window = m_windowModel.at(index.row()).window;
625 return QVariant::fromValue(window);
626 } else if (role == ApplicationRole) {
627 return QVariant::fromValue(m_windowModel.at(index.row()).application);
628 } else {
629 return QVariant();
630 }
631}
A slightly higher concept than MirSurface.
Definition Window.h:48

◆ focusedWindow()

Window * TopLevelWindowModel::focusedWindow ( ) const

Definition at line 766 of file TopLevelWindowModel.cpp.

767{
768 return m_focusedWindow;
769}

◆ idAt()

int TopLevelWindowModel::idAt ( int  index) const

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

Definition at line 700 of file TopLevelWindowModel.cpp.

701{
702 if (index >=0 && index < m_windowModel.count()) {
703 return m_windowModel[index].window->id();
704 } else {
705 return 0;
706 }
707}

◆ 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 663 of file TopLevelWindowModel.cpp.

664{
665 for (int i = 0; i < m_windowModel.count(); ++i) {
666 if (m_windowModel[i].window->id() == id) {
667 return i;
668 }
669 }
670 return -1;
671}

◆ inputMethodSurface()

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

Definition at line 761 of file TopLevelWindowModel.cpp.

762{
763 return m_inputMethodWindow ? m_inputMethodWindow->surface() : nullptr;
764}
lomiri::shell::application::MirSurfaceInterface * surface
Surface backing up this window It might be null if a surface hasn't been created yet (application is ...
Definition Window.h:92

◆ 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 932 of file TopLevelWindowModel.cpp.

933{
934 m_pendingActivation = true;
935}

◆ 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 709 of file TopLevelWindowModel.cpp.

710{
711 if (m_modelState == IdleState) {
712 DEBUG_MSG << "(id=" << id << ") - do it now.";
713 doRaiseId(id);
714 } else {
715 DEBUG_MSG << "(id=" << id << ") - Model busy (modelState=" << m_modelState << "). Try again in the next event loop.";
716 // The model has just signalled some change. If we have a Repeater responding to this update, it will get nuts
717 // if we perform yet another model change straight away.
718 //
719 // A bad sympton of this problem is a Repeater.itemAt(index) call returning null event though Repeater.count says
720 // the index is definitely within bounds.
721 QMetaObject::invokeMethod(this, "raiseId", Qt::QueuedConnection, Q_ARG(int, id));
722 }
723}

◆ 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 613 of file TopLevelWindowModel.cpp.

614{
615 return m_windowModel.count();
616}

◆ 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 899 of file TopLevelWindowModel.cpp.

900{
901 DEBUG_MSG << "(" << focus << "), surfaceManagerBusy is " << m_surfaceManagerBusy;
902
903 if (m_surfaceManagerBusy) {
904 // Something else is probably being focused already, let's not add to
905 // the noise.
906 return;
907 }
908
909 if (focus) {
910 // Give focus back to previous focused window, only if null window is focused.
911 // If null window is not focused, a different app had taken the focus and we
912 // should repect that, or if a pendingActivation is going on.
913 if (m_previousWindow && !m_previousWindow->focused() && !m_pendingActivation &&
914 m_nullWindow == m_focusedWindow && m_previousWindow != m_nullWindow) {
915 m_previousWindow->activate();
916 } else if (!m_pendingActivation) {
917 // The previous window does not exist any more, focus top window.
918 activateTopMostWindowWithoutId(-1);
919 }
920 } else {
921 if (!m_nullWindow->focused()) {
922 m_nullWindow->activate();
923 }
924 }
925}
bool focused
Whether the surface is focused.
Definition Window.h:71
void activate()
Focuses and raises the window.
Definition Window.cpp:137

◆ 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 682 of file TopLevelWindowModel.cpp.

683{
684 if (index >=0 && index < m_windowModel.count()) {
685 return m_windowModel[index].window->surface();
686 } else {
687 return nullptr;
688 }
689}

◆ windowAt()

Window * TopLevelWindowModel::windowAt ( int  index) const

Returns the window at the given index.

Will always be valid

Definition at line 673 of file TopLevelWindowModel.cpp.

674{
675 if (index >=0 && index < m_windowModel.count()) {
676 return m_windowModel[index].window;
677 } else {
678 return nullptr;
679 }
680}

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: