+
     iC  c                  s   R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
HtHt ^ RIt^ RIHtHtHtHtHtHtHtHtHtHtHt ^ RIHt ^ RIHt ^ RIHt ]P@                  P&                  ]P@                  PB                  ]P@                  PD                  ]P@                  PF                  .t$ ! R R	]%]PL                  4      t'](! ]PR                  R
4      '       g   ]*R 4       t+]+]PR                  n+        R t,R t-R t.R t/R t0R t1R R lt2RR.t3R R lt4R R lt5 ! R R4      t6 ! R R]	Pn                  4      t8 ! R R4      t9]9! 4       t:R# ) a}  Find, classify and group devices.

Because usually connected devices pop up multiple times in /dev/input,
in order to provide multiple types of input devices (e.g. a keyboard and a
graphics-tablet at the same time)

Those groups are what is being displayed in the device dropdown, and
events are being read from all of the paths of an individual group in the gui
and the injector.
)annotationsN)ListOptional)EV_KEYEV_ABS
KEY_CAMERAEV_REL
BTN_STYLUSABS_MT_POSITION_XREL_XKEY_ABTN_LEFTREL_Y	REL_WHEEL)	PathUtils)logger)get_device_hashc                  s2    ] tR t^EtRtRtRtRtRtRt	Rt
RtR	# )

DeviceTypeZgamepadZkeyboardZmouseZtouchpadzgraphics-tabletZcameraZunknown N)__name__
__module____qualname____firstlineno__GAMEPADKEYBOARDMOUSETOUCHPADGRAPHICS_TABLETCAMERAUNKNOWN__static_attributes__r       9/usr/lib/python3.14/site-packages/inputremapper/groups.pyr   r   E   s%    GHEH'OFGr   r   pathc                s    V P                   # N)Zfndevice   &r    r!   r!   Q   s    yyr   c                s@   \         P                  P                  \         P                  P                  \         P                  P                  \         P                  P
                  \         P                  P                  \         P                  P                  0pVP                  V P                  \        . 4      4      '       g   R# V P                  \        . 4      p\         P                  P                  V9  d   R# \         P                  P                  V9  d   R# R# )z5Check if joystick movements are available for preset.FT)evdevecodesZBTN_BASEZBTN_AZ	BTN_THUMBZBTN_TOPZBTN_DPAD_DOWNZBTN_GAMEPADZintersectiongetr   r   ZABS_XZABS_Y)capabilitiesZbuttonsZabs_capabilities   &  r    _is_gamepadr+   X   s     	""  G  0 0 <== $''3||!11||!11r   c                s   \         V P                  \        . 4      9   g   R# \        V P                  \        . 4      9   g   R# \        V P                  \        . 4      9   g   R# \
        V P                  \        . 4      9   g   R# R# )z5Check if the capabilities represent those of a mouse.FT)r	   r(   r   r   r   r   r   r)   r%   r    	_is_mouser-   q   sk     L$$VR00L$$VR00 ((44 |''33r   c                H    \         V P                  \        . 4      9   d   R# R# )z?Check if the capabilities represent those of a graphics tablet.TF)r   r(   r   r,   r%   r    _is_graphics_tabletr/      s    \%%fb11r   c                r.   )z8Check if the capabilities represent those of a touchpad.TF)r   r(   r   r,   r%   r    _is_touchpadr0      s    L,,VR88r   c                r.   )z8Check if the capabilities represent those of a keyboard.TF)r
   r(   r   r,   r%   r    _is_keyboardr1      s      ,,r   c                s    V P                  \        4      pT;'       d'    \        V4      ^8H  ;'       d    V^ ,          \        8H  # )z6Check if the capabilities represent those of a camera.)r(   r   lenr   )r)   key_capa   & r    
_is_camerar5      s:    'HHHH*HHx{j/HHr   c                   V ^8  d   QhRR/# )   returnr   r   Zformat   "r    __annotate__r;      s      
 r   c                s   V P                  RR7      p\        V4      '       d   \        P                  # \	        V4      '       d   \        P
                  # \        V4      '       d   \        P                  # \        V4      '       d   \        P                  # \        V4      '       d   \        P                  # \        V4      '       d   \        P                  # \        P                  # )z{Figure out what kind of device this is.

Use this instead of functions like _is_keyboard to avoid getting false
positives.
FZabsinfo)r)   r/   r   r   r0   r   r+   r   r-   r   r5   r   r1   r   r   )r$   r)   r4   r    classifyr=      s     &&u&5L<(( )))L!!"""<  !!!,   L!! """r   z.*Yubico.*YubiKey.*zEee PC WMI hotkeysc               r6   r7   r$   zevdev.InputDevicer   r9   r:   r    r;   r;      s      + r   c                s    \          FE  p\        P                  ! V\        V P                  4      \        P
                  4      '       g   KD   R# 	  R# )zVCheck if a device should not be used in input-remapper.

Parameters
----------
device
TF)DENYLISTreZmatchstrnameZ
IGNORECASE)r$   rB   r4   r    is_denylistedrC      s6     88D#fkk*BMM::  r   c               r6   r>   r   r9   r:   r    r;   r;      s      , r   c                s   V P                   P                   RV P                   P                   RV P                   P                   RV P                   RV P
                  P                  R4      ^ ,          ;'       g    R 2	# )zFind a string key that is unique for a single hardware device.

All InputDevices in /dev/input that originate from the same physical
hardware device should return the same key via this function.
Z_Z/Z-)infoZbustypeZvendorZproductZuniqZphysZsplitr#   r%   r    get_unique_keyrE      su     ;;
q;;
a;;
q ;;-q ;;S!!$++
,	.	r   c                  sd    ] tR t^tRtR R ltRR R lltR R ltR	 t]	R
 R l4       t
R tRtR# )_Groupa  Groups multiple devnodes together.

For example, name could be "Logitech USB Keyboard", devices
might contain "Logitech USB Keyboard System Control" and "Logitech USB
Keyboard". paths is a list of files in /dev/input that belong to the
devices.

They are grouped by usb port.

Members
-------
name : str
    A human readable name, generated from .names, that should always
    look the same for a device model. It is used to generate the
    presets folder structure
c               s(    V ^8  d   QhRRRRRRRR/# )	r7   pathszList[os.PathLike]names	List[str]typeszList[DeviceType | str]keyrA   r   r9   r:   r    r;   _Group.__annotate__   s2     $< $< $< $< &	$<
 $<r   c                s    \        V\        R7      ^ ,          V n        W@n        Wn        W n        V Uu. uF  p\        V4      NK  	  upV n        R# u upi )a5  Specify a group

Parameters
----------
paths
    Paths in /dev/input of the grouped devices
names
    Names of the grouped devices
types
    Types of the grouped devices
key
    Unique identifier of the group.

    It should be human readable and if possible equal to group.name.
    To avoid multiple groups having the same key, a number starting
    with 2 followed by a whitespace should be added to it:
    "key", "key 2", "key 3", ...

    This is important for the autoloading configuration. If the key
    changed over reboots, then autoloading would break.
rK   N)sortedr2   rB   rK   rG   rH   r   rJ   )selfrG   rH   rJ   rK   Ztype_   &&&&& r    __init__Z_Group.__init__   sD    <  3/2	

5:;UEj'U;
;s   ANc               r6   )r7   presetOptional[str]r   r9   r:   r    r;   rL   &  s     < <m <r   c                sD    \         P                  ! V P                  V4      # )zGet a path to the stored preset, or to store a preset to.

This path is unique per device-model, not per group. Groups
of the same model share the same preset paths.
)r   get_preset_pathrB   )rO   rR      &&r    rT   Z_Group.get_preset_path&  s     ((F;;r   c               r6   )r7   r8   zList[evdev.InputDevice]r   r9   r:   r    r;   rL   .  s      4 r   c                	s    . pV P                    F)  p VP                  \        P                  ! V4      4       K+  	  V#   \        \
        3 d    \        P                  ! R T4        KZ  i ; i)zCould not find "%s")rG   appendr&   InputDeviceZFileNotFoundErrorZOSErrorr   error)rO   Zdevicesr!   r*   r    get_devicesZ_Group.get_devices.  s`    +-JJDu0067   &w/ 2D9s   %>(A*)A*c           	     s    \         P                  ! \        V P                  V P                  V P
                  V P                  R7      4      # )z)Return a string representing this object.)rG   rH   rJ   rK   )jsondumpsZdictrG   rH   rJ   rK   rO   r%   r    r[   Z_Group.dumps8  s1    zztzz4::488T
 	
r   c               r6   )r7   
serializedrA   r   r9   r:   r    r;   rL   ?  s      s r   c                s>    V ! R/ \         P                  ! V4      B pV# )z!Load a serialized representation.r   )rZ   loads)Zclsr]   group   && r    r^   Z_Group.loads>  s     -djj,-r   c                	sL    R V P                    R\        \        V 4      4       R2# )z<Group (z) at Z>)rK   ZhexZidr\   r%   r    __repr__Z_Group.__repr__D  s#    $((5RXq99r   )rK   rB   rH   rG   rJ   r"   )r   r   r   r   __doc__rQ   rT   rY   r[   Zclassmethodr^   ra   r   r   r   r    rF   rF      s5    "$<L<
  
:r   rF   c                  s8   a  ] tR tRtRtR V 3R lltR tRtV ;t# )_FindGroupsiH  zThread to get the devices that can be worked with.

Since InputDevice destructors take quite some time, do this
asynchronously so that they can take as much time as they want without
slowing down the initialization.
c               r6   )r7   pipezmultiprocessing.Piper   r9   r:   r    r;   Z_FindGroups.__annotate__P  s     	 	1 	r   c                s0   < Wn         \        SV `	  4        R# )zVConstruct the process.

Parameters
----------
pipe
    used to communicate the result
N)rd   ZsuperrQ   )rO   rd   	__class__s   &&r    rQ   Z_FindGroups.__init__P  s     	r   c                s   \         P                  ! 4       p\         P                  ! V4       \        P                  ! R4       / p\
        P                  ! 4        EF  p \
        P                  ! V4      pTP                  R8X  d   K.  \        T4      pT\        P                   8X  d   KP  TP#                  RR7      pTP%                  \&        4      pTP%                  \(        4      p	TP%                  \*        4      p
Tf,   T	f(   T
f$   \        P                  ! RTP                  4       K  \-        T4      '       d%   \        P                  ! RTP                  4       EK  \/        T4      pTP%                  T4      f   . Y+&   \        P                  ! R	TP0                  TP                  T\3        T4      T4       Y+,          P5                  TP                  Y634       EK  	  . p\7        4       pVP9                  4        F  pV Uu. uF  q^ ,          NK  	  ppV Uu. uF  q^,          NK  	  pp\;        V\<        R
7      ^ ,          pTp^pW9   d   V RV 2pV^,          pK  VP?                  V4       \A        TTT\;        \C        V Uu0 uF*  pV^,          \        PD                  8w  g   K!  V^,          kK,  	  up4      4      R7      pVP5                  VPG                  4       4       K  	  V PH                  PK                  \L        PF                  ! V4      4       VPO                  4        R#   \         dC   p\        P                  ! RTTP                  P                  \        T4      4        Rp?EK  Rp?ii ; iu upi u upi u upi )zDo what get_groups describes.zDiscovering device pathsz!Failed to access path "%s": %s %sNzPower ButtonFr<   z"%s" has no useful capabilitiesz"%s" is denylistedz*Found %s "%s" at "%s", hash "%s", key "%s"rM   Z )rK   rG   rH   rJ   )(asyncioZnew_event_loopZset_event_loopr   debugr&   Zlist_devicesrW   Z	ExceptionrX   re   r   rA   rB   r=   r   r   r)   r(   r   r   r   rC   rE   Zvaluer   rV   ZsetZvaluesrN   r2   ZaddrF   Zlistr   r[   rd   ZsendrZ   Zclose)rO   ZloopZgroupedr!   r$   rX   Zdevice_typer)   r3   Zabs_capaZrel_caparK   resultZ	used_keysr_   ZentryrH   ZdevsZshortest_nameZiZitems   &                    r    runZ_FindGroups.run[  s    %%'t$/0 &&(D**40 {{n,"6*Kj/// "..u.=L#''/H#''/H#''/HH$49I>LV$$16;;? (C{{3'!LL<!!' Ld @Am )r E	^^%E+015%1XX5E1*/0%!HH%D0 #5c215MCA"&q,QMM#eUedtAw*BTBT7T'$q''eUV	E MM%++-(- &0 			tzz&)*

c   7OO,,J	 r 20  Vs0   L,M<NN+N,M976M44M9)rd   )	r   r   r   r   rb   rQ   ri   r   Z__classcell__)re   s   @r    rc   rc   H  s    	 	_ _r   rc   c                  s    ] tR tRtRtR tR R ltR tRR R lltR	 R
 lt	R R lt
R tR tR tR R ltRR R lltRtR# )_Groupsi  z Contains and manages all groups.c                	s    R V n         R # r"   _groupsr\   r%   r    rQ   Z_Groups.__init__  s	    %)r   c               r6   )r7   rK   rA   r   r9   r:   r    r;   _Groups.__annotate__  s     
2 
2C 
2r   c                s    VR8X  dK   \         P                  V R4      f3   \         P                  V R. 4       \         P                  V R4      ! 4        \         P                  W4      # )zTo lazy load group info only when needed.

For example, this helps to keep logs of input-remapper-control clear when it
doesn't need it the information.
rl   refresh)Zobject__getattribute__Z__setattr__)rO   rK   rU   r    ro   Z_Groups.__getattribute__  sT     ) 7 7i H PtY3##D)46&&t11r   c                s   \         P                  ! 4       p\        V^,          4      P                  4        V P	                  V^ ,          P                  4       4       \        V P                  4      ^ 8X  d   \        P                  ! R4       R# V P                   Uu. uF  pRVP                   R2NK  	  pp\        P                  ! RRP                  V4      4       R# u upi )zLook for devices and group them together.

Since this needs to do some stuff with /dev and spawn processes the
result is cached. Use refresh_groups if you need up to date
devices.
zDid not find any input deviceZ"zFound %sz, N)multiprocessingZPiperc   Zstartr^   Zrecvr2   rl   r   rX   rK   rD   Zjoin)rO   rd   r_   Zkeyss   &   r    rn   Z_Groups.refresh  s     ##%DG""$

47<<>"t||!LL8926,,?,a		{!$,D?KK
DIIdO4 @s   Cc               s     V ^8  d   QhRRRR/# )r7   include_inputremapperboolr8   List[_Group]r   r9   r:   r    r;   rm     s     
 
D 
\ 
r   c                s    . pV P                    FA  pVP                  pV'       g   VP                  R4      '       d   K0  VP                  V4       KC  	  V# )zFilter groups.input-remapper)rl   rB   
startswithrV   )rO   rq   rh   r_   rB   s   &&   r    filterZ_Groups.filter  sF    \\E::D(T__=M-N-NMM%  " r   c               r6   )r7   
new_groupsrs   r   r9   r:   r    r;   rm     s     " "\ "r   c                s@    \         P                  ! RV4       Wn        R# )zOverwrite all groups.zOverwriting groups with %sN)r   rg   rl   )rO   rw   rU   r    
set_groupsZ_Groups.set_groups  s    1:>!r   c               r6   )r7   r8   rI   r   r9   r:   r    r;   rm     s     
 
) 
r   c                s    V P                    Uu. uF2  pVP                  P                  R4      '       d   K&  VP                  NK4  	  up# u upi )z5Return a list of all 'name' properties of the groups.rt   )rl   rB   ru   rO   r_   r4   r    list_group_namesZ_Groups.list_group_names  sF     
%::(()9: EJJ%
 	
 
s
   #A
A
c                	,    \        V P                  4      # r"   )r2   rl   r\   r%   r    __len__Z_Groups.__len__  s    4<<  r   c                	r{   r"   )Ziterrl   r\   r%   r    __iter__Z_Groups.__iter__   s    DLL!!r   c                s    \         P                  ! V P                   Uu. uF  qP                  4       NK  	  up4      # u upi )z.Create a deserializable string representation.)rZ   r[   rl   ry   r4   r    r[   Z_Groups.dumps  s+    zzdllClU;;=lCDDCs   >c               r6   )r7   dumprA   r   r9   r:   r    r;   rm     s     K K# Kr   c                s    \         P                  ! V4       Uu. uF  p\        P                  V4      NK  	  upV n        R# u upi )z3Load a serialized representation created via dumps.N)rZ   r^   rF   rl   )rO   r~   r_   r`   r    r^   Z_Groups.loads  s/    9=D9IJ9IU+9IJJs   ANc          
     s,    V ^8  d   QhRRRRRRRRRR/# )	r7   rB   rS   rK   r!   rq   rr   r8   zOptional[_Group]r   r9   r:   r    r;   rm     s<     " "" " 	"
  $" 
"r   c                s&   V P                    F  pV'       g$   VP                  P                  R4      '       d   K.  V'       d   VP                  V8w  d   KI  V'       d   VP                  V8w  d   Kd  V'       d   W5P                  9  d   K~  Vu # 	  R# )zFind a group that matches the provided parameters.

Parameters
----------
name
    "USB Keyboard"
    Not unique, will return the first group that matches.
key
    "USB Keyboard", "USB Keyboard 2", ...
path
    "/dev/input/event3"
rt   N)rl   rB   ru   rK   rG   )rO   rB   rK   r!   rq   r_   rP   r    findZ_Groups.find  sh    & \\E(UZZ-B-BCS-T-T

d*uyyC'KK/L " r   rk   )F)NNNF)r   r   r   r   rb   rQ   ro   rn   rv   rx   rz   r|   r}   r[   r^   r   r   r   r   r    rj   rj     sC    **
25$
"

!"EK" "r   rj   );rb   Z
__future__r    rf   ZenumrZ   rp   Zosr@   Z	threadingZtypingr   r   r&   Zevdev.ecodesr   r   r   r   r   r   r	   r
   r   r   r   Zinputremapper.configs.pathsr   Zinputremapper.logging.loggerr   Zinputremapper.utilsr   r'   ZBTN_TOOL_BRUSHZBTN_TOOL_PENZBTN_TOOL_RUBBERZTABLET_KEYSrA   ZEnumr   ZhasattrrW   Zpropertyr!   r+   r-   r/   r0   r1   r5   r=   r?   rC   rE   rF   ZThreadrc   rj   Zgroupsr   r   r    <module>r      sC  (	 #     	 	  !     2 / / 
LL	LL	LL	LL  	dii  u  &))  "E2,IB "#784W: W:tr)"" rpm mb 
r   