2014-03-31 14:08:14 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2013 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Giovanni Campagna <gcampagn@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/meta-cursor.h"
|
2014-03-31 14:08:14 -04:00
|
|
|
|
2018-04-26 08:29:57 -04:00
|
|
|
#include "backends/meta-backend-private.h"
|
2021-11-15 08:24:53 -05:00
|
|
|
#include "backends/meta-cursor-tracker-private.h"
|
2018-04-26 08:29:57 -04:00
|
|
|
#include "cogl/cogl.h"
|
|
|
|
#include "meta/common.h"
|
|
|
|
|
2021-11-15 08:24:53 -05:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_CURSOR_TRACKER,
|
|
|
|
|
|
|
|
N_PROPS
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *obj_props[N_PROPS];
|
|
|
|
|
2018-04-26 08:53:01 -04:00
|
|
|
enum
|
|
|
|
{
|
2017-11-16 13:16:54 -05:00
|
|
|
TEXTURE_CHANGED,
|
2015-07-17 11:16:39 -04:00
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL];
|
2014-03-31 15:21:19 -04:00
|
|
|
|
2018-04-23 10:57:01 -04:00
|
|
|
typedef struct _MetaCursorSpritePrivate
|
2015-03-10 02:41:12 -04:00
|
|
|
{
|
|
|
|
GObject parent;
|
|
|
|
|
2015-07-16 23:56:42 -04:00
|
|
|
CoglTexture2D *texture;
|
2015-07-17 11:16:39 -04:00
|
|
|
float texture_scale;
|
2019-04-08 12:12:23 -04:00
|
|
|
MetaMonitorTransform texture_transform;
|
2015-07-16 23:56:42 -04:00
|
|
|
int hot_x, hot_y;
|
2021-07-05 10:19:05 -04:00
|
|
|
|
|
|
|
MetaCursorPrepareFunc prepare_func;
|
|
|
|
gpointer prepare_func_data;
|
2021-11-15 08:24:53 -05:00
|
|
|
|
|
|
|
MetaCursorTracker *cursor_tracker;
|
2018-04-23 10:57:01 -04:00
|
|
|
} MetaCursorSpritePrivate;
|
2015-03-10 02:41:12 -04:00
|
|
|
|
2018-04-30 06:03:31 -04:00
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaCursorSprite,
|
|
|
|
meta_cursor_sprite,
|
|
|
|
G_TYPE_OBJECT)
|
2014-03-31 14:08:14 -04:00
|
|
|
|
2018-04-27 09:43:37 -04:00
|
|
|
gboolean
|
|
|
|
meta_cursor_sprite_is_animated (MetaCursorSprite *sprite)
|
2015-07-13 14:32:42 -04:00
|
|
|
{
|
2018-04-27 09:43:37 -04:00
|
|
|
MetaCursorSpriteClass *klass = META_CURSOR_SPRITE_GET_CLASS (sprite);
|
2018-04-23 10:57:01 -04:00
|
|
|
|
2018-04-27 09:43:37 -04:00
|
|
|
if (klass->is_animated)
|
|
|
|
return klass->is_animated (sprite);
|
|
|
|
else
|
|
|
|
return FALSE;
|
2015-07-13 14:32:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-04-23 10:44:11 -04:00
|
|
|
meta_cursor_sprite_tick_frame (MetaCursorSprite *sprite)
|
2015-07-13 14:32:42 -04:00
|
|
|
{
|
2018-04-27 09:43:37 -04:00
|
|
|
return META_CURSOR_SPRITE_GET_CLASS (sprite)->tick_frame (sprite);
|
2015-07-13 14:32:42 -04:00
|
|
|
}
|
|
|
|
|
2018-04-27 09:43:37 -04:00
|
|
|
unsigned int
|
2018-04-23 10:44:11 -04:00
|
|
|
meta_cursor_sprite_get_current_frame_time (MetaCursorSprite *sprite)
|
2015-07-13 14:32:42 -04:00
|
|
|
{
|
2018-04-27 09:43:37 -04:00
|
|
|
return META_CURSOR_SPRITE_GET_CLASS (sprite)->get_current_frame_time (sprite);
|
2015-07-13 14:32:42 -04:00
|
|
|
}
|
|
|
|
|
2018-04-27 09:43:37 -04:00
|
|
|
void
|
|
|
|
meta_cursor_sprite_clear_texture (MetaCursorSprite *sprite)
|
2014-11-27 17:34:25 -05:00
|
|
|
{
|
2018-04-23 10:57:01 -04:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
2015-03-10 02:35:49 -04:00
|
|
|
|
2023-09-18 10:58:36 -04:00
|
|
|
g_clear_object (&priv->texture);
|
2021-07-05 09:47:58 -04:00
|
|
|
meta_cursor_sprite_invalidate (sprite);
|
2014-03-31 15:21:19 -04:00
|
|
|
}
|
|
|
|
|
2015-07-17 11:16:39 -04:00
|
|
|
void
|
2018-04-23 10:44:11 -04:00
|
|
|
meta_cursor_sprite_set_texture (MetaCursorSprite *sprite,
|
2015-07-17 11:16:39 -04:00
|
|
|
CoglTexture *texture,
|
|
|
|
int hot_x,
|
|
|
|
int hot_y)
|
2014-03-31 15:21:19 -04:00
|
|
|
{
|
2018-04-23 10:57:01 -04:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
2023-09-18 10:58:36 -04:00
|
|
|
g_clear_object (&priv->texture);
|
2015-07-17 11:16:39 -04:00
|
|
|
if (texture)
|
2023-09-18 10:58:36 -04:00
|
|
|
priv->texture = g_object_ref (COGL_TEXTURE_2D (texture));
|
2018-04-23 10:57:01 -04:00
|
|
|
priv->hot_x = hot_x;
|
|
|
|
priv->hot_y = hot_y;
|
2017-11-16 13:16:54 -05:00
|
|
|
|
2021-07-05 09:47:58 -04:00
|
|
|
meta_cursor_sprite_invalidate (sprite);
|
|
|
|
|
2018-04-23 10:44:11 -04:00
|
|
|
g_signal_emit (sprite, signals[TEXTURE_CHANGED], 0);
|
2014-03-31 17:13:03 -04:00
|
|
|
}
|
|
|
|
|
2015-07-17 11:16:39 -04:00
|
|
|
void
|
2018-04-23 10:44:11 -04:00
|
|
|
meta_cursor_sprite_set_texture_scale (MetaCursorSprite *sprite,
|
2015-07-17 11:16:39 -04:00
|
|
|
float scale)
|
2014-03-31 17:13:03 -04:00
|
|
|
{
|
2018-04-23 10:57:01 -04:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
2021-07-05 09:47:58 -04:00
|
|
|
if (priv->texture_scale != scale)
|
|
|
|
meta_cursor_sprite_invalidate (sprite);
|
|
|
|
|
2018-04-23 10:57:01 -04:00
|
|
|
priv->texture_scale = scale;
|
2015-07-17 11:16:39 -04:00
|
|
|
}
|
2014-03-31 15:21:19 -04:00
|
|
|
|
2019-04-08 12:12:23 -04:00
|
|
|
void
|
|
|
|
meta_cursor_sprite_set_texture_transform (MetaCursorSprite *sprite,
|
|
|
|
MetaMonitorTransform transform)
|
|
|
|
{
|
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
2021-07-05 09:47:58 -04:00
|
|
|
if (priv->texture_transform != transform)
|
|
|
|
meta_cursor_sprite_invalidate (sprite);
|
|
|
|
|
2019-04-08 12:12:23 -04:00
|
|
|
priv->texture_transform = transform;
|
|
|
|
}
|
|
|
|
|
2014-03-31 15:31:15 -04:00
|
|
|
CoglTexture *
|
2018-04-23 10:44:11 -04:00
|
|
|
meta_cursor_sprite_get_cogl_texture (MetaCursorSprite *sprite)
|
2014-03-31 15:31:15 -04:00
|
|
|
{
|
2018-04-23 10:57:01 -04:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
|
|
|
return COGL_TEXTURE (priv->texture);
|
2014-03-31 15:31:15 -04:00
|
|
|
}
|
|
|
|
|
2015-03-10 23:16:58 -04:00
|
|
|
void
|
2018-04-23 10:44:11 -04:00
|
|
|
meta_cursor_sprite_get_hotspot (MetaCursorSprite *sprite,
|
2015-03-10 23:16:58 -04:00
|
|
|
int *hot_x,
|
|
|
|
int *hot_y)
|
|
|
|
{
|
2018-04-23 10:57:01 -04:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
|
|
|
*hot_x = priv->hot_x;
|
|
|
|
*hot_y = priv->hot_y;
|
2014-03-31 15:31:15 -04:00
|
|
|
}
|
2014-04-23 11:04:08 -04:00
|
|
|
|
2020-03-19 03:58:52 -04:00
|
|
|
int
|
|
|
|
meta_cursor_sprite_get_width (MetaCursorSprite *sprite)
|
|
|
|
{
|
|
|
|
CoglTexture *texture;
|
|
|
|
|
|
|
|
texture = meta_cursor_sprite_get_cogl_texture (sprite);
|
|
|
|
return cogl_texture_get_width (texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
meta_cursor_sprite_get_height (MetaCursorSprite *sprite)
|
|
|
|
{
|
|
|
|
CoglTexture *texture;
|
|
|
|
|
|
|
|
texture = meta_cursor_sprite_get_cogl_texture (sprite);
|
|
|
|
return cogl_texture_get_height (texture);
|
|
|
|
}
|
|
|
|
|
2015-07-17 11:16:39 -04:00
|
|
|
float
|
2018-04-23 10:44:11 -04:00
|
|
|
meta_cursor_sprite_get_texture_scale (MetaCursorSprite *sprite)
|
2014-04-23 11:04:08 -04:00
|
|
|
{
|
2018-04-23 10:57:01 -04:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
|
|
|
return priv->texture_scale;
|
2015-03-10 23:16:58 -04:00
|
|
|
}
|
|
|
|
|
2019-04-08 12:12:23 -04:00
|
|
|
MetaMonitorTransform
|
|
|
|
meta_cursor_sprite_get_texture_transform (MetaCursorSprite *sprite)
|
|
|
|
{
|
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
|
|
|
return priv->texture_transform;
|
|
|
|
}
|
|
|
|
|
2021-07-05 10:19:05 -04:00
|
|
|
void
|
|
|
|
meta_cursor_sprite_set_prepare_func (MetaCursorSprite *sprite,
|
|
|
|
MetaCursorPrepareFunc func,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
|
|
|
priv->prepare_func = func;
|
|
|
|
priv->prepare_func_data = user_data;
|
|
|
|
}
|
|
|
|
|
2015-07-17 11:16:39 -04:00
|
|
|
void
|
2020-07-10 06:25:12 -04:00
|
|
|
meta_cursor_sprite_prepare_at (MetaCursorSprite *sprite,
|
|
|
|
float best_scale,
|
|
|
|
int x,
|
|
|
|
int y)
|
2015-07-17 11:16:39 -04:00
|
|
|
{
|
2021-07-05 10:19:05 -04:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
|
|
|
if (priv->prepare_func)
|
|
|
|
priv->prepare_func (sprite, best_scale, x, y, priv->prepare_func_data);
|
2015-07-17 11:16:39 -04:00
|
|
|
}
|
|
|
|
|
2021-07-05 09:47:58 -04:00
|
|
|
gboolean
|
2018-04-23 10:44:11 -04:00
|
|
|
meta_cursor_sprite_realize_texture (MetaCursorSprite *sprite)
|
2015-03-10 23:16:58 -04:00
|
|
|
{
|
2021-07-05 09:47:58 -04:00
|
|
|
return META_CURSOR_SPRITE_GET_CLASS (sprite)->realize_texture (sprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_cursor_sprite_invalidate (MetaCursorSprite *sprite)
|
|
|
|
{
|
|
|
|
MetaCursorSpriteClass *sprite_class = META_CURSOR_SPRITE_GET_CLASS (sprite);
|
|
|
|
|
|
|
|
if (sprite_class->invalidate)
|
|
|
|
sprite_class->invalidate (sprite);
|
2014-04-23 11:04:08 -04:00
|
|
|
}
|
2015-03-10 02:35:49 -04:00
|
|
|
|
|
|
|
static void
|
2018-04-23 10:44:11 -04:00
|
|
|
meta_cursor_sprite_init (MetaCursorSprite *sprite)
|
2015-03-10 02:35:49 -04:00
|
|
|
{
|
2018-04-23 10:57:01 -04:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
|
|
|
priv->texture_scale = 1.0f;
|
2019-04-08 12:12:23 -04:00
|
|
|
priv->texture_transform = META_MONITOR_TRANSFORM_NORMAL;
|
2015-03-10 02:35:49 -04:00
|
|
|
}
|
|
|
|
|
2021-11-15 08:24:53 -05:00
|
|
|
static void
|
|
|
|
meta_cursor_sprite_constructed (GObject *object)
|
|
|
|
{
|
|
|
|
MetaCursorSprite *sprite = META_CURSOR_SPRITE (object);
|
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
|
|
|
g_assert (priv->cursor_tracker);
|
|
|
|
|
|
|
|
meta_cursor_tracker_register_cursor_sprite (priv->cursor_tracker, sprite);
|
|
|
|
|
2023-09-18 10:58:36 -04:00
|
|
|
g_clear_object (&priv->texture);
|
2021-11-15 08:24:53 -05:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_cursor_sprite_parent_class)->constructed (object);
|
|
|
|
}
|
|
|
|
|
2015-03-10 02:35:49 -04:00
|
|
|
static void
|
|
|
|
meta_cursor_sprite_finalize (GObject *object)
|
|
|
|
{
|
2018-04-23 10:44:11 -04:00
|
|
|
MetaCursorSprite *sprite = META_CURSOR_SPRITE (object);
|
2018-04-23 10:57:01 -04:00
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
2015-03-10 02:35:49 -04:00
|
|
|
|
2023-09-18 10:58:36 -04:00
|
|
|
g_clear_object (&priv->texture);
|
2015-03-10 02:35:49 -04:00
|
|
|
|
2021-11-15 08:24:53 -05:00
|
|
|
meta_cursor_tracker_unregister_cursor_sprite (priv->cursor_tracker, sprite);
|
2021-12-22 13:37:16 -05:00
|
|
|
g_clear_object (&priv->cursor_tracker);
|
2021-11-15 08:24:53 -05:00
|
|
|
|
2015-03-10 02:35:49 -04:00
|
|
|
G_OBJECT_CLASS (meta_cursor_sprite_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2021-11-15 08:24:53 -05:00
|
|
|
static void
|
|
|
|
meta_cursor_tracker_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MetaCursorSprite *sprite = META_CURSOR_SPRITE (object);
|
|
|
|
MetaCursorSpritePrivate *priv =
|
|
|
|
meta_cursor_sprite_get_instance_private (sprite);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_CURSOR_TRACKER:
|
2021-12-22 13:37:16 -05:00
|
|
|
g_set_object (&priv->cursor_tracker, g_value_get_object (value));
|
2021-11-15 08:24:53 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-10 02:35:49 -04:00
|
|
|
static void
|
|
|
|
meta_cursor_sprite_class_init (MetaCursorSpriteClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2021-11-15 08:24:53 -05:00
|
|
|
object_class->constructed = meta_cursor_sprite_constructed;
|
2015-03-10 02:35:49 -04:00
|
|
|
object_class->finalize = meta_cursor_sprite_finalize;
|
2021-11-15 08:24:53 -05:00
|
|
|
object_class->set_property = meta_cursor_tracker_set_property;
|
|
|
|
|
|
|
|
obj_props[PROP_CURSOR_TRACKER] =
|
2023-06-28 08:02:43 -04:00
|
|
|
g_param_spec_object ("cursor-tracker", NULL, NULL,
|
2021-11-15 08:24:53 -05:00
|
|
|
META_TYPE_CURSOR_TRACKER,
|
|
|
|
G_PARAM_WRITABLE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
g_object_class_install_properties (object_class, N_PROPS, obj_props);
|
2015-07-17 11:16:39 -04:00
|
|
|
|
2017-11-16 13:16:54 -05:00
|
|
|
signals[TEXTURE_CHANGED] = g_signal_new ("texture-changed",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
2015-03-10 02:35:49 -04:00
|
|
|
}
|