From 12edec8262b13c48fd64780b50b7f7a8fad9868b Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Wed, 8 Feb 2023 21:58:35 -0800 Subject: [PATCH] screen: add keyboard and mouse properties Adds MksKeyboard and MksMouse types. Setup a MksScreenKind for the MksScreen based on MksQemuConsole:type property. Currently the keyboard and mouse are not wired up, but here for scoping out the properties. --- lib/libmks.h | 7 +- lib/meson.build | 32 ++++++--- lib/mks-init.c | 6 ++ lib/mks-keyboard-private.h | 30 +++++++++ lib/mks-keyboard.c | 91 +++++++++++++++++++++++++ lib/mks-keyboard.h | 33 +++++++++ lib/mks-mouse-private.h | 28 ++++++++ lib/mks-mouse.c | 98 +++++++++++++++++++++++++++ lib/mks-mouse.h | 33 +++++++++ lib/mks-screen.c | 135 ++++++++++++++++++++++++++++++++++++- lib/mks-screen.h | 13 ++++ 11 files changed, 492 insertions(+), 14 deletions(-) create mode 100644 lib/mks-keyboard-private.h create mode 100644 lib/mks-keyboard.c create mode 100644 lib/mks-keyboard.h create mode 100644 lib/mks-mouse-private.h create mode 100644 lib/mks-mouse.c create mode 100644 lib/mks-mouse.h diff --git a/lib/libmks.h b/lib/libmks.h index 20c0642..0a2ce73 100644 --- a/lib/libmks.h +++ b/lib/libmks.h @@ -25,13 +25,16 @@ G_BEGIN_DECLS #define MKS_INSIDE -# include "mks-init.h" # include "mks-device.h" +# include "mks-enums.h" +# include "mks-init.h" +# include "mks-keyboard.h" +# include "mks-mouse.h" # include "mks-screen.h" # include "mks-session.h" # include "mks-types.h" -# include "mks-version-macros.h" # include "mks-version.h" +# include "mks-version-macros.h" #undef MKS_INSIDE G_END_DECLS diff --git a/lib/meson.build b/lib/meson.build index 2be7040..126391c 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -1,10 +1,31 @@ libmks_sources = [ 'mks-init.c', 'mks-device.c', + 'mks-keyboard.c', + 'mks-mouse.c', 'mks-screen.c', 'mks-session.c', ] +libmks_headers = [ + 'libmks.h', + 'mks-device.h', + 'mks-init.h', + 'mks-keyboard.h', + 'mks-mouse.h', + 'mks-screen.h', + 'mks-session.h', + 'mks-types.h', +] + +libmks_enums = gnome.mkenums_simple('mks-enums', + sources: libmks_headers, + install_header: true, + install_dir: join_paths(get_option('libdir'), 'libmks-@0@'.format(api_version)), + identifier_prefix: 'Mks', + symbol_prefix: 'mks', +) + libmks_private_sources = [ 'mks-read-only-list-model.c', @@ -16,15 +37,6 @@ libmks_private_sources = [ ) ] -libmks_headers = [ - 'libmks.h', - 'mks-device.h', - 'mks-init.h', - 'mks-screen.h', - 'mks-session.h', - 'mks-types.h', -] - # Setup mks-version.h for version checking version_split = meson.project_version().split('.') version_conf = configuration_data() @@ -47,7 +59,7 @@ libmks_deps = [ ] libmks = shared_library('mks-' + api_version, - libmks_sources + libmks_private_sources, + libmks_sources + [libmks_enums[0]] + libmks_private_sources, dependencies: libmks_deps, install: true, ) diff --git a/lib/mks-init.c b/lib/mks-init.c index 12550a7..b93f269 100644 --- a/lib/mks-init.c +++ b/lib/mks-init.c @@ -24,8 +24,11 @@ #include "mks-device.h" #include "mks-init.h" +#include "mks-keyboard.h" +#include "mks-mouse.h" #include "mks-qemu.h" #include "mks-read-only-list-model-private.h" +#include "mks-screen.h" #include "mks-session.h" #include "mks-version.h" @@ -48,6 +51,9 @@ mks_init_gtypes (void) /* GTypes that are part of our public API */ g_type_ensure (MKS_TYPE_DEVICE); + g_type_ensure (MKS_TYPE_KEYBOARD); + g_type_ensure (MKS_TYPE_MOUSE); + g_type_ensure (MKS_TYPE_SCREEN); g_type_ensure (MKS_TYPE_SESSION); } diff --git a/lib/mks-keyboard-private.h b/lib/mks-keyboard-private.h new file mode 100644 index 0000000..956d54b --- /dev/null +++ b/lib/mks-keyboard-private.h @@ -0,0 +1,30 @@ +/* + * mks-keyboard-private.h + * + * Copyright 2023 Christian Hergert + * + * 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 3 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include "mks-keyboard.h" + +G_BEGIN_DECLS + + + +G_END_DECLS diff --git a/lib/mks-keyboard.c b/lib/mks-keyboard.c new file mode 100644 index 0000000..9439429 --- /dev/null +++ b/lib/mks-keyboard.c @@ -0,0 +1,91 @@ +/* + * mks-keyboard.c + * + * Copyright 2023 Christian Hergert + * + * 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 3 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include "mks-keyboard.h" + +struct _MksKeyboard +{ + MksDevice parent_instance; +}; + +G_DEFINE_FINAL_TYPE (MksKeyboard, mks_keyboard, MKS_TYPE_DEVICE) + +enum { + PROP_0, + N_PROPS +}; + +static GParamSpec *properties [N_PROPS]; + +static void +mks_keyboard_dispose (GObject *object) +{ + MksKeyboard *self = (MksKeyboard *)object; + + G_OBJECT_CLASS (mks_keyboard_parent_class)->dispose (object); +} + +static void +mks_keyboard_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MksKeyboard *self = MKS_KEYBOARD (object); + + switch (prop_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +mks_keyboard_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MksKeyboard *self = MKS_KEYBOARD (object); + + switch (prop_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +mks_keyboard_class_init (MksKeyboardClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = mks_keyboard_dispose; + object_class->get_property = mks_keyboard_get_property; + object_class->set_property = mks_keyboard_set_property; +} + +static void +mks_keyboard_init (MksKeyboard *self) +{ +} diff --git a/lib/mks-keyboard.h b/lib/mks-keyboard.h new file mode 100644 index 0000000..fd7997d --- /dev/null +++ b/lib/mks-keyboard.h @@ -0,0 +1,33 @@ +/* + * mks-keyboard.h + * + * Copyright 2023 Christian Hergert + * + * 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 3 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include "mks-device.h" + +G_BEGIN_DECLS + +#define MKS_TYPE_KEYBOARD (mks_keyboard_get_type()) + +MKS_AVAILABLE_IN_ALL +G_DECLARE_FINAL_TYPE (MksKeyboard, mks_keyboard, MKS, KEYBOARD, MksDevice) + +G_END_DECLS diff --git a/lib/mks-mouse-private.h b/lib/mks-mouse-private.h new file mode 100644 index 0000000..f20c31e --- /dev/null +++ b/lib/mks-mouse-private.h @@ -0,0 +1,28 @@ +/* + * mks-mouse-private.h + * + * Copyright 2023 Christian Hergert + * + * 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 3 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include "mks-mouse.h" + +G_BEGIN_DECLS + +G_END_DECLS diff --git a/lib/mks-mouse.c b/lib/mks-mouse.c new file mode 100644 index 0000000..3c1d336 --- /dev/null +++ b/lib/mks-mouse.c @@ -0,0 +1,98 @@ +/* + * mks-mouse.c + * + * Copyright 2023 Christian Hergert + * + * 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 3 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include "mks-mouse.h" + +struct _MksMouse +{ + MksDevice parent_instance; +}; + +G_DEFINE_FINAL_TYPE (MksMouse, mks_mouse, MKS_TYPE_DEVICE) + +enum { + PROP_0, + N_PROPS +}; + +static GParamSpec *properties [N_PROPS]; + +MksMouse * +mks_mouse_new (void) +{ + return g_object_new (MKS_TYPE_MOUSE, NULL); +} + +static void +mks_mouse_finalize (GObject *object) +{ + MksMouse *self = (MksMouse *)object; + + G_OBJECT_CLASS (mks_mouse_parent_class)->finalize (object); +} + +static void +mks_mouse_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MksMouse *self = MKS_MOUSE (object); + + switch (prop_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +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); + } +} + +static void +mks_mouse_class_init (MksMouseClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = mks_mouse_finalize; + object_class->get_property = mks_mouse_get_property; + object_class->set_property = mks_mouse_set_property; +} + +static void +mks_mouse_init (MksMouse *self) +{ + +} diff --git a/lib/mks-mouse.h b/lib/mks-mouse.h new file mode 100644 index 0000000..f5239d4 --- /dev/null +++ b/lib/mks-mouse.h @@ -0,0 +1,33 @@ +/* + * mks-mouse.h + * + * Copyright 2023 Christian Hergert + * + * 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 3 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include "mks-device.h" + +G_BEGIN_DECLS + +#define MKS_TYPE_MOUSE (mks_mouse_get_type()) + +MKS_AVAILABLE_IN_ALL +G_DECLARE_FINAL_TYPE (MksMouse, mks_mouse, MKS, MOUSE, MksDevice) + +G_END_DECLS diff --git a/lib/mks-screen.c b/lib/mks-screen.c index fe3ccaf..406d24a 100644 --- a/lib/mks-screen.c +++ b/lib/mks-screen.c @@ -21,30 +21,91 @@ #include "config.h" +#include "mks-device-private.h" +#include "mks-enums.h" #include "mks-qemu.h" +#include "mks-keyboard-private.h" +#include "mks-mouse-private.h" #include "mks-screen-private.h" struct _MksScreen { MksDevice parent_instance; + MksQemuConsole *console; + gulong console_notify_handler; + + MksKeyboard *keyboard; + MksMouse *mouse; + + MksScreenKind kind : 2; }; G_DEFINE_FINAL_TYPE (MksScreen, mks_screen, MKS_TYPE_DEVICE) enum { PROP_0, + PROP_KIND, + PROP_KEYBOARD, + PROP_MOUSE, N_PROPS }; static GParamSpec *properties [N_PROPS]; +static void +mks_screen_console_notify_cb (MksScreen *self, + GParamSpec *pspec, + MksQemuConsole *console) +{ + g_assert (MKS_IS_SCREEN (self)); + g_assert (pspec != NULL); + g_assert (MKS_QEMU_IS_CONSOLE (console)); + + if (strcmp (pspec->name, "label") == 0) + _mks_device_set_name (MKS_DEVICE (self), mks_qemu_console_get_label (console)); +} + +static void +mks_screen_set_console (MksScreen *self, + MksQemuConsole *console) +{ + g_assert (MKS_IS_SCREEN (self)); + g_assert (!console || MKS_QEMU_IS_CONSOLE (console)); + g_assert (self->console == NULL); + + if (g_set_object (&self->console, console)) + { + const char *type; + + self->console_notify_handler = + g_signal_connect_object (console, + "notify", + G_CALLBACK (mks_screen_console_notify_cb), + self, + G_CONNECT_SWAPPED); + + if ((type = mks_qemu_console_get_type_ ((console)))) + { + if (strcmp (type, "Graphic") == 0) + self->kind = MKS_SCREEN_KIND_GRAPHIC; + } + } +} + static void mks_screen_dispose (GObject *object) { MksScreen *self = (MksScreen *)object; - g_clear_object (&self->console); + if (self->console != NULL) + { + g_clear_signal_handler (&self->console_notify_handler, self->console); + g_clear_object (&self->console); + } + + g_clear_object (&self->keyboard); + g_clear_object (&self->mouse); G_OBJECT_CLASS (mks_screen_parent_class)->dispose (object); } @@ -59,6 +120,18 @@ mks_screen_get_property (GObject *object, switch (prop_id) { + case PROP_KEYBOARD: + g_value_set_object (value, mks_screen_get_keyboard (self)); + break; + + case PROP_KIND: + g_value_set_enum (value, mks_screen_get_kind (self)); + break; + + case PROP_MOUSE: + g_value_set_object (value, mks_screen_get_mouse (self)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -87,6 +160,24 @@ mks_screen_class_init (MksScreenClass *klass) object_class->dispose = mks_screen_dispose; object_class->get_property = mks_screen_get_property; object_class->set_property = mks_screen_set_property; + + properties [PROP_KEYBOARD] = + g_param_spec_object ("keyboard", NULL, NULL, + MKS_TYPE_KEYBOARD, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + properties [PROP_KIND] = + g_param_spec_enum ("kind", NULL, NULL, + MKS_TYPE_SCREEN_KIND, + MKS_SCREEN_KIND_TEXT, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + properties [PROP_MOUSE] = + g_param_spec_object ("mouse", NULL, NULL, + MKS_TYPE_MOUSE, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, N_PROPS, properties); } static void @@ -113,7 +204,7 @@ mks_screen_new_cb (GObject *object, g_assert (MKS_IS_SCREEN (self)); g_assert (!console || MKS_QEMU_IS_CONSOLE (console)); - self->console = g_steal_pointer (&console); + mks_screen_set_console (self, console); if (error) g_task_return_error (task, g_steal_pointer (&error)); @@ -160,3 +251,43 @@ _mks_screen_new_finish (GAsyncResult *result, return ret; } + +/** + * mks_screen_get_keyboard: + * @self: a #MksScreen + * + * Gets the #MksScreen:keyboard property. + * + * Returns: (transfer none): a #MksKeyboard + */ +MksKeyboard * +mks_screen_get_keyboard (MksScreen *self) +{ + g_return_val_if_fail (MKS_IS_SCREEN (self), NULL); + + return self->keyboard; +} + +/** + * mks_screen_get_mouse: + * @self: a #MksScreen + * + * Gets the #MksScreen:mouse property. + * + * Returns: (transfer none): a #MksMouse + */ +MksMouse * +mks_screen_get_mouse (MksScreen *self) +{ + g_return_val_if_fail (MKS_IS_SCREEN (self), NULL); + + return self->mouse; +} + +MksScreenKind +mks_screen_get_kind (MksScreen *self) +{ + g_return_val_if_fail (MKS_IS_SCREEN (self), MKS_SCREEN_KIND_TEXT); + + return self->kind; +} diff --git a/lib/mks-screen.h b/lib/mks-screen.h index 62b6f75..7000563 100644 --- a/lib/mks-screen.h +++ b/lib/mks-screen.h @@ -29,7 +29,20 @@ G_BEGIN_DECLS #define MKS_TYPE_SCREEN (mks_screen_get_type()) +typedef enum _MksScreenKind +{ + MKS_SCREEN_KIND_TEXT = 0, + MKS_SCREEN_KIND_GRAPHIC = 1, +} MksScreenKind; + MKS_AVAILABLE_IN_ALL G_DECLARE_FINAL_TYPE (MksScreen, mks_screen, MKS, SCREEN, MksDevice) +MKS_AVAILABLE_IN_ALL +MksScreenKind mks_screen_get_kind (MksScreen *self); +MKS_AVAILABLE_IN_ALL +MksKeyboard *mks_screen_get_keyboard (MksScreen *self); +MKS_AVAILABLE_IN_ALL +MksMouse *mks_screen_get_mouse (MksScreen *self); + G_END_DECLS