Treat the meta bit in the xterm extended modifier key set as the same as
[tmux-openbsd.git] / grid-view.c
blobba142a1c242e5405572f5a4c692334748af0188f
1 /* $OpenBSD$ */
3 /*
4 * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
21 #include <string.h>
23 #include "tmux.h"
26 * Grid view functions. These work using coordinates relative to the visible
27 * screen area.
30 #define grid_view_x(gd, x) (x)
31 #define grid_view_y(gd, y) ((gd)->hsize + (y))
33 /* Get cell for reading. */
34 const struct grid_cell *
35 grid_view_peek_cell(struct grid *gd, u_int px, u_int py)
37 return (grid_peek_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py)));
40 /* Get cell for writing. */
41 struct grid_cell *
42 grid_view_get_cell(struct grid *gd, u_int px, u_int py)
44 return (grid_get_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py)));
47 /* Set cell. */
48 void
49 grid_view_set_cell(
50 struct grid *gd, u_int px, u_int py, const struct grid_cell *gc)
52 grid_set_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py), gc);
55 /* Get UTF-8 for reading. */
56 const struct grid_utf8 *
57 grid_view_peek_utf8(struct grid *gd, u_int px, u_int py)
59 return (grid_peek_utf8(gd, grid_view_x(gd, px), grid_view_y(gd, py)));
62 /* Get UTF-8 for writing. */
63 struct grid_utf8 *
64 grid_view_get_utf8(struct grid *gd, u_int px, u_int py)
66 return (grid_get_utf8(gd, grid_view_x(gd, px), grid_view_y(gd, py)));
69 /* Set UTF-8. */
70 void
71 grid_view_set_utf8(
72 struct grid *gd, u_int px, u_int py, const struct grid_utf8 *gu)
74 grid_set_utf8(gd, grid_view_x(gd, px), grid_view_y(gd, py), gu);
77 /* Clear area. */
78 void
79 grid_view_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny)
81 GRID_DEBUG(gd, "px=%u, py=%u, nx=%u, ny=%u", px, py, nx, ny);
83 px = grid_view_x(gd, px);
84 py = grid_view_y(gd, py);
86 grid_clear(gd, px, py, nx, ny);
89 /* Scroll region up. */
90 void
91 grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower)
93 GRID_DEBUG(gd, "rupper=%u, rlower=%u", rupper, rlower);
95 if (gd->flags & GRID_HISTORY) {
96 grid_collect_history(gd);
97 if (rupper == 0 && rlower == gd->sy - 1)
98 grid_scroll_history(gd);
99 else {
100 rupper = grid_view_y(gd, rupper);
101 rlower = grid_view_y(gd, rlower);
102 grid_scroll_history_region(gd, rupper, rlower);
104 } else {
105 rupper = grid_view_y(gd, rupper);
106 rlower = grid_view_y(gd, rlower);
107 grid_move_lines(gd, rupper, rupper + 1, rlower - rupper);
111 /* Scroll region down. */
112 void
113 grid_view_scroll_region_down(struct grid *gd, u_int rupper, u_int rlower)
115 GRID_DEBUG(gd, "rupper=%u, rlower=%u", rupper, rlower);
117 rupper = grid_view_y(gd, rupper);
118 rlower = grid_view_y(gd, rlower);
120 grid_move_lines(gd, rupper + 1, rupper, rlower - rupper);
123 /* Insert lines. */
124 void
125 grid_view_insert_lines(struct grid *gd, u_int py, u_int ny)
127 u_int sy;
129 GRID_DEBUG(gd, "py=%u, ny=%u", py, ny);
131 py = grid_view_y(gd, py);
133 sy = grid_view_y(gd, gd->sy);
135 grid_move_lines(gd, py + ny, py, sy - py - ny);
138 /* Insert lines in region. */
139 void
140 grid_view_insert_lines_region(struct grid *gd, u_int rlower, u_int py, u_int ny)
142 u_int ny2;
144 GRID_DEBUG(gd, "rlower=%u, py=%u, ny=%u", rlower, py, ny);
146 rlower = grid_view_y(gd, rlower);
148 py = grid_view_y(gd, py);
150 ny2 = rlower + 1 - py - ny;
151 grid_move_lines(gd, rlower + 1 - ny2, py, ny2);
152 grid_clear(gd, 0, py + ny2, gd->sx, ny - ny2);
155 /* Delete lines. */
156 void
157 grid_view_delete_lines(struct grid *gd, u_int py, u_int ny)
159 u_int sy;
161 GRID_DEBUG(gd, "py=%u, ny=%u", py, ny);
163 py = grid_view_y(gd, py);
165 sy = grid_view_y(gd, gd->sy);
167 grid_move_lines(gd, py, py + ny, sy - py - ny);
168 grid_clear(gd, 0, sy - ny, gd->sx, py + ny - (sy - ny));
171 /* Delete lines inside scroll region. */
172 void
173 grid_view_delete_lines_region(struct grid *gd, u_int rlower, u_int py, u_int ny)
175 u_int ny2;
177 GRID_DEBUG(gd, "rlower=%u, py=%u, ny=%u", rlower, py, ny);
179 rlower = grid_view_y(gd, rlower);
181 py = grid_view_y(gd, py);
183 ny2 = rlower + 1 - py - ny;
184 grid_move_lines(gd, py, py + ny, ny2);
185 grid_clear(gd, 0, py + ny2, gd->sx, ny - ny2);
188 /* Insert characters. */
189 void
190 grid_view_insert_cells(struct grid *gd, u_int px, u_int py, u_int nx)
192 u_int sx;
194 GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
196 px = grid_view_x(gd, px);
197 py = grid_view_y(gd, py);
199 sx = grid_view_x(gd, gd->sx);
201 if (px == sx - 1)
202 grid_clear(gd, px, py, 1, 1);
203 else
204 grid_move_cells(gd, px + nx, px, py, sx - px - nx);
207 /* Delete characters. */
208 void
209 grid_view_delete_cells(struct grid *gd, u_int px, u_int py, u_int nx)
211 u_int sx;
213 GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
215 px = grid_view_x(gd, px);
216 py = grid_view_y(gd, py);
218 sx = grid_view_x(gd, gd->sx);
220 grid_move_cells(gd, px, px + nx, py, sx - px - nx);
221 grid_clear(gd, sx - nx, py, px + nx - (sx - nx), 1);
224 /* Convert cells into a string. */
225 char *
226 grid_view_string_cells(struct grid *gd, u_int px, u_int py, u_int nx)
228 GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
230 px = grid_view_x(gd, px);
231 py = grid_view_y(gd, py);
233 return (grid_string_cells(gd, px, py, nx));