From 946a0874d294b6c7a25e9ec9b9a5957e09d24ebb Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Thu, 10 Feb 2022 07:05:56 +0200 Subject: [PATCH] removed the global disable-translation/disable-rotation options, and moved the state variables out of the cfg structure. --- src/cfgfile.c | 16 +--------------- src/cfgfile.h | 4 +--- src/event.c | 25 ++++++++++++++----------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/cfgfile.c b/src/cfgfile.c index 9ee0784..bb58f2b 100644 --- a/src/cfgfile.c +++ b/src/cfgfile.c @@ -1,6 +1,6 @@ /* spacenavd - a free software replacement driver for 6dof space-mice. -Copyright (C) 2007-2019 John Tsiombikas +Copyright (C) 2007-2022 John Tsiombikas 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 @@ -68,8 +68,6 @@ void default_cfg(struct cfg *cfg) cfg->devname[i] = 0; cfg->devid[i][0] = cfg->devid[i][1] = -1; } - cfg->disable_translation = 0; - cfg->disable_rotation = 0; } #define EXPECT(cond) \ @@ -197,14 +195,6 @@ int read_cfg(const char *fname, struct cfg *cfg) EXPECT(isfloat); cfg->sens_rot[2] = fval; - } else if(strcmp(key_str, "disable-rotation") == 0) { - EXPECT(isint); - cfg->disable_rotation = ival; - - } else if(strcmp(key_str, "disable-translation") == 0) { - EXPECT(isint); - cfg->disable_translation = ival; - } else if(strcmp(key_str, "invert-rot") == 0) { if(strchr(val_str, 'x')) { cfg->invert[RX] = !def_axinv[RX]; @@ -390,10 +380,6 @@ int write_cfg(const char *fname, struct cfg *cfg) } fputc('\n', fp); - fprintf(fp, "disable-rotation = %d\n", cfg->disable_rotation); - fprintf(fp, "disable-translation = %d\n", cfg->disable_translation); - fputc('\n', fp); - fprintf(fp, "# dead zone; any motion less than this number, is discarded as noise.\n"); if(cfg->dead_threshold[0] == cfg->dead_threshold[1] && cfg->dead_threshold[1] == cfg->dead_threshold[2] && cfg->dead_threshold[2] == cfg->dead_threshold[3] && cfg->dead_threshold[3] == cfg->dead_threshold[4] && cfg->dead_threshold[4] == cfg->dead_threshold[5]) { diff --git a/src/cfgfile.h b/src/cfgfile.h index 692e819..1003818 100644 --- a/src/cfgfile.h +++ b/src/cfgfile.h @@ -1,6 +1,6 @@ /* spacenavd - a free software replacement driver for 6dof space-mice. -Copyright (C) 2007-2019 John Tsiombikas +Copyright (C) 2007-2022 John Tsiombikas 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 @@ -45,8 +45,6 @@ enum { struct cfg { float sensitivity, sens_trans[3], sens_rot[3]; - int disable_rotation; - int disable_translation; int dead_threshold[MAX_AXES]; int invert[MAX_AXES]; int map_axis[MAX_AXES]; diff --git a/src/event.c b/src/event.c index 93e294f..2952cd1 100644 --- a/src/event.c +++ b/src/event.c @@ -1,6 +1,6 @@ /* spacenavd - a free software replacement driver for 6dof space-mice. -Copyright (C) 2007-2013 John Tsiombikas +Copyright (C) 2007-2022 John Tsiombikas 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 @@ -56,6 +56,9 @@ static unsigned int msec_dif(struct timeval tv1, struct timeval tv2); static struct dev_event *dev_ev_list = NULL; +static int disable_translation, disable_rotation; + + static struct dev_event *add_dev_event(struct device *dev) { struct dev_event *dev_ev, *iter; @@ -143,8 +146,8 @@ void process_input(struct device *dev, struct dev_input *inp) } sign = cfg.invert[inp->idx] ? -1 : 1; - sens_rot = cfg.disable_rotation ? 0 : cfg.sens_rot[inp->idx - 3]; - sens_trans = cfg.disable_translation ? 0 : cfg.sens_trans[inp->idx]; + sens_rot = disable_rotation ? 0 : cfg.sens_rot[inp->idx - 3]; + sens_trans = disable_translation ? 0 : cfg.sens_trans[inp->idx]; inp->val = (int)((float)inp->val * cfg.sensitivity * (inp->idx < 3 ? sens_trans : sens_rot)); @@ -224,6 +227,8 @@ void process_input(struct device *dev, struct dev_input *inp) static void handle_button_action(int act, int pressed) { + if(pressed) return; /* perform all actions on release */ + switch(act) { case BNACT_SENS_INC: cfg.sensitivity *= 1.1f; @@ -235,17 +240,15 @@ static void handle_button_action(int act, int pressed) cfg.sensitivity = 1.0f; break; case BNACT_DISABLE_ROTATION: - if(pressed == BTN_RELEASE) { - cfg.disable_rotation = !cfg.disable_rotation; - if (cfg.disable_rotation) - cfg.disable_translation = 0; + disable_rotation = !disable_rotation; + if(disable_rotation) { + disable_translation = 0; } break; case BNACT_DISABLE_TRANSLATION: - if(pressed == BTN_RELEASE) { - cfg.disable_translation = !cfg.disable_translation; - if (cfg.disable_translation) - cfg.disable_rotation = 0; + disable_translation = !disable_translation; + if(disable_translation) { + disable_rotation = 0; } break; }