2014-03-31 23:00:07 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Red Hat
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Written by:
|
|
|
|
* Jasper St. Pierre <jstpierre@mecheye.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2015-11-06 23:10:41 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2016-05-04 04:19:23 -04:00
|
|
|
#include <clutter/clutter-mutter.h>
|
2014-08-05 08:11:59 -04:00
|
|
|
#include <meta/meta-backend.h>
|
2016-07-22 22:26:39 -04:00
|
|
|
#include <meta/main.h>
|
2014-04-21 19:03:22 -04:00
|
|
|
#include "meta-backend-private.h"
|
2014-10-29 10:30:52 -04:00
|
|
|
#include "meta-input-settings-private.h"
|
2014-03-31 23:00:07 -04:00
|
|
|
|
2014-04-21 19:13:04 -04:00
|
|
|
#include "backends/x11/meta-backend-x11.h"
|
2015-02-11 08:59:21 -05:00
|
|
|
#include "meta-cursor-tracker-private.h"
|
2014-08-13 19:46:32 -04:00
|
|
|
#include "meta-stage.h"
|
2014-05-29 12:11:26 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
2014-04-21 19:13:04 -04:00
|
|
|
#include "backends/native/meta-backend-native.h"
|
2014-05-29 12:11:26 -04:00
|
|
|
#endif
|
2014-04-21 19:13:04 -04:00
|
|
|
|
2014-12-29 21:57:09 -05:00
|
|
|
#include "backends/meta-idle-monitor-private.h"
|
|
|
|
|
2015-02-16 22:37:43 -05:00
|
|
|
#include "backends/meta-monitor-manager-dummy.h"
|
|
|
|
|
2014-04-21 19:03:22 -04:00
|
|
|
static MetaBackend *_backend;
|
|
|
|
|
2014-08-05 08:11:59 -04:00
|
|
|
/**
|
|
|
|
* meta_get_backend:
|
|
|
|
*
|
|
|
|
* Accessor for the singleton MetaBackend.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The only #MetaBackend there is.
|
|
|
|
*/
|
2014-04-21 19:03:22 -04:00
|
|
|
MetaBackend *
|
|
|
|
meta_get_backend (void)
|
|
|
|
{
|
|
|
|
return _backend;
|
|
|
|
}
|
|
|
|
|
2014-04-21 19:41:11 -04:00
|
|
|
struct _MetaBackendPrivate
|
|
|
|
{
|
|
|
|
MetaMonitorManager *monitor_manager;
|
2014-04-22 14:32:55 -04:00
|
|
|
MetaCursorRenderer *cursor_renderer;
|
2014-10-29 10:30:52 -04:00
|
|
|
MetaInputSettings *input_settings;
|
2016-05-07 11:07:46 -04:00
|
|
|
MetaRenderer *renderer;
|
2014-08-13 19:46:32 -04:00
|
|
|
|
2016-05-04 04:19:23 -04:00
|
|
|
ClutterBackend *clutter_backend;
|
2014-08-13 19:46:32 -04:00
|
|
|
ClutterActor *stage;
|
2016-02-25 18:45:50 -05:00
|
|
|
|
|
|
|
guint device_update_idle_id;
|
2014-04-21 19:41:11 -04:00
|
|
|
};
|
|
|
|
typedef struct _MetaBackendPrivate MetaBackendPrivate;
|
|
|
|
|
2016-07-22 22:26:39 -04:00
|
|
|
static void
|
|
|
|
initable_iface_init (GInitableIface *initable_iface);
|
|
|
|
|
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (MetaBackend, meta_backend, G_TYPE_OBJECT,
|
|
|
|
G_ADD_PRIVATE (MetaBackend)
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
|
|
|
|
initable_iface_init));
|
2014-04-21 19:41:11 -04:00
|
|
|
|
2014-04-21 19:03:22 -04:00
|
|
|
static void
|
|
|
|
meta_backend_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaBackend *backend = META_BACKEND (object);
|
2014-04-21 19:41:11 -04:00
|
|
|
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
2014-04-21 19:03:22 -04:00
|
|
|
|
2014-04-21 19:41:11 -04:00
|
|
|
g_clear_object (&priv->monitor_manager);
|
2014-10-29 10:30:52 -04:00
|
|
|
g_clear_object (&priv->input_settings);
|
2014-04-21 19:41:11 -04:00
|
|
|
|
2016-02-25 18:45:50 -05:00
|
|
|
if (priv->device_update_idle_id)
|
|
|
|
g_source_remove (priv->device_update_idle_id);
|
|
|
|
|
2014-12-29 21:57:09 -05:00
|
|
|
g_hash_table_destroy (backend->device_monitors);
|
2014-04-21 19:03:22 -04:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_backend_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2014-08-13 19:46:32 -04:00
|
|
|
static void
|
|
|
|
meta_backend_sync_screen_size (MetaBackend *backend)
|
|
|
|
{
|
|
|
|
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
meta_monitor_manager_get_screen_size (priv->monitor_manager, &width, &height);
|
|
|
|
|
|
|
|
META_BACKEND_GET_CLASS (backend)->update_screen_size (backend, width, height);
|
|
|
|
}
|
|
|
|
|
2015-03-27 10:50:59 -04:00
|
|
|
static void
|
|
|
|
center_pointer (MetaBackend *backend)
|
|
|
|
{
|
|
|
|
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
|
|
|
MetaMonitorInfo *monitors, *primary;
|
|
|
|
guint n_monitors;
|
|
|
|
|
|
|
|
monitors = meta_monitor_manager_get_monitor_infos (priv->monitor_manager, &n_monitors);
|
|
|
|
primary = &monitors[meta_monitor_manager_get_primary_index (priv->monitor_manager)];
|
|
|
|
meta_backend_warp_pointer (backend,
|
|
|
|
primary->rect.x + primary->rect.width / 2,
|
|
|
|
primary->rect.y + primary->rect.height / 2);
|
|
|
|
}
|
|
|
|
|
2016-07-06 03:27:45 -04:00
|
|
|
void
|
|
|
|
meta_backend_monitors_changed (MetaBackend *backend)
|
2014-08-13 19:46:32 -04:00
|
|
|
{
|
2016-07-06 03:27:45 -04:00
|
|
|
MetaMonitorManager *monitor_manager =
|
|
|
|
meta_backend_get_monitor_manager (backend);
|
2015-03-27 10:50:59 -04:00
|
|
|
ClutterDeviceManager *manager = clutter_device_manager_get_default ();
|
|
|
|
ClutterInputDevice *device = clutter_device_manager_get_core_device (manager, CLUTTER_POINTER_DEVICE);
|
|
|
|
ClutterPoint point;
|
|
|
|
|
2014-08-13 19:46:32 -04:00
|
|
|
meta_backend_sync_screen_size (backend);
|
2015-03-27 10:50:59 -04:00
|
|
|
|
|
|
|
if (clutter_input_device_get_coords (device, NULL, &point))
|
|
|
|
{
|
|
|
|
/* If we're outside all monitors, warp the pointer back inside */
|
2016-07-06 03:27:45 -04:00
|
|
|
if (meta_monitor_manager_get_monitor_at_point (monitor_manager,
|
|
|
|
point.x, point.y) < 0)
|
2015-03-27 10:50:59 -04:00
|
|
|
center_pointer (backend);
|
|
|
|
}
|
2014-08-13 19:46:32 -04:00
|
|
|
}
|
|
|
|
|
2014-09-04 15:15:50 -04:00
|
|
|
static MetaIdleMonitor *
|
|
|
|
meta_backend_create_idle_monitor (MetaBackend *backend,
|
|
|
|
int device_id)
|
|
|
|
{
|
|
|
|
return META_BACKEND_GET_CLASS (backend)->create_idle_monitor (backend, device_id);
|
|
|
|
}
|
|
|
|
|
2014-09-04 15:06:03 -04:00
|
|
|
static void
|
|
|
|
create_device_monitor (MetaBackend *backend,
|
|
|
|
int device_id)
|
|
|
|
{
|
2014-12-29 21:57:09 -05:00
|
|
|
MetaIdleMonitor *idle_monitor;
|
|
|
|
|
|
|
|
g_assert (g_hash_table_lookup (backend->device_monitors, &device_id) == NULL);
|
2014-09-04 15:06:03 -04:00
|
|
|
|
2014-12-29 21:57:09 -05:00
|
|
|
idle_monitor = meta_backend_create_idle_monitor (backend, device_id);
|
|
|
|
g_hash_table_insert (backend->device_monitors, &idle_monitor->device_id, idle_monitor);
|
2014-09-04 15:06:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_device_monitor (MetaBackend *backend,
|
|
|
|
int device_id)
|
|
|
|
{
|
2014-12-29 21:57:09 -05:00
|
|
|
g_hash_table_remove (backend->device_monitors, &device_id);
|
2014-09-04 15:06:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_device_added (ClutterDeviceManager *device_manager,
|
|
|
|
ClutterInputDevice *device,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaBackend *backend = META_BACKEND (user_data);
|
|
|
|
int device_id = clutter_input_device_get_device_id (device);
|
|
|
|
|
2014-09-04 15:15:50 -04:00
|
|
|
create_device_monitor (backend, device_id);
|
2014-09-04 15:06:03 -04:00
|
|
|
}
|
|
|
|
|
2015-02-11 11:04:13 -05:00
|
|
|
static inline gboolean
|
|
|
|
device_is_slave_touchscreen (ClutterInputDevice *device)
|
|
|
|
{
|
|
|
|
return (clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_MASTER &&
|
|
|
|
clutter_input_device_get_device_type (device) == CLUTTER_TOUCHSCREEN_DEVICE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gboolean
|
|
|
|
check_has_pointing_device (ClutterDeviceManager *manager)
|
|
|
|
{
|
|
|
|
const GSList *devices;
|
|
|
|
|
|
|
|
devices = clutter_device_manager_peek_devices (manager);
|
|
|
|
|
|
|
|
for (; devices; devices = devices->next)
|
|
|
|
{
|
|
|
|
ClutterInputDevice *device = devices->data;
|
|
|
|
|
|
|
|
if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_MASTER)
|
|
|
|
continue;
|
|
|
|
if (clutter_input_device_get_device_type (device) == CLUTTER_TOUCHSCREEN_DEVICE ||
|
|
|
|
clutter_input_device_get_device_type (device) == CLUTTER_KEYBOARD_DEVICE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gboolean
|
|
|
|
check_has_slave_touchscreen (ClutterDeviceManager *manager)
|
|
|
|
{
|
|
|
|
const GSList *devices;
|
|
|
|
|
|
|
|
devices = clutter_device_manager_peek_devices (manager);
|
|
|
|
|
|
|
|
for (; devices; devices = devices->next)
|
|
|
|
{
|
|
|
|
ClutterInputDevice *device = devices->data;
|
|
|
|
|
|
|
|
if (clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_MASTER &&
|
|
|
|
clutter_input_device_get_device_type (device) == CLUTTER_TOUCHSCREEN_DEVICE)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-09-04 15:06:03 -04:00
|
|
|
static void
|
|
|
|
on_device_removed (ClutterDeviceManager *device_manager,
|
|
|
|
ClutterInputDevice *device,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaBackend *backend = META_BACKEND (user_data);
|
|
|
|
int device_id = clutter_input_device_get_device_id (device);
|
|
|
|
|
2014-09-04 15:15:50 -04:00
|
|
|
destroy_device_monitor (backend, device_id);
|
2015-02-11 11:04:13 -05:00
|
|
|
|
|
|
|
/* If the device the user last interacted goes away, check again pointer
|
|
|
|
* visibility.
|
|
|
|
*/
|
|
|
|
if (backend->current_device_id == device_id)
|
|
|
|
{
|
|
|
|
MetaCursorTracker *cursor_tracker = meta_cursor_tracker_get_for_screen (NULL);
|
|
|
|
gboolean has_touchscreen, has_pointing_device;
|
|
|
|
ClutterInputDeviceType device_type;
|
|
|
|
|
|
|
|
device_type = clutter_input_device_get_device_type (device);
|
|
|
|
has_touchscreen = check_has_slave_touchscreen (device_manager);
|
|
|
|
|
|
|
|
if (device_type == CLUTTER_TOUCHSCREEN_DEVICE && has_touchscreen)
|
|
|
|
{
|
|
|
|
/* There's more touchscreens left, keep the pointer hidden */
|
|
|
|
meta_cursor_tracker_set_pointer_visible (cursor_tracker, FALSE);
|
|
|
|
}
|
|
|
|
else if (device_type != CLUTTER_KEYBOARD_DEVICE)
|
|
|
|
{
|
|
|
|
has_pointing_device = check_has_pointing_device (device_manager);
|
|
|
|
meta_cursor_tracker_set_pointer_visible (cursor_tracker,
|
|
|
|
has_pointing_device &&
|
|
|
|
!has_touchscreen);
|
|
|
|
}
|
|
|
|
}
|
2014-09-04 15:06:03 -04:00
|
|
|
}
|
|
|
|
|
2015-02-16 22:37:43 -05:00
|
|
|
static MetaMonitorManager *
|
|
|
|
create_monitor_manager (MetaBackend *backend)
|
|
|
|
{
|
|
|
|
if (g_getenv ("META_DUMMY_MONITORS"))
|
|
|
|
return g_object_new (META_TYPE_MONITOR_MANAGER_DUMMY, NULL);
|
|
|
|
|
|
|
|
return META_BACKEND_GET_CLASS (backend)->create_monitor_manager (backend);
|
|
|
|
}
|
|
|
|
|
2014-04-22 10:14:59 -04:00
|
|
|
static void
|
|
|
|
meta_backend_real_post_init (MetaBackend *backend)
|
|
|
|
{
|
2014-04-22 14:32:55 -04:00
|
|
|
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
|
|
|
|
2014-08-13 19:46:32 -04:00
|
|
|
priv->stage = meta_stage_new ();
|
|
|
|
clutter_actor_realize (priv->stage);
|
|
|
|
META_BACKEND_GET_CLASS (backend)->select_stage_events (backend);
|
|
|
|
|
2015-02-16 22:37:43 -05:00
|
|
|
priv->monitor_manager = create_monitor_manager (backend);
|
2014-08-13 19:46:32 -04:00
|
|
|
|
|
|
|
meta_backend_sync_screen_size (backend);
|
|
|
|
|
2014-05-15 14:13:39 -04:00
|
|
|
priv->cursor_renderer = META_BACKEND_GET_CLASS (backend)->create_cursor_renderer (backend);
|
2014-09-04 15:06:03 -04:00
|
|
|
|
2014-12-29 21:57:09 -05:00
|
|
|
backend->device_monitors = g_hash_table_new_full (g_int_hash, g_int_equal,
|
|
|
|
NULL, (GDestroyNotify) g_object_unref);
|
|
|
|
|
2014-09-04 15:06:03 -04:00
|
|
|
{
|
2015-02-11 11:04:13 -05:00
|
|
|
MetaCursorTracker *cursor_tracker;
|
2014-09-04 15:06:03 -04:00
|
|
|
ClutterDeviceManager *manager;
|
2015-02-11 11:04:13 -05:00
|
|
|
gboolean has_touchscreen = FALSE;
|
2014-09-04 15:06:03 -04:00
|
|
|
GSList *devices, *l;
|
|
|
|
|
2014-09-04 16:15:03 -04:00
|
|
|
/* Create the core device monitor. */
|
2014-09-04 16:15:03 -04:00
|
|
|
create_device_monitor (backend, 0);
|
2014-09-04 16:15:03 -04:00
|
|
|
|
2014-09-04 15:06:03 -04:00
|
|
|
manager = clutter_device_manager_get_default ();
|
|
|
|
g_signal_connect_object (manager, "device-added",
|
|
|
|
G_CALLBACK (on_device_added), backend, 0);
|
|
|
|
g_signal_connect_object (manager, "device-removed",
|
|
|
|
G_CALLBACK (on_device_removed), backend, 0);
|
|
|
|
|
2014-09-04 15:15:50 -04:00
|
|
|
devices = clutter_device_manager_list_devices (manager);
|
2014-09-04 15:06:03 -04:00
|
|
|
|
|
|
|
for (l = devices; l != NULL; l = l->next)
|
|
|
|
{
|
2014-09-04 15:15:50 -04:00
|
|
|
ClutterInputDevice *device = l->data;
|
2014-09-04 15:06:03 -04:00
|
|
|
on_device_added (manager, device, backend);
|
2015-02-11 11:04:13 -05:00
|
|
|
has_touchscreen |= device_is_slave_touchscreen (device);
|
2014-09-04 15:06:03 -04:00
|
|
|
}
|
|
|
|
|
2015-02-11 11:04:13 -05:00
|
|
|
cursor_tracker = meta_cursor_tracker_get_for_screen (NULL);
|
|
|
|
meta_cursor_tracker_set_pointer_visible (cursor_tracker, !has_touchscreen);
|
|
|
|
|
2014-09-04 15:06:03 -04:00
|
|
|
g_slist_free (devices);
|
|
|
|
}
|
2014-10-29 10:30:52 -04:00
|
|
|
|
|
|
|
priv->input_settings = meta_input_settings_create ();
|
2015-03-27 10:50:59 -04:00
|
|
|
|
|
|
|
center_pointer (backend);
|
2014-04-22 15:15:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static MetaCursorRenderer *
|
|
|
|
meta_backend_real_create_cursor_renderer (MetaBackend *backend)
|
|
|
|
{
|
|
|
|
return meta_cursor_renderer_new ();
|
2014-04-22 10:14:59 -04:00
|
|
|
}
|
|
|
|
|
2014-04-23 10:50:07 -04:00
|
|
|
static gboolean
|
|
|
|
meta_backend_real_grab_device (MetaBackend *backend,
|
|
|
|
int device_id,
|
|
|
|
uint32_t timestamp)
|
|
|
|
{
|
|
|
|
/* Do nothing */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
meta_backend_real_ungrab_device (MetaBackend *backend,
|
|
|
|
int device_id,
|
|
|
|
uint32_t timestamp)
|
|
|
|
{
|
|
|
|
/* Do nothing */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-08-13 19:46:32 -04:00
|
|
|
static void
|
|
|
|
meta_backend_real_select_stage_events (MetaBackend *backend)
|
|
|
|
{
|
|
|
|
/* Do nothing */
|
|
|
|
}
|
|
|
|
|
2015-06-02 04:26:34 -04:00
|
|
|
static gboolean
|
|
|
|
meta_backend_real_get_relative_motion_deltas (MetaBackend *backend,
|
|
|
|
const ClutterEvent *event,
|
|
|
|
double *dx,
|
|
|
|
double *dy,
|
|
|
|
double *dx_unaccel,
|
|
|
|
double *dy_unaccel)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-04-21 19:03:22 -04:00
|
|
|
static void
|
|
|
|
meta_backend_class_init (MetaBackendClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = meta_backend_finalize;
|
2014-04-22 10:14:59 -04:00
|
|
|
|
|
|
|
klass->post_init = meta_backend_real_post_init;
|
2014-04-22 15:15:11 -04:00
|
|
|
klass->create_cursor_renderer = meta_backend_real_create_cursor_renderer;
|
2014-04-23 10:50:07 -04:00
|
|
|
klass->grab_device = meta_backend_real_grab_device;
|
|
|
|
klass->ungrab_device = meta_backend_real_ungrab_device;
|
2014-08-13 19:46:32 -04:00
|
|
|
klass->select_stage_events = meta_backend_real_select_stage_events;
|
2015-06-02 04:26:34 -04:00
|
|
|
klass->get_relative_motion_deltas = meta_backend_real_get_relative_motion_deltas;
|
2014-08-14 17:32:41 -04:00
|
|
|
|
|
|
|
g_signal_new ("keymap-changed",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
2014-09-10 13:16:01 -04:00
|
|
|
g_signal_new ("keymap-layout-group-changed",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 1, G_TYPE_UINT);
|
2015-02-11 08:59:21 -05:00
|
|
|
g_signal_new ("last-device-changed",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 1, G_TYPE_INT);
|
2014-04-21 19:03:22 -04:00
|
|
|
}
|
|
|
|
|
2016-07-22 22:26:39 -04:00
|
|
|
static gboolean
|
|
|
|
meta_backend_initable_init (GInitable *initable,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaBackend *backend = META_BACKEND (initable);
|
|
|
|
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
|
|
|
|
|
|
|
priv->renderer = META_BACKEND_GET_CLASS (backend)->create_renderer (backend);
|
|
|
|
if (!priv->renderer)
|
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"Failed to create MetaRenderer");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
initable_iface_init (GInitableIface *initable_iface)
|
|
|
|
{
|
|
|
|
initable_iface->init = meta_backend_initable_init;
|
|
|
|
}
|
|
|
|
|
2014-04-21 19:03:22 -04:00
|
|
|
static void
|
|
|
|
meta_backend_init (MetaBackend *backend)
|
|
|
|
{
|
|
|
|
_backend = backend;
|
|
|
|
}
|
|
|
|
|
2014-04-22 10:14:59 -04:00
|
|
|
static void
|
|
|
|
meta_backend_post_init (MetaBackend *backend)
|
|
|
|
{
|
|
|
|
META_BACKEND_GET_CLASS (backend)->post_init (backend);
|
|
|
|
}
|
|
|
|
|
2014-08-05 08:11:59 -04:00
|
|
|
/**
|
|
|
|
* meta_backend_get_idle_monitor: (skip)
|
|
|
|
*/
|
2014-04-21 19:03:22 -04:00
|
|
|
MetaIdleMonitor *
|
|
|
|
meta_backend_get_idle_monitor (MetaBackend *backend,
|
|
|
|
int device_id)
|
|
|
|
{
|
2014-12-29 21:57:09 -05:00
|
|
|
return g_hash_table_lookup (backend->device_monitors, &device_id);
|
2014-04-21 19:03:22 -04:00
|
|
|
}
|
|
|
|
|
2014-08-05 08:11:59 -04:00
|
|
|
/**
|
|
|
|
* meta_backend_get_monitor_manager: (skip)
|
|
|
|
*/
|
2014-04-21 19:41:11 -04:00
|
|
|
MetaMonitorManager *
|
|
|
|
meta_backend_get_monitor_manager (MetaBackend *backend)
|
|
|
|
{
|
|
|
|
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
|
|
|
|
|
|
|
return priv->monitor_manager;
|
|
|
|
}
|
|
|
|
|
2014-08-05 08:11:59 -04:00
|
|
|
/**
|
|
|
|
* meta_backend_get_cursor_renderer: (skip)
|
|
|
|
*/
|
2014-04-22 14:32:55 -04:00
|
|
|
MetaCursorRenderer *
|
|
|
|
meta_backend_get_cursor_renderer (MetaBackend *backend)
|
|
|
|
{
|
|
|
|
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
|
|
|
|
|
|
|
return priv->cursor_renderer;
|
|
|
|
}
|
|
|
|
|
2016-05-07 11:07:46 -04:00
|
|
|
/**
|
|
|
|
* meta_backend_get_renderer: (skip)
|
|
|
|
*/
|
|
|
|
MetaRenderer * meta_backend_get_renderer (MetaBackend *backend)
|
|
|
|
{
|
|
|
|
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
|
|
|
|
|
|
|
return priv->renderer;
|
|
|
|
}
|
|
|
|
|
2014-08-05 08:11:59 -04:00
|
|
|
/**
|
|
|
|
* meta_backend_grab_device: (skip)
|
|
|
|
*/
|
2014-04-23 10:50:07 -04:00
|
|
|
gboolean
|
|
|
|
meta_backend_grab_device (MetaBackend *backend,
|
|
|
|
int device_id,
|
|
|
|
uint32_t timestamp)
|
|
|
|
{
|
|
|
|
return META_BACKEND_GET_CLASS (backend)->grab_device (backend, device_id, timestamp);
|
|
|
|
}
|
|
|
|
|
2014-08-05 08:11:59 -04:00
|
|
|
/**
|
|
|
|
* meta_backend_ungrab_device: (skip)
|
|
|
|
*/
|
2014-04-23 10:50:07 -04:00
|
|
|
gboolean
|
|
|
|
meta_backend_ungrab_device (MetaBackend *backend,
|
|
|
|
int device_id,
|
|
|
|
uint32_t timestamp)
|
|
|
|
{
|
|
|
|
return META_BACKEND_GET_CLASS (backend)->ungrab_device (backend, device_id, timestamp);
|
|
|
|
}
|
|
|
|
|
2014-08-05 08:11:59 -04:00
|
|
|
/**
|
|
|
|
* meta_backend_warp_pointer: (skip)
|
|
|
|
*/
|
2014-05-27 14:11:23 -04:00
|
|
|
void
|
|
|
|
meta_backend_warp_pointer (MetaBackend *backend,
|
|
|
|
int x,
|
|
|
|
int y)
|
|
|
|
{
|
|
|
|
META_BACKEND_GET_CLASS (backend)->warp_pointer (backend, x, y);
|
|
|
|
}
|
|
|
|
|
2014-08-04 10:47:35 -04:00
|
|
|
void
|
|
|
|
meta_backend_set_keymap (MetaBackend *backend,
|
|
|
|
const char *layouts,
|
|
|
|
const char *variants,
|
|
|
|
const char *options)
|
|
|
|
{
|
|
|
|
META_BACKEND_GET_CLASS (backend)->set_keymap (backend, layouts, variants, options);
|
|
|
|
}
|
|
|
|
|
2014-08-05 08:11:59 -04:00
|
|
|
/**
|
|
|
|
* meta_backend_get_keymap: (skip)
|
|
|
|
*/
|
2014-08-04 10:47:35 -04:00
|
|
|
struct xkb_keymap *
|
|
|
|
meta_backend_get_keymap (MetaBackend *backend)
|
|
|
|
|
|
|
|
{
|
|
|
|
return META_BACKEND_GET_CLASS (backend)->get_keymap (backend);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_backend_lock_layout_group (MetaBackend *backend,
|
|
|
|
guint idx)
|
|
|
|
{
|
|
|
|
META_BACKEND_GET_CLASS (backend)->lock_layout_group (backend, idx);
|
|
|
|
}
|
|
|
|
|
2014-08-13 19:46:32 -04:00
|
|
|
/**
|
|
|
|
* meta_backend_get_stage:
|
|
|
|
* @backend: A #MetaBackend
|
|
|
|
*
|
|
|
|
* Gets the global #ClutterStage that's managed by this backend.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the #ClutterStage
|
|
|
|
*/
|
|
|
|
ClutterActor *
|
|
|
|
meta_backend_get_stage (MetaBackend *backend)
|
|
|
|
{
|
|
|
|
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
|
|
|
return priv->stage;
|
|
|
|
}
|
|
|
|
|
2016-02-25 18:45:50 -05:00
|
|
|
static gboolean
|
|
|
|
update_last_device (MetaBackend *backend)
|
|
|
|
{
|
|
|
|
MetaCursorTracker *cursor_tracker = meta_cursor_tracker_get_for_screen (NULL);
|
|
|
|
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
|
|
|
ClutterInputDeviceType device_type;
|
|
|
|
ClutterDeviceManager *manager;
|
|
|
|
ClutterInputDevice *device;
|
|
|
|
|
|
|
|
priv->device_update_idle_id = 0;
|
|
|
|
manager = clutter_device_manager_get_default ();
|
|
|
|
device = clutter_device_manager_get_device (manager,
|
|
|
|
backend->current_device_id);
|
|
|
|
device_type = clutter_input_device_get_device_type (device);
|
|
|
|
|
|
|
|
g_signal_emit_by_name (backend, "last-device-changed",
|
|
|
|
backend->current_device_id);
|
|
|
|
|
|
|
|
switch (device_type)
|
|
|
|
{
|
|
|
|
case CLUTTER_KEYBOARD_DEVICE:
|
|
|
|
break;
|
|
|
|
case CLUTTER_TOUCHSCREEN_DEVICE:
|
|
|
|
meta_cursor_tracker_set_pointer_visible (cursor_tracker, FALSE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
meta_cursor_tracker_set_pointer_visible (cursor_tracker, TRUE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
2015-02-11 08:59:21 -05:00
|
|
|
void
|
|
|
|
meta_backend_update_last_device (MetaBackend *backend,
|
|
|
|
int device_id)
|
|
|
|
{
|
2016-02-25 18:45:50 -05:00
|
|
|
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
2015-02-11 08:59:21 -05:00
|
|
|
ClutterDeviceManager *manager;
|
|
|
|
ClutterInputDevice *device;
|
|
|
|
|
|
|
|
if (backend->current_device_id == device_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
manager = clutter_device_manager_get_default ();
|
|
|
|
device = clutter_device_manager_get_device (manager, device_id);
|
|
|
|
|
|
|
|
if (!device ||
|
|
|
|
clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_MASTER)
|
|
|
|
return;
|
|
|
|
|
|
|
|
backend->current_device_id = device_id;
|
|
|
|
|
2016-02-25 18:45:50 -05:00
|
|
|
if (priv->device_update_idle_id == 0)
|
2015-02-11 08:59:21 -05:00
|
|
|
{
|
2016-02-25 18:45:50 -05:00
|
|
|
priv->device_update_idle_id =
|
|
|
|
g_idle_add ((GSourceFunc) update_last_device, backend);
|
|
|
|
g_source_set_name_by_id (priv->device_update_idle_id,
|
|
|
|
"[mutter] update_last_device");
|
2015-02-11 08:59:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-02 04:26:34 -04:00
|
|
|
gboolean
|
|
|
|
meta_backend_get_relative_motion_deltas (MetaBackend *backend,
|
|
|
|
const ClutterEvent *event,
|
|
|
|
double *dx,
|
|
|
|
double *dy,
|
|
|
|
double *dx_unaccel,
|
|
|
|
double *dy_unaccel)
|
|
|
|
{
|
|
|
|
MetaBackendClass *klass = META_BACKEND_GET_CLASS (backend);
|
|
|
|
return klass->get_relative_motion_deltas (backend,
|
|
|
|
event,
|
|
|
|
dx, dy,
|
|
|
|
dx_unaccel, dy_unaccel);
|
|
|
|
}
|
|
|
|
|
2015-06-17 00:10:52 -04:00
|
|
|
void
|
|
|
|
meta_backend_set_client_pointer_constraint (MetaBackend *backend,
|
|
|
|
MetaPointerConstraint *constraint)
|
|
|
|
{
|
2016-07-21 15:12:16 -04:00
|
|
|
g_assert (!constraint || !backend->client_pointer_constraint);
|
2015-06-17 00:10:52 -04:00
|
|
|
|
|
|
|
g_clear_object (&backend->client_pointer_constraint);
|
|
|
|
if (constraint)
|
|
|
|
backend->client_pointer_constraint = g_object_ref (constraint);
|
|
|
|
}
|
|
|
|
|
2014-03-31 23:00:07 -04:00
|
|
|
/* Mutter is responsible for pulling events off the X queue, so Clutter
|
|
|
|
* doesn't need (and shouldn't) run its normal event source which polls
|
|
|
|
* the X fd, but we do have to deal with dispatching events that accumulate
|
|
|
|
* in the clutter queue. This happens, for example, when clutter generate
|
|
|
|
* enter/leave events on mouse motion - several events are queued in the
|
|
|
|
* clutter queue but only one dispatched. It could also happen because of
|
|
|
|
* explicit calls to clutter_event_put(). We add a very simple custom
|
|
|
|
* event loop source which is simply responsible for pulling events off
|
|
|
|
* of the queue and dispatching them before we block for new events.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
event_prepare (GSource *source,
|
|
|
|
gint *timeout_)
|
|
|
|
{
|
|
|
|
*timeout_ = -1;
|
|
|
|
|
|
|
|
return clutter_events_pending ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
event_check (GSource *source)
|
|
|
|
{
|
|
|
|
return clutter_events_pending ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
event_dispatch (GSource *source,
|
|
|
|
GSourceFunc callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ClutterEvent *event = clutter_event_get ();
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
{
|
|
|
|
clutter_do_event (event);
|
|
|
|
clutter_event_free (event);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GSourceFuncs event_funcs = {
|
|
|
|
event_prepare,
|
|
|
|
event_check,
|
|
|
|
event_dispatch
|
|
|
|
};
|
|
|
|
|
2016-07-06 05:05:56 -04:00
|
|
|
ClutterBackend *
|
2016-05-04 04:19:23 -04:00
|
|
|
meta_backend_get_clutter_backend (MetaBackend *backend)
|
|
|
|
{
|
|
|
|
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
|
|
|
|
|
|
|
if (!priv->clutter_backend)
|
|
|
|
{
|
|
|
|
priv->clutter_backend =
|
|
|
|
META_BACKEND_GET_CLASS (backend)->create_clutter_backend (backend);
|
|
|
|
}
|
|
|
|
|
|
|
|
return priv->clutter_backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ClutterBackend *
|
|
|
|
meta_get_clutter_backend (void)
|
|
|
|
{
|
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
|
|
|
|
return meta_backend_get_clutter_backend (backend);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_init_backend (MetaBackendType backend_type)
|
|
|
|
{
|
|
|
|
GType type;
|
2016-07-22 22:26:39 -04:00
|
|
|
MetaBackend *backend;
|
|
|
|
GError *error = NULL;
|
2016-05-04 04:19:23 -04:00
|
|
|
|
|
|
|
switch (backend_type)
|
|
|
|
{
|
|
|
|
case META_BACKEND_TYPE_X11:
|
|
|
|
type = META_TYPE_BACKEND_X11;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
|
|
|
case META_BACKEND_TYPE_NATIVE:
|
|
|
|
type = META_TYPE_BACKEND_NATIVE;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* meta_backend_init() above install the backend globally so
|
|
|
|
* so meta_get_backend() works even during initialization. */
|
2016-07-22 22:26:39 -04:00
|
|
|
backend = g_object_new (type, NULL);
|
|
|
|
if (!g_initable_init (G_INITABLE (backend), NULL, &error))
|
|
|
|
{
|
|
|
|
g_warning ("Failed to create backend: %s", error->message);
|
|
|
|
meta_exit (META_EXIT_ERROR);
|
|
|
|
}
|
2016-05-04 04:19:23 -04:00
|
|
|
}
|
|
|
|
|
2014-08-05 08:11:59 -04:00
|
|
|
/**
|
|
|
|
* meta_clutter_init: (skip)
|
|
|
|
*/
|
2014-03-31 23:00:07 -04:00
|
|
|
void
|
|
|
|
meta_clutter_init (void)
|
|
|
|
{
|
2014-09-08 14:17:03 -04:00
|
|
|
ClutterSettings *clutter_settings;
|
2014-03-31 23:00:07 -04:00
|
|
|
GSource *source;
|
|
|
|
|
2016-05-04 04:19:23 -04:00
|
|
|
clutter_set_custom_backend_func (meta_get_clutter_backend);
|
2014-04-21 19:03:22 -04:00
|
|
|
|
2014-03-31 23:00:07 -04:00
|
|
|
if (clutter_init (NULL, NULL) != CLUTTER_INIT_SUCCESS)
|
2015-10-28 10:52:03 -04:00
|
|
|
{
|
|
|
|
g_warning ("Unable to initialize Clutter.\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
2014-03-31 23:00:07 -04:00
|
|
|
|
2014-09-08 14:17:03 -04:00
|
|
|
/*
|
|
|
|
* XXX: We cannot handle high dpi scaling yet, so fix the scale to 1
|
|
|
|
* for now.
|
|
|
|
*/
|
|
|
|
clutter_settings = clutter_settings_get_default ();
|
|
|
|
g_object_set (clutter_settings, "window-scaling-factor", 1, NULL);
|
|
|
|
|
2014-03-31 23:00:07 -04:00
|
|
|
source = g_source_new (&event_funcs, sizeof (GSource));
|
|
|
|
g_source_attach (source, NULL);
|
|
|
|
g_source_unref (source);
|
2014-04-22 10:14:59 -04:00
|
|
|
|
|
|
|
meta_backend_post_init (_backend);
|
2014-03-31 23:00:07 -04:00
|
|
|
}
|
2016-06-08 05:05:31 -04:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_is_stage_views_enabled (void)
|
|
|
|
{
|
|
|
|
const gchar *mutter_stage_views;
|
|
|
|
|
|
|
|
if (!meta_is_wayland_compositor ())
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
mutter_stage_views = g_getenv ("MUTTER_STAGE_VIEWS");
|
|
|
|
|
|
|
|
if (!mutter_stage_views)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return strcmp (mutter_stage_views, "1") == 0;
|
|
|
|
}
|
2016-05-13 07:31:52 -04:00
|
|
|
|
|
|
|
MetaInputSettings *
|
|
|
|
meta_backend_get_input_settings (MetaBackend *backend)
|
|
|
|
{
|
|
|
|
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
|
|
|
|
|
|
|
return priv->input_settings;
|
|
|
|
}
|