Skip to content

Commit

Permalink
[kitty] introduce kitty_move #1395
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Jun 20, 2021
1 parent 67c57ce commit 8187d35
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
14 changes: 13 additions & 1 deletion src/lib/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ void sprixel_free(sprixel* s);
void sprixel_hide(sprixel* s);

int kitty_draw(const ncpile *p, sprixel* s, FILE* out);
int kitty_move(const ncpile *p, sprixel* s, FILE* out);
int sixel_draw(const ncpile *p, sprixel* s, FILE* out);
// dimy and dimx are cell geometry, not pixel.
sprixel* sprixel_alloc(ncplane* n, int dimy, int dimx);
Expand Down Expand Up @@ -887,13 +888,24 @@ sprite_destroy(const notcurses* nc, const ncpile* p, FILE* out, sprixel* s){
return nc->tcache.pixel_destroy(nc, p, out, s);
}

// precondition: s->invalidated is SPRIXEL_INVALIDATED or SPRIXEL_MOVED.
// precondition: s->invalidated is SPRIXEL_INVALIDATED
static inline int
sprite_draw(const notcurses* n, const ncpile* p, sprixel* s, FILE* out){
//sprixel_debug(stderr, s);
return n->tcache.pixel_draw(p, s, out);
}

// precondition: s->invalidated is SPRIXEL_MOVED or SPRIXEL_INVALIDATED
static inline int
sprite_redraw(const notcurses* n, const ncpile* p, sprixel* s, FILE* out){
//sprixel_debug(stderr, s);
if(s->invalidated == SPRIXEL_MOVED && n->tcache.pixel_move){
return n->tcache.pixel_move(p, s, out);
}else{
return n->tcache.pixel_draw(p, s, out);
}
}

static inline int
sprite_rebuild(const notcurses* nc, sprixel* s, int ycell, int xcell){
const int idx = s->dimx * ycell + xcell;
Expand Down
14 changes: 13 additions & 1 deletion src/lib/kitty.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ int kitty_destroy(const notcurses* nc __attribute__ ((unused)),
}

int kitty_draw(const ncpile* p, sprixel* s, FILE* out){
//fprintf(stderr, "DRAWING %d\n", s->id);
fprintf(stderr, "DRAWING %d\n", s->id);
(void)p;
int ret = 0;
if(fwrite(s->glyph, s->glyphlen, 1, out) != 1){
Expand All @@ -621,6 +621,18 @@ int kitty_draw(const ncpile* p, sprixel* s, FILE* out){
return ret;
}

int kitty_move(const ncpile* p, sprixel* s, FILE* out){
fprintf(stderr, "MOVING %d\n", s->id);
(void)p;
int ret = 0;
if(fprintf(out, "\e_Ga=p,i=%d,p=1,q=2\e\\", s->id) < 0){
ret = -1;
}
s->invalidated = SPRIXEL_QUIESCENT;
return ret;
//return kitty_draw(p, s, out);
}

// clears all kitty bitmaps
int kitty_clear_all(int fd){
//fprintf(stderr, "KITTY UNIVERSAL ERASE\n");
Expand Down
5 changes: 2 additions & 3 deletions src/lib/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -918,14 +918,13 @@ clean_sprixels(notcurses* nc, ncpile* p, FILE* out){
}else if(s->invalidated == SPRIXEL_MOVED || s->invalidated == SPRIXEL_INVALIDATED){
int y, x;
ncplane_yx(s->n, &y, &x);
// FIXME clean this up, don't use sprite_draw, etc.
// without this, kitty flickers
//fprintf(stderr, "1 MOVING BITMAP %d STATE %d AT %d/%d for %p\n", s->id, s->invalidated, y + nc->margin_t, x + nc->margin_l, s->n);
// without this, kitty flickers
if(s->invalidated == SPRIXEL_MOVED){
sprite_destroy(nc, p, out, s);
}
if(goto_location(nc, out, y + nc->margin_t, x + nc->margin_l) == 0){
if(sprite_draw(nc, p, s, out)){
if(sprite_redraw(nc, p, s, out)){
return -1;
}
nc->rstate.hardcursorpos = true;
Expand Down
1 change: 1 addition & 0 deletions src/lib/termdesc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ setup_kitty_bitmaps(tinfo* ti, int fd){
ti->pixel_destroy = kitty_destroy;
ti->pixel_remove = kitty_remove;
ti->pixel_draw = kitty_draw;
ti->pixel_move = kitty_move;
ti->pixel_shutdown = kitty_shutdown;
ti->sprixel_scale_height = 1;
ti->pixel_rebuild = kitty_rebuild;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/termdesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ typedef struct tinfo {
int (*pixel_remove)(int id, FILE* out); // kitty only, issue actual delete command
int (*pixel_init)(const struct tinfo*, int fd); // called when support is detected
int (*pixel_draw)(const struct ncpile* p, struct sprixel* s, FILE* out);
// execute move (erase old graphic, place at new location) if non-NULL
int (*pixel_move)(const struct ncpile* p, struct sprixel* s, FILE* out);
int (*pixel_shutdown)(int fd); // called during context shutdown
int (*pixel_clear_all)(int fd); // called during startup, kitty only
int sprixel_scale_height; // sprixel must be a multiple of this many rows
Expand Down

0 comments on commit 8187d35

Please sign in to comment.