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

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

◆ closeAllWindows()

void TopLevelWindowModel::closeAllWindows ( )

Closes all windows, emits closedAllWindows when done.

Definition at line 875 of file TopLevelWindowModel.cpp.

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

◆ data()

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

Definition at line 613 of file TopLevelWindowModel.cpp.

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

◆ focusedWindow()

Window * TopLevelWindowModel::focusedWindow ( ) const

Definition at line 761 of file TopLevelWindowModel.cpp.

762{
763 return m_focusedWindow;
764}

◆ idAt()

int TopLevelWindowModel::idAt ( int  index) const

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

Definition at line 695 of file TopLevelWindowModel.cpp.

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

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

659{
660 for (int i = 0; i < m_windowModel.count(); ++i) {
661 if (m_windowModel[i].window->id() == id) {
662 return i;
663 }
664 }
665 return -1;
666}

◆ inputMethodSurface()

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

Definition at line 756 of file TopLevelWindowModel.cpp.

757{
758 return m_inputMethodWindow ? m_inputMethodWindow->surface() : nullptr;
759}
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 927 of file TopLevelWindowModel.cpp.

928{
929 m_pendingActivation = true;
930}

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

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

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

609{
610 return m_windowModel.count();
611}

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

895{
896 DEBUG_MSG << "(" << focus << "), surfaceManagerBusy is " << m_surfaceManagerBusy;
897
898 if (m_surfaceManagerBusy) {
899 // Something else is probably being focused already, let's not add to
900 // the noise.
901 return;
902 }
903
904 if (focus) {
905 // Give focus back to previous focused window, only if null window is focused.
906 // If null window is not focused, a different app had taken the focus and we
907 // should repect that, or if a pendingActivation is going on.
908 if (m_previousWindow && !m_previousWindow->focused() && !m_pendingActivation &&
909 m_nullWindow == m_focusedWindow && m_previousWindow != m_nullWindow) {
910 m_previousWindow->activate();
911 } else if (!m_pendingActivation) {
912 // The previous window does not exist any more, focus top window.
913 activateTopMostWindowWithoutId(-1);
914 }
915 } else {
916 if (!m_nullWindow->focused()) {
917 m_nullWindow->activate();
918 }
919 }
920}
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 677 of file TopLevelWindowModel.cpp.

678{
679 if (index >=0 && index < m_windowModel.count()) {
680 return m_windowModel[index].window->surface();
681 } else {
682 return nullptr;
683 }
684}

◆ windowAt()

Window * TopLevelWindowModel::windowAt ( int  index) const

Returns the window at the given index.

Will always be valid

Definition at line 668 of file TopLevelWindowModel.cpp.

669{
670 if (index >=0 && index < m_windowModel.count()) {
671 return m_windowModel[index].window;
672 } else {
673 return nullptr;
674 }
675}

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: