[PATCH weston 3/4 v2] Center zoom area for text cursor position.
Scott Moreau
oreaus at gmail.com
Mon May 21 14:21:26 PDT 2012
Here we install the logic for 'zoom area centered on a given point'.
---
Rebased against master, 380deee3c7b18574d66511287bb01dde51027fbf
src/compositor.c | 29 ++++++++++++++++++++++-------
src/compositor.h | 2 +-
src/shell.c | 2 +-
3 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/src/compositor.c b/src/compositor.c
index 75bda93..20874c6 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1625,7 +1625,7 @@ notify_motion(struct wl_seat *seat, uint32_t time, wl_fixed_t x, wl_fixed_t y)
if (output->zoom.active &&
pixman_region32_contains_point(&output->region,
ix, iy, NULL))
- weston_output_update_zoom(output, x, y);
+ weston_output_update_zoom(output, x, y, 0);
weston_device_repick(seat);
interface = seat->pointer->grab->interface;
@@ -2456,13 +2456,14 @@ weston_text_cursor_position_notify(struct weston_surface *surface,
if (output->zoom.active &&
pixman_region32_contains_point(&output->region,
cur_pos_x, cur_pos_y, NULL))
- weston_output_update_zoom(output, cur_pos_x * 256, cur_pos_y * 256);
+ weston_output_update_zoom(output, cur_pos_x * 256, cur_pos_y * 256, 1);
}
WL_EXPORT void
-weston_output_update_zoom(struct weston_output *output, wl_fixed_t fx, wl_fixed_t fy)
+weston_output_update_zoom(struct weston_output *output, wl_fixed_t fx, wl_fixed_t fy, int text_cursor)
{
int32_t x, y;
+ float trans_min, trans_max;
if (output->zoom.level >= 1.0)
return;
@@ -2470,10 +2471,24 @@ weston_output_update_zoom(struct weston_output *output, wl_fixed_t fx, wl_fixed_
x = wl_fixed_to_int(fx);
y = wl_fixed_to_int(fy);
- output->zoom.trans_x = (((float)(x - output->x) / output->current->width) *
- (output->zoom.level * 2)) - output->zoom.level;
- output->zoom.trans_y = (((float)(y - output->y) / output->current->height) *
- (output->zoom.level * 2)) - output->zoom.level;
+ trans_max = output->zoom.level * 2 - output->zoom.level;
+ trans_min = -trans_max;
+
+ output->zoom.trans_x = ((((float)(x - output->x) / output->current->width) *
+ (output->zoom.level * 2)) - output->zoom.level) *
+ (text_cursor ? (1 / output->zoom.level) : 1);
+ output->zoom.trans_y = ((((float)(y - output->y) / output->current->height) *
+ (output->zoom.level * 2)) - output->zoom.level) *
+ (text_cursor ? (1 / output->zoom.level) : 1);
+
+ if (output->zoom.trans_x > trans_max)
+ output->zoom.trans_x = trans_max;
+ else if (output->zoom.trans_x < trans_min)
+ output->zoom.trans_x = trans_min;
+ if (output->zoom.trans_y > trans_max)
+ output->zoom.trans_y = trans_max;
+ else if (output->zoom.trans_y < trans_min)
+ output->zoom.trans_y = trans_min;
output->dirty = 1;
weston_output_damage(output);
diff --git a/src/compositor.h b/src/compositor.h
index 1b3d08c..7a84082 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -551,7 +551,7 @@ weston_compositor_init(struct weston_compositor *ec, struct wl_display *display)
void
weston_compositor_shutdown(struct weston_compositor *ec);
void
-weston_output_update_zoom(struct weston_output *output, int x, int y);
+weston_output_update_zoom(struct weston_output *output, int x, int y, int text_cursor);
void
weston_text_cursor_position_notify(struct weston_surface *surface, int x, int y);
void
diff --git a/src/shell.c b/src/shell.c
index 6c9ee93..c2581f1 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -1659,7 +1659,7 @@ zoom_binding(struct wl_seat *seat, uint32_t time,
weston_output_update_zoom(output,
seat->pointer->x,
- seat->pointer->y);
+ seat->pointer->y, 0);
}
}
}
--
1.7.7.6
More information about the wayland-devel
mailing list