changeset 403:df4a027623d0 default tip

x11: fix build fail when glib is not detected this can happen if glib is just not installed, or if dev headers are not installed either.
author Paper <paper@tflc.us>
date Mon, 10 Nov 2025 15:51:45 -0500
parents d859306e2db4
children
files include/core/strings.h include/sys/glib/dark_theme.h src/core/strings.cc src/sys/glib/dark_theme.cc src/sys/x11/dark_theme.cc
diffstat 5 files changed, 32 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/include/core/strings.h	Fri Nov 07 18:36:18 2025 -0500
+++ b/include/core/strings.h	Mon Nov 10 15:51:45 2025 -0500
@@ -76,6 +76,9 @@
 
 std::string Translate(const char *str);
 
+/* hehehe */
+bool IsGTKThemeDark(const std::string_view str);
+
 }; // namespace Strings
 
 #endif // MINORI_CORE_STRINGS_H_
--- a/include/sys/glib/dark_theme.h	Fri Nov 07 18:36:18 2025 -0500
+++ b/include/sys/glib/dark_theme.h	Mon Nov 10 15:51:45 2025 -0500
@@ -5,7 +5,6 @@
 
 namespace glib {
 
-bool IsGTKThemeDark(const std::string_view str);
 bool IsInDarkTheme();
 
 }
--- a/src/core/strings.cc	Fri Nov 07 18:36:18 2025 -0500
+++ b/src/core/strings.cc	Mon Nov 10 15:51:45 2025 -0500
@@ -301,4 +301,29 @@
 	return Strings::ToUtf8String(QCoreApplication::tr(str));
 }
 
+/* Moved here from glib code because xsettings parser needs it */
+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 */
+	};
+
+	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()))
+			return true;
+	}
+
+	return false;
+}
+
 } // namespace Strings
--- a/src/sys/glib/dark_theme.cc	Fri Nov 07 18:36:18 2025 -0500
+++ b/src/sys/glib/dark_theme.cc	Mon Nov 10 15:51:45 2025 -0500
@@ -1,4 +1,5 @@
 #include "sys/glib/dark_theme.h"
+#include "core/strings.h"
 
 #include <array>
 #include <cstring>
@@ -33,31 +34,6 @@
 template<typename T>
 using GMallocPtr = std::unique_ptr<T, g_malloc_del<T>>;
 
-/* not really "glib" but GNOME-related enough */
-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 */
-	};
-
-	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()))
-			return true;
-	}
-
-	return false;
-}
-
 bool IsInDarkTheme()
 {
 	GObjectPtr<GSettings> settings(::g_settings_new("org.gnome.desktop.interface"));
@@ -93,7 +69,7 @@
 		if (!str)
 			return false;
 
-		if (IsGTKThemeDark({str, size}))
+		if (Strings::IsGTKThemeDark({str, size}))
 			return true;
 	}
 
--- a/src/sys/x11/dark_theme.cc	Fri Nov 07 18:36:18 2025 -0500
+++ b/src/sys/x11/dark_theme.cc	Mon Nov 10 15:51:45 2025 -0500
@@ -1,6 +1,6 @@
 #include "sys/x11/dark_theme.h"
-#include "sys/glib/dark_theme.h" /* glib::IsGTKThemeDark */
 #include "sys/x11/settings.h"
+#include "core/strings.h"
 
 namespace x11 {
 
@@ -10,7 +10,7 @@
 	if (!FindSetting(u8"Net/ThemeName", setting))
 		return false;
 
-	return glib::IsGTKThemeDark(setting.data.string);
+	return Strings::IsGTKThemeDark(setting.data.string);
 }
 
 } // namespace x11