blob: 064d6a8494992741ceb35d23359ee89c67d8e9a5 [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
Pekka Paalanen3d5d9472019-03-28 16:28:47 +020033#include <libweston/libweston.h>
Marius Vlad63ef0782019-07-16 23:34:14 +030034#include "backend.h"
Marius Vlad4e1d0972019-07-10 20:56:04 +030035#include "libweston-internal.h"
Kristian Høgsberg583a2362012-06-25 17:13:58 -040036#include "text-cursor-position-server-protocol.h"
Jon Cruz867d50e2015-06-15 15:37:10 -070037#include "shared/helpers.h"
Kristian Høgsberg583a2362012-06-25 17:13:58 -040038
Scott Moreau429490d2012-06-17 18:10:59 -060039static void
40weston_zoom_frame_z(struct weston_animation *animation,
Alexandros Frantzis8250a612017-11-16 18:20:52 +020041 struct weston_output *output,
42 const struct timespec *time)
Scott Moreau429490d2012-06-17 18:10:59 -060043{
44 if (animation->frame_counter <= 1)
Alexandros Frantzis8250a612017-11-16 18:20:52 +020045 output->zoom.spring_z.timestamp = *time;
Scott Moreau429490d2012-06-17 18:10:59 -060046
Alexandros Frantzis8250a612017-11-16 18:20:52 +020047 weston_spring_update(&output->zoom.spring_z, time);
Scott Moreau429490d2012-06-17 18:10:59 -060048
49 if (output->zoom.spring_z.current > output->zoom.max_level)
50 output->zoom.spring_z.current = output->zoom.max_level;
51 else if (output->zoom.spring_z.current < 0.0)
52 output->zoom.spring_z.current = 0.0;
53
54 if (weston_spring_done(&output->zoom.spring_z)) {
Ville Syrjäläaa628d02012-11-16 11:48:47 +020055 if (output->zoom.active && output->zoom.level <= 0.0) {
Derek Foremana36eb502015-07-23 14:55:12 -050056 output->zoom.active = false;
Derek Foreman22276a52015-07-23 14:55:15 -050057 output->zoom.seat = NULL;
Ankit Nautiyal93dde242019-07-08 11:46:42 +053058 weston_output_disable_planes_decr(output);
Giulio Camuffo412b0242013-11-14 23:42:51 +010059 wl_list_remove(&output->zoom.motion_listener.link);
Kristian Høgsberg79af73e2012-08-03 15:45:23 -040060 }
Scott Moreau429490d2012-06-17 18:10:59 -060061 output->zoom.spring_z.current = output->zoom.level;
62 wl_list_remove(&animation->link);
63 wl_list_init(&animation->link);
64 }
65
66 output->dirty = 1;
67 weston_output_damage(output);
68}
69
Scott Moreau429490d2012-06-17 18:10:59 -060070static void
Derek Foreman859b52b2015-07-23 14:55:14 -050071zoom_area_center_from_point(struct weston_output *output,
Giulio Camuffo6850e7b2015-10-07 20:14:18 +030072 double *x, double *y)
Scott Moreau429490d2012-06-17 18:10:59 -060073{
74 float level = output->zoom.spring_z.current;
Scott Moreau429490d2012-06-17 18:10:59 -060075
Giulio Camuffoc5a011f2015-10-08 19:13:01 +030076 *x = (*x - output->x) * level + output->width / 2.;
77 *y = (*y - output->y) * level + output->height / 2.;
Scott Moreau429490d2012-06-17 18:10:59 -060078}
79
80static void
81weston_output_update_zoom_transform(struct weston_output *output)
82{
Giulio Camuffo6850e7b2015-10-07 20:14:18 +030083 double x = output->zoom.current.x; /* global pointer coords */
84 double y = output->zoom.current.y;
Jason Ekstrand87535e22014-05-20 22:45:02 -050085 float level;
Scott Moreau429490d2012-06-17 18:10:59 -060086
87 level = output->zoom.spring_z.current;
Scott Moreau429490d2012-06-17 18:10:59 -060088
Ander Conselvan de Oliveira434e8f32012-11-21 15:11:36 +020089 if (!output->zoom.active || level > output->zoom.max_level ||
90 level == 0.0f)
Scott Moreau429490d2012-06-17 18:10:59 -060091 return;
92
Derek Foreman859b52b2015-07-23 14:55:14 -050093 zoom_area_center_from_point(output, &x, &y);
Scott Moreau429490d2012-06-17 18:10:59 -060094
Giulio Camuffoc5a011f2015-10-08 19:13:01 +030095 output->zoom.trans_x = x - output->width / 2;
96 output->zoom.trans_y = y - output->height / 2;
Scott Moreau429490d2012-06-17 18:10:59 -060097
Jason Ekstrand87535e22014-05-20 22:45:02 -050098 if (output->zoom.trans_x < 0)
99 output->zoom.trans_x = 0;
100 if (output->zoom.trans_y < 0)
101 output->zoom.trans_y = 0;
102 if (output->zoom.trans_x > level * output->width)
103 output->zoom.trans_x = level * output->width;
104 if (output->zoom.trans_y > level * output->height)
105 output->zoom.trans_y = level * output->height;
Scott Moreau429490d2012-06-17 18:10:59 -0600106}
107
108static void
Pekka Paalanen98087082015-03-10 12:05:44 +0200109weston_zoom_transition(struct weston_output *output)
Scott Moreau429490d2012-06-17 18:10:59 -0600110{
Scott Moreau429490d2012-06-17 18:10:59 -0600111 if (output->zoom.level != output->zoom.spring_z.current) {
112 output->zoom.spring_z.target = output->zoom.level;
113 if (wl_list_empty(&output->zoom.animation_z.link)) {
114 output->zoom.animation_z.frame_counter = 0;
115 wl_list_insert(output->animation_list.prev,
116 &output->zoom.animation_z.link);
117 }
118 }
119
120 output->dirty = 1;
121 weston_output_damage(output);
122}
123
124WL_EXPORT void
Jason Ekstranda7af7042013-10-12 22:38:11 -0500125weston_output_update_zoom(struct weston_output *output)
Scott Moreau429490d2012-06-17 18:10:59 -0600126{
Derek Foreman22276a52015-07-23 14:55:15 -0500127 struct weston_seat *seat = output->zoom.seat;
Derek Foreman1281a362015-07-31 16:55:32 -0500128 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
Scott Moreau429490d2012-06-17 18:10:59 -0600129
Alexandros Frantzis1c3a40e2018-02-08 15:37:53 +0200130 if (!pointer)
131 return;
132
Derek Foreman25bd8a72015-07-23 14:55:13 -0500133 assert(output->zoom.active);
134
Giulio Camuffo6850e7b2015-10-07 20:14:18 +0300135 output->zoom.current.x = wl_fixed_to_double(pointer->x);
136 output->zoom.current.y = wl_fixed_to_double(pointer->y);
Scott Moreau429490d2012-06-17 18:10:59 -0600137
Pekka Paalanen98087082015-03-10 12:05:44 +0200138 weston_zoom_transition(output);
Scott Moreau429490d2012-06-17 18:10:59 -0600139 weston_output_update_zoom_transform(output);
140}
141
Giulio Camuffo412b0242013-11-14 23:42:51 +0100142static void
143motion(struct wl_listener *listener, void *data)
144{
145 struct weston_output_zoom *zoom =
146 container_of(listener, struct weston_output_zoom, motion_listener);
147 struct weston_output *output =
148 container_of(zoom, struct weston_output, zoom);
149
150 weston_output_update_zoom(output);
151}
152
153WL_EXPORT void
Derek Foreman22276a52015-07-23 14:55:15 -0500154weston_output_activate_zoom(struct weston_output *output,
155 struct weston_seat *seat)
Giulio Camuffo412b0242013-11-14 23:42:51 +0100156{
Derek Foreman1281a362015-07-31 16:55:32 -0500157 struct weston_pointer *pointer = weston_seat_get_pointer(seat);
158
Alexandros Frantzis1c3a40e2018-02-08 15:37:53 +0200159 if (!pointer || output->zoom.active)
Giulio Camuffo412b0242013-11-14 23:42:51 +0100160 return;
161
Derek Foremana36eb502015-07-23 14:55:12 -0500162 output->zoom.active = true;
Derek Foreman22276a52015-07-23 14:55:15 -0500163 output->zoom.seat = seat;
Ankit Nautiyal93dde242019-07-08 11:46:42 +0530164 weston_output_disable_planes_incr(output);
Derek Foreman1281a362015-07-31 16:55:32 -0500165 wl_signal_add(&pointer->motion_signal,
Giulio Camuffo412b0242013-11-14 23:42:51 +0100166 &output->zoom.motion_listener);
167}
168
Scott Moreau429490d2012-06-17 18:10:59 -0600169WL_EXPORT void
170weston_output_init_zoom(struct weston_output *output)
171{
Derek Foremana36eb502015-07-23 14:55:12 -0500172 output->zoom.active = false;
Derek Foreman22276a52015-07-23 14:55:15 -0500173 output->zoom.seat = NULL;
Scott Moreau429490d2012-06-17 18:10:59 -0600174 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 Moreau429490d2012-06-17 18:10:59 -0600179 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 Camuffo412b0242013-11-14 23:42:51 +0100183 output->zoom.motion_listener.notify = motion;
Scott Moreau429490d2012-06-17 18:10:59 -0600184}