Skip to content

Commit 2442eda

Browse files
authored
Merge pull request #787 from o-sdn-o/gui-bridge
Input event reporting (fine scrolling)
2 parents c98cf6c + 00e583a commit 2442eda

File tree

9 files changed

+297
-50
lines changed

9 files changed

+297
-50
lines changed

doc/settings.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ Standard object names
583583
| | | `vtm.gate.AntialiasingMode() -> int` | Toggle anti-aliasing mode.
584584
|`applet` | Running applet | `vtm.applet.Warp(int l, int r, int t, int b)` | Request to deform the applet window. The parameters specify four deltas for the left, right, top and bottom sides of the applet window.
585585
| | | `vtm.applet.ZOrder() -> int` | Request the current z-order state of the applet window.
586-
| | | `vtm.applet.ZOrder(int n) -> int` | Set the current z-order state for the applet window. -1: backmost; 0: plain; 1: topmost.
586+
| | | `vtm.applet.ZOrder(int n) -> int` | Set the current z-order state for the applet window. -1: backmost; 0: normal; 1: topmost.
587587
| | | `vtm.applet.Close()` | Close applet window.
588588
| | | `vtm.applet.Minimize()` | Minimize applet window.
589589
| | | `vtm.applet.Maximize()` | Maximize applet window.
@@ -645,6 +645,8 @@ Standard object names
645645
| | | `vtm.terminal.ClearScrollback()` | Clear the terminal scrollback buffer.
646646
| | | `vtm.terminal.ScrollbackSize() -> int n, m, q` | Get the current scrollback buffer parameters (three integer values):<br>`n` Initial buffer size<br>`m` Grow step<br>`q` Grow limit
647647
| | | `vtm.terminal.ScrollbackSize(int n, int m, int q)` | Set scrollback buffer parameters:<br>`n` Initial buffer size<br>`m` Grow step<br>`q` Grow limit
648+
| | | `vtm.terminal.EventReporting(string args, ...)` | Enable event reporting for the specified sources:<br>`"keyboard"` Keyboard events<br>`"mouse"` Mouse events<br>`"focus"` Focus events<br>`"format"` Line format events<br>`"clipoard"` Clipboard events<br>`"window"` Window size and selection events<br>`"system"` System signals<br>`""` Switch event reporting off
649+
| | | `vtm.terminal.EventReporting()` | Get a list of active event sources.
648650
| | | `vtm.terminal.Restart()` | Restart the current terminal session.
649651
| | | `vtm.terminal.Quit()` | Close terminal.
650652

doc/vt-input-mode.md

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,43 @@ Existing approaches have the following drawbacks:
3333

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

38-
### Format
38+
## Event tracking activation
39+
40+
Event tracking is activated by sending an APC vt-sequence to the terminal with a script to switch the event tracking mode.
41+
42+
The following APC sequences set/reset/request event tracking for the specified event `"Source"`s:
43+
44+
- Set:
45+
```
46+
ESC _ vtm.terminal.EventReporting("Source0", ..., "SourceN") ESC \
47+
```
48+
- Reset (the event tracking is deactivated if an empty string is specified.):
49+
```
50+
ESC _ vtm.terminal.EventReporting("") ESC \
51+
```
52+
- Get a list of active sources:
53+
```
54+
ESC _ src_list=vtm.terminal.EventReporting() ESC \
55+
```
56+
57+
Sources | Events to track
58+
-------------|----------------
59+
`"keyboard"` | Keyboard.
60+
`"mouse"` | Mouse.
61+
`"focus"` | Focus.
62+
`"format"` | Line format.
63+
`"clipboard"`| Clipboard.
64+
`"window"` | Window size and selection.
65+
`"system"` | System signals.
66+
`""` | Empty string to set all event reporting off.
67+
68+
/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).
3969

40-
Signaling uses APC `ESC _ <payload> ESC \` with an event-specific payload syntax.
70+
### Event format
71+
72+
The event signaling also uses APC `ESC _ <payload> ESC \` with an event-specific payload syntax.
4173

4274
The payload consists of a list of attributes in the following format:
4375
```
@@ -49,27 +81,6 @@ Field | Descriprtion
4981
`<attr>` | Attribute name.
5082
`<val>,...,<val>` | Comma-separated value list.
5183

52-
## Initialization
53-
54-
```
55-
Set: ESC _ events=<Source0>,...,<SourceN> ESC \
56-
Reset: ESC _ events ESC \
57-
```
58-
59-
Source | Events to track
60-
-----------|----------------
61-
`keyboard` | Keyboard.
62-
`mouse` | Mouse.
63-
`focus` | Focus.
64-
`format` | Line format.
65-
`clipoard` | Clipboard.
66-
`window` | Window size and selection.
67-
`system` | System signals.
68-
69-
This sequence enables `vt-input-mode` and event tracking for the specified event `Source`s. The `vt-input-mode` is deactivated if none of the `Source`s is specified.
70-
71-
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).
72-
7384
## Events
7485

7586
- Keyboard
@@ -78,7 +89,7 @@ Note: By enabling `vt-input-mode`, all current terminal modes are automatically
7889
```
7990
- Mouse
8091
```
81-
ESC _ event=mouse ; id=0 ; kbmods=<KeyMods> ; coord=<X>,<Y> ; buttons=<ButtonState> ; scroll=<DeltaX>,<DeltaY> ESC \
92+
ESC _ event=mouse ; id=0 ; kbmods=<KeyMods> ; coor=<X>,<Y> ; buttons=<ButtonState> ; scroll=<DeltaX>,<DeltaY> ; finescroll=<DeltaX>,<DeltaY> ESC \
8293
```
8394
- Focus
8495
```
@@ -91,7 +102,7 @@ Note: By enabling `vt-input-mode`, all current terminal modes are automatically
91102
//todo Textinput, Text, IME or Input for IME preview etc
92103
- Clipboard
93104
```
94-
ESC _ event=clipoard ; id=0 ; format=<ClipFormat> ; security=<SecLevel> ; data=<Data> ESC \
105+
ESC _ event=clipboard ; id=0 ; format=<ClipFormat> ; security=<SecLevel> ; data=<Data> ESC \
95106
```
96107
- Window
97108
```
@@ -112,7 +123,7 @@ ESC _ event=keyboard ; id=0 ; kbmods=<KeyMods> ; keyid=<KeyId> ; pressed=<KeyDow
112123
113124
Attribute | Description
114125
------------------------------|------------
115-
`id=0` | Seat id.
126+
`id=0` | Device group id.
116127
`kbmods=<KeyMods>` | Keyboard modifiers.
117128
`keyid=<KeyId>` | Physical key ID.
118129
`pressed=<KeyDown>` | Key state:<br>\<KeyDown\>=1 - Pressed.<br>\<KeyDown\>=0 - Released.
@@ -351,21 +362,17 @@ Key ID | Name | Generic Name | Scan Code | Notes
351362
### Mouse
352363

353364
```
354-
ESC _ event=mouse ; id=0 ; kbmods=<KeyMods> ; coord=<X>,<Y> ; buttons=<ButtonState> ; scroll=<DeltaX>,<DeltaY> ESC \
365+
ESC _ event=mouse ; id=0 ; kbmods=<KeyMods> ; coor=<X>,<Y> ; buttons=<ButtonState> ; scroll=<DeltaX>,<DeltaY> finescroll=<DeltaX>,<DeltaY> ESC \
355366
```
356367

357-
Attribute | Description
358-
----------------------------|------------
359-
`id=0` | Seat id.
360-
`kbmods=<KeyMods>` | Keyboard modifiers (see Keyboard event).
361-
`coord=<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)`.
362-
`buttons=<ButtonState>` | Mouse button state.
363-
`scroll=<DeltaX>,<DeltaY>` | Integer value of high resolution horizontal and vertical scroll delta in integer 1/120 units.
364-
365-
In response to the activation of `mouse` tracking, the application receives a vt-sequence containing current mouse state:
366-
```
367-
ESC _ event=mouse ; kbmods=<KeyMods> ; coord=<X>,<Y> ; buttons=<ButtonState> ESC \
368-
```
368+
Attribute | Description
369+
--------------------------------|------------
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).
369376

370377
The mouse tracking event fires on any mouse activity, as well as on keyboard modifier changes.
371378

@@ -391,7 +398,7 @@ ESC _ event=focus ; id=0 ; state=<FocusState> ESC \
391398

392399
Attribute | Description
393400
---------------------|------------
394-
`id=0` | Seat id.
401+
`id=0` | Device group id.
395402
`state=<FocusState>` | Terminal window focus:<br>\<FocusState\>=1 - Focused.<br>\<FocusState\>=0 - Unfocused.
396403

397404
In response to the activation of `focus` tracking, the application receives a vt-sequence containing current focus state.
@@ -413,12 +420,12 @@ In response to the activation of `format` tracking, the application receives a v
413420
### Clipboard
414421

415422
```
416-
ESC _ event=clipoard ; id=0 ; format=<ClipFormat> ; security=<SecLevel> ; data=<Data> ESC \
423+
ESC _ event=clipboard ; id=0 ; format=<ClipFormat> ; security=<SecLevel> ; data=<Data> ESC \
417424
```
418425

419426
Attribute | Description
420427
----------------------|------------
421-
`id=0` | Seat id.
428+
`id=0` | Device group id.
422429
`format=<ClipFormat>` | Clipboard data format.
423430
`security=<SecLevel>` | Security level.
424431
`data=<Data>` | Base64 encoded data.

src/netxs/desktopio/ansivt.hpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,14 @@ 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
270+
263271
template<class Base>
264272
class basevt
265273
{
@@ -541,8 +549,8 @@ namespace netxs::ansi
541549
}
542550
auto& vmouse(bool b) // escx: Focus and Mouse position reporting/tracking.
543551
{
544-
return add(b ? "\033[?1002;1003;1004;1006;10060h"
545-
: "\033[?1002;1003;1004;1006;10060l");
552+
return add(b ? "\033[?1002;1003;1004;1006;10060h\033_vtm.terminal.EventReporting('mouse')\033\\"
553+
: "\033[?1002;1003;1004;1006;10060l\033_vtm.terminal.EventReporting('')\033\\");
546554
}
547555
auto& setutf(bool b) { return add(b ? "\033%G" : "\033%@" ); } // escx: Select UTF-8 character set (true) or default (faux). Not supported by Apple Terminal on macOS.
548556
auto& altbuf(bool b) { return add(b ? "\033[?1049h" : "\033[?1049l" ); } // escx: Alternative buffer.
@@ -612,6 +620,32 @@ namespace netxs::ansi
612620
return *this;
613621
}
614622
template<class T>
623+
auto& mouse_vtm(T const& gear, fp2d coor) // escx: Mouse tracking report (vt-input-mode).
624+
{
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);
627+
//todo make it fp2d
628+
auto v1 = gear.m_sys.wheelsi;
629+
auto h1 = 0;
630+
auto v2 = wheelfp;
631+
auto h2 = 0;
632+
auto x = ui32{};
633+
auto y = ui32{};
634+
::memcpy(&x, &coor.x, sizeof(x));
635+
::memcpy(&y, &coor.y, sizeof(y));
636+
if (gear.m_sys.hzwheel)
637+
{
638+
std::swap(h1, v1);
639+
std::swap(h2, v2);
640+
}
641+
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); });
643+
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\\");
646+
return *this;
647+
}
648+
template<class T>
615649
auto& mouse_sgr(T const& gear, fp2d coor) // escx: Mouse tracking report (SGR).
616650
{
617651
if (std::isnan(coor.x)) return *this;

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.13";
25+
static const auto version = "v2025.08.14";
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/controls.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,17 @@ namespace netxs::events
282282
::lua_settop(lua, 0);
283283
(push_value(args), ...);
284284
}
285+
void luna::set_return_array(txts const& str_list)
286+
{
287+
::lua_settop(lua, 0);
288+
::lua_createtable(lua, 0, 0);
289+
auto i = 0;
290+
for (auto& s : str_list)
291+
{
292+
::lua_pushlstring(lua, s.data(), s.size());
293+
::lua_rawseti(lua, -2, ++i);
294+
}
295+
}
285296
si32 luna::args_count()
286297
{
287298
return ::lua_gettop(lua);

src/netxs/desktopio/events.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ namespace netxs::events
157157
static si32 vtmlua_push_value( lua_State* lua, auto&& v);
158158
si32 push_value(auto&& v);
159159
void set_return(auto... args);
160+
void set_return_array(txts const& str_list);
160161
si32 args_count();
161162
void read_args(si32 index, auto add_item);
162163
auto get_args_or(si32 idx, auto fallback = {});

src/netxs/desktopio/input.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,16 +752,19 @@ namespace netxs::input
752752
move = 1 << 2,
753753
over = 1 << 3,
754754
utf8 = 1 << 4,
755+
vtim = 1 << 5, // vt-input-mode
755756
buttons_press = bttn,
756757
buttons_drags = bttn | drag,
757758
all_movements = bttn | drag | move,
758759
negative_args = bttn | drag | move | over,
760+
vt_input_mode = bttn | drag | move | over | vtim,
759761
};
760762
enum prot
761763
{
762764
x11,
763765
sgr,
764766
w32,
767+
//vtm, // vt-input-mode
765768
};
766769
struct buttons
767770
{

0 commit comments

Comments
 (0)