This commit is contained in:
Comma Device
2024-04-28 08:36:24 +00:00
parent 224327480a
commit 8e36f610e1
9 changed files with 150 additions and 6 deletions

View File

@@ -0,0 +1,10 @@
Metadata-Version: 1.0
Name: RotationModule
Version: 1.0
Summary: Module for rotating display via native interface
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN

View File

@@ -0,0 +1,6 @@
rotation_module.cc
rotation_module_build.py
RotationModule.egg-info/PKG-INFO
RotationModule.egg-info/SOURCES.txt
RotationModule.egg-info/dependency_links.txt
RotationModule.egg-info/top_level.txt

View File

@@ -0,0 +1 @@
rotation

Binary file not shown.

View File

@@ -1,6 +1,8 @@
#include <QCommandLineParser>
#include <QApplication>
#include <QWidget>
#include <QTextEdit>
#include <QLabel>
#include <QProcess>
#include <QVBoxLayout>
#include <QFont>
@@ -15,8 +17,16 @@
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
if (argc < 2) {
printf("Usage: %s '<command>'\n", argv[0]);
QCommandLineParser parser;
parser.addHelpOption();
parser.addPositionalArgument("command", "The shell command to execute.");
QCommandLineOption titleOption("title", "Set the title displayed at the top of the window.", "title");
parser.addOption(titleOption);
parser.process(app);
QStringList args = parser.positionalArguments();
if (args.isEmpty()) {
fprintf(stderr, "Usage: %s '<command>'\n", argv[0]);
return 1;
}
@@ -43,14 +53,28 @@ int main(int argc, char *argv[]) {
window.setFixedSize(2160, 1080);
QVBoxLayout *layout = new QVBoxLayout(&window);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
QString title = parser.value(titleOption);
QLabel *titleLabel = nullptr;
if (!title.isEmpty()) {
titleLabel = new QLabel(title);
titleLabel->setFont(QFont("Arial", 48));
titleLabel->setAlignment(Qt::AlignCenter);
titleLabel->setFixedSize(window.width(), 150);
titleLabel->setStyleSheet("color: white; background-color: black;");
layout->addWidget(titleLabel);
}
QTextEdit *outputDisplay = new QTextEdit;
outputDisplay->setFont(QFont("Consolas", 32));
outputDisplay->setReadOnly(true);
outputDisplay->setFixedSize(2160, 1080);
outputDisplay->setFixedSize(window.width(), window.height() - (titleLabel ? 150 : 0));
outputDisplay->setStyleSheet("color: white; background-color: black;");
outputDisplay->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // Hide the vertical scrollbar
layout->addWidget(outputDisplay);
QProcess process;
@@ -69,8 +93,8 @@ int main(int argc, char *argv[]) {
app.quit();
});
QString command = argv[1];
QString command = args.first();
process.start(QString("bash -c \"%1\"").arg(command));
return app.exec();
}
}

View File

@@ -0,0 +1,100 @@
#include <QCommandLineParser>
#include <QApplication>
#include <QWidget>
#include <QTextEdit>
#include <QLabel>
#include <QProcess>
#include <QVBoxLayout>
#include <QFont>
#include <QScreen>
#include <QScrollBar>
#include <QGuiApplication>
#include <qpa/qplatformnativeinterface.h>
#include <wayland-client-protocol.h>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QCommandLineParser parser;
parser.addHelpOption();
parser.addPositionalArgument("command", "The shell command to execute.");
QCommandLineOption titleOption("title", "Set the title displayed at the top of the window.", "title");
parser.addOption(titleOption);
parser.process(app);
QStringList args = parser.positionalArguments();
if (args.isEmpty()) {
fprintf(stderr, "Usage: %s '<command>'\n", argv[0]);
return 1;
}
QWidget window;
window.setWindowTitle("Shell Command Output Viewer");
window.setStyleSheet("background-color: black;");
window.showFullScreen();
auto windowHandle = window.windowHandle();
if (!windowHandle) {
fprintf(stderr, "Error: Unable to obtain window handle.\n");
return 1;
}
QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface();
auto *s = static_cast<wl_surface*>(native->nativeResourceForWindow("surface", windowHandle));
if (!s) {
fprintf(stderr, "Error: Unable to obtain native Wayland surface.\n");
return 1;
}
wl_surface_set_buffer_transform(s, WL_OUTPUT_TRANSFORM_270);
wl_surface_commit(s);
window.setFixedSize(2160, 1080);
QVBoxLayout *layout = new QVBoxLayout(&window);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
QString title = parser.value(titleOption);
QLabel *titleLabel = nullptr;
if (!title.isEmpty()) {
titleLabel = new QLabel(title);
titleLabel->setFont(QFont("Arial", 48));
titleLabel->setAlignment(Qt::AlignCenter);
titleLabel->setFixedSize(window.width(), 150);
titleLabel->setStyleSheet("color: white; background-color: black;");
layout->addWidget(titleLabel);
}
QTextEdit *outputDisplay = new QTextEdit;
outputDisplay->setFont(QFont("Consolas", 32));
outputDisplay->setReadOnly(true);
outputDisplay->setFixedSize(window.width(), window.height() - (titleLabel ? 300 : 0));
outputDisplay->setStyleSheet("color: white; background-color: black;");
outputDisplay->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // Hide the vertical scrollbar
layout->addWidget(outputDisplay);
QProcess process;
QObject::connect(&process, &QProcess::readyReadStandardOutput, [&]() {
static QStringList lines;
QString output = process.readAllStandardOutput();
lines += output.split("\n", QString::SkipEmptyParts);
while (lines.size() > 100) {
lines.removeFirst();
}
outputDisplay->setPlainText(lines.join("\n"));
outputDisplay->verticalScrollBar()->setValue(outputDisplay->verticalScrollBar()->maximum());
});
QObject::connect(&process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), [&]() {
app.quit();
});
QString command = args.first();
process.start(QString("bash -c \"%1\"").arg(command));
return app.exec();
}

View File

@@ -0,0 +1,2 @@
../../../selfdrive/manager/build.py
./qt_shell "cat qt_shell.cc; sleep 5" --title="Hello"