commit 9fae0fe
0uppy
·
2026-05-09 14:27:25 +0000 UTC
parent 19aaeb2
slgro 1.3 - config-lua.c now loads the decors from lua yippie woo yay
1 files changed,
+89,
-30
+89,
-30
1@@ -14,16 +14,14 @@ struct config cfg;
2 struct bind *binds = NULL;
3 size_t nbinds = 0;
4
5-static char *spawn_args[128][2]; /* I'd ASSUME that 128 binds SHOULD be enough.........,..,., */
6+static char *spawn_args[128][2];
7 static size_t nspawn = 0;
8
9 static uint32_t parse_mods(const char *s) {
10-
11 uint32_t mods = 0;
12 char buf[64];
13 strncpy(buf, s, sizeof(buf) - 1);
14 char *tok = strtok(buf, "|");
15-
16 while (tok) {
17 if (!strcmp(tok, "MOD4")) mods |= SWC_MOD_LOGO;
18 else if (!strcmp(tok, "MOD1")) mods |= SWC_MOD_ALT;
19@@ -31,18 +29,15 @@ static uint32_t parse_mods(const char *s) {
20 else if (!strcmp(tok, "CTRL")) mods |= SWC_MOD_CTRL;
21 tok = strtok(NULL, "|");
22 }
23-
24 return mods;
25 }
26
27 static uint32_t parse_key(const char *s) {
28-
29 if (s[1] == '\0') {
30 if (s[0] >= 'a' && s[0] <= 'z') return XKB_KEY_a + (s[0] - 'a');
31 if (s[0] >= '1' && s[0] <= '9') return XKB_KEY_1 + (s[0] - '1');
32 if (s[0] == '0') return XKB_KEY_0;
33 }
34-
35 if (!strcmp(s, "Return")) return XKB_KEY_Return;
36 if (!strcmp(s, "Tab")) return XKB_KEY_Tab;
37 if (!strcmp(s, "space")) return XKB_KEY_space;
38@@ -51,21 +46,17 @@ static uint32_t parse_key(const char *s) {
39 if (!strcmp(s, "Up")) return XKB_KEY_Up;
40 if (!strcmp(s, "Down")) return XKB_KEY_Down;
41 fprintf(stderr, "slgro: sorry, unknown key >.< '%s'\n", s);
42-
43 return XKB_KEY_VoidSymbol;
44 }
45
46 static void resolve_action(const char *action, const char *arg_str, int arg_int, struct bind *b) {
47-
48 b->type = SWC_BINDING_KEY;
49-
50 if (!strcmp(action, "spawn")) {
51 spawn_args[nspawn][0] = strdup(arg_str);
52 spawn_args[nspawn][1] = NULL;
53 b->arg.v = spawn_args[nspawn++];
54 b->fn = spawn;
55 }
56-
57 else if (!strcmp(action, "kill")) b->fn = kill_sel;
58 else if (!strcmp(action, "focus_next")) b->fn = focus_next;
59 else if (!strcmp(action, "fullscreen")) b->fn = fullscreen;
60@@ -83,42 +74,109 @@ static void resolve_action(const char *action, const char *arg_str, int arg_int,
61 }
62
63 void load_config(void) {
64-
65 const char *home = getenv("HOME");
66 char path[256];
67 snprintf(path, sizeof(path), "%s/.config/slgro/config.lua", home ? home : ".");
68
69- cfg.motion_throttle_hz = 85;
70- cfg.border_col_active = 0xffffffff;
71- cfg.border_col_normal = 0xffffffff;
72- cfg.border_width = 2;
73+ cfg.motion_throttle_hz = 85;
74+ cfg.border_col_active = 0xffffffff;
75+ cfg.border_col_normal = 0xffffffff;
76+ cfg.border_width = 2;
77+
78+ /* defaults for le slgro v1.3 titlebar update, leaving this here currently for testing */
79+ cfg.decor.color = 0xff444444;
80+ cfg.decor.top = 2;
81+ cfg.decor.right = 2;
82+ cfg.decor.bottom = 2;
83+ cfg.decor.left = 24;
84+ cfg.decor.title.enabled = false;
85+ cfg.decor.title.edge = SWC_DECOR_EDGE_LEFT;
86+ cfg.decor.title.align = SWC_DECOR_ALIGN_START;
87+ cfg.decor.title.color = 0xffffffff;
88+ cfg.decor.title.padding = 8;
89+ cfg.decor.title.font = "monospace:size=12";
90
91 lua_State *L = luaL_newstate();
92 luaL_openlibs(L);
93
94 if (luaL_dofile(L, path) != LUA_OK) {
95- if (luaL_dofile(L, "/usr/share/slgro/config.lua") != LUA_OK) {
96- fprintf(stderr, "slgro: %s\n", lua_tostring(L, -1));
97- fprintf(stderr, "slgro: using defaults :P\n");
98- lua_close(L);
99- return;
100- }
101+ if (luaL_dofile(L, "/usr/share/slgro/config.lua") != LUA_OK) {
102+ fprintf(stderr, "slgro: %s\n", lua_tostring(L, -1));
103+ fprintf(stderr, "slgro: using defaults :P\n");
104+ lua_close(L);
105+ return;
106+ }
107 }
108
109 lua_getglobal(L, "border_active");
110- if (lua_isnumber(L, -1)) cfg.border_col_active = lua_tonumber(L, -1);
111+ if (lua_isnumber(L, -1)) cfg.border_col_active = (uint32_t)lua_tonumber(L, -1);
112 lua_pop(L, 1);
113
114 lua_getglobal(L, "border_normal");
115- if (lua_isnumber(L, -1)) cfg.border_col_normal = lua_tonumber(L, -1);
116+ if (lua_isnumber(L, -1)) cfg.border_col_normal = (uint32_t)lua_tonumber(L, -1);
117 lua_pop(L, 1);
118
119 lua_getglobal(L, "border_width");
120- if (lua_isnumber(L, -1)) cfg.border_width = lua_tonumber(L, -1);
121+ if (lua_isnumber(L, -1)) cfg.border_width = (uint32_t)lua_tonumber(L, -1);
122 lua_pop(L, 1);
123
124 lua_getglobal(L, "motion_throttle_hz");
125- if (lua_isnumber(L, -1)) cfg.motion_throttle_hz = lua_tonumber(L, -1);
126+ if (lua_isnumber(L, -1)) cfg.motion_throttle_hz = (uint32_t)lua_tonumber(L, -1);
127+ lua_pop(L, 1);
128+
129+ lua_getglobal(L, "decor_color");
130+ if (lua_isnumber(L, -1)) cfg.decor.color = (uint32_t)lua_tonumber(L, -1);
131+ lua_pop(L, 1);
132+
133+ lua_getglobal(L, "decor_top");
134+ if (lua_isnumber(L, -1)) cfg.decor.top = (uint32_t)lua_tonumber(L, -1);
135+ lua_pop(L, 1);
136+
137+ lua_getglobal(L, "decor_right");
138+ if (lua_isnumber(L, -1)) cfg.decor.right = (uint32_t)lua_tonumber(L, -1);
139+ lua_pop(L, 1);
140+
141+ lua_getglobal(L, "decor_bottom");
142+ if (lua_isnumber(L, -1)) cfg.decor.bottom = (uint32_t)lua_tonumber(L, -1);
143+ lua_pop(L, 1);
144+
145+ lua_getglobal(L, "decor_left");
146+ if (lua_isnumber(L, -1)) cfg.decor.left = (uint32_t)lua_tonumber(L, -1);
147+ lua_pop(L, 1);
148+
149+ lua_getglobal(L, "decor_title_enabled");
150+ cfg.decor.title.enabled = lua_toboolean(L, -1);
151+ lua_pop(L, 1);
152+
153+ lua_getglobal(L, "decor_title_color");
154+ if (lua_isnumber(L, -1)) cfg.decor.title.color = (uint32_t)lua_tonumber(L, -1);
155+ lua_pop(L, 1);
156+
157+ lua_getglobal(L, "decor_title_padding");
158+ if (lua_isnumber(L, -1)) cfg.decor.title.padding = (uint32_t)lua_tonumber(L, -1);
159+ lua_pop(L, 1);
160+
161+ lua_getglobal(L, "decor_title_font");
162+ if (lua_isstring(L, -1)) cfg.decor.title.font = strdup(lua_tostring(L, -1));
163+ lua_pop(L, 1);
164+
165+ lua_getglobal(L, "decor_title_edge");
166+ if (lua_isstring(L, -1)) {
167+ const char *e = lua_tostring(L, -1);
168+ if (!strcmp(e, "top")) cfg.decor.title.edge = SWC_DECOR_EDGE_TOP;
169+ else if (!strcmp(e, "right")) cfg.decor.title.edge = SWC_DECOR_EDGE_RIGHT;
170+ else if (!strcmp(e, "bottom")) cfg.decor.title.edge = SWC_DECOR_EDGE_BOTTOM;
171+ else cfg.decor.title.edge = SWC_DECOR_EDGE_LEFT;
172+ }
173+ lua_pop(L, 1);
174+
175+ lua_getglobal(L, "decor_title_align");
176+ if (lua_isstring(L, -1)) {
177+ const char *a = lua_tostring(L, -1);
178+ if (!strcmp(a, "center")) cfg.decor.title.align = SWC_DECOR_ALIGN_CENTER;
179+ else if (!strcmp(a, "end")) cfg.decor.title.align = SWC_DECOR_ALIGN_END;
180+ else cfg.decor.title.align = SWC_DECOR_ALIGN_START;
181+ }
182 lua_pop(L, 1);
183
184 lua_getglobal(L, "binds");
185@@ -128,11 +186,12 @@ void load_config(void) {
186 return;
187 }
188
189- size_t n = lua_objlen(L, -1);
190+ int binds_index = lua_gettop(L);
191+ size_t n = lua_objlen(L, binds_index);
192 binds = calloc(n, sizeof(struct bind));
193
194 for (size_t i = 1; i <= n; i++) {
195- lua_rawgeti(L, -1, i);
196+ lua_rawgeti(L, binds_index, i);
197 struct bind b = {0};
198
199 lua_getfield(L, -1, "mods");
200@@ -148,8 +207,8 @@ void load_config(void) {
201 lua_pop(L, 1);
202
203 lua_getfield(L, -1, "arg");
204- const char *arg_str = lua_isstring(L, -1) ? lua_tostring(L, -1) : "";
205- int arg_int = lua_isnumber(L, -1) ? lua_tonumber(L, -1) : 0;
206+ const char *arg_str = lua_isstring(L, -1) ? lua_tostring(L, -1) : "";
207+ int arg_int = lua_isnumber(L, -1) ? (int)lua_tonumber(L, -1) : 0;
208 lua_pop(L, 1);
209
210 if (action) resolve_action(action, arg_str, arg_int, &b);
211@@ -158,4 +217,4 @@ void load_config(void) {
212 }
213
214 lua_close(L); /* man i love lua :3 */
215-}
216+}