mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-20 06:46:26 -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_FIX_POSITION] = "crosshair-fix-position",
|
||||||
[BIND_ACTION_CROSSHAIR_PIXEL_POSITION] = "crosshair-use-pixel-position",
|
[BIND_ACTION_CROSSHAIR_PIXEL_POSITION] = "crosshair-use-pixel-position",
|
||||||
[BIND_ACTION_CROSSHAIR_MOUSE_POSITION] = "crosshair-use-mouse-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_UP] = "font-increase",
|
||||||
[BIND_ACTION_FONT_SIZE_DOWN] = "font-decrease",
|
[BIND_ACTION_FONT_SIZE_DOWN] = "font-decrease",
|
||||||
[BIND_ACTION_FONT_SIZE_RESET] = "font-reset",
|
[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_FIX_POSITION, m_ctrl_shift, {{XKB_KEY_f}}},
|
||||||
{BIND_ACTION_CROSSHAIR_MOUSE_POSITION, m_ctrl_shift, {{XKB_KEY_m}}},
|
{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_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_plus}}},
|
||||||
{BIND_ACTION_FONT_SIZE_UP, m_ctrl, {{XKB_KEY_equal}}},
|
{BIND_ACTION_FONT_SIZE_UP, m_ctrl, {{XKB_KEY_equal}}},
|
||||||
{BIND_ACTION_FONT_SIZE_UP, m_ctrl, {{XKB_KEY_KP_Add}}},
|
{BIND_ACTION_FONT_SIZE_UP, m_ctrl, {{XKB_KEY_KP_Add}}},
|
||||||
|
|
|
||||||
6
config.h
6
config.h
|
|
@ -31,6 +31,12 @@ 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 {
|
struct config_font {
|
||||||
char *pattern;
|
char *pattern;
|
||||||
float pt_size;
|
float pt_size;
|
||||||
|
|
|
||||||
|
|
@ -948,6 +948,12 @@ e.g. *search-start=none*.
|
||||||
|
|
||||||
Default: _Control+Shift+p_.
|
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
|
# SECTION: search-bindings
|
||||||
|
|
||||||
This section lets you override the default key bindings used in
|
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;
|
term->crosshair.use_mouse_pixel_coordinates = !term->crosshair.use_mouse_pixel_coordinates;
|
||||||
return true;
|
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:
|
case BIND_ACTION_FONT_SIZE_UP:
|
||||||
term_font_size_increase(term);
|
term_font_size_increase(term);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ enum bind_action_normal {
|
||||||
BIND_ACTION_CROSSHAIR_MOUSE_POSITION,
|
BIND_ACTION_CROSSHAIR_MOUSE_POSITION,
|
||||||
BIND_ACTION_CROSSHAIR_FIX_POSITION,
|
BIND_ACTION_CROSSHAIR_FIX_POSITION,
|
||||||
BIND_ACTION_CROSSHAIR_PIXEL_POSITION,
|
BIND_ACTION_CROSSHAIR_PIXEL_POSITION,
|
||||||
|
BIND_ACTION_CROSSHAIR_STYLE,
|
||||||
BIND_ACTION_FONT_SIZE_UP,
|
BIND_ACTION_FONT_SIZE_UP,
|
||||||
BIND_ACTION_FONT_SIZE_DOWN,
|
BIND_ACTION_FONT_SIZE_DOWN,
|
||||||
BIND_ACTION_FONT_SIZE_RESET,
|
BIND_ACTION_FONT_SIZE_RESET,
|
||||||
|
|
|
||||||
40
render.c
40
render.c
|
|
@ -1746,12 +1746,13 @@ render_overlay(struct terminal *term)
|
||||||
damage_bounds = (pixman_box32_t){0, 0, buf->width, buf->height};
|
damage_bounds = (pixman_box32_t){0, 0, buf->width, buf->height};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (style == OVERLAY_CROSSHAIR) {
|
if (style == OVERLAY_CROSSHAIR) {
|
||||||
int cursor_row = term->grid->cursor.point.row;
|
int cursor_row = term->grid->cursor.point.row;
|
||||||
int cursor_col = term->grid->cursor.point.col;
|
int cursor_col = term->grid->cursor.point.col;
|
||||||
int mouse_x = 0;
|
int mouse_x = 0;
|
||||||
int mouse_y = 0;
|
int mouse_y = 0;
|
||||||
|
int y = 0;
|
||||||
|
int x = 0;
|
||||||
|
|
||||||
tll_foreach(term->wl->seats, it) {
|
tll_foreach(term->wl->seats, it) {
|
||||||
if (it->item.kbd_focus == term) {
|
if (it->item.kbd_focus == term) {
|
||||||
|
|
@ -1779,32 +1780,27 @@ render_overlay(struct terminal *term)
|
||||||
&(pixman_rectangle16_t){0, 0, term->width, term->height});
|
&(pixman_rectangle16_t){0, 0, term->width, term->height});
|
||||||
|
|
||||||
if (term->crosshair.use_mouse_pixel_coordinates == false) {
|
if (term->crosshair.use_mouse_pixel_coordinates == false) {
|
||||||
int y = term->margins.top + (cursor_row * term->cell_height) + term->cell_height;
|
y = min(term->margins.top + (cursor_row * term->cell_height) + term->cell_height,
|
||||||
int y2 = 1; // --FIXME-- maybe define crosshair thickness?
|
term->height - term->crosshair.width);
|
||||||
|
|
||||||
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} );
|
|
||||||
|
|
||||||
|
x = min(term->margins.left + (cursor_col * term->cell_width),
|
||||||
|
term->width - term->crosshair.width);
|
||||||
} else {
|
} else {
|
||||||
if (mouse_x > 0 || mouse_y > 0) {
|
y = max(min(mouse_y, term->height - term->crosshair.width), 1);
|
||||||
pixman_image_fill_rectangles(
|
x = max(min(mouse_x, term->width - term->crosshair.width), 1);
|
||||||
PIXMAN_OP_SRC, buf->pix[0], &color, 1,
|
}
|
||||||
&(pixman_rectangle16_t){term->margins.left, mouse_y, term->width, 1} );
|
|
||||||
|
|
||||||
|
if (term->crosshair.style == CROSSHAIR_FULL ||
|
||||||
|
term->crosshair.style == CROSSHAIR_HORIZONTAL)
|
||||||
pixman_image_fill_rectangles(
|
pixman_image_fill_rectangles(
|
||||||
PIXMAN_OP_SRC, buf->pix[0], &color, 1,
|
PIXMAN_OP_SRC, buf->pix[0], &color, 1,
|
||||||
&(pixman_rectangle16_t){mouse_x, term->margins.top, 1, term->height} );
|
&(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) {
|
if (term->crosshair.position_fixed == false) {
|
||||||
term->render.last_crosshair.row = cursor_row;
|
term->render.last_crosshair.row = cursor_row;
|
||||||
|
|
|
||||||
|
|
@ -1217,6 +1217,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
||||||
.crosshair.position_fixed = false,
|
.crosshair.position_fixed = false,
|
||||||
.crosshair.use_mouse_position = false,
|
.crosshair.use_mouse_position = false,
|
||||||
.crosshair.use_mouse_pixel_coordinates = false,
|
.crosshair.use_mouse_pixel_coordinates = false,
|
||||||
|
.crosshair.width = 1,
|
||||||
|
.crosshair.style = CROSSHAIR_FULL,
|
||||||
.tab_stops = tll_init(),
|
.tab_stops = tll_init(),
|
||||||
.wl = wayl,
|
.wl = wayl,
|
||||||
.render = {
|
.render = {
|
||||||
|
|
@ -1973,6 +1975,8 @@ term_reset(struct terminal *term, bool hard)
|
||||||
term->crosshair.position_fixed = false;
|
term->crosshair.position_fixed = false;
|
||||||
term->crosshair.use_mouse_position = false;
|
term->crosshair.use_mouse_position = false;
|
||||||
term->crosshair.use_mouse_pixel_coordinates = 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->normal.scroll_damage);
|
||||||
tll_free(term->alt.scroll_damage);
|
tll_free(term->alt.scroll_damage);
|
||||||
|
|
|
||||||
|
|
@ -564,10 +564,12 @@ struct terminal {
|
||||||
} search;
|
} search;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
int width;
|
||||||
bool active;
|
bool active;
|
||||||
bool position_fixed;
|
bool position_fixed;
|
||||||
bool use_mouse_position;
|
bool use_mouse_position;
|
||||||
bool use_mouse_pixel_coordinates;
|
bool use_mouse_pixel_coordinates;
|
||||||
|
enum crosshair_style style;
|
||||||
} crosshair;
|
} crosshair;
|
||||||
|
|
||||||
struct wayland *wl;
|
struct wayland *wl;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue