
    ^j                         d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 	 ddlm
Z
 n#  Y nxY wda e            Zda G d d          Zd	 Zd
 Zd Zd Zd ZdS )a  Fork a child process and inform it of mode changes to each screen.  The
child waits until the parent process dies, and then connects to each X server 
with a mode change and restores the mode.

This emulates the behaviour of Windows and Mac, so that resolution changes
made by an application are not permanent after the program exits, even if
the process is terminated uncleanly.

The child process is communicated to via a pipe, and watches for parent
death with a Linux extension signal handler.
    N)xlib)asbytes)	xf86vmodeFc                   `    e Zd ZdZ ej        e          Zd Zd Ze	d             Z
d Zd ZdS )
ModePacket256siHHIc                 L    || _         || _        || _        || _        || _        d S N)displayscreenwidthheightrate)selfr   r   r   r   r   s         ]/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/display/xlib_vidmoderestore.py__init__zModePacket.__init__-   s)    
			    c                 p    t          j        | j        | j        | j        | j        | j        | j                  S r
   )structpackformatr   r   r   r   r   r   s    r   encodezModePacket.encode4   s*    {4;dk4:t{\`\efffr   c                     t          j        | j        |          \  }}}}} | |                    t	          d                    ||||          S )N )r   unpackr   stripr   )clsdatar   r   r   r   r   s          r   decodezModePacket.decode7   sJ    /5}SZ/N/N,s7==//MMMr   c                 p    | j         j         d| j         d| j         d| j         d| j         d| j         dS )N(z, ))	__class____name__r   r   r   r   r   r   s    r   __repr__zModePacket.__repr__<   sv    .) K KDL K K+K K!%K K/3{K K>BiK K K 	Kr   c                 .   t          j        | j                  }t          || j                  \  }}t          ||| j        | j        | j                  }|t          j
        || j        |           t          ||           t          j        |           d S r
   )r   XOpenDisplayr   get_modes_arrayr   get_matching_moder   r   r   r   XF86VidModeSwitchToModefree_modes_arrayXCloseDisplay)r   r   modesn_modesmodes        r   setzModePacket.set@   s    #DL11($+>>w T[$)TT-gt{DIII(((7#####r   N)r%   
__module____qualname__r   r   calcsizesizer   r   classmethodr    r&   r1    r   r   r   r   )   s        F6?6""D  g g g N N [NK K K$ $ $ $ $r   r   c                     t          j                    } t          j        t          j        t          j                                        }t          j        | |||           ||j        fS r
   )ctypesc_intPOINTERr   XF86VidModeModeInfoXF86VidModeGetAllModeLinesvalue)r   r   countr.   s       r   r)   r)   J   sU    LNNEIFN6>)*GHHIIKKE(&%GGG%+r   c                     t          |          D ]4}| j        |         }|j        |k    r|j        |k    r|j        |k    r|c S 5d S r
   )rangecontentshdisplayvdisplaydotclock)r.   r/   r   r   r   ir0   s          r   r*   r*   Q   sY    7^^  ~a MU""''%%KKK4r   c                     t          |          D ]/}| j        |         }|j        rt          j        |j                   0t          j        |            d S r
   )rA   rB   privsizer   XFreeprivate)r.   r/   rF   r0   s       r   r,   r,   \   sV    7^^ % %~a = 	%Jt|$$$Jur   c                     t           rd S t          j                    \  } at          j                    dk    rt          j        t                     d}t          j                            d          }t          j	        t          j
        t          j
        t          j
        t          j
        f|j        _        |                    |t          j        ddd           fd}t          j                                                     t          j        t          j        |           g }t%          d          }                                r	 t          j        | t*          j                  }||z  }t/          |          t*          j        k    rrt*                              |d t*          j                           }|                    |           |t*          j        d          }t/          |          t*          j        k    rn# t4          $ r Y nw xY w                                |D ]}|                                 t          j        d           d S t          j        |            da d S )Nr      z	libc.so.6c                 0                                      d S r
   )release)signumframeparent_wait_locks     r   _sighupz,_install_restore_mode_child.<locals>._sighup|   s    $$&&&&&r    T)_restore_mode_child_installedospipe_mode_write_pipeforkcloser9   cdllLoadLibraryr:   c_ulongprctlargtypessignalSIGHUP	threadingLockacquirer   lockedreadr   r5   lenr    appendOSErrorr1   _exit)	mode_read_pipePR_SET_PDEATHSIGlibcrR   packetsbufferr   packetrQ   s	           @r   _install_restore_mode_childrp   d   s+    %  (*wyy$N$	wyyA~~
!""" {&&{33%|V^V^%~v~?


#V]Aq!<<<
	' 	' 	' 	' 	' %>++  """fmW--- %%'' 
		w~z??$&kkZ_44'..v6Fz6F/GHHFNN6***#JO$4$45F &kkZ_44     %%'' 
	  	 	FJJLLLL
 	   (,%%%s   
B3G> >
H
Hc                    t                       t          j        | j        j        j                  }| j        j        j        }||ft          v rd S t          ||| j	        | j
        | j        j                  }t          j        t          |                                           t                              ||f           d S r
   )rp   r   XDisplayStringr   r   _displayx_screen_restorable_screensr   r   r   inforE   rU   writerW   r   add)r0   r   r   ro   s       r   set_initial_modery      s    !!!!$+"5">??G[ )F 	///T[$)BTUUFHv}}///Wf-.....r   )__doc__r9   rU   r_   r   ra   pyglet.libs.x11r   pyglet.utilr   r   rT   r1   ru   rW   r   r)   r*   r,   rp   ry   r7   r   r   <module>r}      s$  
 
  				                        	)))))))	D % cee  $ $ $ $ $ $ $ $B      7- 7- 7-t/ / / / /s   + /