- added a configuration option for arbitrarily remapping button numbers

- added preliminary support for emulating keyboard input from button presses


git-svn-id: svn+ssh://svn.code.sf.net/p/spacenav/code/trunk/spacenavd@137 ef983eb1-d774-4af8-acfd-baaf7b16a646
pull/1/head
John Tsiombikas 2012-05-05 05:12:49 +00:00
rodzic 8361610b5e
commit fa6bc12d9e
5 zmienionych plików z 86 dodań i 5 usunięć

Wyświetl plik

@ -52,6 +52,8 @@ void default_cfg(struct cfg *cfg)
for(i=0; i<MAX_BUTTONS; i++) {
cfg->map_button[i] = i;
cfg->kbmap_str[i] = 0;
cfg->kbmap[i] = 0;
}
cfg->repeat_msec = -1;
@ -85,7 +87,7 @@ int read_cfg(const char *fname, struct cfg *cfg)
while(fcntl(fileno(fp), F_SETLKW, &flk) == -1);
while(fgets(buf, sizeof buf, fp)) {
int isint, isfloat, ival, i;
int isint, isfloat, ival, i, bnidx;
float fval;
char *endp, *key_str, *val_str, *line = buf;
while(*line == ' ' || *line == '\t') line++;
@ -221,6 +223,28 @@ int read_cfg(const char *fname, struct cfg *cfg)
cfg->map_axis[i] = swap_yz ? i : def_axmap[i];
}
} else if(sscanf(key_str, "bnmap%d", &bnidx) == 1) {
EXPECT(isint);
if(bnidx < 0 || bnidx >= MAX_BUTTONS || ival < 0 || ival >= MAX_BUTTONS) {
fprintf(stderr, "invalid configuration value for %s, expected a number from 0 to %d\n", key_str, MAX_BUTTONS);
continue;
}
if(cfg->map_button[bnidx] != bnidx) {
printf("warning: multiple mappings for button %d\n", bnidx);
}
cfg->map_button[bnidx] = ival;
} else if(sscanf(key_str, "kbmap%d", &bnidx) == 1) {
if(bnidx < 0 || bnidx >= MAX_BUTTONS) {
fprintf(stderr, "invalid configuration value for %s, expected a number from 0 to %d\n", key_str, MAX_BUTTONS);
continue;
}
if(cfg->kbmap_str[bnidx]) {
printf("warning: multiple keyboard mappings for button %d: %s -> %s\n", bnidx, cfg->kbmap_str[bnidx], val_str);
free(cfg->kbmap_str[bnidx]);
}
cfg->kbmap_str[bnidx] = strdup(val_str);
} else if(strcmp(key_str, "led") == 0) {
if(isint) {
cfg->led = ival;
@ -269,6 +293,7 @@ int read_cfg(const char *fname, struct cfg *cfg)
int write_cfg(const char *fname, struct cfg *cfg)
{
int i, wrote_comment;
FILE *fp;
struct flock flk;
@ -343,6 +368,34 @@ int write_cfg(const char *fname, struct cfg *cfg)
fprintf(fp, "# swap translation along Y and Z axes\n");
fprintf(fp, "swap-yz = %s\n\n", cfg->map_axis[1] == def_axmap[1] ? "false" : "true");
wrote_comment = 0;
for(i=0; i<MAX_BUTTONS; i++) {
if(cfg->map_button[i] != i) {
if(!wrote_comment) {
fprintf(fp, "# button mappings\n");
wrote_comment = 1;
}
fprintf(fp, "bnmap%d = %d\n", i, cfg->map_button[i]);
}
}
if(wrote_comment) {
fputc('\n', fp);
}
wrote_comment = 0;
for(i=0; i<MAX_BUTTONS; i++) {
if(cfg->kbmap_str[i]) {
if(!wrote_comment) {
fprintf(fp, "# button to key mappings\n");
wrote_comment = 1;
}
fprintf(fp, "kbmap%d = %s\n", i, cfg->kbmap_str[i]);
}
}
if(wrote_comment) {
fputc('\n', fp);
}
if(!cfg->led) {
fprintf(fp, "# disable led\n");
fprintf(fp, "led = 0\n\n");

Wyświetl plik

@ -1,6 +1,6 @@
/*
spnavcfg - an interactive GUI configurator for the spacenavd daemon.
Copyright (C) 2007-2010 John Tsiombikas <nuclear@member.fsf.org>
Copyright (C) 2007-2012 John Tsiombikas <nuclear@member.fsf.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -29,6 +29,8 @@ struct cfg {
int invert[6];
int map_axis[6];
int map_button[MAX_BUTTONS];
int kbmap[MAX_BUTTONS];
char *kbmap_str[MAX_BUTTONS];
int led, grab_device;
char serial_dev[PATH_MAX];
int repeat_msec;

Wyświetl plik

@ -1,6 +1,6 @@
/*
spacenavd - a free software replacement driver for 6dof space-mice.
Copyright (C) 2007-2010 John Tsiombikas <nuclear@member.fsf.org>
Copyright (C) 2007-2012 John Tsiombikas <nuclear@member.fsf.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include "event.h"
#include "client.h"
@ -24,6 +25,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "proto_unix.h"
#include "spnavd.h"
#ifdef USE_X11
#include "kbemu.h"
#endif
enum {
MOT_X, MOT_Y, MOT_Z,
MOT_RX, MOT_RY, MOT_RZ
@ -64,6 +69,20 @@ void process_input(struct dev_input *inp)
break;
case INP_BUTTON:
#ifdef USE_X11
/* check to see if we must emulate a keyboard event instead of a
* retular button event for this button
*/
if(cfg.kbmap_str[inp->idx]) {
if(!cfg.kbmap[inp->idx]) {
cfg.kbmap[inp->idx] = kbemu_keysym(cfg.kbmap_str[inp->idx]);
printf("mapping ``%s'' to keysym %d\n", cfg.kbmap_str[inp->idx], (int)cfg.kbmap[inp->idx]);
}
send_kbevent(cfg.kbmap[inp->idx], inp->val);
break;
}
#endif
if(ev_pending) {
dispatch_event(&ev);
ev_pending = 0;

Wyświetl plik

@ -1,6 +1,6 @@
/*
spacenavd - a free software replacement driver for 6dof space-mice.
Copyright (C) 2007-2010 John Tsiombikas <nuclear@member.fsf.org>
Copyright (C) 2007-2012 John Tsiombikas <nuclear@member.fsf.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

Wyświetl plik

@ -1,6 +1,6 @@
/*
spacenavd - a free software replacement driver for 6dof space-mice.
Copyright (C) 2007-2010 John Tsiombikas <nuclear@member.fsf.org>
Copyright (C) 2007-2012 John Tsiombikas <nuclear@member.fsf.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -35,6 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "client.h"
#include "spnavd.h"
#include "xdetect.h"
#include "kbemu.h"
enum cmd_msg {
@ -149,6 +150,9 @@ int init_x11(void)
}
XFlush(dpy);
/* pass the display connection to the keyboard emulation module */
kbemu_set_display(dpy);
xdet_stop(); /* stop X server detection if it was running */
return 0;
}
@ -173,6 +177,9 @@ void close_x11(void)
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
dpy = 0;
/* stop the kbemu module from using an invalid Display* */
kbemu_set_display(0);
}
/* also remove all x11 clients from the client list */