Skip to content

Commit e6c1597

Browse files
committed
Start work on multiple hardware cursors
1 parent d8cfb6b commit e6c1597

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

kitty/screen.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ screen_reset(Screen *self) {
189189
self->last_graphic_char = 0;
190190
self->main_savepoint.is_valid = false;
191191
self->alt_savepoint.is_valid = false;
192+
if (self->extra_cursors.count) {
193+
self->extra_cursors.count = 0;
194+
self->extra_cursors.dirty = true;
195+
}
192196
linebuf_clear(self->linebuf, BLANK_CHAR);
193197
historybuf_clear(self->historybuf);
194198
clear_hyperlink_pool(self->hyperlink_pool);
@@ -673,6 +677,7 @@ dealloc(Screen* self) {
673677
free_hyperlink_pool(self->hyperlink_pool);
674678
free(self->as_ansi_buf.buf);
675679
free(self->last_rendered_window_char.canvas);
680+
free(self->extra_cursors.locations); free(self->paused_rendering.extra_cursors.locations);
676681
if (self->lc) { cleanup_list_of_chars(self->lc); free(self->lc); self->lc = NULL; }
677682
Py_TYPE(self)->tp_free((PyObject*)self);
678683
} // }}}
@@ -1546,6 +1551,10 @@ screen_toggle_screen_buffer(Screen *self, bool save_cursor, bool clear_alt_scree
15461551
self->is_dirty = true;
15471552
grman_mark_layers_dirty(self->grman);
15481553
clear_all_selections(self);
1554+
if (self->extra_cursors.count) {
1555+
self->extra_cursors.count = 0;
1556+
self->extra_cursors.dirty = true;
1557+
}
15491558
global_state.check_for_active_animated_images = true;
15501559
}
15511560

@@ -2475,6 +2484,10 @@ screen_erase_in_display(Screen *self, unsigned int how, bool private) {
24752484
/* fallthrough */
24762485
case 2:
24772486
case 3:
2487+
if (self->extra_cursors.count) {
2488+
self->extra_cursors.count = 0;
2489+
self->extra_cursors.dirty = true;
2490+
}
24782491
grman_clear(self->grman, how == 3, self->cell_size);
24792492
a = 0; b = self->lines; nuke_multicell_chars = false;
24802493
break;
@@ -3079,8 +3092,11 @@ screen_pause_rendering(Screen *self, bool pause, int for_in_ms) {
30793092
self->is_dirty = true;
30803093
// ensure selection data is updated on GPU
30813094
self->selections.last_rendered_count = SIZE_MAX; self->url_ranges.last_rendered_count = SIZE_MAX;
3095+
self->extra_cursors.dirty = true;
30823096
// free grman data
30833097
grman_pause_rendering(NULL, self->paused_rendering.grman);
3098+
// free extra cursors
3099+
free(self->paused_rendering.extra_cursors.locations); zero_at_ptr(&self->paused_rendering.extra_cursors);
30843100
return true;
30853101
}
30863102
if (self->paused_rendering.expires_at) return false;
@@ -3107,6 +3123,14 @@ screen_pause_rendering(Screen *self, bool pause, int for_in_ms) {
31073123
}
31083124
copy_selections(&self->paused_rendering.selections, &self->selections);
31093125
copy_selections(&self->paused_rendering.url_ranges, &self->url_ranges);
3126+
if (self->extra_cursors.count) {
3127+
self->paused_rendering.extra_cursors.locations = calloc(self->extra_cursors.count, sizeof(self->extra_cursors.locations[0]));
3128+
if (self->paused_rendering.extra_cursors.locations) {
3129+
self->paused_rendering.extra_cursors.count = self->extra_cursors.count;
3130+
self->paused_rendering.extra_cursors.dirty = self->extra_cursors.dirty;
3131+
memcpy(self->paused_rendering.extra_cursors.locations, self->extra_cursors.locations, sizeof(self->extra_cursors.locations[0]) * self->extra_cursors.count);
3132+
}
3133+
}
31103134
grman_pause_rendering(self->grman, self->paused_rendering.grman);
31113135
return true;
31123136
}
@@ -3558,7 +3582,13 @@ screen_apply_selection(Screen *self, void *address, size_t size) {
35583582
if (OPT(underline_hyperlinks) == UNDERLINE_NEVER && s->is_hyperlink) continue;
35593583
apply_selection(self, address, s, 2);
35603584
}
3585+
uint8_t *a = address;
35613586
sel->last_rendered_count = sel->count;
3587+
ExtraCursors *ec = self->paused_rendering.expires_at ? &self->paused_rendering.extra_cursors : &self->extra_cursors;
3588+
for (unsigned i = 0; i < ec->count; i++) {
3589+
if (ec->locations[i].cell < size) a[ec->locations[i].cell] |= (ec->locations[i].shape & 7) << 2;
3590+
}
3591+
ec->dirty = false;
35623592
}
35633593

35643594
static index_type
@@ -4804,7 +4834,7 @@ screen_is_selection_dirty(Screen *self) {
48044834
IterationData q;
48054835
if (self->paused_rendering.expires_at) return false;
48064836
if (self->scrolled_by != self->last_rendered.scrolled_by) return true;
4807-
if (self->selections.last_rendered_count != self->selections.count || self->url_ranges.last_rendered_count != self->url_ranges.count) return true;
4837+
if (self->selections.last_rendered_count != self->selections.count || self->url_ranges.last_rendered_count != self->url_ranges.count || self->extra_cursors.dirty) return true;
48084838
for (size_t i = 0; i < self->selections.count; i++) {
48094839
iteration_data(self->selections.items + i, &q, self->columns, 0, self->scrolled_by);
48104840
if (memcmp(&q, &self->selections.items[i].last_rendered, sizeof(IterationData)) != 0) return true;

kitty/screen.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "monotonic.h"
1212
#include "line-buf.h"
1313
#include "history.h"
14-
#include "window_logo.h"
1514

1615
typedef enum ScrollTypes { SCROLL_LINE = -999999, SCROLL_PAGE, SCROLL_FULL } ScrollType;
1716

@@ -88,6 +87,18 @@ typedef struct {
8887
} last_ime_pos;
8988
} OverlayLine;
9089

90+
typedef struct ExtraCursor {
91+
CursorShape shape;
92+
index_type cell;
93+
} ExtraCursor;
94+
95+
typedef struct ExtraCursors {
96+
ExtraCursor *locations;
97+
unsigned count, capacity;
98+
bool dirty;
99+
} ExtraCursors;
100+
101+
91102
typedef struct {
92103
PyObject_HEAD
93104
@@ -171,10 +182,12 @@ typedef struct {
171182
LineBuf *linebuf;
172183
GraphicsManager *grman;
173184
Selections selections, url_ranges;
185+
ExtraCursors extra_cursors;
174186
} paused_rendering;
175187
CharsetState charset;
176188
ListOfChars *lc;
177189
monotonic_t parsing_at;
190+
ExtraCursors extra_cursors;
178191
} Screen;
179192

180193

kitty_tests/layout.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ def do_ops_test(self, q):
155155
self.ae(i, windows.active_group_idx)
156156
check_visible()
157157

158+
# Test
159+
158160
def do_overlay_test(self, q):
159161
windows = create_windows(q)
160162
ids, visible_ids, expect_ids, check_visible = utils(self, q, windows)

0 commit comments

Comments
 (0)