@@ -8,6 +8,10 @@ set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_MODULE_STD 1)
|
||||
|
||||
add_compile_options(
|
||||
-fstack-protector-strong
|
||||
-fwrapv
|
||||
)
|
||||
add_compile_definitions(
|
||||
WLR_USE_UNSTABLE
|
||||
XR_USE_PLATFORM_EGL
|
||||
@@ -16,6 +20,8 @@ add_compile_definitions(
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
||||
find_package(Boost REQUIRED)
|
||||
|
||||
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)
|
||||
@@ -44,6 +50,13 @@ set(PLATFORM DRM)
|
||||
set(BUILD_EXAMPLES OFF)
|
||||
FetchContent_MakeAvailable(raylib)
|
||||
|
||||
FetchContent_Declare(
|
||||
cpptrace
|
||||
GIT_REPOSITORY https://github.com/jeremy-rifkin/cpptrace.git
|
||||
GIT_TAG v1.0.1
|
||||
)
|
||||
FetchContent_MakeAvailable(cpptrace)
|
||||
|
||||
add_executable(${PROJECT_NAME})
|
||||
target_sources(${PROJECT_NAME} PUBLIC
|
||||
src/main.cpp
|
||||
@@ -60,9 +73,17 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
|
||||
PkgConfig::GLES2
|
||||
PkgConfig::WLROOTS
|
||||
PkgConfig::OPENXR
|
||||
|
||||
Boost::boost
|
||||
raylib
|
||||
cpptrace::cpptrace
|
||||
)
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
CXX_CLANG_TIDY "clang-tidy;-header-filter=^${CMAKE_SOURCE_DIR}/src/.*;-checks=*,-some-disabled-checks,misc-const-correctness,modernize-use-nullptr,bugprone-branch-clone,bugprone-use-after-move,performance-unnecessary-value-param,hicpp-no-malloc,cppcoreguidelines-pro-type-const-cast,clang-analyzer-core.NullDereference,-fuchsia-overloaded-operator,-readability-identifier-length,-bugprone-easily-swappable-parameters,-fuchsia-trailing-return,-misc-non-private-member-variables-in-classes,-readability-math-missing-parentheses,-llvmlibc-implementation-in-namespace,-misc-include-cleaner,-modernize-use-std-print,-llvmlibc-restrict-system-libc-headers,-fuchsia-statically-constructed-objects,-cppcoreguidelines-avoid-non-const-global-variables,-llvmlibc-callee-namespace,-misc-use-anonymous-namespace,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-hicpp-uppercase-literal-suffix,-readability-uppercase-literal-suffix,-fuchsia-default-arguments-calls,-altera-unroll-loops,-fuchsia-default-arguments-declarations,-readability-function-cognitive-complexity,-altera-struct-pack-align,-altera-id-dependent-backward-branch,-cppcoreguidelines-pro-type-reinterpret-cast,-boost-use-ranges,-cppcoreguidelines-owning-memory,-readability-redundant-declaration"
|
||||
)
|
||||
|
||||
# Wayland protocol codegen
|
||||
set(XDG_SHELL_XML
|
||||
${WAYLAND_PROTOCOLS_DIR}/stable/xdg-shell/xdg-shell.xml
|
||||
)
|
||||
|
||||
596
src/LunarWM.cppm
596
src/LunarWM.cppm
File diff suppressed because it is too large
Load Diff
113
src/Math.cppm
113
src/Math.cppm
@@ -1,51 +1,54 @@
|
||||
module;
|
||||
|
||||
import std;
|
||||
|
||||
export module LunarWM.Math;
|
||||
|
||||
export namespace LunarWM {
|
||||
namespace Math {
|
||||
import std;
|
||||
|
||||
export namespace LunarWM::Math {
|
||||
|
||||
template<typename T = float>
|
||||
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>
|
||||
auto operator+(Vec2<U> const &other) -> Vec2<U>
|
||||
{
|
||||
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>
|
||||
auto operator-(Vec2<U> const &other) -> Vec2<U>
|
||||
{
|
||||
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>
|
||||
auto operator*(Vec2<U> const &other) -> Vec2<U>
|
||||
{
|
||||
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> auto operator*(T scalar) -> Vec2<U>
|
||||
{
|
||||
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> auto operator/(T scalar) -> Vec2<U>
|
||||
{
|
||||
return { x / scalar, y / scalar };
|
||||
}
|
||||
template<typename U = T>
|
||||
requires std::is_arithmetic_v<U> Vec2 operator-()
|
||||
requires std::is_arithmetic_v<U> auto operator-() -> Vec2
|
||||
{
|
||||
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
|
||||
auto length() const -> T { return std::sqrt(x * x + y * y); }
|
||||
auto lengthSquared() const -> T { return x * x + y * y; }
|
||||
auto normalized() const -> Vec2<T>
|
||||
{
|
||||
T len = length();
|
||||
if (len == T(0))
|
||||
if (len == T(0)) {
|
||||
return { T(0), T(0) };
|
||||
}
|
||||
return *this / len;
|
||||
}
|
||||
|
||||
@@ -53,7 +56,8 @@ requires std::is_arithmetic_v<T> 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>
|
||||
auto operator*(T scalar, Vec2<T> const &v) -> Vec2<T>
|
||||
{
|
||||
return { v.x * scalar, v.y * scalar };
|
||||
}
|
||||
@@ -71,23 +75,23 @@ requires std::is_arithmetic_v<T> struct Rect {
|
||||
{
|
||||
}
|
||||
|
||||
T &x() { return pos.x; }
|
||||
T &y() { return pos.y; }
|
||||
T &w() { return size.x; }
|
||||
T &h() { return size.y; }
|
||||
auto x() -> T & { return pos.x; }
|
||||
auto y() -> T & { return pos.y; }
|
||||
auto w() -> T & { return size.x; }
|
||||
auto h() -> T & { return size.y; }
|
||||
|
||||
T x() const { return pos.x; }
|
||||
T y() const { return pos.y; }
|
||||
T w() const { return size.x; }
|
||||
T h() const { return size.y; }
|
||||
auto x() const -> T { return pos.x; }
|
||||
auto y() const -> T { return pos.y; }
|
||||
auto w() const -> T { return size.x; }
|
||||
auto h() const -> T { return size.y; }
|
||||
|
||||
T left() const { return x(); }
|
||||
T right() const { return x() + w(); }
|
||||
T top() const { return y(); }
|
||||
T bottom() const { return y() + h(); }
|
||||
auto left() const -> T { return x(); }
|
||||
auto right() const -> T { return x() + w(); }
|
||||
auto top() const -> T { return y(); }
|
||||
auto bottom() const -> T { return y() + h(); }
|
||||
|
||||
T &left() { return x(); }
|
||||
T &top() { return y(); }
|
||||
auto left() -> T & { return x(); }
|
||||
auto top() -> T & { return y(); }
|
||||
|
||||
Vec2<T> pos, size;
|
||||
};
|
||||
@@ -95,57 +99,63 @@ requires std::is_arithmetic_v<T> struct Rect {
|
||||
template<typename T = float>
|
||||
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> auto operator[](U const index) -> Vec2<T> &
|
||||
{
|
||||
if (index < 0 || index > 1)
|
||||
if (index < 0 || index > 1) {
|
||||
throw std::out_of_range("A box only has two points");
|
||||
}
|
||||
return m_data[index];
|
||||
}
|
||||
Vec2<T> &first() { return m_data[0]; }
|
||||
Vec2<T> &second() { return m_data[1]; }
|
||||
T &x0() { return m_data[0].x; }
|
||||
T &y0() { return m_data[0].y; }
|
||||
T &x1() { return m_data[1].x; }
|
||||
T &y1() { return m_data[1].y; }
|
||||
T &left()
|
||||
auto first() -> Vec2<T> & { return m_data[0]; }
|
||||
auto second() -> Vec2<T> & { return m_data[1]; }
|
||||
auto x0() -> T & { return m_data[0].x; }
|
||||
auto y0() -> T & { return m_data[0].y; }
|
||||
auto x1() -> T & { return m_data[1].x; }
|
||||
auto y1() -> T & { return m_data[1].y; }
|
||||
auto left() -> T &
|
||||
{
|
||||
if (x0() < x1())
|
||||
if (x0() < x1()) {
|
||||
return x0();
|
||||
}
|
||||
return x1();
|
||||
}
|
||||
T &right()
|
||||
auto right() -> T &
|
||||
{
|
||||
if (x0() > x1())
|
||||
if (x0() > x1()) {
|
||||
return x0();
|
||||
}
|
||||
return x1();
|
||||
}
|
||||
T &top()
|
||||
auto top() -> T &
|
||||
{
|
||||
if (y0() < y1())
|
||||
if (y0() < y1()) {
|
||||
return y0();
|
||||
}
|
||||
return y1();
|
||||
}
|
||||
T &bottom()
|
||||
auto bottom() -> T &
|
||||
{
|
||||
if (y0() > y1())
|
||||
if (y0() > y1()) {
|
||||
return y0();
|
||||
}
|
||||
return y1();
|
||||
}
|
||||
|
||||
Box() { }
|
||||
Box(Rect<T> rect)
|
||||
Box() = default;
|
||||
explicit Box(Rect<T> rect)
|
||||
{
|
||||
this->m_data[0] = rect.pos;
|
||||
this->m_data[1] = rect.pos + rect.size;
|
||||
}
|
||||
|
||||
private:
|
||||
Vec2<T> m_data[2] = {};
|
||||
std::array<Vec2<T>, 2> m_data = {};
|
||||
};
|
||||
|
||||
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>
|
||||
auto subtract_rect(Math::Rect<T> const &src, Math::Rect<T> const &clip)
|
||||
-> std::vector<Math::Rect<T>>
|
||||
{
|
||||
std::vector<Math::Rect<T>> result;
|
||||
|
||||
@@ -208,5 +218,4 @@ requires std::is_arithmetic_v<T> struct Viewport {
|
||||
Vec2<T> depth_limits;
|
||||
};
|
||||
|
||||
} // namespace Math
|
||||
} // namespace LunarWM
|
||||
} // namespace LunarWM::Math
|
||||
|
||||
28
src/main.cpp
28
src/main.cpp
@@ -1,14 +1,30 @@
|
||||
// NOLINTBEGIN
|
||||
#include <cassert>
|
||||
#include <csignal>
|
||||
|
||||
#include <cpptrace/cpptrace.hpp>
|
||||
#include <cpptrace/from_current.hpp>
|
||||
// NOLINTEND
|
||||
|
||||
import std;
|
||||
|
||||
import LunarWM.LunarWM;
|
||||
|
||||
std::unique_ptr<LunarWM::LunarWM> g_comp;
|
||||
static std::unique_ptr<LunarWM::LunarWM> g_comp;
|
||||
|
||||
int main(void) {
|
||||
g_comp = std::make_unique<LunarWM::LunarWM>();
|
||||
g_comp->init();
|
||||
std::signal(SIGINT, [](int) { g_comp->terminate(); });
|
||||
g_comp->run();
|
||||
auto main() noexcept -> int // NOLINT(bugprone-exception-escape)
|
||||
{
|
||||
CPPTRACE_TRY
|
||||
{
|
||||
g_comp = std::make_unique<LunarWM::LunarWM>();
|
||||
g_comp->init();
|
||||
assert(
|
||||
std::signal(SIGINT, [](int) { g_comp->terminate(); }) != SIG_ERR);
|
||||
g_comp->run();
|
||||
}
|
||||
CPPTRACE_CATCH(std::exception const &e)
|
||||
{
|
||||
std::println(std::cerr, "Uncaught exception: {}", e.what());
|
||||
cpptrace::from_current_exception().print();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user