Input handling

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-07-09 07:54:10 +03:00
parent 9fa2a1e8c7
commit dd6cadb50d
6 changed files with 1849 additions and 1529 deletions

View File

@@ -20,6 +20,7 @@ pkg_check_modules(WAYLAND REQUIRED IMPORTED_TARGET GLOBAL wayland-server)
pkg_check_modules(EGL REQUIRED IMPORTED_TARGET egl)
pkg_check_modules(GLES2 REQUIRED IMPORTED_TARGET glesv2)
pkg_check_modules(WLROOTS REQUIRED IMPORTED_TARGET wlroots-0.19)
pkg_check_modules(XKBCOMMON REQUIRED IMPORTED_TARGET xkbcommon)
pkg_check_modules(OPENXR REQUIRED IMPORTED_TARGET openxr)
include(FetchContent)
@@ -45,6 +46,7 @@ target_sources(${PROJECT_NAME} PUBLIC FILE_SET CXX_MODULES FILES
src/LunarWM.cppm
)
target_link_libraries(${PROJECT_NAME} PUBLIC
PkgConfig::XKBCOMMON
PkgConfig::WAYLAND
PkgConfig::EGL
PkgConfig::GLES2

View File

@@ -34,6 +34,7 @@
# For wlroots
libxkbcommon
libxkbcommon.dev
libdrm
xorg.libxcb
pixman

File diff suppressed because it is too large Load Diff

View File

@@ -8,41 +8,41 @@ export namespace LunarWM {
namespace Math {
template<typename T = float>
requires std::is_arithmetic_v<T>
struct Vec2 {
requires std::is_arithmetic_v<T> struct Vec2 {
template<typename U = T>
requires std::is_arithmetic_v<U>
Vec2<U> operator+(Vec2<U> const &other) {
requires std::is_arithmetic_v<U> Vec2<U> operator+(Vec2<U> const &other)
{
return { x + other.x, y + other.y };
}
template<typename U = T>
requires std::is_arithmetic_v<U>
Vec2<U> operator-(Vec2<U> const &other) {
requires std::is_arithmetic_v<U> Vec2<U> operator-(Vec2<U> const &other)
{
return { x - other.x, y - other.y };
}
template<typename U = T>
requires std::is_arithmetic_v<U>
Vec2<U> operator*(Vec2<U> const &other) {
requires std::is_arithmetic_v<U> Vec2<U> operator*(Vec2<U> const &other)
{
return { x * other.x, y * other.x };
}
template<typename U = T>
requires std::is_arithmetic_v<U>
Vec2<U> operator*(T scalar) {
requires std::is_arithmetic_v<U> Vec2<U> operator*(T scalar)
{
return { x * scalar, y * scalar };
}
template<typename U = T>
requires std::is_arithmetic_v<U>
Vec2<U> operator/(T scalar) {
requires std::is_arithmetic_v<U> Vec2<U> operator/(T scalar)
{
return { x / scalar, y / scalar };
}
template<typename U = T>
requires std::is_arithmetic_v<U>
Vec2 operator-() {
requires std::is_arithmetic_v<U> Vec2 operator-()
{
return { -x, -y };
}
T length() const { return std::sqrt(x * x + y * y); }
T lengthSquared() const { return x * x + y * y; }
Vec2<T> normalized() const {
Vec2<T> normalized() const
{
T len = length();
if (len == T(0))
return { T(0), T(0) };
@@ -53,16 +53,23 @@ struct Vec2 {
};
template<typename T>
requires std::is_arithmetic_v<T>
Vec2<T> operator*(T scalar, Vec2<T> const &v) {
requires std::is_arithmetic_v<T> Vec2<T> operator*(T scalar, Vec2<T> const &v)
{
return { v.x * scalar, v.y * scalar };
}
template<typename T = float>
requires std::is_arithmetic_v<T>
struct Rect {
Rect(Vec2<T> pos, Vec2<T> size) : pos(pos), size(size) {}
Rect(T x, T y, T w, T h) : pos({x, y}), size({w, h}) {}
requires std::is_arithmetic_v<T> struct Rect {
Rect(Vec2<T> pos, Vec2<T> size)
: pos(pos)
, size(size)
{
}
Rect(T x, T y, T w, T h)
: pos({ x, y })
, size({ w, h })
{
}
T &x() { return pos.x; }
T &y() { return pos.y; }
@@ -86,11 +93,10 @@ struct Rect {
};
template<typename T = float>
requires std::is_arithmetic_v<T>
struct Box {
requires std::is_arithmetic_v<T> struct Box {
template<typename U = int>
requires std::is_arithmetic_v<U>
Vec2<T> &operator[](U const index) {
requires std::is_arithmetic_v<U> Vec2<T> &operator[](U const index)
{
if (index < 0 || index > 1)
throw std::out_of_range("A box only has two points");
return m_data[index];
@@ -101,29 +107,34 @@ struct Box {
T &y0() { return m_data[0].y; }
T &x1() { return m_data[1].x; }
T &y1() { return m_data[1].y; }
T &left() {
T &left()
{
if (x0() < x1())
return x0();
return x1();
}
T &right() {
T &right()
{
if (x0() > x1())
return x0();
return x1();
}
T &top() {
T &top()
{
if (y0() < y1())
return y0();
return y1();
}
T &bottom() {
T &bottom()
{
if (y0() > y1())
return y0();
return y1();
}
Box() { }
Box(Rect<T> rect) {
Box(Rect<T> rect)
{
this->m_data[0] = rect.pos;
this->m_data[1] = rect.pos + rect.size;
}
@@ -133,9 +144,9 @@ private:
};
template<typename T = int>
requires std::is_arithmetic_v<T>
std::vector<Math::Rect<T>> subtract_rect(Math::Rect<T> const &src,
Math::Rect<T> const &clip) {
requires std::is_arithmetic_v<T> std::vector<Math::Rect<T>> subtract_rect(
Math::Rect<T> const &src, Math::Rect<T> const &clip)
{
std::vector<Math::Rect<T>> result;
auto sx = src.x();
@@ -183,8 +194,8 @@ std::vector<Math::Rect<T>> subtract_rect(Math::Rect<T> const &src,
// Right piece
if (c_right < s_right) {
result.emplace_back(c_right, middle_top, s_right - c_right,
middle_height);
result.emplace_back(
c_right, middle_top, s_right - c_right, middle_height);
}
}
@@ -192,8 +203,7 @@ std::vector<Math::Rect<T>> subtract_rect(Math::Rect<T> const &src,
}
template<typename T = float>
requires std::is_arithmetic_v<T>
struct Viewport {
requires std::is_arithmetic_v<T> struct Viewport {
Rect<T> rect;
Vec2<T> depth_limits;
};

8
tools/format.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(git rev-parse --show-toplevel)"
find "$ROOT/src" -type f -name '*.cppm' -print0 | while IFS= read -r -d '' f; do
clang-format -i --style=file "$f"
done