blob: a1a1ab21986803a635eb6e76392b5a57347fbdc2 [file] [log] [blame]
Scott Moreau429490d2012-06-17 18:10:59 -06001/*
2 * Copyright © 2012 Scott Moreau
3 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -07004 * 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 Moreau429490d2012-06-17 18:10:59 -060011 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -070012 * 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 Moreau429490d2012-06-17 18:10:59 -060024 */
25
Daniel Stonec228e232013-05-22 18:03:19 +030026#include "config.h"
27
Derek Foreman25bd8a72015-07-23 14:55:13 -050028#include <assert.h>
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030029#include <stdint.h>
Kristian Høgsberg583a2362012-06-25 17:13:58 -040030#include <stdlib.h>
Derek Foremana36eb502015-07-23 14:55:12 -050031#include <stdbool.h>
Kristian Høgsberg583a2362012-06-25 17:13:58 -040032
Scott Moreau429490d2012-06-17 18:10:59 -060033#include "compositor.h"
Kristian Høgsberg583a2362012-06-25 17:13:58 -040034#include "text-cursor-position-server-protocol.h"
Jon Cruz867d50e2015-06-15 15:37:10 -070035#include "shared/helpers.h"
Kristian Høgsberg583a2362012-06-25 17:13:58 -040036
Scott Moreau429490d2012-06-17 18:10:59 -060037static void
38weston_zoom_frame_z(struct weston_animation *animation,
39 struct weston_output *output, uint32_t msecs)
40{
41 if (animation->frame_counter <= 1)
42 output->zoom.spring_z.timestamp = msecs;
43
44 weston_spring_update(&output->zoom.spring_z, msecs);
45
46 if (output->zoom.spring_z.current > output->zoom.max_level)
47 output->zoom.spring_z.current = output->zoom.max_level;
48 else if (output->zoom.spring_z.current < 0.0)
49 output->zoom.spring_z.current = 0.0;
50
51 if (weston_spring_done(&output->zoom.spring_z)) {
Ville Syrjäläaa628d02012-11-16 11:48:47 +020052 if (output->zoom.active && output->zoom.level <= 0.0) {
Derek Foremana36eb502015-07-23 14:55:12 -050053 output->zoom.active = false;
Derek Foreman22276a52015-07-23 14:55:15 -050054 output->zoom.seat = NULL;
Kristian Høgsberg79af73e2012-08-03 15:45:23 -040055 output->disable_planes--;
Giulio Camuffo412b0242013-11-14 23:42:51 +010056 wl_list_remove(&output->zoom.motion_listener.link);
Kristian Høgsberg79af73e2012-08-03 15:45:23 -040057 }
Scott Moreau429490d2012-06-17 18:10:59 -060058 output->zoom.spring_z.current = output->zoom.level;
59 wl_list_remove(&animation->link);
60 wl_list_init(&animation->link);
61 }
62
63 output->dirty = 1;
64 weston_output_damage(output);
65}
66
Scott Moreau429490d2012-06-17 18:10:59 -060067static void
Derek Foreman859b52b2015-07-23 14:55:14 -050068zoom_area_center_from_point(struct weston_output *output,
Giulio Camuffo6850e7b2015-10-07 20:14:18 +030069 double *x, double *y)
Scott Moreau429490d2012-06-17 18:10:59 -060070{
71 float level = output->zoom.spring_z.current;
Scott Moreau429490d2012-06-17 18:10:59 -060072
Giulio Camuffoc5a011f2015-10-08 19:13:01 +030073 *x = (*x - output->x) * level + output->width / 2.;
74 *y = (*y - output->y) * level + output->height / 2.;
Scott Moreau429490d2012-06-17 18:10:59 -060075}
76
77static void
78weston_output_update_zoom_transform(struct weston_output *output)
79{
Giulio Camuffo6850e7b2015-10-07 20:14:18 +030080 double x = output->zoom.current.x; /* global pointer coords */
81 double y = output->zoom.current.y;
Jason Ekstrand87535e22014-05-20 22:45:02 -050082 float level;
Scott Moreau429490d2012-06-17 18:10:59 -060083
84 level = output->zoom.spring_z.current;
Scott Moreau429490d2012-06-17 18:10:59 -060085
Ander Conselvan de Oliveira434e8f32012-11-21 15:11:36 +020086 if (!output->zoom.active || level > output->zoom.max_level ||
87 level == 0.0f)
Scott Moreau429490d2012-06-17 18:10:59 -060088 return;
89
Derek Foreman859b52b2015-07-23 14:55:14 -050090 zoom_area_center_from_point(output, &x, &y);
Scott Moreau429490d2012-06-17 18:10:59 -060091
Giulio Camuffoc5a011f2015-10-08 19:13:01 +030092 output->zoom.trans_x = x - output->width / 2;
93 output->zoom.trans_y = y - output->height / 2;
Scott Moreau429490d2012-06-17 18:10:59 -060094
Jason Ekstrand87535e22014-05-20 22:45:02 -050095 if (output->zoom.trans_x < 0)
96 output->zoom.trans_x = 0;
97 if (output->zoom.trans_y < 0)
98 output->zoom.trans_y = 0;
99 if (output->zoom.trans_x > level * output->width)
100 output->zoom.trans_x = level * output->width;
101 if (output->zoom.trans_y > level * output->height)
102 output->zoom.trans_y = level * output->height;
Scott Moreau429490d2012-06-17 18:10:59 -0600103}
104
105static void
Pekka Paalanen98087082015-03-10 12:05:44 +0200106weston_zoom_transition(struct weston_output *output)
Scott Moreau429490d2012-06-17 18:10:59 -0600107{
Scott Moreau429490d2012-06-17 18:10:59 -0600108 if (output->zoom.level != output->zoom.spring_z.current) {
109 output->zoom.spring_z.target = output->zoom.level;
110 if (wl_list_empty(&output->zoom.animation_z.link)) {
111 output->zoom.animation_z.frame_counter = 0;
112 wl_list_insert(output->animation_list.prev,
113 &output->zoom.animation_z.link);
114 }
115 }
116
117 output->dirty = 1;
118 weston_output_damage(output);
119}
120
121WL_EXPORT void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500122weston_output_update_zoom(struct weston_output *output)
Scott Moreau429490d2012-06-17 18:10:59 -0600123{
Derek Foreman22276a52015-07-23 14:55:15 -0500124 struct weston_seat *seat = output->zoom.seat;
Derek Foreman1281a362015-07-31 16:55:32 -0500125 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
Scott Moreau429490d2012-06-17 18:10:59 -0600126
Derek Foreman25bd8a72015-07-23 14:55:13 -0500127 assert(output->zoom.active);
128
Giulio Camuffo6850e7b2015-10-07 20:14:18 +0300129 output->zoom.current.x = wl_fixed_to_double(pointer->x);
130 output->zoom.current.y = wl_fixed_to_double(pointer->y);
Scott Moreau429490d2012-06-17 18:10:59 -0600131
Pekka Paalanen98087082015-03-10 12:05:44 +0200132 weston_zoom_transition(output);
Scott Moreau429490d2012-06-17 18:10:59 -0600133 weston_output_update_zoom_transform(output);
134}
135
Giulio Camuffo412b0242013-11-14 23:42:51 +0100136static void
137motion(struct wl_listener *listener, void *data)
138{
139 struct weston_output_zoom *zoom =
140 container_of(listener, struct weston_output_zoom, motion_listener);
141 struct weston_output *output =
142 container_of(zoom, struct weston_output, zoom);
143
144 weston_output_update_zoom(output);
145}
146
147WL_EXPORT void
Derek Foreman22276a52015-07-23 14:55:15 -0500148weston_output_activate_zoom(struct weston_output *output,
149 struct weston_seat *seat)
Giulio Camuffo412b0242013-11-14 23:42:51 +0100150{
Derek Foreman1281a362015-07-31 16:55:32 -0500151 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
152
Giulio Camuffo412b0242013-11-14 23:42:51 +0100153 if (output->zoom.active)
154 return;
155
Derek Foremana36eb502015-07-23 14:55:12 -0500156 output->zoom.active = true;
Derek Foreman22276a52015-07-23 14:55:15 -0500157 output->zoom.seat = seat;
Giulio Camuffo412b0242013-11-14 23:42:51 +0100158 output->disable_planes++;
Derek Foreman1281a362015-07-31 16:55:32 -0500159 wl_signal_add(&pointer->motion_signal,
Giulio Camuffo412b0242013-11-14 23:42:51 +0100160 &output->zoom.motion_listener);
161}
162
Scott Moreau429490d2012-06-17 18:10:59 -0600163WL_EXPORT void
164weston_output_init_zoom(struct weston_output *output)
165{
Derek Foremana36eb502015-07-23 14:55:12 -0500166 output->zoom.active = false;
Derek Foreman22276a52015-07-23 14:55:15 -0500167 output->zoom.seat = NULL;
Scott Moreau429490d2012-06-17 18:10:59 -0600168 output->zoom.increment = 0.07;
169 output->zoom.max_level = 0.95;
170 output->zoom.level = 0.0;
171 output->zoom.trans_x = 0.0;
172 output->zoom.trans_y = 0.0;
Scott Moreau429490d2012-06-17 18:10:59 -0600173 weston_spring_init(&output->zoom.spring_z, 250.0, 0.0, 0.0);
174 output->zoom.spring_z.friction = 1000;
175 output->zoom.animation_z.frame = weston_zoom_frame_z;
176 wl_list_init(&output->zoom.animation_z.link);
Giulio Camuffo412b0242013-11-14 23:42:51 +0100177 output->zoom.motion_listener.notify = motion;
Scott Moreau429490d2012-06-17 18:10:59 -0600178}