From e1424a42bb3d30abf83725ec3da1a4d044af0ba0 Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Mon, 24 Jun 2024 13:48:05 +0300 Subject: [PATCH] Apply output scale correctly --- meson.build | 3 +++ src/dulcepan.h | 2 ++ src/output.c | 11 +++++++---- src/select.c | 22 ++++++++++++---------- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/meson.build b/meson.build index 1f49cfe..1615107 100644 --- a/meson.build +++ b/meson.build @@ -40,6 +40,8 @@ add_project_arguments(cc.get_supported_arguments([ '-DDP_BIG_ENDIAN=@0@'.format(big_endian.to_int()), ]), language: 'c') +m = cc.find_library('m') + wayland_client = dependency('wayland-client') wayland_protos = dependency('wayland-protocols') @@ -75,6 +77,7 @@ executable( src, dependencies: [ client_protos, + m, wayland_client, cairo, pixman, diff --git a/src/dulcepan.h b/src/dulcepan.h index 24fa65e..5b72ef0 100644 --- a/src/dulcepan.h +++ b/src/dulcepan.h @@ -47,6 +47,8 @@ struct dp_output { int effective_width, effective_height; bool initialized; + double scale; + struct wl_callback *redraw_callback; bool needs_redraw; diff --git a/src/output.c b/src/output.c index a68bf5d..fa1dcef 100644 --- a/src/output.c +++ b/src/output.c @@ -43,6 +43,8 @@ static void layer_surface_handle_configure(void *data, struct zwlr_layer_surface output->effective_width = (int)width; output->effective_height = (int)height; + output->scale = (double)output->transformed_width / output->effective_width; + wp_viewport_set_destination( output->main_viewport, output->effective_width, output->effective_height); wp_viewport_set_destination( @@ -276,10 +278,11 @@ static void redraw(struct dp_output *output) { if (output == selection->output) { int border_size = config->border_size; if (border_size != 0) { - cairo_set_line_width(buffer->cairo, border_size); - double off = border_size / 2.0; + double scaled_size = border_size * output->scale; + cairo_set_line_width(buffer->cairo, scaled_size); + double off = scaled_size / 2.0; cairo_rectangle(buffer->cairo, selection->x - off, selection->y - off, - selection->width + border_size, selection->height + border_size); + selection->width + scaled_size, selection->height + scaled_size); set_cairo_color(buffer->cairo, config->border_color); cairo_stroke(buffer->cairo); } @@ -292,7 +295,7 @@ static void redraw(struct dp_output *output) { wl_surface_attach(output->select_surface, buffer->wl_buffer, 0, 0); wl_surface_damage( - output->select_surface, 0, 0, output->transformed_width, output->transformed_height); + output->select_surface, 0, 0, output->effective_width, output->effective_height); output->redraw_callback = wl_surface_frame(output->select_surface); wl_callback_add_listener(output->redraw_callback, &redraw_callback_listener, output); diff --git a/src/select.c b/src/select.c index 60d5771..9c098cf 100644 --- a/src/select.c +++ b/src/select.c @@ -25,24 +25,26 @@ static void update_action(struct dp_selection *selection, struct dp_output *outp int sx = x - selection->x; int sy = y - selection->y; - if (sx >= RESIZE_INNER_SIZE && sy >= RESIZE_INNER_SIZE && - sx < selection->width - RESIZE_INNER_SIZE && - sy <= selection->height - RESIZE_INNER_SIZE) { + int inner = (int)ceil(RESIZE_INNER_SIZE * output->scale); + int outer = (int)ceil(RESIZE_OUTER_SIZE * output->scale); + int threshold = (int)ceil(RESIZE_THRESHOLD * output->scale); + + if (sx >= inner && sy >= inner && sx < selection->width - inner && + sy <= selection->height - inner) { selection->action = DP_SELECTION_ACTION_MOVING; return; - } else if (sx >= -RESIZE_OUTER_SIZE && sy >= -RESIZE_OUTER_SIZE && - sx < selection->width + RESIZE_OUTER_SIZE && - sy < selection->height + RESIZE_OUTER_SIZE) { + } else if (sx >= -outer && sy >= -outer && sx < selection->width + outer && + sy < selection->height + outer) { int edges = DP_EDGE_NONE; - if (sx >= selection->width - RESIZE_THRESHOLD && sx >= selection->width / 2) { + if (sx >= selection->width - threshold && sx >= selection->width / 2) { edges |= DP_EDGE_RIGHT; - } else if (sx < RESIZE_THRESHOLD) { + } else if (sx < threshold) { edges |= DP_EDGE_LEFT; } - if (sy >= selection->height - RESIZE_THRESHOLD && sy >= selection->height / 2) { + if (sy >= selection->height - threshold && sy >= selection->height / 2) { edges |= DP_EDGE_BOTTOM; - } else if (sy < RESIZE_THRESHOLD) { + } else if (sy < threshold) { edges |= DP_EDGE_TOP; }