Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package wtype for openSUSE:Factory checked in at 2022-07-08 14:02:41 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/wtype (Old) and /work/SRC/openSUSE:Factory/.wtype.new.1523 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "wtype" Fri Jul 8 14:02:41 2022 rev:3 rq:987753 version:0.4 Changes: -------- --- /work/SRC/openSUSE:Factory/wtype/wtype.changes 2020-12-01 14:21:59.657541889 +0100 +++ /work/SRC/openSUSE:Factory/.wtype.new.1523/wtype.changes 2022-07-08 14:02:50.134510421 +0200 @@ -1,0 +2,10 @@ +Thu Jul 7 18:24:09 UTC 2022 - llyyr <llyyr.pub...@gmail.com> + +- Update to 0.4: + * Fix some unicode characters being converted to wrong keysyms (such as ?? and other greek characters) + * Drop reallocarray (for musl builds) + * Do not parse the - stdin placeholder if it appears after -- + * Document stdin input + * Add the -d switch to specify a delay between keystrokes + +------------------------------------------------------------------- Old: ---- v0.3.tar.gz New: ---- v0.4.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ wtype.spec ++++++ --- /var/tmp/diff_new_pack.UlL4ac/_old 2022-07-08 14:02:50.510510869 +0200 +++ /var/tmp/diff_new_pack.UlL4ac/_new 2022-07-08 14:02:50.514510874 +0200 @@ -1,7 +1,7 @@ # # spec file for package wtype # -# Copyright (c) 2020 SUSE LLC +# Copyright (c) 2022 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,7 +17,7 @@ Name: wtype -Version: 0.3 +Version: 0.4 Release: 0 Summary: Xdotool type for Wayland License: MIT ++++++ v0.3.tar.gz -> v0.4.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/wtype-0.3/README.md new/wtype-0.4/README.md --- old/wtype-0.3/README.md 2020-11-24 13:35:53.000000000 +0100 +++ new/wtype-0.4/README.md 2022-01-27 03:43:40.000000000 +0100 @@ -1,6 +1,8 @@ # wtype xdotool type for wayland +[](https://repology.org/project/wtype/versions) + ## Building ``` @@ -23,6 +25,15 @@ wtype -M ctrl c -m ctrl ``` +To alter delay between keystrokes, `-d`. + +``` +# delay of 0 when typing "foo", 120ms on "bar" +wtype foo -d 120 bar + +# also applied on stdin +echo everything | wtype -d 12 - +``` To press/release a named key (as given by [xkb_keysym_get_name](https://xkbcommon.org/doc/current/group__keysyms.html)), `-P`/`-p` can be used. @@ -31,6 +42,7 @@ # Press and release the Left key wtype -P left -p left ``` + Note that when wtype terminates, all the pressed keys/modifiers get released, as the compositor destroys the associated virtual keyboard object. To help performing a more complicated sequence of key presses, `-s` can be used to insert delays into the stream of key events. @@ -38,7 +50,3 @@ # Hold the Right key for 1000ms wtype -P right -s 1000 -p right ``` - -## Limitations - -To support arbitrary unicode characters, `wtype` generates a keymap on the fly and submits it to the compositor for distribution. Unfortunately this is broken under Xwayland as X has an upper limit on the amount of defined keycode-keysym pairs. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/wtype-0.3/main.c new/wtype-0.4/main.c --- old/wtype-0.3/main.c 2020-11-24 13:35:53.000000000 +0100 +++ new/wtype-0.4/main.c 2022-01-27 03:43:40.000000000 +0100 @@ -1,6 +1,4 @@ -#define _GNU_SOURCE - #include <fcntl.h> #include <locale.h> #include <stdbool.h> @@ -47,6 +45,7 @@ struct { unsigned int *key_codes; size_t key_codes_len; + unsigned int delay_ms; }; unsigned int single_key_code; enum wtype_mod mod; @@ -55,6 +54,12 @@ }; +struct keymap_entry { + xkb_keysym_t xkb; + wchar_t wchr; +}; + + struct wtype { struct wl_display *display; struct wl_registry *registry; @@ -62,8 +67,17 @@ struct zwp_virtual_keyboard_manager_v1 *manager; struct zwp_virtual_keyboard_v1 *keyboard; + // Stores a keycode -> (xkb_keysym_t, wchar_t) mapping + // Beware that this is one-indexed (as zero-keycodes are sometimes + // not handled well by clients). + // That is, keymap[0] is a (xkb_keysym_t, wchar_t) pair which we can type by sending + // the keycode 1. + // Beware that the wchar_t does not have to be valid (and is 0 in such cases) + // This is since some keysyms need not have a unicode representation + // (such as the arrow keys and similar) size_t keymap_len; - wchar_t *keymap; + struct keymap_entry *keymap; + uint32_t mod_status; size_t command_count; struct wtype_command *commands; @@ -133,18 +147,55 @@ } -unsigned int get_key_code(struct wtype *wtype, wchar_t ch) +static unsigned int append_keymap_entry(struct wtype *wtype, wchar_t ch, xkb_keysym_t xkb) { + wtype->keymap = realloc( + wtype->keymap, ++wtype->keymap_len * sizeof(wtype->keymap[0]) + ); + wtype->keymap[wtype->keymap_len - 1].wchr = ch; + wtype->keymap[wtype->keymap_len - 1].xkb = xkb; + return wtype->keymap_len; +} + + +unsigned int get_key_code_by_wchar(struct wtype *wtype, wchar_t ch) +{ + const struct { + wchar_t from; + xkb_keysym_t to; + } remap_table[] = { + { L'\n', XKB_KEY_Return }, + { L'\t', XKB_KEY_Tab }, + { L'\e', XKB_KEY_Escape }, + }; for (unsigned int i = 0; i < wtype->keymap_len; i++) { - if (wtype->keymap[i] == ch) { - return i; + if (wtype->keymap[i].wchr == ch) { + return i + 1; } } - wtype->keymap = reallocarray( - wtype->keymap, ++wtype->keymap_len, sizeof(wtype->keymap[0]) - ); - wtype->keymap[wtype->keymap_len - 1] = ch; - return wtype->keymap_len - 1; + + // TODO: Maybe warn if this actually ends up being XKB_KEY_NoSymbol or something? + xkb_keysym_t xkb = xkb_utf32_to_keysym(ch); + for (size_t i = 0; i < ARRAY_SIZE(remap_table); i++) { + if (remap_table[i].from == ch) { + // This overwrites whatever xkb gave us before. + xkb = remap_table[i].to; + break; + } + } + + return append_keymap_entry(wtype, ch, xkb); +} + +unsigned int get_key_code_by_xkb(struct wtype *wtype, xkb_keysym_t xkb) +{ + for (unsigned int i = 0; i < wtype->keymap_len; i++) { + if (wtype->keymap[i].xkb == xkb) { + return i + 1; + } + } + + return append_keymap_entry(wtype, 0, xkb); } @@ -155,17 +206,19 @@ bool raw_text = false; bool prefix_with_space = false; bool use_stdin = false; + unsigned int delay_ms = 0; for (int i = 1; i < argc; i++) { struct wtype_command *cmd = &wtype->commands[wtype->command_count]; if (!raw_text && !strcmp("--", argv[i])) { raw_text = true; - } else if (!strcmp("-", argv[i])) { + } else if (!raw_text && !strcmp("-", argv[i])) { // Output text from stdin if (use_stdin) { fail("Stdin place-holder can only appear once"); } use_stdin = true; cmd->type = WTYPE_COMMAND_TEXT_STDIN; + cmd->delay_ms = delay_ms; wtype->command_count++; } else if (!raw_text && argv[i][0] == '-'){ if (i == argc - 1) { @@ -192,6 +245,12 @@ if (cmd->sleep_ms <= 0) { fail("Invalid sleep time"); } + } else if (!strcmp("-d", argv[i])) { + // Set delay between type keystrokes + delay_ms = atoi(argv[i + 1]); + if (delay_ms <= 0) { + fail("Invalid sleep time"); + } } else if (!strcmp("-k", argv[i])) { //size_t k; xkb_keysym_t ks = xkb_keysym_from_name(argv[i + 1], XKB_KEYSYM_CASE_INSENSITIVE); @@ -201,7 +260,8 @@ cmd->type = WTYPE_COMMAND_TEXT; cmd->key_codes = malloc(sizeof(cmd->key_codes[0])); cmd->key_codes_len = 1; - cmd->key_codes[0] = get_key_code(wtype, ks); + cmd->key_codes[0] = get_key_code_by_xkb(wtype, ks); + cmd->delay_ms = delay_ms; } else if (!strcmp("-P", argv[i]) || !strcmp("-p", argv[i])) { // Press/release a key xkb_keysym_t ks = xkb_keysym_from_name(argv[i + 1], XKB_KEYSYM_CASE_INSENSITIVE); @@ -209,7 +269,7 @@ fail("Unknown key '%s'", argv[i + 1]); } cmd->type = argv[i][1] == 'P' ? WTYPE_COMMAND_KEY_PRESS : WTYPE_COMMAND_KEY_RELEASE; - cmd->single_key_code = get_key_code(wtype, ks); + cmd->single_key_code = get_key_code_by_xkb(wtype, ks); } else { fail("Unknown parameter %s", argv[i]); } @@ -219,6 +279,7 @@ } else { // Text cmd->type = WTYPE_COMMAND_TEXT; + cmd->delay_ms = delay_ms; wtype->command_count++; size_t raw_len = strlen(argv[i]) + 2; // NULL byte and the potential space @@ -240,7 +301,7 @@ cmd->key_codes = calloc(ret, sizeof(cmd->key_codes[0])); cmd->key_codes_len = ret; for (ssize_t k = 0; k < ret; k++) { - cmd->key_codes[k] = get_key_code(wtype, text[k]); + cmd->key_codes[k] = get_key_code_by_wchar(wtype, text[k]); } prefix_with_space = true; } @@ -299,6 +360,7 @@ { for (size_t i = 0; i < cmd->key_codes_len; i++) { type_keycode(wtype, cmd->key_codes[i]); + usleep(cmd->delay_ms * 1000); } } @@ -332,13 +394,14 @@ } k = 0; - unsigned int key_code = get_key_code(wtype, text_char); + unsigned int key_code = get_key_code_by_wchar(wtype, text_char); cmd->key_codes[cmd->key_codes_len++] = key_code; if (cmd->key_codes_len == buf_size) { upload_keymap(wtype); for (size_t i = 0; i < cmd->key_codes_len; i++) { type_keycode(wtype, cmd->key_codes[i]); + usleep(cmd->delay_ms * 1000); } cmd->key_codes_len = 0; } @@ -348,6 +411,7 @@ upload_keymap(wtype); for (size_t i = 0; i < cmd->key_codes_len; i++) { type_keycode(wtype, cmd->key_codes[i]); + usleep(cmd->delay_ms * 1000); } } @@ -373,22 +437,6 @@ static void print_keysym_name(xkb_keysym_t keysym, FILE *f) { - const struct { - wchar_t from; - wchar_t to; - } remap_table[] = { - { '\n', XKB_KEY_Return }, - { '\t', XKB_KEY_Tab }, - { '\e', XKB_KEY_Escape }, - }; - - for (size_t i = 0; i < ARRAY_SIZE(remap_table); i++) { - if (remap_table[i].from == keysym) { - keysym = remap_table[i].to; - break; - } - } - char sym_name[256]; int ret = xkb_keysym_get_name(keysym, sym_name, sizeof(sym_name)); @@ -397,11 +445,6 @@ return; } - if (sym_name[0] == '0' && sym_name[1] == 'x') { - // Unicode, we need special handling for these for whatever reason - snprintf(sym_name, sizeof(sym_name), "U%04x", keysym); - } - fprintf(f, "%s", sym_name); } @@ -423,20 +466,21 @@ "xkb_keycodes \"(unnamed)\" {\n" "minimum = 8;\n" "maximum = %ld;\n", - wtype->keymap_len + 8 + wtype->keymap_len + 8 + 1 ); for (size_t i = 0; i < wtype->keymap_len; i++) { - fprintf(f, "<K%ld> = %ld;\n", i, i + 8); + fprintf(f, "<K%ld> = %ld;\n", i + 1, i + 8 + 1); } fprintf(f, "};\n"); - fprintf(f, "xkb_types \"(unnamed)\" {};\n"); - fprintf(f, "xkb_compatibility \"(unnamed)\" {};\n"); + // TODO: Is including "complete" here really a good idea? + fprintf(f, "xkb_types \"(unnamed)\" { include \"complete\" };\n"); + fprintf(f, "xkb_compatibility \"(unnamed)\" { include \"complete\" };\n"); fprintf(f, "xkb_symbols \"(unnamed)\" {\n"); for (size_t i = 0; i < wtype->keymap_len; i++) { - fprintf(f, "key <K%ld> {[", i); - print_keysym_name(wtype->keymap[i], f); + fprintf(f, "key <K%ld> {[", i + 1); + print_keysym_name(wtype->keymap[i].xkb, f); fprintf(f, "]};\n"); } fprintf(f, "};\n"); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/wtype-0.3/man/wtype.1 new/wtype-0.4/man/wtype.1 --- old/wtype-0.3/man/wtype.1 2020-11-24 13:35:53.000000000 +0100 +++ new/wtype-0.4/man/wtype.1 2022-01-27 03:43:40.000000000 +0100 @@ -1,5 +1,5 @@ .\" Manpage for wtype. -.TH wtype 1 "23 November 2020" "0.2" "wtype man page" +.TH wtype 1 "23 November 2020" "0.4" "wtype man page" .SH NAME wtype \- xdotool type for Wayland .SH SYNOPSIS @@ -9,6 +9,9 @@ .B wtype [OPTION_OR_TEXT]... -- [TEXT]... +.B wtype +[OPTION_OR_TEXT] - + .SH DESCRIPTION .PP wtype is a Wayland tool that allows you to simulate keyboard input like xdotool type for X11. @@ -42,12 +45,18 @@ Type (press and release) key KEY. .TP +.BR \-d\ \fITIME\fR +Sleep for TIME milliseconds between keystrokes when typing texts. +Can be used multiple times, default 0. +.TP + .BR \-s\ \fITIME\fR Sleep for TIME milliseconds before interpreting the following options. This can be used to perform more complicated modifier sequences. -.SH LIMITATIONS -To support arbitrary unicode characters, wtype generates a keymap on the fly and submits it to the compositor for distribution. Unfortunately this is broken under Xwayland as X has an upper limit on the amount of defined keycode-keysym pairs. +.TP +.BR \- +Read text to type from stdin. This option can appear only once. .SH BUGS No known bugs. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/wtype-0.3/meson.build new/wtype-0.4/meson.build --- old/wtype-0.3/meson.build 2020-11-24 13:35:53.000000000 +0100 +++ new/wtype-0.4/meson.build 2022-01-27 03:43:40.000000000 +0100 @@ -1,6 +1,6 @@ project( 'wtype', 'c', - version: '0.0.1', + version: '0.4', license: 'MIT', default_options : [ 'buildtype=release', @@ -16,7 +16,7 @@ git_commit_hash = run_command([git.path(), 'describe', '--always', '--tags']).stdout().strip() git_branch = run_command([git.path(), 'rev-parse', '--abbrev-ref', 'HEAD']).stdout().strip() version = '"@0@ (" __DATE__ ", branch \'@1@\')"'.format(git_commit_hash, git_branch) - add_project_arguments('-DVERSION=@0@'.format(version), language: 'cpp') + add_project_arguments('-DVERSION=@0@'.format(version), language: 'c') endif cc = meson.get_compiler('c')