This commit is contained in:
Mars 2025-05-12 23:12:11 -04:00
parent 89cb92d1c2
commit 6c10918835
Signed by: pupbrained
GPG key ID: 0FF5B8826803F895

View file

@ -57,39 +57,40 @@ namespace {
} }
#endif #endif
#ifdef HAVE_XCB
fn GetX11WindowManager() -> Result<String> { fn GetX11WindowManager() -> Result<String> {
using namespace xcb; using namespace xcb;
using namespace matchit;
using enum ConnError;
using util::types::StringView;
const DisplayGuard conn; const DisplayGuard conn;
if (!conn) if (!conn)
if (const i32 err = connection_has_error(conn.get())) if (const i32 err = ConnectionHasError(conn.get()))
return Err(DracError(DracErrorCode::ApiUnavailable, [&] -> String { return Err(
if (const Option<ConnError> connErr = getConnError(err)) { DracError(
switch (*connErr) { DracErrorCode::ApiUnavailable,
case Generic: return "Stream/Socket/Pipe Error"; match(err)(
case ExtNotSupported: return "Extension Not Supported"; is | Generic = "Stream/Socket/Pipe Error",
case MemInsufficient: return "Insufficient Memory"; is | ExtNotSupported = "Extension Not Supported",
case ReqLenExceed: return "Request Length Exceeded"; is | MemInsufficient = "Insufficient Memory",
case ParseErr: return "Display String Parse Error"; is | ReqLenExceed = "Request Length Exceeded",
case InvalidScreen: return "Invalid Screen"; is | ParseErr = "Display String Parse Error",
case FdPassingFailed: return "FD Passing Failed"; is | InvalidScreen = "Invalid Screen",
default: return std::format("Unknown Error Code ({})", err); is | FdPassingFailed = "FD Passing Failed",
} is | _ = std::format("Unknown Error Code ({})", err)
} )
)
return std::format("Unknown Error Code ({})", err); );
}()));
fn internAtom = [&conn](const StringView name) -> Result<atom_t> { fn internAtom = [&conn](const StringView name) -> Result<atom_t> {
const ReplyGuard<intern_atom_reply_t> reply( using util::types::u16;
intern_atom_reply(conn.get(), intern_atom(conn.get(), 0, static_cast<u16>(name.size()), name.data()), nullptr)
); const ReplyGuard<intern_atom_reply_t> reply(InternAtomReply(conn.get(), InternAtom(conn.get(), 0, static_cast<u16>(name.size()), name.data()), nullptr));
if (!reply) if (!reply)
return Err( return Err(DracError(DracErrorCode::PlatformSpecific, std::format("Failed to get X11 atom reply for '{}'", name)));
DracError(DracErrorCode::PlatformSpecific, std::format("Failed to get X11 atom reply for '{}'", name))
);
return reply->atom; return reply->atom;
}; };
@ -111,30 +112,35 @@ namespace {
return Err(DracError(DracErrorCode::PlatformSpecific, "Failed to get X11 atoms")); return Err(DracError(DracErrorCode::PlatformSpecific, "Failed to get X11 atoms"));
} }
const ReplyGuard<get_property_reply_t> wmWindowReply(get_property_reply( const ReplyGuard<get_property_reply_t> wmWindowReply(GetPropertyReply(
conn.get(), conn.get(),
get_property(conn.get(), 0, conn.rootScreen()->root, *supportingWmCheckAtom, ATOM_WINDOW, 0, 1), GetProperty(conn.get(), 0, conn.rootScreen()->root, *supportingWmCheckAtom, ATOM_WINDOW, 0, 1),
nullptr nullptr
)); ));
if (!wmWindowReply || wmWindowReply->type != ATOM_WINDOW || wmWindowReply->format != 32 || if (!wmWindowReply || wmWindowReply->type != ATOM_WINDOW || wmWindowReply->format != 32 ||
get_property_value_length(wmWindowReply.get()) == 0) GetPropertyValueLength(wmWindowReply.get()) == 0)
return Err(DracError(DracErrorCode::NotFound, "Failed to get _NET_SUPPORTING_WM_CHECK property")); return Err(DracError(DracErrorCode::NotFound, "Failed to get _NET_SUPPORTING_WM_CHECK property"));
const window_t wmRootWindow = *static_cast<window_t*>(get_property_value(wmWindowReply.get())); const window_t wmRootWindow = *static_cast<window_t*>(GetPropertyValue(wmWindowReply.get()));
const ReplyGuard<get_property_reply_t> wmNameReply(get_property_reply( const ReplyGuard<get_property_reply_t> wmNameReply(GetPropertyReply(
conn.get(), get_property(conn.get(), 0, wmRootWindow, *wmNameAtom, *utf8StringAtom, 0, 1024), nullptr conn.get(), GetProperty(conn.get(), 0, wmRootWindow, *wmNameAtom, *utf8StringAtom, 0, 1024), nullptr
)); ));
if (!wmNameReply || wmNameReply->type != *utf8StringAtom || get_property_value_length(wmNameReply.get()) == 0) if (!wmNameReply || wmNameReply->type != *utf8StringAtom || GetPropertyValueLength(wmNameReply.get()) == 0)
return Err(DracError(DracErrorCode::NotFound, "Failed to get _NET_WM_NAME property")); return Err(DracError(DracErrorCode::NotFound, "Failed to get _NET_WM_NAME property"));
const char* nameData = static_cast<const char*>(get_property_value(wmNameReply.get())); const char* nameData = static_cast<const char*>(GetPropertyValue(wmNameReply.get()));
const usize length = get_property_value_length(wmNameReply.get()); const usize length = GetPropertyValueLength(wmNameReply.get());
return String(nameData, length); return String(nameData, length);
} }
#else
fn GetX11WindowManager() -> Result<String> {
return Err(DracError(DracErrorCode::NotSupported, "XCB (X11) support not available"));
}
#endif
fn GetWaylandCompositor() -> Result<String> { fn GetWaylandCompositor() -> Result<String> {
#ifndef __FreeBSD__ #ifndef __FreeBSD__
@ -491,13 +497,7 @@ namespace package {
} }
#else #else
fn GetPkgNgCount() -> Result<u64> { fn GetPkgNgCount() -> Result<u64> {
const PackageManagerInfo pkgInfo = { return GetCountFromDb("pkgng", "/var/db/pkg/local.sqlite", "SELECT COUNT(*) FROM packages");
.id = "pkgng",
.dbPath = "/var/db/pkg/local.sqlite",
.countQuery = "SELECT COUNT(*) FROM packages",
};
return GetCountFromDb(pkgInfo);
} }
#endif #endif
} // namespace package } // namespace package