mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-16 08:21:20 -04:00
Crosshair coredump fix. Crosshair styles.
Fixed possibilities for coredumps when having a fixed cross hair and modifying the window size to the extend the crosshair would now be out of the window boundaries. Implemented a Crosshair style switch from Full Cross to Vertical Line to Horizontal Line.
This commit is contained in:
parent
c742f640af
commit
9a3ac3a406
8 changed files with 63 additions and 26 deletions
2
config.c
2
config.c
|
|
@ -105,6 +105,7 @@ static const char *const binding_action_map[] = {
|
|||
[BIND_ACTION_CROSSHAIR_FIX_POSITION] = "crosshair-fix-position",
|
||||
[BIND_ACTION_CROSSHAIR_PIXEL_POSITION] = "crosshair-use-pixel-position",
|
||||
[BIND_ACTION_CROSSHAIR_MOUSE_POSITION] = "crosshair-use-mouse-position",
|
||||
[BIND_ACTION_CROSSHAIR_STYLE] = "crosshair-style",
|
||||
[BIND_ACTION_FONT_SIZE_UP] = "font-increase",
|
||||
[BIND_ACTION_FONT_SIZE_DOWN] = "font-decrease",
|
||||
[BIND_ACTION_FONT_SIZE_RESET] = "font-reset",
|
||||
|
|
@ -2868,6 +2869,7 @@ add_default_key_bindings(struct config *conf)
|
|||
{BIND_ACTION_CROSSHAIR_FIX_POSITION, m_ctrl_shift, {{XKB_KEY_f}}},
|
||||
{BIND_ACTION_CROSSHAIR_MOUSE_POSITION, m_ctrl_shift, {{XKB_KEY_m}}},
|
||||
{BIND_ACTION_CROSSHAIR_PIXEL_POSITION, m_ctrl_shift, {{XKB_KEY_p}}},
|
||||
{BIND_ACTION_CROSSHAIR_STYLE, m_ctrl_shift, {{XKB_KEY_s}}},
|
||||
{BIND_ACTION_FONT_SIZE_UP, m_ctrl, {{XKB_KEY_plus}}},
|
||||
{BIND_ACTION_FONT_SIZE_UP, m_ctrl, {{XKB_KEY_equal}}},
|
||||
{BIND_ACTION_FONT_SIZE_UP, m_ctrl, {{XKB_KEY_KP_Add}}},
|
||||
|
|
|
|||
8
config.h
8
config.h
|
|
@ -29,7 +29,13 @@ struct font_size_adjustment {
|
|||
|
||||
enum cursor_style { CURSOR_BLOCK, CURSOR_UNDERLINE, CURSOR_BEAM };
|
||||
|
||||
enum conf_size_type {CONF_SIZE_PX, CONF_SIZE_CELLS};
|
||||
enum conf_size_type { CONF_SIZE_PX, CONF_SIZE_CELLS };
|
||||
|
||||
enum crosshair_style {
|
||||
CROSSHAIR_FULL,
|
||||
CROSSHAIR_HORIZONTAL,
|
||||
CROSSHAIR_VERTICAL
|
||||
};
|
||||
|
||||
struct config_font {
|
||||
char *pattern;
|
||||
|
|
|
|||
|
|
@ -948,6 +948,12 @@ e.g. *search-start=none*.
|
|||
|
||||
Default: _Control+Shift+p_.
|
||||
|
||||
*crosshair-style*
|
||||
A toggle to switch the style from full cross to vertical line to
|
||||
horizontal line and back to full cross.
|
||||
|
||||
Default: _Control+Shfit+s_.
|
||||
|
||||
# SECTION: search-bindings
|
||||
|
||||
This section lets you override the default key bindings used in
|
||||
|
|
|
|||
20
input.c
20
input.c
|
|
@ -202,6 +202,26 @@ execute_binding(struct seat *seat, struct terminal *term,
|
|||
term->crosshair.use_mouse_pixel_coordinates = !term->crosshair.use_mouse_pixel_coordinates;
|
||||
return true;
|
||||
|
||||
case BIND_ACTION_CROSSHAIR_STYLE:
|
||||
switch (term->crosshair.style) {
|
||||
case CROSSHAIR_FULL:
|
||||
term->crosshair.style = CROSSHAIR_VERTICAL;
|
||||
break;
|
||||
|
||||
case CROSSHAIR_VERTICAL:
|
||||
term->crosshair.style = CROSSHAIR_HORIZONTAL;
|
||||
break;
|
||||
|
||||
case CROSSHAIR_HORIZONTAL:
|
||||
term->crosshair.style = CROSSHAIR_FULL;
|
||||
break;
|
||||
|
||||
default:
|
||||
BUG("Unhandled crosshair style");
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
|
||||
case BIND_ACTION_FONT_SIZE_UP:
|
||||
term_font_size_increase(term);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ enum bind_action_normal {
|
|||
BIND_ACTION_CROSSHAIR_MOUSE_POSITION,
|
||||
BIND_ACTION_CROSSHAIR_FIX_POSITION,
|
||||
BIND_ACTION_CROSSHAIR_PIXEL_POSITION,
|
||||
BIND_ACTION_CROSSHAIR_STYLE,
|
||||
BIND_ACTION_FONT_SIZE_UP,
|
||||
BIND_ACTION_FONT_SIZE_DOWN,
|
||||
BIND_ACTION_FONT_SIZE_RESET,
|
||||
|
|
|
|||
46
render.c
46
render.c
|
|
@ -1746,17 +1746,18 @@ render_overlay(struct terminal *term)
|
|||
damage_bounds = (pixman_box32_t){0, 0, buf->width, buf->height};
|
||||
}
|
||||
|
||||
|
||||
if (style == OVERLAY_CROSSHAIR) {
|
||||
int cursor_row = term->grid->cursor.point.row;
|
||||
int cursor_col = term->grid->cursor.point.col;
|
||||
int mouse_x = 0;
|
||||
int mouse_y = 0;
|
||||
int y = 0;
|
||||
int x = 0;
|
||||
|
||||
tll_foreach(term->wl->seats, it) {
|
||||
if (it->item.kbd_focus == term) {
|
||||
if (it->item.pointer.hidden == 0 &&
|
||||
term->crosshair.use_mouse_position == true) {
|
||||
term->crosshair.use_mouse_position == true) {
|
||||
|
||||
cursor_row = it->item.mouse.row > 0 ? it->item.mouse.row : 0;
|
||||
cursor_col = it->item.mouse.col > 0 ? it->item.mouse.col : 0;
|
||||
|
|
@ -1779,33 +1780,28 @@ render_overlay(struct terminal *term)
|
|||
&(pixman_rectangle16_t){0, 0, term->width, term->height});
|
||||
|
||||
if (term->crosshair.use_mouse_pixel_coordinates == false) {
|
||||
int y = term->margins.top + (cursor_row * term->cell_height) + term->cell_height;
|
||||
int y2 = 1; // --FIXME-- maybe define crosshair thickness?
|
||||
|
||||
if (y + y2 > term->height)
|
||||
y = term->height - 1;
|
||||
|
||||
pixman_image_fill_rectangles(
|
||||
PIXMAN_OP_SRC, buf->pix[0], &color, 1,
|
||||
&(pixman_rectangle16_t){term->margins.left, y, term->width, y2} );
|
||||
|
||||
pixman_image_fill_rectangles(
|
||||
PIXMAN_OP_SRC, buf->pix[0], &color, 1,
|
||||
&(pixman_rectangle16_t){term->margins.left + (cursor_col * term->cell_width),
|
||||
term->margins.top, 1, term->height} );
|
||||
y = min(term->margins.top + (cursor_row * term->cell_height) + term->cell_height,
|
||||
term->height - term->crosshair.width);
|
||||
|
||||
x = min(term->margins.left + (cursor_col * term->cell_width),
|
||||
term->width - term->crosshair.width);
|
||||
} else {
|
||||
if (mouse_x > 0 || mouse_y > 0) {
|
||||
pixman_image_fill_rectangles(
|
||||
PIXMAN_OP_SRC, buf->pix[0], &color, 1,
|
||||
&(pixman_rectangle16_t){term->margins.left, mouse_y, term->width, 1} );
|
||||
|
||||
pixman_image_fill_rectangles(
|
||||
PIXMAN_OP_SRC, buf->pix[0], &color, 1,
|
||||
&(pixman_rectangle16_t){mouse_x, term->margins.top, 1, term->height} );
|
||||
}
|
||||
y = max(min(mouse_y, term->height - term->crosshair.width), 1);
|
||||
x = max(min(mouse_x, term->width - term->crosshair.width), 1);
|
||||
}
|
||||
|
||||
if (term->crosshair.style == CROSSHAIR_FULL ||
|
||||
term->crosshair.style == CROSSHAIR_HORIZONTAL)
|
||||
pixman_image_fill_rectangles(
|
||||
PIXMAN_OP_SRC, buf->pix[0], &color, 1,
|
||||
&(pixman_rectangle16_t){term->margins.left, y, term->width, term->crosshair.width});
|
||||
|
||||
if (term->crosshair.style == CROSSHAIR_FULL ||
|
||||
term->crosshair.style == CROSSHAIR_VERTICAL)
|
||||
pixman_image_fill_rectangles(
|
||||
PIXMAN_OP_SRC, buf->pix[0], &color, 1,
|
||||
&(pixman_rectangle16_t){x, term->margins.top, term->crosshair.width, term->height});
|
||||
|
||||
if (term->crosshair.position_fixed == false) {
|
||||
term->render.last_crosshair.row = cursor_row;
|
||||
term->render.last_crosshair.col = cursor_col;
|
||||
|
|
|
|||
|
|
@ -1217,6 +1217,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
|||
.crosshair.position_fixed = false,
|
||||
.crosshair.use_mouse_position = false,
|
||||
.crosshair.use_mouse_pixel_coordinates = false,
|
||||
.crosshair.width = 1,
|
||||
.crosshair.style = CROSSHAIR_FULL,
|
||||
.tab_stops = tll_init(),
|
||||
.wl = wayl,
|
||||
.render = {
|
||||
|
|
@ -1973,6 +1975,8 @@ term_reset(struct terminal *term, bool hard)
|
|||
term->crosshair.position_fixed = false;
|
||||
term->crosshair.use_mouse_position = false;
|
||||
term->crosshair.use_mouse_pixel_coordinates = false;
|
||||
term->crosshair.width = 1;
|
||||
term->crosshair.style = CROSSHAIR_FULL;
|
||||
|
||||
tll_free(term->normal.scroll_damage);
|
||||
tll_free(term->alt.scroll_damage);
|
||||
|
|
|
|||
|
|
@ -564,10 +564,12 @@ struct terminal {
|
|||
} search;
|
||||
|
||||
struct {
|
||||
int width;
|
||||
bool active;
|
||||
bool position_fixed;
|
||||
bool use_mouse_position;
|
||||
bool use_mouse_pixel_coordinates;
|
||||
enum crosshair_style style;
|
||||
} crosshair;
|
||||
|
||||
struct wayland *wl;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue