forked from quickshell/quickshell
		
	core: add pragmas
UseQApplication: use QApplication over QGuiApplication (for qqc2-desktop-style) NativeTextRendering: use NativeTextRendering over QtRendering for text Env VAR = VAL: define environment variables (usually qt ones)
This commit is contained in:
		
							parent
							
								
									c0847366dd
								
							
						
					
					
						commit
						082c3c480f
					
				
					 2 changed files with 245 additions and 175 deletions
				
			
		| 
						 | 
					@ -57,8 +57,8 @@ if (NOT CMAKE_BUILD_TYPE)
 | 
				
			||||||
	set(CMAKE_BUILD_TYPE Debug)
 | 
						set(CMAKE_BUILD_TYPE Debug)
 | 
				
			||||||
endif()
 | 
					endif()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
set(QT_DEPS Qt6::Gui Qt6::Qml Qt6::Quick Qt6::QuickControls2)
 | 
					set(QT_DEPS Qt6::Gui Qt6::Qml Qt6::Quick Qt6::QuickControls2 Qt6::Widgets)
 | 
				
			||||||
set(QT_FPDEPS Gui Qml Quick QuickControls2)
 | 
					set(QT_FPDEPS Gui Qml Quick QuickControls2 Widgets)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if (BUILD_TESTING)
 | 
					if (BUILD_TESTING)
 | 
				
			||||||
	enable_testing()
 | 
						enable_testing()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,11 +1,14 @@
 | 
				
			||||||
#include "main.hpp"
 | 
					#include "main.hpp"
 | 
				
			||||||
#include <iostream>
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <qapplication.h>
 | 
				
			||||||
#include <qcommandlineoption.h>
 | 
					#include <qcommandlineoption.h>
 | 
				
			||||||
#include <qcommandlineparser.h>
 | 
					#include <qcommandlineparser.h>
 | 
				
			||||||
 | 
					#include <qcoreapplication.h>
 | 
				
			||||||
#include <qdir.h>
 | 
					#include <qdir.h>
 | 
				
			||||||
#include <qfileinfo.h>
 | 
					#include <qfileinfo.h>
 | 
				
			||||||
#include <qguiapplication.h>
 | 
					#include <qguiapplication.h>
 | 
				
			||||||
 | 
					#include <qhash.h>
 | 
				
			||||||
#include <qlogging.h>
 | 
					#include <qlogging.h>
 | 
				
			||||||
#include <qobject.h>
 | 
					#include <qobject.h>
 | 
				
			||||||
#include <qquickwindow.h>
 | 
					#include <qquickwindow.h>
 | 
				
			||||||
| 
						 | 
					@ -19,9 +22,17 @@
 | 
				
			||||||
#include "rootwrapper.hpp"
 | 
					#include "rootwrapper.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int qs_main(int argc, char** argv) {
 | 
					int qs_main(int argc, char** argv) {
 | 
				
			||||||
	const auto app = QGuiApplication(argc, argv);
 | 
						QString configFilePath;
 | 
				
			||||||
	QGuiApplication::setApplicationName("quickshell");
 | 
						QString workingDirectory;
 | 
				
			||||||
	QGuiApplication::setApplicationVersion("0.1.0 (" GIT_REVISION ")");
 | 
					
 | 
				
			||||||
 | 
						auto useQApplication = false;
 | 
				
			||||||
 | 
						auto nativeTextRendering = false;
 | 
				
			||||||
 | 
						QHash<QString, QString> envOverrides;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							const auto app = QCoreApplication(argc, argv);
 | 
				
			||||||
 | 
							QCoreApplication::setApplicationName("quickshell");
 | 
				
			||||||
 | 
							QCoreApplication::setApplicationVersion("0.1.0 (" GIT_REVISION ")");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		QCommandLineParser parser;
 | 
							QCommandLineParser parser;
 | 
				
			||||||
		parser.addHelpOption();
 | 
							parser.addHelpOption();
 | 
				
			||||||
| 
						 | 
					@ -42,7 +53,6 @@ int qs_main(int argc, char** argv) {
 | 
				
			||||||
		parser.addOption(workdirOption);
 | 
							parser.addOption(workdirOption);
 | 
				
			||||||
		parser.process(app);
 | 
							parser.process(app);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QString configFilePath;
 | 
					 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			auto printCurrent = parser.isSet(currentOption);
 | 
								auto printCurrent = parser.isSet(currentOption);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -138,7 +148,7 @@ int qs_main(int argc, char** argv) {
 | 
				
			||||||
		foundname:;
 | 
							foundname:;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (configPathLevel == 0 && configNameLevel == 0) {
 | 
								if (configPathLevel == 0 && configNameLevel == 0) {
 | 
				
			||||||
			qFatal() << "Pass only one of --path or --config";
 | 
									qCritical() << "Pass only one of --path or --config";
 | 
				
			||||||
				return -1;
 | 
									return -1;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -156,7 +166,8 @@ int qs_main(int argc, char** argv) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							auto split = line.split('=');
 | 
												auto split = line.split('=');
 | 
				
			||||||
							if (split.length() != 2) {
 | 
												if (split.length() != 2) {
 | 
				
			||||||
							qFatal() << "manifest line not in expected format 'name = relativepath':" << line;
 | 
													qCritical() << "manifest line not in expected format 'name = relativepath':"
 | 
				
			||||||
 | 
													            << line;
 | 
				
			||||||
								return -1;
 | 
													return -1;
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -166,10 +177,10 @@ int qs_main(int argc, char** argv) {
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					qFatal() << "configuration" << configName << "not found in manifest" << manifestPath;
 | 
											qCritical() << "configuration" << configName << "not found in manifest" << manifestPath;
 | 
				
			||||||
						return -1;
 | 
											return -1;
 | 
				
			||||||
					} else if (manifestPathLevel < 2) {
 | 
										} else if (manifestPathLevel < 2) {
 | 
				
			||||||
					qFatal() << "cannot open config manifest at" << manifestPath;
 | 
											qCritical() << "cannot open config manifest at" << manifestPath;
 | 
				
			||||||
						return -1;
 | 
											return -1;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					@ -177,10 +188,10 @@ int qs_main(int argc, char** argv) {
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					auto basePathInfo = QFileInfo(basePath);
 | 
										auto basePathInfo = QFileInfo(basePath);
 | 
				
			||||||
					if (!basePathInfo.exists()) {
 | 
										if (!basePathInfo.exists()) {
 | 
				
			||||||
					qFatal() << "base path does not exist:" << basePath;
 | 
											qCritical() << "base path does not exist:" << basePath;
 | 
				
			||||||
						return -1;
 | 
											return -1;
 | 
				
			||||||
					} else if (!QFileInfo(basePathInfo.canonicalFilePath()).isDir()) {
 | 
										} else if (!QFileInfo(basePathInfo.canonicalFilePath()).isDir()) {
 | 
				
			||||||
					qFatal() << "base path is not a directory" << basePath;
 | 
											qCritical() << "base path is not a directory" << basePath;
 | 
				
			||||||
						return -1;
 | 
											return -1;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -192,7 +203,7 @@ int qs_main(int argc, char** argv) {
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				qFatal() << "no directory named " << configName << "found in base path" << basePath;
 | 
										qCritical() << "no directory named " << configName << "found in base path" << basePath;
 | 
				
			||||||
					return -1;
 | 
										return -1;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			haspath:;
 | 
								haspath:;
 | 
				
			||||||
| 
						 | 
					@ -202,7 +213,7 @@ int qs_main(int argc, char** argv) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			auto configFile = QFileInfo(configFilePath);
 | 
								auto configFile = QFileInfo(configFilePath);
 | 
				
			||||||
			if (!configFile.exists()) {
 | 
								if (!configFile.exists()) {
 | 
				
			||||||
			qFatal() << "config path does not exist:" << configFilePath;
 | 
									qCritical() << "config path does not exist:" << configFilePath;
 | 
				
			||||||
				return -1;
 | 
									return -1;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -212,20 +223,20 @@ int qs_main(int argc, char** argv) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			configFile = QFileInfo(configFilePath);
 | 
								configFile = QFileInfo(configFilePath);
 | 
				
			||||||
			if (!configFile.exists()) {
 | 
								if (!configFile.exists()) {
 | 
				
			||||||
			qFatal() << "no shell.qml found in config path:" << configFilePath;
 | 
									qCritical() << "no shell.qml found in config path:" << configFilePath;
 | 
				
			||||||
				return -1;
 | 
									return -1;
 | 
				
			||||||
			} else if (configFile.isDir()) {
 | 
								} else if (configFile.isDir()) {
 | 
				
			||||||
			qFatal() << "shell.qml is a directory:" << configFilePath;
 | 
									qCritical() << "shell.qml is a directory:" << configFilePath;
 | 
				
			||||||
				return -1;
 | 
									return -1;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			configFilePath = QFileInfo(configFilePath).canonicalFilePath();
 | 
								configFilePath = QFileInfo(configFilePath).canonicalFilePath();
 | 
				
			||||||
			configFile = QFileInfo(configFilePath);
 | 
								configFile = QFileInfo(configFilePath);
 | 
				
			||||||
			if (!configFile.exists()) {
 | 
								if (!configFile.exists()) {
 | 
				
			||||||
			qFatal() << "config file does not exist:" << configFilePath;
 | 
									qCritical() << "config file does not exist:" << configFilePath;
 | 
				
			||||||
				return -1;
 | 
									return -1;
 | 
				
			||||||
			} else if (configFile.isDir()) {
 | 
								} else if (configFile.isDir()) {
 | 
				
			||||||
			qFatal() << "config file is a directory:" << configFilePath;
 | 
									qCritical() << "config file is a directory:" << configFilePath;
 | 
				
			||||||
				return -1;
 | 
									return -1;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -243,7 +254,62 @@ int qs_main(int argc, char** argv) {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (parser.isSet(workdirOption)) {
 | 
							if (parser.isSet(workdirOption)) {
 | 
				
			||||||
		QDir::setCurrent(parser.value(workdirOption));
 | 
								workingDirectory = parser.value(workdirOption);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							auto file = QFile(configFilePath);
 | 
				
			||||||
 | 
							if (!file.open(QFile::ReadOnly | QFile::Text)) {
 | 
				
			||||||
 | 
								qCritical() << "could not open config file";
 | 
				
			||||||
 | 
								return -1;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							auto stream = QTextStream(&file);
 | 
				
			||||||
 | 
							while (!stream.atEnd()) {
 | 
				
			||||||
 | 
								auto line = stream.readLine().trimmed();
 | 
				
			||||||
 | 
								if (line.startsWith("//@ pragma ")) {
 | 
				
			||||||
 | 
									auto pragma = line.sliced(11).trimmed();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (pragma == "UseQApplication") useQApplication = true;
 | 
				
			||||||
 | 
									else if (pragma == "NativeTextRendering") nativeTextRendering = true;
 | 
				
			||||||
 | 
									else if (pragma.startsWith("Env ")) {
 | 
				
			||||||
 | 
										auto envPragma = pragma.sliced(4);
 | 
				
			||||||
 | 
										auto splitIdx = envPragma.indexOf('=');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										if (splitIdx == -1) {
 | 
				
			||||||
 | 
											qCritical() << "Env pragma" << pragma << "not in the form 'VAR = VALUE'";
 | 
				
			||||||
 | 
											return -1;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										auto var = envPragma.sliced(0, splitIdx).trimmed();
 | 
				
			||||||
 | 
										auto val = envPragma.sliced(splitIdx + 1).trimmed();
 | 
				
			||||||
 | 
										envOverrides.insert(var, val);
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										qCritical() << "Unrecognized pragma" << pragma;
 | 
				
			||||||
 | 
										return -1;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								} else if (line.startsWith("import")) break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							file.close();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (auto [var, val]: envOverrides.asKeyValueRange()) {
 | 
				
			||||||
 | 
							qputenv(var.toUtf8(), val.toUtf8());
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						QCoreApplication* app = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (useQApplication) {
 | 
				
			||||||
 | 
							app = new QApplication(argc, argv);
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							app = new QGuiApplication(argc, argv);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						QCoreApplication::setApplicationName("quickshell");
 | 
				
			||||||
 | 
						QCoreApplication::setApplicationVersion("0.1.0 (" GIT_REVISION ")");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!workingDirectory.isEmpty()) {
 | 
				
			||||||
 | 
							QDir::setCurrent(workingDirectory);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QuickshellPlugin::initPlugins();
 | 
						QuickshellPlugin::initPlugins();
 | 
				
			||||||
| 
						 | 
					@ -252,8 +318,12 @@ int qs_main(int argc, char** argv) {
 | 
				
			||||||
	// Use a fully transparent window with a colored rect.
 | 
						// Use a fully transparent window with a colored rect.
 | 
				
			||||||
	QQuickWindow::setDefaultAlphaBuffer(true);
 | 
						QQuickWindow::setDefaultAlphaBuffer(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (nativeTextRendering) {
 | 
				
			||||||
 | 
							QQuickWindow::setTextRenderType(QQuickWindow::NativeTextRendering);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	auto root = RootWrapper(configFilePath);
 | 
						auto root = RootWrapper(configFilePath);
 | 
				
			||||||
	QGuiApplication::setQuitOnLastWindowClosed(false);
 | 
						QGuiApplication::setQuitOnLastWindowClosed(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return QGuiApplication::exec();
 | 
						return QCoreApplication::exec();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue