From aec1612de2baf4296799053b7c4c6d45602adbf7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 2 Oct 2017 10:35:51 +0530 Subject: [PATCH] API to enable image placement tests Also fix cursor movement handling after graphics command --- kitty/graphics.c | 18 ++++++++++++++++++ kitty/screen.c | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/kitty/graphics.c b/kitty/graphics.c index af8e33972..b71bf2987 100644 --- a/kitty/graphics.c +++ b/kitty/graphics.c @@ -567,6 +567,7 @@ grman_update_layers(GraphicsManager *self, unsigned int scrolled_by, float xstar self->count++; rd->z_index = ref->z_index; rd->image_id = img->internal_id; rd->src_rect = ref->src_rect; rd->dest_rect = r; + rd->texture_id = img->texture_id; }} if (!self->count) return; // Sort visible refs in draw order (z-index, img) @@ -680,10 +681,27 @@ W(set_send_to_gpu) { Py_RETURN_NONE; } +W(update_layers) { + unsigned int scrolled_by; float xstart, ystart, dx, dy; + PA("Iffff", &scrolled_by, &xstart, &ystart, &dx, &dy); + grman_update_layers(self, scrolled_by, xstart, ystart, dx, dy); + PyObject *ans = PyTuple_New(self->count); + for (size_t i = 0; i < self->count; i++) { + ImageRenderData *r = self->render_pointers[i]; +#define R(attr) Py_BuildValue("{sf sf sf sf}", "left", r->attr.left, "top", r->attr.top, "right", r->attr.right, "bottom", r->attr.bottom) + PyTuple_SET_ITEM(ans, i, + Py_BuildValue("{sN sN sI si sI}", "src_rect", R(src_rect), "dest_rect", R(dest_rect), "group_count", r->group_count, "z_index", r->z_index, "image_id", r->image_id) + ); +#undef R + } + return ans; +} + #define M(x, va) {#x, (PyCFunction)py##x, va, ""} static PyMethodDef methods[] = { M(image_for_client_id, METH_O), + M(update_layers, METH_VARARGS), {NULL} /* Sentinel */ }; diff --git a/kitty/screen.c b/kitty/screen.c index 3aa80fc23..e15915834 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -324,7 +324,7 @@ screen_align(Screen *self) { void screen_alignment_display(Screen *self) { // http://www.vt100.net/docs/vt510-rm/DECALN.html screen_cursor_position(self, 1, 1); - self->margin_top = 0; self->margin_bottom = self->columns - 1; + self->margin_top = 0; self->margin_bottom = self->lines - 1; for (unsigned int y = 0; y < self->linebuf->ynum; y++) { linebuf_init_line(self->linebuf, y); line_clear_text(self->linebuf->line, 0, self->linebuf->xnum, 'E'); @@ -423,7 +423,7 @@ screen_handle_graphics_command(Screen *self, const GraphicsCommand *cmd, const u if (response != NULL) write_to_child(self, response, strlen(response)); if (x != self->cursor->x || y != self->cursor->y) { if (self->cursor->x >= self->columns) { self->cursor->x = 0; self->cursor->y++; } - if (self->cursor->y >= self->lines) { screen_scroll(self, self->lines - (self->cursor->y - 1)); } + if (self->cursor->y > self->margin_bottom) { screen_scroll(self, self->cursor->y - self->margin_bottom); } } } // }}}