Merge branch 'bilelmoussaoui/expose-translate-keycode' into 'main'

keyboard: Expose keycode translation helper

See merge request chergert/libmks!7
This commit is contained in:
Christian Hergert 2023-04-04 03:26:14 +00:00
commit 02edb73d2a
3 changed files with 31 additions and 19 deletions

View File

@ -27,8 +27,6 @@
#include "mks-mouse.h"
#include "mks-util-private.h"
#include "mks-keymap-xorgevdev2qnum-private.h"
struct _MksDisplayPicture
{
GtkWidget parent_instance;
@ -54,22 +52,6 @@ G_DEFINE_FINAL_TYPE (MksDisplayPicture, mks_display_picture, GTK_TYPE_WIDGET)
static GParamSpec *properties [N_PROPS];
static void
mks_display_picture_translate_keycode (MksDisplayPicture *self,
guint keyval,
guint keycode,
guint *translated)
{
g_assert (MKS_IS_DISPLAY_PICTURE (self));
g_assert (translated != NULL);
if (keycode < xorgevdev_to_qnum_len &&
xorgevdev_to_qnum[keycode] != 0)
*translated = xorgevdev_to_qnum[keycode];
else
*translated = keycode;
}
static void
mks_display_picture_keyboard_press_cb (GObject *object,
GAsyncResult *result,
@ -319,7 +301,7 @@ mks_display_picture_legacy_event_cb (MksDisplayPicture *self,
g_assert (MKS_IS_KEYBOARD (self->keyboard));
mks_display_picture_translate_keycode (self, keyval, keycode, &qkeycode);
mks_keyboard_translate (keyval, keycode, &qkeycode);
if (event_type == GDK_KEY_PRESS)
mks_keyboard_press (self->keyboard,

View File

@ -26,6 +26,9 @@
#include "mks-keyboard.h"
#include "mks-util-private.h"
#include "mks-keymap-xorgevdev2qnum-private.h"
struct _MksKeyboard
{
MksDevice parent_instance;
@ -389,3 +392,25 @@ mks_keyboard_release_sync (MksKeyboard *self,
MKS_RETURN (ret);
}
/**
* mks_keyboard_translate:
* @keyval: the keyval
* @keycode: the hardware keycode
* @translated: (out): the translated keycode
*
* Translate a keycode to a QEMU compatible one.
*/
void
mks_keyboard_translate (guint keyval,
guint keycode,
guint *translated)
{
g_assert (translated != NULL);
if (keycode < xorgevdev_to_qnum_len &&
xorgevdev_to_qnum[keycode] != 0)
*translated = xorgevdev_to_qnum[keycode];
else
*translated = keycode;
}

View File

@ -85,4 +85,9 @@ gboolean mks_keyboard_release_sync (MksKeyboard *self,
GCancellable *cancellable,
GError **error);
MKS_AVAILABLE_IN_ALL
void mks_keyboard_translate (guint keyval,
guint keycode,
guint *translated);
G_END_DECLS