Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input event with origin #550

Merged
merged 37 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
fdbe5d4
Update InputEvent to include origin and analog threshold
jonasBoss Nov 20, 2022
4738843
preset save file migration
jonasBoss Nov 20, 2022
df386bd
Merge branch 'beta' into input-event-with-origin
jonasBoss Nov 21, 2022
5b321f0
Use the InputEvent.analog_threshold field instead of value
jonasBoss Nov 22, 2022
fb1d407
Merge branch 'beta' into input-event-with-origin
jonasBoss Nov 24, 2022
56501b8
Make tests start in pycharm again
jonasBoss Nov 24, 2022
2fadc1f
Seperate InputEvent and InputConfiguration
jonasBoss Nov 24, 2022
db652a5
integration tests
jonasBoss Nov 26, 2022
3f6e81d
simplyfied InputEvent
jonasBoss Nov 26, 2022
af96ce1
move find_analog_input_event to InputCombination
jonasBoss Nov 26, 2022
53f2a49
rename InputConfiguration to InputConfig
jonasBoss Nov 26, 2022
b41bcce
move input_configuration.py to configs/input_config.py
jonasBoss Nov 26, 2022
0b88d79
simplified imports
jonasBoss Nov 26, 2022
e76c30b
rename event_combination to input_combination
jonasBoss Nov 26, 2022
705d97b
mypy
jonasBoss Dec 1, 2022
e518a05
use event origin information
jonasBoss Dec 2, 2022
0f724e4
fix reader-service and use md5 hashing
jonasBoss Dec 2, 2022
fc95635
Updated Mapping handlers
jonasBoss Dec 2, 2022
9da39c6
Updated Tests
jonasBoss Dec 2, 2022
2f168a1
Merge branch 'beta' into input-event-with-origin
jonasBoss Dec 6, 2022
11dce4c
fix test_injector
jonasBoss Dec 6, 2022
b7ca337
mypy
jonasBoss Dec 6, 2022
d67dd32
integration tests
jonasBoss Dec 7, 2022
c3b30cf
added unit tests
jonasBoss Dec 9, 2022
e5f0159
usage.md
jonasBoss Dec 10, 2022
9af4a59
refactor injector grab deviece logic
jonasBoss Dec 11, 2022
6c1d8f9
InputConfig docstring
jonasBoss Dec 11, 2022
6067285
refactor migrations._input_combination_from_string
jonasBoss Dec 11, 2022
f94e5e7
amend
jonasBoss Dec 11, 2022
61fe702
refactor temprary preset migration
jonasBoss Dec 11, 2022
5943fd0
made notify_callbacks private
jonasBoss Dec 12, 2022
925ffad
constrain origin to lowercase
jonasBoss Dec 12, 2022
7639422
tabs 'n spaces
jonasBoss Dec 12, 2022
7010955
mypy
jonasBoss Dec 12, 2022
aa3d868
mypy
jonasBoss Dec 13, 2022
699a6f8
Signal no longer inherits Message protocol
jonasBoss Dec 13, 2022
a1d1641
rename origin to origin_hash
jonasBoss Dec 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename InputConfiguration to InputConfig
  • Loading branch information
jonasBoss committed Nov 26, 2022
commit 53f2a496b44f64d1fa020d2320e2065728f1b90d
2 changes: 1 addition & 1 deletion inputremapper/configs/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
)

from inputremapper.configs.system_mapping import system_mapping, DISABLE_NAME
from inputremapper.input_configuration import InputCombination, InputConfiguration
from inputremapper.input_configuration import InputCombination, InputConfig
from inputremapper.exceptions import MacroParsingError
from inputremapper.gui.gettext import _
from inputremapper.gui.messages.message_types import MessageType
Expand Down
18 changes: 9 additions & 9 deletions inputremapper/configs/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from inputremapper.configs.paths import get_preset_path, mkdir, CONFIG_PATH, remove
from inputremapper.configs.preset import Preset
from inputremapper.configs.system_mapping import system_mapping
from inputremapper.input_configuration import InputCombination, InputConfiguration
from inputremapper.input_configuration import InputCombination, InputConfig
from inputremapper.injection.global_uinputs import global_uinputs
from inputremapper.injection.macros.parse import is_this_a_macro
from inputremapper.logger import logger, VERSION, IS_BETA
Expand Down Expand Up @@ -355,10 +355,10 @@ def _convert_to_individual_mappings():
x_config = cfg.copy()
y_config = cfg.copy()
x_config["event_combination"] = InputCombination(
InputConfiguration(type=EV_ABS, code=ABS_X)
InputConfig(type=EV_ABS, code=ABS_X)
)
y_config["event_combination"] = InputCombination(
InputConfiguration(type=EV_ABS, code=ABS_Y)
InputConfig(type=EV_ABS, code=ABS_Y)
)
x_config["output_code"] = REL_X
y_config["output_code"] = REL_Y
Expand All @@ -374,10 +374,10 @@ def _convert_to_individual_mappings():
x_config = cfg.copy()
y_config = cfg.copy()
x_config["event_combination"] = InputCombination(
InputConfiguration(type=EV_ABS, code=ABS_RX)
InputConfig(type=EV_ABS, code=ABS_RX)
)
y_config["event_combination"] = InputCombination(
InputConfiguration(type=EV_ABS, code=ABS_RY)
InputConfig(type=EV_ABS, code=ABS_RY)
)
x_config["output_code"] = REL_X
y_config["output_code"] = REL_Y
Expand All @@ -393,10 +393,10 @@ def _convert_to_individual_mappings():
x_config = cfg.copy()
y_config = cfg.copy()
x_config["event_combination"] = InputCombination(
InputConfiguration(type=EV_ABS, code=ABS_X)
InputConfig(type=EV_ABS, code=ABS_X)
)
y_config["event_combination"] = InputCombination(
InputConfiguration(type=EV_ABS, code=ABS_Y)
InputConfig(type=EV_ABS, code=ABS_Y)
)
x_config["output_code"] = REL_HWHEEL_HI_RES
y_config["output_code"] = REL_WHEEL_HI_RES
Expand All @@ -413,10 +413,10 @@ def _convert_to_individual_mappings():
x_config = cfg.copy()
y_config = cfg.copy()
x_config["event_combination"] = InputCombination(
InputConfiguration(type=EV_ABS, code=ABS_RX)
InputConfig(type=EV_ABS, code=ABS_RX)
)
y_config["event_combination"] = InputCombination(
InputConfiguration(type=EV_ABS, code=ABS_RY)
InputConfig(type=EV_ABS, code=ABS_RY)
)
x_config["output_code"] = REL_HWHEEL_HI_RES
y_config["output_code"] = REL_WHEEL_HI_RES
Expand Down
6 changes: 3 additions & 3 deletions inputremapper/configs/preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from inputremapper.configs.paths import touch

from inputremapper.input_event import InputEvent
from inputremapper.input_configuration import InputCombination, InputConfiguration
from inputremapper.input_configuration import InputCombination, InputConfig

MappingModel = TypeVar("MappingModel", bound=UIMapping)

Expand Down Expand Up @@ -242,7 +242,7 @@ def get_mapping(

def dangerously_mapped_btn_left(self) -> bool:
"""Return True if this mapping disables BTN_Left."""
if InputCombination(InputConfiguration.btn_left()) not in [
if InputCombination(InputConfig.btn_left()) not in [
m.event_combination for m in self
]:
return False
Expand All @@ -256,7 +256,7 @@ def dangerously_mapped_btn_left(self) -> bool:

return (
"btn_left" not in values
or InputConfiguration.btn_left().type_and_code not in values
or InputConfig.btn_left().type_and_code not in values
)

def _combination_changed_callback(
Expand Down
12 changes: 6 additions & 6 deletions inputremapper/gui/components/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from gi.repository import Gtk, GtkSource, Gdk

from inputremapper.configs.mapping import MappingData
from inputremapper.input_configuration import InputCombination, InputConfiguration
from inputremapper.input_configuration import InputCombination, InputConfig
from inputremapper.groups import DeviceType
from inputremapper.gui.controller import Controller
from inputremapper.gui.gettext import _
Expand Down Expand Up @@ -658,7 +658,7 @@ class InputConfigEntry(Gtk.ListBoxRow):

__gtype_name__ = "InputConfigEntry"

def __init__(self, event: InputConfiguration, controller: Controller):
def __init__(self, event: InputConfig, controller: Controller):
super().__init__()

self.input_event = event
Expand Down Expand Up @@ -778,12 +778,12 @@ def __init__(
self._message_broker = message_broker
self._controller = controller
self._gui = gui
self._input_config: Optional[InputConfiguration] = None
self._input_config: Optional[InputConfig] = None

self._gui.connect("state-set", self._on_gtk_toggle)
self._message_broker.subscribe(MessageType.selected_event, self._on_event)

def _on_event(self, input_cfg: InputConfiguration):
def _on_event(self, input_cfg: InputConfig):
with HandlerDisabled(self._gui, self._on_gtk_toggle):
self._gui.set_active(input_cfg.defines_analog_input)
self._input_config = input_cfg
Expand Down Expand Up @@ -812,13 +812,13 @@ def __init__(
self._message_broker = message_broker
self._controller = controller
self._gui = gui
self._input_config: Optional[InputConfiguration] = None
self._input_config: Optional[InputConfig] = None

self._gui.set_increments(1, 1)
self._gui.connect("value-changed", self._on_gtk_changed)
self._message_broker.subscribe(MessageType.selected_event, self._on_event)

def _on_event(self, input_config: InputConfiguration):
def _on_event(self, input_config: InputConfig):
if input_config.type == EV_KEY:
self._gui.set_sensitive(False)
self._gui.set_opacity(0.5)
Expand Down
16 changes: 8 additions & 8 deletions inputremapper/gui/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

from inputremapper.configs.mapping import MappingData, UIMapping
from inputremapper.configs.paths import sanitize_path_component
from inputremapper.input_configuration import InputCombination, InputConfiguration
from inputremapper.input_configuration import InputCombination, InputConfig
from inputremapper.exceptions import DataManagementError
from inputremapper.gui.data_manager import DataManager, DEFAULT_PRESET_NAME
from inputremapper.gui.gettext import _
Expand Down Expand Up @@ -268,7 +268,7 @@ def update_combination(self, combination: InputCombination):

def move_input_config_in_combination(
self,
input_config: InputConfiguration,
input_config: InputConfig,
direction: Union[Literal["up"], Literal["down"]],
):
"""Move the active_input_config up or down in the event_combination of the
Expand All @@ -279,7 +279,7 @@ def move_input_config_in_combination(
):
return
combination: Sequence[
InputConfiguration
InputConfig
] = self.data_manager.active_mapping.event_combination

i = combination.index(input_config)
Expand Down Expand Up @@ -310,11 +310,11 @@ def move_input_config_in_combination(
self.update_combination(InputCombination(combination))
self.load_input_config(input_config)

def load_input_config(self, input_config: InputConfiguration):
"""Load an InputConfiguration form the active mapping input combination."""
def load_input_config(self, input_config: InputConfig):
"""Load an InputConfig form the active mapping input combination."""
self.data_manager.load_input_config(input_config)

def update_input_config(self, new_input_config: InputConfiguration):
def update_input_config(self, new_input_config: InputConfig):
"""Modify the active input configuration."""
try:
self.data_manager.update_input_config(new_input_config)
Expand Down Expand Up @@ -561,7 +561,7 @@ def show_injector_result(self, msg: InjectorStateMessage):
def running():
msg = _("Applied preset %s") % self.data_manager.active_preset.name
if self.data_manager.active_preset.get_mapping(
InputCombination(InputConfiguration.btn_left())
InputCombination(InputConfig.btn_left())
):
msg += _(", CTRL + DEL to stop")
self.show_status(CTX_APPLY, msg)
Expand Down Expand Up @@ -675,7 +675,7 @@ def _change_mapping_type(self, kwargs):
if input_config.defines_analog_input
]:
# there is no analog input configured, let's try to autoconfigure it
inputs: List[InputConfiguration] = list(mapping.event_combination)
inputs: List[InputConfig] = list(mapping.event_combination)
for i, e in enumerate(inputs):
if e.type in [EV_ABS, EV_REL]:
inputs[i] = e.modify(analog_threshold=0)
Expand Down
12 changes: 6 additions & 6 deletions inputremapper/gui/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from inputremapper.configs.preset import Preset
from inputremapper.configs.system_mapping import SystemMapping
from inputremapper.daemon import DaemonProxy
from inputremapper.input_configuration import InputCombination, InputConfiguration
from inputremapper.input_configuration import InputCombination, InputConfig
from inputremapper.exceptions import DataManagementError
from inputremapper.gui.gettext import _
from inputremapper.groups import _Group
Expand Down Expand Up @@ -91,7 +91,7 @@ def __init__(

self._active_preset: Optional[Preset[UIMapping]] = None
self._active_mapping: Optional[UIMapping] = None
self._active_input_config: Optional[InputConfiguration] = None
self._active_input_config: Optional[InputConfig] = None

def publish_group(self):
"""Send active group to the MessageBroker.
Expand Down Expand Up @@ -176,7 +176,7 @@ def active_mapping(self) -> Optional[UIMapping]:
return self._active_mapping

@property
def active_input_config(self) -> Optional[InputConfiguration]:
def active_input_config(self) -> Optional[InputConfig]:
"""The currently loaded event."""
return self._active_input_config

Expand Down Expand Up @@ -340,8 +340,8 @@ def load_mapping(self, combination: InputCombination):
self._active_mapping = mapping
self.publish_mapping()

def load_input_config(self, input_config: InputConfiguration):
"""Load a InputConfiguration from the combination in the active mapping.
def load_input_config(self, input_config: InputConfig):
"""Load a InputConfig from the combination in the active mapping.

Will send "event" message on the MessageBroker,
"""
Expand Down Expand Up @@ -469,7 +469,7 @@ def update_mapping(self, **kwargs):

self.publish_mapping()

def update_input_config(self, new_input_config: InputConfiguration):
def update_input_config(self, new_input_config: InputConfig):
"""Update the active input configuration.

Will send "combination_update", "mapping" and "event" messages to the
Expand Down
26 changes: 9 additions & 17 deletions inputremapper/gui/reader_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from evdev.ecodes import EV_KEY, EV_ABS, EV_REL, REL_HWHEEL, REL_WHEEL

from inputremapper.configs.mapping import UIMapping
from inputremapper.input_configuration import InputCombination, InputConfiguration
from inputremapper.input_configuration import InputCombination, InputConfig
from inputremapper.groups import _Groups, _Group
from inputremapper.injection.event_reader import EventReader
from inputremapper.injection.mapping_handlers.abs_to_btn_handler import AbsToBtnHandler
Expand Down Expand Up @@ -278,17 +278,13 @@ def _create_event_pipeline(self, sources: List[evdev.InputDevice]) -> ContextDum
# positive direction
mapping = UIMapping(
event_combination=InputCombination(
InputConfiguration(
type=EV_ABS, code=ev_code, analog_threshold=30
)
InputConfig(type=EV_ABS, code=ev_code, analog_threshold=30)
),
target_uinput="keyboard",
)
handler: MappingHandler = AbsToBtnHandler(
InputCombination(
InputConfiguration(
type=EV_ABS, code=ev_code, analog_threshold=30
)
InputConfig(type=EV_ABS, code=ev_code, analog_threshold=30)
),
mapping,
)
Expand All @@ -298,17 +294,13 @@ def _create_event_pipeline(self, sources: List[evdev.InputDevice]) -> ContextDum
# negative direction
mapping = UIMapping(
event_combination=InputCombination(
InputConfiguration(
type=EV_ABS, code=ev_code, analog_threshold=-30
)
InputConfig(type=EV_ABS, code=ev_code, analog_threshold=-30)
),
target_uinput="keyboard",
)
handler = AbsToBtnHandler(
InputCombination(
InputConfiguration(
type=EV_ABS, code=ev_code, analog_threshold=-30
)
InputConfig(type=EV_ABS, code=ev_code, analog_threshold=-30)
),
mapping,
)
Expand All @@ -319,7 +311,7 @@ def _create_event_pipeline(self, sources: List[evdev.InputDevice]) -> ContextDum
# positive direction
mapping = UIMapping(
event_combination=InputCombination(
InputConfiguration(
InputConfig(
type=EV_REL,
code=ev_code,
analog_threshold=self.rel_xy_speed[ev_code],
Expand All @@ -331,7 +323,7 @@ def _create_event_pipeline(self, sources: List[evdev.InputDevice]) -> ContextDum
)
handler = RelToBtnHandler(
InputCombination(
InputConfiguration(
InputConfig(
type=EV_REL,
code=ev_code,
analog_threshold=self.rel_xy_speed[ev_code],
Expand All @@ -345,7 +337,7 @@ def _create_event_pipeline(self, sources: List[evdev.InputDevice]) -> ContextDum
# negative direction
mapping = UIMapping(
event_combination=InputCombination(
InputConfiguration(
InputConfig(
type=EV_REL,
code=ev_code,
analog_threshold=-self.rel_xy_speed[ev_code],
Expand All @@ -357,7 +349,7 @@ def _create_event_pipeline(self, sources: List[evdev.InputDevice]) -> ContextDum
)
handler = RelToBtnHandler(
InputCombination(
InputConfiguration(
InputConfig(
type=EV_REL,
code=ev_code,
analog_threshold=-self.rel_xy_speed[ev_code],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from evdev.ecodes import EV_ABS

from inputremapper.configs.mapping import Mapping
from inputremapper.input_configuration import InputCombination, InputConfiguration
from inputremapper.input_configuration import InputCombination, InputConfig
from inputremapper.injection.mapping_handlers.mapping_handler import (
MappingHandler,
InputEventHandler,
Expand All @@ -36,7 +36,7 @@
class AbsToBtnHandler(MappingHandler):
"""Handler which transforms an EV_ABS to a button event."""

_input_config: InputConfiguration
_input_config: InputConfig
_active: bool
_sub_handler: InputEventHandler

Expand Down
6 changes: 3 additions & 3 deletions inputremapper/injection/mapping_handlers/hierarchy_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import evdev
from evdev.ecodes import EV_ABS, EV_REL

from inputremapper.input_configuration import InputCombination, InputConfiguration
from inputremapper.input_configuration import InputCombination, InputConfig
from inputremapper.injection.mapping_handlers.mapping_handler import (
MappingHandler,
InputEventHandler,
Expand All @@ -37,10 +37,10 @@ class HierarchyHandler(MappingHandler):
all other handlers will be notified, but suppressed
"""

_input_config: InputConfiguration
_input_config: InputConfig

def __init__(
self, handlers: List[MappingHandler], input_config: InputConfiguration
self, handlers: List[MappingHandler], input_config: InputConfig
) -> None:
self.handlers = handlers
self._input_config = input_config
Expand Down
Loading