Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Scott Moreau |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and |
| 5 | * its documentation for any purpose is hereby granted without fee, provided |
| 6 | * that the above copyright notice appear in all copies and that both that |
| 7 | * copyright notice and this permission notice appear in supporting |
| 8 | * documentation, and that the name of the copyright holders not be used in |
| 9 | * advertising or publicity pertaining to distribution of the software |
| 10 | * without specific, written prior permission. The copyright holders make |
| 11 | * no representations about the suitability of this software for any |
| 12 | * purpose. It is provided "as is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 15 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 16 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 18 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 19 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 20 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 23 | #include "config.h" |
| 24 | |
Kristian Høgsberg | 583a236 | 2012-06-25 17:13:58 -0400 | [diff] [blame] | 25 | #include <stdlib.h> |
| 26 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 27 | #include "compositor.h" |
Kristian Høgsberg | 583a236 | 2012-06-25 17:13:58 -0400 | [diff] [blame] | 28 | #include "text-cursor-position-server-protocol.h" |
| 29 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 30 | static void |
| 31 | weston_zoom_frame_z(struct weston_animation *animation, |
| 32 | struct weston_output *output, uint32_t msecs) |
| 33 | { |
| 34 | if (animation->frame_counter <= 1) |
| 35 | output->zoom.spring_z.timestamp = msecs; |
| 36 | |
| 37 | weston_spring_update(&output->zoom.spring_z, msecs); |
| 38 | |
| 39 | if (output->zoom.spring_z.current > output->zoom.max_level) |
| 40 | output->zoom.spring_z.current = output->zoom.max_level; |
| 41 | else if (output->zoom.spring_z.current < 0.0) |
| 42 | output->zoom.spring_z.current = 0.0; |
| 43 | |
| 44 | if (weston_spring_done(&output->zoom.spring_z)) { |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 45 | if (output->zoom.active && output->zoom.level <= 0.0) { |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 46 | output->zoom.active = 0; |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 47 | output->disable_planes--; |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 48 | wl_list_remove(&output->zoom.motion_listener.link); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 49 | } |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 50 | output->zoom.spring_z.current = output->zoom.level; |
| 51 | wl_list_remove(&animation->link); |
| 52 | wl_list_init(&animation->link); |
| 53 | } |
| 54 | |
| 55 | output->dirty = 1; |
| 56 | weston_output_damage(output); |
| 57 | } |
| 58 | |
Kristian Høgsberg | ef6f136 | 2012-08-10 10:07:55 -0400 | [diff] [blame] | 59 | static struct weston_seat * |
| 60 | weston_zoom_pick_seat(struct weston_compositor *compositor) |
| 61 | { |
| 62 | return container_of(compositor->seat_list.next, |
| 63 | struct weston_seat, link); |
| 64 | } |
| 65 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 66 | static void |
| 67 | zoom_area_center_from_pointer(struct weston_output *output, |
| 68 | wl_fixed_t *x, wl_fixed_t *y) |
| 69 | { |
| 70 | float level = output->zoom.spring_z.current; |
| 71 | wl_fixed_t offset_x = wl_fixed_from_int(output->x); |
| 72 | wl_fixed_t offset_y = wl_fixed_from_int(output->y); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 73 | wl_fixed_t w = wl_fixed_from_int(output->width); |
| 74 | wl_fixed_t h = wl_fixed_from_int(output->height); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 75 | |
Jason Ekstrand | 87535e2 | 2014-05-20 22:45:02 -0500 | [diff] [blame] | 76 | *x = (*x - offset_x) * level + w / 2; |
| 77 | *y = (*y - offset_y) * level + h / 2; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | static void |
| 81 | weston_output_update_zoom_transform(struct weston_output *output) |
| 82 | { |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 83 | float global_x, global_y; |
Jason Ekstrand | 87535e2 | 2014-05-20 22:45:02 -0500 | [diff] [blame] | 84 | wl_fixed_t x = output->zoom.current.x; /* global pointer coords */ |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 85 | wl_fixed_t y = output->zoom.current.y; |
Jason Ekstrand | 87535e2 | 2014-05-20 22:45:02 -0500 | [diff] [blame] | 86 | float level; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 87 | |
| 88 | level = output->zoom.spring_z.current; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 89 | |
Ander Conselvan de Oliveira | 434e8f3 | 2012-11-21 15:11:36 +0200 | [diff] [blame] | 90 | if (!output->zoom.active || level > output->zoom.max_level || |
| 91 | level == 0.0f) |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 92 | return; |
| 93 | |
Pekka Paalanen | 13fd446 | 2015-03-10 11:13:14 +0200 | [diff] [blame] | 94 | zoom_area_center_from_pointer(output, &x, &y); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 95 | |
| 96 | global_x = wl_fixed_to_double(x); |
| 97 | global_y = wl_fixed_to_double(y); |
| 98 | |
Derek Foreman | 7cb916e | 2015-03-24 11:36:15 -0500 | [diff] [blame] | 99 | output->zoom.trans_x = global_x - output->width / 2; |
| 100 | output->zoom.trans_y = global_y - output->height / 2; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 101 | |
Jason Ekstrand | 87535e2 | 2014-05-20 22:45:02 -0500 | [diff] [blame] | 102 | if (output->zoom.trans_x < 0) |
| 103 | output->zoom.trans_x = 0; |
| 104 | if (output->zoom.trans_y < 0) |
| 105 | output->zoom.trans_y = 0; |
| 106 | if (output->zoom.trans_x > level * output->width) |
| 107 | output->zoom.trans_x = level * output->width; |
| 108 | if (output->zoom.trans_y > level * output->height) |
| 109 | output->zoom.trans_y = level * output->height; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static void |
Pekka Paalanen | 9808708 | 2015-03-10 12:05:44 +0200 | [diff] [blame] | 113 | weston_zoom_transition(struct weston_output *output) |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 114 | { |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 115 | if (output->zoom.level != output->zoom.spring_z.current) { |
| 116 | output->zoom.spring_z.target = output->zoom.level; |
| 117 | if (wl_list_empty(&output->zoom.animation_z.link)) { |
| 118 | output->zoom.animation_z.frame_counter = 0; |
| 119 | wl_list_insert(output->animation_list.prev, |
| 120 | &output->zoom.animation_z.link); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | output->dirty = 1; |
| 125 | weston_output_damage(output); |
| 126 | } |
| 127 | |
| 128 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 129 | weston_output_update_zoom(struct weston_output *output) |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 130 | { |
Kristian Høgsberg | ef6f136 | 2012-08-10 10:07:55 -0400 | [diff] [blame] | 131 | struct weston_seat *seat = weston_zoom_pick_seat(output->compositor); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 132 | |
Pekka Paalanen | 13fd446 | 2015-03-10 11:13:14 +0200 | [diff] [blame] | 133 | output->zoom.current.x = seat->pointer->x; |
| 134 | output->zoom.current.y = seat->pointer->y; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 135 | |
Pekka Paalanen | 9808708 | 2015-03-10 12:05:44 +0200 | [diff] [blame] | 136 | weston_zoom_transition(output); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 137 | weston_output_update_zoom_transform(output); |
| 138 | } |
| 139 | |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 140 | static void |
| 141 | motion(struct wl_listener *listener, void *data) |
| 142 | { |
| 143 | struct weston_output_zoom *zoom = |
| 144 | container_of(listener, struct weston_output_zoom, motion_listener); |
| 145 | struct weston_output *output = |
| 146 | container_of(zoom, struct weston_output, zoom); |
| 147 | |
| 148 | weston_output_update_zoom(output); |
| 149 | } |
| 150 | |
| 151 | WL_EXPORT void |
| 152 | weston_output_activate_zoom(struct weston_output *output) |
| 153 | { |
| 154 | struct weston_seat *seat = weston_zoom_pick_seat(output->compositor); |
| 155 | |
| 156 | if (output->zoom.active) |
| 157 | return; |
| 158 | |
| 159 | output->zoom.active = 1; |
| 160 | output->disable_planes++; |
| 161 | wl_signal_add(&seat->pointer->motion_signal, |
| 162 | &output->zoom.motion_listener); |
| 163 | } |
| 164 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 165 | WL_EXPORT void |
| 166 | weston_output_init_zoom(struct weston_output *output) |
| 167 | { |
| 168 | output->zoom.active = 0; |
| 169 | output->zoom.increment = 0.07; |
| 170 | output->zoom.max_level = 0.95; |
| 171 | output->zoom.level = 0.0; |
| 172 | output->zoom.trans_x = 0.0; |
| 173 | output->zoom.trans_y = 0.0; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 174 | weston_spring_init(&output->zoom.spring_z, 250.0, 0.0, 0.0); |
| 175 | output->zoom.spring_z.friction = 1000; |
| 176 | output->zoom.animation_z.frame = weston_zoom_frame_z; |
| 177 | wl_list_init(&output->zoom.animation_z.link); |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 178 | output->zoom.motion_listener.notify = motion; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 179 | } |