version 1.340, 2020/05/16 16:16:07 |
version 1.341, 2020/05/16 16:20:59 |
|
|
static void server_client_dispatch_read_done(struct client *, |
static void server_client_dispatch_read_done(struct client *, |
struct imsg *); |
struct imsg *); |
|
|
|
/* Compare client windows. */ |
|
static int |
|
server_client_window_cmp(struct client_window *cw1, |
|
struct client_window *cw2) |
|
{ |
|
if (cw1->window < cw2->window) |
|
return (-1); |
|
if (cw1->window > cw2->window) |
|
return (1); |
|
return (0); |
|
} |
|
RB_GENERATE(client_windows, client_window, entry, server_client_window_cmp); |
|
|
/* Number of attached clients. */ |
/* Number of attached clients. */ |
u_int |
u_int |
server_client_how_many(void) |
server_client_how_many(void) |
|
|
c->cwd = NULL; |
c->cwd = NULL; |
|
|
c->queue = cmdq_new(); |
c->queue = cmdq_new(); |
|
RB_INIT(&c->windows); |
|
|
c->tty.fd = -1; |
c->tty.fd = -1; |
c->tty.sx = 80; |
c->tty.sx = 80; |
|
|
server_client_lost(struct client *c) |
server_client_lost(struct client *c) |
{ |
{ |
struct client_file *cf, *cf1; |
struct client_file *cf, *cf1; |
|
struct client_window *cw, *cw1; |
|
|
c->flags |= CLIENT_DEAD; |
c->flags |= CLIENT_DEAD; |
|
|
|
|
cf->error = EINTR; |
cf->error = EINTR; |
file_fire_done(cf); |
file_fire_done(cf); |
} |
} |
|
RB_FOREACH_SAFE(cw, client_windows, &c->windows, cw1) { |
|
RB_REMOVE(client_windows, &c->windows, cw); |
|
free(cw); |
|
} |
|
|
TAILQ_REMOVE(&clients, c, entry); |
TAILQ_REMOVE(&clients, c, entry); |
log_debug("lost client %p", c); |
log_debug("lost client %p", c); |
|
|
|
|
/* Find affected pane. */ |
/* Find affected pane. */ |
if (!KEYC_IS_MOUSE(key) || cmd_find_from_mouse(&fs, m, 0) != 0) |
if (!KEYC_IS_MOUSE(key) || cmd_find_from_mouse(&fs, m, 0) != 0) |
cmd_find_from_session(&fs, s, 0); |
cmd_find_from_client(&fs, c, 0); |
wp = fs.wp; |
wp = fs.wp; |
|
|
/* Forward mouse keys if disabled. */ |
/* Forward mouse keys if disabled. */ |
|
|
{ |
{ |
struct tty *tty = &c->tty; |
struct tty *tty = &c->tty; |
struct window *w = c->session->curw->window; |
struct window *w = c->session->curw->window; |
struct window_pane *wp = w->active, *loop; |
struct window_pane *wp = server_client_get_pane(c), *loop; |
struct screen *s = NULL; |
struct screen *s = NULL; |
struct options *oo = c->session->options; |
struct options *oo = c->session->options; |
int mode = 0, cursor, flags; |
int mode = 0, cursor, flags; |
|
|
flag = CLIENT_READONLY; |
flag = CLIENT_READONLY; |
else if (strcmp(next, "ignore-size") == 0) |
else if (strcmp(next, "ignore-size") == 0) |
flag = CLIENT_IGNORESIZE; |
flag = CLIENT_IGNORESIZE; |
|
else if (strcmp(next, "active-pane") == 0) |
|
flag = CLIENT_ACTIVEPANE; |
else |
else |
continue; |
continue; |
|
|
|
|
strlcat(s, "no-output,", sizeof s); |
strlcat(s, "no-output,", sizeof s); |
if (c->flags & CLIENT_READONLY) |
if (c->flags & CLIENT_READONLY) |
strlcat(s, "read-only,", sizeof s); |
strlcat(s, "read-only,", sizeof s); |
|
if (c->flags & CLIENT_ACTIVEPANE) |
|
strlcat(s, "active-pane,", sizeof s); |
if (c->flags & CLIENT_SUSPENDED) |
if (c->flags & CLIENT_SUSPENDED) |
strlcat(s, "suspended,", sizeof s); |
strlcat(s, "suspended,", sizeof s); |
if (c->flags & CLIENT_UTF8) |
if (c->flags & CLIENT_UTF8) |
|
|
if (*s != '\0') |
if (*s != '\0') |
s[strlen(s) - 1] = '\0'; |
s[strlen(s) - 1] = '\0'; |
return (s); |
return (s); |
|
} |
|
|
|
/* Get client window. */ |
|
static struct client_window * |
|
server_client_get_client_window(struct client *c, u_int id) |
|
{ |
|
struct client_window cw = { .window = id }; |
|
|
|
return (RB_FIND(client_windows, &c->windows, &cw)); |
|
} |
|
|
|
/* Get client active pane. */ |
|
struct window_pane * |
|
server_client_get_pane(struct client *c) |
|
{ |
|
struct session *s = c->session; |
|
struct client_window *cw; |
|
|
|
if (s == NULL) |
|
return (NULL); |
|
|
|
if (~c->flags & CLIENT_ACTIVEPANE) |
|
return (s->curw->window->active); |
|
cw = server_client_get_client_window(c, s->curw->window->id); |
|
if (cw == NULL) |
|
return (s->curw->window->active); |
|
return (cw->pane); |
|
} |
|
|
|
/* Set client active pane. */ |
|
void |
|
server_client_set_pane(struct client *c, struct window_pane *wp) |
|
{ |
|
struct session *s = c->session; |
|
struct client_window *cw; |
|
|
|
if (s == NULL) |
|
return; |
|
|
|
cw = server_client_get_client_window(c, s->curw->window->id); |
|
if (cw == NULL) { |
|
cw = xcalloc(1, sizeof *cw); |
|
cw->window = s->curw->window->id; |
|
RB_INSERT(client_windows, &c->windows, cw); |
|
} |
|
cw->pane = wp; |
|
log_debug("%s pane now %%%u", c->name, wp->id); |
|
} |
|
|
|
/* Remove pane from client lists. */ |
|
void |
|
server_client_remove_pane(struct window_pane *wp) |
|
{ |
|
struct client *c; |
|
struct window *w = wp->window; |
|
struct client_window *cw; |
|
|
|
TAILQ_FOREACH(c, &clients, entry) { |
|
cw = server_client_get_client_window(c, w->id); |
|
if (cw != NULL && cw->pane == wp) { |
|
RB_REMOVE(client_windows, &c->windows, cw); |
|
free(cw); |
|
} |
|
} |
} |
} |