diff --git a/kcm/kcm_kscreen.desktop.cmake b/kcm/kcm_kscreen.desktop.cmake index 85532eb..8ec697c 100644 --- a/kcm/kcm_kscreen.desktop.cmake +++ b/kcm/kcm_kscreen.desktop.cmake @@ -1,103 +1,106 @@ [Desktop Entry] Exec=kcmshell5 kcm_kscreen Icon=preferences-desktop-display-randr Type=Service X-KDE-ServiceTypes=KCModule X-KDE-Library=kcm_kscreen X-KDE-ParentApp=kcontrol X-KDE-System-Settings-Parent-Category=display X-KDE-Weight=40 X-KDE-PluginInfo-Version=@KSCREEN_VERSION@ Name=Displays Name[ca]=Pantalles Name[ca@valencia]=Pantalles Name[da]=Skærme Name[de]=Anzeigen Name[el]=Οθόνες Name[en_GB]=Displays Name[es]=Pantallas +Name[fi]=Näytöt Name[he]=תצוגות Name[it]=Schermi Name[nl]=Schermen +Name[nn]=Skjermar Name[pl]=Ekrany Name[pt]=Ecrãs Name[ru]=Экраны Name[sk]=Obrazovky Name[sl]=Zasloni Name[sv]=Bildskärmar Name[uk]=Дисплеї Name[x-test]=xxDisplaysxx +Name[zh_CN]=显示 Comment=Manage and configure monitors and displays Comment[ar]=أدر واضبط الشّاشات والعروض Comment[ast]=Xestiona y configura los monitores y pantalles Comment[bs]=Upravljanje i konfiguracija monitora i ekrana Comment[ca]=Gestiona i configura els monitors i pantalles Comment[ca@valencia]=Gestiona i configura els monitors i pantalles Comment[cs]=Spravovat a nastavit monitory a zobrazení Comment[da]=Håndtér og indstil monitorer og skærme Comment[de]=Verwaltung und Einrichtung vom Monitoren und Anzeigen Comment[el]=Διαχείριση και διαμόρφωση οθονών και απεικονίσεων Comment[en_GB]=Manage and configure monitors and displays Comment[es]=Gestionar y configurar monitores y pantallas Comment[et]=Monitoride ja ekraanide haldamine ja seadistamine Comment[fi]=Näyttöjen asetusten hallinta Comment[fr]=Gère et configure les moniteurs et les écrans Comment[gl]=Xestiona a configura os monitores e a resolución Comment[he]=נהל את הגדרות המסכים והתצוגות שלך Comment[hu]=Monitorok és kijelzők kezelése és beállítása Comment[it]=Gestisci e configura monitor e schermi Comment[ko]=모니터와 디스플레이 설정 및 관리 Comment[lt]=Tvarkyti ir konfigūruoti monitorius ir ekranus Comment[nb]=Håndter og sett opp monitorer og skjermer Comment[nl]=Monitoren en schermen beheren en instellen Comment[nn]=Set opp skjermar og skjermbilete Comment[pa]=ਮਾਨੀਟਰ ਤੇ ਡਿਸਪਲੇਅ ਦਾ ਪਰਬੰਧ ਤੇ ਸੰਰਚਨਾ ਕਰੋ Comment[pl]=Zarządzanie i ustawienia ekranów Comment[pt]=Faz a gestão e configuração dos monitores e ecrãs Comment[pt_BR]=Gerencia e configura monitores e telas Comment[ro]=Gestionează și configurează monitoare și afișaje Comment[ru]=Настройка экранов и видеовыходов Comment[sk]=Správa a nastavenie monitorov a obrazoviek Comment[sl]=Upravljajte in nastavljajte zaslone in prikazovalnike Comment[sr]=Управљање и подешавање монитора̂ и екрана̂ Comment[sr@ijekavian]=Управљање и подешавање монитора̂ и екрана̂ Comment[sr@ijekavianlatin]=Upravljanje i podešavanje monitorâ̂ i ekranâ̂ Comment[sr@latin]=Upravljanje i podešavanje monitorâ̂ i ekranâ̂ Comment[sv]=Hantera och ställ in bildskärmar Comment[tr]=Ekranları ve görüntüleri yönet, yapılandır Comment[uk]=Керування і налаштовування моніторів і дисплеїв Comment[x-test]=xxManage and configure monitors and displaysxx Comment[zh_CN]=管理和配置显示和监视器 Comment[zh_TW]=管理與設定螢幕與顯示 X-KDE-Keywords=display,monitor,scale,scaling,resolution,orientation,outputs X-KDE-Keywords[ast]=pantalla,pantalles,monitores,monitor,escalar,escala,escaláu,resolución,orientación,salíes,salida X-KDE-Keywords[ca]=pantalla,monitor,escala,escalat,resolució,orientació,sortides X-KDE-Keywords[ca@valencia]=pantalla,monitor,escala,escalat,resolució,orientació,eixides X-KDE-Keywords[da]=skærm,monitor,skaler,opløsning,orientering,output X-KDE-Keywords[de]=Anzeige,Monitor,Bildschirm,Skalierung,Auflösung,Ausrichtung,Ausgabe X-KDE-Keywords[el]=απεικόνιση,οθόνη,κλίμακα,κλιμάκωση,ανάλυση,προσανατολισμός,έξοδοι X-KDE-Keywords[en_GB]=display,monitor,scale,scaling,resolution,orientation,outputs X-KDE-Keywords[es]=pantalla,monitor,escala,escalado,resolución,orientación,salidas X-KDE-Keywords[et]=kuva,monitor,ekraan,skaleerimine,lahutusvõime,eraldusvõime,orientatsioon,väljundid X-KDE-Keywords[fi]=display,monitor,scale,scaling,resolution,orientation,outputs,näyttö,monitori,skaalaus,resoluutio,tarkkuus,suunta,kierto,ulostulot X-KDE-Keywords[fr]=affichage,moniteur,échelle,mise à l'échelle,résolution,orientation,sorties X-KDE-Keywords[gl]=display,pantalla,monitor,scale,escala,scaling,escalar,resolution,resolución,orientation,orientación,outputs,saída,saídas X-KDE-Keywords[it]=schermo,monitor,scala,riscalatura,risoluzione,orientazione,uscite X-KDE-Keywords[ko]=display,monitor,scale,scaling,resolution,orientation,outputs,디스플레이,모니터,비율,배율,해상도,출력,방향 X-KDE-Keywords[nl]=scherm,monitor,schaal,schalen,resolutie,oriëntatie,uitvoer X-KDE-Keywords[nn]=skjermbilete,skjerm,skala,skalering,oppløysing,skjermoppløysing,retning,utgang X-KDE-Keywords[pl]=wyświetlacz,monitor,skala,skalowanie,rozdzielczość,kierunek,orientacja,wyjścia X-KDE-Keywords[pt]=ecrã,monitor,escala,resolução,orientação,saídas X-KDE-Keywords[pt_BR]=tela,monitor,escala,ajuste,resolução,orientação,saídas X-KDE-Keywords[ru]=display,monitor,scale,scaling,resolution,orientation,outputs,экран,монитор,масштаб,разрешение,ориентация,выводы X-KDE-Keywords[sk]=displej,monitor,mierka,škálovanie,rozlíšenie,orientácia,výstupy X-KDE-Keywords[sl]=prikaz,zaslon,monitor,umerjanje,merilo,ločljivost,resolucija,orientacija,usmerjenost,izhodi X-KDE-Keywords[sr]=display,monitor,scale,scaling,resolution,oritentation,outputs,приказ,монитор,екран,скалирање,резолуција,оријентација,излаз X-KDE-Keywords[sr@ijekavian]=display,monitor,scale,scaling,resolution,oritentation,outputs,приказ,монитор,екран,скалирање,резолуција,оријентација,излаз X-KDE-Keywords[sr@ijekavianlatin]=display,monitor,scale,scaling,resolution,oritentation,outputs,prikaz,monitor,ekran,skaliranje,rezolucija,orijentacija,izlaz X-KDE-Keywords[sr@latin]=display,monitor,scale,scaling,resolution,oritentation,outputs,prikaz,monitor,ekran,skaliranje,rezolucija,orijentacija,izlaz X-KDE-Keywords[sv]=skärm,bildskärm,skala,skalning,upplösning,orientering,utgångar X-KDE-Keywords[uk]=display,monitor,scale,scaling,resolution,orientation,outputs,дисплей,монітор,масштаб,масштабування,роздільність,здатність,орієнтація,виведення,виходи X-KDE-Keywords[x-test]=xxdisplayxx,xxmonitorxx,xxscalexx,xxscalingxx,xxresolutionxx,xxorientationxx,xxoutputsxx X-KDE-Keywords[zh_CN]=display,monitor,scale,scaling,resolution,orientation,outputs,显示,监视器,缩放,分辨率,旋转,方位,输出 diff --git a/kcm/src/widget.cpp b/kcm/src/widget.cpp index 5d1ac0d..16be309 100644 --- a/kcm/src/widget.cpp +++ b/kcm/src/widget.cpp @@ -1,478 +1,479 @@ /* * Copyright (C) 2013 Daniel Vr??til * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ #include "widget.h" #include "controlpanel.h" #ifdef WITH_PROFILES #include "profilesmodel.h" #endif #include "primaryoutputcombo.h" #include #include #include #include #include #include "declarative/qmloutput.h" #include "declarative/qmlscreen.h" #include "utils.h" #include "scalingconfig.h" #include #include #include #include #include #include #include #include #include #include #include #include #define QML_PATH "kcm_kscreen/qml/" Widget::Widget(QWidget *parent): QWidget(parent), mScreen(0), mConfig(0), mPrevConfig(0) { qRegisterMetaType(); setMinimumHeight(550); QVBoxLayout *layout = new QVBoxLayout(this); QSplitter *splitter = new QSplitter(Qt::Vertical, this); layout->addWidget(splitter); mDeclarativeView = new QQuickView(); QWidget *container = QWidget::createWindowContainer(mDeclarativeView, this); mDeclarativeView->setResizeMode(QQuickView::SizeRootObjectToView); mDeclarativeView->setMinimumHeight(280); container->setMinimumHeight(280); splitter->addWidget(container); QWidget *widget = new QWidget(this); splitter->addWidget(widget); splitter->setStretchFactor(1, 1); widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); QVBoxLayout *vbox = new QVBoxLayout(widget); widget->setLayout(vbox); QHBoxLayout *hbox = new QHBoxLayout; vbox->addLayout(hbox); mPrimaryCombo = new PrimaryOutputCombo(this); connect(mPrimaryCombo, &PrimaryOutputCombo::changed, this, &Widget::changed); hbox->addWidget(new QLabel(i18n("Primary display:"))); hbox->addWidget(mPrimaryCombo); hbox->addStretch(); #ifdef WITH_PROFILES mProfilesModel = new ProfilesModel(this); connect(mProfilesModel, &ProfilesModel::modelUpdated()), this, &Widget::slotProfilesUpdated); mProfilesCombo = new QComboBox(this); mProfilesCombo->setModel(mProfilesModel); mProfilesCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents); hbox->addWidget(new QLabel(i18n("Active profile"))); hbox->addWidget(mProfilesCombo); #endif mControlPanel = new ControlPanel(this); connect(mControlPanel, &ControlPanel::changed, this, &Widget::changed); vbox->addWidget(mControlPanel); mUnifyButton = new QPushButton(i18n("Unify Outputs"), this); connect(mUnifyButton, &QPushButton::released, [this]{ slotUnifyOutputs(); }); vbox->addWidget(mUnifyButton); auto setScaleButton = new QPushButton(i18n("Scale Display"), this); connect(setScaleButton, &QPushButton::released, [this] { QPointer dialog = new ScalingConfig(mConfig->outputs(), this); dialog->exec(); delete dialog; }); vbox->addWidget(setScaleButton); mOutputTimer = new QTimer(this); connect(mOutputTimer, &QTimer::timeout, this, &Widget::clearOutputIdentifiers); loadQml(); } Widget::~Widget() { clearOutputIdentifiers(); } bool Widget::eventFilter(QObject* object, QEvent* event) { if (event->type() == QEvent::Resize) { if (mOutputIdentifiers.contains(qobject_cast(object))) { QResizeEvent *e = static_cast(event); const QRect screenSize = object->property("screenSize").toRect(); QRect geometry(QPoint(0, 0), e->size()); geometry.moveCenter(screenSize.center()); static_cast(object)->setGeometry(geometry); // Pass the event further } } return QObject::eventFilter(object, event); } void Widget::setConfig(const KScreen::ConfigPtr &config) { if (mConfig) { KScreen::ConfigMonitor::instance()->removeConfig(mConfig); for (const KScreen::OutputPtr &output : mConfig->outputs()) { output->disconnect(this); } } mConfig = config; KScreen::ConfigMonitor::instance()->addConfig(mConfig); mScreen->setConfig(mConfig); mControlPanel->setConfig(mConfig); mPrimaryCombo->setConfig(mConfig); + mUnifyButton->setEnabled(mConfig->outputs().count() > 1); for (const KScreen::OutputPtr &output : mConfig->outputs()) { connect(output.data(), &KScreen::Output::isEnabledChanged, this, &Widget::slotOutputEnabledChanged); connect(output.data(), &KScreen::Output::posChanged, this, &Widget::changed); } // Select the primary (or only) output by default QMLOutput *qmlOutput = mScreen->primaryOutput(); if (qmlOutput) { mScreen->setActiveOutput(qmlOutput); } else { if (mScreen->outputs().count() > 0) { mScreen->setActiveOutput(mScreen->outputs()[0]); } } slotOutputEnabledChanged(); } KScreen::ConfigPtr Widget::currentConfig() const { return mConfig; } void Widget::loadQml() { qmlRegisterType("org.kde.kscreen", 1, 0, "QMLOutput"); qmlRegisterType("org.kde.kscreen", 1, 0, "QMLScreen"); qmlRegisterType("org.kde.kscreen", 1, 0, "KScreenOutput"); qmlRegisterType("org.kde.kscreen", 1, 0, "KScreenEdid"); qmlRegisterType("org.kde.kscreen", 1, 0, "KScreenMode"); //const QString file = QDir::currentPath() + "/main.qml"; const QString file = QStandardPaths::locate(QStandardPaths::QStandardPaths::GenericDataLocation, QStringLiteral("kcm_kscreen/qml/main.qml")); mDeclarativeView->setSource(QUrl::fromLocalFile(file)); QQuickItem* rootObject = mDeclarativeView->rootObject(); mScreen = rootObject->findChild(QStringLiteral("outputView")); if (!mScreen) { return; } mScreen->setEngine(mDeclarativeView->engine()); connect(mScreen, &QMLScreen::focusedOutputChanged, this, &Widget::slotFocusedOutputChanged); connect(rootObject->findChild(QStringLiteral("identifyButton")), SIGNAL(clicked()), this, SLOT(slotIdentifyButtonClicked())); } void Widget::slotFocusedOutputChanged(QMLOutput *output) { mControlPanel->activateOutput(output->outputPtr()); } void Widget::slotOutputEnabledChanged() { int enabledOutputsCnt = 0; Q_FOREACH (const KScreen::OutputPtr &output, mConfig->outputs()) { if (output->isEnabled()) { ++enabledOutputsCnt; } if (enabledOutputsCnt > 1) { break; } } mUnifyButton->setEnabled(enabledOutputsCnt > 1); } void Widget::slotUnifyOutputs() { QMLOutput *base = mScreen->primaryOutput(); QList clones; if (!base) { Q_FOREACH (QMLOutput *output, mScreen->outputs()) { if (output->output()->isConnected() && output->output()->isEnabled()) { base = output; break; } } if (!base) { // WTF? return; } } if (base->isCloneMode()) { setConfig(mPrevConfig); mPrevConfig.clear(); mPrimaryCombo->setEnabled(true); mUnifyButton->setText(i18n("Unify Outputs")); } else { // Clone the current config, so that we can restore it in case user // breaks the cloning mPrevConfig = mConfig->clone(); Q_FOREACH (QMLOutput *output, mScreen->outputs()) { if (!output->output()->isConnected()) { continue; } if (!output->output()->isEnabled()) { output->setVisible(false); continue; } if (base == 0) { base = output; } output->setOutputX(0); output->setOutputY(0); output->output()->setPos(QPoint(0, 0)); output->output()->setClones(QList()); if (base != output) { clones << output->output()->id(); output->setCloneOf(base); output->setVisible(false); } } base->output()->setClones(clones); base->setIsCloneMode(true); mScreen->updateOutputsPlacement(); mPrimaryCombo->setEnabled(false); mControlPanel->setUnifiedOutput(base->outputPtr()); mUnifyButton->setText(i18n("Break Unified Outputs")); } Q_EMIT changed(); } void Widget::slotProfileChanged(int index) { #ifdef WITH_PROFILES const QVariantMap profile = mProfilesCombo->itemData(index, ProfilesModel::ProfileRole).toMap(); const QVariantList outputs = profile[QLatin1String("outputs")].toList(); // FIXME: Copy-pasted from KDED's Serializer::config() KScreen::Config *config = KScreen::Config::current(); KScreen::OutputList outputList = config->outputs(); Q_FOREACH(KScreen::Output * output, outputList) { if (!output->isConnected() && output->isEnabled()) { output->setEnabled(false); } } KScreen::Config *outputsConfig = config->clone(); Q_FOREACH(const QVariant & info, outputs) { KScreen::Output *output = findOutput(outputsConfig, info.toMap()); if (!output) { continue; } delete outputList.take(output->id()); outputList.insert(output->id(), output); } config->setOutputs(outputList); setConfig(config); #else Q_UNUSED(index) #endif } // FIXME: Copy-pasted from KDED's Serializer::findOutput() KScreen::OutputPtr Widget::findOutput(const KScreen::ConfigPtr &config, const QVariantMap &info) { KScreen::OutputList outputs = config->outputs(); Q_FOREACH(const KScreen::OutputPtr &output, outputs) { if (!output->isConnected()) { continue; } const QString outputId = (output->edid() && output->edid()->isValid()) ? output->edid()->hash() : output->name(); if (outputId != info[QStringLiteral("id")].toString()) { continue; } QVariantMap posInfo = info[QStringLiteral("pos")].toMap(); QPoint point(posInfo[QStringLiteral("x")].toInt(), posInfo[QStringLiteral("y")].toInt()); output->setPos(point); output->setPrimary(info[QStringLiteral("primary")].toBool()); output->setEnabled(info[QStringLiteral("enabled")].toBool()); output->setRotation(static_cast(info[QStringLiteral("rotation")].toInt())); QVariantMap modeInfo = info[QStringLiteral("mode")].toMap(); QVariantMap modeSize = modeInfo[QStringLiteral("size")].toMap(); QSize size(modeSize[QStringLiteral("width")].toInt(), modeSize[QStringLiteral("height")].toInt()); const KScreen::ModeList modes = output->modes(); Q_FOREACH(const KScreen::ModePtr &mode, modes) { if (mode->size() != size) { continue; } if (QString::number(mode->refreshRate()) != modeInfo[QStringLiteral("refresh")].toString()) { continue; } output->setCurrentModeId(mode->id()); break; } return output; } return KScreen::OutputPtr(); } void Widget::slotProfilesAboutToUpdate() { #ifdef WITH_PROFILES disconnect(mProfilesCombo, &QComboBox::currentIndexChanged, this, &Widget::slotProfileChanged); #endif } void Widget::slotProfilesUpdated() { #ifdef WITH_PROFILES connect(mProfilesCombo, &QComboBox::currentIndexChanged, this, &Widget::slotProfileChanged); const int index = mProfilesModel->activeProfileIndex(); mProfilesCombo->setCurrentIndex(index); #endif } void Widget::clearOutputIdentifiers() { mOutputTimer->stop(); qDeleteAll(mOutputIdentifiers); mOutputIdentifiers.clear(); } void Widget::slotIdentifyButtonClicked(bool checked) { Q_UNUSED(checked); connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, this, &Widget::slotIdentifyOutputs); } void Widget::slotIdentifyOutputs(KScreen::ConfigOperation *op) { if (op->hasError()) { return; } const KScreen::ConfigPtr config = qobject_cast(op)->config(); const QString qmlPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral(QML_PATH "OutputIdentifier.qml")); mOutputTimer->stop(); clearOutputIdentifiers(); /* Obtain the current active configuration from KScreen */ Q_FOREACH (const KScreen::OutputPtr &output, config->outputs()) { if (!output->isConnected() || !output->currentMode()) { continue; } const KScreen::ModePtr mode = output->currentMode(); QQuickView *view = new QQuickView(); view->setFlags(Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); view->setResizeMode(QQuickView::SizeViewToRootObject); view->setSource(QUrl::fromLocalFile(qmlPath)); view->installEventFilter(this); QQuickItem *rootObj = view->rootObject(); if (!rootObj) { qWarning() << "Failed to obtain root item"; continue; } QSize realSize; if (output->isHorizontal()) { realSize = mode->size(); } else { realSize = QSize(mode->size().height(), mode->size().width()); } rootObj->setProperty("outputName", Utils::outputName(output)); rootObj->setProperty("modeName", Utils::sizeToString(realSize)); view->setProperty("screenSize", QRect(output->pos(), realSize)); mOutputIdentifiers << view; } Q_FOREACH (QQuickView *view, mOutputIdentifiers) { view->show(); } mOutputTimer->start(2500); }