
    ^jt                       d Z ddlmZ ddlmZ ddlmZ ddlm	Z
 ddlmZ er,ddlmZmZmZ ddlmZmZ ee         ee         z  ee         z  Zd	Zd	Zd
ZdZdZeez   Zeez   Zeez   ZdZdZdZd dZd!dZ d"dZ!d"dZ"d!dZ#d!dZ$d"dZ%dS )#a  Factory functions to provide equivalent functionality as the Linux ioctl macros.

Ioctl macros are commonly used on Linux for interacting with character (char)
files. This module provides factory functions that create custom helper functions
to perform these same types of operations.

In pyglet, the input/evdev backend uses these functions for interacting with input
devices. For example, the helper functions are first defined::

    # Create a function for reading a HID descriptor size:
    HIDIOCGRDESCSIZE = _IOR(code='H', nr=0x01, struct=ctypes.c_uint)

    # Create a function for writing Force Feedback data:
    EVIOCSFF = _IOW(code='E', nr=0x80, struct=FFEventStruct)

    # Create a function to read a device name as a str:
    EVIOCGNAME = _IOR_str('E', 0x06)

These functions are then called to perform the operations::

    # Query the HID descriptor size (as uint):
    desc_size = HIDIOCGRDESCSIZE(fileno).value

    # Write a force feedback event (defined in a Structure):
    EVIOCSFF(fileno, ff_event_struct_instance)

    # Query the device name:
    name = EVIOCGNAME(fileno)


https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/ioctl.h

    )annotations)ioctl)sizeof)create_string_buffer)TYPE_CHECKING)	Structurec_intc_uint)CallableUnion            io_dir'Union[_IOC_NONE, _IOC_READ, _IOC_WRITE]codeintnrsizereturnc                X    | t           z  |t          z  z  |t          z  z  |t          z  z  S N)_IOC_DIRSHIFT_IOC_TYPESHIFT_IOC_NRSHIFT_IOC_SIZESHIFT)r   r   r   r   s       L/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/libs/ioctl.py_IOCr   C   s-    m#(>?2CUVZ^bpZpqq    strstructc_datar   c                x    t          t          t          |           |t                              fd}|S )Nc                4     | }t          | |           |S r   _ioctl)filenoargsbufferrequestr"   s      r   fz_IOR.<locals>.fJ   s%    vw'''r    )r   	_IOC_READord_sizeofr   r   r"   r,   r+   s     ` @r   _IORr1   G   sH    9c$iiWV__==G     
 Hr    c                      fd}|S )Nc                    t          t          t                    t          |                    }t	          | ||           |S r   )r   r-   r.   r/   r'   r(   r*   r+   r   r   s      r   r,   z_IOR_len.<locals>.fT   s9    y#d))RAAvw'''r     r   r   r,   s   `` r   _IOR_lenr7   R   )         
 Hr    c                4    t          | |          dfd	}|S )N   c                @     | t          |                    j        S r   )_create_string_buffervalue)r(   lengthgs     r   r,   z_IOR_str.<locals>.f_   s!    q.v6677==r    )r:   )r7   )r   r   r,   r?   s      @r   _IOR_strr@   \   s7    rA> > > > > > Hr    c                x    t          t          t          |           |t                              fd}|S )Nc                `    t          |          s |          }t          | |           d S r   )
isinstancer'   )r(   r*   r+   r"   s     r   r,   z_IOW.<locals>.fh   s:    &&)) 	$VF^^Fvw'''''r    )r   
_IOC_WRITEr.   r/   r0   s     ` @r   _IOWrE   e   sH    :s4yy"gfoo>>G( ( ( ( ( (
 Hr    c                    t          t          t          z  t          |           |t	          |                    fd}|S )Nc                *    t          | |           |S r   r&   )r(   r*   r+   s     r   r,   z_IOWR.<locals>.fs   s    vw'''r    )r   r-   rD   r.   r/   r0   s       @r   _IOWRrH   p   sG    9z)3t99b'&//JJG     Hr    c                      fd}|S )Nc                    t          t          t          z  t                    t	          |                    }t          | ||           |S r   )r   r-   rD   r.   r/   r'   r4   s      r   r,   z_IOWR_len.<locals>.f|   s>    y:-s4yy"gfooNNvw'''r    r5   r6   s   `` r   	_IOWR_lenrK   z   r8   r    N)
r   r   r   r   r   r   r   r   r   r   )r   r!   r   r   r"   r#   r   r   )r   r!   r   r   r   r   )&__doc__
__future__r   fcntlr   r'   ctypesr   r/   r   r<   typingr   r   r	   r
   r   r   typer#   _IOC_NRBITS_IOC_TYPEBITS_IOC_SIZEBITS_IOC_DIRBITSr   r   r   r   	_IOC_NONErD   r-   r   r1   r7   r@   rE   rH   rK   r5   r    r   <module>rW      s     B # " " " " " ! ! ! ! ! ! $ $ $ $ $ $ @ @ @ @ @ @             ://////////&&&&&&&&)_tE{*T&\9F +-/.	
	r r r r                    r    