1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
|
/*
* Copyright (C) 2017 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3, as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Screen.h"
#include "Screens.h"
#include "WorkspaceManager.h"
#include "Workspace.h"
Screen::Screen(QObject *parent)
: QObject(parent)
{
}
void Screen::connectToScreen(qtmir::Screen *screen)
{
m_wrapped = screen;
connect(screen, &qtmir::Screen::usedChanged, this, &Screen::usedChanged);
connect(screen, &qtmir::Screen::nameChanged, this, &Screen::nameChanged);
connect(screen, &qtmir::Screen::outputTypeChanged, this, &Screen::outputTypeChanged);
connect(screen, &qtmir::Screen::outputTypeChanged, this, &Screen::outputTypeNameChanged);
connect(screen, &qtmir::Screen::scaleChanged, this, &Screen::scaleChanged);
connect(screen, &qtmir::Screen::formFactorChanged, this, &Screen::formFactorChanged);
connect(screen, &qtmir::Screen::physicalSizeChanged, this, &Screen::physicalSizeChanged);
connect(screen, &qtmir::Screen::positionChanged, this, &Screen::positionChanged);
connect(screen, &qtmir::Screen::activeChanged, this, &Screen::activeChanged);
connect(screen, &qtmir::Screen::currentModeIndexChanged, this, &Screen::currentModeIndexChanged);
connect(screen, &qtmir::Screen::availableModesChanged, this, &Screen::availableModesChanged);
}
void Screen::connectToScreen(Screen *screen)
{
connectToScreen(screen->wrapped());
connect(screen, &Screen::currentWorkspaceChanged, this, &Screen::currentWorkspaceChanged);
}
void Screen::setCurrentWorkspace2(Workspace *workspace)
{
// Make sure we use the correct concrete class. Don't want to use a Proxy.
workspace->setCurrentOn(this);
}
bool Screen::used() const
{
if (!m_wrapped) return false;
return m_wrapped->used();
}
QString Screen::name() const
{
if (!m_wrapped) return QString();
return m_wrapped->name();
}
float Screen::scale() const
{
if (!m_wrapped) return 1.0;
return m_wrapped->scale();
}
QSizeF Screen::physicalSize() const
{
if (!m_wrapped) return QSizeF();
return m_wrapped->physicalSize();
}
Screen::FormFactor Screen::formFactor() const
{
if (!m_wrapped) return static_cast<Screen::FormFactor>(qtmir::FormFactorUnknown);
return static_cast<Screen::FormFactor>(m_wrapped->formFactor());
}
qtmir::OutputTypes Screen::outputType() const
{
if (!m_wrapped) return qtmir::Unknown;
return m_wrapped->outputType();
}
MirPowerMode Screen::powerMode() const
{
if (!m_wrapped) return mir_power_mode_on;
return m_wrapped->powerMode();
}
Qt::ScreenOrientation Screen::orientation() const
{
if (!m_wrapped) return Qt::PrimaryOrientation;
return m_wrapped->orientation();
}
QPoint Screen::position() const
{
if (!m_wrapped) return QPoint();
return m_wrapped->position();
}
QQmlListProperty<qtmir::ScreenMode> Screen::availableModes()
{
if (!m_wrapped) return QQmlListProperty<qtmir::ScreenMode>();
return m_wrapped->availableModes();
}
uint Screen::currentModeIndex() const
{
if (!m_wrapped) return -1;
return m_wrapped->currentModeIndex();
}
bool Screen::isActive() const
{
if (!m_wrapped) return false;
return m_wrapped->isActive();
}
void Screen::activate()
{
setActive(true);
}
void Screen::setActive(bool active)
{
if (!m_wrapped) return;
m_wrapped->setActive(active);
}
QScreen *Screen::qscreen() const
{
if (!m_wrapped) return nullptr;
return m_wrapped->qscreen();
}
ScreenConfig *Screen::beginConfiguration() const
{
if (!m_wrapped) return nullptr;
return new ScreenConfig(m_wrapped->beginConfiguration());
}
bool Screen::applyConfiguration(ScreenConfig *configuration)
{
if (!m_wrapped) return false;
return m_wrapped->applyConfiguration(configuration->m_config);
}
QString Screen::outputTypeName() const
{
switch (m_wrapped->outputType()) {
case qtmir::Unknown:
return tr("Unknown");
case qtmir::VGA:
return tr("VGA");
case qtmir::DVII:
case qtmir::DVID:
case qtmir::DVIA:
return tr("DVI");
case qtmir::Composite:
return tr("Composite");
case qtmir::SVideo:
return tr("S-Video");
case qtmir::LVDS:
case qtmir::NinePinDIN:
case qtmir::EDP:
case qtmir::DSI:
case qtmir::DPI:
return tr("Internal");
case qtmir::Component:
return tr("Component");
case qtmir::DisplayPort:
return tr("DisplayPort");
case qtmir::HDMIA:
case qtmir::HDMIB:
return tr("HDMI");
case qtmir::TV:
return tr("TV");
case qtmir::Virtual:
return tr("Virtual");
}
return QString();
}
bool Screen::isSameAs(Screen *screen) const
{
if (!screen) return false;
if (screen == this) return true;
return wrapped() == screen->wrapped();
}
void Screen::sync(Screen *proxy)
{
if (!proxy) return;
workspaces()->sync(proxy->workspaces());
}
ConcreteScreen::ConcreteScreen(qtmir::Screen* wrapped)
: m_workspaces(new WorkspaceModel)
{
connectToScreen(wrapped);
// Connect the active workspace to activate the screen.
connect(m_workspaces.data(), &WorkspaceModel::workspaceInserted, this, [this](int, Workspace* workspace) {
connect(workspace, &Workspace::activeChanged, this, [this, workspace](bool active) {
if (active) {
setCurrentWorkspace(workspace);
activate();
}
});
if (workspace->isActive()) {
activate();
setCurrentWorkspace(workspace);
}
if (!m_currentWorspace) {
setCurrentWorkspace(workspace);
}
});
connect(m_workspaces.data(), &WorkspaceModel::workspaceRemoved, this, [this](Workspace* workspace) {
disconnect(workspace, &Workspace::activeChanged, this, 0);
if (workspace == m_currentWorspace) {
resetCurrentWorkspace();
}
});
connect(this, &ConcreteScreen::activeChanged, this, [this](bool active) {
if (active && m_currentWorspace) {
m_currentWorspace->activate();
}
});
}
void ConcreteScreen::resetCurrentWorkspace()
{
auto newCurrent = m_workspaces->rowCount() > 0 ? m_workspaces->get(0) : nullptr;
if (m_currentWorspace != newCurrent) {
m_currentWorspace = newCurrent;
Q_EMIT currentWorkspaceChanged(newCurrent);
}
}
WorkspaceModel *ConcreteScreen::workspaces() const
{
return m_workspaces.data();
}
Workspace *ConcreteScreen::currentWorkspace() const
{
return m_currentWorspace.data();
}
void ConcreteScreen::setCurrentWorkspace(Workspace *workspace)
{
if (m_currentWorspace != workspace) {
m_currentWorspace = workspace;
Q_EMIT currentWorkspaceChanged(workspace);
}
}
ProxyScreen::ProxyScreen(Screen *const screen, ProxyScreens* screens)
: m_workspaces(new ProxyWorkspaceModel(screen->workspaces(), this))
, m_original(screen)
, m_screens(screens)
{
connectToScreen(screen);
auto updateCurrentWorkspaceFn = [this](Workspace* realWorkspace) {
Q_FOREACH(Workspace* workspace, m_workspaces->list()) {
auto p = qobject_cast<ProxyWorkspace*>(workspace);
if (p && p->proxyObject() == realWorkspace) {
if (m_currentWorspace != p) {
m_currentWorspace = p;
Q_EMIT currentWorkspaceChanged(p);
}
}
}
};
connect(screen, &Screen::currentWorkspaceChanged, this, updateCurrentWorkspaceFn);
updateCurrentWorkspaceFn(screen->currentWorkspace());
}
WorkspaceModel *ProxyScreen::workspaces() const
{
return m_workspaces.data();
}
Workspace *ProxyScreen::currentWorkspace() const
{
return m_currentWorspace.data();
}
void ProxyScreen::setCurrentWorkspace(Workspace *workspace)
{
auto p = qobject_cast<ProxyWorkspace*>(workspace);
if (p) {
m_original->setCurrentWorkspace(p->proxyObject());
}
}
bool ProxyScreen::isSyncing() const
{
return m_screens->isSyncing();
}
ScreenConfig::ScreenConfig(qtmir::ScreenConfiguration *config)
: m_config(config)
{
}
ScreenConfig::~ScreenConfig()
{
delete m_config;
}
|