aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2020-02-27 22:56:11 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2020-02-27 22:56:11 +0100
commita424316456d661bf0d588ff6ddf31f3e35a9374b (patch)
tree6aeeb0d1b6df1d341ebd159e6646531ee2b4e568
parent455e12dd72806a7ae0fccb41ebe538727c374323 (diff)
parentde04cad026d0979f5f4a00fe6b359d7698776d65 (diff)
downloadd2tk.lv2-a424316456d661bf0d588ff6ddf31f3e35a9374b.tar.xz
Merge commit 'de04cad026d0979f5f4a00fe6b359d7698776d65'
-rw-r--r--subprojects/d2tk/.gitlab-ci.yml20
-rw-r--r--subprojects/d2tk/VERSION2
-rwxr-xr-xsubprojects/d2tk/check_for_font3
-rw-r--r--subprojects/d2tk/d2tk/base.h76
-rw-r--r--subprojects/d2tk/d2tk/config.h.in1
-rw-r--r--subprojects/d2tk/d2tk/core.h1
-rw-r--r--subprojects/d2tk/example/d2tk_fbdev.c21
-rw-r--r--subprojects/d2tk/example/example.c681
-rw-r--r--subprojects/d2tk/linenoise/.gitignore3
-rw-r--r--subprojects/d2tk/linenoise/LICENSE25
-rw-r--r--subprojects/d2tk/linenoise/Makefile7
-rw-r--r--subprojects/d2tk/linenoise/README.markdown229
-rw-r--r--subprojects/d2tk/linenoise/example.c74
-rw-r--r--subprojects/d2tk/linenoise/linenoise.c1201
-rw-r--r--subprojects/d2tk/linenoise/linenoise.h73
-rw-r--r--subprojects/d2tk/meson.build351
-rw-r--r--subprojects/d2tk/meson_options.txt44
-rw-r--r--subprojects/d2tk/src/backend_cairo.c18
-rw-r--r--subprojects/d2tk/src/backend_nanovg.c7
-rw-r--r--subprojects/d2tk/src/base.c86
-rw-r--r--subprojects/d2tk/src/base_bar.c135
-rw-r--r--subprojects/d2tk/src/base_button.c17
-rw-r--r--subprojects/d2tk/src/base_internal.h8
-rw-r--r--subprojects/d2tk/src/base_pty.c190
-rw-r--r--subprojects/d2tk/src/base_spinner.c102
-rw-r--r--subprojects/d2tk/src/base_vkb.c621
-rw-r--r--subprojects/d2tk/src/core.c47
-rw-r--r--subprojects/d2tk/src/core_internal.h4
-rw-r--r--subprojects/d2tk/src/frontend_fbdev.c2
-rw-r--r--subprojects/d2tk/ttf/FiraMono-Bold.ttfbin206548 -> 0 bytes
-rw-r--r--subprojects/d2tk/ttf/LICENSE93
31 files changed, 1682 insertions, 2460 deletions
diff --git a/subprojects/d2tk/.gitlab-ci.yml b/subprojects/d2tk/.gitlab-ci.yml
index 42bea53..8627344 100644
--- a/subprojects/d2tk/.gitlab-ci.yml
+++ b/subprojects/d2tk/.gitlab-ci.yml
@@ -2,6 +2,7 @@ stages:
- build
- deploy
+# templates
.variables_template: &variables_definition
variables:
BASE_NAME: "d2tk"
@@ -17,6 +18,7 @@ stages:
.build_template: &build_definition
<<: *common_definition
+ stage: build
script:
- meson --prefix="/" --libdir="lib" --cross-file "${CI_BUILD_NAME}" build
- sed -i -e '/framework/s/-Wl,-O1//g' -e '/framework/s/-Wl,--start-group//g' -e '/framework/s/-Wl,--end-group//g' build/build.ninja
@@ -25,21 +27,26 @@ stages:
.test_template: &test_definition
<<: *common_definition
+ stage: build
script:
- meson --prefix="/" --libdir="lib" --cross-file "${CI_BUILD_NAME}" build
- sed -i -e '/framework/s/-Wl,-O1//g' -e '/framework/s/-Wl,--start-group//g' -e '/framework/s/-Wl,--end-group//g' build/build.ninja
- ninja -C build
- DESTDIR="${CI_PROJECT_DIR}/${BASE_NAME}-$(cat VERSION)/${CI_BUILD_NAME}" ninja -C build install
- - ninja -C build test
+
+ - meson test -C build
.analyze_template: &analyze_definition
<<: *common_definition
+ stage: build
script:
- meson --prefix="/" --libdir="lib" --cross-file "${CI_BUILD_NAME}" build
- sed -i -e '/framework/s/-Wl,-O1//g' -e '/framework/s/-Wl,--start-group//g' -e '/framework/s/-Wl,--end-group//g' build/build.ninja
- ninja -C build
- DESTDIR="${CI_PROJECT_DIR}/${BASE_NAME}-$(cat VERSION)/${CI_BUILD_NAME}" ninja -C build install
- - ninja -C build test
+
+ - meson test -C build
+ - meson test -C build --wrap=valgrind
- CC=clang CXX=clang++ meson --prefix="/" --libdir="lib" --cross-file "${CI_BUILD_NAME}" clang
- ninja -C clang
@@ -50,22 +57,22 @@ stages:
- scan-build --status-bugs ninja -C scanbuild test
.universal_linux_template: &universal_linux_definition
- image: ventosus/universal-linux-gnu
+ image: ventosus/universal-linux-gnu:buster
<<: *analyze_definition
.arm_linux_template: &arm_linux_definition
- image: ventosus/arm-linux-gnueabihf
+ image: ventosus/arm-linux-gnueabihf:buster
<<: *test_definition
.universal_w64_template: &universal_w64_definition
image: ventosus/universal-w64-mingw32
- <<: *build_definition
+ <<: *test_definition
.universal_apple_template: &universal_apple_definition
image: ventosus/universal-apple-darwin
<<: *build_definition
-# building in docker
+# targets
x86_64-linux-gnu:
before_script:
- apt-get install -y libglu1-mesa-dev libevdev-dev libvterm-dev
@@ -106,7 +113,6 @@ pack:
- "${BASE_NAME}-$(cat VERSION)/"
pages:
- <<: *variables_definition
stage: deploy
before_script:
- apt-get update -y
diff --git a/subprojects/d2tk/VERSION b/subprojects/d2tk/VERSION
index bfac85b..a688425 100644
--- a/subprojects/d2tk/VERSION
+++ b/subprojects/d2tk/VERSION
@@ -1 +1 @@
-0.1.951
+0.1.1017
diff --git a/subprojects/d2tk/check_for_font b/subprojects/d2tk/check_for_font
new file mode 100755
index 0000000..befcbf4
--- /dev/null
+++ b/subprojects/d2tk/check_for_font
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+fc-list | grep "$1"
diff --git a/subprojects/d2tk/d2tk/base.h b/subprojects/d2tk/d2tk/base.h
index 38108e7..98c2f48 100644
--- a/subprojects/d2tk/d2tk/base.h
+++ b/subprojects/d2tk/d2tk/base.h
@@ -26,8 +26,6 @@
#include <utf8.h/utf8.h>
-#include "config.h"
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -43,6 +41,7 @@ typedef struct _d2tk_flowmatrix_t d2tk_flowmatrix_t;
typedef struct _d2tk_flowmatrix_node_t d2tk_flowmatrix_node_t;
typedef struct _d2tk_flowmatrix_arc_t d2tk_flowmatrix_arc_t;
typedef struct _d2tk_pane_t d2tk_pane_t;
+typedef struct _d2tk_pty_t d2tk_pty_t;
typedef struct _d2tk_base_t d2tk_base_t;
struct _d2tk_pos_t {
@@ -155,9 +154,9 @@ typedef enum _d2tk_flag_t {
D2TK_FLAG_TABLE_REL = (1 << 9),
} d2tk_flag_t;
-#define D2TK_ID_IDX(IDX) ((d2tk_id_t)__LINE__ << 16) | (IDX)
+#define D2TK_ID_IDX(IDX) ( ((d2tk_id_t)__LINE__ << 16) | (IDX) )
#define D2TK_ID_FILE_IDX(IDX) \
- ((d2tk_id_t)d2tk_hash(__FILE__, -1) << 32) | D2TK_ID_IDX((IDX))
+ ( ((d2tk_id_t)d2tk_hash(__FILE__, -1) << 32) | D2TK_ID_IDX((IDX)) )
#define D2TK_ID D2TK_ID_IDX(0)
#define D2TK_ID_FILE D2TK_ID_FILE_IDX(0)
@@ -169,6 +168,7 @@ extern const size_t d2tk_flowmatrix_sz;
extern const size_t d2tk_flowmatrix_node_sz;
extern const size_t d2tk_flowmatrix_arc_sz;
extern const size_t d2tk_pane_sz;
+extern const size_t d2tk_pty_sz;
D2TK_API d2tk_table_t *
d2tk_table_begin(const d2tk_rect_t *rect, unsigned N, unsigned M,
@@ -416,6 +416,14 @@ d2tk_base_button(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect);
d2tk_state_is_changed(d2tk_base_button(__VA_ARGS__))
D2TK_API d2tk_state_t
+d2tk_base_toggle_label_image(d2tk_base_t *base, d2tk_id_t id, ssize_t lbl_len,
+ const char *lbl, d2tk_align_t align, ssize_t path_len, const char *path,
+ const d2tk_rect_t *rect, bool *value);
+
+#define d2tk_base_toggle_label_image_is_changed(...) \
+ d2tk_state_is_changed(d2tk_base_toggle_label_image(__VA_ARGS__))
+
+D2TK_API d2tk_state_t
d2tk_base_toggle_label(d2tk_base_t *base, d2tk_id_t id, ssize_t lbl_len,
const char *lbl, d2tk_align_t align, const d2tk_rect_t *rect, bool *value);
@@ -475,14 +483,38 @@ d2tk_base_link(d2tk_base_t *base, d2tk_id_t id, ssize_t lbl_len, const char *lbl
d2tk_state_is_changed(d2tk_base_link(__VA_ARGS__))
#if D2TK_PTY
-typedef void (*d2tk_clone_t)(FILE *stderr, void *data);
+D2TK_API d2tk_pty_t *
+d2tk_pty_begin(d2tk_base_t *base, d2tk_id_t id, char **argv,
+ d2tk_coord_t height, const d2tk_rect_t *rect, bool reinit, d2tk_pty_t *pty);
+
+D2TK_API bool
+d2tk_pty_not_end(d2tk_pty_t *pty);
+
+D2TK_API d2tk_pty_t *
+d2tk_pty_next(d2tk_pty_t *pty);
D2TK_API d2tk_state_t
-d2tk_base_pty(d2tk_base_t *base, d2tk_id_t id, d2tk_clone_t clone, void *data,
- d2tk_coord_t height, const d2tk_rect_t *rect, bool reinit);
+d2tk_pty_get_state(d2tk_pty_t *pty);
+
+D2TK_API uint32_t
+d2tk_pty_get_max_red(d2tk_pty_t *pty);
-#define d2tk_base_pty_is_changed(...) \
- d2tk_state_is_changed(d2tk_base_pty(__VA_ARGS__))
+D2TK_API uint32_t
+d2tk_pty_get_max_green(d2tk_pty_t *pty);
+
+D2TK_API uint32_t
+d2tk_pty_get_max_blue(d2tk_pty_t *pty);
+
+#define D2TK_BASE_PTY(BASE, ID, ARGV, HEIGHT, RECT, REINIT, PTY) \
+ for(d2tk_pty_t *(PTY) = d2tk_pty_begin((BASE), (ID), (ARGV), (HEIGHT), \
+ (RECT), (REINIT), alloca(d2tk_pty_sz)); \
+ d2tk_pty_not_end((PTY)); \
+ (PTY) = d2tk_pty_next((PTY)))
+#endif
+
+#if D2TK_EVDEV
+D2TK_API d2tk_state_t
+d2tk_base_vkb(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect);
#endif
D2TK_API d2tk_state_t
@@ -534,6 +566,20 @@ d2tk_base_dial_double(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
#define d2tk_base_dial_double_is_changed(...) \
d2tk_state_is_changed(d2tk_base_dial_double(__VA_ARGS__))
+D2TK_API d2tk_state_t
+d2tk_base_spinner_int32(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
+ int32_t min, int32_t *value, int32_t max);
+
+#define d2tk_base_spinner_int32_is_changed(...) \
+ d2tk_state_is_changed(d2tk_base_spinner_int32(__VA_ARGS__))
+
+D2TK_API d2tk_state_t
+d2tk_base_bar_int32(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
+ int32_t min, int32_t *value, int32_t max);
+
+#define d2tk_base_bar_int32_is_changed(...) \
+ d2tk_state_is_changed(d2tk_base_bar_int32(__VA_ARGS__))
+
D2TK_API d2tk_flowmatrix_t *
d2tk_flowmatrix_begin(d2tk_base_t *base, const d2tk_rect_t *rect, d2tk_id_t id,
d2tk_flowmatrix_t *flowmatrix);
@@ -647,6 +693,12 @@ d2tk_base_set_butmask(d2tk_base_t *base, d2tk_butmask_t mask, bool down);
D2TK_API bool
d2tk_base_get_butmask(d2tk_base_t *base, d2tk_butmask_t mask, bool clear);
+D2TK_API bool
+d2tk_base_get_butmask_down(d2tk_base_t *base, d2tk_butmask_t mask);
+
+D2TK_API bool
+d2tk_base_get_butmask_up(d2tk_base_t *base, d2tk_butmask_t mask);
+
D2TK_API void
d2tk_base_set_mouse_pos(d2tk_base_t *base, d2tk_coord_t x, d2tk_coord_t y);
@@ -672,6 +724,12 @@ d2tk_base_set_keymask(d2tk_base_t *base, d2tk_keymask_t mask, bool down);
D2TK_API bool
d2tk_base_get_keymask(d2tk_base_t *base, d2tk_keymask_t mask, bool clear);
+D2TK_API bool
+d2tk_base_get_keymask_down(d2tk_base_t *base, d2tk_keymask_t mask);
+
+D2TK_API bool
+d2tk_base_get_keymask_up(d2tk_base_t *base, d2tk_keymask_t mask);
+
D2TK_API void
d2tk_base_set_dimensions(d2tk_base_t *base, d2tk_coord_t w, d2tk_coord_t h);
diff --git a/subprojects/d2tk/d2tk/config.h.in b/subprojects/d2tk/d2tk/config.h.in
index 0488566..5bf1ed2 100644
--- a/subprojects/d2tk/d2tk/config.h.in
+++ b/subprojects/d2tk/d2tk/config.h.in
@@ -1,3 +1,4 @@
#define D2TK_PTY @D2TK_PTY@
#define D2TK_EVDEV @D2TK_EVDEV@
#define D2TK_INPUT_1_15 @D2TK_INPUT_1_15@
+#define D2TK_FONTCONFIG @D2TK_FONTCONFIG@
diff --git a/subprojects/d2tk/d2tk/core.h b/subprojects/d2tk/d2tk/core.h
index bbe0d3c..8de5cc5 100644
--- a/subprojects/d2tk/d2tk/core.h
+++ b/subprojects/d2tk/d2tk/core.h
@@ -21,6 +21,7 @@
#include <stdint.h>
#include <stdbool.h>
+#include "config.h"
#include <d2tk/d2tk.h>
#ifdef __cplusplus
diff --git a/subprojects/d2tk/example/d2tk_fbdev.c b/subprojects/d2tk/example/d2tk_fbdev.c
index a6c9c26..d298190 100644
--- a/subprojects/d2tk/example/d2tk_fbdev.c
+++ b/subprojects/d2tk/example/d2tk_fbdev.c
@@ -33,6 +33,7 @@ typedef void (*foreach_t)(const char *path, const char *d_name);
struct _app_t {
d2tk_fbdev_t *fbdev;
+ bool show_cursor;
};
static sig_atomic_t done = false;
@@ -52,11 +53,14 @@ _expose(void *data, d2tk_coord_t w, d2tk_coord_t h)
d2tk_example_run(base, w, h);
- d2tk_coord_t x = 0;
- d2tk_coord_t y = 0;
+ if(app->show_cursor)
+ {
+ d2tk_coord_t x = 0;
+ d2tk_coord_t y = 0;
- d2tk_base_get_mouse_pos(base, &x, &y);
- d2tk_base_cursor(base, &D2TK_RECT(x, y, 24, 24));
+ d2tk_base_get_mouse_pos(base, &x, &y);
+ d2tk_base_cursor(base, &D2TK_RECT(x, y, 24, 24));
+ }
return EXIT_SUCCESS;
}
@@ -153,7 +157,7 @@ main(int argc, char **argv)
static char fb_device [PATH_MAX] = AUTO;
int c;
- while( (c = getopt(argc, argv, "f:")) != -1)
+ while( (c = getopt(argc, argv, "f:c")) != -1)
{
switch(c)
{
@@ -161,11 +165,16 @@ main(int argc, char **argv)
{
strncpy(fb_device, optarg, PATH_MAX-1);
} break;
+ case 'c':
+ {
+ app.show_cursor = true;
+ } break;
default:
{
fprintf(stderr, "Usage: %s\n"
- " -f fb_device (auto)\n\n",
+ " -f fb_device (auto)\n"
+ " -c show cursor\n\n",
argv[0]);
} return EXIT_FAILURE;
}
diff --git a/subprojects/d2tk/example/example.c b/subprojects/d2tk/example/example.c
index 166c602..2d8b94e 100644
--- a/subprojects/d2tk/example/example.c
+++ b/subprojects/d2tk/example/example.c
@@ -26,23 +26,6 @@
#include <d2tk/frontend_pugl.h>
#include "example/example.h"
-#if D2TK_EVDEV
-# include <libevdev/libevdev.h>
-# include <libevdev/libevdev-uinput.h>
-
-typedef struct _fake_t fake_t;
-
-struct _fake_t {
- struct libevdev *dev;
- struct libevdev_uinput *uidev;
-};
-
-static fake_t fake = {
- .dev = NULL,
- .uidev = NULL
-};
-#endif
-
typedef union _val_t val_t;
union _val_t {
@@ -56,6 +39,7 @@ union _val_t {
typedef enum _bar_t {
BAR_MIX,
+ BAR_SPINNER,
BAR_SEQ,
BAR_TABLE_ABS,
BAR_SCROLL,
@@ -81,6 +65,7 @@ typedef enum _bar_t {
static bar_t bar = BAR_MIX;
static const char *bar_lbl [BAR_MAX] = {
[BAR_MIX] = "Mix of many",
+ [BAR_SPINNER] = "Spinner",
[BAR_SEQ] = "Sequencer",
[BAR_TABLE_ABS] = "Table Abs",
[BAR_SCROLL] = "Scrollbar",
@@ -265,6 +250,28 @@ _render_c_mix(d2tk_base_t *base, const d2tk_rect_t *rect)
}
static inline void
+_render_c_spinner(d2tk_base_t *base, const d2tk_rect_t *rect)
+{
+#define N 8
+#define M 24
+ static int32_t val [N*M];
+
+ D2TK_BASE_TABLE(rect, N, M, D2TK_FLAG_TABLE_REL, tab)
+ {
+ const d2tk_rect_t *trect = d2tk_table_get_rect(tab);
+ const unsigned k = d2tk_table_get_index(tab);
+ const d2tk_id_t id = D2TK_ID_IDX(k);
+
+ if(d2tk_base_spinner_int32_is_changed(base, id, trect, -99, &val[k], 99))
+ {
+ fprintf(stdout, "spinner %016"PRIx64" %"PRIi32"\n", id, val[k]);
+ }
+ }
+#undef N
+#undef M
+}
+
+static inline void
_render_c_seq(d2tk_base_t *base, const d2tk_rect_t *rect)
{
#define N (8*12)
@@ -805,80 +812,6 @@ _render_c_utf8(d2tk_base_t *base, const d2tk_rect_t *rect)
}
#if D2TK_PTY
-#include <linenoise/linenoise.h>
-
-static void
-_completion(const char *buf, linenoiseCompletions *lc)
-{
- switch(buf[0])
- {
- case 'b':
- {
- linenoiseAddCompletion(lc, "bar");
- } break;
- case 'c':
- {
- linenoiseAddCompletion(lc, "clear");
- } break;
- case 'f':
- {
- linenoiseAddCompletion(lc, "foo");
- } break;
- }
-}
-
-static char *
-_hints(const char *buf, int *color, int *bold)
-{
- static const char *hint = "<cmd>";
-
- switch(buf[0])
- {
- case '\0':
- {
- *color = 36;
- *bold = 0;
- return (char *)hint;
- } break;
- }
-
- return NULL;
-}
-
-static void
-_curses(FILE *err __attribute__((unused)), void *data __attribute__((unused)))
-{
- linenoiseSetMultiLine(0);
- linenoiseSetCompletionCallback(_completion);
- linenoiseSetHintsCallback(_hints);
- linenoiseHistorySetMaxLen(128);
-
- while(true)
- {
- char *line = linenoise("> ");
-
- if(!line)
- {
- break;
- }
-
- if(strlen(line))
- {
- //FIXME
- linenoiseHistoryAdd(line);
- }
-
- if(!strcmp(line, "clear"))
- {
- linenoiseClearScreen();
- }
-
- linenoiseFree(line);
- }
-
- _exit(EXIT_SUCCESS);
-}
-
static inline void
_render_c_pty(d2tk_base_t *base, const d2tk_rect_t *rect)
{
@@ -888,6 +821,10 @@ _render_c_pty(d2tk_base_t *base, const d2tk_rect_t *rect)
NULL
};
+ static uint32_t last_red = 0x0;;
+ static uint32_t last_green = 0x0;;
+ static uint32_t last_blue = 0x0;;
+
static d2tk_coord_t hfrac [2] = { 1, 1 };
D2TK_BASE_LAYOUT(rect, 2, hfrac, D2TK_FLAG_LAYOUT_X_REL, hlay)
@@ -899,11 +836,35 @@ _render_c_pty(d2tk_base_t *base, const d2tk_rect_t *rect)
{
case 0:
{
- d2tk_base_pty(base, D2TK_ID, NULL, argv, HEIGHT, hrect, false);
+ D2TK_BASE_PTY(base, D2TK_ID, argv, HEIGHT, hrect, false, pty)
+ {
+ const uint32_t max_red = d2tk_pty_get_max_red(pty);
+ const uint32_t max_green = d2tk_pty_get_max_green(pty);
+ const uint32_t max_blue = d2tk_pty_get_max_blue(pty);
+
+ if(max_red != last_red)
+ {
+ fprintf(stderr, "max_red: 0x%08x\n", max_red);
+ last_red = max_red;
+ }
+ if(max_green != last_green)
+ {
+ fprintf(stderr, "max_green: 0x%08x\n", max_green);
+ last_green = max_green;
+ }
+ if(max_blue != last_blue)
+ {
+ fprintf(stderr, "max_blue: 0x%08x\n", max_blue);
+ last_blue = max_blue;
+ }
+ }
} break;
case 1:
{
- d2tk_base_pty(base, D2TK_ID, _curses, NULL, HEIGHT, hrect, false);
+ D2TK_BASE_PTY(base, D2TK_ID, argv, HEIGHT, hrect, false, pty)
+ {
+ // nothing to do
+ }
} break;
}
}
@@ -1161,548 +1122,22 @@ _render_c_browser(d2tk_base_t *base, const d2tk_rect_t *rect)
#endif
#if D2TK_EVDEV
-static void
-_fake_event(unsigned type, unsigned code, int value)
-{
- if(fake.uidev)
- {
- libevdev_uinput_write_event(fake.uidev, type, code, value);
- }
-}
-
-static void
-_fake_key_down(unsigned keycode)
-{
- _fake_event(EV_KEY, keycode, 1);
- _fake_event(EV_SYN, SYN_REPORT, 0);
-}
-
-static void
-_fake_key_up(unsigned keycode)
-{
- _fake_event(EV_KEY, keycode, 0);
- _fake_event(EV_SYN, SYN_REPORT, 0);
-}
-
-typedef struct _keybtn_t keybtn_t;
-
-struct _keybtn_t {
- const char *name;
- const char *altn;
- unsigned code;
- float rect [4];
-};
-
-#define W (1.f / 15.f)
-#define W_2 (W / 2)
-#define H (1.f / 6.f)
-
-static const keybtn_t keybtns [] = {
- // row 1
- {
- .name = "Esc",
- .code = KEY_ESC,
- .rect = { 0*W, 0*H, W + W_2, H }
- },
- {
- .name = "F1",
- .code = KEY_F1,
- .rect = { 1*W + W_2, 0*H, W, H }
- },
- {
- .name = "F2",
- .code = KEY_F2,
- .rect = { 2*W + W_2, 0*H, W, H }
- },
- {
- .name = "F3",
- .code = KEY_F3,
- .rect = { 3*W + W_2, 0*H, W, H }
- },
- {
- .name = "F4",
- .code = KEY_F4,
- .rect = { 4*W + W_2, 0*H, W, H }
- },
- {
- .name = "F5",
- .code = KEY_F5,
- .rect = { 5*W + W_2, 0*H, W, H }
- },
- {
- .name = "F6",
- .code = KEY_F6,
- .rect = { 6*W + W_2, 0*H, W, H }
- },
- {
- .name = "F7",
- .code = KEY_F7,
- .rect = { 7*W + W_2, 0*H, W, H }
- },
- {
- .name = "F8",
- .code = KEY_F8,
- .rect = { 8*W + W_2, 0*H, W, H }
- },
- {
- .name = "F9",
- .code = KEY_F9,
- .rect = { 9*W + W_2, 0*H, W, H }
- },
- {
- .name = "F10",
- .code = KEY_F10,
- .rect = { 10*W + W_2, 0*H, W, H }
- },
- {
- .name = "F11",
- .code = KEY_F11,
- .rect = { 11*W + W_2, 0*H, W, H }
- },
- {
- .name = "F12",
- .code = KEY_F12,
- .rect = { 12*W + W_2, 0*H, W, H }
- },
- {
- .name = "Delete",
- .code = KEY_DELETE,
- .rect = { 13*W + W_2, 0*H, W + W_2, H }
- },
-
- // row 2
- {
- .name = "`",
- .altn = "~",
- .code = KEY_GRAVE,
- .rect = { 0*W, 1*H, W, H }
- },
- {
- .name = "1",
- .altn = "!",
- .code = KEY_1,
- .rect = { 1*W, 1*H, W, H }
- },
- {
- .name = "2",
- .altn = "@",
- .code = KEY_2,
- .rect = { 2*W, 1*H, W, H }
- },
- {
- .name = "3",
- .altn = "#",
- .code = KEY_3,
- .rect = { 3*W, 1*H, W, H }
- },
- {
- .name = "4",
- .altn = "$",
- .code = KEY_4,
- .rect = { 4*W, 1*H, W, H }
- },
- {
- .name = "5",
- .altn = "%",
- .code = KEY_5,
- .rect = { 5*W, 1*H, W, H }
- },
- {
- .name = "6",
- .altn = "^",
- .code = KEY_6,
- .rect = { 6*W, 1*H, W, H }
- },
- {
- .name = "7",
- .altn = "&",
- .code = KEY_7,
- .rect = { 7*W, 1*H, W, H }
- },
- {
- .name = "8",
- .altn = "*",
- .code = KEY_8,
- .rect = { 8*W, 1*H, W, H }
- },
- {
- .name = "9",
- .altn = "(",
- .code = KEY_9,
- .rect = { 9*W, 1*H, W, H }
- },
- {
- .name = "0",
- .altn = ")",
- .code = KEY_0,
- .rect = { 10*W, 1*H, W, H }
- },
- {
- .name = "-",
- .altn = "_",
- .code = KEY_MINUS,
- .rect = { 11*W, 1*H, W, H }
- },
- {
- .name = "=",
- .altn = "+",
- .code = KEY_EQUAL,
- .rect = { 12*W, 1*H, W, H }
- },
- {
- .name = "Back",
- .code = KEY_BACKSPACE,
- .rect = { 13*W, 1*H, 2*W, H }
- },
-
- // row 3
- {
- .name = "Tab",
- .code = KEY_TAB,
- .rect = { 0*W, 2*H, W + W_2, H }
- },
- {
- .name = "Q",
- .code = KEY_Q,
- .rect = { 1*W + W_2, 2*H, W, H }
- },
- {
- .name = "W",
- .code = KEY_W,
- .rect = { 2*W + W_2, 2*H, W, H }
- },
- {
- .name = "E",
- .code = KEY_E,
- .rect = { 3*W + W_2, 2*H, W, H }
- },
- {
- .name = "R",
- .code = KEY_R,
- .rect = { 4*W + W_2, 2*H, W, H }
- },
- {
- .name = "T",
- .code = KEY_T,
- .rect = { 5*W + W_2, 2*H, W, H }
- },
- {
- .name = "Y",
- .code = KEY_Y,
- .rect = { 6*W + W_2, 2*H, W, H }
- },
- {
- .name = "U",
- .code = KEY_U,
- .rect = { 7*W + W_2, 2*H, W, H }
- },
- {
- .name = "I",
- .code = KEY_I,
- .rect = { 8*W + W_2, 2*H, W, H }
- },
- {
- .name = "O",
- .code = KEY_O,
- .rect = { 9*W + W_2, 2*H, W, H }
- },
- {
- .name = "P",
- .code = KEY_P,
- .rect = { 10*W + W_2, 2*H, W, H }
- },
- {
- .name = "[",
- .altn = "{",
- .code = KEY_LEFTBRACE,
- .rect = { 11*W + W_2, 2*H, W, H }
- },
- {
- .name = "]",
- .altn = "}",
- .code = KEY_RIGHTBRACE,
- .rect = { 12*W + W_2, 2*H, W, H }
- },
- {
- .name = "\\",
- .altn = "|",
- .code = KEY_BACKSLASH,
- .rect = { 13*W + W_2, 2*H, 2*W - W_2, H }
- },
-
- // row 4
- {
- .name = "Caps",
- .code = KEY_CAPSLOCK,
- .rect = { 0*W, 3*H, W*2, H }
- },
- {
- .name = "A",
- .code = KEY_A,
- .rect = { 2*W, 3*H, W, H }
- },
- {
- .name = "S",
- .code = KEY_S,
- .rect = { 3*W, 3*H, W, H }
- },
- {
- .name = "D",
- .code = KEY_D,
- .rect = { 4*W, 3*H, W, H }
- },
- {
- .name = "F",
- .code = KEY_F,
- .rect = { 5*W, 3*H, W, H }
- },
- {
- .name = "G",
- .code = KEY_G,
- .rect = { 6*W, 3*H, W, H }
- },
- {
- .name = "H",
- .code = KEY_H,
- .rect = { 7*W, 3*H, W, H }
- },
- {
- .name = "J",
- .code = KEY_J,
- .rect = { 8*W, 3*H, W, H }
- },
- {
- .name = "K",
- .code = KEY_K,
- .rect = { 9*W, 3*H, W, H }
- },
- {
- .name = "L",
- .code = KEY_L,
- .rect = { 10*W, 3*H, W, H }
- },
- {
- .name = ";",
- .altn = ":",
- .code = KEY_SEMICOLON,
- .rect = { 11*W, 3*H, W, H }
- },
- {
- .name = "'",
- .altn = "\"",
- .code = KEY_APOSTROPHE,
- .rect = { 12*W, 3*H, W, H }
- },
- {
- .name = "Enter",
- .code = KEY_ENTER,
- .rect = { 13*W, 3*H, W*2, H }
- },
-
- // row 5
- {
- .name = "Shift",
- .code = KEY_LEFTSHIFT,
- .rect = { 0*W, 4*H, W*2 + W_2, H }
- },
- {
- .name = "Z",
- .code = KEY_Z,
- .rect = { 2*W + W_2, 4*H, W, H }
- },
- {
- .name = "X",
- .code = KEY_X,
- .rect = { 3*W + W_2, 4*H, W, H }
- },
- {
- .name = "C",
- .code = KEY_C,
- .rect = { 4*W + W_2, 4*H, W, H }
- },
- {
- .name = "V",
- .code = KEY_V,
- .rect = { 5*W + W_2, 4*H, W, H }
- },
- {
- .name = "B",
- .code = KEY_B,
- .rect = { 6*W + W_2, 4*H, W, H }
- },
- {
- .name = "N",
- .code = KEY_N,
- .rect = { 7*W + W_2, 4*H, W, H }
- },
- {
- .name = "M",
- .code = KEY_M,
- .rect = { 8*W + W_2, 4*H, W, H }
- },
- {
- .name = ",",
- .altn = "<",
- .code = KEY_COMMA,
- .rect = { 9*W + W_2, 4*H, W, H }
- },
- {
- .name = ".",
- .altn = ">",
- .code = KEY_DOT,
- .rect = { 10*W + W_2, 4*H, W, H }
- },
- {
- .name = "/",
- .altn = "?",
- .code = KEY_SLASH,
- .rect = { 11*W + W_2, 4*H, W, H }
- },
- {
- .name = "Shift",
- .code = KEY_RIGHTSHIFT,
- .rect = { 12*W + W_2, 4*H, 3*W - W_2, H }
- },
-
- // row 6
- {
- .name = "Fn",
- .code = KEY_FN,
- .rect = { 0*W, 5*H, W, H }
- },
- {
- .name = "Ctrl",
- .code = KEY_LEFTCTRL,
- .rect = { 1*W, 5*H, W, H }
- },
- {
- .name = "Mta",
- .code = KEY_LEFTMETA,
- .rect = { 2*W, 5*H, W, H }
- },
- {
- .name = "Alt",
- .code = KEY_LEFTALT,
- .rect = { 3*W, 5*H, W, H }
- },
- {
- .name = "Space",
- .code = KEY_SPACE,
- .rect = { 4*W, 5*H, 5*W, H }
- },
- {
- .name = "Alt",
- .code = KEY_RIGHTALT,
- .rect = { 9*W, 5*H, W, H }
- },
- {
- .name = "Mta",
- .code = KEY_RIGHTMETA,
- .rect = { 10*W, 5*H, W, H }
- },
- {
- .name = "Ctrl",
- .code = KEY_RIGHTCTRL,
- .rect = { 11*W, 5*H, W, H }
- },
- {
- .name = "Hom",
- .code = KEY_HOME,
- .rect = { 12*W, 5*H, W, H }
- },
- {
- .name = "End",
- .code = KEY_END,
- .rect = { 13*W, 5*H, W, H }
- },
- {
- .name = "Ins",
- .code = KEY_INSERT,
- .rect = { 14*W, 5*H, W, H }
- },
-
- { // sentinel
- .name = NULL
- }
-};
-
static inline void
_render_c_keyboard(d2tk_base_t *base, const d2tk_rect_t *rect)
{
- for(const keybtn_t *keybtn = keybtns; keybtn->name; keybtn++)
- {
- const d2tk_rect_t bnd = {
- .x = rect->x + keybtn->rect[0]*rect->w,
- .y = rect->y + keybtn->rect[1]*rect->h,
- .w = keybtn->rect[2]*rect->w,
- .h = keybtn->rect[3]*rect->h
- };
-
- const char *lbl = d2tk_base_get_modmask(base, D2TK_MODMASK_SHIFT, false)
- && keybtn->altn
- ? keybtn->altn
- : keybtn->name;
-
- const d2tk_state_t state = d2tk_base_button_label(base,
- D2TK_ID_IDX(keybtn-keybtns), -1, lbl, D2TK_ALIGN_CENTERED, &bnd);
-
- if(d2tk_state_is_down(state))
- {
- _fake_key_down(keybtn->code);
- }
- else if(d2tk_state_is_up(state))
- {
- _fake_key_up(keybtn->code);
- }
- }
+ d2tk_base_vkb(base, D2TK_ID, rect);
}
#endif
D2TK_API int
d2tk_example_init(void)
-{
-#if D2TK_EVDEV
- fake.dev = libevdev_new();
- if(!fake.dev)
- {
- fprintf(stderr, "Error: libevdev_new\n");
- return EXIT_FAILURE;;
- }
- libevdev_set_name(fake.dev, "Fake keyboard");
- libevdev_enable_event_type(fake.dev, EV_SYN);
- libevdev_enable_event_code(fake.dev, EV_SYN, SYN_REPORT, NULL);
- libevdev_enable_event_type(fake.dev, EV_KEY);
- for(const keybtn_t *keybtn = keybtns; keybtn->name; keybtn++)
- {
- libevdev_enable_event_code(fake.dev, EV_KEY, keybtn->code, NULL);
- }
-
- fake.uidev = NULL;
- libevdev_uinput_create_from_device(fake.dev, LIBEVDEV_UINPUT_OPEN_MANAGED,
- &fake.uidev);
- if(!fake.uidev)
- {
- fprintf(stderr, "Warning: libevdev_uinput_create_from_device\n");
- return EXIT_FAILURE;
- }
-#endif
-
+{
return EXIT_SUCCESS;
}
D2TK_API void
d2tk_example_deinit(void)
{
-#if D2TK_EVDEV
- if(fake.uidev)
- {
- libevdev_uinput_destroy(fake.uidev);
- }
- if(fake.dev)
- {
- libevdev_free(fake.dev);
- }
-#endif
}
D2TK_API void
@@ -1743,6 +1178,10 @@ d2tk_example_run(d2tk_base_t *base, d2tk_coord_t w, d2tk_coord_t h)
{
_render_c_mix(base, vrect);
} break;
+ case BAR_SPINNER:
+ {
+ _render_c_spinner(base, vrect);
+ } break;
case BAR_SEQ:
{
_render_c_seq(base, vrect);
diff --git a/subprojects/d2tk/linenoise/.gitignore b/subprojects/d2tk/linenoise/.gitignore
deleted file mode 100644
index 7ab7825..0000000
--- a/subprojects/d2tk/linenoise/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-linenoise_example
-*.dSYM
-history.txt
diff --git a/subprojects/d2tk/linenoise/LICENSE b/subprojects/d2tk/linenoise/LICENSE
deleted file mode 100644
index 18e8148..0000000
--- a/subprojects/d2tk/linenoise/LICENSE
+++ /dev/null
@@ -1,25 +0,0 @@
-Copyright (c) 2010-2014, Salvatore Sanfilippo <antirez at gmail dot com>
-Copyright (c) 2010-2013, Pieter Noordhuis <pcnoordhuis at gmail dot com>
-
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
-* Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/subprojects/d2tk/linenoise/Makefile b/subprojects/d2tk/linenoise/Makefile
deleted file mode 100644
index a285410..0000000
--- a/subprojects/d2tk/linenoise/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-linenoise_example: linenoise.h linenoise.c
-
-linenoise_example: linenoise.c example.c
- $(CC) -Wall -W -Os -g -o linenoise_example linenoise.c example.c
-
-clean:
- rm -f linenoise_example
diff --git a/subprojects/d2tk/linenoise/README.markdown b/subprojects/d2tk/linenoise/README.markdown
deleted file mode 100644
index 9f583c7..0000000
--- a/subprojects/d2tk/linenoise/README.markdown
+++ /dev/null
@@ -1,229 +0,0 @@
-# Linenoise
-
-A minimal, zero-config, BSD licensed, readline replacement used in Redis,
-MongoDB, and Android.
-
-* Single and multi line editing mode with the usual key bindings implemented.
-* History handling.
-* Completion.
-* Hints (suggestions at the right of the prompt as you type).
-* About 1,100 lines of BSD license source code.
-* Only uses a subset of VT100 escapes (ANSI.SYS compatible).
-
-## Can a line editing library be 20k lines of code?
-
-Line editing with some support for history is a really important feature for command line utilities. Instead of retyping almost the same stuff again and again it's just much better to hit the up arrow and edit on syntax errors, or in order to try a slightly different command. But apparently code dealing with terminals is some sort of Black Magic: readline is 30k lines of code, libedit 20k. Is it reasonable to link small utilities to huge libraries just to get a minimal support for line editing?
-
-So what usually happens is either:
-
- * Large programs with configure scripts disabling line editing if readline is not present in the system, or not supporting it at all since readline is GPL licensed and libedit (the BSD clone) is not as known and available as readline is (Real world example of this problem: Tclsh).
- * Smaller programs not using a configure script not supporting line editing at all (A problem we had with Redis-cli for instance).
-
-The result is a pollution of binaries without line editing support.
-
-So I spent more or less two hours doing a reality check resulting in this little library: is it *really* needed for a line editing library to be 20k lines of code? Apparently not, it is possibe to get a very small, zero configuration, trivial to embed library, that solves the problem. Smaller programs will just include this, supporting line editing out of the box. Larger programs may use this little library or just checking with configure if readline/libedit is available and resorting to Linenoise if not.
-
-## Terminals, in 2010.
-
-Apparently almost every terminal you can happen to use today has some kind of support for basic VT100 escape sequences. So I tried to write a lib using just very basic VT100 features. The resulting library appears to work everywhere I tried to use it, and now can work even on ANSI.SYS compatible terminals, since no
-VT220 specific sequences are used anymore.
-
-The library is currently about 1100 lines of code. In order to use it in your project just look at the *example.c* file in the source distribution, it is trivial. Linenoise is BSD code, so you can use both in free software and commercial software.
-
-## Tested with...
-
- * Linux text only console ($TERM = linux)
- * Linux KDE terminal application ($TERM = xterm)
- * Linux xterm ($TERM = xterm)
- * Linux Buildroot ($TERM = vt100)
- * Mac OS X iTerm ($TERM = xterm)
- * Mac OS X default Terminal.app ($TERM = xterm)
- * OpenBSD 4.5 through an OSX Terminal.app ($TERM = screen)
- * IBM AIX 6.1
- * FreeBSD xterm ($TERM = xterm)
- * ANSI.SYS
- * Emacs comint mode ($TERM = dumb)
-
-Please test it everywhere you can and report back!
-
-## Let's push this forward!
-
-Patches should be provided in the respect of Linenoise sensibility for small
-easy to understand code.
-
-Send feedbacks to antirez at gmail
-
-# The API
-
-Linenoise is very easy to use, and reading the example shipped with the
-library should get you up to speed ASAP. Here is a list of API calls
-and how to use them.
-
- char *linenoise(const char *prompt);
-
-This is the main Linenoise call: it shows the user a prompt with line editing
-and history capabilities. The prompt you specify is used as a prompt, that is,
-it will be printed to the left of the cursor. The library returns a buffer
-with the line composed by the user, or NULL on end of file or when there
-is an out of memory condition.
-
-When a tty is detected (the user is actually typing into a terminal session)
-the maximum editable line length is `LINENOISE_MAX_LINE`. When instead the
-standard input is not a tty, which happens every time you redirect a file
-to a program, or use it in an Unix pipeline, there are no limits to the
-length of the line that can be returned.
-
-The returned line should be freed with the `free()` standard system call.
-However sometimes it could happen that your program uses a different dynamic
-allocation library, so you may also used `linenoiseFree` to make sure the
-line is freed with the same allocator it was created.
-
-The canonical loop used by a program using Linenoise will be something like
-this:
-
- while((line = linenoise("hello> ")) != NULL) {
- printf("You wrote: %s\n", line);
- linenoiseFree(line); /* Or just free(line) if you use libc malloc. */
- }
-
-## Single line VS multi line editing
-
-By default, Linenoise uses single line editing, that is, a single row on the
-screen will be used, and as the user types more, the text will scroll towards
-left to make room. This works if your program is one where the user is
-unlikely to write a lot of text, otherwise multi line editing, where multiple
-screens rows are used, can be a lot more comfortable.
-
-In order to enable multi line editing use the following API call:
-
- linenoiseSetMultiLine(1);
-
-You can disable it using `0` as argument.
-
-## History
-
-Linenoise supporst history, so that the user does not have to retype
-again and again the same things, but can use the down and up arrows in order
-to search and re-edit already inserted lines of text.
-
-The followings are the history API calls:
-
- int linenoiseHistoryAdd(const char *line);
- int linenoiseHistorySetMaxLen(int len);
- int linenoiseHistorySave(const char *filename);
- int linenoiseHistoryLoad(const char *filename);
-
-Use `linenoiseHistoryAdd` every time you want to add a new element
-to the top of the history (it will be the first the user will see when
-using the up arrow).
-
-Note that for history to work, you have to set a length for the history
-(which is zero by default, so history will be disabled if you don't set
-a proper one). This is accomplished using the `linenoiseHistorySetMaxLen`
-function.
-
-Linenoise has direct support for persisting the history into an history
-file. The functions `linenoiseHistorySave` and `linenoiseHistoryLoad` do
-just that. Both functions return -1 on error and 0 on success.
-
-## Completion
-
-Linenoise supports completion, which is the ability to complete the user
-input when she or he presses the `<TAB>` key.
-
-In order to use completion, you need to register a completion callback, which
-is called every time the user presses `<TAB>`. Your callback will return a
-list of items that are completions for the current string.
-
-The following is an example of registering a completion callback:
-
- linenoiseSetCompletionCallback(completion);
-
-The completion must be a function returning `void` and getting as input
-a `const char` pointer, which is the line the user has typed so far, and
-a `linenoiseCompletions` object pointer, which is used as argument of
-`linenoiseAddCompletion` in order to add completions inside the callback.
-An example will make it more clear:
-
- void completion(const char *buf, linenoiseCompletions *lc) {
- if (buf[0] == 'h') {
- linenoiseAddCompletion(lc,"hello");
- linenoiseAddCompletion(lc,"hello there");
- }
- }
-
-Basically in your completion callback, you inspect the input, and return
-a list of items that are good completions by using `linenoiseAddCompletion`.
-
-If you want to test the completion feature, compile the example program
-with `make`, run it, type `h` and press `<TAB>`.
-
-## Hints
-
-Linenoise has a feature called *hints* which is very useful when you
-use Linenoise in order to implement a REPL (Read Eval Print Loop) for
-a program that accepts commands and arguments, but may also be useful in
-other conditions.
-
-The feature shows, on the right of the cursor, as the user types, hints that
-may be useful. The hints can be displayed using a different color compared
-to the color the user is typing, and can also be bold.
-
-For example as the user starts to type `"git remote add"`, with hints it's
-possible to show on the right of the prompt a string `<name> <url>`.
-
-The feature works similarly to the history feature, using a callback.
-To register the callback we use:
-
- linenoiseSetHintsCallback(hints);
-
-The callback itself is implemented like this:
-
- char *hints(const char *buf, int *color, int *bold) {
- if (!strcasecmp(buf,"git remote add")) {
- *color = 35;
- *bold = 0;
- return " <name> <url>";
- }
- return NULL;
- }
-
-The callback function returns the string that should be displayed or NULL
-if no hint is available for the text the user currently typed. The returned
-string will be trimmed as needed depending on the number of columns available
-on the screen.
-
-It is possible to return a string allocated in dynamic way, by also registering
-a function to deallocate the hint string once used:
-
- void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback *);
-
-The free hint callback will just receive the pointer and free the string
-as needed (depending on how the hits callback allocated it).
-
-As you can see in the example above, a `color` (in xterm color terminal codes)
-can be provided together with a `bold` attribute. If no color is set, the
-current terminal foreground color is used. If no bold attribute is set,
-non-bold text is printed.
-
-Color codes are:
-
- red = 31
- green = 32
- yellow = 33
- blue = 34
- magenta = 35
- cyan = 36
- white = 37;
-
-## Screen handling
-
-Sometimes you may want to clear the screen as a result of something the
-user typed. You can do this by calling the following function:
-
- void linenoiseClearScreen(void);
-
-## Related projects
-
-* [Linenoise NG](https://github.com/arangodb/linenoise-ng) is a fork of Linenoise that aims to add more advanced features like UTF-8 support, Windows support and other features. Uses C++ instead of C as development language.
-* [Linenoise-swift](https://github.com/andybest/linenoise-swift) is a reimplementation of Linenoise written in Swift.
diff --git a/subprojects/d2tk/linenoise/example.c b/subprojects/d2tk/linenoise/example.c
deleted file mode 100644
index 3a544d3..0000000
--- a/subprojects/d2tk/linenoise/example.c
+++ /dev/null
@@ -1,74 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "linenoise.h"
-
-
-void completion(const char *buf, linenoiseCompletions *lc) {
- if (buf[0] == 'h') {
- linenoiseAddCompletion(lc,"hello");
- linenoiseAddCompletion(lc,"hello there");
- }
-}
-
-char *hints(const char *buf, int *color, int *bold) {
- if (!strcasecmp(buf,"hello")) {
- *color = 35;
- *bold = 0;
- return " World";
- }
- return NULL;
-}
-
-int main(int argc, char **argv) {
- char *line;
- char *prgname = argv[0];
-
- /* Parse options, with --multiline we enable multi line editing. */
- while(argc > 1) {
- argc--;
- argv++;
- if (!strcmp(*argv,"--multiline")) {
- linenoiseSetMultiLine(1);
- printf("Multi-line mode enabled.\n");
- } else if (!strcmp(*argv,"--keycodes")) {
- linenoisePrintKeyCodes();
- exit(0);
- } else {
- fprintf(stderr, "Usage: %s [--multiline] [--keycodes]\n", prgname);
- exit(1);
- }
- }
-
- /* Set the completion callback. This will be called every time the
- * user uses the <tab> key. */
- linenoiseSetCompletionCallback(completion);
- linenoiseSetHintsCallback(hints);
-
- /* Load history from file. The history file is just a plain text file
- * where entries are separated by newlines. */
- linenoiseHistoryLoad("history.txt"); /* Load the history at startup */
-
- /* Now this is the main loop of the typical linenoise-based application.
- * The call to linenoise() will block as long as the user types something
- * and presses enter.
- *
- * The typed string is returned as a malloc() allocated string by
- * linenoise, so the user needs to free() it. */
- while((line = linenoise("hello> ")) != NULL) {
- /* Do something with the string. */
- if (line[0] != '\0' && line[0] != '/') {
- printf("echo: '%s'\n", line);
- linenoiseHistoryAdd(line); /* Add to the history. */
- linenoiseHistorySave("history.txt"); /* Save the history on disk. */
- } else if (!strncmp(line,"/historylen",11)) {
- /* The "/historylen" command will change the history len. */
- int len = atoi(line+11);
- linenoiseHistorySetMaxLen(len);
- } else if (line[0] == '/') {
- printf("Unreconized command: %s\n", line);
- }
- free(line);
- }
- return 0;
-}
diff --git a/subprojects/d2tk/linenoise/linenoise.c b/subprojects/d2tk/linenoise/linenoise.c
deleted file mode 100644
index 10ffd71..0000000
--- a/subprojects/d2tk/linenoise/linenoise.c
+++ /dev/null
@@ -1,1201 +0,0 @@
-/* linenoise.c -- guerrilla line editing library against the idea that a
- * line editing lib needs to be 20,000 lines of C code.
- *
- * You can find the latest source code at:
- *
- * http://github.com/antirez/linenoise
- *
- * Does a number of crazy assumptions that happen to be true in 99.9999% of
- * the 2010 UNIX computers around.
- *
- * ------------------------------------------------------------------------
- *
- * Copyright (c) 2010-2016, Salvatore Sanfilippo <antirez at gmail dot com>
- * Copyright (c) 2010-2013, Pieter Noordhuis <pcnoordhuis at gmail dot com>
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * ------------------------------------------------------------------------
- *
- * References:
- * - http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
- * - http://www.3waylabs.com/nw/WWW/products/wizcon/vt220.html
- *
- * Todo list:
- * - Filter bogus Ctrl+<char> combinations.
- * - Win32 support
- *
- * Bloat:
- * - History search like Ctrl+r in readline?
- *
- * List of escape sequences used by this program, we do everything just
- * with three sequences. In order to be so cheap we may have some
- * flickering effect with some slow terminal, but the lesser sequences
- * the more compatible.
- *
- * EL (Erase Line)
- * Sequence: ESC [ n K
- * Effect: if n is 0 or missing, clear from cursor to end of line
- * Effect: if n is 1, clear from beginning of line to cursor
- * Effect: if n is 2, clear entire line
- *
- * CUF (CUrsor Forward)
- * Sequence: ESC [ n C
- * Effect: moves cursor forward n chars
- *
- * CUB (CUrsor Backward)
- * Sequence: ESC [ n D
- * Effect: moves cursor backward n chars
- *
- * The following is used to get the terminal width if getting
- * the width with the TIOCGWINSZ ioctl fails
- *
- * DSR (Device Status Report)
- * Sequence: ESC [ 6 n
- * Effect: reports the current cusor position as ESC [ n ; m R
- * where n is the row and m is the column
- *
- * When multi line mode is enabled, we also use an additional escape
- * sequence. However multi line editing is disabled by default.
- *
- * CUU (Cursor Up)
- * Sequence: ESC [ n A
- * Effect: moves cursor up of n chars.
- *
- * CUD (Cursor Down)
- * Sequence: ESC [ n B
- * Effect: moves cursor down of n chars.
- *
- * When linenoiseClearScreen() is called, two additional escape sequences
- * are used in order to clear the screen and position the cursor at home
- * position.
- *
- * CUP (Cursor position)
- * Sequence: ESC [ H
- * Effect: moves the cursor to upper left corner
- *
- * ED (Erase display)
- * Sequence: ESC [ 2 J
- * Effect: clear the whole screen
- *
- */
-
-#include <termios.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-#include "linenoise.h"
-
-#define LINENOISE_DEFAULT_HISTORY_MAX_LEN 100
-#define LINENOISE_MAX_LINE 4096
-static char *unsupported_term[] = {"dumb","cons25","emacs",NULL};
-static linenoiseCompletionCallback *completionCallback = NULL;
-static linenoiseHintsCallback *hintsCallback = NULL;
-static linenoiseFreeHintsCallback *freeHintsCallback = NULL;
-
-static struct termios orig_termios; /* In order to restore at exit.*/
-static int rawmode = 0; /* For atexit() function to check if restore is needed*/
-static int mlmode = 0; /* Multi line mode. Default is single line. */
-static int atexit_registered = 0; /* Register atexit just 1 time. */
-static int history_max_len = LINENOISE_DEFAULT_HISTORY_MAX_LEN;
-static int history_len = 0;
-static char **history = NULL;
-
-/* The linenoiseState structure represents the state during line editing.
- * We pass this state to functions implementing specific editing
- * functionalities. */
-struct linenoiseState {
- int ifd; /* Terminal stdin file descriptor. */
- int ofd; /* Terminal stdout file descriptor. */
- char *buf; /* Edited line buffer. */
- size_t buflen; /* Edited line buffer size. */
- const char *prompt; /* Prompt to display. */
- size_t plen; /* Prompt length. */
- size_t pos; /* Current cursor position. */
- size_t oldpos; /* Previous refresh cursor position. */
- size_t len; /* Current edited line length. */
- size_t cols; /* Number of columns in terminal. */
- size_t maxrows; /* Maximum num of rows used so far (multiline mode) */
- int history_index; /* The history index we are currently editing. */
-};
-
-enum KEY_ACTION{
- KEY_NULL = 0, /* NULL */
- CTRL_A = 1, /* Ctrl+a */
- CTRL_B = 2, /* Ctrl-b */
- CTRL_C = 3, /* Ctrl-c */
- CTRL_D = 4, /* Ctrl-d */
- CTRL_E = 5, /* Ctrl-e */
- CTRL_F = 6, /* Ctrl-f */
- CTRL_H = 8, /* Ctrl-h */
- TAB = 9, /* Tab */
- CTRL_K = 11, /* Ctrl+k */
- CTRL_L = 12, /* Ctrl+l */
- ENTER = 13, /* Enter */
- CTRL_N = 14, /* Ctrl-n */
- CTRL_P = 16, /* Ctrl-p */
- CTRL_T = 20, /* Ctrl-t */
- CTRL_U = 21, /* Ctrl+u */
- CTRL_W = 23, /* Ctrl+w */
- ESC = 27, /* Escape */
- BACKSPACE = 127 /* Backspace */
-};
-
-static void linenoiseAtExit(void);
-int linenoiseHistoryAdd(const char *line);
-static void refreshLine(struct linenoiseState *l);
-
-/* Debugging macro. */
-#if 0
-FILE *lndebug_fp = NULL;
-#define lndebug(...) \
- do { \
- if (lndebug_fp == NULL) { \
- lndebug_fp = fopen("/tmp/lndebug.txt","a"); \
- fprintf(lndebug_fp, \
- "[%d %d %d] p: %d, rows: %d, rpos: %d, max: %d, oldmax: %d\n", \
- (int)l->len,(int)l->pos,(int)l->oldpos,plen,rows,rpos, \
- (int)l->maxrows,old_rows); \
- } \
- fprintf(lndebug_fp, ", " __VA_ARGS__); \
- fflush(lndebug_fp); \
- } while (0)
-#else
-#define lndebug(fmt, ...)
-#endif
-
-/* ======================= Low level terminal handling ====================== */
-
-/* Set if to use or not the multi line mode. */
-void linenoiseSetMultiLine(int ml) {
- mlmode = ml;
-}
-
-/* Return true if the terminal name is in the list of terminals we know are
- * not able to understand basic escape sequences. */
-static int isUnsupportedTerm(void) {
- char *term = getenv("TERM");
- int j;
-
- if (term == NULL) return 0;
- for (j = 0; unsupported_term[j]; j++)
- if (!strcasecmp(term,unsupported_term[j])) return 1;
- return 0;
-}
-
-/* Raw mode: 1960 magic shit. */
-static int enableRawMode(int fd) {
- struct termios raw;
-
- if (!isatty(STDIN_FILENO)) goto fatal;
- if (!atexit_registered) {
- atexit(linenoiseAtExit);
- atexit_registered = 1;
- }
- if (tcgetattr(fd,&orig_termios) == -1) goto fatal;
-
- raw = orig_termios; /* modify the original mode */
- /* input modes: no break, no CR to NL, no parity check, no strip char,
- * no start/stop output control. */
- raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
- /* output modes - disable post processing */
- raw.c_oflag &= ~(OPOST);
- /* control modes - set 8 bit chars */
- raw.c_cflag |= (CS8);
- /* local modes - choing off, canonical off, no extended functions,
- * no signal chars (^Z,^C) */
- raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
- /* control chars - set return condition: min number of bytes and timer.
- * We want read to return every single byte, without timeout. */
- raw.c_cc[VMIN] = 1; raw.c_cc[VTIME] = 0; /* 1 byte, no timer */
-
- /* put terminal in raw mode after flushing */
- if (tcsetattr(fd,TCSAFLUSH,&raw) < 0) goto fatal;
- rawmode = 1;
- return 0;
-
-fatal:
- errno = ENOTTY;
- return -1;
-}
-
-static void disableRawMode(int fd) {
- /* Don't even check the return value as it's too late. */
- if (rawmode && tcsetattr(fd,TCSAFLUSH,&orig_termios) != -1)
- rawmode = 0;
-}
-
-/* Use the ESC [6n escape sequence to query the horizontal cursor position
- * and return it. On error -1 is returned, on success the position of the
- * cursor. */
-static int getCursorPosition(int ifd, int ofd) {
- char buf[32];
- int cols, rows;
- unsigned int i = 0;
-
- /* Report cursor location */
- if (write(ofd, "\x1b[6n", 4) != 4) return -1;
-
- /* Read the response: ESC [ rows ; cols R */
- while (i < sizeof(buf)-1) {
- if (read(ifd,buf+i,1) != 1) break;
- if (buf[i] == 'R') break;
- i++;
- }
- buf[i] = '\0';
-
- /* Parse it. */
- if (buf[0] != ESC || buf[1] != '[') return -1;
- if (sscanf(buf+2,"%d;%d",&rows,&cols) != 2) return -1;
- return cols;
-}
-
-/* Try to get the number of columns in the current terminal, or assume 80
- * if it fails. */
-static int getColumns(int ifd, int ofd) {
- struct winsize ws;
-
- if (ioctl(1, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) {
- /* ioctl() failed. Try to query the terminal itself. */
- int start, cols;
-
- /* Get the initial position so we can restore it later. */
- start = getCursorPosition(ifd,ofd);
- if (start == -1) goto failed;
-
- /* Go to right margin and get position. */
- if (write(ofd,"\x1b[999C",6) != 6) goto failed;
- cols = getCursorPosition(ifd,ofd);
- if (cols == -1) goto failed;
-
- /* Restore position. */
- if (cols > start) {
- char seq[32];
- snprintf(seq,32,"\x1b[%dD",cols-start);
- if (write(ofd,seq,strlen(seq)) == -1) {
- /* Can't recover... */
- }
- }
- return cols;
- } else {
- return ws.ws_col;
- }
-
-failed:
- return 80;
-}
-
-/* Clear the screen. Used to handle ctrl+l */
-void linenoiseClearScreen(void) {
- if (write(STDOUT_FILENO,"\x1b[H\x1b[2J",7) <= 0) {
- /* nothing to do, just to avoid warning. */
- }
-}
-
-/* Beep, used for completion when there is nothing to complete or when all
- * the choices were already shown. */
-static void linenoiseBeep(void) {
- fprintf(stderr, "\x7");
- fflush(stderr);
-}
-
-/* ============================== Completion ================================ */
-
-/* Free a list of completion option populated by linenoiseAddCompletion(). */
-static void freeCompletions(linenoiseCompletions *lc) {
- size_t i;
- for (i = 0; i < lc->len; i++)
- free(lc->cvec[i]);
- if (lc->cvec != NULL)
- free(lc->cvec);
-}
-
-/* This is an helper function for linenoiseEdit() and is called when the
- * user types the <tab> key in order to complete the string currently in the
- * input.
- *
- * The state of the editing is encapsulated into the pointed linenoiseState
- * structure as described in the structure definition. */
-static int completeLine(struct linenoiseState *ls) {
- linenoiseCompletions lc = { 0, NULL };
- int nread, nwritten;
- char c = 0;
-
- completionCallback(ls->buf,&lc);
- if (lc.len == 0) {
- linenoiseBeep();
- } else {
- size_t stop = 0, i = 0;
-
- while(!stop) {
- /* Show completion or original buffer */
- if (i < lc.len) {
- struct linenoiseState saved = *ls;
-
- ls->len = ls->pos = strlen(lc.cvec[i]);
- ls->buf = lc.cvec[i];
- refreshLine(ls);
- ls->len = saved.len;
- ls->pos = saved.pos;
- ls->buf = saved.buf;
- } else {
- refreshLine(ls);
- }
-
- nread = read(ls->ifd,&c,1);
- if (nread <= 0) {
- freeCompletions(&lc);
- return -1;
- }
-
- switch(c) {
- case 9: /* tab */
- i = (i+1) % (lc.len+1);
- if (i == lc.len) linenoiseBeep();
- break;
- case 27: /* escape */
- /* Re-show original buffer */
- if (i < lc.len) refreshLine(ls);
- stop = 1;
- break;
- default:
- /* Update buffer and return */
- if (i < lc.len) {
- nwritten = snprintf(ls->buf,ls->buflen,"%s",lc.cvec[i]);
- ls->len = ls->pos = nwritten;
- }
- stop = 1;
- break;
- }
- }
- }
-
- freeCompletions(&lc);
- return c; /* Return last read character */
-}
-
-/* Register a callback function to be called for tab-completion. */
-void linenoiseSetCompletionCallback(linenoiseCompletionCallback *fn) {
- completionCallback = fn;
-}
-
-/* Register a hits function to be called to show hits to the user at the
- * right of the prompt. */
-void linenoiseSetHintsCallback(linenoiseHintsCallback *fn) {
- hintsCallback = fn;
-}
-
-/* Register a function to free the hints returned by the hints callback
- * registered with linenoiseSetHintsCallback(). */
-void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback *fn) {
- freeHintsCallback = fn;
-}
-
-/* This function is used by the callback function registered by the user
- * in order to add completion options given the input string when the
- * user typed <tab>. See the example.c source code for a very easy to
- * understand example. */
-void linenoiseAddCompletion(linenoiseCompletions *lc, const char *str) {
- size_t len = strlen(str);
- char *copy, **cvec;
-
- copy = malloc(len+1);
- if (copy == NULL) return;
- memcpy(copy,str,len+1);
- cvec = realloc(lc->cvec,sizeof(char*)*(lc->len+1));
- if (cvec == NULL) {
- free(copy);
- return;
- }
- lc->cvec = cvec;
- lc->cvec[lc->len++] = copy;
-}
-
-/* =========================== Line editing ================================= */
-
-/* We define a very simple "append buffer" structure, that is an heap
- * allocated string where we can append to. This is useful in order to
- * write all the escape sequences in a buffer and flush them to the standard
- * output in a single call, to avoid flickering effects. */
-struct abuf {
- char *b;
- int len;
-};
-
-static void abInit(struct abuf *ab) {
- ab->b = NULL;
- ab->len = 0;
-}
-
-static void abAppend(struct abuf *ab, const char *s, int len) {
- char *new = realloc(ab->b,ab->len+len);
-
- if (new == NULL) return;
- memcpy(new+ab->len,s,len);
- ab->b = new;
- ab->len += len;
-}
-
-static void abFree(struct abuf *ab) {
- free(ab->b);
-}
-
-/* Helper of refreshSingleLine() and refreshMultiLine() to show hints
- * to the right of the prompt. */
-void refreshShowHints(struct abuf *ab, struct linenoiseState *l, int plen) {
- char seq[64];
- if (hintsCallback && plen+l->len < l->cols) {
- int color = -1, bold = 0;
- char *hint = hintsCallback(l->buf,&color,&bold);
- if (hint) {
- int hintlen = strlen(hint);
- int hintmaxlen = l->cols-(plen+l->len);
- if (hintlen > hintmaxlen) hintlen = hintmaxlen;
- if (bold == 1 && color == -1) color = 37;
- if (color != -1 || bold != 0)
- snprintf(seq,64,"\033[%d;%d;49m",bold,color);
- else
- seq[0] = '\0';
- abAppend(ab,seq,strlen(seq));
- abAppend(ab,hint,hintlen);
- if (color != -1 || bold != 0)
- abAppend(ab,"\033[0m",4);
- /* Call the function to free the hint returned. */
- if (freeHintsCallback) freeHintsCallback(hint);
- }
- }
-}
-
-/* Single line low level line refresh.
- *
- * Rewrite the currently edited line accordingly to the buffer content,
- * cursor position, and number of columns of the terminal. */
-static void refreshSingleLine(struct linenoiseState *l) {
- char seq[64];
- size_t plen = strlen(l->prompt);
- int fd = l->ofd;
- char *buf = l->buf;
- size_t len = l->len;
- size_t pos = l->pos;
- struct abuf ab;
-
- while((plen+pos) >= l->cols) {
- buf++;
- len--;
- pos--;
- }
- while (plen+len > l->cols) {
- len--;
- }
-
- abInit(&ab);
- /* Cursor to left edge */
- snprintf(seq,64,"\r");
- abAppend(&ab,seq,strlen(seq));
- /* Write the prompt and the current buffer content */
- abAppend(&ab,l->prompt,strlen(l->prompt));
- abAppend(&ab,buf,len);
- /* Show hits if any. */
- refreshShowHints(&ab,l,plen);
- /* Erase to right */
- snprintf(seq,64,"\x1b[0K");
- abAppend(&ab,seq,strlen(seq));
- /* Move cursor to original position. */
- snprintf(seq,64,"\r\x1b[%dC", (int)(pos+plen));
- abAppend(&ab,seq,strlen(seq));
- if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */
- abFree(&ab);
-}
-
-/* Multi line low level line refresh.
- *
- * Rewrite the currently edited line accordingly to the buffer content,
- * cursor position, and number of columns of the terminal. */
-static void refreshMultiLine(struct linenoiseState *l) {
- char seq[64];
- int plen = strlen(l->prompt);
- int rows = (plen+l->len+l->cols-1)/l->cols; /* rows used by current buf. */
- int rpos = (plen+l->oldpos+l->cols)/l->cols; /* cursor relative row. */
- int rpos2; /* rpos after refresh. */
- int col; /* colum position, zero-based. */
- int old_rows = l->maxrows;
- int fd = l->ofd, j;
- struct abuf ab;
-
- /* Update maxrows if needed. */
- if (rows > (int)l->maxrows) l->maxrows = rows;
-
- /* First step: clear all the lines used before. To do so start by
- * going to the last row. */
- abInit(&ab);
- if (old_rows-rpos > 0) {
- lndebug("go down %d", old_rows-rpos);
- snprintf(seq,64,"\x1b[%dB", old_rows-rpos);
- abAppend(&ab,seq,strlen(seq));
- }
-
- /* Now for every row clear it, go up. */
- for (j = 0; j < old_rows-1; j++) {
- lndebug("clear+up");
- snprintf(seq,64,"\r\x1b[0K\x1b[1A");
- abAppend(&ab,seq,strlen(seq));
- }
-
- /* Clean the top line. */
- lndebug("clear");
- snprintf(seq,64,"\r\x1b[0K");
- abAppend(&ab,seq,strlen(seq));
-
- /* Write the prompt and the current buffer content */
- abAppend(&ab,l->prompt,strlen(l->prompt));
- abAppend(&ab,l->buf,l->len);
-
- /* Show hits if any. */
- refreshShowHints(&ab,l,plen);
-
- /* If we are at the very end of the screen with our prompt, we need to
- * emit a newline and move the prompt to the first column. */
- if (l->pos &&
- l->pos == l->len &&
- (l->pos+plen) % l->cols == 0)
- {
- lndebug("<newline>");
- abAppend(&ab,"\n",1);
- snprintf(seq,64,"\r");
- abAppend(&ab,seq,strlen(seq));
- rows++;
- if (rows > (int)l->maxrows) l->maxrows = rows;
- }
-
- /* Move cursor to right position. */
- rpos2 = (plen+l->pos+l->cols)/l->cols; /* current cursor relative row. */
- lndebug("rpos2 %d", rpos2);
-
- /* Go up till we reach the expected positon. */
- if (rows-rpos2 > 0) {
- lndebug("go-up %d", rows-rpos2);
- snprintf(seq,64,"\x1b[%dA", rows-rpos2);
- abAppend(&ab,seq,strlen(seq));
- }
-
- /* Set column. */
- col = (plen+(int)l->pos) % (int)l->cols;
- lndebug("set col %d", 1+col);
- if (col)
- snprintf(seq,64,"\r\x1b[%dC", col);
- else
- snprintf(seq,64,"\r");
- abAppend(&ab,seq,strlen(seq));
-
- lndebug("\n");
- l->oldpos = l->pos;
-
- if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */
- abFree(&ab);
-}
-
-/* Calls the two low level functions refreshSingleLine() or
- * refreshMultiLine() according to the selected mode. */
-static void refreshLine(struct linenoiseState *l) {
- if (mlmode)
- refreshMultiLine(l);
- else
- refreshSingleLine(l);
-}
-
-/* Insert the character 'c' at cursor current position.
- *
- * On error writing to the terminal -1 is returned, otherwise 0. */
-int linenoiseEditInsert(struct linenoiseState *l, char c) {
- if (l->len < l->buflen) {
- if (l->len == l->pos) {
- l->buf[l->pos] = c;
- l->pos++;
- l->len++;
- l->buf[l->len] = '\0';
- if ((!mlmode && l->plen+l->len < l->cols && !hintsCallback)) {
- /* Avoid a full update of the line in the
- * trivial case. */
- if (write(l->ofd,&c,1) == -1) return -1;
- } else {
- refreshLine(l);
- }
- } else {
- memmove(l->buf+l->pos+1,l->buf+l->pos,l->len-l->pos);
- l->buf[l->pos] = c;
- l->len++;
- l->pos++;
- l->buf[l->len] = '\0';
- refreshLine(l);
- }
- }
- return 0;
-}
-
-/* Move cursor on the left. */
-void linenoiseEditMoveLeft(struct linenoiseState *l) {
- if (l->pos > 0) {
- l->pos--;
- refreshLine(l);
- }
-}
-
-/* Move cursor on the right. */
-void linenoiseEditMoveRight(struct linenoiseState *l) {
- if (l->pos != l->len) {
- l->pos++;
- refreshLine(l);
- }
-}
-
-/* Move cursor to the start of the line. */
-void linenoiseEditMoveHome(struct linenoiseState *l) {
- if (l->pos != 0) {
- l->pos = 0;
- refreshLine(l);
- }
-}
-
-/* Move cursor to the end of the line. */
-void linenoiseEditMoveEnd(struct linenoiseState *l) {
- if (l->pos != l->len) {
- l->pos = l->len;
- refreshLine(l);
- }
-}
-
-/* Substitute the currently edited line with the next or previous history
- * entry as specified by 'dir'. */
-#define LINENOISE_HISTORY_NEXT 0
-#define LINENOISE_HISTORY_PREV 1
-void linenoiseEditHistoryNext(struct linenoiseState *l, int dir) {
- if (history_len > 1) {
- /* Update the current history entry before to
- * overwrite it with the next one. */
- free(history[history_len - 1 - l->history_index]);
- history[history_len - 1 - l->history_index] = strdup(l->buf);
- /* Show the new entry */
- l->history_index += (dir == LINENOISE_HISTORY_PREV) ? 1 : -1;
- if (l->history_index < 0) {
- l->history_index = 0;
- return;
- } else if (l->history_index >= history_len) {
- l->history_index = history_len-1;
- return;
- }
- strncpy(l->buf,history[history_len - 1 - l->history_index],l->buflen);
- l->buf[l->buflen-1] = '\0';
- l->len = l->pos = strlen(l->buf);
- refreshLine(l);
- }
-}
-
-/* Delete the character at the right of the cursor without altering the cursor
- * position. Basically this is what happens with the "Delete" keyboard key. */
-void linenoiseEditDelete(struct linenoiseState *l) {
- if (l->len > 0 && l->pos < l->len) {
- memmove(l->buf+l->pos,l->buf+l->pos+1,l->len-l->pos-1);
- l->len--;
- l->buf[l->len] = '\0';
- refreshLine(l);
- }
-}
-
-/* Backspace implementation. */
-void linenoiseEditBackspace(struct linenoiseState *l) {
- if (l->pos > 0 && l->len > 0) {
- memmove(l->buf+l->pos-1,l->buf+l->pos,l->len-l->pos);
- l->pos--;
- l->len--;
- l->buf[l->len] = '\0';
- refreshLine(l);
- }
-}
-
-/* Delete the previosu word, maintaining the cursor at the start of the
- * current word. */
-void linenoiseEditDeletePrevWord(struct linenoiseState *l) {
- size_t old_pos = l->pos;
- size_t diff;
-
- while (l->pos > 0 && l->buf[l->pos-1] == ' ')
- l->pos--;
- while (l->pos > 0 && l->buf[l->pos-1] != ' ')
- l->pos--;
- diff = old_pos - l->pos;
- memmove(l->buf+l->pos,l->buf+old_pos,l->len-old_pos+1);
- l->len -= diff;
- refreshLine(l);
-}
-
-/* This function is the core of the line editing capability of linenoise.
- * It expects 'fd' to be already in "raw mode" so that every key pressed
- * will be returned ASAP to read().
- *
- * The resulting string is put into 'buf' when the user type enter, or
- * when ctrl+d is typed.
- *
- * The function returns the length of the current buffer. */
-static int linenoiseEdit(int stdin_fd, int stdout_fd, char *buf, size_t buflen, const char *prompt)
-{
- struct linenoiseState l;
-
- /* Populate the linenoise state that we pass to functions implementing
- * specific editing functionalities. */
- l.ifd = stdin_fd;
- l.ofd = stdout_fd;
- l.buf = buf;
- l.buflen = buflen;
- l.prompt = prompt;
- l.plen = strlen(prompt);
- l.oldpos = l.pos = 0;
- l.len = 0;
- l.cols = getColumns(stdin_fd, stdout_fd);
- l.maxrows = 0;
- l.history_index = 0;
-
- /* Buffer starts empty. */
- l.buf[0] = '\0';
- l.buflen--; /* Make sure there is always space for the nulterm */
-
- /* The latest history entry is always our current buffer, that
- * initially is just an empty string. */
- linenoiseHistoryAdd("");
-
- if (write(l.ofd,prompt,l.plen) == -1) return -1;
- while(1) {
- char c;
- int nread;
- char seq[3];
-
- nread = read(l.ifd,&c,1);
- if (nread <= 0) return l.len;
-
- /* Only autocomplete when the callback is set. It returns < 0 when
- * there was an error reading from fd. Otherwise it will return the
- * character that should be handled next. */
- if (c == 9 && completionCallback != NULL) {
- c = completeLine(&l);
- /* Return on errors */
- if (c < 0) return l.len;
- /* Read next character when 0 */
- if (c == 0) continue;
- }
-
- switch(c) {
- case ENTER: /* enter */
- history_len--;
- free(history[history_len]);
- if (mlmode) linenoiseEditMoveEnd(&l);
- if (hintsCallback) {
- /* Force a refresh without hints to leave the previous
- * line as the user typed it after a newline. */
- linenoiseHintsCallback *hc = hintsCallback;
- hintsCallback = NULL;
- refreshLine(&l);
- hintsCallback = hc;
- }
- return (int)l.len;
- case CTRL_C: /* ctrl-c */
- errno = EAGAIN;
- return -1;
- case BACKSPACE: /* backspace */
- case 8: /* ctrl-h */
- linenoiseEditBackspace(&l);
- break;
- case CTRL_D: /* ctrl-d, remove char at right of cursor, or if the
- line is empty, act as end-of-file. */
- if (l.len > 0) {
- linenoiseEditDelete(&l);
- } else {
- history_len--;
- free(history[history_len]);
- return -1;
- }
- break;
- case CTRL_T: /* ctrl-t, swaps current character with previous. */
- if (l.pos > 0 && l.pos < l.len) {
- int aux = buf[l.pos-1];
- buf[l.pos-1] = buf[l.pos];
- buf[l.pos] = aux;
- if (l.pos != l.len-1) l.pos++;
- refreshLine(&l);
- }
- break;
- case CTRL_B: /* ctrl-b */
- linenoiseEditMoveLeft(&l);
- break;
- case CTRL_F: /* ctrl-f */
- linenoiseEditMoveRight(&l);
- break;
- case CTRL_P: /* ctrl-p */
- linenoiseEditHistoryNext(&l, LINENOISE_HISTORY_PREV);
- break;
- case CTRL_N: /* ctrl-n */
- linenoiseEditHistoryNext(&l, LINENOISE_HISTORY_NEXT);
- break;
- case ESC: /* escape sequence */
- /* Read the next two bytes representing the escape sequence.
- * Use two calls to handle slow terminals returning the two
- * chars at different times. */
- if (read(l.ifd,seq,1) == -1) break;
- if (read(l.ifd,seq+1,1) == -1) break;
-
- /* ESC [ sequences. */
- if (seq[0] == '[') {
- if (seq[1] >= '0' && seq[1] <= '9') {
- /* Extended escape, read additional byte. */
- if (read(l.ifd,seq+2,1) == -1) break;
- if (seq[2] == '~') {
- switch(seq[1]) {
- case '3': /* Delete key. */
- linenoiseEditDelete(&l);
- break;
- }
- }
- } else {
- switch(seq[1]) {
- case 'A': /* Up */
- linenoiseEditHistoryNext(&l, LINENOISE_HISTORY_PREV);
- break;
- case 'B': /* Down */
- linenoiseEditHistoryNext(&l, LINENOISE_HISTORY_NEXT);
- break;
- case 'C': /* Right */
- linenoiseEditMoveRight(&l);
- break;
- case 'D': /* Left */
- linenoiseEditMoveLeft(&l);
- break;
- case 'H': /* Home */
- linenoiseEditMoveHome(&l);
- break;
- case 'F': /* End*/
- linenoiseEditMoveEnd(&l);
- break;
- }
- }
- }
-
- /* ESC O sequences. */
- else if (seq[0] == 'O') {
- switch(seq[1]) {
- case 'H': /* Home */
- linenoiseEditMoveHome(&l);
- break;
- case 'F': /* End*/
- linenoiseEditMoveEnd(&l);
- break;
- }
- }
- break;
- default:
- if (linenoiseEditInsert(&l,c)) return -1;
- break;
- case CTRL_U: /* Ctrl+u, delete the whole line. */
- buf[0] = '\0';
- l.pos = l.len = 0;
- refreshLine(&l);
- break;
- case CTRL_K: /* Ctrl+k, delete from current to end of line. */
- buf[l.pos] = '\0';
- l.len = l.pos;
- refreshLine(&l);
- break;
- case CTRL_A: /* Ctrl+a, go to the start of the line */
- linenoiseEditMoveHome(&l);
- break;
- case CTRL_E: /* ctrl+e, go to the end of the line */
- linenoiseEditMoveEnd(&l);
- break;
- case CTRL_L: /* ctrl+l, clear screen */
- linenoiseClearScreen();
- refreshLine(&l);
- break;
- case CTRL_W: /* ctrl+w, delete previous word */
- linenoiseEditDeletePrevWord(&l);
- break;
- }
- }
- return l.len;
-}
-
-/* This special mode is used by linenoise in order to print scan codes
- * on screen for debugging / development purposes. It is implemented
- * by the linenoise_example program using the --keycodes option. */
-void linenoisePrintKeyCodes(void) {
- char quit[4];
-
- printf("Linenoise key codes debugging mode.\n"
- "Press keys to see scan codes. Type 'quit' at any time to exit.\n");
- if (enableRawMode(STDIN_FILENO) == -1) return;
- memset(quit,' ',4);
- while(1) {
- char c;
- int nread;
-
- nread = read(STDIN_FILENO,&c,1);
- if (nread <= 0) continue;
- memmove(quit,quit+1,sizeof(quit)-1); /* shift string to left. */
- quit[sizeof(quit)-1] = c; /* Insert current char on the right. */
- if (memcmp(quit,"quit",sizeof(quit)) == 0) break;
-
- printf("'%c' %02x (%d) (type quit to exit)\n",
- isprint(c) ? c : '?', (int)c, (int)c);
- printf("\r"); /* Go left edge manually, we are in raw mode. */
- fflush(stdout);
- }
- disableRawMode(STDIN_FILENO);
-}
-
-/* This function calls the line editing function linenoiseEdit() using
- * the STDIN file descriptor set in raw mode. */
-static int linenoiseRaw(char *buf, size_t buflen, const char *prompt) {
- int count;
-
- if (buflen == 0) {
- errno = EINVAL;
- return -1;
- }
-
- if (enableRawMode(STDIN_FILENO) == -1) return -1;
- count = linenoiseEdit(STDIN_FILENO, STDOUT_FILENO, buf, buflen, prompt);
- disableRawMode(STDIN_FILENO);
- printf("\n");
- return count;
-}
-
-/* This function is called when linenoise() is called with the standard
- * input file descriptor not attached to a TTY. So for example when the
- * program using linenoise is called in pipe or with a file redirected
- * to its standard input. In this case, we want to be able to return the
- * line regardless of its length (by default we are limited to 4k). */
-static char *linenoiseNoTTY(void) {
- char *line = NULL;
- size_t len = 0, maxlen = 0;
-
- while(1) {
- if (len == maxlen) {
- if (maxlen == 0) maxlen = 16;
- maxlen *= 2;
- char *oldval = line;
- line = realloc(line,maxlen);
- if (line == NULL) {
- if (oldval) free(oldval);
- return NULL;
- }
- }
- int c = fgetc(stdin);
- if (c == EOF || c == '\n') {
- if (c == EOF && len == 0) {
- free(line);
- return NULL;
- } else {
- line[len] = '\0';
- return line;
- }
- } else {
- line[len] = c;
- len++;
- }
- }
-}
-
-/* The high level function that is the main API of the linenoise library.
- * This function checks if the terminal has basic capabilities, just checking
- * for a blacklist of stupid terminals, and later either calls the line
- * editing function or uses dummy fgets() so that you will be able to type
- * something even in the most desperate of the conditions. */
-char *linenoise(const char *prompt) {
- char buf[LINENOISE_MAX_LINE];
- int count;
-
- if (!isatty(STDIN_FILENO)) {
- /* Not a tty: read from file / pipe. In this mode we don't want any
- * limit to the line size, so we call a function to handle that. */
- return linenoiseNoTTY();
- } else if (isUnsupportedTerm()) {
- size_t len;
-
- printf("%s",prompt);
- fflush(stdout);
- if (fgets(buf,LINENOISE_MAX_LINE,stdin) == NULL) return NULL;
- len = strlen(buf);
- while(len && (buf[len-1] == '\n' || buf[len-1] == '\r')) {
- len--;
- buf[len] = '\0';
- }
- return strdup(buf);
- } else {
- count = linenoiseRaw(buf,LINENOISE_MAX_LINE,prompt);
- if (count == -1) return NULL;
- return strdup(buf);
- }
-}
-
-/* This is just a wrapper the user may want to call in order to make sure
- * the linenoise returned buffer is freed with the same allocator it was
- * created with. Useful when the main program is using an alternative
- * allocator. */
-void linenoiseFree(void *ptr) {
- free(ptr);
-}
-
-/* ================================ History ================================= */
-
-/* Free the history, but does not reset it. Only used when we have to
- * exit() to avoid memory leaks are reported by valgrind & co. */
-static void freeHistory(void) {
- if (history) {
- int j;
-
- for (j = 0; j < history_len; j++)
- free(history[j]);
- free(history);
- }
-}
-
-/* At exit we'll try to fix the terminal to the initial conditions. */
-static void linenoiseAtExit(void) {
- disableRawMode(STDIN_FILENO);
- freeHistory();
-}
-
-/* This is the API call to add a new entry in the linenoise history.
- * It uses a fixed array of char pointers that are shifted (memmoved)
- * when the history max length is reached in order to remove the older
- * entry and make room for the new one, so it is not exactly suitable for huge
- * histories, but will work well for a few hundred of entries.
- *
- * Using a circular buffer is smarter, but a bit more complex to handle. */
-int linenoiseHistoryAdd(const char *line) {
- char *linecopy;
-
- if (history_max_len == 0) return 0;
-
- /* Initialization on first call. */
- if (history == NULL) {
- history = malloc(sizeof(char*)*history_max_len);
- if (history == NULL) return 0;
- memset(history,0,(sizeof(char*)*history_max_len));
- }
-
- /* Don't add duplicated lines. */
- if (history_len && !strcmp(history[history_len-1], line)) return 0;
-
- /* Add an heap allocated copy of the line in the history.
- * If we reached the max length, remove the older line. */
- linecopy = strdup(line);
- if (!linecopy) return 0;
- if (history_len == history_max_len) {
- free(history[0]);
- memmove(history,history+1,sizeof(char*)*(history_max_len-1));
- history_len--;
- }
- history[history_len] = linecopy;
- history_len++;
- return 1;
-}
-
-/* Set the maximum length for the history. This function can be called even
- * if there is already some history, the function will make sure to retain
- * just the latest 'len' elements if the new history length value is smaller
- * than the amount of items already inside the history. */
-int linenoiseHistorySetMaxLen(int len) {
- char **new;
-
- if (len < 1) return 0;
- if (history) {
- int tocopy = history_len;
-
- new = malloc(sizeof(char*)*len);
- if (new == NULL) return 0;
-
- /* If we can't copy everything, free the elements we'll not use. */
- if (len < tocopy) {
- int j;
-
- for (j = 0; j < tocopy-len; j++) free(history[j]);
- tocopy = len;
- }
- memset(new,0,sizeof(char*)*len);
- memcpy(new,history+(history_len-tocopy), sizeof(char*)*tocopy);
- free(history);
- history = new;
- }
- history_max_len = len;
- if (history_len > history_max_len)
- history_len = history_max_len;
- return 1;
-}
-
-/* Save the history in the specified file. On success 0 is returned
- * otherwise -1 is returned. */
-int linenoiseHistorySave(const char *filename) {
- mode_t old_umask = umask(S_IXUSR|S_IRWXG|S_IRWXO);
- FILE *fp;
- int j;
-
- fp = fopen(filename,"w");
- umask(old_umask);
- if (fp == NULL) return -1;
- chmod(filename,S_IRUSR|S_IWUSR);
- for (j = 0; j < history_len; j++)
- fprintf(fp,"%s\n",history[j]);
- fclose(fp);
- return 0;
-}
-
-/* Load the history from the specified file. If the file does not exist
- * zero is returned and no operation is performed.
- *
- * If the file exists and the operation succeeded 0 is returned, otherwise
- * on error -1 is returned. */
-int linenoiseHistoryLoad(const char *filename) {
- FILE *fp = fopen(filename,"r");
- char buf[LINENOISE_MAX_LINE];
-
- if (fp == NULL) return -1;
-
- while (fgets(buf,LINENOISE_MAX_LINE,fp) != NULL) {
- char *p;
-
- p = strchr(buf,'\r');
- if (!p) p = strchr(buf,'\n');
- if (p) *p = '\0';
- linenoiseHistoryAdd(buf);
- }
- fclose(fp);
- return 0;
-}
diff --git a/subprojects/d2tk/linenoise/linenoise.h b/subprojects/d2tk/linenoise/linenoise.h
deleted file mode 100644
index ed20232..0000000
--- a/subprojects/d2tk/linenoise/linenoise.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/* linenoise.h -- VERSION 1.0
- *
- * Guerrilla line editing library against the idea that a line editing lib
- * needs to be 20,000 lines of C code.
- *
- * See linenoise.c for more information.
- *
- * ------------------------------------------------------------------------
- *
- * Copyright (c) 2010-2014, Salvatore Sanfilippo <antirez at gmail dot com>
- * Copyright (c) 2010-2013, Pieter Noordhuis <pcnoordhuis at gmail dot com>
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef __LINENOISE_H
-#define __LINENOISE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct linenoiseCompletions {
- size_t len;
- char **cvec;
-} linenoiseCompletions;
-
-typedef void(linenoiseCompletionCallback)(const char *, linenoiseCompletions *);
-typedef char*(linenoiseHintsCallback)(const char *, int *color, int *bold);
-typedef void(linenoiseFreeHintsCallback)(void *);
-void linenoiseSetCompletionCallback(linenoiseCompletionCallback *);
-void linenoiseSetHintsCallback(linenoiseHintsCallback *);
-void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback *);
-void linenoiseAddCompletion(linenoiseCompletions *, const char *);
-
-char *linenoise(const char *prompt);
-void linenoiseFree(void *ptr);
-int linenoiseHistoryAdd(const char *line);
-int linenoiseHistorySetMaxLen(int len);
-int linenoiseHistorySave(const char *filename);
-int linenoiseHistoryLoad(const char *filename);
-void linenoiseClearScreen(void);
-void linenoiseSetMultiLine(int ml);
-void linenoisePrintKeyCodes(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __LINENOISE_H */
diff --git a/subprojects/d2tk/meson.build b/subprojects/d2tk/meson.build
index cf79757..f4467e2 100644
--- a/subprojects/d2tk/meson.build
+++ b/subprojects/d2tk/meson.build
@@ -6,7 +6,29 @@ project('d2tk', 'c', default_options : [
'c_std=gnu11'])
static_link = false #meson.is_cross_build()
-build_debug = get_option('build-debug')
+
+build_debug_overlay = get_option('build-debug-overlay')
+build_examples = get_option('build-examples')
+build_tests = get_option('build-tests')
+
+use_backend_cairo = get_option('use-backend-cairo')
+use_backend_nanovg = get_option('use-backend-nanovg')
+use_frontend_fbdev = get_option('use-frontend-fbdev')
+use_frontend_pugl= get_option('use-frontend-pugl')
+
+use_vterm = get_option('use-vterm')
+use_evdev = get_option('use-evdev')
+use_fontconfig = get_option('use-fontconfig')
+
+grep = find_program('grep',
+ native : true,
+ required : use_fontconfig)
+fc_list = find_program('fc-list',
+ native : true,
+ required : use_fontconfig)
+check_for_font = find_program('check_for_font',
+ native : true,
+ required : use_fontconfig)
prefix = get_option('prefix')
datadir = get_option('datadir')
@@ -18,35 +40,74 @@ add_project_arguments('-DD2TK_DATA_DIR="'+pdatadir+'"', language : 'c')
cc = meson.get_compiler('c')
+# mandatory dependencies
m_dep = cc.find_library('m')
-util_dep = cc.find_library('util', required : false)
-freetype_dep = dependency('freetype2', version : '>=18.0.0',
- static : static_link, required : false)
-pixman_dep = dependency('pixman-1', version : '>=0.34.0',
- static : static_link, required : false)
-cairo_dep = dependency('cairo', version : '>=1.14.0',
- static : static_link, required : false)
-cairo_xlib_dep = dependency('cairo-xlib', version : '>=1.14.0',
- static : static_link, required : false)
-evdev_dep = dependency('libevdev', version : '>=1.5.0',
- static : static_link, required : false)
-input_dep = dependency('libinput', version : '>=1.6.0',
- static : static_link, required : false)
-udev_dep = dependency('libudev', version : '>=220',
- static : static_link, required : false)
-glew_dep = dependency('glew', version : '>=2.1.0',
- static : static_link, required : false)
-vterm_dep = dependency('vterm', version : '>=0.1',
- static : static_link, required : false)
-
-if not glew_dep.found()
+
+# dependencies for backend_cairo/frontend_pugl
+freetype_dep = dependency('freetype2',
+ version : '>=18.0.0',
+ static : static_link,
+ required : use_backend_cairo)
+pixman_dep = dependency('pixman-1',
+ version : '>=0.34.0',
+ static : static_link,
+ required : use_backend_cairo)
+cairo_dep = dependency('cairo',
+ version : '>=1.14.0',
+ static : static_link,
+ required : use_backend_cairo)
+cairo_deps = [freetype_dep, pixman_dep, cairo_dep]
+if use_frontend_pugl.enabled()
+ cairo_xlib_dep = dependency('cairo-xlib',
+ version : '>=1.14.0',
+ static : static_link,
+ required : use_backend_cairo)
+endif
+
+# dependencies for frontend_fbdev
+input_dep = dependency('libinput',
+ version : '>=1.6.0',
+ static : static_link,
+ required : use_frontend_fbdev)
+udev_dep = dependency('libudev',
+ static : static_link,
+ required : use_frontend_fbdev)
+evdev_dep = dependency('libevdev',
+ version : '>=1.5.0',
+ static : static_link,
+ required : use_frontend_fbdev)
+
+# dependencies for backend_nanovg
+glew_dep = dependency('glew',
+ version : '>=2.1.0',
+ static : static_link,
+ required : false)
+if use_backend_nanovg.enabled() and not glew_dep.found()
# use embedded glew
glew_dep = declare_dependency(
include_directories : include_directories('glew-2.1.0'),
sources : join_paths('glew-2.1.0', 'glew.c'))
endif
-deps = [m_dep, evdev_dep, vterm_dep]
+# optional dependencies
+util_dep = cc.find_library('util',
+ required : use_vterm)
+vterm_dep = dependency('vterm',
+ version : '>=0.1',
+ static : static_link,
+ required : use_vterm)
+if not use_frontend_fbdev.enabled()
+ evdev_dep = dependency('libevdev',
+ version : '>=1.5.0',
+ static : static_link,
+ required : use_evdev)
+endif
+fontconfig_dep = dependency('fontconfig',
+ version : '>=2.0.0',
+ static : static_link,
+ required : use_fontconfig)
+
+deps = [m_dep, evdev_dep, vterm_dep, fontconfig_dep]
links = []
pugl_inc = include_directories('pugl')
@@ -63,7 +124,7 @@ conf_data.set('MICRO_VERSION', version[2])
add_project_arguments('-D_GNU_SOURCE', language : 'c')
-if build_debug
+if build_debug_overlay
add_project_arguments('-DD2TK_DEBUG', language : 'c')
endif
@@ -87,20 +148,22 @@ lib_srcs = [
join_paths('src', 'base_label.c'),
join_paths('src', 'base_link.c'),
join_paths('src', 'base_dial.c'),
+ join_paths('src', 'base_spinner.c'),
+ join_paths('src', 'base_bar.c'),
join_paths('src', 'base_flowmatrix.c')
]
-if vterm_dep.found()
+if use_vterm.enabled()
conf_data.set('D2TK_PTY', 1)
lib_srcs += join_paths('src', 'base_pty.c')
- lib_srcs += join_paths('linenoise', 'linenoise.c')
deps += util_dep
else
conf_data.set('D2TK_PTY', 0)
endif
-if evdev_dep.found()
+if use_evdev.enabled()
conf_data.set('D2TK_EVDEV', 1)
+ lib_srcs += join_paths('src', 'base_vkb.c')
else
conf_data.set('D2TK_EVDEV', 0)
endif
@@ -111,10 +174,24 @@ else
conf_data.set('D2TK_INPUT_1_15', 0)
endif
-bin_srcs = [
+if use_fontconfig.enabled()
+ conf_data.set('D2TK_FONTCONFIG', 1)
+else
+ conf_data.set('D2TK_FONTCONFIG', 0)
+endif
+
+example_srcs = [
join_paths('example', 'example.c')
]
+example_pugl_srcs = [
+ join_paths('example', 'd2tk_pugl.c')
+]
+
+example_fbdev_srcs = [
+ join_paths('example', 'd2tk_fbdev.c')
+]
+
pugl_srcs = [
join_paths('src', 'frontend_pugl.c'),
join_paths('pugl', 'pugl', 'detail', 'implementation.c')
@@ -124,10 +201,6 @@ pugl_gl_srcs = []
pugl_cairo_srcs = []
-pugl_bin_srcs = [
- join_paths('example', 'd2tk_pugl.c')
-]
-
nanovg_srcs = [
join_paths('nanovg', 'src', 'nanovg.c'),
join_paths('src', 'backend_nanovg.c')
@@ -141,10 +214,6 @@ fbdev_srcs = [
join_paths('src', 'frontend_fbdev.c')
]
-fbdev_bin_srcs = [
- join_paths('example', 'd2tk_fbdev.c')
-]
-
test_core_srcs = [
join_paths('test', 'core.c'),
join_paths('test', 'mock.c')
@@ -160,9 +229,9 @@ c_args = ['-fvisibility=hidden',
if host_machine.system() == 'windows'
add_project_arguments('-DGLEW_STATIC', language : 'c')
- deps += cc.find_library('opengl32')
- deps += cc.find_library('gdi32')
- deps += cc.find_library('ws2_32')
+ deps += cc.find_library('opengl32', required : use_frontend_pugl)
+ deps += cc.find_library('gdi32', required : use_frontend_pugl)
+ deps += cc.find_library('ws2_32', required : true)
pugl_srcs += 'pugl/pugl/detail/win.c'
pugl_gl_srcs += 'pugl/pugl/detail/win_gl.c'
pugl_cairo_srcs += 'pugl/pugl/detail/win_cairo.c'
@@ -174,126 +243,146 @@ elif host_machine.system() == 'darwin'
pugl_gl_srcs += 'pugl/pugl/detail/mac_gl.m'
pugl_cairo_srcs += 'pugl/pugl/detail/mac_cairo.m'
else
- deps += dependency('gl')
- deps += dependency('x11', version : '>=1.6.0')
- deps += dependency('xext', version : '>=1.3.0')
+ deps += dependency('gl', required : use_frontend_pugl)
+ deps += dependency('x11', version : '>=1.6.0', required : use_frontend_pugl)
+ deps += dependency('xext', version : '>=1.3.0', required : use_frontend_pugl)
pugl_srcs += 'pugl/pugl/detail/x11.c'
pugl_gl_srcs += 'pugl/pugl/detail/x11_gl.c'
pugl_cairo_srcs += 'pugl/pugl/detail/x11_cairo.c'
endif
-if freetype_dep.found() and pixman_dep.found() and cairo_dep.found() and cairo_xlib_dep.found() and (host_machine.system() == 'linux')
- d2tk_cairo = declare_dependency(
- compile_args : '-DPUGL_HAVE_CAIRO',
- include_directories : inc_dir,
- dependencies : [deps, freetype_dep, pixman_dep, cairo_dep, cairo_xlib_dep],
- link_args : links,
- sources : [lib_srcs, cairo_srcs, pugl_srcs, pugl_cairo_srcs])
-
- executable('d2tk.cairo', [bin_srcs, pugl_bin_srcs],
- c_args : c_args,
- include_directories : inc_dir,
- dependencies: d2tk_cairo,
- install : false)
+if use_backend_cairo.enabled()
+ if use_frontend_pugl.enabled()
+ d2tk_cairo = declare_dependency(
+ compile_args : '-DPUGL_HAVE_CAIRO',
+ include_directories : inc_dir,
+ dependencies : [deps, cairo_deps, cairo_xlib_dep],
+ link_args : links,
+ sources : [lib_srcs, cairo_srcs, pugl_srcs, pugl_cairo_srcs])
+
+ if build_examples
+ executable('d2tk.cairo', [example_srcs, example_pugl_srcs],
+ c_args : c_args,
+ include_directories : inc_dir,
+ dependencies: d2tk_cairo,
+ install : false)
+ endif
+ endif
- if input_dep.found() and udev_dep.found() and evdev_dep.found()
+ if use_frontend_fbdev.enabled()
d2tk_fbdev = declare_dependency(
include_directories : inc_dir,
- dependencies : [deps, freetype_dep, pixman_dep, cairo_dep, input_dep, udev_dep],
+ dependencies : [deps, cairo_deps, input_dep, udev_dep, evdev_dep],
link_args : links,
sources : [lib_srcs, cairo_srcs, fbdev_srcs])
- executable('d2tk.fbdev', [bin_srcs, fbdev_bin_srcs],
- c_args : c_args,
- include_directories : inc_dir,
- dependencies: d2tk_fbdev,
- install : false)
+ if build_examples
+ executable('d2tk.fbdev', [example_srcs, example_fbdev_srcs],
+ c_args : c_args,
+ include_directories : inc_dir,
+ dependencies: d2tk_fbdev,
+ install : false)
+ endif
endif
endif
-d2tk_nanovg = declare_dependency(
- include_directories : inc_dir,
- dependencies : [deps, glew_dep],
- link_args : links,
- sources : [lib_srcs, nanovg_srcs, pugl_srcs, pugl_gl_srcs])
-
-executable('d2tk.nanovg', [bin_srcs, pugl_bin_srcs],
- c_args : c_args,
- include_directories : inc_dir,
- dependencies: d2tk_nanovg,
- install : false)
+if use_backend_nanovg.enabled()
+ if use_frontend_pugl.enabled()
+ d2tk_nanovg = declare_dependency(
+ include_directories : inc_dir,
+ dependencies : [deps, glew_dep],
+ link_args : links,
+ sources : [lib_srcs, nanovg_srcs, pugl_srcs, pugl_gl_srcs])
+
+ if build_examples
+ executable('d2tk.nanovg', [example_srcs, example_pugl_srcs],
+ c_args : c_args,
+ include_directories : inc_dir,
+ dependencies: d2tk_nanovg,
+ install : false)
+ endif
+ endif
+endif
-configure_file(
+config_h = configure_file(
input : join_paths('d2tk', 'config.h.in'),
output : 'config.h',
configuration : conf_data,
install : false)
-configure_file(
- input : join_paths('ttf', 'FiraSans-Bold.ttf'),
- output : 'FiraSans-Bold.ttf',
- copy : true,
- install : false)
+if not use_fontconfig.enabled()
+ fira_sans_bold_ttf = configure_file(
+ input : join_paths('ttf', 'FiraSans-Bold.ttf'),
+ output : 'FiraSans:bold.ttf',
+ copy : true,
+ install : false)
-configure_file(
- input : join_paths('ttf', 'FiraMono-Bold.ttf'),
- output : 'FiraMono-Bold.ttf',
- copy : true,
- install : false)
+ fira_code_bold_ttf = configure_file(
+ input : join_paths('ttf', 'FiraCode-Bold.ttf'),
+ output : 'FiraCode:bold.ttf',
+ copy : true,
+ install : false)
-configure_file(
- input : join_paths('ttf', 'FiraCode-Bold.ttf'),
- output : 'FiraCode-Bold.ttf',
- copy : true,
- install : false)
+ fira_code_light_ttf = configure_file(
+ input : join_paths('ttf', 'FiraCode-Light.ttf'),
+ output : 'FiraCode:light.ttf',
+ copy : true,
+ install : false)
-configure_file(
- input : join_paths('ttf', 'FiraCode-Light.ttf'),
- output : 'FiraCode-Light.ttf',
- copy : true,
- install : false)
+ fira_code_medium_ttf = configure_file(
+ input : join_paths('ttf', 'FiraCode-Medium.ttf'),
+ output : 'FiraCode:medium.ttf',
+ copy : true,
+ install : false)
-configure_file(
- input : join_paths('ttf', 'FiraCode-Medium.ttf'),
- output : 'FiraCode-Medium.ttf',
- copy : true,
- install : false)
+ fira_code_regular_ttf = configure_file(
+ input : join_paths('ttf', 'FiraCode-Regular.ttf'),
+ output : 'FiraCode:regular.ttf',
+ copy : true,
+ install : false)
+endif
-configure_file(
- input : join_paths('ttf', 'FiraCode-Regular.ttf'),
- output : 'FiraCode-Regular.ttf',
- copy : true,
- install : false)
+if build_examples
+ configure_file(
+ input : join_paths('example', 'libre-arrow-circle-right.png'),
+ output : 'libre-arrow-circle-right.png',
+ copy : true,
+ install : false)
-configure_file(
- input : join_paths('example', 'libre-arrow-circle-right.png'),
- output : 'libre-arrow-circle-right.png',
- copy : true,
- install : false)
+ configure_file(
+ input : join_paths('example', 'libre-gui-folder.png'),
+ output : 'libre-gui-folder.png',
+ copy : true,
+ install : false)
-configure_file(
- input : join_paths('example', 'libre-gui-folder.png'),
- output : 'libre-gui-folder.png',
- copy : true,
- install : false)
+ configure_file(
+ input : join_paths('example', 'libre-gui-file.png'),
+ output : 'libre-gui-file.png',
+ copy : true,
+ install : false)
+endif
-configure_file(
- input : join_paths('example', 'libre-gui-file.png'),
- output : 'libre-gui-file.png',
- copy : true,
- install : false)
+if build_tests
+ test_core = executable('test.core', [test_core_srcs, lib_srcs],
+ c_args : c_args,
+ dependencies : deps,
+ include_directories : inc_dir,
+ install : false)
-test_core = executable('test.core', [test_core_srcs, lib_srcs],
- c_args : c_args,
- dependencies : deps,
- include_directories : inc_dir,
- install : false)
+ test_base = executable('test.base', [test_base_srcs, lib_srcs],
+ c_args : c_args,
+ dependencies : deps,
+ include_directories : inc_dir,
+ install : false)
-test_base = executable('test.base', [test_base_srcs, lib_srcs],
- c_args : c_args,
- dependencies : deps,
- include_directories : inc_dir,
- install : false)
+ test('Test core', test_core)
+ test('Test base', test_base)
-test('Test core', test_core)
-test('Test base', test_base)
+ if fc_list.found() and grep.found() and check_for_font.found()
+ test('FiraSans-Bold.ttf', check_for_font, args : ['FiraSans-Bold.ttf'])
+ test('FiraCode-Light.ttf', check_for_font, args : ['FiraCode-Light.tt'])
+ test('FiraCode-Regular.ttf', check_for_font, args : ['FiraCode-Regular.ttf'])
+ test('FiraCode-Medium.ttf', check_for_font, args : ['FiraCode-Medium.ttf'])
+ test('FiraCode-Bold.ttf', check_for_font, args : ['FiraCode-Bold.ttf'])
+ endif
+endif
diff --git a/subprojects/d2tk/meson_options.txt b/subprojects/d2tk/meson_options.txt
index a658483..6396503 100644
--- a/subprojects/d2tk/meson_options.txt
+++ b/subprojects/d2tk/meson_options.txt
@@ -1 +1,43 @@
-option('build-debug', type : 'boolean', value : false)
+option('build-debug-overlay',
+ type : 'boolean',
+ value : false,
+ yield : true)
+option('build-examples',
+ type : 'boolean',
+ value : false,
+ yield : true)
+option('build-tests',
+ type : 'boolean',
+ value : true,
+ yield : true)
+
+option('use-backend-cairo',
+ type : 'feature',
+ value : 'disabled',
+ yield : true)
+option('use-backend-nanovg',
+ type : 'feature',
+ value : 'disabled',
+ yield : true)
+
+option('use-frontend-fbdev',
+ type : 'feature',
+ value : 'disabled',
+ yield : true)
+option('use-frontend-pugl',
+ type : 'feature',
+ value : 'disabled',
+ yield : true)
+
+option('use-vterm',
+ type : 'feature',
+ value : 'disabled',
+ yield : true)
+option('use-evdev',
+ type : 'feature',
+ value : 'disabled',
+ yield : true)
+option('use-fontconfig',
+ type : 'feature',
+ value : 'disabled',
+ yield : true)
diff --git a/subprojects/d2tk/src/backend_cairo.c b/subprojects/d2tk/src/backend_cairo.c
index 14d3d81..95db476 100644
--- a/subprojects/d2tk/src/backend_cairo.c
+++ b/subprojects/d2tk/src/backend_cairo.c
@@ -576,13 +576,12 @@ d2tk_cairo_process(void *data, d2tk_core_t *core, const d2tk_com_t *com,
if(!*sprite)
{
- char *ft_path = NULL;
- assert(asprintf(&ft_path, "%s%s", backend->bundle_path, body->face) != -1);
- assert(ft_path);
+ char ft_path [1024];
+ d2tk_core_get_font_path(core, backend->bundle_path, body->face,
+ sizeof(ft_path), ft_path);
FT_Face ft_face = NULL;
FT_New_Face(backend->library, ft_path, 0, &ft_face);
- free(ft_path);
assert(ft_face);
cairo_font_face_t *face = cairo_ft_font_face_create_for_ft_face(ft_face, 0);
@@ -610,7 +609,6 @@ d2tk_cairo_process(void *data, d2tk_core_t *core, const d2tk_com_t *com,
cairo_text_extents_t extents;
cairo_text_extents(ctx, body->text, &extents);
int32_t x = -extents.x_bearing;
- int32_t y = -extents.y_bearing;
if(body->align & D2TK_ALIGN_LEFT)
{
@@ -627,19 +625,21 @@ d2tk_cairo_process(void *data, d2tk_core_t *core, const d2tk_com_t *com,
x -= extents.width;
}
+ cairo_font_extents_t font_extents;
+ cairo_font_extents(ctx, &font_extents);
+ double y = 0;
+
if(body->align & D2TK_ALIGN_TOP)
{
- y += body->y;
+ y += body->y + font_extents.ascent;
}
else if(body->align & D2TK_ALIGN_MIDDLE)
{
- y += body->y + body->h / 2;
- y -= extents.height / 2;
+ y += body->y + body->h / 2 + font_extents.descent;
}
else if(body->align & D2TK_ALIGN_BOTTOM)
{
y += body->y + body->h;
- y -= extents.height;
}
cairo_move_to(ctx, x + xo, y + yo);
diff --git a/subprojects/d2tk/src/backend_nanovg.c b/subprojects/d2tk/src/backend_nanovg.c
index 247e4eb..4e4dbb6 100644
--- a/subprojects/d2tk/src/backend_nanovg.c
+++ b/subprojects/d2tk/src/backend_nanovg.c
@@ -657,12 +657,11 @@ d2tk_nanovg_process(void *data, d2tk_core_t *core, const d2tk_com_t *com,
if(!*sprite)
{
- char *ft_path = NULL;
- assert(asprintf(&ft_path, "%s%s", backend->bundle_path, body->face) != -1);
- assert(ft_path);
+ char ft_path [1024];
+ d2tk_core_get_font_path(core, backend->bundle_path, body->face,
+ sizeof(ft_path), ft_path);
const int face = nvgCreateFont(ctx, body->face, ft_path);
- free(ft_path);
assert(face != -1);
*sprite = (uintptr_t)face;
diff --git a/subprojects/d2tk/src/base.c b/subprojects/d2tk/src/base.c
index 63c11f7..c12e9be 100644
--- a/subprojects/d2tk/src/base.c
+++ b/subprojects/d2tk/src/base.c
@@ -129,6 +129,12 @@ _d2tk_base_get_atom(d2tk_base_t *base, d2tk_id_t id, d2tk_atom_type_t type,
len = d2tk_atom_body_pty_sz;
} break;
#endif
+#if D2TK_EVDEV
+ case D2TK_ATOM_VKB:
+ {
+ len = d2tk_atom_body_vkb_sz;
+ } break;
+#endif
case D2TK_ATOM_FLOW_NODE:
// fall-through
case D2TK_ATOM_FLOW_ARC:
@@ -467,6 +473,15 @@ d2tk_base_is_active_hot(d2tk_base_t *base, d2tk_id_t id,
bool newfocus = curfocus;
const bool lastfocus = _d2tk_flip_equal_old(&base->focusitem, id);
+ // test for mouse up
+ if( is_active
+ && !d2tk_base_get_butmask(base, D2TK_BUTMASK_LEFT, false) )
+ {
+ _d2tk_flip_clear(&base->activeitem);
+ is_active = false;
+ state |= D2TK_STATE_UP;
+ }
+
// handle forward focus
if(curfocus)
{
@@ -505,11 +520,19 @@ d2tk_base_is_active_hot(d2tk_base_t *base, d2tk_id_t id,
}
}
- if(d2tk_base_get_keymask(base, D2TK_KEYMASK_ENTER, false))
+ if(d2tk_base_get_keymask_up(base, D2TK_KEYMASK_ENTER))
+ {
+ is_active = false;
+ }
+ else if(d2tk_base_get_keymask_down(base, D2TK_KEYMASK_ENTER))
{
is_active = true;
state |= D2TK_STATE_ENTER;
}
+ else if(d2tk_base_get_keymask(base, D2TK_KEYMASK_ENTER, false))
+ {
+ is_active = true;
+ }
}
else if(!base->focused)
{
@@ -518,15 +541,6 @@ d2tk_base_is_active_hot(d2tk_base_t *base, d2tk_id_t id,
base->focused = true; // set focused flag
}
- // test for mouse up
- if( is_active
- && !d2tk_base_get_butmask(base, D2TK_BUTMASK_LEFT, false) )
- {
- _d2tk_flip_clear(&base->activeitem);
- is_active = false;
- state |= D2TK_STATE_UP;
- }
-
// test for mouse over
if(d2tk_base_is_hit(base, rect))
{
@@ -644,11 +658,13 @@ d2tk_base_is_active_hot(d2tk_base_t *base, d2tk_id_t id,
#define light_orange 0xffcf00ff
#define dark_orange 0xcf9f00ff
+#define FONT_SANS_BOLD "FiraSans:bold"
+
D2TK_API const d2tk_style_t *
d2tk_base_get_default_style()
{
static const d2tk_style_t style = {
- .font_face = "FiraSans-Bold.ttf",
+ .font_face = FONT_SANS_BOLD,
.border_width = 1,
.padding = 1,
.rounding = 4,
@@ -797,6 +813,9 @@ d2tk_base_post(d2tk_base_t *base)
base->focused = false;
}
+ base->mouse.mask_prev = base->mouse.mask;
+ base->keys.mask_prev = base->keys.mask;
+
_d2tk_base_clear_chars(base);
d2tk_core_post(base->core);
@@ -919,6 +938,29 @@ d2tk_base_get_butmask(d2tk_base_t *base, d2tk_butmask_t mask, bool clear)
}
D2TK_API bool
+d2tk_base_get_butmask_prev(d2tk_base_t *base, d2tk_butmask_t mask)
+{
+ const bool old_state = (base->mouse.mask_prev & mask) == mask;
+
+ return old_state;
+
+}
+
+D2TK_API bool
+d2tk_base_get_butmask_down(d2tk_base_t *base, d2tk_butmask_t mask)
+{
+ return !d2tk_base_get_butmask_prev(base, mask)
+ && d2tk_base_get_butmask(base, mask, false);
+}
+
+D2TK_API bool
+d2tk_base_get_butmask_up(d2tk_base_t *base, d2tk_butmask_t mask)
+{
+ return d2tk_base_get_butmask_prev(base, mask)
+ && !d2tk_base_get_butmask(base, mask, false);
+}
+
+D2TK_API bool
d2tk_base_set_modmask(d2tk_base_t *base, d2tk_modmask_t mask, bool down)
{
const bool old_state = (base->keys.mod & mask) == mask;
@@ -980,6 +1022,28 @@ d2tk_base_get_keymask(d2tk_base_t *base, d2tk_keymask_t mask, bool clear)
}
+D2TK_API bool
+d2tk_base_get_keymask_prev(d2tk_base_t *base, d2tk_keymask_t mask)
+{
+ const bool old_state = (base->keys.mask_prev & mask) == mask;
+
+ return old_state;
+}
+
+D2TK_API bool
+d2tk_base_get_keymask_down(d2tk_base_t *base, d2tk_keymask_t mask)
+{
+ return !d2tk_base_get_keymask_prev(base, mask)
+ && d2tk_base_get_keymask(base, mask, false);
+}
+
+D2TK_API bool
+d2tk_base_get_keymask_up(d2tk_base_t *base, d2tk_keymask_t mask)
+{
+ return d2tk_base_get_keymask_prev(base, mask)
+ && !d2tk_base_get_keymask(base, mask, false);
+}
+
D2TK_API void
d2tk_base_set_dimensions(d2tk_base_t *base, d2tk_coord_t w, d2tk_coord_t h)
{
diff --git a/subprojects/d2tk/src/base_bar.c b/subprojects/d2tk/src/base_bar.c
new file mode 100644
index 0000000..61c9e1c
--- /dev/null
+++ b/subprojects/d2tk/src/base_bar.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2018-2019 Hanspeter Portner (dev@open-music-kontrollers.ch)
+ *
+ * This is free software: you can redistribute it and/or modify
+ * it under the terms of the Artistic License 2.0 as published by
+ * The Perl Foundation.
+ *
+ * This source is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Artistic License 2.0 for more details.
+ *
+ * You should have received a copy of the Artistic License 2.0
+ * along the source as a COPYING file. If not, obtain it from
+ * http://www.perlfoundation.org/artistic_license_2_0.
+ */
+
+#include <inttypes.h>
+#include <math.h>
+#include <stdio.h>
+
+#include "base_internal.h"
+
+static inline void
+_d2tk_base_draw_bar(d2tk_core_t *core, const d2tk_rect_t *rect,
+ d2tk_state_t state, const d2tk_style_t *style, float rel)
+{
+ const d2tk_hash_dict_t dict [] = {
+ { rect, sizeof(d2tk_rect_t) },
+ { &state , sizeof(d2tk_state_t) },
+ { style, sizeof(d2tk_style_t) },
+ { &rel, sizeof(float) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
+
+ D2TK_CORE_WIDGET(core, hash, widget)
+ {
+ d2tk_rect_t bnd_outer;
+ d2tk_rect_t bnd_inner;
+ d2tk_rect_shrink(&bnd_outer, rect, style->padding);
+ d2tk_rect_shrink(&bnd_inner, &bnd_outer, 2*style->padding);
+
+ d2tk_triple_t triple = D2TK_TRIPLE_NONE;
+ d2tk_triple_t triple_active = D2TK_TRIPLE_ACTIVE;
+ d2tk_triple_t triple_inactive = D2TK_TRIPLE_NONE;
+
+ if(d2tk_state_is_active(state))
+ {
+ triple |= D2TK_TRIPLE_ACTIVE;
+ }
+
+ if(d2tk_state_is_hot(state))
+ {
+ triple |= D2TK_TRIPLE_HOT;
+ triple_active |= D2TK_TRIPLE_HOT;
+ triple_inactive |= D2TK_TRIPLE_HOT;
+ }
+
+ if(d2tk_state_is_focused(state))
+ {
+ triple |= D2TK_TRIPLE_FOCUS;
+ triple_active |= D2TK_TRIPLE_FOCUS;
+ triple_inactive |= D2TK_TRIPLE_FOCUS;
+ }
+
+ {
+ const size_t ref = d2tk_core_bbox_push(core, true, rect);
+
+ d2tk_core_begin_path(core);
+ d2tk_core_rounded_rect(core, &bnd_inner, style->rounding);
+ d2tk_core_color(core, style->fill_color[triple_inactive]);
+ d2tk_core_stroke_width(core, 0);
+ d2tk_core_fill(core);
+
+ bnd_inner.w *= rel;
+
+ d2tk_core_begin_path(core);
+ d2tk_core_rounded_rect(core, &bnd_inner, style->rounding);
+ d2tk_core_color(core, style->fill_color[triple_active]);
+ d2tk_core_stroke_width(core, 0);
+ d2tk_core_fill(core);
+
+ d2tk_core_begin_path(core);
+ d2tk_core_rounded_rect(core, &bnd_outer, style->rounding);
+ d2tk_core_color(core, style->stroke_color[triple]);
+ d2tk_core_stroke_width(core, style->border_width);
+ d2tk_core_stroke(core);
+
+ d2tk_core_bbox_pop(core, ref);
+ }
+ }
+}
+
+D2TK_API d2tk_state_t
+d2tk_base_bar_int32(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
+ int32_t min, int32_t *value, int32_t max)
+{
+ d2tk_state_t state = d2tk_base_is_active_hot(base, id, rect,
+ D2TK_FLAG_SCROLL);
+
+ const int32_t oldvalue = *value;
+
+ if(d2tk_state_is_scroll_up(state))
+ {
+ *value += base->scroll.ody;
+ d2tk_clip_int32(min, value, max);
+ }
+ else if(d2tk_state_is_scroll_down(state))
+ {
+ *value += base->scroll.ody;
+ d2tk_clip_int32(min, value, max);
+ }
+ else if(d2tk_state_is_motion(state))
+ {
+ const int32_t adx = abs(base->mouse.dx);
+ const int32_t ady = abs(base->mouse.dy);
+ const int32_t adz = adx > ady ? base->mouse.dx : -base->mouse.dy;
+
+ *value += adz;
+ d2tk_clip_int32(min, value, max);
+ }
+
+ if(oldvalue != *value)
+ {
+ state |= D2TK_STATE_CHANGED;
+ }
+
+ float rel = (float)(*value - min) / (max - min);
+ d2tk_clip_float(0.f, &rel, 1.f);
+
+ _d2tk_base_draw_bar(base->core, rect, state, d2tk_base_get_style(base), rel);
+
+ return state;
+}
diff --git a/subprojects/d2tk/src/base_button.c b/subprojects/d2tk/src/base_button.c
index bd0df6c..244e7d1 100644
--- a/subprojects/d2tk/src/base_button.c
+++ b/subprojects/d2tk/src/base_button.c
@@ -164,8 +164,9 @@ d2tk_base_button(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect)
}
D2TK_API d2tk_state_t
-d2tk_base_toggle_label(d2tk_base_t *base, d2tk_id_t id, ssize_t lbl_len,
- const char *lbl, d2tk_align_t align, const d2tk_rect_t *rect, bool *value)
+d2tk_base_toggle_label_image(d2tk_base_t *base, d2tk_id_t id, ssize_t lbl_len,
+ const char *lbl, d2tk_align_t align, ssize_t path_len, const char *path,
+ const d2tk_rect_t *rect, bool *value)
{
d2tk_state_t state = d2tk_base_is_active_hot(base, id, rect, D2TK_FLAG_NONE);
@@ -192,13 +193,21 @@ d2tk_base_toggle_label(d2tk_base_t *base, d2tk_id_t id, ssize_t lbl_len,
triple |= D2TK_TRIPLE_FOCUS;
}
- _d2tk_base_draw_button(base->core, lbl_len, lbl, align, 0, NULL, rect, triple,
- d2tk_base_get_style(base));
+ _d2tk_base_draw_button(base->core, lbl_len, lbl, align, path_len, path, rect,
+ triple, d2tk_base_get_style(base));
return state;
}
D2TK_API d2tk_state_t
+d2tk_base_toggle_label(d2tk_base_t *base, d2tk_id_t id, ssize_t lbl_len,
+ const char *lbl, d2tk_align_t align, const d2tk_rect_t *rect, bool *value)
+{
+ return d2tk_base_toggle_label_image(base, id, lbl_len, lbl, align, 0, NULL,
+ rect, value);
+}
+
+D2TK_API d2tk_state_t
d2tk_base_toggle(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
bool *value)
{
diff --git a/subprojects/d2tk/src/base_internal.h b/subprojects/d2tk/src/base_internal.h
index 31ad648..e17b5a4 100644
--- a/subprojects/d2tk/src/base_internal.h
+++ b/subprojects/d2tk/src/base_internal.h
@@ -34,6 +34,9 @@ typedef enum _d2tk_atom_type_t {
#if D2TK_PTY
D2TK_ATOM_PTY,
#endif
+#if D2TK_EVDEV
+ D2TK_ATOM_VKB,
+#endif
} d2tk_atom_type_t;
typedef enum _d2tk_atom_event_type_t {
@@ -74,6 +77,7 @@ struct _d2tk_base_t {
d2tk_coord_t dx;
d2tk_coord_t dy;
d2tk_butmask_t mask;
+ d2tk_butmask_t mask_prev;
} mouse;
struct {
@@ -88,6 +92,7 @@ struct _d2tk_base_t {
utf8_int32_t chars [32];
unsigned keymod;
d2tk_keymask_t mask;
+ d2tk_keymask_t mask_prev;
d2tk_modmask_t mod;
} keys;
@@ -113,6 +118,9 @@ extern const size_t d2tk_atom_body_scroll_sz;
#if D2TK_PTY
extern const size_t d2tk_atom_body_pty_sz;
#endif
+#if D2TK_EVDEV
+extern const size_t d2tk_atom_body_vkb_sz;
+#endif
void *
_d2tk_base_get_atom(d2tk_base_t *base, d2tk_id_t id, d2tk_atom_type_t type,
diff --git a/subprojects/d2tk/src/base_pty.c b/subprojects/d2tk/src/base_pty.c
index 2255fb3..9c705fb 100644
--- a/subprojects/d2tk/src/base_pty.c
+++ b/subprojects/d2tk/src/base_pty.c
@@ -38,8 +38,14 @@
#define MAX(x, y) (x > y ? y : x)
+#define FONT_CODE_LIGHT "FiraCode:light"
+#define FONT_CODE_REGULAR "FiraCode:regular"
+#define FONT_CODE_MEDIUM "FiraCode:medium"
+#define FONT_CODE_BOLD "FiraCode:bold"
+
typedef struct _cell_t cell_t;
typedef struct _d2tk_atom_body_pty_t d2tk_atom_body_pty_t;
+typedef struct _d2tk_pty_t d2tk_pty_t;
struct _cell_t {
char lbl [8];
@@ -72,10 +78,20 @@ struct _d2tk_atom_body_pty_t {
bool cursor_visible;
int cursor_shape;
+ uint32_t max_red;
+ uint32_t max_green;
+ uint32_t max_blue;
+
cell_t cells [NROWS_MAX][NCOLS_MAX];
};
+struct _d2tk_pty_t {
+ d2tk_state_t state;
+ d2tk_atom_body_pty_t *vpty;
+};
+
const size_t d2tk_atom_body_pty_sz = sizeof(d2tk_atom_body_pty_t);
+const size_t d2tk_pty_sz = sizeof(d2tk_pty_t);
static inline uint32_t
_term_dark(d2tk_atom_body_pty_t *vpty)
@@ -222,18 +238,8 @@ static const VTermScreenCallbacks screen_callbacks = {
.resize = _screen_resize
};
-static void
-_term_clone(FILE *stderr_save, void *data)
-{
- char **argv = data;
-
- execvp(argv[0], argv);
-
- fprintf(stderr_save, "cannot exec(%s) - %s\n", argv[0], strerror(errno));
-}
-
static int
-_term_init(d2tk_atom_body_pty_t *vpty, d2tk_clone_t clone, void *data,
+_term_init(d2tk_atom_body_pty_t *vpty, char **argv,
d2tk_coord_t height, d2tk_coord_t ncols, d2tk_coord_t nrows)
{
vpty->height = height;
@@ -324,12 +330,8 @@ _term_init(d2tk_atom_body_pty_t *vpty, d2tk_clone_t clone, void *data,
putenv("TERM=xterm-256color");
//putenv("COLORTERM=truecolor");
- if(!clone)
- {
- clone = _term_clone;
- }
-
- clone(stderr_save, data);
+ execvp(argv[0], argv);
+ fprintf(stderr_save, "cannot exec(%s) - %s\n", argv[0], strerror(errno));
_exit(EXIT_FAILURE);
}
@@ -451,16 +453,14 @@ _term_event(d2tk_atom_event_type_t event, void *data)
}
static inline void
-_term_set_dark_light(d2tk_atom_body_pty_t *vpty, uint32_t fg)
+_term_set_dark_light(d2tk_atom_body_pty_t *vpty, uint32_t fg,
+ int32_t r1, int32_t g1, int32_t b1)
{
const int32_t r0 = (vpty->light >> 24) & 0xff;
const int32_t g0 = (vpty->light >> 16) & 0xff;
const int32_t b0 = (vpty->light >> 8) & 0xff;
const int32_t d0 = (r0 - g0) + (r0 - b0);
- const int32_t r1 = (fg >> 24) & 0xff;
- const int32_t g1 = (fg >> 16) & 0xff;
- const int32_t b1 = (fg >> 8) & 0xff;
const int32_t d1 = (r1 - g1) + (r1 - b1);
if(d1 > d0)
@@ -474,6 +474,70 @@ _term_set_dark_light(d2tk_atom_body_pty_t *vpty, uint32_t fg)
}
static inline void
+_term_set_max_red(d2tk_atom_body_pty_t *vpty, uint32_t fg,
+ int32_t r1, int32_t g1, int32_t b1)
+{
+ const int32_t r0 = (vpty->max_red >> 24) & 0xff;
+ const int32_t g0 = (vpty->max_red >> 16) & 0xff;
+ const int32_t b0 = (vpty->max_red >> 8) & 0xff;
+ const int32_t d0 = (r0 - g0) + (r0 - b0);
+
+ const int32_t d1 = (r1 - g1) + (r1 - b1);
+
+ if(d1 > d0)
+ {
+ vpty->max_red = fg;
+ }
+}
+
+static inline void
+_term_set_max_green(d2tk_atom_body_pty_t *vpty, uint32_t fg,
+ int32_t r1, int32_t g1, int32_t b1)
+{
+ const int32_t r0 = (vpty->max_green >> 24) & 0xff;
+ const int32_t g0 = (vpty->max_green >> 16) & 0xff;
+ const int32_t b0 = (vpty->max_green >> 8) & 0xff;
+ const int32_t d0 = (g0 - r0) + (g0 - b0);
+
+ const int32_t d1 = (g1 - r1) + (g1 - b1);
+
+ if(d1 > d0)
+ {
+ vpty->max_green = fg;
+ }
+}
+
+static inline void
+_term_set_max_blue(d2tk_atom_body_pty_t *vpty, uint32_t fg,
+ int32_t r1, int32_t g1, int32_t b1)
+{
+ const int32_t r0 = (vpty->max_blue >> 24) & 0xff;
+ const int32_t g0 = (vpty->max_blue >> 16) & 0xff;
+ const int32_t b0 = (vpty->max_blue >> 8) & 0xff;
+ const int32_t d0 = (b0 - r0) + (b0 - g0);
+
+ const int32_t d1 = (b1 - r1) + (b1 - g1);
+
+ if(d1 > d0)
+ {
+ vpty->max_blue = fg;
+ }
+}
+
+static inline void
+_term_set_colors(d2tk_atom_body_pty_t *vpty, uint32_t fg)
+{
+ const int32_t r1 = (fg >> 24) & 0xff;
+ const int32_t g1 = (fg >> 16) & 0xff;
+ const int32_t b1 = (fg >> 8) & 0xff;
+
+ _term_set_dark_light(vpty, fg, r1, g1, b1);
+ _term_set_max_red(vpty, fg, r1, g1, b1);
+ _term_set_max_green(vpty, fg, r1, g1, b1);
+ _term_set_max_blue(vpty, fg, r1, g1, b1);
+}
+
+static inline void
_term_update(d2tk_atom_body_pty_t *vpty)
{
VTermPos cursor;
@@ -583,7 +647,7 @@ _term_update(d2tk_atom_body_pty_t *vpty)
tar->fg = fg_rgba;
tar->bg = bg_rgba;
- _term_set_dark_light(vpty, fg_rgba);
+ _term_set_colors(vpty, fg_rgba);
}
}
}
@@ -733,12 +797,13 @@ _term_behave(d2tk_base_t *base, d2tk_atom_body_pty_t *vpty,
vterm_mouse_move(vpty->vterm, row, col, mod);
- vterm_mouse_button(vpty->vterm, 1,
- d2tk_base_get_butmask(base, D2TK_BUTMASK_LEFT, false), mod);
- vterm_mouse_button(vpty->vterm, 2,
- d2tk_base_get_butmask(base, D2TK_BUTMASK_MIDDLE, false), mod);
- vterm_mouse_button(vpty->vterm, 3,
- d2tk_base_get_butmask(base, D2TK_BUTMASK_RIGHT, false), mod);
+ const bool btn_l = d2tk_base_get_butmask(base, D2TK_BUTMASK_LEFT, false);
+ const bool btn_m = d2tk_base_get_butmask(base, D2TK_BUTMASK_MIDDLE, false);
+ const bool btn_r = d2tk_base_get_butmask(base, D2TK_BUTMASK_RIGHT, false);
+
+ vterm_mouse_button(vpty->vterm, 1, btn_l, mod);
+ vterm_mouse_button(vpty->vterm, 2, btn_m, mod);
+ vterm_mouse_button(vpty->vterm, 3, btn_r, mod);
if(dy > 0)
{
@@ -796,27 +861,27 @@ _term_draw(d2tk_base_t *base, d2tk_atom_body_pty_t *vpty,
if(cell->bold)
{
- style.font_face = "FiraCode-Bold.ttf";
+ style.font_face = FONT_CODE_BOLD;
}
else if(cell->italic)
{
- style.font_face = "FiraCode-Light.ttf";
+ style.font_face = FONT_CODE_LIGHT;
}
else
{
- style.font_face = "FiraCode-Regular.ttf";
+ style.font_face = FONT_CODE_REGULAR;
}
d2tk_base_set_style(base, &style);
d2tk_base_label(base, cell->lbl_len, cell->lbl, 1.f, trect,
- D2TK_ALIGN_LEFT | D2TK_ALIGN_TOP);
+ D2TK_ALIGN_LEFT | D2TK_ALIGN_BOTTOM);
d2tk_base_set_style(base, old_style);
if(cell->cursor)
{
- style.font_face = "FiraCode-Bold.ttf";
+ style.font_face = FONT_CODE_BOLD;
style.text_fill_color[D2TK_TRIPLE_NONE] = 0x0;
style.text_stroke_color[D2TK_TRIPLE_NONE] = focus
? DEFAULT_FG
@@ -848,12 +913,15 @@ _term_draw(d2tk_base_t *base, d2tk_atom_body_pty_t *vpty,
}
}
-D2TK_API d2tk_state_t
-d2tk_base_pty(d2tk_base_t *base, d2tk_id_t id, d2tk_clone_t clone, void *data,
- d2tk_coord_t height, const d2tk_rect_t *rect, bool reinit)
+D2TK_API d2tk_pty_t *
+d2tk_pty_begin(d2tk_base_t *base, d2tk_id_t id, char **argv,
+ d2tk_coord_t height, const d2tk_rect_t *rect, bool reinit, d2tk_pty_t *pty)
{
+ memset(pty, 0x0, sizeof(d2tk_pty_t));
+
d2tk_atom_body_pty_t *vpty = _d2tk_base_get_atom(base, id, D2TK_ATOM_PTY,
_term_event);
+ pty->vpty = vpty;
const d2tk_coord_t width = height / 2;
const d2tk_coord_t ncols = rect->w / width;
@@ -866,7 +934,7 @@ d2tk_base_pty(d2tk_base_t *base, d2tk_id_t id, d2tk_clone_t clone, void *data,
if(vpty->height == 0)
{
- if(_term_init(vpty, clone, data, height, ncols, nrows) != 0)
+ if(_term_init(vpty, argv, height, ncols, nrows) != 0)
{
fprintf(stderr, "[%s] _term_init failed\n", __func__);
}
@@ -879,32 +947,68 @@ d2tk_base_pty(d2tk_base_t *base, d2tk_id_t id, d2tk_clone_t clone, void *data,
style.fill_color[D2TK_TRIPLE_ACTIVE_HOT] = _term_light(vpty);
style.fill_color[D2TK_TRIPLE_ACTIVE_FOCUS] = _term_dark(vpty);
style.fill_color[D2TK_TRIPLE_ACTIVE_HOT_FOCUS] = _term_light(vpty);
- style.font_face = "FiraCode-Regular.ttf";
+ style.font_face = FONT_CODE_REGULAR;
d2tk_base_set_style(base, &style);
_term_resize(vpty, ncols, nrows);
- d2tk_state_t state = _term_behave(base, vpty, id, rect);
+ pty->state = _term_behave(base, vpty, id, rect);
_term_input(vpty);
- _term_draw(base, vpty, rect, d2tk_state_is_focused(state));
+ _term_draw(base, vpty, rect, d2tk_state_is_focused(pty->state));
if(_term_done(vpty))
{
_term_deinit(vpty);
- state |= D2TK_STATE_CLOSE;
+ pty->state |= D2TK_STATE_CLOSE;
}
if(vpty->bell)
{
- state |= D2TK_STATE_BELL;
+ pty->state |= D2TK_STATE_BELL;
vpty->bell = 0;
}
d2tk_base_set_style(base, old_style);
- return state;
+ return pty;
+}
+
+D2TK_API bool
+d2tk_pty_not_end(d2tk_pty_t *pty)
+{
+ return pty ? true : false;
+}
+
+D2TK_API d2tk_pty_t *
+d2tk_pty_next(d2tk_pty_t *pty __attribute__((unused)))
+{
+ return NULL;
+}
+
+D2TK_API d2tk_state_t
+d2tk_pty_get_state(d2tk_pty_t *pty)
+{
+ return pty->state;
+}
+
+D2TK_API uint32_t
+d2tk_pty_get_max_red(d2tk_pty_t *pty)
+{
+ return pty->vpty->max_red;
+}
+
+D2TK_API uint32_t
+d2tk_pty_get_max_green(d2tk_pty_t *pty)
+{
+ return pty->vpty->max_green;
+}
+
+D2TK_API uint32_t
+d2tk_pty_get_max_blue(d2tk_pty_t *pty)
+{
+ return pty->vpty->max_blue;
}
diff --git a/subprojects/d2tk/src/base_spinner.c b/subprojects/d2tk/src/base_spinner.c
new file mode 100644
index 0000000..2ee43a9
--- /dev/null
+++ b/subprojects/d2tk/src/base_spinner.c
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2018-2019 Hanspeter Portner (dev@open-music-kontrollers.ch)
+ *
+ * This is free software: you can redistribute it and/or modify
+ * it under the terms of the Artistic License 2.0 as published by
+ * The Perl Foundation.
+ *
+ * This source is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Artistic License 2.0 for more details.
+ *
+ * You should have received a copy of the Artistic License 2.0
+ * along the source as a COPYING file. If not, obtain it from
+ * http://www.perlfoundation.org/artistic_license_2_0.
+ */
+
+#include <inttypes.h>
+
+#include "base_internal.h"
+
+D2TK_API d2tk_state_t
+d2tk_base_spinner_int32(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
+ int32_t min, int32_t *value, int32_t max)
+{
+ d2tk_state_t state = D2TK_STATE_NONE;
+ const d2tk_coord_t h2 = rect->h/2;
+ const d2tk_coord_t h8 = rect->h/8;
+ const d2tk_coord_t fract [3] = { h2, 0, h2 };
+ D2TK_BASE_LAYOUT(rect, 3, fract, D2TK_FLAG_LAYOUT_X_ABS, lay)
+ {
+ const unsigned k = d2tk_layout_get_index(lay);
+ const d2tk_rect_t *lrect= d2tk_layout_get_rect(lay);
+ const d2tk_id_t itrid = D2TK_ID_IDX(k);
+ const d2tk_id_t subid = (itrid << 32) | id;
+
+ switch(k)
+ {
+ case 0:
+ {
+ d2tk_rect_t bnd;
+ d2tk_rect_shrink_y(&bnd, lrect, h8);
+
+ static const char arrow [] = "◀";
+ const d2tk_state_t substate = d2tk_base_button_label(base, subid,
+ sizeof(arrow), arrow, D2TK_ALIGN_CENTERED, &bnd);
+
+ if(d2tk_state_is_changed(substate))
+ {
+ const int32_t old_value = *value;
+
+ *value -= 1;
+ d2tk_clip_int32(min, value, max);
+
+ if(old_value != *value)
+ {
+ state |= D2TK_STATE_CHANGED;
+ }
+ }
+ } break;
+ case 1:
+ {
+ const d2tk_state_t substate = d2tk_base_bar_int32(base, subid, lrect,
+ min, value, max);
+
+ state |= substate;
+
+ d2tk_rect_t bnd;
+ d2tk_rect_shrink(&bnd, lrect, 5); //FIXME relative to style->border
+
+ char lbl [16];
+ const ssize_t lbl_len = snprintf(lbl, sizeof(lbl), "%+"PRIi32, *value);
+ d2tk_base_label(base, lbl_len, lbl, 0.75f, &bnd,
+ D2TK_ALIGN_MIDDLE | D2TK_ALIGN_RIGHT);
+ } break;
+ case 2:
+ {
+ d2tk_rect_t bnd;
+ d2tk_rect_shrink_y(&bnd, lrect, h8);
+
+ static const char arrow [] = "▶";
+ const d2tk_state_t substate = d2tk_base_button_label(base, subid,
+ sizeof(arrow), arrow, D2TK_ALIGN_CENTERED, &bnd);
+
+ if(d2tk_state_is_changed(substate))
+ {
+ const int32_t old_value = *value;
+
+ *value += 1;
+ d2tk_clip_int32(min, value, max);
+
+ if(old_value != *value)
+ {
+ state |= D2TK_STATE_CHANGED;
+ }
+ }
+ } break;
+ }
+ }
+
+ return state;
+}
diff --git a/subprojects/d2tk/src/base_vkb.c b/subprojects/d2tk/src/base_vkb.c
new file mode 100644
index 0000000..6d6ebe1
--- /dev/null
+++ b/subprojects/d2tk/src/base_vkb.c
@@ -0,0 +1,621 @@
+/*
+ * Copyright (c) 2018-2019 Hanspeter Portner (dev@open-music-kontrollers.ch)
+ *
+ * This is free software: you can redistribute it and/or modify
+ * it under the terms of the Artistic License 2.0 as published by
+ * The Perl Foundation.
+ *
+ * This source is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Artistic License 2.0 for more details.
+ *
+ * You should have received a copy of the Artistic License 2.0
+ * along the source as a COPYING file. If not, obtain it from
+ * http://www.perlfoundation.org/artistic_license_2_0.
+ */
+
+#include <stddef.h>
+#include <string.h>
+#include <errno.h>
+
+#include "base_internal.h"
+
+#include <libevdev/libevdev.h>
+#include <libevdev/libevdev-uinput.h>
+
+typedef struct _d2tk_atom_body_vkb_t d2tk_atom_body_vkb_t;
+
+struct _d2tk_atom_body_vkb_t
+{
+ struct libevdev *dev;
+ struct libevdev_uinput *uidev;
+};
+
+const size_t d2tk_atom_body_vkb_sz = sizeof(d2tk_atom_body_vkb_t);
+
+static void
+_fake_event(d2tk_atom_body_vkb_t *vkb, unsigned type, unsigned code, int value)
+{
+ if(vkb->uidev)
+ {
+ libevdev_uinput_write_event(vkb->uidev, type, code, value);
+ }
+}
+
+static void
+_fake_key_down(d2tk_atom_body_vkb_t *vkb, unsigned keycode)
+{
+ _fake_event(vkb, EV_KEY, keycode, 1);
+ _fake_event(vkb, EV_SYN, SYN_REPORT, 0);
+}
+
+static void
+_fake_key_up(d2tk_atom_body_vkb_t *vkb, unsigned keycode)
+{
+ _fake_event(vkb, EV_KEY, keycode, 0);
+ _fake_event(vkb, EV_SYN, SYN_REPORT, 0);
+}
+
+typedef struct _keybtn_t keybtn_t;
+
+struct _keybtn_t {
+ const char *name;
+ const char *altn;
+ unsigned code;
+ float rect [4];
+};
+
+#define W (1.f / 15.f)
+#define W_2 (W / 2)
+#define H (1.f / 6.f)
+
+static const keybtn_t keybtns [] = {
+ // row 1
+ {
+ .name = "Esc",
+ .code = KEY_ESC,
+ .rect = { 0*W, 0*H, W + W_2, H }
+ },
+ {
+ .name = "F1",
+ .code = KEY_F1,
+ .rect = { 1*W + W_2, 0*H, W, H }
+ },
+ {
+ .name = "F2",
+ .code = KEY_F2,
+ .rect = { 2*W + W_2, 0*H, W, H }
+ },
+ {
+ .name = "F3",
+ .code = KEY_F3,
+ .rect = { 3*W + W_2, 0*H, W, H }
+ },
+ {
+ .name = "F4",
+ .code = KEY_F4,
+ .rect = { 4*W + W_2, 0*H, W, H }
+ },
+ {
+ .name = "F5",
+ .code = KEY_F5,
+ .rect = { 5*W + W_2, 0*H, W, H }
+ },
+ {
+ .name = "F6",
+ .code = KEY_F6,
+ .rect = { 6*W + W_2, 0*H, W, H }
+ },
+ {
+ .name = "F7",
+ .code = KEY_F7,
+ .rect = { 7*W + W_2, 0*H, W, H }
+ },
+ {
+ .name = "F8",
+ .code = KEY_F8,
+ .rect = { 8*W + W_2, 0*H, W, H }
+ },
+ {
+ .name = "F9",
+ .code = KEY_F9,
+ .rect = { 9*W + W_2, 0*H, W, H }
+ },
+ {
+ .name = "F10",
+ .code = KEY_F10,
+ .rect = { 10*W + W_2, 0*H, W, H }
+ },
+ {
+ .name = "F11",
+ .code = KEY_F11,
+ .rect = { 11*W + W_2, 0*H, W, H }
+ },
+ {
+ .name = "F12",
+ .code = KEY_F12,
+ .rect = { 12*W + W_2, 0*H, W, H }
+ },
+ {
+ .name = "Delete",
+ .code = KEY_DELETE,
+ .rect = { 13*W + W_2, 0*H, W + W_2, H }
+ },
+
+ // row 2
+ {
+ .name = "`",
+ .altn = "~",
+ .code = KEY_GRAVE,
+ .rect = { 0*W, 1*H, W, H }
+ },
+ {
+ .name = "1",
+ .altn = "!",
+ .code = KEY_1,
+ .rect = { 1*W, 1*H, W, H }
+ },
+ {
+ .name = "2",
+ .altn = "@",
+ .code = KEY_2,
+ .rect = { 2*W, 1*H, W, H }
+ },
+ {
+ .name = "3",
+ .altn = "#",
+ .code = KEY_3,
+ .rect = { 3*W, 1*H, W, H }
+ },
+ {
+ .name = "4",
+ .altn = "$",
+ .code = KEY_4,
+ .rect = { 4*W, 1*H, W, H }
+ },
+ {
+ .name = "5",
+ .altn = "%",
+ .code = KEY_5,
+ .rect = { 5*W, 1*H, W, H }
+ },
+ {
+ .name = "6",
+ .altn = "^",
+ .code = KEY_6,
+ .rect = { 6*W, 1*H, W, H }
+ },
+ {
+ .name = "7",
+ .altn = "&",
+ .code = KEY_7,
+ .rect = { 7*W, 1*H, W, H }
+ },
+ {
+ .name = "8",
+ .altn = "*",
+ .code = KEY_8,
+ .rect = { 8*W, 1*H, W, H }
+ },
+ {
+ .name = "9",
+ .altn = "(",
+ .code = KEY_9,
+ .rect = { 9*W, 1*H, W, H }
+ },
+ {
+ .name = "0",
+ .altn = ")",
+ .code = KEY_0,
+ .rect = { 10*W, 1*H, W, H }
+ },
+ {
+ .name = "-",
+ .altn = "_",
+ .code = KEY_MINUS,
+ .rect = { 11*W, 1*H, W, H }
+ },
+ {
+ .name = "=",
+ .altn = "+",
+ .code = KEY_EQUAL,
+ .rect = { 12*W, 1*H, W, H }
+ },
+ {
+ .name = "Back",
+ .code = KEY_BACKSPACE,
+ .rect = { 13*W, 1*H, 2*W, H }
+ },
+
+ // row 3
+ {
+ .name = "Tab",
+ .code = KEY_TAB,
+ .rect = { 0*W, 2*H, W + W_2, H }
+ },
+ {
+ .name = "Q",
+ .code = KEY_Q,
+ .rect = { 1*W + W_2, 2*H, W, H }
+ },
+ {
+ .name = "W",
+ .code = KEY_W,
+ .rect = { 2*W + W_2, 2*H, W, H }
+ },
+ {
+ .name = "E",
+ .code = KEY_E,
+ .rect = { 3*W + W_2, 2*H, W, H }
+ },
+ {
+ .name = "R",
+ .code = KEY_R,
+ .rect = { 4*W + W_2, 2*H, W, H }
+ },
+ {
+ .name = "T",
+ .code = KEY_T,
+ .rect = { 5*W + W_2, 2*H, W, H }
+ },
+ {
+ .name = "Y",
+ .code = KEY_Y,
+ .rect = { 6*W + W_2, 2*H, W, H }
+ },
+ {
+ .name = "U",
+ .code = KEY_U,
+ .rect = { 7*W + W_2, 2*H, W, H }
+ },
+ {
+ .name = "I",
+ .code = KEY_I,
+ .rect = { 8*W + W_2, 2*H, W, H }
+ },
+ {
+ .name = "O",
+ .code = KEY_O,
+ .rect = { 9*W + W_2, 2*H, W, H }
+ },
+ {
+ .name = "P",
+ .code = KEY_P,
+ .rect = { 10*W + W_2, 2*H, W, H }
+ },
+ {
+ .name = "[",
+ .altn = "{",
+ .code = KEY_LEFTBRACE,
+ .rect = { 11*W + W_2, 2*H, W, H }
+ },
+ {
+ .name = "]",
+ .altn = "}",
+ .code = KEY_RIGHTBRACE,
+ .rect = { 12*W + W_2, 2*H, W, H }
+ },
+ {
+ .name = "\\",
+ .altn = "|",
+ .code = KEY_BACKSLASH,
+ .rect = { 13*W + W_2, 2*H, 2*W - W_2, H }
+ },
+
+ // row 4
+ {
+ .name = "Caps",
+ .code = KEY_CAPSLOCK,
+ .rect = { 0*W, 3*H, W*2, H }
+ },
+ {
+ .name = "A",
+ .code = KEY_A,
+ .rect = { 2*W, 3*H, W, H }
+ },
+ {
+ .name = "S",
+ .code = KEY_S,
+ .rect = { 3*W, 3*H, W, H }
+ },
+ {
+ .name = "D",
+ .code = KEY_D,
+ .rect = { 4*W, 3*H, W, H }
+ },
+ {
+ .name = "F",
+ .code = KEY_F,
+ .rect = { 5*W, 3*H, W, H }
+ },
+ {
+ .name = "G",
+ .code = KEY_G,
+ .rect = { 6*W, 3*H, W, H }
+ },
+ {
+ .name = "H",
+ .code = KEY_H,
+ .rect = { 7*W, 3*H, W, H }
+ },
+ {
+ .name = "J",
+ .code = KEY_J,
+ .rect = { 8*W, 3*H, W, H }
+ },
+ {
+ .name = "K",
+ .code = KEY_K,
+ .rect = { 9*W, 3*H, W, H }
+ },
+ {
+ .name = "L",
+ .code = KEY_L,
+ .rect = { 10*W, 3*H, W, H }
+ },
+ {
+ .name = ";",
+ .altn = ":",
+ .code = KEY_SEMICOLON,
+ .rect = { 11*W, 3*H, W, H }
+ },
+ {
+ .name = "'",
+ .altn = "\"",
+ .code = KEY_APOSTROPHE,
+ .rect = { 12*W, 3*H, W, H }
+ },
+ {
+ .name = "Enter",
+ .code = KEY_ENTER,
+ .rect = { 13*W, 3*H, W*2, H }
+ },
+
+ // row 5
+ {
+ .name = "Shift",
+ .code = KEY_LEFTSHIFT,
+ .rect = { 0*W, 4*H, W*2 + W_2, H }
+ },
+ {
+ .name = "Z",
+ .code = KEY_Z,
+ .rect = { 2*W + W_2, 4*H, W, H }
+ },
+ {
+ .name = "X",
+ .code = KEY_X,
+ .rect = { 3*W + W_2, 4*H, W, H }
+ },
+ {
+ .name = "C",
+ .code = KEY_C,
+ .rect = { 4*W + W_2, 4*H, W, H }
+ },
+ {
+ .name = "V",
+ .code = KEY_V,
+ .rect = { 5*W + W_2, 4*H, W, H }
+ },
+ {
+ .name = "B",
+ .code = KEY_B,
+ .rect = { 6*W + W_2, 4*H, W, H }
+ },
+ {
+ .name = "N",
+ .code = KEY_N,
+ .rect = { 7*W + W_2, 4*H, W, H }
+ },
+ {
+ .name = "M",
+ .code = KEY_M,
+ .rect = { 8*W + W_2, 4*H, W, H }
+ },
+ {
+ .name = ",",
+ .altn = "<",
+ .code = KEY_COMMA,
+ .rect = { 9*W + W_2, 4*H, W, H }
+ },
+ {
+ .name = ".",
+ .altn = ">",
+ .code = KEY_DOT,
+ .rect = { 10*W + W_2, 4*H, W, H }
+ },
+ {
+ .name = "/",
+ .altn = "?",
+ .code = KEY_SLASH,
+ .rect = { 11*W + W_2, 4*H, W, H }
+ },
+ {
+ .name = "Shift",
+ .code = KEY_RIGHTSHIFT,
+ .rect = { 12*W + W_2, 4*H, 3*W - W_2, H }
+ },
+
+ // row 6
+ {
+ .name = "Fn",
+ .code = KEY_FN,
+ .rect = { 0*W, 5*H, W, H }
+ },
+ {
+ .name = "Ctrl",
+ .code = KEY_LEFTCTRL,
+ .rect = { 1*W, 5*H, W, H }
+ },
+ {
+ .name = "Mta",
+ .code = KEY_LEFTMETA,
+ .rect = { 2*W, 5*H, W, H }
+ },
+ {
+ .name = "Alt",
+ .code = KEY_LEFTALT,
+ .rect = { 3*W, 5*H, W, H }
+ },
+ {
+ .name = "Space",
+ .code = KEY_SPACE,
+ .rect = { 4*W, 5*H, 5*W, H }
+ },
+ {
+ .name = "Alt",
+ .code = KEY_RIGHTALT,
+ .rect = { 9*W, 5*H, W, H }
+ },
+ {
+ .name = "Mta",
+ .code = KEY_RIGHTMETA,
+ .rect = { 10*W, 5*H, W, H }
+ },
+ {
+ .name = "Ctrl",
+ .code = KEY_RIGHTCTRL,
+ .rect = { 11*W, 5*H, W, H }
+ },
+ {
+ .name = "Hom",
+ .code = KEY_HOME,
+ .rect = { 12*W, 5*H, W, H }
+ },
+ {
+ .name = "End",
+ .code = KEY_END,
+ .rect = { 13*W, 5*H, W, H }
+ },
+ {
+ .name = "Ins",
+ .code = KEY_INSERT,
+ .rect = { 14*W, 5*H, W, H }
+ },
+
+ { // sentinel
+ .name = NULL
+ }
+};
+
+static int
+_vkb_deinit(d2tk_atom_body_vkb_t *vkb)
+{
+ if(vkb->uidev)
+ {
+ libevdev_uinput_destroy(vkb->uidev);
+ vkb->uidev = NULL;
+ }
+
+ if(vkb->dev)
+ {
+ libevdev_free(vkb->dev);
+ vkb->dev = NULL;
+ }
+
+ return 0;
+}
+
+static int
+_vkb_init(d2tk_atom_body_vkb_t *vkb)
+{
+ if(vkb->dev)
+ {
+ return 0; // already initialized
+ }
+
+ vkb->dev = libevdev_new();
+ if(!vkb->dev)
+ {
+ fprintf(stderr, "libevdev_new: %s\n", strerror(errno));
+ return 1;;
+ }
+
+ libevdev_set_name(vkb->dev, "D2TK keyboard");
+ libevdev_enable_event_type(vkb->dev, EV_SYN);
+ libevdev_enable_event_code(vkb->dev, EV_SYN, SYN_REPORT, NULL);
+ libevdev_enable_event_type(vkb->dev, EV_KEY);
+
+ for(const keybtn_t *keybtn = keybtns; keybtn->name; keybtn++)
+ {
+ libevdev_enable_event_code(vkb->dev, EV_KEY, keybtn->code, NULL);
+ }
+
+ vkb->uidev = NULL;
+ libevdev_uinput_create_from_device(vkb->dev, LIBEVDEV_UINPUT_OPEN_MANAGED,
+ &vkb->uidev);
+ if(!vkb->uidev)
+ {
+ fprintf(stderr, "libevdev_uinput_create_from_device: %s\n", strerror(errno));
+ return 1;
+ }
+
+ return 0;
+}
+
+static int
+_vkb_event(d2tk_atom_event_type_t event, void *data)
+{
+ d2tk_atom_body_vkb_t *vkb = data;
+
+ switch(event)
+ {
+ case D2TK_ATOM_EVENT_DEINIT:
+ {
+ return _vkb_deinit(vkb);
+ } break;
+
+ case D2TK_ATOM_EVENT_PROBE:
+ // fall-through
+ case D2TK_ATOM_EVENT_NONE:
+ // fall-through
+ default:
+ {
+ // nothing to do
+ } break;
+ }
+
+ return 0;
+}
+
+D2TK_API d2tk_state_t
+d2tk_base_vkb(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect)
+{
+ d2tk_atom_body_vkb_t *vkb = _d2tk_base_get_atom(base, id, D2TK_ATOM_VKB,
+ _vkb_event);
+
+ _vkb_init(vkb);
+
+ for(const keybtn_t *keybtn = keybtns; keybtn->name; keybtn++)
+ {
+ const d2tk_rect_t bnd = {
+ .x = rect->x + keybtn->rect[0]*rect->w,
+ .y = rect->y + keybtn->rect[1]*rect->h,
+ .w = keybtn->rect[2]*rect->w,
+ .h = keybtn->rect[3]*rect->h
+ };
+
+ const char *lbl = d2tk_base_get_modmask(base, D2TK_MODMASK_SHIFT, false)
+ && keybtn->altn
+ ? keybtn->altn
+ : keybtn->name;
+
+ const unsigned idx = keybtn - keybtns;
+ const d2tk_id_t itrid = D2TK_ID_IDX(idx);
+ const d2tk_id_t subid = (itrid << 32) | id;
+ const d2tk_state_t state = d2tk_base_button_label(base, subid,
+ -1, lbl, D2TK_ALIGN_CENTERED, &bnd);
+
+ if(d2tk_state_is_down(state))
+ {
+ _fake_key_down(vkb, keybtn->code);
+ }
+ else if(d2tk_state_is_up(state))
+ {
+ _fake_key_up(vkb, keybtn->code);
+ }
+ }
+
+ return D2TK_STATE_NONE;
+}
diff --git a/subprojects/d2tk/src/core.c b/subprojects/d2tk/src/core.c
index fbf9864..b4781ef 100644
--- a/subprojects/d2tk/src/core.c
+++ b/subprojects/d2tk/src/core.c
@@ -33,6 +33,10 @@
#include "core_internal.h"
#include <d2tk/hash.h>
+#if D2TK_FONTCONFIG
+# include <fontconfig/fontconfig.h>
+#endif
+
#define _D2TK_SPRITES_MAX 0x10000 //FIXME how big?
#define _D2TK_SPRITES_MASK (_D2TK_SPRITES_MAX - 1)
#define _D2TK_SPRITES_TTL 0x100
@@ -1633,3 +1637,46 @@ d2tk_core_set_full_refresh(d2tk_core_t *core)
{
core->full_refresh = true;
}
+
+int
+d2tk_core_get_font_path(d2tk_core_t *core, const char *bundle_path,
+ const char *rel_path, size_t abs_len, char *abs_path)
+{
+ int ret = 1;
+
+#if D2TK_FONTCONFIG
+ (void)core;
+ (void)bundle_path;
+
+ FcConfig *config = FcInitLoadConfigAndFonts();
+ FcPattern *pat = FcNameParse((FcChar8 *)rel_path);
+ FcConfigSubstitute(config, pat, FcMatchPattern);
+ FcDefaultSubstitute(pat);
+
+ //FcPatternPrint(pat);
+
+ FcResult result;
+ FcPattern *font = FcFontMatch(config, pat, &result);
+ if(font)
+ {
+ FcChar8 *file = NULL;
+ if(FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch)
+ {
+ snprintf(abs_path, abs_len, "%s", file);
+ ret = 0;
+ }
+
+ FcPatternDestroy(font);
+ }
+
+ FcPatternDestroy(pat);
+
+ FcConfigDestroy(config);
+#else
+ (void)core;
+ snprintf(abs_path, abs_len, "%s%s.ttf", bundle_path, rel_path);
+ ret = 0;
+#endif
+
+ return ret;
+}
diff --git a/subprojects/d2tk/src/core_internal.h b/subprojects/d2tk/src/core_internal.h
index d281832..d46af9e 100644
--- a/subprojects/d2tk/src/core_internal.h
+++ b/subprojects/d2tk/src/core_internal.h
@@ -292,6 +292,10 @@ d2tk_core_set_bg_color(d2tk_core_t *core, uint32_t rgba);
uint32_t
d2tk_core_get_bg_color(d2tk_core_t *core);
+int
+d2tk_core_get_font_path(d2tk_core_t *core, const char *bundle_path,
+ const char *rel_path, size_t abs_len, char *abs_path);
+
#ifdef __cplusplus
}
#endif
diff --git a/subprojects/d2tk/src/frontend_fbdev.c b/subprojects/d2tk/src/frontend_fbdev.c
index e5121ee..762f72f 100644
--- a/subprojects/d2tk/src/frontend_fbdev.c
+++ b/subprojects/d2tk/src/frontend_fbdev.c
@@ -532,7 +532,7 @@ d2tk_fbdev_step(d2tk_fbdev_t *fbdev)
const int32_t slot= libinput_event_touch_get_seat_slot(evt);
(void)slot; //FIXME
- d2tk_base_set_butmask(fbdev->base, D2TK_BUTMASK_RIGHT, false);
+ d2tk_base_set_butmask(fbdev->base, D2TK_BUTMASK_LEFT, false);
} break;
case LIBINPUT_EVENT_TOUCH_MOTION:
{
diff --git a/subprojects/d2tk/ttf/FiraMono-Bold.ttf b/subprojects/d2tk/ttf/FiraMono-Bold.ttf
deleted file mode 100644
index 6d4ffb0..0000000
--- a/subprojects/d2tk/ttf/FiraMono-Bold.ttf
+++ /dev/null
Binary files differ
diff --git a/subprojects/d2tk/ttf/LICENSE b/subprojects/d2tk/ttf/LICENSE
new file mode 100644
index 0000000..805e0b3
--- /dev/null
+++ b/subprojects/d2tk/ttf/LICENSE
@@ -0,0 +1,93 @@
+Copyright (c) 2014, The Fira Code Project Authors (https://github.com/tonsky/FiraCode)
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+This license is copied below, and is also available with a FAQ at:
+http://scripts.sil.org/OFL
+
+
+-----------------------------------------------------------
+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
+-----------------------------------------------------------
+
+PREAMBLE
+The goals of the Open Font License (OFL) are to stimulate worldwide
+development of collaborative font projects, to support the font creation
+efforts of academic and linguistic communities, and to provide a free and
+open framework in which fonts may be shared and improved in partnership
+with others.
+
+The OFL allows the licensed fonts to be used, studied, modified and
+redistributed freely as long as they are not sold by themselves. The
+fonts, including any derivative works, can be bundled, embedded,
+redistributed and/or sold with any software provided that any reserved
+names are not used by derivative works. The fonts and derivatives,
+however, cannot be released under any other type of license. The
+requirement for fonts to remain under this license does not apply
+to any document created using the fonts or their derivatives.
+
+DEFINITIONS
+"Font Software" refers to the set of files released by the Copyright
+Holder(s) under this license and clearly marked as such. This may
+include source files, build scripts and documentation.
+
+"Reserved Font Name" refers to any names specified as such after the
+copyright statement(s).
+
+"Original Version" refers to the collection of Font Software components as
+distributed by the Copyright Holder(s).
+
+"Modified Version" refers to any derivative made by adding to, deleting,
+or substituting -- in part or in whole -- any of the components of the
+Original Version, by changing formats or by porting the Font Software to a
+new environment.
+
+"Author" refers to any designer, engineer, programmer, technical
+writer or other person who contributed to the Font Software.
+
+PERMISSION & CONDITIONS
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the Font Software, to use, study, copy, merge, embed, modify,
+redistribute, and sell modified and unmodified copies of the Font
+Software, subject to the following conditions:
+
+1) Neither the Font Software nor any of its individual components,
+in Original or Modified Versions, may be sold by itself.
+
+2) Original or Modified Versions of the Font Software may be bundled,
+redistributed and/or sold with any software, provided that each copy
+contains the above copyright notice and this license. These can be
+included either as stand-alone text files, human-readable headers or
+in the appropriate machine-readable metadata fields within text or
+binary files as long as those fields can be easily viewed by the user.
+
+3) No Modified Version of the Font Software may use the Reserved Font
+Name(s) unless explicit written permission is granted by the corresponding
+Copyright Holder. This restriction only applies to the primary font name as
+presented to the users.
+
+4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
+Software shall not be used to promote, endorse or advertise any
+Modified Version, except to acknowledge the contribution(s) of the
+Copyright Holder(s) and the Author(s) or with their explicit written
+permission.
+
+5) The Font Software, modified or unmodified, in part or in whole,
+must be distributed entirely under this license, and must not be
+distributed under any other license. The requirement for fonts to
+remain under this license does not apply to any document created
+using the Font Software.
+
+TERMINATION
+This license becomes null and void if any of the above conditions are
+not met.
+
+DISCLAIMER
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
+OTHER DEALINGS IN THE FONT SOFTWARE.