kopia lustrzana https://github.com/FreeSpacenav/spacenavd
- added raw axis/button events
- fixed dropping events when the client's event mask doesn't matchpull/68/head
rodzic
3fb72ed7ef
commit
b922cb75f8
10
src/client.h
10
src/client.h
|
@ -35,10 +35,12 @@ enum {
|
||||||
|
|
||||||
/* event selection (must match SPNAV_EVMASK* in libspnav/spnav.h) */
|
/* event selection (must match SPNAV_EVMASK* in libspnav/spnav.h) */
|
||||||
enum {
|
enum {
|
||||||
EVMASK_MOTION = 1,
|
EVMASK_MOTION = 0x01,
|
||||||
EVMASK_BUTTON = 2,
|
EVMASK_BUTTON = 0x02,
|
||||||
EVMASK_DEV = 4,
|
EVMASK_DEV = 0x04,
|
||||||
EVMASK_CFG = 8
|
EVMASK_CFG = 0x08,
|
||||||
|
EVMASK_RAWAXIS = 0x10,
|
||||||
|
EVMASK_RAWBUTTON = 0x20
|
||||||
};
|
};
|
||||||
|
|
||||||
struct device;
|
struct device;
|
||||||
|
|
24
src/event.c
24
src/event.c
|
@ -151,9 +151,15 @@ void process_input(struct device *dev, struct dev_input *inp)
|
||||||
int sign, axis;
|
int sign, axis;
|
||||||
struct dev_event *dev_ev;
|
struct dev_event *dev_ev;
|
||||||
float sens_rot, sens_trans;
|
float sens_rot, sens_trans;
|
||||||
|
spnav_event ev;
|
||||||
|
|
||||||
switch(inp->type) {
|
switch(inp->type) {
|
||||||
case INP_MOTION:
|
case INP_MOTION:
|
||||||
|
ev.type = EVENT_RAWAXIS;
|
||||||
|
ev.axis.idx = inp->idx;
|
||||||
|
ev.axis.value = inp->val;
|
||||||
|
broadcast_event(&ev);
|
||||||
|
|
||||||
if(abs(inp->val) < cfg.dead_threshold[inp->idx] ) {
|
if(abs(inp->val) < cfg.dead_threshold[inp->idx] ) {
|
||||||
inp->val = 0;
|
inp->val = 0;
|
||||||
}
|
}
|
||||||
|
@ -181,6 +187,11 @@ void process_input(struct device *dev, struct dev_input *inp)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INP_BUTTON:
|
case INP_BUTTON:
|
||||||
|
ev.type = EVENT_RAWBUTTON;
|
||||||
|
ev.button.press = inp->val;
|
||||||
|
ev.button.bnum = inp->idx;
|
||||||
|
broadcast_event(&ev);
|
||||||
|
|
||||||
/* check to see if the button has been bound to an action */
|
/* check to see if the button has been bound to an action */
|
||||||
if(cfg.bnact[inp->idx] > 0) {
|
if(cfg.bnact[inp->idx] > 0) {
|
||||||
handle_button_action(cfg.bnact[inp->idx], inp->val);
|
handle_button_action(cfg.bnact[inp->idx], inp->val);
|
||||||
|
@ -248,12 +259,15 @@ static void handle_button_action(int act, int pressed)
|
||||||
switch(act) {
|
switch(act) {
|
||||||
case BNACT_SENS_INC:
|
case BNACT_SENS_INC:
|
||||||
cfg.sensitivity *= 1.1f;
|
cfg.sensitivity *= 1.1f;
|
||||||
|
broadcast_cfg_event(REQ_GCFG_SENS, *(int*)&cfg.sensitivity);
|
||||||
break;
|
break;
|
||||||
case BNACT_SENS_DEC:
|
case BNACT_SENS_DEC:
|
||||||
cfg.sensitivity *= 0.9f;
|
cfg.sensitivity *= 0.9f;
|
||||||
|
broadcast_cfg_event(REQ_GCFG_SENS, *(int*)&cfg.sensitivity);
|
||||||
break;
|
break;
|
||||||
case BNACT_SENS_RESET:
|
case BNACT_SENS_RESET:
|
||||||
cfg.sensitivity = 1.0f;
|
cfg.sensitivity = 1.0f;
|
||||||
|
broadcast_cfg_event(REQ_GCFG_SENS, *(int*)&cfg.sensitivity);
|
||||||
break;
|
break;
|
||||||
case BNACT_DISABLE_ROTATION:
|
case BNACT_DISABLE_ROTATION:
|
||||||
disable_rotation = !disable_rotation;
|
disable_rotation = !disable_rotation;
|
||||||
|
@ -331,6 +345,16 @@ void broadcast_event(spnav_event *ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void broadcast_cfg_event(int cfg, int val)
|
||||||
|
{
|
||||||
|
spnav_event ev = {0};
|
||||||
|
|
||||||
|
ev.type = EVENT_CFG;
|
||||||
|
ev.cfg.cfg = cfg;
|
||||||
|
ev.cfg.data[0] = val;
|
||||||
|
broadcast_event(&ev);
|
||||||
|
}
|
||||||
|
|
||||||
static void send_event(spnav_event *ev, struct client *c)
|
static void send_event(spnav_event *ev, struct client *c)
|
||||||
{
|
{
|
||||||
switch(get_client_type(c)) {
|
switch(get_client_type(c)) {
|
||||||
|
|
14
src/event.h
14
src/event.h
|
@ -29,7 +29,10 @@ enum {
|
||||||
|
|
||||||
/* protocol v1 events */
|
/* protocol v1 events */
|
||||||
EVENT_DEV, /* device change */
|
EVENT_DEV, /* device change */
|
||||||
EVENT_CFG /* configuration change */
|
EVENT_CFG, /* configuration change */
|
||||||
|
|
||||||
|
EVENT_RAWAXIS,
|
||||||
|
EVENT_RAWBUTTON
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { DEV_ADD, DEV_RM };
|
enum { DEV_ADD, DEV_RM };
|
||||||
|
@ -62,12 +65,19 @@ struct event_cfg {
|
||||||
int data[6];
|
int data[6];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct event_axis {
|
||||||
|
int type;
|
||||||
|
int idx;
|
||||||
|
int value;
|
||||||
|
};
|
||||||
|
|
||||||
typedef union spnav_event {
|
typedef union spnav_event {
|
||||||
int type;
|
int type;
|
||||||
struct event_motion motion;
|
struct event_motion motion;
|
||||||
struct event_button button;
|
struct event_button button;
|
||||||
struct event_dev dev;
|
struct event_dev dev;
|
||||||
struct event_cfg cfg;
|
struct event_cfg cfg;
|
||||||
|
struct event_axis axis;
|
||||||
} spnav_event;
|
} spnav_event;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -96,4 +106,6 @@ void repeat_last_event(struct device *dev);
|
||||||
/* broadcasts an event to all clients */
|
/* broadcasts an event to all clients */
|
||||||
void broadcast_event(spnav_event *ev);
|
void broadcast_event(spnav_event *ev);
|
||||||
|
|
||||||
|
void broadcast_cfg_event(int cfg, int val);
|
||||||
|
|
||||||
#endif /* EVENT_H_ */
|
#endif /* EVENT_H_ */
|
||||||
|
|
|
@ -12,6 +12,8 @@ enum {
|
||||||
UEV_RELEASE,
|
UEV_RELEASE,
|
||||||
UEV_DEV,
|
UEV_DEV,
|
||||||
UEV_CFG,
|
UEV_CFG,
|
||||||
|
UEV_RAWAXIS,
|
||||||
|
UEV_RAWBUTTON,
|
||||||
|
|
||||||
MAX_UEV
|
MAX_UEV
|
||||||
};
|
};
|
||||||
|
|
|
@ -106,7 +106,7 @@ void send_uevent(spnav_event *ev, struct client *c)
|
||||||
|
|
||||||
switch(ev->type) {
|
switch(ev->type) {
|
||||||
case EVENT_MOTION:
|
case EVENT_MOTION:
|
||||||
if(!(c->evmask & EVMASK_MOTION)) break;
|
if(!(c->evmask & EVMASK_MOTION)) return;
|
||||||
|
|
||||||
data[0] = UEV_MOTION;
|
data[0] = UEV_MOTION;
|
||||||
|
|
||||||
|
@ -118,15 +118,32 @@ void send_uevent(spnav_event *ev, struct client *c)
|
||||||
data[7] = ev->motion.period;
|
data[7] = ev->motion.period;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case EVENT_RAWAXIS:
|
||||||
|
if(!(c->evmask & EVMASK_RAWAXIS)) return;
|
||||||
|
|
||||||
|
data[0] = UEV_RAWAXIS;
|
||||||
|
data[1] = ev->axis.idx;
|
||||||
|
data[2] = ev->axis.value;
|
||||||
|
break;
|
||||||
|
|
||||||
case EVENT_BUTTON:
|
case EVENT_BUTTON:
|
||||||
if(!(c->evmask & EVMASK_BUTTON)) break;
|
if(!(c->evmask & EVMASK_BUTTON)) return;
|
||||||
|
|
||||||
data[0] = ev->button.press ? UEV_PRESS : UEV_RELEASE;
|
data[0] = ev->button.press ? UEV_PRESS : UEV_RELEASE;
|
||||||
data[1] = ev->button.bnum;
|
data[1] = ev->button.bnum;
|
||||||
|
data[2] = ev->button.press;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EVENT_RAWBUTTON:
|
||||||
|
if(!(c->evmask & EVMASK_RAWBUTTON)) return;
|
||||||
|
|
||||||
|
data[0] = UEV_RAWBUTTON;
|
||||||
|
data[1] = ev->button.bnum;
|
||||||
|
data[2] = ev->button.press;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVENT_DEV:
|
case EVENT_DEV:
|
||||||
if(!(c->evmask & EVMASK_DEV)) break;
|
if(!(c->evmask & EVMASK_DEV)) return;
|
||||||
|
|
||||||
data[0] = UEV_DEV;
|
data[0] = UEV_DEV;
|
||||||
data[1] = ev->dev.op;
|
data[1] = ev->dev.op;
|
||||||
|
@ -137,7 +154,7 @@ void send_uevent(spnav_event *ev, struct client *c)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVENT_CFG:
|
case EVENT_CFG:
|
||||||
if(!(c->evmask & EVMASK_CFG)) break;
|
if(!(c->evmask & EVMASK_CFG)) return;
|
||||||
|
|
||||||
data[0] = UEV_CFG;
|
data[0] = UEV_CFG;
|
||||||
data[1] = ev->cfg.cfg;
|
data[1] = ev->cfg.cfg;
|
||||||
|
@ -145,7 +162,7 @@ void send_uevent(spnav_event *ev, struct client *c)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(write(get_client_socket(c), data, sizeof data) == -1 && errno == EINTR);
|
while(write(get_client_socket(c), data, sizeof data) == -1 && errno == EINTR);
|
||||||
|
|
Ładowanie…
Reference in New Issue