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 | |
Derek Foreman | 25bd8a7 | 2015-07-23 14:55:13 -0500 | [diff] [blame] | 28 | #include <assert.h> |
Kristian Høgsberg | 583a236 | 2012-06-25 17:13:58 -0400 | [diff] [blame] | 29 | #include <stdlib.h> |
Derek Foreman | a36eb50 | 2015-07-23 14:55:12 -0500 | [diff] [blame] | 30 | #include <stdbool.h> |
Kristian Høgsberg | 583a236 | 2012-06-25 17:13:58 -0400 | [diff] [blame] | 31 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 32 | #include "compositor.h" |
Kristian Høgsberg | 583a236 | 2012-06-25 17:13:58 -0400 | [diff] [blame] | 33 | #include "text-cursor-position-server-protocol.h" |
Jon Cruz | 867d50e | 2015-06-15 15:37:10 -0700 | [diff] [blame] | 34 | #include "shared/helpers.h" |
Kristian Høgsberg | 583a236 | 2012-06-25 17:13:58 -0400 | [diff] [blame] | 35 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 36 | static void |
| 37 | weston_zoom_frame_z(struct weston_animation *animation, |
| 38 | struct weston_output *output, uint32_t msecs) |
| 39 | { |
| 40 | if (animation->frame_counter <= 1) |
| 41 | output->zoom.spring_z.timestamp = msecs; |
| 42 | |
| 43 | weston_spring_update(&output->zoom.spring_z, msecs); |
| 44 | |
| 45 | if (output->zoom.spring_z.current > output->zoom.max_level) |
| 46 | output->zoom.spring_z.current = output->zoom.max_level; |
| 47 | else if (output->zoom.spring_z.current < 0.0) |
| 48 | output->zoom.spring_z.current = 0.0; |
| 49 | |
| 50 | if (weston_spring_done(&output->zoom.spring_z)) { |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 51 | if (output->zoom.active && output->zoom.level <= 0.0) { |
Derek Foreman | a36eb50 | 2015-07-23 14:55:12 -0500 | [diff] [blame] | 52 | output->zoom.active = false; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 53 | output->zoom.seat = NULL; |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 54 | output->disable_planes--; |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 55 | wl_list_remove(&output->zoom.motion_listener.link); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 56 | } |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 57 | output->zoom.spring_z.current = output->zoom.level; |
| 58 | wl_list_remove(&animation->link); |
| 59 | wl_list_init(&animation->link); |
| 60 | } |
| 61 | |
| 62 | output->dirty = 1; |
| 63 | weston_output_damage(output); |
| 64 | } |
| 65 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 66 | static void |
Derek Foreman | 859b52b | 2015-07-23 14:55:14 -0500 | [diff] [blame] | 67 | zoom_area_center_from_point(struct weston_output *output, |
Giulio Camuffo | 6850e7b | 2015-10-07 20:14:18 +0300 | [diff] [blame^] | 68 | double *x, double *y) |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 69 | { |
| 70 | float level = output->zoom.spring_z.current; |
Giulio Camuffo | 6850e7b | 2015-10-07 20:14:18 +0300 | [diff] [blame^] | 71 | double offset_x = output->x; |
| 72 | double offset_y = output->y; |
| 73 | double w = output->width; |
| 74 | double h = 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; |
Giulio Camuffo | 6850e7b | 2015-10-07 20:14:18 +0300 | [diff] [blame^] | 84 | double x = output->zoom.current.x; /* global pointer coords */ |
| 85 | double 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 | |
Derek Foreman | 859b52b | 2015-07-23 14:55:14 -0500 | [diff] [blame] | 94 | zoom_area_center_from_point(output, &x, &y); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 95 | |
Giulio Camuffo | 6850e7b | 2015-10-07 20:14:18 +0300 | [diff] [blame^] | 96 | global_x = x; |
| 97 | global_y = y; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 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 | { |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 131 | struct weston_seat *seat = output->zoom.seat; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 132 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 133 | |
Derek Foreman | 25bd8a7 | 2015-07-23 14:55:13 -0500 | [diff] [blame] | 134 | assert(output->zoom.active); |
| 135 | |
Giulio Camuffo | 6850e7b | 2015-10-07 20:14:18 +0300 | [diff] [blame^] | 136 | output->zoom.current.x = wl_fixed_to_double(pointer->x); |
| 137 | output->zoom.current.y = wl_fixed_to_double(pointer->y); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 138 | |
Pekka Paalanen | 9808708 | 2015-03-10 12:05:44 +0200 | [diff] [blame] | 139 | weston_zoom_transition(output); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 140 | weston_output_update_zoom_transform(output); |
| 141 | } |
| 142 | |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 143 | static void |
| 144 | motion(struct wl_listener *listener, void *data) |
| 145 | { |
| 146 | struct weston_output_zoom *zoom = |
| 147 | container_of(listener, struct weston_output_zoom, motion_listener); |
| 148 | struct weston_output *output = |
| 149 | container_of(zoom, struct weston_output, zoom); |
| 150 | |
| 151 | weston_output_update_zoom(output); |
| 152 | } |
| 153 | |
| 154 | WL_EXPORT void |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 155 | weston_output_activate_zoom(struct weston_output *output, |
| 156 | struct weston_seat *seat) |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 157 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 158 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 159 | |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 160 | if (output->zoom.active) |
| 161 | return; |
| 162 | |
Derek Foreman | a36eb50 | 2015-07-23 14:55:12 -0500 | [diff] [blame] | 163 | output->zoom.active = true; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 164 | output->zoom.seat = seat; |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 165 | output->disable_planes++; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 166 | wl_signal_add(&pointer->motion_signal, |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 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; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 174 | output->zoom.seat = NULL; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 175 | output->zoom.increment = 0.07; |
| 176 | output->zoom.max_level = 0.95; |
| 177 | output->zoom.level = 0.0; |
| 178 | output->zoom.trans_x = 0.0; |
| 179 | output->zoom.trans_y = 0.0; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 180 | weston_spring_init(&output->zoom.spring_z, 250.0, 0.0, 0.0); |
| 181 | output->zoom.spring_z.friction = 1000; |
| 182 | output->zoom.animation_z.frame = weston_zoom_frame_z; |
| 183 | wl_list_init(&output->zoom.animation_z.link); |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 184 | output->zoom.motion_listener.notify = motion; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 185 | } |