diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d26b20..c85e1ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,14 @@ set(MSDFGEN_DISABLE_SVG ON) set(MSDFGEN_DISABLE_PNG ON) FetchContent_MakeAvailable(msdfgen) +FetchContent_Declare( + mINI + GIT_REPOSITORY https://github.com/metayeti/mINI.git + GIT_TAG "0.9.18" + GIT_SHALLOW 1 +) +FetchContent_MakeAvailable(mINI) + find_program(WAYLAND_SCANNER wayland-scanner REQUIRED) pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir) @@ -140,6 +148,7 @@ add_custom_target(generate_protocols ALL add_executable(waylight ${GEN_C_PRIVATES} + ${CMAKE_CURRENT_SOURCE_DIR}/src/IconRegistry.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/TextRenderer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/ImGui.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/App.cpp @@ -163,6 +172,7 @@ target_link_libraries(waylight PRIVATE PkgConfig::FONTCONFIG PkgConfig::HARFBUZZ + mINI raylib msdfgen::msdfgen-core msdfgen::msdfgen-ext diff --git a/src/IconRegistry.cpp b/src/IconRegistry.cpp index a184461..55dda53 100644 --- a/src/IconRegistry.cpp +++ b/src/IconRegistry.cpp @@ -5,6 +5,8 @@ #include #include +#include + IconTheme::IconTheme(std::filesystem::path const &themes_directory_path) { for (auto const &dir : @@ -15,6 +17,56 @@ IconTheme::IconTheme(std::filesystem::path const &themes_directory_path) auto const index_path = dir.path() / "index.theme"; if (std::filesystem::is_regular_file(index_path)) continue; + + mINI::INIFile ini_file(index_path); + mINI::INIStructure ini; + ini_file.read(ini); + + auto const &directories { ini["Icon Theme"]["Directories"] }; + for (auto const &&dir_entry : directories | std::views::split(':')) { + auto const dir_entry_str { std::string( + dir_entry.begin(), dir_entry.end()) }; + auto const path { std::filesystem::path(dir_entry_str) }; + auto const path_actual { dir.path() / path }; + + if (!std::filesystem::is_directory(path_actual)) + continue; + + auto const &type_raw { ini[dir_entry_str]["Type"] }; + DirectoryEntry::Type type; + if (type_raw == "Fixed") { + type = DirectoryEntry::Type::Fixed; + } else if (type_raw == "Scalable") { + type = DirectoryEntry::Type::Scalable; + } else if (type_raw == "Threshold") { + type = DirectoryEntry::Type::Threshold; + } else { + continue; + } + + auto const &context_raw { ini[dir_entry_str]["context"] }; + DirectoryEntry::Context context; + if (context_raw == "Actions") { + context = DirectoryEntry::Context::Actions; + } else if (type_raw == "Devices") { + context = DirectoryEntry::Context::Devices; + } else if (type_raw == "FileSystems") { + context = DirectoryEntry::Context::FileSystems; + } else if (type_raw == "MomeTypes") { + context = DirectoryEntry::Context::MimeTypes; + } else { + continue; + } + + int size { std::atoi(ini[dir_entry_str]["Size"].c_str()) }; + + m_directories.push_back({ + .path = path, + .size = size, + .type = type, + .context = context, + }); + } } } @@ -44,7 +96,7 @@ IconRegistry::IconRegistry() theme_directory_paths.push_back(path); } - for (auto const &path : std::move(theme_directory_paths) + for (auto &&path : std::move(theme_directory_paths) | std::views::filter([](std::filesystem::path &path) { return std::filesystem::is_directory(path); })) { diff --git a/src/IconRegistry.hpp b/src/IconRegistry.hpp index d57be76..796d9b6 100644 --- a/src/IconRegistry.hpp +++ b/src/IconRegistry.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -10,8 +11,35 @@ struct IconTheme { IconTheme(std::filesystem::path const &themes_directory_path); ~IconTheme() = default; + auto inherits() const -> std::span + { + return std::span { m_inherits }; + } + private: + struct DirectoryEntry { + enum class Type { + Fixed, + Scalable, + Threshold, + }; + + enum class Context { + Actions, + Devices, + FileSystems, + MimeTypes, + }; + + std::filesystem::path path; + int size; + Type type; + Context context; + }; + std::unordered_map m_cached_icons; + std::vector m_inherits; + std::vector m_directories; }; struct IconRegistry { diff --git a/src/ImGui.hpp b/src/ImGui.hpp index 43a3fa8..c868b3f 100644 --- a/src/ImGui.hpp +++ b/src/ImGui.hpp @@ -118,11 +118,7 @@ private: { return sel_anchor_idx != -1 && sel_anchor_idx != curr_idx; } - void clear_selection() - { - sel_anchor_idx = -1; - selecting_all = false; - } + void clear_selection() { sel_anchor_idx = -1; } }; struct ListViewState {