| 1 | /** |
| 2 | * @file point.h |
| 3 | * |
| 4 | * Terminal point types for referencing locations in the terminal grid. |
| 5 | */ |
| 6 | |
| 7 | #ifndef GHOSTTY_VT_POINT_H |
| 8 | #define GHOSTTY_VT_POINT_H |
| 9 | |
| 10 | #include <stdint.h> |
| 11 | |
| 12 | #ifdef __cplusplus |
| 13 | extern "C" { |
| 14 | #endif |
| 15 | |
| 16 | /** @defgroup point Point |
| 17 | * |
| 18 | * Types for referencing x/y positions in the terminal grid under |
| 19 | * different coordinate systems (active area, viewport, full screen, |
| 20 | * scrollback history). |
| 21 | * |
| 22 | * @{ |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | * A coordinate in the terminal grid. |
| 27 | * |
| 28 | * @ingroup point |
| 29 | */ |
| 30 | typedef struct { |
| 31 | /** Column (0-indexed). */ |
| 32 | uint16_t x; |
| 33 | |
| 34 | /** Row (0-indexed). May exceed page size for screen/history tags. */ |
| 35 | uint32_t y; |
| 36 | } GhosttyPointCoordinate; |
| 37 | |
| 38 | /** |
| 39 | * Point reference tag. |
| 40 | * |
| 41 | * Determines which coordinate system a point uses. |
| 42 | * |
| 43 | * @ingroup point |
| 44 | */ |
| 45 | typedef enum GHOSTTY_ENUM_TYPED { |
| 46 | /** Active area where the cursor can move. */ |
| 47 | GHOSTTY_POINT_TAG_ACTIVE = 0, |
| 48 | |
| 49 | /** Visible viewport (changes when scrolled). */ |
| 50 | GHOSTTY_POINT_TAG_VIEWPORT = 1, |
| 51 | |
| 52 | /** Full screen including scrollback. */ |
| 53 | GHOSTTY_POINT_TAG_SCREEN = 2, |
| 54 | |
| 55 | /** Scrollback history only (before active area). */ |
| 56 | GHOSTTY_POINT_TAG_HISTORY = 3, |
| 57 | GHOSTTY_POINT_TAG_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE, |
| 58 | } GhosttyPointTag; |
| 59 | |
| 60 | /** |
| 61 | * Point value union. |
| 62 | * |
| 63 | * @ingroup point |
| 64 | */ |
| 65 | typedef union { |
| 66 | /** Coordinate (used for all tag variants). */ |
| 67 | GhosttyPointCoordinate coordinate; |
| 68 | |
| 69 | /** Padding for ABI compatibility. Do not use. */ |
| 70 | uint64_t _padding[2]; |
| 71 | } GhosttyPointValue; |
| 72 | |
| 73 | /** |
| 74 | * Tagged union for a point in the terminal grid. |
| 75 | * |
| 76 | * @ingroup point |
| 77 | */ |
| 78 | typedef struct { |
| 79 | GhosttyPointTag tag; |
| 80 | GhosttyPointValue value; |
| 81 | } GhosttyPoint; |
| 82 | |
| 83 | /** @} */ |
| 84 | |
| 85 | #ifdef __cplusplus |
| 86 | } |
| 87 | #endif |
| 88 | |
| 89 | #endif /* GHOSTTY_VT_POINT_H */ |