+
     i  c                  s$   R t ^ RIHt ^ RIt^ RIHtHtHtHtH	t	 ^ RI
t
^ RIHtHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt  ! R
 R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]P8                  4      t ! R R4      tR# )a&  Provides protocols for mapping handlers

*** The architecture behind mapping handlers ***

Handling an InputEvent is done in 3 steps:
 1. Input Event Handling
    A MappingHandler that does Input event handling receives Input Events directly
    from the EventReader.
    To do so it must implement the InputEventHandler protocol.
    An InputEventHandler may handle multiple events (InputEvent.type_and_code)

 2. Event Transformation
    The event gets transformed as described by the mapping.
    e.g.: combining multiple events to a single one
        transforming EV_ABS to EV_REL
        macros
        ...
    Multiple transformations may get chained

 3. Event Injection
    The transformed event gets injected to a global_uinput

MappingHandlers can implement one or more of these steps.

Overview of implemented handlers and the steps they implement:

Step 1:
 - HierarchyHandler

Step 1 and 2:
 - CombinationHandler
 - AbsToBtnHandler
 - RelToBtnHandler

Step 1, 2 and 3:
 - AbsToRelHandler
 - NullHandler

Step 2 and 3:
 - KeyHandler
 - MacroHandler
)annotationsN)DictProtocolSetOptionalList)InputCombinationInputConfig)Mapping)MappingParsingError)GlobalUInputs)
InputEvent)loggerc                  s"    ] tR t^LtR R ltRtR# )EventListenerc                    V ^8  d   QhRRRR/# )   eventzevdev.InputEventreturnNone Zformat   "]/usr/lib/python3.14/site-packages/inputremapper/injection/mapping_handlers/mapping_handler.py__annotate__ZEventListener.__annotate__M   s    BB$4BB    c                	s   "   R # 5iNr   )selfr      &&r   __call__ZEventListener.__call__M   s     ss   r   N)__name__
__module____qualname____firstlineno__r   __static_attributes__r   r   r   r   r   L   s    BBr   r   c                  s2    ] tR t^Pt$ RtR]R&   R R ltRtR# )ContextProtocolz+The parts from context needed for handlers.zSet[EventListener]Z	listenersc                   V ^8  d   QhRR/# )r   r   zevdev.UInputr   r   r   r   r   ZContextProtocol.__annotate__U   s       r   c                	    R # r   r   )r   Zorigin_hashr   r   get_forward_uinputZ"ContextProtocol.get_forward_uinputU   s    r   r   N)r   r   r   r    __doc____annotations__r%   r!   r   r   r   r"   r"   P   s    5!! r   r"   c                  s*    ] tR t^YtRtRR R lltRtR# )NotifyCallbackz`Type signature of InputEventHandler.notify

return True if the event was actually taken care of
c               (    V ^8  d   QhRRRRRRRR/# r   r   r   sourcezevdev.InputDevicesuppressboolr   r   r   r   r   r   ZNotifyCallback.__annotate___   2       " 	
 
r   c                	r$   r   r   r   r   r+   r,      &&&&r   r   ZNotifyCallback.__call___       
 r   r   NF)r   r   r   r    r&   r   r!   r   r   r   r(   r(   Y   s    
 r   r(   c                  s6    ] tR t^gtRtRR R lltR R ltRtR# )	InputEventHandlerzNThe protocol any handler, which can be part of an event pipeline, must follow.c               r)   r*   r   r   r   r   r   InputEventHandler.__annotate__j   r.   r   c                	r$   r   r   r/   r0   r   notifyZInputEventHandler.notifyj   r1   r   c               r#   r   r   r   r   r   r   r   r   r4   q   s      t r   c                    R# )8Reset the state of the handler e.g. release any buttons.Nr   r      &r   resetZInputEventHandler.resetq   s    r   r   Nr2   )r   r   r   r    r&   r5   r;   r!   r   r   r   r3   r3   g   s    X r   r3   c                  s   ] tR t^vt]P
                  ! 4       t]P
                  ! 4       t]P
                  ! 4       t]P
                  ! 4       t	]P
                  ! 4       t
]P
                  ! 4       t]P
                  ! 4       t]P
                  ! 4       t]P
                  ! 4       t]P
                  ! 4       t]P
                  ! 4       t]P
                  ! 4       t]P
                  ! 4       t]P
                  ! 4       tRtR# )HandlerEnumsr   N)r   r   r   r    enumZautoZabs2btnZrel2btnZmacroZkeyZbtn2relZrel2relZabs2relZbtn2absZrel2absZabs2abscombinationZ	hierarchyZ
axisswitchZdisabler!   r   r   r   r<   r<   v   s    iikGiikGIIKE
))+C iikGiikGiikGiikGiikGiikG ))+K		IJiikGr   r<   c                  s    ] tR t^t$ RtR]R&   R]R&   R]R&   R R	 ltRR
 R lltR R ltR R lt	R R lt
R R ltR R ltR R ltR R ltRtR# )MappingHandlerzThe protocol an InputEventHandler must follow if it should be
dynamically integrated in an event-pipeline by the mapping parser
r   mappingzList[InputConfig]input_configszOptional[InputEventHandler]_sub_handlerc               s(    V ^8  d   QhRRRRRRRR/# )	r   r>   r   r@   r   global_uinputsr
   r   r   r   r   r   r   r   MappingHandler.__annotate__   s2     - -%- - &	- 
-r   c                sL    W n         \        V4      V n        RV n        W0n        R# )zsInitialize the handler

Parameters
----------
combination
    the combination from sub_handler.wrap_with()
mapping
N)r@   ZlistrA   rB   rC   )r   r>   r@   rC   Z_s   &&&&,r   __init__ZMappingHandler.__init__   s$     !+. ,r   c               r)   r*   r   r   r   r   r   rD      s2     " "" "" 	"
 
"r   c                    \         h)zNotify this handler about an incoming event.

Parameters
----------
event
    The newest event that came from `source`, and that should be mapped to
    something else
source
    Where `event` comes from
ZNotImplementedErrorr/   r0   r   r5   ZMappingHandler.notify   s
      "!r   c               r#   r6   r   r   r   r   r   rD      s     " "t "r   c                rF   )r8   rG   r9   r:   r   r;   ZMappingHandler.reset   s    !!r   c               r#   r   r   r-   r   r   r   r   r   rD      s     ) ) )r   c                s:    \        V P                  4       4      ^ 8  # )z>If this handler needs to be wrapped in another MappingHandler.)Zlen	wrap_withr9   r:   r   needs_wrappingZMappingHandler.needs_wrapping   s    4>>#$q((r   c               r#   rH   r   r   r   r   r   rD      s      t r   c                r7   )zCIf this handler needs ranking and wrapping with a HierarchyHandler.Fr   r9   r:   r   needs_rankingZMappingHandler.needs_ranking   s    r   c               r#   )r   r   zOptional[InputCombination]r   r   r   r   r   rD      s     D D3 Dr   c                r7   )z5The combination for which this handler needs ranking.Nr   r9   r:   r   rank_byZMappingHandler.rank_by   s    r   c               r#   )r   r   z$Dict[InputCombination, HandlerEnums]r   r   r   r   r   rD      s      ? r   c                s    / # )zA dict of InputCombination -> HandlerEnums.

for each InputCombination this handler should be wrapped
with the given MappingHandler.
r   r9   r:   r   rI   ZMappingHandler.wrap_with   s	     	r   c               r   )r   handlerr3   r   r   r   r   r   r   r   rD      s     $ $'8 $T $r   c                s    Wn         R# )z Give this handler a sub_handler.N)rB   )r   rM   r   r   set_sub_handlerZMappingHandler.set_sub_handler   s    #r   c               r   )r   input_configr   r   r   r   r   r   r   r   rD      s     
0 
0 
0 
0r   c                s    V P                   '       g$   \        P                  ! V 4       \        RV R7      hV P                   P	                  V4       R# )z*Remove the config from self.input_configs.z#Cannot remove a non existing config)Zmapping_handlerN)rA   r   Zdebug_mapping_handlerr	   Zremove)r   rO   r   r   occlude_input_eventZ"MappingHandler.occlude_input_event   sD    !!!((.%5t  	!!,/r   )rB   rC   rA   r@   Nr2   )r   r   r   r    r&   r'   rE   r5   r;   rJ   rK   rL   rI   rN   rP   r!   r   r   r   r?   r?      sP      %$---("$")D$
0 
0r   r?   )r&   Z
__future__r    r=   Ztypingr   r   r   r   r   ZevdevZ"inputremapper.configs.input_configr   r   Zinputremapper.configs.mappingr   Zinputremapper.exceptionsr	   Z&inputremapper.injection.global_uinputsr
   Zinputremapper.input_eventr   Zinputremapper.logging.loggerr   r   r"   r(   r3   ZEnumr<   r?   r   r   r   <module>rQ      s|   &)T #  6 6  L 1 8 @ 0 /CH Ch X  499 0W0 W0r   