From 14a66762a655779388ed3d135b05bc0a109aca24 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 17 May 2017 10:33:33 +0530 Subject: [PATCH] Fix incorrect response to request for device attributes --- kitty/data-types.h | 4 +++- kitty/parser.c | 8 +++++++- kitty/screen.c | 13 +++++++++++-- setup.py | 2 ++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/kitty/data-types.h b/kitty/data-types.h index 8d2522b10..1306b6b8a 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -15,6 +15,8 @@ #define UNUSED __attribute__ ((unused)) #define MAX(x, y) (((x) > (y)) ? (x) : (y)) #define MIN(x, y) (((x) > (y)) ? (y) : (x)) +#define xstr(s) str(s) +#define str(s) #s typedef Py_UCS4 char_type; typedef uint32_t color_type; @@ -405,7 +407,7 @@ void set_color_table_color(Screen *self, unsigned int code, PyObject*); uint32_t* translation_table(uint32_t which); uint32_t *latin1_charset; void screen_request_capabilities(Screen *, PyObject *); -void report_device_attributes(Screen *self, unsigned int UNUSED mode, bool UNUSED secondary); +void report_device_attributes(Screen *self, unsigned int UNUSED mode, char start_modifier); void select_graphic_rendition(Screen *self, unsigned int *params, unsigned int count); void report_device_status(Screen *self, unsigned int which, bool UNUSED); void report_mode_status(Screen *self, unsigned int which, bool); diff --git a/kitty/parser.c b/kitty/parser.c index c9a9016f1..45a1161a3 100644 --- a/kitty/parser.c +++ b/kitty/parser.c @@ -362,6 +362,12 @@ dispatch_csi(Screen *screen, PyObject DUMP_UNUSED *dump_callback) { name(screen, p1, private); \ break; +#define CALL_CSI_HANDLER1S(name, defval) \ + p1 = num_params > 0 ? params[0] : defval; \ + REPORT_COMMAND(name, p1, start_modifier); \ + name(screen, p1, start_modifier); \ + break; + #define CALL_CSI_HANDLER1M(name, defval) \ p1 = num_params > 0 ? params[0] : defval; \ REPORT_COMMAND(name, p1, end_modifier); \ @@ -458,7 +464,7 @@ dispatch_csi(Screen *screen, PyObject DUMP_UNUSED *dump_callback) { case ECH: CALL_CSI_HANDLER1(screen_erase_characters, 1); case DA: - CALL_CSI_HANDLER1P(report_device_attributes, 0, '>'); + CALL_CSI_HANDLER1S(report_device_attributes, 0); case TBC: CALL_CSI_HANDLER1(screen_clear_tab_stop, 0); case SM: diff --git a/kitty/screen.c b/kitty/screen.c index ec03b233a..4af72edcd 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -887,8 +887,17 @@ callback(const char *name, Screen *self, const char *data, unsigned int sz) { } void -report_device_attributes(Screen *self, unsigned int UNUSED mode, bool UNUSED secondary) { - callback("write_to_child", self, "\x1b[>1;4600;0c", 0); // same as libvte +report_device_attributes(Screen *self, unsigned int mode, char start_modifier) { + if (mode == 0) { + switch(start_modifier) { + case 0: + callback("write_to_child", self, "\x1b[?62;c", 0); // VT-220 with no extra info + break; + case '>': + callback("write_to_child", self, "\x1b[>1;" xstr(PRIMARY_VERSION) ";" xstr(SECONDARY_VERSION) "c", 0); // VT-220 + primary version + secondary version + break; + } + } } void diff --git a/setup.py b/setup.py index 1a28f11df..21b548959 100755 --- a/setup.py +++ b/setup.py @@ -131,6 +131,8 @@ def init_env(debug=False, sanitize=False, native_optimizations=True): ldflags += shlex.split(os.environ.get('LDFLAGS', '')) cflags.append('-pthread') + cflags.append('-DPRIMARY_VERSION={}'.format(version[0])) + cflags.append('-DSECONDARY_VERSION={}'.format(version[1])) if not is_travis and not isosx and subprocess.Popen( [PKGCONFIG, 'glew', '--atleast-version=2'] ).wait() != 0: