File indexing completed on 2024-12-22 05:17:15
0001 /* 0002 * This file is part of the KDE wacomtablet project. For copyright 0003 * information and license terms see the AUTHORS and COPYING files 0004 * in the top-level directory of this distribution. 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #include "screensinfo.h" 0021 0022 #include <QApplication> 0023 #include <QScreen> 0024 0025 namespace Wacom 0026 { 0027 0028 namespace ScreensInfo 0029 { 0030 0031 const QRect getUnifiedDisplayGeometry() 0032 { 0033 QRect unitedScreen(0, 0, 0, 0); 0034 for (const auto &screen : getScreenGeometries()) { 0035 unitedScreen = unitedScreen.united(screen); 0036 } 0037 0038 return unitedScreen; 0039 } 0040 0041 const QMap<QString, QRect> getScreenGeometries() 0042 { 0043 QMap<QString, QRect> screenGeometries; 0044 for (auto screen : QGuiApplication::screens()) { 0045 QRect geometry = screen->geometry(); 0046 screenGeometries[screen->name()] = QRect(geometry.topLeft(), geometry.size() * screen->devicePixelRatio()); 0047 } 0048 0049 return screenGeometries; 0050 } 0051 0052 const ScreenRotation getScreenRotation(QString output) 0053 { 0054 for (const auto &screen : QGuiApplication::screens()) { 0055 if (screen->name() == output) { 0056 switch (screen->orientation()) { 0057 case Qt::PrimaryOrientation: 0058 case Qt::LandscapeOrientation: 0059 return ScreenRotation::NONE; 0060 case Qt::PortraitOrientation: 0061 return ScreenRotation::CW; 0062 case Qt::InvertedLandscapeOrientation: 0063 return ScreenRotation::HALF; 0064 case Qt::InvertedPortraitOrientation: 0065 return ScreenRotation::CCW; 0066 } 0067 } 0068 } 0069 0070 return ScreenRotation::NONE; 0071 } 0072 0073 const QString getPrimaryScreenName() 0074 { 0075 return QGuiApplication::primaryScreen()->name(); 0076 } 0077 0078 const QString getNextScreenName(QString output) 0079 { 0080 const auto screenNames = getScreenGeometries().keys(); 0081 const auto index = screenNames.indexOf(output); 0082 0083 if (index >= screenNames.size() - 1) { 0084 return screenNames.at(0); 0085 } else { 0086 return screenNames.at(index + 1); 0087 } 0088 } 0089 0090 } 0091 0092 }