mirror of
https://github.com/tmux/tmux.git
synced 2024-12-13 01:48:47 +00:00
Give control code its own state struct.
This commit is contained in:
parent
6c82982711
commit
18aab90959
43
control.c
43
control.c
@ -38,6 +38,11 @@ struct control_offset {
|
|||||||
};
|
};
|
||||||
RB_HEAD(control_offsets, control_offset);
|
RB_HEAD(control_offsets, control_offset);
|
||||||
|
|
||||||
|
/* Control state. */
|
||||||
|
struct control_state {
|
||||||
|
struct control_offsets offsets;
|
||||||
|
};
|
||||||
|
|
||||||
/* Compare client offsets. */
|
/* Compare client offsets. */
|
||||||
static int
|
static int
|
||||||
control_offset_cmp(struct control_offset *co1, struct control_offset *co2)
|
control_offset_cmp(struct control_offset *co1, struct control_offset *co2)
|
||||||
@ -54,31 +59,26 @@ RB_GENERATE_STATIC(control_offsets, control_offset, entry, control_offset_cmp);
|
|||||||
static struct control_offset *
|
static struct control_offset *
|
||||||
control_get_offset(struct client *c, struct window_pane *wp)
|
control_get_offset(struct client *c, struct window_pane *wp)
|
||||||
{
|
{
|
||||||
struct control_offset co = { .pane = wp->id };
|
struct control_state *cs = c->control_state;
|
||||||
|
struct control_offset co = { .pane = wp->id };
|
||||||
|
|
||||||
if (c->offsets == NULL)
|
return (RB_FIND(control_offsets, &cs->offsets, &co));
|
||||||
return (NULL);
|
|
||||||
return (RB_FIND(control_offsets, c->offsets, &co));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add pane offsets for this client. */
|
/* Add pane offsets for this client. */
|
||||||
static struct control_offset *
|
static struct control_offset *
|
||||||
control_add_offset(struct client *c, struct window_pane *wp)
|
control_add_offset(struct client *c, struct window_pane *wp)
|
||||||
{
|
{
|
||||||
|
struct control_state *cs = c->control_state;
|
||||||
struct control_offset *co;
|
struct control_offset *co;
|
||||||
|
|
||||||
co = control_get_offset(c, wp);
|
co = control_get_offset(c, wp);
|
||||||
if (co != NULL)
|
if (co != NULL)
|
||||||
return (co);
|
return (co);
|
||||||
|
|
||||||
if (c->offsets == NULL) {
|
|
||||||
c->offsets = xmalloc(sizeof *c->offsets);
|
|
||||||
RB_INIT(c->offsets);
|
|
||||||
}
|
|
||||||
|
|
||||||
co = xcalloc(1, sizeof *co);
|
co = xcalloc(1, sizeof *co);
|
||||||
co->pane = wp->id;
|
co->pane = wp->id;
|
||||||
RB_INSERT(control_offsets, c->offsets, co);
|
RB_INSERT(control_offsets, &cs->offsets, co);
|
||||||
memcpy(&co->offset, &wp->offset, sizeof co->offset);
|
memcpy(&co->offset, &wp->offset, sizeof co->offset);
|
||||||
return (co);
|
return (co);
|
||||||
}
|
}
|
||||||
@ -87,15 +87,13 @@ control_add_offset(struct client *c, struct window_pane *wp)
|
|||||||
void
|
void
|
||||||
control_free_offsets(struct client *c)
|
control_free_offsets(struct client *c)
|
||||||
{
|
{
|
||||||
|
struct control_state *cs = c->control_state;
|
||||||
struct control_offset *co, *co1;
|
struct control_offset *co, *co1;
|
||||||
|
|
||||||
if (c->offsets == NULL)
|
RB_FOREACH_SAFE(co, control_offsets, &cs->offsets, co1) {
|
||||||
return;
|
RB_REMOVE(control_offsets, &cs->offsets, co);
|
||||||
RB_FOREACH_SAFE(co, control_offsets, c->offsets, co1) {
|
|
||||||
RB_REMOVE(control_offsets, c->offsets, co);
|
|
||||||
free(co);
|
free(co);
|
||||||
}
|
}
|
||||||
free(c->offsets);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get offsets for client. */
|
/* Get offsets for client. */
|
||||||
@ -255,8 +253,23 @@ control_callback(__unused struct client *c, __unused const char *path,
|
|||||||
void
|
void
|
||||||
control_start(struct client *c)
|
control_start(struct client *c)
|
||||||
{
|
{
|
||||||
|
struct control_state *cs;
|
||||||
|
|
||||||
|
cs = c->control_state = xcalloc(1, sizeof *cs);
|
||||||
|
RB_INIT(&cs->offsets);
|
||||||
|
|
||||||
file_read(c, "-", control_callback, c);
|
file_read(c, "-", control_callback, c);
|
||||||
|
|
||||||
if (c->flags & CLIENT_CONTROLCONTROL)
|
if (c->flags & CLIENT_CONTROLCONTROL)
|
||||||
file_print(c, "\033P1000p");
|
file_print(c, "\033P1000p");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Stop control mode. */
|
||||||
|
void
|
||||||
|
control_stop(struct client *c)
|
||||||
|
{
|
||||||
|
struct control_state *cs = c->control_state;
|
||||||
|
|
||||||
|
control_free_offsets(c);
|
||||||
|
free(cs);
|
||||||
|
}
|
||||||
|
@ -306,6 +306,8 @@ server_client_lost(struct client *c)
|
|||||||
TAILQ_REMOVE(&clients, c, entry);
|
TAILQ_REMOVE(&clients, c, entry);
|
||||||
log_debug("lost client %p", c);
|
log_debug("lost client %p", c);
|
||||||
|
|
||||||
|
if (c->flags & CLIENT_CONTROL)
|
||||||
|
control_stop(c);
|
||||||
if (c->flags & CLIENT_TERMINAL)
|
if (c->flags & CLIENT_TERMINAL)
|
||||||
tty_free(&c->tty);
|
tty_free(&c->tty);
|
||||||
free(c->ttyname);
|
free(c->ttyname);
|
||||||
|
5
tmux.h
5
tmux.h
@ -45,7 +45,7 @@ struct cmdq_item;
|
|||||||
struct cmdq_list;
|
struct cmdq_list;
|
||||||
struct cmdq_state;
|
struct cmdq_state;
|
||||||
struct cmds;
|
struct cmds;
|
||||||
struct control_offsets;
|
struct control_state;
|
||||||
struct environ;
|
struct environ;
|
||||||
struct format_job_tree;
|
struct format_job_tree;
|
||||||
struct format_tree;
|
struct format_tree;
|
||||||
@ -1563,7 +1563,7 @@ struct client {
|
|||||||
struct cmdq_list *queue;
|
struct cmdq_list *queue;
|
||||||
|
|
||||||
struct client_windows windows;
|
struct client_windows windows;
|
||||||
struct control_offsets *offsets;
|
struct control_state *control_state;
|
||||||
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int fd;
|
int fd;
|
||||||
@ -2813,6 +2813,7 @@ char *parse_window_name(const char *);
|
|||||||
|
|
||||||
/* control.c */
|
/* control.c */
|
||||||
void control_start(struct client *);
|
void control_start(struct client *);
|
||||||
|
void control_stop(struct client *);
|
||||||
void control_set_pane_on(struct client *, struct window_pane *);
|
void control_set_pane_on(struct client *, struct window_pane *);
|
||||||
void control_set_pane_off(struct client *, struct window_pane *);
|
void control_set_pane_off(struct client *, struct window_pane *);
|
||||||
struct window_pane_offset *control_pane_offset(struct client *,
|
struct window_pane_offset *control_pane_offset(struct client *,
|
||||||
|
Loading…
Reference in New Issue
Block a user