Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Scott Moreau |
| 3 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to deal in the Software without restriction, including |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | * permit persons to whom the Software is furnished to do so, subject to |
| 10 | * the following conditions: |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 11 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 12 | * The above copyright notice and this permission notice (including the |
| 13 | * next paragraph) shall be included in all copies or substantial |
| 14 | * portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 24 | */ |
| 25 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 26 | #include "config.h" |
| 27 | |
Kristian Høgsberg | 583a236 | 2012-06-25 17:13:58 -0400 | [diff] [blame] | 28 | #include <stdlib.h> |
Derek Foreman | a36eb50 | 2015-07-23 14:55:12 -0500 | [diff] [blame^] | 29 | #include <stdbool.h> |
Kristian Høgsberg | 583a236 | 2012-06-25 17:13:58 -0400 | [diff] [blame] | 30 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 31 | #include "compositor.h" |
Kristian Høgsberg | 583a236 | 2012-06-25 17:13:58 -0400 | [diff] [blame] | 32 | #include "text-cursor-position-server-protocol.h" |
Jon Cruz | 867d50e | 2015-06-15 15:37:10 -0700 | [diff] [blame] | 33 | #include "shared/helpers.h" |
Kristian Høgsberg | 583a236 | 2012-06-25 17:13:58 -0400 | [diff] [blame] | 34 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 35 | static void |
| 36 | weston_zoom_frame_z(struct weston_animation *animation, |
| 37 | struct weston_output *output, uint32_t msecs) |
| 38 | { |
| 39 | if (animation->frame_counter <= 1) |
| 40 | output->zoom.spring_z.timestamp = msecs; |
| 41 | |
| 42 | weston_spring_update(&output->zoom.spring_z, msecs); |
| 43 | |
| 44 | if (output->zoom.spring_z.current > output->zoom.max_level) |
| 45 | output->zoom.spring_z.current = output->zoom.max_level; |
| 46 | else if (output->zoom.spring_z.current < 0.0) |
| 47 | output->zoom.spring_z.current = 0.0; |
| 48 | |
| 49 | if (weston_spring_done(&output->zoom.spring_z)) { |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 50 | if (output->zoom.active && output->zoom.level <= 0.0) { |
Derek Foreman | a36eb50 | 2015-07-23 14:55:12 -0500 | [diff] [blame^] | 51 | output->zoom.active = false; |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 52 | output->disable_planes--; |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 53 | wl_list_remove(&output->zoom.motion_listener.link); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 54 | } |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 55 | output->zoom.spring_z.current = output->zoom.level; |
| 56 | wl_list_remove(&animation->link); |
| 57 | wl_list_init(&animation->link); |
| 58 | } |
| 59 | |
| 60 | output->dirty = 1; |
| 61 | weston_output_damage(output); |
| 62 | } |
| 63 | |
Kristian Høgsberg | ef6f136 | 2012-08-10 10:07:55 -0400 | [diff] [blame] | 64 | static struct weston_seat * |
| 65 | weston_zoom_pick_seat(struct weston_compositor *compositor) |
| 66 | { |
| 67 | return container_of(compositor->seat_list.next, |
| 68 | struct weston_seat, link); |
| 69 | } |
| 70 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 71 | static void |
| 72 | zoom_area_center_from_pointer(struct weston_output *output, |
| 73 | wl_fixed_t *x, wl_fixed_t *y) |
| 74 | { |
| 75 | float level = output->zoom.spring_z.current; |
| 76 | wl_fixed_t offset_x = wl_fixed_from_int(output->x); |
| 77 | wl_fixed_t offset_y = wl_fixed_from_int(output->y); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 78 | wl_fixed_t w = wl_fixed_from_int(output->width); |
| 79 | wl_fixed_t h = wl_fixed_from_int(output->height); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 80 | |
Jason Ekstrand | 87535e2 | 2014-05-20 22:45:02 -0500 | [diff] [blame] | 81 | *x = (*x - offset_x) * level + w / 2; |
| 82 | *y = (*y - offset_y) * level + h / 2; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static void |
| 86 | weston_output_update_zoom_transform(struct weston_output *output) |
| 87 | { |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 88 | float global_x, global_y; |
Jason Ekstrand | 87535e2 | 2014-05-20 22:45:02 -0500 | [diff] [blame] | 89 | wl_fixed_t x = output->zoom.current.x; /* global pointer coords */ |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 90 | wl_fixed_t y = output->zoom.current.y; |
Jason Ekstrand | 87535e2 | 2014-05-20 22:45:02 -0500 | [diff] [blame] | 91 | float level; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 92 | |
| 93 | level = output->zoom.spring_z.current; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 94 | |
Ander Conselvan de Oliveira | 434e8f3 | 2012-11-21 15:11:36 +0200 | [diff] [blame] | 95 | if (!output->zoom.active || level > output->zoom.max_level || |
| 96 | level == 0.0f) |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 97 | return; |
| 98 | |
Pekka Paalanen | 13fd446 | 2015-03-10 11:13:14 +0200 | [diff] [blame] | 99 | zoom_area_center_from_pointer(output, &x, &y); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 100 | |
| 101 | global_x = wl_fixed_to_double(x); |
| 102 | global_y = wl_fixed_to_double(y); |
| 103 | |
Derek Foreman | 7cb916e | 2015-03-24 11:36:15 -0500 | [diff] [blame] | 104 | output->zoom.trans_x = global_x - output->width / 2; |
| 105 | output->zoom.trans_y = global_y - output->height / 2; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 106 | |
Jason Ekstrand | 87535e2 | 2014-05-20 22:45:02 -0500 | [diff] [blame] | 107 | if (output->zoom.trans_x < 0) |
| 108 | output->zoom.trans_x = 0; |
| 109 | if (output->zoom.trans_y < 0) |
| 110 | output->zoom.trans_y = 0; |
| 111 | if (output->zoom.trans_x > level * output->width) |
| 112 | output->zoom.trans_x = level * output->width; |
| 113 | if (output->zoom.trans_y > level * output->height) |
| 114 | output->zoom.trans_y = level * output->height; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | static void |
Pekka Paalanen | 9808708 | 2015-03-10 12:05:44 +0200 | [diff] [blame] | 118 | weston_zoom_transition(struct weston_output *output) |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 119 | { |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 120 | if (output->zoom.level != output->zoom.spring_z.current) { |
| 121 | output->zoom.spring_z.target = output->zoom.level; |
| 122 | if (wl_list_empty(&output->zoom.animation_z.link)) { |
| 123 | output->zoom.animation_z.frame_counter = 0; |
| 124 | wl_list_insert(output->animation_list.prev, |
| 125 | &output->zoom.animation_z.link); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | output->dirty = 1; |
| 130 | weston_output_damage(output); |
| 131 | } |
| 132 | |
| 133 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 134 | weston_output_update_zoom(struct weston_output *output) |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 135 | { |
Kristian Høgsberg | ef6f136 | 2012-08-10 10:07:55 -0400 | [diff] [blame] | 136 | struct weston_seat *seat = weston_zoom_pick_seat(output->compositor); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 137 | |
Pekka Paalanen | 13fd446 | 2015-03-10 11:13:14 +0200 | [diff] [blame] | 138 | output->zoom.current.x = seat->pointer->x; |
| 139 | output->zoom.current.y = seat->pointer->y; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 140 | |
Pekka Paalanen | 9808708 | 2015-03-10 12:05:44 +0200 | [diff] [blame] | 141 | weston_zoom_transition(output); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 142 | weston_output_update_zoom_transform(output); |
| 143 | } |
| 144 | |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 145 | static void |
| 146 | motion(struct wl_listener *listener, void *data) |
| 147 | { |
| 148 | struct weston_output_zoom *zoom = |
| 149 | container_of(listener, struct weston_output_zoom, motion_listener); |
| 150 | struct weston_output *output = |
| 151 | container_of(zoom, struct weston_output, zoom); |
| 152 | |
| 153 | weston_output_update_zoom(output); |
| 154 | } |
| 155 | |
| 156 | WL_EXPORT void |
| 157 | weston_output_activate_zoom(struct weston_output *output) |
| 158 | { |
| 159 | struct weston_seat *seat = weston_zoom_pick_seat(output->compositor); |
| 160 | |
| 161 | if (output->zoom.active) |
| 162 | return; |
| 163 | |
Derek Foreman | a36eb50 | 2015-07-23 14:55:12 -0500 | [diff] [blame^] | 164 | output->zoom.active = true; |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 165 | output->disable_planes++; |
| 166 | wl_signal_add(&seat->pointer->motion_signal, |
| 167 | &output->zoom.motion_listener); |
| 168 | } |
| 169 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 170 | WL_EXPORT void |
| 171 | weston_output_init_zoom(struct weston_output *output) |
| 172 | { |
Derek Foreman | a36eb50 | 2015-07-23 14:55:12 -0500 | [diff] [blame^] | 173 | output->zoom.active = false; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 174 | output->zoom.increment = 0.07; |
| 175 | output->zoom.max_level = 0.95; |
| 176 | output->zoom.level = 0.0; |
| 177 | output->zoom.trans_x = 0.0; |
| 178 | output->zoom.trans_y = 0.0; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 179 | weston_spring_init(&output->zoom.spring_z, 250.0, 0.0, 0.0); |
| 180 | output->zoom.spring_z.friction = 1000; |
| 181 | output->zoom.animation_z.frame = weston_zoom_frame_z; |
| 182 | wl_list_init(&output->zoom.animation_z.link); |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 183 | output->zoom.motion_listener.notify = motion; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 184 | } |