+
     i  c                   s    R t ^ RIt^ RIt^ RIt^ RI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Ht  ! R R]4      t ! R	 R
4      tR# )z5Because multiple calls to async_read_loop won't work.N)AsyncIteratorProtocolSetList)EventListenerNotifyCallback
InputEvent)logger)get_device_hash
DeviceHashc                   sV   a  ] tR t^'t o R tV 3R lR ltV 3R lR ltV 3R ltRtV t	R# )	Contextc                    R # N self   &I/usr/lib/python3.14/site-packages/inputremapper/injection/event_reader.pyresetZContext.reset*   s    S    c                s6   < V ^8  d   QhRS[ RS[S[,          /# )   input_eventreturn)r   r   r   Zformat__classdict__   "r   __annotate__Context.__annotate__,   s    XX
XtN?SXr   c                r   r   r   )r   r      &&r   get_notify_callbacksZContext.get_notify_callbacks,   s    UXr   c                s:   < V ^8  d   QhRS[ RS[P                  /# )r   origin_hashr   )r
   evdevZUInputr   r   r   r   r   .   s    NNjNU\\Nr   c                r   r   r   )r   r   r   r   get_forward_uinputZContext.get_forward_uinput.   s    3r   c                s6   < V ^8  d   Qh/ S[ S[,          ;R&   # )r   	listeners)r   r   r   r   r   r   r   '   s     =!! r   r   N)
__name__
__module____qualname____firstlineno__r   r   r!   Z__annotate_func____static_attributes____classdictcell__r      @r   r   r   '   s      XXNN  r   r   c                   s   a  ] tR t^1t o RtV 3R lR ltR 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RtV tR# )EventReaderaR  Reads input events from a single device and distributes them.

There is one EventReader object for each source, which tells multiple
mapping_handlers that a new event is ready so that they can inject all sorts of
funny things.

Other devnodes may be present for the hardware device, in which case this
needs to be created multiple times.
c                sX   < V ^8  d   QhRS[ RS[P                  RS[P                  RR/# )r   contextsource
stop_eventr   N)r   r    ZInputDeviceasyncioEventr   r   r   r   EventReader.__annotate__<   s=     % %% !!% MM	%
 
%r   c                sJ    \        V4      V n        W n        Wn        W0n        R# )z^Initialize all mapping_handlers

Parameters
----------
source
    where to read keycodes from
N)r	   _device_hash_sourcer,   r.   )r   r,   r-   r.   s   &&&&r   __init__ZEventReader.__init__<   s      ,F3$r   c                s:    V P                   P                  4        R# )zStop the reader.N)r.   setr   r   r   stopZEventReader.stopN   s    r   c                sD   < V ^8  d   QhRS[ S[P                  ,          /# )r   r   )r    r    r   r   r   r   r   r1   R   s      u/?/?!@ r   c               s  "   \         P                  ! V P                  P                  4       4      p\         P                  ! 4       p\         P
                  ! 4       pVP                  V P                  P                  4       VP                  4        \         P                  ! V\         P                  ! VP                  4       4      0\         P                  R7      G Rj  xL
 w  rE\        P                  ! V P                  P                  4       4      P                  ^ 8H  pV'       d   \        P                  ! R4       VP!                  4       '       g	   V'       d[   V F  pVP#                  4        K  	  VP%                  V P                  P                  4       4       \        P&                  ! R4       R# VP)                  4        V P                  P+                  4       ;p'       g   EK[  V5x  K,   EL5i)T)Zreturn_whenNz#fd broke, was the device unplugged?zread loop stopped)r/   ZTaskr.   ZwaitZget_running_loopr0   Z
add_readerr3   Zfilenor5   ZFIRST_COMPLETEDosZstatZst_nlinkr   errorZdoneZcancelZremove_readerdebugZclearZread_one)	r   Z	stop_taskZloopZevents_ready_ZpendingZ	fd_brokenZtaskevents	   &        r   	read_loopZEventReader.read_loopR   sM    LL!5!5!78	'')}}++-|/?/?@&||GLL):):)<=>#33  JA
  3 3 56??1DI BC~~9#DKKM $""4<<#6#6#8901 <<0022%22+s&   CG4G1A4G4G4B	G4*G4c                s&   < V ^8  d   QhRS[ RS[/# )r   r;   r   )r   Zboolr   r   r   r   r1   p   s      j T r   c                sB   VP                   \        P                  P                  8X  d   R# VP                   \        P                  P                  8X  d   R# RpV P
                  P                  V4      pV'       d$   V F  pV! WP                  R7      V,          pK  	  V# )zQSend the event to the NotifyCallbacks.

Return if anyone took care of the event.
F)r-   )typer    ecodesEV_MSCEV_SYNr,   r   r3   )r   r;   handledZnotify_callbacksZnotify_callbacks   &&   r   send_to_handlersZEventReader.send_to_handlersp   sw    
 ::,,,::,,,<<<<UC#3)%EO $4 r   c                $   < V ^8  d   QhRS[ RR/# r   r;   r   Nr   r   r   r   r   r1      s     ' 'Z 'D 'r   c                s  "   VP                   \        P                  P                  8X  d   R# VP                   \        P                  P                  8X  d   R# V P
                  P                  P                  4        FC  pV! V4      G Rj  xL
  \        ^4       F!  p\        P                  ! ^ 4      G Rj  xL
  K#  	  KE  	  R#  L: L5i)zSend the event to listeners.N)r=   r    r>   r?   r@   r,   r"   ZcopyZranger/   Zsleep)r   r;   Zlistenerr:   s   &&  r   send_to_listenersZEventReader.send_to_listeners   s     ::,,,::,,,..335H 5/!! 1XmmA&&&  6 " 's$   B	C
C+C
7C8C
C
c                rC   rD   r   r   r   r   r   r1      s     - -Z -D -r   c                s   V P                   P                  V P                  4      pVP                  \        P
                  P                  8X  d   \        P                  ! W4       VP                  ! VP                  !   R# )z.Forward an event, which injects it unmodified.N)
r,   r!   r2   r=   r    r>   EV_KEYr   ZwriteZevent_tuple)r   r;   Z
forward_to   && r   forwardZEventReader.forward   sR    \\44T5F5FG
::,,,LL+%++,r   c                rC   rD   r   r   r   r   r   r1      s        *    r   c                s  "   VP                   \        P                  P                  8X  d   VP                  ^8X  d   R# V P                  V4      G Rj  xL
  V P                  V4      pV'       g   V P                  V4       R# R#  L25i)r   N)r=   r    r>   rF   ZvaluerE   rB   rH   )r   r;   rA   rG   r   handleZEventReader.handle   sh     ::,,,1A $$U+++''.LL 	 	,s   ABBB1Bc           
     s  "   \         P                  ! RV P                  P                  V P                  P                  4       V P                  4         Rj  xL
  p \        P                  ! V P                  \        P                  ! WP                  R7      4      4       KQ   LL  \         dC   p\         P                  ! RT\        T4      4       \        P                   ! T4        Rp?K  Rp?ii ; iDT P"                  P%                  4        \         P&                  ! RT P                  P                  4       R# 5i)zStart doing things.

Can be stopped by stopping the asyncio loop or by setting the stop_event.
This loop reads events from a single device only.
z,Starting to listen for events from %s, fd %sN)r   z Handling event %s failed with %szread loop for %s stopped)r   r9   r3   ZpathZfdr<   r/   Zensure_futurerI   r   Z
from_eventr2   Z	Exceptionr8   r=   	tracebackZprint_exceptionr,   r   Zinfo)r   r;   Zes   &  r   runZEventReader.run   s      	:LLLLOO	
  >>+ 	- 	-%
- %%KK"--eARARS		-  -?QP))!,,- , 	.0A0ABsP   AD>C6B$C6D>AB&"D>$C6&C317C.(D>.C33AD>)r2   r3   r,   r.   N)r#   r$   r%   r&   __doc__r4   r6   r<   rB   rE   rH   rI   rK   r'   r(   r)   r*   r   r+   r+   1   sW     % %$ < (' '4- -   C Cr   r+   )rL   r/   r7   rJ   Ztypingr    r   r   r   r    Z8inputremapper.injection.mapping_handlers.mapping_handlerr   r   Zinputremapper.input_eventr   Zinputremapper.logging.loggerr   Zinputremapper.utilsr	   r
   r   r+   r   r   r   <module>rM      sH   * <  	  5 5  1 / ;Oh O_C _Cr   