interactive-wayland: Add support for Compose
parent
fed96378a1
commit
c7f4e308f2
|
@ -280,7 +280,7 @@ process_event(struct keyboard *kbd, uint16_t type, uint16_t code, int32_t value)
|
||||||
|
|
||||||
if (value != KEY_STATE_RELEASE) {
|
if (value != KEY_STATE_RELEASE) {
|
||||||
tools_print_keycode_state(
|
tools_print_keycode_state(
|
||||||
kbd->state, kbd->compose_state, keycode,
|
NULL, kbd->state, kbd->compose_state, keycode,
|
||||||
consumed_mode, print_fields
|
consumed_mode, print_fields
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -36,7 +37,9 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "xkbcommon/xkbcommon.h"
|
#include "xkbcommon/xkbcommon.h"
|
||||||
|
#include "xkbcommon/xkbcommon-compose.h"
|
||||||
#include "tools-common.h"
|
#include "tools-common.h"
|
||||||
|
#include "src/utils.h"
|
||||||
|
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
#include "xdg-shell-client-protocol.h"
|
#include "xdg-shell-client-protocol.h"
|
||||||
|
@ -56,6 +59,7 @@ struct interactive_dpy {
|
||||||
uint32_t shm_format;
|
uint32_t shm_format;
|
||||||
|
|
||||||
struct xkb_context *ctx;
|
struct xkb_context *ctx;
|
||||||
|
struct xkb_compose_table *compose_table;
|
||||||
|
|
||||||
struct wl_surface *wl_surf;
|
struct wl_surface *wl_surf;
|
||||||
struct xdg_surface *xdg_surf;
|
struct xdg_surface *xdg_surf;
|
||||||
|
@ -76,6 +80,7 @@ struct interactive_seat {
|
||||||
|
|
||||||
struct xkb_keymap *keymap;
|
struct xkb_keymap *keymap;
|
||||||
struct xkb_state *state;
|
struct xkb_state *state;
|
||||||
|
struct xkb_compose_state *compose_state;
|
||||||
|
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
};
|
};
|
||||||
|
@ -394,17 +399,30 @@ kbd_key(void *data, struct wl_keyboard *wl_kbd, uint32_t serial, uint32_t time,
|
||||||
uint32_t key, uint32_t state)
|
uint32_t key, uint32_t state)
|
||||||
{
|
{
|
||||||
struct interactive_seat *seat = data;
|
struct interactive_seat *seat = data;
|
||||||
|
xkb_keycode_t keycode = key + EVDEV_OFFSET;
|
||||||
|
|
||||||
if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
|
if (seat->compose_state && state != WL_KEYBOARD_KEY_STATE_RELEASED) {
|
||||||
return;
|
xkb_keysym_t keysym = xkb_state_key_get_one_sym(seat->state, keycode);
|
||||||
|
xkb_compose_state_feed(seat->compose_state, keysym);
|
||||||
|
}
|
||||||
|
|
||||||
printf("%s: ", seat->name_str);
|
if (state != WL_KEYBOARD_KEY_STATE_RELEASED) {
|
||||||
tools_print_keycode_state(seat->state, NULL, key + EVDEV_OFFSET,
|
char *prefix = asprintf_safe("%s: ", seat->name_str);
|
||||||
XKB_CONSUMED_MODE_XKB,
|
tools_print_keycode_state(prefix, seat->state, seat->compose_state, keycode,
|
||||||
PRINT_ALL_FIELDS);
|
XKB_CONSUMED_MODE_XKB,
|
||||||
|
PRINT_ALL_FIELDS);
|
||||||
|
free(prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seat->compose_state) {
|
||||||
|
enum xkb_compose_status status = xkb_compose_state_get_status(seat->compose_state);
|
||||||
|
if (status == XKB_COMPOSE_CANCELLED || status == XKB_COMPOSE_COMPOSED)
|
||||||
|
xkb_compose_state_reset(seat->compose_state);
|
||||||
|
}
|
||||||
|
|
||||||
/* Exit on ESC. */
|
/* Exit on ESC. */
|
||||||
if (xkb_state_key_get_one_sym(seat->state, key + EVDEV_OFFSET) == XKB_KEY_Escape)
|
if (xkb_state_key_get_one_sym(seat->state, keycode) == XKB_KEY_Escape &&
|
||||||
|
state != WL_KEYBOARD_KEY_STATE_PRESSED)
|
||||||
terminate = true;
|
terminate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -518,8 +536,10 @@ seat_capabilities(void *data, struct wl_seat *wl_seat, uint32_t caps)
|
||||||
|
|
||||||
xkb_state_unref(seat->state);
|
xkb_state_unref(seat->state);
|
||||||
xkb_keymap_unref(seat->keymap);
|
xkb_keymap_unref(seat->keymap);
|
||||||
|
xkb_compose_state_unref(seat->compose_state);
|
||||||
|
|
||||||
seat->state = NULL;
|
seat->state = NULL;
|
||||||
|
seat->compose_state = NULL;
|
||||||
seat->keymap = NULL;
|
seat->keymap = NULL;
|
||||||
seat->wl_kbd = NULL;
|
seat->wl_kbd = NULL;
|
||||||
}
|
}
|
||||||
|
@ -564,6 +584,10 @@ seat_create(struct interactive_dpy *inter, struct wl_registry *registry,
|
||||||
seat->wl_seat = wl_registry_bind(registry, name, &wl_seat_interface,
|
seat->wl_seat = wl_registry_bind(registry, name, &wl_seat_interface,
|
||||||
MIN(version, 5));
|
MIN(version, 5));
|
||||||
wl_seat_add_listener(seat->wl_seat, &seat_listener, seat);
|
wl_seat_add_listener(seat->wl_seat, &seat_listener, seat);
|
||||||
|
if (seat->inter->compose_table) {
|
||||||
|
seat->compose_state = xkb_compose_state_new(seat->inter->compose_table,
|
||||||
|
XKB_COMPOSE_STATE_NO_FLAGS);
|
||||||
|
}
|
||||||
ret = asprintf(&seat->name_str, "seat:%d",
|
ret = asprintf(&seat->name_str, "seat:%d",
|
||||||
wl_proxy_get_id((struct wl_proxy *) seat->wl_seat));
|
wl_proxy_get_id((struct wl_proxy *) seat->wl_seat));
|
||||||
assert(ret >= 0);
|
assert(ret >= 0);
|
||||||
|
@ -580,6 +604,7 @@ seat_destroy(struct interactive_seat *seat)
|
||||||
wl_keyboard_destroy(seat->wl_kbd);
|
wl_keyboard_destroy(seat->wl_kbd);
|
||||||
|
|
||||||
xkb_state_unref(seat->state);
|
xkb_state_unref(seat->state);
|
||||||
|
xkb_compose_state_unref(seat->compose_state);
|
||||||
xkb_keymap_unref(seat->keymap);
|
xkb_keymap_unref(seat->keymap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -673,19 +698,56 @@ dpy_disconnect(struct interactive_dpy *inter)
|
||||||
wl_display_disconnect(inter->dpy);
|
wl_display_disconnect(inter->dpy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
usage(FILE *fp, char *progname)
|
||||||
|
{
|
||||||
|
fprintf(fp,
|
||||||
|
"Usage: %s [--help] [--enable-compose]\n",
|
||||||
|
progname);
|
||||||
|
fprintf(fp,
|
||||||
|
" --enable-compose enable Compose\n"
|
||||||
|
" --help display this help and exit\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct interactive_dpy inter;
|
struct interactive_dpy inter;
|
||||||
struct wl_registry *registry;
|
struct wl_registry *registry;
|
||||||
|
const char *locale;
|
||||||
|
struct xkb_compose_table *compose_table = NULL;
|
||||||
|
|
||||||
if (argc != 1) {
|
bool with_compose = false;
|
||||||
ret = strcmp(argv[1], "--help");
|
enum options {
|
||||||
fprintf(ret ? stderr : stdout, "Usage: %s [--help]\n", argv[0]);
|
OPT_COMPOSE,
|
||||||
if (ret)
|
};
|
||||||
fprintf(stderr, "unrecognized option: %s\n", argv[1]);
|
static struct option opts[] = {
|
||||||
return ret ? EXIT_INVALID_USAGE : EXIT_SUCCESS;
|
{"help", no_argument, 0, 'h'},
|
||||||
|
{"enable-compose", no_argument, 0, OPT_COMPOSE},
|
||||||
|
{0, 0, 0, 0},
|
||||||
|
};
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
int opt;
|
||||||
|
int option_index = 0;
|
||||||
|
|
||||||
|
opt = getopt_long(argc, argv, "h", opts, &option_index);
|
||||||
|
if (opt == -1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (opt) {
|
||||||
|
case OPT_COMPOSE:
|
||||||
|
with_compose = true;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
usage(stdout, argv[0]);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
case '?':
|
||||||
|
usage(stderr, argv[0]);
|
||||||
|
return EXIT_INVALID_USAGE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
@ -707,6 +769,20 @@ main(int argc, char *argv[])
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (with_compose) {
|
||||||
|
locale = setlocale(LC_CTYPE, NULL);
|
||||||
|
compose_table =
|
||||||
|
xkb_compose_table_new_from_locale(inter.ctx, locale,
|
||||||
|
XKB_COMPOSE_COMPILE_NO_FLAGS);
|
||||||
|
if (!compose_table) {
|
||||||
|
fprintf(stderr, "Couldn't create compose from locale\n");
|
||||||
|
goto err_compose;
|
||||||
|
}
|
||||||
|
inter.compose_table = compose_table;
|
||||||
|
} else {
|
||||||
|
inter.compose_table = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
registry = wl_display_get_registry(inter.dpy);
|
registry = wl_display_get_registry(inter.dpy);
|
||||||
wl_registry_add_listener(registry, ®istry_listener, &inter);
|
wl_registry_add_listener(registry, ®istry_listener, &inter);
|
||||||
|
|
||||||
|
@ -738,6 +814,8 @@ main(int argc, char *argv[])
|
||||||
wl_registry_destroy(registry);
|
wl_registry_destroy(registry);
|
||||||
err_conn:
|
err_conn:
|
||||||
dpy_disconnect(&inter);
|
dpy_disconnect(&inter);
|
||||||
|
err_compose:
|
||||||
|
xkb_compose_table_unref(compose_table);
|
||||||
err_out:
|
err_out:
|
||||||
exit(ret >= 0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
exit(ret >= 0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,7 +242,7 @@ process_event(xcb_generic_event_t *gevent, struct keyboard *kbd)
|
||||||
xcb_key_press_event_t *event = (xcb_key_press_event_t *) gevent;
|
xcb_key_press_event_t *event = (xcb_key_press_event_t *) gevent;
|
||||||
xkb_keycode_t keycode = event->detail;
|
xkb_keycode_t keycode = event->detail;
|
||||||
|
|
||||||
tools_print_keycode_state(kbd->state, NULL, keycode,
|
tools_print_keycode_state(NULL, kbd->state, NULL, keycode,
|
||||||
XKB_CONSUMED_MODE_XKB,
|
XKB_CONSUMED_MODE_XKB,
|
||||||
PRINT_ALL_FIELDS);
|
PRINT_ALL_FIELDS);
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,8 @@ print_keys_modmaps(struct xkb_keymap *keymap) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
tools_print_keycode_state(struct xkb_state *state,
|
tools_print_keycode_state(char *prefix,
|
||||||
|
struct xkb_state *state,
|
||||||
struct xkb_compose_state *compose_state,
|
struct xkb_compose_state *compose_state,
|
||||||
xkb_keycode_t keycode,
|
xkb_keycode_t keycode,
|
||||||
enum xkb_consumed_mode consumed_mode,
|
enum xkb_consumed_mode consumed_mode,
|
||||||
|
@ -182,6 +183,9 @@ tools_print_keycode_state(struct xkb_state *state,
|
||||||
syms = &sym;
|
syms = &sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (prefix)
|
||||||
|
printf("%s", prefix);
|
||||||
|
|
||||||
print_keycode(keymap, "keycode [ ", keycode, " ] ");
|
print_keycode(keymap, "keycode [ ", keycode, " ] ");
|
||||||
|
|
||||||
#ifdef ENABLE_PRIVATE_APIS
|
#ifdef ENABLE_PRIVATE_APIS
|
||||||
|
|
|
@ -61,7 +61,8 @@ print_keys_modmaps(struct xkb_keymap *keymap);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
tools_print_keycode_state(struct xkb_state *state,
|
tools_print_keycode_state(char *prefix,
|
||||||
|
struct xkb_state *state,
|
||||||
struct xkb_compose_state *compose_state,
|
struct xkb_compose_state *compose_state,
|
||||||
xkb_keycode_t keycode,
|
xkb_keycode_t keycode,
|
||||||
enum xkb_consumed_mode consumed_mode,
|
enum xkb_consumed_mode consumed_mode,
|
||||||
|
|
|
@ -28,6 +28,9 @@ This is a debugging tool, its behavior or output is not guaranteed to be stable.
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Fl \-help
|
.It Fl \-help
|
||||||
Print help and exit
|
Print help and exit
|
||||||
|
.
|
||||||
|
.It Fl \-enable\-compose
|
||||||
|
Enable Compose functionality
|
||||||
.El
|
.El
|
||||||
.
|
.
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
|
|
Loading…
Reference in New Issue