Revision: 2686 http://tmux.svn.sourceforge.net/tmux/?rev=2686&view=rev Author: tcunha Date: 2012-01-29 12:57:01 +0000 (Sun, 29 Jan 2012) Log Message: ----------- Sync OpenBSD patchset 1015:
Add an option to move the status line to the top of the screen, requested by many. Modified Paths: -------------- trunk/layout.c trunk/options-table.c trunk/screen-redraw.c trunk/server-client.c trunk/status.c trunk/tmux.1 trunk/tmux.h trunk/tty.c Modified: trunk/layout.c =================================================================== --- trunk/layout.c 2012-01-29 12:53:33 UTC (rev 2685) +++ trunk/layout.c 2012-01-29 12:57:01 UTC (rev 2686) @@ -502,14 +502,14 @@ wp->yoff <= 1 + c->last_mouse.y && wp->yoff + wp->sy >= c->last_mouse.y) { layout_resize_pane(wp, LAYOUT_LEFTRIGHT, - mouse->x - c->last_mouse.x); + mouse->x - c->last_mouse.x); pane_border = 1; } if (wp->yoff + wp->sy == c->last_mouse.y && wp->xoff <= 1 + c->last_mouse.x && wp->xoff + wp->sx >= c->last_mouse.x) { layout_resize_pane(wp, LAYOUT_TOPBOTTOM, - mouse->y - c->last_mouse.y); + mouse->y - c->last_mouse.y); pane_border = 1; } } Modified: trunk/options-table.c =================================================================== --- trunk/options-table.c 2012-01-29 12:53:33 UTC (rev 2685) +++ trunk/options-table.c 2012-01-29 12:57:01 UTC (rev 2686) @@ -47,6 +47,9 @@ const char *options_table_status_justify_list[] = { "left", "centre", "right", NULL }; +const char *options_table_status_position_list[] = { + "top", "bottom", NULL +}; const char *options_table_bell_action_list[] = { "none", "any", "current", NULL }; @@ -358,6 +361,12 @@ .default_num = 10 }, + { .name = "status-position", + .type = OPTIONS_TABLE_CHOICE, + .choices = options_table_status_position_list, + .default_num = 1 + }, + { .name = "status-right", .type = OPTIONS_TABLE_STRING, .default_str = "\"#22T\" %H:%M %d-%b-%y" Modified: trunk/screen-redraw.c =================================================================== --- trunk/screen-redraw.c 2012-01-29 12:53:33 UTC (rev 2685) +++ trunk/screen-redraw.c 2012-01-29 12:57:01 UTC (rev 2686) @@ -170,25 +170,33 @@ screen_redraw_screen(struct client *c, int status_only, int borders_only) { struct window *w = c->session->curw->window; + struct options *oo = &c->session->options; struct tty *tty = &c->tty; struct window_pane *wp; struct grid_cell active_gc, other_gc; - u_int i, j, type; - int status, fg, bg; + u_int i, j, type, top; + int status, spos, fg, bg; /* Suspended clients should not be updated. */ if (c->flags & CLIENT_SUSPENDED) return; /* Get status line, er, status. */ + spos = options_get_number(oo, "status-position"); if (c->message_string != NULL || c->prompt_string != NULL) status = 1; else - status = options_get_number(&c->session->options, "status"); + status = options_get_number(oo, "status"); + top = 0; + if (status && spos == 0) + top = 1; /* If only drawing status and it is present, don't need the rest. */ if (status_only && status) { - tty_draw_line(tty, &c->status, 0, 0, tty->sy - 1); + if (top) + tty_draw_line(tty, &c->status, 0, 0, 0); + else + tty_draw_line(tty, &c->status, 0, 0, tty->sy - 1); tty_reset(tty); return; } @@ -198,19 +206,23 @@ memcpy(&active_gc, &grid_default_cell, sizeof active_gc); active_gc.data = other_gc.data = 'x'; /* not space */ active_gc.attr = other_gc.attr = GRID_ATTR_CHARSET; - fg = options_get_number(&c->session->options, "pane-border-fg"); + fg = options_get_number(oo, "pane-border-fg"); colour_set_fg(&other_gc, fg); - bg = options_get_number(&c->session->options, "pane-border-bg"); + bg = options_get_number(oo, "pane-border-bg"); colour_set_bg(&other_gc, bg); - fg = options_get_number(&c->session->options, "pane-active-border-fg"); + fg = options_get_number(oo, "pane-active-border-fg"); colour_set_fg(&active_gc, fg); - bg = options_get_number(&c->session->options, "pane-active-border-bg"); + bg = options_get_number(oo, "pane-active-border-bg"); colour_set_bg(&active_gc, bg); /* Draw background and borders. */ for (j = 0; j < tty->sy - status; j++) { - if (status_only && j != tty->sy - 1) - continue; + if (status_only) { + if (spos == 1 && j != tty->sy - 1) + continue; + else if (spos == 0 && j != 0) + break; + } for (i = 0; i < tty->sx; i++) { type = screen_redraw_check_cell(c, i, j); if (type == CELL_INSIDE) @@ -219,7 +231,7 @@ tty_attributes(tty, &active_gc); else tty_attributes(tty, &other_gc); - tty_cursor(tty, i, j); + tty_cursor(tty, i, top + j); tty_putc(tty, CELL_BORDERS[type]); } } @@ -233,17 +245,26 @@ if (!window_pane_visible(wp)) continue; for (i = 0; i < wp->sy; i++) { - if (status_only && wp->yoff + i != tty->sy - 1) - continue; - tty_draw_line(tty, wp->screen, i, wp->xoff, wp->yoff); + if (status_only) { + if (spos == 1 && wp->yoff + i != tty->sy - 1) + continue; + else if (spos == 0 && wp->yoff + i != 0) + break; + } + tty_draw_line( + tty, wp->screen, i, wp->xoff, top + wp->yoff); } if (c->flags & CLIENT_IDENTIFY) screen_redraw_draw_number(c, wp); } /* Draw the status line. */ - if (status) - tty_draw_line(tty, &c->status, 0, 0, tty->sy - 1); + if (status) { + if (top) + tty_draw_line(tty, &c->status, 0, 0, 0); + else + tty_draw_line(tty, &c->status, 0, 0, tty->sy - 1); + } tty_reset(tty); } @@ -251,10 +272,14 @@ void screen_redraw_pane(struct client *c, struct window_pane *wp) { - u_int i; + u_int i, yoff; + yoff = wp->yoff; + if (status_at_line(c) == 0) + yoff++; + for (i = 0; i < wp->sy; i++) - tty_draw_line(&c->tty, wp->screen, i, wp->xoff, wp->yoff); + tty_draw_line(&c->tty, wp->screen, i, wp->xoff, yoff); tty_reset(&c->tty); } Modified: trunk/server-client.c =================================================================== --- trunk/server-client.c 2012-01-29 12:53:33 UTC (rev 2685) +++ trunk/server-client.c 2012-01-29 12:57:01 UTC (rev 2686) @@ -26,6 +26,8 @@ #include "tmux.h" +void server_client_check_mouse(struct client *c, + struct window_pane *wp, struct mouse_event *mouse); void server_client_handle_key(int, struct mouse_event *, void *); void server_client_repeat_timer(int, short, void *); void server_client_check_exit(struct client *); @@ -261,6 +263,65 @@ } } +/* Check for mouse keys. */ +void +server_client_check_mouse( + struct client *c, struct window_pane *wp, struct mouse_event *mouse) +{ + struct session *s = c->session; + struct options *oo = &s->options; + int statusat; + + statusat = status_at_line(c); + + /* Is this a window selection click on the status line? */ + if (statusat != -1 && mouse->y == (u_int)statusat && + options_get_number(oo, "mouse-select-window")) { + if (mouse->b == MOUSE_UP && c->last_mouse.b != MOUSE_UP) { + status_set_window_at(c, mouse->x); + return; + } + if (mouse->b & MOUSE_45) { + if ((mouse->b & MOUSE_BUTTON) == MOUSE_1) { + session_previous(c->session, 0); + server_redraw_session(s); + } + if ((mouse->b & MOUSE_BUTTON) == MOUSE_2) { + session_next(c->session, 0); + server_redraw_session(s); + } + return; + } + } + + /* + * Not on status line - adjust mouse position if status line is at the + * top and limit if at the bottom. From here on a struct mouse + * represents the offset onto the window itself. + */ + if (statusat == 0 &&mouse->y > 0) + mouse->y--; + else if (statusat > 0 && mouse->y >= (u_int)statusat) + mouse->y = statusat - 1; + + /* Is this a pane selection? Allow down only in copy mode. */ + if (options_get_number(oo, "mouse-select-pane") && + ((!(mouse->b & MOUSE_DRAG) && mouse->b != MOUSE_UP) || + wp->mode != &window_copy_mode)) { + window_set_active_at(wp->window, mouse->x, mouse->y); + server_redraw_window_borders(wp->window); + wp = wp->window->active; /* may have changed */ + } + + /* Check if trying to resize pane. */ + if (options_get_number(oo, "mouse-resize-pane")) + layout_resize_pane_mouse(c, mouse); + + /* Update last and pass through to client. */ + memcpy(&c->last_mouse, mouse, sizeof c->last_mouse); + window_pane_mouse(wp, c->session, mouse); +} + /* Handle data key input from client. */ void server_client_handle_key(int key, struct mouse_event *mouse, void *data) @@ -316,43 +377,7 @@ if (key == KEYC_MOUSE) { if (c->flags & CLIENT_READONLY) return; - if (options_get_number(oo, "mouse-select-pane") && - (!(options_get_number(oo, "status") && - mouse->y + 1 == c->tty.sy)) && - ((!(mouse->b & MOUSE_DRAG) && mouse->b != MOUSE_UP) || - wp->mode != &window_copy_mode)) { - /* - * Allow pane switching in copy mode only by mouse down - * (click). - */ - window_set_active_at(w, mouse->x, mouse->y); - server_redraw_window_borders(w); - wp = w->active; - } - if (mouse->y + 1 == c->tty.sy && - options_get_number(oo, "mouse-select-window") && - options_get_number(oo, "status")) { - if (mouse->b == MOUSE_UP && - c->last_mouse.b != MOUSE_UP) { - status_set_window_at(c, mouse->x); - return; - } - if (mouse->b & MOUSE_45) { - if ((mouse->b & MOUSE_BUTTON) == MOUSE_1) { - session_previous(c->session, 0); - server_redraw_session(s); - } - if ((mouse->b & MOUSE_BUTTON) == MOUSE_2) { - session_next(c->session, 0); - server_redraw_session(s); - } - return; - } - } - if (options_get_number(oo, "mouse-resize-pane")) - layout_resize_pane_mouse(c, mouse); - memcpy(&c->last_mouse, mouse, sizeof c->last_mouse); - window_pane_mouse(wp, c->session, mouse); + server_client_check_mouse(c, wp, mouse); return; } @@ -471,7 +496,7 @@ struct screen *s = wp->screen; struct options *oo = &c->session->options; struct options *wo = &w->options; - int status, mode; + int status, mode, o; if (c->flags & CLIENT_SUSPENDED) return; @@ -481,8 +506,10 @@ status = options_get_number(oo, "status"); if (!window_pane_visible(wp) || wp->yoff + s->cy >= c->tty.sy - status) tty_cursor(&c->tty, 0, 0); - else - tty_cursor(&c->tty, wp->xoff + s->cx, wp->yoff + s->cy); + else { + o = status && options_get_number (oo, "status-position") == 0; + tty_cursor(&c->tty, wp->xoff + s->cx, o + wp->yoff + s->cy); + } /* * Resizing panes with the mouse requires at least button mode to give Modified: trunk/status.c =================================================================== --- trunk/status.c 2012-01-29 12:53:33 UTC (rev 2685) +++ trunk/status.c 2012-01-29 12:57:01 UTC (rev 2686) @@ -60,6 +60,20 @@ return (strcmp(so1->cmd, so2->cmd)); } +/* Get screen line of status line. -1 means off. */ +int +status_at_line(struct client *c) +{ + struct session *s = c->session; + + if (!options_get_number(&s->options, "status")) + return (-1); + + if (options_get_number(&s->options, "status-position") == 0) + return (0); + return (c->tty.sy - 1); +} + /* Retrieve options for left string. */ char * status_redraw_get_left(struct client *c, Modified: trunk/tmux.1 =================================================================== --- trunk/tmux.1 2012-01-29 12:53:33 UTC (rev 2685) +++ trunk/tmux.1 2012-01-29 12:57:01 UTC (rev 2686) @@ -2203,6 +2203,10 @@ .Ar length of the left component of the status bar. The default is 10. +.It Xo Ic status-position +.Op Ic top | bottom +.Xc +Set the position of the status line. .It Ic status-right Ar string Display .Ar string Modified: trunk/tmux.h =================================================================== --- trunk/tmux.h 2012-01-29 12:53:33 UTC (rev 2685) +++ trunk/tmux.h 2012-01-29 12:57:01 UTC (rev 2686) @@ -1074,6 +1074,9 @@ u_int orupper; u_int orlower; + u_int xoff; + u_int yoff; + /* Saved last cell on line. */ struct grid_cell last_cell; struct grid_utf8 last_utf8; @@ -1459,8 +1462,8 @@ int tty_open(struct tty *, const char *, char **); void tty_close(struct tty *); void tty_free(struct tty *); -void tty_write(void (*)( - struct tty *, const struct tty_ctx *), const struct tty_ctx *); +void tty_write( + void (*)(struct tty *, const struct tty_ctx *), struct tty_ctx *); void tty_cmd_alignmenttest(struct tty *, const struct tty_ctx *); void tty_cmd_cell(struct tty *, const struct tty_ctx *); void tty_cmd_clearendofline(struct tty *, const struct tty_ctx *); @@ -1718,6 +1721,7 @@ /* status.c */ int status_out_cmp(struct status_out *, struct status_out *); RB_PROTOTYPE(status_out_tree, status_out, entry, status_out_cmp); +int status_at_line(struct client *); void status_free_jobs(struct status_out_tree *); void status_update_jobs(struct client *); void status_set_window_at(struct client *, u_int); Modified: trunk/tty.c =================================================================== --- trunk/tty.c 2012-01-29 12:53:33 UTC (rev 2685) +++ trunk/tty.c 2012-01-29 12:57:01 UTC (rev 2686) @@ -513,10 +513,10 @@ if (ctx->ocy < ctx->orupper || ctx->ocy > ctx->orlower) { for (i = ctx->ocy; i < screen_size_y(s); i++) - tty_draw_line(tty, s, i, wp->xoff, wp->yoff); + tty_draw_line(tty, s, i, ctx->xoff, ctx->yoff); } else { for (i = ctx->orupper; i <= ctx->orlower; i++) - tty_draw_line(tty, s, i, wp->xoff, wp->yoff); + tty_draw_line(tty, s, i, ctx->xoff, ctx->yoff); } } @@ -585,11 +585,13 @@ } void -tty_write(void (*cmdfn)( - struct tty *, const struct tty_ctx *), const struct tty_ctx *ctx) +tty_write( + void (*cmdfn)(struct tty *, const struct tty_ctx *), struct tty_ctx *ctx) { struct window_pane *wp = ctx->wp; struct client *c; + struct session *s; + struct options *oo; u_int i; /* wp can be NULL if updating the screen but not the terminal. */ @@ -607,12 +609,20 @@ continue; if (c->flags & CLIENT_SUSPENDED) continue; + s = c->session; - if (c->session->curw->window == wp->window) { + if (s->curw->window == wp->window) { if (c->tty.term == NULL) continue; if (c->tty.flags & (TTY_FREEZE|TTY_BACKOFF)) continue; + oo = &s->options; + + ctx->xoff = wp->xoff; + ctx->yoff = wp->yoff; + if (status_at_line(c) == 0) + ctx->yoff++; + cmdfn(&c->tty, ctx); } } @@ -625,8 +635,8 @@ struct screen *s = wp->screen; u_int i; - if (wp->xoff != 0 || screen_size_x(s) < tty->sx) { - tty_draw_line(tty, wp->screen, ctx->ocy, wp->xoff, wp->yoff); + if (ctx->xoff != 0 || screen_size_x(s) < tty->sx) { + tty_draw_line(tty, wp->screen, ctx->ocy, ctx->xoff, ctx->yoff); return; } @@ -644,7 +654,7 @@ tty_putc(tty, ' '); tty_putcode(tty, TTYC_RMIR); } else - tty_draw_line(tty, wp->screen, ctx->ocy, wp->xoff, wp->yoff); + tty_draw_line(tty, wp->screen, ctx->ocy, ctx->xoff, ctx->yoff); } void @@ -653,10 +663,10 @@ struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; - if (wp->xoff != 0 || screen_size_x(s) < tty->sx || + if (ctx->xoff != 0 || screen_size_x(s) < tty->sx || (!tty_term_has(tty->term, TTYC_DCH) && !tty_term_has(tty->term, TTYC_DCH1))) { - tty_draw_line(tty, wp->screen, ctx->ocy, wp->xoff, wp->yoff); + tty_draw_line(tty, wp->screen, ctx->ocy, ctx->xoff, ctx->yoff); return; } @@ -675,7 +685,7 @@ struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; - if (wp->xoff != 0 || screen_size_x(s) < tty->sx || + if (ctx->xoff != 0 || screen_size_x(s) < tty->sx || !tty_term_has(tty->term, TTYC_CSR) || !tty_term_has(tty->term, TTYC_IL1)) { tty_redraw_region(tty, ctx); @@ -696,7 +706,7 @@ struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; - if (wp->xoff != 0 || screen_size_x(s) < tty->sx || + if (ctx->xoff != 0 || screen_size_x(s) < tty->sx || !tty_term_has(tty->term, TTYC_CSR) || !tty_term_has(tty->term, TTYC_DL1)) { tty_redraw_region(tty, ctx); @@ -722,7 +732,7 @@ tty_cursor_pane(tty, ctx, 0, ctx->ocy); - if (wp->xoff == 0 && screen_size_x(s) >= tty->sx && + if (ctx->xoff == 0 && screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) { tty_putcode(tty, TTYC_EL); } else { @@ -742,7 +752,7 @@ tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); - if (wp->xoff == 0 && screen_size_x(s) >= tty->sx && + if (ctx->xoff == 0 && screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) tty_putcode(tty, TTYC_EL); else { @@ -754,12 +764,11 @@ void tty_cmd_clearstartofline(struct tty *tty, const struct tty_ctx *ctx) { - struct window_pane *wp = ctx->wp; - u_int i; + u_int i; tty_reset(tty); - if (wp->xoff == 0 && tty_term_has(tty->term, TTYC_EL1)) { + if (ctx->xoff == 0 && tty_term_has(tty->term, TTYC_EL1)) { tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); tty_putcode(tty, TTYC_EL1); } else { @@ -778,7 +787,7 @@ if (ctx->ocy != ctx->orupper) return; - if (wp->xoff != 0 || screen_size_x(s) < tty->sx || + if (ctx->xoff != 0 || screen_size_x(s) < tty->sx || !tty_term_has(tty->term, TTYC_CSR) || !tty_term_has(tty->term, TTYC_RI)) { tty_redraw_region(tty, ctx); @@ -802,7 +811,7 @@ if (ctx->ocy != ctx->orlower) return; - if (wp->xoff != 0 || screen_size_x(s) < tty->sx || + if (ctx->xoff != 0 || screen_size_x(s) < tty->sx || !tty_term_has(tty->term, TTYC_CSR)) { tty_redraw_region(tty, ctx); return; @@ -836,7 +845,7 @@ tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); - if (wp->xoff == 0 && screen_size_x(s) >= tty->sx && + if (ctx->xoff == 0 && screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) { tty_putcode(tty, TTYC_EL); if (ctx->ocy != screen_size_y(s) - 1) { @@ -872,7 +881,7 @@ tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1); tty_cursor_pane(tty, ctx, 0, 0); - if (wp->xoff == 0 && screen_size_x(s) >= tty->sx && + if (ctx->xoff == 0 && screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) { for (i = 0; i < ctx->ocy; i++) { tty_putcode(tty, TTYC_EL); @@ -902,7 +911,7 @@ tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1); tty_cursor_pane(tty, ctx, 0, 0); - if (wp->xoff == 0 && screen_size_x(s) >= tty->sx && + if (ctx->xoff == 0 && screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) { for (i = 0; i < screen_size_y(s); i++) { tty_putcode(tty, TTYC_EL); @@ -957,7 +966,7 @@ /* Is the cursor in the very last position? */ if (ctx->ocx > wp->sx - width) { - if (wp->xoff != 0 || wp->sx != tty->sx) { + if (ctx->xoff != 0 || wp->sx != tty->sx) { /* * The pane doesn't fill the entire line, the linefeed * will already have happened, so just move the cursor. @@ -991,7 +1000,7 @@ * Cannot rely on not being a partial character, so just redraw the * whole line. */ - tty_draw_line(tty, wp->screen, ctx->ocy, wp->xoff, wp->yoff); + tty_draw_line(tty, wp->screen, ctx->ocy, ctx->xoff, ctx->yoff); } void @@ -1078,9 +1087,7 @@ tty_region_pane( struct tty *tty, const struct tty_ctx *ctx, u_int rupper, u_int rlower) { - struct window_pane *wp = ctx->wp; - - tty_region(tty, wp->yoff + rupper, wp->yoff + rlower); + tty_region(tty, ctx->yoff + rupper, ctx->yoff + rlower); } /* Set region at absolute position. */ @@ -1112,9 +1119,7 @@ void tty_cursor_pane(struct tty *tty, const struct tty_ctx *ctx, u_int cx, u_int cy) { - struct window_pane *wp = ctx->wp; - - tty_cursor(tty, wp->xoff + cx, wp->yoff + cy); + tty_cursor(tty, ctx->xoff + cx, ctx->yoff + cy); } /* Move cursor to absolute position. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 _______________________________________________ tmux-cvs mailing list tmux-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-cvs