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 | |
| 76 | *x -= ((((*x - offset_x) / (float) w) - 0.5) * (w * (1.0 - level))); |
| 77 | *y -= ((((*y - offset_y) / (float) h) - 0.5) * (h * (1.0 - level))); |
| 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; |
| 84 | wl_fixed_t x = output->zoom.current.x; |
| 85 | wl_fixed_t y = output->zoom.current.y; |
| 86 | float trans_min, trans_max; |
| 87 | float ratio, level; |
| 88 | |
| 89 | level = output->zoom.spring_z.current; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 90 | |
Ander Conselvan de Oliveira | 434e8f3 | 2012-11-21 15:11:36 +0200 | [diff] [blame] | 91 | if (!output->zoom.active || level > output->zoom.max_level || |
| 92 | level == 0.0f) |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 93 | return; |
| 94 | |
Carlos Olmedo Escobar | 1a873aa | 2015-01-17 20:31:53 +0100 | [diff] [blame] | 95 | ratio = 1 / level; |
| 96 | |
Pekka Paalanen | 13fd446 | 2015-03-10 11:13:14 +0200 | [diff] [blame] | 97 | zoom_area_center_from_pointer(output, &x, &y); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 98 | |
| 99 | global_x = wl_fixed_to_double(x); |
| 100 | global_y = wl_fixed_to_double(y); |
| 101 | |
| 102 | output->zoom.trans_x = |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 103 | ((((global_x - output->x) / output->width) * |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 104 | (level * 2)) - level) * ratio; |
| 105 | output->zoom.trans_y = |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 106 | ((((global_y - output->y) / output->height) * |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 107 | (level * 2)) - level) * ratio; |
| 108 | |
| 109 | trans_max = level * 2 - level; |
| 110 | trans_min = -trans_max; |
| 111 | |
| 112 | /* Clip zoom area to output */ |
| 113 | if (output->zoom.trans_x > trans_max) |
| 114 | output->zoom.trans_x = trans_max; |
| 115 | else if (output->zoom.trans_x < trans_min) |
| 116 | output->zoom.trans_x = trans_min; |
| 117 | if (output->zoom.trans_y > trans_max) |
| 118 | output->zoom.trans_y = trans_max; |
| 119 | else if (output->zoom.trans_y < trans_min) |
| 120 | output->zoom.trans_y = trans_min; |
| 121 | } |
| 122 | |
| 123 | static void |
Pekka Paalanen | 9808708 | 2015-03-10 12:05:44 +0200 | [diff] [blame^] | 124 | weston_zoom_transition(struct weston_output *output) |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 125 | { |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 126 | if (output->zoom.level != output->zoom.spring_z.current) { |
| 127 | output->zoom.spring_z.target = output->zoom.level; |
| 128 | if (wl_list_empty(&output->zoom.animation_z.link)) { |
| 129 | output->zoom.animation_z.frame_counter = 0; |
| 130 | wl_list_insert(output->animation_list.prev, |
| 131 | &output->zoom.animation_z.link); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | output->dirty = 1; |
| 136 | weston_output_damage(output); |
| 137 | } |
| 138 | |
| 139 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 140 | weston_output_update_zoom(struct weston_output *output) |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 141 | { |
Kristian Høgsberg | ef6f136 | 2012-08-10 10:07:55 -0400 | [diff] [blame] | 142 | struct weston_seat *seat = weston_zoom_pick_seat(output->compositor); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 143 | |
Pekka Paalanen | 13fd446 | 2015-03-10 11:13:14 +0200 | [diff] [blame] | 144 | output->zoom.current.x = seat->pointer->x; |
| 145 | output->zoom.current.y = seat->pointer->y; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 146 | |
Pekka Paalanen | 9808708 | 2015-03-10 12:05:44 +0200 | [diff] [blame^] | 147 | weston_zoom_transition(output); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 148 | weston_output_update_zoom_transform(output); |
| 149 | } |
| 150 | |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 151 | static void |
| 152 | motion(struct wl_listener *listener, void *data) |
| 153 | { |
| 154 | struct weston_output_zoom *zoom = |
| 155 | container_of(listener, struct weston_output_zoom, motion_listener); |
| 156 | struct weston_output *output = |
| 157 | container_of(zoom, struct weston_output, zoom); |
| 158 | |
| 159 | weston_output_update_zoom(output); |
| 160 | } |
| 161 | |
| 162 | WL_EXPORT void |
| 163 | weston_output_activate_zoom(struct weston_output *output) |
| 164 | { |
| 165 | struct weston_seat *seat = weston_zoom_pick_seat(output->compositor); |
| 166 | |
| 167 | if (output->zoom.active) |
| 168 | return; |
| 169 | |
| 170 | output->zoom.active = 1; |
| 171 | output->disable_planes++; |
| 172 | wl_signal_add(&seat->pointer->motion_signal, |
| 173 | &output->zoom.motion_listener); |
| 174 | } |
| 175 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 176 | WL_EXPORT void |
| 177 | weston_output_init_zoom(struct weston_output *output) |
| 178 | { |
| 179 | output->zoom.active = 0; |
| 180 | output->zoom.increment = 0.07; |
| 181 | output->zoom.max_level = 0.95; |
| 182 | output->zoom.level = 0.0; |
| 183 | output->zoom.trans_x = 0.0; |
| 184 | output->zoom.trans_y = 0.0; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 185 | weston_spring_init(&output->zoom.spring_z, 250.0, 0.0, 0.0); |
| 186 | output->zoom.spring_z.friction = 1000; |
| 187 | output->zoom.animation_z.frame = weston_zoom_frame_z; |
| 188 | wl_list_init(&output->zoom.animation_z.link); |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 189 | output->zoom.motion_listener.notify = motion; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 190 | } |