2016-03-04 13:25:14 +03: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 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2016-03-04 13:25:14 +03:00
|
|
|
#include "qemu/config-file.h"
|
Include qemu/main-loop.h less
In my "build everything" tree, changing qemu/main-loop.h triggers a
recompile of some 5600 out of 6600 objects (not counting tests and
objects that don't depend on qemu/osdep.h). It includes block/aio.h,
which in turn includes qemu/event_notifier.h, qemu/notify.h,
qemu/processor.h, qemu/qsp.h, qemu/queue.h, qemu/thread-posix.h,
qemu/thread.h, qemu/timer.h, and a few more.
Include qemu/main-loop.h only where it's needed. Touching it now
recompiles only some 1700 objects. For block/aio.h and
qemu/event_notifier.h, these numbers drop from 5600 to 2800. For the
others, they shrink only slightly.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190812052359.30071-21-armbru@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
2019-08-12 08:23:50 +03:00
|
|
|
#include "qemu/main-loop.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2016-03-04 13:25:14 +03:00
|
|
|
#include "qemu/sockets.h"
|
|
|
|
#include "ui/input.h"
|
2016-03-11 10:38:20 +03:00
|
|
|
#include "qom/object_interfaces.h"
|
2019-01-24 00:45:55 +03:00
|
|
|
#include "sysemu/iothread.h"
|
|
|
|
#include "block/aio.h"
|
2016-03-04 13:25:14 +03:00
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include "standard-headers/linux/input.h"
|
|
|
|
|
2016-06-16 12:03:20 +03:00
|
|
|
static bool linux_is_button(unsigned int lnx)
|
|
|
|
{
|
|
|
|
if (lnx < 0x100) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (lnx >= 0x160 && lnx < 0x2c0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-11 10:38:20 +03: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 13:25:14 +03:00
|
|
|
typedef struct InputLinux InputLinux;
|
2016-03-11 10:38:20 +03:00
|
|
|
typedef struct InputLinuxClass InputLinuxClass;
|
2016-03-04 13:25:14 +03:00
|
|
|
|
|
|
|
struct InputLinux {
|
2016-03-11 10:38:20 +03:00
|
|
|
Object parent;
|
|
|
|
|
|
|
|
char *evdev;
|
2016-03-04 13:25:14 +03:00
|
|
|
int fd;
|
2016-03-04 13:25:16 +03:00
|
|
|
bool repeat;
|
2016-03-04 13:25:14 +03:00
|
|
|
bool grab_request;
|
|
|
|
bool grab_active;
|
2016-03-04 13:25:15 +03:00
|
|
|
bool grab_all;
|
2016-03-04 13:25:14 +03:00
|
|
|
bool keydown[KEY_CNT];
|
|
|
|
int keycount;
|
|
|
|
int wheel;
|
2016-03-11 10:38:20 +03:00
|
|
|
bool initialized;
|
2016-06-16 12:03:20 +03:00
|
|
|
|
|
|
|
bool has_rel_x;
|
|
|
|
bool has_abs_x;
|
|
|
|
int num_keys;
|
|
|
|
int num_btns;
|
2017-05-05 16:42:31 +03:00
|
|
|
int abs_x_min;
|
|
|
|
int abs_x_max;
|
|
|
|
int abs_y_min;
|
|
|
|
int abs_y_max;
|
2017-03-27 21:26:24 +03:00
|
|
|
struct input_event event;
|
|
|
|
int read_offset;
|
2016-06-16 12:03:20 +03:00
|
|
|
|
2019-01-24 00:45:55 +03:00
|
|
|
enum GrabToggleKeys grab_toggle;
|
|
|
|
|
2016-03-04 13:25:15 +03:00
|
|
|
QTAILQ_ENTRY(InputLinux) next;
|
2016-03-04 13:25:14 +03:00
|
|
|
};
|
|
|
|
|
2016-03-11 10:38:20 +03:00
|
|
|
struct InputLinuxClass {
|
|
|
|
ObjectClass parent_class;
|
|
|
|
};
|
|
|
|
|
2016-03-04 13:25:15 +03:00
|
|
|
static QTAILQ_HEAD(, InputLinux) inputs = QTAILQ_HEAD_INITIALIZER(inputs);
|
|
|
|
|
2016-03-04 13:25:14 +03:00
|
|
|
static void input_linux_toggle_grab(InputLinux *il)
|
|
|
|
{
|
|
|
|
intptr_t request = !il->grab_active;
|
2016-03-04 13:25:15 +03:00
|
|
|
InputLinux *item;
|
2016-03-04 13:25:14 +03:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = ioctl(il->fd, EVIOCGRAB, request);
|
|
|
|
if (rc < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
il->grab_active = !il->grab_active;
|
2016-03-04 13:25:15 +03: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 13:25:14 +03:00
|
|
|
}
|
|
|
|
|
2019-01-24 00:45:55 +03:00
|
|
|
static bool input_linux_check_toggle(InputLinux *il)
|
|
|
|
{
|
|
|
|
switch (il->grab_toggle) {
|
|
|
|
case GRAB_TOGGLE_KEYS_CTRL_CTRL:
|
|
|
|
return il->keydown[KEY_LEFTCTRL] &&
|
|
|
|
il->keydown[KEY_RIGHTCTRL];
|
|
|
|
|
|
|
|
case GRAB_TOGGLE_KEYS_ALT_ALT:
|
|
|
|
return il->keydown[KEY_LEFTALT] &&
|
|
|
|
il->keydown[KEY_RIGHTALT];
|
|
|
|
|
2019-08-18 13:50:38 +03:00
|
|
|
case GRAB_TOGGLE_KEYS_SHIFT_SHIFT:
|
|
|
|
return il->keydown[KEY_LEFTSHIFT] &&
|
|
|
|
il->keydown[KEY_RIGHTSHIFT];
|
|
|
|
|
2019-01-24 00:45:55 +03:00
|
|
|
case GRAB_TOGGLE_KEYS_META_META:
|
|
|
|
return il->keydown[KEY_LEFTMETA] &&
|
|
|
|
il->keydown[KEY_RIGHTMETA];
|
|
|
|
|
|
|
|
case GRAB_TOGGLE_KEYS_SCROLLLOCK:
|
|
|
|
return il->keydown[KEY_SCROLLLOCK];
|
|
|
|
|
|
|
|
case GRAB_TOGGLE_KEYS_CTRL_SCROLLLOCK:
|
|
|
|
return (il->keydown[KEY_LEFTCTRL] ||
|
|
|
|
il->keydown[KEY_RIGHTCTRL]) &&
|
|
|
|
il->keydown[KEY_SCROLLLOCK];
|
|
|
|
|
|
|
|
case GRAB_TOGGLE_KEYS__MAX:
|
|
|
|
/* avoid gcc error */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool input_linux_should_skip(InputLinux *il,
|
|
|
|
struct input_event *event)
|
|
|
|
{
|
|
|
|
return (il->grab_toggle == GRAB_TOGGLE_KEYS_SCROLLLOCK ||
|
|
|
|
il->grab_toggle == GRAB_TOGGLE_KEYS_CTRL_SCROLLLOCK) &&
|
|
|
|
event->code == KEY_SCROLLLOCK;
|
|
|
|
}
|
|
|
|
|
2016-06-16 12:03:19 +03:00
|
|
|
static void input_linux_handle_keyboard(InputLinux *il,
|
|
|
|
struct input_event *event)
|
|
|
|
{
|
|
|
|
if (event->type == EV_KEY) {
|
|
|
|
if (event->value > 2 || (event->value > 1 && !il->repeat)) {
|
|
|
|
/*
|
|
|
|
* ignore autorepeat + unknown key events
|
|
|
|
* 0 == up, 1 == down, 2 == autorepeat, other == undefined
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (event->code >= KEY_CNT) {
|
|
|
|
/*
|
|
|
|
* Should not happen. But better safe than sorry,
|
|
|
|
* and we make Coverity happy too.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 */
|
2019-01-24 00:45:55 +03:00
|
|
|
if (il->grab_active && !input_linux_should_skip(il, event)) {
|
2016-06-16 12:03:19 +03:00
|
|
|
int qcode = qemu_input_linux_to_qcode(event->code);
|
|
|
|
qemu_input_event_send_key_qcode(NULL, qcode, event->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hotkey -> record switch request ... */
|
2019-01-24 00:45:55 +03:00
|
|
|
if (input_linux_check_toggle(il)) {
|
2016-06-16 12:03:19 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-04 13:25:14 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-06-16 12:03:18 +03:00
|
|
|
static void input_linux_handle_mouse(InputLinux *il, struct input_event *event)
|
|
|
|
{
|
|
|
|
if (!il->grab_active) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2016-12-06 22:00:07 +03:00
|
|
|
case BTN_SIDE:
|
|
|
|
qemu_input_queue_btn(NULL, INPUT_BUTTON_SIDE, event->value);
|
|
|
|
break;
|
|
|
|
case BTN_EXTRA:
|
|
|
|
qemu_input_queue_btn(NULL, INPUT_BUTTON_EXTRA, event->value);
|
|
|
|
break;
|
2016-06-16 12:03:18 +03:00
|
|
|
};
|
|
|
|
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;
|
2017-05-05 16:42:31 +03:00
|
|
|
case EV_ABS:
|
|
|
|
switch (event->code) {
|
|
|
|
case ABS_X:
|
|
|
|
qemu_input_queue_abs(NULL, INPUT_AXIS_X, event->value,
|
|
|
|
il->abs_x_min, il->abs_x_max);
|
|
|
|
break;
|
|
|
|
case ABS_Y:
|
|
|
|
qemu_input_queue_abs(NULL, INPUT_AXIS_Y, event->value,
|
|
|
|
il->abs_y_min, il->abs_y_max);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2016-06-16 12:03:18 +03:00
|
|
|
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-06-16 12:03:20 +03:00
|
|
|
static void input_linux_event(void *opaque)
|
2016-03-04 13:25:14 +03:00
|
|
|
{
|
|
|
|
InputLinux *il = opaque;
|
|
|
|
int rc;
|
2017-03-27 21:26:24 +03:00
|
|
|
int read_size;
|
|
|
|
uint8_t *p = (uint8_t *)&il->event;
|
2016-03-04 13:25:14 +03:00
|
|
|
|
|
|
|
for (;;) {
|
2017-03-27 21:26:24 +03:00
|
|
|
read_size = sizeof(il->event) - il->read_offset;
|
|
|
|
rc = read(il->fd, &p[il->read_offset], read_size);
|
|
|
|
if (rc != read_size) {
|
2016-03-04 13:25:14 +03:00
|
|
|
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);
|
2017-03-27 21:26:24 +03:00
|
|
|
} else if (rc > 0) {
|
|
|
|
il->read_offset += rc;
|
2016-03-04 13:25:14 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-03-27 21:26:24 +03:00
|
|
|
il->read_offset = 0;
|
2016-03-04 13:25:14 +03:00
|
|
|
|
2016-06-16 12:03:20 +03:00
|
|
|
if (il->num_keys) {
|
2017-03-27 21:26:24 +03:00
|
|
|
input_linux_handle_keyboard(il, &il->event);
|
2016-06-16 12:03:20 +03:00
|
|
|
}
|
2017-05-05 16:42:31 +03:00
|
|
|
if ((il->has_rel_x || il->has_abs_x) && il->num_btns) {
|
2017-03-27 21:26:24 +03:00
|
|
|
input_linux_handle_mouse(il, &il->event);
|
2016-06-16 12:03:20 +03:00
|
|
|
}
|
2016-03-04 13:25:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-11 10:38:20 +03:00
|
|
|
static void input_linux_complete(UserCreatable *uc, Error **errp)
|
2016-03-04 13:25:14 +03:00
|
|
|
{
|
2016-03-11 10:38:20 +03:00
|
|
|
InputLinux *il = INPUT_LINUX(uc);
|
2016-10-12 16:03:04 +03:00
|
|
|
uint8_t evtmap, relmap, absmap;
|
|
|
|
uint8_t keymap[KEY_CNT / 8], keystate[KEY_CNT / 8];
|
2016-06-16 12:03:20 +03:00
|
|
|
unsigned int i;
|
2016-03-04 13:25:14 +03:00
|
|
|
int rc, ver;
|
2017-05-05 16:42:31 +03:00
|
|
|
struct input_absinfo absinfo;
|
2016-03-04 13:25:14 +03:00
|
|
|
|
|
|
|
if (!il->evdev) {
|
|
|
|
error_setg(errp, "no input device specified");
|
2016-03-11 10:38:20 +03:00
|
|
|
return;
|
2016-03-04 13:25:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
il->fd = open(il->evdev, O_RDWR);
|
|
|
|
if (il->fd < 0) {
|
|
|
|
error_setg_file_open(errp, errno, il->evdev);
|
2016-03-11 10:38:20 +03:00
|
|
|
return;
|
2016-03-04 13:25:14 +03: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 12:21:43 +03:00
|
|
|
if (rc < 0) {
|
ui/input-linux: Do not ignore ioctl() return value
Fix warnings reported by Clang static code analyzer:
CC ui/input-linux.o
ui/input-linux.c:343:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:351:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:354:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_X), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:357:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_Y), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:365:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_KEY, sizeof(keymap)), keymap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:366:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGKEY(sizeof(keystate)), keystate);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Message-id: 20200322161219.17757-1-philmd@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2020-03-22 19:12:19 +03:00
|
|
|
goto err_read_event_bits;
|
2016-04-12 12:21:43 +03:00
|
|
|
}
|
2016-03-04 13:25:14 +03:00
|
|
|
|
|
|
|
if (evtmap & (1 << EV_REL)) {
|
2016-06-16 12:03:20 +03:00
|
|
|
relmap = 0;
|
2016-04-12 12:21:43 +03:00
|
|
|
rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap);
|
ui/input-linux: Do not ignore ioctl() return value
Fix warnings reported by Clang static code analyzer:
CC ui/input-linux.o
ui/input-linux.c:343:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:351:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:354:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_X), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:357:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_Y), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:365:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_KEY, sizeof(keymap)), keymap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:366:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGKEY(sizeof(keystate)), keystate);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Message-id: 20200322161219.17757-1-philmd@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2020-03-22 19:12:19 +03:00
|
|
|
if (rc < 0) {
|
|
|
|
goto err_read_event_bits;
|
|
|
|
}
|
2016-06-16 12:03:20 +03:00
|
|
|
if (relmap & (1 << REL_X)) {
|
|
|
|
il->has_rel_x = true;
|
2016-04-12 12:21:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (evtmap & (1 << EV_ABS)) {
|
2016-06-16 12:03:20 +03:00
|
|
|
absmap = 0;
|
|
|
|
rc = ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap);
|
ui/input-linux: Do not ignore ioctl() return value
Fix warnings reported by Clang static code analyzer:
CC ui/input-linux.o
ui/input-linux.c:343:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:351:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:354:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_X), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:357:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_Y), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:365:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_KEY, sizeof(keymap)), keymap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:366:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGKEY(sizeof(keystate)), keystate);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Message-id: 20200322161219.17757-1-philmd@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2020-03-22 19:12:19 +03:00
|
|
|
if (rc < 0) {
|
|
|
|
goto err_read_event_bits;
|
|
|
|
}
|
2016-06-16 12:03:20 +03:00
|
|
|
if (absmap & (1 << ABS_X)) {
|
|
|
|
il->has_abs_x = true;
|
2017-05-05 16:42:31 +03:00
|
|
|
rc = ioctl(il->fd, EVIOCGABS(ABS_X), &absinfo);
|
ui/input-linux: Do not ignore ioctl() return value
Fix warnings reported by Clang static code analyzer:
CC ui/input-linux.o
ui/input-linux.c:343:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:351:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:354:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_X), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:357:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_Y), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:365:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_KEY, sizeof(keymap)), keymap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:366:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGKEY(sizeof(keystate)), keystate);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Message-id: 20200322161219.17757-1-philmd@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2020-03-22 19:12:19 +03:00
|
|
|
if (rc < 0) {
|
|
|
|
error_setg(errp, "%s: failed to get get absolute X value",
|
|
|
|
il->evdev);
|
|
|
|
goto err_close;
|
|
|
|
}
|
2017-05-05 16:42:31 +03:00
|
|
|
il->abs_x_min = absinfo.minimum;
|
|
|
|
il->abs_x_max = absinfo.maximum;
|
|
|
|
rc = ioctl(il->fd, EVIOCGABS(ABS_Y), &absinfo);
|
ui/input-linux: Do not ignore ioctl() return value
Fix warnings reported by Clang static code analyzer:
CC ui/input-linux.o
ui/input-linux.c:343:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:351:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:354:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_X), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:357:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_Y), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:365:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_KEY, sizeof(keymap)), keymap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:366:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGKEY(sizeof(keystate)), keystate);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Message-id: 20200322161219.17757-1-philmd@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2020-03-22 19:12:19 +03:00
|
|
|
if (rc < 0) {
|
|
|
|
error_setg(errp, "%s: failed to get get absolute Y value",
|
|
|
|
il->evdev);
|
|
|
|
goto err_close;
|
|
|
|
}
|
2017-05-05 16:42:31 +03:00
|
|
|
il->abs_y_min = absinfo.minimum;
|
|
|
|
il->abs_y_max = absinfo.maximum;
|
2016-04-12 12:21:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-16 12:03:20 +03:00
|
|
|
if (evtmap & (1 << EV_KEY)) {
|
|
|
|
memset(keymap, 0, sizeof(keymap));
|
|
|
|
rc = ioctl(il->fd, EVIOCGBIT(EV_KEY, sizeof(keymap)), keymap);
|
ui/input-linux: Do not ignore ioctl() return value
Fix warnings reported by Clang static code analyzer:
CC ui/input-linux.o
ui/input-linux.c:343:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:351:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:354:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_X), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:357:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_Y), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:365:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_KEY, sizeof(keymap)), keymap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:366:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGKEY(sizeof(keystate)), keystate);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Message-id: 20200322161219.17757-1-philmd@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2020-03-22 19:12:19 +03:00
|
|
|
if (rc < 0) {
|
|
|
|
goto err_read_event_bits;
|
|
|
|
}
|
2016-10-12 16:03:04 +03:00
|
|
|
rc = ioctl(il->fd, EVIOCGKEY(sizeof(keystate)), keystate);
|
ui/input-linux: Do not ignore ioctl() return value
Fix warnings reported by Clang static code analyzer:
CC ui/input-linux.o
ui/input-linux.c:343:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:351:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:354:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_X), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:357:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_Y), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:365:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_KEY, sizeof(keymap)), keymap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:366:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGKEY(sizeof(keystate)), keystate);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Message-id: 20200322161219.17757-1-philmd@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2020-03-22 19:12:19 +03:00
|
|
|
if (rc < 0) {
|
|
|
|
error_setg(errp, "%s: failed to get global key state", il->evdev);
|
|
|
|
goto err_close;
|
|
|
|
}
|
2016-06-16 12:03:20 +03:00
|
|
|
for (i = 0; i < KEY_CNT; i++) {
|
|
|
|
if (keymap[i / 8] & (1 << (i % 8))) {
|
|
|
|
if (linux_is_button(i)) {
|
|
|
|
il->num_btns++;
|
|
|
|
} else {
|
|
|
|
il->num_keys++;
|
|
|
|
}
|
2016-10-12 16:03:04 +03:00
|
|
|
if (keystate[i / 8] & (1 << (i % 8))) {
|
|
|
|
il->keydown[i] = true;
|
|
|
|
il->keycount++;
|
|
|
|
}
|
2016-06-16 12:03:20 +03:00
|
|
|
}
|
|
|
|
}
|
2016-03-04 13:25:14 +03:00
|
|
|
}
|
2016-06-16 12:03:20 +03:00
|
|
|
|
|
|
|
qemu_set_fd_handler(il->fd, input_linux_event, NULL, il);
|
2016-10-12 16:03:04 +03:00
|
|
|
if (il->keycount) {
|
|
|
|
/* delay grab until all keys are released */
|
|
|
|
il->grab_request = true;
|
|
|
|
} else {
|
|
|
|
input_linux_toggle_grab(il);
|
|
|
|
}
|
2016-03-04 13:25:15 +03:00
|
|
|
QTAILQ_INSERT_TAIL(&inputs, il, next);
|
2016-03-11 10:38:20 +03:00
|
|
|
il->initialized = true;
|
|
|
|
return;
|
2016-03-04 13:25:14 +03:00
|
|
|
|
ui/input-linux: Do not ignore ioctl() return value
Fix warnings reported by Clang static code analyzer:
CC ui/input-linux.o
ui/input-linux.c:343:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_REL, sizeof(relmap)), &relmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:351:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_ABS, sizeof(absmap)), &absmap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:354:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_X), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:357:13: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGABS(ABS_Y), &absinfo);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:365:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGBIT(EV_KEY, sizeof(keymap)), keymap);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui/input-linux.c:366:9: warning: Value stored to 'rc' is never read
rc = ioctl(il->fd, EVIOCGKEY(sizeof(keystate)), keystate);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Message-id: 20200322161219.17757-1-philmd@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2020-03-22 19:12:19 +03:00
|
|
|
err_read_event_bits:
|
|
|
|
error_setg(errp, "%s: failed to read event bits", il->evdev);
|
|
|
|
|
2016-03-04 13:25:14 +03:00
|
|
|
err_close:
|
|
|
|
close(il->fd);
|
2016-03-11 10:38:20 +03: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 13:25:14 +03:00
|
|
|
}
|
|
|
|
|
2016-03-11 10:38:20 +03: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;
|
|
|
|
}
|
|
|
|
|
2019-01-24 00:45:55 +03:00
|
|
|
static int input_linux_get_grab_toggle(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
InputLinux *il = INPUT_LINUX(obj);
|
|
|
|
|
|
|
|
return il->grab_toggle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void input_linux_set_grab_toggle(Object *obj, int value,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
InputLinux *il = INPUT_LINUX(obj);
|
|
|
|
|
|
|
|
il->grab_toggle = value;
|
|
|
|
}
|
|
|
|
|
2016-03-11 10:38:20 +03:00
|
|
|
static void input_linux_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
object_property_add_str(obj, "evdev",
|
|
|
|
input_linux_get_evdev,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
input_linux_set_evdev);
|
2016-03-11 10:38:20 +03:00
|
|
|
object_property_add_bool(obj, "grab_all",
|
|
|
|
input_linux_get_grab_all,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
input_linux_set_grab_all);
|
2016-03-11 10:38:20 +03:00
|
|
|
object_property_add_bool(obj, "repeat",
|
|
|
|
input_linux_get_repeat,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
input_linux_set_repeat);
|
2019-01-24 00:45:55 +03:00
|
|
|
object_property_add_enum(obj, "grab-toggle", "GrabToggleKeys",
|
|
|
|
&GrabToggleKeys_lookup,
|
|
|
|
input_linux_get_grab_toggle,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
input_linux_set_grab_toggle);
|
2016-03-11 10:38:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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 13:25:14 +03:00
|
|
|
};
|
|
|
|
|
2016-03-11 10:38:20 +03:00
|
|
|
static void register_types(void)
|
2016-03-04 13:25:14 +03:00
|
|
|
{
|
2016-03-11 10:38:20 +03:00
|
|
|
type_register_static(&input_linux_info);
|
2016-03-04 13:25:14 +03:00
|
|
|
}
|
2016-03-11 10:38:20 +03:00
|
|
|
|
|
|
|
type_init(register_types);
|