bspwm/settings.c

105 lines
3.3 KiB
C
Raw Normal View History

#define _BSD_SOURCE
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-08-02 22:37:20 +02:00
#include "common.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);
2012-08-07 12:17:47 +02:00
active_border_color = string_expr(L, "active_border_color", ACTIVE_BORDER_COLOR);
locked_border_color = string_expr(L, "locked_border_color", LOCKED_BORDER_COLOR);
urgent_border_color = string_expr(L, "urgent_border_color", URGENT_BORDER_COLOR);
inner_border_color = string_expr(L, "inner_border_color", INNER_BORDER_COLOR);
2012-08-02 20:41:25 +02:00
smart_surroundings = bool_expr(L, "smart_surroundings", SMART_SURROUNDINGS);
2012-08-07 12:17:47 +02:00
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);
2012-07-30 19:43:54 +02:00
border_width = inner_border_width + outer_border_width;
2012-08-07 12:17:47 +02:00
window_gap = int_expr(L, "window_gap", WINDOW_GAP);
2012-08-01 12:25:18 +02:00
}
2012-08-02 22:37:20 +02:00
void get_setting(lua_State *L, char* rsp)
2012-08-01 12:25:18 +02:00
{
char *name;
2012-08-02 20:41:25 +02:00
if (!has_table(L, "get"))
2012-08-01 12:25:18 +02:00
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)
2012-08-02 22:37:20 +02:00
sprintf(rsp, "%i\n", inner_border_width);
2012-08-07 12:17:47 +02:00
else if (strcmp(name, "outer_border_width") == 0)
sprintf(rsp, "%i\n", outer_border_width);
else if (strcmp(name, "window_gap") == 0)
sprintf(rsp, "%i\n", window_gap);
2012-08-01 12:25:18 +02:00
else if (strcmp(name, "normal_border_color") == 0)
2012-08-02 22:37:20 +02:00
sprintf(rsp, "%s\n", normal_border_color);
2012-08-07 12:17:47 +02:00
else if (strcmp(name, "active_border_color") == 0)
sprintf(rsp, "%s\n", active_border_color);
else if (strcmp(name, "locked_border_color") == 0)
sprintf(rsp, "%s\n", locked_border_color);
else if (strcmp(name, "urgent_border_color") == 0)
sprintf(rsp, "%s\n", urgent_border_color);
2012-08-01 12:25:18 +02:00
else if (strcmp(name, "inner_border_color") == 0)
2012-08-02 22:37:20 +02:00
sprintf(rsp, "%s\n", inner_border_color);
2012-08-07 12:17:47 +02:00
else if (strcmp(name, "smart_surroundings") == 0)
sprintf(rsp, "%s\n", BOOLSTR(smart_surroundings));
2012-08-01 12:25:18 +02:00
}
void set_setting(lua_State *L)
{
char *name, *backup;
2012-08-01 12:25:18 +02:00
2012-08-02 20:41:25 +02:00
if (!has_table(L, "set"))
2012-08-01 12:25:18 +02:00
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) {
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) {
backup = strdup(normal_border_color);
2012-08-01 12:46:23 +02:00
free(normal_border_color);
normal_border_color = string_expr(L, "set.value", backup);
2012-08-01 12:46:23 +02:00
} else if (strcmp(name, "inner_border_color") == 0) {
backup = strdup(inner_border_color);
2012-08-01 12:46:23 +02:00
free(inner_border_color);
inner_border_color = string_expr(L, "set.value", backup);
} else if (strcmp(name, "smart_surroundings") == 0) {
smart_surroundings = bool_expr(L, "set.value", smart_surroundings);
2012-08-01 12:46:23 +02:00
}
if (backup != NULL)
free(backup);
2012-07-30 19:43:54 +02:00
}