config: use hyprutils helper (#6891)

* flake.lock: update

nix/overlays: remove xwayland overlay (merged upstream)

* config: use hyprutils helper

* flake.lock: update

* CMake & Meson: update required versions
This commit is contained in:
Mihai Fufezan 2024-07-16 22:23:37 +03:00 committed by GitHub
parent bd526822de
commit da956c8a97
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 53 additions and 65 deletions

View file

@ -113,7 +113,7 @@ pkg_check_modules(deps REQUIRED IMPORTED_TARGET
wayland-server wayland-client wayland-cursor wayland-protocols wayland-server wayland-client wayland-cursor wayland-protocols
cairo pango pangocairo pixman-1 cairo pango pangocairo pixman-1
libdrm libinput hwdata libseat libdisplay-info libliftoff libudev gbm libdrm libinput hwdata libseat libdisplay-info libliftoff libudev gbm
hyprlang>=0.3.2 hyprcursor>=0.1.7 hyprutils>=0.1.5 hyprlang>=0.3.2 hyprcursor>=0.1.7 hyprutils>=0.2.0
) )
find_package(hyprwayland-scanner 0.3.10 REQUIRED) find_package(hyprwayland-scanner 0.3.10 REQUIRED)

View file

@ -87,11 +87,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1720545076, "lastModified": 1721071737,
"narHash": "sha256-Pxacc2uoxI00koXp5+CyNqHOTQlqNlK0rlRHDBHX4+g=", "narHash": "sha256-qmC9jGfbE4+EIBbbSAkrfR/p49wShjpv4/KztgE/P54=",
"owner": "hyprwm", "owner": "hyprwm",
"repo": "hyprutils", "repo": "hyprutils",
"rev": "6174a2a25f4e216c0f1d0c4278adc23c476b1d09", "rev": "eb1ceff2b87f6820789249f63faa8e9dcb54d05f",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -125,11 +125,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1720542800, "lastModified": 1720957393,
"narHash": "sha256-ZgnNHuKV6h2+fQ5LuqnUaqZey1Lqqt5dTUAiAnqH0QQ=", "narHash": "sha256-oedh2RwpjEa+TNxhg5Je9Ch6d3W1NKi7DbRO1ziHemA=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "feb2849fdeb70028c70d73b848214b00d324a497", "rev": "693bc46d169f5af9c992095736e82c3488bf7dbb",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -25,7 +25,6 @@ in {
inputs.hyprlang.overlays.default inputs.hyprlang.overlays.default
inputs.hyprutils.overlays.default inputs.hyprutils.overlays.default
inputs.hyprwayland-scanner.overlays.default inputs.hyprwayland-scanner.overlays.default
self.overlays.xwayland
# Hyprland packages themselves # Hyprland packages themselves
(final: prev: let (final: prev: let
@ -63,14 +62,4 @@ in {
hyprland-extras = lib.composeManyExtensions [ hyprland-extras = lib.composeManyExtensions [
inputs.xdph.overlays.xdg-desktop-portal-hyprland inputs.xdph.overlays.xdg-desktop-portal-hyprland
]; ];
# Patches XWayland's pkgconfig file to not include Cflags or includedir
# The above two variables trip up CMake and the build fails
xwayland = final: prev: {
xwayland = prev.xwayland.overrideAttrs (old: {
postInstall = ''
sed -i '/includedir/d' $out/lib/pkgconfig/xwayland.pc
'';
});
};
} }

View file

@ -8,6 +8,7 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <hyprutils/path/Path.hpp>
#include <string.h> #include <string.h>
#include <string> #include <string>
#include <sys/stat.h> #include <sys/stat.h>
@ -628,25 +629,49 @@ CConfigManager::CConfigManager() {
g_pHyprError->queueCreate(ERR.value(), CColor{1.0, 0.1, 0.1, 1.0}); g_pHyprError->queueCreate(ERR.value(), CColor{1.0, 0.1, 0.1, 1.0});
} }
std::string CConfigManager::getConfigDir() { std::optional<std::string> CConfigManager::generateConfig(std::string configPath) {
static const char* xdgConfigHome = getenv("XDG_CONFIG_HOME"); std::string parentPath = std::filesystem::path(configPath).parent_path();
if (xdgConfigHome && std::filesystem::path(xdgConfigHome).is_absolute()) if (!std::filesystem::is_directory(parentPath)) {
return xdgConfigHome; Debug::log(WARN, "Creating config home directory");
try {
std::filesystem::create_directories(parentPath);
} catch (std::exception e) { throw e; }
}
static const char* home = getenv("HOME"); Debug::log(WARN, "No config file found; attempting to generate.");
std::ofstream ofs;
ofs.open(configPath, std::ios::trunc);
ofs << AUTOCONFIG;
ofs.close();
if (!home) if (!std::filesystem::exists(configPath))
throw std::runtime_error("Neither HOME nor XDG_CONFIG_HOME is set in the environment. Cannot determine config directory."); return "Config could not be generated.";
return home + std::string("/.config"); return configPath;
} }
std::string CConfigManager::getMainConfigPath() { std::string CConfigManager::getMainConfigPath() {
if (!g_pCompositor->explicitConfigPath.empty()) if (!g_pCompositor->explicitConfigPath.empty())
return g_pCompositor->explicitConfigPath; return g_pCompositor->explicitConfigPath;
return getConfigDir() + "/hypr/" + (ISDEBUG ? "hyprlandd.conf" : "hyprland.conf"); static const auto paths = Hyprutils::Path::findConfig(ISDEBUG ? "hyprlandd" : "hyprland");
if (paths.first.has_value()) {
return paths.first.value();
} else if (paths.second.has_value()) {
auto configPath = Hyprutils::Path::fullConfigPath(paths.second.value(), ISDEBUG ? "hyprlandd" : "hyprland");
return generateConfig(configPath).value();
} else
throw std::runtime_error("Neither HOME nor XDG_CONFIG_HOME are set in the environment. Could not find config in XDG_CONFIG_DIRS or /etc/xdg.");
}
std::optional<std::string> CConfigManager::verifyConfigExists() {
std::string mainConfigPath = getMainConfigPath();
if (!std::filesystem::exists(mainConfigPath))
return "broken config dir?";
return {};
} }
const std::string CConfigManager::getConfigString() { const std::string CConfigManager::getConfigString() {
@ -742,32 +767,6 @@ void CConfigManager::setDefaultAnimationVars() {
CREATEANIMCFG("specialWorkspace", "workspaces"); CREATEANIMCFG("specialWorkspace", "workspaces");
} }
std::optional<std::string> CConfigManager::verifyConfigExists() {
std::string mainConfigPath = getMainConfigPath();
if (g_pCompositor->explicitConfigPath.empty() && !std::filesystem::exists(mainConfigPath)) {
std::string configPath = std::filesystem::path(mainConfigPath).parent_path();
if (!std::filesystem::is_directory(configPath)) {
Debug::log(WARN, "Creating config home directory");
try {
std::filesystem::create_directories(configPath);
} catch (...) { return "Broken config file! (Could not create config directory)"; }
}
Debug::log(WARN, "No config file found; attempting to generate.");
std::ofstream ofs;
ofs.open(mainConfigPath, std::ios::trunc);
ofs << AUTOCONFIG;
ofs.close();
}
if (!std::filesystem::exists(mainConfigPath))
return "broken config dir?";
return {};
}
std::optional<std::string> CConfigManager::resetHLConfig() { std::optional<std::string> CConfigManager::resetHLConfig() {
m_dMonitorRules.clear(); m_dMonitorRules.clear();
m_dWindowRules.clear(); m_dWindowRules.clear();

View file

@ -101,7 +101,6 @@ class CConfigManager {
void* const* getConfigValuePtr(const std::string&); void* const* getConfigValuePtr(const std::string&);
Hyprlang::CConfigValue* getHyprlangConfigValuePtr(const std::string& name, const std::string& specialCat = ""); Hyprlang::CConfigValue* getHyprlangConfigValuePtr(const std::string& name, const std::string& specialCat = "");
void onPluginLoadUnload(const std::string& name, bool load); void onPluginLoadUnload(const std::string& name, bool load);
static std::string getConfigDir();
static std::string getMainConfigPath(); static std::string getMainConfigPath();
const std::string getConfigString(); const std::string getConfigString();
@ -228,7 +227,8 @@ class CConfigManager {
void updateBlurredLS(const std::string&, const bool); void updateBlurredLS(const std::string&, const bool);
void setDefaultAnimationVars(); void setDefaultAnimationVars();
std::optional<std::string> resetHLConfig(); std::optional<std::string> resetHLConfig();
std::optional<std::string> verifyConfigExists(); static std::optional<std::string> generateConfig(std::string configPath);
static std::optional<std::string> verifyConfigExists();
void postConfigReload(const Hyprlang::CParseResult& result); void postConfigReload(const Hyprlang::CParseResult& result);
void reload(); void reload();
SWorkspaceRule mergeWorkspaceRules(const SWorkspaceRule&, const SWorkspaceRule&); SWorkspaceRule mergeWorkspaceRules(const SWorkspaceRule&, const SWorkspaceRule&);

View file

@ -11,9 +11,9 @@ executable('Hyprland', src,
dependency('wayland-client'), dependency('wayland-client'),
wlroots.get_variable('wlroots'), wlroots.get_variable('wlroots'),
dependency('cairo'), dependency('cairo'),
dependency('hyprcursor'), dependency('hyprcursor', version: '>=0.1.7'),
dependency('hyprlang', version: '>= 0.3.2'), dependency('hyprlang', version: '>= 0.3.2'),
dependency('hyprutils', version: '>= 0.1.1'), dependency('hyprutils', version: '>= 0.2.0'),
dependency('libdrm'), dependency('libdrm'),
dependency('egl'), dependency('egl'),
dependency('xkbcommon'), dependency('xkbcommon'),

View file

@ -842,7 +842,7 @@ void CHyprOpenGLImpl::applyScreenShader(const std::string& path) {
if (path == "" || path == STRVAL_EMPTY) if (path == "" || path == STRVAL_EMPTY)
return; return;
std::ifstream infile(absolutePath(path, g_pConfigManager->getConfigDir())); std::ifstream infile(absolutePath(path, g_pConfigManager->getMainConfigPath()));
if (!infile.good()) { if (!infile.good()) {
g_pConfigManager->addParseError("Screen shader parser: Screen shader path not found"); g_pConfigManager->addParseError("Screen shader parser: Screen shader path not found");