From b5110b759e84185de01fd761ee20105b15009095 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Sun, 3 Mar 2024 02:24:33 -0800 Subject: [PATCH] feat: add Quickshell.env --- docs | 2 +- src/core/qmlglobal.cpp | 9 +++++++++ src/core/qmlglobal.hpp | 4 ++++ src/io/socket.hpp | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs b/docs index 79579222..8b40a464 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 79579222a31dc1f6355e0c3020917c29165f766c +Subproject commit 8b40a464af5c1338d842e61f8ec517d142454cbc diff --git a/src/core/qmlglobal.cpp b/src/core/qmlglobal.cpp index ada4b9e1..014999d6 100644 --- a/src/core/qmlglobal.cpp +++ b/src/core/qmlglobal.cpp @@ -8,8 +8,10 @@ #include #include #include +#include #include #include +#include #include "qmlscreen.hpp" #include "rootwrapper.hpp" @@ -74,3 +76,10 @@ void QuickshellGlobal::updateScreens() { emit this->screensChanged(); } + +QVariant QuickshellGlobal::env(const QString& variable) { // NOLINT + auto vstr = variable.toStdString(); + if (!qEnvironmentVariableIsSet(vstr.data())) return QVariant(); + + return qEnvironmentVariable(vstr.data()); +} diff --git a/src/core/qmlglobal.hpp b/src/core/qmlglobal.hpp index 6c9634f3..f9b4ff86 100644 --- a/src/core/qmlglobal.hpp +++ b/src/core/qmlglobal.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "qmlscreen.hpp" @@ -50,6 +51,9 @@ public: /// [Reloadable]: ../reloadable Q_INVOKABLE void reload(bool hard); + /// Returns the string value of an environment variable or null if it is not set. + Q_INVOKABLE QVariant env(const QString& variable); + signals: void screensChanged(); diff --git a/src/io/socket.hpp b/src/io/socket.hpp index 4fcf16b6..25b8a1df 100644 --- a/src/io/socket.hpp +++ b/src/io/socket.hpp @@ -8,8 +8,8 @@ #include #include -#include "datastream.hpp" #include "../core/reload.hpp" +#include "datastream.hpp" ///! Unix socket listener. class Socket: public DataStream {