Skip to content

Instantly share code, notes, and snippets.

@uobikiemukot
Last active March 12, 2018 02:11
Show Gist options
  • Save uobikiemukot/1b80c33b83648803dedf6f5a13993009 to your computer and use it in GitHub Desktop.
Save uobikiemukot/1b80c33b83648803dedf6f5a13993009 to your computer and use it in GitHub Desktop.
yaft rotated screeen support
diff --git a/ChangeLog b/ChangeLog
index 49a59d5..1d75b60 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -83,3 +83,11 @@
ex)
$ ./mkfont alias-file your/favorite/bdf > glyph.h
$ make yaft
+
+2014-03-07 haru
+ * version 0.2.1
+ * conf.hにいくつかの設定を追加
+ * ROTATE = NORMAL or CLOCKWISE or COUNTER_CLOCKWISE or UPSIDE_DOWN
+ * LAZY_DRAW(データ量が多いときに描画を抑制する)を追加
+ * BACKGROUND_DRAW(VT切り替え後も描画を続ける)を追加
+ * struct terminalのoffsetを削除
diff --git a/color.h b/color.h
index 1aa9465..307fc51 100644
--- a/color.h
+++ b/color.h
@@ -5,9 +5,9 @@
*/
const uint32_t color_list[COLORS] = {
/* system color: 16
- 0x000000, 0xAA0000, 0x00AA00, 0xAA5500, 0x0000AA, 0xAA00AA, 0x00AAAA, 0xAAAAAA,
- 0x555555, 0xFF5555, 0x55FF55, 0xFFFF55, 0x5555FF, 0xFF55FF, 0x55FFFF, 0xFFFFFF,
*/
+ 0x000000, 0xAA0000, 0x00AA00, 0xAA5500, 0x0000AA, 0xAA00AA, 0x00AAAA, 0xAAAAAA/* 0xAAAAAA */,
+ 0x555555, 0xFF5555, 0x55FF55, 0xFFFF55, 0x5555FF, 0xFF55FF, 0x55FFFF, 0xDFDFDF/* 0xFFFFFF */,
/* dark system color
0x000000, 0x660000, 0x006600, 0x661100, 0x000066, 0x660066, 0x006666, 0x666666,
0x444444, 0x774444, 0x447744, 0x777744, 0x444477, 0x774477, 0x447777, 0x777777,
@@ -17,9 +17,9 @@ const uint32_t color_list[COLORS] = {
0x002B36, 0xCB4B16, 0x586E75, 0x657B83, 0x839496, 0x6C71C4, 0x93A1A1, 0xFDF6E3,
*/
/* solarized fix
- */
0x000000, 0xDC322F, 0x859900, 0xB58900, 0x268BD2, 0xD33682, 0x2AA198, 0x93A1A1,
0x555555, 0xEC423F, 0x95A910, 0xA59910, 0x6C71C4, 0xE34692, 0x3AB1A8, 0xCEC8B5,
+ */
/* color cube: 216 */
0x000000, 0x00005F, 0x000087, 0x0000AF, 0x0000D7, 0x0000FF, 0x005F00, 0x005F5F,
0x005F87, 0x005FAF, 0x005FD7, 0x005FFF, 0x008700, 0x00875F, 0x008787, 0x0087AF,
diff --git a/common.h b/common.h
index 6f67d75..c9522cb 100644
--- a/common.h
+++ b/common.h
@@ -108,19 +108,6 @@ struct margin { int top, bottom; };
struct color_t { uint32_t r, g, b; };
struct color_pair { uint8_t fg, bg; };
-struct framebuffer {
- char *fp; /* pointer of framebuffer(read only) */
- char *wall; /* buffer for wallpaper */
- char *buf; /* copy of framebuffer */
- int fd; /* file descriptor of framebuffer */
- struct pair res; /* resolution (x, y) */
- long screen_size; /* screen data size (byte) */
- int line_length; /* line length (byte) */
- int bpp; /* BYTES per pixel */
- uint32_t color_palette[COLORS];
- struct fb_cmap *cmap, *cmap_org;
-};
-
struct cell {
const struct static_glyph_t *gp; /* pointer to glyph */
struct color_pair color;/* color (fg, bg) */
@@ -153,7 +140,7 @@ struct state_t { /* for save, restore state */
struct terminal {
int fd; /* master fd */
- struct pair offset; /* window offset (x, y) */
+ //struct pair offset; /* window offset (x, y) */
int width, height; /* terminal size (pixel) */
int cols, lines; /* terminal size (cell) */
struct cell *cells; /* pointer to each cell: cells[cols + lines * num_of_cols] */
@@ -170,5 +157,18 @@ struct terminal {
struct ucs_t ucs; /* store UTF-8 sequence */
};
+struct framebuffer {
+ char *fp; /* pointer of framebuffer(read only) */
+ char *wall; /* buffer for wallpaper */
+ char *buf; /* copy of framebuffer */
+ int fd; /* file descriptor of framebuffer */
+ struct pair res; /* resolution (x, y) */
+ long screen_size; /* screen data size (byte) */
+ int line_length; /* line length (byte) */
+ int bpp; /* BYTES per pixel */
+ uint32_t color_palette[COLORS];
+ struct fb_cmap *cmap, *cmap_org;
+};
+
#include "conf.h" /* user configuration */
#include "color.h" /* 256color definition */
diff --git a/conf.h b/conf.h
index 0acc0b9..55f604d 100644
--- a/conf.h
+++ b/conf.h
@@ -10,16 +10,9 @@ const char *term_name = "yaft-256color";
/* color: index number of color_palette[] in color.h */
enum {
- /*
- */
DEFAULT_FG = 7,
DEFAULT_BG = 0,
CURSOR_COLOR = 2,
- /* solarized
- DEFAULT_FG = 12,
- DEFAULT_BG = 8,
- CURSOR_COLOR = 2,
- */
};
/* misc */
@@ -29,4 +22,8 @@ enum {
SUBSTITUTE_HALF = 0x20, /* used for missing glyph: SPACE (0x20) */
SUBSTITUTE_WIDE = 0x3000, /* used for missing glyph: IDEOGRAPHIC SPACE(0x3000) */
REPLACEMENT_CHAR = 0xFFFD, /* used for malformed UTF-8 sequence: REPLACEMENT CHARACTER */
+ LAZY_DRAW = false,
+ BACKGROUND_DRAW = false,
+ NORMAL = 0, CLOCKWISE = 90, UPSIDE_DOWN = 180, COUNTER_CLOCKWISE = 270,
+ ROTATE = CLOCKWISE, /* 0 or 90 or 180 or 270 (see above) */
};
diff --git a/framebuffer.h b/framebuffer.h
index 319dda4..cab65c9 100644
--- a/framebuffer.h
+++ b/framebuffer.h
@@ -175,73 +175,145 @@ void fb_die(struct framebuffer *fb)
eclose(fb->fd);
}
-void set_bitmap(struct framebuffer *fb, struct terminal *term, int y, int x, int offset, char *src)
+int get_rotated_pos(struct framebuffer *fb, struct terminal *term, int x, int y)
{
- int i, shift, glyph_width;
+ int p, q;
+ long pos;
+
+ if (ROTATE == CLOCKWISE) {
+ p = y;
+ q = (term->width - 1) - x;
+ }
+ else if (ROTATE == UPSIDE_DOWN) {
+ p = (term->width - 1) - x;
+ q = (term->height - 1) - y;
+ }
+ else if (ROTATE == COUNTER_CLOCKWISE) {
+ p = (term->height - 1) - y;
+ q = x;
+ }
+ else { /* rotate: NORMAL */
+ p = x;
+ q = y;
+ }
+
+ pos = p * fb->bpp + q * fb->line_length;
+ if (pos < 0 || pos >= fb->screen_size) {
+ fprintf(stderr, "(%d, %d) -> (%d, %d) term:(%d, %d) res:(%d, %d) pos:%ld\n",
+ x, y, p, q, term->width, term->height, fb->res.x, fb->res.y, pos);
+ exit(EXIT_FAILURE);
+ }
+
+ return pos;
+}
+
+void draw_line(struct framebuffer *fb, struct terminal *term, int line)
+{
+ int copy_size, pos, bit_shift, margin_right;
+
+ int col, glyph_width_offset, glyph_height_offset;
uint32_t pixel;
struct color_pair color;
struct cell *cp;
const struct static_glyph_t *gp;
- cp = &term->cells[x + y * term->cols];
- if (cp->wide == NEXT_TO_WIDE)
- return;
-
- gp = cp->gp;
- glyph_width = gp->width * cell_width;
- shift = ((glyph_width + BITS_PER_BYTE - 1) / BITS_PER_BYTE) * BITS_PER_BYTE;
- color = cp->color;
-
- if ((term->mode & MODE_CURSOR && y == term->cursor.y) /* cursor */
- && (x == term->cursor.x || (cp->wide == WIDE && (x + 1) == term->cursor.x))) {
- color.fg = DEFAULT_BG;
- color.bg = CURSOR_COLOR;
+ /*
+ 1280(width) x 1024(height) = 1310720 pixels
+
+ 0 1279
+ +-- ... --+
+ | |
+ 1280 +-- ... --+2559
+ | |
+ . .
+ . .
+ +-- ... --+
+ 1309440 1310719
+
+ cell size: 8x16
+ term cell: line 0 - 63 col 0 - 159
+ */
+
+ pos = get_rotated_pos(fb, term, term->width - 1, line * cell_height);
+ copy_size = (ROTATE == CLOCKWISE || ROTATE == COUNTER_CLOCKWISE) ?
+ cell_height * fb->bpp: cell_height * fb->line_length;
+
+ for (col = term->cols - 1; col >= 0; col--) {
+ margin_right = (term->cols - 1 - col) * cell_width;
+
+ /* get cell color and glyph */
+ cp = &term->cells[col + line * term->cols];
+ color = cp->color;
+ gp = cp->gp;
+
+ /* check cursor positon */
+ if ((term->mode & MODE_CURSOR && line == term->cursor.y)
+ && (col == term->cursor.x
+ || (cp->wide == WIDE && (col + 1) == term->cursor.x)
+ || (cp->wide == NEXT_TO_WIDE && (col - 1) == term->cursor.x))) {
+ color.fg = DEFAULT_BG;
+ color.bg = CURSOR_COLOR;
+ }
+
+ for (glyph_height_offset = 0; glyph_height_offset < cell_height; glyph_height_offset++) {
+ if ((glyph_height_offset == (cell_height - 1)) && (cp->attribute & attr_mask[UNDERLINE]))
+ color.bg = color.fg;
+
+ for (glyph_width_offset = 0; glyph_width_offset < cell_width; glyph_width_offset++) {
+ pos = get_rotated_pos(fb, term, term->width - 1 - margin_right - glyph_width_offset,
+ // min: 1280 - 1 - (160 - 1 - 0) * 8 - 7 = 0 / max: 1280 - 1 - (160 - 1 - 159) * 8 - 0 = 1279
+ line * cell_height + glyph_height_offset);
+ // min: 0 * 16 + 0 = 0 / max: (64 - 1) * 16 + 15 = 1023
+
+ if (cp->wide == WIDE)
+ bit_shift = glyph_width_offset + cell_width;
+ else
+ bit_shift = glyph_width_offset;
+
+ /* set color palette */
+ if (gp->bitmap[glyph_height_offset] & (0x01 << bit_shift))
+ pixel = fb->color_palette[color.fg];
+ else if (fb->wall && color.bg == DEFAULT_BG) /* wallpaper */
+ memcpy(&pixel, fb->wall + pos, fb->bpp);
+ else
+ pixel = fb->color_palette[color.bg];
+
+ memcpy(fb->buf + pos, &pixel, fb->bpp);
+ }
+ }
+
+ if (ROTATE == CLOCKWISE || ROTATE == COUNTER_CLOCKWISE) {
+ for (glyph_width_offset = 0; glyph_width_offset < cell_width; glyph_width_offset++) {
+ pos = (ROTATE == CLOCKWISE) ?
+ get_rotated_pos(fb, term, term->width - 1 - margin_right - glyph_width_offset, line * cell_height):
+ // min: 1024 - 1 - (128 - 1 - 0) * 8 - 7 = 0 / max: 1024 - 1 - (128 - 1 - 127) * 8 - 0 = 1023
+ // min: 0 * 16 = 0 / max: 79 * 16 = 1264
+ get_rotated_pos(fb, term, term->width - 1 - margin_right - glyph_width_offset, (line + 1) * cell_height - 1);
+ // min: 1 * 16 - 1 = 15 / max: 80 * 16 - 1 = 1279
+ memcpy(fb->fp + pos, fb->buf + pos, copy_size);
+ }
+ }
}
- if ((offset == (cell_height - 1)) /* underline */
- && (cp->attribute & attr_mask[UNDERLINE]))
- color.bg = color.fg;
-
- for (i = 0; i < glyph_width; i++) {
- if (gp->bitmap[offset] & (0x01 << (shift - i - 1)))
- pixel = fb->color_palette[color.fg];
- else if (fb->wall && color.bg == DEFAULT_BG) /* wallpaper */
- memcpy(&pixel, fb->wall + (i + x * cell_width + term->offset.x) * fb->bpp
- + (offset + y * cell_height + term->offset.y) * fb->line_length, fb->bpp);
- else
- pixel = fb->color_palette[color.bg];
- memcpy(src + i * fb->bpp, &pixel, fb->bpp);
+ if (ROTATE == NORMAL || ROTATE == UPSIDE_DOWN) {
+ pos = (ROTATE == NORMAL) ?
+ get_rotated_pos(fb, term, 0, line * cell_height):
+ get_rotated_pos(fb, term, term->width - 1, (line + 1) * cell_height - 1);
+ memcpy(fb->fp + pos, fb->buf + pos, copy_size);
}
-}
-void draw_line(struct framebuffer *fb, struct terminal *term, int y)
-{
- int offset, x, size, pos;
- char *src, *dst;
-
- pos = term->offset.x * fb->bpp + (term->offset.y + y * cell_height) * fb->line_length;
- size = term->width * fb->bpp;
-
- for (offset = 0; offset < cell_height; offset++) {
- for (x = 0; x < term->cols; x++)
- set_bitmap(fb, term, y, x, offset,
- fb->buf + pos + x * cell_width * fb->bpp + offset * fb->line_length);
- src = fb->buf + pos + offset * fb->line_length;
- dst = fb->fp + pos + offset * fb->line_length;
- memcpy(dst, src, size);
- }
- term->line_dirty[y] = (term->mode & MODE_CURSOR && term->cursor.y == y) ? true: false;
+ term->line_dirty[line] = ((term->mode & MODE_CURSOR) && term->cursor.y == line) ? true: false;
}
void refresh(struct framebuffer *fb, struct terminal *term)
{
- int y;
+ int line;
if (term->mode & MODE_CURSOR)
term->line_dirty[term->cursor.y] = true;
- for (y = 0; y < term->lines; y++) {
- if (term->line_dirty[y])
- draw_line(fb, term, y);
+ for (line = 0; line < term->lines; line++) {
+ if (term->line_dirty[line])
+ draw_line(fb, term, line);
}
}
diff --git a/parse.h b/parse.h
index c0095e5..947ce8d 100644
--- a/parse.h
+++ b/parse.h
@@ -219,11 +219,9 @@ void utf8_character(struct terminal *term, uint8_t ch)
|| ((term->ucs.code & 0xFFFF) == 0xFFFE || (term->ucs.code & 0xFFFF) == 0xFFFF)
|| (term->ucs.code > 0x10FFFF))
addch(term, REPLACEMENT_CHAR);
- else {
- if (DEBUG)
- fprintf(stderr, "unicode: U+%4.4X\n", term->ucs.code);
+ else
addch(term, term->ucs.code);
- }
+
reset_ucs(term);
}
}
@@ -242,19 +240,16 @@ void parse(struct terminal *term, uint8_t *buf, int size)
for (i = 0; i < size; i++) {
ch = buf[i];
if (term->esc.state == RESET) {
- if (term->ucs.following_byte > 0 && (ch < 0x80 || ch > 0xBF)) { /* interruput: need to rewrite */
+ if (term->ucs.following_byte > 0 && (ch < 0x80 || ch > 0xBF)) { /* interrupt */
addch(term, REPLACEMENT_CHAR);
reset_ucs(term);
}
if (ch <= 0x1F)
control_character(term, ch);
- else if (ch <= 0x7F) {
- if (DEBUG)
- fprintf(stderr, "ascii: %c\n", ch);
+ else if (ch <= 0x7F)
addch(term, ch);
- }
- else /* ch >= 0x80 */
+ else
utf8_character(term, ch);
}
else if (term->esc.state == STATE_ESC) {
diff --git a/pos_test.c b/pos_test.c
new file mode 100644
index 0000000..531d808
--- /dev/null
+++ b/pos_test.c
@@ -0,0 +1,46 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+enum {
+ NORMAL = 0,
+ CLOCKWISE = 90,
+ UPSIDE_DOWN = 180,
+ COUNTER_CLOCKWISE = 270,
+};
+
+struct disp_t {
+ int x, y;
+ int bpp, line_length;
+};
+
+
+int get_rotated_pos(struct disp_t disp, int x, int y, int rotate)
+{
+ if (rotate == CLOCKWISE)
+ return y * disp.bpp + (disp.x - 1 - x) * disp.y * disp.bpp;
+ else if (rotate == UPSIDE_DOWN)
+ return (disp.x - 1 - x) * disp.bpp + (disp.y - 1 - y) * disp.line_length;
+ else if (rotate == COUNTER_CLOCKWISE)
+ return (disp.y - 1 - y) * disp.bpp + x * disp.y * disp.bpp;
+ else /* rotate: NORMAL */
+ return x * disp.bpp + y * disp.line_length;
+}
+
+int main()
+{
+ int i, j, pos;
+ struct disp_t disp = {.x = 1280, .y = 1024, .bpp = 4, .line_length = 5120};
+
+ for (i = 0; i < disp.x; i++) {
+ for (j = 0; j < disp.y; j++) {
+ pos = get_rotated_pos(disp, i, j, COUNTER_CLOCKWISE);
+ if (!(0 <= pos && pos < 5242880)) {
+ printf("i:%d j:%d pos:%d\n", i, j, pos);
+ exit(EXIT_FAILURE);
+ }
+ else
+ printf("%d\n", pos);
+ }
+ }
+}
diff --git a/rotate.h b/rotate.h
new file mode 100644
index 0000000..4afa289
--- /dev/null
+++ b/rotate.h
@@ -0,0 +1,171 @@
+/* See LICENSE for licence details. */
+int my_ceil(int value, int division)
+{
+ return ((value + division - 1) / division);
+}
+
+void set_bit_normal(struct framebuffer *fb, struct terminal *term, int y, int x, int offset, char *src)
+{
+ int i, shift, glyph_width;
+ uint32_t pixel;
+ struct color_pair color;
+ struct cell *cp;
+ const struct static_glyph_t *gp;
+
+ cp = &term->cells[x + y * term->cols];
+ if (cp->wide == NEXT_TO_WIDE)
+ return;
+
+ gp = cp->gp;
+ glyph_width = gp->width * cell_width;
+ shift = ((glyph_width + BITS_PER_BYTE - 1) / BITS_PER_BYTE) * BITS_PER_BYTE;
+ color = cp->color;
+
+ if ((term->mode & MODE_CURSOR && y == term->cursor.y) /* cursor */
+ && (x == term->cursor.x || (cp->wide == WIDE && (x + 1) == term->cursor.x))) {
+ color.fg = DEFAULT_BG;
+ color.bg = CURSOR_COLOR;
+ }
+
+ if ((offset == (cell_height - 1)) /* underline */
+ && (cp->attribute & attr_mask[UNDERLINE]))
+ color.bg = color.fg;
+
+ for (i = 0; i < glyph_width; i++) {
+ if (gp->bitmap[offset] & (0x01 << (shift - i - 1)))
+ pixel = fb->color_palette[color.fg];
+ else if (fb->wall && color.bg == DEFAULT_BG) /* wallpaper */
+ memcpy(&pixel, fb->wall + (i + x * cell_width) * fb->bpp
+ + (offset + y * cell_height) * fb->line_length, fb->bpp);
+ else
+ pixel = fb->color_palette[color.bg];
+ memcpy(src + i * fb->bpp, &pixel, fb->bpp);
+ }
+}
+
+void draw_line_normal(struct framebuffer *fb, struct terminal *term, int y)
+{
+ int offset, x, size, pos;
+ char *src, *dst;
+
+ pos = (y * cell_height) * fb->line_length;
+ size = fb->res.x * fb->bpp;
+
+ for (offset = 0; offset < cell_height; offset++) {
+ for (x = 0; x < term->cols; x++)
+ fb->set_bit(fb, term, y, x, offset,
+ fb->buf + pos + x * cell_width * fb->bpp + offset * fb->line_length);
+ src = fb->buf + pos + offset * fb->line_length;
+ dst = fb->fp + pos + offset * fb->line_length;
+ memcpy(dst, src, size);
+ }
+ term->line_dirty[y] = (term->mode & MODE_CURSOR && term->cursor.y == y) ? true: false;
+}
+
+void draw_line_clockwise(struct framebuffer *fb, struct terminal *term, int line)
+{
+ int y, pos, copy_size;
+ char *src, *dst;
+
+ int col, glyph_width_offset, glyph_height_offset, glyph_width; //bits_per_glyph_width;
+ uint32_t pixel;
+ struct color_pair color;
+ struct cell *cp;
+ const struct static_glyph_t *gp;
+
+ /* calc address of framebuffer */
+ /*
+ terminal pos
+ (fb->res.x, line * cell_height)
+ framebuffer pos
+ ((line * cell_height), 0)
+ */
+ pos = (line * cell_height) * fb->bpp;
+ copy_size = cell_height * fb->bpp;
+
+ for (y = 0; y < fb->res.x; y++) {
+ col = term->cols - 1 - (y / cell_width);
+ for (glyph_height_offset = 0; glyph_height_offset < cell_height; glyph_height_offset++) {
+ /* check cell */
+ cp = &term->cells[col + line * term->cols];
+ color = cp->color;
+ if (cp->wide == NEXT_TO_WIDE)
+ continue;
+
+ /* check glyph */
+ gp = cp->gp;
+ glyph_width = gp->width * cell_width; /* gp->width: 1 or 2 */
+ //bits_per_glyph_width = my_ceil(glyph_width, BITS_PER_BYTE) * BITS_PER_BYTE;
+ glyph_width_offset = (y / cell_width);
+
+ /* check cursor position */
+ if ((term->mode & MODE_CURSOR && line == term->cursor.y)
+ && (col == term->cursor.x || (cp->wide == WIDE && (col + 1) == term->cursor.x))) {
+ color.fg = DEFAULT_BG;
+ color.bg = CURSOR_COLOR;
+ }
+
+ /* set underline */
+ if ((glyph_height_offset == (cell_height - 1)) && (cp->attribute & attr_mask[UNDERLINE]))
+ color.bg = color.fg;
+
+ /* set color palette */
+ if (gp->bitmap[glyph_height_offset] & (0x01 << glyph_width_offset))
+ pixel = fb->color_palette[color.fg];
+ else if (fb->wall && color.bg == DEFAULT_BG) /* wallpaper */
+ memcpy(&pixel, fb->wall + (col * cell_width) * fb->bpp
+ + (glyph_height_offset + line * cell_height) * fb->line_length, fb->bpp);
+ else
+ pixel = fb->color_palette[color.bg];
+
+ memcpy(fb->buf + glyph_height_offset * fb->bpp + y * fb->line_length, &pixel, fb->bpp);
+ }
+ src = fb->buf + pos + y * fb->line_length;
+ dst = fb->fp + pos + y * fb->line_length;
+ memcpy(dst, src, copy_size);
+ }
+}
+
+void set_bit_upside_down(struct framebuffer *fb, struct terminal *term, int y, int x, int offset, char *src)
+{
+}
+
+void draw_line_upside_down(struct framebuffer *fb, struct terminal *term, int y)
+{
+}
+
+void set_bit_counter_clockwise(struct framebuffer *fb, struct terminal *term, int y, int x, int offset, char *src)
+{
+}
+
+void draw_line_counter_clockwise(struct framebuffer *fb, struct terminal *term, int y)
+{
+}
+
+void check_rotate(struct framebuffer *fb)
+{
+ int tmp;
+
+ if (ROTATE == CLOCKWISE || ROTATE == COUNTER_CLOCKWISE) {
+ tmp = fb->res.x;
+ fb->res.x = fb->res.y;
+ fb->res.y = tmp;
+ }
+
+ if (ROTATE == CLOCKWISE) {
+ //fb->set_bit = set_bit_clockwise;
+ fb->draw_line = draw_line_clockwise;
+ }
+ else if (ROTATE == UPSIDE_DOWN) {
+ fb->set_bit = set_bit_upside_down;
+ fb->draw_line = draw_line_upside_down;
+ }
+ else if (ROTATE == COUNTER_CLOCKWISE) {
+ fb->set_bit = set_bit_counter_clockwise;
+ fb->draw_line = draw_line_counter_clockwise;
+ }
+ else { /* rotate: NORMAL */
+ fb->set_bit = set_bit_normal;
+ fb->draw_line = draw_line_normal;
+ }
+}
diff --git a/terminal.h b/terminal.h
index f5a5438..302135b 100644
--- a/terminal.h
+++ b/terminal.h
@@ -167,6 +167,9 @@ void addch(struct terminal *term, uint32_t code)
int width;
const struct static_glyph_t *gp;
+ if (DEBUG)
+ fprintf(stderr, "addch: U+%.4X\n", code);
+
width = wcwidth(code);
if (width <= 0) /* zero width */
return;
@@ -275,18 +278,31 @@ void reset(struct terminal *term)
reset_ucs(term);
}
+void swap(int *a, int *b)
+{
+ int tmp;
+
+ tmp = *a;
+ *a = *b;
+ *b = tmp;
+}
+
void term_init(struct terminal *term, struct pair res)
{
+ //term->offset.x = TERM_OFFSET_X;
+ //term->offset.y = TERM_OFFSET_Y;
term->width = res.x;
term->height = res.y;
- term->offset.x = term->offset.y = 0;
+
+ if (ROTATE == CLOCKWISE || ROTATE == COUNTER_CLOCKWISE)
+ swap(&term->width, &term->height);
term->cols = term->width / cell_width;
term->lines = term->height / cell_height;
if (DEBUG)
fprintf(stderr, "width:%d height:%d cols:%d lines:%d\n",
- term->width, term->height, term->cols, term->lines);
+ res.x, res.y, term->cols, term->lines);
term->line_dirty = (bool *) emalloc(sizeof(bool) * term->lines);
term->tabstop = (bool *) emalloc(sizeof(bool) * term->cols);
diff --git a/yaft.c b/yaft.c
index a8eeed9..345959d 100644
--- a/yaft.c
+++ b/yaft.c
@@ -25,7 +25,8 @@ void handler(int signo)
ioctl(STDIN_FILENO, VT_RELDISP, 1);
sigfillset(&sigset);
sigdelset(&sigset, SIGUSR1);
- sigsuspend(&sigset);
+ if (!BACKGROUND_DRAW)
+ sigsuspend(&sigset);
}
else {
tty.visible = true;
@@ -150,7 +151,7 @@ int main()
if (DEBUG)
ewrite(STDOUT_FILENO, buf, size);
parse(&term, buf, size);
- if (size == BUFSIZE) /* lazy drawing */
+ if (LAZY_DRAW && size == BUFSIZE)
continue;
refresh(&fb, &term);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment