2014-04-21 18:05:59 -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
|
2023-08-07 05:50:23 -04:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2014-04-21 18:05:59 -04:00
|
|
|
*
|
|
|
|
* Written by:
|
|
|
|
* Jasper St. Pierre <jstpierre@mecheye.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/meta-cursor-renderer.h"
|
2014-04-21 18:05:59 -04:00
|
|
|
|
2016-04-19 05:33:14 -04:00
|
|
|
#include <math.h>
|
2014-08-13 19:46:32 -04:00
|
|
|
|
2020-07-10 06:25:12 -04:00
|
|
|
#include "backends/meta-backend-private.h"
|
|
|
|
#include "backends/meta-logical-monitor.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/meta-stage-private.h"
|
|
|
|
#include "clutter/clutter.h"
|
2019-05-06 09:25:16 -04:00
|
|
|
#include "clutter/clutter-mutter.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "cogl/cogl.h"
|
clutter: Paint views with individual frame clocks
Replace the default master clock with multiple frame clocks, each
driving its own stage view. As each stage view represents one CRTC, this
means we draw each CRTC with its own designated frame clock,
disconnected from all the others.
For example this means we when using the native backend will never need
to wait for one monitor to vsync before painting another, so e.g. having
a 144 Hz monitor next to a 60 Hz monitor, things including both Wayland
and X11 applications and shell UI will be able to render at the
corresponding monitor refresh rate.
This also changes a warning about missed frames when sending
_NETWM_FRAME_TIMINGS messages to a debug log entry, as it's expected
that we'll start missing frames e.g. when a X11 window (via Xwayland) is
exclusively within a stage view that was not painted, while another one
was, still increasing the global frame clock.
Addititonally, this also requires the X11 window actor to schedule
timeouts for _NET_WM_FRAME_DRAWN/_NET_WM_FRAME_TIMINGS event emitting,
if the actor wasn't on any stage views, as now we'll only get the frame
callbacks on actors when they actually were painted, while in the past,
we'd invoke that vfunc when anything was painted.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/903
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285
2020-05-29 18:27:56 -04:00
|
|
|
#include "core/boxes-private.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "meta/meta-backend.h"
|
|
|
|
#include "meta/util.h"
|
2023-07-19 10:59:04 -04:00
|
|
|
#include "mtk/mtk.h"
|
2014-04-21 18:05:59 -04:00
|
|
|
|
2018-09-13 05:28:51 -04:00
|
|
|
G_DEFINE_INTERFACE (MetaHwCursorInhibitor, meta_hw_cursor_inhibitor,
|
|
|
|
G_TYPE_OBJECT)
|
|
|
|
|
2020-05-27 03:29:04 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_BACKEND,
|
2020-07-13 07:32:48 -04:00
|
|
|
PROP_DEVICE,
|
2020-05-27 03:29:04 -04:00
|
|
|
|
|
|
|
N_PROPS
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *obj_props[N_PROPS];
|
|
|
|
|
2014-04-21 18:05:59 -04:00
|
|
|
struct _MetaCursorRendererPrivate
|
|
|
|
{
|
2020-05-27 03:29:04 -04:00
|
|
|
MetaBackend *backend;
|
|
|
|
|
2017-06-08 10:13:16 -04:00
|
|
|
float current_x;
|
|
|
|
float current_y;
|
2014-04-21 18:05:59 -04:00
|
|
|
|
2020-07-13 07:32:48 -04:00
|
|
|
ClutterInputDevice *device;
|
2015-03-09 23:23:00 -04:00
|
|
|
MetaCursorSprite *displayed_cursor;
|
cursor-renderer: Disconnect the overlay cursor from the displayed cursor
The displayed cursor is the one displayed on the screen, e.g. via the
hardware cursor plane, by Xorg, or using the stage overlay.
When screen recording under X11, we don't get a stream of pointer and
cursor updates, as they might be grabbed by some other client. Because
of this, the cursor tracker or cursor renderer are not kept up to date
with positional and cursor state.
To be able to use the stage overlays when recording, we need to be able
to update the overlay without updating the displayed cursor, as we
shouldn't update the X server with cursor state we just retrieved from
it.
Thus, to achieve this, create a separate overlay cursor pointer. When
being a display server, they are always the same, but when using X11,
during screen recording, the overlay one will be polled at a fixed
interval to get a somewhat up to date state.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1391
2020-07-31 15:13:45 -04:00
|
|
|
MetaCursorSprite *overlay_cursor;
|
|
|
|
|
2016-05-02 07:49:13 -04:00
|
|
|
MetaOverlay *stage_overlay;
|
2022-12-21 12:28:35 -05:00
|
|
|
gboolean needs_overlay;
|
2020-05-29 17:10:41 -04:00
|
|
|
gulong after_paint_handler_id;
|
2018-09-13 05:28:51 -04:00
|
|
|
|
|
|
|
GList *hw_cursor_inhibitors;
|
2014-04-21 18:05:59 -04:00
|
|
|
};
|
|
|
|
typedef struct _MetaCursorRendererPrivate MetaCursorRendererPrivate;
|
|
|
|
|
2018-12-19 03:04:25 -05:00
|
|
|
enum
|
|
|
|
{
|
2016-01-10 11:28:54 -05:00
|
|
|
CURSOR_PAINTED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
static guint signals[LAST_SIGNAL];
|
|
|
|
|
2014-04-21 18:05:59 -04:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorRenderer, meta_cursor_renderer, G_TYPE_OBJECT);
|
|
|
|
|
2020-07-13 11:45:41 -04:00
|
|
|
gboolean
|
2020-07-13 11:29:51 -04:00
|
|
|
meta_hw_cursor_inhibitor_is_cursor_inhibited (MetaHwCursorInhibitor *inhibitor)
|
2018-09-13 05:28:51 -04:00
|
|
|
{
|
|
|
|
MetaHwCursorInhibitorInterface *iface =
|
|
|
|
META_HW_CURSOR_INHIBITOR_GET_IFACE (inhibitor);
|
|
|
|
|
2020-07-13 11:29:51 -04:00
|
|
|
return iface->is_cursor_inhibited (inhibitor);
|
2018-09-13 05:28:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_hw_cursor_inhibitor_default_init (MetaHwCursorInhibitorInterface *iface)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-01-10 11:28:54 -05:00
|
|
|
void
|
|
|
|
meta_cursor_renderer_emit_painted (MetaCursorRenderer *renderer,
|
2021-02-02 08:49:56 -05:00
|
|
|
MetaCursorSprite *cursor_sprite,
|
|
|
|
ClutterStageView *stage_view)
|
2016-01-10 11:28:54 -05:00
|
|
|
{
|
2021-02-02 08:49:56 -05:00
|
|
|
g_signal_emit (renderer, signals[CURSOR_PAINTED], 0, cursor_sprite, stage_view);
|
2016-01-10 11:28:54 -05:00
|
|
|
}
|
|
|
|
|
2019-05-06 09:25:16 -04:00
|
|
|
static void
|
|
|
|
align_cursor_position (MetaCursorRenderer *renderer,
|
2019-02-20 10:23:04 -05:00
|
|
|
graphene_rect_t *rect)
|
2019-05-06 09:25:16 -04:00
|
|
|
{
|
|
|
|
MetaCursorRendererPrivate *priv =
|
|
|
|
meta_cursor_renderer_get_instance_private (renderer);
|
2020-05-27 03:29:04 -04:00
|
|
|
ClutterActor *stage = meta_backend_get_stage (priv->backend);
|
2019-05-06 09:25:16 -04:00
|
|
|
ClutterStageView *view;
|
2023-07-19 10:59:04 -04:00
|
|
|
MtkRectangle view_layout;
|
2019-05-06 09:25:16 -04:00
|
|
|
float view_scale;
|
|
|
|
|
|
|
|
view = clutter_stage_get_view_at (CLUTTER_STAGE (stage),
|
|
|
|
priv->current_x,
|
|
|
|
priv->current_y);
|
|
|
|
if (!view)
|
|
|
|
return;
|
|
|
|
|
|
|
|
clutter_stage_view_get_layout (view, &view_layout);
|
|
|
|
view_scale = clutter_stage_view_get_scale (view);
|
|
|
|
|
2019-02-20 10:23:04 -05:00
|
|
|
graphene_rect_offset (rect, -view_layout.x, -view_layout.y);
|
2019-05-06 09:25:16 -04:00
|
|
|
rect->origin.x = floorf (rect->origin.x * view_scale) / view_scale;
|
|
|
|
rect->origin.y = floorf (rect->origin.y * view_scale) / view_scale;
|
2019-02-20 10:23:04 -05:00
|
|
|
graphene_rect_offset (rect, view_layout.x, view_layout.y);
|
2019-05-06 09:25:16 -04:00
|
|
|
}
|
|
|
|
|
cursor-renderer: Disconnect the overlay cursor from the displayed cursor
The displayed cursor is the one displayed on the screen, e.g. via the
hardware cursor plane, by Xorg, or using the stage overlay.
When screen recording under X11, we don't get a stream of pointer and
cursor updates, as they might be grabbed by some other client. Because
of this, the cursor tracker or cursor renderer are not kept up to date
with positional and cursor state.
To be able to use the stage overlays when recording, we need to be able
to update the overlay without updating the displayed cursor, as we
shouldn't update the X server with cursor state we just retrieved from
it.
Thus, to achieve this, create a separate overlay cursor pointer. When
being a display server, they are always the same, but when using X11,
during screen recording, the overlay one will be polled at a fixed
interval to get a somewhat up to date state.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1391
2020-07-31 15:13:45 -04:00
|
|
|
void
|
|
|
|
meta_cursor_renderer_update_stage_overlay (MetaCursorRenderer *renderer,
|
|
|
|
MetaCursorSprite *cursor_sprite)
|
2014-04-21 18:05:59 -04:00
|
|
|
{
|
|
|
|
MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
|
2020-05-27 03:29:04 -04:00
|
|
|
ClutterActor *stage = meta_backend_get_stage (priv->backend);
|
2022-06-22 08:08:24 -04:00
|
|
|
CoglTexture *texture = NULL;
|
2019-02-20 10:23:04 -05:00
|
|
|
graphene_rect_t rect = GRAPHENE_RECT_INIT_ZERO;
|
2022-06-22 08:08:24 -04:00
|
|
|
MetaMonitorTransform buffer_transform = META_MONITOR_TRANSFORM_NORMAL;
|
2015-07-17 11:16:39 -04:00
|
|
|
|
cursor-renderer: Disconnect the overlay cursor from the displayed cursor
The displayed cursor is the one displayed on the screen, e.g. via the
hardware cursor plane, by Xorg, or using the stage overlay.
When screen recording under X11, we don't get a stream of pointer and
cursor updates, as they might be grabbed by some other client. Because
of this, the cursor tracker or cursor renderer are not kept up to date
with positional and cursor state.
To be able to use the stage overlays when recording, we need to be able
to update the overlay without updating the displayed cursor, as we
shouldn't update the X server with cursor state we just retrieved from
it.
Thus, to achieve this, create a separate overlay cursor pointer. When
being a display server, they are always the same, but when using X11,
during screen recording, the overlay one will be polled at a fixed
interval to get a somewhat up to date state.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1391
2020-07-31 15:13:45 -04:00
|
|
|
g_set_object (&priv->overlay_cursor, cursor_sprite);
|
|
|
|
|
2019-05-06 09:25:16 -04:00
|
|
|
if (cursor_sprite)
|
|
|
|
{
|
|
|
|
rect = meta_cursor_renderer_calculate_rect (renderer, cursor_sprite);
|
|
|
|
align_cursor_position (renderer, &rect);
|
|
|
|
}
|
|
|
|
|
2016-05-02 07:49:13 -04:00
|
|
|
if (!priv->stage_overlay)
|
|
|
|
priv->stage_overlay = meta_stage_create_cursor_overlay (META_STAGE (stage));
|
|
|
|
|
2020-07-29 04:32:58 -04:00
|
|
|
if (cursor_sprite)
|
2022-06-22 08:08:24 -04:00
|
|
|
{
|
|
|
|
texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
|
|
|
|
buffer_transform =
|
|
|
|
meta_cursor_sprite_get_texture_transform (cursor_sprite);
|
|
|
|
}
|
2014-08-21 15:00:03 -04:00
|
|
|
|
2022-12-21 12:28:35 -05:00
|
|
|
meta_overlay_set_visible (priv->stage_overlay, priv->needs_overlay);
|
2016-05-02 07:49:13 -04:00
|
|
|
meta_stage_update_cursor_overlay (META_STAGE (stage), priv->stage_overlay,
|
2022-06-22 08:08:24 -04:00
|
|
|
texture, &rect, buffer_transform);
|
2014-04-21 18:05:59 -04:00
|
|
|
}
|
|
|
|
|
2020-05-29 17:10:41 -04:00
|
|
|
static void
|
|
|
|
meta_cursor_renderer_after_paint (ClutterStage *stage,
|
clutter: Paint views with individual frame clocks
Replace the default master clock with multiple frame clocks, each
driving its own stage view. As each stage view represents one CRTC, this
means we draw each CRTC with its own designated frame clock,
disconnected from all the others.
For example this means we when using the native backend will never need
to wait for one monitor to vsync before painting another, so e.g. having
a 144 Hz monitor next to a 60 Hz monitor, things including both Wayland
and X11 applications and shell UI will be able to render at the
corresponding monitor refresh rate.
This also changes a warning about missed frames when sending
_NETWM_FRAME_TIMINGS messages to a debug log entry, as it's expected
that we'll start missing frames e.g. when a X11 window (via Xwayland) is
exclusively within a stage view that was not painted, while another one
was, still increasing the global frame clock.
Addititonally, this also requires the X11 window actor to schedule
timeouts for _NET_WM_FRAME_DRAWN/_NET_WM_FRAME_TIMINGS event emitting,
if the actor wasn't on any stage views, as now we'll only get the frame
callbacks on actors when they actually were painted, while in the past,
we'd invoke that vfunc when anything was painted.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/903
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285
2020-05-29 18:27:56 -04:00
|
|
|
ClutterStageView *stage_view,
|
2022-10-13 11:50:34 -04:00
|
|
|
ClutterFrame *frame,
|
2020-05-29 17:10:41 -04:00
|
|
|
MetaCursorRenderer *renderer)
|
2016-01-10 11:28:54 -05:00
|
|
|
{
|
|
|
|
MetaCursorRendererPrivate *priv =
|
|
|
|
meta_cursor_renderer_get_instance_private (renderer);
|
|
|
|
|
2022-12-21 12:28:35 -05:00
|
|
|
if (priv->displayed_cursor && priv->needs_overlay)
|
clutter: Paint views with individual frame clocks
Replace the default master clock with multiple frame clocks, each
driving its own stage view. As each stage view represents one CRTC, this
means we draw each CRTC with its own designated frame clock,
disconnected from all the others.
For example this means we when using the native backend will never need
to wait for one monitor to vsync before painting another, so e.g. having
a 144 Hz monitor next to a 60 Hz monitor, things including both Wayland
and X11 applications and shell UI will be able to render at the
corresponding monitor refresh rate.
This also changes a warning about missed frames when sending
_NETWM_FRAME_TIMINGS messages to a debug log entry, as it's expected
that we'll start missing frames e.g. when a X11 window (via Xwayland) is
exclusively within a stage view that was not painted, while another one
was, still increasing the global frame clock.
Addititonally, this also requires the X11 window actor to schedule
timeouts for _NET_WM_FRAME_DRAWN/_NET_WM_FRAME_TIMINGS event emitting,
if the actor wasn't on any stage views, as now we'll only get the frame
callbacks on actors when they actually were painted, while in the past,
we'd invoke that vfunc when anything was painted.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/903
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285
2020-05-29 18:27:56 -04:00
|
|
|
{
|
|
|
|
graphene_rect_t rect;
|
2023-07-19 19:46:15 -04:00
|
|
|
MtkRectangle view_layout;
|
clutter: Paint views with individual frame clocks
Replace the default master clock with multiple frame clocks, each
driving its own stage view. As each stage view represents one CRTC, this
means we draw each CRTC with its own designated frame clock,
disconnected from all the others.
For example this means we when using the native backend will never need
to wait for one monitor to vsync before painting another, so e.g. having
a 144 Hz monitor next to a 60 Hz monitor, things including both Wayland
and X11 applications and shell UI will be able to render at the
corresponding monitor refresh rate.
This also changes a warning about missed frames when sending
_NETWM_FRAME_TIMINGS messages to a debug log entry, as it's expected
that we'll start missing frames e.g. when a X11 window (via Xwayland) is
exclusively within a stage view that was not painted, while another one
was, still increasing the global frame clock.
Addititonally, this also requires the X11 window actor to schedule
timeouts for _NET_WM_FRAME_DRAWN/_NET_WM_FRAME_TIMINGS event emitting,
if the actor wasn't on any stage views, as now we'll only get the frame
callbacks on actors when they actually were painted, while in the past,
we'd invoke that vfunc when anything was painted.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/903
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285
2020-05-29 18:27:56 -04:00
|
|
|
graphene_rect_t view_rect;
|
|
|
|
|
|
|
|
rect = meta_cursor_renderer_calculate_rect (renderer,
|
|
|
|
priv->displayed_cursor);
|
|
|
|
clutter_stage_view_get_layout (stage_view, &view_layout);
|
2023-08-08 06:27:58 -04:00
|
|
|
view_rect = mtk_rectangle_to_graphene_rect (&view_layout);
|
clutter: Paint views with individual frame clocks
Replace the default master clock with multiple frame clocks, each
driving its own stage view. As each stage view represents one CRTC, this
means we draw each CRTC with its own designated frame clock,
disconnected from all the others.
For example this means we when using the native backend will never need
to wait for one monitor to vsync before painting another, so e.g. having
a 144 Hz monitor next to a 60 Hz monitor, things including both Wayland
and X11 applications and shell UI will be able to render at the
corresponding monitor refresh rate.
This also changes a warning about missed frames when sending
_NETWM_FRAME_TIMINGS messages to a debug log entry, as it's expected
that we'll start missing frames e.g. when a X11 window (via Xwayland) is
exclusively within a stage view that was not painted, while another one
was, still increasing the global frame clock.
Addititonally, this also requires the X11 window actor to schedule
timeouts for _NET_WM_FRAME_DRAWN/_NET_WM_FRAME_TIMINGS event emitting,
if the actor wasn't on any stage views, as now we'll only get the frame
callbacks on actors when they actually were painted, while in the past,
we'd invoke that vfunc when anything was painted.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/903
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285
2020-05-29 18:27:56 -04:00
|
|
|
if (graphene_rect_intersection (&rect, &view_rect, NULL))
|
2021-02-02 08:49:56 -05:00
|
|
|
{
|
|
|
|
meta_cursor_renderer_emit_painted (renderer,
|
|
|
|
priv->displayed_cursor,
|
|
|
|
stage_view);
|
|
|
|
}
|
clutter: Paint views with individual frame clocks
Replace the default master clock with multiple frame clocks, each
driving its own stage view. As each stage view represents one CRTC, this
means we draw each CRTC with its own designated frame clock,
disconnected from all the others.
For example this means we when using the native backend will never need
to wait for one monitor to vsync before painting another, so e.g. having
a 144 Hz monitor next to a 60 Hz monitor, things including both Wayland
and X11 applications and shell UI will be able to render at the
corresponding monitor refresh rate.
This also changes a warning about missed frames when sending
_NETWM_FRAME_TIMINGS messages to a debug log entry, as it's expected
that we'll start missing frames e.g. when a X11 window (via Xwayland) is
exclusively within a stage view that was not painted, while another one
was, still increasing the global frame clock.
Addititonally, this also requires the X11 window actor to schedule
timeouts for _NET_WM_FRAME_DRAWN/_NET_WM_FRAME_TIMINGS event emitting,
if the actor wasn't on any stage views, as now we'll only get the frame
callbacks on actors when they actually were painted, while in the past,
we'd invoke that vfunc when anything was painted.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/903
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285
2020-05-29 18:27:56 -04:00
|
|
|
}
|
2016-01-10 11:28:54 -05:00
|
|
|
}
|
|
|
|
|
2014-05-17 11:22:05 -04:00
|
|
|
static gboolean
|
2015-07-17 11:16:39 -04:00
|
|
|
meta_cursor_renderer_real_update_cursor (MetaCursorRenderer *renderer,
|
|
|
|
MetaCursorSprite *cursor_sprite)
|
2014-04-22 15:39:09 -04:00
|
|
|
{
|
2015-10-22 08:43:46 -04:00
|
|
|
if (cursor_sprite)
|
|
|
|
meta_cursor_sprite_realize_texture (cursor_sprite);
|
|
|
|
|
2023-08-25 14:07:36 -04:00
|
|
|
return TRUE;
|
2014-04-22 15:15:11 -04:00
|
|
|
}
|
2014-04-22 15:39:09 -04:00
|
|
|
|
2020-05-27 03:29:04 -04:00
|
|
|
static void
|
|
|
|
meta_cursor_renderer_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MetaCursorRenderer *renderer = META_CURSOR_RENDERER (object);
|
|
|
|
MetaCursorRendererPrivate *priv =
|
|
|
|
meta_cursor_renderer_get_instance_private (renderer);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_BACKEND:
|
|
|
|
g_value_set_object (value, priv->backend);
|
|
|
|
break;
|
2020-07-13 07:32:48 -04:00
|
|
|
case PROP_DEVICE:
|
|
|
|
g_value_set_object (value, priv->device);
|
|
|
|
break;
|
2020-05-27 03:29:04 -04:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_cursor_renderer_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MetaCursorRenderer *renderer = META_CURSOR_RENDERER (object);
|
|
|
|
MetaCursorRendererPrivate *priv =
|
|
|
|
meta_cursor_renderer_get_instance_private (renderer);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_BACKEND:
|
|
|
|
priv->backend = g_value_get_object (value);
|
|
|
|
break;
|
2020-07-13 07:32:48 -04:00
|
|
|
case PROP_DEVICE:
|
|
|
|
priv->device = g_value_get_object (value);
|
|
|
|
break;
|
2020-05-27 03:29:04 -04:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-02 07:49:13 -04:00
|
|
|
static void
|
|
|
|
meta_cursor_renderer_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaCursorRenderer *renderer = META_CURSOR_RENDERER (object);
|
|
|
|
MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
|
2020-05-27 03:29:04 -04:00
|
|
|
ClutterActor *stage = meta_backend_get_stage (priv->backend);
|
2016-05-02 07:49:13 -04:00
|
|
|
|
|
|
|
if (priv->stage_overlay)
|
|
|
|
meta_stage_remove_cursor_overlay (META_STAGE (stage), priv->stage_overlay);
|
|
|
|
|
2020-05-29 17:10:41 -04:00
|
|
|
g_clear_signal_handler (&priv->after_paint_handler_id, stage);
|
2016-01-10 11:28:54 -05:00
|
|
|
|
2020-07-31 15:10:34 -04:00
|
|
|
g_clear_object (&priv->displayed_cursor);
|
cursor-renderer: Disconnect the overlay cursor from the displayed cursor
The displayed cursor is the one displayed on the screen, e.g. via the
hardware cursor plane, by Xorg, or using the stage overlay.
When screen recording under X11, we don't get a stream of pointer and
cursor updates, as they might be grabbed by some other client. Because
of this, the cursor tracker or cursor renderer are not kept up to date
with positional and cursor state.
To be able to use the stage overlays when recording, we need to be able
to update the overlay without updating the displayed cursor, as we
shouldn't update the X server with cursor state we just retrieved from
it.
Thus, to achieve this, create a separate overlay cursor pointer. When
being a display server, they are always the same, but when using X11,
during screen recording, the overlay one will be polled at a fixed
interval to get a somewhat up to date state.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1391
2020-07-31 15:13:45 -04:00
|
|
|
g_clear_object (&priv->overlay_cursor);
|
2020-07-31 15:10:34 -04:00
|
|
|
|
2016-05-02 07:49:13 -04:00
|
|
|
G_OBJECT_CLASS (meta_cursor_renderer_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2020-05-29 17:10:41 -04:00
|
|
|
static void
|
|
|
|
meta_cursor_renderer_constructed (GObject *object)
|
|
|
|
{
|
|
|
|
MetaCursorRenderer *renderer = META_CURSOR_RENDERER (object);
|
|
|
|
MetaCursorRendererPrivate *priv =
|
|
|
|
meta_cursor_renderer_get_instance_private (renderer);
|
|
|
|
ClutterActor *stage;
|
|
|
|
|
|
|
|
stage = meta_backend_get_stage (priv->backend);
|
|
|
|
priv->after_paint_handler_id =
|
|
|
|
g_signal_connect (stage, "after-paint",
|
|
|
|
G_CALLBACK (meta_cursor_renderer_after_paint),
|
|
|
|
renderer);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_cursor_renderer_parent_class)->constructed (object);
|
|
|
|
}
|
|
|
|
|
2014-04-22 15:15:11 -04:00
|
|
|
static void
|
|
|
|
meta_cursor_renderer_class_init (MetaCursorRendererClass *klass)
|
|
|
|
{
|
2016-05-02 07:49:13 -04:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2020-05-27 03:29:04 -04:00
|
|
|
object_class->get_property = meta_cursor_renderer_get_property;
|
|
|
|
object_class->set_property = meta_cursor_renderer_set_property;
|
2016-05-02 07:49:13 -04:00
|
|
|
object_class->finalize = meta_cursor_renderer_finalize;
|
2020-05-29 17:10:41 -04:00
|
|
|
object_class->constructed = meta_cursor_renderer_constructed;
|
2014-04-22 15:15:11 -04:00
|
|
|
klass->update_cursor = meta_cursor_renderer_real_update_cursor;
|
2016-01-10 11:28:54 -05:00
|
|
|
|
2020-05-27 03:29:04 -04:00
|
|
|
obj_props[PROP_BACKEND] =
|
2023-06-28 08:02:43 -04:00
|
|
|
g_param_spec_object ("backend", NULL, NULL,
|
2020-05-27 03:29:04 -04:00
|
|
|
META_TYPE_BACKEND,
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2020-07-13 07:32:48 -04:00
|
|
|
obj_props[PROP_DEVICE] =
|
2023-06-28 08:02:43 -04:00
|
|
|
g_param_spec_object ("device", NULL, NULL,
|
2020-07-13 07:32:48 -04:00
|
|
|
CLUTTER_TYPE_INPUT_DEVICE,
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2020-05-27 03:29:04 -04:00
|
|
|
g_object_class_install_properties (object_class, N_PROPS, obj_props);
|
|
|
|
|
2016-01-10 11:28:54 -05:00
|
|
|
signals[CURSOR_PAINTED] = g_signal_new ("cursor-painted",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
2021-02-02 08:49:56 -05:00
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
G_TYPE_POINTER,
|
|
|
|
CLUTTER_TYPE_STAGE_VIEW);
|
2014-04-22 15:15:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_cursor_renderer_init (MetaCursorRenderer *renderer)
|
|
|
|
{
|
2014-04-22 15:39:09 -04:00
|
|
|
}
|
|
|
|
|
2022-12-21 12:59:55 -05:00
|
|
|
static gboolean
|
|
|
|
calculate_sprite_geometry (MetaCursorSprite *cursor_sprite,
|
|
|
|
graphene_size_t *size,
|
|
|
|
graphene_point_t *hotspot)
|
2015-07-17 11:16:39 -04:00
|
|
|
{
|
|
|
|
CoglTexture *texture;
|
|
|
|
int hot_x, hot_y;
|
|
|
|
int width, height;
|
|
|
|
float texture_scale;
|
|
|
|
|
2023-01-25 12:44:29 -05:00
|
|
|
meta_cursor_sprite_realize_texture (cursor_sprite);
|
2015-07-17 11:16:39 -04:00
|
|
|
texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
|
|
|
|
if (!texture)
|
2022-12-21 12:59:55 -05:00
|
|
|
return FALSE;
|
2015-07-17 11:16:39 -04:00
|
|
|
|
|
|
|
meta_cursor_sprite_get_hotspot (cursor_sprite, &hot_x, &hot_y);
|
|
|
|
texture_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite);
|
|
|
|
width = cogl_texture_get_width (texture);
|
|
|
|
height = cogl_texture_get_height (texture);
|
|
|
|
|
2022-12-21 12:59:55 -05:00
|
|
|
*size = (graphene_size_t) {
|
|
|
|
.width = width * texture_scale,
|
|
|
|
.height = height * texture_scale
|
|
|
|
};
|
|
|
|
*hotspot = (graphene_point_t) {
|
|
|
|
.x = hot_x * texture_scale,
|
|
|
|
.y = hot_y * texture_scale
|
2015-07-17 11:16:39 -04:00
|
|
|
};
|
2022-12-21 12:59:55 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
graphene_rect_t
|
|
|
|
meta_cursor_renderer_calculate_rect (MetaCursorRenderer *renderer,
|
|
|
|
MetaCursorSprite *cursor_sprite)
|
|
|
|
{
|
|
|
|
MetaCursorRendererPrivate *priv =
|
|
|
|
meta_cursor_renderer_get_instance_private (renderer);
|
|
|
|
graphene_rect_t rect = GRAPHENE_RECT_INIT_ZERO;
|
|
|
|
graphene_point_t hotspot;
|
|
|
|
|
|
|
|
if (!calculate_sprite_geometry (cursor_sprite, &rect.size, &hotspot))
|
|
|
|
return GRAPHENE_RECT_INIT_ZERO;
|
|
|
|
|
|
|
|
rect.origin = (graphene_point_t) { .x = -hotspot.x, .y = -hotspot.y };
|
|
|
|
graphene_rect_offset (&rect, priv->current_x, priv->current_y);
|
|
|
|
return rect;
|
2015-07-17 11:16:39 -04:00
|
|
|
}
|
|
|
|
|
2020-07-10 06:25:12 -04:00
|
|
|
static float
|
|
|
|
find_highest_logical_monitor_scale (MetaBackend *backend,
|
|
|
|
MetaCursorSprite *cursor_sprite)
|
|
|
|
{
|
|
|
|
MetaMonitorManager *monitor_manager =
|
|
|
|
meta_backend_get_monitor_manager (backend);
|
|
|
|
MetaCursorRenderer *cursor_renderer =
|
|
|
|
meta_backend_get_cursor_renderer (backend);
|
|
|
|
graphene_rect_t cursor_rect;
|
|
|
|
GList *logical_monitors;
|
|
|
|
GList *l;
|
|
|
|
float highest_scale = 0.0f;
|
|
|
|
|
|
|
|
cursor_rect = meta_cursor_renderer_calculate_rect (cursor_renderer,
|
|
|
|
cursor_sprite);
|
|
|
|
|
|
|
|
logical_monitors =
|
|
|
|
meta_monitor_manager_get_logical_monitors (monitor_manager);
|
|
|
|
for (l = logical_monitors; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaLogicalMonitor *logical_monitor = l->data;
|
|
|
|
graphene_rect_t logical_monitor_rect =
|
2023-08-08 06:27:58 -04:00
|
|
|
mtk_rectangle_to_graphene_rect (&logical_monitor->rect);
|
2020-07-10 06:25:12 -04:00
|
|
|
|
|
|
|
if (!graphene_rect_intersection (&cursor_rect,
|
|
|
|
&logical_monitor_rect,
|
|
|
|
NULL))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
highest_scale = MAX (highest_scale, logical_monitor->scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
return highest_scale;
|
|
|
|
}
|
|
|
|
|
2014-04-21 18:05:59 -04:00
|
|
|
static void
|
2018-05-09 11:59:32 -04:00
|
|
|
meta_cursor_renderer_update_cursor (MetaCursorRenderer *renderer,
|
|
|
|
MetaCursorSprite *cursor_sprite)
|
2014-04-21 18:05:59 -04:00
|
|
|
{
|
|
|
|
MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
|
|
|
|
|
2015-07-17 11:16:39 -04:00
|
|
|
if (cursor_sprite)
|
2020-07-10 06:25:12 -04:00
|
|
|
{
|
|
|
|
float scale = find_highest_logical_monitor_scale (priv->backend,
|
|
|
|
cursor_sprite);
|
|
|
|
meta_cursor_sprite_prepare_at (cursor_sprite,
|
|
|
|
MAX (1, scale),
|
|
|
|
(int) priv->current_x,
|
|
|
|
(int) priv->current_y);
|
|
|
|
}
|
2014-04-21 18:05:59 -04:00
|
|
|
|
2022-12-21 12:28:35 -05:00
|
|
|
priv->needs_overlay =
|
2015-07-17 11:16:39 -04:00
|
|
|
META_CURSOR_RENDERER_GET_CLASS (renderer)->update_cursor (renderer,
|
|
|
|
cursor_sprite);
|
2014-05-17 11:22:05 -04:00
|
|
|
|
cursor-renderer: Disconnect the overlay cursor from the displayed cursor
The displayed cursor is the one displayed on the screen, e.g. via the
hardware cursor plane, by Xorg, or using the stage overlay.
When screen recording under X11, we don't get a stream of pointer and
cursor updates, as they might be grabbed by some other client. Because
of this, the cursor tracker or cursor renderer are not kept up to date
with positional and cursor state.
To be able to use the stage overlays when recording, we need to be able
to update the overlay without updating the displayed cursor, as we
shouldn't update the X server with cursor state we just retrieved from
it.
Thus, to achieve this, create a separate overlay cursor pointer. When
being a display server, they are always the same, but when using X11,
during screen recording, the overlay one will be polled at a fixed
interval to get a somewhat up to date state.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1391
2020-07-31 15:13:45 -04:00
|
|
|
meta_cursor_renderer_update_stage_overlay (renderer, cursor_sprite);
|
2014-04-21 18:05:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MetaCursorRenderer *
|
2020-07-13 07:32:48 -04:00
|
|
|
meta_cursor_renderer_new (MetaBackend *backend,
|
|
|
|
ClutterInputDevice *device)
|
2014-04-21 18:05:59 -04:00
|
|
|
{
|
2020-05-27 03:29:04 -04:00
|
|
|
return g_object_new (META_TYPE_CURSOR_RENDERER,
|
|
|
|
"backend", backend,
|
2020-07-13 07:32:48 -04:00
|
|
|
"device", device,
|
2020-05-27 03:29:04 -04:00
|
|
|
NULL);
|
2014-04-21 18:05:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-09 23:23:00 -04:00
|
|
|
meta_cursor_renderer_set_cursor (MetaCursorRenderer *renderer,
|
|
|
|
MetaCursorSprite *cursor_sprite)
|
2014-04-21 18:05:59 -04:00
|
|
|
{
|
|
|
|
MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
|
|
|
|
|
2015-03-09 23:23:00 -04:00
|
|
|
if (priv->displayed_cursor == cursor_sprite)
|
2014-04-21 18:05:59 -04:00
|
|
|
return;
|
2020-07-31 15:10:34 -04:00
|
|
|
g_set_object (&priv->displayed_cursor, cursor_sprite);
|
2015-07-17 11:16:39 -04:00
|
|
|
|
2018-05-09 11:59:32 -04:00
|
|
|
meta_cursor_renderer_update_cursor (renderer, cursor_sprite);
|
2014-04-21 18:05:59 -04:00
|
|
|
}
|
|
|
|
|
2015-07-13 14:36:05 -04:00
|
|
|
void
|
|
|
|
meta_cursor_renderer_force_update (MetaCursorRenderer *renderer)
|
|
|
|
{
|
2015-07-17 11:16:39 -04:00
|
|
|
MetaCursorRendererPrivate *priv =
|
|
|
|
meta_cursor_renderer_get_instance_private (renderer);
|
|
|
|
|
2018-05-09 11:59:32 -04:00
|
|
|
meta_cursor_renderer_update_cursor (renderer, priv->displayed_cursor);
|
2015-07-13 14:36:05 -04:00
|
|
|
}
|
|
|
|
|
2014-04-21 18:05:59 -04:00
|
|
|
void
|
2020-07-13 08:09:44 -04:00
|
|
|
meta_cursor_renderer_update_position (MetaCursorRenderer *renderer)
|
2014-04-21 18:05:59 -04:00
|
|
|
{
|
|
|
|
MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
|
2020-07-13 08:09:44 -04:00
|
|
|
graphene_point_t pos;
|
2014-04-21 18:05:59 -04:00
|
|
|
|
2020-11-18 09:49:02 -05:00
|
|
|
clutter_seat_query_state (clutter_input_device_get_seat (priv->device),
|
|
|
|
priv->device, NULL, &pos, NULL);
|
2020-07-13 08:09:44 -04:00
|
|
|
priv->current_x = pos.x;
|
|
|
|
priv->current_y = pos.y;
|
2014-04-21 18:05:59 -04:00
|
|
|
|
2018-05-09 11:59:32 -04:00
|
|
|
meta_cursor_renderer_update_cursor (renderer, priv->displayed_cursor);
|
2014-04-21 18:05:59 -04:00
|
|
|
}
|
|
|
|
|
2015-03-09 23:23:00 -04:00
|
|
|
MetaCursorSprite *
|
2014-04-22 15:15:11 -04:00
|
|
|
meta_cursor_renderer_get_cursor (MetaCursorRenderer *renderer)
|
2014-04-21 18:05:59 -04:00
|
|
|
{
|
2014-04-22 15:15:11 -04:00
|
|
|
MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
|
2014-04-21 18:05:59 -04:00
|
|
|
|
cursor-renderer: Disconnect the overlay cursor from the displayed cursor
The displayed cursor is the one displayed on the screen, e.g. via the
hardware cursor plane, by Xorg, or using the stage overlay.
When screen recording under X11, we don't get a stream of pointer and
cursor updates, as they might be grabbed by some other client. Because
of this, the cursor tracker or cursor renderer are not kept up to date
with positional and cursor state.
To be able to use the stage overlays when recording, we need to be able
to update the overlay without updating the displayed cursor, as we
shouldn't update the X server with cursor state we just retrieved from
it.
Thus, to achieve this, create a separate overlay cursor pointer. When
being a display server, they are always the same, but when using X11,
during screen recording, the overlay one will be polled at a fixed
interval to get a somewhat up to date state.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1391
2020-07-31 15:13:45 -04:00
|
|
|
return priv->overlay_cursor;
|
2014-04-21 18:05:59 -04:00
|
|
|
}
|
2018-09-13 05:28:51 -04:00
|
|
|
|
2020-07-13 07:32:48 -04:00
|
|
|
ClutterInputDevice *
|
|
|
|
meta_cursor_renderer_get_input_device (MetaCursorRenderer *renderer)
|
|
|
|
{
|
|
|
|
MetaCursorRendererPrivate *priv =
|
|
|
|
meta_cursor_renderer_get_instance_private (renderer);
|
|
|
|
|
|
|
|
return priv->device;
|
|
|
|
}
|
2022-05-27 13:35:01 -04:00
|
|
|
|
|
|
|
MetaBackend *
|
|
|
|
meta_cursor_renderer_get_backend (MetaCursorRenderer *renderer)
|
|
|
|
{
|
|
|
|
MetaCursorRendererPrivate *priv =
|
|
|
|
meta_cursor_renderer_get_instance_private (renderer);
|
|
|
|
|
|
|
|
return priv->backend;
|
|
|
|
}
|