Files
clearpilot/system/clearpilot/tools/qt_webview.cc
Your Name 05aab16504 wip
2024-05-10 00:45:37 -05:00

67 lines
1.8 KiB
C++

#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>
#include <QWebEngineView>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QCommandLineParser parser;
parser.addHelpOption();
parser.addPositionalArgument("command", "The URL to open.");
parser.process(app);
QStringList args = parser.positionalArguments();
if (args.isEmpty()) {
fprintf(stderr, "Usage: %s '<command>'\n", argv[0]);
return 1;
}
// Common init
QWidget window;
window.setWindowTitle("Webview");
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 url = args.first();
QWebEngineView *web_view = new QWebEngineView();
web_view->load(QUrl("http://www.fark.com/"));
layout->addWidget(web_view);
return app.exec();
}