2023-02-09 12:38:48 +00:00
|
|
|
/*
|
|
|
|
* mks-paintable.c
|
|
|
|
*
|
|
|
|
* Copyright 2023 Christian Hergert <chergert@redhat.com>
|
|
|
|
*
|
2023-06-02 17:01:16 +00:00
|
|
|
* This library is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
* License, or (at your option) any later version.
|
2023-02-09 12:38:48 +00:00
|
|
|
*
|
2023-06-02 17:01:16 +00:00
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
2023-02-09 12:38:48 +00:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2023-06-01 11:04:35 +00:00
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
2023-02-09 12:38:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <glib/gstdio.h>
|
2023-02-16 03:40:48 +00:00
|
|
|
#include <gtk/gtk.h>
|
2023-02-11 01:32:09 +00:00
|
|
|
#include <pixman.h>
|
2023-02-11 00:14:51 +00:00
|
|
|
|
2023-02-14 01:38:30 +00:00
|
|
|
#include "mks-cairo-framebuffer-private.h"
|
2023-02-15 00:27:09 +00:00
|
|
|
#include "mks-dmabuf-paintable-private.h"
|
2023-02-10 01:32:00 +00:00
|
|
|
#include "mks-paintable-private.h"
|
2023-02-11 00:14:51 +00:00
|
|
|
#include "mks-qemu.h"
|
2023-02-18 00:27:36 +00:00
|
|
|
#include "mks-util-private.h"
|
2023-02-09 12:38:48 +00:00
|
|
|
|
2023-02-15 20:16:47 +00:00
|
|
|
#include "mks-marshal.h"
|
|
|
|
|
2023-02-09 12:38:48 +00:00
|
|
|
struct _MksPaintable
|
|
|
|
{
|
2023-05-01 15:59:33 +00:00
|
|
|
GObject parent_instance;
|
|
|
|
GdkGLContext *gl_context;
|
|
|
|
MksQemuListener *listener;
|
|
|
|
GDBusConnection *connection;
|
|
|
|
GdkPaintable *child;
|
|
|
|
GdkCursor *cursor;
|
|
|
|
MksDmabufScanoutData *scanout_data;
|
|
|
|
int mouse_x;
|
|
|
|
int mouse_y;
|
|
|
|
guint y_inverted : 1;
|
2023-02-09 12:38:48 +00:00
|
|
|
};
|
|
|
|
|
2023-02-15 15:01:32 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
2023-02-15 20:02:03 +00:00
|
|
|
PROP_CURSOR,
|
2023-02-15 15:01:32 +00:00
|
|
|
PROP_PAINTABLE,
|
|
|
|
N_PROPS
|
|
|
|
};
|
|
|
|
|
2023-02-15 20:16:47 +00:00
|
|
|
enum {
|
|
|
|
MOUSE_SET,
|
|
|
|
N_SIGNALS
|
|
|
|
};
|
|
|
|
|
2023-02-15 15:01:32 +00:00
|
|
|
static GParamSpec *properties [N_PROPS];
|
2023-02-15 20:16:47 +00:00
|
|
|
static guint signals [N_SIGNALS];
|
2023-02-15 15:01:32 +00:00
|
|
|
|
2023-02-11 01:32:09 +00:00
|
|
|
static cairo_format_t
|
|
|
|
_pixman_format_to_cairo_format (guint pixman_format)
|
|
|
|
{
|
|
|
|
switch (pixman_format)
|
|
|
|
{
|
2023-02-18 00:27:36 +00:00
|
|
|
#if _CAIRO_CHECK_VERSION(1, 17, 2)
|
2023-02-11 01:32:09 +00:00
|
|
|
case PIXMAN_rgba_float:
|
|
|
|
return CAIRO_FORMAT_RGBA128F;
|
|
|
|
case PIXMAN_rgb_float:
|
|
|
|
return CAIRO_FORMAT_RGB96F;
|
2023-02-18 00:27:36 +00:00
|
|
|
#endif
|
|
|
|
|
2023-02-11 01:32:09 +00:00
|
|
|
case PIXMAN_a8r8g8b8:
|
|
|
|
return CAIRO_FORMAT_ARGB32;
|
|
|
|
case PIXMAN_x2r10g10b10:
|
|
|
|
return CAIRO_FORMAT_RGB30;
|
|
|
|
case PIXMAN_x8r8g8b8:
|
|
|
|
return CAIRO_FORMAT_RGB24;
|
|
|
|
case PIXMAN_a8:
|
|
|
|
return CAIRO_FORMAT_A8;
|
|
|
|
case PIXMAN_a1:
|
|
|
|
return CAIRO_FORMAT_A1;
|
|
|
|
case PIXMAN_r5g6b5:
|
|
|
|
return CAIRO_FORMAT_RGB16_565;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
static int
|
|
|
|
mks_paintable_get_intrinsic_height (GdkPaintable *paintable)
|
2023-02-09 12:38:48 +00:00
|
|
|
{
|
2023-02-15 00:27:09 +00:00
|
|
|
GdkPaintable *child = MKS_PAINTABLE (paintable)->child;
|
2023-02-14 01:38:30 +00:00
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
return child ? gdk_paintable_get_intrinsic_height (child) : 0;
|
2023-02-09 12:38:48 +00:00
|
|
|
}
|
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
static int
|
|
|
|
mks_paintable_get_intrinsic_width (GdkPaintable *paintable)
|
2023-02-09 12:38:48 +00:00
|
|
|
{
|
2023-02-15 00:27:09 +00:00
|
|
|
GdkPaintable *child = MKS_PAINTABLE (paintable)->child;
|
2023-02-14 01:38:30 +00:00
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
return child ? gdk_paintable_get_intrinsic_width (child) : 0;
|
2023-02-09 12:38:48 +00:00
|
|
|
}
|
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
static double
|
|
|
|
mks_paintable_get_intrinsic_aspect_ratio (GdkPaintable *paintable)
|
2023-02-09 12:38:48 +00:00
|
|
|
{
|
2023-02-15 00:27:09 +00:00
|
|
|
GdkPaintable *child = MKS_PAINTABLE (paintable)->child;
|
2023-02-09 12:38:48 +00:00
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
return child ? gdk_paintable_get_intrinsic_aspect_ratio (child) : .0;
|
2023-02-09 12:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-02-11 00:14:51 +00:00
|
|
|
mks_paintable_snapshot (GdkPaintable *paintable,
|
|
|
|
GdkSnapshot *snapshot,
|
|
|
|
double width,
|
|
|
|
double height)
|
2023-02-09 12:38:48 +00:00
|
|
|
{
|
2023-02-16 03:40:48 +00:00
|
|
|
MksPaintable *self = MKS_PAINTABLE (paintable);
|
2023-02-12 18:39:14 +00:00
|
|
|
|
2023-02-16 03:40:48 +00:00
|
|
|
if (self->child != NULL)
|
|
|
|
{
|
|
|
|
if (MKS_IS_DMABUF_PAINTABLE (self->child) && !self->y_inverted)
|
|
|
|
{
|
|
|
|
gtk_snapshot_save (snapshot);
|
|
|
|
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (0, height));
|
|
|
|
gtk_snapshot_scale (snapshot, 1, -1);
|
|
|
|
gdk_paintable_snapshot (self->child, snapshot, width, height);
|
|
|
|
gtk_snapshot_restore (snapshot);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gdk_paintable_snapshot (self->child, snapshot, width, height);
|
|
|
|
}
|
|
|
|
}
|
2023-02-11 00:14:51 +00:00
|
|
|
}
|
2023-02-09 12:38:48 +00:00
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
static void
|
|
|
|
paintable_iface_init (GdkPaintableInterface *iface)
|
|
|
|
{
|
|
|
|
iface->get_intrinsic_height = mks_paintable_get_intrinsic_height;
|
|
|
|
iface->get_intrinsic_width = mks_paintable_get_intrinsic_width;
|
|
|
|
iface->get_intrinsic_aspect_ratio = mks_paintable_get_intrinsic_aspect_ratio;
|
|
|
|
iface->snapshot = mks_paintable_snapshot;
|
2023-02-09 12:38:48 +00:00
|
|
|
}
|
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
G_DEFINE_FINAL_TYPE_WITH_CODE (MksPaintable, mks_paintable, G_TYPE_OBJECT,
|
|
|
|
G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE, paintable_iface_init))
|
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
static GdkGLContext *
|
|
|
|
mks_paintable_get_gl_context (MksPaintable *self,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_assert (MKS_IS_PAINTABLE (self));
|
|
|
|
|
|
|
|
if (self->gl_context == NULL)
|
|
|
|
{
|
|
|
|
GdkDisplay *display = gdk_display_get_default ();
|
|
|
|
|
|
|
|
if (!(self->gl_context = gdk_display_create_gl_context (display, error)))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self->gl_context;
|
|
|
|
}
|
|
|
|
|
2023-02-09 12:38:48 +00:00
|
|
|
static void
|
2023-02-11 00:14:51 +00:00
|
|
|
mks_paintable_dispose (GObject *object)
|
2023-02-09 12:38:48 +00:00
|
|
|
{
|
2023-02-11 00:14:51 +00:00
|
|
|
MksPaintable *self = (MksPaintable *)object;
|
2023-02-09 12:38:48 +00:00
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
g_clear_object (&self->connection);
|
|
|
|
g_clear_object (&self->listener);
|
2023-02-15 00:27:09 +00:00
|
|
|
g_clear_object (&self->child);
|
|
|
|
g_clear_object (&self->gl_context);
|
2023-02-15 20:02:03 +00:00
|
|
|
g_clear_object (&self->cursor);
|
2023-02-09 12:38:48 +00:00
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
G_OBJECT_CLASS (mks_paintable_parent_class)->dispose (object);
|
2023-02-09 12:38:48 +00:00
|
|
|
}
|
|
|
|
|
2023-02-15 15:01:32 +00:00
|
|
|
static void
|
|
|
|
mks_paintable_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MksPaintable *self = MKS_PAINTABLE (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2023-02-15 20:02:03 +00:00
|
|
|
case PROP_CURSOR:
|
|
|
|
g_value_set_object (value, _mks_paintable_get_cursor (self));
|
|
|
|
break;
|
|
|
|
|
2023-02-15 15:01:32 +00:00
|
|
|
case PROP_PAINTABLE:
|
|
|
|
g_value_set_object (value, self->child);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-09 12:38:48 +00:00
|
|
|
static void
|
|
|
|
mks_paintable_class_init (MksPaintableClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->dispose = mks_paintable_dispose;
|
2023-02-15 15:01:32 +00:00
|
|
|
object_class->get_property = mks_paintable_get_property;
|
|
|
|
|
2023-02-15 20:02:03 +00:00
|
|
|
properties [PROP_CURSOR] =
|
|
|
|
g_param_spec_object ("cursor", NULL, NULL,
|
|
|
|
GDK_TYPE_CURSOR,
|
|
|
|
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2023-02-15 15:01:32 +00:00
|
|
|
properties [PROP_PAINTABLE] =
|
|
|
|
g_param_spec_object ("paintable", NULL, NULL,
|
|
|
|
GDK_TYPE_PAINTABLE,
|
|
|
|
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, N_PROPS, properties);
|
2023-02-15 20:16:47 +00:00
|
|
|
|
|
|
|
signals [MOUSE_SET] =
|
|
|
|
g_signal_new ("mouse-set",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL,
|
|
|
|
_mks_marshal_VOID__INT_INT,
|
|
|
|
G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
|
|
|
|
g_signal_set_va_marshaller (signals [MOUSE_SET],
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
_mks_marshal_VOID__INT_INTv);
|
2023-02-09 12:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mks_paintable_init (MksPaintable *self)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-02-14 19:59:04 +00:00
|
|
|
static void
|
|
|
|
mks_paintable_invalidate_contents_cb (MksPaintable *self,
|
|
|
|
GdkPaintable *paintable)
|
|
|
|
{
|
|
|
|
g_assert (MKS_IS_PAINTABLE (self));
|
|
|
|
g_assert (GDK_IS_PAINTABLE (paintable));
|
|
|
|
|
|
|
|
gdk_paintable_invalidate_contents (GDK_PAINTABLE (self));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mks_paintable_invalidate_size_cb (MksPaintable *self,
|
|
|
|
GdkPaintable *paintable)
|
|
|
|
{
|
|
|
|
g_assert (MKS_IS_PAINTABLE (self));
|
|
|
|
g_assert (GDK_IS_PAINTABLE (paintable));
|
|
|
|
|
|
|
|
gdk_paintable_invalidate_size (GDK_PAINTABLE (self));
|
|
|
|
}
|
|
|
|
|
2023-02-14 01:38:30 +00:00
|
|
|
static void
|
2023-02-15 00:27:09 +00:00
|
|
|
mks_paintable_set_child (MksPaintable *self,
|
|
|
|
GdkPaintable *child)
|
2023-02-14 01:38:30 +00:00
|
|
|
{
|
|
|
|
gboolean size_changed;
|
|
|
|
|
|
|
|
g_assert (MKS_IS_PAINTABLE (self));
|
2023-02-15 00:27:09 +00:00
|
|
|
g_assert (!child || GDK_IS_PAINTABLE (child));
|
2023-02-14 01:38:30 +00:00
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
if (self->child == child)
|
2023-02-14 01:38:30 +00:00
|
|
|
return;
|
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
size_changed = self->child == NULL ||
|
|
|
|
child == NULL ||
|
|
|
|
gdk_paintable_get_intrinsic_width (self->child) != gdk_paintable_get_intrinsic_width (child) ||
|
|
|
|
gdk_paintable_get_intrinsic_height (self->child) != gdk_paintable_get_intrinsic_height (child);
|
2023-02-14 01:38:30 +00:00
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
if (self->child != NULL)
|
2023-02-14 01:38:30 +00:00
|
|
|
{
|
2023-02-15 00:27:09 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (self->child,
|
|
|
|
G_CALLBACK (mks_paintable_invalidate_size_cb),
|
2023-02-14 01:38:30 +00:00
|
|
|
self);
|
2023-02-15 00:27:09 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (self->child,
|
|
|
|
G_CALLBACK (mks_paintable_invalidate_contents_cb),
|
2023-02-14 01:38:30 +00:00
|
|
|
self);
|
2023-02-15 00:27:09 +00:00
|
|
|
g_clear_object (&self->child);
|
2023-02-14 01:38:30 +00:00
|
|
|
}
|
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
if (child != NULL)
|
2023-02-14 01:38:30 +00:00
|
|
|
{
|
2023-02-15 00:27:09 +00:00
|
|
|
self->child = g_object_ref (child);
|
|
|
|
g_signal_connect_object (self->child,
|
2023-02-14 01:38:30 +00:00
|
|
|
"invalidate-size",
|
2023-02-14 19:59:04 +00:00
|
|
|
G_CALLBACK (mks_paintable_invalidate_size_cb),
|
2023-02-14 01:38:30 +00:00
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
2023-02-15 00:27:09 +00:00
|
|
|
g_signal_connect_object (self->child,
|
2023-02-14 01:38:30 +00:00
|
|
|
"invalidate-contents",
|
2023-02-14 19:59:04 +00:00
|
|
|
G_CALLBACK (mks_paintable_invalidate_contents_cb),
|
2023-02-14 01:38:30 +00:00
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_paintable_invalidate_contents (GDK_PAINTABLE (self));
|
|
|
|
|
|
|
|
if (size_changed)
|
|
|
|
gdk_paintable_invalidate_size (GDK_PAINTABLE (self));
|
2023-02-15 15:01:32 +00:00
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PAINTABLE]);
|
2023-02-14 01:38:30 +00:00
|
|
|
}
|
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
static gboolean
|
|
|
|
mks_paintable_listener_scanout_dmabuf (MksPaintable *self,
|
|
|
|
GDBusMethodInvocation *invocation,
|
|
|
|
GUnixFDList *unix_fd_list,
|
|
|
|
GVariant *dmabuf,
|
|
|
|
guint width,
|
|
|
|
guint height,
|
|
|
|
guint stride,
|
|
|
|
guint fourcc,
|
|
|
|
guint64 modifier,
|
|
|
|
gboolean y0_top,
|
|
|
|
MksQemuListener *listener)
|
2023-02-09 12:38:48 +00:00
|
|
|
{
|
2023-02-15 00:27:09 +00:00
|
|
|
g_autoptr(MksDmabufPaintable) child = NULL;
|
|
|
|
g_autoptr(GError) error = NULL;
|
2023-05-01 15:59:33 +00:00
|
|
|
int dmabuf_fd = -1;
|
|
|
|
MksDmabufScanoutData *scanout_data;
|
2023-02-15 00:27:09 +00:00
|
|
|
guint handle;
|
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
g_assert (MKS_IS_PAINTABLE (self));
|
|
|
|
g_assert (G_IS_DBUS_METHOD_INVOCATION (invocation));
|
|
|
|
g_assert (MKS_QEMU_IS_LISTENER (listener));
|
2023-02-15 00:27:09 +00:00
|
|
|
g_assert (g_variant_is_of_type (dmabuf, G_VARIANT_TYPE_HANDLE));
|
|
|
|
|
|
|
|
handle = g_variant_get_handle (dmabuf);
|
|
|
|
|
|
|
|
if (handle >= g_unix_fd_list_get_length (unix_fd_list))
|
|
|
|
{
|
|
|
|
g_dbus_method_invocation_return_error_literal (invocation,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
"Invalid handle to DMA-BUF");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-05-01 15:59:33 +00:00
|
|
|
if (!MKS_IS_DMABUF_PAINTABLE (self->child))
|
|
|
|
{
|
|
|
|
child = mks_dmabuf_paintable_new ();
|
|
|
|
mks_paintable_set_child (self, GDK_PAINTABLE (child));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (-1 == (dmabuf_fd = g_unix_fd_list_get (unix_fd_list, handle, &error)))
|
2023-02-15 00:27:09 +00:00
|
|
|
{
|
|
|
|
g_dbus_method_invocation_return_gerror (invocation, error);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-02-16 03:40:48 +00:00
|
|
|
self->y_inverted = !y0_top;
|
2023-05-01 15:59:33 +00:00
|
|
|
scanout_data = g_new0 (MksDmabufScanoutData, 1);
|
|
|
|
|
|
|
|
scanout_data->dmabuf_fd = dmabuf_fd;
|
|
|
|
scanout_data->width = width;
|
|
|
|
scanout_data->height = height;
|
|
|
|
scanout_data->stride = stride;
|
|
|
|
scanout_data->fourcc = fourcc;
|
|
|
|
scanout_data->modifier = modifier;
|
2023-05-24 13:17:46 +00:00
|
|
|
if (self->scanout_data)
|
|
|
|
g_clear_fd (&self->scanout_data->dmabuf_fd, NULL);
|
|
|
|
|
2023-05-01 15:59:33 +00:00
|
|
|
g_clear_pointer (&self->scanout_data, g_free);
|
|
|
|
self->scanout_data = scanout_data;
|
2023-02-09 12:38:48 +00:00
|
|
|
|
2023-02-11 01:21:33 +00:00
|
|
|
mks_qemu_listener_complete_scanout_dmabuf (listener, invocation, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
2023-02-09 12:38:48 +00:00
|
|
|
}
|
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
static gboolean
|
|
|
|
mks_paintable_listener_update_dmabuf (MksPaintable *self,
|
|
|
|
GDBusMethodInvocation *invocation,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
MksQemuListener *listener)
|
|
|
|
{
|
2023-05-01 15:59:33 +00:00
|
|
|
cairo_region_t *region = NULL;
|
|
|
|
g_autoptr(GError) error = NULL;
|
|
|
|
GdkGLContext *gl_context;
|
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
g_assert (MKS_IS_PAINTABLE (self));
|
|
|
|
g_assert (G_IS_DBUS_METHOD_INVOCATION (invocation));
|
|
|
|
g_assert (MKS_QEMU_IS_LISTENER (listener));
|
|
|
|
|
|
|
|
if (MKS_IS_DMABUF_PAINTABLE (self->child))
|
2023-05-01 15:59:33 +00:00
|
|
|
{
|
|
|
|
g_assert (self->scanout_data != NULL);
|
|
|
|
if (!self->y_inverted)
|
|
|
|
y = self->scanout_data->height - y - height;
|
|
|
|
|
|
|
|
region = cairo_region_create_rectangle (&(cairo_rectangle_int_t) { x, y, width, height });
|
|
|
|
if (!(gl_context = mks_paintable_get_gl_context (self, &error)) ||
|
|
|
|
!mks_dmabuf_paintable_import (MKS_DMABUF_PAINTABLE (self->child),
|
|
|
|
gl_context,
|
|
|
|
self->scanout_data,
|
|
|
|
region,
|
|
|
|
&error))
|
|
|
|
{
|
|
|
|
g_dbus_method_invocation_return_gerror (invocation, error);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
mks_qemu_listener_complete_update_dmabuf (listener, invocation);
|
2023-05-01 15:59:33 +00:00
|
|
|
cleanup:
|
|
|
|
g_clear_pointer (®ion, cairo_region_destroy);
|
2023-02-15 00:27:09 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
static gboolean
|
|
|
|
mks_paintable_listener_update (MksPaintable *self,
|
|
|
|
GDBusMethodInvocation *invocation,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
guint stride,
|
|
|
|
guint pixman_format,
|
2023-02-14 20:24:15 +00:00
|
|
|
GVariant *bytestring,
|
2023-02-11 00:14:51 +00:00
|
|
|
MksQemuListener *listener)
|
2023-02-09 12:38:48 +00:00
|
|
|
{
|
2023-02-14 20:24:15 +00:00
|
|
|
g_autoptr(GBytes) bytes = NULL;
|
2023-02-14 01:38:30 +00:00
|
|
|
cairo_surface_t *source;
|
2023-02-14 20:24:15 +00:00
|
|
|
const guint8 *data;
|
2023-02-14 01:38:30 +00:00
|
|
|
cairo_t *cr;
|
2023-02-11 17:19:29 +00:00
|
|
|
cairo_format_t format;
|
2023-02-14 01:38:30 +00:00
|
|
|
gsize data_len;
|
2023-02-11 17:19:29 +00:00
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
g_assert (MKS_IS_PAINTABLE (self));
|
|
|
|
g_assert (G_IS_DBUS_METHOD_INVOCATION (invocation));
|
|
|
|
g_assert (MKS_QEMU_IS_LISTENER (listener));
|
2023-02-09 12:38:48 +00:00
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
if (!MKS_IS_CAIRO_FRAMEBUFFER (self->child) ||
|
2023-02-14 01:38:30 +00:00
|
|
|
!(format = _pixman_format_to_cairo_format (pixman_format)))
|
2023-02-11 17:19:29 +00:00
|
|
|
{
|
|
|
|
g_dbus_method_invocation_return_error_literal (invocation,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
2023-02-14 01:38:30 +00:00
|
|
|
"Invalid operation");
|
2023-02-11 17:19:29 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-02-14 20:24:15 +00:00
|
|
|
bytes = g_variant_get_data_as_bytes (bytestring);
|
|
|
|
data = g_bytes_get_data (bytes, &data_len);
|
2023-02-12 18:39:14 +00:00
|
|
|
|
2023-02-14 01:38:30 +00:00
|
|
|
if (data_len < cairo_format_stride_for_width (format, width) * height)
|
|
|
|
{
|
|
|
|
g_dbus_method_invocation_return_error_literal (invocation,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
"Stride invalid for size");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2023-02-12 18:39:14 +00:00
|
|
|
|
2023-02-14 01:38:30 +00:00
|
|
|
/* We can get in a protocol race condition here in that we will get updates
|
|
|
|
* for framebuffer content _BEFORE_ we'll get notified of property changes
|
|
|
|
* about the MksQemuConsole's size.
|
|
|
|
*
|
|
|
|
* To overcome that, if we detect something larger than our current
|
|
|
|
* framebuffer, we'll resize it and draw over the old contents in a
|
|
|
|
* new framebuffer.
|
|
|
|
*
|
|
|
|
* When shrinking, we can do this as well and then handle it when the
|
|
|
|
* console size notification arrives.
|
|
|
|
*
|
|
|
|
* Generally this is seen at startup during EFI/BIOS.
|
|
|
|
*/
|
2023-02-15 00:27:09 +00:00
|
|
|
if (x + width > gdk_paintable_get_intrinsic_width (self->child) ||
|
|
|
|
y + height > gdk_paintable_get_intrinsic_height (self->child))
|
2023-02-14 01:38:30 +00:00
|
|
|
{
|
2023-02-15 00:27:09 +00:00
|
|
|
guint max_width = MAX (gdk_paintable_get_intrinsic_width (self->child), x + width);
|
|
|
|
guint max_height = MAX (gdk_paintable_get_intrinsic_height (self->child), y + height);
|
2023-02-14 01:38:30 +00:00
|
|
|
g_autoptr(MksCairoFramebuffer) framebuffer = mks_cairo_framebuffer_new (format, max_width, max_height);
|
2023-02-12 18:39:14 +00:00
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
mks_cairo_framebuffer_copy_to (MKS_CAIRO_FRAMEBUFFER (self->child), framebuffer);
|
|
|
|
mks_paintable_set_child (self, GDK_PAINTABLE (framebuffer));
|
2023-02-12 18:39:14 +00:00
|
|
|
}
|
2023-02-11 01:21:33 +00:00
|
|
|
|
2023-02-14 20:24:15 +00:00
|
|
|
source = cairo_image_surface_create_for_data ((guint8 *)data, format, width, height, stride);
|
2023-02-15 00:27:09 +00:00
|
|
|
cr = mks_cairo_framebuffer_update (MKS_CAIRO_FRAMEBUFFER (self->child), x, y, width, height);
|
2023-02-14 19:59:04 +00:00
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
2023-02-14 01:38:30 +00:00
|
|
|
cairo_set_source_surface (cr, source, 0, 0);
|
2023-02-14 19:59:04 +00:00
|
|
|
cairo_rectangle (cr, 0, 0, width, height);
|
2023-02-14 20:24:15 +00:00
|
|
|
cairo_paint (cr);
|
2023-02-14 01:38:30 +00:00
|
|
|
cairo_destroy (cr);
|
|
|
|
cairo_surface_destroy (source);
|
|
|
|
|
2023-02-11 01:12:07 +00:00
|
|
|
mks_qemu_listener_complete_update (listener, invocation);
|
|
|
|
|
|
|
|
return TRUE;
|
2023-02-09 12:38:48 +00:00
|
|
|
}
|
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
static gboolean
|
|
|
|
mks_paintable_listener_scanout (MksPaintable *self,
|
|
|
|
GDBusMethodInvocation *invocation,
|
|
|
|
guint width,
|
|
|
|
guint height,
|
|
|
|
guint stride,
|
|
|
|
guint pixman_format,
|
2023-02-14 20:24:15 +00:00
|
|
|
GVariant *bytestring,
|
2023-02-11 00:14:51 +00:00
|
|
|
MksQemuListener *listener)
|
2023-02-09 12:38:48 +00:00
|
|
|
{
|
2023-02-14 20:24:15 +00:00
|
|
|
g_autoptr(GBytes) bytes = NULL;
|
2023-02-14 01:38:30 +00:00
|
|
|
cairo_surface_t *source;
|
2023-02-14 20:24:15 +00:00
|
|
|
const guint8 *data;
|
2023-02-14 01:38:30 +00:00
|
|
|
cairo_t *cr;
|
2023-02-11 17:19:29 +00:00
|
|
|
cairo_format_t format;
|
2023-02-12 18:39:14 +00:00
|
|
|
gsize data_len;
|
2023-02-09 12:38:48 +00:00
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
g_assert (MKS_IS_PAINTABLE (self));
|
|
|
|
g_assert (G_IS_DBUS_METHOD_INVOCATION (invocation));
|
|
|
|
g_assert (MKS_QEMU_IS_LISTENER (listener));
|
2023-02-14 20:24:15 +00:00
|
|
|
g_assert (g_variant_is_of_type (bytestring, G_VARIANT_TYPE_BYTESTRING));
|
2023-02-09 12:38:48 +00:00
|
|
|
|
2023-02-11 17:19:29 +00:00
|
|
|
if (!(format = _pixman_format_to_cairo_format (pixman_format)))
|
|
|
|
{
|
|
|
|
g_dbus_method_invocation_return_error_literal (invocation,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
"Pixman format not supported");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-02-14 20:24:15 +00:00
|
|
|
bytes = g_variant_get_data_as_bytes (bytestring);
|
|
|
|
data = g_bytes_get_data (bytes, &data_len);
|
2023-02-09 12:38:48 +00:00
|
|
|
|
2023-02-14 01:38:30 +00:00
|
|
|
if (data_len < cairo_format_stride_for_width (format, width) * height)
|
2023-02-12 18:39:14 +00:00
|
|
|
{
|
2023-02-14 01:38:30 +00:00
|
|
|
g_dbus_method_invocation_return_error_literal (invocation,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
"Stride invalid for size");
|
|
|
|
return TRUE;
|
2023-02-12 18:39:14 +00:00
|
|
|
}
|
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
if (self->child == NULL ||
|
|
|
|
!MKS_IS_CAIRO_FRAMEBUFFER (self->child) ||
|
|
|
|
width != gdk_paintable_get_intrinsic_width (self->child) ||
|
|
|
|
height != gdk_paintable_get_intrinsic_height (self->child))
|
2023-02-14 01:38:30 +00:00
|
|
|
{
|
2023-02-15 00:27:09 +00:00
|
|
|
g_autoptr(MksCairoFramebuffer) child = mks_cairo_framebuffer_new (format, width, height);
|
2023-02-12 18:39:14 +00:00
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
mks_paintable_set_child (self, GDK_PAINTABLE (child));
|
2023-02-14 01:38:30 +00:00
|
|
|
}
|
2023-02-11 01:12:07 +00:00
|
|
|
|
2023-02-16 03:40:48 +00:00
|
|
|
self->y_inverted = FALSE;
|
|
|
|
|
2023-02-14 20:24:15 +00:00
|
|
|
source = cairo_image_surface_create_for_data ((guint8 *)data, format, width, height, stride);
|
2023-02-15 00:27:09 +00:00
|
|
|
cr = mks_cairo_framebuffer_update (MKS_CAIRO_FRAMEBUFFER (self->child), 0, 0, width, height);
|
2023-02-14 01:38:30 +00:00
|
|
|
cairo_set_source_surface (cr, source, 0, 0);
|
2023-02-14 19:59:04 +00:00
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
2023-02-14 01:38:30 +00:00
|
|
|
cairo_rectangle (cr, 0, 0, width, height);
|
|
|
|
cairo_paint (cr);
|
|
|
|
cairo_destroy (cr);
|
|
|
|
cairo_surface_destroy (source);
|
2023-02-09 12:38:48 +00:00
|
|
|
|
2023-02-11 01:12:07 +00:00
|
|
|
mks_qemu_listener_complete_scanout (listener, invocation);
|
|
|
|
|
|
|
|
return TRUE;
|
2023-02-09 12:38:48 +00:00
|
|
|
}
|
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
static gboolean
|
|
|
|
mks_paintable_listener_cursor_define (MksPaintable *self,
|
|
|
|
GDBusMethodInvocation *invocation,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int hot_x,
|
|
|
|
int hot_y,
|
2023-02-15 20:02:03 +00:00
|
|
|
GVariant *bytestring,
|
2023-02-11 00:14:51 +00:00
|
|
|
MksQemuListener *listener)
|
2023-02-09 12:38:48 +00:00
|
|
|
{
|
2023-02-15 20:02:03 +00:00
|
|
|
g_autoptr(GBytes) bytes = NULL;
|
|
|
|
g_autoptr(GdkTexture) texture = NULL;
|
|
|
|
g_autoptr(GdkCursor) cursor = NULL;
|
|
|
|
gsize data_len;
|
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
g_assert (MKS_IS_PAINTABLE (self));
|
|
|
|
g_assert (G_IS_DBUS_METHOD_INVOCATION (invocation));
|
|
|
|
g_assert (MKS_QEMU_IS_LISTENER (listener));
|
|
|
|
|
2023-02-15 20:02:03 +00:00
|
|
|
if (width < 1 || width > 512 ||
|
|
|
|
height < 1 || height > 512 ||
|
|
|
|
!(bytes = g_variant_get_data_as_bytes (bytestring)))
|
|
|
|
goto failure;
|
|
|
|
|
|
|
|
data_len = g_bytes_get_size (bytes);
|
|
|
|
if (data_len != (4 * width * height))
|
|
|
|
goto failure;
|
|
|
|
|
|
|
|
texture = gdk_memory_texture_new (width,
|
|
|
|
height,
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
GDK_MEMORY_B8G8R8A8_PREMULTIPLIED,
|
|
|
|
#else
|
|
|
|
GDK_MEMORY_A8R8G8B8_PREMULTIPLIED,
|
|
|
|
#endif
|
|
|
|
bytes,
|
|
|
|
width * 4);
|
|
|
|
|
|
|
|
cursor = gdk_cursor_new_from_texture (texture, hot_x, hot_y, NULL);
|
|
|
|
|
|
|
|
if (g_set_object (&self->cursor, cursor))
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CURSOR]);
|
|
|
|
|
|
|
|
failure:
|
2023-02-11 01:21:33 +00:00
|
|
|
mks_qemu_listener_complete_cursor_define (listener, invocation);
|
|
|
|
|
|
|
|
return TRUE;
|
2023-02-09 12:38:48 +00:00
|
|
|
}
|
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
static gboolean
|
|
|
|
mks_paintable_listener_mouse_set (MksPaintable *self,
|
|
|
|
GDBusMethodInvocation *invocation,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int on,
|
|
|
|
MksQemuListener *listener)
|
2023-02-09 12:38:48 +00:00
|
|
|
{
|
|
|
|
g_assert (MKS_IS_PAINTABLE (self));
|
2023-02-11 00:14:51 +00:00
|
|
|
g_assert (G_IS_DBUS_METHOD_INVOCATION (invocation));
|
|
|
|
g_assert (MKS_QEMU_IS_LISTENER (listener));
|
2023-02-09 12:38:48 +00:00
|
|
|
|
2023-02-15 20:16:47 +00:00
|
|
|
self->mouse_x = x;
|
|
|
|
self->mouse_y = y;
|
|
|
|
|
2023-02-11 01:21:33 +00:00
|
|
|
mks_qemu_listener_complete_mouse_set (listener, invocation);
|
|
|
|
|
2023-02-15 20:16:47 +00:00
|
|
|
g_signal_emit (self, signals[MOUSE_SET], 0, x, y);
|
|
|
|
|
2023-02-11 01:21:33 +00:00
|
|
|
return TRUE;
|
2023-02-09 12:38:48 +00:00
|
|
|
}
|
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
static gboolean
|
|
|
|
mks_paintable_listener_disable (MksPaintable *self,
|
|
|
|
GDBusMethodInvocation *invocation,
|
|
|
|
MksQemuListener *listener)
|
2023-02-09 12:38:48 +00:00
|
|
|
{
|
2023-02-11 00:14:51 +00:00
|
|
|
g_assert (MKS_IS_PAINTABLE (self));
|
|
|
|
g_assert (G_IS_DBUS_METHOD_INVOCATION (invocation));
|
|
|
|
g_assert (MKS_QEMU_IS_LISTENER (listener));
|
|
|
|
|
2023-02-15 00:27:09 +00:00
|
|
|
if (MKS_IS_CAIRO_FRAMEBUFFER (self->child))
|
|
|
|
mks_cairo_framebuffer_clear (MKS_CAIRO_FRAMEBUFFER (self->child));
|
2023-02-11 01:21:33 +00:00
|
|
|
|
2023-02-14 01:38:30 +00:00
|
|
|
gdk_paintable_invalidate_contents (GDK_PAINTABLE (self));
|
2023-02-11 01:12:07 +00:00
|
|
|
|
2023-02-11 01:21:33 +00:00
|
|
|
mks_qemu_listener_complete_disable (listener, invocation);
|
|
|
|
|
|
|
|
return TRUE;
|
2023-02-09 12:38:48 +00:00
|
|
|
}
|
2023-02-10 01:32:00 +00:00
|
|
|
|
|
|
|
|
2023-02-11 01:12:07 +00:00
|
|
|
static void
|
|
|
|
mks_paintable_connection_cb (GObject *object,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
g_autoptr(MksPaintable) self = user_data;
|
|
|
|
g_autoptr(GDBusConnection) connection = NULL;
|
|
|
|
g_autoptr(GError) error = NULL;
|
|
|
|
|
|
|
|
g_assert (MKS_IS_PAINTABLE (self));
|
|
|
|
g_assert (G_IS_ASYNC_RESULT (result));
|
|
|
|
|
|
|
|
if (!(connection = g_dbus_connection_new_finish (result, &error)))
|
|
|
|
{
|
|
|
|
g_warning ("Failed to create D-Bus connection: %s", error->message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_set_object (&self->connection, connection);
|
|
|
|
|
|
|
|
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->listener),
|
|
|
|
connection,
|
|
|
|
"/org/qemu/Display1/Listener",
|
|
|
|
&error))
|
|
|
|
{
|
|
|
|
g_warning ("Failed to export listener on bus: %s", error->message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_dbus_connection_start_message_processing (connection);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
GdkPaintable *
|
|
|
|
_mks_paintable_new (GCancellable *cancellable,
|
|
|
|
int *peer_fd,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_autoptr(MksPaintable) self = NULL;
|
|
|
|
g_autoptr(GSocketConnection) io_stream = NULL;
|
|
|
|
g_autoptr(GSocket) socket = NULL;
|
|
|
|
g_autofd int us = -1;
|
|
|
|
g_autofd int them = -1;
|
|
|
|
|
|
|
|
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
|
|
|
|
g_return_val_if_fail (peer_fd != NULL, NULL);
|
|
|
|
|
|
|
|
*peer_fd = -1;
|
|
|
|
|
|
|
|
self = g_object_new (MKS_TYPE_PAINTABLE, NULL);
|
|
|
|
|
|
|
|
/* Create a socketpair() to use for D-Bus P2P protocol. We will be receiving
|
|
|
|
* DMA-BUF FDs over this.
|
|
|
|
*/
|
|
|
|
if (!create_socketpair (&us, &them, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Create socket for our side of the socket pair */
|
|
|
|
if (!(socket = g_socket_new_from_fd (us, error)))
|
|
|
|
return NULL;
|
|
|
|
us = -1;
|
|
|
|
|
|
|
|
/* And convert that socket into a GIOStream */
|
|
|
|
io_stream = g_socket_connection_factory_create_connection (socket);
|
|
|
|
|
|
|
|
/* Setup our listener and callbacks to process requests */
|
2023-02-11 01:12:07 +00:00
|
|
|
self->listener = mks_qemu_listener_skeleton_new ();
|
|
|
|
g_signal_connect_object (self->listener,
|
2023-02-11 00:14:51 +00:00
|
|
|
"handle-scanout",
|
|
|
|
G_CALLBACK (mks_paintable_listener_scanout),
|
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
2023-02-11 01:12:07 +00:00
|
|
|
g_signal_connect_object (self->listener,
|
2023-02-11 00:14:51 +00:00
|
|
|
"handle-update",
|
|
|
|
G_CALLBACK (mks_paintable_listener_update),
|
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
2023-02-11 01:12:07 +00:00
|
|
|
g_signal_connect_object (self->listener,
|
2023-02-11 00:14:51 +00:00
|
|
|
"handle-scanout-dmabuf",
|
|
|
|
G_CALLBACK (mks_paintable_listener_scanout_dmabuf),
|
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
2023-02-11 01:12:07 +00:00
|
|
|
g_signal_connect_object (self->listener,
|
2023-02-11 00:14:51 +00:00
|
|
|
"handle-update-dmabuf",
|
|
|
|
G_CALLBACK (mks_paintable_listener_update_dmabuf),
|
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
2023-02-11 01:12:07 +00:00
|
|
|
g_signal_connect_object (self->listener,
|
2023-02-11 00:14:51 +00:00
|
|
|
"handle-disable",
|
|
|
|
G_CALLBACK (mks_paintable_listener_disable),
|
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
2023-02-11 01:12:07 +00:00
|
|
|
g_signal_connect_object (self->listener,
|
2023-02-11 00:14:51 +00:00
|
|
|
"handle-cursor-define",
|
|
|
|
G_CALLBACK (mks_paintable_listener_cursor_define),
|
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
2023-02-11 01:12:07 +00:00
|
|
|
g_signal_connect_object (self->listener,
|
2023-02-11 00:14:51 +00:00
|
|
|
"handle-mouse-set",
|
|
|
|
G_CALLBACK (mks_paintable_listener_mouse_set),
|
|
|
|
self,
|
|
|
|
G_CONNECT_SWAPPED);
|
|
|
|
|
2023-02-11 01:12:07 +00:00
|
|
|
/* Asynchronously create connection because we can't do it synchronously
|
|
|
|
* as the other side is doing AUTHENTICATION_SERVER for no good reason.
|
2023-02-11 00:14:51 +00:00
|
|
|
*/
|
2023-02-11 01:12:07 +00:00
|
|
|
g_dbus_connection_new (G_IO_STREAM (io_stream),
|
|
|
|
NULL,
|
|
|
|
G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING|G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
|
|
|
|
NULL,
|
|
|
|
cancellable,
|
|
|
|
mks_paintable_connection_cb,
|
|
|
|
g_object_ref (self));
|
2023-02-11 00:14:51 +00:00
|
|
|
|
|
|
|
*peer_fd = g_steal_fd (&them);
|
|
|
|
|
2023-02-11 01:12:07 +00:00
|
|
|
g_assert (*peer_fd != -1);
|
|
|
|
g_assert (MKS_IS_PAINTABLE (self));
|
|
|
|
g_assert (MKS_QEMU_IS_LISTENER (self->listener));
|
|
|
|
|
2023-02-11 00:14:51 +00:00
|
|
|
return GDK_PAINTABLE (g_steal_pointer (&self));
|
2023-02-10 01:32:00 +00:00
|
|
|
}
|
2023-02-15 20:02:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* _mks_paintable_get_cursor:
|
|
|
|
* @self: a #MksPaintable
|
|
|
|
*
|
2023-05-23 10:24:33 +00:00
|
|
|
* Gets the cursor as defined by the QEMU instance.
|
2023-02-15 20:02:03 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer none) (nullable): a #GdkCursor or %NULL
|
|
|
|
*/
|
|
|
|
GdkCursor *
|
|
|
|
_mks_paintable_get_cursor (MksPaintable *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MKS_IS_PAINTABLE (self), NULL);
|
|
|
|
|
|
|
|
return self->cursor;
|
|
|
|
}
|