diff src/sys/x11/settings.cc @ 379:5eaafed6c10b

*: clang-format
author Paper <paper@tflc.us>
date Wed, 05 Nov 2025 12:59:46 -0500
parents 99c961c91809
children
line wrap: on
line diff
--- 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;