Commit 659d750b authored by Sebastian Kügler's avatar Sebastian Kügler
Browse files

allow setting rotation from kscreen-doctor

This patch allows the rotation of an output to be set from kscreen-doctor.

The syntax is
kscreen-doctor output.HDMI-2.rotation.left
parent a427b0b1
......@@ -258,6 +258,27 @@ void Doctor::parsePositionalArgs()
qApp->exit(9);
return;
}
} else if ((ops.count() == 4) && (ops[2] == QStringLiteral("orientation") || ops[2] == QStringLiteral("rotation"))) {
const QString _rotation = ops[3].toLower();
bool ok = false;
const QHash<QString, KScreen::Output::Rotation> rotationMap({
{QStringLiteral("none"), KScreen::Output::None},
{QStringLiteral("normal"), KScreen::Output::None},
{QStringLiteral("left"), KScreen::Output::Left},
{QStringLiteral("right"), KScreen::Output::Right},
{QStringLiteral("inverted"), KScreen::Output::Inverted}
});
KScreen::Output::Rotation rot = KScreen::Output::None;
// set orientation
if (rotationMap.contains(_rotation)) {
ok = true;
rot = rotationMap[_rotation];
}
if (!ok || !setRotation(output_id, rot)) {
qCDebug(KSCREEN_DOCTOR) << "Could not set orientation " << _rotation << " to output " << output_id;
qApp->exit(9);
return;
}
} else {
cerr << "Unable to parse arguments" << op << endl;
qApp->exit(2);
......@@ -438,6 +459,24 @@ bool Doctor::setScale(int id, qreal scale)
return false;
}
bool Doctor::setRotation(int id, KScreen::Output::Rotation rot)
{
if (!m_config) {
qCWarning(KSCREEN_DOCTOR) << "Invalid config.";
return false;
}
Q_FOREACH (const auto &output, m_config->outputs()) {
if (output->id() == id) {
output->setRotation(rot);
m_changed = true;
return true;
}
}
cout << "Output rotation " << id << " invalid." << endl;
return false;
}
void Doctor::applyConfig()
{
if (!m_changed) {
......
......@@ -23,11 +23,12 @@
#include <QObject>
#include "../config.h"
#include <KScreen/Output>
namespace KScreen
{
class ConfigOperation;
class DpmsClient;
//static const QString s_socketName = QStringLiteral("libkscreen-test-wayland-backend-0");
class Doctor : public QObject
{
......@@ -53,6 +54,7 @@ public:
bool setPosition(int id, const QPoint &pos);
bool setMode(int id, const QString &mode_id);
bool setScale(int id, qreal scale);
bool setRotation(int id, KScreen::Output::Rotation rot);
Q_SIGNALS:
void outputsChanged();
......
......@@ -57,7 +57,9 @@ int main(int argc, char **argv)
"\n Position the hdmi monitor on the right of the laptop panel\n"
" $ kscreen-doctor output.HDMI-2.position.0,1280 output.eDP-1.position.0,0\n"
"\n Set resolution mode\n"
" $ kscreen-doctor output.HDMI-2.mode.1920x1080@60 \n";
" $ kscreen-doctor output.HDMI-2.mode.1920x1080@60 \n"
"\n Set rotation (possible values: none, left, right, inverted)\n"
" $ kscreen-doctor output.HDMI-2.rotation.left \n";
/*
"\nError codes:\n"
" 2 : general parse error\n"
......
Supports Markdown
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