mirror of
https://codeberg.org/vyivel/dulcepan/
synced 2025-03-12 18:59:15 +02:00
Apply output scale correctly
This commit is contained in:
parent
218b498814
commit
e1424a42bb
@ -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,
|
||||
|
@ -47,6 +47,8 @@ struct dp_output {
|
||||
int effective_width, effective_height;
|
||||
bool initialized;
|
||||
|
||||
double scale;
|
||||
|
||||
struct wl_callback *redraw_callback;
|
||||
bool needs_redraw;
|
||||
|
||||
|
11
src/output.c
11
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);
|
||||
|
22
src/select.c
22
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user