2013-08-13 06:57:41 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2014-05-02 09:34:02 -04:00
|
|
|
/*
|
2013-08-13 06:57:41 -04:00
|
|
|
* Copyright 2013 Red Hat, Inc.
|
2014-05-02 09:34:02 -04:00
|
|
|
*
|
2013-08-13 06:57:41 -04:00
|
|
|
* 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.
|
2014-05-02 09:34:02 -04:00
|
|
|
*
|
2013-08-13 06:57:41 -04:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-11 20:42:06 -05:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2013-08-13 06:57:41 -04:00
|
|
|
*
|
|
|
|
* Author: Giovanni Campagna <gcampagn@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:cursor-tracker
|
|
|
|
* @title: MetaCursorTracker
|
2013-09-04 10:50:19 -04:00
|
|
|
* @short_description: Mutter cursor tracking helper. Originally only
|
|
|
|
* tracking the cursor image, now more of a "core
|
|
|
|
* pointer abstraction"
|
2013-08-13 06:57:41 -04:00
|
|
|
*/
|
|
|
|
|
2014-11-03 13:31:25 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/meta-cursor-tracker-private.h"
|
2013-08-13 06:57:41 -04:00
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include <string.h>
|
2013-09-04 10:50:19 -04:00
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/meta-backend-private.h"
|
|
|
|
#include "cogl/cogl.h"
|
2020-07-31 15:08:15 -04:00
|
|
|
#include "core/display-private.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "clutter/clutter.h"
|
|
|
|
#include "meta/main.h"
|
|
|
|
#include "meta/util.h"
|
2014-03-18 22:01:31 -04:00
|
|
|
|
2020-07-27 09:12:33 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_BACKEND,
|
|
|
|
|
|
|
|
N_PROPS
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *obj_props[N_PROPS];
|
|
|
|
|
2020-07-27 05:50:46 -04:00
|
|
|
typedef struct _MetaCursorTrackerPrivate
|
|
|
|
{
|
2020-07-27 09:12:33 -04:00
|
|
|
MetaBackend *backend;
|
|
|
|
|
2020-07-27 05:43:30 -04:00
|
|
|
gboolean is_showing;
|
|
|
|
|
2020-07-29 05:22:19 -04:00
|
|
|
int track_position_count;
|
|
|
|
|
2020-07-29 05:20:21 -04:00
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
|
2020-07-27 05:43:30 -04:00
|
|
|
MetaCursorSprite *effective_cursor; /* May be NULL when hidden */
|
|
|
|
MetaCursorSprite *displayed_cursor;
|
|
|
|
|
|
|
|
/* Wayland clients can set a NULL buffer as their cursor
|
|
|
|
* explicitly, which means that we shouldn't display anything.
|
|
|
|
* So, we can't simply store a NULL in window_cursor to
|
|
|
|
* determine an unset window cursor; we need an extra boolean.
|
|
|
|
*/
|
|
|
|
gboolean has_window_cursor;
|
|
|
|
MetaCursorSprite *window_cursor;
|
|
|
|
|
|
|
|
MetaCursorSprite *root_cursor;
|
2020-07-27 05:50:46 -04:00
|
|
|
} MetaCursorTrackerPrivate;
|
2020-07-27 05:43:30 -04:00
|
|
|
|
2020-07-27 05:50:46 -04:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorTracker, meta_cursor_tracker,
|
|
|
|
G_TYPE_OBJECT)
|
2013-08-13 06:57:41 -04:00
|
|
|
|
2018-12-19 03:04:25 -05:00
|
|
|
enum
|
|
|
|
{
|
2014-07-26 10:20:58 -04:00
|
|
|
CURSOR_CHANGED,
|
2018-12-12 05:27:16 -05:00
|
|
|
CURSOR_MOVED,
|
2019-02-16 16:48:17 -05:00
|
|
|
VISIBILITY_CHANGED,
|
2014-07-26 10:20:58 -04:00
|
|
|
LAST_SIGNAL
|
2013-08-13 06:57:41 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL];
|
|
|
|
|
2020-07-31 15:08:15 -04:00
|
|
|
void
|
|
|
|
meta_cursor_tracker_notify_cursor_changed (MetaCursorTracker *tracker)
|
|
|
|
{
|
|
|
|
g_signal_emit (tracker, signals[CURSOR_CHANGED], 0);
|
|
|
|
}
|
|
|
|
|
2017-11-16 13:26:41 -05:00
|
|
|
static void
|
|
|
|
cursor_texture_updated (MetaCursorSprite *cursor,
|
|
|
|
MetaCursorTracker *tracker)
|
|
|
|
{
|
|
|
|
g_signal_emit (tracker, signals[CURSOR_CHANGED], 0);
|
|
|
|
}
|
|
|
|
|
2017-11-16 13:23:09 -05:00
|
|
|
static gboolean
|
|
|
|
update_displayed_cursor (MetaCursorTracker *tracker)
|
2014-04-21 18:05:59 -04:00
|
|
|
{
|
2020-07-27 05:50:46 -04:00
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
2014-07-22 11:09:12 -04:00
|
|
|
MetaDisplay *display = meta_get_display ();
|
2017-11-16 13:23:09 -05:00
|
|
|
MetaCursorSprite *cursor = NULL;
|
2014-07-22 11:09:12 -04:00
|
|
|
|
2017-11-20 07:08:06 -05:00
|
|
|
if (display && meta_display_windows_are_interactable (display) &&
|
2020-07-27 05:50:46 -04:00
|
|
|
priv->has_window_cursor)
|
|
|
|
cursor = priv->window_cursor;
|
2017-11-20 07:08:06 -05:00
|
|
|
else
|
2020-07-27 05:50:46 -04:00
|
|
|
cursor = priv->root_cursor;
|
2017-11-16 13:23:09 -05:00
|
|
|
|
2020-07-27 05:50:46 -04:00
|
|
|
if (priv->displayed_cursor == cursor)
|
2017-11-16 13:23:09 -05:00
|
|
|
return FALSE;
|
|
|
|
|
2020-07-27 05:50:46 -04:00
|
|
|
if (priv->displayed_cursor)
|
2017-11-20 07:20:36 -05:00
|
|
|
{
|
2020-07-27 05:50:46 -04:00
|
|
|
g_signal_handlers_disconnect_by_func (priv->displayed_cursor,
|
2017-11-20 07:20:36 -05:00
|
|
|
cursor_texture_updated,
|
|
|
|
tracker);
|
|
|
|
}
|
|
|
|
|
2020-07-27 05:50:46 -04:00
|
|
|
g_set_object (&priv->displayed_cursor, cursor);
|
2017-11-20 07:20:36 -05:00
|
|
|
|
|
|
|
if (cursor)
|
|
|
|
{
|
|
|
|
g_signal_connect (cursor, "texture-changed",
|
|
|
|
G_CALLBACK (cursor_texture_updated), tracker);
|
|
|
|
}
|
|
|
|
|
2017-11-16 13:23:09 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
update_effective_cursor (MetaCursorTracker *tracker)
|
|
|
|
{
|
2020-07-27 05:50:46 -04:00
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
2017-11-16 13:23:09 -05:00
|
|
|
MetaCursorSprite *cursor = NULL;
|
|
|
|
|
2020-07-27 05:50:46 -04:00
|
|
|
if (priv->is_showing)
|
|
|
|
cursor = priv->displayed_cursor;
|
2017-11-16 13:23:09 -05:00
|
|
|
|
2020-07-27 05:50:46 -04:00
|
|
|
return g_set_object (&priv->effective_cursor, cursor);
|
2014-04-21 18:05:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-11-16 13:23:09 -05:00
|
|
|
change_cursor_renderer (MetaCursorTracker *tracker)
|
2014-04-21 18:05:59 -04:00
|
|
|
{
|
2020-07-27 05:50:46 -04:00
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
2016-12-01 03:54:04 -05:00
|
|
|
MetaCursorRenderer *cursor_renderer =
|
2020-07-27 09:12:33 -04:00
|
|
|
meta_backend_get_cursor_renderer (priv->backend);
|
2016-12-01 03:54:04 -05:00
|
|
|
|
2020-07-27 05:50:46 -04:00
|
|
|
meta_cursor_renderer_set_cursor (cursor_renderer, priv->effective_cursor);
|
2014-04-21 18:05:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sync_cursor (MetaCursorTracker *tracker)
|
|
|
|
{
|
2019-01-03 10:40:42 -05:00
|
|
|
gboolean cursor_changed = FALSE;
|
|
|
|
|
|
|
|
cursor_changed = update_displayed_cursor (tracker);
|
2014-04-21 18:05:59 -04:00
|
|
|
|
2017-11-16 13:23:09 -05:00
|
|
|
if (update_effective_cursor (tracker))
|
|
|
|
change_cursor_renderer (tracker);
|
2019-01-03 10:40:42 -05:00
|
|
|
|
|
|
|
if (cursor_changed)
|
|
|
|
g_signal_emit (tracker, signals[CURSOR_CHANGED], 0);
|
2014-04-21 18:05:59 -04:00
|
|
|
}
|
2013-09-05 10:45:41 -04:00
|
|
|
|
2020-07-29 05:22:19 -04:00
|
|
|
static void
|
|
|
|
meta_cursor_tracker_real_set_force_track_position (MetaCursorTracker *tracker,
|
|
|
|
gboolean is_enabled)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-07-31 15:08:15 -04:00
|
|
|
static MetaCursorSprite *
|
|
|
|
meta_cursor_tracker_real_get_sprite (MetaCursorTracker *tracker)
|
|
|
|
{
|
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
|
|
|
|
|
|
|
return priv->displayed_cursor;
|
|
|
|
}
|
|
|
|
|
2013-08-13 06:57:41 -04:00
|
|
|
static void
|
2020-07-27 05:50:46 -04:00
|
|
|
meta_cursor_tracker_init (MetaCursorTracker *tracker)
|
2013-08-13 06:57:41 -04:00
|
|
|
{
|
2020-07-27 05:50:46 -04:00
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
|
|
|
|
|
|
|
priv->is_showing = TRUE;
|
2020-07-29 05:20:21 -04:00
|
|
|
priv->x = -1.0;
|
|
|
|
priv->y = -1.0;
|
2013-08-13 06:57:41 -04:00
|
|
|
}
|
|
|
|
|
2020-07-27 09:12:33 -04:00
|
|
|
static void
|
|
|
|
meta_cursor_tracker_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MetaCursorTracker *tracker = META_CURSOR_TRACKER (object);
|
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_BACKEND:
|
|
|
|
g_value_set_object (value, priv->backend);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_cursor_tracker_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MetaCursorTracker *tracker = META_CURSOR_TRACKER (object);
|
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_BACKEND:
|
|
|
|
priv->backend = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-13 06:57:41 -04:00
|
|
|
static void
|
|
|
|
meta_cursor_tracker_finalize (GObject *object)
|
|
|
|
{
|
2020-07-27 05:50:46 -04:00
|
|
|
MetaCursorTracker *tracker = META_CURSOR_TRACKER (object);
|
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
2013-08-13 06:57:41 -04:00
|
|
|
|
2020-07-27 05:50:46 -04:00
|
|
|
g_clear_object (&priv->effective_cursor);
|
|
|
|
g_clear_object (&priv->displayed_cursor);
|
|
|
|
g_clear_object (&priv->root_cursor);
|
2013-09-06 04:37:03 -04:00
|
|
|
|
2013-08-13 06:57:41 -04:00
|
|
|
G_OBJECT_CLASS (meta_cursor_tracker_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_cursor_tracker_class_init (MetaCursorTrackerClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2020-07-27 09:12:33 -04:00
|
|
|
object_class->get_property = meta_cursor_tracker_get_property;
|
|
|
|
object_class->set_property = meta_cursor_tracker_set_property;
|
2013-08-13 06:57:41 -04:00
|
|
|
object_class->finalize = meta_cursor_tracker_finalize;
|
|
|
|
|
2020-07-29 05:22:19 -04:00
|
|
|
klass->set_force_track_position =
|
|
|
|
meta_cursor_tracker_real_set_force_track_position;
|
2020-07-31 15:08:15 -04:00
|
|
|
klass->get_sprite =
|
|
|
|
meta_cursor_tracker_real_get_sprite;
|
2020-07-29 05:22:19 -04:00
|
|
|
|
2020-07-27 09:12:33 -04:00
|
|
|
obj_props[PROP_BACKEND] =
|
|
|
|
g_param_spec_object ("backend",
|
|
|
|
"backend",
|
|
|
|
"MetaBackend",
|
|
|
|
META_TYPE_BACKEND,
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
g_object_class_install_properties (object_class, N_PROPS, obj_props);
|
|
|
|
|
2013-08-13 06:57:41 -04:00
|
|
|
signals[CURSOR_CHANGED] = g_signal_new ("cursor-changed",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
2018-12-12 05:27:16 -05:00
|
|
|
|
2019-07-24 05:34:35 -04:00
|
|
|
/**
|
|
|
|
* MetaCursorTracker::cursor-moved:
|
|
|
|
* @cursor: The #MetaCursorTracker
|
|
|
|
* @x: The new X coordinate of the cursor
|
|
|
|
* @y: The new Y coordinate of the cursor
|
|
|
|
*
|
|
|
|
* Notifies when the cursor has moved to a new location.
|
|
|
|
*/
|
2018-12-12 05:27:16 -05:00
|
|
|
signals[CURSOR_MOVED] = g_signal_new ("cursor-moved",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
2020-07-09 18:40:55 -04:00
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
2019-02-16 16:48:17 -05:00
|
|
|
|
|
|
|
signals[VISIBILITY_CHANGED] = g_signal_new ("visibility-changed",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
2019-07-24 05:23:08 -04:00
|
|
|
0, NULL, NULL, NULL,
|
2019-02-16 16:48:17 -05:00
|
|
|
G_TYPE_NONE, 0);
|
2013-08-13 06:57:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-26 15:43:17 -04:00
|
|
|
* meta_cursor_tracker_get_for_display:
|
|
|
|
* @display: the #MetaDisplay
|
2013-08-13 06:57:41 -04:00
|
|
|
*
|
2017-08-26 15:43:17 -04:00
|
|
|
* Retrieves the cursor tracker object for @display.
|
2013-08-13 06:57:41 -04:00
|
|
|
*
|
|
|
|
* Returns: (transfer none):
|
|
|
|
*/
|
|
|
|
MetaCursorTracker *
|
2017-08-26 15:43:17 -04:00
|
|
|
meta_cursor_tracker_get_for_display (MetaDisplay *display)
|
2013-08-13 06:57:41 -04:00
|
|
|
{
|
2016-11-29 07:30:22 -05:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaCursorTracker *tracker = meta_backend_get_cursor_tracker (backend);
|
|
|
|
|
|
|
|
g_assert (tracker);
|
2013-08-13 06:57:41 -04:00
|
|
|
|
2016-11-29 07:30:22 -05:00
|
|
|
return tracker;
|
2013-08-13 06:57:41 -04:00
|
|
|
}
|
|
|
|
|
2013-11-18 19:19:42 -05:00
|
|
|
static void
|
2015-03-09 23:23:00 -04:00
|
|
|
set_window_cursor (MetaCursorTracker *tracker,
|
|
|
|
gboolean has_cursor,
|
|
|
|
MetaCursorSprite *cursor_sprite)
|
2013-11-18 19:19:42 -05:00
|
|
|
{
|
2020-07-27 05:50:46 -04:00
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
|
|
|
|
|
|
|
g_clear_object (&priv->window_cursor);
|
2015-03-09 23:23:00 -04:00
|
|
|
if (cursor_sprite)
|
2020-07-27 05:50:46 -04:00
|
|
|
priv->window_cursor = g_object_ref (cursor_sprite);
|
|
|
|
priv->has_window_cursor = has_cursor;
|
2013-11-19 15:43:46 -05:00
|
|
|
sync_cursor (tracker);
|
2013-11-18 19:19:42 -05:00
|
|
|
}
|
|
|
|
|
2013-08-13 06:57:41 -04:00
|
|
|
/**
|
|
|
|
* meta_cursor_tracker_get_sprite:
|
|
|
|
*
|
|
|
|
* Returns: (transfer none):
|
|
|
|
*/
|
|
|
|
CoglTexture *
|
|
|
|
meta_cursor_tracker_get_sprite (MetaCursorTracker *tracker)
|
|
|
|
{
|
2015-03-09 23:23:00 -04:00
|
|
|
MetaCursorSprite *cursor_sprite;
|
2014-05-13 15:44:02 -04:00
|
|
|
|
2020-07-31 15:08:15 -04:00
|
|
|
cursor_sprite = META_CURSOR_TRACKER_GET_CLASS (tracker)->get_sprite (tracker);
|
2013-08-13 06:57:41 -04:00
|
|
|
|
2020-07-31 15:08:15 -04:00
|
|
|
if (!cursor_sprite)
|
|
|
|
return NULL;
|
2013-08-13 06:57:41 -04:00
|
|
|
|
2020-07-31 15:08:15 -04:00
|
|
|
meta_cursor_sprite_realize_texture (cursor_sprite);
|
|
|
|
return meta_cursor_sprite_get_cogl_texture (cursor_sprite);
|
2013-08-13 06:57:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_cursor_tracker_get_hot:
|
|
|
|
* @tracker:
|
|
|
|
* @x: (out):
|
|
|
|
* @y: (out):
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
meta_cursor_tracker_get_hot (MetaCursorTracker *tracker,
|
|
|
|
int *x,
|
|
|
|
int *y)
|
|
|
|
{
|
2015-03-09 23:23:00 -04:00
|
|
|
MetaCursorSprite *cursor_sprite;
|
2014-05-13 15:44:02 -04:00
|
|
|
|
2013-08-13 06:57:41 -04:00
|
|
|
g_return_if_fail (META_IS_CURSOR_TRACKER (tracker));
|
|
|
|
|
2020-07-31 15:08:15 -04:00
|
|
|
cursor_sprite = META_CURSOR_TRACKER_GET_CLASS (tracker)->get_sprite (tracker);
|
2013-08-13 06:57:41 -04:00
|
|
|
|
2015-03-09 23:23:00 -04:00
|
|
|
if (cursor_sprite)
|
2015-07-17 11:16:39 -04:00
|
|
|
meta_cursor_sprite_get_hotspot (cursor_sprite, x, y);
|
2013-09-05 10:45:41 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (x)
|
|
|
|
*x = 0;
|
|
|
|
if (y)
|
|
|
|
*y = 0;
|
|
|
|
}
|
2013-08-13 06:57:41 -04:00
|
|
|
}
|
|
|
|
|
2013-11-18 19:19:42 -05:00
|
|
|
void
|
2015-03-09 23:23:00 -04:00
|
|
|
meta_cursor_tracker_set_window_cursor (MetaCursorTracker *tracker,
|
|
|
|
MetaCursorSprite *cursor_sprite)
|
2013-11-18 19:19:42 -05:00
|
|
|
{
|
2015-03-09 23:23:00 -04:00
|
|
|
set_window_cursor (tracker, TRUE, cursor_sprite);
|
2013-11-18 19:19:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_cursor_tracker_unset_window_cursor (MetaCursorTracker *tracker)
|
|
|
|
{
|
|
|
|
set_window_cursor (tracker, FALSE, NULL);
|
|
|
|
}
|
|
|
|
|
2018-10-19 03:15:54 -04:00
|
|
|
/**
|
|
|
|
* meta_cursor_tracker_set_root_cursor:
|
|
|
|
* @tracker: a #MetaCursorTracker object.
|
|
|
|
* @cursor_sprite: (transfer none): the new root cursor
|
|
|
|
*
|
|
|
|
* Sets the root cursor (the cursor that is shown if not modified by a window).
|
|
|
|
* The #MetaCursorTracker will take a strong reference to the sprite.
|
|
|
|
*/
|
2013-08-13 06:57:41 -04:00
|
|
|
void
|
2015-03-09 23:23:00 -04:00
|
|
|
meta_cursor_tracker_set_root_cursor (MetaCursorTracker *tracker,
|
|
|
|
MetaCursorSprite *cursor_sprite)
|
2013-08-13 06:57:41 -04:00
|
|
|
{
|
2020-07-27 05:50:46 -04:00
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
|
|
|
|
|
|
|
g_clear_object (&priv->root_cursor);
|
2015-03-09 23:23:00 -04:00
|
|
|
if (cursor_sprite)
|
2020-07-27 05:50:46 -04:00
|
|
|
priv->root_cursor = g_object_ref (cursor_sprite);
|
2013-08-13 06:57:41 -04:00
|
|
|
|
2014-03-31 17:22:23 -04:00
|
|
|
sync_cursor (tracker);
|
2013-08-13 06:57:41 -04:00
|
|
|
}
|
|
|
|
|
2013-11-18 19:19:42 -05:00
|
|
|
void
|
|
|
|
meta_cursor_tracker_update_position (MetaCursorTracker *tracker,
|
2017-06-08 10:13:16 -04:00
|
|
|
float new_x,
|
|
|
|
float new_y)
|
2013-11-18 19:19:42 -05:00
|
|
|
{
|
2020-07-27 09:12:33 -04:00
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
2016-12-01 03:54:04 -05:00
|
|
|
MetaCursorRenderer *cursor_renderer =
|
2020-07-27 09:12:33 -04:00
|
|
|
meta_backend_get_cursor_renderer (priv->backend);
|
2020-07-29 05:20:21 -04:00
|
|
|
gboolean position_changed;
|
2016-12-01 03:54:04 -05:00
|
|
|
|
2020-07-29 05:20:21 -04:00
|
|
|
if (priv->x != new_x || priv->y != new_y)
|
|
|
|
{
|
|
|
|
position_changed = TRUE;
|
|
|
|
priv->x = new_x;
|
|
|
|
priv->y = new_y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
position_changed = FALSE;
|
|
|
|
}
|
|
|
|
|
2016-12-01 03:54:04 -05:00
|
|
|
meta_cursor_renderer_set_position (cursor_renderer, new_x, new_y);
|
2018-12-12 05:27:16 -05:00
|
|
|
|
2020-07-29 05:20:21 -04:00
|
|
|
if (position_changed)
|
2020-07-09 18:40:55 -04:00
|
|
|
g_signal_emit (tracker, signals[CURSOR_MOVED], 0);
|
2013-08-13 06:57:41 -04:00
|
|
|
}
|
2013-09-04 10:50:19 -04:00
|
|
|
|
2020-06-06 07:04:32 -04:00
|
|
|
void
|
|
|
|
meta_cursor_tracker_get_pointer (MetaCursorTracker *tracker,
|
|
|
|
graphene_point_t *coords,
|
|
|
|
ClutterModifierType *mods)
|
2013-09-04 10:50:19 -04:00
|
|
|
{
|
2019-10-04 15:57:26 -04:00
|
|
|
ClutterSeat *seat;
|
2013-09-04 10:50:19 -04:00
|
|
|
ClutterInputDevice *cdevice;
|
|
|
|
|
2019-10-04 15:57:26 -04:00
|
|
|
seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
|
|
|
|
cdevice = clutter_seat_get_pointer (seat);
|
2013-09-04 10:50:19 -04:00
|
|
|
|
2020-06-06 07:04:32 -04:00
|
|
|
clutter_seat_query_state (seat, cdevice, NULL, coords, mods);
|
2013-09-04 10:50:19 -04:00
|
|
|
}
|
2013-09-04 10:56:00 -04:00
|
|
|
|
2020-07-29 05:22:19 -04:00
|
|
|
void
|
|
|
|
meta_cursor_tracker_track_position (MetaCursorTracker *tracker)
|
|
|
|
{
|
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
|
|
|
|
|
|
|
priv->track_position_count++;
|
|
|
|
if (priv->track_position_count == 1)
|
|
|
|
{
|
|
|
|
MetaCursorTrackerClass *klass =
|
|
|
|
META_CURSOR_TRACKER_GET_CLASS (tracker);
|
|
|
|
|
|
|
|
klass->set_force_track_position (tracker, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_cursor_tracker_untrack_position (MetaCursorTracker *tracker)
|
|
|
|
{
|
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
|
|
|
|
2020-07-31 15:21:23 -04:00
|
|
|
g_return_if_fail (priv->track_position_count > 0);
|
2020-07-29 05:22:19 -04:00
|
|
|
|
|
|
|
priv->track_position_count--;
|
|
|
|
if (priv->track_position_count == 0)
|
|
|
|
{
|
|
|
|
MetaCursorTrackerClass *klass =
|
|
|
|
META_CURSOR_TRACKER_GET_CLASS (tracker);
|
|
|
|
|
|
|
|
klass->set_force_track_position (tracker, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-10 15:28:05 -04:00
|
|
|
gboolean
|
|
|
|
meta_cursor_tracker_get_pointer_visible (MetaCursorTracker *tracker)
|
|
|
|
{
|
2020-07-27 05:50:46 -04:00
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
|
|
|
|
|
|
|
return priv->is_showing;
|
2019-04-10 15:28:05 -04:00
|
|
|
}
|
|
|
|
|
2013-09-04 10:56:00 -04:00
|
|
|
void
|
|
|
|
meta_cursor_tracker_set_pointer_visible (MetaCursorTracker *tracker,
|
|
|
|
gboolean visible)
|
|
|
|
{
|
2020-07-27 05:50:46 -04:00
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
|
|
|
|
|
|
|
if (visible == priv->is_showing)
|
2013-09-04 10:56:00 -04:00
|
|
|
return;
|
2020-07-27 05:50:46 -04:00
|
|
|
priv->is_showing = visible;
|
2013-09-04 10:56:00 -04:00
|
|
|
|
2014-04-27 10:49:29 -04:00
|
|
|
sync_cursor (tracker);
|
2019-02-16 16:48:17 -05:00
|
|
|
|
|
|
|
g_signal_emit (tracker, signals[VISIBILITY_CHANGED], 0);
|
2013-09-04 10:56:00 -04:00
|
|
|
}
|
2020-07-31 15:21:23 -04:00
|
|
|
MetaBackend *
|
|
|
|
meta_cursor_tracker_get_backend (MetaCursorTracker *tracker)
|
|
|
|
{
|
|
|
|
MetaCursorTrackerPrivate *priv =
|
|
|
|
meta_cursor_tracker_get_instance_private (tracker);
|
|
|
|
|
|
|
|
return priv->backend;
|
|
|
|
}
|