lib: add MksMouse:is-absolute property

This commit is contained in:
Christian Hergert 2023-02-09 03:10:42 -08:00
parent 76b74b0769
commit c35baef43e
3 changed files with 67 additions and 23 deletions

View File

@ -27,6 +27,7 @@
struct _MksMouse
{
MksDevice parent_instance;
MksQemuMouse *mouse;
};
struct _MksMouseClass
@ -38,23 +39,53 @@ G_DEFINE_FINAL_TYPE (MksMouse, mks_mouse, MKS_TYPE_DEVICE)
enum {
PROP_0,
PROP_IS_ABSOLUTE,
N_PROPS
};
static GParamSpec *properties [N_PROPS];
MksMouse *
mks_mouse_new (void)
static void
mks_mouse_set_mouse (MksMouse *self,
MksQemuMouse *mouse)
{
return g_object_new (MKS_TYPE_MOUSE, NULL);
g_assert (MKS_IS_MOUSE (self));
g_assert (MKS_QEMU_IS_MOUSE (mouse));
g_set_object (&self->mouse, mouse);
}
static gboolean
mks_mouse_setup (MksDevice *device,
MksQemuObject *object)
{
MksMouse *self = (MksMouse *)device;
g_autolist(GDBusInterface) interfaces = NULL;
g_assert (MKS_IS_MOUSE (self));
g_assert (MKS_QEMU_IS_OBJECT (object));
interfaces = g_dbus_object_get_interfaces (G_DBUS_OBJECT (object));
for (const GList *iter = interfaces; iter; iter = iter->next)
{
GDBusInterface *iface = iter->data;
if (MKS_QEMU_IS_MOUSE (iface))
mks_mouse_set_mouse (self, MKS_QEMU_MOUSE (iface));
}
return self->mouse != NULL;
}
static void
mks_mouse_finalize (GObject *object)
mks_mouse_dispose (GObject *object)
{
MksMouse *self = (MksMouse *)object;
G_OBJECT_CLASS (mks_mouse_parent_class)->finalize (object);
g_clear_object (&self->mouse);
G_OBJECT_CLASS (mks_mouse_parent_class)->dispose (object);
}
static void
@ -67,21 +98,10 @@ mks_mouse_get_property (GObject *object,
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
case PROP_IS_ABSOLUTE:
g_value_set_boolean (value, mks_mouse_get_is_absolute (self));
break;
static void
mks_mouse_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
MksMouse *self = MKS_MOUSE (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -91,14 +111,33 @@ static void
mks_mouse_class_init (MksMouseClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
MksDeviceClass *device_class = MKS_DEVICE_CLASS (klass);
object_class->finalize = mks_mouse_finalize;
object_class->dispose = mks_mouse_dispose;
object_class->get_property = mks_mouse_get_property;
object_class->set_property = mks_mouse_set_property;
device_class->setup = mks_mouse_setup;
properties [PROP_IS_ABSOLUTE] =
g_param_spec_boolean ("is-absolute", NULL, NULL,
FALSE,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
mks_mouse_init (MksMouse *self)
{
}
gboolean
mks_mouse_get_is_absolute (MksMouse *self)
{
g_return_val_if_fail (MKS_IS_MOUSE (self), FALSE);
if (self->mouse)
return mks_qemu_mouse_get_is_absolute (self->mouse);
return FALSE;
}

View File

@ -43,6 +43,8 @@ G_BEGIN_DECLS
typedef struct _MksMouseClass MksMouseClass;
MKS_AVAILABLE_IN_ALL
GType mks_mouse_get_type (void) G_GNUC_CONST;
GType mks_mouse_get_type (void) G_GNUC_CONST;
MKS_AVAILABLE_IN_ALL
gboolean mks_mouse_get_is_absolute (MksMouse *self);
G_END_DECLS

View File

@ -49,6 +49,9 @@ print_device_info (MksDevice *device,
else if (MKS_IS_KEYBOARD (device))
g_print (", modifiers=0x%x",
mks_keyboard_get_modifiers (MKS_KEYBOARD (device)));
else if (MKS_IS_MOUSE (device))
g_print (", is-absolute=%u",
mks_mouse_get_is_absolute (MKS_MOUSE (device)));
g_print (")\n");
if (MKS_IS_SCREEN (device))