mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-21 06:46:46 -04:00
MR 3421 change: remove scale param, always scale to dst width or height
This commit is contained in:
parent
ebae11dd32
commit
23f73e3331
3 changed files with 31 additions and 88 deletions
|
|
@ -27,9 +27,7 @@ static const char usage[] =
|
||||||
"usage: mirror <src> <dst>\n"
|
"usage: mirror <src> <dst>\n"
|
||||||
" e.g. mirror eDP-1 HDMI-A-1\n"
|
" e.g. mirror eDP-1 HDMI-A-1\n"
|
||||||
"keys:\n"
|
"keys:\n"
|
||||||
" a: WLR_MIRROR_SCALE_ASPECT\n"
|
" m: toggle mirroring\n"
|
||||||
" f: WLR_MIRROR_SCALE_FULL\n"
|
|
||||||
" c: WLR_MIRROR_SCALE_CENTER\n"
|
|
||||||
" esc: exit\n";
|
" esc: exit\n";
|
||||||
|
|
||||||
struct sample_state {
|
struct sample_state {
|
||||||
|
|
@ -88,7 +86,7 @@ struct sample_keyboard {
|
||||||
struct wl_listener destroy;
|
struct wl_listener destroy;
|
||||||
};
|
};
|
||||||
|
|
||||||
void start_mirror(struct sample_state *state, enum wlr_mirror_scale scale);
|
void start_mirror(struct sample_state *state);
|
||||||
void end_mirror(struct sample_state *state);
|
void end_mirror(struct sample_state *state);
|
||||||
void handle_mirror_ready(struct wl_listener *listener, void *data);
|
void handle_mirror_ready(struct wl_listener *listener, void *data);
|
||||||
void handle_mirror_destroy(struct wl_listener *listener, void *data);
|
void handle_mirror_destroy(struct wl_listener *listener, void *data);
|
||||||
|
|
@ -104,7 +102,7 @@ void handle_keyboard_destroy(struct wl_listener *listener, void *data);
|
||||||
void render_rects(struct wlr_renderer *renderer, struct sample_output *output, float colour[]);
|
void render_rects(struct wlr_renderer *renderer, struct sample_output *output, float colour[]);
|
||||||
|
|
||||||
// start a mirror session
|
// start a mirror session
|
||||||
void start_mirror(struct sample_state *state, enum wlr_mirror_scale scale) {
|
void start_mirror(struct sample_state *state) {
|
||||||
struct sample_output *output_src = state->output_src;
|
struct sample_output *output_src = state->output_src;
|
||||||
struct sample_output *output_dst = state->output_dst;
|
struct sample_output *output_dst = state->output_dst;
|
||||||
if (!output_src || !output_dst) {
|
if (!output_src || !output_dst) {
|
||||||
|
|
@ -124,7 +122,6 @@ void start_mirror(struct sample_state *state, enum wlr_mirror_scale scale) {
|
||||||
mirror->dy = 1;
|
mirror->dy = 1;
|
||||||
|
|
||||||
// params immutable over the session
|
// params immutable over the session
|
||||||
mirror->params.scale = scale;
|
|
||||||
mirror->params.overlay_cursor = true;
|
mirror->params.overlay_cursor = true;
|
||||||
mirror->params.output_dst = state->output_dst->wlr_output;
|
mirror->params.output_dst = state->output_dst->wlr_output;
|
||||||
|
|
||||||
|
|
@ -300,8 +297,6 @@ void handle_keyboard_key(struct wl_listener *listener, void *data) {
|
||||||
uint32_t keycode = event->keycode + 8;
|
uint32_t keycode = event->keycode + 8;
|
||||||
const xkb_keysym_t *syms;
|
const xkb_keysym_t *syms;
|
||||||
int nsyms = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state, keycode, &syms);
|
int nsyms = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state, keycode, &syms);
|
||||||
bool start_end_mirror = false;
|
|
||||||
enum wlr_mirror_scale scale;
|
|
||||||
|
|
||||||
for (int i = 0; i < nsyms; i++) {
|
for (int i = 0; i < nsyms; i++) {
|
||||||
xkb_keysym_t sym = syms[i];
|
xkb_keysym_t sym = syms[i];
|
||||||
|
|
@ -310,31 +305,18 @@ void handle_keyboard_key(struct wl_listener *listener, void *data) {
|
||||||
case XKB_KEY_Escape:
|
case XKB_KEY_Escape:
|
||||||
wl_display_terminate(state->display);
|
wl_display_terminate(state->display);
|
||||||
break;
|
break;
|
||||||
case XKB_KEY_f:
|
case XKB_KEY_m:
|
||||||
scale = WLR_MIRROR_SCALE_FULL;
|
if (state->mirror) {
|
||||||
start_end_mirror = true;
|
end_mirror(state);
|
||||||
break;
|
} else {
|
||||||
case XKB_KEY_a:
|
start_mirror(state);
|
||||||
scale = WLR_MIRROR_SCALE_ASPECT;
|
}
|
||||||
start_end_mirror = true;
|
|
||||||
break;
|
|
||||||
case XKB_KEY_c:
|
|
||||||
scale = WLR_MIRROR_SCALE_CENTER;
|
|
||||||
start_end_mirror = true;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start_end_mirror) {
|
|
||||||
if (state->mirror) {
|
|
||||||
end_mirror(state);
|
|
||||||
} else {
|
|
||||||
start_mirror(state, scale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_output_destroy(struct wl_listener *listener, void *data) {
|
void handle_output_destroy(struct wl_listener *listener, void *data) {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
* Allows mirroring: rendering some contents of one output (the src) on another
|
* Allows mirroring: rendering some contents of one output (the src) on another
|
||||||
* output (the dst). dst is fixed for the duration of the session, src may vary.
|
* output (the dst). dst is fixed for the duration of the session, src may vary.
|
||||||
*
|
*
|
||||||
|
* Content will be scaled to fit the width or height of dst.
|
||||||
|
*
|
||||||
* On output_srcs precommit, wlr_mirror::ready is emitted. The compositor may
|
* On output_srcs precommit, wlr_mirror::ready is emitted. The compositor may
|
||||||
* call wlr_mirror_request_ to request to render a frame on dst.
|
* call wlr_mirror_request_ to request to render a frame on dst.
|
||||||
*
|
*
|
||||||
|
|
@ -31,29 +33,11 @@
|
||||||
* wlr_mirror_destroy
|
* wlr_mirror_destroy
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum wlr_mirror_scale {
|
|
||||||
/**
|
|
||||||
* src will be stretched to cover dst, distorting if necessary.
|
|
||||||
*/
|
|
||||||
WLR_MIRROR_SCALE_FULL,
|
|
||||||
/**
|
|
||||||
* src will be stretched to the width or the height of dst, preserving the
|
|
||||||
* aspect ratio.
|
|
||||||
*/
|
|
||||||
WLR_MIRROR_SCALE_ASPECT,
|
|
||||||
/**
|
|
||||||
* src will be rendered 1:1 at the center of dst. Content may be lost.
|
|
||||||
*/
|
|
||||||
WLR_MIRROR_SCALE_CENTER,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Immutable over session.
|
* Immutable over session.
|
||||||
*/
|
*/
|
||||||
struct wlr_mirror_params {
|
struct wlr_mirror_params {
|
||||||
|
|
||||||
enum wlr_mirror_scale scale;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the src cursor on dst.
|
* Render the src cursor on dst.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -127,11 +127,10 @@ static void calculate_absolute_box(struct wlr_box *absolute,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Position a box according to the scale method. It will be rotated from src
|
* Position a box scaled to fit the width or height of dst. It will be rotated
|
||||||
* to dst.
|
* from src to dst.
|
||||||
*/
|
*/
|
||||||
static void calculate_dst_box(struct wlr_fbox *box_dst,
|
static void calculate_dst_box(struct wlr_fbox *box_dst,
|
||||||
enum wlr_mirror_scale scale_method,
|
|
||||||
enum wl_output_transform transform_src,
|
enum wl_output_transform transform_src,
|
||||||
enum wl_output_transform transform_dst,
|
enum wl_output_transform transform_dst,
|
||||||
int32_t width_src, int32_t height_src,
|
int32_t width_src, int32_t height_src,
|
||||||
|
|
@ -146,46 +145,24 @@ static void calculate_dst_box(struct wlr_fbox *box_dst,
|
||||||
rotate_v_h(&width_src_rotated, &height_src_rotated, transform_src, width_src, height_src);
|
rotate_v_h(&width_src_rotated, &height_src_rotated, transform_src, width_src, height_src);
|
||||||
rotate_v_h(&width_dst_rotated, &height_dst_rotated, transform_dst, width_dst, height_dst);
|
rotate_v_h(&width_dst_rotated, &height_dst_rotated, transform_dst, width_dst, height_dst);
|
||||||
|
|
||||||
switch (scale_method) {
|
if (width_dst_rotated * height_src_rotated > height_dst_rotated * width_src_rotated) {
|
||||||
case WLR_MIRROR_SCALE_CENTER:
|
// expand to dst height
|
||||||
box_dst->width = width_src;
|
width_scaled = ((float) width_src_rotated) * height_dst_rotated / height_src_rotated;
|
||||||
box_dst->height = height_src;
|
height_scaled = height_dst_rotated;
|
||||||
box_dst->x = (((float) width_dst_rotated) - width_src_rotated) / 2;
|
} else {
|
||||||
box_dst->y = (((float) height_dst_rotated) - height_src_rotated) / 2;
|
// expand to dst width
|
||||||
break;
|
width_scaled = width_dst_rotated;
|
||||||
case WLR_MIRROR_SCALE_ASPECT:
|
height_scaled = ((float) height_src_rotated) * width_dst_rotated / width_src_rotated;
|
||||||
if (width_dst_rotated * height_src_rotated > height_dst_rotated * width_src_rotated) {
|
|
||||||
// expand to dst height
|
|
||||||
width_scaled = ((float) width_src_rotated) * height_dst_rotated / height_src_rotated;
|
|
||||||
height_scaled = height_dst_rotated;
|
|
||||||
} else {
|
|
||||||
// expand to dst width
|
|
||||||
width_scaled = width_dst_rotated;
|
|
||||||
height_scaled = ((float) height_src_rotated) * width_dst_rotated / width_src_rotated;
|
|
||||||
}
|
|
||||||
if (src_rotated) {
|
|
||||||
box_dst->width = height_scaled;
|
|
||||||
box_dst->height = width_scaled;
|
|
||||||
} else {
|
|
||||||
box_dst->width = width_scaled;
|
|
||||||
box_dst->height = height_scaled;
|
|
||||||
}
|
|
||||||
box_dst->x = (((float) width_dst_rotated) - width_scaled) / 2;
|
|
||||||
box_dst->y = (((float) height_dst_rotated) - height_scaled) / 2;
|
|
||||||
break;
|
|
||||||
case WLR_MIRROR_SCALE_FULL:
|
|
||||||
default:
|
|
||||||
if (src_rotated) {
|
|
||||||
box_dst->width = height_dst_rotated;
|
|
||||||
box_dst->height = width_dst_rotated;
|
|
||||||
} else {
|
|
||||||
box_dst->width = width_dst_rotated;
|
|
||||||
box_dst->height = height_dst_rotated;
|
|
||||||
}
|
|
||||||
box_dst->x = 0;
|
|
||||||
box_dst->y = 0;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
if (src_rotated) {
|
||||||
|
box_dst->width = height_scaled;
|
||||||
|
box_dst->height = width_scaled;
|
||||||
|
} else {
|
||||||
|
box_dst->width = width_scaled;
|
||||||
|
box_dst->height = height_scaled;
|
||||||
|
}
|
||||||
|
box_dst->x = (((float) width_dst_rotated) - width_scaled) / 2;
|
||||||
|
box_dst->y = (((float) height_dst_rotated) - height_scaled) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -340,7 +317,7 @@ static void output_dst_handle_frame(struct wl_listener *listener, void *data) {
|
||||||
|
|
||||||
// scale and position a box for the dst
|
// scale and position a box for the dst
|
||||||
struct wlr_fbox fbox_dst = {0};
|
struct wlr_fbox fbox_dst = {0};
|
||||||
calculate_dst_box(&fbox_dst, state->params.scale,
|
calculate_dst_box(&fbox_dst,
|
||||||
output_src->transform, output_dst->transform,
|
output_src->transform, output_dst->transform,
|
||||||
box_src.width, box_src.height,
|
box_src.width, box_src.height,
|
||||||
output_dst->width, output_dst->height);
|
output_dst->width, output_dst->height);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue