
    7}e                     6   d Z ddlZddlZddlmZ ej                            e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                            ej                            d                    Zej        Zej        e_        ej        Zee_        ej        Zee_        ej        Zde_        ege_        ej        Zee_        eej        ej        ej        ej        eege_        ej        Zde_        eeege_        e                    ed	          Zd
 Z d Z! e            Z"ddZ# ej$        dee          Z% e%e#          Z&d Z'ddZ(dS )zGEventloop hook for OS X

Calls NSApp / CoreFoundation APIs via ctypes.
    N)Eventobjcc                 Z    t          | t                    s|                     d          } | S )zensure utf8 bytesutf8)
isinstancebytesencode)ss    :lib/python3.11/site-packages/ipykernel/_eventloop_macos.py_utf8r      s*    a HHVH    c                 P    t                               t          |                     S )z)create a selector name (for ObjC methods))r   sel_registerNamer   )names    r   nr       s      t---r   c                 P    t                               t          |                     S )zget an ObjC Class by name)r   objc_getClassr   )	classnames    r   Cr   %   s    eI..///r   CoreFoundationkCFRunLoopCommonModesc                  V    t          t          d          t          d                    S )z0Return the global NSApplication instance (NSApp)NSApplicationsharedApplication)msgr   r    r   r   _NSAppr   Q   s#    q!!1%8#9#9:::r   c                     t          t          d          t          d          ddddddddd          }t          | t          d          t          |          d           dS )zWake the ApplicationNSEventz]otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:   r   NzpostEvent:atStart:T)r   r   r   void_p)NSAppevents     r   _waker$   V   su    	)	B	
 	
 								 E  q%&&ut<<<<<r   c                 "   t                                            t                      }t          |t	          d                    r/t          |t	          d          |           t          |           dS t          t                                 dS )z.Callback to fire when there's input to be read	isRunningzstop:N)
_triggeredsetr   r   r   r$   CFRunLoopStopCFRunLoopGetCurrent)timerloopr"   s      r   stopr-   n   sw    NNHHE 5!K..!! -E1W::u%%%e)++,,,,,r   c           	          t          dt                      | z   dddt          d          }t          t	                      |t
                     dS )z1Register callback to stop eventloop after a delayNr   )CFRunLoopTimerCreateCFAbsoluteTimeGetCurrent_c_stop_callbackCFRunLoopAddTimerCFRunLoopGetMainr   )delayr+   s     r   _stop_afterr5      s^      ""U*			 E     r      c                    t                                            t                      }t          |            t	          |t          d                     t                                           st                                           dS dS )z<run the Cocoa eventloop for the specified duration (seconds)runN)	r'   clearr   r5   r   r   is_setr   CFRunLoopRun)durationr"   s     r   mainloopr=      s{     HHEqxx &
 	##%%%%%& &r   )NN)r6   ))__doc__ctypesctypes.util	threadingr   cdllLoadLibraryutilfind_libraryr   c_void_pr!   r   restyper   objc_msgSendargtypesr   r   r   r   r   r0   c_doubler*   r3   r)   r/   c_intr2   in_dllr   r   r$   r'   r-   	CFUNCTYPE_c_callback_func_typer1   r5   r=   r   r   r   <module>rO      sT              {v{77??@@	#   &  "  $f-  
  . . .
0 0 0 ((
K-..  *B #)?   $8 $  !2 !  ,   %: %  

O
O
L
L

!   #4    $ff5  n6MNN ; ; ;
= = =* UWW

- 
- 
- 
- )(vv>> ((..   $& & & & & &r   