Skip to content

Commit

Permalink
Merge branch 'prompt-click-events' of https://github.com/pianohacker/…
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Sep 6, 2024
2 parents cda0237 + b8f28d7 commit bfbffc3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
14 changes: 13 additions & 1 deletion kitty/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,19 @@ move_cursor_to_mouse_if_at_shell_prompt(Window *w) {
Screen *screen = w->render_data.screen;
int y = screen_cursor_at_a_shell_prompt(screen);
if (y < 0 || (unsigned)y > w->mouse_pos.cell_y) return false;
return screen_fake_move_cursor_to_position(screen, w->mouse_pos.cell_x, w->mouse_pos.cell_y);

if (screen_prompt_supports_click_events(screen)) {
int sz = encode_mouse_event_impl(&w->mouse_pos, SGR_PROTOCOL, 1, PRESS, 0);
if (sz > 0) {
mouse_event_buf[sz] = 0;
write_escape_code_to_child(screen, ESC_CSI, mouse_event_buf);
return true;
}

return false;
} else {
return screen_fake_move_cursor_to_position(screen, w->mouse_pos.cell_x, w->mouse_pos.cell_y);
}
}


Expand Down
6 changes: 6 additions & 0 deletions kitty/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,11 @@ screen_cursor_at_a_shell_prompt(const Screen *self) {
return -1;
}

bool
screen_prompt_supports_click_events(const Screen *self) {
return (bool) self->prompt_settings.supports_click_events;
}

bool
screen_fake_move_cursor_to_position(Screen *self, index_type start_x, index_type start_y) {
SelectionBoundary a = {.x=start_x, .y=start_y}, b = {.x=self->cursor->x, .y=self->cursor->y};
Expand Down Expand Up @@ -2308,6 +2313,7 @@ parse_prompt_mark(Screen *self, char *buf, PromptKind *pk) {
if (strcmp(token, "k=s") == 0) *pk = SECONDARY_PROMPT;
else if (strcmp(token, "redraw=0") == 0) self->prompt_settings.redraws_prompts_at_all = 0;
else if (strcmp(token, "special_key=1") == 0) self->prompt_settings.uses_special_keys_for_cursor_movement = 1;
else if (strcmp(token, "click_events=1") == 0) self->prompt_settings.supports_click_events = 1;
}
}

Expand Down
2 changes: 2 additions & 0 deletions kitty/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ typedef struct {
struct {
unsigned int redraws_prompts_at_all: 1;
unsigned int uses_special_keys_for_cursor_movement: 1;
unsigned int supports_click_events: 1;
};
unsigned int val;
} prompt_settings;
Expand Down Expand Up @@ -274,6 +275,7 @@ uint8_t screen_current_key_encoding_flags(Screen *self);
void screen_report_key_encoding_flags(Screen *self);
int screen_detect_url(Screen *screen, unsigned int x, unsigned int y);
int screen_cursor_at_a_shell_prompt(const Screen *);
bool screen_prompt_supports_click_events(const Screen *);
bool screen_fake_move_cursor_to_position(Screen *, index_type x, index_type y);
bool screen_send_signal_for_key(Screen *, char key);
bool get_line_edge_colors(Screen *self, color_type *left, color_type *right);
Expand Down

0 comments on commit bfbffc3

Please sign in to comment.