diff options
author | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2021-04-12 22:47:38 +0200 |
---|---|---|
committer | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2021-04-12 22:47:38 +0200 |
commit | fbdc4b07177e6daab2739f78e81355b89bb95b78 (patch) | |
tree | 01f92cb438d0dceebd4aeac31de8fa0aa5d19b34 | |
parent | 9ea55367360e28ba4273f248ed9056f07b0eaf78 (diff) | |
download | synthpod-fbdc4b07177e6daab2739f78e81355b89bb95b78.tar.xz |
Squashed 'subprojects/d2tk/' changes from 820f3571a..5a3295fa5
5a3295fa5 base: properly discover console mouse support.
e3df17dd1 Merge commit '268cadaeb0b190faa7c4aca0ec00fcd05131d165'
268cadaeb Squashed 'linenoise/' changes from 42b1d41ba..9dfa3862c
3779e8309 base: close pty master after freeing vterm.
43a666461 base: fix segfault in lineedit atom gc.
ebff6eed2 base: prototype atom garbage collection.
git-subtree-dir: subprojects/d2tk
git-subtree-split: 5a3295fa5b2e0fe4724125e5c8473f1d13d04caa
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | example/example.c | 2 | ||||
-rwxr-xr-x | linenoise/linenoise.c | 1 | ||||
-rw-r--r-- | src/base.c | 49 | ||||
-rw-r--r-- | src/base_internal.h | 1 | ||||
-rw-r--r-- | src/base_pty.c | 47 |
6 files changed, 74 insertions, 28 deletions
@@ -1 +1 @@ -0.1.1241 +0.1.1253 diff --git a/example/example.c b/example/example.c index 9da7b3d7..be8ed79c 100644 --- a/example/example.c +++ b/example/example.c @@ -67,7 +67,7 @@ typedef enum _bar_t { BAR_MAX } bar_t; -static int32_t bar = BAR_MIX; +static int32_t bar = BAR_LINEEDIT; static const char *bar_lbl [BAR_MAX] = { [BAR_MIX] = "Mix of many", [BAR_SPINNER] = "Spinner", diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index e7d8b16d..aac26fa6 100755 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -1164,7 +1164,6 @@ static int linenoiseRaw(linenoiseApp *app, char *buf, size_t buflen, const char if (enableRawMode(app, app->fd_in) == -1) return -1; count = linenoiseEdit(app, app->fd_in, app->fd_out, buf, buflen, prompt); disableRawMode(app, app->fd_in); - printf("\n"); return count; } @@ -173,6 +173,7 @@ _d2tk_base_get_atom(d2tk_base_t *base, d2tk_id_t id, d2tk_atom_type_t type, } } + atom->ttl = 32; //FIXME return atom->body; } @@ -793,24 +794,52 @@ d2tk_base_set_ttls(d2tk_base_t *base, uint32_t sprites, uint32_t memcaches) d2tk_core_set_ttls(base->core, sprites, memcaches); } -D2TK_API void -d2tk_base_free(d2tk_base_t *base) +static void +_d2tk_atom_deinit(d2tk_atom_t *atom) +{ + atom->id = 0; + atom->type = 0; + if(atom->event) + { + atom->event(D2TK_ATOM_EVENT_DEINIT, atom->body); + atom->event = NULL; + } + free(atom->body); + atom->body = NULL; + atom->ttl = 0; +} + +static void +_d2tk_atom_gc(d2tk_base_t *base) { for(unsigned i = 0; i < _D2TK_MAX_ATOM; i++) { d2tk_atom_t *atom = &base->atoms[i]; - atom->id = 0; - atom->type = 0; - if(atom->event) + if(!atom->id || (--atom->ttl > 0) ) { - atom->event(D2TK_ATOM_EVENT_DEINIT, atom->body); - atom->event = NULL; + continue; } - free(atom->body); - atom->body = NULL; + + _d2tk_atom_deinit(atom); } +} +static void +_d2tk_atom_free(d2tk_base_t *base) +{ + for(unsigned i = 0; i < _D2TK_MAX_ATOM; i++) + { + d2tk_atom_t *atom = &base->atoms[i]; + + _d2tk_atom_deinit(atom); + } +} + +D2TK_API void +d2tk_base_free(d2tk_base_t *base) +{ + _d2tk_atom_free(base); d2tk_core_free(base->core); free(base); } @@ -867,6 +896,8 @@ d2tk_base_post(d2tk_base_t *base) _d2tk_base_clear_chars(base); + _d2tk_atom_gc(base); + d2tk_core_post(base->core); } diff --git a/src/base_internal.h b/src/base_internal.h index 0ece0bf7..f801418e 100644 --- a/src/base_internal.h +++ b/src/base_internal.h @@ -56,6 +56,7 @@ struct _d2tk_flip_t { struct _d2tk_atom_t { d2tk_id_t id; d2tk_atom_type_t type; + uint32_t ttl; void *body; d2tk_atom_event_t event; }; diff --git a/src/base_pty.c b/src/base_pty.c index 6267ed47..b380a4cb 100644 --- a/src/base_pty.c +++ b/src/base_pty.c @@ -91,9 +91,10 @@ struct _d2tk_atom_body_pty_t { d2tk_coord_t ncols; d2tk_coord_t nrows; unsigned bell; + bool hasmouse; int fd; - pid_t kid; + ptrdiff_t kid; thread_data_t thread_data; bool is_threaded; @@ -184,6 +185,11 @@ _term_done_thread(d2tk_atom_body_pty_t *vpty) pthread_join(vpty->kid, NULL); +#if D2TK_DEBUG == 1 + fprintf(stderr, "[%s] child with pid %ld has exited\n", + __func__, vpty->kid); +#endif + _term_clear(vpty); return 1; } @@ -192,9 +198,9 @@ static inline int _term_done_fork(d2tk_atom_body_pty_t *vpty) { int stat = 0; - const int kid = waitpid(vpty->kid, NULL, WNOHANG); + const ptrdiff_t kid = waitpid(vpty->kid, NULL, WNOHANG); #if D2TK_DEBUG == 1 - fprintf(stderr, "[%s] waitpid of child with pid %d: %d (%d)\n", + fprintf(stderr, "[%s] waitpid of child with pid %ld: %ld (%d)\n", __func__, vpty->kid, kid, stat); #endif @@ -212,14 +218,14 @@ _term_done_fork(d2tk_atom_body_pty_t *vpty) if(WIFSIGNALED(stat)) { #if D2TK_DEBUG == 1 - fprintf(stderr, "[%s] child with pid %d has exited with signal %d\n", + fprintf(stderr, "[%s] child with pid %ld has exited with signal %d\n", __func__, vpty->kid, WTERMSIG(stat)); #endif } else if(WIFEXITED(stat)) { #if D2TK_DEBUG == 1 - fprintf(stderr, "[%s] child with pid %d has exited with status %d\n", + fprintf(stderr, "[%s] child with pid %ld has exited with status %d\n", __func__, vpty->kid, WEXITSTATUS(stat)); #endif } @@ -270,6 +276,10 @@ _screen_settermprop(VTermProp prop, VTermValue *val, void *data) { vpty->cursor_shape = val->number; } break; + case VTERM_PROP_MOUSE: + { + vpty->hasmouse = true; + } break; default: { @@ -393,7 +403,7 @@ _thread(void *data) return NULL; } -static int +static ptrdiff_t _threadpty(int *amaster, const struct termios *termp, const struct winsize *winp, d2tk_base_pty_cb_t cb, void *data, thread_data_t *thread_data) { @@ -425,7 +435,7 @@ _threadpty(int *amaster, const struct termios *termp, const struct winsize *winp return thread; } -static int +static ptrdiff_t _forkpty(int *amaster, const struct termios *termp, const struct winsize *winp, void *data) { @@ -545,7 +555,7 @@ _term_init(d2tk_atom_body_pty_t *vpty, d2tk_base_pty_cb_t cb, void *data, } #if D2TK_DEBUG == 1 - fprintf(stderr, "[%s] child with pid %i has spawned\n", __func__, vpty->kid); + fprintf(stderr, "[%s] child with pid %ld has spawned\n", __func__, vpty->kid); #endif fcntl(vpty->fd, F_SETFL, fcntl(vpty->fd, F_GETFL) | O_NONBLOCK); @@ -579,6 +589,11 @@ _term_deinit_thread(d2tk_atom_body_pty_t *vpty) pthread_join(vpty->kid, NULL); +#if D2TK_DEBUG == 1 + fprintf(stderr, "[%s] child with pid %ld has exited\n", + __func__, vpty->kid); +#endif + _term_clear(vpty); } @@ -620,14 +635,14 @@ _term_deinit_fork(d2tk_atom_body_pty_t *vpty) if(WIFSIGNALED(stat)) { #if D2TK_DEBUG == 1 - fprintf(stderr, "[%s] child with pid %d has exited with signal %d\n", + fprintf(stderr, "[%s] child with pid %ld has exited with signal %d\n", __func__, vpty->kid, WTERMSIG(stat)); #endif } else if(WIFEXITED(stat)) { #if D2TK_DEBUG == 1 - fprintf(stderr, "[%s] child with pid %d has exited with status %d\n", + fprintf(stderr, "[%s] child with pid %ld has exited with status %d\n", __func__, vpty->kid, WEXITSTATUS(stat)); #endif } @@ -652,6 +667,11 @@ _term_deinit(d2tk_atom_body_pty_t *vpty) ? _term_deinit_thread(vpty) : _term_deinit_fork(vpty); + if(vpty->vterm) + { + vterm_free(vpty->vterm); + } + if(vpty->fd) { close(vpty->fd); @@ -659,11 +679,6 @@ _term_deinit(d2tk_atom_body_pty_t *vpty) vpty->fd = 0; } - if(vpty->vterm) - { - vterm_free(vpty->vterm); - } - memset(vpty, 0x0, sizeof(d2tk_atom_body_pty_t)); return ret; @@ -1015,7 +1030,7 @@ _term_behave(d2tk_base_t *base, d2tk_atom_body_pty_t *vpty, vterm_state_focus_out(vpty->state); } - if(flags & D2TK_FLAG_PTY_NOMOUSE) + if( !vpty->hasmouse || (flags & D2TK_FLAG_PTY_NOMOUSE) ) { return state; } |