2016-03-04 11:25:14 +01:00
|
|
|
/*
|
|
|
|
* 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/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2016-03-04 11:25:14 +01:00
|
|
|
#include "qemu-common.h"
|
|
|
|
#include "qemu/config-file.h"
|
|
|
|
#include "qemu/sockets.h"
|
|
|
|
#include "sysemu/sysemu.h"
|
|
|
|
#include "ui/input.h"
|
2016-03-11 08:38:20 +01:00
|
|
|
#include "qom/object_interfaces.h"
|
2016-03-04 11:25:14 +01:00
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include "standard-headers/linux/input.h"
|
|
|
|
|
|
|
|
static int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RL] = 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];
|
|
|
|
}
|
|
|
|
|
2016-03-11 08:38:20 +01:00
|
|
|
#define TYPE_INPUT_LINUX "input-linux"
|
|
|
|
#define INPUT_LINUX(obj) \
|
|
|
|
OBJECT_CHECK(InputLinux, (obj), TYPE_INPUT_LINUX)
|
|
|
|
#define INPUT_LINUX_GET_CLASS(obj) \
|
|
|
|
OBJECT_GET_CLASS(InputLinuxClass, (obj), TYPE_INPUT_LINUX)
|
|
|
|
#define INPUT_LINUX_CLASS(klass) \
|
|
|
|
OBJECT_CLASS_CHECK(InputLinuxClass, (klass), TYPE_INPUT_LINUX)
|
|
|
|
|
2016-03-04 11:25:14 +01:00
|
|
|
typedef struct InputLinux InputLinux;
|
2016-03-11 08:38:20 +01:00
|
|
|
typedef struct InputLinuxClass InputLinuxClass;
|
2016-03-04 11:25:14 +01:00
|
|
|
|
|
|
|
struct InputLinux {
|
2016-03-11 08:38:20 +01:00
|
|
|
Object parent;
|
|
|
|
|
|
|
|
char *evdev;
|
2016-03-04 11:25:14 +01:00
|
|
|
int fd;
|
2016-03-04 11:25:16 +01:00
|
|
|
bool repeat;
|
2016-03-04 11:25:14 +01:00
|
|
|
bool grab_request;
|
|
|
|
bool grab_active;
|
2016-03-04 11:25:15 +01:00
|
|
|
bool grab_all;
|
2016-03-04 11:25:14 +01:00
|
|
|
bool keydown[KEY_CNT];
|
|
|
|
int keycount;
|
|
|
|
int wheel;
|
2016-03-11 08:38:20 +01:00
|
|
|
bool initialized;
|
2016-03-04 11:25:15 +01:00
|
|
|
QTAILQ_ENTRY(InputLinux) next;
|
2016-03-04 11:25:14 +01:00
|
|
|
};
|
|
|
|
|
2016-03-11 08:38:20 +01:00
|
|
|
struct InputLinuxClass {
|
|
|
|
ObjectClass parent_class;
|
|
|
|
};
|
|
|
|
|
2016-03-04 11:25:15 +01:00
|
|
|
static QTAILQ_HEAD(, InputLinux) inputs = QTAILQ_HEAD_INITIALIZER(inputs);
|
|
|
|
|
2016-03-04 11:25:14 +01:00
|
|
|
static void input_linux_toggle_grab(InputLinux *il)
|
|
|
|
{
|
|
|
|
intptr_t request = !il->grab_active;
|
2016-03-04 11:25:15 +01:00
|
|
|
InputLinux *item;
|
2016-03-04 11:25:14 +01:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = ioctl(il->fd, EVIOCGRAB, request);
|
|
|
|
if (rc < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
il->grab_active = !il->grab_active;
|
2016-03-04 11:25:15 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2016-03-04 11:25:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2016-03-04 11:25:16 +01:00
|
|
|
if (event.value > 2 || (event.value > 1 && !il->repeat)) {
|
2016-03-04 11:25:14 +01:00
|
|
|
/*
|
|
|
|
* ignore autorepeat + unknown key events
|
|
|
|
* 0 == up, 1 == down, 2 == autorepeat, other == undefined
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-16 12:50:49 +01:00
|
|
|
if (event.code >= KEY_CNT) {
|
|
|
|
/*
|
|
|
|
* Should not happen. But better safe than sorry,
|
|
|
|
* and we make Coverity happy too.
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-04 11:25:14 +01:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2016-03-04 11:25:15 +01:00
|
|
|
/* only send event to guest when grab is active */
|
|
|
|
if (!il->grab_active) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-03-04 11:25:14 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-11 08:38:20 +01:00
|
|
|
static void input_linux_complete(UserCreatable *uc, Error **errp)
|
2016-03-04 11:25:14 +01:00
|
|
|
{
|
2016-03-11 08:38:20 +01:00
|
|
|
InputLinux *il = INPUT_LINUX(uc);
|
2016-04-12 11:21:43 +02:00
|
|
|
uint32_t evtmap, relmap, absmap;
|
2016-03-04 11:25:14 +01:00
|
|
|
int rc, ver;
|
|
|
|
|
|
|
|
if (!il->evdev) {
|
|
|
|
error_setg(errp, "no input device specified");
|
2016-03-11 08:38:20 +01:00
|
|
|
return;
|
2016-03-04 11:25:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
il->fd = open(il->evdev, O_RDWR);
|
|
|
|
if (il->fd < 0) {
|
|
|
|
error_setg_file_open(errp, errno, il->evdev);
|
2016-03-11 08:38:20 +01:00
|
|
|
return;
|
2016-03-04 11:25:14 +01:00
|
|
|
}
|
|
|
|
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);
|
2016-04-12 11:21:43 +02:00
|
|
|
if (rc < 0) {
|
|
|
|
error_setg(errp, "%s: failed to read event bits", il->evdev);
|
|
|
|
goto err_close;
|
|
|
|
}
|
2016-03-04 11:25:14 +01:00
|
|
|
|
|
|
|
if (evtmap & (1 << EV_REL)) {
|
2016-04-12 11:21:43 +02:00
|
|
|
rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap);
|
|
|
|
if (rc < 0) {
|
|
|
|
relmap = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (evtmap & (1 << EV_ABS)) {
|
|
|
|
ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap);
|
|
|
|
if (rc < 0) {
|
|
|
|
absmap = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((evtmap & (1 << EV_REL)) &&
|
|
|
|
(relmap & (1 << REL_X))) {
|
|
|
|
/* has relative x axis -> assume mouse */
|
2016-03-04 11:25:14 +01:00
|
|
|
qemu_set_fd_handler(il->fd, input_linux_event_mouse, NULL, il);
|
2016-04-12 11:21:43 +02:00
|
|
|
} else if ((evtmap & (1 << EV_ABS)) &&
|
|
|
|
(absmap & (1 << ABS_X))) {
|
|
|
|
/* has absolute x axis -> not supported */
|
2016-03-04 11:25:14 +01:00
|
|
|
error_setg(errp, "tablet/touchscreen not supported");
|
|
|
|
goto err_close;
|
|
|
|
} else if (evtmap & (1 << EV_KEY)) {
|
2016-04-12 11:21:43 +02:00
|
|
|
/* has keys/buttons (and no x axis) -> assume keyboard */
|
2016-03-04 11:25:14 +01:00
|
|
|
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);
|
2016-03-04 11:25:15 +01:00
|
|
|
QTAILQ_INSERT_TAIL(&inputs, il, next);
|
2016-03-11 08:38:20 +01:00
|
|
|
il->initialized = true;
|
|
|
|
return;
|
2016-03-04 11:25:14 +01:00
|
|
|
|
|
|
|
err_close:
|
|
|
|
close(il->fd);
|
2016-03-11 08:38:20 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void input_linux_instance_finalize(Object *obj)
|
|
|
|
{
|
|
|
|
InputLinux *il = INPUT_LINUX(obj);
|
|
|
|
|
|
|
|
if (il->initialized) {
|
|
|
|
QTAILQ_REMOVE(&inputs, il, next);
|
|
|
|
close(il->fd);
|
|
|
|
}
|
|
|
|
g_free(il->evdev);
|
2016-03-04 11:25:14 +01:00
|
|
|
}
|
|
|
|
|
2016-03-11 08:38:20 +01:00
|
|
|
static char *input_linux_get_evdev(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
InputLinux *il = INPUT_LINUX(obj);
|
|
|
|
|
|
|
|
return g_strdup(il->evdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void input_linux_set_evdev(Object *obj, const char *value,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
InputLinux *il = INPUT_LINUX(obj);
|
|
|
|
|
|
|
|
if (il->evdev) {
|
|
|
|
error_setg(errp, "evdev property already set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
il->evdev = g_strdup(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool input_linux_get_grab_all(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
InputLinux *il = INPUT_LINUX(obj);
|
|
|
|
|
|
|
|
return il->grab_all;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void input_linux_set_grab_all(Object *obj, bool value,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
InputLinux *il = INPUT_LINUX(obj);
|
|
|
|
|
|
|
|
il->grab_all = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool input_linux_get_repeat(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
InputLinux *il = INPUT_LINUX(obj);
|
|
|
|
|
|
|
|
return il->repeat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void input_linux_set_repeat(Object *obj, bool value,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
InputLinux *il = INPUT_LINUX(obj);
|
|
|
|
|
|
|
|
il->repeat = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void input_linux_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
object_property_add_str(obj, "evdev",
|
|
|
|
input_linux_get_evdev,
|
|
|
|
input_linux_set_evdev, NULL);
|
|
|
|
object_property_add_bool(obj, "grab_all",
|
|
|
|
input_linux_get_grab_all,
|
|
|
|
input_linux_set_grab_all, NULL);
|
|
|
|
object_property_add_bool(obj, "repeat",
|
|
|
|
input_linux_get_repeat,
|
|
|
|
input_linux_set_repeat, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void input_linux_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
|
|
|
|
|
|
|
|
ucc->complete = input_linux_complete;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo input_linux_info = {
|
|
|
|
.name = TYPE_INPUT_LINUX,
|
|
|
|
.parent = TYPE_OBJECT,
|
|
|
|
.class_size = sizeof(InputLinuxClass),
|
|
|
|
.class_init = input_linux_class_init,
|
|
|
|
.instance_size = sizeof(InputLinux),
|
|
|
|
.instance_init = input_linux_instance_init,
|
|
|
|
.instance_finalize = input_linux_instance_finalize,
|
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_USER_CREATABLE },
|
|
|
|
{ }
|
|
|
|
}
|
2016-03-04 11:25:14 +01:00
|
|
|
};
|
|
|
|
|
2016-03-11 08:38:20 +01:00
|
|
|
static void register_types(void)
|
2016-03-04 11:25:14 +01:00
|
|
|
{
|
2016-03-11 08:38:20 +01:00
|
|
|
type_register_static(&input_linux_info);
|
2016-03-04 11:25:14 +01:00
|
|
|
}
|
2016-03-11 08:38:20 +01:00
|
|
|
|
|
|
|
type_init(register_types);
|