i think i got everything
This commit is contained in:
parent
8293ef42b6
commit
cf51e3e569
19 changed files with 671 additions and 805 deletions
69
src/os/linux/display_guards.cpp
Normal file
69
src/os/linux/display_guards.cpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
#ifdef __linux__
|
||||
|
||||
#include <utility> // for std::exchange
|
||||
|
||||
#include "display_guards.h"
|
||||
|
||||
#include "src/util/macros.h"
|
||||
|
||||
namespace os::linux {
|
||||
DisplayGuard::DisplayGuard(CStr name) : m_Display(XOpenDisplay(name)) {}
|
||||
|
||||
DisplayGuard::~DisplayGuard() {
|
||||
if (m_Display)
|
||||
XCloseDisplay(m_Display);
|
||||
}
|
||||
|
||||
DisplayGuard::DisplayGuard(DisplayGuard&& other) noexcept : m_Display(std::exchange(other.m_Display, nullptr)) {}
|
||||
|
||||
fn DisplayGuard::operator=(DisplayGuard&& other) noexcept -> DisplayGuard& {
|
||||
if (this != &other) {
|
||||
if (m_Display)
|
||||
XCloseDisplay(m_Display);
|
||||
|
||||
m_Display = std::exchange(other.m_Display, nullptr);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
DisplayGuard::operator bool() const { return m_Display != nullptr; }
|
||||
|
||||
fn DisplayGuard::get() const -> Display* { return m_Display; }
|
||||
|
||||
fn DisplayGuard::defaultRootWindow() const -> Window {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
|
||||
return DefaultRootWindow(m_Display);
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
WaylandDisplayGuard::WaylandDisplayGuard() : m_Display(wl_display_connect(nullptr)) {}
|
||||
|
||||
WaylandDisplayGuard::~WaylandDisplayGuard() {
|
||||
if (m_Display)
|
||||
wl_display_disconnect(m_Display);
|
||||
}
|
||||
|
||||
WaylandDisplayGuard::WaylandDisplayGuard(WaylandDisplayGuard&& other) noexcept
|
||||
: m_Display(std::exchange(other.m_Display, nullptr)) {}
|
||||
|
||||
fn WaylandDisplayGuard::operator=(WaylandDisplayGuard&& other) noexcept -> WaylandDisplayGuard& {
|
||||
if (this != &other) {
|
||||
if (m_Display)
|
||||
wl_display_disconnect(m_Display);
|
||||
|
||||
m_Display = std::exchange(other.m_Display, nullptr);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
WaylandDisplayGuard::operator bool() const { return m_Display != nullptr; }
|
||||
|
||||
fn WaylandDisplayGuard::get() const -> wl_display* { return m_Display; }
|
||||
|
||||
fn WaylandDisplayGuard::fd() const -> i32 { return m_Display ? wl_display_get_fd(m_Display) : -1; }
|
||||
}
|
||||
|
||||
#endif
|
69
src/os/linux/display_guards.h
Normal file
69
src/os/linux/display_guards.h
Normal file
|
@ -0,0 +1,69 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <wayland-client.h>
|
||||
|
||||
#include "src/util/macros.h"
|
||||
|
||||
namespace os::linux {
|
||||
/**
|
||||
* RAII wrapper for X11 Display connections
|
||||
* Automatically handles resource acquisition and cleanup
|
||||
*/
|
||||
class DisplayGuard {
|
||||
private:
|
||||
Display* m_Display;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Opens an X11 display connection
|
||||
* @param name Display name (nullptr for default)
|
||||
*/
|
||||
explicit DisplayGuard(CStr name = nullptr);
|
||||
~DisplayGuard();
|
||||
|
||||
// Non-copyable
|
||||
DisplayGuard(const DisplayGuard&) = delete;
|
||||
fn operator=(const DisplayGuard&)->DisplayGuard& = delete;
|
||||
|
||||
// Movable
|
||||
DisplayGuard(DisplayGuard&& other) noexcept;
|
||||
fn operator=(DisplayGuard&& other) noexcept -> DisplayGuard&;
|
||||
|
||||
[[nodiscard]] operator bool() const;
|
||||
[[nodiscard]] fn get() const -> Display*;
|
||||
[[nodiscard]] fn defaultRootWindow() const -> Window;
|
||||
};
|
||||
|
||||
/**
|
||||
* RAII wrapper for Wayland display connections
|
||||
* Automatically handles resource acquisition and cleanup
|
||||
*/
|
||||
class WaylandDisplayGuard {
|
||||
private:
|
||||
wl_display* m_Display;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Opens a Wayland display connection
|
||||
*/
|
||||
WaylandDisplayGuard();
|
||||
~WaylandDisplayGuard();
|
||||
|
||||
// Non-copyable
|
||||
WaylandDisplayGuard(const WaylandDisplayGuard&) = delete;
|
||||
fn operator=(const WaylandDisplayGuard&)->WaylandDisplayGuard& = delete;
|
||||
|
||||
// Movable
|
||||
WaylandDisplayGuard(WaylandDisplayGuard&& other) noexcept;
|
||||
fn operator=(WaylandDisplayGuard&& other) noexcept -> WaylandDisplayGuard&;
|
||||
|
||||
[[nodiscard]] operator bool() const;
|
||||
[[nodiscard]] fn get() const -> wl_display*;
|
||||
[[nodiscard]] fn fd() const -> i32;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,9 +1 @@
|
|||
#include "src/os/linux/pkg_count.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
fn GetApkPackageCount() -> optional<usize> {
|
||||
fs::path apkDbPath("/lib/apk/db/installed");
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
|
|
@ -2,37 +2,35 @@
|
|||
|
||||
#include "src/util/macros.h"
|
||||
|
||||
using std::optional;
|
||||
|
||||
// Get package count from dpkg (Debian/Ubuntu)
|
||||
fn GetDpkgPackageCount() -> optional<usize>;
|
||||
fn GetDpkgPackageCount() -> Option<usize>;
|
||||
|
||||
// Get package count from RPM (Red Hat/Fedora/CentOS)
|
||||
fn GetRpmPackageCount() -> std::optional<usize>;
|
||||
fn GetRpmPackageCount() -> Option<usize>;
|
||||
|
||||
// Get package count from pacman (Arch Linux)
|
||||
fn GetPacmanPackageCount() -> std::optional<usize>;
|
||||
fn GetPacmanPackageCount() -> Option<usize>;
|
||||
|
||||
// Get package count from Portage (Gentoo)
|
||||
fn GetPortagePackageCount() -> std::optional<usize>;
|
||||
fn GetPortagePackageCount() -> Option<usize>;
|
||||
|
||||
// Get package count from zypper (openSUSE)
|
||||
fn GetZypperPackageCount() -> std::optional<usize>;
|
||||
fn GetZypperPackageCount() -> Option<usize>;
|
||||
|
||||
// Get package count from apk (Alpine)
|
||||
fn GetApkPackageCount() -> std::optional<usize>;
|
||||
fn GetApkPackageCount() -> Option<usize>;
|
||||
|
||||
// Get package count from nix
|
||||
fn GetNixPackageCount() -> std::optional<usize>;
|
||||
fn GetNixPackageCount() -> Option<usize>;
|
||||
|
||||
// Get package count from flatpak
|
||||
fn GetFlatpakPackageCount() -> std::optional<usize>;
|
||||
fn GetFlatpakPackageCount() -> Option<usize>;
|
||||
|
||||
// Get package count from snap
|
||||
fn GetSnapPackageCount() -> std::optional<usize>;
|
||||
fn GetSnapPackageCount() -> Option<usize>;
|
||||
|
||||
// Get package count from AppImage
|
||||
fn GetAppimagePackageCount() -> std::optional<usize>;
|
||||
fn GetAppimagePackageCount() -> Option<usize>;
|
||||
|
||||
// Get total package count from all available package managers
|
||||
fn GetTotalPackageCount() -> std::optional<usize>;
|
||||
fn GetTotalPackageCount() -> Option<usize>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue