KWin
Loading...
Searching...
No Matches
screen.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include "screen.h"
10#include "core/output.h"
11#include "integration.h"
12#include "logging.h"
13#include "platformcursor.h"
14
15#include <qpa/qwindowsysteminterface.h>
16
17namespace KWin
18{
19namespace QPA
20{
21
22static int forcedDpi()
23{
24 return qEnvironmentVariableIsSet("QT_WAYLAND_FORCE_DPI") ? qEnvironmentVariableIntValue("QT_WAYLAND_FORCE_DPI") : -1;
25}
26
27Screen::Screen(Output *output, Integration *integration)
28 : m_output(output)
29 , m_cursor(new PlatformCursor)
30 , m_integration(integration)
31{
32 connect(output, &Output::geometryChanged, this, &Screen::handleGeometryChanged);
33}
34
35Screen::~Screen() = default;
36
37QList<QPlatformScreen *> Screen::virtualSiblings() const
38{
39 const auto screens = m_integration->screens();
40
41 QList<QPlatformScreen *> siblings;
42 siblings.reserve(siblings.size());
43
44 for (Screen *screen : screens) {
45 siblings << screen;
46 }
47
48 return siblings;
49}
50
51int Screen::depth() const
52{
53 return 32;
54}
55
56QImage::Format Screen::format() const
57{
58 return QImage::Format_ARGB32_Premultiplied;
59}
60
61QRect Screen::geometry() const
62{
63 if (Q_UNLIKELY(!m_output)) {
64 qCCritical(KWIN_QPA) << "Attempting to get the geometry of a destroyed output";
65 return QRect();
66 }
67 return m_output->geometry();
68}
69
71{
72 if (Q_UNLIKELY(!m_output)) {
73 qCCritical(KWIN_QPA) << "Attempting to get the physical size of a destroyed output";
74 return QSizeF();
75 }
76 return m_output->physicalSize();
77}
78
79QPlatformCursor *Screen::cursor() const
80{
81 return m_cursor.get();
82}
83
85{
86 const int dpi = forcedDpi();
87 return dpi > 0 ? QDpi(dpi, dpi) : QDpi(96, 96);
88}
89
91{
92 if (Q_UNLIKELY(!m_output)) {
93 qCCritical(KWIN_QPA) << "Attempting to get the scale factor of a destroyed output";
94 return 1;
95 }
96 return m_output->scale();
97}
98
99QString Screen::name() const
100{
101 if (Q_UNLIKELY(!m_output)) {
102 qCCritical(KWIN_QPA) << "Attempting to get the name of a destroyed output";
103 return QString();
104 }
105 return m_output->name();
106}
107
108void Screen::handleGeometryChanged()
109{
110 QWindowSystemInterface::handleScreenGeometryChange(screen(), geometry(), geometry());
111}
112
114{
115 const int dpi = forcedDpi();
116 return dpi > 0 ? QDpi(dpi, dpi) : QDpi(96, 96);
117}
118
119}
120}
121
122#include "moc_screen.cpp"
void geometryChanged()
QHash< Output *, Screen * > screens() const
QDpi logicalDpi() const override
Definition screen.cpp:113
~Screen() override
QSizeF physicalSize() const override
Definition screen.cpp:70
QPlatformCursor * cursor() const override
Definition screen.cpp:79
Screen(Output *output, Integration *integration)
Definition screen.cpp:27
qreal devicePixelRatio() const override
Definition screen.cpp:90
QImage::Format format() const override
Definition screen.cpp:56
QList< QPlatformScreen * > virtualSiblings() const override
Definition screen.cpp:37
QString name() const override
Definition screen.cpp:99
QRect geometry() const override
Definition screen.cpp:61
int depth() const override
Definition screen.cpp:51
QDpi logicalDpi() const override
Definition screen.cpp:84