make it possible to display on multible screens

This commit is contained in:
delia 2025-04-17 14:11:38 +02:00
parent 4797fdb1e6
commit b4b0f56158
7 changed files with 39 additions and 95 deletions

View File

@ -82,90 +82,9 @@ int main (int argc, char* argv[]) {
uiWindow->show();
return qapp.exec();
/*
auto* window = new QWidget();
window->setWindowTitle("Wallpapers :3");
auto* scrollArea = new QScrollArea(window);
scrollArea->setWidgetResizable(true);
auto* container = new QWidget();
auto* layout = new QGridLayout(container);
int cols = 3;
// Wallpaper Process
auto* wallpaperEngine = new QProcess(window);
for (size_t i = 0; i < wallpaperPaths.size(); i++) {
QPixmap pixmap(QString::fromStdString(wallpaperPaths[i] + "/preview.jpg"));
if (pixmap.isNull()) {
pixmap = QPixmap(256, 256);
pixmap.fill(Qt::black);
}
auto* button = new QPushButton();
button->setIcon(pixmap.scaled(256, 256, Qt::KeepAspectRatio));
button->setText("Hii :3");
button->setIconSize(QSize(256, 256));
button->setFixedSize(384, 364);
button->setProperty("path", QString::fromStdString(wallpaperPaths[i]));
QAbstractButton::connect(button, &QPushButton::clicked, [button, &qapp, argc, argv, window, wallpaperEngine]() {
QString clickedPath = button->property("path").toString();
button->setEnabled(false);
if (wallpaperEngine->state() == QProcess::Running) {
// Stop WallpaperProcess
wallpaperEngine->terminate();
if (!wallpaperEngine->waitForFinished(3000)) {
wallpaperEngine->kill();
wallpaperEngine->waitForFinished();
}
}
// start Wallpaper Process
wallpaperEngine->start(QCoreApplication::applicationFilePath(), {"--screen-root", "DP-2", clickedPath});
QObject::connect(wallpaperEngine, &QProcess::started, button, [=]() {
button->setEnabled(true);
});
QObject::connect(wallpaperEngine, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), window, [](int exitcode, QProcess::ExitStatus status) {
std::cout << exitcode << "\r\n";
});
// qapp.exit();
});
int row = i / cols;
int col = i % cols;
layout->addWidget(button, row, col);
}
QObject::connect(&qapp, &QCoreApplication::aboutToQuit, window, [&qapp, wallpaperEngine]() {
wallpaperEngine->terminate();
wallpaperEngine->waitForFinished(3000);
});
container->setLayout(layout);
scrollArea->setWidget(container);
auto* mainlayout = new QVBoxLayout(window);
mainlayout->addWidget(scrollArea);
window->setLayout(mainlayout);
window->show();
return qapp.exec();
*/
}
WallpaperEngine::WebBrowser::CWebBrowserContext webBrowserContext(argc, argv);
std::string wallpaperPath = "/home/delia/.local/share/Steam/steamapps/workshop/content/431960/1838246129";
std::string display = "DP-2";
WallpaperEngine::Application::CApplicationContext appContext (argc, argv);
// halt if the list-properties option was specified

View File

@ -5,6 +5,7 @@
#include <qcursor.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qprocess.h>
#include <qwidget.h>
#include <vector>
@ -12,6 +13,7 @@ UIWindow::UIWindow(QWidget* parent, QApplication* qapp) {
this->qapp = qapp;
this->screenSelector = new QComboBox(this);
this->extraFlagsInput = new QLineEdit(this);
this->wallpaperEngine = new QProcess(this);
}
void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
@ -34,7 +36,7 @@ void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
int cols = 5;
// Wallpaper Process
auto* wallpaperEngine = new QProcess(this);
// auto* wallpaperEngine = new QProcess(this);
for (size_t i = 0; i < wallpaperPaths.size(); i++) {
QPixmap pixmap(QString::fromStdString(wallpaperPaths[i] + "/preview.jpg"));
@ -50,21 +52,14 @@ void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
button->setProperty("path", QString::fromStdString(wallpaperPaths[i]));
QAbstractButton::connect(button, &QPushButton::clicked, [button, this, wallpaperEngine]() {
QAbstractButton::connect(button, &QPushButton::clicked, [button, this]() {
QString clickedPath = button->property("path").toString();
button->setEnabled(false);
if (wallpaperEngine->state() == QProcess::Running) {
// Stop WallpaperProcess
wallpaperEngine->terminate();
if (!wallpaperEngine->waitForFinished(3000)) {
wallpaperEngine->kill();
wallpaperEngine->waitForFinished();
}
}
// start Wallpaper Process
wallpaperEngine->start(QCoreApplication::applicationFilePath(), {"--screen-root", this->screenSelector->currentText(), "--bg", clickedPath});
this->selectedWallpapers[this->screenSelector->currentText().toStdString()] = clickedPath.toStdString();
startNewWallpaperEngine();
QObject::connect(wallpaperEngine, &QProcess::started, button, [=]() {
button->setEnabled(true);
});
@ -76,7 +71,7 @@ void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
layout->addWidget(button, row, col);
}
QObject::connect(this->qapp, &QCoreApplication::aboutToQuit, this, [wallpaperEngine]() {
QObject::connect(this->qapp, &QCoreApplication::aboutToQuit, this, [this]() {
wallpaperEngine->terminate();
wallpaperEngine->waitForFinished(3000);
});
@ -107,3 +102,27 @@ void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
mainlayout->addWidget(extraFlagsInput);
this->setLayout(mainlayout);
}
void UIWindow::startNewWallpaperEngine() {
if (wallpaperEngine->state() == QProcess::Running) {
// Stop WallpaperProcess
wallpaperEngine->terminate();
if (!wallpaperEngine->waitForFinished(3000)) {
wallpaperEngine->kill();
wallpaperEngine->waitForFinished();
}
}
// create args
QStringList args;
for (auto wallpaper : this->selectedWallpapers) {
args.push_back("--screen-root");
args.push_back(QString::fromStdString(wallpaper.first));
args.push_back("--bg");
args.push_back(QString::fromStdString(wallpaper.second));
}
// start Wallpaper Process
wallpaperEngine->start(QCoreApplication::applicationFilePath(), args);
}

View File

@ -1,10 +1,12 @@
#pragma once
#include <map>
#include <qapplication.h>
#include <qcombobox.h>
#include <qgridlayout.h>
#include <qlineedit.h>
#include <qobjectdefs.h>
#include <qprocess.h>
#include <qwidget.h>
#include <QScrollArea>
#include <QProcess>
@ -30,4 +32,8 @@ class UIWindow : public QWidget {
QApplication* qapp;
QComboBox* screenSelector;
QLineEdit* extraFlagsInput;
std::map<std::string, std::string> selectedWallpapers;
QProcess* wallpaperEngine;
void startNewWallpaperEngine();
};