File indexing completed on 2024-04-28 16:49:43

0001 /*
0002  *  SPDX-FileCopyrightText: 2014-2015 Sebastian Kügler <sebas@kde.org>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "doctor.h"
0008 
0009 #include <QCommandLineParser>
0010 #include <QGuiApplication>
0011 
0012 #include <QDebug>
0013 
0014 /** Usage example:
0015  * kscreen-doctor --set output.0.disable output.1.mode.1 output.1.enable"
0016  *
0017  * Error codes:
0018  * 2 : general parse error
0019  * 3 : output id parse error
0020  * 4 : mode id parse error
0021  * 5 : position parse error
0022  *
0023  * 8 : invalid output id
0024  * 9 : invalid mode id
0025  *
0026  */
0027 
0028 int main(int argc, char **argv)
0029 {
0030     const QString desc = QStringLiteral(
0031         "kscreen-doctor allows to change the screen setup from the command-line.\n"
0032         "\n"
0033         "Setting the output configuration is done in an atomic fashion, all settings\n"
0034         "are applied in a single command.\n"
0035         "kscreen-doctor can be used to enable and disable outputs, to position screens,\n"
0036         "change resolution (mode setting), etc.. You should put all your options into \n"
0037         "a single invocation of kscreen-doctor, so they can all be applied at once.\n"
0038         "\n"
0039         "Usage examples:\n\n"
0040         "   Show output information:\n"
0041         "   $ kscreen-doctor -o\n"
0042         "   Output: 1 eDP-1 enabled connected Panel Modes: Modes: 1:800x600@60 [...] Geometry: 0,0 1280x800\n"
0043         "   Output: 70 HDMI-2 enabled connected  HDMI Modes: 1:800x600@60 [...] Geometry: 1280,0 1920x1080\n"
0044         "\n   Disable the hdmi output, enable the laptop panel and set it to a specific mode\n"
0045         "   $ kscreen-doctor output.HDMI-2.disable output.eDP-1.mode.1 output.eDP-1.enable\n"
0046         "\n   Position the hdmi monitor on the right of the laptop panel\n"
0047         "   $ kscreen-doctor output.HDMI-2.position.1280,0 output.eDP-1.position.0,0\n"
0048         "\n   Set resolution mode\n"
0049         "   $ kscreen-doctor output.HDMI-2.mode.1920x1080@60 \n"
0050         "\n   Set scale (note: fractional scaling is only supported on wayland)\n"
0051         "   $ kscreen-doctor output.HDMI-2.scale.2 \n"
0052         "\n   Set rotation (possible values: none, left, right, inverted)\n"
0053         "   $ kscreen-doctor output.HDMI-2.rotation.left \n");
0054     /*
0055         "\nError codes:\n"
0056         "   2 : general parse error\n"
0057         "   3 : output id parse error\n"
0058         "   4 : mode id parse error\n"
0059         "   5 : position parse error\n"
0060 
0061         "   8 : invalid output id\n"
0062         "   9 : invalid mode id\n";
0063     */
0064     const QString syntax = QStringLiteral(
0065         "Specific output settings are separated by spaces, each setting is in the form of\n"
0066         "output.<name>.<setting>[.<value>]\n"
0067         "For example:\n"
0068         "$ kscreen-doctor output.HDMI-2.enable \\ \n"
0069         "                output.eDP-1.mode.4 \\ \n"
0070         "                output.eDP-1.position.1280,0\n"
0071         "Multiple settings are passed in order to have kscreen-doctor apply these settings in one go.\n");
0072 
0073     QGuiApplication app(argc, argv);
0074 
0075     KScreen::Doctor server;
0076 
0077     QCommandLineOption info =
0078         QCommandLineOption(QStringList() << QStringLiteral("i") << QStringLiteral("info"), QStringLiteral("Show runtime information: backends, logging, etc."));
0079     QCommandLineOption outputs = QCommandLineOption(QStringList() << QStringLiteral("o") << QStringLiteral("outputs"), QStringLiteral("Show outputs"));
0080     QCommandLineOption json =
0081         QCommandLineOption(QStringList() << QStringLiteral("j") << QStringLiteral("json"), QStringLiteral("Show configuration in JSON format"));
0082     QCommandLineOption dpms = QCommandLineOption(QStringList() << QStringLiteral("d") << QStringLiteral("dpms"),
0083                                                  QStringLiteral("Display power management (wayland only)"),
0084                                                  QStringLiteral("off"));
0085     QCommandLineOption dpmsExcluded = QCommandLineOption({QStringLiteral("dpms-excluded")},
0086                                                          QStringLiteral("Do not apply the dpms change to the output with said model names"),
0087                                                          QStringLiteral("connector"));
0088     QCommandLineOption log = QCommandLineOption(QStringList() << QStringLiteral("l") << QStringLiteral("log"),
0089                                                 QStringLiteral("Write a comment to the log file"),
0090                                                 QStringLiteral("comment"));
0091 
0092     QCommandLineParser parser;
0093     parser.setApplicationDescription(desc);
0094     parser.addPositionalArgument(QStringLiteral("config"), syntax, QStringLiteral("[output.<name>.<setting> output.<name>.setting [...]]"));
0095     parser.addHelpOption();
0096     parser.addOption(info);
0097     parser.addOption(json);
0098     parser.addOption(outputs);
0099     parser.addOption(dpms);
0100     parser.addOption(log);
0101     parser.addOption(dpmsExcluded);
0102     parser.process(app);
0103 
0104     if (!parser.positionalArguments().isEmpty()) {
0105         server.setOptionList(parser.positionalArguments());
0106     }
0107 
0108     server.start(&parser);
0109     return app.exec();
0110 }