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 "dius/tty.h"
5#include "ttx/key_event_io.h"
6#include "ttx/mouse.h"
7#include "ttx/mouse_event.h"
8#include "ttx/params.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// Mouse protocol - determines which mouse events are forwarded to the application.
26// The enum values are determined by the terminal mode which enables them.
27enum class MouseProtocol {
28 None = 0,
29 X10 = 9,
30 VT200 = 1000,
31 BtnEvent = 1002,
32 AnyEvent = 1003,
33};
34
35constexpr auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<MouseProtocol>) {
36 using enum MouseProtocol;
37 return di::make_enumerators<"MouseProtocol">(di::enumerator<"None", None>, di::enumerator<"X10", X10>,
38 di::enumerator<"VT200", VT200>, di::enumerator<"BtnEvent", BtnEvent>,
39 di::enumerator<"AnyEvent", AnyEvent>);
40}
41
42// Mouse encoding - determines the bytes sent to the application when an event is forwarded.
43// The enum values are determined by the terminal mode which enables them.
44enum class MouseEncoding {
45 X10 = 9,
46 UTF8 = 1005,
47 SGR = 1006,
48 URXVT = 1015,
49 SGRPixels = 1016,
50};
51
52constexpr auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<MouseEncoding>) {
53 using enum MouseEncoding;
54 return di::make_enumerators<"MouseEncoding">(di::enumerator<"X10", X10>, di::enumerator<"UTF8", UTF8>,
55 di::enumerator<"SGR", SGR>, di::enumerator<"URXVT", URXVT>,
56 di::enumerator<"SGRPixels", SGRPixels>);
57}
58
59// Mouse scroll protocol - controls how the vertical scroll buttons are sent in cases
60// where mouse reporting otherwise wouldn't happen.
66
67auto serialize_mouse_event(MouseEvent const& event, MouseProtocol protocol, MouseEncoding encoding,
68 di::Optional<MousePosition> prev_event_position, MouseScrollProtocol const& scroll_protocol,
69 dius::tty::WindowSize const& window_size) -> di::Optional<di::TransparentString>;
70auto mouse_event_from_csi(CSI const& csi, di::Optional<dius::tty::WindowSize> window_size_if_using_pixels = {})
71 -> di::Optional<MouseEvent>;
72}
Definition cursor_style.h:5
MouseEncoding
Definition mouse_event_io.h:44
@ SGRPixels
Definition mouse_event_io.h:49
@ SGR
Definition mouse_event_io.h:47
@ URXVT
Definition mouse_event_io.h:48
@ UTF8
Definition mouse_event_io.h:46
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< CursorStyle >)
Definition cursor_style.h:16
MouseProtocol
Definition mouse_event_io.h:27
@ AnyEvent
Definition mouse_event_io.h:32
@ BtnEvent
Definition mouse_event_io.h:31
@ X10
Definition mouse_event_io.h:29
@ VT200
Definition mouse_event_io.h:30
auto serialize_mouse_event(MouseEvent const &event, MouseProtocol protocol, MouseEncoding encoding, di::Optional< MousePosition > prev_event_position, MouseScrollProtocol const &scroll_protocol, dius::tty::WindowSize const &window_size) -> di::Optional< di::TransparentString >
Definition mouse_event_io.cpp:139
ApplicationCursorKeysMode
Definition key_event_io.h:14
@ Disabled
Definition key_event_io.h:15
auto mouse_event_from_csi(CSI const &csi, di::Optional< dius::tty::WindowSize > window_size_if_using_pixels={}) -> di::Optional< MouseEvent >
Definition mouse_event_io.cpp:219
@ Enabled
Definition focus_event_io.h:12
@ Disabled
Definition focus_event_io.h:11
Definition mouse_event_io.h:61
AlternateScrollMode alternate_scroll_mode
Definition mouse_event_io.h:62
bool in_alternate_screen_buffer
Definition mouse_event_io.h:64
ApplicationCursorKeysMode application_cursor_keys_mode
Definition mouse_event_io.h:63