cursor-tracker: Move out more X11:isms to the X11 backend

This includes the xfixes cursor management.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1391
This commit is contained in:
Jonas Ådahl 2020-07-31 21:08:15 +02:00
parent a80b0f34e3
commit 3d19b8f49c
5 changed files with 96 additions and 86 deletions

View File

@ -24,7 +24,6 @@
#include "backends/meta-cursor.h"
#include "backends/meta-cursor-renderer.h"
#include "backends/x11/cm/meta-cursor-sprite-xfixes.h"
#include "meta/meta-cursor-tracker.h"
struct _MetaCursorTrackerClass
@ -33,11 +32,9 @@ struct _MetaCursorTrackerClass
void (* set_force_track_position) (MetaCursorTracker *tracker,
gboolean is_enabled);
MetaCursorSprite * (* get_sprite) (MetaCursorTracker *tracker);
};
gboolean meta_cursor_tracker_handle_xevent (MetaCursorTracker *tracker,
XEvent *xevent);
void meta_cursor_tracker_set_window_cursor (MetaCursorTracker *tracker,
MetaCursorSprite *cursor_sprite);
void meta_cursor_tracker_unset_window_cursor (MetaCursorTracker *tracker);
@ -54,4 +51,6 @@ void meta_cursor_tracker_untrack_position (MetaCursorTracker *tracker);
MetaCursorSprite * meta_cursor_tracker_get_displayed_cursor (MetaCursorTracker *tracker);
void meta_cursor_tracker_notify_cursor_changed (MetaCursorTracker *tracker);
#endif

View File

@ -36,14 +36,12 @@
#include <string.h>
#include "backends/meta-backend-private.h"
#include "backends/x11/cm/meta-cursor-sprite-xfixes.h"
#include "cogl/cogl.h"
#include "core/display-private.h"
#include "clutter/clutter.h"
#include "meta-marshal.h"
#include "meta/main.h"
#include "meta/meta-x11-errors.h"
#include "meta/util.h"
#include "x11/meta-x11-display-private.h"
enum
{
@ -79,9 +77,6 @@ typedef struct _MetaCursorTrackerPrivate
MetaCursorSprite *window_cursor;
MetaCursorSprite *root_cursor;
/* The cursor from the X11 server. */
MetaCursorSpriteXfixes *xfixes_cursor;
} MetaCursorTrackerPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorTracker, meta_cursor_tracker,
@ -97,6 +92,12 @@ enum
static guint signals[LAST_SIGNAL];
void
meta_cursor_tracker_notify_cursor_changed (MetaCursorTracker *tracker)
{
g_signal_emit (tracker, signals[CURSOR_CHANGED], 0);
}
static void
cursor_texture_updated (MetaCursorSprite *cursor,
MetaCursorTracker *tracker)
@ -183,6 +184,15 @@ meta_cursor_tracker_real_set_force_track_position (MetaCursorTracker *tracker,
{
}
static MetaCursorSprite *
meta_cursor_tracker_real_get_sprite (MetaCursorTracker *tracker)
{
MetaCursorTrackerPrivate *priv =
meta_cursor_tracker_get_instance_private (tracker);
return priv->displayed_cursor;
}
static void
meta_cursor_tracker_init (MetaCursorTracker *tracker)
{
@ -261,6 +271,8 @@ meta_cursor_tracker_class_init (MetaCursorTrackerClass *klass)
klass->set_force_track_position =
meta_cursor_tracker_real_set_force_track_position;
klass->get_sprite =
meta_cursor_tracker_real_get_sprite;
obj_props[PROP_BACKEND] =
g_param_spec_object ("backend",
@ -341,47 +353,6 @@ set_window_cursor (MetaCursorTracker *tracker,
sync_cursor (tracker);
}
gboolean
meta_cursor_tracker_handle_xevent (MetaCursorTracker *tracker,
XEvent *xevent)
{
MetaCursorTrackerPrivate *priv =
meta_cursor_tracker_get_instance_private (tracker);
MetaX11Display *x11_display = meta_get_display ()->x11_display;
XFixesCursorNotifyEvent *notify_event;
if (meta_is_wayland_compositor ())
return FALSE;
if (xevent->xany.type != x11_display->xfixes_event_base + XFixesCursorNotify)
return FALSE;
notify_event = (XFixesCursorNotifyEvent *)xevent;
if (notify_event->subtype != XFixesDisplayCursorNotify)
return FALSE;
g_clear_object (&priv->xfixes_cursor);
g_signal_emit (tracker, signals[CURSOR_CHANGED], 0);
return TRUE;
}
static void
ensure_xfixes_cursor (MetaCursorTracker *tracker)
{
MetaCursorTrackerPrivate *priv =
meta_cursor_tracker_get_instance_private (tracker);
MetaDisplay *display = meta_get_display ();
g_autoptr (GError) error = NULL;
if (priv->xfixes_cursor)
return;
priv->xfixes_cursor = meta_cursor_sprite_xfixes_new (display, &error);
if (!priv->xfixes_cursor)
g_warning ("Failed to create XFIXES cursor: %s", error->message);
}
/**
* meta_cursor_tracker_get_sprite:
*
@ -390,32 +361,16 @@ ensure_xfixes_cursor (MetaCursorTracker *tracker)
CoglTexture *
meta_cursor_tracker_get_sprite (MetaCursorTracker *tracker)
{
MetaCursorTrackerPrivate *priv =
meta_cursor_tracker_get_instance_private (tracker);
MetaCursorSprite *cursor_sprite;
g_return_val_if_fail (META_IS_CURSOR_TRACKER (tracker), NULL);
cursor_sprite = META_CURSOR_TRACKER_GET_CLASS (tracker)->get_sprite (tracker);
if (meta_is_wayland_compositor ())
{
cursor_sprite = priv->displayed_cursor;
}
else
{
ensure_xfixes_cursor (tracker);
cursor_sprite = META_CURSOR_SPRITE (priv->xfixes_cursor);
}
if (!cursor_sprite)
return NULL;
if (cursor_sprite)
{
meta_cursor_sprite_realize_texture (cursor_sprite);
return meta_cursor_sprite_get_cogl_texture (cursor_sprite);
}
else
{
return NULL;
}
}
/**
* meta_cursor_tracker_get_hot:
@ -429,21 +384,11 @@ meta_cursor_tracker_get_hot (MetaCursorTracker *tracker,
int *x,
int *y)
{
MetaCursorTrackerPrivate *priv =
meta_cursor_tracker_get_instance_private (tracker);
MetaCursorSprite *cursor_sprite;
g_return_if_fail (META_IS_CURSOR_TRACKER (tracker));
if (meta_is_wayland_compositor ())
{
cursor_sprite = priv->displayed_cursor;
}
else
{
ensure_xfixes_cursor (tracker);
cursor_sprite = META_CURSOR_SPRITE (priv->xfixes_cursor);
}
cursor_sprite = META_CURSOR_TRACKER_GET_CLASS (tracker)->get_sprite (tracker);
if (cursor_sprite)
meta_cursor_sprite_get_hotspot (cursor_sprite, x, y);

View File

@ -22,7 +22,10 @@
#include "backends/x11/meta-cursor-tracker-x11.h"
#include "backends/x11/cm/meta-cursor-sprite-xfixes.h"
#include "clutter/clutter-private.h"
#include "meta/meta-x11-errors.h"
#include "x11/meta-x11-display-private.h"
#define UPDATE_POSITION_TIMEOUT_MS (ms (100))
@ -32,11 +35,36 @@ struct _MetaCursorTrackerX11
gboolean is_force_track_position_enabled;
guint update_position_timeout_id;
MetaCursorSpriteXfixes *xfixes_cursor;
};
G_DEFINE_TYPE (MetaCursorTrackerX11, meta_cursor_tracker_x11,
META_TYPE_CURSOR_TRACKER)
static void
ensure_xfixes_cursor (MetaCursorTrackerX11 *tracker_x11);
gboolean
meta_cursor_tracker_x11_handle_xevent (MetaCursorTrackerX11 *tracker_x11,
XEvent *xevent)
{
MetaX11Display *x11_display = meta_get_display ()->x11_display;
XFixesCursorNotifyEvent *notify_event;
if (xevent->xany.type != x11_display->xfixes_event_base + XFixesCursorNotify)
return FALSE;
notify_event = (XFixesCursorNotifyEvent *)xevent;
if (notify_event->subtype != XFixesDisplayCursorNotify)
return FALSE;
g_clear_object (&tracker_x11->xfixes_cursor);
meta_cursor_tracker_notify_cursor_changed (META_CURSOR_TRACKER (tracker_x11));
return TRUE;
}
static void
update_position (MetaCursorTrackerX11 *tracker_x11)
{
@ -47,6 +75,20 @@ update_position (MetaCursorTrackerX11 *tracker_x11)
meta_cursor_tracker_update_position (tracker, x, y);
}
static void
ensure_xfixes_cursor (MetaCursorTrackerX11 *tracker_x11)
{
MetaDisplay *display = meta_get_display ();
g_autoptr (GError) error = NULL;
if (tracker_x11->xfixes_cursor)
return;
tracker_x11->xfixes_cursor = meta_cursor_sprite_xfixes_new (display, &error);
if (!tracker_x11->xfixes_cursor)
g_warning ("Failed to create XFIXES cursor: %s", error->message);
}
static gboolean
update_position_timeout (gpointer user_data)
{
@ -83,6 +125,18 @@ meta_cursor_tracker_x11_set_force_track_position (MetaCursorTracker *tracker,
}
}
static MetaCursorSprite *
meta_cursor_tracker_x11_get_sprite (MetaCursorTracker *tracker)
{
MetaCursorTrackerX11 *tracker_x11 = META_CURSOR_TRACKER_X11 (tracker);
ensure_xfixes_cursor (META_CURSOR_TRACKER_X11 (tracker));
if (tracker_x11->xfixes_cursor)
return META_CURSOR_SPRITE (tracker_x11->xfixes_cursor);
else
return NULL;
}
static void
meta_cursor_tracker_x11_dispose (GObject *object)
{
@ -108,4 +162,6 @@ meta_cursor_tracker_x11_class_init (MetaCursorTrackerX11Class *klass)
tracker_class->set_force_track_position =
meta_cursor_tracker_x11_set_force_track_position;
tracker_class->get_sprite =
meta_cursor_tracker_x11_get_sprite;
}

View File

@ -28,4 +28,7 @@ G_DECLARE_FINAL_TYPE (MetaCursorTrackerX11, meta_cursor_tracker_x11,
META, CURSOR_TRACKER_X11,
MetaCursorTracker)
gboolean meta_cursor_tracker_x11_handle_xevent (MetaCursorTrackerX11 *tracker_x11,
XEvent *xevent);
#endif /* META_CURSOR_TRACKER_X11_H */

View File

@ -31,6 +31,7 @@
#include "backends/meta-cursor-tracker-private.h"
#include "backends/x11/meta-backend-x11.h"
#include "backends/x11/meta-cursor-tracker-x11.h"
#include "compositor/meta-compositor-x11.h"
#include "cogl/cogl.h"
#include "core/bell.h"
@ -1829,12 +1830,18 @@ meta_x11_display_handle_xevent (MetaX11Display *x11_display,
if (event->xany.window == x11_display->xroot)
{
cursor_tracker = meta_backend_get_cursor_tracker (backend);
if (meta_cursor_tracker_handle_xevent (cursor_tracker, event))
if (META_IS_CURSOR_TRACKER_X11 (cursor_tracker))
{
MetaCursorTrackerX11 *cursor_tracker_x11 =
META_CURSOR_TRACKER_X11 (cursor_tracker);
if (meta_cursor_tracker_x11_handle_xevent (cursor_tracker_x11, event))
{
bypass_gtk = bypass_compositor = TRUE;
goto out;
}
}
}
modified = event_get_modified_window (x11_display, event);