Compare commits
18 Commits
wip/split-
...
wip/ui-on-
Author | SHA1 | Date | |
---|---|---|---|
5bc7ae4095 | |||
1a78515606 | |||
4122257bce | |||
29f6e3bda5 | |||
bbcbf5820f | |||
ee7c58984a | |||
03e5bbf59f | |||
cc6becb163 | |||
e3b855a583 | |||
5d8dd0653e | |||
abe94827f5 | |||
72b88c929e | |||
4752776ebf | |||
c40868b239 | |||
a21e7a2188 | |||
371fba6843 | |||
be02fa1120 | |||
43730f1660 |
@ -133,7 +133,7 @@ AC_ARG_WITH([wayland-protocols],
|
||||
AC_ARG_WITH([xwayland-path],
|
||||
[AS_HELP_STRING([--with-xwayland-path], [Absolute path for an X Wayland server])],
|
||||
[XWAYLAND_PATH="$withval"],
|
||||
[XWAYLAND_PATH="$bindir/Xorg"])
|
||||
[XWAYLAND_PATH="$bindir/Xwayland"])
|
||||
|
||||
AM_GLIB_GNU_GETTEXT
|
||||
|
||||
|
@ -41,14 +41,11 @@ mutter_built_sources = \
|
||||
gtk-shell-protocol.c \
|
||||
gtk-shell-server-protocol.h \
|
||||
xdg-shell-protocol.c \
|
||||
xdg-shell-server-protocol.h \
|
||||
xserver-protocol.c \
|
||||
xserver-server-protocol.h
|
||||
xdg-shell-server-protocol.h
|
||||
|
||||
wayland_protocols = \
|
||||
wayland/protocol/gtk-shell.xml \
|
||||
wayland/protocol/xdg-shell.xml \
|
||||
wayland/protocol/xserver.xml
|
||||
wayland/protocol/xdg-shell.xml
|
||||
|
||||
libmutter_wayland_la_SOURCES = \
|
||||
backends/meta-backend.c \
|
||||
@ -70,16 +67,12 @@ libmutter_wayland_la_SOURCES = \
|
||||
backends/meta-monitor-manager-dummy.h \
|
||||
backends/edid-parse.c \
|
||||
backends/edid.h \
|
||||
backends/native/meta-cursor-tracker-native.c \
|
||||
backends/native/meta-cursor-tracker-native.h \
|
||||
backends/native/meta-idle-monitor-native.c \
|
||||
backends/native/meta-idle-monitor-native.h \
|
||||
backends/native/meta-monitor-manager-kms.c \
|
||||
backends/native/meta-monitor-manager-kms.h \
|
||||
backends/native/meta-weston-launch.c \
|
||||
backends/native/meta-weston-launch.h \
|
||||
backends/x11/meta-cursor-tracker-x11.c \
|
||||
backends/x11/meta-cursor-tracker-x11.h \
|
||||
backends/x11/meta-idle-monitor-xsync.c \
|
||||
backends/x11/meta-idle-monitor-xsync.h \
|
||||
backends/x11/meta-monitor-manager-xrandr.c \
|
||||
@ -218,8 +211,9 @@ libmutter_wayland_la_SOURCES = \
|
||||
wayland/meta-wayland.c \
|
||||
wayland/meta-wayland.h \
|
||||
wayland/meta-wayland-private.h \
|
||||
wayland/meta-xwayland-private.h \
|
||||
wayland/meta-xwayland.c \
|
||||
wayland/meta-xwayland.h \
|
||||
wayland/meta-xwayland-private.h \
|
||||
wayland/meta-wayland-data-device.c \
|
||||
wayland/meta-wayland-data-device.h \
|
||||
wayland/meta-wayland-keyboard.c \
|
||||
|
@ -27,11 +27,6 @@
|
||||
#include <cogl/cogl.h>
|
||||
#include <gbm.h>
|
||||
|
||||
#include <X11/cursorfont.h>
|
||||
#include <X11/extensions/Xfixes.h>
|
||||
#include <X11/Xcursor/Xcursor.h>
|
||||
#include <wayland-server.h>
|
||||
|
||||
typedef struct {
|
||||
CoglTexture2D *texture;
|
||||
struct gbm_bo *bo;
|
||||
@ -52,26 +47,4 @@ struct gbm_bo *meta_cursor_reference_get_gbm_bo (MetaCursorReference *cursor,
|
||||
int *hot_x,
|
||||
int *hot_y);
|
||||
|
||||
void meta_cursor_reference_load_gbm_buffer (MetaCursorReference *cursor,
|
||||
struct gbm_device *gbm,
|
||||
uint8_t *pixels,
|
||||
int width,
|
||||
int height,
|
||||
int rowstride,
|
||||
uint32_t gbm_format);
|
||||
|
||||
void meta_cursor_reference_import_gbm_buffer (MetaCursorReference *cursor,
|
||||
struct gbm_device *gbm,
|
||||
struct wl_resource *buffer,
|
||||
int width,
|
||||
int height);
|
||||
|
||||
MetaCursorReference *meta_cursor_reference_from_xfixes_cursor_image (XFixesCursorImage *cursor_image);
|
||||
|
||||
MetaCursorReference *meta_cursor_reference_from_xcursor_image (XcursorImage *xc_image);
|
||||
|
||||
MetaCursorReference *meta_cursor_reference_from_buffer (struct wl_resource *buffer,
|
||||
int hot_x,
|
||||
int hot_y);
|
||||
|
||||
#endif /* META_CURSOR_PRIVATE_H */
|
||||
|
@ -30,7 +30,10 @@
|
||||
struct _MetaCursorTracker {
|
||||
GObject parent_instance;
|
||||
|
||||
MetaScreen *screen;
|
||||
|
||||
gboolean is_showing;
|
||||
gboolean has_hw_cursor;
|
||||
|
||||
/* The cursor tracker stores the cursor for the current grab
|
||||
* operation, the cursor for the window with pointer focus, and
|
||||
@ -46,15 +49,9 @@ struct _MetaCursorTracker {
|
||||
*/
|
||||
MetaCursorReference *displayed_cursor;
|
||||
|
||||
/* This is the cursor that would be displayed if we hadn't been
|
||||
* asked to hide it. i.e. it's the same as displayed_cursor unless
|
||||
* is_showing is false.
|
||||
*/
|
||||
MetaCursorReference *current_cursor;
|
||||
|
||||
MetaCursorReference *grab_cursor;
|
||||
|
||||
/* Wayland clients can set a NULL buffer as their cursor
|
||||
/* Wayland clients can set a NULL buffer as their cursor
|
||||
* explicitly, which means that we shouldn't display anything.
|
||||
* So, we can't simply store a NULL in window_cursor to
|
||||
* determine an unset window cursor; we need an extra boolean.
|
||||
@ -65,37 +62,23 @@ struct _MetaCursorTracker {
|
||||
MetaCursorReference *root_cursor;
|
||||
|
||||
MetaCursorReference *theme_cursors[META_CURSOR_LAST];
|
||||
|
||||
int current_x, current_y;
|
||||
MetaRectangle current_rect;
|
||||
MetaRectangle previous_rect;
|
||||
gboolean previous_is_valid;
|
||||
|
||||
CoglPipeline *pipeline;
|
||||
int drm_fd;
|
||||
struct gbm_device *gbm;
|
||||
};
|
||||
|
||||
struct _MetaCursorTrackerClass {
|
||||
GObjectClass parent_class;
|
||||
|
||||
void (*get_pointer) (MetaCursorTracker *tracker,
|
||||
int *x,
|
||||
int *y,
|
||||
ClutterModifierType *mods);
|
||||
|
||||
void (*sync_cursor) (MetaCursorTracker *tracker);
|
||||
|
||||
void (*ensure_cursor) (MetaCursorTracker *tracker);
|
||||
|
||||
void (*load_cursor_pixels) (MetaCursorTracker *tracker,
|
||||
MetaCursorReference *cursor,
|
||||
uint8_t *pixels,
|
||||
int width,
|
||||
int height,
|
||||
int rowstride,
|
||||
uint32_t format);
|
||||
|
||||
void (*load_cursor_buffer) (MetaCursorTracker *tracker,
|
||||
MetaCursorReference *cursor,
|
||||
struct wl_resource *buffer);
|
||||
};
|
||||
|
||||
void _meta_cursor_tracker_set_window_cursor (MetaCursorTracker *tracker,
|
||||
gboolean has_cursor,
|
||||
MetaCursorReference *cursor);
|
||||
void _meta_cursor_tracker_sync_cursor (MetaCursorTracker *tracker);
|
||||
gboolean meta_cursor_tracker_handle_xevent (MetaCursorTracker *tracker,
|
||||
XEvent *xevent);
|
||||
|
||||
void meta_cursor_tracker_set_grab_cursor (MetaCursorTracker *tracker,
|
||||
MetaCursorReference *cursor);
|
||||
@ -104,13 +87,12 @@ void meta_cursor_tracker_set_window_cursor (MetaCursorTracker *tracker,
|
||||
void meta_cursor_tracker_unset_window_cursor (MetaCursorTracker *tracker);
|
||||
void meta_cursor_tracker_set_root_cursor (MetaCursorTracker *tracker,
|
||||
MetaCursorReference *cursor);
|
||||
MetaCursorReference *
|
||||
meta_cursor_tracker_get_cursor_from_theme (MetaCursorTracker *tracker,
|
||||
MetaCursor cursor);
|
||||
MetaCursorReference *
|
||||
meta_cursor_tracker_get_cursor_from_buffer (MetaCursorTracker *tracker,
|
||||
struct wl_resource *buffer,
|
||||
int hot_x,
|
||||
int hot_y);
|
||||
|
||||
void meta_cursor_tracker_update_position (MetaCursorTracker *tracker,
|
||||
int new_x,
|
||||
int new_y);
|
||||
void meta_cursor_tracker_paint (MetaCursorTracker *tracker);
|
||||
|
||||
void meta_cursor_tracker_force_update (MetaCursorTracker *tracker);
|
||||
|
||||
#endif
|
||||
|
@ -33,11 +33,20 @@
|
||||
#include <meta/util.h>
|
||||
#include <meta/errors.h>
|
||||
|
||||
#include <cogl/cogl.h>
|
||||
#include <cogl/cogl-wayland-server.h>
|
||||
#include <clutter/clutter.h>
|
||||
#include <gbm.h>
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
#include "meta-cursor-private.h"
|
||||
#include "meta-cursor-tracker-private.h"
|
||||
#include "backends/native/meta-cursor-tracker-native.h"
|
||||
#include "backends/x11/meta-cursor-tracker-x11.h"
|
||||
#include "screen-private.h"
|
||||
#include "meta-monitor-manager.h"
|
||||
|
||||
#include "wayland/meta-wayland-private.h"
|
||||
|
||||
G_DEFINE_TYPE (MetaCursorTracker, meta_cursor_tracker, G_TYPE_OBJECT);
|
||||
|
||||
@ -48,6 +57,11 @@ enum {
|
||||
|
||||
static guint signals[LAST_SIGNAL];
|
||||
|
||||
static void meta_cursor_tracker_set_crtc_has_hw_cursor (MetaCursorTracker *tracker,
|
||||
MetaCRTC *crtc,
|
||||
gboolean has_hw_cursor);
|
||||
static void sync_cursor (MetaCursorTracker *tracker);
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_init (MetaCursorTracker *self)
|
||||
{
|
||||
@ -74,32 +88,14 @@ meta_cursor_tracker_finalize (GObject *object)
|
||||
if (self->theme_cursors[i])
|
||||
meta_cursor_reference_unref (self->theme_cursors[i]);
|
||||
|
||||
if (self->pipeline)
|
||||
cogl_object_unref (self->pipeline);
|
||||
if (self->gbm)
|
||||
gbm_device_destroy (self->gbm);
|
||||
|
||||
G_OBJECT_CLASS (meta_cursor_tracker_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
default_do_nothing (MetaCursorTracker *tracker)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
default_load_cursor_pixels (MetaCursorTracker *tracker,
|
||||
MetaCursorReference *cursor,
|
||||
uint8_t *pixels,
|
||||
int width,
|
||||
int height,
|
||||
int rowstride,
|
||||
uint32_t format)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
default_load_cursor_buffer (MetaCursorTracker *tracker,
|
||||
MetaCursorReference *cursor,
|
||||
struct wl_resource *buffer)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_class_init (MetaCursorTrackerClass *klass)
|
||||
{
|
||||
@ -107,11 +103,6 @@ meta_cursor_tracker_class_init (MetaCursorTrackerClass *klass)
|
||||
|
||||
object_class->finalize = meta_cursor_tracker_finalize;
|
||||
|
||||
klass->sync_cursor = default_do_nothing;
|
||||
klass->ensure_cursor = default_do_nothing;
|
||||
klass->load_cursor_pixels = default_load_cursor_pixels;
|
||||
klass->load_cursor_buffer = default_load_cursor_buffer;
|
||||
|
||||
signals[CURSOR_CHANGED] = g_signal_new ("cursor-changed",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
@ -120,6 +111,81 @@ meta_cursor_tracker_class_init (MetaCursorTrackerClass *klass)
|
||||
G_TYPE_NONE, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
on_monitors_changed (MetaMonitorManager *monitors,
|
||||
MetaCursorTracker *tracker)
|
||||
{
|
||||
MetaCRTC *crtcs;
|
||||
unsigned int i, n_crtcs;
|
||||
|
||||
if (!tracker->has_hw_cursor)
|
||||
return;
|
||||
|
||||
/* Go through the new list of monitors, find out where the cursor is */
|
||||
meta_monitor_manager_get_resources (monitors, NULL, NULL, &crtcs, &n_crtcs, NULL, NULL);
|
||||
|
||||
for (i = 0; i < n_crtcs; i++)
|
||||
{
|
||||
MetaRectangle *rect = &crtcs[i].rect;
|
||||
gboolean has;
|
||||
|
||||
has = meta_rectangle_overlap (&tracker->current_rect, rect);
|
||||
|
||||
/* Need to do it unconditionally here, our tracking is
|
||||
wrong because we reloaded the CRTCs */
|
||||
meta_cursor_tracker_set_crtc_has_hw_cursor (tracker, &crtcs[i], has);
|
||||
}
|
||||
}
|
||||
|
||||
static MetaCursorTracker *
|
||||
make_wayland_cursor_tracker (MetaScreen *screen)
|
||||
{
|
||||
MetaWaylandCompositor *compositor;
|
||||
CoglContext *ctx;
|
||||
MetaMonitorManager *monitors;
|
||||
MetaCursorTracker *self;
|
||||
|
||||
self = g_object_new (META_TYPE_CURSOR_TRACKER, NULL);
|
||||
self->screen = screen;
|
||||
|
||||
ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
||||
self->pipeline = cogl_pipeline_new (ctx);
|
||||
|
||||
compositor = meta_wayland_compositor_get_default ();
|
||||
compositor->seat->cursor_tracker = self;
|
||||
meta_cursor_tracker_update_position (self,
|
||||
wl_fixed_to_int (compositor->seat->pointer.x),
|
||||
wl_fixed_to_int (compositor->seat->pointer.y));
|
||||
|
||||
#if defined(CLUTTER_WINDOWING_EGL)
|
||||
if (clutter_check_windowing_backend (CLUTTER_WINDOWING_EGL))
|
||||
{
|
||||
CoglRenderer *cogl_renderer = cogl_display_get_renderer (cogl_context_get_display (ctx));
|
||||
self->drm_fd = cogl_kms_renderer_get_kms_fd (cogl_renderer);
|
||||
self->gbm = gbm_create_device (self->drm_fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
monitors = meta_monitor_manager_get ();
|
||||
g_signal_connect_object (monitors, "monitors-changed",
|
||||
G_CALLBACK (on_monitors_changed), self, 0);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static MetaCursorTracker *
|
||||
make_x11_cursor_tracker (MetaScreen *screen)
|
||||
{
|
||||
MetaCursorTracker *self = g_object_new (META_TYPE_CURSOR_TRACKER, NULL);
|
||||
self->screen = screen;
|
||||
|
||||
XFixesSelectCursorInput (screen->display->xdisplay,
|
||||
screen->xroot,
|
||||
XFixesDisplayCursorNotifyMask);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* meta_cursor_tracker_get_for_screen:
|
||||
* @screen: the #MetaScreen
|
||||
@ -137,14 +203,127 @@ meta_cursor_tracker_get_for_screen (MetaScreen *screen)
|
||||
return screen->cursor_tracker;
|
||||
|
||||
if (meta_is_wayland_compositor ())
|
||||
self = g_object_new (META_TYPE_CURSOR_TRACKER_NATIVE, NULL);
|
||||
self = make_wayland_cursor_tracker (screen);
|
||||
else
|
||||
self = g_object_new (META_TYPE_CURSOR_TRACKER_X11, NULL);
|
||||
self = make_x11_cursor_tracker (screen);
|
||||
|
||||
screen->cursor_tracker = self;
|
||||
return self;
|
||||
}
|
||||
|
||||
static void
|
||||
set_window_cursor (MetaCursorTracker *tracker,
|
||||
gboolean has_cursor,
|
||||
MetaCursorReference *cursor)
|
||||
{
|
||||
g_clear_pointer (&tracker->window_cursor, meta_cursor_reference_unref);
|
||||
if (cursor)
|
||||
tracker->window_cursor = meta_cursor_reference_ref (cursor);
|
||||
tracker->has_window_cursor = has_cursor;
|
||||
sync_cursor (tracker);
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_cursor_tracker_handle_xevent (MetaCursorTracker *tracker,
|
||||
XEvent *xevent)
|
||||
{
|
||||
XFixesCursorNotifyEvent *notify_event;
|
||||
|
||||
if (meta_is_wayland_compositor ())
|
||||
return FALSE;
|
||||
|
||||
if (xevent->xany.type != tracker->screen->display->xfixes_event_base + XFixesCursorNotify)
|
||||
return FALSE;
|
||||
|
||||
notify_event = (XFixesCursorNotifyEvent *)xevent;
|
||||
if (notify_event->subtype != XFixesDisplayCursorNotify)
|
||||
return FALSE;
|
||||
|
||||
set_window_cursor (tracker, FALSE, NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static MetaCursorReference *
|
||||
meta_cursor_reference_take_texture (CoglTexture2D *texture,
|
||||
int hot_x,
|
||||
int hot_y)
|
||||
{
|
||||
MetaCursorReference *self;
|
||||
|
||||
self = g_slice_new0 (MetaCursorReference);
|
||||
self->ref_count = 1;
|
||||
self->image.texture = texture;
|
||||
self->image.hot_x = hot_x;
|
||||
self->image.hot_y = hot_y;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static void
|
||||
ensure_xfixes_cursor (MetaCursorTracker *tracker)
|
||||
{
|
||||
XFixesCursorImage *cursor_image;
|
||||
CoglTexture2D *sprite;
|
||||
guint8 *cursor_data;
|
||||
gboolean free_cursor_data;
|
||||
CoglContext *ctx;
|
||||
|
||||
if (tracker->has_window_cursor)
|
||||
return;
|
||||
|
||||
cursor_image = XFixesGetCursorImage (tracker->screen->display->xdisplay);
|
||||
if (!cursor_image)
|
||||
return;
|
||||
|
||||
/* Like all X APIs, XFixesGetCursorImage() returns arrays of 32-bit
|
||||
* quantities as arrays of long; we need to convert on 64 bit */
|
||||
if (sizeof(long) == 4)
|
||||
{
|
||||
cursor_data = (guint8 *)cursor_image->pixels;
|
||||
free_cursor_data = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i, j;
|
||||
guint32 *cursor_words;
|
||||
gulong *p;
|
||||
guint32 *q;
|
||||
|
||||
cursor_words = g_new (guint32, cursor_image->width * cursor_image->height);
|
||||
cursor_data = (guint8 *)cursor_words;
|
||||
|
||||
p = cursor_image->pixels;
|
||||
q = cursor_words;
|
||||
for (j = 0; j < cursor_image->height; j++)
|
||||
for (i = 0; i < cursor_image->width; i++)
|
||||
*(q++) = *(p++);
|
||||
|
||||
free_cursor_data = TRUE;
|
||||
}
|
||||
|
||||
ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
||||
sprite = cogl_texture_2d_new_from_data (ctx,
|
||||
cursor_image->width,
|
||||
cursor_image->height,
|
||||
CLUTTER_CAIRO_FORMAT_ARGB32,
|
||||
cursor_image->width * 4, /* stride */
|
||||
cursor_data,
|
||||
NULL);
|
||||
|
||||
if (free_cursor_data)
|
||||
g_free (cursor_data);
|
||||
|
||||
if (sprite != NULL)
|
||||
{
|
||||
MetaCursorReference *cursor = meta_cursor_reference_take_texture (sprite,
|
||||
cursor_image->xhot,
|
||||
cursor_image->yhot);
|
||||
set_window_cursor (tracker, TRUE, cursor);
|
||||
}
|
||||
XFree (cursor_image);
|
||||
}
|
||||
|
||||
/**
|
||||
* meta_cursor_tracker_get_sprite:
|
||||
*
|
||||
@ -155,10 +334,11 @@ meta_cursor_tracker_get_sprite (MetaCursorTracker *tracker)
|
||||
{
|
||||
g_return_val_if_fail (META_IS_CURSOR_TRACKER (tracker), NULL);
|
||||
|
||||
META_CURSOR_TRACKER_GET_CLASS (tracker)->ensure_cursor (tracker);
|
||||
if (!meta_is_wayland_compositor ())
|
||||
ensure_xfixes_cursor (tracker);
|
||||
|
||||
if (tracker->current_cursor)
|
||||
return meta_cursor_reference_get_cogl_texture (tracker->current_cursor, NULL, NULL);
|
||||
if (tracker->displayed_cursor)
|
||||
return meta_cursor_reference_get_cogl_texture (tracker->displayed_cursor, NULL, NULL);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
@ -177,10 +357,11 @@ meta_cursor_tracker_get_hot (MetaCursorTracker *tracker,
|
||||
{
|
||||
g_return_if_fail (META_IS_CURSOR_TRACKER (tracker));
|
||||
|
||||
META_CURSOR_TRACKER_GET_CLASS (tracker)->ensure_cursor (tracker);
|
||||
if (!meta_is_wayland_compositor ())
|
||||
ensure_xfixes_cursor (tracker);
|
||||
|
||||
if (tracker->current_cursor)
|
||||
meta_cursor_reference_get_cogl_texture (tracker->current_cursor, x, y);
|
||||
if (tracker->displayed_cursor)
|
||||
meta_cursor_reference_get_cogl_texture (tracker->displayed_cursor, x, y);
|
||||
else
|
||||
{
|
||||
if (x)
|
||||
@ -190,32 +371,6 @@ meta_cursor_tracker_get_hot (MetaCursorTracker *tracker,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_meta_cursor_tracker_set_window_cursor (MetaCursorTracker *tracker,
|
||||
gboolean has_cursor,
|
||||
MetaCursorReference *cursor)
|
||||
{
|
||||
g_clear_pointer (&tracker->window_cursor, meta_cursor_reference_unref);
|
||||
if (cursor)
|
||||
tracker->window_cursor = meta_cursor_reference_ref (cursor);
|
||||
tracker->has_window_cursor = has_cursor;
|
||||
|
||||
_meta_cursor_tracker_sync_cursor (tracker);
|
||||
}
|
||||
|
||||
void
|
||||
meta_cursor_tracker_set_window_cursor (MetaCursorTracker *tracker,
|
||||
MetaCursorReference *cursor)
|
||||
{
|
||||
_meta_cursor_tracker_set_window_cursor (tracker, TRUE, cursor);
|
||||
}
|
||||
|
||||
void
|
||||
meta_cursor_tracker_unset_window_cursor (MetaCursorTracker *tracker)
|
||||
{
|
||||
_meta_cursor_tracker_set_window_cursor (tracker, FALSE, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
meta_cursor_tracker_set_grab_cursor (MetaCursorTracker *tracker,
|
||||
MetaCursorReference *cursor)
|
||||
@ -224,7 +379,20 @@ meta_cursor_tracker_set_grab_cursor (MetaCursorTracker *tracker,
|
||||
if (cursor)
|
||||
tracker->grab_cursor = meta_cursor_reference_ref (cursor);
|
||||
|
||||
_meta_cursor_tracker_sync_cursor (tracker);
|
||||
sync_cursor (tracker);
|
||||
}
|
||||
|
||||
void
|
||||
meta_cursor_tracker_set_window_cursor (MetaCursorTracker *tracker,
|
||||
MetaCursorReference *cursor)
|
||||
{
|
||||
set_window_cursor (tracker, TRUE, cursor);
|
||||
}
|
||||
|
||||
void
|
||||
meta_cursor_tracker_unset_window_cursor (MetaCursorTracker *tracker)
|
||||
{
|
||||
set_window_cursor (tracker, FALSE, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
@ -235,12 +403,78 @@ meta_cursor_tracker_set_root_cursor (MetaCursorTracker *tracker,
|
||||
if (cursor)
|
||||
tracker->root_cursor = meta_cursor_reference_ref (cursor);
|
||||
|
||||
_meta_cursor_tracker_sync_cursor (tracker);
|
||||
sync_cursor (tracker);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
should_have_hw_cursor (MetaCursorTracker *tracker)
|
||||
{
|
||||
if (tracker->displayed_cursor)
|
||||
return (meta_cursor_reference_get_gbm_bo (tracker->displayed_cursor, NULL, NULL) != NULL);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
update_hw_cursor (MetaCursorTracker *tracker)
|
||||
{
|
||||
MetaMonitorManager *monitors;
|
||||
MetaCRTC *crtcs;
|
||||
unsigned int i, n_crtcs;
|
||||
gboolean enabled;
|
||||
|
||||
enabled = should_have_hw_cursor (tracker);
|
||||
tracker->has_hw_cursor = enabled;
|
||||
|
||||
monitors = meta_monitor_manager_get ();
|
||||
meta_monitor_manager_get_resources (monitors, NULL, NULL, &crtcs, &n_crtcs, NULL, NULL);
|
||||
|
||||
for (i = 0; i < n_crtcs; i++)
|
||||
{
|
||||
MetaRectangle *rect = &crtcs[i].rect;
|
||||
gboolean has;
|
||||
|
||||
has = enabled && meta_rectangle_overlap (&tracker->current_rect, rect);
|
||||
|
||||
if (has || crtcs[i].has_hw_cursor)
|
||||
meta_cursor_tracker_set_crtc_has_hw_cursor (tracker, &crtcs[i], has);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
move_hw_cursor (MetaCursorTracker *tracker)
|
||||
{
|
||||
MetaMonitorManager *monitors;
|
||||
MetaCRTC *crtcs;
|
||||
unsigned int i, n_crtcs;
|
||||
|
||||
monitors = meta_monitor_manager_get ();
|
||||
meta_monitor_manager_get_resources (monitors, NULL, NULL, &crtcs, &n_crtcs, NULL, NULL);
|
||||
|
||||
g_assert (tracker->has_hw_cursor);
|
||||
|
||||
for (i = 0; i < n_crtcs; i++)
|
||||
{
|
||||
MetaRectangle *rect = &crtcs[i].rect;
|
||||
gboolean has;
|
||||
|
||||
has = meta_rectangle_overlap (&tracker->current_rect, rect);
|
||||
|
||||
if (has != crtcs[i].has_hw_cursor)
|
||||
meta_cursor_tracker_set_crtc_has_hw_cursor (tracker, &crtcs[i], has);
|
||||
if (has)
|
||||
drmModeMoveCursor (tracker->drm_fd, crtcs[i].crtc_id,
|
||||
tracker->current_rect.x - rect->x,
|
||||
tracker->current_rect.y - rect->y);
|
||||
}
|
||||
}
|
||||
|
||||
static MetaCursorReference *
|
||||
get_current_cursor (MetaCursorTracker *tracker)
|
||||
get_displayed_cursor (MetaCursorTracker *tracker)
|
||||
{
|
||||
if (!tracker->is_showing)
|
||||
return NULL;
|
||||
|
||||
if (tracker->grab_cursor)
|
||||
return tracker->grab_cursor;
|
||||
|
||||
@ -250,47 +484,225 @@ get_current_cursor (MetaCursorTracker *tracker)
|
||||
return tracker->root_cursor;
|
||||
}
|
||||
|
||||
static MetaCursorReference *
|
||||
get_displayed_cursor (MetaCursorTracker *tracker)
|
||||
static void
|
||||
update_displayed_cursor (MetaCursorTracker *tracker)
|
||||
{
|
||||
if (!tracker->is_showing)
|
||||
return NULL;
|
||||
if (meta_is_wayland_compositor ())
|
||||
{
|
||||
if (tracker->displayed_cursor)
|
||||
{
|
||||
CoglTexture *texture = meta_cursor_reference_get_cogl_texture (tracker->displayed_cursor, NULL, NULL);
|
||||
cogl_pipeline_set_layer_texture (tracker->pipeline, 0, texture);
|
||||
}
|
||||
else
|
||||
cogl_pipeline_set_layer_texture (tracker->pipeline, 0, NULL);
|
||||
|
||||
return get_current_cursor (tracker);
|
||||
update_hw_cursor (tracker);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sync_displayed_cursor (MetaCursorTracker *tracker)
|
||||
{
|
||||
MetaCursorReference *displayed_cursor = get_displayed_cursor (tracker);
|
||||
|
||||
if (tracker->displayed_cursor == displayed_cursor)
|
||||
return;
|
||||
|
||||
g_clear_pointer (&tracker->displayed_cursor, meta_cursor_reference_unref);
|
||||
if (displayed_cursor)
|
||||
tracker->displayed_cursor = meta_cursor_reference_ref (displayed_cursor);
|
||||
|
||||
update_displayed_cursor (tracker);
|
||||
g_signal_emit (tracker, signals[CURSOR_CHANGED], 0);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_queue_redraw (MetaCursorTracker *tracker)
|
||||
{
|
||||
MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
|
||||
ClutterActor *stage = compositor->stage;
|
||||
cairo_rectangle_int_t clip;
|
||||
|
||||
g_assert (meta_is_wayland_compositor ());
|
||||
|
||||
/* Clear the location the cursor was at before, if we need to. */
|
||||
if (tracker->previous_is_valid)
|
||||
{
|
||||
clip.x = tracker->previous_rect.x;
|
||||
clip.y = tracker->previous_rect.y;
|
||||
clip.width = tracker->previous_rect.width;
|
||||
clip.height = tracker->previous_rect.height;
|
||||
clutter_actor_queue_redraw_with_clip (stage, &clip);
|
||||
tracker->previous_is_valid = FALSE;
|
||||
}
|
||||
|
||||
if (tracker->has_hw_cursor || !tracker->displayed_cursor)
|
||||
return;
|
||||
|
||||
clip.x = tracker->current_rect.x;
|
||||
clip.y = tracker->current_rect.y;
|
||||
clip.width = tracker->current_rect.width;
|
||||
clip.height = tracker->current_rect.height;
|
||||
clutter_actor_queue_redraw_with_clip (stage, &clip);
|
||||
}
|
||||
|
||||
static void
|
||||
sync_cursor (MetaCursorTracker *tracker)
|
||||
{
|
||||
MetaCursorReference *displayed_cursor;
|
||||
|
||||
sync_displayed_cursor (tracker);
|
||||
displayed_cursor = tracker->displayed_cursor;
|
||||
|
||||
if (displayed_cursor)
|
||||
{
|
||||
CoglTexture *texture;
|
||||
int hot_x, hot_y;
|
||||
|
||||
texture = meta_cursor_reference_get_cogl_texture (displayed_cursor, &hot_x, &hot_y);
|
||||
|
||||
tracker->current_rect.x = tracker->current_x - hot_x;
|
||||
tracker->current_rect.y = tracker->current_y - hot_y;
|
||||
tracker->current_rect.width = cogl_texture_get_width (COGL_TEXTURE (texture));
|
||||
tracker->current_rect.height = cogl_texture_get_height (COGL_TEXTURE (texture));
|
||||
}
|
||||
else
|
||||
{
|
||||
tracker->current_rect.x = 0;
|
||||
tracker->current_rect.y = 0;
|
||||
tracker->current_rect.width = 0;
|
||||
tracker->current_rect.height = 0;
|
||||
}
|
||||
|
||||
if (meta_is_wayland_compositor ())
|
||||
{
|
||||
if (tracker->has_hw_cursor)
|
||||
move_hw_cursor (tracker);
|
||||
else
|
||||
meta_cursor_tracker_queue_redraw (tracker);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_meta_cursor_tracker_sync_cursor (MetaCursorTracker *tracker)
|
||||
meta_cursor_tracker_update_position (MetaCursorTracker *tracker,
|
||||
int new_x,
|
||||
int new_y)
|
||||
{
|
||||
MetaCursorReference *current_cursor = get_current_cursor (tracker);
|
||||
MetaCursorReference *displayed_cursor = get_displayed_cursor (tracker);
|
||||
g_assert (meta_is_wayland_compositor ());
|
||||
|
||||
if (tracker->displayed_cursor != displayed_cursor)
|
||||
tracker->current_x = new_x;
|
||||
tracker->current_y = new_y;
|
||||
|
||||
sync_cursor (tracker);
|
||||
}
|
||||
|
||||
void
|
||||
meta_cursor_tracker_paint (MetaCursorTracker *tracker)
|
||||
{
|
||||
g_assert (meta_is_wayland_compositor ());
|
||||
|
||||
if (tracker->has_hw_cursor || !tracker->displayed_cursor)
|
||||
return;
|
||||
|
||||
cogl_framebuffer_draw_rectangle (cogl_get_draw_framebuffer (),
|
||||
tracker->pipeline,
|
||||
tracker->current_rect.x,
|
||||
tracker->current_rect.y,
|
||||
tracker->current_rect.x +
|
||||
tracker->current_rect.width,
|
||||
tracker->current_rect.y +
|
||||
tracker->current_rect.height);
|
||||
|
||||
tracker->previous_rect = tracker->current_rect;
|
||||
tracker->previous_is_valid = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_set_crtc_has_hw_cursor (MetaCursorTracker *tracker,
|
||||
MetaCRTC *crtc,
|
||||
gboolean has)
|
||||
{
|
||||
if (has)
|
||||
{
|
||||
g_clear_pointer (&tracker->displayed_cursor, meta_cursor_reference_unref);
|
||||
if (displayed_cursor)
|
||||
tracker->displayed_cursor = meta_cursor_reference_ref (displayed_cursor);
|
||||
MetaCursorReference *displayed_cursor = tracker->displayed_cursor;
|
||||
struct gbm_bo *bo;
|
||||
union gbm_bo_handle handle;
|
||||
int width, height;
|
||||
int hot_x, hot_y;
|
||||
|
||||
META_CURSOR_TRACKER_GET_CLASS (tracker)->sync_cursor (tracker);
|
||||
bo = meta_cursor_reference_get_gbm_bo (displayed_cursor, &hot_x, &hot_y);
|
||||
|
||||
handle = gbm_bo_get_handle (bo);
|
||||
width = gbm_bo_get_width (bo);
|
||||
height = gbm_bo_get_height (bo);
|
||||
|
||||
drmModeSetCursor2 (tracker->drm_fd, crtc->crtc_id, handle.u32,
|
||||
width, height, hot_x, hot_y);
|
||||
crtc->has_hw_cursor = TRUE;
|
||||
}
|
||||
|
||||
if (tracker->current_cursor != current_cursor)
|
||||
else
|
||||
{
|
||||
g_clear_pointer (&tracker->current_cursor, meta_cursor_reference_unref);
|
||||
if (current_cursor)
|
||||
tracker->current_cursor = meta_cursor_reference_ref (current_cursor);
|
||||
|
||||
g_signal_emit (tracker, signals[CURSOR_CHANGED], 0);
|
||||
drmModeSetCursor2 (tracker->drm_fd, crtc->crtc_id, 0, 0, 0, 0, 0);
|
||||
crtc->has_hw_cursor = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
get_pointer_position_gdk (int *x,
|
||||
int *y,
|
||||
int *mods)
|
||||
{
|
||||
GdkDeviceManager *gmanager;
|
||||
GdkDevice *gdevice;
|
||||
GdkScreen *gscreen;
|
||||
|
||||
gmanager = gdk_display_get_device_manager (gdk_display_get_default ());
|
||||
gdevice = gdk_x11_device_manager_lookup (gmanager, META_VIRTUAL_CORE_POINTER_ID);
|
||||
|
||||
gdk_device_get_position (gdevice, &gscreen, x, y);
|
||||
if (mods)
|
||||
gdk_device_get_state (gdevice,
|
||||
gdk_screen_get_root_window (gscreen),
|
||||
NULL, (GdkModifierType*)mods);
|
||||
}
|
||||
|
||||
static void
|
||||
get_pointer_position_clutter (int *x,
|
||||
int *y,
|
||||
int *mods)
|
||||
{
|
||||
ClutterDeviceManager *cmanager;
|
||||
ClutterInputDevice *cdevice;
|
||||
ClutterPoint point;
|
||||
|
||||
cmanager = clutter_device_manager_get_default ();
|
||||
cdevice = clutter_device_manager_get_core_device (cmanager, CLUTTER_POINTER_DEVICE);
|
||||
|
||||
clutter_input_device_get_coords (cdevice, NULL, &point);
|
||||
if (x)
|
||||
*x = point.x;
|
||||
if (y)
|
||||
*y = point.y;
|
||||
if (mods)
|
||||
*mods = clutter_input_device_get_modifier_state (cdevice);
|
||||
}
|
||||
|
||||
void
|
||||
meta_cursor_tracker_get_pointer (MetaCursorTracker *tracker,
|
||||
int *x,
|
||||
int *y,
|
||||
ClutterModifierType *mods)
|
||||
{
|
||||
META_CURSOR_TRACKER_GET_CLASS (tracker)->get_pointer (tracker, x, y, mods);
|
||||
/* We can't use the clutter interface when not running as a wayland compositor,
|
||||
because we need to query the server, rather than using the last cached value.
|
||||
OTOH, on wayland we can't use GDK, because that only sees the events
|
||||
we forward to xwayland.
|
||||
*/
|
||||
if (meta_is_wayland_compositor ())
|
||||
get_pointer_position_clutter (x, y, (int*)mods);
|
||||
else
|
||||
get_pointer_position_gdk (x, y, (int*)mods);
|
||||
}
|
||||
|
||||
void
|
||||
@ -301,51 +713,26 @@ meta_cursor_tracker_set_pointer_visible (MetaCursorTracker *tracker,
|
||||
return;
|
||||
tracker->is_showing = visible;
|
||||
|
||||
_meta_cursor_tracker_sync_cursor (tracker);
|
||||
if (meta_is_wayland_compositor ())
|
||||
{
|
||||
sync_cursor (tracker);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (visible)
|
||||
XFixesShowCursor (tracker->screen->display->xdisplay,
|
||||
tracker->screen->xroot);
|
||||
else
|
||||
XFixesHideCursor (tracker->screen->display->xdisplay,
|
||||
tracker->screen->xroot);
|
||||
}
|
||||
}
|
||||
|
||||
MetaCursorReference *
|
||||
meta_cursor_tracker_get_cursor_from_theme (MetaCursorTracker *tracker,
|
||||
MetaCursor meta_cursor)
|
||||
void
|
||||
meta_cursor_tracker_force_update (MetaCursorTracker *tracker)
|
||||
{
|
||||
MetaCursorReference *cursor;
|
||||
XcursorImage *xc_image;
|
||||
g_assert (meta_is_wayland_compositor ());
|
||||
|
||||
if (tracker->theme_cursors[meta_cursor])
|
||||
return meta_cursor_reference_ref (tracker->theme_cursors[meta_cursor]);
|
||||
|
||||
xc_image = meta_display_load_x_cursor (meta_get_display (), meta_cursor);
|
||||
if (!xc_image)
|
||||
return NULL;
|
||||
|
||||
cursor = meta_cursor_reference_from_xcursor_image (xc_image);
|
||||
|
||||
META_CURSOR_TRACKER_GET_CLASS (tracker)->load_cursor_pixels (tracker,
|
||||
cursor,
|
||||
(uint8_t *) xc_image->pixels,
|
||||
xc_image->width,
|
||||
xc_image->height,
|
||||
xc_image->width * 4,
|
||||
GBM_FORMAT_ARGB8888);
|
||||
XcursorImageDestroy (xc_image);
|
||||
|
||||
tracker->theme_cursors[meta_cursor] = cursor;
|
||||
|
||||
return meta_cursor_reference_ref (cursor);
|
||||
}
|
||||
|
||||
MetaCursorReference *
|
||||
meta_cursor_tracker_get_cursor_from_buffer (MetaCursorTracker *tracker,
|
||||
struct wl_resource *buffer,
|
||||
int hot_x,
|
||||
int hot_y)
|
||||
{
|
||||
MetaCursorReference *cursor;
|
||||
|
||||
cursor = meta_cursor_reference_from_buffer (buffer, hot_x, hot_y);
|
||||
|
||||
META_CURSOR_TRACKER_GET_CLASS (tracker)->load_cursor_buffer (tracker,
|
||||
cursor,
|
||||
buffer);
|
||||
return cursor;
|
||||
update_hw_cursor (tracker);
|
||||
sync_cursor (tracker);
|
||||
}
|
||||
|
@ -27,23 +27,16 @@
|
||||
|
||||
#include "display-private.h"
|
||||
#include "screen-private.h"
|
||||
#include "meta-cursor-tracker-private.h"
|
||||
#include "meta-cursor-tracker-private.h" /* for tracker->gbm */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <X11/cursorfont.h>
|
||||
#include <X11/extensions/Xfixes.h>
|
||||
#include <X11/Xcursor/Xcursor.h>
|
||||
|
||||
#include <cogl/cogl-wayland-server.h>
|
||||
|
||||
static MetaCursorReference *
|
||||
meta_cursor_reference_new (void)
|
||||
{
|
||||
MetaCursorReference *self;
|
||||
|
||||
self = g_slice_new0 (MetaCursorReference);
|
||||
self->ref_count = 1;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
MetaCursorReference *
|
||||
meta_cursor_reference_ref (MetaCursorReference *self)
|
||||
{
|
||||
@ -197,21 +190,14 @@ load_cursor_on_client (MetaDisplay *display,
|
||||
return image;
|
||||
}
|
||||
|
||||
XcursorImage *
|
||||
meta_display_load_x_cursor (MetaDisplay *display,
|
||||
MetaCursor cursor)
|
||||
{
|
||||
return load_cursor_on_client (display, cursor);
|
||||
}
|
||||
|
||||
void
|
||||
meta_cursor_reference_load_gbm_buffer (MetaCursorReference *cursor,
|
||||
struct gbm_device *gbm,
|
||||
uint8_t *pixels,
|
||||
int width,
|
||||
int height,
|
||||
int rowstride,
|
||||
uint32_t gbm_format)
|
||||
static void
|
||||
meta_cursor_image_load_gbm_buffer (struct gbm_device *gbm,
|
||||
MetaCursorImage *image,
|
||||
uint8_t *pixels,
|
||||
int width,
|
||||
int height,
|
||||
int rowstride,
|
||||
uint32_t gbm_format)
|
||||
{
|
||||
if (width > 64 || height > 64)
|
||||
{
|
||||
@ -225,154 +211,180 @@ meta_cursor_reference_load_gbm_buffer (MetaCursorReference *cursor,
|
||||
uint8_t buf[4 * 64 * 64];
|
||||
int i;
|
||||
|
||||
cursor->image.bo = gbm_bo_create (gbm, 64, 64,
|
||||
gbm_format, GBM_BO_USE_CURSOR_64X64 | GBM_BO_USE_WRITE);
|
||||
image->bo = gbm_bo_create (gbm, 64, 64,
|
||||
gbm_format, GBM_BO_USE_CURSOR_64X64 | GBM_BO_USE_WRITE);
|
||||
|
||||
memset (buf, 0, sizeof(buf));
|
||||
for (i = 0; i < height; i++)
|
||||
memcpy (buf + i * 4 * 64, pixels + i * rowstride, width * 4);
|
||||
|
||||
gbm_bo_write (cursor->image.bo, buf, 64 * 64 * 4);
|
||||
gbm_bo_write (image->bo, buf, 64 * 64 * 4);
|
||||
}
|
||||
else
|
||||
meta_warning ("HW cursor for format %d not supported\n", gbm_format);
|
||||
}
|
||||
|
||||
void
|
||||
meta_cursor_reference_import_gbm_buffer (MetaCursorReference *cursor,
|
||||
struct gbm_device *gbm,
|
||||
struct wl_resource *buffer,
|
||||
int width,
|
||||
int height)
|
||||
static void
|
||||
meta_cursor_image_load_from_xcursor_image (MetaCursorTracker *tracker,
|
||||
MetaCursorImage *image,
|
||||
XcursorImage *xc_image)
|
||||
{
|
||||
/* HW cursors must be 64x64, but 64x64 is huge, and no cursor theme actually uses
|
||||
that, so themed cursors must be padded with transparent pixels to fill the
|
||||
overlay. This is trivial if we have CPU access to the data, but it's not
|
||||
possible if the buffer is in GPU memory (and possibly tiled too), so if we
|
||||
don't get the right size, we fallback to GL.
|
||||
*/
|
||||
if (width != 64 || height != 64)
|
||||
{
|
||||
meta_warning ("Invalid cursor size (must be 64x64), falling back to software (GL) cursors\n");
|
||||
return;
|
||||
}
|
||||
|
||||
cursor->image.bo = gbm_bo_import (gbm, GBM_BO_IMPORT_WL_BUFFER,
|
||||
buffer, GBM_BO_USE_CURSOR_64X64);
|
||||
if (!cursor->image.bo)
|
||||
meta_warning ("Importing HW cursor from wl_buffer failed\n");
|
||||
}
|
||||
|
||||
MetaCursorReference *
|
||||
meta_cursor_reference_from_xfixes_cursor_image (XFixesCursorImage *cursor_image)
|
||||
{
|
||||
MetaCursorReference *cursor;
|
||||
CoglTexture2D *sprite;
|
||||
CoglContext *ctx;
|
||||
guint8 *cursor_data;
|
||||
gboolean free_cursor_data;
|
||||
|
||||
cursor = meta_cursor_reference_new ();
|
||||
|
||||
/* Like all X APIs, XFixesGetCursorImage() returns arrays of 32-bit
|
||||
* quantities as arrays of long; we need to convert on 64 bit */
|
||||
if (sizeof(long) == 4)
|
||||
{
|
||||
cursor_data = (guint8 *)cursor_image->pixels;
|
||||
free_cursor_data = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i, j;
|
||||
guint32 *cursor_words;
|
||||
gulong *p;
|
||||
guint32 *q;
|
||||
|
||||
cursor_words = g_new (guint32, cursor_image->width * cursor_image->height);
|
||||
cursor_data = (guint8 *)cursor_words;
|
||||
|
||||
p = cursor_image->pixels;
|
||||
q = cursor_words;
|
||||
for (j = 0; j < cursor_image->height; j++)
|
||||
for (i = 0; i < cursor_image->width; i++)
|
||||
*(q++) = *(p++);
|
||||
|
||||
free_cursor_data = TRUE;
|
||||
}
|
||||
|
||||
ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
||||
sprite = cogl_texture_2d_new_from_data (ctx,
|
||||
cursor_image->width,
|
||||
cursor_image->height,
|
||||
CLUTTER_CAIRO_FORMAT_ARGB32,
|
||||
cursor_image->width * 4, /* stride */
|
||||
cursor_data,
|
||||
NULL);
|
||||
if (free_cursor_data)
|
||||
g_free (cursor_data);
|
||||
|
||||
cursor->image.texture = sprite;
|
||||
cursor->image.hot_x = cursor_image->xhot;
|
||||
cursor->image.hot_y = cursor_image->yhot;
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
MetaCursorReference *
|
||||
meta_cursor_reference_from_xcursor_image (XcursorImage *xc_image)
|
||||
{
|
||||
MetaCursorReference *cursor;
|
||||
int width, height, rowstride;
|
||||
CoglPixelFormat cogl_format;
|
||||
uint32_t gbm_format;
|
||||
ClutterBackend *clutter_backend;
|
||||
CoglContext *cogl_context;
|
||||
|
||||
cursor = meta_cursor_reference_new ();
|
||||
|
||||
width = xc_image->width;
|
||||
height = xc_image->height;
|
||||
rowstride = width * 4;
|
||||
|
||||
gbm_format = GBM_FORMAT_ARGB8888;
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
cogl_format = COGL_PIXEL_FORMAT_BGRA_8888;
|
||||
#else
|
||||
cogl_format = COGL_PIXEL_FORMAT_ARGB_8888;
|
||||
#endif
|
||||
|
||||
cursor->image.hot_x = xc_image->xhot;
|
||||
cursor->image.hot_y = xc_image->yhot;
|
||||
image->hot_x = xc_image->xhot;
|
||||
image->hot_y = xc_image->yhot;
|
||||
|
||||
clutter_backend = clutter_get_default_backend ();
|
||||
cogl_context = clutter_backend_get_cogl_context (clutter_backend);
|
||||
cursor->image.texture = cogl_texture_2d_new_from_data (cogl_context,
|
||||
width, height,
|
||||
cogl_format,
|
||||
rowstride,
|
||||
(uint8_t *) xc_image->pixels,
|
||||
NULL);
|
||||
return cursor;
|
||||
image->texture = cogl_texture_2d_new_from_data (cogl_context,
|
||||
width, height,
|
||||
cogl_format,
|
||||
rowstride,
|
||||
(uint8_t *) xc_image->pixels,
|
||||
NULL);
|
||||
|
||||
if (tracker->gbm)
|
||||
meta_cursor_image_load_gbm_buffer (tracker->gbm,
|
||||
image,
|
||||
(uint8_t *) xc_image->pixels,
|
||||
width, height, rowstride,
|
||||
gbm_format);
|
||||
}
|
||||
|
||||
MetaCursorReference *
|
||||
meta_cursor_reference_from_buffer (struct wl_resource *buffer,
|
||||
int hot_x,
|
||||
int hot_y)
|
||||
meta_cursor_reference_from_theme (MetaCursorTracker *tracker,
|
||||
MetaCursor cursor)
|
||||
{
|
||||
MetaCursorReference *self;
|
||||
XcursorImage *image;
|
||||
|
||||
if (tracker->theme_cursors[cursor])
|
||||
return meta_cursor_reference_ref (tracker->theme_cursors[cursor]);
|
||||
|
||||
image = load_cursor_on_client (tracker->screen->display, cursor);
|
||||
if (!image)
|
||||
return NULL;
|
||||
|
||||
self = g_slice_new0 (MetaCursorReference);
|
||||
self->ref_count = 1;
|
||||
meta_cursor_image_load_from_xcursor_image (tracker, &self->image, image);
|
||||
|
||||
XcursorImageDestroy (image);
|
||||
return self;
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_image_load_from_buffer (MetaCursorTracker *tracker,
|
||||
MetaCursorImage *image,
|
||||
struct wl_resource *buffer,
|
||||
int hot_x,
|
||||
int hot_y)
|
||||
{
|
||||
MetaCursorReference *cursor;
|
||||
ClutterBackend *backend;
|
||||
CoglContext *cogl_context;
|
||||
struct wl_shm_buffer *shm_buffer;
|
||||
uint32_t gbm_format;
|
||||
int width, height;
|
||||
|
||||
cursor = meta_cursor_reference_new ();
|
||||
|
||||
cursor->image.hot_x = hot_x;
|
||||
cursor->image.hot_y = hot_y;
|
||||
image->hot_x = hot_x;
|
||||
image->hot_y = hot_y;
|
||||
|
||||
backend = clutter_get_default_backend ();
|
||||
cogl_context = clutter_backend_get_cogl_context (backend);
|
||||
|
||||
cursor->image.texture = cogl_wayland_texture_2d_new_from_buffer (cogl_context, buffer, NULL);
|
||||
image->texture = cogl_wayland_texture_2d_new_from_buffer (cogl_context, buffer, NULL);
|
||||
|
||||
return cursor;
|
||||
width = cogl_texture_get_width (COGL_TEXTURE (image->texture));
|
||||
height = cogl_texture_get_height (COGL_TEXTURE (image->texture));
|
||||
|
||||
shm_buffer = wl_shm_buffer_get (buffer);
|
||||
if (shm_buffer)
|
||||
{
|
||||
if (tracker->gbm)
|
||||
{
|
||||
int rowstride = wl_shm_buffer_get_stride (shm_buffer);
|
||||
|
||||
switch (wl_shm_buffer_get_format (shm_buffer))
|
||||
{
|
||||
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
||||
case WL_SHM_FORMAT_ARGB8888:
|
||||
gbm_format = GBM_FORMAT_ARGB8888;
|
||||
break;
|
||||
case WL_SHM_FORMAT_XRGB8888:
|
||||
gbm_format = GBM_FORMAT_XRGB8888;
|
||||
break;
|
||||
#else
|
||||
case WL_SHM_FORMAT_ARGB8888:
|
||||
gbm_format = GBM_FORMAT_ARGB8888;
|
||||
break;
|
||||
case WL_SHM_FORMAT_XRGB8888:
|
||||
gbm_format = GBM_FORMAT_XRGB8888;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
g_warn_if_reached ();
|
||||
gbm_format = GBM_FORMAT_ARGB8888;
|
||||
}
|
||||
|
||||
meta_cursor_image_load_gbm_buffer (tracker->gbm,
|
||||
image,
|
||||
(uint8_t *) wl_shm_buffer_get_data (shm_buffer),
|
||||
width, height, rowstride,
|
||||
gbm_format);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* HW cursors must be 64x64, but 64x64 is huge, and no cursor theme actually uses
|
||||
that, so themed cursors must be padded with transparent pixels to fill the
|
||||
overlay. This is trivial if we have CPU access to the data, but it's not
|
||||
possible if the buffer is in GPU memory (and possibly tiled too), so if we
|
||||
don't get the right size, we fallback to GL.
|
||||
*/
|
||||
if (width != 64 || height != 64)
|
||||
{
|
||||
meta_warning ("Invalid cursor size (must be 64x64), falling back to software (GL) cursors\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (tracker->gbm)
|
||||
{
|
||||
image->bo = gbm_bo_import (tracker->gbm, GBM_BO_IMPORT_WL_BUFFER,
|
||||
buffer, GBM_BO_USE_CURSOR_64X64);
|
||||
if (!image->bo)
|
||||
meta_warning ("Importing HW cursor from wl_buffer failed\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MetaCursorReference *
|
||||
meta_cursor_reference_from_buffer (MetaCursorTracker *tracker,
|
||||
struct wl_resource *buffer,
|
||||
int hot_x,
|
||||
int hot_y)
|
||||
{
|
||||
MetaCursorReference *self;
|
||||
|
||||
self = g_slice_new0 (MetaCursorReference);
|
||||
self->ref_count = 1;
|
||||
meta_cursor_image_load_from_buffer (tracker, &self->image, buffer, hot_x, hot_y);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
CoglTexture *
|
||||
|
@ -27,4 +27,16 @@ typedef struct _MetaCursorReference MetaCursorReference;
|
||||
MetaCursorReference * meta_cursor_reference_ref (MetaCursorReference *cursor);
|
||||
void meta_cursor_reference_unref (MetaCursorReference *cursor);
|
||||
|
||||
#include <meta/meta-cursor-tracker.h>
|
||||
#include <meta/common.h>
|
||||
#include <wayland-server.h>
|
||||
|
||||
MetaCursorReference * meta_cursor_reference_from_theme (MetaCursorTracker *tracker,
|
||||
MetaCursor cursor);
|
||||
|
||||
MetaCursorReference * meta_cursor_reference_from_buffer (MetaCursorTracker *tracker,
|
||||
struct wl_resource *buffer,
|
||||
int hot_x,
|
||||
int hot_y);
|
||||
|
||||
#endif /* META_CURSOR_H */
|
||||
|
@ -1,443 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 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/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <cogl/cogl.h>
|
||||
#include <cogl/cogl-wayland-server.h>
|
||||
#include <clutter/clutter.h>
|
||||
#include <gbm.h>
|
||||
|
||||
#include "display-private.h"
|
||||
#include "meta-cursor-tracker-native.h"
|
||||
#include "meta-cursor-tracker-private.h"
|
||||
#include "meta-monitor-manager.h"
|
||||
#include "meta-cursor-private.h"
|
||||
|
||||
#include "wayland/meta-wayland-private.h"
|
||||
|
||||
struct _MetaCursorTrackerNative
|
||||
{
|
||||
MetaCursorTracker parent;
|
||||
|
||||
gboolean has_hw_cursor;
|
||||
|
||||
int current_x, current_y;
|
||||
MetaRectangle current_rect;
|
||||
MetaRectangle previous_rect;
|
||||
gboolean previous_is_valid;
|
||||
|
||||
CoglPipeline *pipeline;
|
||||
int drm_fd;
|
||||
struct gbm_device *gbm;
|
||||
};
|
||||
|
||||
struct _MetaCursorTrackerNativeClass
|
||||
{
|
||||
MetaCursorTrackerClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (MetaCursorTrackerNative, meta_cursor_tracker_native, META_TYPE_CURSOR_TRACKER);
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_native_load_cursor_pixels (MetaCursorTracker *tracker,
|
||||
MetaCursorReference *cursor,
|
||||
uint8_t *pixels,
|
||||
int width,
|
||||
int height,
|
||||
int rowstride,
|
||||
uint32_t format)
|
||||
{
|
||||
MetaCursorTrackerNative *self = META_CURSOR_TRACKER_NATIVE (tracker);
|
||||
|
||||
if (!self->gbm)
|
||||
return;
|
||||
|
||||
meta_cursor_reference_load_gbm_buffer (cursor,
|
||||
self->gbm,
|
||||
pixels,
|
||||
width, height, rowstride,
|
||||
format);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_native_load_cursor_buffer (MetaCursorTracker *tracker,
|
||||
MetaCursorReference *cursor,
|
||||
struct wl_resource *buffer)
|
||||
{
|
||||
struct wl_shm_buffer *shm_buffer;
|
||||
int width, height;
|
||||
|
||||
width = cogl_texture_get_width (COGL_TEXTURE (cursor->image.texture));
|
||||
height = cogl_texture_get_height (COGL_TEXTURE (cursor->image.texture));
|
||||
|
||||
shm_buffer = wl_shm_buffer_get (buffer);
|
||||
if (shm_buffer)
|
||||
{
|
||||
uint32_t gbm_format;
|
||||
uint8_t *pixels = wl_shm_buffer_get_data (shm_buffer);
|
||||
int rowstride = wl_shm_buffer_get_stride (shm_buffer);
|
||||
|
||||
switch (wl_shm_buffer_get_format (shm_buffer))
|
||||
{
|
||||
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
||||
case WL_SHM_FORMAT_ARGB8888:
|
||||
gbm_format = GBM_FORMAT_ARGB8888;
|
||||
break;
|
||||
case WL_SHM_FORMAT_XRGB8888:
|
||||
gbm_format = GBM_FORMAT_XRGB8888;
|
||||
break;
|
||||
#else
|
||||
case WL_SHM_FORMAT_ARGB8888:
|
||||
gbm_format = GBM_FORMAT_ARGB8888;
|
||||
break;
|
||||
case WL_SHM_FORMAT_XRGB8888:
|
||||
gbm_format = GBM_FORMAT_XRGB8888;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
g_warn_if_reached ();
|
||||
gbm_format = GBM_FORMAT_ARGB8888;
|
||||
}
|
||||
|
||||
meta_cursor_tracker_native_load_cursor_pixels (tracker,
|
||||
cursor,
|
||||
pixels,
|
||||
width,
|
||||
height,
|
||||
rowstride,
|
||||
gbm_format);
|
||||
}
|
||||
else
|
||||
{
|
||||
MetaCursorTrackerNative *self = META_CURSOR_TRACKER_NATIVE (tracker);
|
||||
if (!self->gbm)
|
||||
return;
|
||||
meta_cursor_reference_import_gbm_buffer (cursor, self->gbm, buffer, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_crtc_has_hw_cursor (MetaCursorTrackerNative *self,
|
||||
MetaCRTC *crtc,
|
||||
gboolean has)
|
||||
{
|
||||
MetaCursorTracker *tracker = META_CURSOR_TRACKER (self);
|
||||
|
||||
if (has)
|
||||
{
|
||||
MetaCursorReference *displayed_cursor = tracker->displayed_cursor;
|
||||
struct gbm_bo *bo;
|
||||
union gbm_bo_handle handle;
|
||||
int width, height;
|
||||
int hot_x, hot_y;
|
||||
|
||||
bo = meta_cursor_reference_get_gbm_bo (displayed_cursor, &hot_x, &hot_y);
|
||||
|
||||
handle = gbm_bo_get_handle (bo);
|
||||
width = gbm_bo_get_width (bo);
|
||||
height = gbm_bo_get_height (bo);
|
||||
|
||||
drmModeSetCursor2 (self->drm_fd, crtc->crtc_id, handle.u32,
|
||||
width, height, hot_x, hot_y);
|
||||
crtc->has_hw_cursor = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
drmModeSetCursor2 (self->drm_fd, crtc->crtc_id, 0, 0, 0, 0, 0);
|
||||
crtc->has_hw_cursor = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_monitors_changed (MetaMonitorManager *monitors,
|
||||
MetaCursorTrackerNative *self)
|
||||
{
|
||||
MetaCRTC *crtcs;
|
||||
unsigned int i, n_crtcs;
|
||||
|
||||
if (!self->has_hw_cursor)
|
||||
return;
|
||||
|
||||
/* Go through the new list of monitors, find out where the cursor is */
|
||||
meta_monitor_manager_get_resources (monitors, NULL, NULL, &crtcs, &n_crtcs, NULL, NULL);
|
||||
|
||||
for (i = 0; i < n_crtcs; i++)
|
||||
{
|
||||
MetaRectangle *rect = &crtcs[i].rect;
|
||||
gboolean has;
|
||||
|
||||
has = meta_rectangle_overlap (&self->current_rect, rect);
|
||||
|
||||
/* Need to do it unconditionally here, our tracking is
|
||||
wrong because we reloaded the CRTCs */
|
||||
set_crtc_has_hw_cursor (self, &crtcs[i], has);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
should_have_hw_cursor (MetaCursorTrackerNative *self)
|
||||
{
|
||||
MetaCursorTracker *tracker = META_CURSOR_TRACKER (self);
|
||||
|
||||
if (tracker->displayed_cursor)
|
||||
return (meta_cursor_reference_get_gbm_bo (tracker->displayed_cursor, NULL, NULL) != NULL);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
update_hw_cursor (MetaCursorTrackerNative *self)
|
||||
{
|
||||
MetaMonitorManager *monitors;
|
||||
MetaCRTC *crtcs;
|
||||
unsigned int i, n_crtcs;
|
||||
gboolean enabled;
|
||||
|
||||
enabled = should_have_hw_cursor (self);
|
||||
self->has_hw_cursor = enabled;
|
||||
|
||||
monitors = meta_monitor_manager_get ();
|
||||
meta_monitor_manager_get_resources (monitors, NULL, NULL, &crtcs, &n_crtcs, NULL, NULL);
|
||||
|
||||
for (i = 0; i < n_crtcs; i++)
|
||||
{
|
||||
MetaRectangle *rect = &crtcs[i].rect;
|
||||
gboolean has;
|
||||
|
||||
has = enabled && meta_rectangle_overlap (&self->current_rect, rect);
|
||||
|
||||
if (has || crtcs[i].has_hw_cursor)
|
||||
set_crtc_has_hw_cursor (self, &crtcs[i], has);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
move_hw_cursor (MetaCursorTrackerNative *self)
|
||||
{
|
||||
MetaMonitorManager *monitors;
|
||||
MetaCRTC *crtcs;
|
||||
unsigned int i, n_crtcs;
|
||||
|
||||
monitors = meta_monitor_manager_get ();
|
||||
meta_monitor_manager_get_resources (monitors, NULL, NULL, &crtcs, &n_crtcs, NULL, NULL);
|
||||
|
||||
g_assert (self->has_hw_cursor);
|
||||
|
||||
for (i = 0; i < n_crtcs; i++)
|
||||
{
|
||||
MetaRectangle *rect = &crtcs[i].rect;
|
||||
gboolean has;
|
||||
|
||||
has = meta_rectangle_overlap (&self->current_rect, rect);
|
||||
|
||||
if (has != crtcs[i].has_hw_cursor)
|
||||
set_crtc_has_hw_cursor (self, &crtcs[i], has);
|
||||
if (has)
|
||||
drmModeMoveCursor (self->drm_fd, crtcs[i].crtc_id,
|
||||
self->current_rect.x - rect->x,
|
||||
self->current_rect.y - rect->y);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
queue_redraw (MetaCursorTrackerNative *self)
|
||||
{
|
||||
MetaCursorTracker *tracker = META_CURSOR_TRACKER (self);
|
||||
MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
|
||||
ClutterActor *stage = compositor->stage;
|
||||
cairo_rectangle_int_t clip;
|
||||
|
||||
/* Clear the location the cursor was at before, if we need to. */
|
||||
if (self->previous_is_valid)
|
||||
{
|
||||
clip.x = self->previous_rect.x;
|
||||
clip.y = self->previous_rect.y;
|
||||
clip.width = self->previous_rect.width;
|
||||
clip.height = self->previous_rect.height;
|
||||
clutter_actor_queue_redraw_with_clip (stage, &clip);
|
||||
self->previous_is_valid = FALSE;
|
||||
}
|
||||
|
||||
if (self->has_hw_cursor || !tracker->displayed_cursor)
|
||||
return;
|
||||
|
||||
clip.x = self->current_rect.x;
|
||||
clip.y = self->current_rect.y;
|
||||
clip.width = self->current_rect.width;
|
||||
clip.height = self->current_rect.height;
|
||||
clutter_actor_queue_redraw_with_clip (stage, &clip);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_native_sync_cursor (MetaCursorTracker *tracker)
|
||||
{
|
||||
MetaCursorTrackerNative *self = META_CURSOR_TRACKER_NATIVE (tracker);
|
||||
MetaCursorReference *displayed_cursor;
|
||||
|
||||
displayed_cursor = tracker->displayed_cursor;
|
||||
|
||||
if (displayed_cursor)
|
||||
{
|
||||
CoglTexture *texture;
|
||||
int hot_x, hot_y;
|
||||
|
||||
texture = meta_cursor_reference_get_cogl_texture (displayed_cursor, &hot_x, &hot_y);
|
||||
cogl_pipeline_set_layer_texture (self->pipeline, 0, texture);
|
||||
|
||||
self->current_rect.x = self->current_x - hot_x;
|
||||
self->current_rect.y = self->current_y - hot_y;
|
||||
self->current_rect.width = cogl_texture_get_width (COGL_TEXTURE (texture));
|
||||
self->current_rect.height = cogl_texture_get_height (COGL_TEXTURE (texture));
|
||||
}
|
||||
else
|
||||
{
|
||||
cogl_pipeline_set_layer_texture (self->pipeline, 0, NULL);
|
||||
|
||||
self->current_rect.x = 0;
|
||||
self->current_rect.y = 0;
|
||||
self->current_rect.width = 0;
|
||||
self->current_rect.height = 0;
|
||||
}
|
||||
|
||||
update_hw_cursor (self);
|
||||
|
||||
if (self->has_hw_cursor)
|
||||
move_hw_cursor (self);
|
||||
else
|
||||
queue_redraw (self);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_native_get_pointer (MetaCursorTracker *tracker,
|
||||
int *x,
|
||||
int *y,
|
||||
ClutterModifierType *mods)
|
||||
{
|
||||
ClutterDeviceManager *cmanager;
|
||||
ClutterInputDevice *cdevice;
|
||||
ClutterPoint point;
|
||||
|
||||
/* On wayland we can't use GDK, because that only sees the events we
|
||||
* forward to xwayland.
|
||||
*/
|
||||
cmanager = clutter_device_manager_get_default ();
|
||||
cdevice = clutter_device_manager_get_core_device (cmanager, CLUTTER_POINTER_DEVICE);
|
||||
|
||||
clutter_input_device_get_coords (cdevice, NULL, &point);
|
||||
if (x)
|
||||
*x = point.x;
|
||||
if (y)
|
||||
*y = point.y;
|
||||
if (mods)
|
||||
*mods = clutter_input_device_get_modifier_state (cdevice);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_native_finalize (GObject *object)
|
||||
{
|
||||
MetaCursorTrackerNative *self = META_CURSOR_TRACKER_NATIVE (object);
|
||||
|
||||
if (self->pipeline)
|
||||
cogl_object_unref (self->pipeline);
|
||||
if (self->gbm)
|
||||
gbm_device_destroy (self->gbm);
|
||||
|
||||
G_OBJECT_CLASS (meta_cursor_tracker_native_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_native_class_init (MetaCursorTrackerNativeClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
MetaCursorTrackerClass *cursor_tracker_class = META_CURSOR_TRACKER_CLASS (klass);
|
||||
|
||||
object_class->finalize = meta_cursor_tracker_native_finalize;
|
||||
|
||||
cursor_tracker_class->get_pointer = meta_cursor_tracker_native_get_pointer;
|
||||
cursor_tracker_class->sync_cursor = meta_cursor_tracker_native_sync_cursor;
|
||||
cursor_tracker_class->load_cursor_pixels = meta_cursor_tracker_native_load_cursor_pixels;
|
||||
cursor_tracker_class->load_cursor_buffer = meta_cursor_tracker_native_load_cursor_buffer;
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_native_init (MetaCursorTrackerNative *self)
|
||||
{
|
||||
MetaWaylandCompositor *compositor;
|
||||
CoglContext *ctx;
|
||||
MetaMonitorManager *monitors;
|
||||
|
||||
ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
||||
self->pipeline = cogl_pipeline_new (ctx);
|
||||
|
||||
compositor = meta_wayland_compositor_get_default ();
|
||||
compositor->seat->cursor_tracker = META_CURSOR_TRACKER (self);
|
||||
meta_cursor_tracker_native_update_position (self,
|
||||
wl_fixed_to_int (compositor->seat->pointer.x),
|
||||
wl_fixed_to_int (compositor->seat->pointer.y));
|
||||
|
||||
#if defined(CLUTTER_WINDOWING_EGL)
|
||||
if (clutter_check_windowing_backend (CLUTTER_WINDOWING_EGL))
|
||||
{
|
||||
CoglRenderer *cogl_renderer = cogl_display_get_renderer (cogl_context_get_display (ctx));
|
||||
self->drm_fd = cogl_kms_renderer_get_kms_fd (cogl_renderer);
|
||||
self->gbm = gbm_create_device (self->drm_fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
monitors = meta_monitor_manager_get ();
|
||||
g_signal_connect_object (monitors, "monitors-changed",
|
||||
G_CALLBACK (on_monitors_changed), self, 0);
|
||||
}
|
||||
|
||||
void
|
||||
meta_cursor_tracker_native_update_position (MetaCursorTrackerNative *self,
|
||||
int new_x,
|
||||
int new_y)
|
||||
{
|
||||
self->current_x = new_x;
|
||||
self->current_y = new_y;
|
||||
|
||||
_meta_cursor_tracker_sync_cursor (META_CURSOR_TRACKER (self));
|
||||
}
|
||||
|
||||
void
|
||||
meta_cursor_tracker_native_paint (MetaCursorTrackerNative *self)
|
||||
{
|
||||
MetaCursorTracker *tracker = META_CURSOR_TRACKER (self);
|
||||
|
||||
if (self->has_hw_cursor || !tracker->displayed_cursor)
|
||||
return;
|
||||
|
||||
cogl_framebuffer_draw_rectangle (cogl_get_draw_framebuffer (),
|
||||
self->pipeline,
|
||||
self->current_rect.x,
|
||||
self->current_rect.y,
|
||||
self->current_rect.x +
|
||||
self->current_rect.width,
|
||||
self->current_rect.y +
|
||||
self->current_rect.height);
|
||||
|
||||
self->previous_rect = self->current_rect;
|
||||
self->previous_is_valid = TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
meta_cursor_tracker_native_force_update (MetaCursorTrackerNative *self)
|
||||
{
|
||||
_meta_cursor_tracker_sync_cursor (META_CURSOR_TRACKER (self));
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 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/>.
|
||||
*/
|
||||
|
||||
#ifndef META_CURSOR_TRACKER_NATIVE_H
|
||||
#define META_CURSOR_TRACKER_NATIVE_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <meta/meta-cursor-tracker.h>
|
||||
|
||||
#define META_TYPE_CURSOR_TRACKER_NATIVE (meta_cursor_tracker_native_get_type ())
|
||||
#define META_CURSOR_TRACKER_NATIVE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_CURSOR_TRACKER_NATIVE, MetaCursorTrackerNative))
|
||||
#define META_CURSOR_TRACKER_NATIVE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_CURSOR_TRACKER_NATIVE, MetaCursorTrackerNativeClass))
|
||||
#define META_IS_CURSOR_TRACKER_NATIVE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_CURSOR_TRACKER_NATIVE))
|
||||
#define META_IS_CURSOR_TRACKER_NATIVE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_CURSOR_TRACKER_NATIVE))
|
||||
#define META_CURSOR_TRACKER_NATIVE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_CURSOR_TRACKER_NATIVE, MetaCursorTrackerNativeClass))
|
||||
|
||||
typedef struct _MetaCursorTrackerNative MetaCursorTrackerNative;
|
||||
typedef struct _MetaCursorTrackerNativeClass MetaCursorTrackerNativeClass;
|
||||
|
||||
GType meta_cursor_tracker_native_get_type (void);
|
||||
|
||||
void meta_cursor_tracker_native_update_position (MetaCursorTrackerNative *tracker,
|
||||
int new_x,
|
||||
int new_y);
|
||||
void meta_cursor_tracker_native_paint (MetaCursorTrackerNative *tracker);
|
||||
|
||||
void meta_cursor_tracker_native_force_update (MetaCursorTrackerNative *tracker);
|
||||
|
||||
#endif /* META_CURSOR_TRACKER_NATIVE_H */
|
@ -44,7 +44,6 @@
|
||||
|
||||
#include "wayland/meta-wayland-private.h"
|
||||
#include "meta-cursor-tracker-private.h"
|
||||
#include "meta-cursor-tracker-native.h"
|
||||
#include "meta-weston-launch.h"
|
||||
|
||||
struct _MetaLauncher
|
||||
@ -220,7 +219,7 @@ meta_launcher_enter (MetaLauncher *launcher)
|
||||
* update. */
|
||||
|
||||
clutter_actor_queue_redraw (compositor->stage);
|
||||
meta_cursor_tracker_native_force_update (META_CURSOR_TRACKER_NATIVE (compositor->seat->cursor_tracker));
|
||||
meta_cursor_tracker_force_update (compositor->seat->cursor_tracker);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,138 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 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/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
#include <meta/errors.h>
|
||||
|
||||
#include "display-private.h"
|
||||
#include "meta-cursor-tracker-x11.h"
|
||||
#include "meta-cursor-tracker-private.h"
|
||||
#include "meta-cursor-private.h"
|
||||
|
||||
struct _MetaCursorTrackerX11
|
||||
{
|
||||
MetaCursorTracker parent;
|
||||
};
|
||||
|
||||
struct _MetaCursorTrackerX11Class
|
||||
{
|
||||
MetaCursorTrackerClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (MetaCursorTrackerX11, meta_cursor_tracker_x11, META_TYPE_CURSOR_TRACKER);
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_x11_get_pointer (MetaCursorTracker *tracker,
|
||||
int *x,
|
||||
int *y,
|
||||
ClutterModifierType *mods)
|
||||
{
|
||||
GdkDeviceManager *gmanager;
|
||||
GdkDevice *gdevice;
|
||||
GdkScreen *gscreen;
|
||||
|
||||
/* We can't use the clutter interface when not running as a wayland
|
||||
* compositor, because we need to query the server, rather than
|
||||
* using the last cached value.
|
||||
*/
|
||||
gmanager = gdk_display_get_device_manager (gdk_display_get_default ());
|
||||
gdevice = gdk_x11_device_manager_lookup (gmanager, META_VIRTUAL_CORE_POINTER_ID);
|
||||
|
||||
gdk_device_get_position (gdevice, &gscreen, x, y);
|
||||
if (mods)
|
||||
gdk_device_get_state (gdevice,
|
||||
gdk_screen_get_root_window (gscreen),
|
||||
NULL, (GdkModifierType*)mods);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_x11_sync_cursor (MetaCursorTracker *tracker)
|
||||
{
|
||||
MetaDisplay *display = meta_get_display ();
|
||||
|
||||
meta_error_trap_push (display);
|
||||
if (tracker->is_showing)
|
||||
XFixesShowCursor (display->xdisplay,
|
||||
DefaultRootWindow (display->xdisplay));
|
||||
else
|
||||
XFixesHideCursor (display->xdisplay,
|
||||
DefaultRootWindow (display->xdisplay));
|
||||
meta_error_trap_pop (display);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_x11_ensure_cursor (MetaCursorTracker *tracker)
|
||||
{
|
||||
MetaDisplay *display = meta_get_display ();
|
||||
XFixesCursorImage *cursor_image;
|
||||
MetaCursorReference *cursor;
|
||||
|
||||
if (tracker->has_window_cursor)
|
||||
return;
|
||||
|
||||
cursor_image = XFixesGetCursorImage (display->xdisplay);
|
||||
if (!cursor_image)
|
||||
return;
|
||||
|
||||
cursor = meta_cursor_reference_from_xfixes_cursor_image (cursor_image);
|
||||
|
||||
_meta_cursor_tracker_set_window_cursor (tracker, TRUE, cursor);
|
||||
|
||||
XFree (cursor_image);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_x11_class_init (MetaCursorTrackerX11Class *klass)
|
||||
{
|
||||
MetaCursorTrackerClass *cursor_tracker_class = META_CURSOR_TRACKER_CLASS (klass);
|
||||
|
||||
cursor_tracker_class->get_pointer = meta_cursor_tracker_x11_get_pointer;
|
||||
cursor_tracker_class->sync_cursor = meta_cursor_tracker_x11_sync_cursor;
|
||||
cursor_tracker_class->ensure_cursor = meta_cursor_tracker_x11_ensure_cursor;
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_tracker_x11_init (MetaCursorTrackerX11 *self)
|
||||
{
|
||||
MetaDisplay *display = meta_get_display ();
|
||||
|
||||
XFixesSelectCursorInput (display->xdisplay,
|
||||
DefaultRootWindow (display->xdisplay),
|
||||
XFixesDisplayCursorNotifyMask);
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_cursor_tracker_x11_handle_xevent (MetaCursorTrackerX11 *tracker,
|
||||
XEvent *xevent)
|
||||
{
|
||||
MetaDisplay *display = meta_get_display ();
|
||||
XFixesCursorNotifyEvent *notify_event;
|
||||
|
||||
if (xevent->xany.type != display->xfixes_event_base + XFixesCursorNotify)
|
||||
return FALSE;
|
||||
|
||||
notify_event = (XFixesCursorNotifyEvent *)xevent;
|
||||
if (notify_event->subtype != XFixesDisplayCursorNotify)
|
||||
return FALSE;
|
||||
|
||||
_meta_cursor_tracker_set_window_cursor (META_CURSOR_TRACKER (tracker), FALSE, NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 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/>.
|
||||
*/
|
||||
|
||||
#ifndef META_CURSOR_TRACKER_X11_H
|
||||
#define META_CURSOR_TRACKER_X11_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <meta/meta-cursor-tracker.h>
|
||||
|
||||
#define META_TYPE_CURSOR_TRACKER_X11 (meta_cursor_tracker_x11_get_type ())
|
||||
#define META_CURSOR_TRACKER_X11(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_CURSOR_TRACKER_X11, MetaCursorTrackerX11))
|
||||
#define META_CURSOR_TRACKER_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_CURSOR_TRACKER_X11, MetaCursorTrackerX11Class))
|
||||
#define META_IS_CURSOR_TRACKER_X11(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_CURSOR_TRACKER_X11))
|
||||
#define META_IS_CURSOR_TRACKER_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_CURSOR_TRACKER_X11))
|
||||
#define META_CURSOR_TRACKER_X11_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_CURSOR_TRACKER_X11, MetaCursorTrackerX11Class))
|
||||
|
||||
typedef struct _MetaCursorTrackerX11 MetaCursorTrackerX11;
|
||||
typedef struct _MetaCursorTrackerX11Class MetaCursorTrackerX11Class;
|
||||
|
||||
GType meta_cursor_tracker_x11_get_type (void);
|
||||
|
||||
gboolean
|
||||
meta_cursor_tracker_x11_handle_xevent (MetaCursorTrackerX11 *tracker,
|
||||
XEvent *xevent);
|
||||
|
||||
#endif /* META_CURSOR_TRACKER_X11_H */
|
@ -491,7 +491,7 @@ redirect_windows (MetaScreen *screen)
|
||||
*/
|
||||
while (TRUE)
|
||||
{
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
XCompositeRedirectSubwindows (xdisplay, xroot, CompositeRedirectManual);
|
||||
XSync (xdisplay, FALSE);
|
||||
|
||||
|
@ -31,7 +31,6 @@
|
||||
|
||||
#include <glib.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xcursor/Xcursor.h>
|
||||
#include <meta/common.h>
|
||||
#include <meta/boxes.h>
|
||||
#include <meta/display.h>
|
||||
@ -93,6 +92,7 @@ struct _MetaDisplay
|
||||
Display *xdisplay;
|
||||
|
||||
int clutter_event_filter;
|
||||
GSource *x11_event_source;
|
||||
|
||||
Window leader_window;
|
||||
Window timestamp_pinging_window;
|
||||
@ -148,13 +148,10 @@ struct _MetaDisplay
|
||||
guint focused_by_us : 1;
|
||||
|
||||
/*< private-ish >*/
|
||||
guint error_trap_synced_at_last_pop : 1;
|
||||
MetaScreen *screen;
|
||||
GHashTable *xids;
|
||||
GHashTable *wayland_windows;
|
||||
int error_traps;
|
||||
int (* error_trap_handler) (Display *display,
|
||||
XErrorEvent *error);
|
||||
|
||||
int server_grab_count;
|
||||
|
||||
/* serials of leave/unmap events that may
|
||||
@ -257,6 +254,8 @@ struct _MetaDisplay
|
||||
/* Closing down the display */
|
||||
int closing;
|
||||
|
||||
GSList *error_traps;
|
||||
|
||||
/* Managed by group.c */
|
||||
GHashTable *groups_by_leader;
|
||||
|
||||
@ -398,8 +397,6 @@ MetaDisplay* meta_get_display (void);
|
||||
|
||||
Cursor meta_display_create_x_cursor (MetaDisplay *display,
|
||||
MetaCursor cursor);
|
||||
XcursorImage *meta_display_load_x_cursor (MetaDisplay *display,
|
||||
MetaCursor cursor);
|
||||
|
||||
void meta_display_set_grab_op_cursor (MetaDisplay *display,
|
||||
MetaScreen *screen,
|
||||
|
@ -446,7 +446,7 @@ meta_display_open (void)
|
||||
|
||||
meta_verbose ("Opening display '%s'\n", XDisplayName (NULL));
|
||||
|
||||
xdisplay = meta_ui_get_display ();
|
||||
xdisplay = XOpenDisplay (NULL);
|
||||
|
||||
if (xdisplay == NULL)
|
||||
{
|
||||
@ -472,9 +472,6 @@ meta_display_open (void)
|
||||
*/
|
||||
the_display->name = g_strdup (XDisplayName (NULL));
|
||||
the_display->xdisplay = xdisplay;
|
||||
the_display->error_trap_synced_at_last_pop = TRUE;
|
||||
the_display->error_traps = 0;
|
||||
the_display->error_trap_handler = NULL;
|
||||
the_display->server_grab_count = 0;
|
||||
the_display->display_opening = TRUE;
|
||||
|
||||
@ -835,7 +832,7 @@ meta_display_open (void)
|
||||
* now it always manages exactly one screen as specified by the DISPLAY
|
||||
* environment variable.
|
||||
*/
|
||||
i = meta_ui_get_screen_number ();
|
||||
i = DefaultScreen (the_display->xdisplay);
|
||||
screen = meta_screen_new (the_display, i, timestamp);
|
||||
|
||||
if (!screen)
|
||||
@ -1016,9 +1013,6 @@ meta_display_close (MetaDisplay *display,
|
||||
return;
|
||||
}
|
||||
|
||||
if (display->error_traps > 0)
|
||||
meta_bug ("Display closed with error traps pending\n");
|
||||
|
||||
display->closing += 1;
|
||||
|
||||
meta_prefs_remove_listener (prefs_changed_callback, display);
|
||||
@ -1873,7 +1867,7 @@ meta_display_set_grab_op_cursor (MetaDisplay *display,
|
||||
|
||||
meta_error_trap_pop (display);
|
||||
|
||||
cursor_ref = meta_cursor_tracker_get_cursor_from_theme (screen->cursor_tracker, cursor);
|
||||
cursor_ref = meta_cursor_reference_from_theme (screen->cursor_tracker, cursor);
|
||||
meta_cursor_tracker_set_grab_cursor (screen->cursor_tracker, cursor_ref);
|
||||
meta_cursor_reference_unref (cursor_ref);
|
||||
}
|
||||
@ -2212,7 +2206,7 @@ meta_change_button_grab (MetaDisplay *display,
|
||||
mods = (XIGrabModifiers) { modmask | ignored_mask, 0 };
|
||||
|
||||
if (meta_is_debugging ())
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
|
||||
/* GrabModeSync means freeze until XAllowEvents */
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2001 Havoc Pennington, error trapping inspired by GDK
|
||||
* code copyrighted by the GTK team.
|
||||
*
|
||||
/*
|
||||
* 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
|
||||
@ -13,9 +12,11 @@
|
||||
* 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/>.
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -27,42 +28,250 @@
|
||||
#include <config.h>
|
||||
#include <meta/errors.h>
|
||||
#include "display-private.h"
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
/* In GTK+-3.0, the error trapping code was significantly rewritten. The new code
|
||||
* has some neat features (like knowing automatically if a sync is needed or not
|
||||
* and handling errors asynchronously when the error code isn't needed immediately),
|
||||
* but it's basically incompatible with the hacks we played with GTK+-2.0 to
|
||||
* use a custom error handler along with gdk_error_trap_push().
|
||||
*
|
||||
* Since the main point of our custom error trap was to get the error logged
|
||||
* to the right place, with GTK+-3.0 we simply omit our own error handler and
|
||||
* use the GTK+ handling straight-up.
|
||||
* (See https://bugzilla.gnome.org/show_bug.cgi?id=630216 for restoring logging.)
|
||||
*/
|
||||
/* This is a copy-paste of the error handling code in GDK, modified
|
||||
* so that it works with mutter's internal structures, since we don't
|
||||
* have a GDK display open. */
|
||||
|
||||
/* compare X sequence numbers handling wraparound */
|
||||
#define SEQUENCE_COMPARE(a,op,b) (((long) (a) - (long) (b)) op 0)
|
||||
|
||||
typedef struct _GdkErrorTrap GdkErrorTrap;
|
||||
|
||||
struct _GdkErrorTrap
|
||||
{
|
||||
/* Next sequence when trap was pushed, i.e. first sequence to
|
||||
* ignore
|
||||
*/
|
||||
gulong start_sequence;
|
||||
|
||||
/* Next sequence when trap was popped, i.e. first sequence
|
||||
* to not ignore. 0 if trap is still active.
|
||||
*/
|
||||
gulong end_sequence;
|
||||
|
||||
/* Most recent error code within the sequence */
|
||||
int error_code;
|
||||
};
|
||||
|
||||
/* delivers an error event from the error handler in gdkmain-x11.c */
|
||||
static void
|
||||
meta_display_error_event (MetaDisplay *display,
|
||||
XErrorEvent *error)
|
||||
{
|
||||
GSList *tmp_list;
|
||||
gboolean ignore;
|
||||
|
||||
ignore = FALSE;
|
||||
for (tmp_list = display->error_traps;
|
||||
tmp_list != NULL;
|
||||
tmp_list = tmp_list->next)
|
||||
{
|
||||
GdkErrorTrap *trap;
|
||||
|
||||
trap = tmp_list->data;
|
||||
|
||||
if (SEQUENCE_COMPARE (trap->start_sequence, <=, error->serial) &&
|
||||
(trap->end_sequence == 0 ||
|
||||
SEQUENCE_COMPARE (trap->end_sequence, >, error->serial)))
|
||||
{
|
||||
ignore = TRUE;
|
||||
trap->error_code = error->error_code;
|
||||
break; /* only innermost trap gets the error code */
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignore)
|
||||
{
|
||||
gchar buf[64];
|
||||
gchar *msg;
|
||||
|
||||
XGetErrorText (display->xdisplay, error->error_code, buf, 63);
|
||||
|
||||
msg =
|
||||
g_strdup_printf ("mutter received an X Window System error: %s\n"
|
||||
" (Details: serial %ld error_code %d request_code %d minor_code %d)\n",
|
||||
buf,
|
||||
error->serial,
|
||||
error->error_code,
|
||||
error->request_code,
|
||||
error->minor_code);
|
||||
|
||||
g_error ("%s", msg);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
gdk_x_error (Display *xdisplay,
|
||||
XErrorEvent *error)
|
||||
{
|
||||
MetaDisplay *display = meta_display_for_x_display (xdisplay);
|
||||
meta_display_error_event (display, error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* non-GDK previous error handler */
|
||||
typedef int (*GdkXErrorHandler) (Display *, XErrorEvent *);
|
||||
static GdkXErrorHandler _gdk_old_error_handler;
|
||||
/* number of times we've pushed the GDK error handler */
|
||||
static int _gdk_error_handler_push_count = 0;
|
||||
|
||||
static void
|
||||
_gdk_x11_error_handler_push (void)
|
||||
{
|
||||
GdkXErrorHandler previous;
|
||||
|
||||
previous = XSetErrorHandler (gdk_x_error);
|
||||
|
||||
if (_gdk_error_handler_push_count > 0)
|
||||
{
|
||||
if (previous != gdk_x_error)
|
||||
g_warning ("XSetErrorHandler() called with a GDK error trap pushed. Don't do that.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_gdk_old_error_handler = previous;
|
||||
}
|
||||
|
||||
_gdk_error_handler_push_count += 1;
|
||||
}
|
||||
|
||||
static void
|
||||
_gdk_x11_error_handler_pop (void)
|
||||
{
|
||||
g_return_if_fail (_gdk_error_handler_push_count > 0);
|
||||
|
||||
_gdk_error_handler_push_count -= 1;
|
||||
|
||||
if (_gdk_error_handler_push_count == 0)
|
||||
{
|
||||
XSetErrorHandler (_gdk_old_error_handler);
|
||||
_gdk_old_error_handler = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
delete_outdated_error_traps (MetaDisplay *display)
|
||||
{
|
||||
GSList *tmp_list;
|
||||
gulong processed_sequence;
|
||||
|
||||
processed_sequence = XLastKnownRequestProcessed (display->xdisplay);
|
||||
|
||||
tmp_list = display->error_traps;
|
||||
while (tmp_list != NULL)
|
||||
{
|
||||
GdkErrorTrap *trap = tmp_list->data;
|
||||
|
||||
if (trap->end_sequence != 0 &&
|
||||
SEQUENCE_COMPARE (trap->end_sequence, <=, processed_sequence))
|
||||
{
|
||||
GSList *free_me = tmp_list;
|
||||
|
||||
tmp_list = tmp_list->next;
|
||||
display->error_traps = g_slist_delete_link (display->error_traps, free_me);
|
||||
g_slice_free (GdkErrorTrap, trap);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
meta_error_trap_push (MetaDisplay *display)
|
||||
{
|
||||
gdk_error_trap_push ();
|
||||
GdkErrorTrap *trap;
|
||||
|
||||
delete_outdated_error_traps (display);
|
||||
|
||||
/* set up the Xlib callback to tell us about errors */
|
||||
_gdk_x11_error_handler_push ();
|
||||
|
||||
trap = g_slice_new0 (GdkErrorTrap);
|
||||
|
||||
trap->start_sequence = XNextRequest (display->xdisplay);
|
||||
trap->error_code = Success;
|
||||
|
||||
display->error_traps =
|
||||
g_slist_prepend (display->error_traps, trap);
|
||||
}
|
||||
|
||||
static gint
|
||||
meta_error_trap_pop_internal (MetaDisplay *display,
|
||||
gboolean need_code)
|
||||
{
|
||||
GdkErrorTrap *trap;
|
||||
GSList *tmp_list;
|
||||
int result;
|
||||
|
||||
g_return_val_if_fail (display->error_traps != NULL, Success);
|
||||
|
||||
/* Find the first trap that hasn't been popped already */
|
||||
trap = NULL; /* quiet gcc */
|
||||
for (tmp_list = display->error_traps;
|
||||
tmp_list != NULL;
|
||||
tmp_list = tmp_list->next)
|
||||
{
|
||||
trap = tmp_list->data;
|
||||
|
||||
if (trap->end_sequence == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
g_return_val_if_fail (trap != NULL, Success);
|
||||
g_assert (trap->end_sequence == 0);
|
||||
|
||||
/* May need to sync to fill in trap->error_code if we care about
|
||||
* getting an error code.
|
||||
*/
|
||||
if (need_code)
|
||||
{
|
||||
gulong processed_sequence;
|
||||
gulong next_sequence;
|
||||
|
||||
next_sequence = XNextRequest (display->xdisplay);
|
||||
processed_sequence = XLastKnownRequestProcessed (display->xdisplay);
|
||||
|
||||
/* If our last request was already processed, there is no point
|
||||
* in syncing. i.e. if last request was a round trip (or even if
|
||||
* we got an event with the serial of a non-round-trip)
|
||||
*/
|
||||
if ((next_sequence - 1) != processed_sequence)
|
||||
{
|
||||
XSync (display->xdisplay, False);
|
||||
}
|
||||
|
||||
result = trap->error_code;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = Success;
|
||||
}
|
||||
|
||||
/* record end of trap, giving us a range of
|
||||
* error sequences we'll ignore.
|
||||
*/
|
||||
trap->end_sequence = XNextRequest (display->xdisplay);
|
||||
|
||||
/* remove the Xlib callback */
|
||||
_gdk_x11_error_handler_pop ();
|
||||
|
||||
/* we may already be outdated */
|
||||
delete_outdated_error_traps (display);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
meta_error_trap_pop (MetaDisplay *display)
|
||||
{
|
||||
gdk_error_trap_pop_ignored ();
|
||||
}
|
||||
|
||||
void
|
||||
meta_error_trap_push_with_return (MetaDisplay *display)
|
||||
{
|
||||
gdk_error_trap_push ();
|
||||
meta_error_trap_pop_internal (display, FALSE);
|
||||
}
|
||||
|
||||
int
|
||||
meta_error_trap_pop_with_return (MetaDisplay *display)
|
||||
{
|
||||
return gdk_error_trap_pop ();
|
||||
return meta_error_trap_pop_internal (display, TRUE);
|
||||
}
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
#include "x11/window-x11.h"
|
||||
#include "x11/xprops.h"
|
||||
#include "wayland/meta-xwayland.h"
|
||||
#include "wayland/meta-wayland-private.h"
|
||||
#include "meta-surface-actor-wayland.h"
|
||||
|
||||
@ -77,9 +78,8 @@ get_input_event (MetaDisplay *display,
|
||||
{
|
||||
XIEvent *input_event;
|
||||
|
||||
/* NB: GDK event filters already have generic events
|
||||
* allocated, so no need to do XGetEventData() on our own
|
||||
*/
|
||||
XGetEventData (display->xdisplay, &event->xcookie);
|
||||
|
||||
input_event = (XIEvent *) event->xcookie.data;
|
||||
|
||||
switch (input_event->evtype)
|
||||
@ -859,6 +859,17 @@ handle_input_xevent (MetaDisplay *display,
|
||||
if (input_event == NULL)
|
||||
return FALSE;
|
||||
|
||||
switch (input_event->evtype)
|
||||
{
|
||||
case XI_Enter:
|
||||
case XI_Leave:
|
||||
case XI_FocusIn:
|
||||
case XI_FocusOut:
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
modified = xievent_get_modified_window (display, input_event);
|
||||
window = modified != None ? meta_display_lookup_x_window (display, modified) : NULL;
|
||||
|
||||
@ -933,12 +944,11 @@ handle_input_xevent (MetaDisplay *display,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Don't send FocusIn / FocusOut to Clutter */
|
||||
return TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
/* Don't pass these events through to Clutter / GTK+ */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1040,7 +1050,7 @@ convert_property (MetaDisplay *display,
|
||||
conversion_targets[2] = display->atom_TIMESTAMP;
|
||||
conversion_targets[3] = display->atom_VERSION;
|
||||
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
if (target == display->atom_TARGETS)
|
||||
XChangeProperty (display->xdisplay, w, property,
|
||||
XA_ATOM, 32, PropModeReplace,
|
||||
@ -1115,7 +1125,7 @@ process_selection_request (MetaDisplay *display,
|
||||
unsigned long num, rest;
|
||||
unsigned char *data;
|
||||
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
if (XGetWindowProperty (display->xdisplay,
|
||||
event->xselectionrequest.requestor,
|
||||
event->xselectionrequest.property, 0, 256, False,
|
||||
@ -1536,7 +1546,12 @@ handle_other_xevent (MetaDisplay *display,
|
||||
case ClientMessage:
|
||||
if (window)
|
||||
{
|
||||
if (!frame_was_receiver)
|
||||
if (event->xclient.message_type == display->atom_WL_SURFACE_ID)
|
||||
{
|
||||
guint32 surface_id = event->xclient.data.l[0];
|
||||
meta_xwayland_handle_wl_surface_id (window, surface_id);
|
||||
}
|
||||
else if (!frame_was_receiver)
|
||||
meta_window_x11_client_message (window, event);
|
||||
}
|
||||
else
|
||||
@ -1734,12 +1749,12 @@ window_has_xwindow (MetaWindow *window,
|
||||
* busy around here. Most of this function is a ginormous switch statement
|
||||
* dealing with all the kinds of events that might turn up.
|
||||
*/
|
||||
static gboolean
|
||||
static void
|
||||
meta_display_handle_xevent (MetaDisplay *display,
|
||||
XEvent *event)
|
||||
{
|
||||
Window modified;
|
||||
gboolean bypass_compositor = FALSE, bypass_gtk = FALSE;
|
||||
gboolean bypass_compositor = FALSE;
|
||||
XIEvent *input_event;
|
||||
MetaMonitorManager *monitor;
|
||||
|
||||
@ -1748,13 +1763,13 @@ meta_display_handle_xevent (MetaDisplay *display,
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STARTUP_NOTIFICATION
|
||||
sn_display_process_event (display->sn_display, event);
|
||||
if (sn_display_process_event (display->sn_display, event))
|
||||
{
|
||||
bypass_compositor = TRUE;
|
||||
goto out;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Intercept XRandR events early and don't attempt any
|
||||
processing for them. We still let them through to Gdk though,
|
||||
so it can update its own internal state.
|
||||
*/
|
||||
monitor = meta_monitor_manager_get ();
|
||||
if (meta_monitor_manager_handle_xevent (monitor, event))
|
||||
{
|
||||
@ -1783,7 +1798,7 @@ meta_display_handle_xevent (MetaDisplay *display,
|
||||
{
|
||||
if (meta_screen_handle_xevent (display->screen, event))
|
||||
{
|
||||
bypass_gtk = bypass_compositor = TRUE;
|
||||
bypass_compositor = TRUE;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@ -1794,8 +1809,9 @@ meta_display_handle_xevent (MetaDisplay *display,
|
||||
|
||||
if (event->type == UnmapNotify)
|
||||
{
|
||||
if (meta_ui_window_should_not_cause_focus (display->xdisplay,
|
||||
modified))
|
||||
MetaUI *ui = display->screen->ui;
|
||||
|
||||
if (meta_ui_window_should_not_cause_focus (ui, modified))
|
||||
{
|
||||
meta_display_add_ignored_crossing_serial (display, event->xany.serial);
|
||||
meta_topic (META_DEBUG_FOCUS,
|
||||
@ -1817,7 +1833,7 @@ meta_display_handle_xevent (MetaDisplay *display,
|
||||
#ifdef HAVE_XI23
|
||||
if (meta_display_process_barrier_event (display, input_event))
|
||||
{
|
||||
bypass_gtk = bypass_compositor = TRUE;
|
||||
bypass_compositor = TRUE;
|
||||
goto out;
|
||||
}
|
||||
#endif /* HAVE_XI23 */
|
||||
@ -1828,27 +1844,20 @@ meta_display_handle_xevent (MetaDisplay *display,
|
||||
*/
|
||||
if (handle_input_xevent (display, input_event, event->xany.serial))
|
||||
{
|
||||
bypass_gtk = bypass_compositor = TRUE;
|
||||
bypass_compositor = TRUE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (handle_other_xevent (display, event))
|
||||
{
|
||||
bypass_gtk = TRUE;
|
||||
goto out;
|
||||
}
|
||||
goto out;
|
||||
|
||||
out:
|
||||
if (!bypass_compositor)
|
||||
{
|
||||
MetaWindow *window = modified != None ? meta_display_lookup_x_window (display, modified) : NULL;
|
||||
|
||||
if (meta_compositor_process_event (display->compositor, event, window))
|
||||
bypass_gtk = TRUE;
|
||||
meta_compositor_process_event (display->compositor, event, window);
|
||||
}
|
||||
|
||||
display->current_time = CurrentTime;
|
||||
return bypass_gtk;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -2159,19 +2168,6 @@ meta_display_handle_event (MetaDisplay *display,
|
||||
return bypass_clutter;
|
||||
}
|
||||
|
||||
static GdkFilterReturn
|
||||
xevent_filter (GdkXEvent *xevent,
|
||||
GdkEvent *event,
|
||||
gpointer data)
|
||||
{
|
||||
MetaDisplay *display = data;
|
||||
|
||||
if (meta_display_handle_xevent (display, xevent))
|
||||
return GDK_FILTER_REMOVE;
|
||||
else
|
||||
return GDK_FILTER_CONTINUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
event_callback (const ClutterEvent *event,
|
||||
gpointer data)
|
||||
@ -2181,20 +2177,90 @@ event_callback (const ClutterEvent *event,
|
||||
return meta_display_handle_event (display, event);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GSource source;
|
||||
|
||||
MetaDisplay *display;
|
||||
GPollFD event_poll_fd;
|
||||
} X11EventSource;
|
||||
|
||||
static gboolean
|
||||
x11_event_source_prepare (GSource *source,
|
||||
gint *timeout)
|
||||
{
|
||||
X11EventSource *source_x11 = (X11EventSource *) source;
|
||||
MetaDisplay *display = source_x11->display;
|
||||
|
||||
*timeout = -1;
|
||||
|
||||
return XPending (display->xdisplay);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
x11_event_source_check (GSource *source)
|
||||
{
|
||||
X11EventSource *source_x11 = (X11EventSource *) source;
|
||||
MetaDisplay *display = source_x11->display;
|
||||
|
||||
if (source_x11->event_poll_fd.revents & G_IO_IN)
|
||||
return XPending (display->xdisplay);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
x11_event_source_dispatch (GSource *source,
|
||||
GSourceFunc callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
X11EventSource *source_x11 = (X11EventSource *) source;
|
||||
MetaDisplay *display = source_x11->display;
|
||||
XEvent event;
|
||||
|
||||
XNextEvent (display->xdisplay, &event);
|
||||
meta_display_handle_xevent (display, &event);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GSourceFuncs x11_event_source_funcs = {
|
||||
x11_event_source_prepare,
|
||||
x11_event_source_check,
|
||||
x11_event_source_dispatch,
|
||||
};
|
||||
|
||||
static GSource *
|
||||
x11_event_source_new (MetaDisplay *display)
|
||||
{
|
||||
GSource *source = g_source_new (&x11_event_source_funcs, sizeof (X11EventSource));
|
||||
X11EventSource *source_x11 = (X11EventSource *) source;
|
||||
|
||||
source_x11->display = display;
|
||||
source_x11->event_poll_fd.fd = ConnectionNumber (display->xdisplay);
|
||||
source_x11->event_poll_fd.events = G_IO_IN;
|
||||
g_source_add_poll (source, &source_x11->event_poll_fd);
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
void
|
||||
meta_display_init_events (MetaDisplay *display)
|
||||
{
|
||||
gdk_window_add_filter (NULL, xevent_filter, display);
|
||||
display->clutter_event_filter = clutter_event_add_filter (NULL,
|
||||
event_callback,
|
||||
NULL,
|
||||
display);
|
||||
|
||||
display->x11_event_source = x11_event_source_new (display);
|
||||
g_source_attach (display->x11_event_source, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
meta_display_free_events (MetaDisplay *display)
|
||||
{
|
||||
gdk_window_remove_filter (NULL, xevent_filter, display);
|
||||
clutter_event_remove_filter (display->clutter_event_filter);
|
||||
display->clutter_event_filter = 0;
|
||||
|
||||
g_source_unref (display->x11_event_source);
|
||||
display->x11_event_source = NULL;
|
||||
}
|
||||
|
@ -92,7 +92,6 @@ meta_window_ensure_frame (MetaWindow *window)
|
||||
visual = NULL;
|
||||
|
||||
frame->xwindow = meta_ui_create_frame_window (window->screen->ui,
|
||||
window->display->xdisplay,
|
||||
visual,
|
||||
frame->rect.x,
|
||||
frame->rect.y,
|
||||
|
@ -1065,7 +1065,7 @@ meta_change_keygrab (MetaDisplay *display,
|
||||
mods = (XIGrabModifiers) { modmask | ignored_mask, 0 };
|
||||
|
||||
if (meta_is_debugging ())
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
if (grab)
|
||||
XIGrabKeycode (display->xdisplay,
|
||||
META_VIRTUAL_CORE_KEYBOARD_ID,
|
||||
@ -1410,7 +1410,7 @@ grab_keyboard (MetaDisplay *display,
|
||||
/* Grab the keyboard, so we get key releases and all key
|
||||
* presses
|
||||
*/
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
|
||||
/* Strictly, we only need to set grab_mode on the keyboard device
|
||||
* while the pointer should always be XIGrabModeAsync. Unfortunately
|
||||
|
@ -43,7 +43,6 @@
|
||||
#include "mutter-enum-types.h"
|
||||
#include "core.h"
|
||||
#include "meta-cursor-tracker-private.h"
|
||||
#include "backends/x11/meta-cursor-tracker-x11.h"
|
||||
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
|
||||
@ -561,7 +560,7 @@ meta_screen_new (MetaDisplay *display,
|
||||
}
|
||||
|
||||
/* We want to find out when the current selection owner dies */
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
attrs.event_mask = StructureNotifyMask;
|
||||
XChangeWindowAttributes (xdisplay,
|
||||
current_wm_sn_owner, CWEventMask, &attrs);
|
||||
@ -620,7 +619,7 @@ meta_screen_new (MetaDisplay *display,
|
||||
}
|
||||
|
||||
/* select our root window events */
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
|
||||
/* We need to or with the existing event mask since
|
||||
* gtk+ may be interested in other events.
|
||||
@ -758,8 +757,7 @@ meta_screen_new (MetaDisplay *display,
|
||||
screen->keys_grabbed = FALSE;
|
||||
meta_screen_grab_keys (screen);
|
||||
|
||||
screen->ui = meta_ui_new (screen->display->xdisplay,
|
||||
screen->xscreen);
|
||||
screen->ui = meta_ui_new ();
|
||||
|
||||
screen->tile_preview_timeout_id = 0;
|
||||
|
||||
@ -839,7 +837,7 @@ meta_screen_free (MetaScreen *screen,
|
||||
meta_stack_free (screen->stack);
|
||||
meta_stack_tracker_free (screen->stack_tracker);
|
||||
|
||||
meta_error_trap_push_with_return (screen->display);
|
||||
meta_error_trap_push (screen->display);
|
||||
XSelectInput (screen->display->xdisplay, screen->xroot, 0);
|
||||
if (meta_error_trap_pop_with_return (screen->display) != Success)
|
||||
meta_warning ("Could not release screen %d on display \"%s\"\n",
|
||||
@ -1390,7 +1388,7 @@ meta_screen_update_cursor (MetaScreen *screen)
|
||||
Cursor xcursor;
|
||||
MetaCursorReference *cursor_ref;
|
||||
|
||||
cursor_ref = meta_cursor_tracker_get_cursor_from_theme (screen->cursor_tracker, cursor);
|
||||
cursor_ref = meta_cursor_reference_from_theme (screen->cursor_tracker, cursor);
|
||||
meta_cursor_tracker_set_root_cursor (screen->cursor_tracker, cursor_ref);
|
||||
meta_cursor_reference_unref (cursor_ref);
|
||||
|
||||
@ -3306,10 +3304,7 @@ gboolean
|
||||
meta_screen_handle_xevent (MetaScreen *screen,
|
||||
XEvent *xevent)
|
||||
{
|
||||
if (meta_is_wayland_compositor ())
|
||||
return FALSE;
|
||||
|
||||
if (meta_cursor_tracker_x11_handle_xevent (META_CURSOR_TRACKER_X11 (screen->cursor_tracker), xevent))
|
||||
if (meta_cursor_tracker_handle_xevent (screen->cursor_tracker, xevent))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
|
@ -3953,7 +3953,7 @@ meta_window_create_sync_request_alarm (MetaWindow *window)
|
||||
window->sync_request_alarm != None)
|
||||
return;
|
||||
|
||||
meta_error_trap_push_with_return (window->display);
|
||||
meta_error_trap_push (window->display);
|
||||
|
||||
/* In the new (extended style), the counter value is initialized by
|
||||
* the client before mapping the window. In the old style, we're
|
||||
@ -8038,7 +8038,7 @@ warp_grab_pointer (MetaWindow *window,
|
||||
*x = CLAMP (*x, 0, window->screen->rect.width-1);
|
||||
*y = CLAMP (*y, 0, window->screen->rect.height-1);
|
||||
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
|
||||
meta_topic (META_DEBUG_WINDOW_OPS,
|
||||
"Warping pointer to %d,%d with window at %d,%d\n",
|
||||
|
@ -81,6 +81,7 @@ item(ATOM_PAIR)
|
||||
item(BACKLIGHT)
|
||||
item(_XKB_RULES_NAMES)
|
||||
item(hotplug_mode_update)
|
||||
item(WL_SURFACE_ID)
|
||||
|
||||
/* Oddities: These are used, and we need atoms for them,
|
||||
* but when we need all _NET_WM hints (i.e. when we're making
|
||||
|
@ -30,7 +30,6 @@
|
||||
void meta_error_trap_push (MetaDisplay *display);
|
||||
void meta_error_trap_pop (MetaDisplay *display);
|
||||
|
||||
void meta_error_trap_push_with_return (MetaDisplay *display);
|
||||
/* returns X error code, or 0 for no error */
|
||||
int meta_error_trap_pop_with_return (MetaDisplay *display);
|
||||
|
||||
|
264
src/ui/ui.c
264
src/ui/ui.c
@ -39,8 +39,9 @@ static void meta_ui_accelerator_parse (const char *accel,
|
||||
|
||||
struct _MetaUI
|
||||
{
|
||||
Display *xdisplay;
|
||||
Screen *xscreen;
|
||||
GdkDisplay *display;
|
||||
GdkScreen *screen;
|
||||
|
||||
MetaFrames *frames;
|
||||
|
||||
/* For double-click tracking */
|
||||
@ -60,202 +61,17 @@ meta_ui_init (void)
|
||||
meta_fatal ("Unable to open X display %s\n", XDisplayName (NULL));
|
||||
}
|
||||
|
||||
Display*
|
||||
meta_ui_get_display (void)
|
||||
{
|
||||
return GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
|
||||
}
|
||||
|
||||
gint
|
||||
meta_ui_get_screen_number (void)
|
||||
{
|
||||
return gdk_screen_get_number (gdk_screen_get_default ());
|
||||
}
|
||||
|
||||
/* For XInput2 */
|
||||
#include "display-private.h"
|
||||
|
||||
static gboolean
|
||||
is_input_event (XEvent *event)
|
||||
{
|
||||
MetaDisplay *display = meta_get_display ();
|
||||
|
||||
return (event->type == GenericEvent &&
|
||||
event->xcookie.extension == display->xinput_opcode);
|
||||
}
|
||||
|
||||
/* We do some of our event handling in frames.c, which expects
|
||||
* GDK events delivered by GTK+. However, since the transition to
|
||||
* client side windows, we can't let GDK see button events, since the
|
||||
* client-side tracking of implicit and explicit grabs it does will
|
||||
* get confused by our direct use of X grabs in the core code.
|
||||
*
|
||||
* So we do a very minimal GDK => GTK event conversion here and send on the
|
||||
* events we care about, and then filter them out so they don't go
|
||||
* through the normal GDK event handling.
|
||||
*
|
||||
* To reduce the amount of code, the only events fields filled out
|
||||
* below are the ones that frames.c uses. If frames.c is modified to
|
||||
* use more fields, more fields need to be filled out below.
|
||||
*/
|
||||
|
||||
static gboolean
|
||||
maybe_redirect_mouse_event (XEvent *xevent)
|
||||
{
|
||||
GdkDisplay *gdisplay;
|
||||
GdkDeviceManager *gmanager;
|
||||
GdkDevice *gdevice;
|
||||
MetaUI *ui;
|
||||
GdkEvent *gevent;
|
||||
GdkWindow *gdk_window;
|
||||
Window window;
|
||||
XIEvent *xev;
|
||||
XIDeviceEvent *xev_d = NULL;
|
||||
XIEnterEvent *xev_e = NULL;
|
||||
|
||||
if (!is_input_event (xevent))
|
||||
return FALSE;
|
||||
|
||||
xev = (XIEvent *) xevent->xcookie.data;
|
||||
|
||||
switch (xev->evtype)
|
||||
{
|
||||
case XI_ButtonPress:
|
||||
case XI_ButtonRelease:
|
||||
case XI_Motion:
|
||||
xev_d = (XIDeviceEvent *) xev;
|
||||
window = xev_d->event;
|
||||
break;
|
||||
case XI_Enter:
|
||||
case XI_Leave:
|
||||
xev_e = (XIEnterEvent *) xev;
|
||||
window = xev_e->event;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gdisplay = gdk_x11_lookup_xdisplay (xev->display);
|
||||
ui = g_object_get_data (G_OBJECT (gdisplay), "meta-ui");
|
||||
if (!ui)
|
||||
return FALSE;
|
||||
|
||||
gdk_window = gdk_x11_window_lookup_for_display (gdisplay, window);
|
||||
if (gdk_window == NULL)
|
||||
return FALSE;
|
||||
|
||||
gmanager = gdk_display_get_device_manager (gdisplay);
|
||||
gdevice = gdk_x11_device_manager_lookup (gmanager, META_VIRTUAL_CORE_POINTER_ID);
|
||||
|
||||
/* If GDK already thinks it has a grab, we better let it see events; this
|
||||
* is the menu-navigation case and events need to get sent to the appropriate
|
||||
* (client-side) subwindow for individual menu items.
|
||||
*/
|
||||
if (gdk_display_device_is_grabbed (gdisplay, gdevice))
|
||||
return FALSE;
|
||||
|
||||
switch (xev->evtype)
|
||||
{
|
||||
case XI_ButtonPress:
|
||||
case XI_ButtonRelease:
|
||||
if (xev_d->evtype == XI_ButtonPress)
|
||||
{
|
||||
GtkSettings *settings = gtk_settings_get_default ();
|
||||
int double_click_time;
|
||||
int double_click_distance;
|
||||
|
||||
g_object_get (settings,
|
||||
"gtk-double-click-time", &double_click_time,
|
||||
"gtk-double-click-distance", &double_click_distance,
|
||||
NULL);
|
||||
|
||||
if (xev_d->detail == ui->button_click_number &&
|
||||
xev_d->event == ui->button_click_window &&
|
||||
xev_d->time < ui->button_click_time + double_click_time &&
|
||||
ABS (xev_d->event_x - ui->button_click_x) <= double_click_distance &&
|
||||
ABS (xev_d->event_y - ui->button_click_y) <= double_click_distance)
|
||||
{
|
||||
gevent = gdk_event_new (GDK_2BUTTON_PRESS);
|
||||
|
||||
ui->button_click_number = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
gevent = gdk_event_new (GDK_BUTTON_PRESS);
|
||||
ui->button_click_number = xev_d->detail;
|
||||
ui->button_click_window = xev_d->event;
|
||||
ui->button_click_time = xev_d->time;
|
||||
ui->button_click_x = xev_d->event_x;
|
||||
ui->button_click_y = xev_d->event_y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gevent = gdk_event_new (GDK_BUTTON_RELEASE);
|
||||
}
|
||||
|
||||
gevent->button.window = g_object_ref (gdk_window);
|
||||
gevent->button.button = xev_d->detail;
|
||||
gevent->button.time = xev_d->time;
|
||||
gevent->button.x = xev_d->event_x;
|
||||
gevent->button.y = xev_d->event_y;
|
||||
gevent->button.x_root = xev_d->root_x;
|
||||
gevent->button.y_root = xev_d->root_y;
|
||||
|
||||
break;
|
||||
case XI_Motion:
|
||||
gevent = gdk_event_new (GDK_MOTION_NOTIFY);
|
||||
gevent->motion.type = GDK_MOTION_NOTIFY;
|
||||
gevent->motion.window = g_object_ref (gdk_window);
|
||||
break;
|
||||
case XI_Enter:
|
||||
case XI_Leave:
|
||||
gevent = gdk_event_new (xev_e->evtype == XI_Enter ? GDK_ENTER_NOTIFY : GDK_LEAVE_NOTIFY);
|
||||
gevent->crossing.window = g_object_ref (gdk_window);
|
||||
gevent->crossing.x = xev_e->event_x;
|
||||
gevent->crossing.y = xev_e->event_y;
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
|
||||
/* If we've gotten here, we've created the gdk_event and should send it on */
|
||||
gdk_event_set_device (gevent, gdevice);
|
||||
gtk_main_do_event (gevent);
|
||||
gdk_event_free (gevent);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GdkFilterReturn
|
||||
ui_filter_func (GdkXEvent *xevent,
|
||||
GdkEvent *event,
|
||||
gpointer data)
|
||||
{
|
||||
if (maybe_redirect_mouse_event (xevent))
|
||||
return GDK_FILTER_REMOVE;
|
||||
else
|
||||
return GDK_FILTER_CONTINUE;
|
||||
}
|
||||
|
||||
MetaUI*
|
||||
meta_ui_new (Display *xdisplay,
|
||||
Screen *screen)
|
||||
meta_ui_new (void)
|
||||
{
|
||||
GdkDisplay *gdisplay;
|
||||
MetaUI *ui;
|
||||
|
||||
ui = g_new0 (MetaUI, 1);
|
||||
ui->xdisplay = xdisplay;
|
||||
ui->xscreen = screen;
|
||||
ui->display = gdk_display_get_default ();
|
||||
ui->screen = gdk_screen_get_default ();
|
||||
|
||||
gdisplay = gdk_x11_lookup_xdisplay (xdisplay);
|
||||
g_assert (gdisplay == gdk_display_get_default ());
|
||||
ui->frames = meta_frames_new (gdk_screen_get_number (ui->screen));
|
||||
|
||||
gdk_window_add_filter (NULL, ui_filter_func, NULL);
|
||||
|
||||
ui->frames = meta_frames_new (XScreenNumberOfScreen (screen));
|
||||
/* GTK+ needs the frame-sync protocol to work in order to properly
|
||||
* handle style changes. This means that the dummy widget we create
|
||||
* to get the style for title bars actually needs to be mapped
|
||||
@ -264,25 +80,14 @@ meta_ui_new (Display *xdisplay,
|
||||
*/
|
||||
gtk_widget_show (GTK_WIDGET (ui->frames));
|
||||
|
||||
gdk_window_add_filter (NULL, ui_filter_func, NULL);
|
||||
|
||||
g_object_set_data (G_OBJECT (gdisplay), "meta-ui", ui);
|
||||
|
||||
return ui;
|
||||
}
|
||||
|
||||
void
|
||||
meta_ui_free (MetaUI *ui)
|
||||
{
|
||||
GdkDisplay *gdisplay;
|
||||
|
||||
gtk_widget_destroy (GTK_WIDGET (ui->frames));
|
||||
|
||||
gdisplay = gdk_x11_lookup_xdisplay (ui->xdisplay);
|
||||
g_object_set_data (G_OBJECT (gdisplay), "meta-ui", NULL);
|
||||
|
||||
gdk_window_remove_filter (NULL, ui_filter_func, NULL);
|
||||
|
||||
g_free (ui);
|
||||
}
|
||||
|
||||
@ -307,7 +112,6 @@ meta_ui_get_frame_borders (MetaUI *ui,
|
||||
|
||||
Window
|
||||
meta_ui_create_frame_window (MetaUI *ui,
|
||||
Display *xdisplay,
|
||||
Visual *xvisual,
|
||||
gint x,
|
||||
gint y,
|
||||
@ -316,7 +120,7 @@ meta_ui_create_frame_window (MetaUI *ui,
|
||||
gint screen_no,
|
||||
gulong *create_serial)
|
||||
{
|
||||
GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
|
||||
GdkDisplay *display = ui->display;
|
||||
GdkScreen *screen = gdk_display_get_screen (display, screen_no);
|
||||
GdkWindowAttr attrs;
|
||||
gint attributes_mask;
|
||||
@ -365,7 +169,7 @@ meta_ui_create_frame_window (MetaUI *ui,
|
||||
* as long as you pass in a colormap.
|
||||
*/
|
||||
if (create_serial)
|
||||
*create_serial = XNextRequest (xdisplay);
|
||||
*create_serial = XNextRequest (GDK_DISPLAY_XDISPLAY (display));
|
||||
window =
|
||||
gdk_window_new (gdk_screen_get_root_window(screen),
|
||||
&attrs, attributes_mask);
|
||||
@ -399,10 +203,9 @@ void
|
||||
meta_ui_map_frame (MetaUI *ui,
|
||||
Window xwindow)
|
||||
{
|
||||
GdkDisplay *display = ui->display;
|
||||
GdkWindow *window;
|
||||
GdkDisplay *display;
|
||||
|
||||
display = gdk_x11_lookup_xdisplay (ui->xdisplay);
|
||||
window = gdk_x11_window_lookup_for_display (display, xwindow);
|
||||
|
||||
if (window)
|
||||
@ -413,10 +216,9 @@ void
|
||||
meta_ui_unmap_frame (MetaUI *ui,
|
||||
Window xwindow)
|
||||
{
|
||||
GdkDisplay *display = ui->display;
|
||||
GdkWindow *window;
|
||||
GdkDisplay *display;
|
||||
|
||||
display = gdk_x11_lookup_xdisplay (ui->xdisplay);
|
||||
window = gdk_x11_window_lookup_for_display (display, xwindow);
|
||||
|
||||
if (window)
|
||||
@ -634,13 +436,13 @@ meta_ui_get_default_mini_icon (MetaUI *ui)
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_ui_window_should_not_cause_focus (Display *xdisplay,
|
||||
Window xwindow)
|
||||
meta_ui_window_should_not_cause_focus (MetaUI *ui,
|
||||
Window xwindow)
|
||||
{
|
||||
GdkWindow *window;
|
||||
GdkDisplay *display;
|
||||
|
||||
display = gdk_x11_lookup_xdisplay (xdisplay);
|
||||
display = ui->display;
|
||||
window = gdk_x11_window_lookup_for_display (display, xwindow);
|
||||
|
||||
/* we shouldn't cause focus if we're an override redirect
|
||||
@ -652,38 +454,6 @@ meta_ui_window_should_not_cause_focus (Display *xdisplay,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
char*
|
||||
meta_text_property_to_utf8 (Display *xdisplay,
|
||||
const XTextProperty *prop)
|
||||
{
|
||||
GdkDisplay *display;
|
||||
char **list;
|
||||
int count;
|
||||
char *retval;
|
||||
|
||||
list = NULL;
|
||||
|
||||
display = gdk_x11_lookup_xdisplay (xdisplay);
|
||||
count = gdk_text_property_to_utf8_list_for_display (display,
|
||||
gdk_x11_xatom_to_atom_for_display (display, prop->encoding),
|
||||
prop->format,
|
||||
prop->value,
|
||||
prop->nitems,
|
||||
&list);
|
||||
|
||||
if (count == 0)
|
||||
retval = NULL;
|
||||
else
|
||||
{
|
||||
retval = list[0];
|
||||
list[0] = g_strdup (""); /* something to free */
|
||||
}
|
||||
|
||||
g_strfreev (list);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
meta_ui_theme_get_frame_borders (MetaUI *ui,
|
||||
MetaFrameType type,
|
||||
@ -703,8 +473,7 @@ meta_ui_theme_get_frame_borders (MetaUI *ui,
|
||||
|
||||
if (!font_desc)
|
||||
{
|
||||
GdkDisplay *display = gdk_x11_lookup_xdisplay (ui->xdisplay);
|
||||
GdkScreen *screen = gdk_display_get_screen (display, XScreenNumberOfScreen (ui->xscreen));
|
||||
GdkScreen *screen = ui->screen;
|
||||
GtkWidgetPath *widget_path;
|
||||
|
||||
style = gtk_style_context_new ();
|
||||
@ -943,10 +712,9 @@ gboolean
|
||||
meta_ui_window_is_widget (MetaUI *ui,
|
||||
Window xwindow)
|
||||
{
|
||||
GdkDisplay *display;
|
||||
GdkDisplay *display = ui->display;
|
||||
GdkWindow *window;
|
||||
|
||||
display = gdk_x11_lookup_xdisplay (ui->xdisplay);
|
||||
window = gdk_x11_window_lookup_for_display (display, xwindow);
|
||||
|
||||
if (window)
|
||||
|
15
src/ui/ui.h
15
src/ui/ui.h
@ -42,12 +42,7 @@ typedef enum
|
||||
|
||||
void meta_ui_init (void);
|
||||
|
||||
Display* meta_ui_get_display (void);
|
||||
|
||||
gint meta_ui_get_screen_number (void);
|
||||
|
||||
MetaUI* meta_ui_new (Display *xdisplay,
|
||||
Screen *screen);
|
||||
MetaUI* meta_ui_new (void);
|
||||
void meta_ui_free (MetaUI *ui);
|
||||
|
||||
void meta_ui_theme_get_frame_borders (MetaUI *ui,
|
||||
@ -65,7 +60,6 @@ void meta_ui_get_frame_mask (MetaUI *ui,
|
||||
cairo_t *cr);
|
||||
|
||||
Window meta_ui_create_frame_window (MetaUI *ui,
|
||||
Display *xdisplay,
|
||||
Visual *xvisual,
|
||||
gint x,
|
||||
gint y,
|
||||
@ -139,11 +133,8 @@ GdkPixbuf* meta_gdk_pixbuf_get_from_pixmap (Pixmap xpixmap,
|
||||
GdkPixbuf* meta_ui_get_default_window_icon (MetaUI *ui);
|
||||
GdkPixbuf* meta_ui_get_default_mini_icon (MetaUI *ui);
|
||||
|
||||
gboolean meta_ui_window_should_not_cause_focus (Display *xdisplay,
|
||||
Window xwindow);
|
||||
|
||||
char* meta_text_property_to_utf8 (Display *xdisplay,
|
||||
const XTextProperty *prop);
|
||||
gboolean meta_ui_window_should_not_cause_focus (MetaUI *ui,
|
||||
Window xwindow);
|
||||
|
||||
void meta_ui_set_current_theme (const char *name);
|
||||
gboolean meta_ui_have_a_theme (void);
|
||||
|
@ -38,7 +38,6 @@
|
||||
#include "meta-shaped-texture-private.h"
|
||||
#include "meta-wayland-stage.h"
|
||||
#include "meta-cursor-tracker-private.h"
|
||||
#include "backends/native/meta-cursor-tracker-native.h"
|
||||
#include "meta-surface-actor-wayland.h"
|
||||
|
||||
#define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int (10)
|
||||
@ -77,10 +76,10 @@ meta_wayland_seat_update_cursor_surface (MetaWaylandSeat *seat)
|
||||
if (seat->cursor_surface && seat->cursor_surface->buffer)
|
||||
{
|
||||
struct wl_resource *buffer = seat->cursor_surface->buffer->resource;
|
||||
cursor = meta_cursor_tracker_get_cursor_from_buffer (seat->cursor_tracker,
|
||||
buffer,
|
||||
seat->hotspot_x,
|
||||
seat->hotspot_y);
|
||||
cursor = meta_cursor_reference_from_buffer (seat->cursor_tracker,
|
||||
buffer,
|
||||
seat->hotspot_x,
|
||||
seat->hotspot_y);
|
||||
}
|
||||
else
|
||||
cursor = NULL;
|
||||
@ -387,9 +386,9 @@ meta_wayland_seat_update_pointer (MetaWaylandSeat *seat,
|
||||
|
||||
if (seat->cursor_tracker)
|
||||
{
|
||||
meta_cursor_tracker_native_update_position (META_CURSOR_TRACKER_NATIVE (seat->cursor_tracker),
|
||||
wl_fixed_to_int (seat->pointer.x),
|
||||
wl_fixed_to_int (seat->pointer.y));
|
||||
meta_cursor_tracker_update_position (seat->cursor_tracker,
|
||||
wl_fixed_to_int (seat->pointer.x),
|
||||
wl_fixed_to_int (seat->pointer.y));
|
||||
|
||||
if (seat->pointer.current == NULL)
|
||||
meta_cursor_tracker_unset_window_cursor (seat->cursor_tracker);
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include "meta/meta-window-actor.h"
|
||||
#include "meta/meta-shaped-texture.h"
|
||||
#include "meta-cursor-tracker-private.h"
|
||||
#include "backends/native/meta-cursor-tracker-native.h"
|
||||
|
||||
G_DEFINE_TYPE (MetaWaylandStage, meta_wayland_stage, CLUTTER_TYPE_STAGE);
|
||||
|
||||
@ -43,7 +42,7 @@ meta_wayland_stage_paint (ClutterActor *actor)
|
||||
|
||||
compositor = meta_wayland_compositor_get_default ();
|
||||
if (compositor->seat->cursor_tracker)
|
||||
meta_cursor_tracker_native_paint (META_CURSOR_TRACKER_NATIVE (compositor->seat->cursor_tracker));
|
||||
meta_cursor_tracker_paint (compositor->seat->cursor_tracker);
|
||||
}
|
||||
|
||||
static void
|
||||
|
32
src/wayland/meta-wayland-surface-private.h
Normal file
32
src/wayland/meta-wayland-surface-private.h
Normal file
@ -0,0 +1,32 @@
|
||||
/* -*- 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Written by:
|
||||
* Jasper St. Pierre <jstpierre@mecheye.net>
|
||||
*/
|
||||
|
||||
#ifndef META_WAYLAND_SURFACE_PRIVATE_H
|
||||
#define META_WAYLAND_SURFACE_PRIVATE_H
|
||||
|
||||
#include "meta-wayland-types.h"
|
||||
|
||||
void meta_wayland_surface_commit (MetaWaylandSurface *surface);
|
||||
|
||||
#endif /* META_WAYLAND_SURFACE_PRIVATE_H */
|
@ -48,6 +48,7 @@
|
||||
#include "meta-wayland-keyboard.h"
|
||||
#include "meta-wayland-pointer.h"
|
||||
#include "meta-wayland-data-device.h"
|
||||
#include "meta-wayland-surface-private.h"
|
||||
|
||||
#include "meta-cursor-tracker-private.h"
|
||||
#include "display-private.h"
|
||||
@ -117,6 +118,286 @@ surface_process_damage (MetaWaylandSurface *surface,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
empty_region (cairo_region_t *region)
|
||||
{
|
||||
cairo_rectangle_int_t rectangle = { 0, 0, 0, 0 };
|
||||
cairo_region_intersect_rectangle (region, &rectangle);
|
||||
}
|
||||
|
||||
static void
|
||||
ensure_buffer_texture (MetaWaylandBuffer *buffer)
|
||||
{
|
||||
CoglContext *ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
||||
CoglError *catch_error = NULL;
|
||||
CoglTexture *texture;
|
||||
|
||||
texture = COGL_TEXTURE (cogl_wayland_texture_2d_new_from_buffer (ctx,
|
||||
buffer->resource,
|
||||
&catch_error));
|
||||
if (!texture)
|
||||
{
|
||||
cogl_error_free (catch_error);
|
||||
meta_warning ("Could not import pending buffer, ignoring commit\n");
|
||||
return;
|
||||
}
|
||||
|
||||
buffer->texture = texture;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
commit_attached_surface (MetaWaylandSurface *surface,
|
||||
MetaWaylandDoubleBufferedState *pending)
|
||||
{
|
||||
/* wl_surface.attach */
|
||||
if (pending->newly_attached && surface->buffer != pending->buffer)
|
||||
{
|
||||
surface_set_buffer (surface, pending->buffer);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
cursor_surface_commit (MetaWaylandSurface *surface,
|
||||
MetaWaylandDoubleBufferedState *pending)
|
||||
{
|
||||
if (commit_attached_surface (surface, pending))
|
||||
meta_wayland_seat_update_cursor_surface (surface->compositor->seat);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
actor_surface_commit (MetaWaylandSurface *surface,
|
||||
MetaWaylandDoubleBufferedState *pending)
|
||||
{
|
||||
MetaSurfaceActor *surface_actor = surface->surface_actor;
|
||||
MetaWaylandBuffer *buffer = pending->buffer;
|
||||
gboolean buffer_changed;
|
||||
|
||||
buffer_changed = commit_attached_surface (surface, pending);
|
||||
|
||||
if (buffer_changed && buffer)
|
||||
{
|
||||
ensure_buffer_texture (buffer);
|
||||
meta_surface_actor_wayland_set_buffer (META_SURFACE_ACTOR_WAYLAND (surface->surface_actor), buffer);
|
||||
}
|
||||
|
||||
surface_process_damage (surface, pending->damage);
|
||||
|
||||
if (pending->opaque_region)
|
||||
meta_surface_actor_set_opaque_region (surface_actor, pending->opaque_region);
|
||||
if (pending->input_region)
|
||||
meta_surface_actor_set_input_region (surface_actor, pending->input_region);
|
||||
|
||||
return buffer_changed;
|
||||
}
|
||||
|
||||
static void
|
||||
toplevel_surface_commit (MetaWaylandSurface *surface,
|
||||
MetaWaylandDoubleBufferedState *pending)
|
||||
{
|
||||
if (actor_surface_commit (surface, pending))
|
||||
{
|
||||
MetaWindow *window = surface->window;
|
||||
MetaWaylandBuffer *buffer = pending->buffer;
|
||||
|
||||
meta_window_set_surface_mapped (window, buffer != NULL);
|
||||
/* We resize X based surfaces according to X events */
|
||||
if (buffer != NULL && window->client_type == META_WINDOW_CLIENT_TYPE_WAYLAND)
|
||||
{
|
||||
int new_width, new_height;
|
||||
|
||||
new_width = cogl_texture_get_width (buffer->texture);
|
||||
new_height = cogl_texture_get_height (buffer->texture);
|
||||
|
||||
if (new_width != window->rect.width ||
|
||||
new_height != window->rect.height ||
|
||||
pending->dx != 0 ||
|
||||
pending->dy != 0)
|
||||
meta_window_move_resize_wayland (window, new_width, new_height, pending->dx, pending->dy);
|
||||
}
|
||||
}
|
||||
|
||||
if (pending->frame_extents_changed)
|
||||
meta_window_set_custom_frame_extents (surface->window, &pending->frame_extents);
|
||||
}
|
||||
|
||||
static void
|
||||
surface_handle_pending_buffer_destroy (struct wl_listener *listener, void *data)
|
||||
{
|
||||
MetaWaylandDoubleBufferedState *state =
|
||||
wl_container_of (listener, state, buffer_destroy_listener);
|
||||
|
||||
state->buffer = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
double_buffered_state_init (MetaWaylandDoubleBufferedState *state)
|
||||
{
|
||||
state->newly_attached = FALSE;
|
||||
state->buffer = NULL;
|
||||
state->dx = 0;
|
||||
state->dy = 0;
|
||||
|
||||
state->damage = cairo_region_create ();
|
||||
state->buffer_destroy_listener.notify =
|
||||
surface_handle_pending_buffer_destroy;
|
||||
wl_list_init (&state->frame_callback_list);
|
||||
|
||||
state->frame_extents_changed = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
double_buffered_state_destroy (MetaWaylandDoubleBufferedState *state)
|
||||
{
|
||||
MetaWaylandFrameCallback *cb, *next;
|
||||
|
||||
g_clear_pointer (&state->damage, cairo_region_destroy);
|
||||
g_clear_pointer (&state->input_region, cairo_region_destroy);
|
||||
g_clear_pointer (&state->opaque_region, cairo_region_destroy);
|
||||
|
||||
if (state->buffer)
|
||||
wl_list_remove (&state->buffer_destroy_listener.link);
|
||||
wl_list_for_each_safe (cb, next, &state->frame_callback_list, link)
|
||||
wl_resource_destroy (cb->resource);
|
||||
}
|
||||
|
||||
static void
|
||||
double_buffered_state_reset (MetaWaylandDoubleBufferedState *state)
|
||||
{
|
||||
double_buffered_state_destroy (state);
|
||||
double_buffered_state_init (state);
|
||||
}
|
||||
|
||||
static void
|
||||
move_double_buffered_state (MetaWaylandDoubleBufferedState *from,
|
||||
MetaWaylandDoubleBufferedState *to)
|
||||
{
|
||||
if (from->buffer)
|
||||
wl_list_remove (&from->buffer_destroy_listener.link);
|
||||
|
||||
to->newly_attached = from->newly_attached;
|
||||
from->newly_attached = FALSE;
|
||||
|
||||
to->buffer = from->buffer;
|
||||
from->buffer = NULL;
|
||||
if (to->buffer)
|
||||
wl_signal_add (&to->buffer->destroy_signal, &to->buffer_destroy_listener);
|
||||
|
||||
to->dx = from->dx;
|
||||
to->dy = from->dy;
|
||||
from->dx = from->dy = 0;
|
||||
|
||||
empty_region (to->damage);
|
||||
cairo_region_union (to->damage, from->damage);
|
||||
empty_region (from->damage);
|
||||
|
||||
g_clear_pointer (&to->input_region, cairo_region_destroy);
|
||||
g_clear_pointer (&to->opaque_region, cairo_region_destroy);
|
||||
to->input_region = from->input_region;
|
||||
to->opaque_region = from->opaque_region;
|
||||
from->input_region = from->opaque_region = NULL;
|
||||
|
||||
wl_list_init (&to->frame_callback_list);
|
||||
wl_list_insert_list (&to->frame_callback_list, &from->frame_callback_list);
|
||||
wl_list_init (&from->frame_callback_list);
|
||||
}
|
||||
|
||||
static void
|
||||
subsurface_surface_commit (MetaWaylandSurface *surface,
|
||||
MetaWaylandDoubleBufferedState *pending)
|
||||
{
|
||||
/*
|
||||
* If the sub-surface is in synchronous mode, post-pone the commit of its
|
||||
* state until the sub-surface parent commits.
|
||||
*
|
||||
* This is done by moving the various states (damage, input region, buffer
|
||||
* etc.) from the buffered state pending commit to the sub-surface's pending
|
||||
* buffered state.
|
||||
*
|
||||
* The sub-surface's pending buffered state will be committed to the
|
||||
* associated surface when its parent surface is committed, or if the user
|
||||
* issues a wl_subsurface.set_desync request.
|
||||
*/
|
||||
if (surface->sub.synchronous)
|
||||
{
|
||||
move_double_buffered_state (pending, &surface->sub.pending_surface_state);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (actor_surface_commit (surface, pending))
|
||||
{
|
||||
MetaSurfaceActor *surface_actor = surface->surface_actor;
|
||||
MetaWaylandBuffer *buffer = pending->buffer;
|
||||
float x, y;
|
||||
|
||||
if (buffer != NULL)
|
||||
clutter_actor_show (CLUTTER_ACTOR (surface_actor));
|
||||
else
|
||||
clutter_actor_hide (CLUTTER_ACTOR (surface_actor));
|
||||
|
||||
clutter_actor_get_position (CLUTTER_ACTOR (surface_actor), &x, &y);
|
||||
x += pending->dx;
|
||||
y += pending->dy;
|
||||
clutter_actor_set_position (CLUTTER_ACTOR (surface_actor), x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
subsurface_parent_surface_committed (MetaWaylandSurface *surface);
|
||||
|
||||
static void
|
||||
parent_surface_committed (gpointer data, gpointer user_data)
|
||||
{
|
||||
subsurface_parent_surface_committed (data);
|
||||
}
|
||||
|
||||
static void
|
||||
commit_double_buffered_state (MetaWaylandSurface *surface,
|
||||
MetaWaylandDoubleBufferedState *pending)
|
||||
{
|
||||
MetaWaylandCompositor *compositor = surface->compositor;
|
||||
|
||||
if (surface == compositor->seat->cursor_surface)
|
||||
cursor_surface_commit (surface, pending);
|
||||
else if (surface->window)
|
||||
toplevel_surface_commit (surface, pending);
|
||||
else if (surface->subsurface.resource)
|
||||
subsurface_surface_commit (surface, pending);
|
||||
else
|
||||
{
|
||||
/* Unknown surface type. In this case, it's most likely a XWayland
|
||||
* surface that we haven't gotten the ClientMessage for yet. Make
|
||||
* sure *not* to reset the double-buffered state or do anything too
|
||||
* fancy. */
|
||||
return;
|
||||
}
|
||||
|
||||
g_list_foreach (surface->subsurfaces,
|
||||
parent_surface_committed,
|
||||
NULL);
|
||||
|
||||
if (pending->buffer)
|
||||
{
|
||||
wl_list_remove (&pending->buffer_destroy_listener.link);
|
||||
pending->buffer = NULL;
|
||||
}
|
||||
|
||||
/* wl_surface.frame */
|
||||
wl_list_insert_list (&compositor->frame_callbacks, &pending->frame_callback_list);
|
||||
wl_list_init (&pending->frame_callback_list);
|
||||
|
||||
double_buffered_state_reset (pending);
|
||||
}
|
||||
|
||||
void
|
||||
meta_wayland_surface_commit (MetaWaylandSurface *surface)
|
||||
{
|
||||
commit_double_buffered_state (surface, &surface->pending);
|
||||
}
|
||||
|
||||
static void
|
||||
wl_surface_destroy (struct wl_client *client,
|
||||
struct wl_resource *resource)
|
||||
@ -243,269 +524,6 @@ wl_surface_set_input_region (struct wl_client *client,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
empty_region (cairo_region_t *region)
|
||||
{
|
||||
cairo_rectangle_int_t rectangle = { 0, 0, 0, 0 };
|
||||
cairo_region_intersect_rectangle (region, &rectangle);
|
||||
}
|
||||
|
||||
static void
|
||||
ensure_buffer_texture (MetaWaylandBuffer *buffer)
|
||||
{
|
||||
CoglContext *ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
||||
CoglError *catch_error = NULL;
|
||||
CoglTexture *texture;
|
||||
|
||||
texture = COGL_TEXTURE (cogl_wayland_texture_2d_new_from_buffer (ctx,
|
||||
buffer->resource,
|
||||
&catch_error));
|
||||
if (!texture)
|
||||
{
|
||||
cogl_error_free (catch_error);
|
||||
meta_warning ("Could not import pending buffer, ignoring commit\n");
|
||||
return;
|
||||
}
|
||||
|
||||
buffer->texture = texture;
|
||||
}
|
||||
|
||||
static void
|
||||
cursor_surface_commit (MetaWaylandSurface *surface,
|
||||
MetaWaylandDoubleBufferedState *pending,
|
||||
gboolean buffer_changed)
|
||||
{
|
||||
if (buffer_changed)
|
||||
meta_wayland_seat_update_cursor_surface (surface->compositor->seat);
|
||||
}
|
||||
|
||||
static void
|
||||
actor_surface_commit (MetaWaylandSurface *surface,
|
||||
MetaWaylandDoubleBufferedState *pending,
|
||||
gboolean buffer_changed)
|
||||
{
|
||||
MetaSurfaceActor *surface_actor = surface->surface_actor;
|
||||
MetaWaylandBuffer *buffer = pending->buffer;
|
||||
|
||||
if (buffer_changed && buffer)
|
||||
{
|
||||
ensure_buffer_texture (buffer);
|
||||
meta_surface_actor_wayland_set_buffer (META_SURFACE_ACTOR_WAYLAND (surface->surface_actor), buffer);
|
||||
}
|
||||
|
||||
surface_process_damage (surface, pending->damage);
|
||||
|
||||
if (pending->opaque_region)
|
||||
meta_surface_actor_set_opaque_region (surface_actor, pending->opaque_region);
|
||||
if (pending->input_region)
|
||||
meta_surface_actor_set_input_region (surface_actor, pending->input_region);
|
||||
}
|
||||
|
||||
static void
|
||||
toplevel_surface_commit (MetaWaylandSurface *surface,
|
||||
MetaWaylandDoubleBufferedState *pending,
|
||||
gboolean buffer_changed)
|
||||
{
|
||||
actor_surface_commit (surface, pending, buffer_changed);
|
||||
|
||||
if (buffer_changed)
|
||||
{
|
||||
MetaWindow *window = surface->window;
|
||||
MetaWaylandBuffer *buffer = pending->buffer;
|
||||
|
||||
meta_window_set_surface_mapped (window, buffer != NULL);
|
||||
/* We resize X based surfaces according to X events */
|
||||
if (buffer != NULL && window->client_type == META_WINDOW_CLIENT_TYPE_WAYLAND)
|
||||
{
|
||||
int new_width, new_height;
|
||||
|
||||
new_width = cogl_texture_get_width (buffer->texture);
|
||||
new_height = cogl_texture_get_height (buffer->texture);
|
||||
|
||||
if (new_width != window->rect.width ||
|
||||
new_height != window->rect.height ||
|
||||
pending->dx != 0 ||
|
||||
pending->dy != 0)
|
||||
meta_window_move_resize_wayland (window, new_width, new_height, pending->dx, pending->dy);
|
||||
}
|
||||
}
|
||||
|
||||
if (pending->frame_extents_changed)
|
||||
meta_window_set_custom_frame_extents (surface->window, &pending->frame_extents);
|
||||
}
|
||||
|
||||
static void
|
||||
surface_handle_pending_buffer_destroy (struct wl_listener *listener, void *data)
|
||||
{
|
||||
MetaWaylandDoubleBufferedState *state =
|
||||
wl_container_of (listener, state, buffer_destroy_listener);
|
||||
|
||||
state->buffer = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
double_buffered_state_init (MetaWaylandDoubleBufferedState *state)
|
||||
{
|
||||
state->newly_attached = FALSE;
|
||||
state->buffer = NULL;
|
||||
state->dx = 0;
|
||||
state->dy = 0;
|
||||
|
||||
state->damage = cairo_region_create ();
|
||||
state->buffer_destroy_listener.notify =
|
||||
surface_handle_pending_buffer_destroy;
|
||||
wl_list_init (&state->frame_callback_list);
|
||||
|
||||
state->frame_extents_changed = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
double_buffered_state_destroy (MetaWaylandDoubleBufferedState *state)
|
||||
{
|
||||
MetaWaylandFrameCallback *cb, *next;
|
||||
|
||||
g_clear_pointer (&state->damage, cairo_region_destroy);
|
||||
g_clear_pointer (&state->input_region, cairo_region_destroy);
|
||||
g_clear_pointer (&state->opaque_region, cairo_region_destroy);
|
||||
|
||||
if (state->buffer)
|
||||
wl_list_remove (&state->buffer_destroy_listener.link);
|
||||
wl_list_for_each_safe (cb, next, &state->frame_callback_list, link)
|
||||
wl_resource_destroy (cb->resource);
|
||||
}
|
||||
|
||||
static void
|
||||
double_buffered_state_reset (MetaWaylandDoubleBufferedState *state)
|
||||
{
|
||||
double_buffered_state_destroy (state);
|
||||
double_buffered_state_init (state);
|
||||
}
|
||||
|
||||
static void
|
||||
move_double_buffered_state (MetaWaylandDoubleBufferedState *from,
|
||||
MetaWaylandDoubleBufferedState *to)
|
||||
{
|
||||
if (from->buffer)
|
||||
wl_list_remove (&from->buffer_destroy_listener.link);
|
||||
|
||||
to->newly_attached = from->newly_attached;
|
||||
from->newly_attached = FALSE;
|
||||
|
||||
to->buffer = from->buffer;
|
||||
from->buffer = NULL;
|
||||
if (to->buffer)
|
||||
wl_signal_add (&to->buffer->destroy_signal, &to->buffer_destroy_listener);
|
||||
|
||||
to->dx = from->dx;
|
||||
to->dy = from->dy;
|
||||
from->dx = from->dy = 0;
|
||||
|
||||
empty_region (to->damage);
|
||||
cairo_region_union (to->damage, from->damage);
|
||||
empty_region (from->damage);
|
||||
|
||||
g_clear_pointer (&to->input_region, cairo_region_destroy);
|
||||
g_clear_pointer (&to->opaque_region, cairo_region_destroy);
|
||||
to->input_region = from->input_region;
|
||||
to->opaque_region = from->opaque_region;
|
||||
from->input_region = from->opaque_region = NULL;
|
||||
|
||||
wl_list_init (&to->frame_callback_list);
|
||||
wl_list_insert_list (&to->frame_callback_list, &from->frame_callback_list);
|
||||
wl_list_init (&from->frame_callback_list);
|
||||
}
|
||||
|
||||
static void
|
||||
subsurface_surface_commit (MetaWaylandSurface *surface,
|
||||
MetaWaylandDoubleBufferedState *pending,
|
||||
gboolean buffer_changed)
|
||||
{
|
||||
/*
|
||||
* If the sub-surface is in synchronous mode, post-pone the commit of its
|
||||
* state until the sub-surface parent commits.
|
||||
*
|
||||
* This is done by moving the various states (damage, input region, buffer
|
||||
* etc.) from the buffered state pending commit to the sub-surface's pending
|
||||
* buffered state.
|
||||
*
|
||||
* The sub-surface's pending buffered state will be committed to the
|
||||
* associated surface when its parent surface is committed, or if the user
|
||||
* issues a wl_subsurface.set_desync request.
|
||||
*/
|
||||
if (surface->sub.synchronous)
|
||||
{
|
||||
move_double_buffered_state (pending, &surface->sub.pending_surface_state);
|
||||
}
|
||||
else
|
||||
{
|
||||
actor_surface_commit (surface, pending, buffer_changed);
|
||||
|
||||
if (buffer_changed)
|
||||
{
|
||||
MetaSurfaceActor *surface_actor = surface->surface_actor;
|
||||
MetaWaylandBuffer *buffer = pending->buffer;
|
||||
float x, y;
|
||||
|
||||
if (buffer != NULL)
|
||||
clutter_actor_show (CLUTTER_ACTOR (surface_actor));
|
||||
else
|
||||
clutter_actor_hide (CLUTTER_ACTOR (surface_actor));
|
||||
|
||||
clutter_actor_get_position (CLUTTER_ACTOR (surface_actor), &x, &y);
|
||||
x += pending->dx;
|
||||
y += pending->dy;
|
||||
clutter_actor_set_position (CLUTTER_ACTOR (surface_actor), x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
subsurface_parent_surface_committed (MetaWaylandSurface *surface);
|
||||
|
||||
static void
|
||||
parent_surface_committed (gpointer data, gpointer user_data)
|
||||
{
|
||||
subsurface_parent_surface_committed (data);
|
||||
}
|
||||
|
||||
static void
|
||||
commit_double_buffered_state (MetaWaylandSurface *surface,
|
||||
MetaWaylandDoubleBufferedState *pending)
|
||||
{
|
||||
MetaWaylandCompositor *compositor = surface->compositor;
|
||||
gboolean buffer_changed = FALSE;
|
||||
|
||||
/* wl_surface.attach */
|
||||
if (pending->newly_attached && surface->buffer != pending->buffer)
|
||||
{
|
||||
surface_set_buffer (surface, pending->buffer);
|
||||
buffer_changed = TRUE;
|
||||
}
|
||||
|
||||
if (surface == compositor->seat->cursor_surface)
|
||||
cursor_surface_commit (surface, pending, buffer_changed);
|
||||
else if (surface->window)
|
||||
toplevel_surface_commit (surface, pending, buffer_changed);
|
||||
else if (surface->subsurface.resource)
|
||||
subsurface_surface_commit (surface, pending, buffer_changed);
|
||||
|
||||
g_list_foreach (surface->subsurfaces,
|
||||
parent_surface_committed,
|
||||
NULL);
|
||||
|
||||
if (pending->buffer)
|
||||
{
|
||||
wl_list_remove (&pending->buffer_destroy_listener.link);
|
||||
pending->buffer = NULL;
|
||||
}
|
||||
|
||||
/* wl_surface.frame */
|
||||
wl_list_insert_list (&compositor->frame_callbacks, &pending->frame_callback_list);
|
||||
wl_list_init (&pending->frame_callback_list);
|
||||
|
||||
double_buffered_state_reset (pending);
|
||||
}
|
||||
|
||||
static void
|
||||
wl_surface_commit (struct wl_client *client,
|
||||
struct wl_resource *resource)
|
||||
@ -516,7 +534,7 @@ wl_surface_commit (struct wl_client *client,
|
||||
if (!surface)
|
||||
return;
|
||||
|
||||
commit_double_buffered_state (surface, &surface->pending);
|
||||
meta_wayland_surface_commit (surface);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -23,23 +23,22 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "meta-xwayland.h"
|
||||
#include "meta-xwayland-private.h"
|
||||
|
||||
#include "meta-wayland-surface-private.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-unix.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/wait.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "meta-window-actor-private.h"
|
||||
#include "xserver-server-protocol.h"
|
||||
|
||||
static void
|
||||
xserver_finished_init (MetaXWaylandManager *manager);
|
||||
|
||||
static void
|
||||
associate_window_with_surface (MetaWindow *window,
|
||||
MetaWaylandSurface *surface)
|
||||
@ -57,57 +56,71 @@ associate_window_with_surface (MetaWindow *window,
|
||||
window->surface = surface;
|
||||
|
||||
meta_compositor_window_surface_changed (display->compositor, window);
|
||||
|
||||
/* Since the association comes in the form of a ClientMessage,
|
||||
* we have no way to know when the surface was set up. Since
|
||||
* commit just breaks if we don't have a window associated with
|
||||
* it, we need to do a commit *again* here. */
|
||||
meta_wayland_surface_commit (surface);
|
||||
}
|
||||
|
||||
static void
|
||||
xserver_set_window_id (struct wl_client *client,
|
||||
struct wl_resource *compositor_resource,
|
||||
struct wl_resource *surface_resource,
|
||||
guint32 xid)
|
||||
static gboolean
|
||||
associate_window_with_surface_id (MetaXWaylandManager *manager,
|
||||
MetaWindow *window,
|
||||
guint32 surface_id)
|
||||
{
|
||||
MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource);
|
||||
MetaDisplay *display = meta_get_display ();
|
||||
struct wl_resource *resource;
|
||||
|
||||
resource = wl_client_get_object (manager->client, surface_id);
|
||||
if (resource)
|
||||
{
|
||||
MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
|
||||
associate_window_with_surface (window, surface);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
MetaXWaylandManager *manager;
|
||||
MetaWindow *window;
|
||||
guint32 surface_id;
|
||||
} AssociateWindowWithSurfaceOp;
|
||||
|
||||
window = meta_display_lookup_x_window (display, xid);
|
||||
if (!window)
|
||||
return;
|
||||
static gboolean
|
||||
associate_window_with_surface_idle (gpointer user_data)
|
||||
{
|
||||
AssociateWindowWithSurfaceOp *op = user_data;
|
||||
if (!associate_window_with_surface_id (op->manager, op->window, op->surface_id))
|
||||
{
|
||||
/* Not here? Oh well... nothing we can do */
|
||||
g_warning ("Unknown surface ID %d (from window %s)", op->surface_id, op->window->desc);
|
||||
}
|
||||
g_free (op);
|
||||
|
||||
associate_window_with_surface (window, surface);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static const struct xserver_interface xserver_implementation = {
|
||||
xserver_set_window_id
|
||||
};
|
||||
|
||||
static void
|
||||
bind_xserver (struct wl_client *client,
|
||||
void *data,
|
||||
guint32 version,
|
||||
guint32 id)
|
||||
void
|
||||
meta_xwayland_handle_wl_surface_id (MetaWindow *window,
|
||||
guint32 surface_id)
|
||||
{
|
||||
MetaXWaylandManager *manager = data;
|
||||
MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
|
||||
MetaXWaylandManager *manager = &compositor->xwayland_manager;
|
||||
|
||||
/* If it's a different client than the xserver we launched,
|
||||
* just freeze up... */
|
||||
if (client != manager->client)
|
||||
return;
|
||||
|
||||
manager->xserver_resource = wl_resource_create (client, &xserver_interface,
|
||||
MIN (META_XSERVER_VERSION, version), id);
|
||||
wl_resource_set_implementation (manager->xserver_resource,
|
||||
&xserver_implementation, manager, NULL);
|
||||
|
||||
xserver_send_listen_socket (manager->xserver_resource, manager->abstract_fd);
|
||||
xserver_send_listen_socket (manager->xserver_resource, manager->unix_fd);
|
||||
|
||||
/* Make sure xwayland will recieve the above sockets in a finite
|
||||
* time before unblocking the initialization mainloop since we are
|
||||
* then going to immediately try and connect to those as the window
|
||||
* manager. */
|
||||
wl_client_flush (client);
|
||||
|
||||
xserver_finished_init (manager);
|
||||
if (!associate_window_with_surface_id (manager, window, surface_id))
|
||||
{
|
||||
/* No surface ID yet... it should arrive after the next
|
||||
* iteration through the loop, so queue an idle and see
|
||||
* what happens.
|
||||
*/
|
||||
AssociateWindowWithSurfaceOp *op = g_new0 (AssociateWindowWithSurfaceOp, 1);
|
||||
op->manager = manager;
|
||||
op->window = window;
|
||||
op->surface_id = surface_id;
|
||||
g_idle_add (associate_window_with_surface_idle, op);
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
@ -346,6 +359,16 @@ xserver_finished_init (MetaXWaylandManager *manager)
|
||||
g_clear_pointer (&manager->init_loop, g_main_loop_unref);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
got_sigusr1 (gpointer user_data)
|
||||
{
|
||||
MetaXWaylandManager *manager = user_data;
|
||||
|
||||
xserver_finished_init (manager);
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_xwayland_start (MetaXWaylandManager *manager,
|
||||
struct wl_display *wl_display)
|
||||
@ -356,10 +379,6 @@ meta_xwayland_start (MetaXWaylandManager *manager,
|
||||
if (!choose_xdisplay (manager))
|
||||
return FALSE;
|
||||
|
||||
wl_global_create (wl_display, &xserver_interface,
|
||||
META_XSERVER_VERSION,
|
||||
manager, bind_xserver);
|
||||
|
||||
/* We want xwayland to be a wayland client so we make a socketpair to setup a
|
||||
* wayland protocol connection. */
|
||||
if (socketpair (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sp) < 0)
|
||||
@ -372,7 +391,7 @@ meta_xwayland_start (MetaXWaylandManager *manager,
|
||||
manager->pid = fork ();
|
||||
if (manager->pid == 0)
|
||||
{
|
||||
char socket_fd[8];
|
||||
char socket_fd[8], unix_fd[8], abstract_fd[8];
|
||||
|
||||
/* We passed SOCK_CLOEXEC, so dup the FD so it isn't
|
||||
* closed on exec.. */
|
||||
@ -380,6 +399,12 @@ meta_xwayland_start (MetaXWaylandManager *manager,
|
||||
snprintf (socket_fd, sizeof (socket_fd), "%d", fd);
|
||||
setenv ("WAYLAND_SOCKET", socket_fd, TRUE);
|
||||
|
||||
fd = dup (manager->abstract_fd);
|
||||
snprintf (abstract_fd, sizeof (abstract_fd), "%d", fd);
|
||||
|
||||
fd = dup (manager->unix_fd);
|
||||
snprintf (unix_fd, sizeof (unix_fd), "%d", fd);
|
||||
|
||||
/* xwayland, please. */
|
||||
if (getenv ("XWAYLAND_STFU"))
|
||||
{
|
||||
@ -390,12 +415,16 @@ meta_xwayland_start (MetaXWaylandManager *manager,
|
||||
dup2 (dev_null, STDERR_FILENO);
|
||||
}
|
||||
|
||||
/* We have to ignore SIGUSR1 in the child to make sure
|
||||
* that the server will send it to mutter-wayland. */
|
||||
signal(SIGUSR1, SIG_IGN);
|
||||
|
||||
if (execl (XWAYLAND_PATH, XWAYLAND_PATH,
|
||||
manager->display_name,
|
||||
"-wayland",
|
||||
"-rootless",
|
||||
"-noreset",
|
||||
"-nolisten", "all",
|
||||
"-listen", abstract_fd,
|
||||
"-listen", unix_fd,
|
||||
NULL) < 0)
|
||||
{
|
||||
g_error ("Failed to spawn XWayland: %m");
|
||||
@ -407,6 +436,7 @@ meta_xwayland_start (MetaXWaylandManager *manager,
|
||||
}
|
||||
|
||||
g_child_watch_add (manager->pid, xserver_died, NULL);
|
||||
g_unix_signal_add (SIGUSR1, got_sigusr1, manager);
|
||||
manager->client = wl_client_create (wl_display, sp[0]);
|
||||
|
||||
/* We need to run a mainloop until we know xwayland has a binding
|
||||
|
35
src/wayland/meta-xwayland.h
Normal file
35
src/wayland/meta-xwayland.h
Normal file
@ -0,0 +1,35 @@
|
||||
/* -*- 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Written by:
|
||||
* Jasper St. Pierre <jstpierre@mecheye.net>
|
||||
*/
|
||||
|
||||
#ifndef META_XWAYLAND_H
|
||||
#define META_XWAYLAND_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <meta/types.h>
|
||||
|
||||
void
|
||||
meta_xwayland_handle_wl_surface_id (MetaWindow *window,
|
||||
guint32 surface_id);
|
||||
|
||||
#endif /* META_XWAYLAND_H */
|
@ -1,18 +0,0 @@
|
||||
<protocol name="xserver">
|
||||
|
||||
<interface name="xserver" version="1">
|
||||
<request name="set_window_id">
|
||||
<arg name="surface" type="object" interface="wl_surface"/>
|
||||
<arg name="id" type="uint"/>
|
||||
</request>
|
||||
|
||||
<event name="client">
|
||||
<arg name="fd" type="fd"/>
|
||||
</event>
|
||||
|
||||
<event name="listen_socket">
|
||||
<arg name="fd" type="fd"/>
|
||||
</event>
|
||||
</interface>
|
||||
|
||||
</protocol>
|
@ -230,7 +230,7 @@ read_rgb_icon (MetaDisplay *display,
|
||||
int mini_w, mini_h;
|
||||
gulong *data_as_long;
|
||||
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
type = None;
|
||||
data = NULL;
|
||||
result = XGetWindowProperty (display->xdisplay,
|
||||
@ -504,7 +504,7 @@ get_kwm_win_icon (MetaDisplay *display,
|
||||
*pixmap = None;
|
||||
*mask = None;
|
||||
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
icons = NULL;
|
||||
result = XGetWindowProperty (display->xdisplay, xwindow,
|
||||
display->atom__KWM_WIN_ICON,
|
||||
|
@ -1665,12 +1665,12 @@ meta_window_x11_client_message (MetaWindow *window,
|
||||
char *str1;
|
||||
char *str2;
|
||||
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
str1 = XGetAtomName (display->xdisplay, first);
|
||||
if (meta_error_trap_pop_with_return (display) != Success)
|
||||
str1 = NULL;
|
||||
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
str2 = XGetAtomName (display->xdisplay, second);
|
||||
if (meta_error_trap_pop_with_return (display) != Success)
|
||||
str2 = NULL;
|
||||
@ -2298,7 +2298,7 @@ meta_window_x11_new (MetaDisplay *display,
|
||||
wm_state_to_string (existing_wm_state));
|
||||
}
|
||||
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
|
||||
/*
|
||||
* XAddToSaveSet can only be called on windows created by a different
|
||||
@ -2309,7 +2309,7 @@ meta_window_x11_new (MetaDisplay *display,
|
||||
*/
|
||||
XAddToSaveSet (display->xdisplay, xwindow);
|
||||
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
|
||||
event_mask = PropertyChangeMask;
|
||||
if (attrs.override_redirect)
|
||||
|
@ -191,7 +191,7 @@ get_property (MetaDisplay *display,
|
||||
results->bytes_after = 0;
|
||||
results->format = 0;
|
||||
|
||||
meta_error_trap_push_with_return (display);
|
||||
meta_error_trap_push (display);
|
||||
if (XGetWindowProperty (display->xdisplay, xwindow, xatom,
|
||||
0, G_MAXLONG,
|
||||
False, req_type, &results->type, &results->format,
|
||||
@ -736,6 +736,29 @@ meta_prop_get_cardinal_with_atom_type (MetaDisplay *display,
|
||||
return cardinal_with_atom_type_from_results (&results, prop_type, cardinal_p);
|
||||
}
|
||||
|
||||
static char *
|
||||
text_property_to_utf8 (Display *xdisplay,
|
||||
const XTextProperty *prop)
|
||||
{
|
||||
char *ret = NULL;
|
||||
char **local_list = NULL;
|
||||
int count = 0;
|
||||
int res;
|
||||
|
||||
res = XmbTextPropertyToTextList (xdisplay, prop, &local_list, &count);
|
||||
if (res == XNoMemory || res == XLocaleNotSupported || res == XConverterNotFound)
|
||||
goto out;
|
||||
|
||||
if (count == 0)
|
||||
goto out;
|
||||
|
||||
ret = g_strdup (local_list[0]);
|
||||
|
||||
out:
|
||||
meta_XFree (local_list);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
text_property_from_results (GetPropertyResults *results,
|
||||
char **utf8_str_p)
|
||||
@ -743,15 +766,14 @@ text_property_from_results (GetPropertyResults *results,
|
||||
XTextProperty tp;
|
||||
|
||||
*utf8_str_p = NULL;
|
||||
|
||||
|
||||
tp.value = results->prop;
|
||||
results->prop = NULL;
|
||||
tp.encoding = results->type;
|
||||
tp.format = results->format;
|
||||
tp.nitems = results->n_items;
|
||||
|
||||
*utf8_str_p = meta_text_property_to_utf8 (results->display->xdisplay,
|
||||
&tp);
|
||||
*utf8_str_p = text_property_to_utf8 (results->display->xdisplay, &tp);
|
||||
|
||||
if (tp.value != NULL)
|
||||
XFree (tp.value);
|
||||
|
Reference in New Issue
Block a user