
    ^h                        S r SSKrSSKrSSKJr  \R
                  R                  \R                  R                  S5      5      r	\R                  r\\	R                  l        \\	R                  l        \\	R                  l        \	R                  rS rS rS r\R
                  R                  \R                  R                  S5      5      r\R*                  r\R,                  \l        \R.                  r\\l        \R0                  r\\l        \R2                  rS\l        \/\l        \R6                  r\\l        \\R,                  \R,                  \R8                  \R8                  \\/\l        \R:                  rS\l        \\\/\l        \R=                  \S	5      rS
 r S r!\" 5       r"SS jr#\RH                  " S\\5      r%\%" \#5      r&S r'SS jr(g)zGEventloop hook for OS X

Calls NSApp / CoreFoundation APIs via ctypes.
    N)Eventobjcc                 R    [        U [        5      (       d  U R                  S5      n U $ )zensure utf8 bytesutf8)
isinstancebytesencode)ss    T/home/james-whalen/.local/lib/python3.13/site-packages/ipykernel/_eventloop_macos.py_utf8r      s"    aHHVH    c                 >    [         R                  [        U 5      5      $ )z)create a selector name (for ObjC methods))r   sel_registerNamer   )names    r   nr      s      t--r   c                 >    [         R                  [        U 5      5      $ )zget an ObjC Class by name)r   objc_getClassr   )	classnames    r   Cr   $   s    eI.//r   CoreFoundationkCFRunLoopCommonModesc                  |    [         [         /[        R                  l        [	        [        S5      [        S5      5      $ )z0Return the global NSApplication instance (NSApp)NSApplicationsharedApplicationvoid_pr   objc_msgSendargtypesmsgr   r    r   r   _NSAppr!   P   s-    "(&!1Dq!1%8#9::r   c                 |   [         [         [         [         [         [         [         [         [         [         [         /[        R                  l        [	        [        S5      [        S5      SSSSSSSSS5      n[         [         [         [         /[        R                  l        [	        U [        S5      [        U5      S5        g)zWake the ApplicationNSEventz]otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:   r   NzpostEvent:atStart:Tr   )NSAppevents     r   _waker'   V   s     	"D 	)	B	
 								E  #)&&&!ADq%&ut<r   c                 d   [         R                  5         [        5       n[        [        /[        R
                  l        [        U[        S5      5      (       aF  [        [        [        /[        R
                  l        [        U[        S5      U5        [        U5        g[        [        5       5        g)z.Callback to fire when there's input to be read	isRunningzstop:N)
_triggeredsetr!   r   r   r   r   r   r   r'   CFRunLoopStopCFRunLoopGetCurrent)timerloopr%   s      r   stopr0   |   sq    NNHE #)&!1D
5!K.!!&,ff%="E1W:u%e)+,r   c           	      v    [        S[        5       U -   SSS[        S5      n[        [	        5       U[
        5        g)z1Register callback to stop eventloop after a delayNr   )CFRunLoopTimerCreateCFAbsoluteTimeGetCurrent_c_stop_callbackCFRunLoopAddTimerCFRunLoopGetMainr   )delayr.   s     r   _stop_afterr8      s?      "U*			E r   c                    [         R                  5         [        5       n[        U 5        [        [        /[
        R                  l        [        U[        S5      5        [         R                  5       (       d  [        R                  5         gg)z<run the Cocoa eventloop for the specified duration (seconds)runN)r*   clearr!   r8   r   r   r   r   r   r   is_setr   CFRunLoopRun)durationr%   s     r   mainloopr?      sb     HE"(&!1Dqx
 	##% r   )NN)   ))__doc__ctypesctypes.util	threadingr   cdllLoadLibraryutilfind_libraryr   c_void_pr   r   restyper   r   r   r   r   r   r   r3   c_doubler-   r6   r,   r   r2   c_intr5   in_dllr   r!   r'   r*   r0   	CFUNCTYPE_c_callback_func_typer4   r8   r?   r    r   r   <module>rP      s     {{v{{77?@	#    &   "   
.
0 ((
KK-. *BB #)??   $88 $  !22 !  ,,   %:: %  

OO
OO
LL
LL

!   #44    $ff5  n6MN ; =F W
- ((vv> (. $&r   