mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
main: initialize scale to '1'
This ensures we always have a valid (but possibly incorrect) scaling value. This allows us to simplify code that uses the scale - it doesn't have to verify the scale if valid. Furthermore, since render_resize() is the function that actually updates term->scale, make sure to call it *before* updating the cursor (otherwise, the cursor will use the old scaling value).
This commit is contained in:
parent
7323f18859
commit
2d6369482e
3 changed files with 7 additions and 22 deletions
5
input.c
5
input.c
|
|
@ -404,9 +404,8 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
|
|||
{
|
||||
struct terminal *term = data;
|
||||
|
||||
const int scale = term->scale >= 1 ? term->scale : 1;
|
||||
int x = wl_fixed_to_int(surface_x) * scale;
|
||||
int y = wl_fixed_to_int(surface_y) * scale;
|
||||
int x = wl_fixed_to_int(surface_x) * term->scale;
|
||||
int y = wl_fixed_to_int(surface_y) * term->scale;
|
||||
|
||||
int col = (x - term->x_margin) / term->cell_width;
|
||||
int row = (y - term->y_margin) / term->cell_height;
|
||||
|
|
|
|||
10
main.c
10
main.c
|
|
@ -138,9 +138,8 @@ output_scale(void *data, struct wl_output *wl_output, int32_t factor)
|
|||
struct monitor *mon = data;
|
||||
mon->scale = factor;
|
||||
|
||||
int old_scale = mon->term->scale >= 1 ? mon->term->scale : 1;
|
||||
render_resize(mon->term, mon->term->width / mon->term->scale, mon->term->height / mon->term->scale);
|
||||
render_reload_cursor_theme(mon->term);
|
||||
render_resize(mon->term, mon->term->width / old_scale, mon->term->height / old_scale);
|
||||
}
|
||||
|
||||
static const struct wl_output_listener output_listener = {
|
||||
|
|
@ -280,9 +279,8 @@ surface_enter(void *data, struct wl_surface *wl_surface,
|
|||
tll_push_back(term->wl.on_outputs, &it->item);
|
||||
|
||||
/* Resize, since scale-to-use may have changed */
|
||||
int scale = term->scale >= 1 ? term->scale : 1;
|
||||
render_resize(term, term->width / term->scale, term->height / term->scale);
|
||||
render_reload_cursor_theme(term);
|
||||
render_resize(term, term->width / scale, term->height / scale);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -303,9 +301,8 @@ surface_leave(void *data, struct wl_surface *wl_surface,
|
|||
tll_remove(term->wl.on_outputs, it);
|
||||
|
||||
/* Resize, since scale-to-use may have changed */
|
||||
int scale = term->scale >= 1 ? term->scale : 1;
|
||||
render_resize(term, term->width / term->scale, term->height / term->scale);
|
||||
render_reload_cursor_theme(term);
|
||||
render_resize(term, term->width / scale, term->height / scale);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -502,6 +499,7 @@ main(int argc, char *const *argv)
|
|||
.keypad_keys_mode = KEYPAD_NUMERICAL,
|
||||
.auto_margin = true,
|
||||
.window_title_stack = tll_init(),
|
||||
.scale = 1,
|
||||
.flash = {
|
||||
.fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC | TFD_NONBLOCK),
|
||||
},
|
||||
|
|
|
|||
14
render.c
14
render.c
|
|
@ -931,18 +931,6 @@ render_reload_cursor_theme(struct terminal *term)
|
|||
if (term->wl.pointer.size == 0)
|
||||
return true;
|
||||
|
||||
int scale = -1;
|
||||
tll_foreach(term->wl.on_outputs, it) {
|
||||
if (it->item->scale > scale)
|
||||
scale = it->item->scale;
|
||||
}
|
||||
|
||||
if (scale == -1) {
|
||||
/* Haven't 'entered' an output yet? */
|
||||
LOG_WARN("unknown scale, using '1'");
|
||||
scale = 1;
|
||||
}
|
||||
|
||||
if (term->wl.pointer.theme != NULL) {
|
||||
wl_cursor_theme_destroy(term->wl.pointer.theme);
|
||||
term->wl.pointer.theme = NULL;
|
||||
|
|
@ -953,7 +941,7 @@ render_reload_cursor_theme(struct terminal *term)
|
|||
term->wl.pointer.theme_name, term->wl.pointer.size);
|
||||
|
||||
term->wl.pointer.theme = wl_cursor_theme_load(
|
||||
term->wl.pointer.theme_name, term->wl.pointer.size * scale, term->wl.shm);
|
||||
term->wl.pointer.theme_name, term->wl.pointer.size * term->scale, term->wl.shm);
|
||||
if (term->wl.pointer.theme == NULL) {
|
||||
LOG_ERR("failed to load cursor theme");
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue