core: add qt version check in preprocessor

This commit is contained in:
outfoxxed committed 2026-04-27 02:18:32 -07:00
1 parent 055e384668
commit 2ba2ae48b4
4 files changed
+29 -1

No files matched your search

+8
View File
@@ -18,8 +18,10 @@
#include <qscreen.h>
#include <qtenvironmentvariables.h>
#include <qtmetamacros.h>
#include <qtversion.h>
#include <qtypes.h>
#include <qvariant.h>
#include <qversionnumber.h>
#include <qwindowdefs.h>
#include <unistd.h>
@@ -343,6 +345,12 @@ bool QuickshellGlobal::hasVersion(qint32 major, qint32 minor) {
return QuickshellGlobal::hasVersion(major, minor, QStringList());
}
bool QuickshellGlobal::hasQtVersion(int major, int minor) {
auto qtVersion = QVersionNumber::fromString(qVersion());
auto requiredVersion = QVersionNumber(major, minor);
return qtVersion >= requiredVersion;
}
QuickshellGlobal* QuickshellGlobal::create(QQmlEngine* engine, QJSEngine* /*unused*/) {
auto* qsg = new QuickshellGlobal();
auto* generation = EngineGeneration::findEngineGeneration(engine);
+12 -1
View File
@@ -244,7 +244,7 @@ public:
/// it is assumed that all unreleased features are present. The unreleased feature list
/// may be omitted.
///
/// > [!NOTE] You can feature gate code blocks using Quickshell's preprocessor which
/// > [!NOTE] You can version gate code blocks using Quickshell's preprocessor which
/// > has the same function available.
/// >
/// > ```qml
@@ -254,6 +254,17 @@ public:
/// > ```
Q_INVOKABLE static bool hasVersion(qint32 major, qint32 minor, const QStringList& features);
Q_INVOKABLE static bool hasVersion(qint32 major, qint32 minor);
/// Check if Qt's version is at least `major.minor`.
///
/// > [!NOTE] You can version gate code blocks using Quickshell's preprocessor which
/// > has the same function available.
/// >
/// > ```qml
/// > //@ if hasVersion(6, 10)
/// > ...
/// > //@ endif
/// > ```
Q_INVOKABLE static bool hasQtVersion(qint32 major, qint32 minor);
void clearReloadPopupInhibit() { this->mInhibitReloadPopup = false; }
[[nodiscard]] bool isReloadPopupInhibited() const { return this->mInhibitReloadPopup; }
+8
View File
@@ -2,6 +2,8 @@
#include <qcontainerfwd.h>
#include <qtenvironmentvariables.h>
#include <qtversion.h>
#include <qversionnumber.h>
#include "build.hpp"
@@ -20,6 +22,12 @@ bool PreprocEnv::hasVersion(int major, int minor, const QStringList& features) {
return QS_VERSION_MAJOR == major && QS_VERSION_MINOR == minor;
}
bool PreprocEnv::hasQtVersion(int major, int minor) {
auto qtVersion = QVersionNumber::fromString(qVersion());
auto requiredVersion = QVersionNumber(major, minor);
return qtVersion >= requiredVersion;
}
QString PreprocEnv::env(const QString& variable) {
return qEnvironmentVariable(variable.toStdString().c_str());
}
+1
View File
@@ -12,6 +12,7 @@ class PreprocEnv: public QObject {
public:
Q_INVOKABLE static bool
hasVersion(int major, int minor, const QStringList& features = QStringList());
Q_INVOKABLE static bool hasQtVersion(int major, int minor);
Q_INVOKABLE static QString env(const QString& variable);
Q_INVOKABLE static bool isEnvSet(const QString& variable);