2013-05-03 17:51:22 +00:00
|
|
|
/*
|
|
|
|
* Wayland Support
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Intel Corporation
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "meta-wayland-seat.h"
|
2014-04-22 21:58:01 +00:00
|
|
|
|
2014-04-22 22:05:44 +00:00
|
|
|
#include "meta-wayland-private.h"
|
2014-04-22 21:58:01 +00:00
|
|
|
#include "meta-wayland-versions.h"
|
2014-07-10 14:13:54 +00:00
|
|
|
#include "meta-wayland-data-device.h"
|
2013-05-03 17:51:22 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
unbind_resource (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_list_remove (wl_resource_get_link (resource));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
seat_get_pointer (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
|
|
|
MetaWaylandSeat *seat = wl_resource_get_user_data (resource);
|
2014-04-17 20:41:37 +00:00
|
|
|
MetaWaylandPointer *pointer = &seat->pointer;
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2014-04-17 21:16:17 +00:00
|
|
|
meta_wayland_pointer_create_new_resource (pointer, client, resource, id);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
seat_get_keyboard (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
|
|
|
MetaWaylandSeat *seat = wl_resource_get_user_data (resource);
|
2014-04-17 20:41:37 +00:00
|
|
|
MetaWaylandKeyboard *keyboard = &seat->keyboard;
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2014-04-17 22:22:26 +00:00
|
|
|
meta_wayland_keyboard_create_new_resource (keyboard, client, resource, id);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
seat_get_touch (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
2014-04-24 12:50:47 +00:00
|
|
|
MetaWaylandSeat *seat = wl_resource_get_user_data (resource);
|
|
|
|
MetaWaylandTouch *touch = &seat->touch;
|
|
|
|
|
|
|
|
meta_wayland_touch_create_new_resource (touch, client, resource, id);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2014-04-17 20:36:45 +00:00
|
|
|
static const struct wl_seat_interface seat_interface = {
|
|
|
|
seat_get_pointer,
|
|
|
|
seat_get_keyboard,
|
|
|
|
seat_get_touch
|
|
|
|
};
|
2013-05-03 17:51:22 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
bind_seat (struct wl_client *client,
|
|
|
|
void *data,
|
|
|
|
guint32 version,
|
|
|
|
guint32 id)
|
|
|
|
{
|
|
|
|
MetaWaylandSeat *seat = data;
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
2013-09-10 11:45:27 +00:00
|
|
|
resource = wl_resource_create (client, &wl_seat_interface,
|
|
|
|
MIN (META_WL_SEAT_VERSION, version), id);
|
2013-09-10 11:03:37 +00:00
|
|
|
wl_resource_set_implementation (resource, &seat_interface, seat, unbind_resource);
|
2013-05-03 17:51:22 +00:00
|
|
|
wl_list_insert (&seat->base_resource_list, wl_resource_get_link (resource));
|
|
|
|
|
|
|
|
wl_seat_send_capabilities (resource,
|
|
|
|
WL_SEAT_CAPABILITY_POINTER |
|
2014-04-24 12:50:47 +00:00
|
|
|
WL_SEAT_CAPABILITY_KEYBOARD |
|
|
|
|
WL_SEAT_CAPABILITY_TOUCH);
|
2013-09-10 11:03:37 +00:00
|
|
|
|
2014-05-12 21:00:49 +00:00
|
|
|
if (version >= WL_SEAT_NAME_SINCE_VERSION)
|
2013-09-10 11:03:37 +00:00
|
|
|
wl_seat_send_name (resource, "seat0");
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 22:05:44 +00:00
|
|
|
static MetaWaylandSeat *
|
2014-02-18 01:49:04 +00:00
|
|
|
meta_wayland_seat_new (struct wl_display *display)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
|
|
|
MetaWaylandSeat *seat = g_new0 (MetaWaylandSeat, 1);
|
|
|
|
|
|
|
|
wl_list_init (&seat->base_resource_list);
|
|
|
|
|
2014-04-17 22:12:23 +00:00
|
|
|
meta_wayland_pointer_init (&seat->pointer, display);
|
2014-02-18 01:49:04 +00:00
|
|
|
meta_wayland_keyboard_init (&seat->keyboard, display);
|
2014-04-24 12:50:47 +00:00
|
|
|
meta_wayland_touch_init (&seat->touch, display);
|
2014-07-10 14:31:08 +00:00
|
|
|
meta_wayland_data_device_init (&seat->data_device);
|
2013-05-03 17:51:22 +00:00
|
|
|
|
2013-09-10 11:45:27 +00:00
|
|
|
wl_global_create (display, &wl_seat_interface, META_WL_SEAT_VERSION, seat, bind_seat);
|
2013-05-03 17:51:22 +00:00
|
|
|
|
|
|
|
return seat;
|
|
|
|
}
|
|
|
|
|
2014-04-22 22:05:44 +00:00
|
|
|
void
|
|
|
|
meta_wayland_seat_init (MetaWaylandCompositor *compositor)
|
|
|
|
{
|
|
|
|
compositor->seat = meta_wayland_seat_new (compositor->wayland_display);
|
|
|
|
}
|
|
|
|
|
2014-04-17 22:57:25 +00:00
|
|
|
void
|
|
|
|
meta_wayland_seat_free (MetaWaylandSeat *seat)
|
|
|
|
{
|
|
|
|
meta_wayland_pointer_release (&seat->pointer);
|
|
|
|
meta_wayland_keyboard_release (&seat->keyboard);
|
2014-04-24 12:50:47 +00:00
|
|
|
meta_wayland_touch_release (&seat->touch);
|
2014-04-17 22:57:25 +00:00
|
|
|
|
|
|
|
g_slice_free (MetaWaylandSeat, seat);
|
|
|
|
}
|
|
|
|
|
2014-04-17 23:07:43 +00:00
|
|
|
void
|
|
|
|
meta_wayland_seat_update (MetaWaylandSeat *seat,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case CLUTTER_MOTION:
|
|
|
|
case CLUTTER_BUTTON_PRESS:
|
|
|
|
case CLUTTER_BUTTON_RELEASE:
|
|
|
|
case CLUTTER_SCROLL:
|
2014-04-17 21:52:11 +00:00
|
|
|
meta_wayland_pointer_update (&seat->pointer, event);
|
2014-04-17 23:07:43 +00:00
|
|
|
break;
|
2014-04-17 21:52:11 +00:00
|
|
|
|
2014-04-17 23:07:43 +00:00
|
|
|
case CLUTTER_KEY_PRESS:
|
|
|
|
case CLUTTER_KEY_RELEASE:
|
|
|
|
meta_wayland_keyboard_update (&seat->keyboard, (const ClutterKeyEvent *) event);
|
|
|
|
break;
|
2014-04-17 21:52:11 +00:00
|
|
|
|
2014-04-24 12:50:47 +00:00
|
|
|
case CLUTTER_TOUCH_BEGIN:
|
|
|
|
case CLUTTER_TOUCH_UPDATE:
|
|
|
|
case CLUTTER_TOUCH_END:
|
|
|
|
meta_wayland_touch_update (&seat->touch, event);
|
|
|
|
break;
|
|
|
|
|
2014-04-17 23:07:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-13 20:41:29 +00:00
|
|
|
gboolean
|
|
|
|
meta_wayland_seat_handle_event (MetaWaylandSeat *seat,
|
|
|
|
const ClutterEvent *event)
|
|
|
|
{
|
2013-05-03 17:51:22 +00:00
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case CLUTTER_MOTION:
|
|
|
|
case CLUTTER_BUTTON_PRESS:
|
|
|
|
case CLUTTER_BUTTON_RELEASE:
|
2014-04-17 23:10:39 +00:00
|
|
|
case CLUTTER_SCROLL:
|
2014-04-17 22:16:49 +00:00
|
|
|
return meta_wayland_pointer_handle_event (&seat->pointer, event);
|
2014-04-17 23:10:39 +00:00
|
|
|
|
2013-05-03 17:51:22 +00:00
|
|
|
case CLUTTER_KEY_PRESS:
|
|
|
|
case CLUTTER_KEY_RELEASE:
|
2013-09-04 13:01:11 +00:00
|
|
|
return meta_wayland_keyboard_handle_event (&seat->keyboard,
|
|
|
|
(const ClutterKeyEvent *) event);
|
2014-04-24 12:50:47 +00:00
|
|
|
case CLUTTER_TOUCH_BEGIN:
|
|
|
|
case CLUTTER_TOUCH_UPDATE:
|
|
|
|
case CLUTTER_TOUCH_END:
|
|
|
|
return meta_wayland_touch_handle_event (&seat->touch, event);
|
2013-05-03 17:51:22 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-09-04 13:01:11 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-17 22:46:14 +00:00
|
|
|
meta_wayland_seat_repick (MetaWaylandSeat *seat)
|
2013-05-03 17:51:22 +00:00
|
|
|
{
|
2014-04-17 22:16:49 +00:00
|
|
|
meta_wayland_pointer_repick (&seat->pointer);
|
2013-05-03 17:51:22 +00:00
|
|
|
}
|
2014-04-17 23:14:17 +00:00
|
|
|
|
2014-07-10 14:13:54 +00:00
|
|
|
void
|
|
|
|
meta_wayland_seat_set_input_focus (MetaWaylandSeat *seat,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
meta_wayland_keyboard_set_focus (&seat->keyboard, surface);
|
2014-07-10 14:31:08 +00:00
|
|
|
meta_wayland_data_device_set_keyboard_focus (&seat->data_device);
|
2014-07-10 14:13:54 +00:00
|
|
|
}
|
|
|
|
|
2014-04-17 23:14:17 +00:00
|
|
|
void
|
|
|
|
meta_wayland_seat_update_cursor_surface (MetaWaylandSeat *seat)
|
|
|
|
{
|
|
|
|
meta_wayland_pointer_update_cursor_surface (&seat->pointer);
|
|
|
|
}
|
2014-05-22 14:57:02 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_wayland_seat_can_grab_surface (MetaWaylandSeat *seat,
|
|
|
|
MetaWaylandSurface *surface,
|
|
|
|
uint32_t serial)
|
|
|
|
{
|
|
|
|
return meta_wayland_pointer_can_grab_surface (&seat->pointer, surface, serial);
|
|
|
|
}
|