pty: merge input and close callbacks
There is no reason to keep two callbacks as the caller always registers both. Hence, we can use a shared callback. Reading length 0 means closed like reading from an fd. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
da0623c260
commit
ecb7ddbc29
22
src/pty.c
22
src/pty.c
@ -50,9 +50,6 @@ struct kmscon_pty {
|
|||||||
|
|
||||||
kmscon_pty_input_cb input_cb;
|
kmscon_pty_input_cb input_cb;
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
kmscon_pty_closed_cb closed_cb;
|
|
||||||
void *closed_data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int kmscon_pty_new(struct kmscon_pty **out, struct kmscon_eloop *loop,
|
int kmscon_pty_new(struct kmscon_pty **out, struct kmscon_eloop *loop,
|
||||||
@ -290,12 +287,12 @@ static void pty_input(struct kmscon_fd *fd, int mask, void *data)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pty->input_cb)
|
if (pty->input_cb && len)
|
||||||
pty->input_cb(pty, u8, len, pty->data);
|
pty->input_cb(pty, u8, len, pty->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
int kmscon_pty_open(struct kmscon_pty *pty, unsigned short width,
|
int kmscon_pty_open(struct kmscon_pty *pty, unsigned short width,
|
||||||
unsigned short height, kmscon_pty_closed_cb closed_cb, void *data)
|
unsigned short height)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -317,32 +314,21 @@ int kmscon_pty_open(struct kmscon_pty *pty, unsigned short width,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
pty->closed_cb = closed_cb;
|
|
||||||
pty->closed_data = data;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kmscon_pty_close(struct kmscon_pty *pty)
|
void kmscon_pty_close(struct kmscon_pty *pty)
|
||||||
{
|
{
|
||||||
kmscon_pty_closed_cb cb;
|
|
||||||
void *data;
|
|
||||||
|
|
||||||
if (!pty || pty->fd < 0)
|
if (!pty || pty->fd < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
kmscon_eloop_rm_fd(pty->efd);
|
kmscon_eloop_rm_fd(pty->efd);
|
||||||
pty->efd = NULL;
|
pty->efd = NULL;
|
||||||
|
|
||||||
close(pty->fd);
|
close(pty->fd);
|
||||||
pty->fd = -1;
|
pty->fd = -1;
|
||||||
|
|
||||||
cb = pty->closed_cb;
|
if (pty->input_cb)
|
||||||
data = pty->closed_data;
|
pty->input_cb(pty, NULL, 0, pty->data);
|
||||||
pty->closed_cb = NULL;
|
|
||||||
pty->closed_data = NULL;
|
|
||||||
|
|
||||||
if (cb)
|
|
||||||
cb(pty, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void kmscon_pty_write(struct kmscon_pty *pty, const char *u8, size_t len)
|
void kmscon_pty_write(struct kmscon_pty *pty, const char *u8, size_t len)
|
||||||
|
@ -49,7 +49,6 @@ struct kmscon_pty;
|
|||||||
|
|
||||||
typedef void (*kmscon_pty_input_cb)
|
typedef void (*kmscon_pty_input_cb)
|
||||||
(struct kmscon_pty *pty, char *u8, size_t len, void *data);
|
(struct kmscon_pty *pty, char *u8, size_t len, void *data);
|
||||||
typedef void (*kmscon_pty_closed_cb) (struct kmscon_pty *pty, void *data);
|
|
||||||
|
|
||||||
int kmscon_pty_new(struct kmscon_pty **out, struct kmscon_eloop *loop,
|
int kmscon_pty_new(struct kmscon_pty **out, struct kmscon_eloop *loop,
|
||||||
kmscon_pty_input_cb input_cb, void *data);
|
kmscon_pty_input_cb input_cb, void *data);
|
||||||
@ -57,7 +56,7 @@ void kmscon_pty_ref(struct kmscon_pty *pty);
|
|||||||
void kmscon_pty_unref(struct kmscon_pty *pty);
|
void kmscon_pty_unref(struct kmscon_pty *pty);
|
||||||
|
|
||||||
int kmscon_pty_open(struct kmscon_pty *pty, unsigned short width,
|
int kmscon_pty_open(struct kmscon_pty *pty, unsigned short width,
|
||||||
unsigned short height, kmscon_pty_closed_cb closed_cb, void *data);
|
unsigned short height);
|
||||||
void kmscon_pty_close(struct kmscon_pty *pty);
|
void kmscon_pty_close(struct kmscon_pty *pty);
|
||||||
|
|
||||||
void kmscon_pty_write(struct kmscon_pty *pty, const char *u8, size_t len);
|
void kmscon_pty_write(struct kmscon_pty *pty, const char *u8, size_t len);
|
||||||
|
@ -111,12 +111,16 @@ static void pty_input(struct kmscon_pty *pty, char *u8, size_t len, void *data)
|
|||||||
size_t i;
|
size_t i;
|
||||||
struct kmscon_terminal *term = data;
|
struct kmscon_terminal *term = data;
|
||||||
|
|
||||||
/* FIXME: UTF-8. */
|
if (!len) {
|
||||||
for (i=0; i < len; i++)
|
kmscon_terminal_close(term);
|
||||||
if (u8[i] < 128)
|
} else {
|
||||||
kmscon_vte_input(term->vte, u8[i]);
|
/* FIXME: UTF-8. */
|
||||||
|
for (i=0; i < len; i++)
|
||||||
|
if (u8[i] < 128)
|
||||||
|
kmscon_vte_input(term->vte, u8[i]);
|
||||||
|
|
||||||
schedule_redraw(term);
|
schedule_redraw(term);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int kmscon_terminal_new(struct kmscon_terminal **out,
|
int kmscon_terminal_new(struct kmscon_terminal **out,
|
||||||
@ -203,12 +207,6 @@ void kmscon_terminal_unref(struct kmscon_terminal *term)
|
|||||||
log_debug("terminal: destroying terminal object\n");
|
log_debug("terminal: destroying terminal object\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pty_closed(struct kmscon_pty *pty, void *data)
|
|
||||||
{
|
|
||||||
struct kmscon_terminal *term = data;
|
|
||||||
kmscon_terminal_close(term);
|
|
||||||
}
|
|
||||||
|
|
||||||
int kmscon_terminal_open(struct kmscon_terminal *term,
|
int kmscon_terminal_open(struct kmscon_terminal *term,
|
||||||
kmscon_terminal_closed_cb closed_cb, void *data)
|
kmscon_terminal_closed_cb closed_cb, void *data)
|
||||||
{
|
{
|
||||||
@ -220,7 +218,7 @@ int kmscon_terminal_open(struct kmscon_terminal *term,
|
|||||||
|
|
||||||
width = kmscon_console_get_width(term->console);
|
width = kmscon_console_get_width(term->console);
|
||||||
height = kmscon_console_get_height(term->console);
|
height = kmscon_console_get_height(term->console);
|
||||||
ret = kmscon_pty_open(term->pty, width, height, pty_closed, term);
|
ret = kmscon_pty_open(term->pty, width, height);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user