set/reset mode window functions.

This commit is contained in:
Nicholas Marriott 2007-12-06 10:04:43 +00:00
parent 103748d6ad
commit 7dc18f68e3
9 changed files with 67 additions and 58 deletions

3
TODO
View File

@ -61,8 +61,7 @@
- chmod +x socket when any client is attached - chmod +x socket when any client is attached
- split clients into three RB trees by fd: attached/unattached/dead? - split clients into three RB trees by fd: attached/unattached/dead?
or tailqs? what would be fastest per-char? or tailqs? what would be fastest per-char?
- everything should write via a screen and modes should be done by switching - multiple paste buffers
screen out
-- For 0.2 -------------------------------------------------------------------- -- For 0.2 --------------------------------------------------------------------
- window splitting? - window splitting?

View File

@ -1,4 +1,4 @@
/* $Id: cmd-copy-mode.c,v 1.3 2007-12-06 09:46:21 nicm Exp $ */ /* $Id: cmd-copy-mode.c,v 1.4 2007-12-06 10:04:42 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -44,11 +44,8 @@ cmd_copy_mode_exec(unused void *ptr, struct cmd_ctx *ctx)
{ {
struct window *w = ctx->session->curw->window; struct window *w = ctx->session->curw->window;
if (w->mode == NULL && ctx->flags & CMD_KEY) { if (ctx->flags & CMD_KEY)
w->mode = &window_copy_mode; window_set_mode(w, &window_copy_mode);
w->mode->init(w);
server_redraw_window(w);
}
if (ctx->cmdclient != NULL) if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);

View File

@ -1,4 +1,4 @@
/* $Id: cmd-scroll-mode.c,v 1.5 2007-12-06 09:46:22 nicm Exp $ */ /* $Id: cmd-scroll-mode.c,v 1.6 2007-12-06 10:04:42 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -44,11 +44,8 @@ cmd_scroll_mode_exec(unused void *ptr, struct cmd_ctx *ctx)
{ {
struct window *w = ctx->session->curw->window; struct window *w = ctx->session->curw->window;
if (w->mode == NULL && ctx->flags & CMD_KEY) { if (ctx->flags & CMD_KEY)
w->mode = &window_scroll_mode; window_set_mode(w, &window_scroll_mode);
w->mode->init(w);
server_redraw_window(w);
}
if (ctx->cmdclient != NULL) if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);

View File

@ -1,4 +1,4 @@
/* $Id: key-bindings.c,v 1.23 2007-12-06 09:46:22 nicm Exp $ */ /* $Id: key-bindings.c,v 1.24 2007-12-06 10:04:42 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -165,11 +165,7 @@ key_bindings_print(struct cmd_ctx *ctx, const char *fmt, ...)
struct window *w = ctx->session->curw->window; struct window *w = ctx->session->curw->window;
va_list ap; va_list ap;
if (w->mode == NULL) { if (window_set_mode(w, &window_more_mode) != 0)
w->mode = &window_more_mode;
w->mode->init(w);
server_redraw_window(w);
} else if (w->mode != &window_more_mode)
return; return;
va_start(ap, fmt); va_start(ap, fmt);

6
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.109 2007-12-06 09:46:23 nicm Exp $ */ /* $Id: tmux.h,v 1.110 2007-12-06 10:04:42 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -467,7 +467,7 @@ struct input_ctx {
* right function to handle input and output. * right function to handle input and output.
*/ */
struct window_mode { struct window_mode {
void (*init)(struct window *); struct screen *(*init)(struct window *);
void (*free)(struct window *); void (*free)(struct window *);
void (*resize)(struct window *, u_int, u_int); void (*resize)(struct window *, u_int, u_int);
void (*key)(struct window *, int); void (*key)(struct window *, int);
@ -905,6 +905,8 @@ struct window *window_create(
const char *, const char *, const char **, u_int, u_int); const char *, const char *, const char **, u_int, u_int);
void window_destroy(struct window *); void window_destroy(struct window *);
int window_resize(struct window *, u_int, u_int); int window_resize(struct window *, u_int, u_int);
int window_set_mode(struct window *, const struct window_mode *);
void window_reset_mode(struct window *);
void window_parse(struct window *); void window_parse(struct window *);
void window_key(struct window *, int); void window_key(struct window *, int);

View File

@ -1,4 +1,4 @@
/* $Id: window-copy.c,v 1.13 2007-12-06 09:46:23 nicm Exp $ */ /* $Id: window-copy.c,v 1.14 2007-12-06 10:04:43 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -22,7 +22,7 @@
#include "tmux.h" #include "tmux.h"
void window_copy_init(struct window *); struct screen *window_copy_init(struct window *);
void window_copy_free(struct window *); void window_copy_free(struct window *);
void window_copy_resize(struct window *, u_int, u_int); void window_copy_resize(struct window *, u_int, u_int);
void window_copy_key(struct window *, int); void window_copy_key(struct window *, int);
@ -76,7 +76,7 @@ struct window_copy_mode_data {
u_int cy; u_int cy;
}; };
void struct screen *
window_copy_init(struct window *w) window_copy_init(struct window *w)
{ {
struct window_copy_mode_data *data; struct window_copy_mode_data *data;
@ -94,13 +94,14 @@ window_copy_init(struct window *w)
screen_create(s, screen_size_x(&w->base), screen_size_y(&w->base)); screen_create(s, screen_size_x(&w->base), screen_size_y(&w->base));
s->cx = data->cx; s->cx = data->cx;
s->cy = data->cy; s->cy = data->cy;
w->screen = s;
screen_write_start(&ctx, s, NULL, NULL); screen_write_start(&ctx, s, NULL, NULL);
for (i = 0; i < screen_size_y(s); i++) for (i = 0; i < screen_size_y(s); i++)
window_copy_write_line(w, &ctx, i); window_copy_write_line(w, &ctx, i);
screen_write_move_cursor(&ctx, data->cx, data->cy); screen_write_move_cursor(&ctx, data->cx, data->cy);
screen_write_stop(&ctx); screen_write_stop(&ctx);
return (s);
} }
void void
@ -108,11 +109,8 @@ window_copy_free(struct window *w)
{ {
struct window_copy_mode_data *data = w->modedata; struct window_copy_mode_data *data = w->modedata;
w->screen = &w->base;
screen_destroy(&data->screen); screen_destroy(&data->screen);
xfree(data);
w->mode = NULL;
xfree(w->modedata);
} }
void void
@ -136,8 +134,7 @@ window_copy_key(struct window *w, int key)
switch (key) { switch (key) {
case 'Q': case 'Q':
case 'q': case 'q':
window_copy_free(w); window_reset_mode(w);
server_redraw_window(w);
break; break;
case 'h': case 'h':
case KEYC_LEFT: case KEYC_LEFT:
@ -185,8 +182,7 @@ window_copy_key(struct window *w, int key)
case '\027': /* C-w */ case '\027': /* C-w */
case '\r': /* enter */ case '\r': /* enter */
window_copy_copy_selection(w); window_copy_copy_selection(w);
window_copy_free(w); window_reset_mode(w);
server_redraw_window(w);
break; break;
case '\001': /* C-a */ case '\001': /* C-a */
window_copy_cursor_start_of_line(w); window_copy_cursor_start_of_line(w);

View File

@ -1,4 +1,4 @@
/* $Id: window-more.c,v 1.6 2007-12-06 09:46:23 nicm Exp $ */ /* $Id: window-more.c,v 1.7 2007-12-06 10:04:43 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -22,7 +22,7 @@
#include "tmux.h" #include "tmux.h"
void window_more_init(struct window *); struct screen *window_more_init(struct window *);
void window_more_free(struct window *); void window_more_free(struct window *);
void window_more_resize(struct window *, u_int, u_int); void window_more_resize(struct window *, u_int, u_int);
void window_more_key(struct window *, int); void window_more_key(struct window *, int);
@ -83,7 +83,7 @@ window_more_add(struct window *w, const char *fmt, ...)
va_end(ap); va_end(ap);
} }
void struct screen *
window_more_init(struct window *w) window_more_init(struct window *w)
{ {
struct window_more_mode_data *data; struct window_more_mode_data *data;
@ -96,7 +96,8 @@ window_more_init(struct window *w)
s = &data->screen; s = &data->screen;
screen_create(s, screen_size_x(&w->base), screen_size_y(&w->base)); screen_create(s, screen_size_x(&w->base), screen_size_y(&w->base));
s->mode = 0; s->mode = 0;
w->screen = s;
return (s);
} }
void void
@ -105,15 +106,12 @@ window_more_free(struct window *w)
struct window_more_mode_data *data = w->modedata; struct window_more_mode_data *data = w->modedata;
u_int i; u_int i;
w->screen = &w->base;
screen_destroy(&data->screen);
for (i = 0; i < ARRAY_LENGTH(&data->list); i++) for (i = 0; i < ARRAY_LENGTH(&data->list); i++)
xfree(ARRAY_ITEM(&data->list, i)); xfree(ARRAY_ITEM(&data->list, i));
ARRAY_FREE(&data->list); ARRAY_FREE(&data->list);
w->mode = NULL; screen_destroy(&data->screen);
xfree(w->modedata); xfree(data);
} }
void void
@ -135,8 +133,7 @@ window_more_key(struct window *w, int key)
switch (key) { switch (key) {
case 'Q': case 'Q':
case 'q': case 'q':
window_more_free(w); window_reset_mode(w);
server_redraw_window(w);
break; break;
case 'k': case 'k':
case 'K': case 'K':

View File

@ -1,4 +1,4 @@
/* $Id: window-scroll.c,v 1.15 2007-12-06 09:46:23 nicm Exp $ */ /* $Id: window-scroll.c,v 1.16 2007-12-06 10:04:43 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -22,7 +22,7 @@
#include "tmux.h" #include "tmux.h"
void window_scroll_init(struct window *); struct screen *window_scroll_init(struct window *);
void window_scroll_free(struct window *); void window_scroll_free(struct window *);
void window_scroll_resize(struct window *, u_int, u_int); void window_scroll_resize(struct window *, u_int, u_int);
void window_scroll_key(struct window *, int); void window_scroll_key(struct window *, int);
@ -52,7 +52,7 @@ struct window_scroll_mode_data {
u_int oy; u_int oy;
}; };
void struct screen *
window_scroll_init(struct window *w) window_scroll_init(struct window *w)
{ {
struct window_scroll_mode_data *data; struct window_scroll_mode_data *data;
@ -67,12 +67,13 @@ window_scroll_init(struct window *w)
s = &data->screen; s = &data->screen;
screen_create(s, screen_size_x(&w->base), screen_size_y(&w->base)); screen_create(s, screen_size_x(&w->base), screen_size_y(&w->base));
s->mode = 0; s->mode = 0;
w->screen = s;
screen_write_start(&ctx, s, NULL, NULL); screen_write_start(&ctx, s, NULL, NULL);
for (i = 0; i < screen_size_y(s); i++) for (i = 0; i < screen_size_y(s); i++)
window_scroll_write_line(w, &ctx, i); window_scroll_write_line(w, &ctx, i);
screen_write_stop(&ctx); screen_write_stop(&ctx);
return (s);
} }
void void
@ -80,11 +81,8 @@ window_scroll_free(struct window *w)
{ {
struct window_scroll_mode_data *data = w->modedata; struct window_scroll_mode_data *data = w->modedata;
w->screen = &w->base;
screen_destroy(&data->screen); screen_destroy(&data->screen);
xfree(data);
w->mode = NULL;
xfree(w->modedata);
} }
void void
@ -107,8 +105,7 @@ window_scroll_key(struct window *w, int key)
switch (key) { switch (key) {
case 'Q': case 'Q':
case 'q': case 'q':
window_scroll_free(w); window_reset_mode(w);
server_redraw_window(w);
break; break;
case 'h': case 'h':
case KEYC_LEFT: case KEYC_LEFT:

View File

@ -1,4 +1,4 @@
/* $Id: window.c,v 1.33 2007-12-06 09:46:23 nicm Exp $ */ /* $Id: window.c,v 1.34 2007-12-06 10:04:43 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -244,9 +244,8 @@ window_destroy(struct window *w)
input_free(w); input_free(w);
window_reset_mode(w);
screen_destroy(&w->base); screen_destroy(&w->base);
if (w->mode != NULL)
w->mode->free(w);
buffer_destroy(w->in); buffer_destroy(w->in);
buffer_destroy(w->out); buffer_destroy(w->out);
@ -276,6 +275,35 @@ window_resize(struct window *w, u_int sx, u_int sy)
return (0); return (0);
} }
int
window_set_mode(struct window *w, const struct window_mode *mode)
{
struct screen *s;
if (w->mode != NULL || w->mode == mode)
return (1);
w->mode = mode;
if ((s = w->mode->init(w)) != NULL)
w->screen = s;
server_redraw_window(w);
return (0);
}
void
window_reset_mode(struct window *w)
{
if (w->mode == NULL)
return;
w->mode->free(w);
w->mode = NULL;
w->screen = &w->base;
server_redraw_window(w);
}
void void
window_parse(struct window *w) window_parse(struct window *w)
{ {