[vte] emulation: Implement XTERM_SMGRAPHICS sequence
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] emulation: Implement XTERM_SMGRAPHICS sequence
- Date: Fri, 23 Oct 2020 17:55:26 +0000 (UTC)
commit be953b92769cfeab1fdddc84676f8bb1ae8f57b5
Author: Christian Persch <chpe src gnome org>
Date: Fri Oct 23 19:55:05 2020 +0200
emulation: Implement XTERM_SMGRAPHICS sequence
src/parser-reply.hh | 1 +
src/parser-seq.py | 4 +-
src/sixel-context.hh | 4 +-
src/vtedefines.hh | 2 +
src/vteseq.cc | 117 +++++++++++++++++++++++++++++++++++++++++++++++++--
5 files changed, 121 insertions(+), 7 deletions(-)
---
diff --git a/src/parser-reply.hh b/src/parser-reply.hh
index 81e1b516..2dfc2240 100644
--- a/src/parser-reply.hh
+++ b/src/parser-reply.hh
@@ -30,6 +30,7 @@ _VTE_REPLY(XTERM_MOUSE_EXT_SGR_REPORT_BUTTON_PRESS, CSI, 'M', LT, NONE, ) /
_VTE_REPLY(XTERM_FOCUS_OUT, CSI, 'O', NONE, NONE, ) /* XTERM focus out report */
_VTE_REPLY(DECXCPR, CSI, 'R', WHAT, NONE, ) /* extended cursor position
report */
_VTE_REPLY(CPR, CSI, 'R', NONE, NONE, ) /* cursor position report */
+_VTE_REPLY(XTERM_SMGRAPHICS_REPORT, CSI, 'S', WHAT, NONE, ) /* xterm graphics attribute
report */
_VTE_REPLY(DECDA1R, CSI, 'c', WHAT, NONE, ) /* DA1 report */
_VTE_REPLY(DECDA2R, CSI, 'c', GT, NONE, ) /* DA2 report */
_VTE_REPLY(SGR, CSI, 'm', NONE, NONE, ) /* SGR */
diff --git a/src/parser-seq.py b/src/parser-seq.py
index 2ed8314b..a349d1d9 100755
--- a/src/parser-seq.py
+++ b/src/parser-seq.py
@@ -547,8 +547,8 @@ sequences = [
comment='scroll up'),
seq_CSI('SPD', 'S', intermediates=(Intermediate.SPACE,),
comment='select presentation directions'),
- seq_CSI('XTERM_SGFX', 'S', pintro=(ParameterIntro.WHAT,), flags=Flags.NOP,
- comment='xterm sixel graphics'),
+ seq_CSI('XTERM_SMGRAPHICS', 'S', pintro=(ParameterIntro.WHAT,),
+ comment='xterm graphics attributes'),
seq_CSI('SD', 'T',
comment='scroll down'),
seq_CSI('XTERM_IHMT', 'T', flags=Flags.NOP,
diff --git a/src/sixel-context.hh b/src/sixel-context.hh
index 1754f8f5..8364702f 100644
--- a/src/sixel-context.hh
+++ b/src/sixel-context.hh
@@ -72,9 +72,9 @@ private:
uint32_t m_introducer{0};
uint32_t m_st{0};
- static inline constexpr unsigned const k_max_width = 2048u;
+ static inline constexpr unsigned const k_max_width = VTE_SIXEL_MAX_WIDTH;
- static inline constexpr unsigned const k_max_height = 2052u;
+ static inline constexpr unsigned const k_max_height = VTE_SIXEL_MAX_HEIGHT;
static_assert((k_max_height % 6) == 0, "k_max_height not divisible by 6");
static inline constexpr int const k_num_colors = VTE_SIXEL_NUM_COLOR_REGISTERS;
diff --git a/src/vtedefines.hh b/src/vtedefines.hh
index d3c07501..63150685 100644
--- a/src/vtedefines.hh
+++ b/src/vtedefines.hh
@@ -146,4 +146,6 @@
#define VTE_SIXEL_ENABLED_DEFAULT false
+#define VTE_SIXEL_MAX_WIDTH (2048)
+#define VTE_SIXEL_MAX_HEIGHT (2052)
#define VTE_SIXEL_NUM_COLOR_REGISTERS (1024)
diff --git a/src/vteseq.cc b/src/vteseq.cc
index 8a7a4906..461ef3c8 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -8724,13 +8724,124 @@ Terminal::XTERM_RTM(vte::parser::Sequence const& seq)
}
void
-Terminal::XTERM_SGFX(vte::parser::Sequence const& seq)
+Terminal::XTERM_SMGRAPHICS(vte::parser::Sequence const& seq)
{
/*
- * XTERM_SGFX - xterm-sixel-graphics
+ * XTERM_SMGRAPHICS - xterm set or request graphics attributes
+ * Set or request graphics attributes for SIXEL and REGIS.
*
- * Probably not worth implementing.
+ * Reply: XTERM_SMGRAPHICS_REPORT
+ *
+ * Arguments:
+ * args[0]: select function
+ * 0: number of colour registers
+ * 1: SIXEL geometry
+ * 2: REGIS geometry
+ * args[1]: select subfunction
+ * 1: read attribute
+ * 2: reset attribute
+ * 3: set attribute
+ * 4: read maximum value of attribute
+ * args[2:]: values, used only for subfuncion 3
+ *
+ * Defaults:
+ * args[0]: no default
+ * args[1]: no default
+ * args[2:]: no default
+ *
+ * The reply is XTERM_SMGRAPHICS_REPORT, with arguments:
+ * args[0]: function
+ * args[1]: status
+ * 0: success
+ * 1: error in function parameter
+ * 2: error in subfunction parameter
+ * 3: failure
+ *
+ * References: XTERM
*/
+
+ auto const attr = seq.collect1(0);
+ auto const what = seq.collect1(1);
+ auto status = 3, rv0 = -2, rv1 = -2;
+
+ switch (attr) {
+#ifdef WITH_SIXEL
+ case 0: /* Colour registers.
+ *
+ * VTE doesn't support changing the number of colour registers, so always
+ * return the fixed number, and set() returns success iff the passed number
+ * was less or equal that number.
+ */
+ switch (what) {
+ case 1: /* read */
+ case 2: /* reset */
+ case 4: /* read maximum */
+ status = 0;
+ rv0 = VTE_SIXEL_NUM_COLOR_REGISTERS;
+ break;
+ case 3: /* set */
+ status = (seq.collect1(2) <= VTE_SIXEL_NUM_COLOR_REGISTERS) ? 0 : 2;
+ rv0 = VTE_SIXEL_NUM_COLOR_REGISTERS;
+ break;
+ case -1: /* no default */
+ default:
+ status = 2;
+ break;
+ }
+ break;
+
+ case 1: /* SIXEL graphics geometry.
+ *
+ * VTE doesn't support variable geometries; always report
+ * the maximum size of a SIXEL graphic, and set() returns success iff the
+ * passed numbers are less or equal to that number.
+ */
+ switch (what) {
+ case 1: /* read */
+ case 2: /* reset */
+ case 4: /* read maximum */
+ status = 0;
+ rv0 = VTE_SIXEL_MAX_WIDTH;
+ rv1 = VTE_SIXEL_MAX_HEIGHT;
+ break;
+
+ case 3: /* set */ {
+ auto w = int{}, h = int{};
+ if (seq.collect(2, {&w, &h}) &&
+ w > 0 && w <= VTE_SIXEL_MAX_WIDTH &&
+ h > 0 && h <= VTE_SIXEL_MAX_HEIGHT) {
+ rv0 = VTE_SIXEL_MAX_WIDTH;
+ rv1 = VTE_SIXEL_MAX_HEIGHT;
+ status = 0;
+ } else {
+ status = 3;
+ }
+
+ break;
+ }
+
+ case -1: /* no default */
+ default:
+ status = 2;
+ break;
+ }
+ break;
+
+#endif /* WITH_SIXEL */
+
+#if 0 /* ifdef WITH_REGIS */
+ case 2:
+ status = 1;
+ break;
+#endif
+
+ case -1: /* no default value */
+ default:
+ status = 1;
+ break;
+ }
+
+ reply(seq, VTE_REPLY_XTERM_SMGRAPHICS_REPORT, {attr, status, rv0, rv1});
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]