26
.clang-format
Normal file
26
.clang-format
Normal 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
|
||||
101
src/App.hpp
101
src/App.hpp
@@ -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,95 +46,106 @@ 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{};
|
||||
wl_registry *registry{};
|
||||
wl_compositor *compositor{};
|
||||
wl_seat *seat{};
|
||||
wl_keyboard *kbd{};
|
||||
wl_surface *wl_surface{};
|
||||
zwlr_layer_shell_v1 *layer_shell{};
|
||||
zwlr_layer_surface_v1 *layer_surface{};
|
||||
ext_background_effect_manager_v1 *mgr{};
|
||||
ext_background_effect_surface_v1 *eff{};
|
||||
org_kde_kwin_blur_manager *kde_blur_mgr{};
|
||||
org_kde_kwin_blur *kde_blur{};
|
||||
wl_display *display {};
|
||||
wl_registry *registry {};
|
||||
wl_compositor *compositor {};
|
||||
wl_seat *seat {};
|
||||
wl_keyboard *kbd {};
|
||||
wl_surface *wl_surface {};
|
||||
zwlr_layer_shell_v1 *layer_shell {};
|
||||
zwlr_layer_surface_v1 *layer_surface {};
|
||||
ext_background_effect_manager_v1 *mgr {};
|
||||
ext_background_effect_surface_v1 *eff {};
|
||||
org_kde_kwin_blur_manager *kde_blur_mgr {};
|
||||
org_kde_kwin_blur *kde_blur {};
|
||||
} m_wayland;
|
||||
|
||||
struct {
|
||||
EGLDisplay edpy{EGL_NO_DISPLAY};
|
||||
EGLConfig ecfg{};
|
||||
EGLContext ectx{EGL_NO_CONTEXT};
|
||||
EGLSurface esurf{EGL_NO_SURFACE};
|
||||
wl_egl_window *wegl{};
|
||||
EGLDisplay edpy { EGL_NO_DISPLAY };
|
||||
EGLConfig ecfg {};
|
||||
EGLContext ectx { EGL_NO_CONTEXT };
|
||||
EGLSurface esurf { EGL_NO_SURFACE };
|
||||
wl_egl_window *wegl {};
|
||||
} m_gl;
|
||||
|
||||
struct {
|
||||
XdpPortal *portal{};
|
||||
XdpSettings *settings{};
|
||||
XdpPortal *portal {};
|
||||
XdpSettings *settings {};
|
||||
} m_xdp;
|
||||
|
||||
struct {
|
||||
TypingBuffer typing{};
|
||||
TypingBuffer typing {};
|
||||
|
||||
xkb_context *xkb_ctx{};
|
||||
xkb_keymap *xkb_keymap{};
|
||||
xkb_state *xkb_state{};
|
||||
xkb_context *xkb_ctx {};
|
||||
xkb_keymap *xkb_keymap {};
|
||||
xkb_state *xkb_state {};
|
||||
|
||||
std::unordered_set<u32> held;
|
||||
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();
|
||||
}
|
||||
} m_kbd;
|
||||
|
||||
enum_array<Theme, ColorScheme> m_themes{make_default_themes()};
|
||||
Theme m_active_theme{Theme::Light};
|
||||
enum_array<Theme, ColorScheme> m_themes { make_default_themes() };
|
||||
Theme m_active_theme { Theme::Light };
|
||||
|
||||
int m_win_w{800};
|
||||
int m_win_h{600};
|
||||
bool m_running{true};
|
||||
bool m_visible{true};
|
||||
int m_win_w { 800 };
|
||||
int m_win_h { 600 };
|
||||
bool m_running { true };
|
||||
bool m_visible { true };
|
||||
|
||||
int m_sfd{-1};
|
||||
int m_sfd { -1 };
|
||||
};
|
||||
|
||||
@@ -12,12 +12,13 @@ struct ColorScheme {
|
||||
|
||||
enum class Theme : int { Light = 0, Dark, _last = Dark };
|
||||
|
||||
template <> struct enum_traits<Theme> {
|
||||
template<> struct enum_traits<Theme> {
|
||||
static constexpr Theme first = Theme::Light;
|
||||
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 =
|
||||
|
||||
@@ -11,8 +11,9 @@ 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 * {
|
||||
static char utf8[5] = {0};
|
||||
inline auto rune_to_string(uint32_t cp) -> char const *
|
||||
{
|
||||
static char utf8[5] = { 0 };
|
||||
for (auto &c : utf8)
|
||||
c = 0;
|
||||
|
||||
|
||||
@@ -5,17 +5,17 @@
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
|
||||
template <class E> struct enum_traits;
|
||||
template<class E> struct enum_traits;
|
||||
|
||||
template <class E>
|
||||
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;
|
||||
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;
|
||||
|
||||
template <EnumLike E, class T> struct enum_array {
|
||||
template<EnumLike E, class T> struct enum_array {
|
||||
using value_type = T;
|
||||
using enum_type = E;
|
||||
using underlying_index_type = std::size_t;
|
||||
@@ -24,50 +24,56 @@ template <EnumLike E, class T> struct enum_array {
|
||||
static constexpr E last = enum_traits<E>::last;
|
||||
static constexpr std::size_t size_value = enum_count_v<E>;
|
||||
|
||||
std::array<T, size_value> _data{};
|
||||
std::array<T, size_value> _data {};
|
||||
|
||||
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) {
|
||||
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)
|
||||
{
|
||||
enum_array<E, std::decay_t<T>> arr;
|
||||
static_assert(sizeof...(rest) + 1 == enum_count_v<E>,
|
||||
"initializer count must match enum range");
|
||||
arr._data = {std::forward<T>(first_val), std::forward<U>(rest)...};
|
||||
arr._data = { std::forward<T>(first_val), std::forward<U>(rest)... };
|
||||
return arr;
|
||||
}
|
||||
|
||||
8
tools/format.sh
Executable file
8
tools/format.sh
Executable 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
|
||||
Reference in New Issue
Block a user