Commit 788656c2 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

doctor: Add an option to allow excluding outputs from a dpms action

This is useful when playing a movie or similar and you want to dim the
other outputs.
parent b05af982
......@@ -99,7 +99,13 @@ void Doctor::start(QCommandLineParser *parser)
return;
}
m_dpmsClient = new DpmsClient(this);
if (m_parser->isSet(QStringLiteral("dpms-excluded"))) {
const auto excludedConnectors= m_parser->values(QStringLiteral("dpms-excluded"));
m_dpmsClient->setExcludedOutputNames(excludedConnectors);
}
connect(m_dpmsClient, &DpmsClient::finished, qApp, &QCoreApplication::quit);
const QString dpmsArg = m_parser->value(QStringLiteral("dpms"));
......
......@@ -107,9 +107,7 @@ void KScreen::DpmsClient::changeMode(KWayland::Client::Dpms::Mode mode)
{
const auto outputs = m_registry->interfaces(Registry::Interface::Output);
for (auto outputInterface : outputs) {
KWayland::Client::Output *output = m_registry->createOutput(outputInterface.name, outputInterface.version, m_registry);
qDebug() << "OUTPUT!" << output->model() << output->manufacturer() << output->geometry();
Dpms *dpms = nullptr;
if (m_dpmsManager) {
......@@ -118,11 +116,16 @@ void KScreen::DpmsClient::changeMode(KWayland::Client::Dpms::Mode mode)
if (dpms) {
QObject::connect(dpms, &Dpms::supportedChanged, this,
[dpms, mode, this] {
[dpms, mode, output, this] {
if (m_excludedOutputNames.contains(output->model())) {
qDebug() << "Skipping" << output->model() << output->manufacturer();
return;
}
if (dpms->isSupported()) {
QObject::connect(dpms, &Dpms::modeChanged, this,
&DpmsClient::modeChanged, Qt::QueuedConnection);
qDebug() << "Switching " << (mode == Dpms::Mode::On ? "on" : "off");
qDebug() << "Switching" << output->model() << output->manufacturer() << (mode == Dpms::Mode::On ? "on" : "off");
m_modeChanges++;
dpms->requestMode(mode);
}
......@@ -130,8 +133,6 @@ void KScreen::DpmsClient::changeMode(KWayland::Client::Dpms::Mode mode)
}, Qt::QueuedConnection
);
}
qDebug() << "dpms->isSupported()" << dpms->isSupported();
}
}
......
......@@ -19,8 +19,8 @@
#ifndef KSCREEN_DPMSCLIENT_H
#define KSCREEN_DPMSCLIENT_H
#include <QCommandLineParser>
#include <QObject>
#include <QRect>
#include "../config.h"
#include <KWayland/Client/registry.h>
......@@ -46,6 +46,10 @@ public:
explicit DpmsClient(QObject *parent = nullptr);
~DpmsClient() override;
void setExcludedOutputNames(const QStringList &excluded) {
m_excludedOutputNames = excluded;
}
void connect();
void off();
void on();
......@@ -69,6 +73,7 @@ private:
bool m_supportedOututCount = 0;
int m_modeChanges = 0;
QStringList m_excludedOutputNames;
};
} // namespace
......
......@@ -92,6 +92,8 @@ int main(int argc, char **argv)
QStringLiteral("Show configuration in JSON format"));
QCommandLineOption dpms = QCommandLineOption(QStringList() << QStringLiteral("d") << QStringLiteral("dpms"),
QStringLiteral("Display power management (wayland only)"), QStringLiteral("off"));
QCommandLineOption dpmsExcluded = QCommandLineOption({QStringLiteral("dpms-excluded")},
QStringLiteral("Do not apply the dpms change to the output with said model names"), QStringLiteral("connector"));
QCommandLineOption log = QCommandLineOption(QStringList() << QStringLiteral("l") << QStringLiteral("log"),
QStringLiteral("Write a comment to the log file"), QStringLiteral("comment"));
......@@ -104,6 +106,7 @@ int main(int argc, char **argv)
parser.addOption(outputs);
parser.addOption(dpms);
parser.addOption(log);
parser.addOption(dpmsExcluded);
parser.process(app);
if (!parser.positionalArguments().isEmpty()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment