Add Alvin library: input, capture, windows and vision
A cross-platform C++23 library with a platform-neutral public API and runtime-selected backends: - Input: Wayland virtual pointer/keyboard (Hyprland, wlroots), libei via the RemoteDesktop portal (GNOME, KDE), uinput, and Win32 SendInput - Capture: ScreenCast portal + PipeWire, and Win32 GDI - Windows: Hyprland IPC and Win32 enumeration - Monitors via wl_output/xdg-output and EnumDisplayMonitors - Optional OpenCV template matching (alvin::vision) Also adds the `alvin` CLI, Catch2 unit tests, install rules with find_package(Alvin) support, API docs (docs/API.md and the Obsidian vault), and README instructions for both ways of consuming the library. Windows backends are written but not yet compiled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
76ff506fd0
commit
ca7e62ac8d
59 files changed
+6515
-1
No files matched your search
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "alvin/error.hpp"
|
||||
|
||||
namespace alvin {
|
||||
|
||||
struct Point {
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
friend bool operator==(const Point&, const Point&) = default;
|
||||
};
|
||||
|
||||
struct Size {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
friend bool operator==(const Size&, const Size&) = default;
|
||||
};
|
||||
|
||||
// All rectangles are in global desktop coordinates (logical pixels, i.e. after
|
||||
// monitor scaling) unless documented otherwise.
|
||||
struct Rect {
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
int right() const { return x + width; }
|
||||
int bottom() const { return y + height; }
|
||||
Point center() const { return {x + width / 2, y + height / 2}; }
|
||||
bool empty() const { return width <= 0 || height <= 0; }
|
||||
bool contains(Point p) const { return p.x >= x && p.y >= y && p.x < right() && p.y < bottom(); }
|
||||
|
||||
// Smallest rect containing both. An empty rect acts as identity.
|
||||
Rect united(const Rect& o) const;
|
||||
|
||||
friend bool operator==(const Rect&, const Rect&) = default;
|
||||
};
|
||||
|
||||
struct Monitor {
|
||||
std::string name; // connector name, e.g. "DP-1" or "\\\\.\\DISPLAY1"
|
||||
std::string description;
|
||||
Rect bounds; // logical position/size in the global desktop
|
||||
Size pixelSize; // physical mode size in pixels
|
||||
double scale = 1.0;
|
||||
bool primary = false;
|
||||
};
|
||||
|
||||
// Enumerate monitors on the current session.
|
||||
Result<std::vector<Monitor>> listMonitors();
|
||||
|
||||
// Bounding box of all monitors, i.e. the space absolute pointer motion maps onto.
|
||||
Result<Rect> desktopBounds();
|
||||
|
||||
} // namespace alvin
|
||||
Reference in new issue
Block a user