diff --git a/src/Compositor.cpp b/src/Compositor.cpp index c3f959614482..7f17d5157d9f 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -393,6 +393,7 @@ void CCompositor::initAllSignals() { } g_pConfigManager->m_bWantsMonitorReload = true; + g_pCursorManager->syncGsettings(); } else { Debug::log(LOG, "Session got deactivated!"); diff --git a/src/managers/CursorManager.cpp b/src/managers/CursorManager.cpp index 3f3a25f6f4e5..8a14b31d1ba4 100644 --- a/src/managers/CursorManager.cpp +++ b/src/managers/CursorManager.cpp @@ -3,6 +3,8 @@ #include "../config/ConfigValue.hpp" #include "PointerManager.hpp" #include "../xwayland/XWayland.hpp" +#include +#include static int cursorAnimTimer(SP self, void* data) { const auto cursorMgr = reinterpret_cast(data); @@ -337,4 +339,66 @@ bool CCursorManager::changeTheme(const std::string& name, const int size) { updateTheme(); return true; -} \ No newline at end of file +} + +void CCursorManager::syncGsettings() { + syncGsettings(m_szTheme.empty() ? m_pXcursor->themeName : m_szTheme, m_iSize); +} + +void CCursorManager::syncGsettings(const std::string& name, int size) { + static auto SYNCGSETTINGS = CConfigValue("cursor:sync_gsettings_theme"); + if (!*SYNCGSETTINGS) + return; + + 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; + 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; + if constexpr (std::is_same_v) + g_settings_set_string(gsettings, paramName.c_str(), value.c_str()); + else if constexpr (std::is_same_v) + g_settings_set_int(gsettings, paramName.c_str(), value); + }, + paramValue); + + g_settings_sync(); + g_object_unref(gsettings); + }; + + Debug::log(LOG, "syncing gsettings {} {}", name, size); + + setValue("cursor-theme", name, "org.gnome.desktop.interface"); + setValue("cursor-size", size, "org.gnome.desktop.interface"); +} diff --git a/src/managers/CursorManager.hpp b/src/managers/CursorManager.hpp index ceb4816baf34..d0bb7da8d5ba 100644 --- a/src/managers/CursorManager.hpp +++ b/src/managers/CursorManager.hpp @@ -53,6 +53,8 @@ class CCursorManager { void updateTheme(); SCursorImageData dataFor(const std::string& name); // for xwayland void setXWaylandCursor(); + void syncGsettings(); + static void syncGsettings(const std::string& name, int size); void tickAnimatedCursor(); @@ -75,4 +77,4 @@ class CCursorManager { Hyprcursor::SCursorShapeData m_sCurrentCursorShapeData; }; -inline std::unique_ptr g_pCursorManager; \ No newline at end of file +inline std::unique_ptr g_pCursorManager; diff --git a/src/managers/XCursorManager.cpp b/src/managers/XCursorManager.cpp index 1108bbb20e66..7c4c50601e74 100644 --- a/src/managers/XCursorManager.cpp +++ b/src/managers/XCursorManager.cpp @@ -5,6 +5,7 @@ #include #include "config/ConfigValue.hpp" #include "helpers/CursorShapes.hpp" +#include "../managers/CursorManager.hpp" #include "debug/Log.hpp" #include "XCursorManager.hpp" @@ -150,9 +151,7 @@ void CXCursorManager::loadTheme(std::string const& name, int size) { cursors.emplace_back(cursor); } - static auto SYNCGSETTINGS = CConfigValue("cursor:sync_gsettings_theme"); - if (*SYNCGSETTINGS) - syncGsettings(); + CCursorManager::syncGsettings(themeName, lastLoadSize); } SP CXCursorManager::getShape(std::string const& shape, int size) { @@ -549,55 +548,3 @@ std::vector> 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; - 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; - if constexpr (std::is_same_v) - g_settings_set_string(gsettings, paramName.c_str(), value.c_str()); - else if constexpr (std::is_same_v) - 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"); -} diff --git a/src/managers/XCursorManager.hpp b/src/managers/XCursorManager.hpp index 464c1ec3fe82..cd24ae34a9c4 100644 --- a/src/managers/XCursorManager.hpp +++ b/src/managers/XCursorManager.hpp @@ -32,17 +32,17 @@ class CXCursorManager { void loadTheme(const std::string& name, int size); SP getShape(std::string const& shape, int size); + std::string themeName = ""; + private: SP createCursor(std::string const& shape, XcursorImages* xImages); std::unordered_set themePaths(std::string const& theme); std::string getLegacyShapeName(std::string const& shape); std::vector> loadStandardCursors(std::string const& name, int size); std::vector> loadAllFromDir(std::string const& path, int size); - void syncGsettings(); int lastLoadSize = 0; - std::string themeName = ""; SP defaultCursor; SP hyprCursor; std::vector> cursors; -}; \ No newline at end of file +};