
    ;;i`                     D   d Z ddlZddlZddlmZ ej
                  j                  ej                  j                  d            Z	ej                  Zee	j                  _        ee	j                  _        ee	j                  _        eege	j                  _        e	j                  Zd Zd Zd Zej
                  j                  ej                  j                  d            Zej,                  Zee_        eej.                  ej0                  eege_        ej2                  Zej.                  e_        ege_        ej4                  Zde_        eej6                  ge_        ej8                  Zee_        eeege_        ej:                  Zee_        ej<                  Zde_        eeege_        ej>                  Zde_        ege_        ej@                  Z de _        ege _        d	Z!ejE                  ed
      Z#d Z$d Z%d Z& ejN                  deee      Z( e(e&      Z)d Z*d Z+y)zBInputhook for OS X

Calls NSApp / CoreFoundation APIs via ctypes.
    N)Eventobjcc                 H    t        | t              s| j                  d      } | S )zensure utf8 bytesutf8)
isinstancebytesencode)ss    _/home/rose/Desktop/poly/venv/lib/python3.12/site-packages/IPython/terminal/pt_inputhooks/osx.py_utf8r      s    aHHVH    c                 >    t         j                  t        |             S )z)create a selector name (for ObjC methods))r   sel_registerNamer   )names    r   nr      s      t--r   c                 >    t         j                  t        |             S )zget an ObjC Class by name)r   objc_getClassr   )	classnames    r   Cr   !   s    eI.//r   CoreFoundation   kCFRunLoopCommonModesc                  |    t         t         gt        j                  _        t	        t        d      t        d            S )z0Return the global NSApplication instance (NSApp)NSApplicationsharedApplicationvoid_pr   objc_msgSendargtypesmsgr   r    r   r   _NSAppr"   N   s-    "(&!1Dq!1%8#9::r   c                 |   t         t         t         t         t         t         t         t         t         t         t         gt        j                  _        t	        t        d      t        d      ddddddddd      }t         t         t         t         gt        j                  _        t	        | t        d      t        |      d       y)zWake the ApplicationNSEventz]otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:   r   NzpostEvent:atStart:Tr   )NSAppevents     r   _waker(   T   s     	"D 	)	B	
 								E  #)&&&!ADq%&ut<r   c                     t        |        t        |        t               }t        t        t        gt        j
                  _        t        |t        d      |       t        |       y)z.Callback to fire when there's input to be readzstop:N)
CFFileDescriptorInvalidate	CFReleaser"   r   r   r   r   r    r   r(   )fdrefflagsinfor&   s       r   _input_callbackr/   w   sE    u%eHE"(&&!9Dqz5!	%Lr   c                     t        d| dt        d      }t        |t               t	        d|d      }t               }t        ||t               t        |       y)z;Register callback to stop eventloop when there's data on fdNFr   )	CFFileDescriptorCreate_c_input_callbackCFFileDescriptorEnableCallBackskCFFileDescriptorReadCallBack#CFFileDescriptorCreateRunLoopSourceCFRunLoopGetCurrentCFRunLoopAddSourcer   r+   )fdr,   sourceloops       r   _stop_on_readr;      sK    "4U4EtLE#E+HI0ua@F DtV%:;fr   c                     t               }t        | j                                t        t        gt        j
                  _        t        |t        d             y)zInputhook for Cocoa (NSApp)runN)	r"   r;   filenor   r   r   r   r    r   )contextr&   s     r   	inputhookr@      s9    HE'.."#"(&!1Dqxr   ),__doc__ctypesctypes.util	threadingr   cdllLoadLibraryutilfind_libraryr   c_void_pr   r   restyper   r   r   r    r   r   r   r   r1   c_intc_bool#CFFileDescriptorGetNativeDescriptorr3   c_ulongr5   r6   r7   r+   r*   r4   in_dllr   r"   r(   r/   	CFUNCTYPE_c_callback_func_typer2   r;   r@   r!   r   r   <module>rR      s1     {{v{{77?@	#    &   "   $f-   
.0 (()A)ABR)ST'>> !'  #)6<<PV"W  &4&X&X #.4ll # +06x # ,"0"P"P *.  ',2FNN+C  (&4&X&X #.4 # +06/G # ,$88 $  #66 !  %vv6  $$		 X	 +FF %)  "'-h  # !" n6MN ; =F )((vvvF )/: r   