ttx 0.1.0
Loading...
Searching...
No Matches
mouse_event_io.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/reflect/prelude.h"
4#include "ttx/key_event_io.h"
5#include "ttx/mouse.h"
6#include "ttx/mouse_event.h"
7#include "ttx/params.h"
8#include "ttx/size.h"
9
10// Mouse reference: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking
11namespace ttx {
12// Alternate scroll mode - when enabled, scroll events are reported using cursor up/down
13// escape sequences. This only applies when the alternate screen buffer is active.
18
19constexpr auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<AlternateScrollMode>) {
20 using enum AlternateScrollMode;
21 return di::make_enumerators<"AlternateScrollMode">(di::enumerator<"Disabled", Disabled>,
22 di::enumerator<"Enabled", Enabled>);
23}
24
25// Shift escape options - depending on the mode, the terminal will not forward mouse events
26// with shift held to the application.
28 OverrideApplication, // Application mouse mode is ignored when shift is held.
29 ConditionallyForward, // We treat this as always forwarding to the application.
30 AlwaysForward, // Exists for compatibility with xterm, treated the same as conditional.
31 NeverForward, // Exists for compatibility with xterm, treated the same as override.
32};
33
34constexpr auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<ShiftEscapeOptions>) {
35 using enum ShiftEscapeOptions;
36 return di::make_enumerators<"ShiftEscapeOptions">(di::enumerator<"OverrideApplication", OverrideApplication>,
37 di::enumerator<"ConditionallyForward", ConditionallyForward>,
38 di::enumerator<"AlwaysForward", AlwaysForward>,
39 di::enumerator<"NeverForward", NeverForward>);
40}
41
42// Mouse protocol - determines which mouse events are forwarded to the application.
43// The enum values are determined by the terminal mode which enables them.
44enum class MouseProtocol {
45 None = 0,
46 X10 = 9,
47 VT200 = 1000,
48 BtnEvent = 1002,
49 AnyEvent = 1003,
50};
51
52constexpr auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<MouseProtocol>) {
53 using enum MouseProtocol;
54 return di::make_enumerators<"MouseProtocol">(di::enumerator<"None", None>, di::enumerator<"X10", X10>,
55 di::enumerator<"VT200", VT200>, di::enumerator<"BtnEvent", BtnEvent>,
56 di::enumerator<"AnyEvent", AnyEvent>);
57}
58
59// Mouse encoding - determines the bytes sent to the application when an event is forwarded.
60// The enum values are determined by the terminal mode which enables them.
61enum class MouseEncoding {
62 X10 = 9,
63 UTF8 = 1005,
64 SGR = 1006,
65 URXVT = 1015,
66 SGRPixels = 1016,
67};
68
69constexpr auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<MouseEncoding>) {
70 using enum MouseEncoding;
71 return di::make_enumerators<"MouseEncoding">(di::enumerator<"X10", X10>, di::enumerator<"UTF8", UTF8>,
72 di::enumerator<"SGR", SGR>, di::enumerator<"URXVT", URXVT>,
73 di::enumerator<"SGRPixels", SGRPixels>);
74}
75
76// Mouse scroll protocol - controls how the vertical scroll buttons are sent in cases
77// where mouse reporting otherwise wouldn't happen.
83
84auto serialize_mouse_event(MouseEvent const& event, MouseProtocol protocol, MouseEncoding encoding,
85 di::Optional<MousePosition> prev_event_position, MouseScrollProtocol const& scroll_protocol,
86 ShiftEscapeOptions shift_escape_options, Size const& size)
87 -> di::Optional<di::TransparentString>;
88auto mouse_event_from_csi(CSI const& csi, di::Optional<Size const&> size_if_using_pixels = {})
89 -> di::Optional<MouseEvent>;
90}
Definition clipboard.h:10
ShiftEscapeOptions
Definition mouse_event_io.h:27
@ OverrideApplication
Definition mouse_event_io.h:28
@ NeverForward
Definition mouse_event_io.h:31
@ AlwaysForward
Definition mouse_event_io.h:30
@ ConditionallyForward
Definition mouse_event_io.h:29
MouseEncoding
Definition mouse_event_io.h:61
@ SGRPixels
Definition mouse_event_io.h:66
@ SGR
Definition mouse_event_io.h:64
@ URXVT
Definition mouse_event_io.h:65
@ UTF8
Definition mouse_event_io.h:63
AlternateScrollMode
Definition mouse_event_io.h:14
@ Disabled
Definition mouse_event_io.h:15
@ None
Definition direction.h:8
constexpr auto tag_invoke(di::Tag< di::reflect >, di::InPlaceType< ClipboardMode >)
Definition clipboard.h:21
auto mouse_event_from_csi(CSI const &csi, di::Optional< Size const & > size_if_using_pixels={}) -> di::Optional< MouseEvent >
Definition mouse_event_io.cpp:227
MouseProtocol
Definition mouse_event_io.h:44
@ AnyEvent
Definition mouse_event_io.h:49
@ BtnEvent
Definition mouse_event_io.h:48
@ X10
Definition mouse_event_io.h:46
@ VT200
Definition mouse_event_io.h:47
auto serialize_mouse_event(MouseEvent const &event, MouseProtocol protocol, MouseEncoding encoding, di::Optional< MousePosition > prev_event_position, MouseScrollProtocol const &scroll_protocol, ShiftEscapeOptions shift_escape_options, Size const &size) -> di::Optional< di::TransparentString >
Definition mouse_event_io.cpp:140
ApplicationCursorKeysMode
Definition key_event_io.h:14
@ Disabled
Definition key_event_io.h:15
@ Disabled
Disallow read/writing the clipboard.
Definition clipboard.h:18
@ Enabled
Definition focus_event_io.h:12
Definition mouse_event_io.h:78
AlternateScrollMode alternate_scroll_mode
Definition mouse_event_io.h:79
bool in_alternate_screen_buffer
Definition mouse_event_io.h:81
ApplicationCursorKeysMode application_cursor_keys_mode
Definition mouse_event_io.h:80