This cleanup a bit how we store and use the preferred_scale and
preferred_fractional_scale.

This rename some methods to make their behavior more explicit.
This commit is contained in:
Willow Barraco 2023-09-18 11:59:33 +02:00
parent 63c209ec7f
commit 02027621af
No known key found for this signature in database
GPG Key ID: EABA44759877E02A
2 changed files with 23 additions and 17 deletions

View File

@ -96,7 +96,8 @@ struct kbd {
bool print; bool print;
bool print_intersect; bool print_intersect;
uint32_t w, h; uint32_t w, h;
double scale, pending_scale; double scale;
double preferred_scale, preferred_fractional_scale;
bool landscape; bool landscape;
uint8_t mods; uint8_t mods;
uint8_t compose; uint8_t compose;

37
main.c
View File

@ -123,7 +123,7 @@ static void layer_surface_configure(void *data,
uint32_t serial, uint32_t w, uint32_t h); uint32_t serial, uint32_t w, uint32_t h);
static void layer_surface_closed(void *data, static void layer_surface_closed(void *data,
struct zwlr_layer_surface_v1 *surface); struct zwlr_layer_surface_v1 *surface);
static void resize(); static void flip_landscape();
/* event handlers */ /* event handlers */
static const struct wl_pointer_listener pointer_listener = { static const struct wl_pointer_listener pointer_listener = {
@ -345,7 +345,9 @@ wl_surface_enter(void *data, struct wl_surface *wl_surface,
} }
} }
resize(); keyboard.preferred_scale = current_output->scale;
flip_landscape();
} }
static void static void
@ -366,7 +368,7 @@ display_handle_geometry(void *data, struct wl_output *wl_output, int x, int y,
output->h = physical_height; output->h = physical_height;
if (current_output == output) { if (current_output == output) {
resize(); flip_landscape();
}; };
} }
@ -382,7 +384,8 @@ display_handle_scale(void *data, struct wl_output *wl_output, int32_t scale)
output->scale = scale; output->scale = scale;
if (current_output == output) { if (current_output == output) {
resize(); keyboard.preferred_scale = scale;
flip_landscape();
}; };
} }
@ -497,20 +500,20 @@ static const struct xdg_popup_listener xdg_popup_listener = {
}; };
static void static void
wp_fractional_scale_prefered_scale( wp_fractional_scale_preferred_scale(
void *data, struct wp_fractional_scale_v1 *wp_fractional_scale_v1, void *data, struct wp_fractional_scale_v1 *wp_fractional_scale_v1,
uint32_t scale) uint32_t scale)
{ {
keyboard.pending_scale = (double)scale / 120; keyboard.preferred_fractional_scale = (double)scale / 120;
} }
static const struct wp_fractional_scale_v1_listener static const struct wp_fractional_scale_v1_listener
wp_fractional_scale_listener = { wp_fractional_scale_listener = {
.preferred_scale = wp_fractional_scale_prefered_scale, .preferred_scale = wp_fractional_scale_preferred_scale,
}; };
void void
resize() flip_landscape()
{ {
keyboard.landscape = current_output->w > current_output->h; keyboard.landscape = current_output->w > current_output->h;
@ -529,10 +532,6 @@ resize()
keyboard.last_abc_layout = keyboard.layout; keyboard.last_abc_layout = keyboard.layout;
keyboard.last_abc_index = 0; keyboard.last_abc_index = 0;
if (!wfs_mgr || !viewporter) {
keyboard.pending_scale = current_output->scale;
}
if (layer_surface) { if (layer_surface) {
zwlr_layer_surface_v1_set_size(layer_surface, 0, height); zwlr_layer_surface_v1_set_size(layer_surface, 0, height);
zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, height); zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, height);
@ -544,12 +543,17 @@ void
layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface, layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface,
uint32_t serial, uint32_t w, uint32_t h) uint32_t serial, uint32_t w, uint32_t h)
{ {
if (keyboard.w != w || keyboard.h != h || double scale = keyboard.preferred_scale;
keyboard.scale != keyboard.pending_scale || hidden) { if (keyboard.preferred_fractional_scale) {
scale = keyboard.preferred_fractional_scale;
}
if (keyboard.w != w || keyboard.h != h || keyboard.scale != scale ||
hidden) {
keyboard.w = w; keyboard.w = w;
keyboard.h = h; keyboard.h = h;
keyboard.scale = keyboard.pending_scale; keyboard.scale = scale;
hidden = false; hidden = false;
if (wfs_mgr && viewporter) { if (wfs_mgr && viewporter) {
@ -762,7 +766,8 @@ main(int argc, char **argv)
keyboard.scheme = scheme; keyboard.scheme = scheme;
keyboard.layer_index = 0; keyboard.layer_index = 0;
keyboard.scheme1 = scheme1; keyboard.scheme1 = scheme1;
keyboard.pending_scale = 1; keyboard.preferred_scale = 0;
keyboard.preferred_fractional_scale = 0;
uint8_t alpha = 0; uint8_t alpha = 0;
bool alpha_defined = false; bool alpha_defined = false;