2013-04-18 23:07:39 +04:00
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 Intel Corporation
|
2017-11-29 04:42:47 +03:00
|
|
|
|
* Copyright 2017-2018 Collabora, Ltd.
|
|
|
|
|
* Copyright 2017-2018 General Electric Company
|
2013-04-18 23:07:39 +04:00
|
|
|
|
*
|
2015-06-12 01:35:43 +03:00
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
* the following conditions:
|
2013-04-18 23:07:39 +04:00
|
|
|
|
*
|
2015-06-12 01:35:43 +03:00
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
|
* portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
2013-04-18 23:07:39 +04:00
|
|
|
|
*/
|
|
|
|
|
|
2013-08-15 04:10:24 +04:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2016-07-22 12:56:31 +03:00
|
|
|
|
#include <stdbool.h>
|
2013-04-18 23:07:39 +04:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string.h>
|
2013-04-18 23:40:10 +04:00
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <unistd.h>
|
2015-04-30 12:56:37 +03:00
|
|
|
|
#include <values.h>
|
2013-06-24 19:52:44 +04:00
|
|
|
|
#include <fcntl.h>
|
2013-12-14 00:10:56 +04:00
|
|
|
|
#include <limits.h>
|
2019-04-27 00:57:31 +03:00
|
|
|
|
#include <errno.h>
|
2021-01-20 11:34:09 +03:00
|
|
|
|
#include <linux/input.h>
|
2013-04-18 23:07:39 +04:00
|
|
|
|
|
2015-06-16 01:37:08 +03:00
|
|
|
|
#include "shared/helpers.h"
|
2015-06-16 01:37:07 +03:00
|
|
|
|
#include "shared/os-compatibility.h"
|
2017-11-24 19:01:46 +03:00
|
|
|
|
#include "shared/timespec-util.h"
|
2019-03-28 17:28:47 +03:00
|
|
|
|
#include <libweston/libweston.h>
|
2019-07-16 23:44:21 +03:00
|
|
|
|
#include "backend.h"
|
2019-07-10 14:48:39 +03:00
|
|
|
|
#include "libweston-internal.h"
|
2016-11-24 18:30:41 +03:00
|
|
|
|
#include "relative-pointer-unstable-v1-server-protocol.h"
|
|
|
|
|
#include "pointer-constraints-unstable-v1-server-protocol.h"
|
2018-02-16 19:44:16 +03:00
|
|
|
|
#include "input-timestamps-unstable-v1-server-protocol.h"
|
2021-01-20 11:05:45 +03:00
|
|
|
|
#include "tablet-unstable-v2-server-protocol.h"
|
2016-07-22 12:56:31 +03:00
|
|
|
|
|
|
|
|
|
enum pointer_constraint_type {
|
|
|
|
|
POINTER_CONSTRAINT_TYPE_LOCK,
|
|
|
|
|
POINTER_CONSTRAINT_TYPE_CONFINE,
|
|
|
|
|
};
|
|
|
|
|
|
2015-04-30 12:56:37 +03:00
|
|
|
|
enum motion_direction {
|
|
|
|
|
MOTION_DIRECTION_POSITIVE_X = 1 << 0,
|
|
|
|
|
MOTION_DIRECTION_NEGATIVE_X = 1 << 1,
|
|
|
|
|
MOTION_DIRECTION_POSITIVE_Y = 1 << 2,
|
|
|
|
|
MOTION_DIRECTION_NEGATIVE_Y = 1 << 3,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct line {
|
2022-02-02 17:18:18 +03:00
|
|
|
|
struct weston_coord a;
|
|
|
|
|
struct weston_coord b;
|
2015-04-30 12:56:37 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct border {
|
|
|
|
|
struct line line;
|
|
|
|
|
enum motion_direction blocking_dir;
|
|
|
|
|
};
|
|
|
|
|
|
2016-07-22 12:56:31 +03:00
|
|
|
|
static void
|
|
|
|
|
maybe_warp_confined_pointer(struct weston_pointer_constraint *constraint);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
static void
|
|
|
|
|
empty_region(pixman_region32_t *region)
|
|
|
|
|
{
|
|
|
|
|
pixman_region32_fini(region);
|
|
|
|
|
pixman_region32_init(region);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 12:56:31 +03:00
|
|
|
|
static void
|
|
|
|
|
region_init_infinite(pixman_region32_t *region)
|
|
|
|
|
{
|
|
|
|
|
pixman_region32_init_rect(region, INT32_MIN, INT32_MIN,
|
|
|
|
|
UINT32_MAX, UINT32_MAX);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 15:05:50 +03:00
|
|
|
|
static void
|
|
|
|
|
send_timestamp(struct wl_resource *resource,
|
|
|
|
|
const struct timespec *time)
|
|
|
|
|
{
|
|
|
|
|
uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
|
|
|
|
|
|
|
|
|
|
timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
|
|
|
|
|
zwp_input_timestamps_v1_send_timestamp(resource, tv_sec_hi, tv_sec_lo,
|
|
|
|
|
tv_nsec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
send_timestamps_for_input_resource(struct wl_resource *input_resource,
|
|
|
|
|
struct wl_list *list,
|
|
|
|
|
const struct timespec *time)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, list) {
|
|
|
|
|
if (wl_resource_get_user_data(resource) == input_resource)
|
|
|
|
|
send_timestamp(resource, time);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
remove_input_resource_from_timestamps(struct wl_resource *input_resource,
|
|
|
|
|
struct wl_list *list)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, list) {
|
|
|
|
|
if (wl_resource_get_user_data(resource) == input_resource)
|
|
|
|
|
wl_resource_set_user_data(resource, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 04:42:47 +03:00
|
|
|
|
/** Register a touchscreen input device
|
|
|
|
|
*
|
|
|
|
|
* \param touch The parent weston_touch that identifies the seat.
|
|
|
|
|
* \param syspath Unique device name.
|
|
|
|
|
* \param backend_data Backend private data if necessary.
|
|
|
|
|
* \param ops Calibration operations, or NULL for not able to run calibration.
|
|
|
|
|
* \return New touch device, or NULL on failure.
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT struct weston_touch_device *
|
|
|
|
|
weston_touch_create_touch_device(struct weston_touch *touch,
|
|
|
|
|
const char *syspath,
|
|
|
|
|
void *backend_data,
|
|
|
|
|
const struct weston_touch_device_ops *ops)
|
|
|
|
|
{
|
|
|
|
|
struct weston_touch_device *device;
|
|
|
|
|
|
|
|
|
|
assert(syspath);
|
|
|
|
|
if (ops) {
|
|
|
|
|
assert(ops->get_output);
|
|
|
|
|
assert(ops->get_calibration_head_name);
|
|
|
|
|
assert(ops->get_calibration);
|
|
|
|
|
assert(ops->set_calibration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
device = zalloc(sizeof *device);
|
|
|
|
|
if (!device)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
wl_signal_init(&device->destroy_signal);
|
|
|
|
|
|
|
|
|
|
device->syspath = strdup(syspath);
|
|
|
|
|
if (!device->syspath) {
|
|
|
|
|
free(device);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
device->backend_data = backend_data;
|
|
|
|
|
device->ops = ops;
|
|
|
|
|
|
|
|
|
|
device->aggregate = touch;
|
|
|
|
|
wl_list_insert(touch->device_list.prev, &device->link);
|
|
|
|
|
|
|
|
|
|
return device;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Destroy the touch device. */
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_touch_device_destroy(struct weston_touch_device *device)
|
|
|
|
|
{
|
|
|
|
|
wl_list_remove(&device->link);
|
|
|
|
|
wl_signal_emit(&device->destroy_signal, device);
|
|
|
|
|
free(device->syspath);
|
|
|
|
|
free(device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Is it possible to run calibration on this touch device? */
|
|
|
|
|
WL_EXPORT bool
|
|
|
|
|
weston_touch_device_can_calibrate(struct weston_touch_device *device)
|
|
|
|
|
{
|
|
|
|
|
return !!device->ops;
|
|
|
|
|
}
|
|
|
|
|
|
input: introduce touch event mode for calibrator
In addition to the normal touch event processing mode, introduce a new
mode for calibrating a touchscreen input device.
In the calibration mode, normal touch event processing is skipped, and
the raw events are forwarded to the calibrator instead. The calibrator
is not yet implemented, so the calls will be added in a following patch.
To switch between modes, two functions are added, one for entering each
mode. The mode switch happens only when no touches are down on any touch
device, to avoid confusing touch grabs and clients. To realise this, the
state machine has four states: prepare and actual state for both normal
and calibrator modes.
At this point nothing will attempt to change the touch event mode.
The new calibrator mode is necessary, because when calibrating a
touchscreen, the touch events must be routed to the calibration client
directly. The touch coordinates are expected to be wrong, so they cannot
go through the normal focus surface picking. The calibrator code also
cannot use the normal touch grab interface, because it needs to be able
to distinguish between different physical touch input devices, even if
they are part of the same weston_seat. This requirement makes
calibration special enough to warrant the new mode, a sort of "super
grab".
Co-developed by Louis-Francis and Pekka.
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
v1 Tested-by: Matt Hoosier <matt.hoosier@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-11-29 04:42:47 +03:00
|
|
|
|
static enum weston_touch_mode
|
|
|
|
|
weston_touch_device_get_mode(struct weston_touch_device *device)
|
|
|
|
|
{
|
|
|
|
|
return device->aggregate->seat->compositor->touch_mode;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 07:05:38 +03:00
|
|
|
|
static struct weston_pointer_client *
|
|
|
|
|
weston_pointer_client_create(struct wl_client *client)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_client *pointer_client;
|
|
|
|
|
|
|
|
|
|
pointer_client = zalloc(sizeof *pointer_client);
|
|
|
|
|
if (!pointer_client)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
pointer_client->client = client;
|
|
|
|
|
wl_list_init(&pointer_client->pointer_resources);
|
2014-10-22 23:21:17 +04:00
|
|
|
|
wl_list_init(&pointer_client->relative_pointer_resources);
|
2015-07-22 07:05:38 +03:00
|
|
|
|
|
|
|
|
|
return pointer_client;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
weston_pointer_client_destroy(struct weston_pointer_client *pointer_client)
|
|
|
|
|
{
|
2018-02-08 16:37:53 +03:00
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, &pointer_client->pointer_resources) {
|
|
|
|
|
wl_resource_set_user_data(resource, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource,
|
|
|
|
|
&pointer_client->relative_pointer_resources) {
|
|
|
|
|
wl_resource_set_user_data(resource, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_list_remove(&pointer_client->pointer_resources);
|
|
|
|
|
wl_list_remove(&pointer_client->relative_pointer_resources);
|
2015-07-22 07:05:38 +03:00
|
|
|
|
free(pointer_client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
weston_pointer_client_is_empty(struct weston_pointer_client *pointer_client)
|
|
|
|
|
{
|
2014-10-22 23:21:17 +04:00
|
|
|
|
return (wl_list_empty(&pointer_client->pointer_resources) &&
|
|
|
|
|
wl_list_empty(&pointer_client->relative_pointer_resources));
|
2015-07-22 07:05:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct weston_pointer_client *
|
|
|
|
|
weston_pointer_get_pointer_client(struct weston_pointer *pointer,
|
|
|
|
|
struct wl_client *client)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_client *pointer_client;
|
|
|
|
|
|
|
|
|
|
wl_list_for_each(pointer_client, &pointer->pointer_clients, link) {
|
|
|
|
|
if (pointer_client->client == client)
|
|
|
|
|
return pointer_client;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct weston_pointer_client *
|
|
|
|
|
weston_pointer_ensure_pointer_client(struct weston_pointer *pointer,
|
|
|
|
|
struct wl_client *client)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_client *pointer_client;
|
|
|
|
|
|
|
|
|
|
pointer_client = weston_pointer_get_pointer_client(pointer, client);
|
|
|
|
|
if (pointer_client)
|
|
|
|
|
return pointer_client;
|
|
|
|
|
|
|
|
|
|
pointer_client = weston_pointer_client_create(client);
|
|
|
|
|
wl_list_insert(&pointer->pointer_clients, &pointer_client->link);
|
|
|
|
|
|
|
|
|
|
if (pointer->focus &&
|
|
|
|
|
pointer->focus->surface->resource &&
|
|
|
|
|
wl_resource_get_client(pointer->focus->surface->resource) == client) {
|
|
|
|
|
pointer->focus_client = pointer_client;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pointer_client;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
weston_pointer_cleanup_pointer_client(struct weston_pointer *pointer,
|
|
|
|
|
struct weston_pointer_client *pointer_client)
|
|
|
|
|
{
|
|
|
|
|
if (weston_pointer_client_is_empty(pointer_client)) {
|
|
|
|
|
if (pointer->focus_client == pointer_client)
|
|
|
|
|
pointer->focus_client = NULL;
|
|
|
|
|
wl_list_remove(&pointer_client->link);
|
|
|
|
|
weston_pointer_client_destroy(pointer_client);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
unbind_pointer_client_resource(struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer *pointer = wl_resource_get_user_data(resource);
|
|
|
|
|
struct wl_client *client = wl_resource_get_client(resource);
|
|
|
|
|
struct weston_pointer_client *pointer_client;
|
|
|
|
|
|
|
|
|
|
wl_list_remove(wl_resource_get_link(resource));
|
2018-02-08 16:37:53 +03:00
|
|
|
|
|
|
|
|
|
if (pointer) {
|
|
|
|
|
pointer_client = weston_pointer_get_pointer_client(pointer,
|
|
|
|
|
client);
|
|
|
|
|
assert(pointer_client);
|
2018-02-20 15:06:26 +03:00
|
|
|
|
remove_input_resource_from_timestamps(resource,
|
|
|
|
|
&pointer->timestamps_list);
|
2018-02-08 16:37:53 +03:00
|
|
|
|
weston_pointer_cleanup_pointer_client(pointer, pointer_client);
|
|
|
|
|
}
|
2015-07-22 07:05:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
static void unbind_resource(struct wl_resource *resource)
|
|
|
|
|
{
|
2013-06-14 19:08:00 +04:00
|
|
|
|
wl_list_remove(wl_resource_get_link(resource));
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-07 01:21:44 +03:00
|
|
|
|
WL_EXPORT struct weston_coord_global
|
2014-10-22 23:21:17 +04:00
|
|
|
|
weston_pointer_motion_to_abs(struct weston_pointer *pointer,
|
2023-02-07 01:21:44 +03:00
|
|
|
|
struct weston_pointer_motion_event *event)
|
2014-10-22 23:21:17 +04:00
|
|
|
|
{
|
2023-02-07 01:21:44 +03:00
|
|
|
|
struct weston_coord_global pos;
|
|
|
|
|
|
2014-10-22 23:21:17 +04:00
|
|
|
|
if (event->mask & WESTON_POINTER_MOTION_ABS) {
|
2023-02-07 01:21:44 +03:00
|
|
|
|
return event->abs;
|
2014-10-22 23:21:17 +04:00
|
|
|
|
} else if (event->mask & WESTON_POINTER_MOTION_REL) {
|
2022-02-04 01:40:10 +03:00
|
|
|
|
pos.c = weston_coord_add(pointer->pos.c, event->rel);
|
2023-02-07 01:21:44 +03:00
|
|
|
|
return pos;
|
2014-10-22 23:21:17 +04:00
|
|
|
|
}
|
2023-02-07 01:21:44 +03:00
|
|
|
|
|
|
|
|
|
assert(!"invalid motion event");
|
|
|
|
|
pos.c = weston_coord(0, 0);
|
|
|
|
|
return pos;
|
2014-10-22 23:21:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
weston_pointer_motion_to_rel(struct weston_pointer *pointer,
|
|
|
|
|
struct weston_pointer_motion_event *event,
|
2022-02-02 17:21:40 +03:00
|
|
|
|
struct weston_coord *rel,
|
|
|
|
|
struct weston_coord *rel_unaccel)
|
2014-10-22 23:21:17 +04:00
|
|
|
|
{
|
|
|
|
|
if (event->mask & WESTON_POINTER_MOTION_REL &&
|
|
|
|
|
event->mask & WESTON_POINTER_MOTION_REL_UNACCEL) {
|
2022-02-02 17:21:40 +03:00
|
|
|
|
*rel = event->rel;
|
|
|
|
|
*rel_unaccel = event->rel_unaccel;
|
2014-10-22 23:21:17 +04:00
|
|
|
|
return true;
|
|
|
|
|
} else if (event->mask & WESTON_POINTER_MOTION_REL) {
|
2022-02-02 17:21:40 +03:00
|
|
|
|
*rel = event->rel;
|
|
|
|
|
*rel_unaccel = event->rel;
|
2014-10-22 23:21:17 +04:00
|
|
|
|
return true;
|
|
|
|
|
} else if (event->mask & WESTON_POINTER_MOTION_REL_UNACCEL) {
|
2022-02-02 17:21:40 +03:00
|
|
|
|
*rel = event->rel_unaccel;
|
|
|
|
|
*rel_unaccel = event->rel_unaccel;
|
2014-10-22 23:21:17 +04:00
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-18 01:04:08 +04:00
|
|
|
|
WL_EXPORT void
|
2013-05-07 05:51:21 +04:00
|
|
|
|
weston_seat_repick(struct weston_seat *seat)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
{
|
2015-08-01 00:55:32 +03:00
|
|
|
|
const struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2015-06-03 23:53:23 +03:00
|
|
|
|
if (!pointer)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
return;
|
|
|
|
|
|
2015-06-03 23:53:23 +03:00
|
|
|
|
pointer->grab->interface->focus(pointer->grab);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
weston_compositor_idle_inhibit(struct weston_compositor *compositor)
|
|
|
|
|
{
|
|
|
|
|
weston_compositor_wake(compositor);
|
|
|
|
|
compositor->idle_inhibit++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
weston_compositor_idle_release(struct weston_compositor *compositor)
|
|
|
|
|
{
|
|
|
|
|
compositor->idle_inhibit--;
|
|
|
|
|
weston_compositor_wake(compositor);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-20 21:00:24 +04:00
|
|
|
|
static void
|
|
|
|
|
pointer_focus_view_destroyed(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer *pointer =
|
|
|
|
|
container_of(listener, struct weston_pointer,
|
|
|
|
|
focus_view_listener);
|
|
|
|
|
|
2015-05-11 23:40:11 +03:00
|
|
|
|
weston_pointer_clear_focus(pointer);
|
2013-11-20 21:00:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pointer_focus_resource_destroyed(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer *pointer =
|
|
|
|
|
container_of(listener, struct weston_pointer,
|
|
|
|
|
focus_resource_listener);
|
|
|
|
|
|
2015-05-11 23:40:11 +03:00
|
|
|
|
weston_pointer_clear_focus(pointer);
|
2013-11-20 21:00:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
keyboard_focus_resource_destroyed(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct weston_keyboard *keyboard =
|
|
|
|
|
container_of(listener, struct weston_keyboard,
|
|
|
|
|
focus_resource_listener);
|
|
|
|
|
|
|
|
|
|
weston_keyboard_set_focus(keyboard, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
touch_focus_view_destroyed(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct weston_touch *touch =
|
|
|
|
|
container_of(listener, struct weston_touch,
|
|
|
|
|
focus_view_listener);
|
|
|
|
|
|
2015-05-01 00:45:41 +03:00
|
|
|
|
weston_touch_set_focus(touch, NULL);
|
2013-11-20 21:00:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
touch_focus_resource_destroyed(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct weston_touch *touch =
|
|
|
|
|
container_of(listener, struct weston_touch,
|
|
|
|
|
focus_resource_listener);
|
|
|
|
|
|
2015-05-01 00:45:41 +03:00
|
|
|
|
weston_touch_set_focus(touch, NULL);
|
2013-11-20 21:00:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 11:11:41 +03:00
|
|
|
|
static void
|
|
|
|
|
tablet_tool_focus_view_destroyed(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct weston_tablet_tool *tool =
|
|
|
|
|
container_of(listener, struct weston_tablet_tool,
|
|
|
|
|
focus_view_listener);
|
|
|
|
|
|
|
|
|
|
weston_tablet_tool_set_focus(tool, NULL, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_tool_focus_resource_destroyed(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct weston_tablet_tool *tool =
|
|
|
|
|
container_of(listener, struct weston_tablet_tool,
|
|
|
|
|
focus_resource_listener);
|
|
|
|
|
|
|
|
|
|
weston_tablet_tool_set_focus(tool, NULL, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:07:39 +04:00
|
|
|
|
static void
|
2013-09-19 20:32:00 +04:00
|
|
|
|
move_resources(struct wl_list *destination, struct wl_list *source)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2013-09-19 20:32:00 +04:00
|
|
|
|
wl_list_insert_list(destination, source);
|
|
|
|
|
wl_list_init(source);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-19 20:32:00 +04:00
|
|
|
|
move_resources_for_client(struct wl_list *destination,
|
|
|
|
|
struct wl_list *source,
|
|
|
|
|
struct wl_client *client)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2013-09-19 20:32:00 +04:00
|
|
|
|
struct wl_resource *resource, *tmp;
|
|
|
|
|
wl_resource_for_each_safe(resource, tmp, source) {
|
|
|
|
|
if (wl_resource_get_client(resource) == client) {
|
|
|
|
|
wl_list_remove(wl_resource_get_link(resource));
|
|
|
|
|
wl_list_insert(destination,
|
|
|
|
|
wl_resource_get_link(resource));
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-10-29 02:32:02 +04:00
|
|
|
|
default_grab_pointer_focus(struct weston_pointer_grab *grab)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2013-05-07 06:15:05 +04:00
|
|
|
|
struct weston_pointer *pointer = grab->pointer;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
struct weston_view *view;
|
2022-10-28 22:09:34 +03:00
|
|
|
|
bool surface_jump = false;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
|
|
|
|
|
if (pointer->button_count > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-02-04 01:40:10 +03:00
|
|
|
|
view = weston_compositor_pick_view(pointer->seat->compositor,
|
|
|
|
|
pointer->pos);
|
2022-11-10 17:57:02 +03:00
|
|
|
|
if (view && view == pointer->focus) {
|
2022-02-03 02:23:33 +03:00
|
|
|
|
struct weston_coord_surface surf_pos;
|
2022-02-09 02:31:55 +03:00
|
|
|
|
|
2022-11-09 01:09:05 +03:00
|
|
|
|
weston_view_update_transform(view);
|
2022-02-09 02:31:55 +03:00
|
|
|
|
|
2022-02-04 01:40:10 +03:00
|
|
|
|
surf_pos = weston_coord_global_to_surface(view, pointer->pos);
|
2022-02-03 02:23:33 +03:00
|
|
|
|
if (pointer->sx != wl_fixed_from_double(surf_pos.c.x) ||
|
|
|
|
|
pointer->sy != wl_fixed_from_double(surf_pos.c.y))
|
2022-10-28 22:09:34 +03:00
|
|
|
|
surface_jump = true;
|
|
|
|
|
}
|
|
|
|
|
if (pointer->focus != view || surface_jump)
|
2022-10-28 22:06:24 +03:00
|
|
|
|
weston_pointer_set_focus(pointer, view);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 23:21:17 +04:00
|
|
|
|
static void
|
2016-08-12 11:41:32 +03:00
|
|
|
|
pointer_send_relative_motion(struct weston_pointer *pointer,
|
2017-11-24 19:01:46 +03:00
|
|
|
|
const struct timespec *time,
|
2016-08-12 11:41:32 +03:00
|
|
|
|
struct weston_pointer_motion_event *event)
|
2014-10-22 23:21:17 +04:00
|
|
|
|
{
|
|
|
|
|
uint64_t time_usec;
|
2022-02-02 17:21:40 +03:00
|
|
|
|
struct weston_coord rel, rel_unaccel;
|
2014-10-22 23:21:17 +04:00
|
|
|
|
struct wl_list *resource_list;
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
if (!pointer->focus_client)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!weston_pointer_motion_to_rel(pointer, event,
|
2022-02-02 17:21:40 +03:00
|
|
|
|
&rel,
|
|
|
|
|
&rel_unaccel))
|
2014-10-22 23:21:17 +04:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
resource_list = &pointer->focus_client->relative_pointer_resources;
|
2017-11-24 19:01:46 +03:00
|
|
|
|
time_usec = timespec_to_usec(&event->time);
|
2014-10-22 23:21:17 +04:00
|
|
|
|
if (time_usec == 0)
|
2017-11-24 19:01:46 +03:00
|
|
|
|
time_usec = timespec_to_usec(time);
|
2014-10-22 23:21:17 +04:00
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, resource_list) {
|
|
|
|
|
zwp_relative_pointer_v1_send_relative_motion(
|
|
|
|
|
resource,
|
|
|
|
|
(uint32_t) (time_usec >> 32),
|
|
|
|
|
(uint32_t) time_usec,
|
2022-02-02 17:21:40 +03:00
|
|
|
|
wl_fixed_from_double(rel.x),
|
|
|
|
|
wl_fixed_from_double(rel.y),
|
|
|
|
|
wl_fixed_from_double(rel_unaccel.x),
|
|
|
|
|
wl_fixed_from_double(rel_unaccel.y));
|
2014-10-22 23:21:17 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 12:54:55 +03:00
|
|
|
|
static void
|
2017-11-24 19:01:46 +03:00
|
|
|
|
pointer_send_motion(struct weston_pointer *pointer,
|
|
|
|
|
const struct timespec *time,
|
2016-08-12 11:41:32 +03:00
|
|
|
|
wl_fixed_t sx, wl_fixed_t sy)
|
2016-07-22 12:54:55 +03:00
|
|
|
|
{
|
|
|
|
|
struct wl_list *resource_list;
|
|
|
|
|
struct wl_resource *resource;
|
2017-11-24 19:01:46 +03:00
|
|
|
|
uint32_t msecs;
|
2016-07-22 12:54:55 +03:00
|
|
|
|
|
|
|
|
|
if (!pointer->focus_client)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
resource_list = &pointer->focus_client->pointer_resources;
|
2017-11-24 19:01:46 +03:00
|
|
|
|
msecs = timespec_to_msec(time);
|
2018-02-20 15:06:26 +03:00
|
|
|
|
wl_resource_for_each(resource, resource_list) {
|
|
|
|
|
send_timestamps_for_input_resource(resource,
|
2021-07-31 18:25:41 +03:00
|
|
|
|
&pointer->timestamps_list,
|
|
|
|
|
time);
|
2017-11-24 19:01:46 +03:00
|
|
|
|
wl_pointer_send_motion(resource, msecs, sx, sy);
|
2018-02-20 15:06:26 +03:00
|
|
|
|
}
|
2016-07-22 12:54:55 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
WL_EXPORT void
|
2017-11-24 19:01:46 +03:00
|
|
|
|
weston_pointer_send_motion(struct weston_pointer *pointer,
|
|
|
|
|
const struct timespec *time,
|
2016-08-12 11:41:32 +03:00
|
|
|
|
struct weston_pointer_motion_event *event)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2022-10-31 20:38:02 +03:00
|
|
|
|
wl_fixed_t old_sx;
|
|
|
|
|
wl_fixed_t old_sy;
|
2022-11-10 17:12:53 +03:00
|
|
|
|
struct weston_view *old_focus = pointer->focus;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
|
2014-10-05 23:39:14 +04:00
|
|
|
|
if (pointer->focus) {
|
2023-02-07 01:21:44 +03:00
|
|
|
|
struct weston_coord_global pos;
|
2022-02-09 02:31:55 +03:00
|
|
|
|
struct weston_coord_surface surf_pos;
|
|
|
|
|
|
2023-02-07 01:21:44 +03:00
|
|
|
|
pos = weston_pointer_motion_to_abs(pointer, event);
|
2022-10-31 20:38:02 +03:00
|
|
|
|
old_sx = pointer->sx;
|
|
|
|
|
old_sy = pointer->sy;
|
2022-11-09 01:09:05 +03:00
|
|
|
|
weston_view_update_transform(pointer->focus);
|
2022-02-09 02:31:55 +03:00
|
|
|
|
|
2023-02-07 01:21:44 +03:00
|
|
|
|
surf_pos = weston_coord_global_to_surface(pointer->focus, pos);
|
2022-02-09 02:31:55 +03:00
|
|
|
|
pointer->sx = wl_fixed_from_double(surf_pos.c.x);
|
|
|
|
|
pointer->sy = wl_fixed_from_double(surf_pos.c.y);
|
2014-10-05 23:39:14 +04:00
|
|
|
|
}
|
2014-02-06 05:14:42 +04:00
|
|
|
|
|
2014-10-05 23:39:14 +04:00
|
|
|
|
weston_pointer_move(pointer, event);
|
2013-11-15 02:42:52 +04:00
|
|
|
|
|
2022-11-10 17:12:53 +03:00
|
|
|
|
if (pointer->focus && old_focus == pointer->focus &&
|
2022-10-31 20:38:02 +03:00
|
|
|
|
(old_sx != pointer->sx || old_sy != pointer->sy)) {
|
2016-08-12 11:41:32 +03:00
|
|
|
|
pointer_send_motion(pointer, time,
|
|
|
|
|
pointer->sx, pointer->sy);
|
2013-05-09 05:03:21 +04:00
|
|
|
|
}
|
2014-10-22 23:21:17 +04:00
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
pointer_send_relative_motion(pointer, time, event);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-11-24 19:01:46 +03:00
|
|
|
|
default_grab_pointer_motion(struct weston_pointer_grab *grab,
|
|
|
|
|
const struct timespec *time,
|
2016-08-12 11:41:32 +03:00
|
|
|
|
struct weston_pointer_motion_event *event)
|
|
|
|
|
{
|
|
|
|
|
weston_pointer_send_motion(grab->pointer, time, event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Check if the pointer has focused resources.
|
|
|
|
|
*
|
|
|
|
|
* \param pointer The pointer to check for focused resources.
|
|
|
|
|
* \return Whether or not this pointer has focused resources
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT bool
|
|
|
|
|
weston_pointer_has_focus_resource(struct weston_pointer *pointer)
|
|
|
|
|
{
|
|
|
|
|
if (!pointer->focus_client)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (wl_list_empty(&pointer->focus_client->pointer_resources))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Send wl_pointer.button events to focused resources.
|
|
|
|
|
*
|
|
|
|
|
* \param pointer The pointer where the button events originates from.
|
|
|
|
|
* \param time The timestamp of the event
|
|
|
|
|
* \param button The button value of the event
|
2019-06-12 16:05:44 +03:00
|
|
|
|
* \param state The state enum value of the event
|
2016-08-12 11:41:32 +03:00
|
|
|
|
*
|
|
|
|
|
* For every resource that is currently in focus, send a wl_pointer.button event
|
|
|
|
|
* with the passed parameters. The focused resources are the wl_pointer
|
|
|
|
|
* resources of the client which currently has the surface with pointer focus.
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT void
|
2016-07-22 12:55:43 +03:00
|
|
|
|
weston_pointer_send_button(struct weston_pointer *pointer,
|
2017-11-16 19:20:55 +03:00
|
|
|
|
const struct timespec *time, uint32_t button,
|
2016-08-12 11:41:32 +03:00
|
|
|
|
enum wl_pointer_button_state state)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2016-07-22 12:55:43 +03:00
|
|
|
|
struct wl_display *display = pointer->seat->compositor->wl_display;
|
|
|
|
|
struct wl_list *resource_list;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
uint32_t serial;
|
2017-11-16 19:20:55 +03:00
|
|
|
|
uint32_t msecs;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
if (!weston_pointer_has_focus_resource(pointer))
|
2016-07-22 12:55:43 +03:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
resource_list = &pointer->focus_client->pointer_resources;
|
2016-08-12 11:41:32 +03:00
|
|
|
|
serial = wl_display_next_serial(display);
|
2017-11-16 19:20:55 +03:00
|
|
|
|
msecs = timespec_to_msec(time);
|
2018-02-20 15:06:26 +03:00
|
|
|
|
wl_resource_for_each(resource, resource_list) {
|
|
|
|
|
send_timestamps_for_input_resource(resource,
|
2021-07-31 18:25:41 +03:00
|
|
|
|
&pointer->timestamps_list,
|
|
|
|
|
time);
|
2017-11-16 19:20:55 +03:00
|
|
|
|
wl_pointer_send_button(resource, serial, msecs, button, state);
|
2018-02-20 15:06:26 +03:00
|
|
|
|
}
|
2016-07-22 12:55:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
default_grab_pointer_button(struct weston_pointer_grab *grab,
|
2017-11-16 19:20:55 +03:00
|
|
|
|
const struct timespec *time, uint32_t button,
|
2016-08-12 11:41:32 +03:00
|
|
|
|
enum wl_pointer_button_state state)
|
2016-07-22 12:55:43 +03:00
|
|
|
|
{
|
|
|
|
|
struct weston_pointer *pointer = grab->pointer;
|
|
|
|
|
struct weston_compositor *compositor = pointer->seat->compositor;
|
|
|
|
|
struct weston_view *view;
|
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
weston_pointer_send_button(pointer, time, button, state);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
|
|
|
|
|
if (pointer->button_count == 0 &&
|
2013-05-09 00:47:00 +04:00
|
|
|
|
state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
2022-02-04 01:40:10 +03:00
|
|
|
|
view = weston_compositor_pick_view(compositor,
|
|
|
|
|
pointer->pos);
|
2013-05-09 00:47:00 +04:00
|
|
|
|
|
2022-10-28 22:06:24 +03:00
|
|
|
|
weston_pointer_set_focus(pointer, view);
|
2013-05-09 00:47:00 +04:00
|
|
|
|
}
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-04 18:28:29 +04:00
|
|
|
|
/** Send wl_pointer.axis events to focused resources.
|
|
|
|
|
*
|
|
|
|
|
* \param pointer The pointer where the axis events originates from.
|
|
|
|
|
* \param time The timestamp of the event
|
2019-06-12 16:05:44 +03:00
|
|
|
|
* \param event The axis value of the event
|
2014-10-04 18:28:29 +04:00
|
|
|
|
*
|
|
|
|
|
* For every resource that is currently in focus, send a wl_pointer.axis event
|
|
|
|
|
* with the passed parameters. The focused resources are the wl_pointer
|
|
|
|
|
* resources of the client which currently has the surface with pointer focus.
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_pointer_send_axis(struct weston_pointer *pointer,
|
2017-11-16 19:20:56 +03:00
|
|
|
|
const struct timespec *time,
|
2016-01-18 08:58:17 +03:00
|
|
|
|
struct weston_pointer_axis_event *event)
|
2014-10-04 18:28:29 +04:00
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct wl_list *resource_list;
|
2017-11-16 19:20:56 +03:00
|
|
|
|
uint32_t msecs;
|
2014-10-04 18:28:29 +04:00
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
if (!weston_pointer_has_focus_resource(pointer))
|
2015-07-22 07:05:38 +03:00
|
|
|
|
return;
|
|
|
|
|
|
2016-01-18 09:38:22 +03:00
|
|
|
|
resource_list = &pointer->focus_client->pointer_resources;
|
2017-11-16 19:20:56 +03:00
|
|
|
|
msecs = timespec_to_msec(time);
|
2016-01-18 09:38:22 +03:00
|
|
|
|
wl_resource_for_each(resource, resource_list) {
|
|
|
|
|
if (event->has_discrete &&
|
|
|
|
|
wl_resource_get_version(resource) >=
|
|
|
|
|
WL_POINTER_AXIS_DISCRETE_SINCE_VERSION)
|
|
|
|
|
wl_pointer_send_axis_discrete(resource, event->axis,
|
|
|
|
|
event->discrete);
|
|
|
|
|
|
2018-02-20 15:06:26 +03:00
|
|
|
|
if (event->value) {
|
|
|
|
|
send_timestamps_for_input_resource(resource,
|
|
|
|
|
&pointer->timestamps_list,
|
|
|
|
|
time);
|
2017-11-16 19:20:56 +03:00
|
|
|
|
wl_pointer_send_axis(resource, msecs,
|
2016-03-22 18:44:54 +03:00
|
|
|
|
event->axis,
|
|
|
|
|
wl_fixed_from_double(event->value));
|
2018-02-20 15:06:26 +03:00
|
|
|
|
} else if (wl_resource_get_version(resource) >=
|
|
|
|
|
WL_POINTER_AXIS_STOP_SINCE_VERSION) {
|
|
|
|
|
send_timestamps_for_input_resource(resource,
|
|
|
|
|
&pointer->timestamps_list,
|
|
|
|
|
time);
|
2017-11-16 19:20:56 +03:00
|
|
|
|
wl_pointer_send_axis_stop(resource, msecs,
|
2016-01-18 09:38:22 +03:00
|
|
|
|
event->axis);
|
2018-02-20 15:06:26 +03:00
|
|
|
|
}
|
2016-01-18 09:38:22 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
/** Send wl_pointer.axis_source events to focused resources.
|
|
|
|
|
*
|
|
|
|
|
* \param pointer The pointer where the axis_source events originates from.
|
|
|
|
|
* \param source The axis_source enum value of the event
|
|
|
|
|
*
|
|
|
|
|
* For every resource that is currently in focus, send a wl_pointer.axis_source
|
|
|
|
|
* event with the passed parameter. The focused resources are the wl_pointer
|
|
|
|
|
* resources of the client which currently has the surface with pointer focus.
|
|
|
|
|
*/
|
2016-01-18 09:38:22 +03:00
|
|
|
|
WL_EXPORT void
|
2016-08-12 11:41:32 +03:00
|
|
|
|
weston_pointer_send_axis_source(struct weston_pointer *pointer,
|
|
|
|
|
enum wl_pointer_axis_source source)
|
2016-01-18 09:38:22 +03:00
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct wl_list *resource_list;
|
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
if (!weston_pointer_has_focus_resource(pointer))
|
2016-04-21 05:21:48 +03:00
|
|
|
|
return;
|
|
|
|
|
|
2016-01-18 09:38:22 +03:00
|
|
|
|
resource_list = &pointer->focus_client->pointer_resources;
|
|
|
|
|
wl_resource_for_each(resource, resource_list) {
|
|
|
|
|
if (wl_resource_get_version(resource) >=
|
|
|
|
|
WL_POINTER_AXIS_SOURCE_SINCE_VERSION) {
|
|
|
|
|
wl_pointer_send_axis_source(resource, source);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pointer_send_frame(struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
if (wl_resource_get_version(resource) >=
|
|
|
|
|
WL_POINTER_FRAME_SINCE_VERSION) {
|
|
|
|
|
wl_pointer_send_frame(resource);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
/** Send wl_pointer.frame events to focused resources.
|
|
|
|
|
*
|
|
|
|
|
* \param pointer The pointer where the frame events originates from.
|
|
|
|
|
*
|
|
|
|
|
* For every resource that is currently in focus, send a wl_pointer.frame event.
|
|
|
|
|
* The focused resources are the wl_pointer resources of the client which
|
|
|
|
|
* currently has the surface with pointer focus.
|
|
|
|
|
*/
|
2016-01-18 09:38:22 +03:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_pointer_send_frame(struct weston_pointer *pointer)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct wl_list *resource_list;
|
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
if (!weston_pointer_has_focus_resource(pointer))
|
2016-01-29 19:29:46 +03:00
|
|
|
|
return;
|
|
|
|
|
|
2015-07-22 07:05:38 +03:00
|
|
|
|
resource_list = &pointer->focus_client->pointer_resources;
|
2014-10-04 18:28:29 +04:00
|
|
|
|
wl_resource_for_each(resource, resource_list)
|
2016-01-18 09:38:22 +03:00
|
|
|
|
pointer_send_frame(resource);
|
2014-10-04 18:28:29 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
default_grab_pointer_axis(struct weston_pointer_grab *grab,
|
2017-11-16 19:20:56 +03:00
|
|
|
|
const struct timespec *time,
|
2016-01-18 08:58:17 +03:00
|
|
|
|
struct weston_pointer_axis_event *event)
|
2014-10-04 18:28:29 +04:00
|
|
|
|
{
|
2016-01-18 08:58:17 +03:00
|
|
|
|
weston_pointer_send_axis(grab->pointer, time, event);
|
2014-10-04 18:28:29 +04:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-18 09:38:22 +03:00
|
|
|
|
static void
|
|
|
|
|
default_grab_pointer_axis_source(struct weston_pointer_grab *grab,
|
2016-08-12 11:41:32 +03:00
|
|
|
|
enum wl_pointer_axis_source source)
|
2016-01-18 09:38:22 +03:00
|
|
|
|
{
|
|
|
|
|
weston_pointer_send_axis_source(grab->pointer, source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
default_grab_pointer_frame(struct weston_pointer_grab *grab)
|
|
|
|
|
{
|
|
|
|
|
weston_pointer_send_frame(grab->pointer);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-26 01:18:05 +04:00
|
|
|
|
static void
|
|
|
|
|
default_grab_pointer_cancel(struct weston_pointer_grab *grab)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-07 06:15:05 +04:00
|
|
|
|
static const struct weston_pointer_grab_interface
|
2013-04-18 23:07:39 +04:00
|
|
|
|
default_pointer_grab_interface = {
|
2013-10-29 02:32:02 +04:00
|
|
|
|
default_grab_pointer_focus,
|
|
|
|
|
default_grab_pointer_motion,
|
|
|
|
|
default_grab_pointer_button,
|
2014-10-04 18:28:29 +04:00
|
|
|
|
default_grab_pointer_axis,
|
2016-01-18 09:38:22 +03:00
|
|
|
|
default_grab_pointer_axis_source,
|
|
|
|
|
default_grab_pointer_frame,
|
2013-10-26 01:18:05 +04:00
|
|
|
|
default_grab_pointer_cancel,
|
2013-04-18 23:07:39 +04:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
/** Check if the touch has focused resources.
|
|
|
|
|
*
|
|
|
|
|
* \param touch The touch to check for focused resources.
|
|
|
|
|
* \return Whether or not this touch has focused resources
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT bool
|
|
|
|
|
weston_touch_has_focus_resource(struct weston_touch *touch)
|
|
|
|
|
{
|
|
|
|
|
if (!touch->focus)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (wl_list_empty(&touch->focus_resource_list))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Send wl_touch.down events to focused resources.
|
|
|
|
|
*
|
|
|
|
|
* \param touch The touch where the down events originates from.
|
|
|
|
|
* \param time The timestamp of the event
|
|
|
|
|
* \param touch_id The touch_id value of the event
|
2023-02-07 02:00:14 +03:00
|
|
|
|
* \param pos The global coordinate of the event
|
2016-08-12 11:41:32 +03:00
|
|
|
|
*
|
|
|
|
|
* For every resource that is currently in focus, send a wl_touch.down event
|
|
|
|
|
* with the passed parameters. The focused resources are the wl_touch
|
|
|
|
|
* resources of the client which currently has the surface with touch focus.
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT void
|
2017-11-16 19:20:58 +03:00
|
|
|
|
weston_touch_send_down(struct weston_touch *touch, const struct timespec *time,
|
2023-02-07 02:00:14 +03:00
|
|
|
|
int touch_id, struct weston_coord_global pos)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2013-07-22 20:31:38 +04:00
|
|
|
|
struct wl_display *display = touch->seat->compositor->wl_display;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
uint32_t serial;
|
2013-09-19 20:32:00 +04:00
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct wl_list *resource_list;
|
2022-02-09 02:31:55 +03:00
|
|
|
|
struct weston_coord_surface surf_pos;
|
2017-11-16 19:20:58 +03:00
|
|
|
|
uint32_t msecs;
|
2015-07-08 11:55:28 +03:00
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
if (!weston_touch_has_focus_resource(touch))
|
2016-02-02 21:18:48 +03:00
|
|
|
|
return;
|
|
|
|
|
|
2022-12-22 14:47:22 +03:00
|
|
|
|
weston_view_update_transform(touch->focus);
|
|
|
|
|
|
2023-02-07 02:00:14 +03:00
|
|
|
|
surf_pos = weston_coord_global_to_surface(touch->focus, pos);
|
2013-09-19 20:32:00 +04:00
|
|
|
|
|
|
|
|
|
resource_list = &touch->focus_resource_list;
|
2016-08-12 11:41:32 +03:00
|
|
|
|
serial = wl_display_next_serial(display);
|
2017-11-16 19:20:58 +03:00
|
|
|
|
msecs = timespec_to_msec(time);
|
2018-02-20 15:07:03 +03:00
|
|
|
|
wl_resource_for_each(resource, resource_list) {
|
|
|
|
|
send_timestamps_for_input_resource(resource,
|
|
|
|
|
&touch->timestamps_list,
|
|
|
|
|
time);
|
|
|
|
|
wl_touch_send_down(resource, serial, msecs,
|
|
|
|
|
touch->focus->surface->resource,
|
2022-02-09 02:31:55 +03:00
|
|
|
|
touch_id,
|
|
|
|
|
wl_fixed_from_double(surf_pos.c.x),
|
|
|
|
|
wl_fixed_from_double(surf_pos.c.y));
|
2018-02-20 15:07:03 +03:00
|
|
|
|
}
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-07 06:19:57 +04:00
|
|
|
|
static void
|
2017-11-16 19:20:58 +03:00
|
|
|
|
default_grab_touch_down(struct weston_touch_grab *grab,
|
|
|
|
|
const struct timespec *time, int touch_id,
|
2022-02-08 18:50:25 +03:00
|
|
|
|
struct weston_coord_global pos)
|
2016-08-12 11:41:32 +03:00
|
|
|
|
{
|
2023-02-07 02:00:14 +03:00
|
|
|
|
weston_touch_send_down(grab->touch, time, touch_id, pos);
|
2016-08-12 11:41:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Send wl_touch.up events to focused resources.
|
|
|
|
|
*
|
|
|
|
|
* \param touch The touch where the up events originates from.
|
|
|
|
|
* \param time The timestamp of the event
|
|
|
|
|
* \param touch_id The touch_id value of the event
|
|
|
|
|
*
|
|
|
|
|
* For every resource that is currently in focus, send a wl_touch.up event
|
|
|
|
|
* with the passed parameters. The focused resources are the wl_touch
|
|
|
|
|
* resources of the client which currently has the surface with touch focus.
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT void
|
2017-11-16 19:20:59 +03:00
|
|
|
|
weston_touch_send_up(struct weston_touch *touch, const struct timespec *time,
|
|
|
|
|
int touch_id)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2013-07-22 20:31:38 +04:00
|
|
|
|
struct wl_display *display = touch->seat->compositor->wl_display;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
uint32_t serial;
|
2013-09-19 20:32:00 +04:00
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct wl_list *resource_list;
|
2017-11-16 19:20:59 +03:00
|
|
|
|
uint32_t msecs;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
if (!weston_touch_has_focus_resource(touch))
|
|
|
|
|
return;
|
2013-09-19 20:32:00 +04:00
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
resource_list = &touch->focus_resource_list;
|
|
|
|
|
serial = wl_display_next_serial(display);
|
2017-11-16 19:20:59 +03:00
|
|
|
|
msecs = timespec_to_msec(time);
|
2018-02-20 15:07:03 +03:00
|
|
|
|
wl_resource_for_each(resource, resource_list) {
|
|
|
|
|
send_timestamps_for_input_resource(resource,
|
|
|
|
|
&touch->timestamps_list,
|
|
|
|
|
time);
|
2017-11-16 19:20:59 +03:00
|
|
|
|
wl_touch_send_up(resource, serial, msecs, touch_id);
|
2018-02-20 15:07:03 +03:00
|
|
|
|
}
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-07 06:19:57 +04:00
|
|
|
|
static void
|
2016-08-12 11:41:32 +03:00
|
|
|
|
default_grab_touch_up(struct weston_touch_grab *grab,
|
2017-11-16 19:20:59 +03:00
|
|
|
|
const struct timespec *time, int touch_id)
|
2016-08-12 11:41:32 +03:00
|
|
|
|
{
|
|
|
|
|
weston_touch_send_up(grab->touch, time, touch_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Send wl_touch.motion events to focused resources.
|
|
|
|
|
*
|
|
|
|
|
* \param touch The touch where the motion events originates from.
|
|
|
|
|
* \param time The timestamp of the event
|
|
|
|
|
* \param touch_id The touch_id value of the event
|
2023-02-07 02:00:14 +03:00
|
|
|
|
* \param pos The global coordinate of the event
|
2016-08-12 11:41:32 +03:00
|
|
|
|
*
|
|
|
|
|
* For every resource that is currently in focus, send a wl_touch.motion event
|
|
|
|
|
* with the passed parameters. The focused resources are the wl_touch
|
|
|
|
|
* resources of the client which currently has the surface with touch focus.
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT void
|
2017-11-16 19:21:00 +03:00
|
|
|
|
weston_touch_send_motion(struct weston_touch *touch,
|
|
|
|
|
const struct timespec *time, int touch_id,
|
2023-02-07 02:00:14 +03:00
|
|
|
|
struct weston_coord_global pos)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2013-09-19 20:32:00 +04:00
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct wl_list *resource_list;
|
2017-11-16 19:21:00 +03:00
|
|
|
|
uint32_t msecs;
|
2022-02-09 02:31:55 +03:00
|
|
|
|
struct weston_coord_surface surf_pos;
|
2015-07-08 11:55:28 +03:00
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
if (!weston_touch_has_focus_resource(touch))
|
|
|
|
|
return;
|
|
|
|
|
|
2023-02-06 21:04:10 +03:00
|
|
|
|
weston_view_update_transform(touch->focus);
|
|
|
|
|
|
2023-02-07 02:00:14 +03:00
|
|
|
|
surf_pos = weston_coord_global_to_surface(touch->focus, pos);
|
2013-09-19 20:32:00 +04:00
|
|
|
|
|
|
|
|
|
resource_list = &touch->focus_resource_list;
|
2017-11-16 19:21:00 +03:00
|
|
|
|
msecs = timespec_to_msec(time);
|
2013-09-19 20:32:00 +04:00
|
|
|
|
wl_resource_for_each(resource, resource_list) {
|
2018-02-20 15:07:03 +03:00
|
|
|
|
send_timestamps_for_input_resource(resource,
|
|
|
|
|
&touch->timestamps_list,
|
|
|
|
|
time);
|
2022-02-09 02:31:55 +03:00
|
|
|
|
wl_touch_send_motion(resource, msecs, touch_id,
|
|
|
|
|
wl_fixed_from_double(surf_pos.c.x),
|
|
|
|
|
wl_fixed_from_double(surf_pos.c.y));
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-12 11:39:51 +04:00
|
|
|
|
static void
|
2017-11-16 19:21:00 +03:00
|
|
|
|
default_grab_touch_motion(struct weston_touch_grab *grab,
|
|
|
|
|
const struct timespec *time, int touch_id,
|
2022-02-08 18:50:25 +03:00
|
|
|
|
struct weston_coord_global pos)
|
2016-08-12 11:41:32 +03:00
|
|
|
|
{
|
2023-02-07 02:00:14 +03:00
|
|
|
|
weston_touch_send_motion(grab->touch, time, touch_id, pos);
|
2016-08-12 11:41:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Send wl_touch.frame events to focused resources.
|
|
|
|
|
*
|
|
|
|
|
* \param touch The touch where the frame events originates from.
|
|
|
|
|
*
|
|
|
|
|
* For every resource that is currently in focus, send a wl_touch.frame event.
|
|
|
|
|
* The focused resources are the wl_touch resources of the client which
|
|
|
|
|
* currently has the surface with touch focus.
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_touch_send_frame(struct weston_touch *touch)
|
2014-04-12 11:39:51 +04:00
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
if (!weston_touch_has_focus_resource(touch))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, &touch->focus_resource_list)
|
2014-04-12 11:39:51 +04:00
|
|
|
|
wl_touch_send_frame(resource);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
static void
|
|
|
|
|
default_grab_touch_frame(struct weston_touch_grab *grab)
|
|
|
|
|
{
|
|
|
|
|
weston_touch_send_frame(grab->touch);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-26 01:18:05 +04:00
|
|
|
|
static void
|
|
|
|
|
default_grab_touch_cancel(struct weston_touch_grab *grab)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-07 06:19:57 +04:00
|
|
|
|
static const struct weston_touch_grab_interface default_touch_grab_interface = {
|
2013-04-18 23:07:39 +04:00
|
|
|
|
default_grab_touch_down,
|
|
|
|
|
default_grab_touch_up,
|
2013-10-26 01:18:05 +04:00
|
|
|
|
default_grab_touch_motion,
|
2014-04-12 11:39:51 +04:00
|
|
|
|
default_grab_touch_frame,
|
2013-10-26 01:18:05 +04:00
|
|
|
|
default_grab_touch_cancel,
|
2013-04-18 23:07:39 +04:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
/** Check if the keyboard has focused resources.
|
|
|
|
|
*
|
|
|
|
|
* \param keyboard The keyboard to check for focused resources.
|
|
|
|
|
* \return Whether or not this keyboard has focused resources
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT bool
|
|
|
|
|
weston_keyboard_has_focus_resource(struct weston_keyboard *keyboard)
|
|
|
|
|
{
|
|
|
|
|
if (!keyboard->focus)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (wl_list_empty(&keyboard->focus_resource_list))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Send wl_keyboard.key events to focused resources.
|
|
|
|
|
*
|
|
|
|
|
* \param keyboard The keyboard where the key events originates from.
|
|
|
|
|
* \param time The timestamp of the event
|
|
|
|
|
* \param key The key value of the event
|
|
|
|
|
* \param state The state enum value of the event
|
|
|
|
|
*
|
|
|
|
|
* For every resource that is currently in focus, send a wl_keyboard.key event
|
|
|
|
|
* with the passed parameters. The focused resources are the wl_keyboard
|
|
|
|
|
* resources of the client which currently has the surface with keyboard focus.
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_keyboard_send_key(struct weston_keyboard *keyboard,
|
2017-11-16 19:20:57 +03:00
|
|
|
|
const struct timespec *time, uint32_t key,
|
2016-08-12 11:41:32 +03:00
|
|
|
|
enum wl_keyboard_key_state state)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
2013-07-22 20:31:38 +04:00
|
|
|
|
struct wl_display *display = keyboard->seat->compositor->wl_display;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
uint32_t serial;
|
2013-09-19 20:32:00 +04:00
|
|
|
|
struct wl_list *resource_list;
|
2017-11-16 19:20:57 +03:00
|
|
|
|
uint32_t msecs;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
if (!weston_keyboard_has_focus_resource(keyboard))
|
|
|
|
|
return;
|
|
|
|
|
|
2013-09-19 20:32:00 +04:00
|
|
|
|
resource_list = &keyboard->focus_resource_list;
|
2016-08-12 11:41:32 +03:00
|
|
|
|
serial = wl_display_next_serial(display);
|
2017-11-16 19:20:57 +03:00
|
|
|
|
msecs = timespec_to_msec(time);
|
2018-02-20 15:05:50 +03:00
|
|
|
|
wl_resource_for_each(resource, resource_list) {
|
|
|
|
|
send_timestamps_for_input_resource(resource,
|
|
|
|
|
&keyboard->timestamps_list,
|
|
|
|
|
time);
|
2017-11-16 19:20:57 +03:00
|
|
|
|
wl_keyboard_send_key(resource, serial, msecs, key, state);
|
2018-02-20 15:05:50 +03:00
|
|
|
|
}
|
2016-08-12 11:41:32 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
default_grab_keyboard_key(struct weston_keyboard_grab *grab,
|
2017-11-16 19:20:57 +03:00
|
|
|
|
const struct timespec *time, uint32_t key,
|
|
|
|
|
uint32_t state)
|
2016-08-12 11:41:32 +03:00
|
|
|
|
{
|
|
|
|
|
weston_keyboard_send_key(grab->keyboard, time, key, state);
|
2013-09-19 20:32:00 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
send_modifiers_to_resource(struct weston_keyboard *keyboard,
|
|
|
|
|
struct wl_resource *resource,
|
|
|
|
|
uint32_t serial)
|
|
|
|
|
{
|
|
|
|
|
wl_keyboard_send_modifiers(resource,
|
|
|
|
|
serial,
|
|
|
|
|
keyboard->modifiers.mods_depressed,
|
|
|
|
|
keyboard->modifiers.mods_latched,
|
|
|
|
|
keyboard->modifiers.mods_locked,
|
|
|
|
|
keyboard->modifiers.group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
send_modifiers_to_client_in_list(struct wl_client *client,
|
|
|
|
|
struct wl_list *list,
|
|
|
|
|
uint32_t serial,
|
|
|
|
|
struct weston_keyboard *keyboard)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, list) {
|
|
|
|
|
if (wl_resource_get_client(resource) == client)
|
|
|
|
|
send_modifiers_to_resource(keyboard,
|
|
|
|
|
resource,
|
|
|
|
|
serial);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 07:05:38 +03:00
|
|
|
|
static struct weston_pointer_client *
|
|
|
|
|
find_pointer_client_for_surface(struct weston_pointer *pointer,
|
|
|
|
|
struct weston_surface *surface)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2015-07-22 07:05:38 +03:00
|
|
|
|
struct wl_client *client;
|
|
|
|
|
|
2013-04-18 23:07:39 +04:00
|
|
|
|
if (!surface)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2013-06-14 19:08:00 +04:00
|
|
|
|
if (!surface->resource)
|
|
|
|
|
return NULL;
|
2013-09-17 13:54:09 +04:00
|
|
|
|
|
2015-07-22 07:05:38 +03:00
|
|
|
|
client = wl_resource_get_client(surface->resource);
|
|
|
|
|
return weston_pointer_get_pointer_client(pointer, client);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 07:05:38 +03:00
|
|
|
|
static struct weston_pointer_client *
|
|
|
|
|
find_pointer_client_for_view(struct weston_pointer *pointer, struct weston_view *view)
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
{
|
|
|
|
|
if (!view)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2015-07-22 07:05:38 +03:00
|
|
|
|
return find_pointer_client_for_surface(pointer, view->surface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct wl_resource *
|
|
|
|
|
find_resource_for_surface(struct wl_list *list, struct weston_surface *surface)
|
|
|
|
|
{
|
|
|
|
|
if (!surface)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (!surface->resource)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return wl_resource_find_for_client(list, wl_resource_get_client(surface->resource));
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 11:11:41 +03:00
|
|
|
|
static struct wl_resource *
|
|
|
|
|
find_resource_for_view(struct wl_list *list, struct weston_view *view)
|
|
|
|
|
{
|
|
|
|
|
if (!view)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return find_resource_for_surface(list,
|
|
|
|
|
view->surface);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
/** Send wl_keyboard.modifiers events to focused resources and pointer
|
|
|
|
|
* focused resources.
|
|
|
|
|
*
|
|
|
|
|
* \param keyboard The keyboard where the modifiers events originates from.
|
|
|
|
|
* \param serial The serial of the event
|
|
|
|
|
* \param mods_depressed The mods_depressed value of the event
|
|
|
|
|
* \param mods_latched The mods_latched value of the event
|
|
|
|
|
* \param mods_locked The mods_locked value of the event
|
|
|
|
|
* \param group The group value of the event
|
|
|
|
|
*
|
|
|
|
|
* For every resource that is currently in focus, send a wl_keyboard.modifiers
|
|
|
|
|
* event with the passed parameters. The focused resources are the wl_keyboard
|
|
|
|
|
* resources of the client which currently has the surface with keyboard focus.
|
|
|
|
|
* This also sends wl_keyboard.modifiers events to the wl_keyboard resources of
|
|
|
|
|
* the client having pointer focus (if different from the keyboard focus client).
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_keyboard_send_modifiers(struct weston_keyboard *keyboard,
|
|
|
|
|
uint32_t serial, uint32_t mods_depressed,
|
|
|
|
|
uint32_t mods_latched,
|
|
|
|
|
uint32_t mods_locked, uint32_t group)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_pointer *pointer =
|
2016-08-12 11:41:32 +03:00
|
|
|
|
weston_seat_get_pointer(keyboard->seat);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
if (weston_keyboard_has_focus_resource(keyboard)) {
|
|
|
|
|
struct wl_list *resource_list;
|
|
|
|
|
struct wl_resource *resource;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
resource_list = &keyboard->focus_resource_list;
|
|
|
|
|
wl_resource_for_each(resource, resource_list) {
|
|
|
|
|
wl_keyboard_send_modifiers(resource, serial,
|
|
|
|
|
mods_depressed, mods_latched,
|
|
|
|
|
mods_locked, group);
|
|
|
|
|
}
|
2013-09-19 20:32:00 +04:00
|
|
|
|
}
|
2016-08-12 11:41:32 +03:00
|
|
|
|
|
2013-11-15 06:06:16 +04:00
|
|
|
|
if (pointer && pointer->focus && pointer->focus->surface->resource &&
|
|
|
|
|
pointer->focus->surface != keyboard->focus) {
|
2013-09-19 20:32:00 +04:00
|
|
|
|
struct wl_client *pointer_client =
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
wl_resource_get_client(pointer->focus->surface->resource);
|
2016-08-12 11:41:32 +03:00
|
|
|
|
|
2013-09-19 20:32:00 +04:00
|
|
|
|
send_modifiers_to_client_in_list(pointer_client,
|
|
|
|
|
&keyboard->resource_list,
|
|
|
|
|
serial,
|
|
|
|
|
keyboard);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
static void
|
|
|
|
|
default_grab_keyboard_modifiers(struct weston_keyboard_grab *grab,
|
|
|
|
|
uint32_t serial, uint32_t mods_depressed,
|
|
|
|
|
uint32_t mods_latched,
|
|
|
|
|
uint32_t mods_locked, uint32_t group)
|
|
|
|
|
{
|
|
|
|
|
weston_keyboard_send_modifiers(grab->keyboard, serial, mods_depressed,
|
|
|
|
|
mods_latched, mods_locked, group);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-26 01:18:05 +04:00
|
|
|
|
static void
|
|
|
|
|
default_grab_keyboard_cancel(struct weston_keyboard_grab *grab)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:25:39 +04:00
|
|
|
|
static const struct weston_keyboard_grab_interface
|
2013-04-18 23:07:39 +04:00
|
|
|
|
default_keyboard_grab_interface = {
|
2013-10-29 02:32:02 +04:00
|
|
|
|
default_grab_keyboard_key,
|
|
|
|
|
default_grab_keyboard_modifiers,
|
2013-10-26 01:18:05 +04:00
|
|
|
|
default_grab_keyboard_cancel,
|
2013-04-18 23:07:39 +04:00
|
|
|
|
};
|
|
|
|
|
|
2013-05-08 23:02:05 +04:00
|
|
|
|
static void
|
|
|
|
|
pointer_unmap_sprite(struct weston_pointer *pointer)
|
|
|
|
|
{
|
2014-11-12 17:42:52 +03:00
|
|
|
|
struct weston_surface *surface = pointer->sprite->surface;
|
|
|
|
|
|
|
|
|
|
if (weston_surface_is_mapped(surface))
|
|
|
|
|
weston_surface_unmap(surface);
|
2013-05-08 23:02:05 +04:00
|
|
|
|
|
|
|
|
|
wl_list_remove(&pointer->sprite_destroy_listener.link);
|
2016-08-12 11:41:33 +03:00
|
|
|
|
surface->committed = NULL;
|
|
|
|
|
surface->committed_private = NULL;
|
compositor: add weston_surface_set_label_func()
When printing out logs from Weston's actions, mainly for debugging, it
can be very difficult to identify the different surfaces. Inspecting
the configure function pointer is not useful, as the configure functions
may live in modules.
Add vfunc get_label to weston_surface, which will produce a short,
human-readable description of the surface, which allows identifying it
better, rather than just looking at the surface size, for instance.
Set the label function from most parts of Weston, to identify cursors and
drag icons, and panels, backgrounds, screensavers and lock surfaces, and
the desktop shell's application surfaces.
v2: renamed 'description' to 'label', so we get
weston_surface_set_label_func().
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-08-06 20:36:51 +04:00
|
|
|
|
weston_surface_set_label_func(surface, NULL);
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
weston_view_destroy(pointer->sprite);
|
2013-05-08 23:02:05 +04:00
|
|
|
|
pointer->sprite = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pointer_handle_sprite_destroy(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer *pointer =
|
|
|
|
|
container_of(listener, struct weston_pointer,
|
|
|
|
|
sprite_destroy_listener);
|
|
|
|
|
|
|
|
|
|
pointer->sprite = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-03 01:05:05 +04:00
|
|
|
|
static void
|
|
|
|
|
weston_pointer_reset_state(struct weston_pointer *pointer)
|
|
|
|
|
{
|
|
|
|
|
pointer->button_count = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 20:47:51 +04:00
|
|
|
|
static void
|
|
|
|
|
weston_pointer_handle_output_destroy(struct wl_listener *listener, void *data);
|
|
|
|
|
|
2018-02-26 15:55:32 +03:00
|
|
|
|
static struct weston_pointer *
|
2013-11-15 02:42:53 +04:00
|
|
|
|
weston_pointer_create(struct weston_seat *seat)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2013-05-08 07:52:07 +04:00
|
|
|
|
struct weston_pointer *pointer;
|
|
|
|
|
|
2013-08-08 05:57:05 +04:00
|
|
|
|
pointer = zalloc(sizeof *pointer);
|
2013-05-08 07:52:07 +04:00
|
|
|
|
if (pointer == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2015-07-22 07:05:38 +03:00
|
|
|
|
wl_list_init(&pointer->pointer_clients);
|
2013-11-15 02:42:53 +04:00
|
|
|
|
weston_pointer_set_default_grab(pointer,
|
|
|
|
|
seat->compositor->default_pointer_grab);
|
2013-11-20 21:00:24 +04:00
|
|
|
|
wl_list_init(&pointer->focus_resource_listener.link);
|
|
|
|
|
pointer->focus_resource_listener.notify = pointer_focus_resource_destroyed;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
pointer->default_grab.pointer = pointer;
|
|
|
|
|
pointer->grab = &pointer->default_grab;
|
2013-11-15 02:42:50 +04:00
|
|
|
|
wl_signal_init(&pointer->motion_signal);
|
2013-11-19 14:37:15 +04:00
|
|
|
|
wl_signal_init(&pointer->focus_signal);
|
2013-11-20 21:00:24 +04:00
|
|
|
|
wl_list_init(&pointer->focus_view_listener.link);
|
2016-07-22 12:52:58 +03:00
|
|
|
|
wl_signal_init(&pointer->destroy_signal);
|
2018-02-20 15:06:26 +03:00
|
|
|
|
wl_list_init(&pointer->timestamps_list);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
|
2013-05-08 23:02:05 +04:00
|
|
|
|
pointer->sprite_destroy_listener.notify = pointer_handle_sprite_destroy;
|
|
|
|
|
|
2013-04-18 23:07:39 +04:00
|
|
|
|
/* FIXME: Pick better co-ords. */
|
2022-02-04 01:40:10 +03:00
|
|
|
|
pointer->pos.c = weston_coord(100, 100);
|
2013-05-08 07:52:07 +04:00
|
|
|
|
|
2014-01-29 20:47:51 +04:00
|
|
|
|
pointer->output_destroy_listener.notify =
|
|
|
|
|
weston_pointer_handle_output_destroy;
|
|
|
|
|
wl_signal_add(&seat->compositor->output_destroyed_signal,
|
|
|
|
|
&pointer->output_destroy_listener);
|
|
|
|
|
|
2013-05-08 07:52:07 +04:00
|
|
|
|
return pointer;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-26 15:55:32 +03:00
|
|
|
|
static void
|
2013-05-08 07:52:07 +04:00
|
|
|
|
weston_pointer_destroy(struct weston_pointer *pointer)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2018-02-08 16:37:53 +03:00
|
|
|
|
struct weston_pointer_client *pointer_client, *tmp;
|
|
|
|
|
|
2016-07-22 12:52:58 +03:00
|
|
|
|
wl_signal_emit(&pointer->destroy_signal, pointer);
|
|
|
|
|
|
2013-05-08 23:02:05 +04:00
|
|
|
|
if (pointer->sprite)
|
|
|
|
|
pointer_unmap_sprite(pointer);
|
|
|
|
|
|
2018-02-08 16:37:53 +03:00
|
|
|
|
wl_list_for_each_safe(pointer_client, tmp, &pointer->pointer_clients,
|
|
|
|
|
link) {
|
|
|
|
|
wl_list_remove(&pointer_client->link);
|
|
|
|
|
weston_pointer_client_destroy(pointer_client);
|
|
|
|
|
}
|
2013-09-19 20:32:00 +04:00
|
|
|
|
|
2013-11-20 21:00:24 +04:00
|
|
|
|
wl_list_remove(&pointer->focus_resource_listener.link);
|
|
|
|
|
wl_list_remove(&pointer->focus_view_listener.link);
|
2014-01-29 20:47:51 +04:00
|
|
|
|
wl_list_remove(&pointer->output_destroy_listener.link);
|
2018-02-20 15:06:26 +03:00
|
|
|
|
wl_list_remove(&pointer->timestamps_list);
|
2013-05-08 07:52:07 +04:00
|
|
|
|
free(pointer);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-15 02:42:53 +04:00
|
|
|
|
void
|
|
|
|
|
weston_pointer_set_default_grab(struct weston_pointer *pointer,
|
|
|
|
|
const struct weston_pointer_grab_interface *interface)
|
|
|
|
|
{
|
|
|
|
|
if (interface)
|
|
|
|
|
pointer->default_grab.interface = interface;
|
|
|
|
|
else
|
|
|
|
|
pointer->default_grab.interface =
|
|
|
|
|
&default_pointer_grab_interface;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-26 15:55:32 +03:00
|
|
|
|
static struct weston_keyboard *
|
2013-05-08 07:52:07 +04:00
|
|
|
|
weston_keyboard_create(void)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2013-05-08 07:52:07 +04:00
|
|
|
|
struct weston_keyboard *keyboard;
|
|
|
|
|
|
2013-08-08 05:57:05 +04:00
|
|
|
|
keyboard = zalloc(sizeof *keyboard);
|
2013-05-08 07:52:07 +04:00
|
|
|
|
if (keyboard == NULL)
|
2013-09-19 20:32:00 +04:00
|
|
|
|
return NULL;
|
2013-05-08 07:52:07 +04:00
|
|
|
|
|
2013-04-18 23:07:39 +04:00
|
|
|
|
wl_list_init(&keyboard->resource_list);
|
2013-09-19 20:32:00 +04:00
|
|
|
|
wl_list_init(&keyboard->focus_resource_list);
|
2013-11-20 21:00:24 +04:00
|
|
|
|
wl_list_init(&keyboard->focus_resource_listener.link);
|
|
|
|
|
keyboard->focus_resource_listener.notify = keyboard_focus_resource_destroyed;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
wl_array_init(&keyboard->keys);
|
|
|
|
|
keyboard->default_grab.interface = &default_keyboard_grab_interface;
|
|
|
|
|
keyboard->default_grab.keyboard = keyboard;
|
|
|
|
|
keyboard->grab = &keyboard->default_grab;
|
|
|
|
|
wl_signal_init(&keyboard->focus_signal);
|
2018-02-20 15:05:50 +03:00
|
|
|
|
wl_list_init(&keyboard->timestamps_list);
|
2013-05-08 07:52:07 +04:00
|
|
|
|
|
|
|
|
|
return keyboard;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-03 12:14:26 +04:00
|
|
|
|
static void
|
|
|
|
|
weston_xkb_info_destroy(struct weston_xkb_info *xkb_info);
|
|
|
|
|
|
2018-02-26 15:55:32 +03:00
|
|
|
|
static void
|
2013-05-08 07:52:07 +04:00
|
|
|
|
weston_keyboard_destroy(struct weston_keyboard *keyboard)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2018-01-26 19:47:56 +03:00
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, &keyboard->resource_list) {
|
|
|
|
|
wl_resource_set_user_data(resource, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, &keyboard->focus_resource_list) {
|
|
|
|
|
wl_resource_set_user_data(resource, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_list_remove(&keyboard->resource_list);
|
|
|
|
|
wl_list_remove(&keyboard->focus_resource_list);
|
2013-09-19 20:32:00 +04:00
|
|
|
|
|
2017-06-28 19:17:23 +03:00
|
|
|
|
xkb_state_unref(keyboard->xkb_state.state);
|
|
|
|
|
if (keyboard->xkb_info)
|
|
|
|
|
weston_xkb_info_destroy(keyboard->xkb_info);
|
|
|
|
|
xkb_keymap_unref(keyboard->pending_keymap);
|
2013-12-03 12:14:26 +04:00
|
|
|
|
|
2013-04-18 23:07:39 +04:00
|
|
|
|
wl_array_release(&keyboard->keys);
|
2013-11-20 21:00:24 +04:00
|
|
|
|
wl_list_remove(&keyboard->focus_resource_listener.link);
|
2018-02-20 15:05:50 +03:00
|
|
|
|
wl_list_remove(&keyboard->timestamps_list);
|
2013-05-08 07:52:07 +04:00
|
|
|
|
free(keyboard);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-03 01:05:04 +04:00
|
|
|
|
static void
|
|
|
|
|
weston_touch_reset_state(struct weston_touch *touch)
|
|
|
|
|
{
|
|
|
|
|
touch->num_tp = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-26 15:55:32 +03:00
|
|
|
|
static struct weston_touch *
|
2013-05-08 07:52:07 +04:00
|
|
|
|
weston_touch_create(void)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2013-05-08 07:52:07 +04:00
|
|
|
|
struct weston_touch *touch;
|
|
|
|
|
|
2013-08-08 05:57:05 +04:00
|
|
|
|
touch = zalloc(sizeof *touch);
|
2013-05-08 07:52:07 +04:00
|
|
|
|
if (touch == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2017-11-29 04:42:47 +03:00
|
|
|
|
wl_list_init(&touch->device_list);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
wl_list_init(&touch->resource_list);
|
2013-09-19 20:32:00 +04:00
|
|
|
|
wl_list_init(&touch->focus_resource_list);
|
2013-11-20 21:00:24 +04:00
|
|
|
|
wl_list_init(&touch->focus_view_listener.link);
|
|
|
|
|
touch->focus_view_listener.notify = touch_focus_view_destroyed;
|
|
|
|
|
wl_list_init(&touch->focus_resource_listener.link);
|
|
|
|
|
touch->focus_resource_listener.notify = touch_focus_resource_destroyed;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
touch->default_grab.interface = &default_touch_grab_interface;
|
|
|
|
|
touch->default_grab.touch = touch;
|
|
|
|
|
touch->grab = &touch->default_grab;
|
|
|
|
|
wl_signal_init(&touch->focus_signal);
|
2018-02-20 15:07:03 +03:00
|
|
|
|
wl_list_init(&touch->timestamps_list);
|
2013-05-08 07:52:07 +04:00
|
|
|
|
|
|
|
|
|
return touch;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-26 15:55:32 +03:00
|
|
|
|
static void
|
2013-05-08 07:52:07 +04:00
|
|
|
|
weston_touch_destroy(struct weston_touch *touch)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2018-01-26 19:47:57 +03:00
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
2017-11-29 04:42:47 +03:00
|
|
|
|
assert(wl_list_empty(&touch->device_list));
|
|
|
|
|
|
2018-01-26 19:47:57 +03:00
|
|
|
|
wl_resource_for_each(resource, &touch->resource_list) {
|
|
|
|
|
wl_resource_set_user_data(resource, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, &touch->focus_resource_list) {
|
|
|
|
|
wl_resource_set_user_data(resource, NULL);
|
|
|
|
|
}
|
2013-09-19 20:32:00 +04:00
|
|
|
|
|
2018-01-26 19:47:57 +03:00
|
|
|
|
wl_list_remove(&touch->resource_list);
|
|
|
|
|
wl_list_remove(&touch->focus_resource_list);
|
2013-11-20 21:00:24 +04:00
|
|
|
|
wl_list_remove(&touch->focus_view_listener.link);
|
|
|
|
|
wl_list_remove(&touch->focus_resource_listener.link);
|
2018-02-20 15:07:03 +03:00
|
|
|
|
wl_list_remove(&touch->timestamps_list);
|
2013-05-08 07:52:07 +04:00
|
|
|
|
free(touch);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 11:05:45 +03:00
|
|
|
|
WL_EXPORT struct weston_tablet *
|
|
|
|
|
weston_tablet_create(void)
|
|
|
|
|
{
|
|
|
|
|
struct weston_tablet *tablet;
|
|
|
|
|
|
|
|
|
|
tablet = zalloc(sizeof *tablet);
|
|
|
|
|
if (tablet == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
wl_list_init(&tablet->resource_list);
|
|
|
|
|
wl_list_init(&tablet->tool_list);
|
|
|
|
|
|
|
|
|
|
return tablet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_destroy(struct weston_tablet *tablet)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct weston_tablet_tool *tool, *tmptool;
|
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, &tablet->resource_list) {
|
|
|
|
|
zwp_tablet_v2_send_removed(resource);
|
|
|
|
|
wl_resource_set_user_data(resource, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Remove the tablet from the list */
|
|
|
|
|
wl_list_remove(&tablet->link);
|
|
|
|
|
|
|
|
|
|
/* Remove any local tools */
|
|
|
|
|
wl_list_for_each_safe(tool, tmptool, &tablet->tool_list, link)
|
|
|
|
|
weston_seat_release_tablet_tool(tool);
|
|
|
|
|
|
|
|
|
|
if (wl_list_empty(&tablet->resource_list)) {
|
|
|
|
|
free(tablet->name);
|
|
|
|
|
free(tablet);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 11:11:41 +03:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_tool_set_focus(struct weston_tablet_tool *tool,
|
|
|
|
|
struct weston_view *view,
|
|
|
|
|
const struct timespec *time)
|
|
|
|
|
{
|
|
|
|
|
struct wl_list *focus_resource_list;
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct weston_seat *seat = tool->seat;
|
|
|
|
|
uint32_t msecs;
|
|
|
|
|
|
|
|
|
|
focus_resource_list = &tool->focus_resource_list;
|
|
|
|
|
/* FIXME: correct timestamp? */
|
|
|
|
|
msecs = time ? timespec_to_msec(time) : 0;
|
|
|
|
|
if (tool->focus && !wl_list_empty(focus_resource_list)) {
|
|
|
|
|
wl_resource_for_each(resource, focus_resource_list) {
|
2021-01-20 11:20:22 +03:00
|
|
|
|
if (tool->tip_is_down)
|
|
|
|
|
zwp_tablet_tool_v2_send_up(resource);
|
|
|
|
|
|
2021-01-20 11:11:41 +03:00
|
|
|
|
zwp_tablet_tool_v2_send_proximity_out(resource);
|
|
|
|
|
zwp_tablet_tool_v2_send_frame(resource, msecs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
move_resources(&tool->resource_list, focus_resource_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (find_resource_for_view(&tool->resource_list, view)) {
|
|
|
|
|
struct wl_client *surface_client =
|
|
|
|
|
wl_resource_get_client(view->surface->resource);
|
|
|
|
|
|
|
|
|
|
move_resources_for_client(focus_resource_list,
|
|
|
|
|
&tool->resource_list,
|
|
|
|
|
surface_client);
|
|
|
|
|
|
|
|
|
|
tool->focus_serial = wl_display_next_serial(seat->compositor->wl_display);
|
|
|
|
|
wl_resource_for_each(resource, focus_resource_list) {
|
|
|
|
|
struct wl_resource *tr;
|
|
|
|
|
|
|
|
|
|
tr = wl_resource_find_for_client(&tool->current_tablet->resource_list,
|
|
|
|
|
surface_client);
|
|
|
|
|
|
|
|
|
|
zwp_tablet_tool_v2_send_proximity_in(resource, tool->focus_serial,
|
|
|
|
|
tr, view->surface->resource);
|
2021-01-20 11:20:22 +03:00
|
|
|
|
|
|
|
|
|
if (tool->tip_is_down)
|
|
|
|
|
zwp_tablet_tool_v2_send_down(resource,
|
|
|
|
|
tool->focus_serial);
|
|
|
|
|
|
2021-01-20 11:11:41 +03:00
|
|
|
|
zwp_tablet_tool_v2_send_frame(resource, msecs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_list_remove(&tool->focus_view_listener.link);
|
|
|
|
|
wl_list_init(&tool->focus_view_listener.link);
|
|
|
|
|
wl_list_remove(&tool->focus_resource_listener.link);
|
|
|
|
|
wl_list_init(&tool->focus_resource_listener.link);
|
|
|
|
|
|
|
|
|
|
if (view)
|
|
|
|
|
wl_signal_add(&view->destroy_signal,
|
|
|
|
|
&tool->focus_view_listener);
|
|
|
|
|
if (view && view->surface->resource)
|
|
|
|
|
wl_resource_add_destroy_listener(view->surface->resource,
|
|
|
|
|
&tool->focus_resource_listener);
|
|
|
|
|
tool->focus = view;
|
|
|
|
|
tool->focus_view_listener.notify = tablet_tool_focus_view_destroyed;
|
2017-12-19 11:33:33 +03:00
|
|
|
|
|
|
|
|
|
wl_signal_emit(&tool->focus_signal, tool);
|
2021-01-20 11:11:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 11:20:22 +03:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_tool_start_grab(struct weston_tablet_tool *tool,
|
|
|
|
|
struct weston_tablet_tool_grab *grab)
|
|
|
|
|
{
|
|
|
|
|
tool->grab = grab;
|
|
|
|
|
grab->tool = tool;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_tool_end_grab(struct weston_tablet_tool *tool)
|
|
|
|
|
{
|
|
|
|
|
tool->grab = &tool->default_grab;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
default_grab_tablet_tool_proximity_in(struct weston_tablet_tool_grab *grab,
|
|
|
|
|
const struct timespec *time,
|
|
|
|
|
struct weston_tablet *tablet)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_tool_send_proximity_out(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time)
|
|
|
|
|
{
|
|
|
|
|
weston_tablet_tool_set_focus(tool, NULL, time);
|
2021-01-20 11:26:01 +03:00
|
|
|
|
|
|
|
|
|
/* Hide the cursor */
|
|
|
|
|
if (tool->sprite && weston_surface_is_mapped(tool->sprite->surface))
|
|
|
|
|
weston_surface_unmap(tool->sprite->surface);
|
2021-01-20 11:20:22 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
default_grab_tablet_tool_proximity_out(struct weston_tablet_tool_grab *grab,
|
|
|
|
|
const struct timespec *time)
|
|
|
|
|
{
|
|
|
|
|
weston_tablet_tool_send_proximity_out(grab->tool, time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_tool_send_motion(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time,
|
|
|
|
|
struct weston_coord_global pos)
|
|
|
|
|
{
|
|
|
|
|
struct weston_view *current_view;
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct weston_coord_surface surf_pos;
|
|
|
|
|
|
|
|
|
|
current_view = weston_compositor_pick_view(tool->seat->compositor, pos);
|
|
|
|
|
if (current_view != tool->focus)
|
|
|
|
|
weston_tablet_tool_set_focus(tool, current_view, time);
|
2021-01-20 11:26:01 +03:00
|
|
|
|
weston_tablet_tool_cursor_move(tool, pos);
|
2021-01-20 11:20:22 +03:00
|
|
|
|
surf_pos = weston_coord_global_to_surface(tool->focus, pos);
|
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, &tool->focus_resource_list) {
|
|
|
|
|
zwp_tablet_tool_v2_send_motion(resource,
|
|
|
|
|
wl_fixed_from_double(surf_pos.c.x),
|
|
|
|
|
wl_fixed_from_double(surf_pos.c.y));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
default_grab_tablet_tool_motion(struct weston_tablet_tool_grab *grab,
|
|
|
|
|
const struct timespec *time,
|
|
|
|
|
struct weston_coord_global pos)
|
|
|
|
|
{
|
|
|
|
|
weston_tablet_tool_send_motion(grab->tool, time, pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_tool_send_down(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct wl_list *resource_list = &tool->focus_resource_list;
|
|
|
|
|
|
|
|
|
|
if (!wl_list_empty(resource_list)) {
|
|
|
|
|
wl_resource_for_each(resource, resource_list)
|
|
|
|
|
zwp_tablet_tool_v2_send_down(resource, tool->grab_serial);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
default_grab_tablet_tool_down(struct weston_tablet_tool_grab *grab,
|
|
|
|
|
const struct timespec *time)
|
|
|
|
|
{
|
|
|
|
|
weston_tablet_tool_send_down(grab->tool, time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_tool_send_up(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct wl_list *resource_list = &tool->focus_resource_list;
|
|
|
|
|
|
|
|
|
|
if (!wl_list_empty(resource_list)) {
|
|
|
|
|
wl_resource_for_each(resource, resource_list)
|
|
|
|
|
zwp_tablet_tool_v2_send_up(resource);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
default_grab_tablet_tool_up(struct weston_tablet_tool_grab *grab,
|
|
|
|
|
const struct timespec *time)
|
|
|
|
|
{
|
|
|
|
|
weston_tablet_tool_send_up(grab->tool, time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_tool_send_pressure(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time,
|
|
|
|
|
uint32_t pressure)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct wl_list *resource_list = &tool->focus_resource_list;
|
|
|
|
|
|
|
|
|
|
if (!wl_list_empty(resource_list)) {
|
|
|
|
|
wl_resource_for_each(resource, resource_list)
|
|
|
|
|
zwp_tablet_tool_v2_send_pressure(resource, pressure);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
default_grab_tablet_tool_pressure(struct weston_tablet_tool_grab *grab,
|
|
|
|
|
const struct timespec *time,
|
|
|
|
|
uint32_t pressure)
|
|
|
|
|
{
|
|
|
|
|
weston_tablet_tool_send_pressure(grab->tool, time, pressure);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_tool_send_distance(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time,
|
|
|
|
|
uint32_t distance)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct wl_list *resource_list = &tool->focus_resource_list;
|
|
|
|
|
|
|
|
|
|
if (!wl_list_empty(resource_list)) {
|
|
|
|
|
wl_resource_for_each(resource, resource_list)
|
|
|
|
|
zwp_tablet_tool_v2_send_distance(resource, distance);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
default_grab_tablet_tool_distance(struct weston_tablet_tool_grab *grab,
|
|
|
|
|
const struct timespec *time,
|
|
|
|
|
uint32_t distance)
|
|
|
|
|
{
|
|
|
|
|
weston_tablet_tool_send_distance(grab->tool, time, distance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_tool_send_tilt(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time,
|
|
|
|
|
wl_fixed_t tilt_x, wl_fixed_t tilt_y)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct wl_list *resource_list = &tool->focus_resource_list;
|
|
|
|
|
|
|
|
|
|
if (!wl_list_empty(resource_list)) {
|
|
|
|
|
wl_resource_for_each(resource, resource_list)
|
|
|
|
|
zwp_tablet_tool_v2_send_tilt(resource, tilt_x, tilt_y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
default_grab_tablet_tool_tilt(struct weston_tablet_tool_grab *grab,
|
|
|
|
|
const struct timespec *time,
|
|
|
|
|
wl_fixed_t tilt_x, wl_fixed_t tilt_y)
|
|
|
|
|
{
|
|
|
|
|
weston_tablet_tool_send_tilt(grab->tool, time, tilt_x, tilt_y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_tool_send_button(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time,
|
|
|
|
|
uint32_t button, uint32_t state)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, &tool->focus_resource_list) {
|
|
|
|
|
zwp_tablet_tool_v2_send_button(resource, tool->grab_serial,
|
|
|
|
|
button, state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
default_grab_tablet_tool_button(struct weston_tablet_tool_grab *grab,
|
|
|
|
|
const struct timespec *time,
|
|
|
|
|
uint32_t button,
|
|
|
|
|
enum zwp_tablet_tool_v2_button_state state)
|
|
|
|
|
{
|
|
|
|
|
weston_tablet_tool_send_button(grab->tool, time, button, state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_tool_send_frame(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct wl_list *resource_list = &tool->focus_resource_list;
|
|
|
|
|
uint32_t msecs;
|
|
|
|
|
|
|
|
|
|
msecs = timespec_to_msec(time);
|
|
|
|
|
if (!wl_list_empty(resource_list)) {
|
|
|
|
|
wl_resource_for_each(resource, resource_list)
|
|
|
|
|
zwp_tablet_tool_v2_send_frame(resource, msecs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
default_grab_tablet_tool_frame(struct weston_tablet_tool_grab *grab,
|
|
|
|
|
const struct timespec *time)
|
|
|
|
|
{
|
|
|
|
|
weston_tablet_tool_send_frame(grab->tool, time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
default_grab_tablet_tool_cancel(struct weston_tablet_tool_grab *grab)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct weston_tablet_tool_grab_interface default_tablet_tool_grab_interface = {
|
|
|
|
|
default_grab_tablet_tool_proximity_in,
|
|
|
|
|
default_grab_tablet_tool_proximity_out,
|
|
|
|
|
default_grab_tablet_tool_motion,
|
|
|
|
|
default_grab_tablet_tool_down,
|
|
|
|
|
default_grab_tablet_tool_up,
|
|
|
|
|
default_grab_tablet_tool_pressure,
|
|
|
|
|
default_grab_tablet_tool_distance,
|
|
|
|
|
default_grab_tablet_tool_tilt,
|
|
|
|
|
default_grab_tablet_tool_button,
|
|
|
|
|
default_grab_tablet_tool_frame,
|
|
|
|
|
default_grab_tablet_tool_cancel,
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-20 11:26:01 +03:00
|
|
|
|
static void
|
|
|
|
|
tablet_tool_unmap_sprite(struct weston_tablet_tool *tool)
|
|
|
|
|
{
|
|
|
|
|
if (weston_surface_is_mapped(tool->sprite->surface))
|
|
|
|
|
weston_surface_unmap(tool->sprite->surface);
|
|
|
|
|
|
|
|
|
|
wl_list_remove(&tool->sprite_destroy_listener.link);
|
|
|
|
|
tool->sprite->surface->committed = NULL;
|
|
|
|
|
tool->sprite->surface->committed_private = NULL;
|
|
|
|
|
weston_view_destroy(tool->sprite);
|
|
|
|
|
tool->sprite = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_tool_handle_sprite_destroy(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct weston_tablet_tool *tool =
|
|
|
|
|
container_of(listener, struct weston_tablet_tool,
|
|
|
|
|
sprite_destroy_listener);
|
|
|
|
|
|
|
|
|
|
tool->sprite = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 11:05:45 +03:00
|
|
|
|
WL_EXPORT struct weston_tablet_tool *
|
|
|
|
|
weston_tablet_tool_create(void)
|
|
|
|
|
{
|
|
|
|
|
struct weston_tablet_tool *tool;
|
|
|
|
|
|
|
|
|
|
tool = zalloc(sizeof *tool);
|
|
|
|
|
if (tool == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
wl_list_init(&tool->resource_list);
|
2021-01-20 11:11:41 +03:00
|
|
|
|
wl_list_init(&tool->focus_resource_list);
|
|
|
|
|
|
2021-01-20 11:26:01 +03:00
|
|
|
|
wl_list_init(&tool->sprite_destroy_listener.link);
|
|
|
|
|
tool->sprite_destroy_listener.notify = tablet_tool_handle_sprite_destroy;
|
|
|
|
|
|
2021-01-20 11:11:41 +03:00
|
|
|
|
wl_list_init(&tool->focus_view_listener.link);
|
|
|
|
|
tool->focus_view_listener.notify = tablet_tool_focus_view_destroyed;
|
|
|
|
|
|
|
|
|
|
wl_list_init(&tool->focus_resource_listener.link);
|
|
|
|
|
tool->focus_resource_listener.notify = tablet_tool_focus_resource_destroyed;
|
2021-01-20 11:05:45 +03:00
|
|
|
|
|
2021-01-20 11:20:22 +03:00
|
|
|
|
tool->default_grab.interface = &default_tablet_tool_grab_interface;
|
|
|
|
|
tool->default_grab.tool = tool;
|
|
|
|
|
tool->grab = &tool->default_grab;
|
|
|
|
|
|
2017-12-19 11:33:33 +03:00
|
|
|
|
wl_signal_init(&tool->focus_signal);
|
|
|
|
|
wl_signal_init(&tool->removed_signal);
|
|
|
|
|
|
2021-01-20 11:05:45 +03:00
|
|
|
|
return tool;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_tool_destroy(struct weston_tablet_tool *tool)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource, *tmp;
|
|
|
|
|
|
2021-01-20 11:26:01 +03:00
|
|
|
|
if (tool->sprite)
|
|
|
|
|
tablet_tool_unmap_sprite(tool);
|
|
|
|
|
|
2021-01-20 11:05:45 +03:00
|
|
|
|
wl_resource_for_each_safe(resource, tmp, &tool->resource_list) {
|
|
|
|
|
zwp_tablet_tool_v2_send_removed(resource);
|
|
|
|
|
wl_resource_set_user_data(resource, NULL);
|
|
|
|
|
}
|
2021-01-20 11:11:41 +03:00
|
|
|
|
wl_resource_for_each(resource, &tool->focus_resource_list) {
|
|
|
|
|
wl_resource_set_user_data(resource, NULL);
|
|
|
|
|
}
|
2021-01-20 11:05:45 +03:00
|
|
|
|
|
|
|
|
|
wl_list_remove(&tool->link);
|
|
|
|
|
wl_list_remove(&tool->resource_list);
|
2021-01-20 11:11:41 +03:00
|
|
|
|
wl_list_remove(&tool->focus_resource_list);
|
|
|
|
|
wl_list_remove(&tool->focus_view_listener.link);
|
|
|
|
|
wl_list_remove(&tool->focus_resource_listener.link);
|
2021-01-20 11:05:45 +03:00
|
|
|
|
free(tool);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 11:26:01 +03:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_tool_cursor_move(struct weston_tablet_tool *tool,
|
|
|
|
|
struct weston_coord_global pos)
|
|
|
|
|
{
|
|
|
|
|
tool->pos = pos;
|
|
|
|
|
|
|
|
|
|
if (tool->sprite) {
|
2023-08-02 19:38:30 +03:00
|
|
|
|
struct weston_coord_surface hotspot_inv;
|
2022-11-09 22:39:08 +03:00
|
|
|
|
|
2023-08-02 19:38:30 +03:00
|
|
|
|
hotspot_inv = weston_coord_surface_invert(tool->hotspot);
|
|
|
|
|
weston_view_set_position_with_offset(tool->sprite,
|
|
|
|
|
pos, hotspot_inv);
|
2021-01-20 11:26:01 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-20 11:05:45 +03:00
|
|
|
|
|
2013-04-18 23:07:39 +04:00
|
|
|
|
static void
|
2013-05-07 07:19:49 +04:00
|
|
|
|
seat_send_updated_caps(struct weston_seat *seat)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
|
|
|
|
enum wl_seat_capability caps = 0;
|
2013-09-06 20:48:19 +04:00
|
|
|
|
struct wl_resource *resource;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
|
2013-10-18 01:04:05 +04:00
|
|
|
|
if (seat->pointer_device_count > 0)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
caps |= WL_SEAT_CAPABILITY_POINTER;
|
2013-10-18 01:04:05 +04:00
|
|
|
|
if (seat->keyboard_device_count > 0)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
caps |= WL_SEAT_CAPABILITY_KEYBOARD;
|
2013-10-18 01:04:05 +04:00
|
|
|
|
if (seat->touch_device_count > 0)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
caps |= WL_SEAT_CAPABILITY_TOUCH;
|
|
|
|
|
|
2013-09-06 20:48:19 +04:00
|
|
|
|
wl_resource_for_each(resource, &seat->base_resource_list) {
|
|
|
|
|
wl_seat_send_capabilities(resource, caps);
|
2013-06-14 19:08:00 +04:00
|
|
|
|
}
|
2014-04-03 04:53:45 +04:00
|
|
|
|
wl_signal_emit(&seat->updated_caps_signal, seat);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 23:40:11 +03:00
|
|
|
|
|
|
|
|
|
/** Clear the pointer focus
|
|
|
|
|
*
|
|
|
|
|
* \param pointer the pointer to clear focus for.
|
|
|
|
|
*
|
|
|
|
|
* This can be used to unset pointer focus and set the co-ordinates to the
|
|
|
|
|
* arbitrary values we use for the no focus case.
|
|
|
|
|
*
|
2022-10-31 20:30:47 +03:00
|
|
|
|
* There's no requirement to use this function. Passing NULL directly to
|
|
|
|
|
* weston_pointer_set_focus() will do the right thing.
|
2015-05-11 23:40:11 +03:00
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_pointer_clear_focus(struct weston_pointer *pointer)
|
|
|
|
|
{
|
2022-10-28 22:06:24 +03:00
|
|
|
|
weston_pointer_set_focus(pointer, NULL);
|
2015-05-11 23:40:11 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:07:39 +04:00
|
|
|
|
WL_EXPORT void
|
2013-05-07 06:15:05 +04:00
|
|
|
|
weston_pointer_set_focus(struct weston_pointer *pointer,
|
2022-10-28 22:06:24 +03:00
|
|
|
|
struct weston_view *view)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2015-07-22 07:05:38 +03:00
|
|
|
|
struct weston_pointer_client *pointer_client;
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_keyboard *kbd = weston_seat_get_keyboard(pointer->seat);
|
2013-09-19 20:32:00 +04:00
|
|
|
|
struct wl_resource *resource;
|
2015-07-22 07:05:38 +03:00
|
|
|
|
struct wl_resource *surface_resource;
|
2013-07-22 20:31:38 +04:00
|
|
|
|
struct wl_display *display = pointer->seat->compositor->wl_display;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
uint32_t serial;
|
2013-09-19 20:32:00 +04:00
|
|
|
|
struct wl_list *focus_resource_list;
|
2014-02-06 05:14:42 +04:00
|
|
|
|
int refocus = 0;
|
2022-10-28 22:06:24 +03:00
|
|
|
|
wl_fixed_t sx, sy;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
|
2022-10-28 20:37:32 +03:00
|
|
|
|
if (view) {
|
2022-02-09 02:31:55 +03:00
|
|
|
|
struct weston_coord_surface surf_pos;
|
2022-10-28 20:37:32 +03:00
|
|
|
|
|
2022-02-04 01:40:10 +03:00
|
|
|
|
surf_pos = weston_coord_global_to_surface(view, pointer->pos);
|
2022-02-09 02:31:55 +03:00
|
|
|
|
sx = wl_fixed_from_double(surf_pos.c.x);
|
|
|
|
|
sy = wl_fixed_from_double(surf_pos.c.y);
|
2022-02-04 01:40:10 +03:00
|
|
|
|
|
2023-02-07 01:05:42 +03:00
|
|
|
|
if (!weston_view_takes_input_at_point(view, surf_pos))
|
2022-10-28 20:37:32 +03:00
|
|
|
|
weston_log("View focused with external coordinate %d, %d\n",
|
2023-02-07 01:05:42 +03:00
|
|
|
|
(int)surf_pos.c.x, (int)surf_pos.c.y);
|
2022-10-28 20:37:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
if ((!pointer->focus && view) ||
|
|
|
|
|
(pointer->focus && !view) ||
|
2014-02-06 05:14:42 +04:00
|
|
|
|
(pointer->focus && pointer->focus->surface != view->surface) ||
|
2022-10-28 22:09:34 +03:00
|
|
|
|
(view && (pointer->sx != sx || pointer->sy != sy)))
|
2014-02-06 05:14:42 +04:00
|
|
|
|
refocus = 1;
|
2013-09-19 20:32:00 +04:00
|
|
|
|
|
2015-07-22 07:05:38 +03:00
|
|
|
|
if (pointer->focus_client && refocus) {
|
|
|
|
|
focus_resource_list = &pointer->focus_client->pointer_resources;
|
|
|
|
|
if (!wl_list_empty(focus_resource_list)) {
|
|
|
|
|
serial = wl_display_next_serial(display);
|
|
|
|
|
surface_resource = pointer->focus->surface->resource;
|
|
|
|
|
wl_resource_for_each(resource, focus_resource_list) {
|
|
|
|
|
wl_pointer_send_leave(resource, serial,
|
|
|
|
|
surface_resource);
|
2016-01-18 09:38:22 +03:00
|
|
|
|
pointer_send_frame(resource);
|
2015-07-22 07:05:38 +03:00
|
|
|
|
}
|
2013-09-19 20:32:00 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 07:05:38 +03:00
|
|
|
|
pointer->focus_client = NULL;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 07:05:38 +03:00
|
|
|
|
pointer_client = find_pointer_client_for_view(pointer, view);
|
|
|
|
|
if (pointer_client && refocus) {
|
|
|
|
|
struct wl_client *surface_client = pointer_client->client;
|
2013-09-19 20:32:00 +04:00
|
|
|
|
|
2013-04-18 23:07:39 +04:00
|
|
|
|
serial = wl_display_next_serial(display);
|
2013-09-19 20:32:00 +04:00
|
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
if (kbd && kbd->focus != view->surface)
|
2013-10-09 21:54:03 +04:00
|
|
|
|
send_modifiers_to_client_in_list(surface_client,
|
|
|
|
|
&kbd->resource_list,
|
|
|
|
|
serial,
|
|
|
|
|
kbd);
|
|
|
|
|
|
2015-07-22 07:05:38 +03:00
|
|
|
|
pointer->focus_client = pointer_client;
|
2013-09-19 20:32:00 +04:00
|
|
|
|
|
2015-07-22 07:05:38 +03:00
|
|
|
|
focus_resource_list = &pointer->focus_client->pointer_resources;
|
2013-09-19 20:32:00 +04:00
|
|
|
|
wl_resource_for_each(resource, focus_resource_list) {
|
|
|
|
|
wl_pointer_send_enter(resource,
|
|
|
|
|
serial,
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
view->surface->resource,
|
2013-09-19 20:32:00 +04:00
|
|
|
|
sx, sy);
|
2016-01-18 09:38:22 +03:00
|
|
|
|
pointer_send_frame(resource);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
2013-09-19 20:32:00 +04:00
|
|
|
|
|
2013-04-18 23:07:39 +04:00
|
|
|
|
pointer->focus_serial = serial;
|
2013-12-06 15:46:27 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_list_remove(&pointer->focus_view_listener.link);
|
|
|
|
|
wl_list_init(&pointer->focus_view_listener.link);
|
|
|
|
|
wl_list_remove(&pointer->focus_resource_listener.link);
|
|
|
|
|
wl_list_init(&pointer->focus_resource_listener.link);
|
|
|
|
|
if (view)
|
|
|
|
|
wl_signal_add(&view->destroy_signal, &pointer->focus_view_listener);
|
|
|
|
|
if (view && view->surface->resource)
|
2013-11-20 21:00:24 +04:00
|
|
|
|
wl_resource_add_destroy_listener(view->surface->resource,
|
|
|
|
|
&pointer->focus_resource_listener);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
pointer->focus = view;
|
2013-11-20 21:00:24 +04:00
|
|
|
|
pointer->focus_view_listener.notify = pointer_focus_view_destroyed;
|
2022-10-31 20:38:02 +03:00
|
|
|
|
if (view) {
|
|
|
|
|
pointer->sx = sx;
|
|
|
|
|
pointer->sy = sy;
|
|
|
|
|
}
|
2015-05-11 23:40:11 +03:00
|
|
|
|
|
2013-04-18 23:07:39 +04:00
|
|
|
|
wl_signal_emit(&pointer->focus_signal, pointer);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-19 20:32:00 +04:00
|
|
|
|
static void
|
|
|
|
|
send_enter_to_resource_list(struct wl_list *list,
|
|
|
|
|
struct weston_keyboard *keyboard,
|
|
|
|
|
struct weston_surface *surface,
|
|
|
|
|
uint32_t serial)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, list) {
|
|
|
|
|
wl_keyboard_send_enter(resource, serial,
|
|
|
|
|
surface->resource,
|
|
|
|
|
&keyboard->keys);
|
2020-06-17 01:43:57 +03:00
|
|
|
|
send_modifiers_to_resource(keyboard, resource, serial);
|
2013-09-19 20:32:00 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:07:39 +04:00
|
|
|
|
WL_EXPORT void
|
2013-04-18 23:25:39 +04:00
|
|
|
|
weston_keyboard_set_focus(struct weston_keyboard *keyboard,
|
2013-05-08 17:54:37 +04:00
|
|
|
|
struct weston_surface *surface)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
2017-07-21 15:02:40 +03:00
|
|
|
|
struct weston_seat *seat = keyboard->seat;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
struct wl_resource *resource;
|
2013-07-22 20:31:38 +04:00
|
|
|
|
struct wl_display *display = keyboard->seat->compositor->wl_display;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
uint32_t serial;
|
2013-09-19 20:32:00 +04:00
|
|
|
|
struct wl_list *focus_resource_list;
|
2013-04-18 23:07:39 +04:00
|
|
|
|
|
2018-02-22 17:55:15 +03:00
|
|
|
|
/* Keyboard focus on a surface without a client is equivalent to NULL
|
|
|
|
|
* focus as nothing would react to the keyboard events anyway.
|
|
|
|
|
* Just set focus to NULL instead - the destroy listener hangs on the
|
|
|
|
|
* wl_resource anyway.
|
|
|
|
|
*/
|
|
|
|
|
if (surface && !surface->resource)
|
|
|
|
|
surface = NULL;
|
|
|
|
|
|
2013-09-19 20:32:00 +04:00
|
|
|
|
focus_resource_list = &keyboard->focus_resource_list;
|
|
|
|
|
|
|
|
|
|
if (!wl_list_empty(focus_resource_list) && keyboard->focus != surface) {
|
2013-04-18 23:07:39 +04:00
|
|
|
|
serial = wl_display_next_serial(display);
|
2013-09-19 20:32:00 +04:00
|
|
|
|
wl_resource_for_each(resource, focus_resource_list) {
|
|
|
|
|
wl_keyboard_send_leave(resource, serial,
|
|
|
|
|
keyboard->focus->resource);
|
|
|
|
|
}
|
|
|
|
|
move_resources(&keyboard->resource_list, focus_resource_list);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-19 20:32:00 +04:00
|
|
|
|
if (find_resource_for_surface(&keyboard->resource_list, surface) &&
|
|
|
|
|
keyboard->focus != surface) {
|
|
|
|
|
struct wl_client *surface_client =
|
|
|
|
|
wl_resource_get_client(surface->resource);
|
|
|
|
|
|
2013-04-18 23:07:39 +04:00
|
|
|
|
serial = wl_display_next_serial(display);
|
2013-09-19 20:32:00 +04:00
|
|
|
|
|
|
|
|
|
move_resources_for_client(focus_resource_list,
|
|
|
|
|
&keyboard->resource_list,
|
|
|
|
|
surface_client);
|
|
|
|
|
send_enter_to_resource_list(focus_resource_list,
|
|
|
|
|
keyboard,
|
|
|
|
|
surface,
|
|
|
|
|
serial);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
keyboard->focus_serial = serial;
|
2013-12-06 15:46:27 +04:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-11 01:17:24 +03:00
|
|
|
|
/* Since this function gets called from the surface destroy handler
|
|
|
|
|
* we can't just remove the kbd focus listener, or we might corrupt
|
|
|
|
|
* the list it's in.
|
|
|
|
|
* Instead, we'll just set a flag to ignore the focus when the
|
|
|
|
|
* compositor regains kbd focus.
|
|
|
|
|
*/
|
|
|
|
|
seat->use_saved_kbd_focus = false;
|
2017-07-21 15:02:40 +03:00
|
|
|
|
|
2013-12-06 15:46:27 +04:00
|
|
|
|
wl_list_remove(&keyboard->focus_resource_listener.link);
|
|
|
|
|
wl_list_init(&keyboard->focus_resource_listener.link);
|
2018-02-22 17:55:15 +03:00
|
|
|
|
if (surface)
|
2013-11-20 21:00:24 +04:00
|
|
|
|
wl_resource_add_destroy_listener(surface->resource,
|
|
|
|
|
&keyboard->focus_resource_listener);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
|
|
|
|
|
keyboard->focus = surface;
|
|
|
|
|
wl_signal_emit(&keyboard->focus_signal, keyboard);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-22 12:16:56 +03:00
|
|
|
|
/* Users of this function must manually manage the keyboard focus */
|
2013-04-18 23:07:39 +04:00
|
|
|
|
WL_EXPORT void
|
2013-04-18 23:25:39 +04:00
|
|
|
|
weston_keyboard_start_grab(struct weston_keyboard *keyboard,
|
|
|
|
|
struct weston_keyboard_grab *grab)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
|
|
|
|
keyboard->grab = grab;
|
|
|
|
|
grab->keyboard = keyboard;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2013-04-18 23:25:39 +04:00
|
|
|
|
weston_keyboard_end_grab(struct weston_keyboard *keyboard)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
|
|
|
|
keyboard->grab = &keyboard->default_grab;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-26 01:18:05 +04:00
|
|
|
|
static void
|
|
|
|
|
weston_keyboard_cancel_grab(struct weston_keyboard *keyboard)
|
|
|
|
|
{
|
|
|
|
|
keyboard->grab->interface->cancel(keyboard->grab);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:07:39 +04:00
|
|
|
|
WL_EXPORT void
|
2013-05-07 06:15:05 +04:00
|
|
|
|
weston_pointer_start_grab(struct weston_pointer *pointer,
|
|
|
|
|
struct weston_pointer_grab *grab)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
|
|
|
|
pointer->grab = grab;
|
|
|
|
|
grab->pointer = pointer;
|
2013-07-04 08:58:07 +04:00
|
|
|
|
pointer->grab->interface->focus(pointer->grab);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2013-05-07 06:15:05 +04:00
|
|
|
|
weston_pointer_end_grab(struct weston_pointer *pointer)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
|
|
|
|
pointer->grab = &pointer->default_grab;
|
2013-07-04 08:58:07 +04:00
|
|
|
|
pointer->grab->interface->focus(pointer->grab);
|
2013-04-18 23:07:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-26 01:18:05 +04:00
|
|
|
|
static void
|
|
|
|
|
weston_pointer_cancel_grab(struct weston_pointer *pointer)
|
|
|
|
|
{
|
|
|
|
|
pointer->grab->interface->cancel(pointer->grab);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:07:39 +04:00
|
|
|
|
WL_EXPORT void
|
2013-05-07 06:19:57 +04:00
|
|
|
|
weston_touch_start_grab(struct weston_touch *touch, struct weston_touch_grab *grab)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
|
|
|
|
touch->grab = grab;
|
|
|
|
|
grab->touch = touch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2013-05-07 06:19:57 +04:00
|
|
|
|
weston_touch_end_grab(struct weston_touch *touch)
|
2013-04-18 23:07:39 +04:00
|
|
|
|
{
|
|
|
|
|
touch->grab = &touch->default_grab;
|
|
|
|
|
}
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2013-10-26 01:18:05 +04:00
|
|
|
|
static void
|
|
|
|
|
weston_touch_cancel_grab(struct weston_touch *touch)
|
|
|
|
|
{
|
|
|
|
|
touch->grab->interface->cancel(touch->grab);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-07 01:44:51 +03:00
|
|
|
|
static struct weston_coord_global
|
2013-12-14 00:10:56 +04:00
|
|
|
|
weston_pointer_clamp_for_output(struct weston_pointer *pointer,
|
|
|
|
|
struct weston_output *output,
|
2023-02-07 01:44:51 +03:00
|
|
|
|
struct weston_coord_global pos)
|
2013-12-14 00:10:56 +04:00
|
|
|
|
{
|
2023-07-18 21:29:52 +03:00
|
|
|
|
return weston_coord_global_clamp_for_output(pos, output);
|
2013-12-14 00:10:56 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-07 01:44:51 +03:00
|
|
|
|
WL_EXPORT struct weston_coord_global
|
|
|
|
|
weston_pointer_clamp(struct weston_pointer *pointer, struct weston_coord_global pos)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
{
|
2013-06-25 21:56:41 +04:00
|
|
|
|
struct weston_compositor *ec = pointer->seat->compositor;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
struct weston_output *output, *prev = NULL;
|
2022-02-04 01:40:10 +03:00
|
|
|
|
int valid = 0;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
wl_list_for_each(output, &ec->output_list, link) {
|
2013-06-25 21:56:42 +04:00
|
|
|
|
if (pointer->seat->output && pointer->seat->output != output)
|
|
|
|
|
continue;
|
2022-11-09 23:28:15 +03:00
|
|
|
|
if (weston_output_contains_coord(output, pos))
|
2013-04-18 23:40:10 +04:00
|
|
|
|
valid = 1;
|
2022-11-09 23:28:15 +03:00
|
|
|
|
if (weston_output_contains_coord(output, pointer->pos))
|
2013-04-18 23:40:10 +04:00
|
|
|
|
prev = output;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-25 21:56:42 +04:00
|
|
|
|
if (!prev)
|
|
|
|
|
prev = pointer->seat->output;
|
|
|
|
|
|
2013-12-14 00:10:56 +04:00
|
|
|
|
if (prev && !valid)
|
2023-02-07 01:44:51 +03:00
|
|
|
|
pos = weston_pointer_clamp_for_output(pointer, prev, pos);
|
|
|
|
|
|
|
|
|
|
return pos;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-05 23:39:14 +04:00
|
|
|
|
static void
|
|
|
|
|
weston_pointer_move_to(struct weston_pointer *pointer,
|
2023-02-07 01:58:59 +03:00
|
|
|
|
struct weston_coord_global pos)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
{
|
2023-02-07 01:44:51 +03:00
|
|
|
|
pos = weston_pointer_clamp(pointer, pos);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2022-02-04 01:40:10 +03:00
|
|
|
|
pointer->pos = pos;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2013-05-08 23:02:05 +04:00
|
|
|
|
if (pointer->sprite) {
|
2023-08-02 19:38:30 +03:00
|
|
|
|
struct weston_coord_surface hotspot_inv;
|
|
|
|
|
|
|
|
|
|
hotspot_inv = weston_coord_surface_invert(pointer->hotspot);
|
|
|
|
|
weston_view_set_position_with_offset(pointer->sprite,
|
|
|
|
|
pos, hotspot_inv);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
2013-11-15 02:42:50 +04:00
|
|
|
|
|
2013-11-15 02:42:52 +04:00
|
|
|
|
pointer->grab->interface->focus(pointer->grab);
|
2013-11-15 02:42:50 +04:00
|
|
|
|
wl_signal_emit(&pointer->motion_signal, pointer);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-05 23:39:14 +04:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_pointer_move(struct weston_pointer *pointer,
|
|
|
|
|
struct weston_pointer_motion_event *event)
|
|
|
|
|
{
|
2023-02-07 01:21:44 +03:00
|
|
|
|
struct weston_coord_global pos;
|
2014-10-05 23:39:14 +04:00
|
|
|
|
|
2023-02-07 01:21:44 +03:00
|
|
|
|
pos = weston_pointer_motion_to_abs(pointer, event);
|
2023-02-07 01:58:59 +03:00
|
|
|
|
weston_pointer_move_to(pointer, pos);
|
2014-10-05 23:39:14 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-14 00:10:56 +04:00
|
|
|
|
/** Verify if the pointer is in a valid position and move it if it isn't.
|
|
|
|
|
*/
|
2014-01-29 20:47:51 +04:00
|
|
|
|
static void
|
|
|
|
|
weston_pointer_handle_output_destroy(struct wl_listener *listener, void *data)
|
2013-12-14 00:10:56 +04:00
|
|
|
|
{
|
2014-01-29 20:47:51 +04:00
|
|
|
|
struct weston_pointer *pointer;
|
|
|
|
|
struct weston_compositor *ec;
|
2013-12-14 00:10:56 +04:00
|
|
|
|
struct weston_output *output, *closest = NULL;
|
|
|
|
|
int x, y, distance, min = INT_MAX;
|
2023-02-07 01:44:51 +03:00
|
|
|
|
struct weston_coord_global pos;
|
2013-12-14 00:10:56 +04:00
|
|
|
|
|
2014-01-29 20:47:51 +04:00
|
|
|
|
pointer = container_of(listener, struct weston_pointer,
|
|
|
|
|
output_destroy_listener);
|
|
|
|
|
ec = pointer->seat->compositor;
|
|
|
|
|
|
2022-02-04 01:40:10 +03:00
|
|
|
|
x = pointer->pos.c.x;
|
|
|
|
|
y = pointer->pos.c.y;
|
2013-12-14 00:10:56 +04:00
|
|
|
|
|
|
|
|
|
wl_list_for_each(output, &ec->output_list, link) {
|
2022-11-09 23:28:15 +03:00
|
|
|
|
int ox, oy;
|
|
|
|
|
|
|
|
|
|
if (weston_output_contains_coord(output, pointer->pos))
|
2013-12-14 00:10:56 +04:00
|
|
|
|
return;
|
|
|
|
|
|
2022-11-09 23:28:15 +03:00
|
|
|
|
ox = output->pos.c.x;
|
|
|
|
|
oy = output->pos.c.y;
|
2013-12-14 00:10:56 +04:00
|
|
|
|
/* Aproximante the distance from the pointer to the center of
|
|
|
|
|
* the output. */
|
2022-11-09 23:28:15 +03:00
|
|
|
|
distance = abs(ox + output->width / 2 - x) +
|
|
|
|
|
abs(oy + output->height / 2 - y);
|
2013-12-14 00:10:56 +04:00
|
|
|
|
if (distance < min) {
|
|
|
|
|
min = distance;
|
|
|
|
|
closest = output;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Nothing to do if there's no output left. */
|
|
|
|
|
if (!closest)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-02-04 01:40:10 +03:00
|
|
|
|
pos = weston_pointer_clamp_for_output(pointer, closest, pointer->pos);
|
2023-02-07 01:58:59 +03:00
|
|
|
|
weston_pointer_move_to(pointer, pos);
|
2013-12-14 00:10:56 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_motion(struct weston_seat *seat,
|
2017-11-24 19:01:46 +03:00
|
|
|
|
const struct timespec *time,
|
2014-10-05 23:39:14 +04:00
|
|
|
|
struct weston_pointer_motion_event *event)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
{
|
|
|
|
|
struct weston_compositor *ec = seat->compositor;
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
weston_compositor_wake(ec);
|
2014-10-05 23:39:14 +04:00
|
|
|
|
pointer->grab->interface->motion(pointer->grab, time, event);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-19 14:37:12 +04:00
|
|
|
|
static void
|
|
|
|
|
run_modifier_bindings(struct weston_seat *seat, uint32_t old, uint32_t new)
|
|
|
|
|
{
|
|
|
|
|
struct weston_compositor *compositor = seat->compositor;
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
2013-11-19 14:37:12 +04:00
|
|
|
|
uint32_t diff;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
struct {
|
|
|
|
|
uint32_t xkb;
|
|
|
|
|
enum weston_keyboard_modifier weston;
|
|
|
|
|
} mods[] = {
|
2013-12-03 12:14:26 +04:00
|
|
|
|
{ keyboard->xkb_info->ctrl_mod, MODIFIER_CTRL },
|
|
|
|
|
{ keyboard->xkb_info->alt_mod, MODIFIER_ALT },
|
|
|
|
|
{ keyboard->xkb_info->super_mod, MODIFIER_SUPER },
|
|
|
|
|
{ keyboard->xkb_info->shift_mod, MODIFIER_SHIFT },
|
2013-11-19 14:37:12 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
diff = new & ~old;
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(mods); i++) {
|
|
|
|
|
if (diff & (1 << mods[i].xkb))
|
|
|
|
|
weston_compositor_run_modifier_binding(compositor,
|
2015-07-15 21:00:43 +03:00
|
|
|
|
keyboard,
|
2013-11-19 14:37:12 +04:00
|
|
|
|
mods[i].weston,
|
|
|
|
|
WL_KEYBOARD_KEY_STATE_PRESSED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
diff = old & ~new;
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(mods); i++) {
|
|
|
|
|
if (diff & (1 << mods[i].xkb))
|
|
|
|
|
weston_compositor_run_modifier_binding(compositor,
|
2015-07-15 21:00:43 +03:00
|
|
|
|
keyboard,
|
2013-11-19 14:37:12 +04:00
|
|
|
|
mods[i].weston,
|
|
|
|
|
WL_KEYBOARD_KEY_STATE_RELEASED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
WL_EXPORT void
|
2017-11-24 19:01:46 +03:00
|
|
|
|
notify_motion_absolute(struct weston_seat *seat, const struct timespec *time,
|
2023-02-07 16:08:54 +03:00
|
|
|
|
struct weston_coord_global pos)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
{
|
|
|
|
|
struct weston_compositor *ec = seat->compositor;
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
2014-10-05 23:39:14 +04:00
|
|
|
|
struct weston_pointer_motion_event event = { 0 };
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
weston_compositor_wake(ec);
|
2014-10-05 23:39:14 +04:00
|
|
|
|
|
|
|
|
|
event = (struct weston_pointer_motion_event) {
|
|
|
|
|
.mask = WESTON_POINTER_MOTION_ABS,
|
2022-02-02 17:16:38 +03:00
|
|
|
|
.abs = pos,
|
2014-10-05 23:39:14 +04:00
|
|
|
|
};
|
|
|
|
|
pointer->grab->interface->motion(pointer->grab, time, &event);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-18 20:42:19 +04:00
|
|
|
|
static unsigned int
|
|
|
|
|
peek_next_activate_serial(struct weston_compositor *c)
|
|
|
|
|
{
|
|
|
|
|
unsigned serial = c->activate_serial + 1;
|
|
|
|
|
|
|
|
|
|
return serial == 0 ? 1 : serial;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
inc_activate_serial(struct weston_compositor *c)
|
|
|
|
|
{
|
|
|
|
|
c->activate_serial = peek_next_activate_serial (c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2021-03-05 23:07:30 +03:00
|
|
|
|
weston_view_activate_input(struct weston_view *view,
|
2014-10-18 20:42:19 +04:00
|
|
|
|
struct weston_seat *seat,
|
|
|
|
|
uint32_t flags)
|
|
|
|
|
{
|
|
|
|
|
struct weston_compositor *compositor = seat->compositor;
|
2023-03-29 18:30:23 +03:00
|
|
|
|
struct weston_surface_activation_data activation_data;
|
2014-10-18 20:42:19 +04:00
|
|
|
|
|
|
|
|
|
if (flags & WESTON_ACTIVATE_FLAG_CLICKED) {
|
|
|
|
|
view->click_to_activate_serial =
|
|
|
|
|
peek_next_activate_serial(compositor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
weston_seat_set_keyboard_focus(seat, view->surface);
|
2023-03-29 18:30:23 +03:00
|
|
|
|
|
|
|
|
|
inc_activate_serial(compositor);
|
|
|
|
|
|
|
|
|
|
activation_data = (struct weston_surface_activation_data) {
|
2023-03-29 18:33:30 +03:00
|
|
|
|
.view = view,
|
2023-03-29 18:30:23 +03:00
|
|
|
|
.seat = seat,
|
2023-03-29 18:33:30 +03:00
|
|
|
|
.flags = flags
|
2023-03-29 18:30:23 +03:00
|
|
|
|
};
|
|
|
|
|
wl_signal_emit(&compositor->activate_signal, &activation_data);
|
2014-10-18 20:42:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
WL_EXPORT void
|
2017-11-16 19:20:55 +03:00
|
|
|
|
notify_button(struct weston_seat *seat, const struct timespec *time,
|
|
|
|
|
int32_t button, enum wl_pointer_button_state state)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
{
|
|
|
|
|
struct weston_compositor *compositor = seat->compositor;
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
|
|
|
|
weston_compositor_idle_inhibit(compositor);
|
|
|
|
|
if (pointer->button_count == 0) {
|
|
|
|
|
pointer->grab_button = button;
|
2017-11-16 19:20:55 +03:00
|
|
|
|
pointer->grab_time = *time;
|
2022-02-04 01:40:10 +03:00
|
|
|
|
pointer->grab_pos = pointer->pos;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
pointer->button_count++;
|
|
|
|
|
} else {
|
|
|
|
|
weston_compositor_idle_release(compositor);
|
|
|
|
|
pointer->button_count--;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-15 21:00:43 +03:00
|
|
|
|
weston_compositor_run_button_binding(compositor, pointer, time, button,
|
2013-04-18 23:40:10 +04:00
|
|
|
|
state);
|
|
|
|
|
|
|
|
|
|
pointer->grab->interface->button(pointer->grab, time, button, state);
|
|
|
|
|
|
|
|
|
|
if (pointer->button_count == 1)
|
|
|
|
|
pointer->grab_serial =
|
|
|
|
|
wl_display_get_serial(compositor->wl_display);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2017-11-16 19:20:56 +03:00
|
|
|
|
notify_axis(struct weston_seat *seat, const struct timespec *time,
|
2016-01-18 08:58:17 +03:00
|
|
|
|
struct weston_pointer_axis_event *event)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
{
|
|
|
|
|
struct weston_compositor *compositor = seat->compositor;
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
weston_compositor_wake(compositor);
|
|
|
|
|
|
2015-07-15 21:00:43 +03:00
|
|
|
|
if (weston_compositor_run_axis_binding(compositor, pointer,
|
2016-01-18 08:58:17 +03:00
|
|
|
|
time, event))
|
2013-04-18 23:40:10 +04:00
|
|
|
|
return;
|
|
|
|
|
|
2016-01-18 08:58:17 +03:00
|
|
|
|
pointer->grab->interface->axis(pointer->grab, time, event);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-18 09:38:22 +03:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_axis_source(struct weston_seat *seat, uint32_t source)
|
|
|
|
|
{
|
|
|
|
|
struct weston_compositor *compositor = seat->compositor;
|
|
|
|
|
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
|
|
|
|
|
|
|
|
|
weston_compositor_wake(compositor);
|
|
|
|
|
|
|
|
|
|
pointer->grab->interface->axis_source(pointer->grab, source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_pointer_frame(struct weston_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
struct weston_compositor *compositor = seat->compositor;
|
|
|
|
|
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
|
|
|
|
|
|
|
|
|
weston_compositor_wake(compositor);
|
|
|
|
|
|
|
|
|
|
pointer->grab->interface->frame(pointer->grab);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-28 20:44:09 +04:00
|
|
|
|
WL_EXPORT int
|
|
|
|
|
weston_keyboard_set_locks(struct weston_keyboard *keyboard,
|
|
|
|
|
uint32_t mask, uint32_t value)
|
|
|
|
|
{
|
|
|
|
|
uint32_t serial;
|
|
|
|
|
xkb_mod_mask_t mods_depressed, mods_latched, mods_locked, group;
|
|
|
|
|
xkb_mod_mask_t num, caps;
|
|
|
|
|
|
|
|
|
|
/* We don't want the leds to go out of sync with the actual state
|
|
|
|
|
* so if the backend has no way to change the leds don't try to
|
|
|
|
|
* change the state */
|
|
|
|
|
if (!keyboard->seat->led_update)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
mods_depressed = xkb_state_serialize_mods(keyboard->xkb_state.state,
|
|
|
|
|
XKB_STATE_DEPRESSED);
|
|
|
|
|
mods_latched = xkb_state_serialize_mods(keyboard->xkb_state.state,
|
|
|
|
|
XKB_STATE_LATCHED);
|
|
|
|
|
mods_locked = xkb_state_serialize_mods(keyboard->xkb_state.state,
|
|
|
|
|
XKB_STATE_LOCKED);
|
|
|
|
|
group = xkb_state_serialize_group(keyboard->xkb_state.state,
|
2021-07-31 18:25:41 +03:00
|
|
|
|
XKB_STATE_EFFECTIVE);
|
2014-08-28 20:44:09 +04:00
|
|
|
|
|
|
|
|
|
num = (1 << keyboard->xkb_info->mod2_mod);
|
|
|
|
|
caps = (1 << keyboard->xkb_info->caps_mod);
|
|
|
|
|
if (mask & WESTON_NUM_LOCK) {
|
|
|
|
|
if (value & WESTON_NUM_LOCK)
|
|
|
|
|
mods_locked |= num;
|
|
|
|
|
else
|
|
|
|
|
mods_locked &= ~num;
|
|
|
|
|
}
|
|
|
|
|
if (mask & WESTON_CAPS_LOCK) {
|
|
|
|
|
if (value & WESTON_CAPS_LOCK)
|
|
|
|
|
mods_locked |= caps;
|
|
|
|
|
else
|
|
|
|
|
mods_locked &= ~caps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xkb_state_update_mask(keyboard->xkb_state.state, mods_depressed,
|
|
|
|
|
mods_latched, mods_locked, 0, 0, group);
|
|
|
|
|
|
|
|
|
|
serial = wl_display_next_serial(
|
|
|
|
|
keyboard->seat->compositor->wl_display);
|
|
|
|
|
notify_modifiers(keyboard->seat, serial);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_modifiers(struct weston_seat *seat, uint32_t serial)
|
|
|
|
|
{
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
struct weston_keyboard_grab *grab = keyboard->grab;
|
|
|
|
|
uint32_t mods_depressed, mods_latched, mods_locked, group;
|
|
|
|
|
uint32_t mods_lookup;
|
|
|
|
|
enum weston_led leds = 0;
|
|
|
|
|
int changed = 0;
|
|
|
|
|
|
|
|
|
|
/* Serialize and update our internal state, checking to see if it's
|
|
|
|
|
* different to the previous state. */
|
2013-12-03 12:14:26 +04:00
|
|
|
|
mods_depressed = xkb_state_serialize_mods(keyboard->xkb_state.state,
|
2014-08-20 00:59:51 +04:00
|
|
|
|
XKB_STATE_MODS_DEPRESSED);
|
2013-12-03 12:14:26 +04:00
|
|
|
|
mods_latched = xkb_state_serialize_mods(keyboard->xkb_state.state,
|
2014-08-20 00:59:51 +04:00
|
|
|
|
XKB_STATE_MODS_LATCHED);
|
2013-12-03 12:14:26 +04:00
|
|
|
|
mods_locked = xkb_state_serialize_mods(keyboard->xkb_state.state,
|
2014-08-20 00:59:51 +04:00
|
|
|
|
XKB_STATE_MODS_LOCKED);
|
|
|
|
|
group = xkb_state_serialize_layout(keyboard->xkb_state.state,
|
|
|
|
|
XKB_STATE_LAYOUT_EFFECTIVE);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2015-06-03 23:53:26 +03:00
|
|
|
|
if (mods_depressed != keyboard->modifiers.mods_depressed ||
|
|
|
|
|
mods_latched != keyboard->modifiers.mods_latched ||
|
|
|
|
|
mods_locked != keyboard->modifiers.mods_locked ||
|
|
|
|
|
group != keyboard->modifiers.group)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
changed = 1;
|
|
|
|
|
|
2015-06-03 23:53:26 +03:00
|
|
|
|
run_modifier_bindings(seat, keyboard->modifiers.mods_depressed,
|
2013-11-19 14:37:12 +04:00
|
|
|
|
mods_depressed);
|
|
|
|
|
|
2015-06-03 23:53:26 +03:00
|
|
|
|
keyboard->modifiers.mods_depressed = mods_depressed;
|
|
|
|
|
keyboard->modifiers.mods_latched = mods_latched;
|
|
|
|
|
keyboard->modifiers.mods_locked = mods_locked;
|
|
|
|
|
keyboard->modifiers.group = group;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
/* And update the modifier_state for bindings. */
|
|
|
|
|
mods_lookup = mods_depressed | mods_latched;
|
|
|
|
|
seat->modifier_state = 0;
|
2013-12-03 12:14:26 +04:00
|
|
|
|
if (mods_lookup & (1 << keyboard->xkb_info->ctrl_mod))
|
2013-04-18 23:40:10 +04:00
|
|
|
|
seat->modifier_state |= MODIFIER_CTRL;
|
2013-12-03 12:14:26 +04:00
|
|
|
|
if (mods_lookup & (1 << keyboard->xkb_info->alt_mod))
|
2013-04-18 23:40:10 +04:00
|
|
|
|
seat->modifier_state |= MODIFIER_ALT;
|
2013-12-03 12:14:26 +04:00
|
|
|
|
if (mods_lookup & (1 << keyboard->xkb_info->super_mod))
|
2013-04-18 23:40:10 +04:00
|
|
|
|
seat->modifier_state |= MODIFIER_SUPER;
|
2013-12-03 12:14:26 +04:00
|
|
|
|
if (mods_lookup & (1 << keyboard->xkb_info->shift_mod))
|
2013-04-18 23:40:10 +04:00
|
|
|
|
seat->modifier_state |= MODIFIER_SHIFT;
|
|
|
|
|
|
|
|
|
|
/* Finally, notify the compositor that LEDs have changed. */
|
2013-12-03 12:14:26 +04:00
|
|
|
|
if (xkb_state_led_index_is_active(keyboard->xkb_state.state,
|
|
|
|
|
keyboard->xkb_info->num_led))
|
2013-04-18 23:40:10 +04:00
|
|
|
|
leds |= LED_NUM_LOCK;
|
2013-12-03 12:14:26 +04:00
|
|
|
|
if (xkb_state_led_index_is_active(keyboard->xkb_state.state,
|
|
|
|
|
keyboard->xkb_info->caps_led))
|
2013-04-18 23:40:10 +04:00
|
|
|
|
leds |= LED_CAPS_LOCK;
|
2013-12-03 12:14:26 +04:00
|
|
|
|
if (xkb_state_led_index_is_active(keyboard->xkb_state.state,
|
|
|
|
|
keyboard->xkb_info->scroll_led))
|
2013-04-18 23:40:10 +04:00
|
|
|
|
leds |= LED_SCROLL_LOCK;
|
2013-12-03 12:14:26 +04:00
|
|
|
|
if (leds != keyboard->xkb_state.leds && seat->led_update)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
seat->led_update(seat, leds);
|
2013-12-03 12:14:26 +04:00
|
|
|
|
keyboard->xkb_state.leds = leds;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
|
grab->interface->modifiers(grab,
|
|
|
|
|
serial,
|
|
|
|
|
keyboard->modifiers.mods_depressed,
|
|
|
|
|
keyboard->modifiers.mods_latched,
|
|
|
|
|
keyboard->modifiers.mods_locked,
|
|
|
|
|
keyboard->modifiers.group);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
update_modifier_state(struct weston_seat *seat, uint32_t serial, uint32_t key,
|
|
|
|
|
enum wl_keyboard_key_state state)
|
|
|
|
|
{
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
enum xkb_key_direction direction;
|
|
|
|
|
|
|
|
|
|
if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
|
|
|
|
|
direction = XKB_KEY_DOWN;
|
|
|
|
|
else
|
|
|
|
|
direction = XKB_KEY_UP;
|
|
|
|
|
|
|
|
|
|
/* Offset the keycode by 8, as the evdev XKB rules reflect X's
|
|
|
|
|
* broken keycode system, which starts at 8. */
|
2013-12-03 12:14:26 +04:00
|
|
|
|
xkb_state_update_key(keyboard->xkb_state.state, key + 8, direction);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
notify_modifiers(seat, serial);
|
|
|
|
|
}
|
2013-10-10 21:44:19 +04:00
|
|
|
|
|
2017-06-28 19:41:43 +03:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_keyboard_send_keymap(struct weston_keyboard *kbd, struct wl_resource *resource)
|
2013-10-10 21:44:19 +04:00
|
|
|
|
{
|
2017-06-28 19:41:43 +03:00
|
|
|
|
struct weston_xkb_info *xkb_info = kbd->xkb_info;
|
2017-06-28 20:17:46 +03:00
|
|
|
|
int fd;
|
2019-11-01 04:38:45 +03:00
|
|
|
|
size_t size;
|
|
|
|
|
enum ro_anonymous_file_mapmode mapmode;
|
2017-06-28 19:41:43 +03:00
|
|
|
|
|
2019-11-01 04:38:45 +03:00
|
|
|
|
if (wl_resource_get_version(resource) < 7)
|
|
|
|
|
mapmode = RO_ANONYMOUS_FILE_MAPMODE_SHARED;
|
|
|
|
|
else
|
|
|
|
|
mapmode = RO_ANONYMOUS_FILE_MAPMODE_PRIVATE;
|
|
|
|
|
|
|
|
|
|
fd = os_ro_anonymous_file_get_fd(xkb_info->keymap_rofile, mapmode);
|
|
|
|
|
size = os_ro_anonymous_file_size(xkb_info->keymap_rofile);
|
|
|
|
|
|
|
|
|
|
if (fd == -1) {
|
|
|
|
|
weston_log("creating a keymap file failed: %s\n",
|
2019-04-27 00:57:31 +03:00
|
|
|
|
strerror(errno));
|
2017-06-28 20:17:46 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-10 21:44:19 +04:00
|
|
|
|
wl_keyboard_send_keymap(resource,
|
|
|
|
|
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
|
2017-06-28 20:17:46 +03:00
|
|
|
|
fd,
|
2019-11-01 04:38:45 +03:00
|
|
|
|
size);
|
|
|
|
|
|
|
|
|
|
os_ro_anonymous_file_put_fd(fd);
|
2013-10-10 21:44:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
send_modifiers(struct wl_resource *resource, uint32_t serial, struct weston_keyboard *keyboard)
|
|
|
|
|
{
|
|
|
|
|
wl_keyboard_send_modifiers(resource, serial,
|
|
|
|
|
keyboard->modifiers.mods_depressed,
|
|
|
|
|
keyboard->modifiers.mods_latched,
|
|
|
|
|
keyboard->modifiers.mods_locked,
|
|
|
|
|
keyboard->modifiers.group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct weston_xkb_info *
|
|
|
|
|
weston_xkb_info_create(struct xkb_keymap *keymap);
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
update_keymap(struct weston_seat *seat)
|
|
|
|
|
{
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
2013-10-10 21:44:19 +04:00
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
struct weston_xkb_info *xkb_info;
|
|
|
|
|
struct xkb_state *state;
|
|
|
|
|
xkb_mod_mask_t latched_mods;
|
|
|
|
|
xkb_mod_mask_t locked_mods;
|
|
|
|
|
|
2013-12-03 12:14:26 +04:00
|
|
|
|
xkb_info = weston_xkb_info_create(keyboard->pending_keymap);
|
2013-10-10 21:44:19 +04:00
|
|
|
|
|
2013-12-03 12:14:26 +04:00
|
|
|
|
xkb_keymap_unref(keyboard->pending_keymap);
|
|
|
|
|
keyboard->pending_keymap = NULL;
|
2013-10-10 21:44:19 +04:00
|
|
|
|
|
|
|
|
|
if (!xkb_info) {
|
|
|
|
|
weston_log("failed to create XKB info\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
state = xkb_state_new(xkb_info->keymap);
|
|
|
|
|
if (!state) {
|
|
|
|
|
weston_log("failed to initialise XKB state\n");
|
|
|
|
|
weston_xkb_info_destroy(xkb_info);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-03 12:14:26 +04:00
|
|
|
|
latched_mods = xkb_state_serialize_mods(keyboard->xkb_state.state,
|
|
|
|
|
XKB_STATE_MODS_LATCHED);
|
|
|
|
|
locked_mods = xkb_state_serialize_mods(keyboard->xkb_state.state,
|
|
|
|
|
XKB_STATE_MODS_LOCKED);
|
2013-10-10 21:44:19 +04:00
|
|
|
|
xkb_state_update_mask(state,
|
|
|
|
|
0, /* depressed */
|
|
|
|
|
latched_mods,
|
|
|
|
|
locked_mods,
|
|
|
|
|
0, 0, 0);
|
|
|
|
|
|
2013-12-03 12:14:26 +04:00
|
|
|
|
weston_xkb_info_destroy(keyboard->xkb_info);
|
|
|
|
|
keyboard->xkb_info = xkb_info;
|
2013-10-10 21:44:19 +04:00
|
|
|
|
|
2013-12-03 12:14:26 +04:00
|
|
|
|
xkb_state_unref(keyboard->xkb_state.state);
|
|
|
|
|
keyboard->xkb_state.state = state;
|
2013-10-10 21:44:19 +04:00
|
|
|
|
|
2015-06-03 23:53:27 +03:00
|
|
|
|
wl_resource_for_each(resource, &keyboard->resource_list)
|
2017-06-28 19:41:43 +03:00
|
|
|
|
weston_keyboard_send_keymap(keyboard, resource);
|
2015-06-03 23:53:27 +03:00
|
|
|
|
wl_resource_for_each(resource, &keyboard->focus_resource_list)
|
2017-06-28 19:41:43 +03:00
|
|
|
|
weston_keyboard_send_keymap(keyboard, resource);
|
2013-10-10 21:44:19 +04:00
|
|
|
|
|
|
|
|
|
notify_modifiers(seat, wl_display_next_serial(seat->compositor->wl_display));
|
|
|
|
|
|
|
|
|
|
if (!latched_mods && !locked_mods)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-06-03 23:53:27 +03:00
|
|
|
|
wl_resource_for_each(resource, &keyboard->resource_list)
|
|
|
|
|
send_modifiers(resource, wl_display_get_serial(seat->compositor->wl_display), keyboard);
|
|
|
|
|
wl_resource_for_each(resource, &keyboard->focus_resource_list)
|
|
|
|
|
send_modifiers(resource, wl_display_get_serial(seat->compositor->wl_display), keyboard);
|
2013-10-10 21:44:19 +04:00
|
|
|
|
}
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2017-11-16 19:20:57 +03:00
|
|
|
|
notify_key(struct weston_seat *seat, const struct timespec *time, uint32_t key,
|
2013-04-18 23:40:10 +04:00
|
|
|
|
enum wl_keyboard_key_state state,
|
|
|
|
|
enum weston_key_state_update update_state)
|
|
|
|
|
{
|
|
|
|
|
struct weston_compositor *compositor = seat->compositor;
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
struct weston_keyboard_grab *grab = keyboard->grab;
|
2014-11-19 14:43:32 +03:00
|
|
|
|
uint32_t *k, *end;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2014-11-19 14:43:32 +03:00
|
|
|
|
end = keyboard->keys.data + keyboard->keys.size;
|
|
|
|
|
for (k = keyboard->keys.data; k < end; k++) {
|
|
|
|
|
if (*k == key) {
|
|
|
|
|
/* Ignore server-generated repeats. */
|
|
|
|
|
if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
|
|
|
|
|
return;
|
|
|
|
|
*k = *--end;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
keyboard->keys.size = (void *) end - keyboard->keys.data;
|
|
|
|
|
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
|
|
|
|
k = wl_array_add(&keyboard->keys, sizeof *k);
|
|
|
|
|
*k = key;
|
|
|
|
|
}
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2022-03-10 17:51:34 +03:00
|
|
|
|
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
|
|
|
|
weston_compositor_idle_inhibit(compositor);
|
|
|
|
|
} else {
|
|
|
|
|
weston_compositor_idle_release(compositor);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
if (grab == &keyboard->default_grab ||
|
|
|
|
|
grab == &keyboard->input_method_grab) {
|
2015-07-15 21:00:43 +03:00
|
|
|
|
weston_compositor_run_key_binding(compositor, keyboard, time,
|
|
|
|
|
key, state);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
grab = keyboard->grab;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
grab->interface->key(grab, time, key, state);
|
|
|
|
|
|
2013-12-03 12:14:26 +04:00
|
|
|
|
if (keyboard->pending_keymap &&
|
2014-11-19 14:43:32 +03:00
|
|
|
|
keyboard->keys.size == 0)
|
2013-10-10 21:44:19 +04:00
|
|
|
|
update_keymap(seat);
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
if (update_state == STATE_UPDATE_AUTOMATIC) {
|
|
|
|
|
update_modifier_state(seat,
|
|
|
|
|
wl_display_get_serial(compositor->wl_display),
|
|
|
|
|
key,
|
|
|
|
|
state);
|
|
|
|
|
}
|
2015-02-06 20:06:54 +03:00
|
|
|
|
|
2016-06-30 17:01:56 +03:00
|
|
|
|
keyboard->grab_serial = wl_display_get_serial(compositor->wl_display);
|
2015-02-06 20:06:54 +03:00
|
|
|
|
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
2017-11-16 19:20:57 +03:00
|
|
|
|
keyboard->grab_time = *time;
|
2015-02-06 20:06:54 +03:00
|
|
|
|
keyboard->grab_key = key;
|
|
|
|
|
}
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-25 23:58:24 +03:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
clear_pointer_focus(struct weston_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: We should call weston_pointer_set_focus(seat, NULL) here,
|
|
|
|
|
* but somehow that breaks re-entry... */
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_pointer_focus(struct weston_seat *seat, struct weston_output *output,
|
2023-02-07 16:08:54 +03:00
|
|
|
|
struct weston_coord_global pos)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
{
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
|
|
|
|
|
2022-10-25 23:58:24 +03:00
|
|
|
|
assert(output);
|
|
|
|
|
|
2023-02-07 01:58:59 +03:00
|
|
|
|
weston_pointer_move_to(pointer, pos);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
destroy_device_saved_kbd_focus(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct weston_seat *ws;
|
|
|
|
|
|
|
|
|
|
ws = container_of(listener, struct weston_seat,
|
|
|
|
|
saved_kbd_focus_listener);
|
|
|
|
|
|
|
|
|
|
ws->saved_kbd_focus = NULL;
|
2021-08-11 01:17:24 +03:00
|
|
|
|
|
|
|
|
|
wl_list_remove(&ws->saved_kbd_focus_listener.link);
|
|
|
|
|
ws->saved_kbd_focus_listener.notify = NULL;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_keyboard_focus_in(struct weston_seat *seat, struct wl_array *keys,
|
|
|
|
|
enum weston_key_state_update update_state)
|
|
|
|
|
{
|
|
|
|
|
struct weston_compositor *compositor = seat->compositor;
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
2013-05-08 17:54:37 +04:00
|
|
|
|
struct weston_surface *surface;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
uint32_t *k, serial;
|
|
|
|
|
|
|
|
|
|
serial = wl_display_next_serial(compositor->wl_display);
|
|
|
|
|
wl_array_copy(&keyboard->keys, keys);
|
|
|
|
|
wl_array_for_each(k, &keyboard->keys) {
|
|
|
|
|
weston_compositor_idle_inhibit(compositor);
|
|
|
|
|
if (update_state == STATE_UPDATE_AUTOMATIC)
|
|
|
|
|
update_modifier_state(seat, serial, *k,
|
|
|
|
|
WL_KEYBOARD_KEY_STATE_PRESSED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
surface = seat->saved_kbd_focus;
|
|
|
|
|
if (surface) {
|
2021-08-11 01:17:24 +03:00
|
|
|
|
wl_list_remove(&seat->saved_kbd_focus_listener.link);
|
|
|
|
|
seat->saved_kbd_focus_listener.notify = NULL;
|
|
|
|
|
seat->saved_kbd_focus = NULL;
|
|
|
|
|
if (seat->use_saved_kbd_focus)
|
|
|
|
|
weston_keyboard_set_focus(keyboard, surface);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_keyboard_focus_out(struct weston_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
struct weston_compositor *compositor = seat->compositor;
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
|
|
|
|
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
|
2017-07-21 15:02:40 +03:00
|
|
|
|
struct weston_surface *focus = keyboard->focus;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
uint32_t *k, serial;
|
|
|
|
|
|
|
|
|
|
serial = wl_display_next_serial(compositor->wl_display);
|
|
|
|
|
wl_array_for_each(k, &keyboard->keys) {
|
|
|
|
|
weston_compositor_idle_release(compositor);
|
|
|
|
|
update_modifier_state(seat, serial, *k,
|
|
|
|
|
WL_KEYBOARD_KEY_STATE_RELEASED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
seat->modifier_state = 0;
|
|
|
|
|
|
|
|
|
|
weston_keyboard_set_focus(keyboard, NULL);
|
2013-10-26 01:18:05 +04:00
|
|
|
|
weston_keyboard_cancel_grab(keyboard);
|
2015-08-01 00:55:32 +03:00
|
|
|
|
if (pointer)
|
|
|
|
|
weston_pointer_cancel_grab(pointer);
|
2017-07-21 15:02:40 +03:00
|
|
|
|
|
|
|
|
|
if (focus) {
|
2021-08-11 01:17:24 +03:00
|
|
|
|
seat->use_saved_kbd_focus = true;
|
2017-07-21 15:02:40 +03:00
|
|
|
|
seat->saved_kbd_focus = focus;
|
2022-08-30 20:26:28 +03:00
|
|
|
|
assert(seat->saved_kbd_focus_listener.notify == NULL);
|
2017-07-21 15:02:40 +03:00
|
|
|
|
seat->saved_kbd_focus_listener.notify =
|
|
|
|
|
destroy_device_saved_kbd_focus;
|
|
|
|
|
wl_signal_add(&focus->destroy_signal,
|
|
|
|
|
&seat->saved_kbd_focus_listener);
|
|
|
|
|
}
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-23 11:51:06 +04:00
|
|
|
|
WL_EXPORT void
|
2015-05-01 00:45:41 +03:00
|
|
|
|
weston_touch_set_focus(struct weston_touch *touch, struct weston_view *view)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
{
|
2013-09-19 20:32:00 +04:00
|
|
|
|
struct wl_list *focus_resource_list;
|
|
|
|
|
|
2015-05-01 00:45:41 +03:00
|
|
|
|
focus_resource_list = &touch->focus_resource_list;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2015-05-01 00:45:41 +03:00
|
|
|
|
if (view && touch->focus &&
|
|
|
|
|
touch->focus->surface == view->surface) {
|
|
|
|
|
touch->focus = view;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
return;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
}
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2015-05-01 00:45:41 +03:00
|
|
|
|
wl_list_remove(&touch->focus_resource_listener.link);
|
|
|
|
|
wl_list_init(&touch->focus_resource_listener.link);
|
|
|
|
|
wl_list_remove(&touch->focus_view_listener.link);
|
|
|
|
|
wl_list_init(&touch->focus_view_listener.link);
|
2013-11-20 21:00:24 +04:00
|
|
|
|
|
2013-09-19 20:32:00 +04:00
|
|
|
|
if (!wl_list_empty(focus_resource_list)) {
|
2015-05-01 00:45:41 +03:00
|
|
|
|
move_resources(&touch->resource_list,
|
2013-09-19 20:32:00 +04:00
|
|
|
|
focus_resource_list);
|
|
|
|
|
}
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
if (view) {
|
2014-09-04 19:23:05 +04:00
|
|
|
|
struct wl_client *surface_client;
|
|
|
|
|
|
|
|
|
|
if (!view->surface->resource) {
|
2015-05-01 00:45:41 +03:00
|
|
|
|
touch->focus = NULL;
|
2014-09-04 19:23:05 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
surface_client = wl_resource_get_client(view->surface->resource);
|
2013-09-19 20:32:00 +04:00
|
|
|
|
move_resources_for_client(focus_resource_list,
|
2015-05-01 00:45:41 +03:00
|
|
|
|
&touch->resource_list,
|
2013-09-19 20:32:00 +04:00
|
|
|
|
surface_client);
|
2013-11-20 21:00:24 +04:00
|
|
|
|
wl_resource_add_destroy_listener(view->surface->resource,
|
2015-05-01 00:45:41 +03:00
|
|
|
|
&touch->focus_resource_listener);
|
|
|
|
|
wl_signal_add(&view->destroy_signal, &touch->focus_view_listener);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
2015-05-01 00:45:41 +03:00
|
|
|
|
touch->focus = view;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-26 17:18:29 +03:00
|
|
|
|
static void
|
|
|
|
|
process_touch_normal(struct weston_touch_device *device,
|
|
|
|
|
const struct timespec *time, int touch_id,
|
2023-02-07 16:08:54 +03:00
|
|
|
|
const struct weston_coord_global *pos, int touch_type)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
{
|
2018-02-26 15:43:00 +03:00
|
|
|
|
struct weston_touch *touch = device->aggregate;
|
|
|
|
|
struct weston_touch_grab *grab = device->aggregate->grab;
|
|
|
|
|
struct weston_compositor *ec = device->aggregate->seat->compositor;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
struct weston_view *ev;
|
2023-02-07 16:08:54 +03:00
|
|
|
|
|
2022-02-08 18:50:25 +03:00
|
|
|
|
if (touch_type != WL_TOUCH_UP)
|
|
|
|
|
assert(pos);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
/* Update grab's global coordinates. */
|
2022-02-07 22:56:28 +03:00
|
|
|
|
if (touch_id == touch->grab_touch_id && touch_type != WL_TOUCH_UP)
|
|
|
|
|
touch->grab_pos = *pos;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
switch (touch_type) {
|
|
|
|
|
case WL_TOUCH_DOWN:
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
/* the first finger down picks the view, and all further go
|
|
|
|
|
* to that view for the remainder of the touch session i.e.
|
2013-04-18 23:40:10 +04:00
|
|
|
|
* until all touch points are up again. */
|
2013-12-03 01:05:03 +04:00
|
|
|
|
if (touch->num_tp == 1) {
|
2022-02-03 02:23:33 +03:00
|
|
|
|
ev = weston_compositor_pick_view(ec, *pos);
|
2015-05-01 00:45:41 +03:00
|
|
|
|
weston_touch_set_focus(touch, ev);
|
2015-07-08 11:55:28 +03:00
|
|
|
|
} else if (!touch->focus) {
|
2013-04-18 23:40:10 +04:00
|
|
|
|
/* Unexpected condition: We have non-initial touch but
|
|
|
|
|
* there is no focused surface.
|
|
|
|
|
*/
|
2015-10-07 18:59:49 +03:00
|
|
|
|
weston_log("touch event received with %d points down "
|
2013-12-03 01:05:03 +04:00
|
|
|
|
"but no surface focused\n", touch->num_tp);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-15 21:00:43 +03:00
|
|
|
|
weston_compositor_run_touch_binding(ec, touch,
|
2014-02-06 02:25:18 +04:00
|
|
|
|
time, touch_type);
|
|
|
|
|
|
2022-02-08 18:50:25 +03:00
|
|
|
|
grab->interface->down(grab, time, touch_id, *pos);
|
2013-12-03 01:05:03 +04:00
|
|
|
|
if (touch->num_tp == 1) {
|
2013-08-09 08:13:57 +04:00
|
|
|
|
touch->grab_serial =
|
|
|
|
|
wl_display_get_serial(ec->wl_display);
|
2013-10-03 19:43:06 +04:00
|
|
|
|
touch->grab_touch_id = touch_id;
|
2017-11-16 19:20:58 +03:00
|
|
|
|
touch->grab_time = *time;
|
2022-02-07 22:56:28 +03:00
|
|
|
|
touch->grab_pos = *pos;
|
2013-08-09 08:13:57 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
break;
|
|
|
|
|
case WL_TOUCH_MOTION:
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
ev = touch->focus;
|
|
|
|
|
if (!ev)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
break;
|
|
|
|
|
|
2022-02-08 18:50:25 +03:00
|
|
|
|
grab->interface->motion(grab, time, touch_id, *pos);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
break;
|
|
|
|
|
case WL_TOUCH_UP:
|
2017-11-16 19:20:59 +03:00
|
|
|
|
grab->interface->up(grab, time, touch_id);
|
2022-08-09 15:01:29 +03:00
|
|
|
|
touch->pending_focus_reset = true;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
input: introduce touch event mode for calibrator
In addition to the normal touch event processing mode, introduce a new
mode for calibrating a touchscreen input device.
In the calibration mode, normal touch event processing is skipped, and
the raw events are forwarded to the calibrator instead. The calibrator
is not yet implemented, so the calls will be added in a following patch.
To switch between modes, two functions are added, one for entering each
mode. The mode switch happens only when no touches are down on any touch
device, to avoid confusing touch grabs and clients. To realise this, the
state machine has four states: prepare and actual state for both normal
and calibrator modes.
At this point nothing will attempt to change the touch event mode.
The new calibrator mode is necessary, because when calibrating a
touchscreen, the touch events must be routed to the calibration client
directly. The touch coordinates are expected to be wrong, so they cannot
go through the normal focus surface picking. The calibrator code also
cannot use the normal touch grab interface, because it needs to be able
to distinguish between different physical touch input devices, even if
they are part of the same weston_seat. This requirement makes
calibration special enough to warrant the new mode, a sort of "super
grab".
Co-developed by Louis-Francis and Pekka.
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
v1 Tested-by: Matt Hoosier <matt.hoosier@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-11-29 04:42:47 +03:00
|
|
|
|
static enum weston_touch_mode
|
|
|
|
|
get_next_touch_mode(enum weston_touch_mode from)
|
|
|
|
|
{
|
|
|
|
|
switch (from) {
|
|
|
|
|
case WESTON_TOUCH_MODE_PREP_NORMAL:
|
|
|
|
|
return WESTON_TOUCH_MODE_NORMAL;
|
|
|
|
|
|
|
|
|
|
case WESTON_TOUCH_MODE_PREP_CALIB:
|
|
|
|
|
return WESTON_TOUCH_MODE_CALIB;
|
|
|
|
|
|
|
|
|
|
case WESTON_TOUCH_MODE_NORMAL:
|
|
|
|
|
case WESTON_TOUCH_MODE_CALIB:
|
|
|
|
|
return from;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return WESTON_TOUCH_MODE_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Global touch mode update
|
|
|
|
|
*
|
|
|
|
|
* If no seat has a touch down and the compositor is in a PREP touch mode,
|
|
|
|
|
* set the compositor to the goal touch mode.
|
|
|
|
|
*
|
|
|
|
|
* Calls calibrator if touch mode changed.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
weston_compositor_update_touch_mode(struct weston_compositor *compositor)
|
|
|
|
|
{
|
|
|
|
|
struct weston_seat *seat;
|
|
|
|
|
struct weston_touch *touch;
|
|
|
|
|
enum weston_touch_mode goal;
|
|
|
|
|
|
|
|
|
|
wl_list_for_each(seat, &compositor->seat_list, link) {
|
|
|
|
|
touch = weston_seat_get_touch(seat);
|
|
|
|
|
if (!touch)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (touch->num_tp > 0)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goal = get_next_touch_mode(compositor->touch_mode);
|
|
|
|
|
if (compositor->touch_mode != goal) {
|
|
|
|
|
compositor->touch_mode = goal;
|
|
|
|
|
touch_calibrator_mode_changed(compositor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Start transition to normal touch event handling
|
|
|
|
|
*
|
|
|
|
|
* The touch event mode changes when all touches on all touch devices have
|
|
|
|
|
* been lifted. If no touches are currently down, the transition is immediate.
|
|
|
|
|
*
|
|
|
|
|
* \sa weston_touch_mode
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
weston_compositor_set_touch_mode_normal(struct weston_compositor *compositor)
|
|
|
|
|
{
|
|
|
|
|
switch (compositor->touch_mode) {
|
|
|
|
|
case WESTON_TOUCH_MODE_PREP_NORMAL:
|
|
|
|
|
case WESTON_TOUCH_MODE_NORMAL:
|
|
|
|
|
return;
|
|
|
|
|
case WESTON_TOUCH_MODE_PREP_CALIB:
|
|
|
|
|
compositor->touch_mode = WESTON_TOUCH_MODE_NORMAL;
|
|
|
|
|
touch_calibrator_mode_changed(compositor);
|
|
|
|
|
return;
|
|
|
|
|
case WESTON_TOUCH_MODE_CALIB:
|
|
|
|
|
compositor->touch_mode = WESTON_TOUCH_MODE_PREP_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
weston_compositor_update_touch_mode(compositor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Start transition to calibrator touch event handling
|
|
|
|
|
*
|
|
|
|
|
* The touch event mode changes when all touches on all touch devices have
|
|
|
|
|
* been lifted. If no touches are currently down, the transition is immediate.
|
|
|
|
|
*
|
|
|
|
|
* \sa weston_touch_mode
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
weston_compositor_set_touch_mode_calib(struct weston_compositor *compositor)
|
|
|
|
|
{
|
|
|
|
|
switch (compositor->touch_mode) {
|
|
|
|
|
case WESTON_TOUCH_MODE_PREP_CALIB:
|
|
|
|
|
case WESTON_TOUCH_MODE_CALIB:
|
|
|
|
|
assert(0);
|
|
|
|
|
return;
|
|
|
|
|
case WESTON_TOUCH_MODE_PREP_NORMAL:
|
|
|
|
|
compositor->touch_mode = WESTON_TOUCH_MODE_CALIB;
|
|
|
|
|
touch_calibrator_mode_changed(compositor);
|
|
|
|
|
return;
|
|
|
|
|
case WESTON_TOUCH_MODE_NORMAL:
|
|
|
|
|
compositor->touch_mode = WESTON_TOUCH_MODE_PREP_CALIB;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
weston_compositor_update_touch_mode(compositor);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-26 17:18:29 +03:00
|
|
|
|
/** Feed in touch down, motion, and up events, calibratable device.
|
|
|
|
|
*
|
|
|
|
|
* It assumes always the correct cycle sequence until it gets here: touch_down
|
|
|
|
|
* → touch_update → ... → touch_update → touch_end. The driver is responsible
|
|
|
|
|
* for sending along such order.
|
|
|
|
|
*
|
|
|
|
|
* \param device The physical device that generated the event.
|
|
|
|
|
* \param time The event timestamp.
|
|
|
|
|
* \param touch_id ID for the touch point of this event (multi-touch).
|
2023-02-07 16:08:54 +03:00
|
|
|
|
* \param pos X,Y coordinate in compositor global space, or NULL for WL_TOUCH_UP.
|
2018-02-26 17:18:29 +03:00
|
|
|
|
* \param norm Normalized device X, Y coordinates in calibration space, or NULL.
|
|
|
|
|
* \param touch_type Either WL_TOUCH_DOWN, WL_TOUCH_UP, or WL_TOUCH_MOTION.
|
|
|
|
|
*
|
|
|
|
|
* Coordinates double_x and double_y are used for normal operation.
|
|
|
|
|
*
|
|
|
|
|
* Coordinates norm are only used for touch device calibration. If and only if
|
|
|
|
|
* the weston_touch_device does not support calibrating, norm must be NULL.
|
|
|
|
|
*
|
|
|
|
|
* The calibration space is the normalized coordinate space
|
|
|
|
|
* [0.0, 1.0]×[0.0, 1.0] of the weston_touch_device. This is assumed to
|
|
|
|
|
* map to the similar normalized coordinate space of the associated
|
|
|
|
|
* weston_output.
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_touch_normalized(struct weston_touch_device *device,
|
|
|
|
|
const struct timespec *time,
|
|
|
|
|
int touch_id,
|
2023-02-07 16:08:54 +03:00
|
|
|
|
const struct weston_coord_global *pos,
|
2018-02-26 17:18:29 +03:00
|
|
|
|
const struct weston_point2d_device_normalized *norm,
|
|
|
|
|
int touch_type)
|
|
|
|
|
{
|
2017-11-29 04:42:47 +03:00
|
|
|
|
struct weston_seat *seat = device->aggregate->seat;
|
|
|
|
|
struct weston_touch *touch = device->aggregate;
|
|
|
|
|
|
2018-02-26 17:18:29 +03:00
|
|
|
|
if (touch_type != WL_TOUCH_UP) {
|
2023-02-07 16:08:54 +03:00
|
|
|
|
assert(pos);
|
|
|
|
|
|
2018-02-26 17:18:29 +03:00
|
|
|
|
if (weston_touch_device_can_calibrate(device))
|
|
|
|
|
assert(norm != NULL);
|
|
|
|
|
else
|
|
|
|
|
assert(norm == NULL);
|
2023-02-07 16:08:54 +03:00
|
|
|
|
} else {
|
|
|
|
|
assert(!pos);
|
2018-02-26 17:18:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 04:42:47 +03:00
|
|
|
|
/* Update touchpoints count regardless of the current mode. */
|
|
|
|
|
switch (touch_type) {
|
|
|
|
|
case WL_TOUCH_DOWN:
|
|
|
|
|
weston_compositor_idle_inhibit(seat->compositor);
|
|
|
|
|
|
|
|
|
|
touch->num_tp++;
|
|
|
|
|
break;
|
|
|
|
|
case WL_TOUCH_UP:
|
|
|
|
|
if (touch->num_tp == 0) {
|
|
|
|
|
/* This can happen if we start out with one or
|
|
|
|
|
* more fingers on the touch screen, in which
|
|
|
|
|
* case we didn't get the corresponding down
|
|
|
|
|
* event. */
|
2018-03-02 15:20:59 +03:00
|
|
|
|
weston_log("Unmatched touch up event on seat %s, device %s\n",
|
|
|
|
|
seat->seat_name, device->syspath);
|
|
|
|
|
return;
|
2017-11-29 04:42:47 +03:00
|
|
|
|
}
|
|
|
|
|
weston_compositor_idle_release(seat->compositor);
|
|
|
|
|
|
|
|
|
|
touch->num_tp--;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
input: introduce touch event mode for calibrator
In addition to the normal touch event processing mode, introduce a new
mode for calibrating a touchscreen input device.
In the calibration mode, normal touch event processing is skipped, and
the raw events are forwarded to the calibrator instead. The calibrator
is not yet implemented, so the calls will be added in a following patch.
To switch between modes, two functions are added, one for entering each
mode. The mode switch happens only when no touches are down on any touch
device, to avoid confusing touch grabs and clients. To realise this, the
state machine has four states: prepare and actual state for both normal
and calibrator modes.
At this point nothing will attempt to change the touch event mode.
The new calibrator mode is necessary, because when calibrating a
touchscreen, the touch events must be routed to the calibration client
directly. The touch coordinates are expected to be wrong, so they cannot
go through the normal focus surface picking. The calibrator code also
cannot use the normal touch grab interface, because it needs to be able
to distinguish between different physical touch input devices, even if
they are part of the same weston_seat. This requirement makes
calibration special enough to warrant the new mode, a sort of "super
grab".
Co-developed by Louis-Francis and Pekka.
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
v1 Tested-by: Matt Hoosier <matt.hoosier@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-11-29 04:42:47 +03:00
|
|
|
|
/* Properly forward the touch event */
|
|
|
|
|
switch (weston_touch_device_get_mode(device)) {
|
|
|
|
|
case WESTON_TOUCH_MODE_NORMAL:
|
|
|
|
|
case WESTON_TOUCH_MODE_PREP_CALIB:
|
2023-02-07 16:08:54 +03:00
|
|
|
|
process_touch_normal(device, time, touch_id, pos, touch_type);
|
input: introduce touch event mode for calibrator
In addition to the normal touch event processing mode, introduce a new
mode for calibrating a touchscreen input device.
In the calibration mode, normal touch event processing is skipped, and
the raw events are forwarded to the calibrator instead. The calibrator
is not yet implemented, so the calls will be added in a following patch.
To switch between modes, two functions are added, one for entering each
mode. The mode switch happens only when no touches are down on any touch
device, to avoid confusing touch grabs and clients. To realise this, the
state machine has four states: prepare and actual state for both normal
and calibrator modes.
At this point nothing will attempt to change the touch event mode.
The new calibrator mode is necessary, because when calibrating a
touchscreen, the touch events must be routed to the calibration client
directly. The touch coordinates are expected to be wrong, so they cannot
go through the normal focus surface picking. The calibrator code also
cannot use the normal touch grab interface, because it needs to be able
to distinguish between different physical touch input devices, even if
they are part of the same weston_seat. This requirement makes
calibration special enough to warrant the new mode, a sort of "super
grab".
Co-developed by Louis-Francis and Pekka.
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
v1 Tested-by: Matt Hoosier <matt.hoosier@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-11-29 04:42:47 +03:00
|
|
|
|
break;
|
|
|
|
|
case WESTON_TOUCH_MODE_CALIB:
|
|
|
|
|
case WESTON_TOUCH_MODE_PREP_NORMAL:
|
2017-11-29 04:42:47 +03:00
|
|
|
|
notify_touch_calibrator(device, time, touch_id,
|
|
|
|
|
norm, touch_type);
|
input: introduce touch event mode for calibrator
In addition to the normal touch event processing mode, introduce a new
mode for calibrating a touchscreen input device.
In the calibration mode, normal touch event processing is skipped, and
the raw events are forwarded to the calibrator instead. The calibrator
is not yet implemented, so the calls will be added in a following patch.
To switch between modes, two functions are added, one for entering each
mode. The mode switch happens only when no touches are down on any touch
device, to avoid confusing touch grabs and clients. To realise this, the
state machine has four states: prepare and actual state for both normal
and calibrator modes.
At this point nothing will attempt to change the touch event mode.
The new calibrator mode is necessary, because when calibrating a
touchscreen, the touch events must be routed to the calibration client
directly. The touch coordinates are expected to be wrong, so they cannot
go through the normal focus surface picking. The calibrator code also
cannot use the normal touch grab interface, because it needs to be able
to distinguish between different physical touch input devices, even if
they are part of the same weston_seat. This requirement makes
calibration special enough to warrant the new mode, a sort of "super
grab".
Co-developed by Louis-Francis and Pekka.
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
v1 Tested-by: Matt Hoosier <matt.hoosier@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-11-29 04:42:47 +03:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-02-26 17:18:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-12 11:39:51 +04:00
|
|
|
|
WL_EXPORT void
|
2018-02-26 15:43:00 +03:00
|
|
|
|
notify_touch_frame(struct weston_touch_device *device)
|
2014-04-12 11:39:51 +04:00
|
|
|
|
{
|
input: introduce touch event mode for calibrator
In addition to the normal touch event processing mode, introduce a new
mode for calibrating a touchscreen input device.
In the calibration mode, normal touch event processing is skipped, and
the raw events are forwarded to the calibrator instead. The calibrator
is not yet implemented, so the calls will be added in a following patch.
To switch between modes, two functions are added, one for entering each
mode. The mode switch happens only when no touches are down on any touch
device, to avoid confusing touch grabs and clients. To realise this, the
state machine has four states: prepare and actual state for both normal
and calibrator modes.
At this point nothing will attempt to change the touch event mode.
The new calibrator mode is necessary, because when calibrating a
touchscreen, the touch events must be routed to the calibration client
directly. The touch coordinates are expected to be wrong, so they cannot
go through the normal focus surface picking. The calibrator code also
cannot use the normal touch grab interface, because it needs to be able
to distinguish between different physical touch input devices, even if
they are part of the same weston_seat. This requirement makes
calibration special enough to warrant the new mode, a sort of "super
grab".
Co-developed by Louis-Francis and Pekka.
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
v1 Tested-by: Matt Hoosier <matt.hoosier@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-11-29 04:42:47 +03:00
|
|
|
|
struct weston_touch_grab *grab;
|
2014-04-12 11:39:51 +04:00
|
|
|
|
|
input: introduce touch event mode for calibrator
In addition to the normal touch event processing mode, introduce a new
mode for calibrating a touchscreen input device.
In the calibration mode, normal touch event processing is skipped, and
the raw events are forwarded to the calibrator instead. The calibrator
is not yet implemented, so the calls will be added in a following patch.
To switch between modes, two functions are added, one for entering each
mode. The mode switch happens only when no touches are down on any touch
device, to avoid confusing touch grabs and clients. To realise this, the
state machine has four states: prepare and actual state for both normal
and calibrator modes.
At this point nothing will attempt to change the touch event mode.
The new calibrator mode is necessary, because when calibrating a
touchscreen, the touch events must be routed to the calibration client
directly. The touch coordinates are expected to be wrong, so they cannot
go through the normal focus surface picking. The calibrator code also
cannot use the normal touch grab interface, because it needs to be able
to distinguish between different physical touch input devices, even if
they are part of the same weston_seat. This requirement makes
calibration special enough to warrant the new mode, a sort of "super
grab".
Co-developed by Louis-Francis and Pekka.
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
v1 Tested-by: Matt Hoosier <matt.hoosier@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-11-29 04:42:47 +03:00
|
|
|
|
switch (weston_touch_device_get_mode(device)) {
|
|
|
|
|
case WESTON_TOUCH_MODE_NORMAL:
|
|
|
|
|
case WESTON_TOUCH_MODE_PREP_CALIB:
|
|
|
|
|
grab = device->aggregate->grab;
|
|
|
|
|
grab->interface->frame(grab);
|
2022-08-09 15:01:29 +03:00
|
|
|
|
if (grab->touch->pending_focus_reset) {
|
|
|
|
|
if (grab->touch->num_tp == 0)
|
|
|
|
|
weston_touch_set_focus(grab->touch, NULL);
|
|
|
|
|
grab->touch->pending_focus_reset = false;
|
|
|
|
|
}
|
input: introduce touch event mode for calibrator
In addition to the normal touch event processing mode, introduce a new
mode for calibrating a touchscreen input device.
In the calibration mode, normal touch event processing is skipped, and
the raw events are forwarded to the calibrator instead. The calibrator
is not yet implemented, so the calls will be added in a following patch.
To switch between modes, two functions are added, one for entering each
mode. The mode switch happens only when no touches are down on any touch
device, to avoid confusing touch grabs and clients. To realise this, the
state machine has four states: prepare and actual state for both normal
and calibrator modes.
At this point nothing will attempt to change the touch event mode.
The new calibrator mode is necessary, because when calibrating a
touchscreen, the touch events must be routed to the calibration client
directly. The touch coordinates are expected to be wrong, so they cannot
go through the normal focus surface picking. The calibrator code also
cannot use the normal touch grab interface, because it needs to be able
to distinguish between different physical touch input devices, even if
they are part of the same weston_seat. This requirement makes
calibration special enough to warrant the new mode, a sort of "super
grab".
Co-developed by Louis-Francis and Pekka.
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
v1 Tested-by: Matt Hoosier <matt.hoosier@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-11-29 04:42:47 +03:00
|
|
|
|
break;
|
|
|
|
|
case WESTON_TOUCH_MODE_CALIB:
|
|
|
|
|
case WESTON_TOUCH_MODE_PREP_NORMAL:
|
2017-11-29 04:42:47 +03:00
|
|
|
|
notify_touch_calibrator_frame(device);
|
input: introduce touch event mode for calibrator
In addition to the normal touch event processing mode, introduce a new
mode for calibrating a touchscreen input device.
In the calibration mode, normal touch event processing is skipped, and
the raw events are forwarded to the calibrator instead. The calibrator
is not yet implemented, so the calls will be added in a following patch.
To switch between modes, two functions are added, one for entering each
mode. The mode switch happens only when no touches are down on any touch
device, to avoid confusing touch grabs and clients. To realise this, the
state machine has four states: prepare and actual state for both normal
and calibrator modes.
At this point nothing will attempt to change the touch event mode.
The new calibrator mode is necessary, because when calibrating a
touchscreen, the touch events must be routed to the calibration client
directly. The touch coordinates are expected to be wrong, so they cannot
go through the normal focus surface picking. The calibrator code also
cannot use the normal touch grab interface, because it needs to be able
to distinguish between different physical touch input devices, even if
they are part of the same weston_seat. This requirement makes
calibration special enough to warrant the new mode, a sort of "super
grab".
Co-developed by Louis-Francis and Pekka.
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
v1 Tested-by: Matt Hoosier <matt.hoosier@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-11-29 04:42:47 +03:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
weston_compositor_update_touch_mode(device->aggregate->seat->compositor);
|
2014-04-12 11:39:51 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-07 00:56:09 +03:00
|
|
|
|
WL_EXPORT void
|
2018-02-26 15:43:00 +03:00
|
|
|
|
notify_touch_cancel(struct weston_touch_device *device)
|
2015-11-07 00:56:09 +03:00
|
|
|
|
{
|
input: introduce touch event mode for calibrator
In addition to the normal touch event processing mode, introduce a new
mode for calibrating a touchscreen input device.
In the calibration mode, normal touch event processing is skipped, and
the raw events are forwarded to the calibrator instead. The calibrator
is not yet implemented, so the calls will be added in a following patch.
To switch between modes, two functions are added, one for entering each
mode. The mode switch happens only when no touches are down on any touch
device, to avoid confusing touch grabs and clients. To realise this, the
state machine has four states: prepare and actual state for both normal
and calibrator modes.
At this point nothing will attempt to change the touch event mode.
The new calibrator mode is necessary, because when calibrating a
touchscreen, the touch events must be routed to the calibration client
directly. The touch coordinates are expected to be wrong, so they cannot
go through the normal focus surface picking. The calibrator code also
cannot use the normal touch grab interface, because it needs to be able
to distinguish between different physical touch input devices, even if
they are part of the same weston_seat. This requirement makes
calibration special enough to warrant the new mode, a sort of "super
grab".
Co-developed by Louis-Francis and Pekka.
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
v1 Tested-by: Matt Hoosier <matt.hoosier@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-11-29 04:42:47 +03:00
|
|
|
|
struct weston_touch_grab *grab;
|
|
|
|
|
|
|
|
|
|
switch (weston_touch_device_get_mode(device)) {
|
|
|
|
|
case WESTON_TOUCH_MODE_NORMAL:
|
|
|
|
|
case WESTON_TOUCH_MODE_PREP_CALIB:
|
|
|
|
|
grab = device->aggregate->grab;
|
|
|
|
|
grab->interface->cancel(grab);
|
|
|
|
|
break;
|
|
|
|
|
case WESTON_TOUCH_MODE_CALIB:
|
|
|
|
|
case WESTON_TOUCH_MODE_PREP_NORMAL:
|
2017-11-29 04:42:47 +03:00
|
|
|
|
notify_touch_calibrator_cancel(device);
|
input: introduce touch event mode for calibrator
In addition to the normal touch event processing mode, introduce a new
mode for calibrating a touchscreen input device.
In the calibration mode, normal touch event processing is skipped, and
the raw events are forwarded to the calibrator instead. The calibrator
is not yet implemented, so the calls will be added in a following patch.
To switch between modes, two functions are added, one for entering each
mode. The mode switch happens only when no touches are down on any touch
device, to avoid confusing touch grabs and clients. To realise this, the
state machine has four states: prepare and actual state for both normal
and calibrator modes.
At this point nothing will attempt to change the touch event mode.
The new calibrator mode is necessary, because when calibrating a
touchscreen, the touch events must be routed to the calibration client
directly. The touch coordinates are expected to be wrong, so they cannot
go through the normal focus surface picking. The calibrator code also
cannot use the normal touch grab interface, because it needs to be able
to distinguish between different physical touch input devices, even if
they are part of the same weston_seat. This requirement makes
calibration special enough to warrant the new mode, a sort of "super
grab".
Co-developed by Louis-Francis and Pekka.
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
v1 Tested-by: Matt Hoosier <matt.hoosier@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-11-29 04:42:47 +03:00
|
|
|
|
break;
|
|
|
|
|
}
|
2015-11-07 00:56:09 +03:00
|
|
|
|
|
input: introduce touch event mode for calibrator
In addition to the normal touch event processing mode, introduce a new
mode for calibrating a touchscreen input device.
In the calibration mode, normal touch event processing is skipped, and
the raw events are forwarded to the calibrator instead. The calibrator
is not yet implemented, so the calls will be added in a following patch.
To switch between modes, two functions are added, one for entering each
mode. The mode switch happens only when no touches are down on any touch
device, to avoid confusing touch grabs and clients. To realise this, the
state machine has four states: prepare and actual state for both normal
and calibrator modes.
At this point nothing will attempt to change the touch event mode.
The new calibrator mode is necessary, because when calibrating a
touchscreen, the touch events must be routed to the calibration client
directly. The touch coordinates are expected to be wrong, so they cannot
go through the normal focus surface picking. The calibrator code also
cannot use the normal touch grab interface, because it needs to be able
to distinguish between different physical touch input devices, even if
they are part of the same weston_seat. This requirement makes
calibration special enough to warrant the new mode, a sort of "super
grab".
Co-developed by Louis-Francis and Pekka.
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
v1 Tested-by: Matt Hoosier <matt.hoosier@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-11-29 04:42:47 +03:00
|
|
|
|
weston_compositor_update_touch_mode(device->aggregate->seat->compositor);
|
2015-11-07 00:56:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
compositor: add weston_surface_set_label_func()
When printing out logs from Weston's actions, mainly for debugging, it
can be very difficult to identify the different surfaces. Inspecting
the configure function pointer is not useful, as the configure functions
may live in modules.
Add vfunc get_label to weston_surface, which will produce a short,
human-readable description of the surface, which allows identifying it
better, rather than just looking at the surface size, for instance.
Set the label function from most parts of Weston, to identify cursors and
drag icons, and panels, backgrounds, screensavers and lock surfaces, and
the desktop shell's application surfaces.
v2: renamed 'description' to 'label', so we get
weston_surface_set_label_func().
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-08-06 20:36:51 +04:00
|
|
|
|
static int
|
|
|
|
|
pointer_cursor_surface_get_label(struct weston_surface *surface,
|
|
|
|
|
char *buf, size_t len)
|
|
|
|
|
{
|
|
|
|
|
return snprintf(buf, len, "cursor");
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 11:05:45 +03:00
|
|
|
|
static void
|
|
|
|
|
tablet_destroy(struct wl_client *client, struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct zwp_tablet_v2_interface tablet_interface = {
|
|
|
|
|
tablet_destroy,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
send_tablet_added(struct weston_tablet *tablet,
|
|
|
|
|
struct wl_resource *tablet_seat_resource,
|
|
|
|
|
struct wl_resource *tablet_resource)
|
|
|
|
|
{
|
|
|
|
|
zwp_tablet_seat_v2_send_tablet_added(tablet_seat_resource, tablet_resource);
|
|
|
|
|
zwp_tablet_v2_send_name(tablet_resource, tablet->name);
|
|
|
|
|
zwp_tablet_v2_send_id(tablet_resource, tablet->vid, tablet->pid);
|
|
|
|
|
zwp_tablet_v2_send_path(tablet_resource, tablet->path);
|
|
|
|
|
zwp_tablet_v2_send_done(tablet_resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_add_resource(struct weston_tablet *tablet,
|
|
|
|
|
struct wl_client *client,
|
|
|
|
|
struct wl_resource *tablet_seat_resource)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *tablet_resource;
|
|
|
|
|
|
|
|
|
|
tablet_resource = wl_resource_create(client,
|
|
|
|
|
&zwp_tablet_v2_interface,
|
|
|
|
|
1, 0);
|
|
|
|
|
|
|
|
|
|
wl_list_insert(&tablet->resource_list,
|
|
|
|
|
wl_resource_get_link(tablet_resource));
|
|
|
|
|
wl_resource_set_implementation(tablet_resource,
|
|
|
|
|
&tablet_interface,
|
|
|
|
|
tablet,
|
|
|
|
|
unbind_resource);
|
|
|
|
|
|
|
|
|
|
wl_resource_set_user_data(tablet_resource, tablet);
|
|
|
|
|
send_tablet_added(tablet, tablet_seat_resource, tablet_resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_tablet_added(struct weston_tablet *tablet)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *tablet_seat_resource;
|
|
|
|
|
struct weston_seat *seat = tablet->seat;
|
|
|
|
|
|
|
|
|
|
wl_resource_for_each(tablet_seat_resource,
|
|
|
|
|
&seat->tablet_seat_resource_list) {
|
|
|
|
|
tablet_add_resource(tablet,
|
|
|
|
|
wl_resource_get_client(tablet_seat_resource),
|
|
|
|
|
tablet_seat_resource);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 11:26:01 +03:00
|
|
|
|
static void
|
|
|
|
|
tablet_tool_cursor_surface_committed(struct weston_surface *es,
|
|
|
|
|
struct weston_coord_surface new_origin)
|
|
|
|
|
{
|
|
|
|
|
struct weston_tablet_tool *tool = es->committed_private;
|
2023-08-02 19:38:30 +03:00
|
|
|
|
struct weston_coord_surface hotspot_inv;
|
2021-01-20 11:26:01 +03:00
|
|
|
|
|
|
|
|
|
if (es->width == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
assert(es == tool->sprite->surface);
|
|
|
|
|
|
2023-07-18 22:25:27 +03:00
|
|
|
|
tool->hotspot = weston_coord_surface_sub(tool->hotspot, new_origin);
|
2023-08-02 19:38:30 +03:00
|
|
|
|
hotspot_inv = weston_coord_surface_invert(tool->hotspot);
|
|
|
|
|
weston_view_set_position_with_offset(tool->sprite,
|
|
|
|
|
tool->pos, hotspot_inv);
|
2021-01-20 11:26:01 +03:00
|
|
|
|
|
|
|
|
|
empty_region(&es->pending.input);
|
|
|
|
|
empty_region(&es->input);
|
|
|
|
|
|
|
|
|
|
if (!weston_surface_is_mapped(es)) {
|
2023-11-23 18:28:07 +03:00
|
|
|
|
weston_surface_map(es);
|
|
|
|
|
weston_view_move_to_layer(tool->sprite,
|
|
|
|
|
&es->compositor->cursor_layer.view_list);
|
2021-01-20 11:26:01 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 11:05:45 +03:00
|
|
|
|
static void
|
|
|
|
|
tablet_tool_set_cursor(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
|
uint32_t serial, struct wl_resource *surface_resource,
|
|
|
|
|
int32_t hotspot_x, int32_t hotspot_y)
|
|
|
|
|
{
|
2021-01-20 11:26:01 +03:00
|
|
|
|
struct weston_tablet_tool *tool = wl_resource_get_user_data(resource);
|
|
|
|
|
struct weston_surface *surface = NULL;
|
|
|
|
|
|
|
|
|
|
if (!tool)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (surface_resource)
|
|
|
|
|
surface = wl_resource_get_user_data(surface_resource);
|
|
|
|
|
|
|
|
|
|
if (tool->focus == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* tablet->focus->surface->resource can be NULL. Surfaces like the
|
|
|
|
|
* black_surface used in shell.c for fullscreen don't have
|
|
|
|
|
* a resource, but can still have focus */
|
|
|
|
|
if (tool->focus->surface->resource == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (wl_resource_get_client(tool->focus->surface->resource) != client)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (tool->focus_serial - serial > UINT32_MAX / 2)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (surface && tool->sprite && surface != tool->sprite->surface &&
|
|
|
|
|
surface->committed) {
|
|
|
|
|
wl_resource_post_error(surface->resource,
|
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
|
"surface->configure already set");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tool->sprite)
|
|
|
|
|
tablet_tool_unmap_sprite(tool);
|
|
|
|
|
|
|
|
|
|
if (!surface)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
wl_signal_add(&surface->destroy_signal,
|
|
|
|
|
&tool->sprite_destroy_listener);
|
|
|
|
|
surface->committed = tablet_tool_cursor_surface_committed;
|
|
|
|
|
surface->committed_private = tool;
|
|
|
|
|
tool->sprite = weston_view_create(surface);
|
|
|
|
|
tool->hotspot = weston_coord_surface(hotspot_x, hotspot_y, surface);
|
|
|
|
|
|
|
|
|
|
if (surface->buffer_ref.buffer) {
|
|
|
|
|
struct weston_coord_surface delta =
|
|
|
|
|
weston_coord_surface(0, 0, surface);
|
|
|
|
|
|
|
|
|
|
tablet_tool_cursor_surface_committed(surface, delta);
|
|
|
|
|
}
|
2021-01-20 11:05:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_tool_destroy(struct wl_client *client, struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct zwp_tablet_tool_v2_interface tablet_tool_interface = {
|
|
|
|
|
tablet_tool_set_cursor,
|
|
|
|
|
tablet_tool_destroy,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
send_tool_added(struct weston_tablet_tool *tool,
|
|
|
|
|
struct wl_resource *tool_seat_resource,
|
|
|
|
|
struct wl_resource *tool_resource)
|
|
|
|
|
{
|
|
|
|
|
uint32_t caps, cap;
|
|
|
|
|
zwp_tablet_seat_v2_send_tool_added(tool_seat_resource, tool_resource);
|
|
|
|
|
zwp_tablet_tool_v2_send_type(tool_resource, tool->type);
|
|
|
|
|
zwp_tablet_tool_v2_send_hardware_serial(tool_resource,
|
|
|
|
|
tool->serial >> 32,
|
|
|
|
|
tool->serial & 0xFFFFFFFF);
|
|
|
|
|
zwp_tablet_tool_v2_send_hardware_id_wacom(tool_resource,
|
|
|
|
|
tool->hwid >> 32,
|
|
|
|
|
tool->hwid & 0xFFFFFFFF);
|
|
|
|
|
caps = tool->capabilities;
|
|
|
|
|
while (caps != 0) {
|
|
|
|
|
cap = ffs(caps) - 1;
|
|
|
|
|
zwp_tablet_tool_v2_send_capability(tool_resource, cap);
|
|
|
|
|
caps &= ~(1 << cap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
zwp_tablet_tool_v2_send_done(tool_resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_tool_add_resource(struct weston_tablet_tool *tool,
|
|
|
|
|
struct wl_client *client,
|
|
|
|
|
struct wl_resource *tablet_seat_resource)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *tool_resource;
|
|
|
|
|
|
|
|
|
|
tool_resource = wl_resource_create(client,
|
|
|
|
|
&zwp_tablet_tool_v2_interface,
|
|
|
|
|
1, 0);
|
|
|
|
|
|
|
|
|
|
wl_list_insert(&tool->resource_list,
|
|
|
|
|
wl_resource_get_link(tool_resource));
|
|
|
|
|
wl_resource_set_implementation(tool_resource,
|
|
|
|
|
&tablet_tool_interface,
|
|
|
|
|
tool, unbind_resource);
|
|
|
|
|
|
|
|
|
|
wl_resource_set_user_data(tool_resource, tool);
|
|
|
|
|
send_tool_added(tool, tablet_seat_resource, tool_resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_tablet_tool_added(struct weston_tablet_tool *tool)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *tablet_seat_resource;
|
|
|
|
|
struct weston_seat *seat = tool->seat;
|
|
|
|
|
struct wl_client *client;
|
|
|
|
|
|
2017-12-19 11:33:33 +03:00
|
|
|
|
wl_signal_emit(&seat->tablet_tool_added_signal, tool);
|
|
|
|
|
|
2021-01-20 11:05:45 +03:00
|
|
|
|
wl_resource_for_each(tablet_seat_resource,
|
|
|
|
|
&seat->tablet_seat_resource_list) {
|
|
|
|
|
client = wl_resource_get_client(tablet_seat_resource);
|
|
|
|
|
tablet_tool_add_resource(tool, client,
|
|
|
|
|
tablet_seat_resource);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_tablet_tool_proximity_in(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time,
|
|
|
|
|
struct weston_tablet *tablet)
|
|
|
|
|
{
|
2021-01-20 11:20:22 +03:00
|
|
|
|
struct weston_tablet_tool_grab *grab = tool->grab;
|
|
|
|
|
|
|
|
|
|
grab->tool->current_tablet = tablet;
|
|
|
|
|
|
|
|
|
|
grab->interface->proximity_in(grab, time, tablet);
|
2021-01-20 11:05:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_tablet_tool_proximity_out(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time)
|
|
|
|
|
{
|
2021-01-20 11:20:22 +03:00
|
|
|
|
struct weston_tablet_tool_grab *grab = tool->grab;
|
|
|
|
|
|
|
|
|
|
grab->interface->proximity_out(grab, time);
|
2021-01-20 11:05:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_tablet_tool_motion(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time,
|
2021-01-20 11:20:22 +03:00
|
|
|
|
struct weston_coord_global pos)
|
2021-01-20 11:05:45 +03:00
|
|
|
|
{
|
2021-01-20 11:20:22 +03:00
|
|
|
|
struct weston_tablet_tool_grab *grab = tool->grab;
|
|
|
|
|
|
|
|
|
|
weston_compositor_wake(tool->seat->compositor);
|
|
|
|
|
|
|
|
|
|
grab->interface->motion(grab, time, pos);
|
2021-01-20 11:05:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_tablet_tool_pressure(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time, uint32_t pressure)
|
|
|
|
|
{
|
2021-01-20 11:20:22 +03:00
|
|
|
|
struct weston_tablet_tool_grab *grab = tool->grab;
|
|
|
|
|
|
|
|
|
|
weston_compositor_wake(tool->seat->compositor);
|
|
|
|
|
|
|
|
|
|
grab->interface->pressure(grab, time, pressure);
|
2021-01-20 11:05:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_tablet_tool_distance(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time, uint32_t distance)
|
|
|
|
|
{
|
2021-01-20 11:20:22 +03:00
|
|
|
|
struct weston_tablet_tool_grab *grab = tool->grab;
|
|
|
|
|
|
|
|
|
|
weston_compositor_wake(tool->seat->compositor);
|
|
|
|
|
|
|
|
|
|
grab->interface->distance(grab, time, distance);
|
2021-01-20 11:05:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_tablet_tool_tilt(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time,
|
|
|
|
|
wl_fixed_t tilt_x, wl_fixed_t tilt_y)
|
|
|
|
|
{
|
2021-01-20 11:20:22 +03:00
|
|
|
|
struct weston_tablet_tool_grab *grab = tool->grab;
|
|
|
|
|
|
|
|
|
|
weston_compositor_wake(tool->seat->compositor);
|
|
|
|
|
|
|
|
|
|
grab->interface->tilt(grab, time, tilt_x, tilt_y);
|
2021-01-20 11:05:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_tablet_tool_button(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time,
|
2021-01-20 11:20:22 +03:00
|
|
|
|
uint32_t button, uint32_t state)
|
2021-01-20 11:05:45 +03:00
|
|
|
|
{
|
2021-01-20 11:20:22 +03:00
|
|
|
|
struct weston_tablet_tool_grab *grab = tool->grab;
|
|
|
|
|
struct weston_compositor *compositor = tool->seat->compositor;
|
|
|
|
|
|
|
|
|
|
if (state == ZWP_TABLET_TOOL_V2_BUTTON_STATE_PRESSED) {
|
|
|
|
|
tool->button_count++;
|
|
|
|
|
if (tool->button_count == 1)
|
|
|
|
|
weston_compositor_idle_inhibit(compositor);
|
|
|
|
|
} else {
|
|
|
|
|
tool->button_count--;
|
|
|
|
|
if (tool->button_count == 1)
|
|
|
|
|
weston_compositor_idle_release(compositor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tool->grab_serial = wl_display_next_serial(compositor->wl_display);
|
2021-01-20 11:34:09 +03:00
|
|
|
|
|
|
|
|
|
weston_compositor_run_tablet_tool_binding(compositor, tool, button, state);
|
|
|
|
|
|
2021-01-20 11:20:22 +03:00
|
|
|
|
grab->interface->button(grab, time, button, state);
|
2021-01-20 11:05:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_tablet_tool_down(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time)
|
|
|
|
|
{
|
2021-01-20 11:20:22 +03:00
|
|
|
|
struct weston_tablet_tool_grab *grab = tool->grab;
|
|
|
|
|
struct weston_compositor *compositor = tool->seat->compositor;
|
|
|
|
|
|
|
|
|
|
weston_compositor_idle_inhibit(compositor);
|
|
|
|
|
|
|
|
|
|
tool->tip_is_down = true;
|
|
|
|
|
tool->grab_serial = wl_display_get_serial(compositor->wl_display);
|
2017-12-19 11:33:33 +03:00
|
|
|
|
tool->grab_pos = tool->pos;
|
2021-01-20 11:20:22 +03:00
|
|
|
|
|
2021-01-20 11:34:09 +03:00
|
|
|
|
weston_compositor_run_tablet_tool_binding(compositor, tool, BTN_TOUCH,
|
|
|
|
|
ZWP_TABLET_TOOL_V2_BUTTON_STATE_PRESSED);
|
2021-01-20 11:20:22 +03:00
|
|
|
|
grab->interface->down(grab, time);
|
2021-01-20 11:05:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_tablet_tool_up(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time)
|
|
|
|
|
{
|
2021-01-20 11:20:22 +03:00
|
|
|
|
struct weston_tablet_tool_grab *grab = tool->grab;
|
|
|
|
|
struct weston_compositor *compositor = tool->seat->compositor;
|
|
|
|
|
|
|
|
|
|
weston_compositor_idle_release(compositor);
|
|
|
|
|
|
|
|
|
|
tool->tip_is_down = false;
|
|
|
|
|
|
|
|
|
|
grab->interface->up(grab, time);
|
2021-01-20 11:05:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
notify_tablet_tool_frame(struct weston_tablet_tool *tool,
|
|
|
|
|
const struct timespec *time)
|
|
|
|
|
{
|
2021-01-20 11:20:22 +03:00
|
|
|
|
struct weston_tablet_tool_grab *grab = tool->grab;
|
|
|
|
|
|
|
|
|
|
grab->interface->frame(grab, time);
|
2021-01-20 11:05:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
static void
|
2016-08-12 11:41:33 +03:00
|
|
|
|
pointer_cursor_surface_committed(struct weston_surface *es,
|
2022-02-04 17:02:26 +03:00
|
|
|
|
struct weston_coord_surface new_origin)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
{
|
2016-08-12 11:41:33 +03:00
|
|
|
|
struct weston_pointer *pointer = es->committed_private;
|
2023-08-02 19:38:30 +03:00
|
|
|
|
struct weston_coord_surface hotspot_inv;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2013-12-03 07:01:53 +04:00
|
|
|
|
if (es->width == 0)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
return;
|
|
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
assert(es == pointer->sprite->surface);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2023-07-18 22:25:27 +03:00
|
|
|
|
pointer->hotspot = weston_coord_surface_sub(pointer->hotspot,
|
|
|
|
|
new_origin);
|
2023-08-02 19:38:30 +03:00
|
|
|
|
hotspot_inv = weston_coord_surface_invert(pointer->hotspot);
|
|
|
|
|
weston_view_set_position_with_offset(pointer->sprite,
|
|
|
|
|
pointer->pos, hotspot_inv);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
empty_region(&es->pending.input);
|
2014-01-31 18:07:51 +04:00
|
|
|
|
empty_region(&es->input);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
if (!weston_surface_is_mapped(es)) {
|
2022-06-12 22:51:45 +03:00
|
|
|
|
weston_surface_map(es);
|
2023-11-23 18:29:40 +03:00
|
|
|
|
weston_view_move_to_layer(pointer->sprite,
|
|
|
|
|
&es->compositor->cursor_layer.view_list);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pointer_set_cursor(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
|
uint32_t serial, struct wl_resource *surface_resource,
|
|
|
|
|
int32_t x, int32_t y)
|
|
|
|
|
{
|
2013-06-14 19:08:00 +04:00
|
|
|
|
struct weston_pointer *pointer = wl_resource_get_user_data(resource);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
struct weston_surface *surface = NULL;
|
|
|
|
|
|
2018-02-08 16:37:53 +03:00
|
|
|
|
if (!pointer)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
if (surface_resource)
|
2013-06-14 19:07:53 +04:00
|
|
|
|
surface = wl_resource_get_user_data(surface_resource);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2013-05-08 23:02:05 +04:00
|
|
|
|
if (pointer->focus == NULL)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
return;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
/* pointer->focus->surface->resource can be NULL. Surfaces like the
|
2013-06-20 20:13:07 +04:00
|
|
|
|
black_surface used in shell.c for fullscreen don't have
|
|
|
|
|
a resource, but can still have focus */
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
if (pointer->focus->surface->resource == NULL)
|
2013-06-20 20:13:07 +04:00
|
|
|
|
return;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 07:38:11 +04:00
|
|
|
|
if (wl_resource_get_client(pointer->focus->surface->resource) != client)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
return;
|
2013-05-08 23:02:05 +04:00
|
|
|
|
if (pointer->focus_serial - serial > UINT32_MAX / 2)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
return;
|
|
|
|
|
|
2015-03-23 18:55:32 +03:00
|
|
|
|
if (!surface) {
|
|
|
|
|
if (pointer->sprite)
|
|
|
|
|
pointer_unmap_sprite(pointer);
|
|
|
|
|
return;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-18 10:08:03 +03:00
|
|
|
|
if (pointer->sprite && pointer->sprite->surface == surface &&
|
2022-02-04 01:40:10 +03:00
|
|
|
|
pointer->hotspot.c.x == x && pointer->hotspot.c.y == y)
|
2015-03-18 10:08:03 +03:00
|
|
|
|
return;
|
|
|
|
|
|
2015-03-23 18:55:32 +03:00
|
|
|
|
if (!pointer->sprite || pointer->sprite->surface != surface) {
|
|
|
|
|
if (weston_surface_set_role(surface, "wl_pointer-cursor",
|
|
|
|
|
resource,
|
|
|
|
|
WL_POINTER_ERROR_ROLE) < 0)
|
|
|
|
|
return;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2015-03-23 18:55:32 +03:00
|
|
|
|
if (pointer->sprite)
|
|
|
|
|
pointer_unmap_sprite(pointer);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2015-03-23 18:55:32 +03:00
|
|
|
|
wl_signal_add(&surface->destroy_signal,
|
|
|
|
|
&pointer->sprite_destroy_listener);
|
|
|
|
|
|
2016-08-12 11:41:33 +03:00
|
|
|
|
surface->committed = pointer_cursor_surface_committed;
|
|
|
|
|
surface->committed_private = pointer;
|
2015-03-23 18:55:32 +03:00
|
|
|
|
weston_surface_set_label_func(surface,
|
|
|
|
|
pointer_cursor_surface_get_label);
|
|
|
|
|
pointer->sprite = weston_view_create(surface);
|
|
|
|
|
}
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2023-07-18 22:18:12 +03:00
|
|
|
|
pointer->hotspot = weston_coord_surface(x, y, surface);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
input: Use cursor surface dimensions to evaluate presence of content
When setting a cursor surface, use the surface dimensions, instead of the
weston_surface buffer reference, to check if the surface has any
content. A weston_surface without any buffer reference may in fact
have a buffer which was committed in a previous pointer entry, dropped
by weston_surface and now held only internally by the renderer.
Without this fix, when a pointer enters a surface, the cursor image is
not correctly updated if we set a cursor surface with an already
committed buffer from a previous pointer entry, without recommitting the
cursor buffer for the current entry. This can be seen, for example, in
the experimental Wine Wayland driver which handles the cursor in a way
that leads to the following scenario:
Setup: cursor_surface.attach(buffer) & cursor_surface.commit()
On first wl_pointer.enter: pointer.set_cursor(cursor_surface)
compositor/renderer redraws
wl_pointer.leave
On second wl_pointer.enter: pointer.set_cursor(cursor_surface)
When handling the second pointer.set_cursor() request the current code
doesn't find a buffer attached to the cursor_surface (only the renderer
now has a reference to it), so it doesn't update the respective view for
the cursor.
Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
2021-06-09 10:56:26 +03:00
|
|
|
|
if (surface->width != 0) {
|
2022-02-04 17:02:26 +03:00
|
|
|
|
struct weston_coord_surface zero;
|
|
|
|
|
|
|
|
|
|
zero = weston_coord_surface(0, 0, surface);
|
|
|
|
|
pointer_cursor_surface_committed(surface, zero);
|
2014-09-08 21:33:41 +04:00
|
|
|
|
weston_view_schedule_repaint(pointer->sprite);
|
|
|
|
|
}
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 23:11:02 +04:00
|
|
|
|
static void
|
|
|
|
|
pointer_release(struct wl_client *client, struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
static const struct wl_pointer_interface pointer_interface = {
|
2013-08-13 23:11:02 +04:00
|
|
|
|
pointer_set_cursor,
|
|
|
|
|
pointer_release
|
2013-04-18 23:40:10 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
seat_get_pointer(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
|
uint32_t id)
|
|
|
|
|
{
|
2013-06-14 19:08:00 +04:00
|
|
|
|
struct weston_seat *seat = wl_resource_get_user_data(resource);
|
2015-08-01 00:55:32 +03:00
|
|
|
|
/* We use the pointer_state directly, which means we'll
|
|
|
|
|
* give a wl_pointer if the seat has ever had one - even though
|
|
|
|
|
* the spec explicitly states that this request only takes effect
|
|
|
|
|
* if the seat has the pointer capability.
|
|
|
|
|
*
|
|
|
|
|
* This prevents a race between the compositor sending new
|
|
|
|
|
* capabilities and the client trying to use the old ones.
|
|
|
|
|
*/
|
2018-02-15 14:07:09 +03:00
|
|
|
|
struct weston_pointer *pointer = seat ? seat->pointer_state : NULL;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
struct wl_resource *cr;
|
2015-07-22 07:05:38 +03:00
|
|
|
|
struct weston_pointer_client *pointer_client;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2021-07-31 18:25:41 +03:00
|
|
|
|
cr = wl_resource_create(client, &wl_pointer_interface,
|
2013-06-28 05:17:02 +04:00
|
|
|
|
wl_resource_get_version(resource), id);
|
2013-08-07 03:46:25 +04:00
|
|
|
|
if (cr == NULL) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-15 14:07:09 +03:00
|
|
|
|
wl_list_init(wl_resource_get_link(cr));
|
|
|
|
|
wl_resource_set_implementation(cr, &pointer_interface, pointer,
|
|
|
|
|
unbind_pointer_client_resource);
|
|
|
|
|
|
|
|
|
|
/* If we don't have a pointer_state, the resource is inert, so there
|
|
|
|
|
* is nothing more to set up */
|
|
|
|
|
if (!pointer)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-07-22 07:05:38 +03:00
|
|
|
|
pointer_client = weston_pointer_ensure_pointer_client(pointer, client);
|
|
|
|
|
if (!pointer_client) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_list_insert(&pointer_client->pointer_resources,
|
|
|
|
|
wl_resource_get_link(cr));
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
|
if (pointer->focus && pointer->focus->surface->resource &&
|
|
|
|
|
wl_resource_get_client(pointer->focus->surface->resource) == client) {
|
2022-02-09 02:31:55 +03:00
|
|
|
|
struct weston_coord_surface surf_pos;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2022-12-13 19:16:53 +03:00
|
|
|
|
weston_view_update_transform(pointer->focus);
|
|
|
|
|
|
2022-02-09 02:31:55 +03:00
|
|
|
|
surf_pos = weston_coord_global_to_surface(pointer->focus,
|
2022-02-04 01:40:10 +03:00
|
|
|
|
pointer->pos);
|
2013-09-19 20:32:00 +04:00
|
|
|
|
|
|
|
|
|
wl_pointer_send_enter(cr,
|
2015-08-01 00:55:32 +03:00
|
|
|
|
pointer->focus_serial,
|
|
|
|
|
pointer->focus->surface->resource,
|
2022-02-09 02:31:55 +03:00
|
|
|
|
wl_fixed_from_double(surf_pos.c.x),
|
|
|
|
|
wl_fixed_from_double(surf_pos.c.y));
|
2016-01-18 09:38:22 +03:00
|
|
|
|
pointer_send_frame(cr);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 15:05:50 +03:00
|
|
|
|
static void
|
|
|
|
|
destroy_keyboard_resource(struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
struct weston_keyboard *keyboard = wl_resource_get_user_data(resource);
|
|
|
|
|
|
|
|
|
|
wl_list_remove(wl_resource_get_link(resource));
|
|
|
|
|
|
|
|
|
|
if (keyboard) {
|
|
|
|
|
remove_input_resource_from_timestamps(resource,
|
|
|
|
|
&keyboard->timestamps_list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 23:11:02 +04:00
|
|
|
|
static void
|
|
|
|
|
keyboard_release(struct wl_client *client, struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct wl_keyboard_interface keyboard_interface = {
|
|
|
|
|
keyboard_release
|
|
|
|
|
};
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
static void
|
|
|
|
|
seat_get_keyboard(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
|
uint32_t id)
|
|
|
|
|
{
|
2013-06-14 19:08:00 +04:00
|
|
|
|
struct weston_seat *seat = wl_resource_get_user_data(resource);
|
2015-08-01 00:55:32 +03:00
|
|
|
|
/* We use the keyboard_state directly, which means we'll
|
|
|
|
|
* give a wl_keyboard if the seat has ever had one - even though
|
|
|
|
|
* the spec explicitly states that this request only takes effect
|
|
|
|
|
* if the seat has the keyboard capability.
|
|
|
|
|
*
|
|
|
|
|
* This prevents a race between the compositor sending new
|
|
|
|
|
* capabilities and the client trying to use the old ones.
|
|
|
|
|
*/
|
2018-02-15 14:07:09 +03:00
|
|
|
|
struct weston_keyboard *keyboard = seat ? seat->keyboard_state : NULL;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
struct wl_resource *cr;
|
|
|
|
|
|
2021-07-31 18:25:41 +03:00
|
|
|
|
cr = wl_resource_create(client, &wl_keyboard_interface,
|
2013-06-28 05:17:02 +04:00
|
|
|
|
wl_resource_get_version(resource), id);
|
2013-08-07 03:46:25 +04:00
|
|
|
|
if (cr == NULL) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-15 14:07:09 +03:00
|
|
|
|
wl_list_init(wl_resource_get_link(cr));
|
|
|
|
|
wl_resource_set_implementation(cr, &keyboard_interface,
|
2018-02-20 15:05:50 +03:00
|
|
|
|
keyboard, destroy_keyboard_resource);
|
2018-02-15 14:07:09 +03:00
|
|
|
|
|
|
|
|
|
/* If we don't have a keyboard_state, the resource is inert, so there
|
|
|
|
|
* is nothing more to set up */
|
|
|
|
|
if (!keyboard)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-09-19 20:32:00 +04:00
|
|
|
|
/* May be moved to focused list later by either
|
|
|
|
|
* weston_keyboard_set_focus or directly if this client is already
|
|
|
|
|
* focused */
|
2015-06-03 23:53:28 +03:00
|
|
|
|
wl_list_insert(&keyboard->resource_list, wl_resource_get_link(cr));
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2014-08-12 16:58:25 +04:00
|
|
|
|
if (wl_resource_get_version(cr) >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) {
|
|
|
|
|
wl_keyboard_send_repeat_info(cr,
|
|
|
|
|
seat->compositor->kb_repeat_rate,
|
|
|
|
|
seat->compositor->kb_repeat_delay);
|
|
|
|
|
}
|
2014-08-04 21:43:24 +04:00
|
|
|
|
|
2017-06-28 19:41:43 +03:00
|
|
|
|
weston_keyboard_send_keymap(keyboard, cr);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2015-06-03 23:53:28 +03:00
|
|
|
|
if (keyboard->focus && keyboard->focus->resource &&
|
|
|
|
|
wl_resource_get_client(keyboard->focus->resource) == client) {
|
2013-09-19 20:32:00 +04:00
|
|
|
|
struct weston_surface *surface =
|
2015-06-03 23:53:28 +03:00
|
|
|
|
(struct weston_surface *)keyboard->focus;
|
2013-09-19 20:32:00 +04:00
|
|
|
|
|
|
|
|
|
wl_list_remove(wl_resource_get_link(cr));
|
2015-06-03 23:53:28 +03:00
|
|
|
|
wl_list_insert(&keyboard->focus_resource_list,
|
2013-09-19 20:32:00 +04:00
|
|
|
|
wl_resource_get_link(cr));
|
|
|
|
|
wl_keyboard_send_enter(cr,
|
2015-06-03 23:53:28 +03:00
|
|
|
|
keyboard->focus_serial,
|
2013-09-19 20:32:00 +04:00
|
|
|
|
surface->resource,
|
2015-06-03 23:53:28 +03:00
|
|
|
|
&keyboard->keys);
|
2013-09-19 20:32:00 +04:00
|
|
|
|
|
2020-06-17 01:43:57 +03:00
|
|
|
|
send_modifiers_to_resource(keyboard,
|
|
|
|
|
cr,
|
|
|
|
|
keyboard->focus_serial);
|
|
|
|
|
|
2013-09-19 20:32:00 +04:00
|
|
|
|
/* If this is the first keyboard resource for this
|
|
|
|
|
* client... */
|
2015-06-03 23:53:28 +03:00
|
|
|
|
if (keyboard->focus_resource_list.prev ==
|
2013-09-19 20:32:00 +04:00
|
|
|
|
wl_resource_get_link(cr))
|
|
|
|
|
wl_data_device_set_keyboard_focus(seat);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 15:07:03 +03:00
|
|
|
|
static void
|
|
|
|
|
destroy_touch_resource(struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
struct weston_touch *touch = wl_resource_get_user_data(resource);
|
|
|
|
|
|
|
|
|
|
wl_list_remove(wl_resource_get_link(resource));
|
|
|
|
|
|
|
|
|
|
if (touch) {
|
|
|
|
|
remove_input_resource_from_timestamps(resource,
|
|
|
|
|
&touch->timestamps_list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 23:11:02 +04:00
|
|
|
|
static void
|
|
|
|
|
touch_release(struct wl_client *client, struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct wl_touch_interface touch_interface = {
|
|
|
|
|
touch_release
|
|
|
|
|
};
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
static void
|
|
|
|
|
seat_get_touch(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
|
uint32_t id)
|
|
|
|
|
{
|
2013-06-14 19:08:00 +04:00
|
|
|
|
struct weston_seat *seat = wl_resource_get_user_data(resource);
|
2015-08-01 00:55:32 +03:00
|
|
|
|
/* We use the touch_state directly, which means we'll
|
|
|
|
|
* give a wl_touch if the seat has ever had one - even though
|
|
|
|
|
* the spec explicitly states that this request only takes effect
|
|
|
|
|
* if the seat has the touch capability.
|
|
|
|
|
*
|
|
|
|
|
* This prevents a race between the compositor sending new
|
|
|
|
|
* capabilities and the client trying to use the old ones.
|
|
|
|
|
*/
|
2018-02-15 14:07:09 +03:00
|
|
|
|
struct weston_touch *touch = seat ? seat->touch_state : NULL;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
struct wl_resource *cr;
|
|
|
|
|
|
2021-07-31 18:25:41 +03:00
|
|
|
|
cr = wl_resource_create(client, &wl_touch_interface,
|
2013-06-28 05:17:02 +04:00
|
|
|
|
wl_resource_get_version(resource), id);
|
2013-08-07 03:46:25 +04:00
|
|
|
|
if (cr == NULL) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-15 14:07:09 +03:00
|
|
|
|
wl_list_init(wl_resource_get_link(cr));
|
|
|
|
|
wl_resource_set_implementation(cr, &touch_interface,
|
2018-02-20 15:07:03 +03:00
|
|
|
|
touch, destroy_touch_resource);
|
2018-02-15 14:07:09 +03:00
|
|
|
|
|
|
|
|
|
/* If we don't have a touch_state, the resource is inert, so there
|
|
|
|
|
* is nothing more to set up */
|
|
|
|
|
if (!touch)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
|
if (touch->focus &&
|
|
|
|
|
wl_resource_get_client(touch->focus->surface->resource) == client) {
|
2015-10-09 11:28:47 +03:00
|
|
|
|
wl_list_insert(&touch->focus_resource_list,
|
2013-09-19 20:32:00 +04:00
|
|
|
|
wl_resource_get_link(cr));
|
|
|
|
|
} else {
|
2015-10-09 11:28:47 +03:00
|
|
|
|
wl_list_insert(&touch->resource_list,
|
2013-09-19 20:32:00 +04:00
|
|
|
|
wl_resource_get_link(cr));
|
|
|
|
|
}
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 19:49:08 +03:00
|
|
|
|
static void
|
|
|
|
|
seat_release(struct wl_client *client, struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
static const struct wl_seat_interface seat_interface = {
|
|
|
|
|
seat_get_pointer,
|
|
|
|
|
seat_get_keyboard,
|
|
|
|
|
seat_get_touch,
|
2016-03-13 19:49:08 +03:00
|
|
|
|
seat_release,
|
2013-04-18 23:40:10 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id)
|
|
|
|
|
{
|
2013-05-07 07:19:49 +04:00
|
|
|
|
struct weston_seat *seat = data;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
enum wl_seat_capability caps = 0;
|
|
|
|
|
|
2013-06-28 05:17:02 +04:00
|
|
|
|
resource = wl_resource_create(client,
|
2015-11-26 23:17:47 +03:00
|
|
|
|
&wl_seat_interface, version, id);
|
2013-06-14 19:08:00 +04:00
|
|
|
|
wl_list_insert(&seat->base_resource_list, wl_resource_get_link(resource));
|
2013-06-28 05:17:02 +04:00
|
|
|
|
wl_resource_set_implementation(resource, &seat_interface, data,
|
|
|
|
|
unbind_resource);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
|
if (weston_seat_get_pointer(seat))
|
2013-04-18 23:40:10 +04:00
|
|
|
|
caps |= WL_SEAT_CAPABILITY_POINTER;
|
2015-08-01 00:55:32 +03:00
|
|
|
|
if (weston_seat_get_keyboard(seat))
|
2013-04-18 23:40:10 +04:00
|
|
|
|
caps |= WL_SEAT_CAPABILITY_KEYBOARD;
|
2015-08-01 00:55:32 +03:00
|
|
|
|
if (weston_seat_get_touch(seat))
|
2013-04-18 23:40:10 +04:00
|
|
|
|
caps |= WL_SEAT_CAPABILITY_TOUCH;
|
|
|
|
|
|
|
|
|
|
wl_seat_send_capabilities(resource, caps);
|
2014-08-08 00:43:11 +04:00
|
|
|
|
if (version >= WL_SEAT_NAME_SINCE_VERSION)
|
2013-05-31 21:09:51 +04:00
|
|
|
|
wl_seat_send_name(resource, seat->seat_name);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 23:21:17 +04:00
|
|
|
|
static void
|
|
|
|
|
relative_pointer_destroy(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct zwp_relative_pointer_v1_interface relative_pointer_interface = {
|
|
|
|
|
relative_pointer_destroy
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
relative_pointer_manager_destroy(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
relative_pointer_manager_get_relative_pointer(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource,
|
|
|
|
|
uint32_t id,
|
|
|
|
|
struct wl_resource *pointer_resource)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer *pointer =
|
|
|
|
|
wl_resource_get_user_data(pointer_resource);
|
|
|
|
|
struct weston_pointer_client *pointer_client;
|
|
|
|
|
struct wl_resource *cr;
|
|
|
|
|
|
|
|
|
|
cr = wl_resource_create(client, &zwp_relative_pointer_v1_interface,
|
|
|
|
|
wl_resource_get_version(resource), id);
|
|
|
|
|
if (cr == NULL) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pointer_client = weston_pointer_ensure_pointer_client(pointer, client);
|
|
|
|
|
if (!pointer_client) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_list_insert(&pointer_client->relative_pointer_resources,
|
|
|
|
|
wl_resource_get_link(cr));
|
|
|
|
|
wl_resource_set_implementation(cr, &relative_pointer_interface,
|
|
|
|
|
pointer,
|
|
|
|
|
unbind_pointer_client_resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct zwp_relative_pointer_manager_v1_interface relative_pointer_manager = {
|
|
|
|
|
relative_pointer_manager_destroy,
|
|
|
|
|
relative_pointer_manager_get_relative_pointer,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bind_relative_pointer_manager(struct wl_client *client, void *data,
|
|
|
|
|
uint32_t version, uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
struct weston_compositor *compositor = data;
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
resource = wl_resource_create(client,
|
|
|
|
|
&zwp_relative_pointer_manager_v1_interface,
|
|
|
|
|
1, id);
|
|
|
|
|
|
|
|
|
|
wl_resource_set_implementation(resource, &relative_pointer_manager,
|
|
|
|
|
compositor,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-02 21:48:08 +03:00
|
|
|
|
WL_EXPORT int
|
|
|
|
|
weston_compositor_set_xkb_rule_names(struct weston_compositor *ec,
|
|
|
|
|
struct xkb_rule_names *names)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
{
|
|
|
|
|
if (ec->xkb_context == NULL) {
|
2020-05-13 08:24:27 +03:00
|
|
|
|
ec->xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
if (ec->xkb_context == NULL) {
|
|
|
|
|
weston_log("failed to create XKB context\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (names)
|
|
|
|
|
ec->xkb_names = *names;
|
|
|
|
|
if (!ec->xkb_names.rules)
|
|
|
|
|
ec->xkb_names.rules = strdup("evdev");
|
|
|
|
|
if (!ec->xkb_names.model)
|
|
|
|
|
ec->xkb_names.model = strdup("pc105");
|
|
|
|
|
if (!ec->xkb_names.layout)
|
|
|
|
|
ec->xkb_names.layout = strdup("us");
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-17 13:54:09 +04:00
|
|
|
|
static void
|
2013-09-05 17:31:40 +04:00
|
|
|
|
weston_xkb_info_destroy(struct weston_xkb_info *xkb_info)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
{
|
2013-09-05 17:31:40 +04:00
|
|
|
|
if (--xkb_info->ref_count > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-08-20 00:59:52 +04:00
|
|
|
|
xkb_keymap_unref(xkb_info->keymap);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2019-11-01 04:38:45 +03:00
|
|
|
|
os_ro_anonymous_file_destroy(xkb_info->keymap_rofile);
|
2013-09-05 17:31:40 +04:00
|
|
|
|
free(xkb_info);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
weston_compositor_xkb_destroy(struct weston_compositor *ec)
|
|
|
|
|
{
|
|
|
|
|
free((char *) ec->xkb_names.rules);
|
|
|
|
|
free((char *) ec->xkb_names.model);
|
|
|
|
|
free((char *) ec->xkb_names.layout);
|
|
|
|
|
free((char *) ec->xkb_names.variant);
|
|
|
|
|
free((char *) ec->xkb_names.options);
|
2013-09-17 13:54:09 +04:00
|
|
|
|
|
2013-09-05 17:31:40 +04:00
|
|
|
|
if (ec->xkb_info)
|
|
|
|
|
weston_xkb_info_destroy(ec->xkb_info);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
xkb_context_unref(ec->xkb_context);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 17:31:40 +04:00
|
|
|
|
static struct weston_xkb_info *
|
|
|
|
|
weston_xkb_info_create(struct xkb_keymap *keymap)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
{
|
2019-11-01 04:38:45 +03:00
|
|
|
|
char *keymap_string;
|
|
|
|
|
size_t keymap_size;
|
2013-09-05 17:31:40 +04:00
|
|
|
|
struct weston_xkb_info *xkb_info = zalloc(sizeof *xkb_info);
|
|
|
|
|
if (xkb_info == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2014-08-20 00:59:51 +04:00
|
|
|
|
xkb_info->keymap = xkb_keymap_ref(keymap);
|
2013-09-05 17:31:40 +04:00
|
|
|
|
xkb_info->ref_count = 1;
|
|
|
|
|
|
2014-08-20 00:59:51 +04:00
|
|
|
|
xkb_info->shift_mod = xkb_keymap_mod_get_index(xkb_info->keymap,
|
|
|
|
|
XKB_MOD_NAME_SHIFT);
|
|
|
|
|
xkb_info->caps_mod = xkb_keymap_mod_get_index(xkb_info->keymap,
|
|
|
|
|
XKB_MOD_NAME_CAPS);
|
|
|
|
|
xkb_info->ctrl_mod = xkb_keymap_mod_get_index(xkb_info->keymap,
|
|
|
|
|
XKB_MOD_NAME_CTRL);
|
|
|
|
|
xkb_info->alt_mod = xkb_keymap_mod_get_index(xkb_info->keymap,
|
|
|
|
|
XKB_MOD_NAME_ALT);
|
|
|
|
|
xkb_info->mod2_mod = xkb_keymap_mod_get_index(xkb_info->keymap,
|
|
|
|
|
"Mod2");
|
|
|
|
|
xkb_info->mod3_mod = xkb_keymap_mod_get_index(xkb_info->keymap,
|
|
|
|
|
"Mod3");
|
|
|
|
|
xkb_info->super_mod = xkb_keymap_mod_get_index(xkb_info->keymap,
|
|
|
|
|
XKB_MOD_NAME_LOGO);
|
|
|
|
|
xkb_info->mod5_mod = xkb_keymap_mod_get_index(xkb_info->keymap,
|
|
|
|
|
"Mod5");
|
|
|
|
|
|
|
|
|
|
xkb_info->num_led = xkb_keymap_led_get_index(xkb_info->keymap,
|
|
|
|
|
XKB_LED_NAME_NUM);
|
|
|
|
|
xkb_info->caps_led = xkb_keymap_led_get_index(xkb_info->keymap,
|
|
|
|
|
XKB_LED_NAME_CAPS);
|
|
|
|
|
xkb_info->scroll_led = xkb_keymap_led_get_index(xkb_info->keymap,
|
|
|
|
|
XKB_LED_NAME_SCROLL);
|
|
|
|
|
|
2019-11-01 04:38:45 +03:00
|
|
|
|
keymap_string = xkb_keymap_get_as_string(xkb_info->keymap,
|
2017-06-28 20:17:46 +03:00
|
|
|
|
XKB_KEYMAP_FORMAT_TEXT_V1);
|
2019-11-01 04:38:45 +03:00
|
|
|
|
if (keymap_string == NULL) {
|
2013-04-18 23:40:10 +04:00
|
|
|
|
weston_log("failed to get string version of keymap\n");
|
2013-09-05 17:31:40 +04:00
|
|
|
|
goto err_keymap;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
2019-11-01 04:38:45 +03:00
|
|
|
|
keymap_size = strlen(keymap_string) + 1;
|
|
|
|
|
|
|
|
|
|
xkb_info->keymap_rofile = os_ro_anonymous_file_create(keymap_size,
|
|
|
|
|
keymap_string);
|
|
|
|
|
free(keymap_string);
|
|
|
|
|
|
|
|
|
|
if (!xkb_info->keymap_rofile) {
|
|
|
|
|
weston_log("failed to create anonymous file for keymap\n");
|
|
|
|
|
goto err_keymap;
|
|
|
|
|
}
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2013-09-05 17:31:40 +04:00
|
|
|
|
return xkb_info;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2013-09-05 17:31:40 +04:00
|
|
|
|
err_keymap:
|
2014-08-20 00:59:51 +04:00
|
|
|
|
xkb_keymap_unref(xkb_info->keymap);
|
2013-09-05 17:31:40 +04:00
|
|
|
|
free(xkb_info);
|
|
|
|
|
return NULL;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
weston_compositor_build_global_keymap(struct weston_compositor *ec)
|
|
|
|
|
{
|
2013-09-05 17:31:40 +04:00
|
|
|
|
struct xkb_keymap *keymap;
|
|
|
|
|
|
|
|
|
|
if (ec->xkb_info != NULL)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
return 0;
|
|
|
|
|
|
2014-08-20 00:59:51 +04:00
|
|
|
|
keymap = xkb_keymap_new_from_names(ec->xkb_context,
|
|
|
|
|
&ec->xkb_names,
|
|
|
|
|
0);
|
2013-09-05 17:31:40 +04:00
|
|
|
|
if (keymap == NULL) {
|
2013-04-18 23:40:10 +04:00
|
|
|
|
weston_log("failed to compile global XKB keymap\n");
|
|
|
|
|
weston_log(" tried rules %s, model %s, layout %s, variant %s, "
|
|
|
|
|
"options %s\n",
|
|
|
|
|
ec->xkb_names.rules, ec->xkb_names.model,
|
|
|
|
|
ec->xkb_names.layout, ec->xkb_names.variant,
|
|
|
|
|
ec->xkb_names.options);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 17:31:40 +04:00
|
|
|
|
ec->xkb_info = weston_xkb_info_create(keymap);
|
2013-10-24 21:28:41 +04:00
|
|
|
|
xkb_keymap_unref(keymap);
|
2013-09-17 13:54:09 +04:00
|
|
|
|
if (ec->xkb_info == NULL)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-10 21:44:19 +04:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_seat_update_keymap(struct weston_seat *seat, struct xkb_keymap *keymap)
|
|
|
|
|
{
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
|
|
|
|
|
|
|
|
|
if (!keyboard || !keymap)
|
2013-10-10 21:44:19 +04:00
|
|
|
|
return;
|
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
|
xkb_keymap_unref(keyboard->pending_keymap);
|
|
|
|
|
keyboard->pending_keymap = xkb_keymap_ref(keymap);
|
2013-10-10 21:44:19 +04:00
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
|
if (keyboard->keys.size == 0)
|
2013-10-10 21:44:19 +04:00
|
|
|
|
update_keymap(seat);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
WL_EXPORT int
|
|
|
|
|
weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap)
|
|
|
|
|
{
|
2013-05-08 07:52:07 +04:00
|
|
|
|
struct weston_keyboard *keyboard;
|
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
|
if (seat->keyboard_state) {
|
2013-10-18 01:04:05 +04:00
|
|
|
|
seat->keyboard_device_count += 1;
|
|
|
|
|
if (seat->keyboard_device_count == 1)
|
|
|
|
|
seat_send_updated_caps(seat);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
return 0;
|
2013-10-18 01:04:05 +04:00
|
|
|
|
}
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2013-12-03 12:14:26 +04:00
|
|
|
|
keyboard = weston_keyboard_create();
|
|
|
|
|
if (keyboard == NULL) {
|
|
|
|
|
weston_log("failed to allocate weston keyboard struct\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-28 19:17:23 +03:00
|
|
|
|
if (keymap != NULL) {
|
|
|
|
|
keyboard->xkb_info = weston_xkb_info_create(keymap);
|
|
|
|
|
if (keyboard->xkb_info == NULL)
|
2014-01-31 19:35:45 +04:00
|
|
|
|
goto err;
|
2017-06-28 19:17:23 +03:00
|
|
|
|
} else {
|
|
|
|
|
if (weston_compositor_build_global_keymap(seat->compositor) < 0)
|
|
|
|
|
goto err;
|
|
|
|
|
keyboard->xkb_info = seat->compositor->xkb_info;
|
|
|
|
|
keyboard->xkb_info->ref_count++;
|
|
|
|
|
}
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2017-06-28 19:17:23 +03:00
|
|
|
|
keyboard->xkb_state.state = xkb_state_new(keyboard->xkb_info->keymap);
|
|
|
|
|
if (keyboard->xkb_state.state == NULL) {
|
|
|
|
|
weston_log("failed to initialise XKB state\n");
|
|
|
|
|
goto err;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
2017-06-28 19:17:23 +03:00
|
|
|
|
|
|
|
|
|
keyboard->xkb_state.leds = 0;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
|
seat->keyboard_state = keyboard;
|
2014-01-31 19:35:45 +04:00
|
|
|
|
seat->keyboard_device_count = 1;
|
|
|
|
|
keyboard->seat = seat;
|
|
|
|
|
|
2013-05-08 07:52:07 +04:00
|
|
|
|
seat_send_updated_caps(seat);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
return 0;
|
2014-01-31 19:35:45 +04:00
|
|
|
|
|
|
|
|
|
err:
|
|
|
|
|
if (keyboard->xkb_info)
|
|
|
|
|
weston_xkb_info_destroy(keyboard->xkb_info);
|
|
|
|
|
free(keyboard);
|
|
|
|
|
|
|
|
|
|
return -1;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-03 12:14:27 +04:00
|
|
|
|
static void
|
|
|
|
|
weston_keyboard_reset_state(struct weston_keyboard *keyboard)
|
|
|
|
|
{
|
|
|
|
|
struct weston_seat *seat = keyboard->seat;
|
|
|
|
|
struct xkb_state *state;
|
|
|
|
|
|
2017-06-28 19:17:23 +03:00
|
|
|
|
state = xkb_state_new(keyboard->xkb_info->keymap);
|
|
|
|
|
if (!state) {
|
|
|
|
|
weston_log("failed to reset XKB state\n");
|
|
|
|
|
return;
|
2013-12-03 12:14:27 +04:00
|
|
|
|
}
|
2017-06-28 19:17:23 +03:00
|
|
|
|
xkb_state_unref(keyboard->xkb_state.state);
|
|
|
|
|
keyboard->xkb_state.state = state;
|
|
|
|
|
|
|
|
|
|
keyboard->xkb_state.leds = 0;
|
2013-12-03 12:14:27 +04:00
|
|
|
|
|
|
|
|
|
seat->modifier_state = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-18 01:04:05 +04:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_seat_release_keyboard(struct weston_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
seat->keyboard_device_count--;
|
2014-11-19 20:04:12 +03:00
|
|
|
|
assert(seat->keyboard_device_count >= 0);
|
2013-10-18 01:04:05 +04:00
|
|
|
|
if (seat->keyboard_device_count == 0) {
|
2015-08-01 00:55:32 +03:00
|
|
|
|
weston_keyboard_set_focus(seat->keyboard_state, NULL);
|
|
|
|
|
weston_keyboard_cancel_grab(seat->keyboard_state);
|
|
|
|
|
weston_keyboard_reset_state(seat->keyboard_state);
|
2013-10-18 01:04:05 +04:00
|
|
|
|
seat_send_updated_caps(seat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-30 23:09:05 +03:00
|
|
|
|
WL_EXPORT int
|
2013-04-18 23:40:10 +04:00
|
|
|
|
weston_seat_init_pointer(struct weston_seat *seat)
|
|
|
|
|
{
|
2013-05-08 07:52:07 +04:00
|
|
|
|
struct weston_pointer *pointer;
|
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
|
if (seat->pointer_state) {
|
2013-10-18 01:04:05 +04:00
|
|
|
|
seat->pointer_device_count += 1;
|
|
|
|
|
if (seat->pointer_device_count == 1)
|
|
|
|
|
seat_send_updated_caps(seat);
|
2021-03-30 23:09:05 +03:00
|
|
|
|
return 0;
|
2013-10-18 01:04:05 +04:00
|
|
|
|
}
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2013-11-15 02:42:53 +04:00
|
|
|
|
pointer = weston_pointer_create(seat);
|
2013-05-08 07:52:07 +04:00
|
|
|
|
if (pointer == NULL)
|
2021-03-30 23:09:05 +03:00
|
|
|
|
return -1;
|
2013-05-08 07:52:07 +04:00
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
|
seat->pointer_state = pointer;
|
2013-10-18 01:04:05 +04:00
|
|
|
|
seat->pointer_device_count = 1;
|
|
|
|
|
pointer->seat = seat;
|
2013-05-08 07:52:07 +04:00
|
|
|
|
|
|
|
|
|
seat_send_updated_caps(seat);
|
2021-03-30 23:09:05 +03:00
|
|
|
|
|
|
|
|
|
return 0;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-18 01:04:05 +04:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_seat_release_pointer(struct weston_seat *seat)
|
|
|
|
|
{
|
2015-08-01 00:55:32 +03:00
|
|
|
|
struct weston_pointer *pointer = seat->pointer_state;
|
2013-10-18 01:04:05 +04:00
|
|
|
|
|
|
|
|
|
seat->pointer_device_count--;
|
|
|
|
|
if (seat->pointer_device_count == 0) {
|
2015-05-11 23:40:11 +03:00
|
|
|
|
weston_pointer_clear_focus(pointer);
|
2013-10-26 01:18:05 +04:00
|
|
|
|
weston_pointer_cancel_grab(pointer);
|
2013-10-18 01:04:06 +04:00
|
|
|
|
|
2013-10-18 01:04:07 +04:00
|
|
|
|
if (pointer->sprite)
|
|
|
|
|
pointer_unmap_sprite(pointer);
|
|
|
|
|
|
2013-12-03 01:05:05 +04:00
|
|
|
|
weston_pointer_reset_state(pointer);
|
2013-10-18 01:04:05 +04:00
|
|
|
|
seat_send_updated_caps(seat);
|
2015-01-08 00:00:25 +03:00
|
|
|
|
|
|
|
|
|
/* seat->pointer is intentionally not destroyed so that
|
|
|
|
|
* a newly attached pointer on this seat will retain
|
|
|
|
|
* the previous cursor co-ordinates.
|
|
|
|
|
*/
|
2013-10-18 01:04:05 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 11:05:45 +03:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_seat_release_tablet_tool(struct weston_tablet_tool *tool)
|
|
|
|
|
{
|
2017-12-19 11:33:33 +03:00
|
|
|
|
wl_signal_emit(&tool->removed_signal, tool);
|
|
|
|
|
|
2021-01-20 11:05:45 +03:00
|
|
|
|
weston_tablet_tool_destroy(tool);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_seat_release_tablet(struct weston_tablet *tablet)
|
|
|
|
|
{
|
|
|
|
|
weston_tablet_destroy(tablet);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-30 23:09:05 +03:00
|
|
|
|
WL_EXPORT int
|
2013-04-18 23:40:10 +04:00
|
|
|
|
weston_seat_init_touch(struct weston_seat *seat)
|
|
|
|
|
{
|
2013-05-08 07:52:07 +04:00
|
|
|
|
struct weston_touch *touch;
|
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
|
if (seat->touch_state) {
|
2013-10-18 01:04:05 +04:00
|
|
|
|
seat->touch_device_count += 1;
|
|
|
|
|
if (seat->touch_device_count == 1)
|
|
|
|
|
seat_send_updated_caps(seat);
|
2021-03-30 23:09:05 +03:00
|
|
|
|
return 0;
|
2013-10-18 01:04:05 +04:00
|
|
|
|
}
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
2013-05-08 07:52:07 +04:00
|
|
|
|
touch = weston_touch_create();
|
|
|
|
|
if (touch == NULL)
|
2021-03-30 23:09:05 +03:00
|
|
|
|
return -1;
|
2013-05-08 07:52:07 +04:00
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
|
seat->touch_state = touch;
|
2013-10-18 01:04:05 +04:00
|
|
|
|
seat->touch_device_count = 1;
|
2013-05-08 07:52:07 +04:00
|
|
|
|
touch->seat = seat;
|
|
|
|
|
|
|
|
|
|
seat_send_updated_caps(seat);
|
2021-03-30 23:09:05 +03:00
|
|
|
|
|
|
|
|
|
return 0;
|
2013-04-18 23:40:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 11:05:45 +03:00
|
|
|
|
WL_EXPORT struct weston_tablet *
|
|
|
|
|
weston_seat_add_tablet(struct weston_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
struct weston_tablet *tablet;
|
|
|
|
|
|
|
|
|
|
weston_tablet_manager_init(seat->compositor);
|
|
|
|
|
|
|
|
|
|
tablet = weston_tablet_create();
|
|
|
|
|
if (tablet == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
tablet->seat = seat;
|
|
|
|
|
|
|
|
|
|
return tablet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT struct weston_tablet_tool *
|
|
|
|
|
weston_seat_add_tablet_tool(struct weston_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
struct weston_tablet_tool *tool;
|
|
|
|
|
|
|
|
|
|
weston_tablet_manager_init(seat->compositor);
|
|
|
|
|
|
|
|
|
|
tool = weston_tablet_tool_create();
|
|
|
|
|
if (tool == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
wl_list_init(&tool->resource_list);
|
|
|
|
|
tool->seat = seat;
|
|
|
|
|
|
|
|
|
|
return tool;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-18 01:04:05 +04:00
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_seat_release_touch(struct weston_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
seat->touch_device_count--;
|
|
|
|
|
if (seat->touch_device_count == 0) {
|
2015-08-01 00:55:32 +03:00
|
|
|
|
weston_touch_set_focus(seat->touch_state, NULL);
|
|
|
|
|
weston_touch_cancel_grab(seat->touch_state);
|
|
|
|
|
weston_touch_reset_state(seat->touch_state);
|
2013-10-18 01:04:05 +04:00
|
|
|
|
seat_send_updated_caps(seat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
WL_EXPORT void
|
2013-05-31 21:09:50 +04:00
|
|
|
|
weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec,
|
|
|
|
|
const char *seat_name)
|
2013-04-18 23:40:10 +04:00
|
|
|
|
{
|
2013-05-07 06:24:50 +04:00
|
|
|
|
memset(seat, 0, sizeof *seat);
|
|
|
|
|
|
2013-05-07 07:19:49 +04:00
|
|
|
|
seat->selection_data_source = NULL;
|
|
|
|
|
wl_list_init(&seat->base_resource_list);
|
|
|
|
|
wl_signal_init(&seat->selection_signal);
|
|
|
|
|
wl_list_init(&seat->drag_resource_list);
|
|
|
|
|
wl_signal_init(&seat->destroy_signal);
|
2014-04-03 04:53:45 +04:00
|
|
|
|
wl_signal_init(&seat->updated_caps_signal);
|
2021-01-20 11:05:45 +03:00
|
|
|
|
wl_list_init(&seat->tablet_seat_resource_list);
|
|
|
|
|
wl_list_init(&seat->tablet_list);
|
|
|
|
|
wl_list_init(&seat->tablet_tool_list);
|
2017-12-19 11:33:33 +03:00
|
|
|
|
wl_signal_init(&seat->tablet_tool_added_signal);
|
2013-05-07 06:24:50 +04:00
|
|
|
|
|
2019-11-01 04:38:45 +03:00
|
|
|
|
seat->global = wl_global_create(ec->wl_display, &wl_seat_interface,
|
|
|
|
|
MIN(wl_seat_interface.version, 7),
|
2013-07-09 03:03:57 +04:00
|
|
|
|
seat, bind_seat);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
seat->compositor = ec;
|
|
|
|
|
seat->modifier_state = 0;
|
2013-05-31 21:09:50 +04:00
|
|
|
|
seat->seat_name = strdup(seat_name);
|
2013-04-18 23:40:10 +04:00
|
|
|
|
|
|
|
|
|
wl_list_insert(ec->seat_list.prev, &seat->link);
|
|
|
|
|
|
|
|
|
|
clipboard_create(seat);
|
|
|
|
|
|
|
|
|
|
wl_signal_emit(&ec->seat_created_signal, seat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_seat_release(struct weston_seat *seat)
|
|
|
|
|
{
|
2018-02-15 14:07:09 +03:00
|
|
|
|
struct wl_resource *resource;
|
2021-01-20 11:05:45 +03:00
|
|
|
|
struct weston_tablet *tablet, *tmp;
|
|
|
|
|
struct weston_tablet_tool *tool, *tmp_tool;
|
2018-02-15 14:07:09 +03:00
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, &seat->base_resource_list) {
|
|
|
|
|
wl_resource_set_user_data(resource, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_resource_for_each(resource, &seat->drag_resource_list) {
|
|
|
|
|
wl_resource_set_user_data(resource, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_list_remove(&seat->base_resource_list);
|
|
|
|
|
wl_list_remove(&seat->drag_resource_list);
|
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
wl_list_remove(&seat->link);
|
|
|
|
|
|
2014-01-03 22:46:51 +04:00
|
|
|
|
if (seat->saved_kbd_focus)
|
|
|
|
|
wl_list_remove(&seat->saved_kbd_focus_listener.link);
|
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
|
if (seat->pointer_state)
|
|
|
|
|
weston_pointer_destroy(seat->pointer_state);
|
|
|
|
|
if (seat->keyboard_state)
|
|
|
|
|
weston_keyboard_destroy(seat->keyboard_state);
|
|
|
|
|
if (seat->touch_state)
|
|
|
|
|
weston_touch_destroy(seat->touch_state);
|
2021-01-20 11:05:45 +03:00
|
|
|
|
wl_list_for_each_safe(tablet, tmp, &seat->tablet_list, link)
|
|
|
|
|
weston_tablet_destroy(tablet);
|
|
|
|
|
wl_list_for_each_safe(tool, tmp_tool, &seat->tablet_tool_list, link)
|
|
|
|
|
weston_tablet_tool_destroy(tool);
|
2013-05-07 06:24:50 +04:00
|
|
|
|
|
2013-05-31 21:09:50 +04:00
|
|
|
|
free (seat->seat_name);
|
|
|
|
|
|
2013-07-09 03:03:57 +04:00
|
|
|
|
wl_global_destroy(seat->global);
|
2013-07-09 00:20:31 +04:00
|
|
|
|
|
2013-04-18 23:40:10 +04:00
|
|
|
|
wl_signal_emit(&seat->destroy_signal, seat);
|
|
|
|
|
}
|
2015-08-01 00:55:32 +03:00
|
|
|
|
|
|
|
|
|
/** Get a seat's keyboard pointer
|
|
|
|
|
*
|
|
|
|
|
* \param seat The seat to query
|
|
|
|
|
* \return The seat's keyboard pointer, or NULL if no keyboard is present
|
|
|
|
|
*
|
|
|
|
|
* The keyboard pointer for a seat isn't freed when all keyboards are removed,
|
|
|
|
|
* so it should only be used when the seat's keyboard_device_count is greater
|
|
|
|
|
* than zero. This function does that test and only returns a pointer
|
|
|
|
|
* when a keyboard is present.
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT struct weston_keyboard *
|
|
|
|
|
weston_seat_get_keyboard(struct weston_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
if (!seat)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (seat->keyboard_device_count)
|
|
|
|
|
return seat->keyboard_state;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Get a seat's pointer pointer
|
|
|
|
|
*
|
|
|
|
|
* \param seat The seat to query
|
|
|
|
|
* \return The seat's pointer pointer, or NULL if no pointer device is present
|
|
|
|
|
*
|
|
|
|
|
* The pointer pointer for a seat isn't freed when all mice are removed,
|
|
|
|
|
* so it should only be used when the seat's pointer_device_count is greater
|
|
|
|
|
* than zero. This function does that test and only returns a pointer
|
|
|
|
|
* when a pointing device is present.
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT struct weston_pointer *
|
|
|
|
|
weston_seat_get_pointer(struct weston_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
if (!seat)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (seat->pointer_device_count)
|
|
|
|
|
return seat->pointer_state;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 12:56:31 +03:00
|
|
|
|
static const struct zwp_locked_pointer_v1_interface locked_pointer_interface;
|
|
|
|
|
static const struct zwp_confined_pointer_v1_interface confined_pointer_interface;
|
|
|
|
|
|
|
|
|
|
static enum pointer_constraint_type
|
|
|
|
|
pointer_constraint_get_type(struct weston_pointer_constraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
if (wl_resource_instance_of(constraint->resource,
|
|
|
|
|
&zwp_locked_pointer_v1_interface,
|
|
|
|
|
&locked_pointer_interface)) {
|
|
|
|
|
return POINTER_CONSTRAINT_TYPE_LOCK;
|
|
|
|
|
} else if (wl_resource_instance_of(constraint->resource,
|
|
|
|
|
&zwp_confined_pointer_v1_interface,
|
|
|
|
|
&confined_pointer_interface)) {
|
|
|
|
|
return POINTER_CONSTRAINT_TYPE_CONFINE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
abort();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pointer_constraint_notify_activated(struct weston_pointer_constraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource = constraint->resource;
|
|
|
|
|
|
|
|
|
|
switch (pointer_constraint_get_type(constraint)) {
|
|
|
|
|
case POINTER_CONSTRAINT_TYPE_LOCK:
|
|
|
|
|
zwp_locked_pointer_v1_send_locked(resource);
|
|
|
|
|
break;
|
|
|
|
|
case POINTER_CONSTRAINT_TYPE_CONFINE:
|
|
|
|
|
zwp_confined_pointer_v1_send_confined(resource);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pointer_constraint_notify_deactivated(struct weston_pointer_constraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource = constraint->resource;
|
|
|
|
|
|
|
|
|
|
switch (pointer_constraint_get_type(constraint)) {
|
|
|
|
|
case POINTER_CONSTRAINT_TYPE_LOCK:
|
|
|
|
|
zwp_locked_pointer_v1_send_unlocked(resource);
|
|
|
|
|
break;
|
|
|
|
|
case POINTER_CONSTRAINT_TYPE_CONFINE:
|
|
|
|
|
zwp_confined_pointer_v1_send_unconfined(resource);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct weston_pointer_constraint *
|
|
|
|
|
get_pointer_constraint_for_pointer(struct weston_surface *surface,
|
|
|
|
|
struct weston_pointer *pointer)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_constraint *constraint;
|
|
|
|
|
|
|
|
|
|
wl_list_for_each(constraint, &surface->pointer_constraints, link) {
|
|
|
|
|
if (constraint->pointer == pointer)
|
|
|
|
|
return constraint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
|
/** Get a seat's touch pointer
|
|
|
|
|
*
|
|
|
|
|
* \param seat The seat to query
|
|
|
|
|
* \return The seat's touch pointer, or NULL if no touch device is present
|
|
|
|
|
*
|
|
|
|
|
* The touch pointer for a seat isn't freed when all touch devices are removed,
|
|
|
|
|
* so it should only be used when the seat's touch_device_count is greater
|
|
|
|
|
* than zero. This function does that test and only returns a pointer
|
|
|
|
|
* when a touch device is present.
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT struct weston_touch *
|
|
|
|
|
weston_seat_get_touch(struct weston_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
if (!seat)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (seat->touch_device_count)
|
|
|
|
|
return seat->touch_state;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2016-06-30 05:04:07 +03:00
|
|
|
|
|
2021-01-20 11:05:45 +03:00
|
|
|
|
static void
|
|
|
|
|
tablet_seat_destroy(struct wl_client *client, struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct zwp_tablet_seat_v2_interface tablet_seat_interface = {
|
|
|
|
|
tablet_seat_destroy,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_manager_get_tablet_seat(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
|
uint32_t id, struct wl_resource *seat_resource)
|
|
|
|
|
{
|
|
|
|
|
struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
|
|
|
|
|
struct wl_resource *cr;
|
|
|
|
|
struct weston_tablet *tablet;
|
|
|
|
|
struct weston_tablet_tool *tool;
|
|
|
|
|
|
|
|
|
|
cr = wl_resource_create(client, &zwp_tablet_seat_v2_interface,
|
|
|
|
|
wl_resource_get_version(resource), id);
|
|
|
|
|
if (cr == NULL) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* store the resource in the weston_seat */
|
|
|
|
|
wl_list_insert(&seat->tablet_seat_resource_list, wl_resource_get_link(cr));
|
|
|
|
|
wl_resource_set_implementation(cr, &tablet_seat_interface, seat,
|
|
|
|
|
unbind_resource);
|
|
|
|
|
|
|
|
|
|
/* Notify client of any tablets already connected to the system */
|
|
|
|
|
wl_list_for_each(tablet, &seat->tablet_list, link) {
|
|
|
|
|
tablet_add_resource(tablet, client, cr);
|
|
|
|
|
/* Notify client of any local tools already known */
|
|
|
|
|
wl_list_for_each(tool, &tablet->tool_list, link)
|
|
|
|
|
tablet_tool_add_resource(tool, client, cr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Notify client of any global tools already known */
|
|
|
|
|
wl_list_for_each(tool, &seat->tablet_tool_list, link)
|
|
|
|
|
tablet_tool_add_resource(tool, client, cr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_manager_destroy(struct wl_client *client, struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct zwp_tablet_manager_v2_interface tablet_manager_interface = {
|
|
|
|
|
tablet_manager_get_tablet_seat,
|
|
|
|
|
tablet_manager_destroy,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bind_tablet_manager(struct wl_client *client, void *data, uint32_t version,
|
|
|
|
|
uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
struct weston_compositor *compositor = data;
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
resource = wl_resource_create(client, &zwp_tablet_manager_v2_interface,
|
|
|
|
|
MIN(version, 1), id);
|
|
|
|
|
wl_resource_set_implementation(resource, &tablet_manager_interface,
|
|
|
|
|
data, unbind_resource);
|
|
|
|
|
wl_list_insert(&compositor->tablet_manager_resource_list,
|
|
|
|
|
wl_resource_get_link(resource));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_tablet_manager_init(struct weston_compositor *compositor)
|
|
|
|
|
{
|
|
|
|
|
if (compositor->tablet_manager)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
compositor->tablet_manager = wl_global_create(compositor->wl_display,
|
|
|
|
|
&zwp_tablet_manager_v2_interface,
|
|
|
|
|
1, compositor,
|
|
|
|
|
bind_tablet_manager);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-30 05:04:07 +03:00
|
|
|
|
/** Sets the keyboard focus to the given surface
|
|
|
|
|
*
|
2019-06-12 16:05:44 +03:00
|
|
|
|
* \param surface the surface to focus on
|
2016-06-30 05:04:07 +03:00
|
|
|
|
* \param seat The seat to query
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
weston_seat_set_keyboard_focus(struct weston_seat *seat,
|
|
|
|
|
struct weston_surface *surface)
|
|
|
|
|
{
|
|
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
|
|
|
|
|
2016-03-15 15:28:51 +03:00
|
|
|
|
if (keyboard && keyboard->focus != surface) {
|
2016-06-30 05:04:07 +03:00
|
|
|
|
weston_keyboard_set_focus(keyboard, surface);
|
|
|
|
|
wl_data_device_set_keyboard_focus(seat);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-22 23:21:17 +04:00
|
|
|
|
|
2016-07-22 12:56:31 +03:00
|
|
|
|
static void
|
|
|
|
|
enable_pointer_constraint(struct weston_pointer_constraint *constraint,
|
|
|
|
|
struct weston_view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(constraint->view == NULL);
|
|
|
|
|
constraint->view = view;
|
|
|
|
|
pointer_constraint_notify_activated(constraint);
|
|
|
|
|
weston_pointer_start_grab(constraint->pointer, &constraint->grab);
|
2023-03-09 01:39:49 +03:00
|
|
|
|
wl_signal_add(&constraint->view->unmap_signal,
|
|
|
|
|
&constraint->view_unmap_listener);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
is_pointer_constraint_enabled(struct weston_pointer_constraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
return constraint->view != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
weston_pointer_constraint_disable(struct weston_pointer_constraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
constraint->view = NULL;
|
|
|
|
|
pointer_constraint_notify_deactivated(constraint);
|
|
|
|
|
weston_pointer_end_grab(constraint->grab.pointer);
|
2023-03-09 01:39:49 +03:00
|
|
|
|
wl_list_remove(&constraint->view_unmap_listener.link);
|
|
|
|
|
wl_list_init(&constraint->view_unmap_listener.link);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
weston_pointer_constraint_destroy(struct weston_pointer_constraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
if (is_pointer_constraint_enabled(constraint))
|
|
|
|
|
weston_pointer_constraint_disable(constraint);
|
|
|
|
|
|
|
|
|
|
wl_list_remove(&constraint->pointer_destroy_listener.link);
|
|
|
|
|
wl_list_remove(&constraint->surface_commit_listener.link);
|
|
|
|
|
wl_list_remove(&constraint->surface_activate_listener.link);
|
|
|
|
|
|
|
|
|
|
wl_resource_set_user_data(constraint->resource, NULL);
|
|
|
|
|
pixman_region32_fini(&constraint->region);
|
|
|
|
|
wl_list_remove(&constraint->link);
|
|
|
|
|
free(constraint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
disable_pointer_constraint(struct weston_pointer_constraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
switch (constraint->lifetime) {
|
|
|
|
|
case ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT:
|
|
|
|
|
weston_pointer_constraint_destroy(constraint);
|
|
|
|
|
break;
|
|
|
|
|
case ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT:
|
|
|
|
|
weston_pointer_constraint_disable(constraint);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
is_within_constraint_region(struct weston_pointer_constraint *constraint,
|
2022-02-09 00:37:42 +03:00
|
|
|
|
struct weston_coord_surface c)
|
2016-07-22 12:56:31 +03:00
|
|
|
|
{
|
|
|
|
|
struct weston_surface *surface = constraint->surface;
|
|
|
|
|
pixman_region32_t constraint_region;
|
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
|
|
pixman_region32_init(&constraint_region);
|
|
|
|
|
pixman_region32_intersect(&constraint_region,
|
|
|
|
|
&surface->input,
|
|
|
|
|
&constraint->region);
|
|
|
|
|
result = pixman_region32_contains_point(&constraint_region,
|
2022-02-09 00:37:42 +03:00
|
|
|
|
c.c.x, c.c.y, NULL);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
pixman_region32_fini(&constraint_region);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
maybe_enable_pointer_constraint(struct weston_pointer_constraint *constraint)
|
|
|
|
|
{
|
|
|
|
|
struct weston_surface *surface = constraint->surface;
|
|
|
|
|
struct weston_view *vit;
|
|
|
|
|
struct weston_view *view = NULL;
|
|
|
|
|
struct weston_pointer *pointer = constraint->pointer;
|
|
|
|
|
struct weston_keyboard *keyboard;
|
|
|
|
|
struct weston_seat *seat = pointer->seat;
|
2022-02-09 02:31:55 +03:00
|
|
|
|
struct weston_coord_surface c;
|
2016-07-22 12:56:31 +03:00
|
|
|
|
|
|
|
|
|
/* Postpone if no view of the surface was most recently clicked. */
|
|
|
|
|
wl_list_for_each(vit, &surface->views, surface_link) {
|
|
|
|
|
if (vit->click_to_activate_serial ==
|
|
|
|
|
surface->compositor->activate_serial) {
|
|
|
|
|
view = vit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (view == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Postpone if surface doesn't have keyboard focus. */
|
|
|
|
|
keyboard = weston_seat_get_keyboard(seat);
|
|
|
|
|
if (!keyboard || keyboard->focus != surface)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-11-09 01:09:05 +03:00
|
|
|
|
weston_view_update_transform(view);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
/* Postpone constraint if the pointer is not within the
|
|
|
|
|
* constraint region.
|
|
|
|
|
*/
|
2022-02-04 01:40:10 +03:00
|
|
|
|
c = weston_coord_global_to_surface(view, pointer->pos);
|
2022-02-09 00:37:42 +03:00
|
|
|
|
if (!is_within_constraint_region(constraint, c))
|
2016-07-22 12:56:31 +03:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
enable_pointer_constraint(constraint, view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
locked_pointer_grab_pointer_focus(struct weston_pointer_grab *grab)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
locked_pointer_grab_pointer_motion(struct weston_pointer_grab *grab,
|
2017-11-24 19:01:46 +03:00
|
|
|
|
const struct timespec *time,
|
2016-07-22 12:56:31 +03:00
|
|
|
|
struct weston_pointer_motion_event *event)
|
|
|
|
|
{
|
2016-08-12 11:41:32 +03:00
|
|
|
|
pointer_send_relative_motion(grab->pointer, time, event);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
locked_pointer_grab_pointer_button(struct weston_pointer_grab *grab,
|
2017-11-16 19:20:55 +03:00
|
|
|
|
const struct timespec *time,
|
2016-07-22 12:56:31 +03:00
|
|
|
|
uint32_t button,
|
|
|
|
|
uint32_t state_w)
|
|
|
|
|
{
|
|
|
|
|
weston_pointer_send_button(grab->pointer, time, button, state_w);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
locked_pointer_grab_pointer_axis(struct weston_pointer_grab *grab,
|
2017-11-16 19:20:56 +03:00
|
|
|
|
const struct timespec *time,
|
2016-07-22 12:56:31 +03:00
|
|
|
|
struct weston_pointer_axis_event *event)
|
|
|
|
|
{
|
|
|
|
|
weston_pointer_send_axis(grab->pointer, time, event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
locked_pointer_grab_pointer_axis_source(struct weston_pointer_grab *grab,
|
|
|
|
|
uint32_t source)
|
|
|
|
|
{
|
|
|
|
|
weston_pointer_send_axis_source(grab->pointer, source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
locked_pointer_grab_pointer_frame(struct weston_pointer_grab *grab)
|
|
|
|
|
{
|
|
|
|
|
weston_pointer_send_frame(grab->pointer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
locked_pointer_grab_pointer_cancel(struct weston_pointer_grab *grab)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_constraint *constraint =
|
|
|
|
|
container_of(grab, struct weston_pointer_constraint, grab);
|
|
|
|
|
|
|
|
|
|
disable_pointer_constraint(constraint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct weston_pointer_grab_interface
|
|
|
|
|
locked_pointer_grab_interface = {
|
|
|
|
|
locked_pointer_grab_pointer_focus,
|
|
|
|
|
locked_pointer_grab_pointer_motion,
|
|
|
|
|
locked_pointer_grab_pointer_button,
|
|
|
|
|
locked_pointer_grab_pointer_axis,
|
|
|
|
|
locked_pointer_grab_pointer_axis_source,
|
|
|
|
|
locked_pointer_grab_pointer_frame,
|
|
|
|
|
locked_pointer_grab_pointer_cancel,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pointer_constraint_constrain_resource_destroyed(struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_constraint *constraint =
|
|
|
|
|
wl_resource_get_user_data(resource);
|
|
|
|
|
|
|
|
|
|
if (!constraint)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
weston_pointer_constraint_destroy(constraint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pointer_constraint_surface_activate(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct weston_surface_activation_data *activation = data;
|
|
|
|
|
struct weston_pointer *pointer;
|
2023-03-29 18:33:30 +03:00
|
|
|
|
struct weston_surface *focus = activation->view->surface;
|
2016-07-22 12:56:31 +03:00
|
|
|
|
struct weston_pointer_constraint *constraint =
|
|
|
|
|
container_of(listener, struct weston_pointer_constraint,
|
|
|
|
|
surface_activate_listener);
|
|
|
|
|
bool is_constraint_surface;
|
|
|
|
|
|
|
|
|
|
pointer = weston_seat_get_pointer(activation->seat);
|
|
|
|
|
if (!pointer)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
is_constraint_surface =
|
|
|
|
|
get_pointer_constraint_for_pointer(focus, pointer) == constraint;
|
|
|
|
|
|
|
|
|
|
if (is_constraint_surface &&
|
2023-05-03 02:02:09 +03:00
|
|
|
|
!is_pointer_constraint_enabled(constraint)) {
|
|
|
|
|
if (activation->flags & WESTON_ACTIVATE_FLAG_FULLSCREEN) {
|
|
|
|
|
weston_view_update_transform(activation->view);
|
|
|
|
|
weston_pointer_set_focus(pointer, activation->view);
|
|
|
|
|
enable_pointer_constraint(constraint, activation->view);
|
|
|
|
|
maybe_warp_confined_pointer(constraint);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
maybe_enable_pointer_constraint(constraint);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-22 12:56:31 +03:00
|
|
|
|
else if (!is_constraint_surface &&
|
|
|
|
|
is_pointer_constraint_enabled(constraint))
|
|
|
|
|
disable_pointer_constraint(constraint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pointer_constraint_pointer_destroyed(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_constraint *constraint =
|
|
|
|
|
container_of(listener, struct weston_pointer_constraint,
|
|
|
|
|
pointer_destroy_listener);
|
|
|
|
|
|
|
|
|
|
weston_pointer_constraint_destroy(constraint);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-09 01:39:49 +03:00
|
|
|
|
static void
|
|
|
|
|
pointer_constraint_view_unmapped(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_constraint *constraint =
|
|
|
|
|
container_of(listener, struct weston_pointer_constraint,
|
|
|
|
|
view_unmap_listener);
|
|
|
|
|
|
|
|
|
|
disable_pointer_constraint(constraint);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 12:56:31 +03:00
|
|
|
|
static void
|
|
|
|
|
pointer_constraint_surface_committed(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_constraint *constraint =
|
|
|
|
|
container_of(listener, struct weston_pointer_constraint,
|
|
|
|
|
surface_commit_listener);
|
|
|
|
|
|
2022-12-06 19:39:28 +03:00
|
|
|
|
if (is_pointer_constraint_enabled(constraint))
|
|
|
|
|
weston_view_update_transform(constraint->view);
|
|
|
|
|
|
2016-07-22 12:56:31 +03:00
|
|
|
|
if (constraint->region_is_pending) {
|
|
|
|
|
constraint->region_is_pending = false;
|
|
|
|
|
pixman_region32_copy(&constraint->region,
|
|
|
|
|
&constraint->region_pending);
|
|
|
|
|
pixman_region32_fini(&constraint->region_pending);
|
|
|
|
|
pixman_region32_init(&constraint->region_pending);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (constraint->hint_is_pending) {
|
|
|
|
|
constraint->hint_is_pending = false;
|
|
|
|
|
|
|
|
|
|
constraint->hint_is_pending = true;
|
2022-02-09 00:37:42 +03:00
|
|
|
|
constraint->hint = constraint->hint_pending;
|
2016-07-22 12:56:31 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pointer_constraint_get_type(constraint) ==
|
|
|
|
|
POINTER_CONSTRAINT_TYPE_CONFINE &&
|
|
|
|
|
is_pointer_constraint_enabled(constraint))
|
|
|
|
|
maybe_warp_confined_pointer(constraint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct weston_pointer_constraint *
|
|
|
|
|
weston_pointer_constraint_create(struct weston_surface *surface,
|
|
|
|
|
struct weston_pointer *pointer,
|
|
|
|
|
struct weston_region *region,
|
|
|
|
|
enum zwp_pointer_constraints_v1_lifetime lifetime,
|
|
|
|
|
struct wl_resource *cr,
|
|
|
|
|
const struct weston_pointer_grab_interface *grab_interface)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_constraint *constraint;
|
|
|
|
|
|
|
|
|
|
constraint = zalloc(sizeof *constraint);
|
|
|
|
|
if (!constraint)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
constraint->lifetime = lifetime;
|
|
|
|
|
pixman_region32_init(&constraint->region);
|
|
|
|
|
pixman_region32_init(&constraint->region_pending);
|
|
|
|
|
wl_list_insert(&surface->pointer_constraints, &constraint->link);
|
|
|
|
|
constraint->surface = surface;
|
|
|
|
|
constraint->pointer = pointer;
|
|
|
|
|
constraint->resource = cr;
|
|
|
|
|
constraint->grab.interface = grab_interface;
|
|
|
|
|
if (region) {
|
|
|
|
|
pixman_region32_copy(&constraint->region,
|
|
|
|
|
®ion->region);
|
|
|
|
|
} else {
|
|
|
|
|
pixman_region32_fini(&constraint->region);
|
|
|
|
|
region_init_infinite(&constraint->region);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constraint->surface_activate_listener.notify =
|
|
|
|
|
pointer_constraint_surface_activate;
|
2023-03-09 01:39:49 +03:00
|
|
|
|
constraint->view_unmap_listener.notify =
|
|
|
|
|
pointer_constraint_view_unmapped;
|
2016-07-22 12:56:31 +03:00
|
|
|
|
constraint->surface_commit_listener.notify =
|
|
|
|
|
pointer_constraint_surface_committed;
|
|
|
|
|
constraint->pointer_destroy_listener.notify =
|
|
|
|
|
pointer_constraint_pointer_destroyed;
|
|
|
|
|
|
|
|
|
|
wl_signal_add(&surface->compositor->activate_signal,
|
|
|
|
|
&constraint->surface_activate_listener);
|
|
|
|
|
wl_signal_add(&pointer->destroy_signal,
|
|
|
|
|
&constraint->pointer_destroy_listener);
|
|
|
|
|
wl_signal_add(&surface->commit_signal,
|
|
|
|
|
&constraint->surface_commit_listener);
|
|
|
|
|
|
|
|
|
|
return constraint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
init_pointer_constraint(struct wl_resource *pointer_constraints_resource,
|
|
|
|
|
uint32_t id,
|
|
|
|
|
struct weston_surface *surface,
|
|
|
|
|
struct weston_pointer *pointer,
|
|
|
|
|
struct weston_region *region,
|
|
|
|
|
enum zwp_pointer_constraints_v1_lifetime lifetime,
|
|
|
|
|
const struct wl_interface *interface,
|
|
|
|
|
const void *implementation,
|
|
|
|
|
const struct weston_pointer_grab_interface *grab_interface)
|
|
|
|
|
{
|
|
|
|
|
struct wl_client *client =
|
|
|
|
|
wl_resource_get_client(pointer_constraints_resource);
|
|
|
|
|
struct wl_resource *cr;
|
|
|
|
|
struct weston_pointer_constraint *constraint;
|
|
|
|
|
|
2018-02-08 16:37:52 +03:00
|
|
|
|
if (pointer && get_pointer_constraint_for_pointer(surface, pointer)) {
|
2016-07-22 12:56:31 +03:00
|
|
|
|
wl_resource_post_error(pointer_constraints_resource,
|
|
|
|
|
ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED,
|
|
|
|
|
"the pointer has a lock/confine request on this surface");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cr = wl_resource_create(client, interface,
|
|
|
|
|
wl_resource_get_version(pointer_constraints_resource),
|
|
|
|
|
id);
|
|
|
|
|
if (cr == NULL) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-08 16:37:52 +03:00
|
|
|
|
if (pointer) {
|
|
|
|
|
constraint = weston_pointer_constraint_create(surface, pointer,
|
|
|
|
|
region, lifetime,
|
|
|
|
|
cr, grab_interface);
|
|
|
|
|
if (constraint == NULL) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
constraint = NULL;
|
2016-07-22 12:56:31 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_resource_set_implementation(cr, implementation, constraint,
|
|
|
|
|
pointer_constraint_constrain_resource_destroyed);
|
|
|
|
|
|
2018-02-08 16:37:52 +03:00
|
|
|
|
if (constraint)
|
|
|
|
|
maybe_enable_pointer_constraint(constraint);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pointer_constraints_destroy(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
locked_pointer_destroy(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_constraint *constraint =
|
|
|
|
|
wl_resource_get_user_data(resource);
|
|
|
|
|
|
|
|
|
|
if (constraint && constraint->view && constraint->hint_is_pending &&
|
2022-02-09 00:37:42 +03:00
|
|
|
|
is_within_constraint_region(constraint, constraint->hint)) {
|
2023-02-07 01:58:59 +03:00
|
|
|
|
struct weston_coord_global pos;
|
2022-02-09 02:31:55 +03:00
|
|
|
|
|
2023-02-07 01:58:59 +03:00
|
|
|
|
pos = weston_coord_surface_to_global(constraint->view,
|
2022-02-09 00:37:42 +03:00
|
|
|
|
constraint->hint);
|
2023-02-07 01:58:59 +03:00
|
|
|
|
weston_pointer_move_to(constraint->pointer, pos);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
}
|
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
locked_pointer_set_cursor_position_hint(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource,
|
|
|
|
|
wl_fixed_t surface_x,
|
|
|
|
|
wl_fixed_t surface_y)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_constraint *constraint =
|
|
|
|
|
wl_resource_get_user_data(resource);
|
|
|
|
|
|
|
|
|
|
/* Ignore a set cursor hint that was sent after the lock was cancelled.
|
|
|
|
|
*/
|
|
|
|
|
if (!constraint ||
|
|
|
|
|
!constraint->resource ||
|
|
|
|
|
constraint->resource != resource)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
constraint->hint_is_pending = true;
|
2022-02-09 00:37:42 +03:00
|
|
|
|
constraint->hint_pending = weston_coord_surface_from_fixed(surface_x,
|
|
|
|
|
surface_y,
|
2023-10-13 15:37:20 +03:00
|
|
|
|
constraint->surface);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
locked_pointer_set_region(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource,
|
|
|
|
|
struct wl_resource *region_resource)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_constraint *constraint =
|
|
|
|
|
wl_resource_get_user_data(resource);
|
|
|
|
|
struct weston_region *region = region_resource ?
|
|
|
|
|
wl_resource_get_user_data(region_resource) : NULL;
|
|
|
|
|
|
|
|
|
|
if (!constraint)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (region) {
|
|
|
|
|
pixman_region32_copy(&constraint->region_pending,
|
|
|
|
|
®ion->region);
|
|
|
|
|
} else {
|
|
|
|
|
pixman_region32_fini(&constraint->region_pending);
|
|
|
|
|
region_init_infinite(&constraint->region_pending);
|
|
|
|
|
}
|
|
|
|
|
constraint->region_is_pending = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const struct zwp_locked_pointer_v1_interface locked_pointer_interface = {
|
|
|
|
|
locked_pointer_destroy,
|
|
|
|
|
locked_pointer_set_cursor_position_hint,
|
|
|
|
|
locked_pointer_set_region,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pointer_constraints_lock_pointer(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource,
|
|
|
|
|
uint32_t id,
|
|
|
|
|
struct wl_resource *surface_resource,
|
|
|
|
|
struct wl_resource *pointer_resource,
|
|
|
|
|
struct wl_resource *region_resource,
|
|
|
|
|
uint32_t lifetime)
|
|
|
|
|
{
|
|
|
|
|
struct weston_surface *surface =
|
|
|
|
|
wl_resource_get_user_data(surface_resource);
|
|
|
|
|
struct weston_pointer *pointer = wl_resource_get_user_data(pointer_resource);
|
|
|
|
|
struct weston_region *region = region_resource ?
|
|
|
|
|
wl_resource_get_user_data(region_resource) : NULL;
|
|
|
|
|
|
|
|
|
|
init_pointer_constraint(resource, id, surface, pointer, region, lifetime,
|
|
|
|
|
&zwp_locked_pointer_v1_interface,
|
|
|
|
|
&locked_pointer_interface,
|
|
|
|
|
&locked_pointer_grab_interface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
confined_pointer_grab_pointer_focus(struct weston_pointer_grab *grab)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-30 12:56:37 +03:00
|
|
|
|
static double
|
2022-02-02 17:18:18 +03:00
|
|
|
|
weston_coord_cross_product(struct weston_coord a, struct weston_coord b)
|
2015-04-30 12:56:37 +03:00
|
|
|
|
{
|
|
|
|
|
return a.x * b.y - a.y * b.x;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-02 17:18:18 +03:00
|
|
|
|
static struct weston_coord
|
|
|
|
|
weston_coord_multiply_constant(double c, struct weston_coord a)
|
2015-04-30 12:56:37 +03:00
|
|
|
|
{
|
2022-02-02 17:18:18 +03:00
|
|
|
|
return (struct weston_coord) {
|
2015-04-30 12:56:37 +03:00
|
|
|
|
.x = c * a.x,
|
|
|
|
|
.y = c * a.y,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
lines_intersect(struct line *line1, struct line *line2,
|
2022-02-02 17:18:18 +03:00
|
|
|
|
struct weston_coord *intersection)
|
2015-04-30 12:56:37 +03:00
|
|
|
|
{
|
2022-02-02 17:18:18 +03:00
|
|
|
|
struct weston_coord p = line1->a;
|
|
|
|
|
struct weston_coord r = weston_coord_sub(line1->b, line1->a);
|
|
|
|
|
struct weston_coord q = line2->a;
|
|
|
|
|
struct weston_coord s = weston_coord_sub(line2->b, line2->a);
|
|
|
|
|
struct weston_coord tmp;
|
2015-04-30 12:56:37 +03:00
|
|
|
|
double rxs;
|
|
|
|
|
double sxr;
|
|
|
|
|
double t;
|
|
|
|
|
double u;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The line (p, r) and (q, s) intersects where
|
|
|
|
|
*
|
|
|
|
|
* p + t r = q + u s
|
|
|
|
|
*
|
|
|
|
|
* Calculate t:
|
|
|
|
|
*
|
|
|
|
|
* (p + t r) × s = (q + u s) × s
|
|
|
|
|
* p × s + t (r × s) = q × s + u (s × s)
|
|
|
|
|
* p × s + t (r × s) = q × s
|
|
|
|
|
* t (r × s) = q × s - p × s
|
|
|
|
|
* t (r × s) = (q - p) × s
|
|
|
|
|
* t = ((q - p) × s) / (r × s)
|
|
|
|
|
*
|
|
|
|
|
* Using the same method, for u we get:
|
|
|
|
|
*
|
|
|
|
|
* u = ((p - q) × r) / (s × r)
|
|
|
|
|
*/
|
|
|
|
|
|
2022-02-02 17:18:18 +03:00
|
|
|
|
rxs = weston_coord_cross_product(r, s);
|
|
|
|
|
sxr = weston_coord_cross_product(s, r);
|
2015-04-30 12:56:37 +03:00
|
|
|
|
|
|
|
|
|
/* If r × s = 0 then the lines are either parallel or collinear. */
|
|
|
|
|
if (fabs(rxs) < DBL_MIN)
|
|
|
|
|
return false;
|
|
|
|
|
|
2022-02-02 17:18:18 +03:00
|
|
|
|
tmp = weston_coord_sub(q, p);
|
|
|
|
|
t = weston_coord_cross_product(tmp, s) / rxs;
|
|
|
|
|
tmp = weston_coord_sub(p, q);
|
|
|
|
|
u = weston_coord_cross_product(tmp, r) / sxr;
|
2015-04-30 12:56:37 +03:00
|
|
|
|
|
|
|
|
|
/* The lines only intersect if 0 ≤ t ≤ 1 and 0 ≤ u ≤ 1. */
|
|
|
|
|
if (t < 0.0 || t > 1.0 || u < 0.0 || u > 1.0)
|
|
|
|
|
return false;
|
|
|
|
|
|
2022-02-02 17:18:18 +03:00
|
|
|
|
*intersection = weston_coord_add(p, weston_coord_multiply_constant(t, r));
|
2015-04-30 12:56:37 +03:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct border *
|
|
|
|
|
add_border(struct wl_array *array,
|
2022-02-02 21:23:28 +03:00
|
|
|
|
struct weston_coord pos1,
|
|
|
|
|
struct weston_coord pos2,
|
2015-04-30 12:56:37 +03:00
|
|
|
|
enum motion_direction blocking_dir)
|
|
|
|
|
{
|
|
|
|
|
struct border *border = wl_array_add(array, sizeof *border);
|
|
|
|
|
|
|
|
|
|
*border = (struct border) {
|
|
|
|
|
.line = (struct line) {
|
2022-02-02 21:23:28 +03:00
|
|
|
|
.a = pos1,
|
|
|
|
|
.b = pos2
|
2015-04-30 12:56:37 +03:00
|
|
|
|
},
|
|
|
|
|
.blocking_dir = blocking_dir,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return border;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
compare_lines_x(const void *a, const void *b)
|
|
|
|
|
{
|
|
|
|
|
const struct border *border_a = a;
|
|
|
|
|
const struct border *border_b = b;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (border_a->line.a.x == border_b->line.a.x)
|
|
|
|
|
return border_a->line.b.x < border_b->line.b.x;
|
|
|
|
|
else
|
|
|
|
|
return border_a->line.a.x > border_b->line.a.x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
add_non_overlapping_edges(pixman_box32_t *boxes,
|
|
|
|
|
int band_above_start,
|
|
|
|
|
int band_below_start,
|
|
|
|
|
int band_below_end,
|
|
|
|
|
struct wl_array *borders)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
struct wl_array band_merge;
|
|
|
|
|
struct border *border;
|
|
|
|
|
struct border *prev_border;
|
|
|
|
|
struct border *new_border;
|
|
|
|
|
|
|
|
|
|
wl_array_init(&band_merge);
|
|
|
|
|
|
|
|
|
|
/* Add bottom band of previous row, and top band of current row, and
|
|
|
|
|
* sort them so lower left x coordinate comes first. If there are two
|
|
|
|
|
* borders with the same left x coordinate, the wider one comes first.
|
|
|
|
|
*/
|
|
|
|
|
for (i = band_above_start; i < band_below_start; i++) {
|
2022-02-02 21:23:28 +03:00
|
|
|
|
struct weston_coord pos1, pos2;
|
2015-04-30 12:56:37 +03:00
|
|
|
|
pixman_box32_t *box = &boxes[i];
|
2022-02-02 21:23:28 +03:00
|
|
|
|
|
|
|
|
|
pos1 = weston_coord(box->x1, box->y2);
|
|
|
|
|
pos2 = weston_coord(box->x2, box->y2);
|
|
|
|
|
add_border(&band_merge, pos1, pos2, MOTION_DIRECTION_POSITIVE_Y);
|
2015-04-30 12:56:37 +03:00
|
|
|
|
}
|
|
|
|
|
for (i = band_below_start; i < band_below_end; i++) {
|
2022-02-02 21:23:28 +03:00
|
|
|
|
struct weston_coord pos1, pos2;
|
2015-04-30 12:56:37 +03:00
|
|
|
|
pixman_box32_t *box= &boxes[i];
|
2022-02-02 21:23:28 +03:00
|
|
|
|
|
|
|
|
|
pos1 = weston_coord(box->x1, box->y1);
|
|
|
|
|
pos2 = weston_coord(box->x2, box->y1);
|
|
|
|
|
add_border(&band_merge, pos1, pos2, MOTION_DIRECTION_NEGATIVE_Y);
|
2015-04-30 12:56:37 +03:00
|
|
|
|
}
|
|
|
|
|
qsort(band_merge.data,
|
|
|
|
|
band_merge.size / sizeof *border,
|
|
|
|
|
sizeof *border,
|
|
|
|
|
compare_lines_x);
|
|
|
|
|
|
|
|
|
|
/* Combine the two combined bands so that any overlapping border is
|
|
|
|
|
* eliminated. */
|
|
|
|
|
prev_border = NULL;
|
|
|
|
|
wl_array_for_each(border, &band_merge) {
|
|
|
|
|
assert(border->line.a.y == border->line.b.y);
|
|
|
|
|
assert(!prev_border ||
|
|
|
|
|
prev_border->line.a.y == border->line.a.y);
|
|
|
|
|
assert(!prev_border ||
|
|
|
|
|
(prev_border->line.a.x != border->line.a.x ||
|
|
|
|
|
prev_border->line.b.x != border->line.b.x));
|
|
|
|
|
assert(!prev_border ||
|
|
|
|
|
prev_border->line.a.x <= border->line.a.x);
|
|
|
|
|
|
|
|
|
|
if (prev_border &&
|
|
|
|
|
prev_border->line.a.x == border->line.a.x) {
|
|
|
|
|
/*
|
|
|
|
|
* ------------ +
|
|
|
|
|
* ------- =
|
|
|
|
|
* [ ]-----
|
|
|
|
|
*/
|
|
|
|
|
prev_border->line.a.x = border->line.b.x;
|
|
|
|
|
} else if (prev_border &&
|
|
|
|
|
prev_border->line.b.x == border->line.b.x) {
|
|
|
|
|
/*
|
|
|
|
|
* ------------ +
|
|
|
|
|
* ------ =
|
|
|
|
|
* ------[ ]
|
|
|
|
|
*/
|
|
|
|
|
prev_border->line.b.x = border->line.a.x;
|
|
|
|
|
} else if (prev_border &&
|
|
|
|
|
prev_border->line.b.x == border->line.a.x) {
|
|
|
|
|
/*
|
|
|
|
|
* -------- +
|
|
|
|
|
* ------ =
|
|
|
|
|
* --------------
|
|
|
|
|
*/
|
|
|
|
|
prev_border->line.b.x = border->line.b.x;
|
|
|
|
|
} else if (prev_border &&
|
|
|
|
|
prev_border->line.b.x >= border->line.a.x) {
|
|
|
|
|
/*
|
|
|
|
|
* --------------- +
|
|
|
|
|
* ------ =
|
|
|
|
|
* -----[ ]----
|
|
|
|
|
*/
|
|
|
|
|
new_border = add_border(borders,
|
2022-02-02 21:23:28 +03:00
|
|
|
|
border->line.b,
|
|
|
|
|
prev_border->line.b,
|
2015-04-30 12:56:37 +03:00
|
|
|
|
prev_border->blocking_dir);
|
|
|
|
|
prev_border->line.b.x = border->line.a.x;
|
|
|
|
|
prev_border = new_border;
|
|
|
|
|
} else {
|
|
|
|
|
assert(!prev_border ||
|
|
|
|
|
prev_border->line.b.x < border->line.a.x);
|
|
|
|
|
/*
|
|
|
|
|
* First border or non-overlapping.
|
|
|
|
|
*
|
|
|
|
|
* ----- +
|
|
|
|
|
* ----- =
|
|
|
|
|
* ----- -----
|
|
|
|
|
*/
|
|
|
|
|
new_border = wl_array_add(borders, sizeof *border);
|
|
|
|
|
*new_border = *border;
|
|
|
|
|
prev_border = new_border;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_array_release(&band_merge);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
add_band_bottom_edges(pixman_box32_t *boxes,
|
|
|
|
|
int band_start,
|
|
|
|
|
int band_end,
|
|
|
|
|
struct wl_array *borders)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2022-02-02 21:23:28 +03:00
|
|
|
|
struct weston_coord pos1, pos2;
|
2015-04-30 12:56:37 +03:00
|
|
|
|
|
|
|
|
|
for (i = band_start; i < band_end; i++) {
|
2022-02-02 21:23:28 +03:00
|
|
|
|
pos1 = weston_coord(boxes[i].x1, boxes[i].y2);
|
|
|
|
|
pos2 = weston_coord(boxes[i].x2, boxes[i].y2);
|
|
|
|
|
add_border(borders, pos1, pos2, MOTION_DIRECTION_POSITIVE_Y);
|
2015-04-30 12:56:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
region_to_outline(pixman_region32_t *region, struct wl_array *borders)
|
|
|
|
|
{
|
2022-02-02 21:23:28 +03:00
|
|
|
|
struct weston_coord pos1, pos2;
|
2015-04-30 12:56:37 +03:00
|
|
|
|
pixman_box32_t *boxes;
|
|
|
|
|
int num_boxes;
|
|
|
|
|
int i;
|
|
|
|
|
int top_most, bottom_most;
|
|
|
|
|
int current_roof;
|
|
|
|
|
int prev_top;
|
|
|
|
|
int band_start, prev_band_start;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Remove any overlapping lines from the set of rectangles. Note that
|
|
|
|
|
* pixman regions are grouped as rows of rectangles, where rectangles
|
|
|
|
|
* in one row never touch or overlap and are all of the same height.
|
|
|
|
|
*
|
|
|
|
|
* -------- --- -------- ---
|
|
|
|
|
* | | | | | | | |
|
|
|
|
|
* ----------====---- --- ----------- ----- ---
|
|
|
|
|
* | | => | |
|
|
|
|
|
* ----==========--------- ----- ----------
|
|
|
|
|
* | | | |
|
|
|
|
|
* ------------------- -------------------
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
boxes = pixman_region32_rectangles(region, &num_boxes);
|
|
|
|
|
prev_top = 0;
|
|
|
|
|
top_most = boxes[0].y1;
|
|
|
|
|
current_roof = top_most;
|
|
|
|
|
bottom_most = boxes[num_boxes - 1].y2;
|
|
|
|
|
band_start = 0;
|
|
|
|
|
prev_band_start = 0;
|
|
|
|
|
for (i = 0; i < num_boxes; i++) {
|
|
|
|
|
/* Detect if there is a vertical empty space, and add the lower
|
|
|
|
|
* level of the previous band if so was the case. */
|
|
|
|
|
if (i > 0 &&
|
|
|
|
|
boxes[i].y1 != prev_top &&
|
|
|
|
|
boxes[i].y1 != boxes[i - 1].y2) {
|
|
|
|
|
current_roof = boxes[i].y1;
|
|
|
|
|
add_band_bottom_edges(boxes,
|
|
|
|
|
band_start,
|
|
|
|
|
i,
|
|
|
|
|
borders);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Special case adding the last band, since it won't be handled
|
|
|
|
|
* by the band change detection below. */
|
|
|
|
|
if (boxes[i].y1 != current_roof && i == num_boxes - 1) {
|
|
|
|
|
if (boxes[i].y1 != prev_top) {
|
|
|
|
|
/* The last band is a single box, so we don't
|
|
|
|
|
* have a prev_band_start to tell us when the
|
|
|
|
|
* previous band started. */
|
|
|
|
|
add_non_overlapping_edges(boxes,
|
|
|
|
|
band_start,
|
|
|
|
|
i,
|
|
|
|
|
i + 1,
|
|
|
|
|
borders);
|
|
|
|
|
} else {
|
|
|
|
|
add_non_overlapping_edges(boxes,
|
|
|
|
|
prev_band_start,
|
|
|
|
|
band_start,
|
|
|
|
|
i + 1,
|
|
|
|
|
borders);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Detect when passing a band and combine the top border of the
|
|
|
|
|
* just passed band with the bottom band of the previous band.
|
|
|
|
|
*/
|
|
|
|
|
if (boxes[i].y1 != top_most && boxes[i].y1 != prev_top) {
|
|
|
|
|
/* Combine the two passed bands. */
|
|
|
|
|
if (prev_top != current_roof) {
|
|
|
|
|
add_non_overlapping_edges(boxes,
|
|
|
|
|
prev_band_start,
|
|
|
|
|
band_start,
|
|
|
|
|
i,
|
|
|
|
|
borders);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prev_band_start = band_start;
|
|
|
|
|
band_start = i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Add the top border if the box is part of the current roof. */
|
|
|
|
|
if (boxes[i].y1 == current_roof) {
|
2022-02-02 21:23:28 +03:00
|
|
|
|
pos1 = weston_coord(boxes[i].x1, boxes[i].y1);
|
|
|
|
|
pos2 = weston_coord(boxes[i].x2, boxes[i].y1);
|
|
|
|
|
add_border(borders, pos1, pos2, MOTION_DIRECTION_NEGATIVE_Y);
|
2015-04-30 12:56:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Add the bottom border of the last band. */
|
|
|
|
|
if (boxes[i].y2 == bottom_most) {
|
2022-02-02 21:23:28 +03:00
|
|
|
|
pos1 = weston_coord(boxes[i].x1, boxes[i].y2);
|
|
|
|
|
pos2 = weston_coord(boxes[i].x2, boxes[i].y2);
|
|
|
|
|
add_border(borders, pos1, pos2, MOTION_DIRECTION_POSITIVE_Y);
|
2015-04-30 12:56:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Always add the left border. */
|
2022-02-02 21:23:28 +03:00
|
|
|
|
pos1 = weston_coord(boxes[i].x1, boxes[i].y1);
|
|
|
|
|
pos2 = weston_coord(boxes[i].x1, boxes[i].y2);
|
|
|
|
|
add_border(borders, pos1, pos2, MOTION_DIRECTION_NEGATIVE_X);
|
2015-04-30 12:56:37 +03:00
|
|
|
|
|
|
|
|
|
/* Always add the right border. */
|
2022-02-02 21:23:28 +03:00
|
|
|
|
pos1 = weston_coord(boxes[i].x2, boxes[i].y1);
|
|
|
|
|
pos2 = weston_coord(boxes[i].x2, boxes[i].y2);
|
|
|
|
|
add_border(borders, pos1, pos2, MOTION_DIRECTION_POSITIVE_X);
|
2015-04-30 12:56:37 +03:00
|
|
|
|
|
|
|
|
|
prev_top = boxes[i].y1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
is_border_horizontal (struct border *border)
|
|
|
|
|
{
|
|
|
|
|
return border->line.a.y == border->line.b.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
is_border_blocking_directions(struct border *border,
|
|
|
|
|
uint32_t directions)
|
|
|
|
|
{
|
|
|
|
|
/* Don't block parallel motions. */
|
|
|
|
|
if (is_border_horizontal(border)) {
|
|
|
|
|
if ((directions & (MOTION_DIRECTION_POSITIVE_Y |
|
|
|
|
|
MOTION_DIRECTION_NEGATIVE_Y)) == 0)
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
if ((directions & (MOTION_DIRECTION_POSITIVE_X |
|
|
|
|
|
MOTION_DIRECTION_NEGATIVE_X)) == 0)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (~border->blocking_dir & directions) != directions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct border *
|
|
|
|
|
get_closest_border(struct wl_array *borders,
|
|
|
|
|
struct line *motion,
|
|
|
|
|
uint32_t directions)
|
|
|
|
|
{
|
|
|
|
|
struct border *border;
|
2022-02-02 17:18:18 +03:00
|
|
|
|
struct weston_coord intersection;
|
|
|
|
|
struct weston_coord delta;
|
2015-04-30 12:56:37 +03:00
|
|
|
|
double distance_2;
|
|
|
|
|
struct border *closest_border = NULL;
|
|
|
|
|
double closest_distance_2 = DBL_MAX;
|
|
|
|
|
|
|
|
|
|
wl_array_for_each(border, borders) {
|
|
|
|
|
if (!is_border_blocking_directions(border, directions))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!lines_intersect(&border->line, motion, &intersection))
|
|
|
|
|
continue;
|
|
|
|
|
|
2022-02-02 17:18:18 +03:00
|
|
|
|
delta = weston_coord_sub(intersection, motion->a);
|
2015-04-30 12:56:37 +03:00
|
|
|
|
distance_2 = delta.x*delta.x + delta.y*delta.y;
|
|
|
|
|
if (distance_2 < closest_distance_2) {
|
|
|
|
|
closest_border = border;
|
|
|
|
|
closest_distance_2 = distance_2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return closest_border;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
clamp_to_border(struct border *border,
|
|
|
|
|
struct line *motion,
|
|
|
|
|
uint32_t *motion_dir)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* When clamping either rightward or downward motions, the motion needs
|
|
|
|
|
* to be clamped so that the destination coordinate does not end up on
|
|
|
|
|
* the border (see weston_pointer_clamp_event_to_region). Do this by
|
|
|
|
|
* clamping such motions to the border minus the smallest possible
|
|
|
|
|
* wl_fixed_t value.
|
|
|
|
|
*/
|
|
|
|
|
if (is_border_horizontal(border)) {
|
|
|
|
|
if (*motion_dir & MOTION_DIRECTION_POSITIVE_Y)
|
|
|
|
|
motion->b.y = border->line.a.y - wl_fixed_to_double(1);
|
|
|
|
|
else
|
|
|
|
|
motion->b.y = border->line.a.y;
|
|
|
|
|
*motion_dir &= ~(MOTION_DIRECTION_POSITIVE_Y |
|
|
|
|
|
MOTION_DIRECTION_NEGATIVE_Y);
|
|
|
|
|
} else {
|
|
|
|
|
if (*motion_dir & MOTION_DIRECTION_POSITIVE_X)
|
|
|
|
|
motion->b.x = border->line.a.x - wl_fixed_to_double(1);
|
|
|
|
|
else
|
|
|
|
|
motion->b.x = border->line.a.x;
|
|
|
|
|
*motion_dir &= ~(MOTION_DIRECTION_POSITIVE_X |
|
|
|
|
|
MOTION_DIRECTION_NEGATIVE_X);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
|
get_motion_directions(struct line *motion)
|
|
|
|
|
{
|
|
|
|
|
uint32_t directions = 0;
|
|
|
|
|
|
|
|
|
|
if (motion->a.x < motion->b.x)
|
|
|
|
|
directions |= MOTION_DIRECTION_POSITIVE_X;
|
|
|
|
|
else if (motion->a.x > motion->b.x)
|
|
|
|
|
directions |= MOTION_DIRECTION_NEGATIVE_X;
|
|
|
|
|
if (motion->a.y < motion->b.y)
|
|
|
|
|
directions |= MOTION_DIRECTION_POSITIVE_Y;
|
|
|
|
|
else if (motion->a.y > motion->b.y)
|
|
|
|
|
directions |= MOTION_DIRECTION_NEGATIVE_Y;
|
|
|
|
|
|
|
|
|
|
return directions;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-07 01:44:51 +03:00
|
|
|
|
static struct weston_coord_global
|
2016-07-22 12:56:31 +03:00
|
|
|
|
weston_pointer_clamp_event_to_region(struct weston_pointer *pointer,
|
|
|
|
|
struct weston_pointer_motion_event *event,
|
2023-02-07 01:44:51 +03:00
|
|
|
|
pixman_region32_t *region)
|
2016-07-22 12:56:31 +03:00
|
|
|
|
{
|
2015-04-30 12:56:37 +03:00
|
|
|
|
wl_fixed_t old_sx = pointer->sx;
|
|
|
|
|
wl_fixed_t old_sy = pointer->sy;
|
|
|
|
|
struct wl_array borders;
|
|
|
|
|
struct line motion;
|
|
|
|
|
struct border *closest_border;
|
|
|
|
|
uint32_t directions;
|
2023-02-07 01:21:44 +03:00
|
|
|
|
struct weston_coord_global pos;
|
2023-02-07 01:44:51 +03:00
|
|
|
|
struct weston_coord_global clamped_pos;
|
|
|
|
|
struct weston_coord_surface clamped_surf_pos;
|
2023-02-07 01:21:44 +03:00
|
|
|
|
struct weston_coord_surface surf_pos;
|
2016-07-22 12:56:31 +03:00
|
|
|
|
|
2022-10-31 20:41:32 +03:00
|
|
|
|
assert(pointer->focus);
|
|
|
|
|
|
2023-02-07 01:21:44 +03:00
|
|
|
|
pos = weston_pointer_motion_to_abs(pointer, event);
|
|
|
|
|
surf_pos = weston_coord_global_to_surface(pointer->focus, pos);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
|
2015-04-30 12:56:37 +03:00
|
|
|
|
wl_array_init(&borders);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
|
2015-04-30 12:56:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Generate borders given the confine region we are to use. The borders
|
|
|
|
|
* are defined to be the outer region of the allowed area. This means
|
|
|
|
|
* top/left borders are "within" the allowed area, while bottom/right
|
|
|
|
|
* borders are outside. This needs to be considered when clamping
|
|
|
|
|
* confined motion vectors.
|
|
|
|
|
*/
|
|
|
|
|
region_to_outline(region, &borders);
|
|
|
|
|
|
|
|
|
|
motion = (struct line) {
|
2022-02-02 17:18:18 +03:00
|
|
|
|
.a = (struct weston_coord) {
|
2015-04-30 12:56:37 +03:00
|
|
|
|
.x = wl_fixed_to_double(old_sx),
|
|
|
|
|
.y = wl_fixed_to_double(old_sy),
|
|
|
|
|
},
|
2023-02-07 01:21:44 +03:00
|
|
|
|
.b = surf_pos.c,
|
2015-04-30 12:56:37 +03:00
|
|
|
|
};
|
|
|
|
|
directions = get_motion_directions(&motion);
|
|
|
|
|
|
|
|
|
|
while (directions) {
|
|
|
|
|
closest_border = get_closest_border(&borders,
|
|
|
|
|
&motion,
|
|
|
|
|
directions);
|
|
|
|
|
if (closest_border)
|
|
|
|
|
clamp_to_border(closest_border, &motion, &directions);
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-02-07 01:44:51 +03:00
|
|
|
|
|
|
|
|
|
clamped_surf_pos = weston_coord_surface(motion.b.x, motion.b.y,
|
|
|
|
|
pointer->focus->surface);
|
|
|
|
|
clamped_pos = weston_coord_surface_to_global(pointer->focus,
|
|
|
|
|
clamped_surf_pos);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
|
2015-04-30 12:56:37 +03:00
|
|
|
|
wl_array_release(&borders);
|
2023-02-07 01:44:51 +03:00
|
|
|
|
return clamped_pos;
|
2015-04-30 12:56:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static double
|
2022-02-09 00:37:42 +03:00
|
|
|
|
point_to_border_distance_2(struct border *border, struct weston_coord_surface c)
|
2015-04-30 12:56:37 +03:00
|
|
|
|
{
|
|
|
|
|
double orig_x, orig_y;
|
|
|
|
|
double dx, dy;
|
|
|
|
|
|
|
|
|
|
if (is_border_horizontal(border)) {
|
2022-02-09 00:37:42 +03:00
|
|
|
|
if (c.c.x < border->line.a.x)
|
2015-04-30 12:56:37 +03:00
|
|
|
|
orig_x = border->line.a.x;
|
2022-02-09 00:37:42 +03:00
|
|
|
|
else if (c.c.x > border->line.b.x)
|
2015-04-30 12:56:37 +03:00
|
|
|
|
orig_x = border->line.b.x;
|
|
|
|
|
else
|
2022-02-09 00:37:42 +03:00
|
|
|
|
orig_x = c.c.x;
|
2015-04-30 12:56:37 +03:00
|
|
|
|
orig_y = border->line.a.y;
|
|
|
|
|
} else {
|
2022-02-09 00:37:42 +03:00
|
|
|
|
if (c.c.y < border->line.a.y)
|
2015-04-30 12:56:37 +03:00
|
|
|
|
orig_y = border->line.a.y;
|
2022-02-09 00:37:42 +03:00
|
|
|
|
else if (c.c.y > border->line.b.y)
|
2015-04-30 12:56:37 +03:00
|
|
|
|
orig_y = border->line.b.y;
|
|
|
|
|
else
|
2022-02-09 00:37:42 +03:00
|
|
|
|
orig_y = c.c.y;
|
2015-04-30 12:56:37 +03:00
|
|
|
|
orig_x = border->line.a.x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-02-09 00:37:42 +03:00
|
|
|
|
dx = fabs(orig_x - c.c.x);
|
|
|
|
|
dy = fabs(orig_y - c.c.y);
|
2015-04-30 12:56:37 +03:00
|
|
|
|
return dx*dx + dy*dy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2022-02-09 00:37:42 +03:00
|
|
|
|
warp_to_behind_border(struct border *border, struct weston_coord_surface *c)
|
2015-04-30 12:56:37 +03:00
|
|
|
|
{
|
2022-02-09 00:37:42 +03:00
|
|
|
|
double quantum = wl_fixed_to_double(1);
|
|
|
|
|
|
2015-04-30 12:56:37 +03:00
|
|
|
|
switch (border->blocking_dir) {
|
|
|
|
|
case MOTION_DIRECTION_POSITIVE_X:
|
|
|
|
|
case MOTION_DIRECTION_NEGATIVE_X:
|
|
|
|
|
if (border->blocking_dir == MOTION_DIRECTION_POSITIVE_X)
|
2022-02-09 00:37:42 +03:00
|
|
|
|
c->c.x = border->line.a.x - quantum;
|
2015-04-30 12:56:37 +03:00
|
|
|
|
else
|
2022-02-09 00:37:42 +03:00
|
|
|
|
c->c.x = border->line.a.x + quantum;
|
|
|
|
|
if (c->c.y < border->line.a.y)
|
|
|
|
|
c->c.y = border->line.a.y + quantum;
|
|
|
|
|
else if (c->c.y > border->line.b.y)
|
|
|
|
|
c->c.y = border->line.b.y - quantum;
|
2015-04-30 12:56:37 +03:00
|
|
|
|
break;
|
|
|
|
|
case MOTION_DIRECTION_POSITIVE_Y:
|
|
|
|
|
case MOTION_DIRECTION_NEGATIVE_Y:
|
|
|
|
|
if (border->blocking_dir == MOTION_DIRECTION_POSITIVE_Y)
|
2022-02-09 00:37:42 +03:00
|
|
|
|
c->c.y = border->line.a.y - quantum;
|
2015-04-30 12:56:37 +03:00
|
|
|
|
else
|
2022-02-09 00:37:42 +03:00
|
|
|
|
c->c.y = border->line.a.y + quantum;
|
|
|
|
|
if (c->c.x < border->line.a.x)
|
|
|
|
|
c->c.x = border->line.a.x + quantum;
|
|
|
|
|
else if (c->c.x > border->line.b.x)
|
|
|
|
|
c->c.x = border->line.b.x - quantum;
|
2015-04-30 12:56:37 +03:00
|
|
|
|
break;
|
|
|
|
|
}
|
2016-07-22 12:56:31 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
maybe_warp_confined_pointer(struct weston_pointer_constraint *constraint)
|
|
|
|
|
{
|
2022-02-09 00:37:42 +03:00
|
|
|
|
struct weston_coord_global cg;
|
|
|
|
|
struct weston_coord_surface cs;
|
2016-07-22 12:56:31 +03:00
|
|
|
|
|
2022-02-09 00:37:42 +03:00
|
|
|
|
cs = weston_coord_global_to_surface(constraint->view,
|
|
|
|
|
constraint->pointer->pos);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
|
2022-02-09 00:37:42 +03:00
|
|
|
|
if (!is_within_constraint_region(constraint, cs)) {
|
2015-04-30 12:56:37 +03:00
|
|
|
|
pixman_region32_t confine_region;
|
|
|
|
|
struct wl_array borders;
|
|
|
|
|
struct border *border;
|
|
|
|
|
double closest_distance_2 = DBL_MAX;
|
|
|
|
|
struct border *closest_border = NULL;
|
|
|
|
|
|
|
|
|
|
wl_array_init(&borders);
|
|
|
|
|
|
|
|
|
|
pixman_region32_init(&confine_region);
|
|
|
|
|
pixman_region32_intersect(&confine_region,
|
2023-10-13 15:37:20 +03:00
|
|
|
|
&constraint->surface->input,
|
2015-04-30 12:56:37 +03:00
|
|
|
|
&constraint->region);
|
2023-03-23 20:38:38 +03:00
|
|
|
|
assert(pixman_region32_not_empty(&confine_region));
|
2015-04-30 12:56:37 +03:00
|
|
|
|
region_to_outline(&confine_region, &borders);
|
|
|
|
|
pixman_region32_fini(&confine_region);
|
|
|
|
|
|
|
|
|
|
wl_array_for_each(border, &borders) {
|
|
|
|
|
double distance_2;
|
|
|
|
|
|
2022-02-09 00:37:42 +03:00
|
|
|
|
distance_2 = point_to_border_distance_2(border, cs);
|
2015-04-30 12:56:37 +03:00
|
|
|
|
if (distance_2 < closest_distance_2) {
|
|
|
|
|
closest_border = border;
|
|
|
|
|
closest_distance_2 = distance_2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert(closest_border);
|
|
|
|
|
|
2022-02-09 00:37:42 +03:00
|
|
|
|
warp_to_behind_border(closest_border, &cs);
|
2015-04-30 12:56:37 +03:00
|
|
|
|
|
|
|
|
|
wl_array_release(&borders);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
|
2022-02-09 02:31:55 +03:00
|
|
|
|
cg = weston_coord_surface_to_global(constraint->view, cs);
|
2023-02-07 01:58:59 +03:00
|
|
|
|
weston_pointer_move_to(constraint->pointer, cg);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
confined_pointer_grab_pointer_motion(struct weston_pointer_grab *grab,
|
2017-11-24 19:01:46 +03:00
|
|
|
|
const struct timespec *time,
|
2016-07-22 12:56:31 +03:00
|
|
|
|
struct weston_pointer_motion_event *event)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_constraint *constraint =
|
|
|
|
|
container_of(grab, struct weston_pointer_constraint, grab);
|
|
|
|
|
struct weston_pointer *pointer = grab->pointer;
|
|
|
|
|
struct weston_surface *surface;
|
|
|
|
|
wl_fixed_t old_sx = pointer->sx;
|
|
|
|
|
wl_fixed_t old_sy = pointer->sy;
|
|
|
|
|
pixman_region32_t confine_region;
|
2023-02-07 01:44:51 +03:00
|
|
|
|
struct weston_coord_global pos;
|
|
|
|
|
struct weston_coord_surface surf_pos;
|
2016-07-22 12:56:31 +03:00
|
|
|
|
|
|
|
|
|
assert(pointer->focus);
|
|
|
|
|
assert(pointer->focus->surface == constraint->surface);
|
|
|
|
|
|
|
|
|
|
surface = pointer->focus->surface;
|
|
|
|
|
|
2022-12-15 15:40:39 +03:00
|
|
|
|
weston_view_update_transform(pointer->focus);
|
|
|
|
|
|
2016-07-22 12:56:31 +03:00
|
|
|
|
pixman_region32_init(&confine_region);
|
|
|
|
|
pixman_region32_intersect(&confine_region,
|
|
|
|
|
&surface->input,
|
|
|
|
|
&constraint->region);
|
2023-02-07 01:44:51 +03:00
|
|
|
|
pos = weston_pointer_clamp_event_to_region(pointer, event,
|
|
|
|
|
&confine_region);
|
2023-02-07 01:58:59 +03:00
|
|
|
|
weston_pointer_move_to(pointer, pos);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
pixman_region32_fini(&confine_region);
|
|
|
|
|
|
2023-02-07 01:44:51 +03:00
|
|
|
|
surf_pos = weston_coord_global_to_surface(pointer->focus, pos);
|
|
|
|
|
pointer->sx = wl_fixed_from_double(surf_pos.c.x);
|
|
|
|
|
pointer->sy = wl_fixed_from_double(surf_pos.c.y);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
|
|
|
|
|
if (old_sx != pointer->sx || old_sy != pointer->sy) {
|
2016-08-12 11:41:32 +03:00
|
|
|
|
pointer_send_motion(pointer, time,
|
|
|
|
|
pointer->sx, pointer->sy);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-12 11:41:32 +03:00
|
|
|
|
pointer_send_relative_motion(pointer, time, event);
|
2016-07-22 12:56:31 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
confined_pointer_grab_pointer_button(struct weston_pointer_grab *grab,
|
2017-11-16 19:20:55 +03:00
|
|
|
|
const struct timespec *time,
|
2016-07-22 12:56:31 +03:00
|
|
|
|
uint32_t button,
|
|
|
|
|
uint32_t state_w)
|
|
|
|
|
{
|
|
|
|
|
weston_pointer_send_button(grab->pointer, time, button, state_w);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
confined_pointer_grab_pointer_axis(struct weston_pointer_grab *grab,
|
2017-11-16 19:20:56 +03:00
|
|
|
|
const struct timespec *time,
|
2016-07-22 12:56:31 +03:00
|
|
|
|
struct weston_pointer_axis_event *event)
|
|
|
|
|
{
|
|
|
|
|
weston_pointer_send_axis(grab->pointer, time, event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
confined_pointer_grab_pointer_axis_source(struct weston_pointer_grab *grab,
|
|
|
|
|
uint32_t source)
|
|
|
|
|
{
|
|
|
|
|
weston_pointer_send_axis_source(grab->pointer, source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
confined_pointer_grab_pointer_frame(struct weston_pointer_grab *grab)
|
|
|
|
|
{
|
|
|
|
|
weston_pointer_send_frame(grab->pointer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
confined_pointer_grab_pointer_cancel(struct weston_pointer_grab *grab)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_constraint *constraint =
|
|
|
|
|
container_of(grab, struct weston_pointer_constraint, grab);
|
|
|
|
|
|
|
|
|
|
disable_pointer_constraint(constraint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct weston_pointer_grab_interface
|
|
|
|
|
confined_pointer_grab_interface = {
|
|
|
|
|
confined_pointer_grab_pointer_focus,
|
|
|
|
|
confined_pointer_grab_pointer_motion,
|
|
|
|
|
confined_pointer_grab_pointer_button,
|
|
|
|
|
confined_pointer_grab_pointer_axis,
|
|
|
|
|
confined_pointer_grab_pointer_axis_source,
|
|
|
|
|
confined_pointer_grab_pointer_frame,
|
|
|
|
|
confined_pointer_grab_pointer_cancel,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
confined_pointer_destroy(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
confined_pointer_set_region(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource,
|
|
|
|
|
struct wl_resource *region_resource)
|
|
|
|
|
{
|
|
|
|
|
struct weston_pointer_constraint *constraint =
|
|
|
|
|
wl_resource_get_user_data(resource);
|
|
|
|
|
struct weston_region *region = region_resource ?
|
|
|
|
|
wl_resource_get_user_data(region_resource) : NULL;
|
|
|
|
|
|
|
|
|
|
if (!constraint)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (region) {
|
|
|
|
|
pixman_region32_copy(&constraint->region_pending,
|
|
|
|
|
®ion->region);
|
|
|
|
|
} else {
|
|
|
|
|
pixman_region32_fini(&constraint->region_pending);
|
|
|
|
|
region_init_infinite(&constraint->region_pending);
|
|
|
|
|
}
|
|
|
|
|
constraint->region_is_pending = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct zwp_confined_pointer_v1_interface confined_pointer_interface = {
|
|
|
|
|
confined_pointer_destroy,
|
|
|
|
|
confined_pointer_set_region,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pointer_constraints_confine_pointer(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource,
|
|
|
|
|
uint32_t id,
|
|
|
|
|
struct wl_resource *surface_resource,
|
|
|
|
|
struct wl_resource *pointer_resource,
|
|
|
|
|
struct wl_resource *region_resource,
|
|
|
|
|
uint32_t lifetime)
|
|
|
|
|
{
|
|
|
|
|
struct weston_surface *surface =
|
|
|
|
|
wl_resource_get_user_data(surface_resource);
|
|
|
|
|
struct weston_pointer *pointer = wl_resource_get_user_data(pointer_resource);
|
|
|
|
|
struct weston_region *region = region_resource ?
|
|
|
|
|
wl_resource_get_user_data(region_resource) : NULL;
|
|
|
|
|
|
|
|
|
|
init_pointer_constraint(resource, id, surface, pointer, region, lifetime,
|
|
|
|
|
&zwp_confined_pointer_v1_interface,
|
|
|
|
|
&confined_pointer_interface,
|
|
|
|
|
&confined_pointer_grab_interface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct zwp_pointer_constraints_v1_interface pointer_constraints_interface = {
|
|
|
|
|
pointer_constraints_destroy,
|
|
|
|
|
pointer_constraints_lock_pointer,
|
|
|
|
|
pointer_constraints_confine_pointer,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bind_pointer_constraints(struct wl_client *client, void *data,
|
|
|
|
|
uint32_t version, uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
resource = wl_resource_create(client,
|
|
|
|
|
&zwp_pointer_constraints_v1_interface,
|
|
|
|
|
1, id);
|
|
|
|
|
|
|
|
|
|
wl_resource_set_implementation(resource, &pointer_constraints_interface,
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 15:05:50 +03:00
|
|
|
|
static void
|
|
|
|
|
input_timestamps_destroy(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct zwp_input_timestamps_v1_interface
|
|
|
|
|
input_timestamps_interface = {
|
|
|
|
|
input_timestamps_destroy,
|
|
|
|
|
};
|
|
|
|
|
|
2018-02-16 19:44:16 +03:00
|
|
|
|
static void
|
|
|
|
|
input_timestamps_manager_destroy(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
input_timestamps_manager_get_keyboard_timestamps(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource,
|
|
|
|
|
uint32_t id,
|
|
|
|
|
struct wl_resource *keyboard_resource)
|
|
|
|
|
{
|
2018-02-20 15:05:50 +03:00
|
|
|
|
struct weston_keyboard *keyboard =
|
|
|
|
|
wl_resource_get_user_data(keyboard_resource);
|
|
|
|
|
struct wl_resource *input_ts;
|
|
|
|
|
|
|
|
|
|
input_ts = wl_resource_create(client,
|
|
|
|
|
&zwp_input_timestamps_v1_interface,
|
|
|
|
|
1, id);
|
|
|
|
|
if (!input_ts) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (keyboard) {
|
|
|
|
|
wl_list_insert(&keyboard->timestamps_list,
|
|
|
|
|
wl_resource_get_link(input_ts));
|
|
|
|
|
} else {
|
|
|
|
|
wl_list_init(wl_resource_get_link(input_ts));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_resource_set_implementation(input_ts,
|
|
|
|
|
&input_timestamps_interface,
|
|
|
|
|
keyboard_resource,
|
|
|
|
|
unbind_resource);
|
2018-02-16 19:44:16 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
input_timestamps_manager_get_pointer_timestamps(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource,
|
|
|
|
|
uint32_t id,
|
|
|
|
|
struct wl_resource *pointer_resource)
|
|
|
|
|
{
|
2018-02-20 15:06:26 +03:00
|
|
|
|
struct weston_pointer *pointer =
|
|
|
|
|
wl_resource_get_user_data(pointer_resource);
|
|
|
|
|
struct wl_resource *input_ts;
|
|
|
|
|
|
|
|
|
|
input_ts = wl_resource_create(client,
|
|
|
|
|
&zwp_input_timestamps_v1_interface,
|
|
|
|
|
1, id);
|
|
|
|
|
if (!input_ts) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pointer) {
|
|
|
|
|
wl_list_insert(&pointer->timestamps_list,
|
|
|
|
|
wl_resource_get_link(input_ts));
|
|
|
|
|
} else {
|
|
|
|
|
wl_list_init(wl_resource_get_link(input_ts));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_resource_set_implementation(input_ts,
|
|
|
|
|
&input_timestamps_interface,
|
|
|
|
|
pointer_resource,
|
|
|
|
|
unbind_resource);
|
2018-02-16 19:44:16 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
input_timestamps_manager_get_touch_timestamps(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource,
|
|
|
|
|
uint32_t id,
|
|
|
|
|
struct wl_resource *touch_resource)
|
|
|
|
|
{
|
2018-02-20 15:07:03 +03:00
|
|
|
|
struct weston_touch *touch = wl_resource_get_user_data(touch_resource);
|
|
|
|
|
struct wl_resource *input_ts;
|
|
|
|
|
|
|
|
|
|
input_ts = wl_resource_create(client,
|
|
|
|
|
&zwp_input_timestamps_v1_interface,
|
|
|
|
|
1, id);
|
|
|
|
|
if (!input_ts) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (touch) {
|
|
|
|
|
wl_list_insert(&touch->timestamps_list,
|
|
|
|
|
wl_resource_get_link(input_ts));
|
|
|
|
|
} else {
|
|
|
|
|
wl_list_init(wl_resource_get_link(input_ts));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_resource_set_implementation(input_ts,
|
|
|
|
|
&input_timestamps_interface,
|
|
|
|
|
touch_resource,
|
|
|
|
|
unbind_resource);
|
2018-02-16 19:44:16 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct zwp_input_timestamps_manager_v1_interface
|
|
|
|
|
input_timestamps_manager_interface = {
|
|
|
|
|
input_timestamps_manager_destroy,
|
|
|
|
|
input_timestamps_manager_get_keyboard_timestamps,
|
|
|
|
|
input_timestamps_manager_get_pointer_timestamps,
|
|
|
|
|
input_timestamps_manager_get_touch_timestamps,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bind_input_timestamps_manager(struct wl_client *client, void *data,
|
|
|
|
|
uint32_t version, uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource =
|
|
|
|
|
wl_resource_create(client,
|
|
|
|
|
&zwp_input_timestamps_manager_v1_interface,
|
|
|
|
|
1, id);
|
|
|
|
|
|
|
|
|
|
if (resource == NULL) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_resource_set_implementation(resource,
|
|
|
|
|
&input_timestamps_manager_interface,
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 23:21:17 +04:00
|
|
|
|
int
|
|
|
|
|
weston_input_init(struct weston_compositor *compositor)
|
|
|
|
|
{
|
|
|
|
|
if (!wl_global_create(compositor->wl_display,
|
|
|
|
|
&zwp_relative_pointer_manager_v1_interface, 1,
|
|
|
|
|
compositor, bind_relative_pointer_manager))
|
|
|
|
|
return -1;
|
|
|
|
|
|
2016-07-22 12:56:31 +03:00
|
|
|
|
if (!wl_global_create(compositor->wl_display,
|
|
|
|
|
&zwp_pointer_constraints_v1_interface, 1,
|
|
|
|
|
NULL, bind_pointer_constraints))
|
|
|
|
|
return -1;
|
|
|
|
|
|
2018-02-16 19:44:16 +03:00
|
|
|
|
if (!wl_global_create(compositor->wl_display,
|
|
|
|
|
&zwp_input_timestamps_manager_v1_interface, 1,
|
|
|
|
|
NULL, bind_input_timestamps_manager))
|
|
|
|
|
return -1;
|
|
|
|
|
|
2014-10-22 23:21:17 +04:00
|
|
|
|
return 0;
|
|
|
|
|
}
|