Adjust all code to use new kmscon_symbol_t
This is a big performance boost and reduces the code size quite a bit. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
4eca3ef714
commit
a7128cc683
@ -48,9 +48,11 @@
|
||||
|
||||
#include "console.h"
|
||||
#include "log.h"
|
||||
#include "unicode.h"
|
||||
|
||||
struct kmscon_console {
|
||||
size_t ref;
|
||||
struct kmscon_symbol_table *st;
|
||||
|
||||
/* GL texture and font */
|
||||
GLuint tex;
|
||||
@ -146,7 +148,8 @@ err_free:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int kmscon_console_new(struct kmscon_console **out)
|
||||
int kmscon_console_new(struct kmscon_console **out,
|
||||
struct kmscon_symbol_table *st)
|
||||
{
|
||||
struct kmscon_console *con;
|
||||
int ret;
|
||||
@ -160,6 +163,7 @@ int kmscon_console_new(struct kmscon_console **out)
|
||||
|
||||
memset(con, 0, sizeof(*con));
|
||||
con->ref = 1;
|
||||
con->st = st;
|
||||
log_debug("console: new console\n");
|
||||
|
||||
ret = kmscon_buffer_new(&con->cells, 0, 0);
|
||||
@ -169,7 +173,9 @@ int kmscon_console_new(struct kmscon_console **out)
|
||||
con->cells_x = kmscon_buffer_get_width(con->cells);
|
||||
con->cells_y = kmscon_buffer_get_height(con->cells);
|
||||
|
||||
kmscon_symbol_table_ref(con->st);
|
||||
*out = con;
|
||||
|
||||
return 0;
|
||||
|
||||
err_free:
|
||||
@ -200,6 +206,7 @@ void kmscon_console_unref(struct kmscon_console *con)
|
||||
kmscon_console_free_res(con);
|
||||
kmscon_font_unref(con->font);
|
||||
kmscon_buffer_unref(con->cells);
|
||||
kmscon_symbol_table_unref(con->st);
|
||||
free(con);
|
||||
log_debug("console: destroing console\n");
|
||||
}
|
||||
@ -272,7 +279,7 @@ int kmscon_console_resize(struct kmscon_console *con, unsigned int x,
|
||||
if (con->cursor_y > con->cells_y)
|
||||
con->cursor_y = con->cells_y;
|
||||
|
||||
ret = kmscon_font_new(&font, height / con->cells_y);
|
||||
ret = kmscon_font_new(&font, height / con->cells_y, con->st);
|
||||
if (ret) {
|
||||
log_err("console: cannot create new font: %d\n", ret);
|
||||
return ret;
|
||||
@ -362,8 +369,7 @@ void kmscon_console_map(struct kmscon_console *con)
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void kmscon_console_write(struct kmscon_console *con,
|
||||
const struct kmscon_char *ch)
|
||||
void kmscon_console_write(struct kmscon_console *con, kmscon_symbol_t ch)
|
||||
{
|
||||
if (!con)
|
||||
return;
|
||||
|
@ -37,6 +37,7 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include "unicode.h"
|
||||
|
||||
struct kmscon_char;
|
||||
struct kmscon_font;
|
||||
@ -63,13 +64,14 @@ int kmscon_char_append_u8(struct kmscon_char *ch, const char *str, size_t len);
|
||||
|
||||
/* font objects with cached glyphs */
|
||||
|
||||
int kmscon_font_new(struct kmscon_font **out, unsigned int height);
|
||||
int kmscon_font_new(struct kmscon_font **out, unsigned int height,
|
||||
struct kmscon_symbol_table *st);
|
||||
void kmscon_font_ref(struct kmscon_font *font);
|
||||
void kmscon_font_unref(struct kmscon_font *font);
|
||||
|
||||
unsigned int kmscon_font_get_height(struct kmscon_font *font);
|
||||
unsigned int kmscon_font_get_width(struct kmscon_font *font);
|
||||
int kmscon_font_draw(struct kmscon_font *font, const struct kmscon_char *ch,
|
||||
int kmscon_font_draw(struct kmscon_font *font, kmscon_symbol_t ch,
|
||||
void *dcr, uint32_t x, uint32_t y);
|
||||
|
||||
/* console buffer with cell objects */
|
||||
@ -87,14 +89,15 @@ void kmscon_buffer_draw(struct kmscon_buffer *buf, struct kmscon_font *font,
|
||||
unsigned int kmscon_buffer_get_width(struct kmscon_buffer *buf);
|
||||
unsigned int kmscon_buffer_get_height(struct kmscon_buffer *buf);
|
||||
void kmscon_buffer_write(struct kmscon_buffer *buf, unsigned int x,
|
||||
unsigned int y, const struct kmscon_char *ch);
|
||||
void kmscon_buffer_read(struct kmscon_buffer *buf, unsigned int x,
|
||||
unsigned int y, struct kmscon_char *ch);
|
||||
unsigned int y, kmscon_symbol_t ch);
|
||||
kmscon_symbol_t kmscon_buffer_read(struct kmscon_buffer *buf, unsigned int x,
|
||||
unsigned int y);
|
||||
void kmscon_buffer_rotate(struct kmscon_buffer *buf);
|
||||
|
||||
/* console objects */
|
||||
|
||||
int kmscon_console_new(struct kmscon_console **out);
|
||||
int kmscon_console_new(struct kmscon_console **out,
|
||||
struct kmscon_symbol_table *st);
|
||||
void kmscon_console_ref(struct kmscon_console *con);
|
||||
void kmscon_console_unref(struct kmscon_console *con);
|
||||
|
||||
@ -106,6 +109,5 @@ int kmscon_console_resize(struct kmscon_console *con, unsigned int x,
|
||||
void kmscon_console_draw(struct kmscon_console *con);
|
||||
void kmscon_console_map(struct kmscon_console *con);
|
||||
|
||||
void kmscon_console_write(struct kmscon_console *con,
|
||||
const struct kmscon_char *ch);
|
||||
void kmscon_console_write(struct kmscon_console *con, kmscon_symbol_t ch);
|
||||
void kmscon_console_newline(struct kmscon_console *con);
|
||||
|
@ -84,13 +84,14 @@
|
||||
|
||||
#include "console.h"
|
||||
#include "log.h"
|
||||
#include "unicode.h"
|
||||
|
||||
#define DEFAULT_WIDTH 80
|
||||
#define DEFAULT_HEIGHT 24
|
||||
#define DEFAULT_SCROLLBACK 128
|
||||
|
||||
struct cell {
|
||||
struct kmscon_char *ch;
|
||||
kmscon_symbol_t ch;
|
||||
};
|
||||
|
||||
struct line {
|
||||
@ -121,8 +122,6 @@ static void destroy_cell(struct cell *cell)
|
||||
{
|
||||
if (!cell)
|
||||
return;
|
||||
|
||||
kmscon_char_free(cell->ch);
|
||||
}
|
||||
|
||||
static int init_cell(struct cell *cell)
|
||||
@ -131,8 +130,7 @@ static int init_cell(struct cell *cell)
|
||||
return -EINVAL;
|
||||
|
||||
memset(cell, 0, sizeof(*cell));
|
||||
|
||||
return kmscon_char_new(&cell->ch);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void free_line(struct line *line)
|
||||
@ -487,12 +485,12 @@ unsigned int kmscon_buffer_get_height(struct kmscon_buffer *buf)
|
||||
}
|
||||
|
||||
void kmscon_buffer_write(struct kmscon_buffer *buf, unsigned int x,
|
||||
unsigned int y, const struct kmscon_char *ch)
|
||||
unsigned int y, kmscon_symbol_t ch)
|
||||
{
|
||||
struct line *line;
|
||||
int ret;
|
||||
|
||||
if (!buf || !ch)
|
||||
if (!buf)
|
||||
return;
|
||||
|
||||
if (x >= buf->size_x || y >= buf->size_y) {
|
||||
@ -523,42 +521,30 @@ void kmscon_buffer_write(struct kmscon_buffer *buf, unsigned int x,
|
||||
}
|
||||
}
|
||||
|
||||
ret = kmscon_char_set(line->cells[x].ch, ch);
|
||||
if (ret) {
|
||||
log_warning("console: cannot copy character (%d); "
|
||||
"dropping input\n", ret);
|
||||
return;
|
||||
}
|
||||
line->cells[x].ch = ch;
|
||||
}
|
||||
|
||||
void kmscon_buffer_read(struct kmscon_buffer *buf, unsigned int x,
|
||||
unsigned int y, struct kmscon_char *ch)
|
||||
kmscon_symbol_t kmscon_buffer_read(struct kmscon_buffer *buf, unsigned int x,
|
||||
unsigned int y)
|
||||
{
|
||||
struct line *line;
|
||||
|
||||
if (!ch)
|
||||
return;
|
||||
|
||||
if (!buf)
|
||||
goto err_out;
|
||||
return kmscon_symbol_default;
|
||||
|
||||
if (x >= buf->size_x || y >= buf->size_y) {
|
||||
log_warning("console: reading out of buffer bounds\n");
|
||||
goto err_out;
|
||||
return kmscon_symbol_default;
|
||||
}
|
||||
|
||||
line = buf->current[y];
|
||||
if (!line)
|
||||
goto err_out;
|
||||
return kmscon_symbol_default;
|
||||
|
||||
if (x >= line->size)
|
||||
goto err_out;
|
||||
return kmscon_symbol_default;
|
||||
|
||||
kmscon_char_set(ch, line->cells[x].ch);
|
||||
return;
|
||||
|
||||
err_out:
|
||||
kmscon_char_reset(ch);
|
||||
return line->cells[x].ch;
|
||||
}
|
||||
|
||||
void kmscon_buffer_rotate(struct kmscon_buffer *buf)
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include <pango/pangocairo.h>
|
||||
#include "console.h"
|
||||
#include "log.h"
|
||||
#include "unicode.h"
|
||||
|
||||
/* maximum size of a single character */
|
||||
#define KMSCON_CHAR_SIZE 6
|
||||
@ -69,7 +70,7 @@ enum glyph_type {
|
||||
|
||||
struct kmscon_glyph {
|
||||
size_t ref;
|
||||
struct kmscon_char *ch;
|
||||
kmscon_symbol_t ch;
|
||||
unsigned int width;
|
||||
|
||||
int type;
|
||||
@ -88,6 +89,7 @@ struct kmscon_glyph {
|
||||
|
||||
struct kmscon_font {
|
||||
size_t ref;
|
||||
struct kmscon_symbol_table *st;
|
||||
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
@ -95,8 +97,8 @@ struct kmscon_font {
|
||||
PangoContext *ctx;
|
||||
};
|
||||
|
||||
static int kmscon_font_lookup(struct kmscon_font *font,
|
||||
const struct kmscon_char *key, struct kmscon_glyph **out);
|
||||
static int kmscon_font_lookup(struct kmscon_font *font, kmscon_symbol_t key,
|
||||
struct kmscon_glyph **out);
|
||||
|
||||
static int new_char(struct kmscon_char **out, size_t size)
|
||||
{
|
||||
@ -322,34 +324,6 @@ int kmscon_char_append_u8(struct kmscon_char *ch, const char *str, size_t len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a hash for a kmscon_char. This uses a simple hash technique described
|
||||
* by Daniel J. Bernstein.
|
||||
*/
|
||||
static guint kmscon_char_hash(gconstpointer key)
|
||||
{
|
||||
guint val = 5381;
|
||||
size_t i;
|
||||
const struct kmscon_char *ch = (void*)key;
|
||||
|
||||
for (i = 0; i < ch->len; ++i)
|
||||
val = val * 33 + ch->buf[i];
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/* compare two kmscon_char for equality */
|
||||
static gboolean kmscon_char_equal(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
const struct kmscon_char *ch1 = (void*)a;
|
||||
const struct kmscon_char *ch2 = (void*)b;
|
||||
|
||||
if (ch1->len != ch2->len)
|
||||
return FALSE;
|
||||
|
||||
return (memcmp(ch1->buf, ch2->buf, ch1->len) == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Glyphs
|
||||
* Glyphs are for internal use only! The outside world uses kmscon_char
|
||||
@ -369,31 +343,24 @@ static gboolean kmscon_char_equal(gconstpointer a, gconstpointer b)
|
||||
* any text you want. It uses a PangoLayout internally and recalculates the
|
||||
* character sizes each time we draw them.
|
||||
*/
|
||||
static int kmscon_glyph_new(struct kmscon_glyph **out,
|
||||
const struct kmscon_char *ch)
|
||||
static int kmscon_glyph_new(struct kmscon_glyph **out, kmscon_symbol_t ch)
|
||||
{
|
||||
struct kmscon_glyph *glyph;
|
||||
int ret;
|
||||
|
||||
if (!out || !ch || !ch->len)
|
||||
if (!out)
|
||||
return -EINVAL;
|
||||
|
||||
glyph = malloc(sizeof(*glyph));
|
||||
if (!glyph)
|
||||
return -ENOMEM;
|
||||
|
||||
memset(glyph, 0, sizeof(*glyph));
|
||||
glyph->ref = 1;
|
||||
glyph->type = GLYPH_NONE;
|
||||
|
||||
ret = kmscon_char_dup(&glyph->ch, ch);
|
||||
if (ret)
|
||||
goto err_free;
|
||||
glyph->ch = ch;
|
||||
|
||||
*out = glyph;
|
||||
return 0;
|
||||
|
||||
err_free:
|
||||
free(glyph);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -436,7 +403,6 @@ static void kmscon_glyph_unref(struct kmscon_glyph *glyph)
|
||||
return;
|
||||
|
||||
kmscon_glyph_reset(glyph);
|
||||
kmscon_char_free(glyph->ch);
|
||||
free(glyph);
|
||||
}
|
||||
|
||||
@ -454,6 +420,8 @@ static int kmscon_glyph_set(struct kmscon_glyph *glyph,
|
||||
PangoGlyphItem *tmp;
|
||||
PangoGlyphString *str;
|
||||
PangoRectangle rec;
|
||||
size_t len;
|
||||
const char *val;
|
||||
|
||||
if (!glyph || !font)
|
||||
return -EINVAL;
|
||||
@ -462,7 +430,10 @@ static int kmscon_glyph_set(struct kmscon_glyph *glyph,
|
||||
if (!layout)
|
||||
return -EINVAL;
|
||||
|
||||
pango_layout_set_text(layout, glyph->ch->buf, glyph->ch->len);
|
||||
val = kmscon_symbol_get_u8(font->st, glyph->ch, &len);
|
||||
pango_layout_set_text(layout, val, len);
|
||||
kmscon_symbol_free_u8(val);
|
||||
|
||||
pango_layout_get_extents(layout, NULL, &rec);
|
||||
line = pango_layout_get_line_readonly(layout, 0);
|
||||
|
||||
@ -505,23 +476,15 @@ static int measure_width(struct kmscon_font *font)
|
||||
{
|
||||
unsigned int i, num, width;
|
||||
int ret;
|
||||
struct kmscon_char *ch;
|
||||
char buf;
|
||||
kmscon_symbol_t ch;
|
||||
struct kmscon_glyph *glyph;
|
||||
|
||||
if (!font)
|
||||
return -EINVAL;
|
||||
|
||||
ret = kmscon_char_new(&ch);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
num = 0;
|
||||
for (i = 0; i < 127; ++i) {
|
||||
buf = i;
|
||||
ret = kmscon_char_set_u8(ch, &buf, 1);
|
||||
if (ret)
|
||||
continue;
|
||||
ch = kmscon_symbol_make(i);
|
||||
|
||||
ret = kmscon_font_lookup(font, ch, &glyph);
|
||||
if (ret)
|
||||
@ -535,8 +498,6 @@ static int measure_width(struct kmscon_font *font)
|
||||
kmscon_glyph_unref(glyph);
|
||||
}
|
||||
|
||||
kmscon_char_free(ch);
|
||||
|
||||
if (!num)
|
||||
return -EFAULT;
|
||||
|
||||
@ -551,7 +512,8 @@ static int measure_width(struct kmscon_font *font)
|
||||
* \height is the height in pixel that we have for each character.
|
||||
* Returns 0 on success and stores the new font in \out.
|
||||
*/
|
||||
int kmscon_font_new(struct kmscon_font **out, unsigned int height)
|
||||
int kmscon_font_new(struct kmscon_font **out, unsigned int height,
|
||||
struct kmscon_symbol_table *st)
|
||||
{
|
||||
struct kmscon_font *font;
|
||||
int ret;
|
||||
@ -570,6 +532,7 @@ int kmscon_font_new(struct kmscon_font **out, unsigned int height)
|
||||
return -ENOMEM;
|
||||
font->ref = 1;
|
||||
font->height = height;
|
||||
font->st = st;
|
||||
|
||||
map = pango_cairo_font_map_get_default();
|
||||
if (!map) {
|
||||
@ -614,9 +577,8 @@ int kmscon_font_new(struct kmscon_font **out, unsigned int height)
|
||||
cairo_font_options_destroy(opt);
|
||||
}
|
||||
|
||||
font->glyphs = g_hash_table_new_full(kmscon_char_hash,
|
||||
kmscon_char_equal, (GDestroyNotify) kmscon_char_free,
|
||||
(GDestroyNotify) kmscon_glyph_unref);
|
||||
font->glyphs = g_hash_table_new_full(g_direct_hash, g_direct_equal,
|
||||
NULL, (GDestroyNotify) kmscon_glyph_unref);
|
||||
if (!font->glyphs) {
|
||||
ret = -ENOMEM;
|
||||
goto err_ctx;
|
||||
@ -626,7 +588,9 @@ int kmscon_font_new(struct kmscon_font **out, unsigned int height)
|
||||
if (ret)
|
||||
goto err_hash;
|
||||
|
||||
kmscon_symbol_table_ref(font->st);
|
||||
*out = font;
|
||||
|
||||
return 0;
|
||||
|
||||
err_hash:
|
||||
@ -656,6 +620,7 @@ void kmscon_font_unref(struct kmscon_font *font)
|
||||
|
||||
g_hash_table_unref(font->glyphs);
|
||||
g_object_unref(font->ctx);
|
||||
kmscon_symbol_table_unref(font->st);
|
||||
free(font);
|
||||
log_debug("font: destroying font\n");
|
||||
}
|
||||
@ -682,30 +647,25 @@ unsigned int kmscon_font_get_height(struct kmscon_font *font)
|
||||
* Returns 0 on success and stores the glyph with a new reference in \out.
|
||||
*/
|
||||
static int kmscon_font_lookup(struct kmscon_font *font,
|
||||
const struct kmscon_char *key, struct kmscon_glyph **out)
|
||||
kmscon_symbol_t key, struct kmscon_glyph **out)
|
||||
{
|
||||
struct kmscon_glyph *glyph;
|
||||
struct kmscon_char *ch;
|
||||
int ret;
|
||||
|
||||
if (!font || !key || !out)
|
||||
if (!font || !out)
|
||||
return -EINVAL;
|
||||
|
||||
glyph = g_hash_table_lookup(font->glyphs, key);
|
||||
glyph = g_hash_table_lookup(font->glyphs, GUINT_TO_POINTER(key));
|
||||
if (!glyph) {
|
||||
ret = kmscon_char_dup(&ch, key);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = kmscon_glyph_new(&glyph, key);
|
||||
if (ret)
|
||||
goto err_char;
|
||||
return ret;
|
||||
|
||||
ret = kmscon_glyph_set(glyph, font);
|
||||
if (ret)
|
||||
goto err_glyph;
|
||||
|
||||
g_hash_table_insert(font->glyphs, ch, glyph);
|
||||
g_hash_table_insert(font->glyphs, GUINT_TO_POINTER(key), glyph);
|
||||
}
|
||||
|
||||
kmscon_glyph_ref(glyph);
|
||||
@ -714,8 +674,6 @@ static int kmscon_font_lookup(struct kmscon_font *font,
|
||||
|
||||
err_glyph:
|
||||
kmscon_glyph_unref(glyph);
|
||||
err_char:
|
||||
kmscon_char_free(ch);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -724,8 +682,8 @@ err_char:
|
||||
* The glyph will be drawn with the upper-left corner at x/y.
|
||||
* Returns 0 on success.
|
||||
*/
|
||||
int kmscon_font_draw(struct kmscon_font *font, const struct kmscon_char *ch,
|
||||
void *dcr, uint32_t x, uint32_t y)
|
||||
int kmscon_font_draw(struct kmscon_font *font, kmscon_symbol_t ch, void *dcr,
|
||||
uint32_t x, uint32_t y)
|
||||
{
|
||||
struct kmscon_glyph *glyph;
|
||||
int ret;
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "eloop.h"
|
||||
#include "log.h"
|
||||
#include "terminal.h"
|
||||
#include "unicode.h"
|
||||
#include "vte.h"
|
||||
|
||||
struct term_out {
|
||||
@ -105,24 +106,18 @@ static const char help_text[] =
|
||||
|
||||
static void print_help(struct kmscon_terminal *term)
|
||||
{
|
||||
int ret;
|
||||
unsigned int i, len;
|
||||
struct kmscon_char *ch;
|
||||
|
||||
ret = kmscon_char_new_u8(&ch, NULL, 0);
|
||||
if (ret)
|
||||
return;
|
||||
kmscon_symbol_t ch;
|
||||
|
||||
len = sizeof(help_text) - 1;
|
||||
for (i = 0; i < len; ++i) {
|
||||
kmscon_char_set_u8(ch, &help_text[i], 1);
|
||||
ch = kmscon_symbol_make(help_text[i]);
|
||||
kmscon_terminal_input(term, ch);
|
||||
}
|
||||
|
||||
kmscon_char_free(ch);
|
||||
}
|
||||
|
||||
int kmscon_terminal_new(struct kmscon_terminal **out)
|
||||
int kmscon_terminal_new(struct kmscon_terminal **out,
|
||||
struct kmscon_symbol_table *st)
|
||||
{
|
||||
struct kmscon_terminal *term;
|
||||
int ret;
|
||||
@ -143,7 +138,7 @@ int kmscon_terminal_new(struct kmscon_terminal **out)
|
||||
if (ret)
|
||||
goto err_free;
|
||||
|
||||
ret = kmscon_console_new(&term->console);
|
||||
ret = kmscon_console_new(&term->console, st);
|
||||
if (ret)
|
||||
goto err_idle;
|
||||
|
||||
@ -265,8 +260,7 @@ void kmscon_terminal_rm_all_outputs(struct kmscon_terminal *term)
|
||||
}
|
||||
}
|
||||
|
||||
void kmscon_terminal_input(struct kmscon_terminal *term,
|
||||
const struct kmscon_char *ch)
|
||||
void kmscon_terminal_input(struct kmscon_terminal *term, kmscon_symbol_t ch)
|
||||
{
|
||||
kmscon_vte_input(term->vte, ch);
|
||||
schedule_redraw(term);
|
||||
|
@ -36,10 +36,12 @@
|
||||
#include <stdlib.h>
|
||||
#include "console.h"
|
||||
#include "output.h"
|
||||
#include "unicode.h"
|
||||
|
||||
struct kmscon_terminal;
|
||||
|
||||
int kmscon_terminal_new(struct kmscon_terminal **out);
|
||||
int kmscon_terminal_new(struct kmscon_terminal **out,
|
||||
struct kmscon_symbol_table *st);
|
||||
void kmscon_terminal_ref(struct kmscon_terminal *term);
|
||||
void kmscon_terminal_unref(struct kmscon_terminal *term);
|
||||
|
||||
@ -51,7 +53,6 @@ int kmscon_terminal_add_output(struct kmscon_terminal *term,
|
||||
struct kmscon_output *output);
|
||||
void kmscon_terminal_rm_all_outputs(struct kmscon_terminal *term);
|
||||
|
||||
void kmscon_terminal_input(struct kmscon_terminal *term,
|
||||
const struct kmscon_char *ch);
|
||||
void kmscon_terminal_input(struct kmscon_terminal *term, kmscon_symbol_t ch);
|
||||
|
||||
#endif /* KMSCON_TERMINAL_H */
|
||||
|
26
src/vte.c
26
src/vte.c
@ -36,6 +36,7 @@
|
||||
|
||||
#include "console.h"
|
||||
#include "log.h"
|
||||
#include "unicode.h"
|
||||
#include "vte.h"
|
||||
|
||||
struct kmscon_vte {
|
||||
@ -94,28 +95,13 @@ void kmscon_vte_bind(struct kmscon_vte *vte, struct kmscon_console *con)
|
||||
kmscon_console_ref(vte->con);
|
||||
}
|
||||
|
||||
void kmscon_vte_input(struct kmscon_vte *vte, const struct kmscon_char *ch)
|
||||
void kmscon_vte_input(struct kmscon_vte *vte, kmscon_symbol_t ch)
|
||||
{
|
||||
size_t len;
|
||||
const char *val;
|
||||
|
||||
if (!vte || !vte->con)
|
||||
return;
|
||||
|
||||
len = kmscon_char_get_len(ch);
|
||||
val = kmscon_char_get_u8(ch);
|
||||
|
||||
if (len == 1) {
|
||||
if (*val == '\n')
|
||||
kmscon_console_newline(vte->con);
|
||||
else
|
||||
goto write_default;
|
||||
} else {
|
||||
goto write_default;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
write_default:
|
||||
kmscon_console_write(vte->con, ch);
|
||||
if (ch == '\n')
|
||||
kmscon_console_newline(vte->con);
|
||||
else
|
||||
kmscon_console_write(vte->con, ch);
|
||||
}
|
||||
|
@ -35,6 +35,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "console.h"
|
||||
#include "unicode.h"
|
||||
|
||||
struct kmscon_vte;
|
||||
|
||||
@ -43,6 +44,6 @@ void kmscon_vte_ref(struct kmscon_vte *vte);
|
||||
void kmscon_vte_unref(struct kmscon_vte *vte);
|
||||
|
||||
void kmscon_vte_bind(struct kmscon_vte *vte, struct kmscon_console *con);
|
||||
void kmscon_vte_input(struct kmscon_vte *vte, const struct kmscon_char *ch);
|
||||
void kmscon_vte_input(struct kmscon_vte *vte, kmscon_symbol_t ch);
|
||||
|
||||
#endif /* KMSCON_VTE_H */
|
||||
|
@ -45,15 +45,7 @@
|
||||
static void print_buf(struct kmscon_buffer *buf)
|
||||
{
|
||||
unsigned int width, height, x, y;
|
||||
struct kmscon_char *ch;
|
||||
int ret;
|
||||
const char *c;
|
||||
|
||||
ret = kmscon_char_new(&ch);
|
||||
if (ret) {
|
||||
log_warning("Cannot allocate character\n");
|
||||
return;
|
||||
}
|
||||
kmscon_symbol_t ch;
|
||||
|
||||
width = kmscon_buffer_get_width(buf);
|
||||
height = kmscon_buffer_get_height(buf);
|
||||
@ -68,9 +60,8 @@ static void print_buf(struct kmscon_buffer *buf)
|
||||
for (y = 0; y < height; ++y) {
|
||||
printf("x");
|
||||
for (x = 0; x < width; ++x) {
|
||||
kmscon_buffer_read(buf, x, y, ch);
|
||||
c = kmscon_char_get_u8(ch);
|
||||
printf("%c", c ? *c : ' ');
|
||||
ch = kmscon_buffer_read(buf, x, y);
|
||||
printf("%c", ch ? ch : ' ');
|
||||
}
|
||||
printf("x\n");
|
||||
}
|
||||
@ -79,22 +70,15 @@ static void print_buf(struct kmscon_buffer *buf)
|
||||
for (x = 0; x < width; ++x)
|
||||
printf("x");
|
||||
printf("x\n");
|
||||
|
||||
kmscon_char_free(ch);
|
||||
}
|
||||
|
||||
static void test1(struct kmscon_buffer *buf)
|
||||
{
|
||||
int ret;
|
||||
struct kmscon_char *ch;
|
||||
kmscon_symbol_t ch;
|
||||
|
||||
log_info("Test1:\n");
|
||||
|
||||
ret = kmscon_char_new_u8(&ch, "?", 1);
|
||||
if (ret) {
|
||||
log_err("Cannot create character\n");
|
||||
return;
|
||||
}
|
||||
ch = kmscon_symbol_make('?');
|
||||
|
||||
kmscon_buffer_write(buf, 0, 0, ch);
|
||||
kmscon_buffer_write(buf, 9, 2, ch);
|
||||
@ -109,8 +93,6 @@ static void test1(struct kmscon_buffer *buf)
|
||||
print_buf(buf);
|
||||
kmscon_buffer_rotate(buf);
|
||||
print_buf(buf);
|
||||
|
||||
kmscon_char_free(ch);
|
||||
}
|
||||
|
||||
static void test2()
|
||||
|
@ -57,6 +57,7 @@
|
||||
#include "eloop.h"
|
||||
#include "log.h"
|
||||
#include "output.h"
|
||||
#include "unicode.h"
|
||||
#include "vt.h"
|
||||
|
||||
static volatile sig_atomic_t terminate;
|
||||
@ -66,6 +67,7 @@ struct console {
|
||||
struct kmscon_signal *sig_term;
|
||||
struct kmscon_signal *sig_int;
|
||||
struct kmscon_fd *stdin_fd;
|
||||
struct kmscon_symbol_table *st;
|
||||
struct kmscon_compositor *comp;
|
||||
struct kmscon_vt *vt;
|
||||
struct kmscon_console *con;
|
||||
@ -81,7 +83,7 @@ static void stdin_cb(struct kmscon_fd *fd, int mask, void *data)
|
||||
char buf[512];
|
||||
int ret;
|
||||
unsigned int i, len;
|
||||
struct kmscon_char *ch;
|
||||
kmscon_symbol_t ch;
|
||||
|
||||
if (!con || !fd)
|
||||
return;
|
||||
@ -96,20 +98,14 @@ static void stdin_cb(struct kmscon_fd *fd, int mask, void *data)
|
||||
len = ret;
|
||||
log_debug("stdin input read (len: %d)\n", len);
|
||||
|
||||
ret = kmscon_char_new_u8(&ch, NULL, 0);
|
||||
if (ret)
|
||||
return;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
if (buf[i] == '\n') {
|
||||
kmscon_console_newline(con->con);
|
||||
} else {
|
||||
kmscon_char_set_u8(ch, &buf[i], 1);
|
||||
ch = buf[i];
|
||||
kmscon_console_write(con->con, ch);
|
||||
}
|
||||
}
|
||||
|
||||
kmscon_char_free(ch);
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,25 +218,18 @@ static const char help_text[] =
|
||||
|
||||
static void print_help(struct console *con)
|
||||
{
|
||||
int ret;
|
||||
unsigned int i, len;
|
||||
struct kmscon_char *ch;
|
||||
|
||||
ret = kmscon_char_new_u8(&ch, NULL, 0);
|
||||
if (ret)
|
||||
return;
|
||||
kmscon_symbol_t ch;
|
||||
|
||||
len = sizeof(help_text) - 1;
|
||||
for (i = 0; i < len; ++i) {
|
||||
if (help_text[i] == '\n') {
|
||||
kmscon_console_newline(con->con);
|
||||
} else {
|
||||
kmscon_char_set_u8(ch, &help_text[i], 1);
|
||||
ch = help_text[i];
|
||||
kmscon_console_write(con->con, ch);
|
||||
}
|
||||
}
|
||||
|
||||
kmscon_char_free(ch);
|
||||
}
|
||||
|
||||
static void destroy_eloop(struct console *con)
|
||||
@ -250,6 +239,7 @@ static void destroy_eloop(struct console *con)
|
||||
kmscon_console_unref(con->con);
|
||||
kmscon_compositor_unref(con->comp);
|
||||
kmscon_vt_unref(con->vt);
|
||||
kmscon_symbol_table_unref(con->st);
|
||||
kmscon_eloop_rm_fd(con->stdin_fd);
|
||||
kmscon_eloop_rm_signal(con->sig_int);
|
||||
kmscon_eloop_rm_signal(con->sig_term);
|
||||
@ -279,6 +269,10 @@ static int setup_eloop(struct console *con)
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
|
||||
ret = kmscon_symbol_table_new(&con->st);
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
|
||||
ret = kmscon_compositor_new(&con->comp);
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
@ -295,7 +289,7 @@ static int setup_eloop(struct console *con)
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
|
||||
ret = kmscon_console_new(&con->con);
|
||||
ret = kmscon_console_new(&con->con, con->st);
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
|
||||
|
@ -45,10 +45,10 @@
|
||||
#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_symbol_table *st;
|
||||
struct kmscon_compositor *comp;
|
||||
struct kmscon_input *input;
|
||||
struct kmscon_vt *vt;
|
||||
@ -66,18 +66,13 @@ static void read_input(struct kmscon_input *input,
|
||||
struct kmscon_input_event *ev, void *data)
|
||||
{
|
||||
struct app *app = data;
|
||||
int ret;
|
||||
kmscon_symbol_t ch;
|
||||
|
||||
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);
|
||||
ch = kmscon_symbol_make(ev->unicode);
|
||||
kmscon_terminal_input(app->term, ch);
|
||||
}
|
||||
|
||||
static void activate_outputs(struct app *app)
|
||||
@ -133,20 +128,16 @@ static void destroy_app(struct app *app)
|
||||
kmscon_vt_unref(app->vt);
|
||||
kmscon_input_unref(app->input);
|
||||
kmscon_compositor_unref(app->comp);
|
||||
kmscon_symbol_table_unref(app->st);
|
||||
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;
|
||||
@ -161,6 +152,10 @@ static int setup_app(struct app *app)
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
|
||||
ret = kmscon_symbol_table_new(&app->st);
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
|
||||
ret = kmscon_compositor_new(&app->comp);
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
@ -181,7 +176,7 @@ static int setup_app(struct app *app)
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
|
||||
ret = kmscon_terminal_new(&app->term);
|
||||
ret = kmscon_terminal_new(&app->term, app->st);
|
||||
if (ret)
|
||||
goto err_loop;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user