Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-10-05 04:50:09 +03:00
parent 8653b02c44
commit 1414a66e56
6 changed files with 226 additions and 173 deletions

26
.clang-format Normal file
View File

@@ -0,0 +1,26 @@
UseTab: ForIndentation
TabWidth: 4
IndentWidth: 4
ColumnLimit: 80
AlignEscapedNewlines: DontAlign
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
BasedOnStyle: WebKit
BraceWrapping:
AfterFunction: true
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: true
BreakConstructorInitializers: BeforeComma
IndentPPDirectives: AfterHash
IndentRequiresClause: false
InsertNewlineAtEOF: true
LineEnding: LF
NamespaceIndentation: None
PointerAlignment: Right # east pointer
QualifierAlignment: Right # east const
RemoveSemicolon: true
RequiresClausePosition: WithFollowing
RequiresExpressionIndentation: OuterScope
SpaceAfterTemplateKeyword: false

View File

@@ -22,7 +22,7 @@ extern "C" {
#include "common.hpp"
struct TypingBuffer : std::pmr::vector<u32> {
void push_utf8(const char *s);
void push_utf8(char const *s);
};
struct App {
@@ -46,11 +46,13 @@ private:
auto destroy_layer_surface() -> void;
auto ensure_egl_surface() -> void;
auto update_blur_region() -> void;
auto theme() const -> ColorScheme const & { return m_themes[m_active_theme]; }
auto theme() const -> ColorScheme const &
{
return m_themes[m_active_theme];
}
static void on_settings_changed(XdpSettings * /*self*/, const char *ns,
const char *key, GVariant * /*value*/,
gpointer data);
static void on_settings_changed(XdpSettings * /*self*/, char const *ns,
char const *key, GVariant * /*value*/, gpointer data);
struct {
wl_display *display {};
@@ -91,38 +93,47 @@ private:
std::unordered_set<u32> pressed_syms;
std::unordered_set<u32> released_syms;
auto is_down_evdev(u32 evdev) const -> bool {
auto is_down_evdev(u32 evdev) const -> bool
{
return held.find(evdev) != held.end();
}
auto is_down_sym(xkb_keysym_t sym) const -> bool {
auto is_down_sym(xkb_keysym_t sym) const -> bool
{
if (!xkb_state)
return false;
for (auto k : held) {
if (xkb_state_key_get_one_sym(xkb_state,
static_cast<xkb_keycode_t>(k + 8)) == sym)
if (xkb_state_key_get_one_sym(
xkb_state, static_cast<xkb_keycode_t>(k + 8))
== sym)
return true;
}
return false;
}
auto is_sym_pressed(xkb_keysym_t sym) const -> bool {
auto is_sym_pressed(xkb_keysym_t sym) const -> bool
{
return pressed_syms.find(sym) != pressed_syms.end();
}
auto is_sym_released(xkb_keysym_t sym) const -> bool {
auto is_sym_released(xkb_keysym_t sym) const -> bool
{
return released_syms.find(sym) != released_syms.end();
}
auto mod_active(const char *name) const -> bool {
return xkb_state && xkb_state_mod_name_is_active(
xkb_state, name, XKB_STATE_MODS_EFFECTIVE) > 0;
auto mod_active(char const *name) const -> bool
{
return xkb_state
&& xkb_state_mod_name_is_active(
xkb_state, name, XKB_STATE_MODS_EFFECTIVE)
> 0;
}
auto ctrl() const -> bool { return mod_active("Control"); }
auto shift() const -> bool { return mod_active("Shift"); }
void clear_transients() {
void clear_transients()
{
pressed_syms.clear();
released_syms.clear();
}

View File

@@ -17,7 +17,8 @@ template <> struct enum_traits<Theme> {
static constexpr Theme last = Theme::_last;
};
constexpr auto make_default_themes() -> enum_array<Theme, ColorScheme> const {
constexpr auto make_default_themes() -> enum_array<Theme, ColorScheme> const
{
enum_array<Theme, ColorScheme> array;
array[Theme::Light] = {
.window =

View File

@@ -11,7 +11,8 @@ using i64 = std::int64_t;
using usize = std::uintptr_t;
using isize = std::intptr_t;
inline auto rune_to_string(uint32_t cp) -> char const * {
inline auto rune_to_string(uint32_t cp) -> char const *
{
static char utf8[5] = { 0 };
for (auto &c : utf8)
c = 0;

View File

@@ -11,9 +11,9 @@ template <class E>
concept EnumLike = std::is_enum_v<E>;
template<EnumLike E>
constexpr std::size_t enum_count_v =
static_cast<std::size_t>(enum_traits<E>::last) -
static_cast<std::size_t>(enum_traits<E>::first) + 1;
constexpr std::size_t enum_count_v
= static_cast<std::size_t>(enum_traits<E>::last)
- static_cast<std::size_t>(enum_traits<E>::first) + 1;
template<EnumLike E, class T> struct enum_array {
using value_type = T;
@@ -28,43 +28,49 @@ template <EnumLike E, class T> struct enum_array {
static constexpr std::size_t size() noexcept { return size_value; }
constexpr T *data() noexcept { return _data.data(); }
constexpr const T *data() const noexcept { return _data.data(); }
constexpr T const *data() const noexcept { return _data.data(); }
constexpr T *begin() noexcept { return _data.begin().operator->(); }
constexpr const T *begin() const noexcept {
constexpr T const *begin() const noexcept
{
return _data.begin().operator->();
}
constexpr T *end() noexcept { return _data.end().operator->(); }
constexpr const T *end() const noexcept { return _data.end().operator->(); }
constexpr T const *end() const noexcept { return _data.end().operator->(); }
constexpr T &operator[](E e) noexcept { return _data[to_index(e)]; }
constexpr const T &operator[](E e) const noexcept {
constexpr T const &operator[](E e) const noexcept
{
return _data[to_index(e)];
}
constexpr T &at(E e) {
constexpr T &at(E e)
{
auto i = to_index(e);
if (i >= size_value)
throw std::out_of_range("enum_array::at");
return _data[i];
}
constexpr const T &at(E e) const {
constexpr T const &at(E e) const
{
auto i = to_index(e);
if (i >= size_value)
throw std::out_of_range("enum_array::at");
return _data[i];
}
constexpr void fill(const T &v) { _data.fill(v); }
constexpr void fill(T const &v) { _data.fill(v); }
private:
static constexpr std::size_t to_index(E e) noexcept {
static constexpr std::size_t to_index(E e) noexcept
{
return static_cast<std::size_t>(e) - static_cast<std::size_t>(first);
}
};
template<class E, class T, class... U>
requires EnumLike<E> && (std::is_same_v<T, U> && ...)
constexpr auto make_enum_array(T &&first_val, U &&...rest) {
constexpr auto make_enum_array(T &&first_val, U &&...rest)
{
enum_array<E, std::decay_t<T>> arr;
static_assert(sizeof...(rest) + 1 == enum_count_v<E>,
"initializer count must match enum range");

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 '*.cpp' -o -name '*.hpp' -print0 | while IFS= read -r -d '' f; do
clang-format -i --style=file "$f"
done