mirror of
https://github.com/brl/mutter.git
synced 2025-02-09 01:54:10 +00:00
![Robert Bragg](/assets/img/avatar_default.png)
This updates Wayland support in line with upstream changes to the Wayland API and protocol. This update means we no longer use the Cogl stub winsys so a lot of code that had to manually interact with EGL and implement a swap_buffers mechanism could be removed and instead we now depend on Cogl to handle those things for us. This update also adds an input device manager consistent with other clutter backends. Note: to use the client side "wayland" clutter backend you need to have built Cogl with --enable-wayland-egl-platform. If Cogl has been built with support for multiple winsys backends then you should run applications with COGL_RENDERER=EGL in the environment. Reviewed-by: Emmanuele Bassi <ebassi@linux.intel.com>
227 lines
7.3 KiB
C
227 lines
7.3 KiB
C
/*
|
|
* Clutter.
|
|
*
|
|
* An OpenGL based 'interactive canvas' library.
|
|
*
|
|
* Copyright (C) 2011 Intel Corp.
|
|
*
|
|
* 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/>.
|
|
*
|
|
* Authors:
|
|
* Emmanuele Bassi <ebassi@linux.intel.com>
|
|
* Robert Bragg <robert@linux.intel.com>
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include "clutter-input-device-wayland.h"
|
|
#include "clutter-device-manager-wayland.h"
|
|
|
|
#include "clutter-backend.h"
|
|
#include "wayland/clutter-backend-wayland.h"
|
|
#include "clutter-debug.h"
|
|
#include "clutter-device-manager-private.h"
|
|
#include "clutter-private.h"
|
|
|
|
#include "evdev/clutter-xkb-utils.h"
|
|
|
|
#include <wayland-client.h>
|
|
|
|
enum
|
|
{
|
|
PROP_0
|
|
};
|
|
|
|
G_DEFINE_TYPE (ClutterDeviceManagerWayland,
|
|
_clutter_device_manager_wayland,
|
|
CLUTTER_TYPE_DEVICE_MANAGER);
|
|
|
|
static void
|
|
clutter_device_manager_wayland_add_device (ClutterDeviceManager *manager,
|
|
ClutterInputDevice *device)
|
|
{
|
|
ClutterDeviceManagerWayland *manager_wayland =
|
|
CLUTTER_DEVICE_MANAGER_WAYLAND (manager);
|
|
ClutterInputDeviceType device_type;
|
|
gboolean is_pointer, is_keyboard;
|
|
|
|
device_type = clutter_input_device_get_device_type (device);
|
|
is_pointer = (device_type == CLUTTER_POINTER_DEVICE) ? TRUE : FALSE;
|
|
is_keyboard = (device_type == CLUTTER_KEYBOARD_DEVICE) ? TRUE : FALSE;
|
|
|
|
manager_wayland->devices = g_slist_prepend (manager_wayland->devices, device);
|
|
|
|
if (is_pointer && manager_wayland->core_pointer == NULL)
|
|
manager_wayland->core_pointer = device;
|
|
|
|
if (is_keyboard && manager_wayland->core_keyboard == NULL)
|
|
manager_wayland->core_keyboard = device;
|
|
}
|
|
|
|
static void
|
|
clutter_device_manager_wayland_remove_device (ClutterDeviceManager *manager,
|
|
ClutterInputDevice *device)
|
|
{
|
|
ClutterDeviceManagerWayland *manager_wayland = CLUTTER_DEVICE_MANAGER_WAYLAND (manager);
|
|
|
|
manager_wayland->devices = g_slist_remove (manager_wayland->devices, device);
|
|
}
|
|
|
|
static const GSList *
|
|
clutter_device_manager_wayland_get_devices (ClutterDeviceManager *manager)
|
|
{
|
|
return CLUTTER_DEVICE_MANAGER_WAYLAND (manager)->devices;
|
|
}
|
|
|
|
static ClutterInputDevice *
|
|
clutter_device_manager_wayland_get_core_device (ClutterDeviceManager *manager,
|
|
ClutterInputDeviceType type)
|
|
{
|
|
ClutterDeviceManagerWayland *manager_wayland;
|
|
|
|
manager_wayland = CLUTTER_DEVICE_MANAGER_WAYLAND (manager);
|
|
|
|
switch (type)
|
|
{
|
|
case CLUTTER_POINTER_DEVICE:
|
|
return manager_wayland->core_pointer;
|
|
|
|
case CLUTTER_KEYBOARD_DEVICE:
|
|
return manager_wayland->core_keyboard;
|
|
|
|
case CLUTTER_EXTENSION_DEVICE:
|
|
default:
|
|
return NULL;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static ClutterInputDevice *
|
|
clutter_device_manager_wayland_get_device (ClutterDeviceManager *manager,
|
|
gint id)
|
|
{
|
|
ClutterDeviceManagerWayland *manager_wayland =
|
|
CLUTTER_DEVICE_MANAGER_WAYLAND (manager);
|
|
GSList *l;
|
|
|
|
for (l = manager_wayland->devices; l != NULL; l = l->next)
|
|
{
|
|
ClutterInputDevice *device = l->data;
|
|
|
|
if (clutter_input_device_get_device_id (device) == id)
|
|
return device;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static void
|
|
_clutter_device_manager_wayland_class_init (ClutterDeviceManagerWaylandClass *klass)
|
|
{
|
|
ClutterDeviceManagerClass *manager_class;
|
|
|
|
manager_class = CLUTTER_DEVICE_MANAGER_CLASS (klass);
|
|
manager_class->add_device = clutter_device_manager_wayland_add_device;
|
|
manager_class->remove_device = clutter_device_manager_wayland_remove_device;
|
|
manager_class->get_devices = clutter_device_manager_wayland_get_devices;
|
|
manager_class->get_core_device = clutter_device_manager_wayland_get_core_device;
|
|
manager_class->get_device = clutter_device_manager_wayland_get_device;
|
|
}
|
|
|
|
static void
|
|
_clutter_device_manager_wayland_init (ClutterDeviceManagerWayland *self)
|
|
{
|
|
}
|
|
|
|
const char *option_xkb_layout = "us";
|
|
const char *option_xkb_variant = "";
|
|
const char *option_xkb_options = "";
|
|
|
|
void
|
|
_clutter_device_manager_wayland_add_input_group (ClutterDeviceManager *manager,
|
|
uint32_t id)
|
|
{
|
|
ClutterBackend *backend = _clutter_device_manager_get_backend (manager);
|
|
ClutterBackendWayland *backend_wayland = CLUTTER_BACKEND_WAYLAND (backend);
|
|
ClutterInputDeviceWayland *device;
|
|
|
|
device = g_object_new (CLUTTER_TYPE_INPUT_DEVICE_WAYLAND,
|
|
"id", id,
|
|
"device-type", CLUTTER_POINTER_DEVICE,
|
|
"name", "wayland device",
|
|
"enabled", TRUE,
|
|
NULL);
|
|
|
|
device->input_device =
|
|
wl_display_bind (backend_wayland->wayland_display, id,
|
|
&wl_input_device_interface);
|
|
wl_input_device_add_listener (device->input_device,
|
|
&_clutter_input_device_wayland_listener,
|
|
device);
|
|
wl_input_device_set_user_data (device->input_device, device);
|
|
|
|
device->xkb = _clutter_xkb_desc_new (NULL,
|
|
option_xkb_layout,
|
|
option_xkb_variant,
|
|
option_xkb_options);
|
|
if (!device->xkb)
|
|
CLUTTER_NOTE (BACKEND, "Failed to compile keymap");
|
|
|
|
_clutter_device_manager_add_device (manager, CLUTTER_INPUT_DEVICE (device));
|
|
}
|
|
|
|
ClutterDeviceManager *
|
|
_clutter_device_manager_wayland_new (ClutterBackend *backend)
|
|
{
|
|
return g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_WAYLAND,
|
|
"backend", backend,
|
|
NULL);
|
|
}
|
|
|
|
void
|
|
_clutter_events_wayland_init (ClutterBackend *backend)
|
|
{
|
|
ClutterBackendWayland *backend_wayland = CLUTTER_BACKEND_WAYLAND (backend);
|
|
|
|
/* XXX: We actually create the wayland device manager in the backend
|
|
* post_parse vfunc because that's the point where we connect to a compositor
|
|
* and that's also the point where we will be notified of input devices so we
|
|
* need the device-manager to exist early on.
|
|
*
|
|
* To be consistent with other clutter backends though we only associate the
|
|
* device manager with the backend when _clutter_events_wayland_init() is
|
|
* called in _clutter_backend_init_events(). This should still allow the
|
|
* runtime selection of an alternative input backend if desired and in that
|
|
* case the wayland device manager will be benign.
|
|
*
|
|
* FIXME: At some point we could perhaps collapse the
|
|
* _clutter_backend_post_parse(), and _clutter_backend_init_events()
|
|
* functions into one called something like _clutter_backend_init() which
|
|
* would allow the real backend to manage the precise order of
|
|
* initialization.
|
|
*/
|
|
|
|
backend->device_manager = g_object_ref (backend_wayland->device_manager);
|
|
}
|
|
|
|
void
|
|
_clutter_events_wayland_uninit (ClutterBackend *backend)
|
|
{
|
|
g_object_unref (backend->device_manager);
|
|
backend->device_manager = NULL;
|
|
}
|