Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-08-11 01:24:53 +03:00
parent aa80a4c9d0
commit c9590037aa
4 changed files with 116 additions and 17 deletions

View File

@@ -2,6 +2,8 @@ function main(kbd)
return "Super-" .. kbd
end
return {
input = {
keyboard = {
@@ -13,5 +15,18 @@ return {
{ bind = main("Shift-R"), action = lunar.reload_config },
{ bind = main("R"), action = lunar.recenter },
{ bind = main("Tab"), action = lunar.cycle_next },
{ bind = main("Space"), action = function() lunar.exec("kitty") end },
},
space = {
radius = 1.0,
},
displays = {
hud = {
size = 720,
font_size = 24,
},
virtual = {
resolution = { 2560, 1440 },
},
},
}

View File

@@ -160,8 +160,11 @@ int config_load_ref(lua_State *L, int idx, Config *out)
// ======== DEFAULTS ========
out->space.offset = (Vector3) { 0, 0, 0 };
out->space.initial_center = (Vector3) { 0, 1, 0 };
out->space.radius = 0.7f;
out->space.radius = 1.0f;
out->space.window_scale = 0.001f;
out->displays.hud.size = 720;
out->displays.hud.font_size = 24;
out->displays.virtual.resolution = (Vector2) { 2560, 1440 };
// ====== END DEFAULTS ======
out->xwayland.enabled = true;
@@ -290,6 +293,34 @@ int config_load_ref(lua_State *L, int idx, Config *out)
}
lua_pop(L, 1);
lua_getfield(L, -1, "displays");
if (lua_istable(L, -1)) {
lua_getfield(L, -1, "hud");
if (lua_istable(L, -1)) {
lua_getfield(L, -1, "size");
if (lua_isnumber(L, -1))
out->displays.hud.size = (float)lua_tonumber(L, -1);
lua_pop(L, 1);
lua_getfield(L, -1, "font_size");
if (lua_isnumber(L, -1))
out->displays.hud.font_size = (float)lua_tonumber(L, -1);
lua_pop(L, 1);
}
lua_pop(L, 1);
lua_getfield(L, -1, "virtual");
if (lua_istable(L, -1)) {
lua_getfield(L, -1, "resolution");
if (lua_istable(L, -1) || lua_isuserdata(L, -1))
out->displays.virtual.resolution
= lua_readVector2(L, lua_absindex(L, -1));
lua_pop(L, 1);
}
lua_pop(L, 1);
}
lua_pop(L, 1);
lua_pop(L, 1);
return 0;
}

View File

@@ -37,6 +37,16 @@ typedef struct {
bool enabled;
bool lazy;
} xwayland;
struct {
struct {
int size;
float font_size;
} hud;
struct {
Vector2 resolution;
} virtual;
} displays;
} Config;
char const *get_config_path(void);

View File

@@ -5,6 +5,7 @@
#include <assert.h>
#include <ctype.h>
#include <math.h>
#include <spawn.h>
#include <stdlib.h>
#include <EGL/egl.h>
@@ -37,6 +38,10 @@
#include <raymath.h>
#include <rlgl.h>
#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>
#include "vec.h"
void toplevel_commit_notify(struct wl_listener *l, void *)
@@ -122,6 +127,9 @@ bool LunarWM_Toplevel_destroy(LunarWM_Toplevel *this)
bool LunarWM_Toplevel_update(LunarWM_Toplevel *this)
{
if (!this || !this->surface)
return false;
this->texture = wlr_surface_get_texture(this->surface);
struct wlr_client_buffer *cl_buf = this->surface->buffer;
if ((this->texture == nullptr) || (cl_buf == nullptr)) {
@@ -1112,11 +1120,11 @@ static bool init_xr(LunarWM *this)
}
uint32_t const view_count = this->xr.view_configuration_views_count;
uint32_t const eyeW
uint32_t const eye_w
= this->xr.a_view_configuration_views[0].recommendedImageRectWidth;
uint32_t const eyeH
uint32_t const eye_h
= this->xr.a_view_configuration_views[0].recommendedImageRectHeight;
uint32_t const bufW = eyeW * view_count;
uint32_t const buf_w = eye_w * view_count;
if (!this->xr.swapchains.v_color) {
this->xr.swapchains.v_color = vector_create();
@@ -1142,8 +1150,8 @@ static bool init_xr(LunarWM *this)
| XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT,
.format = swapchain_format_color,
.sampleCount = vcv->recommendedSwapchainSampleCount,
.width = bufW,
.height = eyeH,
.width = buf_w,
.height = eye_h,
.faceCount = 1,
.arraySize = 1,
.mipCount = 1,
@@ -1166,8 +1174,8 @@ static bool init_xr(LunarWM *this)
| XR_SWAPCHAIN_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
.format = swapchain_format_depth,
.sampleCount = vcv->recommendedSwapchainSampleCount,
.width = bufW,
.height = eyeH,
.width = buf_w,
.height = eye_h,
.faceCount = 1,
.arraySize = 1,
.mipCount = 1,
@@ -1403,7 +1411,32 @@ static bool init_xr(LunarWM *this)
return true;
}
static void sync_config(LunarWM *this) { }
static void sync_config(LunarWM *this)
{
UnloadTexture(this->renderer.hud_rt.texture);
this->renderer.hud_rt.texture.id = 0;
this->renderer.hud_rt.texture.width = 0;
this->renderer.hud_rt.texture.height = 0;
}
extern char **environ;
static int l_exec(lua_State *L)
{
char const *cmd = luaL_checkstring(L, 1);
pid_t pid;
char *argv[] = { (char *)"sh", (char *)"-c", (char *)cmd, NULL };
int rc = posix_spawnp(&pid, "sh", NULL, NULL, argv, environ);
if (rc != 0) {
lua_pushnil(L);
lua_pushfstring(L, "posix_spawnp failed: %s", strerror(rc));
return 2;
}
lua_pushinteger(L, (lua_Integer)pid);
return 1;
}
static int l_cycle_next(lua_State *L)
{
@@ -1485,6 +1518,8 @@ bool LunarWM_init(LunarWM *this)
lua_setfield(L, -2, "recenter");
lua_pushcfunction(L, l_cycle_next);
lua_setfield(L, -2, "cycle_next");
lua_pushcfunction(L, l_exec);
lua_setfield(L, -2, "exec");
lua_setglobal(L, "lunar");
config_manager_reload(this->cman);
@@ -1942,14 +1977,18 @@ void render_hud(LunarWM *this, float /*dt*/, int hud_size)
{
ClearBackground((Color) { 0, 0, 0, 0 });
float const text_size = this->cman->cfg.displays.hud.font_size;
char const *txt
= TextFormat("WAYLAND_DISPLAY=%s", getenv("WAYLAND_DISPLAY"));
auto txt_w = MeasureText(txt, 24);
DrawText(txt, hud_size / 2 - txt_w / 2, hud_size - 24, 24, WHITE);
DrawText(
txt, hud_size / 2 - txt_w / 2, hud_size - text_size, text_size, WHITE);
txt = TextFormat("DISPLAY=%s", getenv("DISPLAY"));
txt_w = MeasureText(txt, 24);
DrawText(txt, hud_size / 2 - txt_w / 2, hud_size - 24 - 24, 24, WHITE);
txt_w = MeasureText(txt, text_size);
DrawText(txt, hud_size / 2 - txt_w / 2, hud_size - text_size * 2, text_size,
WHITE);
{
time_t t = time(NULL);
@@ -1959,7 +1998,7 @@ void render_hud(LunarWM *this, float /*dt*/, int hud_size)
int minutes = tm_info->tm_min;
txt = TextFormat("%02d:%02d", hours, minutes);
txt_w = MeasureText(txt, 32);
DrawText(txt, hud_size / 2 - txt_w / 2, 0, 32, WHITE);
DrawText(txt, hud_size / 2 - txt_w / 2, 0, text_size, WHITE);
}
}
@@ -1971,7 +2010,11 @@ void render_3d(LunarWM *this, float /*dt*/)
for (size_t i = 0; i < vector_size(this->wayland.v_toplevels); i++) {
auto *tl = this->wayland.v_toplevels[i];
LunarWM_Toplevel_update(tl);
if (!tl || !tl->surface)
continue;
if (!LunarWM_Toplevel_update(tl))
continue;
DrawTexture3D(tl->rl_texture,
Vector3Add(this->renderer.center,
@@ -1982,9 +2025,9 @@ void render_3d(LunarWM *this, float /*dt*/)
rlEnableBackfaceCulling();
for (int h = 0; h < 2; ++h) {
auto *handInfo = &this->xr.hands[h];
auto *hand_info = &this->xr.hands[h];
for (size_t k = 0; k < XR_HAND_JOINT_COUNT_EXT; ++k) {
auto const *jl = &handInfo->joint_locations[k];
auto const *jl = &hand_info->joint_locations[k];
Vector3 const pos = {
jl->pose.position.x,
jl->pose.position.y,
@@ -2097,7 +2140,7 @@ static bool render_layer(LunarWM *this, LunarWM_RenderLayerInfo *info, float dt)
Matrix const view_off_r
= MatrixMultiply(xr_matrix(views[1].pose), head_view);
int const hud_size = eye_h * 0.3;
int const hud_size = this->cman->cfg.displays.hud.size;
if (!IsTextureValid(this->renderer.hud_rt.texture)) {
this->renderer.hud_rt = LoadRenderTexture(hud_size, hud_size);
}