140
src/App.hpp
Normal file
140
src/App.hpp
Normal file
@@ -0,0 +1,140 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory_resource>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <libportal/portal.h>
|
||||
extern "C" {
|
||||
#include "blur-client-protocol.h"
|
||||
#define namespace namespace_
|
||||
#include "ext-background-effect-v1-client-protocol.h"
|
||||
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
||||
#include <libportal/settings.h>
|
||||
#undef namespace
|
||||
}
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-egl.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
|
||||
#include "Theme.hpp"
|
||||
#include "common.hpp"
|
||||
|
||||
struct TypingBuffer : std::pmr::vector<u32> {
|
||||
void push_utf8(const char *s);
|
||||
};
|
||||
|
||||
struct App {
|
||||
App();
|
||||
~App();
|
||||
|
||||
auto run() -> void;
|
||||
auto set_visible(bool visible) -> void;
|
||||
auto visible() const -> bool { return m_visible; }
|
||||
|
||||
auto stop() -> void { m_running = false; }
|
||||
|
||||
private:
|
||||
auto init_wayland() -> void;
|
||||
auto init_egl() -> void;
|
||||
auto init_signal() -> void;
|
||||
auto init_theme_portal() -> void;
|
||||
auto pump_events() -> void;
|
||||
auto render_frame() -> void;
|
||||
auto create_layer_surface() -> void;
|
||||
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]; }
|
||||
|
||||
static void on_settings_changed(XdpSettings * /*self*/, const char *ns,
|
||||
const char *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{};
|
||||
} m_wayland;
|
||||
|
||||
struct {
|
||||
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{};
|
||||
} m_xdp;
|
||||
|
||||
struct {
|
||||
TypingBuffer typing{};
|
||||
|
||||
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 {
|
||||
return held.find(evdev) != held.end();
|
||||
}
|
||||
|
||||
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)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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 {
|
||||
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 ctrl() const -> bool { return mod_active("Control"); }
|
||||
auto shift() const -> bool { return mod_active("Shift"); }
|
||||
|
||||
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};
|
||||
|
||||
int m_win_w{800};
|
||||
int m_win_h{600};
|
||||
bool m_running{true};
|
||||
bool m_visible{true};
|
||||
|
||||
int m_sfd{-1};
|
||||
};
|
||||
Reference in New Issue
Block a user