diff options
| author | Tom Englund <tomenglund26@gmail.com> | 2024-08-09 19:33:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-09 19:33:20 +0200 |
| commit | 8b37e81374928856d8fd859b95a62c8bf4211901 (patch) | |
| tree | 652ada086c38773b8616da8a7926ad7b5ab51dab /src/managers/XCursorManager.cpp | |
| parent | fd1d4e288edd586a3d5273cda053a51f5b14cad7 (diff) | |
cursormgr: add a new setting to sync gsettings (#7253)
cursor:sync_gsettings_theme is set to default true and if enabled it
will now sync xcursor theme loading with gsettings if it can, meaning
CSD clients will now also change to the appropiate theme upon start and
hyprctl setcursor THEME SIZE .
Diffstat (limited to 'src/managers/XCursorManager.cpp')
| -rw-r--r-- | src/managers/XCursorManager.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/managers/XCursorManager.cpp b/src/managers/XCursorManager.cpp index f2a7ab53..1108bbb2 100644 --- a/src/managers/XCursorManager.cpp +++ b/src/managers/XCursorManager.cpp @@ -1,6 +1,9 @@ #include <cstring> #include <dirent.h> #include <filesystem> +#include <gio/gio.h> +#include <gio/gsettingsschema.h> +#include "config/ConfigValue.hpp" #include "helpers/CursorShapes.hpp" #include "debug/Log.hpp" #include "XCursorManager.hpp" @@ -146,6 +149,10 @@ void CXCursorManager::loadTheme(std::string const& name, int size) { cursors.emplace_back(cursor); } + + static auto SYNCGSETTINGS = CConfigValue<Hyprlang::INT>("cursor:sync_gsettings_theme"); + if (*SYNCGSETTINGS) + syncGsettings(); } SP<SXCursors> CXCursorManager::getShape(std::string const& shape, int size) { @@ -542,3 +549,55 @@ std::vector<SP<SXCursors>> CXCursorManager::loadAllFromDir(std::string const& pa return newCursors; } + +void CXCursorManager::syncGsettings() { + auto checkParamExists = [](std::string const& paramName, std::string const& category) { + auto* gSettingsSchemaSource = g_settings_schema_source_get_default(); + + if (!gSettingsSchemaSource) { + Debug::log(WARN, "GSettings default schema source does not exist, cant sync GSettings"); + return false; + } + + auto* gSettingsSchema = g_settings_schema_source_lookup(gSettingsSchemaSource, category.c_str(), true); + bool hasParam = false; + + if (gSettingsSchema != NULL) { + hasParam = gSettingsSchema && g_settings_schema_has_key(gSettingsSchema, paramName.c_str()); + g_settings_schema_unref(gSettingsSchema); + } + + return hasParam; + }; + + using SettingValue = std::variant<std::string, int>; + auto setValue = [&checkParamExists](std::string const& paramName, const SettingValue& paramValue, std::string const& category) { + if (!checkParamExists(paramName, category)) { + Debug::log(WARN, "GSettings parameter doesnt exist {} in {}", paramName, category); + return; + } + + auto* gsettings = g_settings_new(category.c_str()); + + if (!gsettings) { + Debug::log(WARN, "GSettings failed to allocate new settings with category {}", category); + return; + } + + std::visit( + [&](auto&& value) { + using T = std::decay_t<decltype(value)>; + if constexpr (std::is_same_v<T, std::string>) + g_settings_set_string(gsettings, paramName.c_str(), value.c_str()); + else if constexpr (std::is_same_v<T, int>) + g_settings_set_int(gsettings, paramName.c_str(), value); + }, + paramValue); + + g_settings_sync(); + g_object_unref(gsettings); + }; + + setValue("cursor-theme", themeName, "org.gnome.desktop.interface"); + setValue("cursor-size", lastLoadSize, "org.gnome.desktop.interface"); +} |
