mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-03 12:28:13 +08:00
Pre-C23, the C standard allows compilers to choose any integer type that can represent all enum values, so small enums could be backed by char or short. This breaks ABI compatibility with the Zig side, which backs these enums with c_int. Define GHOSTTY_ENUM_MAX_VALUE as INT_MAX in types.h and add it as the last entry in every enum in include/ghostty/vt/. This forces the compiler to use int as the backing type, matching c_int on all targets. INT_MAX is used rather than a fixed constant because enum constants must be representable as int; values above INT_MAX are a constraint violation in standard C. Document this convention in AGENTS.md.
90 lines
1.6 KiB
C
90 lines
1.6 KiB
C
/**
|
|
* @file point.h
|
|
*
|
|
* Terminal point types for referencing locations in the terminal grid.
|
|
*/
|
|
|
|
#ifndef GHOSTTY_VT_POINT_H
|
|
#define GHOSTTY_VT_POINT_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/** @defgroup point Point
|
|
*
|
|
* Types for referencing x/y positions in the terminal grid under
|
|
* different coordinate systems (active area, viewport, full screen,
|
|
* scrollback history).
|
|
*
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* A coordinate in the terminal grid.
|
|
*
|
|
* @ingroup point
|
|
*/
|
|
typedef struct {
|
|
/** Column (0-indexed). */
|
|
uint16_t x;
|
|
|
|
/** Row (0-indexed). May exceed page size for screen/history tags. */
|
|
uint32_t y;
|
|
} GhosttyPointCoordinate;
|
|
|
|
/**
|
|
* Point reference tag.
|
|
*
|
|
* Determines which coordinate system a point uses.
|
|
*
|
|
* @ingroup point
|
|
*/
|
|
typedef enum {
|
|
/** Active area where the cursor can move. */
|
|
GHOSTTY_POINT_TAG_ACTIVE = 0,
|
|
|
|
/** Visible viewport (changes when scrolled). */
|
|
GHOSTTY_POINT_TAG_VIEWPORT = 1,
|
|
|
|
/** Full screen including scrollback. */
|
|
GHOSTTY_POINT_TAG_SCREEN = 2,
|
|
|
|
/** Scrollback history only (before active area). */
|
|
GHOSTTY_POINT_TAG_HISTORY = 3,
|
|
GHOSTTY_POINT_TAG_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
|
|
} GhosttyPointTag;
|
|
|
|
/**
|
|
* Point value union.
|
|
*
|
|
* @ingroup point
|
|
*/
|
|
typedef union {
|
|
/** Coordinate (used for all tag variants). */
|
|
GhosttyPointCoordinate coordinate;
|
|
|
|
/** Padding for ABI compatibility. Do not use. */
|
|
uint64_t _padding[2];
|
|
} GhosttyPointValue;
|
|
|
|
/**
|
|
* Tagged union for a point in the terminal grid.
|
|
*
|
|
* @ingroup point
|
|
*/
|
|
typedef struct {
|
|
GhosttyPointTag tag;
|
|
GhosttyPointValue value;
|
|
} GhosttyPoint;
|
|
|
|
/** @} */
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* GHOSTTY_VT_POINT_H */
|