Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
stages: [commit-msg]
args: [--no-color]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -19,23 +19,23 @@ repos:
- id: check-added-large-files

- repo: https://github.com/BlankSpruce/gersemi
rev: 0.21.0
rev: 0.22.3
hooks:
- id: gersemi
name: CMake linting

- repo: https://github.com/psf/black
rev: 25.1.0
rev: 25.9.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v20.1.8
rev: v21.1.2
hooks:
- id: clang-format
types_or: [c++, c, proto]
# Check linting and style issues
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.12.5"
rev: "v0.14.0"
hooks:
# Run the linter.
- id: ruff-check
Expand All @@ -51,7 +51,7 @@ repos:
exclude: ^(pyproject.toml)

- repo: https://github.com/fsfe/reuse-tool
rev: v5.0.2
rev: v6.1.2
hooks:
- id: reuse-lint-file

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ cpmaddpackage(
cpmaddpackage("gh:fmtlib/fmt#11.2.0")
cpmaddpackage("gh:odygrd/quill@10.1.0")
cpmaddpackage(URI "gh:skypjack/entt@3.15.0" NAME "EnTT" FIND_PACKAGE_ARGUMENTS "CONFIG")
cpmaddpackage(URI "gh:NVIDIA/stdexec#daf12bcc46438f88b3c78212363f7b6531338780" NAME "stdexec" VERSION 0.11 FIND_PACKAGE_ARGUMENTS "CONFIG" OPTIONS "STDEXEC_BUILD_TESTS OFF" "STDEXEC_BUILD_EXAMPLES OFF" "STDEXEC_ENABLE_ASIO ON"
cpmaddpackage(URI "gh:NVIDIA/stdexec#770f7959142c2446319f642c82aed8b07aea3f86" NAME "stdexec" VERSION 0.11 FIND_PACKAGE_ARGUMENTS "CONFIG" OPTIONS "STDEXEC_BUILD_TESTS OFF" "STDEXEC_BUILD_EXAMPLES OFF" "STDEXEC_ENABLE_ASIO ON" "CMAKE_SKIP_INSTALL_RULES ${CMAKE_SKIP_INSTALL_RULES}"
)
cpmaddpackage(URI "gh:Tradias/asio-grpc@3.5.0" FIND_PACKAGE_ARGUMENTS "CONFIG" VERSION 3.4.0)
cpmaddpackage(URI "gh:nlohmann/json@3.12.0" FIND_PACKAGE_ARGUMENTS "CONFIG" NAME "nlohmann_json")
Expand Down
6 changes: 3 additions & 3 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
"debug-build"
],
"cacheVariables": {
"QUITE_INSTALL": false,
"BUILD_TESTING": true,
"CMAKE_SKIP_INSTALL_RULES": true,
"SANITIZE_ADDRESS": false,
"SANITIZE_UNDEFINED": false
}
Expand Down Expand Up @@ -96,13 +96,13 @@
"common"
],
"cacheVariables": {
"QUITE_INSTALL": false,
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"BUILD_TESTING": true,
"CMAKE_C_COMPILER": "gcc-13",
"CMAKE_CXX_COMPILER": "g++-13",
"CMAKE_C_COMPILER_LAUNCHER": "ccache",
"CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
"CMAKE_SKIP_INSTALL_RULES": true
"CMAKE_CXX_COMPILER_LAUNCHER": "ccache"
},
"environment": {
"WAYLAND_DISPLAY": "wl-test-env"
Expand Down
2 changes: 1 addition & 1 deletion libs/client/src/grpc_impl/grpc_remote_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ AsyncResult<void> GrpcRemoteObject::mouse_action()
{
LOG_DEBUG(grpc_remote_object_logger(), "mouse_action for object={}", id());
co_return co_await client_->mouse_injector().single_action(
id(), core::MouseAction{.button = core::MouseButton::left, .trigger = core::MouseTrigger::click});
id(), core::MouseAction{.button = MouseButton::left, .trigger = MouseTrigger::click});
}

AsyncResult<Image> GrpcRemoteObject::take_snapshot()
Expand Down
5 changes: 5 additions & 0 deletions libs/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ target_sources(
TYPE HEADERS
BASE_DIRS include
FILES
include/quite/mouse.hpp
include/quite/keyboard.hpp
include/quite/asio_context.hpp
include/quite/async_result.hpp
include/quite/disable_copy_move.hpp
Expand All @@ -61,6 +63,9 @@ target_sources(
include/quite/value/generic_value_class.hpp
include/quite/value/object_query.hpp
include/quite/injectors/mouse_injector.hpp
include/quite/core/bit.hpp
include/quite/core/bit_flags.hpp
include/quite/core/bit_flags_fmt.hpp
FILE_SET export_config
TYPE HEADERS
BASE_DIRS ${CMAKE_CURRENT_BINARY_DIR}
Expand Down
15 changes: 15 additions & 0 deletions libs/core/include/quite/core/bit.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-FileCopyrightText: 2025 Mathis Logemann <mathis@quite.rocks>
//
// SPDX-License-Identifier: MIT

#pragma once
#include <concepts>

namespace quite
{
template <std::integral T = unsigned int>
constexpr T bit(std::size_t position)
{
return static_cast<T>(1) << position;
}
} // namespace quite
156 changes: 156 additions & 0 deletions libs/core/include/quite/core/bit_flags.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// SPDX-FileCopyrightText: 2025 Mathis Logemann <mathis@quite.rocks>
//
// SPDX-License-Identifier: MIT

#pragma once
#include <initializer_list>
#include <type_traits>
namespace quite
{
template <typename T>
class BitFlags
{
using underlying_t = std::underlying_type_t<T>;

public:
constexpr BitFlags()
: flags_(static_cast<underlying_t>(0))
{}

constexpr explicit BitFlags(T v)
: flags_(to_underlying(v))
{}

constexpr BitFlags(std::initializer_list<T> vs)
: BitFlags()
{
for (T v : vs)
{
flags_ |= to_underlying(v);
}
}

constexpr bool is_set(T v) const
{
return (flags_ & to_underlying(v)) == to_underlying(v);
}

constexpr void set(T v)
{
flags_ |= to_underlying(v);
}

constexpr void unset(T v)
{
flags_ &= ~to_underlying(v);
}

constexpr void clear()
{
flags_ = static_cast<underlying_t>(0);
}

constexpr operator bool() const
{
return flags_ != static_cast<underlying_t>(0);
}

friend constexpr BitFlags operator|(BitFlags lhs, T rhs)
{
return BitFlags(lhs.flags_ | to_underlying(rhs));
}

friend constexpr BitFlags operator|(BitFlags lhs, BitFlags rhs)
{
return BitFlags(lhs.flags_ | rhs.flags_);
}

friend constexpr BitFlags operator&(BitFlags lhs, T rhs)
{
return BitFlags(lhs.flags_ & to_underlying(rhs));
}

friend constexpr BitFlags operator&(BitFlags lhs, BitFlags rhs)
{
return BitFlags(lhs.flags_ & rhs.flags_);
}

friend constexpr BitFlags operator^(BitFlags lhs, T rhs)
{
return BitFlags(lhs.flags_ ^ to_underlying(rhs));
}

friend constexpr BitFlags operator^(BitFlags lhs, BitFlags rhs)
{
return BitFlags(lhs.flags_ ^ rhs.flags_);
}

friend constexpr BitFlags &operator|=(BitFlags &lhs, T rhs)
{
lhs.flags_ |= to_underlying(rhs);
return lhs;
}
friend constexpr BitFlags &operator|=(BitFlags &lhs, BitFlags rhs)
{
lhs.flags_ |= rhs.flags_;
return lhs;
}
friend constexpr BitFlags &operator&=(BitFlags &lhs, T rhs)
{
lhs.flags_ &= to_underlying(rhs);
return lhs;
}
friend constexpr BitFlags &operator&=(BitFlags &lhs, BitFlags rhs)
{
lhs.flags_ &= rhs.flags_;
return lhs;
}
friend constexpr BitFlags &operator^=(BitFlags &lhs, T rhs)
{
lhs.flags_ ^= to_underlying(rhs);
return lhs;
}
friend constexpr BitFlags &operator^=(BitFlags &lhs, BitFlags rhs)
{
lhs.flags_ ^= rhs.flags_;
return lhs;
}

friend constexpr BitFlags operator~(const BitFlags &bf)
{
return BitFlags(~bf.flags_);
}

friend constexpr bool operator==(const BitFlags &lhs, const BitFlags &rhs)
{
return lhs.flags_ == rhs.flags_;
}

friend constexpr bool operator!=(const BitFlags &lhs, const BitFlags &rhs)
{
return lhs.flags_ != rhs.flags_;
}

// Construct BitFlags from raw values.
static constexpr BitFlags from_raw(underlying_t flags)
{
return BitFlags(flags);
}

// Retrieve the raw underlying flags.
constexpr underlying_t to_raw() const
{
return flags_;
}

private:
constexpr explicit BitFlags(underlying_t flags)
: flags_(flags)
{}
static constexpr underlying_t to_underlying(T v)
{
return static_cast<underlying_t>(v);
}
underlying_t flags_;
};
} // namespace quite
34 changes: 34 additions & 0 deletions libs/core/include/quite/core/bit_flags_fmt.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-FileCopyrightText: 2025 Mathis Logemann <mathis@quite.rocks>
//
// SPDX-License-Identifier: MIT

#pragma once
#include <format>
#include "quite/core/bit_flags.hpp"

template <typename T>
struct std::formatter<quite::BitFlags<T>>
{
constexpr auto parse(std::format_parse_context &ctx)
{
return ctx.begin();
}

auto format(const quite::BitFlags<T> &bf, std::format_context &ctx) const
{
using underlying_t = std::underlying_type_t<T>;
constexpr size_t kNumBits = sizeof(underlying_t) * 8;
auto val = bf.to_raw();

// Format as binary string
std::string binary;
binary.reserve(kNumBits);
for (size_t i = 0; i < kNumBits; ++i)
{
binary = ((val & 1) ? '1' : '0') + binary;
val >>= 1;
}

return std::format_to(ctx.out(), "{}", binary);
}
};
3 changes: 2 additions & 1 deletion libs/core/include/quite/injectors/mouse_injector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// SPDX-License-Identifier: MIT

#pragma once
#include "keys.hpp"
#include "quite/async_result.hpp"
#include "quite/geometry.hpp"
#include "quite/keyboard.hpp"
#include "quite/mouse.hpp"
#include "quite/quite_core_export.hpp"
#include "quite/value/object_id.hpp"

Expand Down
18 changes: 18 additions & 0 deletions libs/core/include/quite/keyboard.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2025 Mathis Logemann <mathis@quite.rocks>
//
// SPDX-License-Identifier: MIT

#pragma once
#include "quite/core/bit.hpp"

namespace quite
{
enum class KeyboardModifier
{
none = 0,
shift = bit(0),
control = bit(1),
alt = bit(2),
meta = bit(3),
};
} // namespace quite
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT

#pragma once
namespace quite::core
namespace quite
{
enum class MouseTrigger
{
Expand All @@ -24,13 +24,4 @@ enum class MouseButton
forward,
back,
};

enum class KeyboardModifier
{
none,
shift,
control,
alt,
meta,
};
} // namespace quite::core
} // namespace quite
4 changes: 3 additions & 1 deletion libs/core/src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ Image::Image(std::vector<std::byte> image_data, std::uint32_t width, std::uint32

Image::Image(const std::filesystem::path &filename)
{
int w, h, channels;
int w{};
int h{};
int channels{};
auto *data = stbi_load(filename.c_str(), &w, &h, &channels, 0);
if (data != nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion libs/core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ add_sanitizers(core_test)
target_link_libraries(core_test PRIVATE quite::core Boost::ut)
add_test(NAME core_test COMMAND core_test)

target_sources(core_test PRIVATE test_error.cpp)
target_sources(core_test PRIVATE test_error.cpp test_bit_flags.cpp)
Loading
Loading