@@ 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);
}
@@ 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;
}