Set wayland output scale

Summary:
Provides a virtual method in Screens where backends can supply the scale
of each screen, this is then set on each output.

For the X windowed backend this value is taken from a command line
parameter.

Test Plan:
Ran windowed mode with --scale 1 and 2
then kate --platform=wayland from another screen.
On the latter case UI elements were scaled up correctly

Reviewers: #plasma

Subscribers: plasma-devel, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D3159
icc-effect-5.14.5
David Edmundson 2016-10-26 00:36:02 +01:00
parent e7b27ab955
commit fd58c68ba5
8 changed files with 68 additions and 0 deletions

View File

@ -526,6 +526,12 @@ int main(int argc, char * argv[])
i18n("The height for windowed mode. Default height is 768."),
QStringLiteral("height"));
heightOption.setDefaultValue(QString::number(768));
QCommandLineOption scaleOption(QStringLiteral("scale"),
i18n("The scale for windowed mode. Default value is 1."),
QStringLiteral("scale"));
scaleOption.setDefaultValue(QString::number(1));
QCommandLineOption outputCountOption(QStringLiteral("output-count"),
i18n("The number of windows to open as outputs in windowed mode. Default value is 1"),
QStringLiteral("height"));
@ -554,6 +560,7 @@ int main(int argc, char * argv[])
if (hasSizeOption) {
parser.addOption(widthOption);
parser.addOption(heightOption);
parser.addOption(scaleOption);
}
if (hasOutputCountOption) {
parser.addOption(outputCountOption);
@ -632,6 +639,7 @@ int main(int argc, char * argv[])
QSize initialWindowSize;
QByteArray deviceIdentifier;
int outputCount = 1;
qreal outputScale = 1;
#if HAVE_DRM
if (hasDrmOption && parser.isSet(drmOption)) {
@ -651,6 +659,13 @@ int main(int argc, char * argv[])
std::cerr << "FATAL ERROR incorrect value for height" << std::endl;
return 1;
}
const qreal scale = parser.value(scaleOption).toDouble(&ok);
if (!ok || scale < 1) {
std::cerr << "FATAL ERROR incorrect value for scale" << std::endl;
return 1;
}
outputScale = scale;
initialWindowSize = QSize(width, height);
}
@ -732,6 +747,7 @@ int main(int argc, char * argv[])
if (initialWindowSize.isValid()) {
a.platform()->setInitialWindowSize(initialWindowSize);
}
a.platform()->setInitialOutputScale(outputScale);
a.platform()->setInitialOutputCount(outputCount);
QObject::connect(&a, &KWin::Application::workspaceCreated, server, &KWin::WaylandServer::initWorkspace);

View File

@ -407,6 +407,11 @@ QVector<QRect> Platform::screenGeometries() const
return QVector<QRect>({QRect(QPoint(0, 0), screenSize())});
}
QVector<qreal> Platform::screenScales() const
{
return QVector<qreal>({1});
}
bool Platform::requiresCompositing() const
{
return true;

View File

@ -106,6 +106,14 @@ public:
* Base implementation returns one QRect positioned at 0/0 with screenSize() as size.
**/
virtual QVector<QRect> screenGeometries() const;
/**
* Implementing subclasses should provide all geometries in case the backend represents
* a basic screen and uses the BasicScreens.
*
* Base implementation returns a screen with a scale of 1.
**/
virtual QVector<qreal> screenScales() const;
/**
* Implement this method to receive configuration change requests through KWayland's
* OutputManagement interface.
@ -286,6 +294,12 @@ public:
void setInitialOutputCount(int count) {
m_initialOutputCount = count;
}
qreal initialOutputScale() const {
return m_initialOutputScale;
}
void setInitialOutputScale(qreal scale) {
m_initialOutputScale = scale;
}
public Q_SLOTS:
void pointerMotion(const QPointF &position, quint32 time);
@ -377,6 +391,7 @@ private:
bool m_pointerWarping = false;
bool m_outputsEnabled = true;
int m_initialOutputCount = 1;
qreal m_initialOutputScale = 1;
EGLDisplay m_eglDisplay;
int m_hideCursorCounter = 0;
};

View File

@ -472,4 +472,11 @@ QVector<QRect> X11WindowedBackend::screenGeometries() const
return ret;
}
QVector<qreal> X11WindowedBackend::screenScales() const
{
QVector<qreal> ret;
ret.fill(initialOutputScale(), m_windows.count());
return ret;
}
}

View File

@ -47,6 +47,7 @@ public:
virtual ~X11WindowedBackend();
void init() override;
QVector<QRect> screenGeometries() const override;
QVector<qreal> screenScales() const override;
xcb_connection_t *connection() const {
return m_connection;

View File

@ -91,6 +91,13 @@ float Screens::refreshRate(int screen) const
return 60.0f;
}
qreal Screens::scale(int screen) const
{
Q_UNUSED(screen)
qCWarning(KWIN_CORE, "%s::scale(qreal screen) is a stub, please reimplement it!", metaObject()->className());
return 1;
}
void Screens::reconfigure()
{
if (!m_config) {
@ -213,9 +220,18 @@ QSize BasicScreens::size(int screen) const
return QSize();
}
qreal BasicScreens::scale(int screen) const
{
if (screen < m_scales.count()) {
return m_scales.at(screen);
}
return 1;
}
void BasicScreens::updateCount()
{
m_geometries = m_backend->screenGeometries();
m_scales = m_backend->screenScales();
setCount(m_geometries.count());
}

View File

@ -86,6 +86,11 @@ public:
* @see size()
**/
virtual QSize size(int screen) const = 0;
/*
* The output scale for this display, for use by high DPI displays
*/
virtual qreal scale(int screen) const;
/**
* The bounding size of all screens combined. Overlapping areas
* are not counted multiple times.
@ -164,11 +169,13 @@ public:
QRect geometry(int screen) const override;
int number(const QPoint &pos) const override;
QSize size(int screen) const override;
qreal scale(int screen) const override;
void updateCount() override;
private:
Platform *m_backend;
QVector<QRect> m_geometries;
QVector<qreal> m_scales;
};
inline

View File

@ -370,6 +370,7 @@ void WaylandServer::syncOutputsToWayland()
Q_ASSERT(s);
for (int i = 0; i < s->count(); ++i) {
OutputInterface *output = m_display->createOutput(m_display);
output->setScale(s->scale(i));
const QRect &geo = s->geometry(i);
output->setGlobalPosition(geo.topLeft());
output->setPhysicalSize(geo.size() / 3.8);