| summaryrefslogtreecommitdiff | 
diff options
| -rw-r--r-- | include/relabsd/device/axis.h | 11 | ||||
| -rw-r--r-- | include/relabsd/device/axis_types.h | 1 | ||||
| -rw-r--r-- | src/config/parameters/parameters.c | 3 | ||||
| -rw-r--r-- | src/device/axis/axis.c | 10 | ||||
| -rw-r--r-- | src/device/axis/axis_name.c | 41 | ||||
| -rw-r--r-- | src/device/axis/axis_option.c | 19 | ||||
| -rw-r--r-- | src/device/virtual/virtual_device.c | 18 | ||||
| -rw-r--r-- | src/server/conversion_main_loop.c | 45 | 
8 files changed, 137 insertions, 11 deletions
| diff --git a/include/relabsd/device/axis.h b/include/relabsd/device/axis.h index b6605f5..e3f0794 100644 --- a/include/relabsd/device/axis.h +++ b/include/relabsd/device/axis.h @@ -53,6 +53,12 @@ enum relabsd_axis_name relabsd_axis_parse_name     const char name [const restrict static 1]  ); +/* Same as above, but the string only has to start with the correct name. */ +enum relabsd_axis_name relabsd_axis_parse_name_from_prefix +( +   const char name [const restrict static 1] +); +  /*   * Gives an string representation of an relabsd_axis.   * "??" is returned for RELABSD_UNKNOWN. @@ -94,6 +100,11 @@ void relabsd_axis_initialize     struct relabsd_axis axis [const restrict static 1]  ); +enum relabsd_axis_name relabsd_axis_get_convert_to +( +   const struct relabsd_axis axis [const restrict static 1] +); +  int relabsd_axis_attributes_are_dirty  (     const struct relabsd_axis axis [const restrict static 1] diff --git a/include/relabsd/device/axis_types.h b/include/relabsd/device/axis_types.h index d13ccd8..8fbb726 100644 --- a/include/relabsd/device/axis_types.h +++ b/include/relabsd/device/axis_types.h @@ -41,4 +41,5 @@ struct relabsd_axis     int previous_value;     int flags[RELABSD_AXIS_FLAGS_COUNT];     int attributes_were_modified; +   enum relabsd_axis_name convert_to;  }; diff --git a/src/config/parameters/parameters.c b/src/config/parameters/parameters.c index 04ee498..cee6f2e 100644 --- a/src/config/parameters/parameters.c +++ b/src/config/parameters/parameters.c @@ -464,7 +464,8 @@ void relabsd_parameters_print_usage (const char exec [const restrict static 1])           " [+|-|=]<value>\n"           "\t\tModifies an axis.\n\n" -      "\t[-o | --toggle-option] <axis_name> [direct|real_fuzz|framed|enable]\n" +      "\t[-o | --toggle-option] <axis_name> " +         "[direct|real_fuzz|framed|enable|convert_to=<axis_name>]\n"           "\t\tToggles an axis option.\n",        exec,        exec, diff --git a/src/device/axis/axis.c b/src/device/axis/axis.c index e854e37..1cdb856 100644 --- a/src/device/axis/axis.c +++ b/src/device/axis/axis.c @@ -20,6 +20,8 @@ void relabsd_axis_initialize  )  {     (void) memset(axis, 0, sizeof(struct relabsd_axis)); + +   axis->convert_to = RELABSD_UNKNOWN;  }  void relabsd_axis_to_absinfo @@ -68,3 +70,11 @@ void relabsd_axis_set_attributes_are_dirty  {     axis->attributes_were_modified = val;  } + +enum relabsd_axis_name relabsd_axis_get_convert_to +( +   const struct relabsd_axis axis [const restrict static 1] +) +{ +   return axis->convert_to; +} diff --git a/src/device/axis/axis_name.c b/src/device/axis/axis_name.c index c18a28f..1ac0715 100644 --- a/src/device/axis/axis_name.c +++ b/src/device/axis/axis_name.c @@ -56,6 +56,47 @@ enum relabsd_axis_name relabsd_axis_parse_name     return RELABSD_UNKNOWN;  } +enum relabsd_axis_name relabsd_axis_parse_name_from_prefix +( +   const char name [const restrict static 1] +) +{ +   if (RELABSD_IS_PREFIX("X", name)) +   { +      return RELABSD_X; +   } +   else if (RELABSD_IS_PREFIX("Y", name)) +   { +      return RELABSD_Y; +   } +   else if (RELABSD_IS_PREFIX("Z", name)) +   { +      return RELABSD_Z; +   } +   else if (RELABSD_IS_PREFIX("RX", name)) +   { +      return RELABSD_RX; +   } +   else if (RELABSD_IS_PREFIX("RY", name)) +   { +      return RELABSD_RY; +   } +   else if (RELABSD_IS_PREFIX("RZ", name)) +   { +      return RELABSD_RZ; +   } +   else if (RELABSD_IS_PREFIX("WL", name)) +   { +      return RELABSD_WHEEL; +   } +   else if (RELABSD_IS_PREFIX("MC", name)) +   { +      return RELABSD_MISC; +   } + +   return RELABSD_UNKNOWN; +} +  const char * relabsd_axis_name_to_string (const enum relabsd_axis_name e)  {     switch (e) diff --git a/src/device/axis/axis_option.c b/src/device/axis/axis_option.c index 1d68b78..8e52fe1 100644 --- a/src/device/axis/axis_option.c +++ b/src/device/axis/axis_option.c @@ -57,6 +57,25 @@ int relabsd_axis_enable_option_from_name           );        }     } +   else if (RELABSD_IS_PREFIX("convert_to=", option_name)) +   { +      axis->convert_to = +         relabsd_axis_parse_name_from_prefix +         ( +            option_name + strlen("convert_to=") +         ); + +      if (axis->convert_to == RELABSD_UNKNOWN) +      { +         RELABSD_ERROR +         ( +            "Unknown target axis to convert to in config for axis '%s'.", +            axis_name +         ); + +         return -1; +      } +   }     else     {        RELABSD_ERROR diff --git a/src/device/virtual/virtual_device.c b/src/device/virtual/virtual_device.c index d4be1b8..5ec06f5 100644 --- a/src/device/virtual/virtual_device.c +++ b/src/device/virtual/virtual_device.c @@ -143,11 +143,23 @@ int relabsd_virtual_device_update_axis_absinfo     const struct relabsd_virtual_device device [const restrict static 1]  )  { +   enum relabsd_axis_name target_axis_name;     struct input_absinfo absinfo;     relabsd_axis_to_absinfo(axis, &absinfo); -   /* TODO: report failure? 0 on success, -1 otherwise, no cause given. */ +   target_axis_name = relabsd_axis_get_convert_to(axis); + +   if (target_axis_name == RELABSD_UNKNOWN) +   { +      target_axis_name = axis_name; +   } + +   /* +    * TODO: report failure? 0 on success, -1 otherwise, no cause given. +    * Might want to add an option to see if people want to use the tool to +    * alter existing EV_ABS axes instead of converting from EV_REL to EV_ABS. +    */     (void) libevdev_disable_event_code     (        device->libevdev, @@ -159,7 +171,7 @@ int relabsd_virtual_device_update_axis_absinfo     (        device->libevdev,        EV_ABS, -      relabsd_axis_name_to_evdev_abs(axis_name), +      relabsd_axis_name_to_evdev_abs(target_axis_name),        &absinfo     ); @@ -267,6 +279,7 @@ int relabsd_virtual_device_recreate  )  {     int err; +     RELABSD_S_DEBUG(RELABSD_DEBUG_PROGRAM_FLOW, "Recreating virtual device...");     libevdev_uinput_destroy(device->uinput_device); @@ -288,6 +301,7 @@ int relabsd_virtual_device_recreate     }     RELABSD_S_DEBUG(RELABSD_DEBUG_PROGRAM_FLOW, "Recreated virtual device."); +     return 0;  } diff --git a/src/server/conversion_main_loop.c b/src/server/conversion_main_loop.c index 937fc68..f9af4f8 100644 --- a/src/server/conversion_main_loop.c +++ b/src/server/conversion_main_loop.c @@ -42,6 +42,7 @@ static void convert_input     if (input_type == EV_REL)     { +      struct relabsd_axis * axis;        unsigned int abs_code;        enum relabsd_axis_name axis_name; @@ -53,14 +54,15 @@ static void convert_input           return;        } -      switch -      ( -         relabsd_axis_filter_new_value -         ( -            relabsd_parameters_get_axis(axis_name, &(server->parameters)), -            &value -         ) -      ) +      axis = relabsd_parameters_get_axis(axis_name, &(server->parameters)); +      axis_name = relabsd_axis_get_convert_to(axis); + +      if (axis_name != RELABSD_UNKNOWN) +      { +         abs_code = relabsd_axis_name_to_evdev_abs(axis_name); +      } + +      switch (relabsd_axis_filter_new_value(axis, &value))        {           case -1:              /* Doesn't want the event to be transmitted. */ @@ -93,6 +95,33 @@ static void convert_input              return;        }     } +   else if (input_type == EV_ABS) +   { +      enum relabsd_axis_name axis_name; + +      axis_name = relabsd_axis_name_from_evdev_abs(input_code); + +      if (axis_name != RELABSD_UNKNOWN) +      { +         struct relabsd_axis * axis; + +         axis = relabsd_parameters_get_axis(axis_name, &(server->parameters)); +         axis_name = relabsd_axis_get_convert_to(axis); + +         if (axis_name != RELABSD_UNKNOWN) +         { +            input_code = relabsd_axis_name_to_evdev_abs(axis_name); +         } +      } + +      (void) relabsd_virtual_device_write_evdev_event +      ( +         &(server->virtual_device), +         input_type, +         input_code, +         value +      ); +   }     else     {        /* Any other event is retransmitted as is. */ | 


