void uterm_input_keysym_to_string(struct uterm_input *input,
uint32_t keysym, char *str, size_t size);
+int uterm_input_string_to_keysym(struct uterm_input *input, const char *n,
+ uint32_t *out);
/*
* System Monitor
kbd_desc_keysym_to_string(input->desc, keysym, str, size);
}
+
+int uterm_input_string_to_keysym(struct uterm_input *input, const char *n,
+ uint32_t *out)
+{
+ if (!n || !out)
+ return -EINVAL;
+
+ if (input)
+ return kbd_desc_string_to_keysym(input->desc, n, out);
+
+#ifdef UTERM_HAVE_XKBCOMMON
+ return uxkb_string_to_keysym(n, out);
+#endif
+
+ return plain_string_to_keysym(n, out);
+}
snprintf(str, size, "%#x", keysym);
}
+int plain_string_to_keysym(const char *n, uint32_t *out)
+{
+ /* TODO: we really need to implement this; maybe use a hashtable similar
+ * to the Xlib? */
+ return -EOPNOTSUPP;
+}
+
const struct kbd_desc_ops plain_desc_ops = {
.init = plain_desc_init,
.ref = plain_desc_ref,
.unref = plain_desc_unref,
.alloc = plain_desc_alloc,
.keysym_to_string = plain_keysym_to_string,
+ .string_to_keysym = plain_string_to_keysym,
};
const struct kbd_dev_ops plain_dev_ops = {
xkb_keysym_get_name(keysym, str, size);
}
+int uxkb_string_to_keysym(const char *n, uint32_t *out)
+{
+ uint32_t keysym;
+
+ /* TODO: fix xkbcommon upstream to be case-insensitive if case-sensitive
+ * match fails. */
+ sym = xkb_keysym_from_name(n);
+ if (!sym)
+ return -EFAULT;
+
+ *out = sym;
+ return 0;
+}
+
const struct kbd_desc_ops uxkb_desc_ops = {
.init = uxkb_desc_init,
.ref = uxkb_desc_ref,
.unref = uxkb_desc_unref,
.alloc = uxkb_desc_alloc,
.keysym_to_string = uxkb_keysym_to_string,
+ .string_to_keysym = uxkb_string_to_keysym,
};
const struct kbd_dev_ops uxkb_dev_ops = {
void (*unref) (struct kbd_desc *desc);
int (*alloc) (struct kbd_desc *desc, struct kbd_dev **out);
void (*keysym_to_string) (uint32_t keysym, char *str, size_t size);
+ int (*string_to_keysym) (const char *n, uint32_t *out);
};
struct kbd_dev_ops {
extern const struct kbd_desc_ops plain_desc_ops;
extern const struct kbd_dev_ops plain_dev_ops;
+extern int plain_string_to_keysym(const char *n, uint32_t *out);
+
#ifdef UTERM_HAVE_XKBCOMMON
struct uxkb_desc {
extern const struct kbd_desc_ops uxkb_desc_ops;
extern const struct kbd_dev_ops uxkb_dev_ops;
+extern int uxkb_string_to_keysym(const char *n, uint32_t *out);
+
#else /* !UTERM_HAVE_XKBCOMMON */
struct uxkb_desc {
return desc->ops->keysym_to_string(keysym, str, size);
}
+static inline int kbd_desc_string_to_keysym(struct kbd_desc *desc,
+ const char *n,
+ uint32_t *out)
+{
+ if (!desc)
+ return -EINVAL;
+
+ return desc->ops->string_to_keysym(n, out);
+}
+
static inline void kbd_dev_ref(struct kbd_dev *dev)
{
if (!dev)