API to set screen window number

This commit is contained in:
Kovid Goyal 2021-10-11 18:00:18 +05:30
parent 61a56a0561
commit c3f4e734f1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 18 additions and 2 deletions

View File

@ -973,6 +973,9 @@ class Screen:
def ignore_bells_for(self, duration: float = 1) -> None:
pass
def set_window_number(self, num: int = -1) -> None:
pass
def current_key_encoding_flags(self) -> int:
pass

View File

@ -156,6 +156,7 @@ screen_reset(Screen *self) {
if (self->overlay_line.is_active) deactivate_overlay_line(self);
memset(self->main_key_encoding_flags, 0, sizeof(self->main_key_encoding_flags));
memset(self->alt_key_encoding_flags, 0, sizeof(self->alt_key_encoding_flags));
self->display_window_number = 0;
self->redraws_multiline_prompts = false;
self->last_graphic_char = 0;
self->main_savepoint.is_valid = false;
@ -2728,6 +2729,16 @@ reset_dirty(Screen *self, PyObject *a UNUSED) {
Py_RETURN_NONE;
}
static PyObject*
set_window_number(Screen *self, PyObject *a) {
int num = -1;
if (!PyArg_ParseTuple(a, "|i", &num)) return NULL;
self->display_window_number = MAX(0, num + 1);
self->is_dirty = true;
Py_RETURN_NONE;
}
static PyObject*
is_using_alternate_linebuf(Screen *self, PyObject *a UNUSED) {
if (self->linebuf == self->alt_linebuf) Py_RETURN_TRUE;
@ -3536,6 +3547,7 @@ static PyMethodDef methods[] = {
MND(draw, METH_O)
MND(apply_sgr, METH_O)
MND(cursor_position, METH_VARARGS)
MND(set_window_number, METH_VARARGS)
MND(set_mode, METH_VARARGS)
MND(reset_mode, METH_VARARGS)
MND(reset, METH_NOARGS)

View File

@ -132,6 +132,7 @@ typedef struct {
monotonic_t start, duration;
} ignore_bells;
bool redraws_multiline_prompts;
unsigned int display_window_number;
} Screen;

View File

@ -481,7 +481,7 @@ draw_window_number(OSWindow *os_window, Screen *screen, GLfloat xstart, GLfloat
#define C(shift) ((((GLfloat)((digit_color >> shift) & 0xFF)) / 255.0f))
glUniform4f(seven_segment_program_layout.digit_color_location, C(16), C(8), C(0), 1.);
#undef C
glUniform1i(seven_segment_program_layout.digit_location, 8);
glUniform1i(seven_segment_program_layout.digit_location, screen->display_window_number - 1);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisable(GL_BLEND);
}
@ -735,7 +735,7 @@ draw_cells(ssize_t vao_idx, ssize_t gvao_idx, GLfloat xstart, GLfloat ystart, GL
if (intensity > 0.0f) draw_visual_bell_flash(intensity, xstart, ystart, w, h, screen);
}
if (false) draw_window_number(os_window, screen, xstart, ystart, w, h);
if (screen->display_window_number) draw_window_number(os_window, screen, xstart, ystart, w, h);
}
// }}}