Lines Matching refs:screen

39 static int vterm_screen_set_cell(VTermScreen *screen, VTermPos pos, const VTermScreenCell *cell);
71 static inline ScreenCell *getcell(const VTermScreen *screen, int row, int col) in getcell() argument
73 if(row < 0 || row >= screen->rows) in getcell()
75 if(col < 0 || col >= screen->cols) in getcell()
77 return screen->buffer + (screen->cols * row) + col; in getcell()
80 static ScreenCell *realloc_buffer(VTermScreen *screen, ScreenCell *buffer, int new_rows, int new_co… in realloc_buffer() argument
82 …ScreenCell *new_buffer = vterm_allocator_malloc(screen->vt, sizeof(ScreenCell) * new_rows * new_co… in realloc_buffer()
88 if(buffer && row < screen->rows && col < screen->cols) in realloc_buffer()
89 *new_cell = buffer[row * screen->cols + col]; in realloc_buffer()
92 new_cell->pen = screen->pen; in realloc_buffer()
98 vterm_allocator_free(screen->vt, buffer); in realloc_buffer()
103 static void damagerect(VTermScreen *screen, VTermRect rect) in damagerect() argument
107 switch(screen->damage_merge) { in damagerect()
118 vterm_screen_flush_damage(screen); in damagerect()
121 else if(screen->damaged.start_row == -1) { in damagerect()
123 screen->damaged = rect; in damagerect()
126 else if(rect.start_row == screen->damaged.start_row) { in damagerect()
128 if(screen->damaged.start_col > rect.start_col) in damagerect()
129 screen->damaged.start_col = rect.start_col; in damagerect()
130 if(screen->damaged.end_col < rect.end_col) in damagerect()
131 screen->damaged.end_col = rect.end_col; in damagerect()
136 emit = screen->damaged; in damagerect()
137 screen->damaged = rect; in damagerect()
144 if(screen->damaged.start_row == -1) in damagerect()
145 screen->damaged = rect; in damagerect()
147 rect_expand(&screen->damaged, &rect); in damagerect()
152 fprintf(stderr, "TODO: Maybe merge damage for level %d\n", screen->damage_merge); in damagerect()
156 if(screen->callbacks && screen->callbacks->damage) in damagerect()
157 (*screen->callbacks->damage)(emit, screen->cbdata); in damagerect()
160 static void damagescreen(VTermScreen *screen) in damagescreen() argument
164 .end_row = screen->rows, in damagescreen()
166 .end_col = screen->cols, in damagescreen()
169 damagerect(screen, rect); in damagescreen()
174 VTermScreen *screen = user; in putglyph() local
175 ScreenCell *cell = getcell(screen, pos.row, pos.col); in putglyph()
183 cell->pen = screen->pen; in putglyph()
189 getcell(screen, pos.row, pos.col + col)->chars[0] = (uint32_t)-1; in putglyph()
202 damagerect(screen, rect); in putglyph()
209 VTermScreen *screen = user; in moverect_internal() local
211 if(screen->callbacks && screen->callbacks->sb_pushline && in moverect_internal()
213 dest.end_col == screen->cols && // full width in moverect_internal()
214 screen->buffer == screen->buffers[0]) { // not altscreen in moverect_internal()
217 for(pos.col = 0; pos.col < screen->cols; pos.col++) in moverect_internal()
218 vterm_screen_get_cell(screen, pos, screen->sb_buffer + pos.col); in moverect_internal()
220 (screen->callbacks->sb_pushline)(screen->cols, screen->sb_buffer, screen->cbdata); in moverect_internal()
240 memmove(getcell(screen, row, dest.start_col), in moverect_internal()
241 getcell(screen, row + downward, src.start_col), in moverect_internal()
249 VTermScreen *screen = user; in moverect_user() local
251 if(screen->callbacks && screen->callbacks->moverect) { in moverect_user()
252 if(screen->damage_merge != VTERM_DAMAGE_SCROLL) in moverect_user()
254 vterm_screen_flush_damage(screen); in moverect_user()
256 if((*screen->callbacks->moverect)(dest, src, screen->cbdata)) in moverect_user()
260 damagerect(screen, dest); in moverect_user()
267 VTermScreen *screen = user; in erase_internal() local
270 const VTermLineInfo *info = vterm_state_get_lineinfo(screen->state, row); in erase_internal()
273 ScreenCell *cell = getcell(screen, row, col); in erase_internal()
279 cell->pen = screen->pen; in erase_internal()
290 VTermScreen *screen = user; in erase_user() local
292 damagerect(screen, rect); in erase_user()
305 VTermScreen *screen = user; in scrollrect() local
308 moverect_internal, erase_internal, screen); in scrollrect()
310 if(screen->damage_merge != VTERM_DAMAGE_SCROLL) { in scrollrect()
311 vterm_screen_flush_damage(screen); in scrollrect()
314 moverect_user, erase_user, screen); in scrollrect()
319 if(screen->damaged.start_row != -1 && in scrollrect()
320 !rect_intersects(&rect, &screen->damaged)) { in scrollrect()
321 vterm_screen_flush_damage(screen); in scrollrect()
324 if(screen->pending_scrollrect.start_row == -1) { in scrollrect()
325 screen->pending_scrollrect = rect; in scrollrect()
326 screen->pending_scroll_downward = downward; in scrollrect()
327 screen->pending_scroll_rightward = rightward; in scrollrect()
329 else if(rect_equal(&screen->pending_scrollrect, &rect) && in scrollrect()
330 ((screen->pending_scroll_downward == 0 && downward == 0) || in scrollrect()
331 (screen->pending_scroll_rightward == 0 && rightward == 0))) { in scrollrect()
332 screen->pending_scroll_downward += downward; in scrollrect()
333 screen->pending_scroll_rightward += rightward; in scrollrect()
336 vterm_screen_flush_damage(screen); in scrollrect()
338 screen->pending_scrollrect = rect; in scrollrect()
339 screen->pending_scroll_downward = downward; in scrollrect()
340 screen->pending_scroll_rightward = rightward; in scrollrect()
343 if(screen->damaged.start_row == -1) in scrollrect()
346 if(rect_contains(&rect, &screen->damaged)) { in scrollrect()
347 vterm_rect_move(&screen->damaged, -downward, -rightward); in scrollrect()
348 rect_clip(&screen->damaged, &rect); in scrollrect()
355 else if(rect.start_col <= screen->damaged.start_col && in scrollrect()
356 rect.end_col >= screen->damaged.end_col && in scrollrect()
358 if(screen->damaged.start_row >= rect.start_row && in scrollrect()
359 screen->damaged.start_row < rect.end_row) { in scrollrect()
360 screen->damaged.start_row -= downward; in scrollrect()
361 if(screen->damaged.start_row < rect.start_row) in scrollrect()
362 screen->damaged.start_row = rect.start_row; in scrollrect()
363 if(screen->damaged.start_row > rect.end_row) in scrollrect()
364 screen->damaged.start_row = rect.end_row; in scrollrect()
366 if(screen->damaged.end_row >= rect.start_row && in scrollrect()
367 screen->damaged.end_row < rect.end_row) { in scrollrect()
368 screen->damaged.end_row -= downward; in scrollrect()
369 if(screen->damaged.end_row < rect.start_row) in scrollrect()
370 screen->damaged.end_row = rect.start_row; in scrollrect()
371 if(screen->damaged.end_row > rect.end_row) in scrollrect()
372 screen->damaged.end_row = rect.end_row; in scrollrect()
377 ARGSrect(screen->damaged), ARGSrect(rect)); in scrollrect()
385 VTermScreen *screen = user; in movecursor() local
387 if(screen->callbacks && screen->callbacks->movecursor) in movecursor()
388 return (*screen->callbacks->movecursor)(pos, oldpos, visible, screen->cbdata); in movecursor()
395 VTermScreen *screen = user; in setpenattr() local
399 screen->pen.bold = val->boolean; in setpenattr()
402 screen->pen.underline = val->number; in setpenattr()
405 screen->pen.italic = val->boolean; in setpenattr()
408 screen->pen.blink = val->boolean; in setpenattr()
411 screen->pen.reverse = val->boolean; in setpenattr()
414 screen->pen.strike = val->boolean; in setpenattr()
417 screen->pen.font = val->number; in setpenattr()
420 screen->pen.fg = val->color; in setpenattr()
423 screen->pen.bg = val->color; in setpenattr()
432 VTermScreen *screen = user; in settermprop() local
436 if(val->boolean && !screen->buffers[1]) in settermprop()
439 screen->buffer = val->boolean ? screen->buffers[1] : screen->buffers[0]; in settermprop()
444 damagescreen(screen); in settermprop()
447 screen->global_reverse = val->boolean; in settermprop()
448 damagescreen(screen); in settermprop()
454 if(screen->callbacks && screen->callbacks->settermprop) in settermprop()
455 return (*screen->callbacks->settermprop)(prop, val, screen->cbdata); in settermprop()
462 VTermScreen *screen = user; in setmousefunc() local
464 if(screen->callbacks && screen->callbacks->setmousefunc) in setmousefunc()
465 return (*screen->callbacks->setmousefunc)(func, data, screen->cbdata); in setmousefunc()
472 VTermScreen *screen = user; in bell() local
474 if(screen->callbacks && screen->callbacks->bell) in bell()
475 return (*screen->callbacks->bell)(screen->cbdata); in bell()
482 VTermScreen *screen = user; in resize() local
484 int is_altscreen = (screen->buffers[1] && screen->buffer == screen->buffers[1]); in resize()
486 int old_rows = screen->rows; in resize()
487 int old_cols = screen->cols; in resize()
494 if(!vterm_screen_is_eol(screen, pos)) in resize()
506 vterm_screen_flush_damage(screen); in resize()
512 screen->buffers[0] = realloc_buffer(screen, screen->buffers[0], new_rows, new_cols); in resize()
513 if(screen->buffers[1]) in resize()
514 screen->buffers[1] = realloc_buffer(screen, screen->buffers[1], new_rows, new_cols); in resize()
516 screen->buffer = is_altscreen ? screen->buffers[1] : screen->buffers[0]; in resize()
518 screen->rows = new_rows; in resize()
519 screen->cols = new_cols; in resize()
521 if(screen->sb_buffer) in resize()
522 vterm_allocator_free(screen->vt, screen->sb_buffer); in resize()
524 screen->sb_buffer = vterm_allocator_malloc(screen->vt, sizeof(VTermScreenCell) * new_cols); in resize()
533 damagerect(screen, rect); in resize()
537 if(!is_altscreen && screen->callbacks && screen->callbacks->sb_popline) { in resize()
540 if(!(screen->callbacks->sb_popline(screen->cols, screen->sb_buffer, screen->cbdata))) in resize()
545 .end_row = screen->rows, in resize()
547 .end_col = screen->cols, in resize()
552 for(pos.col = 0; pos.col < screen->cols; pos.col += screen->sb_buffer[pos.col].width) in resize()
553 vterm_screen_set_cell(screen, pos, screen->sb_buffer + pos.col); in resize()
556 damagerect(screen, rect); in resize()
558 vterm_screen_flush_damage(screen); in resize()
571 damagerect(screen, rect); in resize()
574 if(screen->callbacks && screen->callbacks->resize) in resize()
575 return (*screen->callbacks->resize)(new_rows, new_cols, screen->cbdata); in resize()
582 VTermScreen *screen = user; in setlineinfo() local
586 for(int col = 0; col < screen->cols; col++) { in setlineinfo()
587 ScreenCell *cell = getcell(screen, row, col); in setlineinfo()
596 .end_col = newinfo->doublewidth ? screen->cols / 2 : screen->cols, in setlineinfo()
598 damagerect(screen, rect); in setlineinfo()
601 rect.start_col = screen->cols / 2; in setlineinfo()
602 rect.end_col = screen->cols; in setlineinfo()
630 VTermScreen *screen = vterm_allocator_malloc(vt, sizeof(VTermScreen)); in screen_new() local
635 screen->vt = vt; in screen_new()
636 screen->state = state; in screen_new()
638 screen->damage_merge = VTERM_DAMAGE_CELL; in screen_new()
639 screen->damaged.start_row = -1; in screen_new()
640 screen->pending_scrollrect.start_row = -1; in screen_new()
642 screen->rows = rows; in screen_new()
643 screen->cols = cols; in screen_new()
645 screen->buffers[0] = realloc_buffer(screen, NULL, rows, cols); in screen_new()
647 screen->buffer = screen->buffers[0]; in screen_new()
649 screen->sb_buffer = vterm_allocator_malloc(screen->vt, sizeof(VTermScreenCell) * cols); in screen_new()
651 vterm_state_set_callbacks(screen->state, &state_cbs, screen); in screen_new()
653 return screen; in screen_new()
656 INTERNAL void vterm_screen_free(VTermScreen *screen) in vterm_screen_free() argument
658 vterm_allocator_free(screen->vt, screen->buffers[0]); in vterm_screen_free()
659 if(screen->buffers[1]) in vterm_screen_free()
660 vterm_allocator_free(screen->vt, screen->buffers[1]); in vterm_screen_free()
662 vterm_allocator_free(screen->vt, screen->sb_buffer); in vterm_screen_free()
664 vterm_allocator_free(screen->vt, screen); in vterm_screen_free()
667 void vterm_screen_reset(VTermScreen *screen, int hard) in vterm_screen_reset() argument
669 screen->damaged.start_row = -1; in vterm_screen_reset()
670 screen->pending_scrollrect.start_row = -1; in vterm_screen_reset()
671 vterm_state_reset(screen->state, hard); in vterm_screen_reset()
672 vterm_screen_flush_damage(screen); in vterm_screen_reset()
675 static size_t _get_chars(const VTermScreen *screen, const int utf8, void *buffer, size_t len, const… in _get_chars() argument
697 ScreenCell *cell = getcell(screen, row, col); in _get_chars()
725 size_t vterm_screen_get_chars(const VTermScreen *screen, uint32_t *chars, size_t len, const VTermRe… in vterm_screen_get_chars() argument
727 return _get_chars(screen, 0, chars, len, rect); in vterm_screen_get_chars()
730 size_t vterm_screen_get_text(const VTermScreen *screen, char *str, size_t len, const VTermRect rect) in vterm_screen_get_text() argument
732 return _get_chars(screen, 1, str, len, rect); in vterm_screen_get_text()
736 int vterm_screen_get_cell(const VTermScreen *screen, VTermPos pos, VTermScreenCell *cell) in vterm_screen_get_cell() argument
738 ScreenCell *intcell = getcell(screen, pos.row, pos.col); in vterm_screen_get_cell()
752 cell->attrs.reverse = intcell->pen.reverse ^ screen->global_reverse; in vterm_screen_get_cell()
762 if(pos.col < (screen->cols - 1) && in vterm_screen_get_cell()
763 getcell(screen, pos.row, pos.col + 1)->chars[0] == (uint32_t)-1) in vterm_screen_get_cell()
773 static int vterm_screen_set_cell(VTermScreen *screen, VTermPos pos, const VTermScreenCell *cell) in vterm_screen_set_cell() argument
775 ScreenCell *intcell = getcell(screen, pos.row, pos.col); in vterm_screen_set_cell()
789 intcell->pen.reverse = cell->attrs.reverse ^ screen->global_reverse; in vterm_screen_set_cell()
797 getcell(screen, pos.row, pos.col + 1)->chars[0] = (uint32_t)-1; in vterm_screen_set_cell()
802 int vterm_screen_is_eol(const VTermScreen *screen, VTermPos pos) in vterm_screen_is_eol() argument
805 for(; pos.col < screen->cols; pos.col++) { in vterm_screen_is_eol()
806 ScreenCell *cell = getcell(screen, pos.row, pos.col); in vterm_screen_is_eol()
816 if(vt->screen) in vterm_obtain_screen()
817 return vt->screen; in vterm_obtain_screen()
819 VTermScreen *screen = screen_new(vt); in vterm_obtain_screen() local
820 vt->screen = screen; in vterm_obtain_screen()
822 return screen; in vterm_obtain_screen()
825 void vterm_screen_enable_altscreen(VTermScreen *screen, int altscreen) in vterm_screen_enable_altscreen() argument
828 if(!screen->buffers[1] && altscreen) { in vterm_screen_enable_altscreen()
830 vterm_get_size(screen->vt, &rows, &cols); in vterm_screen_enable_altscreen()
832 screen->buffers[1] = realloc_buffer(screen, NULL, rows, cols); in vterm_screen_enable_altscreen()
836 void vterm_screen_set_callbacks(VTermScreen *screen, const VTermScreenCallbacks *callbacks, void *u… in vterm_screen_set_callbacks() argument
838 screen->callbacks = callbacks; in vterm_screen_set_callbacks()
839 screen->cbdata = user; in vterm_screen_set_callbacks()
842 void vterm_screen_flush_damage(VTermScreen *screen) in vterm_screen_flush_damage() argument
844 if(screen->pending_scrollrect.start_row != -1) { in vterm_screen_flush_damage()
845 …vterm_scroll_rect(screen->pending_scrollrect, screen->pending_scroll_downward, screen->pending_scr… in vterm_screen_flush_damage()
846 moverect_user, erase_user, screen); in vterm_screen_flush_damage()
848 screen->pending_scrollrect.start_row = -1; in vterm_screen_flush_damage()
851 if(screen->damaged.start_row != -1) { in vterm_screen_flush_damage()
852 if(screen->callbacks && screen->callbacks->damage) in vterm_screen_flush_damage()
853 (*screen->callbacks->damage)(screen->damaged, screen->cbdata); in vterm_screen_flush_damage()
855 screen->damaged.start_row = -1; in vterm_screen_flush_damage()
859 void vterm_screen_set_damage_merge(VTermScreen *screen, VTermDamageSize size) in vterm_screen_set_damage_merge() argument
861 vterm_screen_flush_damage(screen); in vterm_screen_set_damage_merge()
862 screen->damage_merge = size; in vterm_screen_set_damage_merge()
889 int vterm_screen_get_attrs_extent(const VTermScreen *screen, VTermRect *extent, VTermPos pos, VTerm… in vterm_screen_get_attrs_extent() argument
891 ScreenCell *target = getcell(screen, pos.row, pos.col); in vterm_screen_get_attrs_extent()
900 extent->end_col = screen->cols; in vterm_screen_get_attrs_extent()
905 if(attrs_differ(attrs, target, getcell(screen, pos.row, col))) in vterm_screen_get_attrs_extent()
910 if(attrs_differ(attrs, target, getcell(screen, pos.row, col))) in vterm_screen_get_attrs_extent()