Add screen magnifier

This adds a screen magnifier which can be controlled with the
`ZoomIn` / `ZoomOut` and `ToggleMagnify` actions.

It scales up part of the rendered framebuffer so the magnification
may end up looking blurry depending on the magnification scale.

PR #1774
This commit is contained in:
Simon Long 2024-05-15 23:07:23 +01:00 committed by GitHub
parent ad15c0474d
commit 8ba066a1a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 473 additions and 1 deletions

View file

@ -5,6 +5,7 @@
#include <wlr/types/wlr_scene.h>
#include <wlr/util/log.h>
#include "common/scene-helpers.h"
#include "magnifier.h"
struct wlr_surface *
lab_wlr_surface_from_node(struct wlr_scene_node *node)
@ -44,16 +45,29 @@ lab_wlr_scene_output_commit(struct wlr_scene_output *scene_output)
assert(scene_output);
struct wlr_output *wlr_output = scene_output->output;
struct wlr_output_state *state = &wlr_output->pending;
struct output *output = wlr_output->data;
bool wants_magnification = output_wants_magnification(output);
static bool last_mag = false;
if (!wlr_output->needs_frame && !pixman_region32_not_empty(
&scene_output->damage_ring.current)) {
&scene_output->damage_ring.current) && !wants_magnification
&& last_mag != is_magnify_on()) {
return false;
}
last_mag = is_magnify_on();
if (!wlr_scene_output_build_state(scene_output, state, NULL)) {
wlr_log(WLR_ERROR, "Failed to build output state for %s",
wlr_output->name);
return false;
}
struct wlr_box additional_damage = {0};
if (state->buffer && is_magnify_on()) {
magnify(output, state->buffer, &additional_damage);
}
if (!wlr_output_commit(wlr_output)) {
wlr_log(WLR_INFO, "Failed to commit output %s",
wlr_output->name);
@ -66,5 +80,9 @@ lab_wlr_scene_output_commit(struct wlr_scene_output *scene_output)
* again.
*/
wlr_damage_ring_rotate(&scene_output->damage_ring);
if (!wlr_box_empty(&additional_damage)) {
wlr_damage_ring_add_box(&scene_output->damage_ring, &additional_damage);
}
return true;
}