Skip to content

Commit f54f924

Browse files
committed
working icon
1 parent 93d7fc6 commit f54f924

File tree

7 files changed

+229
-63
lines changed

7 files changed

+229
-63
lines changed

Include/RunAsGPU/Shared/Runner.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ namespace Runner {
1010

1111
std::vector<GraphicalUnit> ListGraphicalUnits();
1212

13-
void RunApplication(const GraphicalUnit& unit, const std::string& bin, const std::vector<std::string>& args, const std::map<std::string, std::string>& env_map);
14-
1513
}
1614

1715
#endif //RUNASGPU_RUNNER_HPP

Sources/AppGUI/MainGUI.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include "UI/MainWindow.hpp"
44

55
int main(int argc, char** argv, char** envp) {
6+
// fucking wayland protocol, failing the damn icon
7+
if (qEnvironmentVariable("XDG_SESSION_TYPE") == "wayland")
8+
qputenv("QT_QPA_PLATFORM", QByteArray("xcb"));
9+
610
QApplication app(argc, argv);
711
QMainWindow mainWin;
812
Ui_MainWindow ui{};

Sources/AppGUI/UI/AppSelector.hpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#ifndef AppSelector_HPP
2+
#define AppSelector_HPP
3+
4+
#include <QtCore/QVariant>
5+
#include <QtWidgets/QAbstractButton>
6+
#include <QtWidgets/QApplication>
7+
#include <QtWidgets/QDialog>
8+
#include <QtWidgets/QDialogButtonBox>
9+
#include <QtWidgets/QLabel>
10+
#include <QtWidgets/QListView>
11+
12+
QT_BEGIN_NAMESPACE
13+
14+
class Ui_AppSelector
15+
{
16+
public:
17+
QDialogButtonBox *buttonBox;
18+
QListView *listInstalledApps;
19+
QLabel *label0;
20+
21+
void setupUi(QDialog *AppSelector)
22+
{
23+
if (AppSelector->objectName().isEmpty())
24+
AppSelector->setObjectName("AppSelector");
25+
AppSelector->resize(590, 385);
26+
buttonBox = new QDialogButtonBox(AppSelector);
27+
buttonBox->setObjectName("buttonBox");
28+
buttonBox->setGeometry(QRect(230, 340, 341, 32));
29+
buttonBox->setOrientation(Qt::Orientation::Horizontal);
30+
buttonBox->setStandardButtons(QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok);
31+
listInstalledApps = new QListView(AppSelector);
32+
listInstalledApps->setObjectName("listInstalledApps");
33+
listInstalledApps->setGeometry(QRect(10, 40, 571, 281));
34+
label0 = new QLabel(AppSelector);
35+
label0->setObjectName("label0");
36+
label0->setGeometry(QRect(10, 10, 151, 18));
37+
38+
retranslateUi(AppSelector);
39+
QObject::connect(buttonBox, &QDialogButtonBox::accepted, AppSelector, qOverload<>(&QDialog::accept));
40+
QObject::connect(buttonBox, &QDialogButtonBox::rejected, AppSelector, qOverload<>(&QDialog::reject));
41+
42+
QMetaObject::connectSlotsByName(AppSelector);
43+
} // setupUi
44+
45+
void retranslateUi(QDialog *AppSelector)
46+
{
47+
AppSelector->setWindowTitle(QCoreApplication::translate("AppSelector", "Select Application", nullptr));
48+
label0->setText(QCoreApplication::translate("AppSelector", "Installed applications:", nullptr));
49+
} // retranslateUi
50+
51+
};
52+
53+
namespace Ui {
54+
class AppSelector: public Ui_AppSelector {};
55+
} // namespace Ui
56+
57+
QT_END_NAMESPACE
58+
59+
#endif // AppSelector_HPP

Sources/AppGUI/UI/AppSelector.ui

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>AppSelector</class>
4+
<widget class="QDialog" name="AppSelector">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>590</width>
10+
<height>385</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Select Application</string>
15+
</property>
16+
<widget class="QDialogButtonBox" name="buttonBox">
17+
<property name="geometry">
18+
<rect>
19+
<x>230</x>
20+
<y>340</y>
21+
<width>341</width>
22+
<height>32</height>
23+
</rect>
24+
</property>
25+
<property name="orientation">
26+
<enum>Qt::Orientation::Horizontal</enum>
27+
</property>
28+
<property name="standardButtons">
29+
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
30+
</property>
31+
</widget>
32+
<widget class="QListView" name="listInstalledApps">
33+
<property name="geometry">
34+
<rect>
35+
<x>10</x>
36+
<y>40</y>
37+
<width>571</width>
38+
<height>281</height>
39+
</rect>
40+
</property>
41+
</widget>
42+
<widget class="QLabel" name="label0">
43+
<property name="geometry">
44+
<rect>
45+
<x>10</x>
46+
<y>10</y>
47+
<width>151</width>
48+
<height>18</height>
49+
</rect>
50+
</property>
51+
<property name="text">
52+
<string>Installed applications:</string>
53+
</property>
54+
</widget>
55+
</widget>
56+
<resources/>
57+
<connections>
58+
<connection>
59+
<sender>buttonBox</sender>
60+
<signal>accepted()</signal>
61+
<receiver>AppSelector</receiver>
62+
<slot>accept()</slot>
63+
<hints>
64+
<hint type="sourcelabel">
65+
<x>248</x>
66+
<y>254</y>
67+
</hint>
68+
<hint type="destinationlabel">
69+
<x>157</x>
70+
<y>274</y>
71+
</hint>
72+
</hints>
73+
</connection>
74+
<connection>
75+
<sender>buttonBox</sender>
76+
<signal>rejected()</signal>
77+
<receiver>AppSelector</receiver>
78+
<slot>reject()</slot>
79+
<hints>
80+
<hint type="sourcelabel">
81+
<x>316</x>
82+
<y>260</y>
83+
</hint>
84+
<hint type="destinationlabel">
85+
<x>286</x>
86+
<y>274</y>
87+
</hint>
88+
</hints>
89+
</connection>
90+
</connections>
91+
</ui>

Sources/AppGUI/UI/MainWindow.cpp

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,47 @@
22
#include "UnitSelector.hpp"
33

44
#include <QMessageBox>
5+
#include <QProcess>
6+
#include <QPixmap>
57

68
#include <RunAsGPU/Shared/GraphicalUnit.hpp>
79
#include <RunAsGPU/Shared/Runner.hpp>
810
#include <IconFinder.hpp>
911

1012
#include "Model/AppListModel.hpp"
1113
#include "Model/AppListDelegate.hpp"
14+
#include "RunAsGPU/Shared/Shared.hpp"
1215

1316
#include <filesystem>
1417
#include <fstream>
1518
#include <iostream>
16-
#include <QProcess>
1719

1820
namespace fs = std::filesystem;
1921

2022
AppListModel *model;
2123
AppListDelegate *delegate;
2224

25+
void run_app(int gpuUnit, const QString &execPath) {
26+
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
27+
env.insert("DRI_PRIME", QString::number(gpuUnit));
28+
29+
auto *process = new QProcess();
30+
process->setProcessEnvironment(env);
31+
process->setProgram(execPath);
32+
process->setArguments(QStringList());
33+
34+
qDebug() << "Running: " << execPath;
35+
process->start();
36+
if (!process->waitForStarted()) {
37+
QMessageBox::warning(nullptr, "Execution Failed", "Failed to start application: " + execPath);
38+
delete process;
39+
return;
40+
}
41+
42+
process->disconnect();
43+
process->setParent(nullptr);
44+
}
45+
2346
void save_default_gpu(const std::vector<GraphicalUnit> &gpu_list, int gpu_unit) {
2447
const char *home_dir = getenv("HOME");
2548
if (!home_dir)
@@ -83,7 +106,7 @@ int get_default_gpu(const std::vector<GraphicalUnit> &gpu_list) {
83106

84107
int gpuUnit;
85108

86-
void Ui_MainWindow::performLogic() const {
109+
void Ui_MainWindow::performLogic(QMainWindow* window) const {
87110
std::vector<GraphicalUnit> gpu_list = Runner::ListGraphicalUnits();
88111
if (gpu_list.empty()) {
89112
std::cerr << "GPU list empty, exiting..." << std::endl;
@@ -94,6 +117,12 @@ void Ui_MainWindow::performLogic() const {
94117
if (gpuUnit == -1)
95118
gpuUnit = 0;
96119

120+
labelUnitSelected->setText("Selected GPU: " + QString::fromStdString(gpu_list[gpuUnit].fullName));
121+
122+
std::string iconPath = GetExecutablePath().parent_path().string() + "/AppIcon.png";
123+
if (fs::exists(iconPath))
124+
window->setWindowIcon(QIcon(QString::fromStdString(iconPath)));
125+
97126
model = new AppListModel(appList);
98127
delegate = new AppListDelegate(appList);
99128

@@ -121,8 +150,14 @@ void Ui_MainWindow::performLogic() const {
121150
QObject::connect(appList, &QListView::doubleClicked, [&](const QModelIndex &index) {
122151
if (index.isValid()) {
123152
QString execPath = index.data(Qt::UserRole).toString();
124-
if (!execPath.isEmpty())
125-
QProcess::startDetached(execPath);
153+
if (execPath.isEmpty()) {
154+
qDebug() << "Invalid application (no executable path given)";
155+
QMessageBox::warning(nullptr, "Invalid application",
156+
"The selected application has no executable path.");
157+
return;
158+
}
159+
160+
run_app(gpuUnit, execPath);
126161
}
127162
});
128163

@@ -142,29 +177,12 @@ void Ui_MainWindow::performLogic() const {
142177

143178
QString execPath = index.data(Qt::UserRole).toString();
144179
if (execPath.isEmpty()) {
180+
qDebug() << "Invalid application (no executable path given)";
145181
QMessageBox::warning(nullptr, "Invalid application", "The selected application has no executable path.");
146182
return;
147183
}
148184

149-
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
150-
env.insert("DRI_PRIME", QString::number(gpuUnit));
151-
152-
auto *process = new QProcess();
153-
process->setProcessEnvironment(env);
154-
process->setProgram(execPath);
155-
process->setArguments(QStringList());
156-
157-
qDebug() << "Running: " << execPath;
158-
process->start();
159-
if (!process->waitForStarted()) {
160-
QMessageBox::warning(nullptr, "Execution Failed", "Failed to start application: " + execPath);
161-
delete process;
162-
return;
163-
}
164-
165-
166-
process->disconnect();
167-
process->setParent(nullptr);
185+
run_app(gpuUnit, execPath);
168186
});
169187

170188
// "Select GPU" button logic

Sources/AppGUI/UI/MainWindow.hpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef MAINWINDOW_HPP
2-
#define MAINWINDOW_HPP
1+
#ifndef MainWindow_HPP
2+
#define MainWindow_HPP
33

44
#include <QtCore/QVariant>
55
#include <QtGui/QIcon>
@@ -13,7 +13,8 @@
1313

1414
QT_BEGIN_NAMESPACE
1515

16-
class Ui_MainWindow {
16+
class Ui_MainWindow
17+
{
1718
public:
1819
QWidget *centralwidget;
1920
QPushButton *btnRun;
@@ -23,31 +24,22 @@ class Ui_MainWindow {
2324
QLabel *labelUnitSelected;
2425
QStatusBar *statusbar;
2526

26-
void setupUi(QMainWindow *MainWindow) {
27+
void setupUi(QMainWindow *MainWindow)
28+
{
2729
if (MainWindow->objectName().isEmpty())
2830
MainWindow->setObjectName("MainWindow");
29-
MainWindow->resize(586, 421);
30-
QSizePolicy sizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
31-
sizePolicy.setHorizontalStretch(0);
32-
sizePolicy.setVerticalStretch(0);
33-
sizePolicy.setHeightForWidth(MainWindow->sizePolicy().hasHeightForWidth());
34-
MainWindow->setSizePolicy(sizePolicy);
35-
MainWindow->setMinimumSize(QSize(586, 421));
36-
MainWindow->setMaximumSize(QSize(586, 421));
37-
QIcon icon;
38-
icon.addFile(QString::fromUtf8("RunAsGPU_Icon.png"), QSize(), QIcon::Mode::Normal, QIcon::State::Off);
39-
MainWindow->setWindowIcon(icon);
31+
MainWindow->resize(660, 460);
32+
MainWindow->setFixedSize(QSize(660, 460));
4033
centralwidget = new QWidget(MainWindow);
4134
centralwidget->setObjectName("centralwidget");
4235
btnRun = new QPushButton(centralwidget);
4336
btnRun->setObjectName("btnRun");
44-
btnRun->setGeometry(QRect(467, 310, 111, 34));
37+
btnRun->setGeometry(QRect(530, 310, 111, 34));
4538
appList = new QListView(centralwidget);
4639
appList->setObjectName("appList");
47-
appList->setGeometry(QRect(0, 20, 581, 281));
48-
appList->setStyleSheet("QListView::item:selected { background-color: #0078d7; }");
49-
appList->setFocusPolicy(Qt::StrongFocus);
40+
appList->setGeometry(QRect(10, 20, 641, 281));
5041
appList->setSelectionBehavior(QAbstractItemView::SelectionBehavior::SelectRows);
42+
appList->setWordWrap(true);
5143
btnApplicationAdd = new QPushButton(centralwidget);
5244
btnApplicationAdd->setObjectName("btnApplicationAdd");
5345
btnApplicationAdd->setGeometry(QRect(0, 310, 121, 34));
@@ -56,7 +48,8 @@ class Ui_MainWindow {
5648
btnUnitSelector->setGeometry(QRect(130, 310, 88, 34));
5749
labelUnitSelected = new QLabel(centralwidget);
5850
labelUnitSelected->setObjectName("labelUnitSelected");
59-
labelUnitSelected->setGeometry(QRect(0, 350, 571, 31));
51+
labelUnitSelected->setGeometry(QRect(10, 350, 631, 71));
52+
labelUnitSelected->setWordWrap(true);
6053
MainWindow->setCentralWidget(centralwidget);
6154
statusbar = new QStatusBar(MainWindow);
6255
statusbar->setObjectName("statusbar");
@@ -66,26 +59,26 @@ class Ui_MainWindow {
6659

6760
QMetaObject::connectSlotsByName(MainWindow);
6861

69-
performLogic();
62+
performLogic(MainWindow);
7063
} // setupUi
7164

72-
void retranslateUi(QMainWindow *MainWindow) const {
65+
void retranslateUi(QMainWindow *MainWindow)
66+
{
7367
MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "RunAsGPU", nullptr));
7468
btnRun->setText(QCoreApplication::translate("MainWindow", "Run Application", nullptr));
7569
btnApplicationAdd->setText(QCoreApplication::translate("MainWindow", "Add Application", nullptr));
7670
btnUnitSelector->setText(QCoreApplication::translate("MainWindow", "Select GPU", nullptr));
7771
labelUnitSelected->setText(QCoreApplication::translate("MainWindow", "Selected GPU: {{UNIT}}", nullptr));
7872
} // retranslateUi
7973

80-
void performLogic() const;
74+
void performLogic(QMainWindow* window) const;
8175

8276
};
8377

8478
namespace Ui {
85-
class MainWindow : public Ui_MainWindow {
86-
};
79+
class MainWindow: public Ui_MainWindow {};
8780
} // namespace Ui
8881

8982
QT_END_NAMESPACE
9083

91-
#endif // MAINWINDOW_HPP
84+
#endif // MainWindow_HPP

0 commit comments

Comments
 (0)