+
     ir7  c                   s  a  R tT0 t R t^ RIHt ^ RIHtHtHtHtH	t	H
t
HtHtHt ^ RIHtHtHt ^ RIHtH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I"H#t# ^ RI$H%t% ^ RI&H't' ^ RI(H)t) ^ RI*H+t+ ^ RI,H-t- ^ RI.H/t/ ^ RI0H1t1 ^ RI2H3t3H4t4H5t5H6t6 ^ RI7H8t8 ^ RI9H:t: ^ RI;H<t< ^ RI=H>t> ^ RI?H@t@ ^ RIAHBtB ]]]	]6,          3,          tC]3P                  ]%]3P                  ]<]3P                  ]1]3P                  ]/]3P                  R]3P                  ]>]3P                  ]']3P                  R]3P                  ]:]3P                  ]#]3P                  ]+]3P                  ]-]3P                  ])]3P                  ]8/tR] ^ k  ! R R4      tSR# )z/Functions to assemble the mapping handler tree.)defaultdict)	DictListTypeOptionalSetIterableSizedTupleSequence)EV_KEYEV_ABSEV_REL)InputCombinationInputConfig)DISABLE_CODEDISABLE_NAME)Mapping)Preset)MappingParsingErrorGlobalUInputs)Parser)AbsToAbsHandler)AbsToBtnHandler)AbsToRelHandler)AxisSwitchHandler)CombinationHandler)HierarchyHandler)
KeyHandler)MacroHandler)HandlerEnumsMappingHandlerContextProtocolInputEventHandler)NullHandler)RelToAbsHandler)RelToBtnHandler)RelToRelHandler)logger)get_evdev_constant_nameNc                   s   a  ] tR t^Pt o V 3R lR ltV 3R lR ltRV 3R lR lltV 3R lR ltV 3R	 lR
 ltV 3R lR lt	V 3R lR lt
V 3R lR ltRtV tR# )MappingParserc                s    < V ^8  d   QhRS[ /# )   global_uinputsr   format__classdict__   "\/usr/lib/python3.14/site-packages/inputremapper/injection/mapping_handlers/mapping_parser.py__annotate__MappingParser.__annotate__Q   s     - -%-    c                s    Wn         R # Nr+   )selfr+   s   &&r0   __init__ZMappingParser.__init__Q   s
     -r3   c                s,   < V ^8  d   QhRS[ RS[RS[/# )r*   presetcontextreturn)r   r!   EventPipelinesr,   r/   r0   r1   r2   W   s.     E EE !E 
	Er3   c           	     s0   . pV F  pV P                  V4      p\        V,          pV'       g)   \        P                  ! RVVP	                  4       4       KQ  V! VP
                  VVV P                  R7      pVP                  V P                  Wr4      4       K  	  \        \        4      pVP                  4        F~  p	V	P                  4       '       g   K  V	P                  4       p
V
'       g$   \        \        V	4      P                    R2V	R7      hW,          P#                  V	4       VP%                  V	4       K  	  V P'                  V4      pV F%  p	VP                  V P                  WRR7      4       K'  	  \        \        4      pV F  p	V	P(                  '       g   Q hV	P(                   Fc  p\        P*                  ! R\-        VP.                  !  VP0                  4       \        P2                  ! V	4       W,          P#                  V	4       Ke  	  K  	  V# )z@Create a dict with a list of MappingHandler for each InputEvent.z0a mapping handler '%s' for %s is not implementedr9   r+   zD claims to need ranking but does not return a combination to rank by)Zmapping_handlerT)ignore_rankingz&event-pipeline with entry point: %s %s)_get_output_handlermapping_handler_classesr'   ZwarningZformat_nameinput_combinationr+   extend_create_event_pipeliner    setcopyneeds_rankingZrank_byr   type__name__addZremove_create_hierarchy_handlersinput_configsZdebugr(   Ztype_and_codeZinput_match_hashZdebug_mapping_handler)r6   r8   r9   handlersmappinghandler_enumconstructorZoutput_handlerZneed_rankinghandlercombinationZranked_handlersZevent_pipelinesZinput_configs   &&&           r0   parse_mappingsZMappingParser.parse_mappingsW   s    G  33G<L1,?KF '')
 ())#22	N OOD77PQ/ 4 #3'}}G$$&&%oo/"-=112 3: ;(/  )--g6( ' 99,G&GOO++GT+R ' +6c*:G((((( ' 5 5<+\-G-GH 11
 ,,W5-11': !6   r3   c                s<   < V ^8  d   QhRS[ RS[RS[S[ ,          /# )r*   rO   r9   r:   )r    r!   r   r,   r/   r0   r1   r2      s.     ) )) !)
 
n	)r3   c                s*   VP                  4       '       d   VP                  4       '       d   V'       g   V.# . pVP                  4       P                  4        F  w  rV\        V,          pV'       g   \        RV R24      hV! VVP                  VV P                  R7      pVP                  V4       V F  p	VP                  V	4       K  	  VP                  V P                  W4      4       K  	  VP                  '       d   VP                  V4       V# )znRecursively wrap a handler with other handlers until the
outer handler needs ranking or is finished wrapping.
zmapping handler z is not implementedr<   )Zneeds_wrappingrE   Z	wrap_withZitemsr?   ZNotImplementedErrorrL   r+   Zset_sub_handlerocclude_input_eventrA   rB   rJ   Zappend)
r6   rO   r9   r=   rK   rP   rM   rN   Zsuper_handlerevents
   &&&&      r0   rB   Z$MappingParser._create_event_pipeline   s     %%''!!##N9)0):):)<)B)B)D%K1,?K)&|n4GH  (#22	M ))'2$ ++E2 %
 OOD77OP' *E*     OOG$r3   c                s&   < V ^8  d   QhRS[ RS[/# )r*   rL   r:   )r   r   r,   r/   r0   r1   r2      s     *
 *
7 *
| *
r3   c                s   VP                   \        8X  g   VP                  \        8X  d   \        P
                  # VP                  '       dG   \        P                  ! VP                  4      '       d   \        P                  # \        P                  # VP                  \        8X  d   \        P                  # V P                  VP                  4      pV'       g   \        RV: R2\        R7      hVP                  \         8X  dp   VP"                  \        8X  d   \        P$                  # VP"                  \         8X  d   \        P&                  # VP"                  \(        8X  d   \        P*                  # VP                  \(        8X  dp   VP"                  \        8X  d   \        P,                  # VP"                  \         8X  d   \        P.                  # VP"                  \(        8X  d   \        P0                  # \        RV: R2\        R7      h)z_Determine the correct output handler.

this is used as a starting point for the mapping parser
zThis mapping = z& does not map to an axis, key or macro)rL   zthe output of mapping = z is unknown)Zoutput_coder   Zoutput_symbolr   r   disabler   Zis_this_a_macromacrokeyZoutput_typer
   
_maps_axisr@   r   r   r   rF   btn2relrel2relr   abs2relbtn2absrel2absabs2abs)r6   rL   Zinput_event   && r0   r>   Z!MappingParser._get_output_handler   s   
 ,.'2G2G<2W'''   %%g&;&;<<#)))###&(###oog&?&?@%"|#IJ 
 &(6)#+++6)#+++6)#+++&(6)#+++6)#+++6)#+++!'WL4g
 	
r3   c                s6   < V ^8  d   QhRS[ RS[S[,          /# )r*   rP   r:   )r   r   r   r,   r/   r0   r1   r2      s!      &6 8K;P r3   c                sD    V F  pVP                   '       g   K  Vu # 	  R# )zxWhether this InputCombination contains an InputEvent that is treated as
an axis and not a binary (key or button) event.
N)Zdefines_analog_input)r6   rP   rS   r^   r0   rW   ZMappingParser._maps_axis   s$     !E))) ! r3   c                s\   < V ^8  d   QhRS[ S[S[S[,          3,          RS[S[,          /# )r*   rK   r:   )r   r   r   r    r,   r/   r0   r1   r2      s4     0 0'^)<<=0 
^	0r3   c                s*   \        4       pVP                  4       p\        4       pV F  pV F  pVP                  V4       K  	  K  	  V F  pV Uu. uF  qVV9   g   K  VNK  	  pp\        V4      ^8X  d!   VP	                  W^ ,          ,          4       KL  V P                  VV4      p. p	V F  pV	P                  W,          4       K  	  VP                  \        V	VV P                  4      4       V	 F  p
V
P                  V4       K  	  K  	  V# u upi )z<Sort handlers by input events and create Hierarchy handlers.)
rC   ZkeysrH   lenZupdate_order_combinationsrA   r   r+   rR   )r6   rK   Zsorted_handlersZall_combinationsZeventsrP   rS   Zcombinations_with_eventZsorted_combinationsZsub_handlersrO   s   &&         r0   rI   Z(MappingParser._create_hierarchy_handlers   s(   
 %#==? ,K$

5! % ,
 E 0@'/?KCW/? $ ' *+q0&&x0J'KL #'":":'# 24L2##H$9:  3   '' ( ++E2 (9 B ?'s   DDc                sL   < V ^8  d   QhRS[ S[,          RS[RS[ S[,          /# )r*   combinationscommon_configr:   )r   r   r   r,   r/   r0   r1   r2   0  s5      +, # 
		r3   c                s   a VP                  \        R7       V P                  VP                  4       4       F"  w  r4WV pVP                  V3R lR7       WQW4% K$  	  VP	                  4        V# )u  Reorder the keys according to some rules.

such that a combination a+b+c is in front of a+b which is in front of b
for a+b+c vs. b+d+e: a+b+c would be in front of b+d+e, because the common key b
has the higher index in the a+b+c (1), than in the b+c+d (0) list
in this example b would be the common key
as for combinations like a+b+c and e+d+c with the common key c: ¯\_(ツ)_/¯

Parameters
----------
combinations
    the list which needs ordering
common_config
    the InputConfig all InputCombination's in combinations have in common
)rV   c                 s&   < V P                  S4      # r4   )Zindex)xrb   s   &r0   Z<lambda>Z3MappingParser._order_combinations.<locals>.<lambda>H  s    (>r3   )Zsortr_   _ranges_with_constant_lengthrD   Zreverse)r6   ra   rb   ZstartZendZsub_lists   &&f   r0   r`   Z!MappingParser._order_combinations0  sl    ( 	c";;L<M<M<OPJE##.HMM>M?&.# Q
 	r3   c                s\   < V ^8  d   QhRS[ S[,          RS[S[S[S[3,          ,          /# )r*   rc   r:   )r	   r   r   r   Zintr,   r/   r0   r1   r2   N  s0      E? 
%S/	"r3   c              #  sX  "   ^ p^ p\        V4       F  w  rE\        V4      V8  d   WB,
          ^8  d   W$3x  \        V4      V8X  d$   V^,           \        V4      8X  d   W$^,           3x  \        V4      V8  d   Tp\        V4      V8  d   \        R4      h\        V4      pK  	  R# 5i)zGet all ranges of x for which the elements have constant length

Parameters
----------
x: Sequence[Sized]
    l must be ordered by increasing length of elements
z=ranges_with_constant_length was called with an unordered listN)Z	enumerater_   r   )r6   rc   Z	start_idxZlast_lenZidxZys   &&    r0   rd   Z*MappingParser._ranges_with_constant_lengthN  s      	lFC1v S_q%8n$1v!cAgQ&7q((1v 	1v )S  1vH #s   B(B*r5   N)F)rG   Z
__module__Z__qualname__Z__firstlineno__r7   rQ   rB   r>   rW   rI   r`   rd   Z__static_attributes__Z__classdictcell__)r.      @r0   r)   r)   P   s[     - -E EN) )V*
 *
X 0 0d < r3   r)   c                s    V ^8  d   Qh/ ^ \         9   d1   \        \        \        \        \
        ,          ,          3,          ;R&   # )r*   r?   )__conditional_annotations__r   r   r   r   r    )r-   s   "r0   r1   r1      s4     5 5R lHT.5I,JJK S 6r3   )Urf   Z__doc__Zcollectionsr    Ztypingr   r   r   r   r   r   r   r   r	   Zevdev.ecodesr
   r   r   Z"inputremapper.configs.input_configr   r   Z%inputremapper.configs.keyboard_layoutr   r   Zinputremapper.configs.mappingr   Zinputremapper.configs.presetr   Zinputremapper.exceptionsr   Z&inputremapper.injection.global_uinputsr   Z$inputremapper.injection.macros.parser   Z;inputremapper.injection.mapping_handlers.abs_to_abs_handlerr   Z;inputremapper.injection.mapping_handlers.abs_to_btn_handlerr   Z;inputremapper.injection.mapping_handlers.abs_to_rel_handlerr   Z<inputremapper.injection.mapping_handlers.axis_switch_handlerr   Z<inputremapper.injection.mapping_handlers.combination_handlerr   Z:inputremapper.injection.mapping_handlers.hierarchy_handlerr   Z4inputremapper.injection.mapping_handlers.key_handlerr   Z6inputremapper.injection.mapping_handlers.macro_handlerr   Z8inputremapper.injection.mapping_handlers.mapping_handlerr   r    r!   r"   Z5inputremapper.injection.mapping_handlers.null_handlerr#   Z;inputremapper.injection.mapping_handlers.rel_to_abs_handlerr$   Z;inputremapper.injection.mapping_handlers.rel_to_btn_handlerr%   Z;inputremapper.injection.mapping_handlers.rel_to_rel_handlerr&   Zinputremapper.logging.loggerr'   Zinputremapper.utilsr(   r;   Zabs2btnZrel2btnrU   rV   rX   rY   rZ   r[   r\   r]   rP   Z	hierarchyZ
axisswitchrT   r?   r)   r1   )rf   re   r0   <module>rg      s>  ( 6 # T T T / / L L 1 / 8 @ 7 W W W X K O  N W W W / 7k3'8#99: //j$//$//0,.+O  &Y Yr3   