mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	Merge pull request #2598 from tokyo4j/refactor-magnifier
magnifier: refactor
This commit is contained in:
		
						commit
						4750214d42
					
				
					 8 changed files with 95 additions and 123 deletions
				
			
		| 
						 | 
					@ -22,4 +22,6 @@ void box_union(struct wlr_box *box_dest, struct wlr_box *box_a,
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct wlr_box box_fit_within(int width, int height, struct wlr_box *bounding_box);
 | 
					struct wlr_box box_fit_within(int width, int height, struct wlr_box *bounding_box);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct wlr_fbox box_to_fbox(struct wlr_box *box);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* LABWC_BOX_H */
 | 
					#endif /* LABWC_BOX_H */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,12 +14,12 @@ enum magnify_dir {
 | 
				
			||||||
	MAGNIFY_DECREASE
 | 
						MAGNIFY_DECREASE
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void magnify_toggle(struct server *server);
 | 
					void magnifier_toggle(struct server *server);
 | 
				
			||||||
void magnify_set_scale(struct server *server, enum magnify_dir dir);
 | 
					void magnifier_set_scale(struct server *server, enum magnify_dir dir);
 | 
				
			||||||
bool output_wants_magnification(struct output *output);
 | 
					bool output_wants_magnification(struct output *output);
 | 
				
			||||||
void magnify(struct output *output, struct wlr_buffer *output_buffer,
 | 
					void magnifier_draw(struct output *output, struct wlr_buffer *output_buffer,
 | 
				
			||||||
	struct wlr_box *damage);
 | 
						struct wlr_box *damage);
 | 
				
			||||||
bool is_magnify_on(void);
 | 
					bool magnifier_is_enabled(void);
 | 
				
			||||||
void magnify_reset(void);
 | 
					void magnifier_reset(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* LABWC_MAGNIFIER_H */
 | 
					#endif /* LABWC_MAGNIFIER_H */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1317,13 +1317,13 @@ actions_run(struct view *activator, struct server *server,
 | 
				
			||||||
			rc.tablet.force_mouse_emulation = !rc.tablet.force_mouse_emulation;
 | 
								rc.tablet.force_mouse_emulation = !rc.tablet.force_mouse_emulation;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case ACTION_TYPE_TOGGLE_MAGNIFY:
 | 
							case ACTION_TYPE_TOGGLE_MAGNIFY:
 | 
				
			||||||
			magnify_toggle(server);
 | 
								magnifier_toggle(server);
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case ACTION_TYPE_ZOOM_IN:
 | 
							case ACTION_TYPE_ZOOM_IN:
 | 
				
			||||||
			magnify_set_scale(server, MAGNIFY_INCREASE);
 | 
								magnifier_set_scale(server, MAGNIFY_INCREASE);
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case ACTION_TYPE_ZOOM_OUT:
 | 
							case ACTION_TYPE_ZOOM_OUT:
 | 
				
			||||||
			magnify_set_scale(server, MAGNIFY_DECREASE);
 | 
								magnifier_set_scale(server, MAGNIFY_DECREASE);
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case ACTION_TYPE_WARP_CURSOR:
 | 
							case ACTION_TYPE_WARP_CURSOR:
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -73,3 +73,14 @@ box_fit_within(int width, int height, struct wlr_box *bound)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return box;
 | 
						return box;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct wlr_fbox
 | 
				
			||||||
 | 
					box_to_fbox(struct wlr_box *box)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return (struct wlr_fbox){
 | 
				
			||||||
 | 
							.x = box->x,
 | 
				
			||||||
 | 
							.y = box->y,
 | 
				
			||||||
 | 
							.width = box->width,
 | 
				
			||||||
 | 
							.height = box->height,
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -114,8 +114,8 @@ lab_wlr_scene_output_commit(struct wlr_scene_output *scene_output,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct wlr_box additional_damage = {0};
 | 
						struct wlr_box additional_damage = {0};
 | 
				
			||||||
	if (state->buffer && is_magnify_on()) {
 | 
						if (state->buffer && magnifier_is_enabled()) {
 | 
				
			||||||
		magnify(output, state->buffer, &additional_damage);
 | 
							magnifier_draw(output, state->buffer, &additional_damage);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool committed = wlr_output_commit_state(wlr_output, state);
 | 
						bool committed = wlr_output_commit_state(wlr_output, state);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1282,8 +1282,10 @@ entry(xmlNode *node, char *nodename, char *content, struct parser_state *state)
 | 
				
			||||||
		rc.mag_height = atoi(content);
 | 
							rc.mag_height = atoi(content);
 | 
				
			||||||
	} else if (!strcasecmp(nodename, "initScale.magnifier")) {
 | 
						} else if (!strcasecmp(nodename, "initScale.magnifier")) {
 | 
				
			||||||
		set_float(content, &rc.mag_scale);
 | 
							set_float(content, &rc.mag_scale);
 | 
				
			||||||
 | 
							rc.mag_scale = MAX(1.0, rc.mag_scale);
 | 
				
			||||||
	} else if (!strcasecmp(nodename, "increment.magnifier")) {
 | 
						} else if (!strcasecmp(nodename, "increment.magnifier")) {
 | 
				
			||||||
		set_float(content, &rc.mag_increment);
 | 
							set_float(content, &rc.mag_increment);
 | 
				
			||||||
 | 
							rc.mag_increment = MAX(0, rc.mag_increment);
 | 
				
			||||||
	} else if (!strcasecmp(nodename, "useFilter.magnifier")) {
 | 
						} else if (!strcasecmp(nodename, "useFilter.magnifier")) {
 | 
				
			||||||
		set_bool(content, &rc.mag_filter);
 | 
							set_bool(content, &rc.mag_filter);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -1797,10 +1799,6 @@ post_processing(void)
 | 
				
			||||||
		wlr_log(WLR_INFO, "load default window switcher fields");
 | 
							wlr_log(WLR_INFO, "load default window switcher fields");
 | 
				
			||||||
		load_default_window_switcher_fields();
 | 
							load_default_window_switcher_fields();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (rc.mag_scale <= 0.0) {
 | 
					 | 
				
			||||||
		rc.mag_scale = 1.0;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										177
									
								
								src/magnifier.c
									
										
									
									
									
								
							
							
						
						
									
										177
									
								
								src/magnifier.c
									
										
									
									
									
								
							| 
						 | 
					@ -1,7 +1,9 @@
 | 
				
			||||||
// SPDX-License-Identifier: GPL-2.0-only
 | 
					// SPDX-License-Identifier: GPL-2.0-only
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <assert.h>
 | 
					#include <assert.h>
 | 
				
			||||||
 | 
					#include <wlr/render/swapchain.h>
 | 
				
			||||||
#include <wlr/types/wlr_output.h>
 | 
					#include <wlr/types/wlr_output.h>
 | 
				
			||||||
 | 
					#include "common/box.h"
 | 
				
			||||||
#include "common/macros.h"
 | 
					#include "common/macros.h"
 | 
				
			||||||
#include "labwc.h"
 | 
					#include "labwc.h"
 | 
				
			||||||
#include "magnifier.h"
 | 
					#include "magnifier.h"
 | 
				
			||||||
| 
						 | 
					@ -14,88 +16,51 @@ static double mag_scale = 0.0;
 | 
				
			||||||
static struct wlr_buffer *tmp_buffer = NULL;
 | 
					static struct wlr_buffer *tmp_buffer = NULL;
 | 
				
			||||||
static struct wlr_texture *tmp_texture = NULL;
 | 
					static struct wlr_texture *tmp_texture = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define CLAMP(in, lower, upper) MAX(MIN((in), (upper)), (lower))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box *damage)
 | 
					magnifier_draw(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box *damage)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int width, height;
 | 
					 | 
				
			||||||
	double x, y;
 | 
					 | 
				
			||||||
	struct wlr_box border_box, dst_box;
 | 
					 | 
				
			||||||
	struct wlr_fbox src_box;
 | 
					 | 
				
			||||||
	bool fullscreen = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* TODO: This looks way too complicated to just get the used format */
 | 
					 | 
				
			||||||
	struct wlr_drm_format wlr_drm_format = {0};
 | 
					 | 
				
			||||||
	struct wlr_shm_attributes shm_attribs = {0};
 | 
					 | 
				
			||||||
	struct wlr_dmabuf_attributes dma_attribs = {0};
 | 
					 | 
				
			||||||
	if (wlr_buffer_get_dmabuf(output_buffer, &dma_attribs)) {
 | 
					 | 
				
			||||||
		wlr_drm_format.format = dma_attribs.format;
 | 
					 | 
				
			||||||
		wlr_drm_format.len = 1;
 | 
					 | 
				
			||||||
		wlr_drm_format.modifiers = &dma_attribs.modifier;
 | 
					 | 
				
			||||||
	} else if (wlr_buffer_get_shm(output_buffer, &shm_attribs)) {
 | 
					 | 
				
			||||||
		wlr_drm_format.format = shm_attribs.format;
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		wlr_log(WLR_ERROR, "Failed to read buffer format");
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* Fetch scale-adjusted cursor coordinates */
 | 
					 | 
				
			||||||
	struct server *server = output->server;
 | 
						struct server *server = output->server;
 | 
				
			||||||
	struct theme *theme = server->theme;
 | 
						struct theme *theme = server->theme;
 | 
				
			||||||
	struct wlr_cursor *cursor = server->seat.cursor;
 | 
						bool fullscreen = (rc.mag_width == -1 || rc.mag_height == -1);
 | 
				
			||||||
	double ox = cursor->x;
 | 
					
 | 
				
			||||||
	double oy = cursor->y;
 | 
						struct wlr_box output_box = {
 | 
				
			||||||
	wlr_output_layout_output_coords(server->output_layout, output->wlr_output, &ox, &oy);
 | 
							.width = output_buffer->width,
 | 
				
			||||||
	ox *= output->wlr_output->scale;
 | 
							.height = output_buffer->height,
 | 
				
			||||||
	oy *= output->wlr_output->scale;
 | 
						};
 | 
				
			||||||
	if (rc.mag_width == -1 || rc.mag_height == -1) {
 | 
					
 | 
				
			||||||
		fullscreen = true;
 | 
						/* Cursor position in physical output coordinate */
 | 
				
			||||||
	}
 | 
						double cursor_x = server->seat.cursor->x;
 | 
				
			||||||
	if ((ox < 0 || oy < 0 || ox >= output_buffer->width || oy >= output_buffer->height)
 | 
						double cursor_y = server->seat.cursor->y;
 | 
				
			||||||
		&& fullscreen) {
 | 
						wlr_output_layout_output_coords(server->output_layout,
 | 
				
			||||||
 | 
							output->wlr_output, &cursor_x, &cursor_y);
 | 
				
			||||||
 | 
						cursor_x *= output->wlr_output->scale;
 | 
				
			||||||
 | 
						cursor_y *= output->wlr_output->scale;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bool cursor_in_output = wlr_box_contains_point(&output_box,
 | 
				
			||||||
 | 
							cursor_x, cursor_y);
 | 
				
			||||||
 | 
						if (fullscreen && !cursor_in_output) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (mag_scale == 0.0) {
 | 
						if (mag_scale == 0.0) {
 | 
				
			||||||
		mag_scale = rc.mag_scale;
 | 
							mag_scale = rc.mag_scale;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (mag_scale == 0.0) {
 | 
						assert(mag_scale >= 1.0);
 | 
				
			||||||
		mag_scale = 1.0;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Magnifier geometry in physical output coordinate */
 | 
				
			||||||
 | 
						struct wlr_box mag_box;
 | 
				
			||||||
	if (fullscreen) {
 | 
						if (fullscreen) {
 | 
				
			||||||
		width = output_buffer->width;
 | 
							mag_box = output_box;
 | 
				
			||||||
		height = output_buffer->height;
 | 
					 | 
				
			||||||
		x = 0;
 | 
					 | 
				
			||||||
		y = 0;
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		width = rc.mag_width + 1;
 | 
							mag_box.x = cursor_x - (rc.mag_width / 2.0);
 | 
				
			||||||
		height = rc.mag_height + 1;
 | 
							mag_box.y = cursor_y - (rc.mag_height / 2.0);
 | 
				
			||||||
		x = ox - (rc.mag_width / 2.0);
 | 
							mag_box.width = rc.mag_width;
 | 
				
			||||||
		y = oy - (rc.mag_height / 2.0);
 | 
							mag_box.height = rc.mag_height;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	double cropped_width = width;
 | 
					 | 
				
			||||||
	double cropped_height = height;
 | 
					 | 
				
			||||||
	double dst_x = 0;
 | 
					 | 
				
			||||||
	double dst_y = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* Ensure everything is kept within output boundaries */
 | 
					 | 
				
			||||||
	if (x < 0) {
 | 
					 | 
				
			||||||
		cropped_width += x;
 | 
					 | 
				
			||||||
		dst_x = x * -1;
 | 
					 | 
				
			||||||
		x = 0;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (y < 0) {
 | 
					 | 
				
			||||||
		cropped_height += y;
 | 
					 | 
				
			||||||
		dst_y = y * -1;
 | 
					 | 
				
			||||||
		y = 0;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	cropped_width = MIN(cropped_width, (double)output_buffer->width - x);
 | 
					 | 
				
			||||||
	cropped_height = MIN(cropped_height, (double)output_buffer->height - y);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* (Re)create the temporary buffer if required */
 | 
						/* (Re)create the temporary buffer if required */
 | 
				
			||||||
	if (tmp_buffer && (tmp_buffer->width != width || tmp_buffer->height != height)) {
 | 
						if (tmp_buffer && (tmp_buffer->width != mag_box.width
 | 
				
			||||||
 | 
								|| tmp_buffer->height != mag_box.height)) {
 | 
				
			||||||
		wlr_log(WLR_DEBUG, "tmp magnifier buffer size changed, dropping");
 | 
							wlr_log(WLR_DEBUG, "tmp magnifier buffer size changed, dropping");
 | 
				
			||||||
		assert(tmp_texture);
 | 
							assert(tmp_texture);
 | 
				
			||||||
		wlr_texture_destroy(tmp_texture);
 | 
							wlr_texture_destroy(tmp_texture);
 | 
				
			||||||
| 
						 | 
					@ -105,7 +70,8 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (!tmp_buffer) {
 | 
						if (!tmp_buffer) {
 | 
				
			||||||
		tmp_buffer = wlr_allocator_create_buffer(
 | 
							tmp_buffer = wlr_allocator_create_buffer(
 | 
				
			||||||
			server->allocator, width, height, &wlr_drm_format);
 | 
								server->allocator, mag_box.width, mag_box.height,
 | 
				
			||||||
 | 
								&output->wlr_output->swapchain->format);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (!tmp_buffer) {
 | 
						if (!tmp_buffer) {
 | 
				
			||||||
		wlr_log(WLR_ERROR, "Failed to allocate temporary magnifier buffer");
 | 
							wlr_log(WLR_ERROR, "Failed to allocate temporary magnifier buffer");
 | 
				
			||||||
| 
						 | 
					@ -137,13 +103,17 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box
 | 
				
			||||||
		goto cleanup;
 | 
							goto cleanup;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct wlr_box src_box_for_copy;
 | 
				
			||||||
 | 
						wlr_box_intersection(&src_box_for_copy, &mag_box, &output_box);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct wlr_box dst_box_for_copy = src_box_for_copy;
 | 
				
			||||||
 | 
						dst_box_for_copy.x -= mag_box.x;
 | 
				
			||||||
 | 
						dst_box_for_copy.y -= mag_box.y;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct wlr_render_texture_options opts = {
 | 
						struct wlr_render_texture_options opts = {
 | 
				
			||||||
		.texture = output_texture,
 | 
							.texture = output_texture,
 | 
				
			||||||
		.src_box = (struct wlr_fbox) {
 | 
							.src_box = box_to_fbox(&src_box_for_copy),
 | 
				
			||||||
			x, y, cropped_width, cropped_height },
 | 
							.dst_box = dst_box_for_copy,
 | 
				
			||||||
		.dst_box = (struct wlr_box) {
 | 
					 | 
				
			||||||
			dst_x, dst_y, cropped_width, cropped_height },
 | 
					 | 
				
			||||||
		.alpha = NULL,
 | 
					 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
	wlr_render_pass_add_texture(tmp_render_pass, &opts);
 | 
						wlr_render_pass_add_texture(tmp_render_pass, &opts);
 | 
				
			||||||
	if (!wlr_render_pass_submit(tmp_render_pass)) {
 | 
						if (!wlr_render_pass_submit(tmp_render_pass)) {
 | 
				
			||||||
| 
						 | 
					@ -161,17 +131,17 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box
 | 
				
			||||||
		goto cleanup;
 | 
							goto cleanup;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Borders */
 | 
						struct wlr_box damage_box;
 | 
				
			||||||
	if (fullscreen) {
 | 
						if (fullscreen) {
 | 
				
			||||||
		border_box.x = 0;
 | 
							damage_box = output_box;
 | 
				
			||||||
		border_box.y = 0;
 | 
					 | 
				
			||||||
		border_box.width = width;
 | 
					 | 
				
			||||||
		border_box.height = height;
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		border_box.x = ox - (width / 2 + theme->mag_border_width);
 | 
							/* Draw borders */
 | 
				
			||||||
		border_box.y = oy - (height / 2 + theme->mag_border_width);
 | 
							struct wlr_box border_box = {
 | 
				
			||||||
		border_box.width = (width + theme->mag_border_width * 2);
 | 
								.x = mag_box.x - theme->mag_border_width,
 | 
				
			||||||
		border_box.height = (height + theme->mag_border_width * 2);
 | 
								.y = mag_box.y - theme->mag_border_width,
 | 
				
			||||||
 | 
								.width = mag_box.width + theme->mag_border_width * 2,
 | 
				
			||||||
 | 
								.height = mag_box.height + theme->mag_border_width * 2,
 | 
				
			||||||
 | 
							};
 | 
				
			||||||
		struct wlr_render_rect_options bg_opts = {
 | 
							struct wlr_render_rect_options bg_opts = {
 | 
				
			||||||
			.box = border_box,
 | 
								.box = border_box,
 | 
				
			||||||
			.color = (struct wlr_render_color) {
 | 
								.color = (struct wlr_render_color) {
 | 
				
			||||||
| 
						 | 
					@ -180,37 +150,31 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box
 | 
				
			||||||
				.b = theme->mag_border_color[2],
 | 
									.b = theme->mag_border_color[2],
 | 
				
			||||||
				.a = theme->mag_border_color[3]
 | 
									.a = theme->mag_border_color[3]
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			.clip = NULL,
 | 
					 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
		wlr_render_pass_add_rect(tmp_render_pass, &bg_opts);
 | 
							wlr_render_pass_add_rect(tmp_render_pass, &bg_opts);
 | 
				
			||||||
 | 
							wlr_box_intersection(&damage_box, &border_box, &output_box);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	src_box.width = width / mag_scale;
 | 
						struct wlr_fbox src_box_for_paste = {
 | 
				
			||||||
	src_box.height = height / mag_scale;
 | 
							.width = mag_box.width / mag_scale,
 | 
				
			||||||
	dst_box.width = width;
 | 
							.height = mag_box.height / mag_scale,
 | 
				
			||||||
	dst_box.height = height;
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (fullscreen) {
 | 
						if (fullscreen) {
 | 
				
			||||||
		src_box.x = CLAMP(ox - (ox / mag_scale), 0.0,
 | 
							src_box_for_paste.x = cursor_x - (cursor_x / mag_scale);
 | 
				
			||||||
			width * (mag_scale - 1.0) / mag_scale);
 | 
							src_box_for_paste.y = cursor_y - (cursor_y / mag_scale);
 | 
				
			||||||
		src_box.y = CLAMP(oy - (oy / mag_scale), 0.0,
 | 
					 | 
				
			||||||
			height * (mag_scale - 1.0) / mag_scale);
 | 
					 | 
				
			||||||
		dst_box.x = 0;
 | 
					 | 
				
			||||||
		dst_box.y = 0;
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		src_box.x = width * (mag_scale - 1.0) / (2.0 * mag_scale);
 | 
							src_box_for_paste.x =
 | 
				
			||||||
		src_box.y = height * (mag_scale - 1.0) / (2.0 * mag_scale);
 | 
								mag_box.width * (mag_scale - 1.0) / (2.0 * mag_scale);
 | 
				
			||||||
		dst_box.x = ox - (width / 2);
 | 
							src_box_for_paste.y =
 | 
				
			||||||
		dst_box.y = oy - (height / 2);
 | 
								mag_box.height * (mag_scale - 1.0) / (2.0 * mag_scale);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Paste the magnified result back into the output buffer */
 | 
						/* Paste the magnified result back into the output buffer */
 | 
				
			||||||
	opts = (struct wlr_render_texture_options) {
 | 
						opts = (struct wlr_render_texture_options) {
 | 
				
			||||||
		.texture = tmp_texture,
 | 
							.texture = tmp_texture,
 | 
				
			||||||
		.src_box = src_box,
 | 
							.src_box = src_box_for_paste,
 | 
				
			||||||
		.dst_box = dst_box,
 | 
							.dst_box = mag_box,
 | 
				
			||||||
		.alpha = NULL,
 | 
					 | 
				
			||||||
		.clip = NULL,
 | 
					 | 
				
			||||||
		.filter_mode = rc.mag_filter ? WLR_SCALE_FILTER_BILINEAR
 | 
							.filter_mode = rc.mag_filter ? WLR_SCALE_FILTER_BILINEAR
 | 
				
			||||||
			: WLR_SCALE_FILTER_NEAREST,
 | 
								: WLR_SCALE_FILTER_NEAREST,
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
| 
						 | 
					@ -221,10 +185,7 @@ magnify(struct output *output, struct wlr_buffer *output_buffer, struct wlr_box
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* And finally mark the extra damage */
 | 
						/* And finally mark the extra damage */
 | 
				
			||||||
	*damage = border_box;
 | 
						*damage = damage_box;
 | 
				
			||||||
	damage->width += 1;
 | 
					 | 
				
			||||||
	damage->height += 1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
cleanup:
 | 
					cleanup:
 | 
				
			||||||
	wlr_buffer_unlock(output_buffer);
 | 
						wlr_buffer_unlock(output_buffer);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -258,7 +219,7 @@ enable_magnifier(struct server *server, bool enable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Toggles magnification on and off */
 | 
					/* Toggles magnification on and off */
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
magnify_toggle(struct server *server)
 | 
					magnifier_toggle(struct server *server)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	enable_magnifier(server, !magnify_on);
 | 
						enable_magnifier(server, !magnify_on);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -270,7 +231,7 @@ magnify_toggle(struct server *server)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Increases and decreases magnification scale */
 | 
					/* Increases and decreases magnification scale */
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
magnify_set_scale(struct server *server, enum magnify_dir dir)
 | 
					magnifier_set_scale(struct server *server, enum magnify_dir dir)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct output *output = output_nearest_to_cursor(server);
 | 
						struct output *output = output_nearest_to_cursor(server);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -296,7 +257,7 @@ magnify_set_scale(struct server *server, enum magnify_dir dir)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Reset any buffers held by the magnifier */
 | 
					/* Reset any buffers held by the magnifier */
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
magnify_reset(void)
 | 
					magnifier_reset(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (tmp_texture && tmp_buffer) {
 | 
						if (tmp_texture && tmp_buffer) {
 | 
				
			||||||
		wlr_texture_destroy(tmp_texture);
 | 
							wlr_texture_destroy(tmp_texture);
 | 
				
			||||||
| 
						 | 
					@ -308,7 +269,7 @@ magnify_reset(void)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Report whether magnification is enabled */
 | 
					/* Report whether magnification is enabled */
 | 
				
			||||||
bool
 | 
					bool
 | 
				
			||||||
is_magnify_on(void)
 | 
					magnifier_is_enabled(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return magnify_on;
 | 
						return magnify_on;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -413,7 +413,7 @@ handle_renderer_lost(struct wl_listener *listener, void *data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	reload_config_and_theme(server);
 | 
						reload_config_and_theme(server);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	magnify_reset();
 | 
						magnifier_reset();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wlr_allocator_destroy(old_allocator);
 | 
						wlr_allocator_destroy(old_allocator);
 | 
				
			||||||
	wlr_renderer_destroy(old_renderer);
 | 
						wlr_renderer_destroy(old_renderer);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue