File indexing completed on 2024-11-10 04:57:06
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #include "screen.h" 0010 #include "core/output.h" 0011 #include "integration.h" 0012 #include "logging.h" 0013 #include "platformcursor.h" 0014 0015 #include <qpa/qwindowsysteminterface.h> 0016 0017 namespace KWin 0018 { 0019 namespace QPA 0020 { 0021 0022 static int forcedDpi() 0023 { 0024 return qEnvironmentVariableIsSet("QT_WAYLAND_FORCE_DPI") ? qEnvironmentVariableIntValue("QT_WAYLAND_FORCE_DPI") : -1; 0025 } 0026 0027 Screen::Screen(Output *output, Integration *integration) 0028 : m_output(output) 0029 , m_cursor(new PlatformCursor) 0030 , m_integration(integration) 0031 { 0032 connect(output, &Output::geometryChanged, this, &Screen::handleGeometryChanged); 0033 } 0034 0035 Screen::~Screen() = default; 0036 0037 QList<QPlatformScreen *> Screen::virtualSiblings() const 0038 { 0039 const auto screens = m_integration->screens(); 0040 0041 QList<QPlatformScreen *> siblings; 0042 siblings.reserve(siblings.size()); 0043 0044 for (Screen *screen : screens) { 0045 siblings << screen; 0046 } 0047 0048 return siblings; 0049 } 0050 0051 int Screen::depth() const 0052 { 0053 return 32; 0054 } 0055 0056 QImage::Format Screen::format() const 0057 { 0058 return QImage::Format_ARGB32_Premultiplied; 0059 } 0060 0061 QRect Screen::geometry() const 0062 { 0063 if (Q_UNLIKELY(!m_output)) { 0064 qCCritical(KWIN_QPA) << "Attempting to get the geometry of a destroyed output"; 0065 return QRect(); 0066 } 0067 return m_output->geometry(); 0068 } 0069 0070 QSizeF Screen::physicalSize() const 0071 { 0072 if (Q_UNLIKELY(!m_output)) { 0073 qCCritical(KWIN_QPA) << "Attempting to get the physical size of a destroyed output"; 0074 return QSizeF(); 0075 } 0076 return m_output->physicalSize(); 0077 } 0078 0079 QPlatformCursor *Screen::cursor() const 0080 { 0081 return m_cursor.get(); 0082 } 0083 0084 QDpi Screen::logicalDpi() const 0085 { 0086 const int dpi = forcedDpi(); 0087 return dpi > 0 ? QDpi(dpi, dpi) : QDpi(96, 96); 0088 } 0089 0090 qreal Screen::devicePixelRatio() const 0091 { 0092 if (Q_UNLIKELY(!m_output)) { 0093 qCCritical(KWIN_QPA) << "Attempting to get the scale factor of a destroyed output"; 0094 return 1; 0095 } 0096 return m_output->scale(); 0097 } 0098 0099 QString Screen::name() const 0100 { 0101 if (Q_UNLIKELY(!m_output)) { 0102 qCCritical(KWIN_QPA) << "Attempting to get the name of a destroyed output"; 0103 return QString(); 0104 } 0105 return m_output->name(); 0106 } 0107 0108 void Screen::handleGeometryChanged() 0109 { 0110 QWindowSystemInterface::handleScreenGeometryChange(screen(), geometry(), geometry()); 0111 } 0112 0113 QDpi PlaceholderScreen::logicalDpi() const 0114 { 0115 const int dpi = forcedDpi(); 0116 return dpi > 0 ? QDpi(dpi, dpi) : QDpi(96, 96); 0117 } 0118 0119 } 0120 } 0121 0122 #include "moc_screen.cpp"