test_terminal: add experimental input support
Add input subsystem to terminal test app. This currently allows to actually "write" to the console. There is still much to do to convert the input to proper data but basic alphanumeric characters work for now. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
af9ab4197c
commit
117d7ddbcd
@ -38,16 +38,19 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "eloop.h"
|
||||
#include "input.h"
|
||||
#include "log.h"
|
||||
#include "output.h"
|
||||
#include "terminal.h"
|
||||
#include "vt.h"
|
||||
|
||||
struct app {
|
||||
struct kmscon_char *ch;
|
||||
struct kmscon_eloop *eloop;
|
||||
struct kmscon_signal *sig_term;
|
||||
struct kmscon_signal *sig_int;
|
||||
struct kmscon_compositor *comp;
|
||||
struct kmscon_input *input;
|
||||
struct kmscon_vt *vt;
|
||||
struct kmscon_terminal *term;
|
||||
};
|
||||
@ -59,6 +62,24 @@ static void sig_term(struct kmscon_signal *sig, int signum, void *data)
|
||||
terminate = 1;
|
||||
}
|
||||
|
||||
static void read_input(struct kmscon_input *input,
|
||||
struct kmscon_input_event *ev, void *data)
|
||||
{
|
||||
struct app *app = data;
|
||||
int ret;
|
||||
|
||||
if (ev->unicode == KMSCON_INPUT_INVALID)
|
||||
return;
|
||||
|
||||
ret = kmscon_char_set_ucs4(app->ch, &ev->unicode, 1);
|
||||
if (ret) {
|
||||
log_warning("Cannot convert UCS4 to UTF8\n");
|
||||
return;
|
||||
}
|
||||
|
||||
kmscon_terminal_input(app->term, app->ch);
|
||||
}
|
||||
|
||||
static void activate_outputs(struct app *app)
|
||||
{
|
||||
struct kmscon_output *iter;
|
||||
@ -95,7 +116,10 @@ static bool vt_switch(struct kmscon_vt *vt, int action, void *data)
|
||||
log_info("test: running without active outputs\n");
|
||||
else if (ret > 0)
|
||||
activate_outputs(app);
|
||||
|
||||
kmscon_input_wake_up(app->input);
|
||||
} else if (action == KMSCON_VT_LEAVE) {
|
||||
kmscon_input_sleep(app->input);
|
||||
kmscon_terminal_rm_all_outputs(app->term);
|
||||
kmscon_compositor_sleep(app->comp);
|
||||
}
|
||||
@ -107,16 +131,22 @@ static void destroy_app(struct app *app)
|
||||
{
|
||||
kmscon_terminal_unref(app->term);
|
||||
kmscon_vt_unref(app->vt);
|
||||
kmscon_input_unref(app->input);
|
||||
kmscon_compositor_unref(app->comp);
|
||||
kmscon_eloop_rm_signal(app->sig_int);
|
||||
kmscon_eloop_rm_signal(app->sig_term);
|
||||
kmscon_eloop_unref(app->eloop);
|
||||
kmscon_char_free(app->ch);
|
||||
}
|
||||
|
||||
static int setup_app(struct app *app)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = kmscon_char_new(&app->ch);
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
|
||||
ret = kmscon_eloop_new(&app->eloop);
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
@ -139,6 +169,10 @@ static int setup_app(struct app *app)
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
|
||||
ret = kmscon_input_new(&app->input);
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
|
||||
ret = kmscon_vt_new(&app->vt, vt_switch, app);
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
@ -155,6 +189,11 @@ static int setup_app(struct app *app)
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
|
||||
ret = kmscon_input_connect_eloop(app->input, app->eloop, read_input,
|
||||
app);
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
|
||||
return 0;
|
||||
|
||||
err_loop:
|
||||
|
Loading…
x
Reference in New Issue
Block a user