kmscon: use local configs instead of global kmscon_conf
We now have the ability to pass on local configurations so we no longer need the global kmscon_conf. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
d40b23d789
commit
9e0db18fb9
@ -37,8 +37,6 @@
|
||||
#include "log.h"
|
||||
#include "shl_misc.h"
|
||||
|
||||
struct kmscon_conf_t kmscon_conf;
|
||||
|
||||
static void print_help()
|
||||
{
|
||||
/*
|
||||
@ -337,14 +335,20 @@ static struct conf_grab def_grab_session_close =
|
||||
static struct conf_grab def_grab_terminal_new =
|
||||
CONF_SINGLE_GRAB(SHL_CONTROL_MASK | SHL_ALT_MASK, XKB_KEY_Return);
|
||||
|
||||
int kmscon_conf_new(struct conf_ctx **out, struct kmscon_conf_t *conf)
|
||||
int kmscon_conf_new(struct conf_ctx **out)
|
||||
{
|
||||
struct conf_ctx *ctx;
|
||||
int ret;
|
||||
struct kmscon_conf_t *conf;
|
||||
|
||||
if (!out || !conf)
|
||||
if (!out)
|
||||
return -EINVAL;
|
||||
|
||||
conf = malloc(sizeof(*conf));
|
||||
if (!conf)
|
||||
return -ENOMEM;
|
||||
memset(conf, 0, sizeof(*conf));
|
||||
|
||||
struct conf_option options[] = {
|
||||
/* Global Options */
|
||||
CONF_OPTION_BOOL('h', "help", aftercheck_help, NULL, &conf->help, false),
|
||||
@ -399,8 +403,10 @@ int kmscon_conf_new(struct conf_ctx **out, struct kmscon_conf_t *conf)
|
||||
|
||||
ret = conf_ctx_new(&ctx, options, sizeof(options) / sizeof(*options),
|
||||
conf);
|
||||
if (ret)
|
||||
if (ret) {
|
||||
free(conf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
*out = ctx;
|
||||
return 0;
|
||||
@ -408,25 +414,37 @@ int kmscon_conf_new(struct conf_ctx **out, struct kmscon_conf_t *conf)
|
||||
|
||||
void kmscon_conf_free(struct conf_ctx *ctx)
|
||||
{
|
||||
void *conf;
|
||||
if (!ctx)
|
||||
return;
|
||||
|
||||
conf = conf_ctx_get_mem(ctx);
|
||||
conf_ctx_free(ctx);
|
||||
free(conf);
|
||||
}
|
||||
|
||||
int kmscon_conf_load_main(struct conf_ctx *ctx, int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
struct kmscon_conf_t *conf;
|
||||
|
||||
if (!ctx)
|
||||
return -EINVAL;
|
||||
|
||||
conf = conf_ctx_get_mem(ctx);
|
||||
|
||||
ret = conf_ctx_parse_argv(ctx, argc, argv);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (kmscon_conf.exit)
|
||||
if (conf->exit)
|
||||
return 0;
|
||||
|
||||
if (!kmscon_conf.debug && !kmscon_conf.verbose && kmscon_conf.silent)
|
||||
if (!conf->debug && !conf->verbose && conf->silent)
|
||||
log_set_config(&LOG_CONFIG_WARNING(0, 0, 0, 0));
|
||||
else
|
||||
log_set_config(&LOG_CONFIG_INFO(kmscon_conf.debug,
|
||||
kmscon_conf.verbose));
|
||||
log_set_config(&LOG_CONFIG_INFO(conf->debug,
|
||||
conf->verbose));
|
||||
|
||||
log_print_init("kmscon");
|
||||
|
||||
|
@ -129,9 +129,7 @@ struct kmscon_conf_t {
|
||||
unsigned int font_ppi;
|
||||
};
|
||||
|
||||
extern struct kmscon_conf_t kmscon_conf;
|
||||
|
||||
int kmscon_conf_new(struct conf_ctx **out, struct kmscon_conf_t *conf);
|
||||
int kmscon_conf_new(struct conf_ctx **out);
|
||||
void kmscon_conf_free(struct conf_ctx *ctx);
|
||||
int kmscon_conf_load_main(struct conf_ctx *ctx, int argc, char **argv);
|
||||
int kmscon_conf_load_seat(struct conf_ctx *ctx, const struct conf_ctx *main,
|
||||
|
@ -62,7 +62,8 @@ struct app_seat {
|
||||
};
|
||||
|
||||
struct kmscon_app {
|
||||
struct conf_ctx *conf;
|
||||
struct conf_ctx *conf_ctx;
|
||||
struct kmscon_conf_t *conf;
|
||||
|
||||
struct ev_eloop *eloop;
|
||||
struct ev_eloop *vt_eloop;
|
||||
@ -117,11 +118,11 @@ static int app_seat_new(struct kmscon_app *app, struct app_seat **out,
|
||||
bool found;
|
||||
|
||||
found = false;
|
||||
if (kmscon_conf.all_seats) {
|
||||
if (app->conf->all_seats) {
|
||||
found = true;
|
||||
} else {
|
||||
for (i = 0; kmscon_conf.seats[i]; ++i) {
|
||||
if (!strcmp(kmscon_conf.seats[i], sname)) {
|
||||
for (i = 0; app->conf->seats[i]; ++i) {
|
||||
if (!strcmp(app->conf->seats[i], sname)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@ -152,7 +153,7 @@ static int app_seat_new(struct kmscon_app *app, struct app_seat **out,
|
||||
goto err_free;
|
||||
}
|
||||
|
||||
ret = kmscon_seat_new(&seat->seat, app->conf, app->eloop, app->vtm,
|
||||
ret = kmscon_seat_new(&seat->seat, app->conf_ctx, app->eloop, app->vtm,
|
||||
sname, app_seat_event, seat);
|
||||
if (ret) {
|
||||
log_error("cannot create seat object on seat %s: %d",
|
||||
@ -404,11 +405,10 @@ static void destroy_app(struct kmscon_app *app)
|
||||
ev_eloop_unref(app->eloop);
|
||||
}
|
||||
|
||||
static int setup_app(struct kmscon_app *app, struct conf_ctx *conf)
|
||||
static int setup_app(struct kmscon_app *app)
|
||||
{
|
||||
int ret;
|
||||
|
||||
app->conf = conf;
|
||||
shl_dlist_init(&app->seats);
|
||||
|
||||
ret = ev_eloop_new(&app->eloop, log_llog);
|
||||
@ -462,23 +462,25 @@ err_app:
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
struct conf_ctx *conf;
|
||||
struct conf_ctx *conf_ctx;
|
||||
struct kmscon_conf_t *conf;
|
||||
struct kmscon_app app;
|
||||
|
||||
ret = kmscon_conf_new(&conf, &kmscon_conf);
|
||||
ret = kmscon_conf_new(&conf_ctx);
|
||||
if (ret) {
|
||||
log_error("cannot create configuration: %d", ret);
|
||||
goto err_out;
|
||||
}
|
||||
conf = conf_ctx_get_mem(conf_ctx);
|
||||
|
||||
ret = kmscon_conf_load_main(conf, argc, argv);
|
||||
ret = kmscon_conf_load_main(conf_ctx, argc, argv);
|
||||
if (ret) {
|
||||
log_error("cannot load configuration: %d", ret);
|
||||
goto err_conf;
|
||||
}
|
||||
|
||||
if (kmscon_conf.exit) {
|
||||
kmscon_conf_free(conf);
|
||||
if (conf->exit) {
|
||||
kmscon_conf_free(conf_ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -486,18 +488,21 @@ int main(int argc, char **argv)
|
||||
kmscon_text_load_all();
|
||||
|
||||
memset(&app, 0, sizeof(app));
|
||||
ret = setup_app(&app, conf);
|
||||
app.conf_ctx = conf_ctx;
|
||||
app.conf = conf;
|
||||
|
||||
ret = setup_app(&app);
|
||||
if (ret)
|
||||
goto err_unload;
|
||||
|
||||
if (kmscon_conf.switchvt) {
|
||||
if (app.conf->switchvt) {
|
||||
log_debug("activating VTs during startup");
|
||||
uterm_vt_master_activate_all(app.vtm);
|
||||
}
|
||||
|
||||
ev_eloop_run(app.eloop, -1);
|
||||
|
||||
if (kmscon_conf.switchvt) {
|
||||
if (app.conf->switchvt) {
|
||||
/* The VT subsystem needs to acknowledge the VT-leave so if it
|
||||
* returns -EINPROGRESS we need to wait for the VT-leave SIGUSR2
|
||||
* signal to arrive. Therefore, we use a separate eloop object
|
||||
@ -524,7 +529,7 @@ err_unload:
|
||||
kmscon_text_unload_all();
|
||||
kmscon_font_unload_all();
|
||||
err_conf:
|
||||
kmscon_conf_free(conf);
|
||||
kmscon_conf_free(conf_ctx);
|
||||
err_out:
|
||||
if (ret)
|
||||
log_err("cannot initialize kmscon, errno %d: %s",
|
||||
|
@ -67,8 +67,8 @@ struct kmscon_seat {
|
||||
struct ev_eloop *eloop;
|
||||
struct uterm_vt_master *vtm;
|
||||
|
||||
struct kmscon_conf_t conf;
|
||||
struct conf_ctx *conf_ctx;
|
||||
struct kmscon_conf_t *conf;
|
||||
|
||||
char *name;
|
||||
bool awake;
|
||||
@ -323,25 +323,25 @@ static void seat_input_event(struct uterm_input *input,
|
||||
if (ev->handled)
|
||||
return;
|
||||
|
||||
if (conf_grab_matches(kmscon_conf.grab_session_next,
|
||||
if (conf_grab_matches(seat->conf->grab_session_next,
|
||||
ev->mods, ev->num_syms, ev->keysyms)) {
|
||||
ev->handled = true;
|
||||
seat_activate_next(seat);
|
||||
return;
|
||||
}
|
||||
if (conf_grab_matches(kmscon_conf.grab_session_prev,
|
||||
if (conf_grab_matches(seat->conf->grab_session_prev,
|
||||
ev->mods, ev->num_syms, ev->keysyms)) {
|
||||
ev->handled = true;
|
||||
seat_activate_prev(seat);
|
||||
return;
|
||||
}
|
||||
if (conf_grab_matches(kmscon_conf.grab_session_close,
|
||||
if (conf_grab_matches(seat->conf->grab_session_close,
|
||||
ev->mods, ev->num_syms, ev->keysyms)) {
|
||||
ev->handled = true;
|
||||
kmscon_session_unregister(seat->cur_sess);
|
||||
return;
|
||||
}
|
||||
if (conf_grab_matches(kmscon_conf.grab_terminal_new,
|
||||
if (conf_grab_matches(seat->conf->grab_terminal_new,
|
||||
ev->mods, ev->num_syms, ev->keysyms)) {
|
||||
ev->handled = true;
|
||||
ret = kmscon_terminal_register(&s, seat);
|
||||
@ -390,11 +390,12 @@ int kmscon_seat_new(struct kmscon_seat **out,
|
||||
goto err_free;
|
||||
}
|
||||
|
||||
ret = kmscon_conf_new(&seat->conf_ctx, &seat->conf);
|
||||
ret = kmscon_conf_new(&seat->conf_ctx);
|
||||
if (ret) {
|
||||
log_error("cannot create seat configuration object: %d", ret);
|
||||
goto err_name;
|
||||
}
|
||||
seat->conf = conf_ctx_get_mem(seat->conf_ctx);
|
||||
|
||||
ret = kmscon_conf_load_seat(seat->conf_ctx, main_conf, seat->name);
|
||||
if (ret) {
|
||||
@ -404,11 +405,11 @@ int kmscon_seat_new(struct kmscon_seat **out,
|
||||
}
|
||||
|
||||
ret = uterm_input_new(&seat->input, seat->eloop,
|
||||
kmscon_conf.xkb_layout,
|
||||
kmscon_conf.xkb_variant,
|
||||
kmscon_conf.xkb_options,
|
||||
kmscon_conf.xkb_repeat_delay,
|
||||
kmscon_conf.xkb_repeat_rate);
|
||||
seat->conf->xkb_layout,
|
||||
seat->conf->xkb_variant,
|
||||
seat->conf->xkb_options,
|
||||
seat->conf->xkb_repeat_delay,
|
||||
seat->conf->xkb_repeat_rate);
|
||||
if (ret)
|
||||
goto err_conf;
|
||||
|
||||
@ -417,7 +418,7 @@ int kmscon_seat_new(struct kmscon_seat **out,
|
||||
goto err_input;
|
||||
|
||||
ret = uterm_vt_allocate(seat->vtm, &seat->vt, seat->name,
|
||||
seat->input, kmscon_conf.vt, seat_vt_event,
|
||||
seat->input, seat->conf->vt, seat_vt_event,
|
||||
seat);
|
||||
if (ret)
|
||||
goto err_input_cb;
|
||||
@ -589,10 +590,10 @@ int kmscon_seat_register_session(struct kmscon_seat *seat,
|
||||
if (!seat || !out)
|
||||
return -EINVAL;
|
||||
|
||||
if (kmscon_conf.session_max &&
|
||||
seat->session_count >= kmscon_conf.session_max) {
|
||||
if (seat->conf->session_max &&
|
||||
seat->session_count >= seat->conf->session_max) {
|
||||
log_warning("maximum number of sessions reached (%d), dropping new session",
|
||||
kmscon_conf.session_max);
|
||||
seat->conf->session_max);
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "conf.h"
|
||||
#include "eloop.h"
|
||||
#include "kmscon_conf.h"
|
||||
#include "kmscon_seat.h"
|
||||
@ -63,6 +64,8 @@ struct kmscon_terminal {
|
||||
bool opened;
|
||||
bool awake;
|
||||
|
||||
struct conf_ctx *conf_ctx;
|
||||
struct kmscon_conf_t *conf;
|
||||
struct kmscon_session *session;
|
||||
|
||||
struct shl_dlist screens;
|
||||
@ -192,9 +195,9 @@ static int add_display(struct kmscon_terminal *term, struct uterm_display *disp)
|
||||
struct kmscon_font_attr attr = { "", 0, 20, false, false, 0, 0 };
|
||||
const char *be;
|
||||
|
||||
attr.ppi = kmscon_conf.font_ppi;
|
||||
attr.points = kmscon_conf.font_size;
|
||||
strncpy(attr.name, kmscon_conf.font_name, KMSCON_FONT_MAX_NAME - 1);
|
||||
attr.ppi = term->conf->font_ppi;
|
||||
attr.points = term->conf->font_size;
|
||||
strncpy(attr.name, term->conf->font_name, KMSCON_FONT_MAX_NAME - 1);
|
||||
attr.name[KMSCON_FONT_MAX_NAME - 1] = 0;
|
||||
|
||||
shl_dlist_for_each(iter, &term->screens) {
|
||||
@ -217,15 +220,15 @@ static int add_display(struct kmscon_terminal *term, struct uterm_display *disp)
|
||||
goto err_free;
|
||||
}
|
||||
|
||||
ret = kmscon_font_find(&scr->font, &attr, kmscon_conf.font_engine);
|
||||
ret = kmscon_font_find(&scr->font, &attr, term->conf->font_engine);
|
||||
if (ret) {
|
||||
log_error("cannot create font");
|
||||
goto err_screen;
|
||||
}
|
||||
|
||||
ret = uterm_screen_use(scr->screen);
|
||||
if (kmscon_conf.render_engine)
|
||||
be = kmscon_conf.render_engine;
|
||||
if (term->conf->render_engine)
|
||||
be = term->conf->render_engine;
|
||||
else if (!ret)
|
||||
be = "gltex";
|
||||
else
|
||||
@ -322,28 +325,28 @@ static void input_event(struct uterm_input *input,
|
||||
if (!term->opened || !term->awake || ev->handled)
|
||||
return;
|
||||
|
||||
if (conf_grab_matches(kmscon_conf.grab_scroll_up,
|
||||
if (conf_grab_matches(term->conf->grab_scroll_up,
|
||||
ev->mods, ev->num_syms, ev->keysyms)) {
|
||||
tsm_screen_sb_up(term->console, 1);
|
||||
schedule_redraw(term);
|
||||
ev->handled = true;
|
||||
return;
|
||||
}
|
||||
if (conf_grab_matches(kmscon_conf.grab_scroll_down,
|
||||
if (conf_grab_matches(term->conf->grab_scroll_down,
|
||||
ev->mods, ev->num_syms, ev->keysyms)) {
|
||||
tsm_screen_sb_down(term->console, 1);
|
||||
schedule_redraw(term);
|
||||
ev->handled = true;
|
||||
return;
|
||||
}
|
||||
if (conf_grab_matches(kmscon_conf.grab_page_up,
|
||||
if (conf_grab_matches(term->conf->grab_page_up,
|
||||
ev->mods, ev->num_syms, ev->keysyms)) {
|
||||
tsm_screen_sb_page_up(term->console, 1);
|
||||
schedule_redraw(term);
|
||||
ev->handled = true;
|
||||
return;
|
||||
}
|
||||
if (conf_grab_matches(kmscon_conf.grab_page_down,
|
||||
if (conf_grab_matches(term->conf->grab_page_down,
|
||||
ev->mods, ev->num_syms, ev->keysyms)) {
|
||||
tsm_screen_sb_page_down(term->console, 1);
|
||||
schedule_redraw(term);
|
||||
@ -499,8 +502,11 @@ int kmscon_terminal_register(struct kmscon_session **out,
|
||||
term->input = kmscon_seat_get_input(seat);
|
||||
shl_dlist_init(&term->screens);
|
||||
|
||||
if (kmscon_conf.fps) {
|
||||
fps = 1000000000ULL / kmscon_conf.fps;
|
||||
term->conf_ctx = kmscon_seat_get_conf(seat);
|
||||
term->conf = conf_ctx_get_mem(term->conf_ctx);
|
||||
|
||||
if (term->conf->fps) {
|
||||
fps = 1000000000ULL / term->conf->fps;
|
||||
if (fps == 0)
|
||||
fps = 1000000000ULL / 100;
|
||||
else if (fps > 200000000ULL)
|
||||
@ -515,8 +521,8 @@ int kmscon_terminal_register(struct kmscon_session **out,
|
||||
ret = tsm_screen_new(&term->console, log_llog);
|
||||
if (ret)
|
||||
goto err_free;
|
||||
tsm_screen_set_max_sb(term->console, kmscon_conf.sb_size);
|
||||
if (kmscon_conf.render_timing)
|
||||
tsm_screen_set_max_sb(term->console, term->conf->sb_size);
|
||||
if (term->conf->render_timing)
|
||||
tsm_screen_set_opts(term->console,
|
||||
TSM_SCREEN_OPT_RENDER_TIMING);
|
||||
|
||||
@ -524,17 +530,17 @@ int kmscon_terminal_register(struct kmscon_session **out,
|
||||
log_llog);
|
||||
if (ret)
|
||||
goto err_con;
|
||||
tsm_vte_set_palette(term->vte, kmscon_conf.palette);
|
||||
tsm_vte_set_palette(term->vte, term->conf->palette);
|
||||
|
||||
ret = kmscon_pty_new(&term->pty, pty_input, term);
|
||||
if (ret)
|
||||
goto err_vte;
|
||||
|
||||
ret = kmscon_pty_set_term(term->pty, kmscon_conf.term);
|
||||
ret = kmscon_pty_set_term(term->pty, term->conf->term);
|
||||
if (ret)
|
||||
goto err_pty;
|
||||
|
||||
ret = kmscon_pty_set_argv(term->pty, kmscon_conf.argv);
|
||||
ret = kmscon_pty_set_argv(term->pty, term->conf->argv);
|
||||
if (ret)
|
||||
goto err_pty;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user