mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-25 04:40:05 +01:00
tools: hide key codes by default
libinput-debug-events prints keycodes as they come in. This makes it dangerous
to be run by users (especially in the background) because it will leak
sensitive information as it is typed. Obfuscate the base set of keycodes
by default, require a --show-keycodes switch to show it.
The few times we actually need the keycodes, we can run the switch in the
debugging tool.
This does not affect keys outside of the main block on the keyboard (F-keys,
multimedia keys).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
(cherry picked from commit 8c1aa1de00)
This commit is contained in:
parent
d0cd796095
commit
1c6e6a6814
3 changed files with 25 additions and 4 deletions
|
|
@ -261,20 +261,31 @@ print_device_notify(struct libinput_event *ev)
|
|||
}
|
||||
|
||||
static void
|
||||
print_key_event(struct libinput_event *ev)
|
||||
print_key_event(struct libinput *li, struct libinput_event *ev)
|
||||
{
|
||||
struct libinput_event_keyboard *k = libinput_event_get_keyboard_event(ev);
|
||||
struct tools_context *context;
|
||||
struct tools_options *options;
|
||||
enum libinput_key_state state;
|
||||
uint32_t key;
|
||||
const char *keyname;
|
||||
|
||||
context = libinput_get_user_data(li);
|
||||
options = &context->options;
|
||||
|
||||
print_event_time(libinput_event_keyboard_get_time(k));
|
||||
state = libinput_event_keyboard_get_key_state(k);
|
||||
|
||||
key = libinput_event_keyboard_get_key(k);
|
||||
keyname = libevdev_event_code_get_name(EV_KEY, key);
|
||||
if (!options->show_keycodes &&
|
||||
(key >= KEY_ESC && key < KEY_ZENKAKUHANKAKU)) {
|
||||
keyname = "***";
|
||||
} else {
|
||||
keyname = libevdev_event_code_get_name(EV_KEY, key);
|
||||
keyname = keyname ? keyname : "???";
|
||||
}
|
||||
printf("%s (%d) %s\n",
|
||||
keyname ? keyname : "???",
|
||||
keyname,
|
||||
key,
|
||||
state == LIBINPUT_KEY_STATE_PRESSED ? "pressed" : "released");
|
||||
}
|
||||
|
|
@ -723,7 +734,7 @@ handle_and_print_events(struct libinput *li)
|
|||
&context.options);
|
||||
break;
|
||||
case LIBINPUT_EVENT_KEYBOARD_KEY:
|
||||
print_key_event(ev);
|
||||
print_key_event(li, ev);
|
||||
break;
|
||||
case LIBINPUT_EVENT_POINTER_MOTION:
|
||||
print_motion_event(ev);
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ enum options {
|
|||
OPT_SCROLL_BUTTON,
|
||||
OPT_SPEED,
|
||||
OPT_PROFILE,
|
||||
OPT_SHOW_KEYCODES,
|
||||
};
|
||||
|
||||
LIBINPUT_ATTRIBUTE_PRINTF(3, 0)
|
||||
|
|
@ -103,6 +104,7 @@ tools_usage(void)
|
|||
"--set-profile=[adaptive|flat].... set pointer acceleration profile\n"
|
||||
"--set-speed=<value>.... set pointer acceleration speed (allowed range [-1, 1]) \n"
|
||||
"--set-tap-map=[lrm|lmr] ... set button mapping for tapping\n"
|
||||
"--show-keycodes.... show all key codes while typing\n"
|
||||
"\n"
|
||||
"These options apply to all applicable devices, if a feature\n"
|
||||
"is not explicitly specified it is left at each device's default.\n"
|
||||
|
|
@ -137,6 +139,7 @@ tools_init_context(struct tools_context *context)
|
|||
options->seat = "seat0";
|
||||
options->speed = 0.0;
|
||||
options->profile = LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
|
||||
options->show_keycodes = false;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -173,6 +176,7 @@ tools_parse_args(int argc, char **argv, struct tools_context *context)
|
|||
{ "set-profile", 1, 0, OPT_PROFILE },
|
||||
{ "set-tap-map", 1, 0, OPT_TAP_MAP },
|
||||
{ "set-speed", 1, 0, OPT_SPEED },
|
||||
{ "show-keycodes", 0, 0, OPT_SHOW_KEYCODES },
|
||||
{ 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
|
@ -337,6 +341,9 @@ tools_parse_args(int argc, char **argv, struct tools_context *context)
|
|||
return 1;
|
||||
}
|
||||
break;
|
||||
case OPT_SHOW_KEYCODES:
|
||||
options->show_keycodes = true;
|
||||
break;
|
||||
default:
|
||||
tools_usage();
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@
|
|||
#ifndef _SHARED_H_
|
||||
#define _SHARED_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <libinput.h>
|
||||
|
||||
enum tools_backend {
|
||||
|
|
@ -36,6 +38,7 @@ struct tools_options {
|
|||
const char *device; /* if backend is BACKEND_DEVICE */
|
||||
const char *seat; /* if backend is BACKEND_UDEV */
|
||||
int grab; /* EVIOCGRAB */
|
||||
bool show_keycodes; /* show keycodes */
|
||||
|
||||
int verbose;
|
||||
int tapping;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue