+
     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 ^ RIHt ^ RIHt RtR
t^tRtRt ! R R	4      t]! 4       tR# )zCMake the systems/environments mapping of keys and codes accessible.N)OptionalListIterableTuple)	PathUtils)logger)
is_serviceZdisablezxmodmap.jsonc                   s   a  ] tR t^,t o Rt]t]t]tV 3R lR lt	RV 3R lR llt
V 3R lR ltR	 tR
 tR 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 3R lR ltV 3R lR ltV 3R ltRtV tR# )KeyboardLayoutz0Stores information about all available keycodes.c                    < V ^8  d   QhRS[ /# )   wantedstrZformat__classdict__   "J/usr/lib/python3.14/site-packages/inputremapper/configs/keyboard_layout.py__annotate__KeyboardLayout.__annotate__3   s     5 5s 5    c                s    . ROpV F[  pW8w  d   K  \         P                  W4      \        J g   K*  \         P                  W/ 4       \         P                  V R4      ! 4        K]  	  \         P                  W4      # )zTo lazy load keyboard_layout info only when needed.

For example, this helps to keep logs of input-remapper-control clear when it
doesn't need it the information.
populate)_mapping_xmodmap_case_insensitive_mapping)Zobject__getattribute__	LAZY_LOADZ__setattr__)selfr
   Zlazy_loaded_attributesZlazy_loaded_attribute   &&  r   r   ZKeyboardLayout.__getattribute__3   sj     "W%;!.&&tCyP ""4C''j9; &< &&t44r   Nc                sV   < V ^8  d   QhRS[ S[S[,          ,          RS[S[,          /# )r	   codesreturn)r    r   intr   r   r   r   r   r   r   F   s,     
O 
O# 7 
O49 
Or   c                s    V'       g   V P                   P                  4       # V P                   P                  4        UUu. uF  w  r#W19   g   K  VNK  	  upp# u uppi )zwGet all possible names in the mapping, optionally filtered by codes.

Parameters
----------
codes: list of event codes
)r   keysitems)r   r   namecoder   r   
list_namesZKeyboardLayout.list_namesF   sI     ==%%'''+}}':':'<N'<'<NNNs    
AAc                r   )r	   symbolr   r   r   r   r   r   R   s     J J3 Jr   c                sz    WP                   9   d   V# V P                  P                  VP                  4       V4      # )z'Return the correct casing for a symbol.)r   r   getlower)r   r$      &&r   correct_caseZKeyboardLayout.correct_caseR   s0    ]]"M--11&,,.&IIr   c                sV    \         P                  ! RR.\         P                  R7      P                  4       p\        P                  ! RTR,           4      T n        T P                  4       p\        T4      ^ 8X  d   \
        P                  ! R	4       R# \        P                  ! \         4      p\        P"                  ! T4       \%        TR
4      ;_uu_ 4       p\
        P&                  ! RT4       \(        P*                  ! Y5^R7       RRR4       TP-                  4        F  w  rgT P/                  Yg4       K  	  R#   \         d    \
        P                  ! R4        R# \         P                   d#   p\
        P                  ! RT4        Rp?R# Rp?ii ; i  + '       g   i     L; i)z>Look up xmodmap -pke, write xmodmap.json, and get the symbols.xmodmapz-pke)Zstderrz;Optional `xmodmap` command not found. This is not critical.Nz'Call to `xmodmap -pke` failed with "%s"z(\d+) = (.+)\nZ
z'`xmodmap -pke` did not yield any symbolZwzWriting "%s")Zindent)
subprocessZcheck_outputZSTDOUTZdecodeZFileNotFoundErrorr   ZinfoZCalledProcessErrorZerrorreZfindallr   _find_legit_mappingslenr   Zget_config_pathXMODMAP_FILENAMEZtouchZopendebugjsonZdumpr    _set)r   r)   Zexmodmap_dictZpathZfiler!   r"   s   &       r   _use_xmodmap_symbolsZ#KeyboardLayout._use_xmodmap_symbolsY   s2   
	 --F#!(( fh  

#4gnE002|!KKAB (()9:$__LL.IIl3  ',,.JDIId! /+ ! 	KKUV,, 	LLBAF	 _s/   6D; 0F;!FF2F3FFF(	c                s    \         P                  P                  P                  4        FF  w  rVP                  R4      '       g   VP                  R4      '       g   K5  V P	                  W4       KH  	  R# )z.Look up the evdev constant names and use them.KEYBTNN)evdevecodesr    Z
startswithr1   )r   r!   Zecode   &  r   _use_linux_evdev_symbolsZ'KeyboardLayout._use_linux_evdev_symbolsx   sJ     <<..446KDu%%)?)?		$& 7r   c                s    \         P                  ! R4       V P                  4        \        4       '       g   V P	                  4        V P                  4        V P                  \        \        4       R# )z7Get a mapping of all available names to their keycodes.zGathering available keycodesN)	r   r/   clearr   r3   r9   r1   DISABLE_NAMEDISABLE_CODE)r   s   &r   r   ZKeyboardLayout.populate~   sG    34

|| %%'%%'		,-r   c                r   )r	   mappingdictr   r   r   r   r      s     
 
d 
r   c                s    \        V P                  4      pVP                  4        F  w  r4V P                  W44       K  	  \        P
                  ! R\        V P                  4      V,
          4       R# )zyUpdate this with new keys.

Parameters
----------
mapping
    maps from name to code. Make sure your keys are lowercase.
z!Updated keycodes with %d new onesN)r-   r   r    r1   r   r/   )r   r=   Z
len_beforer!   r"      &&   r   updateZKeyboardLayout.update   sQ     '
!--/JDIId! * 	/T]]1Cj1P	
r   c                s&   < V ^8  d   QhRS[ RS[/# )r	   r!   r"   )r   r   r   r   r   r   r      s     A A AC Ar   c                s~    W P                   \        V4      &   WP                  \        V4      P                  4       &   R# )zMap name to code.N)r   r   r   r&   )r   r!   r"   s   &&&r   r1   ZKeyboardLayout._set   s+    #'c$i <@&&s4y'89r   c                s6   < V ^8  d   QhRS[ RS[S[,          /# )r	   r!   r   )r   r    r   r   r   r   r   r      s     ' ' ' 'r   c                s    WP                   9  d3   V P                  P                  \        V4      P	                  4       4      pV P                   P                  V4      # )z"Return the code mapped to the key.)r   r   r%   r   r&   )r   r!   r'   r   r%   ZKeyboardLayout.get   sD     }}$1155c$ioo6GHD}}  &&r   c                sx    \        V P                  P                  4       4      pV F  pV P                  V K  	  R# )z.Remove all mapped keys. Only needed for tests.N)listr   r   )r   r   Zkeyr8   r   r:   ZKeyboardLayout.clear   s/    DMM&&()Cc" r   c                r   )r	   r"   )r   r   r   r   r   r      s      S r   c                s   V P                    FE  p\        V^ ,          4      \        ,
          V8X  g   K'  V^,          P                  4       ^ ,          u # 	  \        P
                  P                  P                  VR4      pVe&   \        V4      \        \        39   d
   V^ ,          # V# \        P
                  P                  P                  VR4      pVe&   \        V4      \        \        39   d
   V^ ,          # V# R# )z)Get the first matching name for the code.N)r   r   XKB_KEYCODE_OFFSETsplitr6   r7   r5   r%   ZtyperB   Ztupler4   )r   r"   ZentryZbtn_nameZkey_namer@   r   get_nameZKeyboardLayout.get_name   s    ]]E58}11T9Qx~~'** # <<##''d3H~$.{"O<<##''d3H~$.{"Or   c                r   )r	   r   r>   r   r   r   r   r      s      d r   c                s    / pV P                    F4  w  r#VP                  4       ^ ,          p\        V4      \        ,
          W&   K6  	  V# )zAFrom the parsed xmodmap list find usable symbols and their codes.)r   rD   r   rC   )r   r2   ZkeycodeZnamesr!   s   &    r   r,   Z#KeyboardLayout._find_legit_mappings   sC    "mmNG ;;=#D!$W0B!BL , r   c                s   < V ^8  d   Qh/ S[ S[,          ;R&   S[ S[S[S[S[3,          ,          ,          ;R&   S[ S[,          ;R&   # )r	   r   r   r   )r    r?   r   r   r   r   r   r   r   r   ,   sF      tn(  tE#s(O,-9	 
  (~9 r   )r   )N)Z__name__Z
__module__Z__qualname__Z__firstlineno____doc__r   r   r   r   r   r#   r(   r3   r9   r   rA   r1   r%   r:   rE   r,   Z__annotate_func__Z__static_attributes__Z__classdictcell__)r   s   @r   r   r   ,   s     :(H09H095 5&
O 
OJ J">'.
 
 A A
' '# 4   r   r   i)rF   r0   r+   r*   Ztypingr    r   r   r   r6   Zinputremapper.configs.pathsr   Zinputremapper.logging.loggerr   Zinputremapper.utilsr   r;   r<   rC   r.   r   r   Zkeyboard_layout) r   r   <module>rG      sZ   & J  	  2 2  1 / *  ! 	l lb !"r   