* [Qemu-devel] [PULL 0/5] ui: add linux evdev support, vnc and console fixes
@ 2016-03-09 9:04 Gerd Hoffmann
2016-03-09 9:04 ` [Qemu-devel] [PULL 1/5] vnc: send cursor when a new client is connecting Gerd Hoffmann
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2016-03-09 9:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
Hi,
Here is the ui patch queue, bringing support for linux input devices and
two fixes for the console and vnc.
please pull,
Gerd
The following changes since commit 1464ad45cd6cdeb0b5c1a54d3d3791396e47e52f:
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2016-03-04' into staging (2016-03-06 11:53:27 +0000)
are available in the git repository at:
git://git.kraxel.org/qemu tags/pull-ui-20160309-1
for you to fetch changes up to 58aa7d8e443c7f79710a4f5757966f6c511f2242:
ui/console: add escape sequence \e[5, 6n (2016-03-09 09:35:56 +0100)
----------------------------------------------------------------
add linux evdev support, vnc and console fixes.
----------------------------------------------------------------
Frediano Ziglio (1):
vnc: send cursor when a new client is connecting
Gerd Hoffmann (3):
input: linux evdev support
input-linux: add option to toggle grab on all devices
input-linux: add switch to enable auto-repeat events
Ren Kimura (1):
ui/console: add escape sequence \e[5, 6n
include/ui/input.h | 2 +
qemu-options.hx | 9 ++
ui/Makefile.objs | 1 +
ui/console.c | 56 ++++++--
ui/input-linux.c | 391 +++++++++++++++++++++++++++++++++++++++++++++++++++++
ui/vnc.c | 3 +
vl.c | 11 ++
7 files changed, 458 insertions(+), 15 deletions(-)
create mode 100644 ui/input-linux.c
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [PULL 1/5] vnc: send cursor when a new client is connecting
2016-03-09 9:04 [Qemu-devel] [PULL 0/5] ui: add linux evdev support, vnc and console fixes Gerd Hoffmann
@ 2016-03-09 9:04 ` Gerd Hoffmann
2016-03-09 9:04 ` [Qemu-devel] [PULL 2/5] input: linux evdev support Gerd Hoffmann
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2016-03-09 9:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann, Frediano Ziglio
From: Frediano Ziglio <fziglio@redhat.com>
If you have hardware cursor and you are reconnecting the VNC client
you need to send the cursor. Failing to do so make the cursor invisible
till is changed.
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Message-id: 1456929142-14033-1-git-send-email-fziglio@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
ui/vnc.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/ui/vnc.c b/ui/vnc.c
index 6cd6314..729f630 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2046,6 +2046,9 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
break;
case VNC_ENCODING_RICH_CURSOR:
vs->features |= VNC_FEATURE_RICH_CURSOR_MASK;
+ if (vs->vd->cursor) {
+ vnc_cursor_define(vs);
+ }
break;
case VNC_ENCODING_EXT_KEY_EVENT:
send_ext_key_event_ack(vs);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PULL 2/5] input: linux evdev support
2016-03-09 9:04 [Qemu-devel] [PULL 0/5] ui: add linux evdev support, vnc and console fixes Gerd Hoffmann
2016-03-09 9:04 ` [Qemu-devel] [PULL 1/5] vnc: send cursor when a new client is connecting Gerd Hoffmann
@ 2016-03-09 9:04 ` Gerd Hoffmann
2016-03-09 9:04 ` [Qemu-devel] [PULL 3/5] input-linux: add option to toggle grab on all devices Gerd Hoffmann
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2016-03-09 9:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Gerd Hoffmann
This patch adds support for reading input events directly from linux
evdev devices and forward them to the guest. Unlike virtio-input-host
which simply passes on all events to the guest without looking at them
this will interpret the events and feed them into the qemu input
subsystem.
Therefore this is limited to what the qemu input subsystem and the
emulated input devices are able to handle. Also there is no support for
absolute coordinates (tablet/touchscreen). So we are talking here about
basic mouse and keyboard support.
The advantage is that it'll work without virtio-input drivers in the
guest, the events are delivered to the usual ps/2 or usb input devices
(depending on what the machine happens to have). And for keyboards
qemu is able to switch the keyboard between guest and host on hotkey.
The hotkey is hard-coded for now (both control keys), initialy the
guest owns the keyboard.
Probably most useful when assigning vga devices with vfio and using a
physical monitor instead of vnc/spice/gtk as guest display.
Usage: Add '-input-linux /dev/input/event<nr>' to the qemu command
line. Note that udev has rules which populate /dev/input/by-{id,path}
with static names, which might be more convinient to use.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-id: 1457087116-4379-2-git-send-email-kraxel@redhat.com
---
include/ui/input.h | 2 +
qemu-options.hx | 9 ++
ui/Makefile.objs | 1 +
ui/input-linux.c | 357 +++++++++++++++++++++++++++++++++++++++++++++++++++++
vl.c | 11 ++
5 files changed, 380 insertions(+)
create mode 100644 ui/input-linux.c
diff --git a/include/ui/input.h b/include/ui/input.h
index d06a12d..102d8a3 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -65,4 +65,6 @@ void qemu_input_check_mode_change(void);
void qemu_add_mouse_mode_change_notifier(Notifier *notify);
void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
+int input_linux_init(void *opaque, QemuOpts *opts, Error **errp);
+
#endif /* INPUT_H */
diff --git a/qemu-options.hx b/qemu-options.hx
index 144e6a9..bda92d2 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1226,6 +1226,15 @@ STEXI
Set the initial graphical resolution and depth (PPC, SPARC only).
ETEXI
+DEF("input-linux", 1, QEMU_OPTION_input_linux,
+ "-input-linux <evdev>\n"
+ " Use input device.\n", QEMU_ARCH_ALL)
+STEXI
+@item -input-linux @var{dev}
+@findex -input-linux
+Use input device.
+ETEXI
+
DEF("vnc", HAS_ARG, QEMU_OPTION_vnc ,
"-vnc display start a VNC server on display\n", QEMU_ARCH_ALL)
STEXI
diff --git a/ui/Makefile.objs b/ui/Makefile.objs
index 728393c..dc936f1 100644
--- a/ui/Makefile.objs
+++ b/ui/Makefile.objs
@@ -9,6 +9,7 @@ vnc-obj-y += vnc-jobs.o
common-obj-y += keymaps.o console.o cursor.o qemu-pixman.o
common-obj-y += input.o input-keymap.o input-legacy.o
+common-obj-$(CONFIG_LINUX) += input-linux.o
common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o
common-obj-$(CONFIG_SDL) += sdl.mo x_keymap.o
common-obj-$(CONFIG_COCOA) += cocoa.o
diff --git a/ui/input-linux.c b/ui/input-linux.c
new file mode 100644
index 0000000..5374a2e
--- /dev/null
+++ b/ui/input-linux.c
@@ -0,0 +1,357 @@
+/*
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version. See the COPYING file in the
+ * top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "qemu/config-file.h"
+#include "qemu/sockets.h"
+#include "sysemu/sysemu.h"
+#include "ui/input.h"
+
+#include <sys/ioctl.h>
+#include "standard-headers/linux/input.h"
+
+static int linux_to_qcode[KEY_CNT] = {
+ [KEY_ESC] = Q_KEY_CODE_ESC,
+ [KEY_1] = Q_KEY_CODE_1,
+ [KEY_2] = Q_KEY_CODE_2,
+ [KEY_3] = Q_KEY_CODE_3,
+ [KEY_4] = Q_KEY_CODE_4,
+ [KEY_5] = Q_KEY_CODE_5,
+ [KEY_6] = Q_KEY_CODE_6,
+ [KEY_7] = Q_KEY_CODE_7,
+ [KEY_8] = Q_KEY_CODE_8,
+ [KEY_9] = Q_KEY_CODE_9,
+ [KEY_0] = Q_KEY_CODE_0,
+ [KEY_MINUS] = Q_KEY_CODE_MINUS,
+ [KEY_EQUAL] = Q_KEY_CODE_EQUAL,
+ [KEY_BACKSPACE] = Q_KEY_CODE_BACKSPACE,
+ [KEY_TAB] = Q_KEY_CODE_TAB,
+ [KEY_Q] = Q_KEY_CODE_Q,
+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_CODE_F11,
+ [KEY_F12] = Q_KEY_CODE_F12,
+ [KEY_RIGHTCTRL] = Q_KEY_CODE_CTRL_R,
+ [KEY_SYSRQ] = Q_KEY_CODE_SYSRQ,
+ [KEY_RIGHTALT] = Q_KEY_CODE_ALT_R,
+ [KEY_HOME] = Q_KEY_CODE_HOME,
+ [KEY_UP] = Q_KEY_CODE_UP,
+ [KEY_PAGEUP] = Q_KEY_CODE_PGUP,
+ [KEY_LEFT] = Q_KEY_CODE_LEFT,
+ [KEY_RIGHT] = Q_KEY_CODE_RIGHT,
+ [KEY_END] = Q_KEY_CODE_END,
+ [KEY_DOWN] = Q_KEY_CODE_DOWN,
+ [KEY_PAGEDOWN] = Q_KEY_CODE_PGDN,
+ [KEY_INSERT] = Q_KEY_CODE_INSERT,
+ [KEY_DELETE] = Q_KEY_CODE_DELETE,
+ [KEY_LEFTMETA] = Q_KEY_CODE_META_L,
+ [KEY_RIGHTMETA] = Q_KEY_CODE_META_R,
+ [KEY_MENU] = Q_KEY_CODE_MENU,
+};
+
+static int qemu_input_linux_to_qcode(unsigned int lnx)
+{
+ assert(lnx < KEY_CNT);
+ return linux_to_qcode[lnx];
+}
+
+typedef struct InputLinux InputLinux;
+
+struct InputLinux {
+ const char *evdev;
+ int fd;
+ bool grab_request;
+ bool grab_active;
+ bool keydown[KEY_CNT];
+ int keycount;
+ int wheel;
+};
+
+static void input_linux_toggle_grab(InputLinux *il)
+{
+ intptr_t request = !il->grab_active;
+ int rc;
+
+ rc = ioctl(il->fd, EVIOCGRAB, request);
+ if (rc < 0) {
+ return;
+ }
+ il->grab_active = !il->grab_active;
+}
+
+static void input_linux_event_keyboard(void *opaque)
+{
+ InputLinux *il = opaque;
+ struct input_event event;
+ int rc;
+
+ for (;;) {
+ rc = read(il->fd, &event, sizeof(event));
+ if (rc != sizeof(event)) {
+ if (rc < 0 && errno != EAGAIN) {
+ fprintf(stderr, "%s: read: %s\n", __func__, strerror(errno));
+ qemu_set_fd_handler(il->fd, NULL, NULL, NULL);
+ close(il->fd);
+ }
+ break;
+ }
+
+ switch (event.type) {
+ case EV_KEY:
+ if (event.value > 1) {
+ /*
+ * ignore autorepeat + unknown key events
+ * 0 == up, 1 == down, 2 == autorepeat, other == undefined
+ */
+ continue;
+ }
+ /* keep track of key state */
+ if (!il->keydown[event.code] && event.value) {
+ il->keydown[event.code] = true;
+ il->keycount++;
+ }
+ if (il->keydown[event.code] && !event.value) {
+ il->keydown[event.code] = false;
+ il->keycount--;
+ }
+
+ /* send event to guest when grab is active */
+ if (il->grab_active) {
+ int qcode = qemu_input_linux_to_qcode(event.code);
+ qemu_input_event_send_key_qcode(NULL, qcode, event.value);
+ }
+
+ /* hotkey -> record switch request ... */
+ if (il->keydown[KEY_LEFTCTRL] &&
+ il->keydown[KEY_RIGHTCTRL]) {
+ il->grab_request = true;
+ }
+
+ /*
+ * ... and do the switch when all keys are lifted, so we
+ * confuse neither guest nor host with keys which seem to
+ * be stuck due to missing key-up events.
+ */
+ if (il->grab_request && !il->keycount) {
+ il->grab_request = false;
+ input_linux_toggle_grab(il);
+ }
+ break;
+ }
+ }
+}
+
+static void input_linux_event_mouse_button(int button)
+{
+ qemu_input_queue_btn(NULL, button, true);
+ qemu_input_event_sync();
+ qemu_input_queue_btn(NULL, button, false);
+ qemu_input_event_sync();
+}
+
+static void input_linux_event_mouse(void *opaque)
+{
+ InputLinux *il = opaque;
+ struct input_event event;
+ int rc;
+
+ for (;;) {
+ rc = read(il->fd, &event, sizeof(event));
+ if (rc != sizeof(event)) {
+ if (rc < 0 && errno != EAGAIN) {
+ fprintf(stderr, "%s: read: %s\n", __func__, strerror(errno));
+ qemu_set_fd_handler(il->fd, NULL, NULL, NULL);
+ close(il->fd);
+ }
+ break;
+ }
+
+ switch (event.type) {
+ case EV_KEY:
+ switch (event.code) {
+ case BTN_LEFT:
+ qemu_input_queue_btn(NULL, INPUT_BUTTON_LEFT, event.value);
+ break;
+ case BTN_RIGHT:
+ qemu_input_queue_btn(NULL, INPUT_BUTTON_RIGHT, event.value);
+ break;
+ case BTN_MIDDLE:
+ qemu_input_queue_btn(NULL, INPUT_BUTTON_MIDDLE, event.value);
+ break;
+ case BTN_GEAR_UP:
+ qemu_input_queue_btn(NULL, INPUT_BUTTON_WHEEL_UP, event.value);
+ break;
+ case BTN_GEAR_DOWN:
+ qemu_input_queue_btn(NULL, INPUT_BUTTON_WHEEL_DOWN,
+ event.value);
+ break;
+ };
+ break;
+ case EV_REL:
+ switch (event.code) {
+ case REL_X:
+ qemu_input_queue_rel(NULL, INPUT_AXIS_X, event.value);
+ break;
+ case REL_Y:
+ qemu_input_queue_rel(NULL, INPUT_AXIS_Y, event.value);
+ break;
+ case REL_WHEEL:
+ il->wheel = event.value;
+ break;
+ }
+ break;
+ case EV_SYN:
+ qemu_input_event_sync();
+ if (il->wheel != 0) {
+ input_linux_event_mouse_button((il->wheel > 0)
+ ? INPUT_BUTTON_WHEEL_UP
+ : INPUT_BUTTON_WHEEL_DOWN);
+ il->wheel = 0;
+ }
+ break;
+ }
+ }
+}
+
+int input_linux_init(void *opaque, QemuOpts *opts, Error **errp)
+{
+ InputLinux *il = g_new0(InputLinux, 1);
+ uint32_t evtmap;
+ int rc, ver;
+
+ il->evdev = qemu_opt_get(opts, "evdev");
+ if (!il->evdev) {
+ error_setg(errp, "no input device specified");
+ goto err_free;
+ }
+
+ il->fd = open(il->evdev, O_RDWR);
+ if (il->fd < 0) {
+ error_setg_file_open(errp, errno, il->evdev);
+ goto err_free;
+ }
+ qemu_set_nonblock(il->fd);
+
+ rc = ioctl(il->fd, EVIOCGVERSION, &ver);
+ if (rc < 0) {
+ error_setg(errp, "%s: is not an evdev device", il->evdev);
+ goto err_close;
+ }
+
+ rc = ioctl(il->fd, EVIOCGBIT(0, sizeof(evtmap)), &evtmap);
+
+ if (evtmap & (1 << EV_REL)) {
+ /* has relative axis -> assume mouse */
+ qemu_set_fd_handler(il->fd, input_linux_event_mouse, NULL, il);
+ } else if (evtmap & (1 << EV_ABS)) {
+ /* has absolute axis -> not supported */
+ error_setg(errp, "tablet/touchscreen not supported");
+ goto err_close;
+ } else if (evtmap & (1 << EV_KEY)) {
+ /* has keys/buttons (and no axis) -> assume keyboard */
+ qemu_set_fd_handler(il->fd, input_linux_event_keyboard, NULL, il);
+ } else {
+ /* Huh? What is this? */
+ error_setg(errp, "unknown kind of input device");
+ goto err_close;
+ }
+ input_linux_toggle_grab(il);
+ return 0;
+
+err_close:
+ close(il->fd);
+err_free:
+ g_free(il);
+ return -1;
+}
+
+static QemuOptsList qemu_input_linux_opts = {
+ .name = "input-linux",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_input_linux_opts.head),
+ .implied_opt_name = "evdev",
+ .desc = {
+ {
+ .name = "evdev",
+ .type = QEMU_OPT_STRING,
+ },
+ { /* end of list */ }
+ },
+};
+
+static void input_linux_register_config(void)
+{
+ qemu_add_opts(&qemu_input_linux_opts);
+}
+machine_init(input_linux_register_config);
diff --git a/vl.c b/vl.c
index adeddd9..7a28982 100644
--- a/vl.c
+++ b/vl.c
@@ -72,6 +72,7 @@ int main(int argc, char **argv)
#include "net/slirp.h"
#include "monitor/monitor.h"
#include "ui/console.h"
+#include "ui/input.h"
#include "sysemu/sysemu.h"
#include "sysemu/numa.h"
#include "exec/gdbstub.h"
@@ -3728,6 +3729,12 @@ int main(int argc, char **argv, char **envp)
#endif
break;
}
+ case QEMU_OPTION_input_linux:
+ if (!qemu_opts_parse_noisily(qemu_find_opts("input-linux"),
+ optarg, true)) {
+ exit(1);
+ }
+ break;
case QEMU_OPTION_no_acpi:
acpi_enabled = 0;
break;
@@ -4591,6 +4598,10 @@ int main(int argc, char **argv, char **envp)
qemu_spice_display_init();
}
#endif
+#ifdef CONFIG_LINUX
+ qemu_opts_foreach(qemu_find_opts("input-linux"),
+ input_linux_init, NULL, &error_fatal);
+#endif
if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
exit(1);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PULL 3/5] input-linux: add option to toggle grab on all devices
2016-03-09 9:04 [Qemu-devel] [PULL 0/5] ui: add linux evdev support, vnc and console fixes Gerd Hoffmann
2016-03-09 9:04 ` [Qemu-devel] [PULL 1/5] vnc: send cursor when a new client is connecting Gerd Hoffmann
2016-03-09 9:04 ` [Qemu-devel] [PULL 2/5] input: linux evdev support Gerd Hoffmann
@ 2016-03-09 9:04 ` Gerd Hoffmann
2016-03-09 9:04 ` [Qemu-devel] [PULL 4/5] input-linux: add switch to enable auto-repeat events Gerd Hoffmann
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2016-03-09 9:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
Maintain a list of all input devices. Add an option to make grab
work across all devices (so toggling grab on the keybard can switch
over the mouse too).
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-id: 1457087116-4379-3-git-send-email-kraxel@redhat.com
---
ui/input-linux.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/ui/input-linux.c b/ui/input-linux.c
index 5374a2e..ad43963 100644
--- a/ui/input-linux.c
+++ b/ui/input-linux.c
@@ -134,14 +134,19 @@ struct InputLinux {
int fd;
bool grab_request;
bool grab_active;
+ bool grab_all;
bool keydown[KEY_CNT];
int keycount;
int wheel;
+ QTAILQ_ENTRY(InputLinux) next;
};
+static QTAILQ_HEAD(, InputLinux) inputs = QTAILQ_HEAD_INITIALIZER(inputs);
+
static void input_linux_toggle_grab(InputLinux *il)
{
intptr_t request = !il->grab_active;
+ InputLinux *item;
int rc;
rc = ioctl(il->fd, EVIOCGRAB, request);
@@ -149,6 +154,19 @@ static void input_linux_toggle_grab(InputLinux *il)
return;
}
il->grab_active = !il->grab_active;
+
+ if (!il->grab_all) {
+ return;
+ }
+ QTAILQ_FOREACH(item, &inputs, next) {
+ if (item == il || item->grab_all) {
+ /* avoid endless loops */
+ continue;
+ }
+ if (item->grab_active != il->grab_active) {
+ input_linux_toggle_grab(item);
+ }
+ }
}
static void input_linux_event_keyboard(void *opaque)
@@ -238,6 +256,11 @@ static void input_linux_event_mouse(void *opaque)
break;
}
+ /* only send event to guest when grab is active */
+ if (!il->grab_active) {
+ continue;
+ }
+
switch (event.type) {
case EV_KEY:
switch (event.code) {
@@ -292,6 +315,8 @@ int input_linux_init(void *opaque, QemuOpts *opts, Error **errp)
int rc, ver;
il->evdev = qemu_opt_get(opts, "evdev");
+ il->grab_all = qemu_opt_get_bool(opts, "grab-all", false);
+
if (!il->evdev) {
error_setg(errp, "no input device specified");
goto err_free;
@@ -328,6 +353,7 @@ int input_linux_init(void *opaque, QemuOpts *opts, Error **errp)
goto err_close;
}
input_linux_toggle_grab(il);
+ QTAILQ_INSERT_TAIL(&inputs, il, next);
return 0;
err_close:
@@ -345,6 +371,9 @@ static QemuOptsList qemu_input_linux_opts = {
{
.name = "evdev",
.type = QEMU_OPT_STRING,
+ },{
+ .name = "grab-all",
+ .type = QEMU_OPT_BOOL,
},
{ /* end of list */ }
},
--
1.8.3.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PULL 4/5] input-linux: add switch to enable auto-repeat events
2016-03-09 9:04 [Qemu-devel] [PULL 0/5] ui: add linux evdev support, vnc and console fixes Gerd Hoffmann
` (2 preceding siblings ...)
2016-03-09 9:04 ` [Qemu-devel] [PULL 3/5] input-linux: add option to toggle grab on all devices Gerd Hoffmann
@ 2016-03-09 9:04 ` Gerd Hoffmann
2016-03-09 9:04 ` [Qemu-devel] [PULL 5/5] ui/console: add escape sequence \e[5, 6n Gerd Hoffmann
2016-03-10 5:00 ` [Qemu-devel] [PULL 0/5] ui: add linux evdev support, vnc and console fixes Peter Maydell
5 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2016-03-09 9:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
Enable with "-input-linux /dev/input/${device},repeat=on".
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-id: 1457087116-4379-4-git-send-email-kraxel@redhat.com
---
ui/input-linux.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/ui/input-linux.c b/ui/input-linux.c
index ad43963..0bc0405 100644
--- a/ui/input-linux.c
+++ b/ui/input-linux.c
@@ -132,6 +132,7 @@ typedef struct InputLinux InputLinux;
struct InputLinux {
const char *evdev;
int fd;
+ bool repeat;
bool grab_request;
bool grab_active;
bool grab_all;
@@ -188,7 +189,7 @@ static void input_linux_event_keyboard(void *opaque)
switch (event.type) {
case EV_KEY:
- if (event.value > 1) {
+ if (event.value > 2 || (event.value > 1 && !il->repeat)) {
/*
* ignore autorepeat + unknown key events
* 0 == up, 1 == down, 2 == autorepeat, other == undefined
@@ -316,6 +317,7 @@ int input_linux_init(void *opaque, QemuOpts *opts, Error **errp)
il->evdev = qemu_opt_get(opts, "evdev");
il->grab_all = qemu_opt_get_bool(opts, "grab-all", false);
+ il->repeat = qemu_opt_get_bool(opts, "repeat", false);
if (!il->evdev) {
error_setg(errp, "no input device specified");
@@ -374,6 +376,9 @@ static QemuOptsList qemu_input_linux_opts = {
},{
.name = "grab-all",
.type = QEMU_OPT_BOOL,
+ },{
+ .name = "repeat",
+ .type = QEMU_OPT_BOOL,
},
{ /* end of list */ }
},
--
1.8.3.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PULL 5/5] ui/console: add escape sequence \e[5, 6n
2016-03-09 9:04 [Qemu-devel] [PULL 0/5] ui: add linux evdev support, vnc and console fixes Gerd Hoffmann
` (3 preceding siblings ...)
2016-03-09 9:04 ` [Qemu-devel] [PULL 4/5] input-linux: add switch to enable auto-repeat events Gerd Hoffmann
@ 2016-03-09 9:04 ` Gerd Hoffmann
2016-03-10 5:00 ` [Qemu-devel] [PULL 0/5] ui: add linux evdev support, vnc and console fixes Peter Maydell
5 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2016-03-09 9:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann, Ren Kimura
From: Ren Kimura <rkx1209dev@gmail.com>
Add support of escape sequence "\e[5n" and "\e[6n" to console.
"\e[5n" reports status of console and it always succeed
in virtual console.
"\e[6n" reports now cursor position in console.
Signed-off-by: Ren Kimura <rkx1209dev@gmail.com>
Message-id: 1457466681-7714-2-git-send-email-rkx1209dev@gmail.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
ui/console.c | 56 +++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 41 insertions(+), 15 deletions(-)
diff --git a/ui/console.c b/ui/console.c
index ae61382..8027ba7 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -757,6 +757,31 @@ static void console_clear_xy(QemuConsole *s, int x, int y)
update_xy(s, x, y);
}
+static void console_put_one(QemuConsole *s, int ch)
+{
+ TextCell *c;
+ int y1;
+ if (s->x >= s->width) {
+ /* line wrap */
+ s->x = 0;
+ console_put_lf(s);
+ }
+ y1 = (s->y_base + s->y) % s->total_height;
+ c = &s->cells[y1 * s->width + s->x];
+ c->ch = ch;
+ c->t_attrib = s->t_attrib;
+ update_xy(s, s->x, s->y);
+ s->x++;
+}
+
+static void console_respond_str(QemuConsole *s, const char *buf)
+{
+ while (*buf) {
+ console_put_one(s, *buf);
+ buf++;
+ }
+}
+
/* set cursor, checking bounds */
static void set_cursor(QemuConsole *s, int x, int y)
{
@@ -779,9 +804,9 @@ static void set_cursor(QemuConsole *s, int x, int y)
static void console_putchar(QemuConsole *s, int ch)
{
- TextCell *c;
- int y1, i;
+ int i;
int x, y;
+ char response[40];
switch(s->state) {
case TTY_STATE_NORM:
@@ -817,17 +842,7 @@ static void console_putchar(QemuConsole *s, int ch)
s->state = TTY_STATE_ESC;
break;
default:
- if (s->x >= s->width) {
- /* line wrap */
- s->x = 0;
- console_put_lf(s);
- }
- y1 = (s->y_base + s->y) % s->total_height;
- c = &s->cells[y1 * s->width + s->x];
- c->ch = ch;
- c->t_attrib = s->t_attrib;
- update_xy(s, s->x, s->y);
- s->x++;
+ console_put_one(s, ch);
break;
}
break;
@@ -956,8 +971,19 @@ static void console_putchar(QemuConsole *s, int ch)
console_handle_escape(s);
break;
case 'n':
- /* report cursor position */
- /* TODO: send ESC[row;colR */
+ switch (s->esc_params[0]) {
+ case 5:
+ /* report console status (always succeed)*/
+ console_respond_str(s, "\033[0n");
+ break;
+ case 6:
+ /* report cursor position */
+ sprintf(response, "\033[%d;%dR",
+ (s->y_base + s->y) % s->total_height + 1,
+ s->x + 1);
+ console_respond_str(s, response);
+ break;
+ }
break;
case 's':
/* save cursor position */
--
1.8.3.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PULL 0/5] ui: add linux evdev support, vnc and console fixes
2016-03-09 9:04 [Qemu-devel] [PULL 0/5] ui: add linux evdev support, vnc and console fixes Gerd Hoffmann
` (4 preceding siblings ...)
2016-03-09 9:04 ` [Qemu-devel] [PULL 5/5] ui/console: add escape sequence \e[5, 6n Gerd Hoffmann
@ 2016-03-10 5:00 ` Peter Maydell
5 siblings, 0 replies; 7+ messages in thread
From: Peter Maydell @ 2016-03-10 5:00 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: QEMU Developers
On 9 March 2016 at 16:04, Gerd Hoffmann <kraxel@redhat.com> wrote:
> Hi,
>
> Here is the ui patch queue, bringing support for linux input devices and
> two fixes for the console and vnc.
>
> please pull,
> Gerd
>
> The following changes since commit 1464ad45cd6cdeb0b5c1a54d3d3791396e47e52f:
>
> Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2016-03-04' into staging (2016-03-06 11:53:27 +0000)
>
> are available in the git repository at:
>
>
> git://git.kraxel.org/qemu tags/pull-ui-20160309-1
>
> for you to fetch changes up to 58aa7d8e443c7f79710a4f5757966f6c511f2242:
>
> ui/console: add escape sequence \e[5, 6n (2016-03-09 09:35:56 +0100)
>
> ----------------------------------------------------------------
> add linux evdev support, vnc and console fixes.
>
Applied, thanks.
-- PMM
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-03-10 5:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-09 9:04 [Qemu-devel] [PULL 0/5] ui: add linux evdev support, vnc and console fixes Gerd Hoffmann
2016-03-09 9:04 ` [Qemu-devel] [PULL 1/5] vnc: send cursor when a new client is connecting Gerd Hoffmann
2016-03-09 9:04 ` [Qemu-devel] [PULL 2/5] input: linux evdev support Gerd Hoffmann
2016-03-09 9:04 ` [Qemu-devel] [PULL 3/5] input-linux: add option to toggle grab on all devices Gerd Hoffmann
2016-03-09 9:04 ` [Qemu-devel] [PULL 4/5] input-linux: add switch to enable auto-repeat events Gerd Hoffmann
2016-03-09 9:04 ` [Qemu-devel] [PULL 5/5] ui/console: add escape sequence \e[5, 6n Gerd Hoffmann
2016-03-10 5:00 ` [Qemu-devel] [PULL 0/5] ui: add linux evdev support, vnc and console fixes Peter Maydell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).