Move per-client window sizes into control.c since the only user is for

control mode.
This commit is contained in:
nicm
2026-07-17 08:37:29 +00:00
committed by tmux update bot
parent a177d0f590
commit 2711780dff
5 changed files with 190 additions and 100 deletions

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: server-client.c,v 1.495 2026/07/17 08:13:23 nicm Exp $ */
/* $OpenBSD: server-client.c,v 1.496 2026/07/17 08:37:29 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -23,6 +23,7 @@
#include <errno.h>
#include <event.h>
#include <fcntl.h>
#include <stdint.h>
#include <imsg.h>
#include <paths.h>
#include <stdlib.h>
@@ -48,24 +49,46 @@ static void server_client_set_path(struct client *);
static void server_client_set_progress_bar(struct client *);
static void server_client_reset_state(struct client *);
static void server_client_update_latest(struct client *);
static void server_client_remove_active_pane_client(struct client *);
static void server_client_dispatch(struct imsg *, void *);
static int server_client_dispatch_command(struct client *, struct imsg *);
static int server_client_dispatch_identify(struct client *, struct imsg *);
static int server_client_dispatch_shell(struct client *);
static void server_client_report_theme(struct client *, enum client_theme);
/* Compare client windows. */
/* Client active pane. */
struct client_active_pane {
struct client *client;
u_int window;
struct window_pane *pane;
RB_ENTRY(client_active_pane) entry;
};
RB_HEAD(client_active_panes, client_active_pane);
/* Compare client active panes. */
static int
server_client_window_cmp(struct client_window *cw1,
struct client_window *cw2)
server_client_active_pane_cmp(struct client_active_pane *cap1,
struct client_active_pane *cap2)
{
if (cw1->window < cw2->window)
uintptr_t c1 = (uintptr_t)cap1->client;
uintptr_t c2 = (uintptr_t)cap2->client;
if (c1 < c2)
return (-1);
if (cw1->window > cw2->window)
if (c1 > c2)
return (1);
if (cap1->window < cap2->window)
return (-1);
if (cap1->window > cap2->window)
return (1);
return (0);
}
RB_GENERATE(client_windows, client_window, entry, server_client_window_cmp);
RB_GENERATE_STATIC(client_active_panes, client_active_pane, entry,
server_client_active_pane_cmp);
static struct client_active_panes client_active_panes =
RB_INITIALIZER(&client_active_panes);
/* Number of attached clients. */
u_int
@@ -309,7 +332,6 @@ server_client_create(int fd)
c->out_fd = -1;
c->queue = cmdq_new();
RB_INIT(&c->windows);
RB_INIT(&c->files);
c->tty.sx = 80;
@@ -500,7 +522,6 @@ void
server_client_lost(struct client *c)
{
struct client_file *cf, *cf1;
struct client_window *cw, *cw1;
if (cfg_client == c)
cfg_client = NULL;
@@ -509,15 +530,12 @@ server_client_lost(struct client *c)
server_client_clear_overlay(c);
status_prompt_clear(c);
status_message_clear(c);
server_client_remove_active_pane_client(c);
RB_FOREACH_SAFE(cf, client_files, &c->files, cf1) {
cf->error = EINTR;
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);
log_debug("lost client %p", c);
@@ -3083,28 +3101,29 @@ server_client_get_flags(struct client *c)
return (s);
}
/* Get client window. */
struct client_window *
server_client_get_client_window(struct client *c, u_int id)
/* Get client active pane. */
static struct client_active_pane *
server_client_get_active_pane(struct client *c, u_int id)
{
struct client_window cw = { .window = id };
struct client_active_pane cap = { .client = c, .window = id };
return (RB_FIND(client_windows, &c->windows, &cw));
return (RB_FIND(client_active_panes, &client_active_panes, &cap));
}
/* Add client window. */
struct client_window *
server_client_add_client_window(struct client *c, u_int id)
/* Add client active pane. */
static struct client_active_pane *
server_client_add_active_pane(struct client *c, u_int id)
{
struct client_window *cw;
struct client_active_pane *cap;
cw = server_client_get_client_window(c, id);
if (cw == NULL) {
cw = xcalloc(1, sizeof *cw);
cw->window = id;
RB_INSERT(client_windows, &c->windows, cw);
cap = server_client_get_active_pane(c, id);
if (cap == NULL) {
cap = xcalloc(1, sizeof *cap);
cap->client = c;
cap->window = id;
RB_INSERT(client_active_panes, &client_active_panes, cap);
}
return (cw);
return (cap);
}
/* Get client active pane. */
@@ -3113,7 +3132,7 @@ server_client_get_pane(struct client *c)
{
struct session *s = c->session;
struct window *w;
struct client_window *cw;
struct client_active_pane *cap;
if (s == NULL)
return (NULL);
@@ -3123,10 +3142,10 @@ server_client_get_pane(struct client *c)
return (w->modal);
if (~c->flags & CLIENT_ACTIVEPANE)
return (w->active);
cw = server_client_get_client_window(c, w->id);
if (cw == NULL)
cap = server_client_get_active_pane(c, w->id);
if (cap == NULL)
return (w->active);
return (cw->pane);
return (cap->pane);
}
/* Set client active pane. */
@@ -3134,32 +3153,47 @@ void
server_client_set_pane(struct client *c, struct window_pane *wp)
{
struct session *s = c->session;
struct client_window *cw;
struct client_active_pane *cap;
if (s == NULL)
return;
if (wp->window->modal != NULL && wp != wp->window->modal)
return;
cw = server_client_add_client_window(c, s->curw->window->id);
cw->pane = wp;
cap = server_client_add_active_pane(c, s->curw->window->id);
cap->pane = wp;
log_debug("%s pane now %%%u", c->name, wp->id);
}
/* Remove pane from client lists. */
/* Remove active pane entries for a client. */
static void
server_client_remove_active_pane_client(struct client *c)
{
struct client_active_pane *cap, *cap1;
RB_FOREACH_SAFE(cap, client_active_panes, &client_active_panes, cap1) {
if (cap->client == c) {
RB_REMOVE(client_active_panes, &client_active_panes, cap);
free(cap);
}
}
}
/* Remove pane from client state. */
void
server_client_remove_pane(struct window_pane *wp)
{
struct client *c;
struct window *w = wp->window;
struct client_window *cw;
struct client *c;
struct client_active_pane *cap, *cap1;
RB_FOREACH_SAFE(cap, client_active_panes, &client_active_panes, cap1) {
if (cap->pane == wp) {
RB_REMOVE(client_active_panes, &client_active_panes, cap);
free(cap);
}
}
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);
}
if (c->tty.mouse_last_pane == (int)wp->id) {
c->tty.mouse_last_pane = -1;
c->tty.mouse_drag_update = NULL;