Fix defaults

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-08-10 12:24:43 +03:00
parent ad0d09ebd2
commit 025ee9da91
7 changed files with 363 additions and 18 deletions

View File

@@ -1,5 +1,7 @@
#include "Config.h"
#include "common.h"
#include "lua_helpers.h"
#include <stdio.h>
#include <stdlib.h>
@@ -155,6 +157,16 @@ int config_load_ref(lua_State *L, int idx, Config *out)
memset(out, 0, sizeof(*out));
// ======== DEFAULTS ========
out->space.offset = (Vector3) { 0, 0, 0 };
out->space.initial_center = (Vector3) { 0, 1, 0 };
out->space.radius = 0.7f;
out->space.window_scale = 0.001f;
// ====== END DEFAULTS ======
out->xwayland.enabled = true;
out->xwayland.lazy = true;
int cfg_abs = lua_absindex(L, idx);
if (push_config_table_from_idx(L, cfg_abs) != 0)
return -1;
@@ -215,12 +227,12 @@ int config_load_ref(lua_State *L, int idx, Config *out)
if (ok == 0) {
free(arr);
} else if (ok < n) {
BindingRef *shr = (BindingRef *)realloc(arr, ok * sizeof(*arr));
BindingRef *shr = (BindingRef *)realloc(arr, ok * sizeof(*shr));
if (shr)
arr = shr;
}
out->keybindings.items = (ok ? arr : NULL);
out->keybindings.items = ok ? arr : NULL;
out->keybindings.count = ok;
}
lua_pop(L, 1);
@@ -240,6 +252,44 @@ int config_load_ref(lua_State *L, int idx, Config *out)
}
lua_pop(L, 1);
lua_getfield(L, -1, "space");
if (lua_istable(L, -1)) {
lua_getfield(L, -1, "offset");
if (lua_istable(L, -1) || lua_isuserdata(L, -1))
out->space.offset = lua_readVector3(L, lua_absindex(L, -1));
lua_pop(L, 1);
lua_getfield(L, -1, "initial_center");
if (lua_istable(L, -1) || lua_isuserdata(L, -1))
out->space.initial_center = lua_readVector3(L, lua_absindex(L, -1));
lua_pop(L, 1);
lua_getfield(L, -1, "radius");
if (lua_isnumber(L, -1))
out->space.radius = (float)lua_tonumber(L, -1);
lua_pop(L, 1);
lua_getfield(L, -1, "window_scale");
if (lua_isnumber(L, -1))
out->space.window_scale = (float)lua_tonumber(L, -1);
lua_pop(L, 1);
}
lua_pop(L, 1);
lua_getfield(L, -1, "xwayland");
if (lua_istable(L, -1)) {
lua_getfield(L, -1, "enabled");
if (lua_isboolean(L, -1))
out->xwayland.enabled = lua_toboolean(L, -1);
lua_pop(L, 1);
lua_getfield(L, -1, "lazy");
if (lua_isboolean(L, -1))
out->xwayland.lazy = lua_toboolean(L, -1);
lua_pop(L, 1);
}
lua_pop(L, 1);
lua_pop(L, 1);
return 0;
}