Make ShellXFixesCursor work under wayland
Replace ClutterX11 with GdkX11 + Mutter, so that it works when Clutter is not using the X11 backend. FIXME: doesn't work...
This commit is contained in:
parent
2754a5e3a1
commit
30898007f3
@ -53,7 +53,7 @@ const Magnifier = new Lang.Class({
|
|||||||
this._zoomRegions = [];
|
this._zoomRegions = [];
|
||||||
|
|
||||||
// Create small clutter tree for the magnified mouse.
|
// Create small clutter tree for the magnified mouse.
|
||||||
let xfixesCursor = Shell.XFixesCursor.get_for_stage(global.stage);
|
let xfixesCursor = Shell.XFixesCursor.get_for_screen(global.screen);
|
||||||
this._mouseSprite = new Clutter.Texture();
|
this._mouseSprite = new Clutter.Texture();
|
||||||
xfixesCursor.update_texture_image(this._mouseSprite);
|
xfixesCursor.update_texture_image(this._mouseSprite);
|
||||||
this._cursorRoot = new Clutter.Actor();
|
this._cursorRoot = new Clutter.Actor();
|
||||||
@ -83,7 +83,7 @@ const Magnifier = new Lang.Class({
|
|||||||
* Show the system mouse pointer.
|
* Show the system mouse pointer.
|
||||||
*/
|
*/
|
||||||
showSystemCursor: function() {
|
showSystemCursor: function() {
|
||||||
this._xfixesCursor.show();
|
global.stage.show_cursor();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,7 +91,7 @@ const Magnifier = new Lang.Class({
|
|||||||
* Hide the system mouse pointer.
|
* Hide the system mouse pointer.
|
||||||
*/
|
*/
|
||||||
hideSystemCursor: function() {
|
hideSystemCursor: function() {
|
||||||
this._xfixesCursor.hide();
|
global.stage.hide_cursor();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,7 +112,7 @@ const Magnifier = new Lang.Class({
|
|||||||
// Make sure system mouse pointer is shown when all zoom regions are
|
// Make sure system mouse pointer is shown when all zoom regions are
|
||||||
// invisible.
|
// invisible.
|
||||||
if (!activate)
|
if (!activate)
|
||||||
this._xfixesCursor.show();
|
global.stage.show_cursor();
|
||||||
|
|
||||||
// Notify interested parties of this change
|
// Notify interested parties of this change
|
||||||
this.emit('active-changed', activate);
|
this.emit('active-changed', activate);
|
||||||
|
@ -4,8 +4,11 @@
|
|||||||
|
|
||||||
#include "shell-xfixes-cursor.h"
|
#include "shell-xfixes-cursor.h"
|
||||||
|
|
||||||
#include <clutter/x11/clutter-x11.h>
|
#include <gdk/gdkx.h>
|
||||||
#include <X11/extensions/Xfixes.h>
|
#include <X11/extensions/Xfixes.h>
|
||||||
|
#include <meta/display.h>
|
||||||
|
#include <meta/screen.h>
|
||||||
|
#include <meta/util.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:shell-xfixes-cursor
|
* SECTION:shell-xfixes-cursor
|
||||||
@ -24,7 +27,7 @@ struct _ShellXFixesCursorClass
|
|||||||
struct _ShellXFixesCursor {
|
struct _ShellXFixesCursor {
|
||||||
GObject parent;
|
GObject parent;
|
||||||
|
|
||||||
ClutterStage *stage;
|
MetaScreen *screen;
|
||||||
|
|
||||||
gboolean have_xfixes;
|
gboolean have_xfixes;
|
||||||
int xfixes_event_base;
|
int xfixes_event_base;
|
||||||
@ -36,17 +39,14 @@ struct _ShellXFixesCursor {
|
|||||||
int cursor_hot_y;
|
int cursor_hot_y;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void xfixes_cursor_show (ShellXFixesCursor *xfixes_cursor);
|
static void xfixes_cursor_set_screen (ShellXFixesCursor *xfixes_cursor,
|
||||||
static void xfixes_cursor_hide (ShellXFixesCursor *xfixes_cursor);
|
MetaScreen *screen);
|
||||||
|
|
||||||
static void xfixes_cursor_set_stage (ShellXFixesCursor *xfixes_cursor,
|
|
||||||
ClutterStage *stage);
|
|
||||||
|
|
||||||
static void xfixes_cursor_reset_image (ShellXFixesCursor *xfixes_cursor);
|
static void xfixes_cursor_reset_image (ShellXFixesCursor *xfixes_cursor);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_STAGE,
|
PROP_SCREEN,
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE(ShellXFixesCursor, shell_xfixes_cursor, G_TYPE_OBJECT);
|
G_DEFINE_TYPE(ShellXFixesCursor, shell_xfixes_cursor, G_TYPE_OBJECT);
|
||||||
@ -71,31 +71,22 @@ shell_xfixes_cursor_finalize (GObject *object)
|
|||||||
{
|
{
|
||||||
ShellXFixesCursor *xfixes_cursor = SHELL_XFIXES_CURSOR (object);
|
ShellXFixesCursor *xfixes_cursor = SHELL_XFIXES_CURSOR (object);
|
||||||
|
|
||||||
// Make sure the system cursor is showing before leaving the stage.
|
xfixes_cursor_set_screen (xfixes_cursor, NULL);
|
||||||
xfixes_cursor_show (xfixes_cursor);
|
|
||||||
xfixes_cursor_set_stage (xfixes_cursor, NULL);
|
|
||||||
if (xfixes_cursor->cursor_sprite != NULL)
|
if (xfixes_cursor->cursor_sprite != NULL)
|
||||||
cogl_handle_unref (xfixes_cursor->cursor_sprite);
|
cogl_handle_unref (xfixes_cursor->cursor_sprite);
|
||||||
|
|
||||||
G_OBJECT_CLASS (shell_xfixes_cursor_parent_class)->finalize (object);
|
G_OBJECT_CLASS (shell_xfixes_cursor_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static GdkFilterReturn
|
||||||
xfixes_cursor_on_stage_destroy (ClutterActor *actor,
|
xfixes_cursor_event_filter (XEvent *xev,
|
||||||
ShellXFixesCursor *xfixes_cursor)
|
GdkEvent *ev,
|
||||||
{
|
gpointer data)
|
||||||
xfixes_cursor_set_stage (xfixes_cursor, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ClutterX11FilterReturn
|
|
||||||
xfixes_cursor_event_filter (XEvent *xev,
|
|
||||||
ClutterEvent *cev,
|
|
||||||
gpointer data)
|
|
||||||
{
|
{
|
||||||
ShellXFixesCursor *xfixes_cursor = data;
|
ShellXFixesCursor *xfixes_cursor = data;
|
||||||
|
|
||||||
if (xev->xany.window != clutter_x11_get_stage_window (xfixes_cursor->stage))
|
if (xev->xany.window != meta_get_overlay_window (xfixes_cursor->screen))
|
||||||
return CLUTTER_X11_FILTER_CONTINUE;
|
return GDK_FILTER_CONTINUE;
|
||||||
|
|
||||||
if (xev->xany.type == xfixes_cursor->xfixes_event_base + XFixesCursorNotify)
|
if (xev->xany.type == xfixes_cursor->xfixes_event_base + XFixesCursorNotify)
|
||||||
{
|
{
|
||||||
@ -103,93 +94,43 @@ xfixes_cursor_event_filter (XEvent *xev,
|
|||||||
if (notify_event->subtype == XFixesDisplayCursorNotify)
|
if (notify_event->subtype == XFixesDisplayCursorNotify)
|
||||||
xfixes_cursor_reset_image (xfixes_cursor);
|
xfixes_cursor_reset_image (xfixes_cursor);
|
||||||
}
|
}
|
||||||
return CLUTTER_X11_FILTER_CONTINUE;
|
|
||||||
|
return GDK_FILTER_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xfixes_cursor_set_stage (ShellXFixesCursor *xfixes_cursor,
|
xfixes_cursor_set_screen (ShellXFixesCursor *xfixes_cursor,
|
||||||
ClutterStage *stage)
|
MetaScreen *screen)
|
||||||
{
|
{
|
||||||
if (xfixes_cursor->stage == stage)
|
if (xfixes_cursor->screen == screen)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (xfixes_cursor->stage)
|
if (xfixes_cursor->screen)
|
||||||
{
|
{
|
||||||
g_signal_handlers_disconnect_by_func (xfixes_cursor->stage,
|
gdk_window_remove_filter (NULL, (GdkFilterFunc)xfixes_cursor_event_filter, xfixes_cursor);
|
||||||
(void *)xfixes_cursor_on_stage_destroy,
|
|
||||||
xfixes_cursor);
|
|
||||||
|
|
||||||
clutter_x11_remove_filter (xfixes_cursor_event_filter, xfixes_cursor);
|
|
||||||
}
|
}
|
||||||
xfixes_cursor->stage = stage;
|
|
||||||
if (xfixes_cursor->stage)
|
xfixes_cursor->screen = screen;
|
||||||
|
if (xfixes_cursor->screen)
|
||||||
{
|
{
|
||||||
int error_base;
|
int error_base;
|
||||||
|
|
||||||
xfixes_cursor->stage = stage;
|
gdk_window_add_filter (NULL, (GdkFilterFunc)xfixes_cursor_event_filter, xfixes_cursor);
|
||||||
g_signal_connect (xfixes_cursor->stage, "destroy",
|
|
||||||
G_CALLBACK (xfixes_cursor_on_stage_destroy), xfixes_cursor);
|
|
||||||
|
|
||||||
clutter_x11_add_filter (xfixes_cursor_event_filter, xfixes_cursor);
|
xfixes_cursor->have_xfixes = XFixesQueryExtension (gdk_x11_get_default_xdisplay (),
|
||||||
|
|
||||||
xfixes_cursor->have_xfixes = XFixesQueryExtension (clutter_x11_get_default_display (),
|
|
||||||
&xfixes_cursor->xfixes_event_base,
|
&xfixes_cursor->xfixes_event_base,
|
||||||
&error_base);
|
&error_base);
|
||||||
if (xfixes_cursor->have_xfixes)
|
|
||||||
XFixesSelectCursorInput (clutter_x11_get_default_display (),
|
/* FIXME: this needs to be moved down to mutter as a whole */
|
||||||
clutter_x11_get_stage_window (stage),
|
if (xfixes_cursor->have_xfixes && !meta_is_display_server())
|
||||||
|
XFixesSelectCursorInput (gdk_x11_get_default_xdisplay (),
|
||||||
|
meta_get_overlay_window (screen),
|
||||||
XFixesDisplayCursorNotifyMask);
|
XFixesDisplayCursorNotifyMask);
|
||||||
|
|
||||||
xfixes_cursor_reset_image (xfixes_cursor);
|
xfixes_cursor_reset_image (xfixes_cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
xfixes_cursor_show (ShellXFixesCursor *xfixes_cursor)
|
|
||||||
{
|
|
||||||
int minor, major;
|
|
||||||
Display *xdisplay;
|
|
||||||
Window xwindow;
|
|
||||||
|
|
||||||
if (xfixes_cursor->is_showing == TRUE)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!xfixes_cursor->have_xfixes || !xfixes_cursor->stage)
|
|
||||||
return;
|
|
||||||
|
|
||||||
xdisplay = clutter_x11_get_default_display ();
|
|
||||||
xwindow = clutter_x11_get_stage_window (xfixes_cursor->stage);
|
|
||||||
XFixesQueryVersion (xdisplay, &major, &minor);
|
|
||||||
if (major >= 4)
|
|
||||||
{
|
|
||||||
XFixesShowCursor (xdisplay, xwindow);
|
|
||||||
xfixes_cursor->is_showing = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
xfixes_cursor_hide (ShellXFixesCursor *xfixes_cursor)
|
|
||||||
{
|
|
||||||
int minor, major;
|
|
||||||
Display *xdisplay;
|
|
||||||
Window xwindow;
|
|
||||||
|
|
||||||
if (xfixes_cursor->is_showing == FALSE)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!xfixes_cursor->have_xfixes || !xfixes_cursor->stage)
|
|
||||||
return;
|
|
||||||
|
|
||||||
xdisplay = clutter_x11_get_default_display ();
|
|
||||||
xwindow = clutter_x11_get_stage_window (xfixes_cursor->stage);
|
|
||||||
XFixesQueryVersion (xdisplay, &major, &minor);
|
|
||||||
if (major >= 4)
|
|
||||||
{
|
|
||||||
XFixesHideCursor (xdisplay, xwindow);
|
|
||||||
xfixes_cursor->is_showing = FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xfixes_cursor_reset_image (ShellXFixesCursor *xfixes_cursor)
|
xfixes_cursor_reset_image (ShellXFixesCursor *xfixes_cursor)
|
||||||
{
|
{
|
||||||
@ -201,7 +142,7 @@ xfixes_cursor_reset_image (ShellXFixesCursor *xfixes_cursor)
|
|||||||
if (!xfixes_cursor->have_xfixes)
|
if (!xfixes_cursor->have_xfixes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cursor_image = XFixesGetCursorImage (clutter_x11_get_default_display ());
|
cursor_image = XFixesGetCursorImage (gdk_x11_get_default_xdisplay ());
|
||||||
if (!cursor_image)
|
if (!cursor_image)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -265,8 +206,8 @@ shell_xfixes_cursor_set_property (GObject *object,
|
|||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
case PROP_STAGE:
|
case PROP_SCREEN:
|
||||||
xfixes_cursor_set_stage (xfixes_cursor, g_value_get_object (value));
|
xfixes_cursor_set_screen (xfixes_cursor, g_value_get_object (value));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
@ -284,8 +225,8 @@ shell_xfixes_cursor_get_property (GObject *object,
|
|||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
case PROP_STAGE:
|
case PROP_SCREEN:
|
||||||
g_value_set_object (value, G_OBJECT (xfixes_cursor->stage));
|
g_value_set_object (value, G_OBJECT (xfixes_cursor->screen));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
@ -311,22 +252,22 @@ shell_xfixes_cursor_class_init (ShellXFixesCursorClass *klass)
|
|||||||
gobject_class->set_property = shell_xfixes_cursor_set_property;
|
gobject_class->set_property = shell_xfixes_cursor_set_property;
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class,
|
g_object_class_install_property (gobject_class,
|
||||||
PROP_STAGE,
|
PROP_SCREEN,
|
||||||
g_param_spec_object ("stage",
|
g_param_spec_object ("screen",
|
||||||
"Stage",
|
"Screen",
|
||||||
"Stage for mouse cursor",
|
"Screen for mouse cursor",
|
||||||
CLUTTER_TYPE_STAGE,
|
META_TYPE_SCREEN,
|
||||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shell_xfixes_cursor_get_for_stage:
|
* shell_xfixes_cursor_get_for_screen:
|
||||||
* @stage: (transfer none): The #ClutterStage to get the cursor for
|
* @screen: (transfer none): The #MetaScreen to get the cursor for
|
||||||
*
|
*
|
||||||
* Return value: (transfer none): A #ShellXFixesCursor instance
|
* Return value: (transfer none): A #ShellXFixesCursor instance
|
||||||
*/
|
*/
|
||||||
ShellXFixesCursor *
|
ShellXFixesCursor *
|
||||||
shell_xfixes_cursor_get_for_stage (ClutterStage *stage)
|
shell_xfixes_cursor_get_for_screen (MetaScreen *screen)
|
||||||
{
|
{
|
||||||
ShellXFixesCursor *instance;
|
ShellXFixesCursor *instance;
|
||||||
static GQuark xfixes_cursor_quark;
|
static GQuark xfixes_cursor_quark;
|
||||||
@ -334,47 +275,19 @@ shell_xfixes_cursor_get_for_stage (ClutterStage *stage)
|
|||||||
if (G_UNLIKELY (xfixes_cursor_quark == 0))
|
if (G_UNLIKELY (xfixes_cursor_quark == 0))
|
||||||
xfixes_cursor_quark = g_quark_from_static_string ("gnome-shell-xfixes-cursor");
|
xfixes_cursor_quark = g_quark_from_static_string ("gnome-shell-xfixes-cursor");
|
||||||
|
|
||||||
instance = g_object_get_qdata (G_OBJECT (stage), xfixes_cursor_quark);
|
instance = g_object_get_qdata (G_OBJECT (screen), xfixes_cursor_quark);
|
||||||
|
|
||||||
if (instance == NULL)
|
if (instance == NULL)
|
||||||
{
|
{
|
||||||
instance = g_object_new (SHELL_TYPE_XFIXES_CURSOR,
|
instance = g_object_new (SHELL_TYPE_XFIXES_CURSOR,
|
||||||
"stage", stage,
|
"screen", screen,
|
||||||
NULL);
|
NULL);
|
||||||
g_object_set_qdata (G_OBJECT (stage), xfixes_cursor_quark, instance);
|
g_object_set_qdata (G_OBJECT (screen), xfixes_cursor_quark, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* shell_xfixes_cursor_hide:
|
|
||||||
* @xfixes_cursor: the #ShellXFixesCursor
|
|
||||||
*
|
|
||||||
* Hide the system mouse cursor.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
shell_xfixes_cursor_hide (ShellXFixesCursor *xfixes_cursor)
|
|
||||||
{
|
|
||||||
g_return_if_fail (SHELL_IS_XFIXES_CURSOR (xfixes_cursor));
|
|
||||||
|
|
||||||
xfixes_cursor_hide (xfixes_cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* shell_xfixes_cursor_show:
|
|
||||||
* @xfixes_cursor: the #ShellXFixesCursor
|
|
||||||
*
|
|
||||||
* Show the system mouse cursor to show
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
shell_xfixes_cursor_show (ShellXFixesCursor *xfixes_cursor)
|
|
||||||
{
|
|
||||||
g_return_if_fail (SHELL_IS_XFIXES_CURSOR (xfixes_cursor));
|
|
||||||
|
|
||||||
xfixes_cursor_show (xfixes_cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shell_xfixes_cursor_update_texture_image:
|
* shell_xfixes_cursor_update_texture_image:
|
||||||
* @xfixes_cursor: the #ShellXFixesCursor
|
* @xfixes_cursor: the #ShellXFixesCursor
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <clutter/clutter.h>
|
#include <clutter/clutter.h>
|
||||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||||
|
#include <meta/screen.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -19,10 +20,8 @@ typedef struct _ShellXFixesCursorClass ShellXFixesCursorClass;
|
|||||||
|
|
||||||
GType shell_xfixes_cursor_get_type (void) G_GNUC_CONST;
|
GType shell_xfixes_cursor_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
ShellXFixesCursor *shell_xfixes_cursor_get_for_stage (ClutterStage *stage);
|
ShellXFixesCursor *shell_xfixes_cursor_get_for_screen (MetaScreen *screen);
|
||||||
|
|
||||||
void shell_xfixes_cursor_show (ShellXFixesCursor *xfixes_cursor);
|
|
||||||
void shell_xfixes_cursor_hide (ShellXFixesCursor *xfixes_cursor);
|
|
||||||
int shell_xfixes_cursor_get_hot_x (ShellXFixesCursor *xfixes_cursor);
|
int shell_xfixes_cursor_get_hot_x (ShellXFixesCursor *xfixes_cursor);
|
||||||
int shell_xfixes_cursor_get_hot_y (ShellXFixesCursor *xfixes_cursor);
|
int shell_xfixes_cursor_get_hot_y (ShellXFixesCursor *xfixes_cursor);
|
||||||
void shell_xfixes_cursor_update_texture_image (ShellXFixesCursor *xfixes_cursor,
|
void shell_xfixes_cursor_update_texture_image (ShellXFixesCursor *xfixes_cursor,
|
||||||
|
Loading…
Reference in New Issue
Block a user