Be more conservative about redrawing using flags.

This commit is contained in:
Nicholas Marriott 2008-06-07 06:47:38 +00:00
parent 6f7d59d279
commit 77224aaf8b
3 changed files with 66 additions and 30 deletions

View File

@ -1,4 +1,4 @@
/* $Id: server-fn.c,v 1.38 2008-06-03 21:42:37 nicm Exp $ */
/* $Id: server-fn.c,v 1.39 2008-06-07 06:47:38 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -48,7 +48,9 @@ server_write_session(
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c != NULL && c->session == s)
if (c == NULL || c->session == NULL)
continue;
if (c->session == s)
server_write_client(c, type, buf, len);
}
}
@ -85,19 +87,13 @@ server_clear_client(struct client *c)
void
server_redraw_client(struct client *c)
{
struct screen_redraw_ctx ctx;
screen_redraw_start_client(&ctx, c);
screen_redraw_lines(&ctx, 0, screen_size_y(ctx.s));
screen_redraw_stop(&ctx);
status_write_client(c);
c->flags |= CLIENT_REDRAW;
}
void
server_status_client(struct client *c)
{
status_write_client(c);
c->flags |= CLIENT_STATUS;
}
void
@ -116,19 +112,31 @@ server_clear_session(struct session *s)
void
server_redraw_session(struct session *s)
{
struct screen_redraw_ctx ctx;
struct client *c;
u_int i;
screen_redraw_start_session(&ctx, s);
screen_redraw_lines(&ctx, 0, screen_size_y(ctx.s));
screen_redraw_stop(&ctx);
status_write_session(s);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c == NULL || c->session == NULL)
continue;
if (c->session == s)
server_redraw_client(c);
}
}
void
server_status_session(struct session *s)
{
status_write_session(s);
struct client *c;
u_int i;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c == NULL || c->session == NULL)
continue;
if (c->session == s)
server_status_client(c);
}
}
void
@ -147,13 +155,16 @@ server_clear_window(struct window *w)
void
server_redraw_window(struct window *w)
{
struct screen_redraw_ctx ctx;
struct client *c;
u_int i;
screen_redraw_start_window(&ctx, w);
screen_redraw_lines(&ctx, 0, screen_size_y(ctx.s));
screen_redraw_stop(&ctx);
status_write_window(w);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c == NULL || c->session == NULL)
continue;
if (c->session->curw->window == w)
server_redraw_client(c);
}
}
void

View File

@ -1,4 +1,4 @@
/* $Id: server.c,v 1.56 2008-06-07 06:13:21 nicm Exp $ */
/* $Id: server.c,v 1.57 2008-06-07 06:47:38 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -54,6 +54,7 @@ void server_handle_client(struct client *);
void server_handle_window(struct window *);
void server_lost_client(struct client *);
void server_lost_window(struct window *);
void server_check_redraw(struct client *);
void server_check_status(struct client *);
/* Fork new server. */
@ -269,6 +270,26 @@ server_handle_windows(struct pollfd **pfd)
}
}
/* Check for general redraw on client. */
void
server_check_redraw(struct client *c)
{
struct screen_redraw_ctx ctx;
if (c == NULL || c->session == NULL)
return;
if (c->flags & CLIENT_REDRAW) {
screen_redraw_start_client(&ctx, c);
screen_redraw_lines(&ctx, 0, screen_size_y(ctx.s));
screen_redraw_stop(&ctx);
status_write_client(c);
} else if (c->flags & CLIENT_STATUS)
status_write_client(c);
c->flags &= ~(CLIENT_REDRAW|CLIENT_STATUS);
}
/* Check for status line redraw on client. */
void
server_check_status(struct client *c)
@ -276,8 +297,9 @@ server_check_status(struct client *c)
struct timespec ts;
u_int nlines, interval;
if (c->session == NULL)
if (c == NULL || c->session == NULL)
return;
nlines = options_get_number(&c->session->options, "status-lines");
interval = options_get_number(&c->session->options, "status-interval");
if (nlines == 0 || interval == 0)
@ -288,7 +310,7 @@ server_check_status(struct client *c)
ts.tv_sec -= interval;
if (timespeccmp(&c->status_ts, &ts, <))
server_status_client(c);
c->flags |= CLIENT_STATUS;
}
/* Fill client pollfds. */
@ -301,6 +323,9 @@ server_fill_clients(struct pollfd **pfd)
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
server_check_redraw(c);
server_check_status(c);
if (c == NULL)
(*pfd)->fd = -1;
else {
@ -335,9 +360,7 @@ server_handle_clients(struct pollfd **pfd)
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c != NULL) {
server_check_status(c);
if (c != NULL) {
log_debug("testing client %d (%d)", (*pfd)->fd, c->fd);
if (buffer_poll(*pfd, c->in, c->out) != 0) {
server_lost_client(c);

4
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.136 2008-06-06 20:02:27 nicm Exp $ */
/* $Id: tmux.h,v 1.137 2008-06-07 06:47:38 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -649,6 +649,8 @@ struct client {
#define CLIENT_TERMINAL 0x1
#define CLIENT_PREFIX 0x2
#define CLIENT_MOUSE 0x4
#define CLIENT_REDRAW 0x8
#define CLIENT_STATUS 0x10
int flags;
struct session *session;