mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-06-02 05:28:46 +03:00
c: fix enums for input
This commit is contained in:
@ -19,14 +19,6 @@ extern "C" {
|
||||
|
||||
#define GHOSTTY_SUCCESS 0
|
||||
|
||||
// Masks for input modifiers
|
||||
#define GHOSTTY_INPUT_SHIFT 1
|
||||
#define GHOSTTY_INPUT_CTRL 2
|
||||
#define GHOSTTY_INPUT_ALT 4
|
||||
#define GHOSTTY_INPUT_SUPER 8
|
||||
#define GHOSTTY_INPUT_CAPS 16
|
||||
#define GHOSTTY_INPUT_NUM 32
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Types
|
||||
|
||||
@ -45,140 +37,154 @@ typedef struct {
|
||||
double scale_factor;
|
||||
} ghostty_surface_config_s;
|
||||
|
||||
typedef enum { release, press, repeat } ghostty_input_action_e;
|
||||
typedef enum {
|
||||
invalid,
|
||||
GHOSTTY_MODS_NONE = 0,
|
||||
GHOSTTY_MODS_CTRL = 1 << 1,
|
||||
GHOSTTY_MODS_ALT = 1 << 2,
|
||||
GHOSTTY_MODS_SUPER = 1 << 3,
|
||||
GHOSTTY_MODS_CAPS = 1 << 4,
|
||||
GHOSTTY_MODS_NUM = 1 << 5,
|
||||
} ghostty_input_mods_e;
|
||||
|
||||
typedef enum {
|
||||
GHOSTTY_ACTION_RELEASE,
|
||||
GHOSTTY_ACTION_PRESS,
|
||||
GHOSTTY_ACTION_REPEAT,
|
||||
} ghostty_input_action_e;
|
||||
|
||||
typedef enum {
|
||||
GHOSTTY_KEY_INVALID,
|
||||
|
||||
// a-z
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
d,
|
||||
e,
|
||||
f,
|
||||
g,
|
||||
h,
|
||||
i,
|
||||
j,
|
||||
k,
|
||||
l,
|
||||
m,
|
||||
n,
|
||||
o,
|
||||
p,
|
||||
q,
|
||||
r,
|
||||
s,
|
||||
t,
|
||||
u,
|
||||
v,
|
||||
w,
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
GHOSTTY_KEY_A,
|
||||
GHOSTTY_KEY_B,
|
||||
GHOSTTY_KEY_C,
|
||||
GHOSTTY_KEY_D,
|
||||
GHOSTTY_KEY_E,
|
||||
GHOSTTY_KEY_F,
|
||||
GHOSTTY_KEY_G,
|
||||
GHOSTTY_KEY_H,
|
||||
GHOSTTY_KEY_I,
|
||||
GHOSTTY_KEY_J,
|
||||
GHOSTTY_KEY_K,
|
||||
GHOSTTY_KEY_L,
|
||||
GHOSTTY_KEY_M,
|
||||
GHOSTTY_KEY_N,
|
||||
GHOSTTY_KEY_O,
|
||||
GHOSTTY_KEY_P,
|
||||
GHOSTTY_KEY_Q,
|
||||
GHOSTTY_KEY_R,
|
||||
GHOSTTY_KEY_S,
|
||||
GHOSTTY_KEY_T,
|
||||
GHOSTTY_KEY_U,
|
||||
GHOSTTY_KEY_V,
|
||||
GHOSTTY_KEY_W,
|
||||
GHOSTTY_KEY_X,
|
||||
GHOSTTY_KEY_Y,
|
||||
GHOSTTY_KEY_Z,
|
||||
|
||||
// numbers
|
||||
zero,
|
||||
one,
|
||||
two,
|
||||
three,
|
||||
four,
|
||||
five,
|
||||
six,
|
||||
seven,
|
||||
eight,
|
||||
nine,
|
||||
GHOSTTY_KEY_ZERO,
|
||||
GHOSTTY_KEY_ONE,
|
||||
GHOSTTY_KEY_TWO,
|
||||
GHOSTTY_KEY_THREE,
|
||||
GHOSTTY_KEY_FOUR,
|
||||
GHOSTTY_KEY_FIVE,
|
||||
GHOSTTY_KEY_SIX,
|
||||
GHOSTTY_KEY_SEVEN,
|
||||
GHOSTTY_KEY_EIGHT,
|
||||
GHOSTTY_KEY_NINE,
|
||||
|
||||
// puncuation
|
||||
semicolon,
|
||||
space,
|
||||
apostrophe,
|
||||
comma,
|
||||
grave_accent, // `
|
||||
period,
|
||||
slash,
|
||||
minus,
|
||||
equal,
|
||||
left_bracket, // [
|
||||
right_bracket, // ]
|
||||
backslash, // /
|
||||
GHOSTTY_KEY_SEMICOLON,
|
||||
GHOSTTY_KEY_SPACE,
|
||||
GHOSTTY_KEY_APOSTROPHE,
|
||||
GHOSTTY_KEY_COMMA,
|
||||
GHOSTTY_KEY_GRAVE_ACCENT, // `
|
||||
GHOSTTY_KEY_PERIOD,
|
||||
GHOSTTY_KEY_SLASH,
|
||||
GHOSTTY_KEY_MINUS,
|
||||
GHOSTTY_KEY_EQUAL,
|
||||
GHOSTTY_KEY_LEFT_BRACKET, // [
|
||||
GHOSTTY_KEY_RIGHT_BRACKET, // ]
|
||||
GHOSTTY_KEY_BACKSLASH, // /
|
||||
|
||||
// control
|
||||
up,
|
||||
down,
|
||||
right,
|
||||
left,
|
||||
home,
|
||||
end,
|
||||
insert,
|
||||
delete,
|
||||
caps_lock,
|
||||
scroll_lock,
|
||||
num_lock,
|
||||
page_up,
|
||||
page_down,
|
||||
escape,
|
||||
enter,
|
||||
tab,
|
||||
backspace,
|
||||
print_screen,
|
||||
pause,
|
||||
GHOSTTY_KEY_UP,
|
||||
GHOSTTY_KEY_DOWN,
|
||||
GHOSTTY_KEY_RIGHT,
|
||||
GHOSTTY_KEY_LEFT,
|
||||
GHOSTTY_KEY_HOME,
|
||||
GHOSTTY_KEY_END,
|
||||
GHOSTTY_KEY_INSERT,
|
||||
GHOSTTY_KEY_DELETE,
|
||||
GHOSTTY_KEY_CAPS_LOCK,
|
||||
GHOSTTY_KEY_SCROLL_LOCK,
|
||||
GHOSTTY_KEY_NUM_LOCK,
|
||||
GHOSTTY_KEY_PAGE_UP,
|
||||
GHOSTTY_KEY_PAGE_DOWN,
|
||||
GHOSTTY_KEY_ESCAPE,
|
||||
GHOSTTY_KEY_ENTER,
|
||||
GHOSTTY_KEY_TAB,
|
||||
GHOSTTY_KEY_BACKSPACE,
|
||||
GHOSTTY_KEY_PRINT_SCREEN,
|
||||
GHOSTTY_KEY_PAUSE,
|
||||
|
||||
// function keys
|
||||
f1,
|
||||
f2,
|
||||
f3,
|
||||
f4,
|
||||
f5,
|
||||
f6,
|
||||
f7,
|
||||
f8,
|
||||
f9,
|
||||
f10,
|
||||
f11,
|
||||
f12,
|
||||
f13,
|
||||
f14,
|
||||
f15,
|
||||
f16,
|
||||
f17,
|
||||
f18,
|
||||
f19,
|
||||
f20,
|
||||
f21,
|
||||
f22,
|
||||
f23,
|
||||
f24,
|
||||
f25,
|
||||
GHOSTTY_KEY_F1,
|
||||
GHOSTTY_KEY_F2,
|
||||
GHOSTTY_KEY_F3,
|
||||
GHOSTTY_KEY_F4,
|
||||
GHOSTTY_KEY_F5,
|
||||
GHOSTTY_KEY_F6,
|
||||
GHOSTTY_KEY_F7,
|
||||
GHOSTTY_KEY_F8,
|
||||
GHOSTTY_KEY_F9,
|
||||
GHOSTTY_KEY_F10,
|
||||
GHOSTTY_KEY_F11,
|
||||
GHOSTTY_KEY_F12,
|
||||
GHOSTTY_KEY_F13,
|
||||
GHOSTTY_KEY_F14,
|
||||
GHOSTTY_KEY_F15,
|
||||
GHOSTTY_KEY_F16,
|
||||
GHOSTTY_KEY_F17,
|
||||
GHOSTTY_KEY_F18,
|
||||
GHOSTTY_KEY_F19,
|
||||
GHOSTTY_KEY_F20,
|
||||
GHOSTTY_KEY_F21,
|
||||
GHOSTTY_KEY_F22,
|
||||
GHOSTTY_KEY_F23,
|
||||
GHOSTTY_KEY_F24,
|
||||
GHOSTTY_KEY_F25,
|
||||
|
||||
// keypad
|
||||
kp_0,
|
||||
kp_1,
|
||||
kp_2,
|
||||
kp_3,
|
||||
kp_4,
|
||||
kp_5,
|
||||
kp_6,
|
||||
kp_7,
|
||||
kp_8,
|
||||
kp_9,
|
||||
kp_decimal,
|
||||
kp_divide,
|
||||
kp_multiply,
|
||||
kp_subtract,
|
||||
kp_add,
|
||||
kp_enter,
|
||||
kp_equal,
|
||||
GHOSTTY_KEY_KP_0,
|
||||
GHOSTTY_KEY_KP_1,
|
||||
GHOSTTY_KEY_KP_2,
|
||||
GHOSTTY_KEY_KP_3,
|
||||
GHOSTTY_KEY_KP_4,
|
||||
GHOSTTY_KEY_KP_5,
|
||||
GHOSTTY_KEY_KP_6,
|
||||
GHOSTTY_KEY_KP_7,
|
||||
GHOSTTY_KEY_KP_8,
|
||||
GHOSTTY_KEY_KP_9,
|
||||
GHOSTTY_KEY_KP_DECIMAL,
|
||||
GHOSTTY_KEY_KP_DIVIDE,
|
||||
GHOSTTY_KEY_KP_MULTIPLY,
|
||||
GHOSTTY_KEY_KP_SUBTRACT,
|
||||
GHOSTTY_KEY_KP_ADD,
|
||||
GHOSTTY_KEY_KP_ENTER,
|
||||
GHOSTTY_KEY_KP_EQUAL,
|
||||
|
||||
// modifiers
|
||||
left_shift,
|
||||
left_control,
|
||||
left_alt,
|
||||
left_super,
|
||||
right_shift,
|
||||
right_control,
|
||||
right_alt,
|
||||
right_super,
|
||||
GHOSTTY_KEY_LEFT_SHIFT,
|
||||
GHOSTTY_KEY_LEFT_CONTROL,
|
||||
GHOSTTY_KEY_LEFT_ALT,
|
||||
GHOSTTY_KEY_LEFT_SUPER,
|
||||
GHOSTTY_KEY_RIGHT_SHIFT,
|
||||
GHOSTTY_KEY_RIGHT_CONTROL,
|
||||
GHOSTTY_KEY_RIGHT_ALT,
|
||||
GHOSTTY_KEY_RIGHT_SUPER,
|
||||
} ghostty_input_key_e;
|
||||
|
||||
// Opaque types
|
||||
@ -205,7 +211,7 @@ void ghostty_surface_free(ghostty_surface_t);
|
||||
void ghostty_surface_refresh(ghostty_surface_t);
|
||||
void ghostty_surface_set_content_scale(ghostty_surface_t, double, double);
|
||||
void ghostty_surface_set_size(ghostty_surface_t, uint32_t, uint32_t);
|
||||
void ghostty_surface_key(ghostty_surface_t, ghostty_input_action_e, ghostty_input_key_e, uint8_t);
|
||||
void ghostty_surface_key(ghostty_surface_t, ghostty_input_action_e, ghostty_input_key_e, ghostty_input_mods_e);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ class TerminalSurfaceView_Real: NSView, ObservableObject {
|
||||
|
||||
if let surface = self.surface {
|
||||
if (event.keyCode == 36) {
|
||||
ghostty_surface_key(surface, press, enter, 0)
|
||||
ghostty_surface_key(surface, GHOSTTY_ACTION_PRESS, GHOSTTY_KEY_ENTER, GHOSTTY_MODS_NONE)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -419,8 +419,12 @@ pub const CAPI = struct {
|
||||
win: *Window,
|
||||
action: input.Action,
|
||||
key: input.Key,
|
||||
mods: input.Mods,
|
||||
mods: c_int,
|
||||
) void {
|
||||
win.window.keyCallback(action, key, mods);
|
||||
win.window.keyCallback(
|
||||
action,
|
||||
key,
|
||||
@bitCast(input.Mods, @truncate(u8, @bitCast(c_uint, mods))),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
@ -3,6 +3,8 @@ const Allocator = std.mem.Allocator;
|
||||
|
||||
/// A bitmask for all key modifiers. This is taken directly from the
|
||||
/// GLFW representation, but we use this generically.
|
||||
///
|
||||
/// IMPORTANT: Any changes here update include/ghostty.h
|
||||
pub const Mods = packed struct(u8) {
|
||||
shift: bool = false,
|
||||
ctrl: bool = false,
|
||||
@ -25,6 +27,8 @@ pub const Mods = packed struct(u8) {
|
||||
|
||||
/// The action associated with an input event. This is backed by a c_int
|
||||
/// so that we can use the enum as-is for our embedding API.
|
||||
///
|
||||
/// IMPORTANT: Any changes here update include/ghostty.h
|
||||
pub const Action = enum(c_int) {
|
||||
release,
|
||||
press,
|
||||
@ -38,6 +42,8 @@ pub const Action = enum(c_int) {
|
||||
/// unicode character is sent directly to the pty.
|
||||
///
|
||||
/// This is backed by a c_int so we can use this as-is for our embedding API.
|
||||
///
|
||||
/// IMPORTANT: Any changes here update include/ghostty.h
|
||||
pub const Key = enum(c_int) {
|
||||
invalid,
|
||||
|
||||
|
Reference in New Issue
Block a user