2013-05-03 13:51:22 -04:00
|
|
|
/*
|
|
|
|
* Wayland Support
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Intel Corporation
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright © 2008 Kristian Høgsberg
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that copyright
|
|
|
|
* notice and this permission notice appear in supporting documentation, and
|
|
|
|
* that the name of the copyright holders not be used in advertising or
|
|
|
|
* publicity pertaining to distribution of the software without specific,
|
|
|
|
* written prior permission. The copyright holders make no representations
|
|
|
|
* about the suitability of this software for any purpose. It is provided "as
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
|
|
* OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* The file is based on src/input.c from Weston */
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-08-23 07:57:58 -04:00
|
|
|
#include <clutter/clutter.h>
|
2013-09-11 08:06:05 -04:00
|
|
|
#include <linux/input.h>
|
2013-08-23 07:57:58 -04:00
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
#include "meta-wayland-pointer.h"
|
2013-08-30 12:03:30 -04:00
|
|
|
#include "meta-wayland-private.h"
|
2014-04-17 16:54:30 -04:00
|
|
|
#include "meta-cursor.h"
|
|
|
|
#include "meta-cursor-tracker-private.h"
|
2014-04-17 18:16:49 -04:00
|
|
|
#include "meta-surface-actor-wayland.h"
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2013-07-17 04:44:29 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
2014-04-17 18:16:49 -04:00
|
|
|
#define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int (10)
|
|
|
|
|
2013-09-10 09:53:31 -04:00
|
|
|
static void meta_wayland_pointer_end_popup_grab (MetaWaylandPointer *pointer);
|
|
|
|
|
2014-04-17 17:16:17 -04:00
|
|
|
static void
|
|
|
|
unbind_resource (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_list_remove (wl_resource_get_link (resource));
|
|
|
|
}
|
|
|
|
|
2014-04-17 17:00:59 -04:00
|
|
|
static void
|
|
|
|
set_cursor_surface (MetaWaylandPointer *pointer,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
if (pointer->cursor_surface == surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (pointer->cursor_surface)
|
|
|
|
wl_list_remove (&pointer->cursor_surface_destroy_listener.link);
|
|
|
|
|
|
|
|
pointer->cursor_surface = surface;
|
|
|
|
|
|
|
|
if (pointer->cursor_surface)
|
|
|
|
wl_resource_add_destroy_listener (pointer->cursor_surface->resource,
|
|
|
|
&pointer->cursor_surface_destroy_listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pointer_handle_cursor_surface_destroy (struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
MetaWaylandPointer *pointer = wl_container_of (listener, pointer, cursor_surface_destroy_listener);
|
|
|
|
|
|
|
|
set_cursor_surface (pointer, NULL);
|
|
|
|
meta_wayland_pointer_update_cursor_surface (pointer);
|
|
|
|
}
|
|
|
|
|
2013-12-03 10:50:35 -05:00
|
|
|
static void
|
2014-02-17 19:13:16 -05:00
|
|
|
pointer_handle_focus_surface_destroy (struct wl_listener *listener, void *data)
|
2013-12-03 10:50:35 -05:00
|
|
|
{
|
2014-02-17 19:13:16 -05:00
|
|
|
MetaWaylandPointer *pointer = wl_container_of (listener, pointer, focus_surface_listener);
|
2014-02-20 11:29:28 -05:00
|
|
|
|
2014-04-16 19:04:09 -04:00
|
|
|
meta_wayland_pointer_set_focus (pointer, NULL);
|
2013-12-03 10:50:35 -05:00
|
|
|
}
|
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
static void
|
|
|
|
default_grab_focus (MetaWaylandPointerGrab *grab,
|
2014-03-16 11:50:38 -04:00
|
|
|
MetaWaylandSurface *surface)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
|
|
|
MetaWaylandPointer *pointer = grab->pointer;
|
|
|
|
|
|
|
|
if (pointer->button_count > 0)
|
|
|
|
return;
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
meta_wayland_pointer_set_focus (pointer, surface);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
default_grab_motion (MetaWaylandPointerGrab *grab,
|
2013-09-11 08:06:05 -04:00
|
|
|
const ClutterEvent *event)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2014-04-16 15:10:48 -04:00
|
|
|
MetaWaylandPointer *pointer = grab->pointer;
|
2013-05-03 13:51:22 -04:00
|
|
|
struct wl_resource *resource;
|
2014-04-16 15:11:10 -04:00
|
|
|
struct wl_list *l;
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2014-04-16 15:11:10 -04:00
|
|
|
l = &pointer->focus_resource_list;
|
|
|
|
wl_resource_for_each(resource, l)
|
2013-09-11 08:06:05 -04:00
|
|
|
{
|
|
|
|
wl_fixed_t sx, sy;
|
|
|
|
|
2014-04-16 15:10:48 -04:00
|
|
|
meta_wayland_pointer_get_relative_coordinates (pointer,
|
|
|
|
pointer->focus_surface,
|
|
|
|
&sx, &sy);
|
2013-09-11 08:06:05 -04:00
|
|
|
wl_pointer_send_motion (resource, clutter_event_get_time (event), sx, sy);
|
|
|
|
}
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
default_grab_button (MetaWaylandPointerGrab *grab,
|
2013-09-11 08:06:05 -04:00
|
|
|
const ClutterEvent *event)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
|
|
|
MetaWaylandPointer *pointer = grab->pointer;
|
|
|
|
struct wl_resource *resource;
|
2014-04-16 15:11:10 -04:00
|
|
|
struct wl_list *l;
|
2013-09-11 08:06:05 -04:00
|
|
|
ClutterEventType event_type;
|
|
|
|
|
|
|
|
event_type = clutter_event_type (event);
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2014-04-16 15:11:10 -04:00
|
|
|
l = &grab->pointer->focus_resource_list;
|
|
|
|
wl_resource_for_each(resource, l)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2014-04-16 15:29:59 -04:00
|
|
|
struct wl_client *client = wl_resource_get_client (pointer->focus_surface->resource);
|
2013-05-03 13:51:22 -04:00
|
|
|
struct wl_display *display = wl_client_get_display (client);
|
2013-09-11 08:06:05 -04:00
|
|
|
uint32_t button;
|
|
|
|
uint32_t serial;
|
|
|
|
|
|
|
|
button = clutter_event_get_button (event);
|
|
|
|
switch (button)
|
|
|
|
{
|
|
|
|
/* The evdev input right and middle button numbers are swapped
|
|
|
|
relative to how Clutter numbers them */
|
|
|
|
case 2:
|
|
|
|
button = BTN_MIDDLE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
button = BTN_RIGHT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
button = button + BTN_LEFT - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
serial = wl_display_next_serial (display);
|
2013-09-11 08:06:05 -04:00
|
|
|
wl_pointer_send_button (resource, serial,
|
|
|
|
clutter_event_get_time (event), button,
|
|
|
|
event_type == CLUTTER_BUTTON_PRESS ? 1 : 0);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
if (pointer->button_count == 0 && event_type == CLUTTER_BUTTON_RELEASE)
|
|
|
|
meta_wayland_pointer_set_focus (pointer, pointer->current);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const MetaWaylandPointerGrabInterface default_pointer_grab_interface = {
|
|
|
|
default_grab_focus,
|
|
|
|
default_grab_motion,
|
|
|
|
default_grab_button
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2014-04-17 18:12:23 -04:00
|
|
|
meta_wayland_pointer_init (MetaWaylandPointer *pointer,
|
|
|
|
struct wl_display *display)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2013-08-23 07:57:58 -04:00
|
|
|
ClutterDeviceManager *manager;
|
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
memset (pointer, 0, sizeof *pointer);
|
2014-04-17 18:12:23 -04:00
|
|
|
|
|
|
|
pointer->display = display;
|
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
wl_list_init (&pointer->resource_list);
|
2014-04-16 15:11:10 -04:00
|
|
|
wl_list_init (&pointer->focus_resource_list);
|
2014-02-18 18:00:26 -05:00
|
|
|
|
2014-02-17 19:13:16 -05:00
|
|
|
pointer->focus_surface_listener.notify = pointer_handle_focus_surface_destroy;
|
2014-02-18 18:00:26 -05:00
|
|
|
|
2014-04-18 10:15:40 -04:00
|
|
|
pointer->cursor_surface = NULL;
|
|
|
|
pointer->cursor_surface_destroy_listener.notify = pointer_handle_cursor_surface_destroy;
|
|
|
|
pointer->hotspot_x = 16;
|
|
|
|
pointer->hotspot_y = 16;
|
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
pointer->default_grab.interface = &default_pointer_grab_interface;
|
|
|
|
pointer->default_grab.pointer = pointer;
|
|
|
|
pointer->grab = &pointer->default_grab;
|
|
|
|
|
2013-08-23 07:57:58 -04:00
|
|
|
manager = clutter_device_manager_get_default ();
|
2014-04-18 10:27:48 -04:00
|
|
|
pointer->device = clutter_device_manager_get_core_device (manager, CLUTTER_POINTER_DEVICE);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_pointer_release (MetaWaylandPointer *pointer)
|
|
|
|
{
|
2014-04-17 17:00:59 -04:00
|
|
|
set_cursor_surface (pointer, NULL);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2014-04-17 17:52:11 -04:00
|
|
|
static int
|
|
|
|
count_buttons (const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
static gint maskmap[5] =
|
|
|
|
{
|
|
|
|
CLUTTER_BUTTON1_MASK, CLUTTER_BUTTON2_MASK, CLUTTER_BUTTON3_MASK,
|
|
|
|
CLUTTER_BUTTON4_MASK, CLUTTER_BUTTON5_MASK
|
|
|
|
};
|
|
|
|
ClutterModifierType mod_mask;
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
mod_mask = clutter_event_get_state (event);
|
|
|
|
count = 0;
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
if (mod_mask & maskmap[i])
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2014-04-18 18:54:35 -04:00
|
|
|
static void
|
|
|
|
sync_focus_surface (MetaWaylandPointer *pointer)
|
|
|
|
{
|
2014-04-20 10:59:49 -04:00
|
|
|
MetaDisplay *display = meta_get_display ();
|
|
|
|
MetaWaylandSurface *focus_surface;
|
|
|
|
|
2014-04-20 11:43:10 -04:00
|
|
|
/* Don't update the focus surface while we have a move/resize grab. */
|
|
|
|
if (meta_grab_op_is_moving_or_resizing (display->grab_op))
|
2014-04-20 10:59:49 -04:00
|
|
|
return;
|
|
|
|
|
2014-04-20 11:08:09 -04:00
|
|
|
if (meta_grab_op_should_block_wayland (display->grab_op))
|
|
|
|
focus_surface = NULL;
|
|
|
|
else
|
|
|
|
focus_surface = pointer->current;
|
2014-04-18 18:53:38 -04:00
|
|
|
|
|
|
|
if (focus_surface != pointer->focus_surface)
|
|
|
|
{
|
|
|
|
const MetaWaylandPointerGrabInterface *interface = pointer->grab->interface;
|
|
|
|
interface->focus (pointer->grab, focus_surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-17 18:16:49 -04:00
|
|
|
static void
|
|
|
|
repick_for_event (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *for_event)
|
|
|
|
{
|
2014-04-18 18:46:15 -04:00
|
|
|
ClutterActor *actor = NULL;
|
2014-04-17 18:16:49 -04:00
|
|
|
|
|
|
|
if (for_event)
|
|
|
|
{
|
|
|
|
actor = clutter_event_get_source (for_event);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-18 10:27:48 -04:00
|
|
|
ClutterStage *stage = clutter_input_device_get_pointer_stage (pointer->device);
|
2014-04-17 18:16:49 -04:00
|
|
|
|
|
|
|
if (stage)
|
2014-04-18 10:27:48 -04:00
|
|
|
{
|
|
|
|
ClutterPoint pos;
|
|
|
|
|
|
|
|
clutter_input_device_get_coords (pointer->device, NULL, &pos);
|
|
|
|
actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_REACTIVE,
|
|
|
|
pos.x, pos.y);
|
|
|
|
}
|
2014-04-17 18:16:49 -04:00
|
|
|
}
|
|
|
|
|
2014-04-18 18:51:17 -04:00
|
|
|
if (META_IS_SURFACE_ACTOR_WAYLAND (actor))
|
2014-04-18 18:46:15 -04:00
|
|
|
pointer->current = meta_surface_actor_wayland_get_surface (META_SURFACE_ACTOR_WAYLAND (actor));
|
|
|
|
else
|
|
|
|
pointer->current = NULL;
|
2014-04-18 18:38:20 -04:00
|
|
|
|
2014-04-18 18:46:15 -04:00
|
|
|
if (pointer->cursor_tracker && pointer->current == NULL)
|
2014-04-18 18:38:20 -04:00
|
|
|
meta_cursor_tracker_unset_window_cursor (pointer->cursor_tracker);
|
|
|
|
|
2014-04-18 18:53:38 -04:00
|
|
|
sync_focus_surface (pointer);
|
2014-04-17 18:16:49 -04:00
|
|
|
}
|
|
|
|
|
2014-04-20 10:59:49 -04:00
|
|
|
void
|
|
|
|
meta_wayland_pointer_update (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
pointer->button_count = count_buttons (event);
|
|
|
|
|
|
|
|
repick_for_event (pointer, event);
|
|
|
|
|
|
|
|
if (pointer->cursor_tracker)
|
|
|
|
{
|
|
|
|
ClutterPoint pos;
|
|
|
|
|
|
|
|
clutter_input_device_get_coords (pointer->device, NULL, &pos);
|
|
|
|
meta_cursor_tracker_update_position (pointer->cursor_tracker, pos.x, pos.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-17 18:16:49 -04:00
|
|
|
static void
|
|
|
|
notify_motion (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
pointer->grab->interface->motion (pointer->grab, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_motion_event (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
notify_motion (pointer, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_button_event (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
gboolean implicit_grab;
|
|
|
|
|
|
|
|
notify_motion (pointer, event);
|
|
|
|
|
|
|
|
implicit_grab = (event->type == CLUTTER_BUTTON_PRESS) && (pointer->button_count == 1);
|
|
|
|
if (implicit_grab)
|
|
|
|
{
|
|
|
|
pointer->grab_button = clutter_event_get_button (event);
|
|
|
|
pointer->grab_time = clutter_event_get_time (event);
|
2014-04-18 10:27:48 -04:00
|
|
|
clutter_event_get_coords (event, &pointer->grab_x, &pointer->grab_y);
|
2014-04-17 18:16:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pointer->grab->interface->button (pointer->grab, event);
|
|
|
|
|
|
|
|
if (implicit_grab)
|
|
|
|
pointer->grab_serial = wl_display_get_serial (pointer->display);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_scroll_event (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
struct wl_list *l;
|
|
|
|
wl_fixed_t x_value = 0, y_value = 0;
|
|
|
|
|
|
|
|
notify_motion (pointer, event);
|
|
|
|
|
|
|
|
if (clutter_event_is_pointer_emulated (event))
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (clutter_event_get_scroll_direction (event))
|
|
|
|
{
|
|
|
|
case CLUTTER_SCROLL_UP:
|
|
|
|
y_value = -DEFAULT_AXIS_STEP_DISTANCE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_SCROLL_DOWN:
|
|
|
|
y_value = DEFAULT_AXIS_STEP_DISTANCE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_SCROLL_LEFT:
|
|
|
|
x_value = -DEFAULT_AXIS_STEP_DISTANCE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_SCROLL_RIGHT:
|
|
|
|
x_value = DEFAULT_AXIS_STEP_DISTANCE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_SCROLL_SMOOTH:
|
|
|
|
{
|
|
|
|
double dx, dy;
|
|
|
|
clutter_event_get_scroll_delta (event, &dx, &dy);
|
|
|
|
x_value = wl_fixed_from_double (dx);
|
|
|
|
y_value = wl_fixed_from_double (dy);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
l = &pointer->focus_resource_list;
|
|
|
|
wl_resource_for_each (resource, l)
|
|
|
|
{
|
|
|
|
if (x_value)
|
|
|
|
wl_pointer_send_axis (resource, clutter_event_get_time (event),
|
|
|
|
WL_POINTER_AXIS_HORIZONTAL_SCROLL, x_value);
|
|
|
|
if (y_value)
|
|
|
|
wl_pointer_send_axis (resource, clutter_event_get_time (event),
|
|
|
|
WL_POINTER_AXIS_VERTICAL_SCROLL, y_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_wayland_pointer_handle_event (MetaWaylandPointer *pointer,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case CLUTTER_MOTION:
|
|
|
|
handle_motion_event (pointer, event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_BUTTON_PRESS:
|
|
|
|
case CLUTTER_BUTTON_RELEASE:
|
|
|
|
handle_button_event (pointer, event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_SCROLL:
|
|
|
|
handle_scroll_event (pointer, event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-04-16 15:11:10 -04:00
|
|
|
static void
|
|
|
|
move_resources (struct wl_list *destination, struct wl_list *source)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2014-04-16 15:11:10 -04:00
|
|
|
wl_list_insert_list (destination, source);
|
|
|
|
wl_list_init (source);
|
|
|
|
}
|
2013-05-03 13:51:22 -04:00
|
|
|
|
2014-04-16 15:11:10 -04:00
|
|
|
static void
|
|
|
|
move_resources_for_client (struct wl_list *destination,
|
|
|
|
struct wl_list *source,
|
|
|
|
struct wl_client *client)
|
|
|
|
{
|
|
|
|
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-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_pointer_set_focus (MetaWaylandPointer *pointer,
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandSurface *surface)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2014-04-16 15:11:10 -04:00
|
|
|
if (pointer->focus_surface == surface && !wl_list_empty (&pointer->focus_resource_list))
|
2013-11-19 20:20:13 -05:00
|
|
|
return;
|
|
|
|
|
2014-02-18 23:16:54 -05:00
|
|
|
if (pointer->focus_surface)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2014-04-16 15:11:10 -04:00
|
|
|
struct wl_resource *resource;
|
|
|
|
struct wl_list *l;
|
|
|
|
|
|
|
|
l = &pointer->focus_resource_list;
|
|
|
|
if (!wl_list_empty (l))
|
2014-01-31 18:18:59 -05:00
|
|
|
{
|
2014-04-16 15:29:59 -04:00
|
|
|
struct wl_client *client = wl_resource_get_client (pointer->focus_surface->resource);
|
2014-04-16 14:49:30 -04:00
|
|
|
struct wl_display *display = wl_client_get_display (client);
|
|
|
|
uint32_t serial = wl_display_next_serial (display);
|
2014-01-31 18:18:59 -05:00
|
|
|
|
2014-04-16 15:11:10 -04:00
|
|
|
wl_resource_for_each (resource, l)
|
|
|
|
{
|
|
|
|
wl_pointer_send_leave (resource, serial, pointer->focus_surface->resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
move_resources (&pointer->resource_list, &pointer->focus_resource_list);
|
2014-02-18 23:16:54 -05:00
|
|
|
}
|
2014-02-19 07:56:56 -05:00
|
|
|
|
|
|
|
wl_list_remove (&pointer->focus_surface_listener.link);
|
|
|
|
pointer->focus_surface = NULL;
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2014-02-18 23:16:54 -05:00
|
|
|
if (surface != NULL)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2014-04-16 15:11:10 -04:00
|
|
|
struct wl_resource *resource;
|
|
|
|
struct wl_list *l;
|
2014-04-18 10:27:48 -04:00
|
|
|
ClutterPoint pos;
|
2014-04-16 15:11:10 -04:00
|
|
|
|
2014-02-18 23:16:54 -05:00
|
|
|
pointer->focus_surface = surface;
|
|
|
|
wl_resource_add_destroy_listener (pointer->focus_surface->resource, &pointer->focus_surface_listener);
|
2013-09-11 08:06:05 -04:00
|
|
|
|
2014-04-18 10:27:48 -04:00
|
|
|
clutter_input_device_get_coords (pointer->device, NULL, &pos);
|
|
|
|
|
2014-04-16 14:47:06 -04:00
|
|
|
meta_window_handle_enter (pointer->focus_surface->window,
|
|
|
|
/* XXX -- can we reliably get a timestamp for setting focus? */
|
|
|
|
clutter_get_current_event_time (),
|
2014-04-18 10:27:48 -04:00
|
|
|
pos.x, pos.y);
|
2014-04-16 14:47:06 -04:00
|
|
|
|
2014-04-16 15:11:10 -04:00
|
|
|
move_resources_for_client (&pointer->focus_resource_list,
|
|
|
|
&pointer->resource_list,
|
|
|
|
wl_resource_get_client (pointer->focus_surface->resource));
|
|
|
|
|
|
|
|
l = &pointer->focus_resource_list;
|
|
|
|
if (!wl_list_empty (l))
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2014-04-16 15:29:59 -04:00
|
|
|
struct wl_client *client = wl_resource_get_client (pointer->focus_surface->resource);
|
2014-02-18 23:16:54 -05:00
|
|
|
struct wl_display *display = wl_client_get_display (client);
|
|
|
|
uint32_t serial = wl_display_next_serial (display);
|
2014-02-18 18:00:26 -05:00
|
|
|
|
2014-04-16 15:11:10 -04:00
|
|
|
wl_resource_for_each (resource, l)
|
|
|
|
{
|
|
|
|
wl_fixed_t sx, sy;
|
2014-02-18 23:18:13 -05:00
|
|
|
|
2014-04-16 15:11:10 -04:00
|
|
|
meta_wayland_pointer_get_relative_coordinates (pointer, pointer->focus_surface, &sx, &sy);
|
|
|
|
wl_pointer_send_enter (resource, serial, pointer->focus_surface->resource, sx, sy);
|
|
|
|
}
|
2014-02-18 18:00:26 -05:00
|
|
|
|
2014-02-18 23:16:54 -05:00
|
|
|
pointer->focus_serial = serial;
|
|
|
|
}
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_pointer_start_grab (MetaWaylandPointer *pointer,
|
|
|
|
MetaWaylandPointerGrab *grab)
|
|
|
|
{
|
|
|
|
const MetaWaylandPointerGrabInterface *interface;
|
|
|
|
|
|
|
|
pointer->grab = grab;
|
|
|
|
interface = pointer->grab->interface;
|
|
|
|
grab->pointer = pointer;
|
|
|
|
|
|
|
|
if (pointer->current)
|
2014-03-16 11:50:38 -04:00
|
|
|
interface->focus (pointer->grab, pointer->current);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_pointer_end_grab (MetaWaylandPointer *pointer)
|
|
|
|
{
|
|
|
|
const MetaWaylandPointerGrabInterface *interface;
|
|
|
|
|
|
|
|
pointer->grab = &pointer->default_grab;
|
|
|
|
interface = pointer->grab->interface;
|
2014-03-16 11:50:38 -04:00
|
|
|
interface->focus (pointer->grab, pointer->current);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
typedef struct {
|
|
|
|
MetaWaylandPointerGrab generic;
|
|
|
|
|
2013-09-11 08:53:48 -04:00
|
|
|
struct wl_client *grab_client;
|
|
|
|
struct wl_list all_popups;
|
2013-09-11 08:06:05 -04:00
|
|
|
} MetaWaylandPopupGrab;
|
|
|
|
|
2013-09-11 08:53:48 -04:00
|
|
|
typedef struct {
|
|
|
|
MetaWaylandPopupGrab *grab;
|
|
|
|
MetaWaylandSurface *surface;
|
|
|
|
struct wl_listener surface_destroy_listener;
|
|
|
|
|
|
|
|
struct wl_list link;
|
|
|
|
} MetaWaylandPopup;
|
|
|
|
|
2013-09-10 09:53:31 -04:00
|
|
|
static void
|
|
|
|
popup_grab_focus (MetaWaylandPointerGrab *grab,
|
2014-03-16 11:50:38 -04:00
|
|
|
MetaWaylandSurface *surface)
|
2013-09-10 09:53:31 -04:00
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandPopupGrab *popup_grab = (MetaWaylandPopupGrab*)grab;
|
|
|
|
|
2013-09-10 09:53:31 -04:00
|
|
|
/* Popup grabs are in owner-events mode (ie, events for the same client
|
|
|
|
are reported as normal) */
|
2013-11-19 18:48:18 -05:00
|
|
|
if (surface && wl_resource_get_client (surface->resource) == popup_grab->grab_client)
|
2014-04-12 03:29:16 -04:00
|
|
|
meta_wayland_pointer_set_focus (grab->pointer, surface);
|
2013-09-10 09:53:31 -04:00
|
|
|
else
|
2013-09-11 08:06:05 -04:00
|
|
|
meta_wayland_pointer_set_focus (grab->pointer, NULL);
|
2013-09-10 09:53:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
popup_grab_motion (MetaWaylandPointerGrab *grab,
|
2013-09-11 08:06:05 -04:00
|
|
|
const ClutterEvent *event)
|
2013-09-10 09:53:31 -04:00
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
default_grab_motion (grab, event);
|
2013-09-10 09:53:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
popup_grab_button (MetaWaylandPointerGrab *grab,
|
2013-09-11 08:06:05 -04:00
|
|
|
const ClutterEvent *event)
|
2013-09-10 09:53:31 -04:00
|
|
|
{
|
|
|
|
MetaWaylandPointer *pointer = grab->pointer;
|
|
|
|
|
2014-04-16 15:29:59 -04:00
|
|
|
if (pointer->focus_surface)
|
|
|
|
default_grab_button (grab, event);
|
2013-09-11 08:06:05 -04:00
|
|
|
else if (clutter_event_type (event) == CLUTTER_BUTTON_RELEASE &&
|
2013-09-10 09:53:31 -04:00
|
|
|
pointer->button_count == 0)
|
|
|
|
meta_wayland_pointer_end_popup_grab (grab->pointer);
|
|
|
|
}
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
static MetaWaylandPointerGrabInterface popup_grab_interface = {
|
2013-09-10 09:53:31 -04:00
|
|
|
popup_grab_focus,
|
|
|
|
popup_grab_motion,
|
|
|
|
popup_grab_button
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_pointer_end_popup_grab (MetaWaylandPointer *pointer)
|
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandPopupGrab *popup_grab;
|
2013-09-11 08:53:48 -04:00
|
|
|
MetaWaylandPopup *popup, *tmp;
|
2013-09-10 09:53:31 -04:00
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
popup_grab = (MetaWaylandPopupGrab*)pointer->grab;
|
2013-09-10 09:53:31 -04:00
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
g_assert (popup_grab->generic.interface == &popup_grab_interface);
|
2013-09-10 09:53:31 -04:00
|
|
|
|
2013-09-11 08:53:48 -04:00
|
|
|
wl_list_for_each_safe (popup, tmp, &popup_grab->all_popups, link)
|
2013-09-10 09:53:31 -04:00
|
|
|
{
|
2014-02-28 00:18:42 -05:00
|
|
|
meta_wayland_surface_popup_done (popup->surface);
|
2013-09-11 08:53:48 -04:00
|
|
|
wl_list_remove (&popup->surface_destroy_listener.link);
|
|
|
|
wl_list_remove (&popup->link);
|
|
|
|
g_slice_free (MetaWaylandPopup, popup);
|
2013-09-10 09:53:31 -04:00
|
|
|
}
|
|
|
|
|
2014-03-10 15:00:59 -04:00
|
|
|
{
|
|
|
|
MetaDisplay *display = meta_get_display ();
|
|
|
|
meta_display_end_grab_op (display,
|
|
|
|
meta_display_get_current_time_roundtrip (display));
|
|
|
|
}
|
|
|
|
|
2013-09-10 09:53:31 -04:00
|
|
|
meta_wayland_pointer_end_grab (pointer);
|
2013-09-11 08:06:05 -04:00
|
|
|
g_slice_free (MetaWaylandPopupGrab, popup_grab);
|
2013-09-10 09:53:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_popup_surface_destroy (struct wl_listener *listener,
|
|
|
|
void *data)
|
|
|
|
{
|
2013-09-11 08:53:48 -04:00
|
|
|
MetaWaylandPopup *popup =
|
|
|
|
wl_container_of (listener, popup, surface_destroy_listener);
|
|
|
|
MetaWaylandPopupGrab *popup_grab = popup->grab;
|
2013-09-10 09:53:31 -04:00
|
|
|
|
2013-09-11 08:53:48 -04:00
|
|
|
wl_list_remove (&popup->link);
|
|
|
|
g_slice_free (MetaWaylandPopup, popup);
|
|
|
|
|
|
|
|
if (wl_list_empty (&popup_grab->all_popups))
|
|
|
|
meta_wayland_pointer_end_popup_grab (popup_grab->generic.pointer);
|
2013-09-10 09:53:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_wayland_pointer_start_popup_grab (MetaWaylandPointer *pointer,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
2013-09-11 08:06:05 -04:00
|
|
|
MetaWaylandPopupGrab *grab;
|
2013-09-11 08:53:48 -04:00
|
|
|
MetaWaylandPopup *popup;
|
2013-09-10 09:53:31 -04:00
|
|
|
|
2013-09-11 08:53:48 -04:00
|
|
|
if (pointer->grab != &pointer->default_grab)
|
|
|
|
{
|
2014-02-18 18:06:55 -05:00
|
|
|
if (pointer->grab->interface != &popup_grab_interface)
|
|
|
|
return FALSE;
|
2013-09-10 09:53:31 -04:00
|
|
|
|
2014-02-18 18:06:55 -05:00
|
|
|
grab = (MetaWaylandPopupGrab*)pointer->grab;
|
2013-09-11 08:53:48 -04:00
|
|
|
|
2014-02-18 18:06:55 -05:00
|
|
|
if (wl_resource_get_client (surface->resource) != grab->grab_client)
|
|
|
|
return FALSE;
|
2013-09-11 08:53:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pointer->grab == &pointer->default_grab)
|
|
|
|
{
|
2014-03-10 15:00:59 -04:00
|
|
|
MetaWindow *window = surface->window;
|
|
|
|
|
2013-09-11 08:53:48 -04:00
|
|
|
grab = g_slice_new0 (MetaWaylandPopupGrab);
|
|
|
|
grab->generic.interface = &popup_grab_interface;
|
|
|
|
grab->generic.pointer = pointer;
|
|
|
|
grab->grab_client = wl_resource_get_client (surface->resource);
|
|
|
|
wl_list_init (&grab->all_popups);
|
|
|
|
|
|
|
|
meta_wayland_pointer_start_grab (pointer, (MetaWaylandPointerGrab*)grab);
|
2014-03-10 15:00:59 -04:00
|
|
|
|
|
|
|
meta_display_begin_grab_op (window->display,
|
|
|
|
window->screen,
|
|
|
|
window,
|
2014-04-20 11:37:46 -04:00
|
|
|
META_GRAB_OP_WAYLAND_POPUP,
|
2014-03-10 15:00:59 -04:00
|
|
|
FALSE, /* pointer_already_grabbed */
|
|
|
|
FALSE, /* frame_action */
|
|
|
|
1, /* button. XXX? */
|
|
|
|
0, /* modmask */
|
|
|
|
meta_display_get_current_time_roundtrip (window->display),
|
2014-04-18 10:27:48 -04:00
|
|
|
pointer->grab_x,
|
|
|
|
pointer->grab_y);
|
2013-09-11 08:53:48 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
grab = (MetaWaylandPopupGrab*)pointer->grab;
|
2013-09-10 09:53:31 -04:00
|
|
|
|
2013-09-11 08:53:48 -04:00
|
|
|
popup = g_slice_new0 (MetaWaylandPopup);
|
|
|
|
popup->grab = grab;
|
|
|
|
popup->surface = surface;
|
|
|
|
popup->surface_destroy_listener.notify = on_popup_surface_destroy;
|
2014-02-28 00:18:42 -05:00
|
|
|
if (surface->xdg_popup.resource)
|
|
|
|
wl_resource_add_destroy_listener (surface->xdg_popup.resource, &popup->surface_destroy_listener);
|
|
|
|
else if (surface->wl_shell_surface.resource)
|
|
|
|
wl_resource_add_destroy_listener (surface->wl_shell_surface.resource, &popup->surface_destroy_listener);
|
2013-09-10 09:53:31 -04:00
|
|
|
|
2013-09-11 08:53:48 -04:00
|
|
|
wl_list_insert (&grab->all_popups, &popup->link);
|
2013-09-10 09:53:31 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2013-09-11 08:06:05 -04:00
|
|
|
|
2014-04-17 18:16:49 -04:00
|
|
|
void
|
|
|
|
meta_wayland_pointer_repick (MetaWaylandPointer *pointer)
|
|
|
|
{
|
|
|
|
repick_for_event (pointer, NULL);
|
|
|
|
}
|
|
|
|
|
2013-09-11 08:06:05 -04:00
|
|
|
void
|
|
|
|
meta_wayland_pointer_get_relative_coordinates (MetaWaylandPointer *pointer,
|
|
|
|
MetaWaylandSurface *surface,
|
|
|
|
wl_fixed_t *sx,
|
|
|
|
wl_fixed_t *sy)
|
|
|
|
{
|
|
|
|
float xf = 0.0f, yf = 0.0f;
|
|
|
|
|
2014-04-25 14:38:24 -04:00
|
|
|
ClutterActor *actor = CLUTTER_ACTOR (surface->surface_actor);
|
2013-09-11 08:06:05 -04:00
|
|
|
|
2014-04-25 14:38:24 -04:00
|
|
|
if (actor)
|
|
|
|
{
|
|
|
|
ClutterPoint pos;
|
|
|
|
clutter_input_device_get_coords (pointer->device, NULL, &pos);
|
2014-04-18 10:27:48 -04:00
|
|
|
|
2014-04-25 14:38:24 -04:00
|
|
|
clutter_actor_transform_stage_point (actor, pos.x, pos.y, &xf, &yf);
|
2013-09-11 08:06:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
*sx = wl_fixed_from_double (xf);
|
|
|
|
*sy = wl_fixed_from_double (yf);
|
|
|
|
}
|
2014-03-16 15:32:52 -04:00
|
|
|
|
2014-04-17 16:54:30 -04:00
|
|
|
void
|
|
|
|
meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer)
|
|
|
|
{
|
|
|
|
MetaCursorReference *cursor;
|
|
|
|
|
|
|
|
if (pointer->cursor_tracker == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (pointer->cursor_surface && pointer->cursor_surface->buffer)
|
|
|
|
{
|
|
|
|
struct wl_resource *buffer = pointer->cursor_surface->buffer->resource;
|
2014-04-23 10:38:30 -04:00
|
|
|
cursor = meta_cursor_reference_from_buffer (buffer,
|
2014-04-17 16:54:30 -04:00
|
|
|
pointer->hotspot_x,
|
|
|
|
pointer->hotspot_y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cursor = NULL;
|
|
|
|
|
|
|
|
meta_cursor_tracker_set_window_cursor (pointer->cursor_tracker, cursor);
|
|
|
|
|
|
|
|
if (cursor)
|
|
|
|
meta_cursor_reference_unref (cursor);
|
|
|
|
}
|
2014-04-17 17:00:59 -04:00
|
|
|
|
2014-04-17 17:16:17 -04:00
|
|
|
static void
|
2014-04-17 18:16:49 -04:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
MetaWaylandPointer *pointer = wl_resource_get_user_data (resource);
|
|
|
|
MetaWaylandSurface *surface;
|
|
|
|
|
|
|
|
surface = (surface_resource ? wl_resource_get_user_data (surface_resource) : NULL);
|
|
|
|
|
|
|
|
if (pointer->focus_surface == NULL)
|
|
|
|
return;
|
|
|
|
if (wl_resource_get_client (pointer->focus_surface->resource) != client)
|
|
|
|
return;
|
|
|
|
if (pointer->focus_serial - serial > G_MAXUINT32 / 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pointer->hotspot_x = x;
|
|
|
|
pointer->hotspot_y = y;
|
|
|
|
set_cursor_surface (pointer, surface);
|
|
|
|
meta_wayland_pointer_update_cursor_surface (pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-04-17 17:16:17 -04:00
|
|
|
pointer_release (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy (resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_pointer_interface pointer_interface = {
|
|
|
|
pointer_set_cursor,
|
|
|
|
pointer_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_pointer_create_new_resource (MetaWaylandPointer *pointer,
|
|
|
|
struct wl_client *client,
|
|
|
|
struct wl_resource *seat_resource,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
|
|
|
struct wl_resource *cr;
|
|
|
|
|
|
|
|
cr = wl_resource_create (client, &wl_pointer_interface,
|
|
|
|
MIN (META_WL_POINTER_VERSION, wl_resource_get_version (seat_resource)), id);
|
|
|
|
wl_resource_set_implementation (cr, &pointer_interface, pointer, unbind_resource);
|
|
|
|
wl_list_insert (&pointer->resource_list, wl_resource_get_link (cr));
|
|
|
|
|
|
|
|
if (pointer->focus_surface && wl_resource_get_client (pointer->focus_surface->resource) == client)
|
|
|
|
meta_wayland_pointer_set_focus (pointer, pointer->focus_surface);
|
2014-04-17 17:00:59 -04:00
|
|
|
}
|