Hello community, here is the log from the commit of package libmanette for openSUSE:Factory checked in at 2019-03-28 22:49:29 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/libmanette (Old) and /work/SRC/openSUSE:Factory/.libmanette.new.25356 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "libmanette" Thu Mar 28 22:49:29 2019 rev:4 rq:689303 version:0.2.2 Changes: -------- --- /work/SRC/openSUSE:Factory/libmanette/libmanette.changes 2018-10-01 08:16:20.454009261 +0200 +++ /work/SRC/openSUSE:Factory/.libmanette.new.25356/libmanette.changes 2019-03-28 22:49:34.543045078 +0100 @@ -1,0 +2,11 @@ +Mon Mar 11 09:32:30 UTC 2019 - Bjørn Lie <[email protected]> + +- Update to version 0.2.2: + + Device: + - Handle absolute axes with min > 0. + - Handle the axes' flat to support axes to d-pad mapping. + + Mapping: + - Support negative analog axis to button mappings. + - Support full-range axis to button mappings. + +------------------------------------------------------------------- Old: ---- libmanette-0.2.1.tar.xz New: ---- libmanette-0.2.2.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ libmanette.spec ++++++ --- /var/tmp/diff_new_pack.ngAhy8/_old 2019-03-28 22:49:34.939045006 +0100 +++ /var/tmp/diff_new_pack.ngAhy8/_new 2019-03-28 22:49:34.943045005 +0100 @@ -1,7 +1,7 @@ # # spec file for package libmanette # -# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -20,7 +20,7 @@ %define package_version 0_2-0 Name: libmanette -Version: 0.2.1 +Version: 0.2.2 Release: 0 Summary: A simple GObject game controller library License: LGPL-2.1-or-later ++++++ libmanette-0.2.1.tar.xz -> libmanette-0.2.2.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libmanette-0.2.1/NEWS new/libmanette-0.2.2/NEWS --- old/libmanette-0.2.1/NEWS 2018-07-30 10:44:57.000000000 +0200 +++ new/libmanette-0.2.2/NEWS 2019-03-11 10:04:16.000000000 +0100 @@ -1,4 +1,15 @@ ============= +Version 0.2.2 +============= + +* Device: + - Handle absolute axes with min > 0. + - Handle the axes' flat to support axes to d-pad mapping. +* Mapping: + - Support negative analog axis to button mappings. + - Support full-range axis to button mappings. + +============= Version 0.2.1 ============= diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libmanette-0.2.1/meson.build new/libmanette-0.2.2/meson.build --- old/libmanette-0.2.1/meson.build 2018-07-30 10:44:57.000000000 +0200 +++ new/libmanette-0.2.2/meson.build 2019-03-11 10:04:16.000000000 +0100 @@ -1,5 +1,5 @@ project('libmanette','c', - version: '0.2.1', + version: '0.2.2', meson_version: '>= 0.43.0', ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libmanette-0.2.1/src/manette-device.c new/libmanette-0.2.2/src/manette-device.c --- old/libmanette-0.2.1/src/manette-device.c 2018-07-30 10:44:57.000000000 +0200 +++ new/libmanette-0.2.2/src/manette-device.c 2019-03-11 10:04:16.000000000 +0100 @@ -25,6 +25,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include "manette-event-mapping-private.h" #include "manette-event-private.h" #include "manette-mapping-manager.h" @@ -71,6 +72,23 @@ /* Private */ +static guint +event_type_to_signal (ManetteEventType event_type) +{ + switch (event_type) { + case MANETTE_EVENT_BUTTON_PRESS: + return SIG_BUTTON_PRESS_EVENT; + case MANETTE_EVENT_BUTTON_RELEASE: + return SIG_BUTTON_RELEASE_EVENT; + case MANETTE_EVENT_ABSOLUTE: + return SIG_ABSOLUTE_AXIS_EVENT; + case MANETTE_EVENT_HAT: + return SIG_HAT_AXIS_EVENT; + default: + return N_SIGNALS; + } +} + static ManetteDeviceEventSignalData * manette_device_event_signal_data_new (ManetteDevice *self, guint signal_id, @@ -157,248 +175,23 @@ forward_event (ManetteDevice *self, ManetteEvent *event) { - switch (manette_event_get_event_type (event)) { - case MANETTE_EVENT_ABSOLUTE: - emit_event_signal_deferred (self, signals[SIG_ABSOLUTE_AXIS_EVENT], event); - - return; - case MANETTE_EVENT_BUTTON_PRESS: - emit_event_signal_deferred (self, signals[SIG_BUTTON_PRESS_EVENT], event); - - return; - case MANETTE_EVENT_BUTTON_RELEASE: - emit_event_signal_deferred (self, signals[SIG_BUTTON_RELEASE_EVENT], event); - - return; - case MANETTE_EVENT_HAT: - emit_event_signal_deferred (self, signals[SIG_HAT_AXIS_EVENT], event); - - return; - default: - return; - } -} - -static void -map_absolute_event (ManetteDevice *self, - ManetteEventAbsolute *event) -{ - const ManetteMappingBinding * const *bindings; - const ManetteMappingBinding * binding; - ManetteEvent *mapped_event; - guint signal; - gdouble absolute_value; - gboolean pressed; - - bindings = manette_mapping_get_bindings (self->mapping, - MANETTE_MAPPING_INPUT_TYPE_AXIS, - event->hardware_index); - if (bindings == NULL) - return; - - for (; *bindings != NULL; bindings++) { - binding = *bindings; - - if (binding->source.range == MANETTE_MAPPING_RANGE_NEGATIVE && - event->value > 0.) - continue; - - if (binding->source.range == MANETTE_MAPPING_RANGE_POSITIVE && - event->value < 0.) - continue; - - - mapped_event = manette_event_copy ((ManetteEvent *) event); - - switch (binding->destination.type) { - case EV_ABS: - absolute_value = binding->source.invert ? -event->value : event->value; - - signal = SIG_ABSOLUTE_AXIS_EVENT; - mapped_event->any.type = MANETTE_EVENT_ABSOLUTE; - mapped_event->absolute.axis = binding->destination.code; - switch (binding->destination.range) { - case MANETTE_MAPPING_RANGE_FULL: - mapped_event->absolute.value = absolute_value; - - break; - case MANETTE_MAPPING_RANGE_NEGATIVE: - mapped_event->absolute.value = (absolute_value / 2) - 1; - - break; - case MANETTE_MAPPING_RANGE_POSITIVE: - mapped_event->absolute.value = (absolute_value / 2) + 1; - - break; - default: - break; - } - - break; - case EV_KEY: - pressed = binding->source.invert ? event->value < -0. : event->value > 0.; - - signal = pressed ? SIG_BUTTON_PRESS_EVENT : SIG_BUTTON_RELEASE_EVENT; - mapped_event->any.type = pressed ? MANETTE_EVENT_BUTTON_PRESS : - MANETTE_EVENT_BUTTON_RELEASE; - mapped_event->button.button = binding->destination.code; - - break; - default: - manette_event_free (mapped_event); - - return; - } - - emit_event_signal_deferred (self, signals[signal], mapped_event); - - manette_event_free (mapped_event); - } -} - -static void -map_button_event (ManetteDevice *self, - ManetteEventButton *event) -{ - const ManetteMappingBinding * const *bindings; - const ManetteMappingBinding * binding; - ManetteEvent *mapped_event; - guint signal; - gboolean pressed; - - bindings = manette_mapping_get_bindings (self->mapping, - MANETTE_MAPPING_INPUT_TYPE_BUTTON, - event->hardware_index); - if (bindings == NULL) - return; - - for (; *bindings != NULL; bindings++) { - binding = *bindings; - - mapped_event = manette_event_copy ((ManetteEvent *) event); - - pressed = event->type == MANETTE_EVENT_BUTTON_PRESS; - - switch (binding->destination.type) { - case EV_ABS: - signal = SIG_ABSOLUTE_AXIS_EVENT; - mapped_event->any.type = MANETTE_EVENT_ABSOLUTE; - mapped_event->absolute.axis = binding->destination.code; - switch (binding->destination.range) { - case MANETTE_MAPPING_RANGE_NEGATIVE: - mapped_event->absolute.value = pressed ? -1 : 0; - - break; - case MANETTE_MAPPING_RANGE_FULL: - case MANETTE_MAPPING_RANGE_POSITIVE: - mapped_event->absolute.value = pressed ? 1 : 0; - - break; - default: - mapped_event->absolute.value = 0; - - break; - } - - break; - case EV_KEY: - signal = pressed ? SIG_BUTTON_PRESS_EVENT : SIG_BUTTON_RELEASE_EVENT; - mapped_event->any.type = pressed ? MANETTE_EVENT_BUTTON_PRESS : - MANETTE_EVENT_BUTTON_RELEASE; - mapped_event->button.button = binding->destination.code; - - break; - default: - manette_event_free (mapped_event); - - return; - } - - emit_event_signal_deferred (self, signals[signal], mapped_event); - - manette_event_free (mapped_event); - } -} - -static void -map_hat_event (ManetteDevice *self, - ManetteEventHat *event) -{ - const ManetteMappingBinding * const *bindings; - const ManetteMappingBinding * binding; - ManetteEvent *mapped_event; - guint signal; - gboolean pressed; - - bindings = manette_mapping_get_bindings (self->mapping, - MANETTE_MAPPING_INPUT_TYPE_HAT, - event->hardware_index); - if (bindings == NULL) - return; - - for (; *bindings != NULL; bindings++) { - binding = *bindings; - - if (binding->source.range == MANETTE_MAPPING_RANGE_NEGATIVE && - event->value > 0) - continue; - - if (binding->source.range == MANETTE_MAPPING_RANGE_POSITIVE && - event->value < 0) - continue; - - mapped_event = manette_event_copy ((ManetteEvent *) event); - - pressed = abs (event->value); - - switch (binding->destination.type) { - case EV_ABS: - signal = SIG_ABSOLUTE_AXIS_EVENT; - mapped_event->any.type = MANETTE_EVENT_ABSOLUTE; - mapped_event->absolute.axis = binding->destination.code; - mapped_event->absolute.value = abs (event->value); - - break; - case EV_KEY: - signal = pressed ? SIG_BUTTON_PRESS_EVENT : SIG_BUTTON_RELEASE_EVENT; - mapped_event->any.type = pressed ? MANETTE_EVENT_BUTTON_PRESS : - MANETTE_EVENT_BUTTON_RELEASE; - mapped_event->button.button = binding->destination.code; - - break; - default: - manette_event_free (mapped_event); - - return; - } - - emit_event_signal_deferred (self, signals[signal], mapped_event); + guint signal = event_type_to_signal (manette_event_get_event_type (event)); - manette_event_free (mapped_event); - } + if (signal != N_SIGNALS) + emit_event_signal_deferred (self, signals[signal], event); } static void map_event (ManetteDevice *self, - ManetteEvent *event) + ManetteEvent *event) { - switch (manette_event_get_event_type (event)) { - case MANETTE_EVENT_BUTTON_PRESS: - case MANETTE_EVENT_BUTTON_RELEASE: - map_button_event (self, &event->button); - - break; - case MANETTE_EVENT_ABSOLUTE: - map_absolute_event (self, &event->absolute); + GSList *mapped_events = manette_map_event (self->mapping, event); + GSList *l = NULL; - break; - case MANETTE_EVENT_HAT: - map_hat_event (self, &event->hat); + for (l = mapped_events; l != NULL; l = l ->next) + forward_event (self, l->data); - break; - default: - break; - } + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); } static void @@ -592,7 +385,6 @@ centered_absolute_value (struct input_absinfo *abs_info, gint32 value) { - gint64 min_absolute; gint64 max_normalized; gint64 value_normalized; gint64 max_centered; @@ -601,14 +393,16 @@ g_return_val_if_fail (abs_info != NULL, 0.0); - min_absolute = llabs ((gint64) abs_info->minimum); - - max_normalized = ((gint64) abs_info->maximum) + min_absolute; - value_normalized = ((gint64) value) + min_absolute; + /* Adapt the value and the maximum to a minimum of 0. */ + max_normalized = ((gint64) abs_info->maximum) - abs_info->minimum; + value_normalized = ((gint64) value) - abs_info->minimum; max_centered = max_normalized / 2; value_centered = (value_normalized - max_normalized) + max_centered; + if (value_centered > -abs_info->flat && value_centered < abs_info->flat) + value_centered = 0; + divisor = value_centered < 0 ? max_centered + 1 : max_centered;; return ((gdouble) value_centered) / ((gdouble) divisor); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libmanette-0.2.1/src/manette-event-mapping-private.h new/libmanette-0.2.2/src/manette-event-mapping-private.h --- old/libmanette-0.2.1/src/manette-event-mapping-private.h 1970-01-01 01:00:00.000000000 +0100 +++ new/libmanette-0.2.2/src/manette-event-mapping-private.h 2019-03-11 10:04:16.000000000 +0100 @@ -0,0 +1,36 @@ +/* manette-event-mapping-private.h + * + * Copyright (C) 2018 Adrien Plazas <[email protected]> + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MANETTE_EVENT_MAPPING_PRIVATE_H +#define MANETTE_EVENT_MAPPING_PRIVATE_H + +#if !defined(MANETTE_COMPILATION) +# error "This file is private, only <libmanette.h> can be included directly." +#endif + +#include "manette-event.h" +#include "manette-mapping.h" + +G_BEGIN_DECLS + +GSList *manette_map_event (ManetteMapping *mapping, + ManetteEvent *event); + +G_END_DECLS + +#endif /* MANETTE_EVENT_MAPPING_PRIVATE_H */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libmanette-0.2.1/src/manette-event-mapping.c new/libmanette-0.2.2/src/manette-event-mapping.c --- old/libmanette-0.2.1/src/manette-event-mapping.c 1970-01-01 01:00:00.000000000 +0100 +++ new/libmanette-0.2.2/src/manette-event-mapping.c 2019-03-11 10:04:16.000000000 +0100 @@ -0,0 +1,236 @@ +/* manette-event-mapping.c + * + * Copyright (C) 2018 Adrien Plazas <[email protected]> + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "manette-event-mapping-private.h" + +#include <linux/input-event-codes.h> +#include "manette-event-private.h" + +static GSList * +map_button_event (ManetteMapping *mapping, + ManetteEventButton *event) +{ + const ManetteMappingBinding * const *bindings; + const ManetteMappingBinding * binding; + GSList *mapped_events = NULL; + ManetteEvent *mapped_event; + gboolean pressed; + + bindings = manette_mapping_get_bindings (mapping, + MANETTE_MAPPING_INPUT_TYPE_BUTTON, + event->hardware_index); + if (bindings == NULL) + return NULL; + + for (; *bindings != NULL; bindings++) { + binding = *bindings; + + mapped_event = manette_event_copy ((ManetteEvent *) event); + + pressed = event->type == MANETTE_EVENT_BUTTON_PRESS; + + switch (binding->destination.type) { + case EV_ABS: + mapped_event->any.type = MANETTE_EVENT_ABSOLUTE; + mapped_event->absolute.axis = binding->destination.code; + switch (binding->destination.range) { + case MANETTE_MAPPING_RANGE_NEGATIVE: + mapped_event->absolute.value = pressed ? -1 : 0; + + break; + case MANETTE_MAPPING_RANGE_FULL: + case MANETTE_MAPPING_RANGE_POSITIVE: + mapped_event->absolute.value = pressed ? 1 : 0; + + break; + default: + mapped_event->absolute.value = 0; + + break; + } + + break; + case EV_KEY: + mapped_event->any.type = pressed ? MANETTE_EVENT_BUTTON_PRESS : + MANETTE_EVENT_BUTTON_RELEASE; + mapped_event->button.button = binding->destination.code; + + break; + default: + manette_event_free (mapped_event); + + continue; + } + + mapped_events = g_slist_append (mapped_events, mapped_event); + } + + return mapped_events; +} + +static GSList * +map_absolute_event (ManetteMapping *mapping, + ManetteEventAbsolute *event) +{ + const ManetteMappingBinding * const *bindings; + const ManetteMappingBinding * binding; + GSList *mapped_events = NULL; + ManetteEvent *mapped_event; + gdouble absolute_value; + gboolean pressed; + + bindings = manette_mapping_get_bindings (mapping, + MANETTE_MAPPING_INPUT_TYPE_AXIS, + event->hardware_index); + if (bindings == NULL) + return NULL; + + for (; *bindings != NULL; bindings++) { + binding = *bindings; + + if (binding->source.range == MANETTE_MAPPING_RANGE_NEGATIVE && + event->value > 0.) + continue; + + if (binding->source.range == MANETTE_MAPPING_RANGE_POSITIVE && + event->value < 0.) + continue; + + mapped_event = manette_event_copy ((ManetteEvent *) event); + + switch (binding->destination.type) { + case EV_ABS: + absolute_value = binding->source.invert ? -event->value : event->value; + + mapped_event->any.type = MANETTE_EVENT_ABSOLUTE; + mapped_event->absolute.axis = binding->destination.code; + switch (binding->destination.range) { + case MANETTE_MAPPING_RANGE_FULL: + mapped_event->absolute.value = absolute_value; + + break; + case MANETTE_MAPPING_RANGE_NEGATIVE: + mapped_event->absolute.value = (absolute_value / 2) - 1; + + break; + case MANETTE_MAPPING_RANGE_POSITIVE: + mapped_event->absolute.value = (absolute_value / 2) + 1; + + break; + default: + break; + } + + break; + case EV_KEY: + if (binding->source.range == MANETTE_MAPPING_RANGE_FULL) + pressed = binding->source.invert ? event->value < 0. : + event->value > 0.; + else + pressed = binding->source.invert ? event->value == 0. : + event->value != 0.; + + mapped_event->any.type = pressed ? MANETTE_EVENT_BUTTON_PRESS : + MANETTE_EVENT_BUTTON_RELEASE; + mapped_event->button.button = binding->destination.code; + + break; + default: + manette_event_free (mapped_event); + + continue; + } + + mapped_events = g_slist_append (mapped_events, mapped_event); + } + + return mapped_events; +} + +static GSList * +map_hat_event (ManetteMapping *mapping, + ManetteEventHat *event) +{ + const ManetteMappingBinding * const *bindings; + const ManetteMappingBinding * binding; + GSList *mapped_events = NULL; + ManetteEvent *mapped_event; + gboolean pressed; + + bindings = manette_mapping_get_bindings (mapping, + MANETTE_MAPPING_INPUT_TYPE_HAT, + event->hardware_index); + if (bindings == NULL) + return NULL; + + for (; *bindings != NULL; bindings++) { + binding = *bindings; + + if (binding->source.range == MANETTE_MAPPING_RANGE_NEGATIVE && + event->value > 0) + continue; + + if (binding->source.range == MANETTE_MAPPING_RANGE_POSITIVE && + event->value < 0) + continue; + + mapped_event = manette_event_copy ((ManetteEvent *) event); + + pressed = abs (event->value); + + switch (binding->destination.type) { + case EV_ABS: + mapped_event->any.type = MANETTE_EVENT_ABSOLUTE; + mapped_event->absolute.axis = binding->destination.code; + mapped_event->absolute.value = abs (event->value); + + break; + case EV_KEY: + mapped_event->any.type = pressed ? MANETTE_EVENT_BUTTON_PRESS : + MANETTE_EVENT_BUTTON_RELEASE; + mapped_event->button.button = binding->destination.code; + + break; + default: + manette_event_free (mapped_event); + + continue; + } + + mapped_events = g_slist_append (mapped_events, mapped_event); + } + + return mapped_events; +} + +GSList * +manette_map_event (ManetteMapping *mapping, + ManetteEvent *event) +{ + switch (manette_event_get_event_type (event)) { + case MANETTE_EVENT_BUTTON_PRESS: + case MANETTE_EVENT_BUTTON_RELEASE: + return map_button_event (mapping, &event->button); + case MANETTE_EVENT_ABSOLUTE: + return map_absolute_event (mapping, &event->absolute); + case MANETTE_EVENT_HAT: + return map_hat_event (mapping, &event->hat); + default: + return NULL; + } +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libmanette-0.2.1/src/manette-event.c new/libmanette-0.2.2/src/manette-event.c --- old/libmanette-0.2.1/src/manette-event.c 2018-07-30 10:44:57.000000000 +0200 +++ new/libmanette-0.2.2/src/manette-event.c 2019-03-11 10:04:16.000000000 +0100 @@ -56,7 +56,8 @@ copy = manette_event_new (); memcpy(copy, self, sizeof (ManetteEvent)); - copy->any.device = g_object_ref (self->any.device); + if (self->any.device != NULL) + copy->any.device = g_object_ref (self->any.device); return copy; } @@ -72,7 +73,8 @@ { g_return_if_fail (self); - g_object_unref (self->any.device); + if (self->any.device != NULL) + g_object_unref (self->any.device); g_slice_free (ManetteEvent, self); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libmanette-0.2.1/src/meson.build new/libmanette-0.2.2/src/meson.build --- old/libmanette-0.2.1/src/meson.build 2018-07-30 10:44:57.000000000 +0200 +++ new/libmanette-0.2.2/src/meson.build 2019-03-11 10:04:16.000000000 +0100 @@ -13,6 +13,7 @@ libmanette_resources[0], 'manette-device.c', 'manette-event.c', + 'manette-event-mapping.c', 'manette-mapping.c', 'manette-mapping-manager.c', 'manette-mapping-error.c', diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libmanette-0.2.1/tests/meson.build new/libmanette-0.2.2/tests/meson.build --- old/libmanette-0.2.1/tests/meson.build 2018-07-30 10:44:57.000000000 +0200 +++ new/libmanette-0.2.2/tests/meson.build 2019-03-11 10:04:16.000000000 +0100 @@ -1,4 +1,5 @@ tests = [ + ['ManetteEventMapping', 'test-event-mapping'], ['ManetteMapping', 'test-mapping'], ['ManetteMappingManager', 'test-mapping-manager'], ] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libmanette-0.2.1/tests/test-event-mapping.c new/libmanette-0.2.2/tests/test-event-mapping.c --- old/libmanette-0.2.1/tests/test-event-mapping.c 1970-01-01 01:00:00.000000000 +0100 +++ new/libmanette-0.2.2/tests/test-event-mapping.c 2019-03-11 10:04:16.000000000 +0100 @@ -0,0 +1,470 @@ +/* test-event-mapping.c + * + * Copyright (C) 2018 Adrien Plazas <[email protected]> + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <linux/input-event-codes.h> +#include "../src/manette-event-mapping-private.h" +#include "../src/manette-event-private.h" + +#define MAPPING_EMPTY "00000000000000000000000000000000,empty," +#define MAPPING_BUTTON "00000000000000000000000000000000,button,a:b0,b:b1,x:b2,y:b3," +#define MAPPING_AXIS "00000000000000000000000000000000,axis,leftx:a0,lefty:a1,-rightx:-a2,+rightx:+a2,-righty:+a3~,+righty:-a3~," +#define MAPPING_HAT "00000000000000000000000000000000,hat,dpleft:h0.8,dpright:h0.2,dpup:h0.1,dpdown:h0.4," +#define MAPPING_AXIS_DPAD "00000000000000000000000000000000,button,dpleft:-a0,dpright:+a0,dpup:-a1,dpdown:+a1," +#define MAPPING_AXIS_TRIGGER "00000000000000000000000000000000,trigger,lefttrigger:a0,righttrigger:a1," + +#define DUMMY_TIMESTAMP 0x76543210 + +static void +cmp_event_any_except_type (ManetteEvent *event1, + ManetteEvent *event2) +{ + g_assert_cmpint (event1->any.time, ==, event2->any.time); + g_assert (event1->any.device == event2->any.device); + g_assert_cmpuint (event1->any.hardware_type, ==, event2->any.hardware_type); + g_assert_cmpuint (event1->any.hardware_code, ==, event2->any.hardware_code); + g_assert_cmpint (event1->any.hardware_value, ==, event2->any.hardware_value); + g_assert_cmpuint (event1->any.hardware_index, ==, event2->any.hardware_index); +} + +static void +test_null (void) +{ + ManetteMapping *mapping; + GError *error = NULL; + + mapping = manette_mapping_new (NULL, &error); + g_assert_error (error, + MANETTE_MAPPING_ERROR, + MANETTE_MAPPING_ERROR_NOT_A_MAPPING); + g_error_free (error); + + g_assert_null (mapping); +} + +static void +test_empty_mapping (void) +{ + ManetteMapping *mapping; + ManetteEvent event = {}; + GSList *mapped_events; + GError *error = NULL; + + mapping = manette_mapping_new (MAPPING_EMPTY, &error); + g_assert_no_error (error); + g_assert_nonnull (mapping); + g_assert_true (MANETTE_IS_MAPPING (mapping)); + + event.any.type = MANETTE_EVENT_BUTTON_PRESS; + event.any.time = DUMMY_TIMESTAMP; + event.any.hardware_type = EV_KEY; + event.any.hardware_code = BTN_SOUTH; + event.any.hardware_value = G_MAXINT; + event.any.hardware_index = 0; + event.button.button = 0; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 0); + + g_object_unref (mapping); +} + +static void +test_button_mapping (void) +{ + ManetteMapping *mapping; + ManetteEvent event = {}; + GSList *mapped_events; + ManetteEvent *mapped_event; + GError *error = NULL; + + mapping = manette_mapping_new (MAPPING_BUTTON, &error); + g_assert_no_error (error); + g_assert_nonnull (mapping); + g_assert_true (MANETTE_IS_MAPPING (mapping)); + + event.any.type = MANETTE_EVENT_BUTTON_PRESS; + event.any.time = DUMMY_TIMESTAMP; + event.any.hardware_type = EV_KEY; + event.any.hardware_code = BTN_SOUTH; + event.any.hardware_value = G_MAXINT; + event.any.hardware_index = 0; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 1); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_PRESS); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_SOUTH); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + g_object_unref (mapping); +} + +static void +test_axis_mapping (void) +{ + ManetteMapping *mapping; + ManetteEvent event = {}; + GSList *mapped_events; + ManetteEvent *mapped_event; + GError *error = NULL; + + mapping = manette_mapping_new (MAPPING_AXIS, &error); + g_assert_no_error (error); + g_assert_nonnull (mapping); + g_assert_true (MANETTE_IS_MAPPING (mapping)); + + event.any.type = MANETTE_EVENT_ABSOLUTE; + event.any.time = DUMMY_TIMESTAMP; + event.any.hardware_type = EV_ABS; + event.any.hardware_code = ABS_X; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 1); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_ABSOLUTE); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->absolute.axis, ==, ABS_X); + g_assert_cmpfloat (mapped_event->absolute.value, ==, 0); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + event.any.type = MANETTE_EVENT_ABSOLUTE; + event.any.time = DUMMY_TIMESTAMP; + event.any.hardware_type = EV_ABS; + event.any.hardware_code = ABS_Y; + event.any.hardware_index = 1; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 1); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_ABSOLUTE); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->absolute.axis, ==, ABS_Y); + g_assert_cmpfloat (mapped_event->absolute.value, ==, 0); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + g_object_unref (mapping); +} + +static void +test_hat_mapping (void) +{ + ManetteMapping *mapping; + ManetteEvent event = {}; + GSList *mapped_events; + ManetteEvent *mapped_event; + GError *error = NULL; + + mapping = manette_mapping_new (MAPPING_HAT, &error); + g_assert_no_error (error); + g_assert_nonnull (mapping); + g_assert_true (MANETTE_IS_MAPPING (mapping)); + + event.any.type = MANETTE_EVENT_HAT; + event.any.time = DUMMY_TIMESTAMP; + event.any.hardware_type = EV_ABS; + event.any.hardware_code = ABS_HAT0X; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 2); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_RELEASE); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_DPAD_LEFT); + + mapped_event = mapped_events->next->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_RELEASE); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_DPAD_RIGHT); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + event.hat.value = -1; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 1); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_PRESS); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_DPAD_LEFT); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + event.hat.value = 1; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 1); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_PRESS); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_DPAD_RIGHT); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + g_object_unref (mapping); +} + +static void +test_axis_dpad_mapping (void) +{ + ManetteMapping *mapping; + ManetteEvent event = {}; + GSList *mapped_events; + ManetteEvent *mapped_event; + GError *error = NULL; + + mapping = manette_mapping_new (MAPPING_AXIS_DPAD, &error); + g_assert_no_error (error); + g_assert_nonnull (mapping); + g_assert_true (MANETTE_IS_MAPPING (mapping)); + + event.any.type = MANETTE_EVENT_ABSOLUTE; + event.any.time = DUMMY_TIMESTAMP; + event.any.hardware_type = EV_ABS; + event.any.hardware_code = ABS_X; + event.any.hardware_index = 0; + event.absolute.axis = ABS_RX; + event.absolute.value = 0.0; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 2); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_RELEASE); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_DPAD_LEFT); + + mapped_event = mapped_events->next->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_RELEASE); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_DPAD_RIGHT); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + event.any.type = MANETTE_EVENT_ABSOLUTE; + event.any.time = DUMMY_TIMESTAMP; + event.any.hardware_type = EV_ABS; + event.any.hardware_code = ABS_X; + event.any.hardware_index = 0; + event.absolute.axis = ABS_RX; + event.absolute.value = -1.0; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 1); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_PRESS); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_DPAD_LEFT); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + event.any.type = MANETTE_EVENT_ABSOLUTE; + event.any.time = DUMMY_TIMESTAMP; + event.any.hardware_type = EV_ABS; + event.any.hardware_code = ABS_X; + event.any.hardware_index = 0; + event.absolute.axis = ABS_RX; + event.absolute.value = 1.0; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 1); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_PRESS); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_DPAD_RIGHT); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + event.any.type = MANETTE_EVENT_ABSOLUTE; + event.any.time = DUMMY_TIMESTAMP; + event.any.hardware_type = EV_ABS; + event.any.hardware_code = ABS_Y; + event.any.hardware_index = 1; + event.absolute.axis = ABS_RY; + event.absolute.value = 0.0; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 2); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_RELEASE); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_DPAD_UP); + + mapped_event = mapped_events->next->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_RELEASE); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_DPAD_DOWN); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + event.any.type = MANETTE_EVENT_ABSOLUTE; + event.any.time = DUMMY_TIMESTAMP; + event.any.hardware_type = EV_ABS; + event.any.hardware_code = ABS_Y; + event.any.hardware_index = 1; + event.absolute.axis = ABS_RY; + event.absolute.value = -1.0; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 1); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_PRESS); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_DPAD_UP); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + event.any.type = MANETTE_EVENT_ABSOLUTE; + event.any.time = DUMMY_TIMESTAMP; + event.any.hardware_type = EV_ABS; + event.any.hardware_code = ABS_Y; + event.any.hardware_index = 1; + event.absolute.axis = ABS_RY; + event.absolute.value = 1.0; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 1); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_PRESS); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_DPAD_DOWN); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + g_object_unref (mapping); +} + +static void +test_axis_trigger_mapping (void) +{ + ManetteMapping *mapping; + ManetteEvent event = {}; + GSList *mapped_events; + ManetteEvent *mapped_event; + GError *error = NULL; + + mapping = manette_mapping_new (MAPPING_AXIS_TRIGGER, &error); + g_assert_no_error (error); + g_assert_nonnull (mapping); + g_assert_true (MANETTE_IS_MAPPING (mapping)); + + event.any.type = MANETTE_EVENT_ABSOLUTE; + event.any.time = DUMMY_TIMESTAMP; + event.any.hardware_type = EV_ABS; + event.any.hardware_code = ABS_X; + event.any.hardware_index = 0; + event.absolute.axis = ABS_RX; + event.absolute.value = 1.0; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 1); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_PRESS); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_TL2); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + event.any.type = MANETTE_EVENT_ABSOLUTE; + event.any.time = DUMMY_TIMESTAMP; + event.any.hardware_type = EV_ABS; + event.any.hardware_code = ABS_X; + event.any.hardware_index = 0; + event.absolute.axis = ABS_RX; + event.absolute.value = -1.0; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 1); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_RELEASE); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_TL2); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + event.any.type = MANETTE_EVENT_ABSOLUTE; + event.any.time = DUMMY_TIMESTAMP; + event.any.hardware_type = EV_ABS; + event.any.hardware_code = ABS_Y; + event.any.hardware_index = 1; + event.absolute.axis = ABS_RY; + event.absolute.value = 1.0; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 1); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_PRESS); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_TR2); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + event.any.type = MANETTE_EVENT_ABSOLUTE; + event.any.time = DUMMY_TIMESTAMP; + event.any.hardware_type = EV_ABS; + event.any.hardware_code = ABS_Y; + event.any.hardware_index = 1; + event.absolute.axis = ABS_RY; + event.absolute.value = -1.0; + + mapped_events = manette_map_event (mapping, &event); + g_assert_cmpint (g_slist_length (mapped_events), ==, 1); + + mapped_event = mapped_events->data; + g_assert_cmpint (mapped_event->any.type, ==, MANETTE_EVENT_BUTTON_RELEASE); + cmp_event_any_except_type (mapped_event, &event); + g_assert_cmpuint (mapped_event->button.button, ==, BTN_TR2); + + g_slist_free_full (mapped_events, (GDestroyNotify) manette_event_free); + + g_object_unref (mapping); +} + +int +main (int argc, + char *argv[]) +{ + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/ManetteEventMapping/test_null", test_null); + g_test_add_func ("/ManetteEventMapping/test_empty_mapping", test_empty_mapping); + g_test_add_func ("/ManetteEventMapping/test_button_mapping", test_button_mapping); + g_test_add_func ("/ManetteEventMapping/test_axis_mapping", test_axis_mapping); + g_test_add_func ("/ManetteEventMapping/test_hat_mapping", test_hat_mapping); + g_test_add_func ("/ManetteEventMapping/test_axis_dpad_mapping", test_axis_dpad_mapping); + g_test_add_func ("/ManetteEventMapping/test_axis_trigger_mapping", test_axis_trigger_mapping); + + return g_test_run(); +}
