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"
|
|
|
|
#include "cogl/cogl.h"
|
|
|
|
#include "meta/common.h"
|
|
|
|
|
2018-04-26 08:53:01 -04:00
|
|
|
enum
|
|
|
|
{
|
2015-07-17 11:16:39 -04:00
|
|
|
PREPARE_AT,
|
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;
|
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
|
|
|
|
2018-04-27 09:43:37 -04:00
|
|
|
g_clear_pointer (&priv->texture, cogl_object_unref);
|
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);
|
|
|
|
|
|
|
|
g_clear_pointer (&priv->texture, cogl_object_unref);
|
2015-07-17 11:16:39 -04:00
|
|
|
if (texture)
|
2018-04-23 10:57:01 -04:00
|
|
|
priv->texture = cogl_object_ref (texture);
|
|
|
|
priv->hot_x = hot_x;
|
|
|
|
priv->hot_y = hot_y;
|
2017-11-16 13:16:54 -05:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-07-17 11:16:39 -04:00
|
|
|
void
|
2018-04-23 10:44:11 -04:00
|
|
|
meta_cursor_sprite_prepare_at (MetaCursorSprite *sprite,
|
2015-07-17 11:16:39 -04:00
|
|
|
int x,
|
|
|
|
int y)
|
|
|
|
{
|
2018-04-23 10:44:11 -04:00
|
|
|
g_signal_emit (sprite, signals[PREPARE_AT], 0, x, y);
|
2015-07-17 11:16:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-04-23 10:44:11 -04:00
|
|
|
meta_cursor_sprite_realize_texture (MetaCursorSprite *sprite)
|
2015-03-10 23:16:58 -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->realize_texture)
|
|
|
|
klass->realize_texture (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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-04-23 10:57:01 -04:00
|
|
|
g_clear_pointer (&priv->texture, cogl_object_unref);
|
2015-03-10 02:35:49 -04:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_cursor_sprite_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_cursor_sprite_class_init (MetaCursorSpriteClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = meta_cursor_sprite_finalize;
|
2015-07-17 11:16:39 -04:00
|
|
|
|
|
|
|
signals[PREPARE_AT] = g_signal_new ("prepare-at",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT);
|
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
|
|
|
}
|