Unity 8
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 (unity::shell::application::MirSurfaceInterface *inputMethodSurface)
 
void focusedWindowChanged (Window *focusedWindow)
 
void listChanged ()
 Emitted when the list changes. More...
 
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
 
unity::shell::application::MirSurfaceInterface * inputMethodSurface () const
 
WindowfocusedWindow () const
 
int nextId () const
 
Q_INVOKABLE unity::shell::application::MirSurfaceInterface * surfaceAt (int index) const
 Returns the surface at the given index. More...
 
Q_INVOKABLE WindowwindowAt (int index) const
 Returns the window at the given index. More...
 
Q_INVOKABLE unity::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. More...
 
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 (unity::shell::application::ApplicationManagerInterface *)
 
void setSurfaceManager (unity::shell::application::SurfaceManagerInterface *)
 
void setRootFocus (bool focus)
 
bool rootFocus ()
 

Properties

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

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

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  };

Member Function Documentation

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

652 {
653  for (int i = 0; i < m_windowModel.count(); ++i) {
654  if (m_windowModel[i].window->id() == id) {
655  return i;
656  }
657  }
658  return -1;
659 }
void TopLevelWindowModel::listChanged ( )
signal

Emitted when the list changes.

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

unityapi::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 670 of file TopLevelWindowModel.cpp.

671 {
672  if (index >=0 && index < m_windowModel.count()) {
673  return m_windowModel[index].window->surface();
674  } else {
675  return nullptr;
676  }
677 }
Window * TopLevelWindowModel::windowAt ( int  index) const

Returns the window at the given index.

Will always be valid

Definition at line 661 of file TopLevelWindowModel.cpp.

662 {
663  if (index >=0 && index < m_windowModel.count()) {
664  return m_windowModel[index].window;
665  } else {
666  return nullptr;
667  }
668 }

Property Documentation

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.

unityapi::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.

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.

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: