aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2019-12-15 21:20:07 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2019-12-15 21:20:07 +0100
commitbd64c946800da528ed6ef7fbe3b2a8a2ea175ecf (patch)
tree375cc3904883da55528d7d3d47d90e494beb031b
parent79e9620b9fd5a255a79756d03cc19847b883eeec (diff)
downloadd2tk-bd64c946800da528ed6ef7fbe3b2a8a2ea175ecf.tar.xz
base: prototype synchronous atom probe.
-rw-r--r--VERSION2
-rw-r--r--d2tk/base.h3
-rw-r--r--meson.build2
-rw-r--r--src/base.c34
-rw-r--r--src/base_internal.h18
-rw-r--r--src/base_pty.c128
-rw-r--r--src/frontend_pugl.c2
7 files changed, 108 insertions, 81 deletions
diff --git a/VERSION b/VERSION
index 00b303b..3275c36 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.913
+0.1.915
diff --git a/d2tk/base.h b/d2tk/base.h
index 7f54af3..31e716a 100644
--- a/d2tk/base.h
+++ b/d2tk/base.h
@@ -619,6 +619,9 @@ d2tk_base_pre(d2tk_base_t *base);
D2TK_API void
d2tk_base_post(d2tk_base_t *base);
+D2TK_API void
+d2tk_base_probe(d2tk_base_t *base);
+
D2TK_API bool
d2tk_base_set_again(d2tk_base_t *base);
diff --git a/meson.build b/meson.build
index 08e3515..f81ac9f 100644
--- a/meson.build
+++ b/meson.build
@@ -20,7 +20,6 @@ cc = meson.get_compiler('c')
m_dep = cc.find_library('m')
util_dep = cc.find_library('util', required : false)
-thread_dep = dependency('threads')
freetype_dep = dependency('freetype2', version : '>=18.0.0',
static : static_link, required : false)
pixman_dep = dependency('pixman-1', version : '>=0.34.0',
@@ -94,7 +93,6 @@ lib_srcs = [
if vterm_dep.found()
conf_data.set('D2TK_PTY', 1)
lib_srcs += join_paths('src', 'base_pty.c')
- deps += thread_dep
deps += util_dep
else
conf_data.set('D2TK_PTY', 0)
diff --git a/src/base.c b/src/base.c
index 864c891..f0ff45d 100644
--- a/src/base.c
+++ b/src/base.c
@@ -89,7 +89,7 @@ _d2tk_flip_clear_old(d2tk_flip_t *flip)
void *
_d2tk_base_get_atom(d2tk_base_t *base, d2tk_id_t id, d2tk_atom_type_t type,
- d2tk_atom_deinit_t deinit)
+ d2tk_atom_event_t event)
{
for(unsigned i = 0, idx = (id + i*i) & _D2TK_MASK_ATOMS;
i < _D2TK_MAX_ATOM;
@@ -106,7 +106,7 @@ _d2tk_base_get_atom(d2tk_base_t *base, d2tk_id_t id, d2tk_atom_type_t type,
{
atom->id = id;
atom->type = type;
- atom->deinit = deinit;
+ atom->event = event;
size_t len;
switch(atom->type)
@@ -141,10 +141,10 @@ _d2tk_base_get_atom(d2tk_base_t *base, d2tk_id_t id, d2tk_atom_type_t type,
if(len == 0)
{
- if(atom->deinit)
+ if(atom->event)
{
- atom->deinit(atom->body);
- atom->deinit = NULL;
+ atom->event(D2TK_ATOM_EVENT_DEINIT, atom->body);
+ atom->event = NULL;
}
free(atom->body);
atom->body = 0;
@@ -735,10 +735,10 @@ d2tk_base_free(d2tk_base_t *base)
atom->id = 0;
atom->type = 0;
- if(atom->deinit)
+ if(atom->event)
{
- atom->deinit(atom->body);
- atom->deinit = NULL;
+ atom->event(D2TK_ATOM_EVENT_DEINIT, atom->body);
+ atom->event = NULL;
}
free(atom->body);
atom->body = NULL;
@@ -791,6 +791,24 @@ d2tk_base_post(d2tk_base_t *base)
}
D2TK_API void
+d2tk_base_probe(d2tk_base_t *base)
+{
+ for(unsigned i = 0; i < _D2TK_MAX_ATOM; i++)
+ {
+ d2tk_atom_t *atom = &base->atoms[i];
+
+ if(atom->id && atom->type && atom->event)
+ {
+ if(atom->event(D2TK_ATOM_EVENT_PROBE, atom->body))
+ {
+ d2tk_base_set_again(base);
+ break;
+ }
+ }
+ }
+}
+
+D2TK_API void
d2tk_base_clear_focus(d2tk_base_t *base)
{
base->clear_focus = true;
diff --git a/src/base_internal.h b/src/base_internal.h
index 955a85b..31ad648 100644
--- a/src/base_internal.h
+++ b/src/base_internal.h
@@ -24,10 +24,6 @@
#define _D2TK_MAX_ATOM 0x1000
#define _D2TK_MASK_ATOMS (_D2TK_MAX_ATOM - 1)
-typedef struct _d2tk_flip_t d2tk_flip_t;
-typedef struct _d2tk_atom_t d2tk_atom_t;
-typedef void (*d2tk_atom_deinit_t)(void *data);
-
typedef enum _d2tk_atom_type_t {
D2TK_ATOM_NONE,
D2TK_ATOM_SCROLL,
@@ -40,6 +36,16 @@ typedef enum _d2tk_atom_type_t {
#endif
} d2tk_atom_type_t;
+typedef enum _d2tk_atom_event_type_t {
+ D2TK_ATOM_EVENT_NONE,
+ D2TK_ATOM_EVENT_PROBE,
+ D2TK_ATOM_EVENT_DEINIT
+} d2tk_atom_event_type_t;
+
+typedef struct _d2tk_flip_t d2tk_flip_t;
+typedef struct _d2tk_atom_t d2tk_atom_t;
+typedef int (*d2tk_atom_event_t)(d2tk_atom_event_type_t event, void *data);
+
struct _d2tk_flip_t {
d2tk_id_t old;
d2tk_id_t cur;
@@ -49,7 +55,7 @@ struct _d2tk_atom_t {
d2tk_id_t id;
d2tk_atom_type_t type;
void *body;
- d2tk_atom_deinit_t deinit;
+ d2tk_atom_event_t event;
};
struct _d2tk_base_t {
@@ -110,7 +116,7 @@ extern const size_t d2tk_atom_body_pty_sz;
void *
_d2tk_base_get_atom(d2tk_base_t *base, d2tk_id_t id, d2tk_atom_type_t type,
- d2tk_atom_deinit_t deinit);
+ d2tk_atom_event_t event);
d2tk_state_t
_d2tk_base_is_active_hot_vertical_scroll(d2tk_base_t *base);
diff --git a/src/base_pty.c b/src/base_pty.c
index 6ff3875..10ef17d 100644
--- a/src/base_pty.c
+++ b/src/base_pty.c
@@ -22,7 +22,6 @@
#include <fcntl.h>
#include <vterm.h>
#include <pty.h>
-#include <pthread.h>
#include <sys/wait.h>
#include <poll.h>
@@ -59,9 +58,6 @@ struct _d2tk_atom_body_pty_t {
int fd;
pid_t kid;
- atomic_bool done;
- pthread_t thread;
-
VTerm *vterm;
VTermScreen *screen;
VTermState *state;
@@ -71,7 +67,6 @@ struct _d2tk_atom_body_pty_t {
int cursor_shape;
- bool again;
d2tk_base_t *base;
cell_t cells [NROWS_MAX][NCOLS_MAX];
@@ -79,39 +74,6 @@ struct _d2tk_atom_body_pty_t {
const size_t d2tk_atom_body_pty_sz = sizeof(d2tk_atom_body_pty_t);
-static void *
-_term_thread(void *data)
-{
- d2tk_atom_body_pty_t *vpty = data;
-
- struct pollfd fds = {
- .fd = vpty->fd,
- .events = POLLIN
- };
-
- while(!atomic_load(&vpty->done))
- {
- switch(poll(&fds, 1, 1000))
- {
- case -1:
- {
- //printf("[%s] error: %s\n", __func__, strerror(errno));
- } break;
- case 0:
- {
- //printf("[%s] timeout\n", __func__);
- } break;
- default:
- {
- //printf("[%s] ready\n", __func__);
- d2tk_base_set_again(vpty->base);
- } break;
- }
- }
-
- return NULL;
-}
-
static inline uint32_t
_term_dark(d2tk_atom_body_pty_t *vpty)
{
@@ -179,8 +141,6 @@ _term_output(const char *buf, size_t len, void *data)
fprintf(stderr, "write failed '%s'\n", strerror(errno));
return;
}
-
- vpty->again = true;
}
static int
@@ -347,23 +307,47 @@ _term_init(d2tk_atom_body_pty_t *vpty, char **argv, d2tk_coord_t height,
vterm_screen_set_callbacks(vpty->screen, &screen_callbacks, vpty);
vterm_screen_reset(vpty->screen, 1);
- atomic_init(&vpty->done, false);
- pthread_create(&vpty->thread, NULL, _term_thread, vpty);
-
return 0;
}
-static inline void
+static int
+_term_probe(d2tk_atom_body_pty_t *vpty)
+{
+ int again = 0;
+
+ struct pollfd fds = {
+ .fd = vpty->fd,
+ .events = POLLIN
+ };
+
+ switch(poll(&fds, 1, 0))
+ {
+ case -1:
+ {
+ //printf("[%s] error: %s\n", __func__, strerror(errno));
+ } break;
+ case 0:
+ {
+ //printf("[%s] timeout\n", __func__);
+ } break;
+ default:
+ {
+ //printf("[%s] ready\n", __func__);
+ again = 1;
+ } break;
+ }
+
+ return again;
+}
+
+static int
_term_deinit(d2tk_atom_body_pty_t *vpty)
{
if(!vpty)
{
- return;
+ return 1;
}
- atomic_store(&vpty->done, true);
- pthread_join(vpty->thread, NULL);
-
kill(vpty->kid, SIGINT);
kill(vpty->kid, SIGTERM);
kill(vpty->kid, SIGQUIT);
@@ -372,6 +356,35 @@ _term_deinit(d2tk_atom_body_pty_t *vpty)
vterm_free(vpty->vterm);
memset(vpty, 0x0, sizeof(d2tk_atom_body_pty_t));
+
+ return 0;
+}
+
+static int
+_term_event(d2tk_atom_event_type_t event, void *data)
+{
+ d2tk_atom_body_pty_t *vpty = data;
+
+ switch(event)
+ {
+ case D2TK_ATOM_EVENT_PROBE:
+ {
+ return _term_probe(vpty);
+ } break;
+ case D2TK_ATOM_EVENT_DEINIT:
+ {
+ return _term_deinit(vpty);
+ } break;
+
+ case D2TK_ATOM_EVENT_NONE:
+ // fall-through
+ default:
+ {
+ // nothing to do
+ } break;
+ }
+
+ return 0;
}
static inline void
@@ -530,16 +543,13 @@ _term_input_cb(const char *buf, size_t len, void *data)
vterm_input_write(vpty->vterm, buf, len);
}
-static inline int
+static inline void
_term_input(d2tk_atom_body_pty_t *vpty)
{
if(_term_read(vpty, _term_input_cb, vpty) )
{
_term_update(vpty);
- return 1;
}
-
- return 0;
}
static inline void
@@ -766,7 +776,7 @@ d2tk_base_pty(d2tk_base_t *base, d2tk_id_t id, char **argv, d2tk_coord_t height,
const d2tk_rect_t *rect)
{
d2tk_atom_body_pty_t *vpty = _d2tk_base_get_atom(base, id, D2TK_ATOM_PTY,
- (d2tk_atom_deinit_t)_term_deinit);
+ _term_event);
d2tk_state_t state = D2TK_STATE_NONE;
const d2tk_coord_t width = height / 2;
@@ -797,20 +807,10 @@ d2tk_base_pty(d2tk_base_t *base, d2tk_id_t id, char **argv, d2tk_coord_t height,
_term_behave(base, vpty, rect);
- if(_term_input(vpty))
- {
- vpty->again = true;
- }
+ _term_input(vpty);
_term_draw(base, vpty, rect);
- if(vpty->again)
- {
- d2tk_base_set_again(base);
-
- vpty->again = false;
- }
-
if(_term_done(vpty))
{
_term_deinit(vpty);
diff --git a/src/frontend_pugl.c b/src/frontend_pugl.c
index 6a5c655..d0ff8c7 100644
--- a/src/frontend_pugl.c
+++ b/src/frontend_pugl.c
@@ -409,6 +409,8 @@ _d2tk_pugl_event_func(PuglView *view, const PuglEvent *e)
D2TK_API int
d2tk_pugl_step(d2tk_pugl_t *dpugl)
{
+ d2tk_base_probe(dpugl->base);
+
if(d2tk_base_get_again(dpugl->base))
{
puglPostRedisplay(dpugl->view);