mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-26 06:10:56 +00:00
[input] Add a per-device event data pointer
This might pose a problem with multiple event targets (we'll see), but it will make connecting input devices to bindings much easier.
This commit is contained in:
parent
f5ccf46ae3
commit
b95c749438
7 changed files with 107 additions and 3 deletions
|
@ -60,6 +60,9 @@ typedef struct in_driver_s {
|
|||
void (*init) (void *data);
|
||||
void (*shutdown) (void *data);
|
||||
|
||||
void (*set_device_event_data) (void *device, void *event_data, void *data);
|
||||
void *(*get_device_event_data) (void *device, void *data);
|
||||
|
||||
// The driver must provide either both or none of add_select and
|
||||
// chec_select.
|
||||
void (*add_select) (struct qf_fd_set *fdset, int *maxfd, void *data);
|
||||
|
@ -81,6 +84,7 @@ typedef struct in_device_s {
|
|||
void *device;
|
||||
const char *name;
|
||||
const char *id;
|
||||
void *event_data;
|
||||
} in_device_t;
|
||||
|
||||
/*** Connect a device and its axes and buttons to logical axes and buttons.
|
||||
|
@ -139,6 +143,8 @@ void IN_RemoveDevice (int devid);
|
|||
void IN_SendConnectedDevices (void);
|
||||
const char *IN_GetDeviceName (int devid) __attribute__((pure));
|
||||
const char *IN_GetDeviceId (int devid) __attribute__((pure));
|
||||
void IN_SetDeviceEventData (int devid, void *data);
|
||||
void *IN_GetDeviceEventData (int devid);
|
||||
int IN_AxisInfo (int devid, in_axisinfo_t *axes, int *numaxes);
|
||||
int IN_ButtonInfo (int devid, in_buttoninfo_t *button, int *numbuttons);
|
||||
|
||||
|
|
|
@ -63,12 +63,14 @@ typedef struct {
|
|||
} IE_key_event_t;
|
||||
|
||||
typedef struct {
|
||||
void *data;
|
||||
int devid;
|
||||
int axis;
|
||||
int value;
|
||||
} IE_axis_event_t;
|
||||
|
||||
typedef struct {
|
||||
void *data;
|
||||
int devid;
|
||||
int button;
|
||||
int state;
|
||||
|
|
|
@ -204,6 +204,34 @@ IN_GetDeviceId (int devid)
|
|||
return in_devices.a[devid].id;
|
||||
}
|
||||
|
||||
void
|
||||
IN_SetDeviceEventData (int devid, void *data)
|
||||
{
|
||||
if ((size_t) devid >= in_devices.size) {
|
||||
return;
|
||||
}
|
||||
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
||||
return;
|
||||
}
|
||||
in_regdriver_t *rd = &in_drivers.a[in_devices.a[devid].driverid];
|
||||
rd->driver.set_device_event_data (in_devices.a[devid].device, data,
|
||||
rd->data);
|
||||
}
|
||||
|
||||
void *
|
||||
IN_GetDeviceEventData (int devid)
|
||||
{
|
||||
if ((size_t) devid >= in_devices.size) {
|
||||
return 0;
|
||||
}
|
||||
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
||||
return 0;
|
||||
}
|
||||
in_regdriver_t *rd = &in_drivers.a[in_devices.a[devid].driverid];
|
||||
return rd->driver.get_device_event_data (in_devices.a[devid].device,
|
||||
rd->data);
|
||||
}
|
||||
|
||||
int
|
||||
IN_AxisInfo (int devid, in_axisinfo_t *axes, int *numaxes)
|
||||
{
|
||||
|
|
|
@ -51,6 +51,7 @@ typedef struct devmap_s {
|
|||
struct devmap_s *next;
|
||||
struct devmap_s **prev;
|
||||
device_t *device;
|
||||
void *event_data;
|
||||
int devid;
|
||||
} devmap_t;
|
||||
|
||||
|
@ -76,6 +77,22 @@ in_evdev_shutdown (void *data)
|
|||
inputlib_close ();
|
||||
}
|
||||
|
||||
static void
|
||||
in_evdev_set_device_event_data (void *device, void *event_data, void *data)
|
||||
{
|
||||
device_t *dev = device;
|
||||
devmap_t *dm = dev->data;
|
||||
dm->event_data = event_data;
|
||||
}
|
||||
|
||||
static void *
|
||||
in_evdev_get_device_event_data (void *device, void *data)
|
||||
{
|
||||
device_t *dev = device;
|
||||
devmap_t *dm = dev->data;
|
||||
return dm->event_data;
|
||||
}
|
||||
|
||||
static void
|
||||
in_evdev_axis_event (axis_t *axis, void *_dm)
|
||||
{
|
||||
|
@ -86,6 +103,7 @@ in_evdev_axis_event (axis_t *axis, void *_dm)
|
|||
.type = ie_axis,
|
||||
.when = Sys_LongTime (),
|
||||
.axis = {
|
||||
.data = dm->event_data,
|
||||
.devid = dm->devid,
|
||||
.axis = axis->num,
|
||||
.value = axis->value,
|
||||
|
@ -104,6 +122,7 @@ in_evdev_button_event (button_t *button, void *_dm)
|
|||
.type = ie_button,
|
||||
.when = Sys_LongTime (),
|
||||
.button = {
|
||||
.data = dm->event_data,
|
||||
.devid = dm->devid,
|
||||
.button = button->num,
|
||||
.state = button->state,
|
||||
|
@ -223,6 +242,8 @@ in_evdev_button_info (void *data, void *device, in_buttoninfo_t *buttons,
|
|||
static in_driver_t in_evdev_driver = {
|
||||
.init = in_evdev_init,
|
||||
.shutdown = in_evdev_shutdown,
|
||||
.set_device_event_data = in_evdev_set_device_event_data,
|
||||
.get_device_event_data = in_evdev_get_device_event_data,
|
||||
.add_select = in_evdev_add_select,
|
||||
.check_select = in_evdev_check_select,
|
||||
.clear_states = in_evdev_clear_states,
|
||||
|
|
|
@ -390,6 +390,17 @@ in_win_shutdown (void *data)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
in_win_set_device_event_data (void *device, void *event_data, void *data)
|
||||
{
|
||||
}
|
||||
|
||||
static void *
|
||||
in_win_get_device_event_data (void *device, void *data)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
IN_MouseEvent (unsigned mstate)
|
||||
{
|
||||
|
@ -875,6 +886,8 @@ MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
static in_driver_t in_win_driver = {
|
||||
.init = in_win_init,
|
||||
.shutdown = in_win_shutdown,
|
||||
.set_device_event_data = in_win_set_device_event_data,
|
||||
.get_device_event_data = in_win_get_device_event_data,
|
||||
.process_events = in_win_process_events,
|
||||
.clear_states = in_win_clear_states,
|
||||
//.grab_input = in_win_grab_input,
|
||||
|
|
|
@ -87,6 +87,7 @@ typedef struct x11_device_s {
|
|||
int num_buttons;
|
||||
in_axisinfo_t *axes;
|
||||
in_buttoninfo_t *buttons;
|
||||
void *event_data;
|
||||
int devid;
|
||||
} x11_device_t;
|
||||
|
||||
|
@ -645,6 +646,7 @@ in_x11_send_axis_event (int devid, in_axisinfo_t *axis)
|
|||
.type = ie_axis,
|
||||
.when = Sys_LongTime (),
|
||||
.axis = {
|
||||
.data = x11_mouse_device.event_data,
|
||||
.devid = devid,
|
||||
.axis = axis->axis,
|
||||
.value = axis->value,
|
||||
|
@ -677,12 +679,13 @@ in_x11_send_key_event (void)
|
|||
}
|
||||
|
||||
static void
|
||||
in_x11_send_button_event (int devid, in_buttoninfo_t *button)
|
||||
in_x11_send_button_event (int devid, in_buttoninfo_t *button, void *event_data)
|
||||
{
|
||||
IE_event_t event = {
|
||||
.type = ie_button,
|
||||
.when = Sys_LongTime (),
|
||||
.button = {
|
||||
.data = event_data,
|
||||
.devid = devid,
|
||||
.button = button->button,
|
||||
.state = button->state,
|
||||
|
@ -779,7 +782,8 @@ event_button (XEvent *event)
|
|||
int press = event->type == ButtonPress;
|
||||
|
||||
x11_mouse_buttons[but].state = press;
|
||||
in_x11_send_button_event (x11_mouse_device.devid, &x11_mouse_buttons[but]);
|
||||
in_x11_send_button_event (x11_mouse_device.devid, &x11_mouse_buttons[but],
|
||||
x11_mouse_device.event_data);
|
||||
|
||||
x11_mouse.shift = event->xmotion.state & 0xff;
|
||||
x11_mouse.x = event->xmotion.x;
|
||||
|
@ -803,7 +807,8 @@ event_key (XEvent *event)
|
|||
key = (event->xkey.keycode - 8) & 0xff;
|
||||
x11_key_buttons[key].state = event->type == KeyPress;
|
||||
in_x11_send_button_event (x11_keyboard_device.devid,
|
||||
&x11_key_buttons[key]);
|
||||
&x11_key_buttons[key],
|
||||
x11_keyboard_device.event_data);
|
||||
|
||||
x11_key.shift = event->xmotion.state & 0xff;
|
||||
XLateKey (&event->xkey, &x11_key.code, &x11_key.unicode);
|
||||
|
@ -942,6 +947,20 @@ in_x11_shutdown (void *data)
|
|||
X11_CloseDisplay ();
|
||||
}
|
||||
|
||||
static void
|
||||
in_x11_set_device_event_data (void *device, void *event_data, void *data)
|
||||
{
|
||||
x11_device_t *dev = device;
|
||||
dev->event_data = event_data;
|
||||
}
|
||||
|
||||
static void *
|
||||
in_x11_get_device_event_data (void *device, void *data)
|
||||
{
|
||||
x11_device_t *dev = device;
|
||||
return dev->event_data;
|
||||
}
|
||||
|
||||
static void
|
||||
in_x11_init_cvars (void)
|
||||
{
|
||||
|
@ -1028,6 +1047,8 @@ in_x11_clear_states (void *data)
|
|||
static in_driver_t in_x11_driver = {
|
||||
.init = in_x11_init,
|
||||
.shutdown = in_x11_shutdown,
|
||||
.set_device_event_data = in_x11_set_device_event_data,
|
||||
.get_device_event_data = in_x11_get_device_event_data,
|
||||
#ifdef X11_USE_SELECT
|
||||
.add_select = in_x11_add_select,
|
||||
.check_select = in_x11_check_select,
|
||||
|
|
|
@ -467,6 +467,17 @@ term_shutdown (void *_res)
|
|||
{
|
||||
}
|
||||
|
||||
static void
|
||||
term_set_device_event_data (void *device, void *event_data, void *data)
|
||||
{
|
||||
}
|
||||
|
||||
static void *
|
||||
term_get_device_event_data (void *device, void *data)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define FD 0
|
||||
static void
|
||||
term_add_select (qf_fd_set *fdset, int *maxfd, void *_res)
|
||||
|
@ -506,6 +517,8 @@ term_check_select (qf_fd_set *fdset, void *_res)
|
|||
static in_driver_t term_driver = {
|
||||
.init = term_init,
|
||||
.shutdown = term_shutdown,
|
||||
.set_device_event_data = term_set_device_event_data,
|
||||
.get_device_event_data = term_get_device_event_data,
|
||||
.add_select = term_add_select,
|
||||
.check_select = term_check_select,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue