Mercurial > minori
changeset 379:5eaafed6c10b
*: clang-format
| author | Paper <paper@tflc.us> |
|---|---|
| date | Wed, 05 Nov 2025 12:59:46 -0500 |
| parents | 5912dafc6e28 |
| children | 861368fd42ff |
| files | include/core/anime_db.h include/core/filesystem.h src/core/anime_db.cc src/sys/glib/dark_theme.cc src/sys/osx/dark_theme.cc src/sys/osx/permissions.cc src/sys/win32/dark_theme.cc src/sys/x11/dark_theme.cc src/sys/x11/settings.cc |
| diffstat | 9 files changed, 112 insertions(+), 84 deletions(-) [+] |
line wrap: on
line diff
--- a/include/core/anime_db.h Wed Nov 05 12:50:35 2025 -0500 +++ b/include/core/anime_db.h Wed Nov 05 12:59:46 2025 -0500 @@ -3,9 +3,9 @@ #include "core/anime.h" #include "json/json_fwd.hpp" +#include <QImage> #include <string> #include <unordered_map> -#include <QImage> namespace Anime {
--- a/include/core/filesystem.h Wed Nov 05 12:50:35 2025 -0500 +++ b/include/core/filesystem.h Wed Nov 05 12:59:46 2025 -0500 @@ -8,8 +8,8 @@ void CreateDirectories(const std::filesystem::path &path); std::filesystem::path GetDotPath(); // %APPDATA%/minori/, ~/Library/Application Support/minori/, ~/.config/minori/... std::filesystem::path GetConfigPath(); // (dotpath)/config.json -std::filesystem::path GetAnimeDBPath(); // (dotpath)/anime/db.json -std::filesystem::path GetTorrentsPath(); // (dotpath)/torrents/... +std::filesystem::path GetAnimeDBPath(); // (dotpath)/anime/db.json +std::filesystem::path GetTorrentsPath(); // (dotpath)/torrents/... std::filesystem::path GetAnimePostersPath(); // (dotpath)/anime/posters/ } // namespace Filesystem
--- a/src/core/anime_db.cc Wed Nov 05 12:50:35 2025 -0500 +++ b/src/core/anime_db.cc Wed Nov 05 12:59:46 2025 -0500 @@ -1,10 +1,10 @@ #include "core/anime_db.h" #include "core/anime.h" #include "core/filesystem.h" +#include "core/http.h" #include "core/json.h" #include "core/session.h" #include "core/strings.h" -#include "core/http.h" #include "gui/translate/anilist.h" #include "gui/translate/anime.h"
--- a/src/sys/glib/dark_theme.cc Wed Nov 05 12:50:35 2025 -0500 +++ b/src/sys/glib/dark_theme.cc Wed Nov 05 12:59:46 2025 -0500 @@ -1,27 +1,27 @@ #include "sys/glib/dark_theme.h" +#include <array> #include <cstring> #include <gio/gio.h> +#include <memory> #include <string_view> -#include <memory> -#include <array> namespace glib { /* deleters */ template<typename T> struct g_object_del { - void operator()(T* p) const { ::g_object_unref(p); }; + void operator()(T *p) const { ::g_object_unref(p); }; }; template<typename T> struct g_variant_del { - void operator()(T* p) const { ::g_variant_unref(p); }; + void operator()(T *p) const { ::g_variant_unref(p); }; }; template<typename T> struct g_malloc_del { - void operator()(T* p) const { ::g_free(p); }; + void operator()(T *p) const { ::g_free(p); }; }; template<typename T> @@ -34,29 +34,32 @@ using GMallocPtr = std::unique_ptr<T, g_malloc_del<T>>; /* not really "glib" but GNOME-related enough */ -bool IsGTKThemeDark(const std::string_view str) { +bool IsGTKThemeDark(const std::string_view str) +{ /* if that doesn't exist, use the GTK theme and check for some known * suffixes. if one is found, return * * XXX probably better to use case folding here */ static constexpr std::array<std::string_view, 3> suffixes = { - "-dark", /* Adwaita-dark */ - "-Dark", /* Arc-Dark */ - "-Darker", /* Arc-Darker */ + "-dark", /* Adwaita-dark */ + "-Dark", /* Arc-Dark */ + "-Darker", /* Arc-Darker */ }; - for (const auto& suffix : suffixes) { + for (const auto &suffix : suffixes) { if (str.size() < suffix.size()) continue; - if (std::equal(str.data() + str.size() - suffix.length(), str.data() + str.size(), suffix.begin(), suffix.end())) + if (std::equal(str.data() + str.size() - suffix.length(), str.data() + str.size(), suffix.begin(), + suffix.end())) return true; } return false; } -bool IsInDarkTheme() { +bool IsInDarkTheme() +{ GObjectPtr<GSettings> settings(::g_settings_new("org.gnome.desktop.interface")); if (!settings) return false; @@ -69,7 +72,7 @@ /* this is free'd upon deconstruction of the GVariantPtr */ gsize size; - const gchar* str = ::g_variant_get_string(val.get(), &size); + const gchar *str = ::g_variant_get_string(val.get(), &size); if (!str) return false; @@ -86,7 +89,7 @@ return false; gsize size; - const gchar* str = ::g_variant_get_string(gtk_theme.get(), &size); + const gchar *str = ::g_variant_get_string(gtk_theme.get(), &size); if (!str) return false;
--- a/src/sys/osx/dark_theme.cc Wed Nov 05 12:50:35 2025 -0500 +++ b/src/sys/osx/dark_theme.cc Wed Nov 05 12:59:46 2025 -0500 @@ -18,17 +18,19 @@ static const CFStringRef kAppKitBundleID = CFSTR("com.apple.AppKit"); -bool RetrieveAppearanceNames() { +bool RetrieveAppearanceNames() +{ CFBundleRef appkit_bundle = CFBundleGetBundleWithIdentifier(kAppKitBundleID); if (!appkit_bundle) return false; - - auto aqua_appearance = reinterpret_cast<CFStringRef*>(CFBundleGetDataPointerForName(appkit_bundle, CFSTR("NSAppearanceNameAqua"))); + + auto aqua_appearance = + reinterpret_cast<CFStringRef *>(CFBundleGetDataPointerForName(appkit_bundle, CFSTR("NSAppearanceNameAqua"))); if (!aqua_appearance) return false; NSAppearanceNameAqua = *aqua_appearance; - auto dark_aqua_appearance = reinterpret_cast<CFStringRef*>( + auto dark_aqua_appearance = reinterpret_cast<CFStringRef *>( CFBundleGetDataPointerForName(appkit_bundle, CFSTR("NSAppearanceNameDarkAqua"))); if (!dark_aqua_appearance) return false; @@ -37,7 +39,8 @@ return true; } -bool DarkThemeAvailable() { +bool DarkThemeAvailable() +{ if (__builtin_available(macOS 10.14, *)) { return true; } else { @@ -45,7 +48,8 @@ } } -bool IsInDarkTheme() { +bool IsInDarkTheme() +{ if (!DarkThemeAvailable()) return false; @@ -56,7 +60,7 @@ // NSArray* array = @[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]; CFArrayRef array = []() -> CFArrayRef { CFStringRef refs[] = {NSAppearanceNameAqua, NSAppearanceNameDarkAqua}; - return CFArrayCreate(NULL, reinterpret_cast<const void**>(refs), 2, &kCFTypeArrayCallBacks); + return CFArrayCreate(NULL, reinterpret_cast<const void **>(refs), 2, &kCFTypeArrayCallBacks); }(); // NSApplication* app = [NSApplication sharedApplication]; @@ -82,7 +86,8 @@ return CFEqual(appearance, NSAppearanceNameDarkAqua); } -bool SetToDarkTheme() { +bool SetToDarkTheme() +{ // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code if (!DarkThemeAvailable()) return false; @@ -107,7 +112,8 @@ return true; } -bool SetToLightTheme() { +bool SetToLightTheme() +{ // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code if (!DarkThemeAvailable()) return false; @@ -131,7 +137,8 @@ return true; } -void SetToAutoTheme() { +void SetToAutoTheme() +{ if (!DarkThemeAvailable()) return;
--- a/src/sys/osx/permissions.cc Wed Nov 05 12:50:35 2025 -0500 +++ b/src/sys/osx/permissions.cc Wed Nov 05 12:59:46 2025 -0500 @@ -9,7 +9,8 @@ namespace osx { -bool AskForPermissions() { +bool AskForPermissions() +{ if (::AXIsProcessTrusted()) return true;
--- a/src/sys/win32/dark_theme.cc Wed Nov 05 12:50:35 2025 -0500 +++ b/src/sys/win32/dark_theme.cc Wed Nov 05 12:59:46 2025 -0500 @@ -19,14 +19,16 @@ class Dwmapi { public: - Dwmapi() { + Dwmapi() + { /* load functions */ library.reset(::LoadLibraryW(L"dwmapi.dll")); - set_wind_attrib = reinterpret_cast<decltype(::DwmSetWindowAttribute)*>( + set_wind_attrib = reinterpret_cast<decltype(::DwmSetWindowAttribute) *>( GetProcAddress(library.get(), "DwmSetWindowAttribute")); } - HRESULT SetWindowAttribute(HWND hWnd, DWORD key, LPCVOID data, DWORD sz_data) { + HRESULT SetWindowAttribute(HWND hWnd, DWORD key, LPCVOID data, DWORD sz_data) + { if (!library.get()) return E_POINTER; @@ -40,14 +42,15 @@ protected: Library library = nullptr; - decltype(::DwmSetWindowAttribute)* set_wind_attrib; + decltype(::DwmSetWindowAttribute) *set_wind_attrib; }; Dwmapi dwmapi; namespace win32 { -bool SetTitleBarToBlack(QWidget* win, bool enabled) { +bool SetTitleBarToBlack(QWidget *win, bool enabled) +{ /* 19 and 20 are *both* DWMWA_USE_IMMERSIVE_DARK_MODE. * * It's 20 on newer versions of windows (i.e. win11 and late win10), @@ -75,18 +78,21 @@ return b; } -void SetTitleBarsToBlack(bool enabled) { - for (QWidget* widget : qApp->topLevelWidgets()) { +void SetTitleBarsToBlack(bool enabled) +{ + for (QWidget *widget : qApp->topLevelWidgets()) { SetTitleBarToBlack(widget, enabled); } } -bool DarkThemeAvailable() { - const auto& ver = QOperatingSystemVersion::current(); +bool DarkThemeAvailable() +{ + const auto &ver = QOperatingSystemVersion::current(); return (ver.majorVersion() > 10) ? true : (ver.majorVersion() == 10 && ver.microVersion() >= 17763); } -bool IsInDarkTheme() { +bool IsInDarkTheme() +{ QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", QSettings::NativeFormat); return settings.value("AppsUseLightTheme", 1).toInt() == 0;
--- a/src/sys/x11/dark_theme.cc Wed Nov 05 12:50:35 2025 -0500 +++ b/src/sys/x11/dark_theme.cc Wed Nov 05 12:59:46 2025 -0500 @@ -1,10 +1,11 @@ #include "sys/x11/dark_theme.h" +#include "sys/glib/dark_theme.h" /* glib::IsGTKThemeDark */ #include "sys/x11/settings.h" -#include "sys/glib/dark_theme.h" /* glib::IsGTKThemeDark */ namespace x11 { -bool IsInDarkTheme() { +bool IsInDarkTheme() +{ SettingsItem setting; if (!FindSetting(u8"Net/ThemeName", setting)) return false; @@ -12,4 +13,4 @@ return glib::IsGTKThemeDark(setting.data.string); } -} // namespace glib +} // namespace x11
--- a/src/sys/x11/settings.cc Wed Nov 05 12:50:35 2025 -0500 +++ b/src/sys/x11/settings.cc Wed Nov 05 12:59:46 2025 -0500 @@ -1,15 +1,15 @@ #include "sys/x11/settings.h" #include "core/byte_stream.h" +#include <array> #include <cassert> +#include <climits> +#include <cstdint> #include <cstring> -#include <cstdint> -#include <climits> +#include <map> +#include <memory> +#include <optional> #include <string_view> -#include <memory> -#include <array> -#include <optional> -#include <map> #include <xcb/xcb.h> @@ -17,21 +17,21 @@ namespace x11 { -bool SettingsItem::VerifyType() { +bool SettingsItem::VerifyType() +{ switch (type) { case SettingsItem::TypeInt: case SettingsItem::TypeStr: - case SettingsItem::TypeRgba: - return true; - default: - return false; + case SettingsItem::TypeRgba: return true; + default: return false; } } /* -------------------------------------------------------------------------- */ /* xsettings parser */ -static constexpr std::size_t GetPadding(std::size_t length, std::size_t increment) { +static constexpr std::size_t GetPadding(std::size_t length, std::size_t increment) +{ /* ripped from xsettingsd */ return (increment - (length % increment)) % increment; } @@ -58,27 +58,25 @@ std::uint32_t total_items_ = 0; }; -std::uint32_t Parser::GetTotalItems(void) { +std::uint32_t Parser::GetTotalItems(void) +{ return total_items_; } -Parser::Parser(std::uint8_t *bytes, std::size_t size) : stream(bytes, size) { +Parser::Parser(std::uint8_t *bytes, std::size_t size) : stream(bytes, size) +{ } -bool Parser::ParseHeader(void) { +bool Parser::ParseHeader(void) +{ std::uint8_t byte_order; if (!stream.ReadBinary<std::uint8_t>(byte_order)) return false; switch (byte_order) { - case MSBFirst: - stream.SetEndianness(ByteStream::ByteOrder::Big); - break; - case LSBFirst: - stream.SetEndianness(ByteStream::ByteOrder::Little); - break; - default: - return false; /* errr */ + case MSBFirst: stream.SetEndianness(ByteStream::ByteOrder::Big); break; + case LSBFirst: stream.SetEndianness(ByteStream::ByteOrder::Little); break; + default: return false; /* errr */ } stream.Advance(3); @@ -92,7 +90,8 @@ return true; } -std::optional<SettingsItem> Parser::ParseNextItem(void) { +std::optional<SettingsItem> Parser::ParseNextItem(void) +{ SettingsItem item; /* read one byte */ @@ -145,10 +144,10 @@ } case SettingsItem::TypeRgba: { /* it's actually RBGA, but whatever. */ - if (!stream.ReadInt<std::uint16_t>(item.data.rgba.red) - || !stream.ReadInt<std::uint16_t>(item.data.rgba.blue) - || !stream.ReadInt<std::uint16_t>(item.data.rgba.green) - || !stream.ReadInt<std::uint16_t>(item.data.rgba.alpha)) + if (!stream.ReadInt<std::uint16_t>(item.data.rgba.red) || + !stream.ReadInt<std::uint16_t>(item.data.rgba.blue) || + !stream.ReadInt<std::uint16_t>(item.data.rgba.green) || + !stream.ReadInt<std::uint16_t>(item.data.rgba.alpha)) return std::nullopt; break; @@ -180,24 +179,31 @@ /* RAII is nice */ struct XcbGrabber { - XcbGrabber(::xcb_connection_t *conn) { ::xcb_grab_server(conn); conn_ = conn; } + XcbGrabber(::xcb_connection_t *conn) + { + ::xcb_grab_server(conn); + conn_ = conn; + } ~XcbGrabber() { ::xcb_ungrab_server(conn_); } private: ::xcb_connection_t *conn_; }; -static ::xcb_window_t GetSelectionOwner(::xcb_connection_t *conn, ::xcb_atom_t selection) { +static ::xcb_window_t GetSelectionOwner(::xcb_connection_t *conn, ::xcb_atom_t selection) +{ ::xcb_window_t owner = XCB_NONE; - MallocPtr<::xcb_get_selection_owner_reply_t> reply(::xcb_get_selection_owner_reply(conn, ::xcb_get_selection_owner(conn, selection), nullptr)); - + MallocPtr<::xcb_get_selection_owner_reply_t> reply( + ::xcb_get_selection_owner_reply(conn, ::xcb_get_selection_owner(conn, selection), nullptr)); + if (reply) owner = reply->owner; - + return owner; } -static bool GetRawSettingsData(std::vector<uint8_t>& bytes) { +static bool GetRawSettingsData(std::vector<uint8_t> &bytes) +{ int screen; XcbConnectionPtr conn(::xcb_connect(nullptr, &screen)); @@ -213,15 +219,15 @@ std::map<Atom, ::xcb_atom_t> atoms; { std::map<Atom, std::string> names = { - {XSETTINGS_SCREEN, fmt::format("_XSETTINGS_S{}", screen)}, - {XSETTINGS_SETTINGS, "_XSETTINGS_SETTINGS"}, + {XSETTINGS_SCREEN, fmt::format("_XSETTINGS_S{}", screen)}, + {XSETTINGS_SETTINGS, "_XSETTINGS_SETTINGS"}, }; std::map<Atom, ::xcb_intern_atom_cookie_t> atom_cookies; - for (const auto& name : names) + for (const auto &name : names) atom_cookies[name.first] = ::xcb_intern_atom(conn.get(), false, name.second.size(), name.second.data()); - for (const auto& cookie : atom_cookies) { + for (const auto &cookie : atom_cookies) { MallocPtr<::xcb_intern_atom_reply_t> reply(::xcb_intern_atom_reply(conn.get(), cookie.second, nullptr)); if (!reply || reply->atom == XCB_NONE) return false; @@ -239,7 +245,9 @@ if (win == XCB_NONE) return false; - reply.reset(::xcb_get_property_reply(conn.get(), ::xcb_get_property(conn.get(), 0, win, atoms[XSETTINGS_SETTINGS], XCB_ATOM_ANY, 0L, UINT_MAX), nullptr)); + reply.reset(::xcb_get_property_reply( + conn.get(), ::xcb_get_property(conn.get(), 0, win, atoms[XSETTINGS_SETTINGS], XCB_ATOM_ANY, 0L, UINT_MAX), + nullptr)); }; if (!reply) return false; @@ -257,7 +265,8 @@ /* ------------------------------------------------------------------------- */ /* now for the actual all-important public API stringing all this together */ -bool GetSettings(std::vector<SettingsItem>& settings) { +bool GetSettings(std::vector<SettingsItem> &settings) +{ std::vector<std::uint8_t> xsettings_raw; if (!GetRawSettingsData(xsettings_raw)) return false; @@ -279,7 +288,8 @@ return true; } -bool FindSetting(const std::string& name, SettingsItem& setting) { +bool FindSetting(const std::string &name, SettingsItem &setting) +{ std::vector<std::uint8_t> xsettings_raw; if (!GetRawSettingsData(xsettings_raw)) return false; @@ -295,7 +305,7 @@ if (!opt_item) return false; - SettingsItem& item = opt_item.value(); + SettingsItem &item = opt_item.value(); if (item.name == name) { setting = item; return true;
