File indexing completed on 2024-05-12 09:36:15

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         "\n   Set HDR mode (possible values: enable, disable)\n"
0055         "   $ kscreen-doctor output.HDMI-2.hdr.enable\n"
0056         "\n   Set SDR brightness (possible values: 100-1000)\n"
0057         "   $ kscreen-doctor output.HDMI-2.sdr-brightness.300\n"
0058         "\n   Set wide color gamut mode (possible values: enable, disable)\n"
0059         "   $ kscreen-doctor output.HDMI-2.wcg.enable\n"
0060         "\n   Set ICC profile path\n"
0061         "   $ kscreen-doctor output.HDMI-2.iccprofile.\"/path/to/profile.icc\"\n");
0062     /*
0063         "\nError codes:\n"
0064         "   2 : general parse error\n"
0065         "   3 : output id parse error\n"
0066         "   4 : mode id parse error\n"
0067         "   5 : position parse error\n"
0068 
0069         "   8 : invalid output id\n"
0070         "   9 : invalid mode id\n";
0071     */
0072     const QString syntax = QStringLiteral(
0073         "Specific output settings are separated by spaces, each setting is in the form of\n"
0074         "output.<name>.<setting>[.<value>]\n"
0075         "For example:\n"
0076         "$ kscreen-doctor output.HDMI-2.enable \\ \n"
0077         "                output.eDP-1.mode.4 \\ \n"
0078         "                output.eDP-1.position.1280,0\n"
0079         "Multiple settings are passed in order to have kscreen-doctor apply these settings in one go.\n");
0080 
0081     QGuiApplication::setDesktopSettingsAware(false);
0082     QGuiApplication app(argc, argv);
0083 
0084     KScreen::Doctor server;
0085 
0086     QCommandLineOption info =
0087         QCommandLineOption(QStringList() << QStringLiteral("i") << QStringLiteral("info"), QStringLiteral("Show runtime information: backends, logging, etc."));
0088     QCommandLineOption outputs = QCommandLineOption(QStringList() << QStringLiteral("o") << QStringLiteral("outputs"), QStringLiteral("Show outputs"));
0089     QCommandLineOption json =
0090         QCommandLineOption(QStringList() << QStringLiteral("j") << QStringLiteral("json"), QStringLiteral("Show configuration in JSON format"));
0091     QCommandLineOption dpms = QCommandLineOption(QStringList() << QStringLiteral("d") << QStringLiteral("dpms"),
0092                                                  QStringLiteral("Display power management (wayland only)"),
0093                                                  QStringLiteral("off"));
0094     QCommandLineOption dpmsExcluded = QCommandLineOption({QStringLiteral("dpms-excluded")},
0095                                                          QStringLiteral("Do not apply the dpms change to the output with said model names"),
0096                                                          QStringLiteral("connector"));
0097     QCommandLineOption log = QCommandLineOption(QStringList() << QStringLiteral("l") << QStringLiteral("log"),
0098                                                 QStringLiteral("Write a comment to the log file"),
0099                                                 QStringLiteral("comment"));
0100 
0101     QCommandLineParser parser;
0102     parser.setApplicationDescription(desc);
0103     parser.addPositionalArgument(QStringLiteral("config"), syntax, QStringLiteral("[output.<name>.<setting> output.<name>.setting [...]]"));
0104     parser.addHelpOption();
0105     parser.addOption(info);
0106     parser.addOption(json);
0107     parser.addOption(outputs);
0108     parser.addOption(dpms);
0109     parser.addOption(log);
0110     parser.addOption(dpmsExcluded);
0111     parser.process(app);
0112 
0113     if (!parser.positionalArguments().isEmpty()) {
0114         server.setOptionList(parser.positionalArguments());
0115     }
0116 
0117     server.start(&parser);
0118     return app.exec();
0119 }