bspwm/settings.c

84 lines
2.6 KiB
C
Raw Normal View History

2012-07-30 19:43:54 +02:00
#include <stdio.h>
2012-08-01 12:46:23 +02:00
#include <stdlib.h>
2012-08-01 12:25:18 +02:00
#include <string.h>
2012-07-30 14:54:20 +02:00
#include "utils.h"
#include "luautils.h"
2012-07-30 19:43:54 +02:00
#include "settings.h"
2012-07-30 14:54:20 +02:00
void load_settings(void)
{
2012-07-30 17:23:25 +02:00
lua_State *L = lua_open();
luaopen_base(L);
2012-07-30 14:54:20 +02:00
2012-07-30 17:23:25 +02:00
if (luaL_loadfile(L, CONFIG_FILE) == 0) {
2012-08-01 12:25:18 +02:00
if (lua_pcall(L, 0, 0, 0) == 0)
2012-07-30 19:43:54 +02:00
apply_settings(L);
2012-08-01 12:25:18 +02:00
else
2012-07-30 14:54:20 +02:00
die("error: cannot interpret configuration file\n");
} else {
die("error: could not load configuration file\n");
}
2012-07-30 17:23:25 +02:00
lua_close(L);
2012-07-30 14:54:20 +02:00
}
2012-07-30 19:43:54 +02:00
void apply_settings(lua_State *L)
{
2012-08-02 09:57:57 +02:00
normal_border_color = string_expr(L, "normal_border_color", NORMAL_BORDER_COLOR);
split_ratio = double_expr(L, "split_ratio", SPLIT_RATIO);
2012-08-01 12:25:18 +02:00
smart_surroundings = lua_boolexpr(L, "smart_surroundings", SMART_SURROUNDINGS);
2012-08-02 09:57:57 +02:00
outer_border_width = int_expr(L, "outer_border_width", OUTER_BORDER_WIDTH);
inner_border_width = int_expr(L, "inner_border_width", INNER_BORDER_WIDTH);
inner_border_color = string_expr(L, "inner_border_color", INNER_BORDER_COLOR);
2012-07-30 19:43:54 +02:00
border_width = inner_border_width + outer_border_width;
2012-08-01 12:25:18 +02:00
/* printf("split ratio: %f\n", split_ratio); */
/* printf("outer_border_width: %i\n", outer_border_width); */
/* printf("inner_border_color: %s\n", inner_border_color); */
/* printf("normal_border_color: %s\n", normal_border_color); */
/* printf("default normal_border_color: %s\n", NORMAL_BORDER_COLOR); */
/* printf("outer_border_color: %s\n", outer_border_color); */
/* printf("smart_surroundings: %i\n", smart_surroundings); */
}
void get_setting(lua_State *L)
{
char *name;
if (!lua_hastable(L, "get"))
return;
2012-08-02 09:57:57 +02:00
name = string_expr(L, "get.name", NULL);
2012-08-01 12:25:18 +02:00
if (name == NULL)
return;
if (strcmp(name, "inner_border_width") == 0)
printf("%i\n", inner_border_width);
else if (strcmp(name, "normal_border_color") == 0)
printf("%s\n", normal_border_color);
else if (strcmp(name, "inner_border_color") == 0)
printf("%s\n", inner_border_color);
}
void set_setting(lua_State *L)
{
char *name;
if (!lua_hastable(L, "set"))
return;
2012-08-02 09:57:57 +02:00
name = string_expr(L, "set.name", NULL);
2012-08-01 12:25:18 +02:00
if (name == NULL)
return;
2012-08-01 12:46:23 +02:00
if (strcmp(name, "inner_border_width") == 0) {
2012-08-02 09:57:57 +02:00
inner_border_width = int_expr(L, "set.value", INNER_BORDER_WIDTH);
2012-08-01 12:46:23 +02:00
} else if (strcmp(name, "normal_border_color") == 0) {
free(normal_border_color);
2012-08-02 09:57:57 +02:00
normal_border_color = string_expr(L, "set.value", NORMAL_BORDER_COLOR);
2012-08-01 12:46:23 +02:00
} else if (strcmp(name, "inner_border_color") == 0) {
free(inner_border_color);
2012-08-02 09:57:57 +02:00
inner_border_color = string_expr(L, "set.value", INNER_BORDER_COLOR);
2012-08-01 12:46:23 +02:00
}
2012-07-30 19:43:54 +02:00
}