Skip to content

Commit a9595a3

Browse files
authored
Merge pull request #788 from o-sdn-o/gui-bridge
Make vt-input-mode mouse reporting better
2 parents d003c92 + e57ce69 commit a9595a3

File tree

4 files changed

+56
-52
lines changed

4 files changed

+56
-52
lines changed

doc/vt-input-mode.md

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Existing approaches have the following drawbacks:
3131

3232
## Conventions
3333

34-
- We use HEX-form of the uint32 (IEEE-754 32-bit binary float, Little-Endian) for the floating point value representation.
34+
- We use HEX-form of the uint32 for the 32-bit floating point value representation (IEEE-754 32-bit binary float, Little-Endian).
3535
- Space characters are not used in sequence payloads and are only used for readability of the description.
3636
- //todo: keyboard only: All unescaped symbols outside of this protocol should be treated as clipboard pasted data.
3737

@@ -63,17 +63,15 @@ Sources | Events to track
6363
`"clipboard"`| Clipboard.
6464
`"window"` | Window size and selection.
6565
`"system"` | System signals.
66-
`""` | Empty string to set all event reporting off.
66+
`""` | Set event reporting off.
6767

6868
/todo: keyboard only: Note: By enabling `vt-input-mode`, all current terminal modes are automatically saved (to be restored on exit) and switched to something like "raw" mode, in which input is available character by character, echoing is disabled, and all special processing of terminal input and output characters is disabled (except for `LF` to `CR+LF` conversion).
6969

7070
### Event format
7171

72-
The event signaling also uses APC `ESC _ <payload> ESC \` with an event-specific payload syntax.
73-
74-
The payload consists of a list of attributes in the following format:
72+
The event signaling also uses APC `ESC _ <payload> ESC \` vt-sequences with the following payload format:
7573
```
76-
<attr>=<val>,...,<val>; ...; <attr>=<val>,...,<val>
74+
<attr>=<val>,...,<val>;...;<attr>=<val>,...,<val>
7775
```
7876

7977
Field | Descriprtion
@@ -85,15 +83,15 @@ Field | Descriprtion
8583

8684
- Keyboard
8785
```
88-
ESC _ event=keyboard ; id=0 ; kbmods=<KeyMods> ; keyid=<KeyId> ; pressed=<KeyDown> ; scancode=<ScanCode> ; id_chord=<HexFormString> ; ch_chord=<HexFormString> ; sc_chord=<HexFormString> ; cluster=<C0>,...,<Cn> ESC \
86+
ESC _ event=keyboard ; id=<ID> ; kbmods=<KeyMods> ; keyid=<KeyId> ; pressed=<KeyDown> ; scancode=<ScanCode> ; id_chord=<HexFormString> ; ch_chord=<HexFormString> ; sc_chord=<HexFormString> ; cluster=<C0>,...,<Cn> ESC \
8987
```
9088
- Mouse
9189
```
92-
ESC _ event=mouse ; id=0 ; kbmods=<KeyMods> ; coor=<X>,<Y> ; buttons=<ButtonState> ; scroll=<DeltaX>,<DeltaY> ; finescroll=<DeltaX>,<DeltaY> ESC \
90+
ESC _ event=mouse ; id=<ID> ; kbmods=<KeyMods> ; coor=<X>,<Y> ; buttons=<ButtonState> ; iscroll=<DeltaX>,<DeltaY> ; fscroll=<DeltaX>,<DeltaY> ESC \
9391
```
9492
- Focus
9593
```
96-
ESC _ event=focus ; id=0 ; state=<FocusState> ESC \
94+
ESC _ event=focus ; id=<ID> ; state=<FocusState> ESC \
9795
```
9896
- Format
9997
```
@@ -102,7 +100,7 @@ Field | Descriprtion
102100
//todo Textinput, Text, IME or Input for IME preview etc
103101
- Clipboard
104102
```
105-
ESC _ event=clipboard ; id=0 ; format=<ClipFormat> ; security=<SecLevel> ; data=<Data> ESC \
103+
ESC _ event=clipboard ; id=<ID> ; format=<ClipFormat> ; security=<SecLevel> ; data=<Data> ESC \
106104
```
107105
- Window
108106
```
@@ -116,15 +114,15 @@ Field | Descriprtion
116114
### Keyboard
117115

118116
```
119-
ESC _ event=keyboard ; id=0 ; kbmods=<KeyMods> ; keyid=<KeyId> ; pressed=<KeyDown> ; scancode=<ScanCode> ; id_chord=<HexFormString> ; ch_chord=<HexFormString> ; sc_chord=<HexFormString> ; cluster=<C0>,...,<Cn> ESC \
117+
ESC _ event=keyboard ; id=<ID> ; kbmods=<KeyMods> ; keyid=<KeyId> ; pressed=<KeyDown> ; scancode=<ScanCode> ; id_chord=<HexFormString> ; ch_chord=<HexFormString> ; sc_chord=<HexFormString> ; cluster=<C0>,...,<Cn> ESC \
120118
```
121119

122120
> Q: Do we need to track scancode chord? `scanchord=<Code0>,...,<CodeN>`?
123121
124122
Attribute | Description
125123
------------------------------|------------
126-
`id=0` | Device group id.
127-
`kbmods=<KeyMods>` | Keyboard modifiers.
124+
`id=<ID>` | Device group id (unsigned integer value).
125+
`kbmods=<KeyMods>` | Keyboard modifiers bit field.
128126
`keyid=<KeyId>` | Physical key ID.
129127
`pressed=<KeyDown>` | Key state:<br>\<KeyDown\>=1 - Pressed.<br>\<KeyDown\>=0 - Released.
130128
`scancode=<ScanCode>` | Scan code.
@@ -135,7 +133,7 @@ Attribute | Description
135133

136134
In response to the activation of `keyboard` tracking, the application receives a vt-sequence containing keyboard modifiers state:
137135
```
138-
ESC _ event=keyboard ; id=0 ; kbmods=<KeyMods> ESC \
136+
ESC _ event=keyboard ; id=<ID> ; kbmods=<KeyMods> ESC \
139137
```
140138

141139
The full sequence is fired after every key press and key release. The sequence can contain a string generated by a keystroke as a set of codepoints: `C0 + ... + Cn`. ~~The string can be fragmented and delivered by multiple consecutive events.~~
@@ -362,17 +360,17 @@ Key ID | Name | Generic Name | Scan Code | Notes
362360
### Mouse
363361

364362
```
365-
ESC _ event=mouse ; id=0 ; kbmods=<KeyMods> ; coor=<X>,<Y> ; buttons=<ButtonState> ; scroll=<DeltaX>,<DeltaY> ; finescroll=<DeltaX>,<DeltaY> ESC \
363+
ESC _ event=mouse ; id=<ID> ; kbmods=<KeyMods> ; coor=<X>,<Y> ; buttons=<ButtonState> ; iscroll=<DeltaX>,<DeltaY> ; fscroll=<DeltaX>,<DeltaY> ESC \
366364
```
367365

368366
Attribute | Description
369367
--------------------------------|------------
370-
`id=0` | Device group id.
371-
`kbmods=<KeyMods>` | Keyboard modifiers (see Keyboard event).
372-
`coor=<X>,<Y>` | Pixel-wise coordinates of the mouse pointer. Each coordinate is represented in the form of a floating point value of the sum of the integer coordinate of the cell in the terminal window grid and the relative offset within the cell in the range `[0.0f, 1.0f)`.
373-
`buttons=<ButtonState>` | Mouse button state.
374-
`scroll=<DeltaX>,<DeltaY>` | Integer values of low resolution horizontal and vertical scroll deltas in integer 1/1 units (one scroll line corresponds to a value of 1).
375-
`finescroll=<DeltaX>,<DeltaY>` | Integer values of high resolution horizontal and vertical scroll deltas in integer 1/120 units (one scroll line corresponds to a value of 120).
368+
`id=<ID>` | Device group id (unsigned integer value).
369+
`kbmods=<KeyMods>` | Keyboard modifiers bit field (see Keyboard event).
370+
`coor=<X>,<Y>` | Pixel-wise 32-bit floating point coordinates of the mouse pointer relative to the console's text cell grid. The integer part corresponds to the cell coordinates, and the fractional part corresponds to the normalized position within the cell. The pointer's screen pixel coordinates can be calculated by multiplying these floating point values by the cell size. Receiving a NaN value is a signal that the mouse has left the window or disconnected.
371+
`buttons=<ButtonState>` | Mouse buttons bit field.
372+
`iscroll=<DeltaX>,<DeltaY>` | Low-resolution integer horizontal and vertical scroll deltas (one scroll line corresponds to a value of 1). Low-resolution scroll deltas increase as the values of high-resolution deltas accumulate, and are zeroed when the scroll direction changes.
373+
`fscroll=<DeltaX>,<DeltaY>` | High-resolution 32-bit floating-point horizontal and vertical scroll deltas (one scroll line corresponds to a value of 1.0f).
376374

377375
The mouse tracking event fires on any mouse activity, as well as on keyboard modifier changes.
378376

@@ -393,12 +391,12 @@ Note: Mouse tracking will continue outside the terminal window as long as the mo
393391
### Focus
394392

395393
```
396-
ESC _ event=focus ; id=0 ; state=<FocusState> ESC \
394+
ESC _ event=focus ; id=<ID> ; state=<FocusState> ESC \
397395
```
398396

399397
Attribute | Description
400398
---------------------|------------
401-
`id=0` | Device group id.
399+
`id=<ID>` | Device group id (unsigned integer value).
402400
`state=<FocusState>` | Terminal window focus:<br>\<FocusState\>=1 - Focused.<br>\<FocusState\>=0 - Unfocused.
403401

404402
In response to the activation of `focus` tracking, the application receives a vt-sequence containing current focus state.
@@ -420,12 +418,12 @@ In response to the activation of `format` tracking, the application receives a v
420418
### Clipboard
421419

422420
```
423-
ESC _ event=clipboard ; id=0 ; format=<ClipFormat> ; security=<SecLevel> ; data=<Data> ESC \
421+
ESC _ event=clipboard ; id=<ID> ; format=<ClipFormat> ; security=<SecLevel> ; data=<Data> ESC \
424422
```
425423

426424
Attribute | Description
427425
----------------------|------------
428-
`id=0` | Device group id.
426+
`id=<ID>` | Device group id (unsigned integer value).
429427
`format=<ClipFormat>` | Clipboard data format.
430428
`security=<SecLevel>` | Security level.
431429
`data=<Data>` | Base64 encoded data.

src/netxs/desktopio/ansivt.hpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,13 @@ namespace netxs::ansi
260260
static const auto paste_begin = "\033[200~"sv; // Bracketed paste begin.
261261
static const auto paste_end = "\033[201~"sv; // Bracketed paste end.
262262

263-
static constexpr auto apc_prefix_mouse = "event=mouse;"sv;
264-
static constexpr auto apc_prefix_mouse_id = "id="sv; // ui32
265-
static constexpr auto apc_prefix_mouse_kbmods = "kbmods="sv; // ui32
266-
static constexpr auto apc_prefix_mouse_coor = "coor="sv; // fp32,fp32
267-
static constexpr auto apc_prefix_mouse_buttons = "buttons="sv; // ui32
268-
static constexpr auto apc_prefix_mouse_scroll = "scroll="sv; // si32,si32
269-
static constexpr auto apc_prefix_mouse_finescroll = "finescroll="sv; // si32,si32
263+
static constexpr auto apc_prefix_mouse = "event=mouse;"sv;
264+
static constexpr auto apc_prefix_mouse_id = "id="sv; // ui32
265+
static constexpr auto apc_prefix_mouse_kbmods = "kbmods="sv; // ui32
266+
static constexpr auto apc_prefix_mouse_coor = "coor="sv; // fp32,fp32
267+
static constexpr auto apc_prefix_mouse_buttons = "buttons="sv; // ui32
268+
static constexpr auto apc_prefix_mouse_iscroll = "iscroll="sv; // si32,si32
269+
static constexpr auto apc_prefix_mouse_fscroll = "fscroll="sv; // fp32,fp32
270270

271271
template<class Base>
272272
class basevt
@@ -622,27 +622,31 @@ namespace netxs::ansi
622622
template<class T>
623623
auto& mouse_vtm(T const& gear, fp2d coor) // escx: Mouse tracking report (vt-input-mode).
624624
{
625-
// ESC _ event=mouse ; id=0 ; kbmods=<KeyMods> ; coor=<X>,<Y> ; buttons=<ButtonState> ; scroll=<DeltaX>,<DeltaY> ST
626-
auto wheelfp = netxs::saturate_cast<si32>(gear.m_sys.wheelfp * 120);
625+
// ESC _ event=mouse ; id=0 ; kbmods=<KeyMods> ; coor=<X>,<Y> ; buttons=<ButtonState> ; iscroll=<DeltaX>,<DeltaY> ; fscroll=<DeltaX>,<DeltaY> ST
627626
//todo make it fp2d
628-
auto v1 = gear.m_sys.wheelsi;
629-
auto h1 = 0;
630-
auto v2 = wheelfp;
631-
auto h2 = 0;
632627
auto x = ui32{};
633628
auto y = ui32{};
634629
::memcpy(&x, &coor.x, sizeof(x));
635630
::memcpy(&y, &coor.y, sizeof(y));
631+
auto iv = gear.m_sys.wheelsi;
632+
auto ih = 0;
633+
auto fh = ui32{};
634+
auto fv = ui32{};
635+
::memcpy(&fv, &gear.m_sys.wheelfp, sizeof(fv));
636636
if (gear.m_sys.hzwheel)
637637
{
638-
std::swap(h1, v1);
639-
std::swap(h2, v2);
638+
std::swap(ih, iv);
639+
std::swap(fh, fv);
640640
}
641641
add("\033_event=mouse;id=", gear.id, ";kbmods=", gear.m_sys.ctlstat, ";coor=");
642-
utf::_to_hex(netxs::letoh(x), 4 * 2, [&](char c){ add(c); });
642+
utf::_to_hex(x, 4 * 2, [&](char c){ add(c); });
643643
add(",");
644-
utf::_to_hex(netxs::letoh(y), 4 * 2, [&](char c){ add(c); });
645-
add(";buttons=", gear.m_sys.buttons, ";scroll=", h1, ",", v1, ";finescroll=", h2, ",", v2, "\033\\");
644+
utf::_to_hex(y, 4 * 2, [&](char c){ add(c); });
645+
add(";buttons=", gear.m_sys.buttons, ";iscroll=", ih, ",", iv, ";fscroll=");
646+
utf::_to_hex(fh, 4 * 2, [&](char c){ add(c); });
647+
add(",");
648+
utf::_to_hex(fv, 4 * 2, [&](char c){ add(c); });
649+
add("\033\\");
646650
return *this;
647651
}
648652
template<class T>

src/netxs/desktopio/application.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace netxs::app
2222

2323
namespace netxs::app::shared
2424
{
25-
static const auto version = "v2025.08.14";
25+
static const auto version = "v2025.08.15";
2626
static const auto repository = "https://github.com/directvt/vtm";
2727
static const auto usr_config = "~/.config/vtm/settings.xml"s;
2828
static const auto sys_config = "/etc/vtm/settings.xml"s;

src/netxs/desktopio/system.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5707,9 +5707,9 @@ namespace netxs::os
57075707
m.buttons = b.value();
57085708
}
57095709
}
5710-
else if (frag.starts_with(ansi::apc_prefix_mouse_scroll))
5710+
else if (frag.starts_with(ansi::apc_prefix_mouse_iscroll))
57115711
{
5712-
frag.remove_prefix(ansi::apc_prefix_mouse_scroll.size());
5712+
frag.remove_prefix(ansi::apc_prefix_mouse_iscroll.size());
57135713
if (auto h = utf::to_int<si32>(frag); h && frag)
57145714
{
57155715
frag.pop_front(); // Pop ','
@@ -5721,17 +5721,19 @@ namespace netxs::os
57215721
}
57225722
}
57235723
}
5724-
else if (frag.starts_with(ansi::apc_prefix_mouse_finescroll))
5724+
else if (frag.starts_with(ansi::apc_prefix_mouse_fscroll))
57255725
{
5726-
frag.remove_prefix(ansi::apc_prefix_mouse_finescroll.size());
5727-
if (auto h = utf::to_int<si32>(frag); h && frag)
5726+
frag.remove_prefix(ansi::apc_prefix_mouse_fscroll.size());
5727+
if (auto h = utf::to_int<ui32, 16>(frag); h && frag)
57285728
{
57295729
frag.pop_front(); // Pop ','
5730-
if (auto v = utf::to_int<si32>(frag))
5730+
if (auto v = utf::to_int<ui32, 16>(frag))
57315731
{
57325732
//todo make it fp2d
5733-
m.hzwheel = h.value() != 0;
5734-
m.wheelfp = (m.hzwheel ? h.value() : v.value()) / 120.0;
5733+
auto fh = *reinterpret_cast<fp32*>(&h.value());
5734+
auto fv = *reinterpret_cast<fp32*>(&v.value());
5735+
m.hzwheel = fh != 0;
5736+
m.wheelfp = m.hzwheel ? fh : fv;
57355737
}
57365738
}
57375739
}

0 commit comments

Comments
 (0)