
    
3jNm                    $   S SK Jr  S SKrS SKJr  S SKJr  S SKJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJr  S SKJr  S SKJr  S SKJr  \(       a  S S	KJrJr  S S
KJ r   S SK!J"r"  S*S jr# " S S\
5      r$ " S S\5      r% " S S\
5      r& " S S\
5      r' " S S\"5      r( " S S\(5      r) " S S\
5      r* " S S\*5      r+ " S S\*5      r,S+S jr- " S  S!\
5      r. " S" S#\
5      r/ " S$ S%\
5      r0 " S& S'5      r1\1" 5       r2S,S( jr3S-S) jr4g).    )annotationsN)suppress)copy)CDLLPOINTERArray	Structure_Pointer	addressofc_charc_char_pc_intc_uintc_uint8c_uint16c_uint32c_void_pcastcdll)RLock)TYPE_CHECKING)finalize)CallableIterable)Any)ScreenShotErrorc                &    [        U [        U5        g)a  Make sure that superobject is not GC'd before subobject.

In XCB, a structure often is allocated with additional trailing
data following it, with special accessors to get pointers to that
extra data.

In ctypes, if you access a structure field, a pointer value, etc.,
then the outer object won't be garbage collected until after the
inner object.  (This uses the ctypes _b_base_ mechanism.)

However, when using the XCB accessor functions, you don't get that
guarantee automatically.  Once all references to the outer
structure have dropped, then we will free the memory for it (the
response structures XCB returns have to be freed by us), including
the trailing data.  If there are live references to the trailing
data, then those will become invalid.

To prevent this, we use depends_on to make sure that the
outer structure is not released before all the references to the
inner objects have been cleared.
N)r   id)	subobjectsuperobjects     N/home/wildlama/miniconda3/lib/python3.13/site-packages/mss/linux/xcbhelpers.py
depends_onr"   B   s    6 YK(    c                      \ rS rSrSrg)
Connectionc    N)__name__
__module____qualname____firstlineno____static_attributes__r'   r#   r!   r%   r%   c   s    r#   r%   c                  (    \ rS rSrSS jrSS jrSrg)XIDg   c                j    [        U[        5      (       a  U R                  UR                  :H  $ [        $ N)
isinstancer.   valueNotImplemented)selfothers     r!   __eq__
XID.__eq__h   s&    ,6uc,B,BtzzU[[(VVr#   c                ,    [        U R                  5      $ r1   )hashr3   r5   s    r!   __hash__XID.__hash__k   s    DJJr#   r'   N)r6   objectreturnbool)r?   int)r(   r)   r*   r+   r7   r<   r,   r'   r#   r!   r.   r.   g   s    W r#   r.   c            
      T    \ rS rSrS\4S\4S\4S\4S\4S\4S\4S	\S
-  4S\44	rSrg)GenericErrorStructureo   response_type
error_codesequenceresource_id
minor_code
major_codepad0pad   full_sequencer'   N	r(   r)   r*   r+   r   r   r   _fields_r,   r'   r#   r!   rC   rC   o   sW     
'"	w	X	!	x 	w		1	(#
Hr#   rC   c                  <    \ rS rSrS\4S\S-  4S\4S\4S\44rSr	g	)
InternAtomReply   rE   rK      rG   lengthatomr'   N)
r(   r)   r*   r+   r   r   r   r.   rP   r,   r'   r#   r!   rR   rR      s4    	'"	1	X	8	Hr#   rR   c                      \ rS rSrSrSrg)XError   zBase exception class for anything related to X11.

This is not prefixed with Xcb to prevent confusion with the XCB
error structures.
r'   Nr(   r)   r*   r+   __doc__r,   r'   r#   r!   rX   rX      s    r#   rX   c                  @   ^  \ rS rSrSrSU 4S jjrSU 4S jjrSrU =r$ )XProtoError   z,Exception indicating server-reported errors.c                `  > [        U[        5      (       a  UR                  n[        U[        5      (       d   eUR                  UR
                  UR                  UR                  UR                  UR                  S.n[        R                  (       Gah  [        [        5      " 5       n[        R                  R                  X5      nUS:X  Ga.   [        [        5      " 5       n[        R                  R!                  XBR                  U5      nUR#                  SSS9US'   U(       a,  UR                  R$                  nUb  UR#                  SSS9US'   [        R                  R'                  XBR                  5      n	U	R#                  SSS9US'   [        R                  R)                  XBR                  UR                  5      n
U
(       a  U
R#                  SSS9US	'   [        R                  R+                  U5        [,        TU ]]  S
US9  g ! [        R                  R+                  U5        f = f)N)rF   rG   rH   rI   rJ   rN   r   asciireplace)errorserror	extension
major_name
minor_namezX11 Protocol Error)details)r2   r
   contentsrC   rF   rG   rH   rI   rJ   rN   LIBrb   r   XcbErrorsContextxcb_errors_context_newr   xcb_errors_get_name_for_errordecoder3   "xcb_errors_get_name_for_major_code"xcb_errors_get_name_for_minor_codexcb_errors_context_freesuper__init__)r5   xcb_connxcb_errrg   ctxctx_new_setupext_name
error_nameext_name_strre   rf   	__class__s              r!   rr   XProtoError.__init__   s   gx((&&G'#89999 ",,(("..!,,!,,$22
 :::*+-CJJ==hLM!<&x02H!$!I!I#OaOack!lJ'1'8'8'8'SGG$'/'8'8'>'>'33?3F3FwW`3F3aGK0!$!N!NsTfTf!gJ,6,=,=gi,=,XGL)!$!N!N//1C1C"J "0:0A0A'R[0A0\-JJ66s;-w? JJ66s;s   DH !H-c                L  > [         TU ]  5       nU R                  nSU;   a  US    SUS    S3OUS   nSU;   a  US    SUS    S3OUS   nSU;   a  US    SUS    S3OUS   nS	U;   a  S
US	    3OSnUSU SU U 3US   S:w  a  SU 3OS-   SUS    SUS    3-   -  nU$ )Nrc   rF   z ()re   rJ   rf   rI   rd   z
  Extension:   z
X Error of failed request:  z$
  Major opcode of failed request:  r   z$
  Minor opcode of failed request:  z#
  Resource id in failed request:  rH   z%
  Serial number of failed request:  rN   )rq   __str__rg   )r5   msgrg   
error_desc
major_desc
minor_descext_descrz   s          r!   r   XProtoError.__str__   sB   go,,HOSZHZ-.b1A0B!D`ght`u
DPT[D[w|$%R(='>a@ahiuav 	 EQT[D[w|$%R(='>a@ahiuav 	 ALw@V%gk&:%;<\^,ZL3J<zKGN|G\`aGa6zlCgik 5W]5K4L4W_5M4NPP	
 
r#   r'   )rs   r%   rt   rC   r?   None)r?   str)	r(   r)   r*   r+   r[   rr   r   r,   __classcell__)rz   s   @r!   r]   r]      s    6+@Z r#   r]   c                  ,    \ rS rSrSrS\44rSS jrSrg)
CookieBasei  zGeneric XCB cookie.

XCB does not export this as a base type.  However, all XCB cookies
have the same structure, so this encompasses the common structure
in Python.
rG   c                V    [         R                  R                  XR                  5        g)z<Free memory associated with this request, and ignore errors.N)ri   xcbxcb_discard_replyrG   )r5   rs   s     r!   discardCookieBase.discard  s    !!(MM:r#   r'   Nrs   r%   r?   r   )	r(   r)   r*   r+   r[   r   rP   r   r,   r'   r#   r!   r   r     s     V$&H;r#   r   c                  "    \ rS rSrSrSS jrSrg)
VoidCookiei  zSXCB cookie for requests with no responses.

This corresponds to xcb_void_cookie_t.
c                    [         R                  R                  X5      nU(       d  g[        UR                  5      n[         R
                  R                  U5        [        X5      e)zeVerify that the function completed successfully.

This will raise an exception if there is an error.
N)ri   r   xcb_request_checkr   rh   cfreer]   )r5   rs   err_perrs       r!   checkVoidCookie.check  sG    
 ))(95>>"

5(((r#   r'   Nr   )r(   r)   r*   r+   r[   r   r,   r'   r#   r!   r   r     s    

)r#   r   c                  "    \ rS rSrSrSS jrSrg)ReplyCookieBasei)  Nc                   [        [        5      " 5       nU R                  c   eU R                  XU5      nU(       ae  U(       a  [        R                  R                  U5        [        UR                  5      n[        R                  R                  U5        [        X5      eU(       d   e[        [        UR                  5      5      n[        U[        R                  R
                  U5      nSUl        UR                  $ )zWait for and return the server's response.

The response will be freed (with libc's free) when it, and its
descendents, are no longer referenced.

If the server indicates an error, an exception is raised
instead.
F)r   rC   _xcb_reply_funcri   r   r   r   rh   r]   r   r   r   atexit)r5   rs   r   reply_perr_copyreply_void_p	finalizers          r!   replyReplyCookieBase.reply,  s     -.0##///&&xu=

7#ENN+HEEJJuh11w  	'*:*: ;<Wceejj,?	 	r#   r'   )rs   r%   r?   r	   )r(   r)   r*   r+   r   r   r,   r'   r#   r!   r   r   )  s    O r#   r   c                :   UnUR                  5       R                  SS5      n[        X5      n[        X S35      n[        U S3[        4SU05      nX&l        Xl        [        [        5      U[        [        [        5      5      /Ul        [        U5      Ul        g)a  Set up ctypes for a response-returning XCB function.

This is only applicable to checked (the default) variants of
functions that have a response type.

This arranges for the ctypes function to take the given argtypes.
The ctypes function will then return an XcbTypedCookie (rather,
a function-specific subclass of it).  That can be used to call the
XCB xcb_blahblah_reply function to check for errors and return the
server's response.
_r~   _replyCookier   N)
titlera   getattrtyper   argtypesrestyper   r%   rC   )	libnamerequest_argtypesreply_struct	base_name
title_namerequest_func
reply_funccookie_types	            r!   initialize_xcb_typed_funcr   M  s     I"**33J3%Lfo.J*V,.@CTV`BabK,&":.WWMbEc=deJ .Jr#   c                  $    \ rS rSrS\4S\44rSrg)XcbExtensionii  r   	global_idr'   N)r(   r)   r*   r+   r   r   rP   r,   r'   r#   r!   r   r   i  s    "[%$89Hr#   r   c                      \ rS rSrSrSrg)rj   im  a+  A context for using libxcb-errors.

Create a context with xcb_errors_context_new() and destroy it with
xcb_errors_context_free(). Except for xcb_errors_context_free(),
all functions in libxcb-errors are thread-safe and can be called
from multiple threads at the same time, even on the same context.
r'   NrZ   r'   r#   r!   rj   rj   m  s    r#   rj   c            	      H    \ rS rSrS\4S\4S\4S\4S\4S\4S\4S	\44rS
rg)QueryExtensionReplyiz  rE   rK   rG   rU   presentmajor_opcodefirst_eventfirst_errorr'   NrO   r'   r#   r!   r   r   z  sI    	'"		X	8	G	!	 	 	Hr#   r   c                  Z    \ rS rSrSr\" 1 Sk5      rS	S jrS	S jr\" 5       4S
S jjr	Sr
g)LibContaineri  a  Container for XCB-related libraries.

There is one instance exposed as the xcb.LIB global.

You can access libxcb.so as xcb.LIB.xcb, libc as xcb.LIB.c, etc.
These are not set up until initialize() is called.  It is safe to
call initialize() multiple times.

Library accesses through this container return the ctypes CDLL
object.  There are no smart wrappers (although the return types are
the cookie classes defined above).  In other words, if you're
accessing xcb.LIB.xcb.xcb_foo, then you need to handle the .reply()
calls and such yourself.  If you're accessing the wrapper functions
in the xcb module xcb.foo, then it will take care of that for you.
>	   r   r   randrrb   renderxfixesrandr_id	render_id	xfixes_idc                >    [        5       U l        SU l        SU l        g )NF)r   _lock_initializinginitializedr;   s    r!   rr   LibContainer.__init__  s    W
" r#   c                *   U R                      U R                  (       a  Sn[        U5      eSU l        U R                   H&  n[        [        5         [        X5        S S S 5        M(     S S S 5        g ! , (       d  f       MB  = f! , (       d  f       g = f)Nz"Cannot reset during initializationF)r   r   RuntimeErrorr   _EXPOSED_NAMESr   AttributeErrordelattr)r5   r   r   s      r!   resetLibContainer.reset  sj    ZZ!!:"3''$D++n-D' .- , Z .- Zs$   ABA2B2
B<B
Bc                   SSK Jn  U R                     U R                  (       a
   S S S 5        g U R                  (       a  Sn[        U5      e SU l        [        R                  " S 5      U l        [        /U R                  R                  l        S U R                  R                  l        [        R                  R                  S5      nUc  Sn[!        U5      e[        R                  " U5      U l        [%        [&        5      [(        /U R"                  R*                  l        [%        [,        5      U R"                  R*                  l        [%        [&        5      [.        /U R"                  R0                  l        S U R"                  R0                  l        [%        [&        5      [%        [2        5      /U R"                  R4                  l        [%        [6        5      U R"                  R4                  l        [%        [&        5      [%        [2        5      /U R"                  R8                  l        S U R"                  R8                  l        [%        [&        5      /U R"                  R:                  l        [<        U R"                  R:                  l        [%        [&        5      /U R"                  R>                  l        [%        U5      U R"                  R>                  l        [%        [&        5      /U R"                  R@                  l        [B        U R"                  R@                  l        [D        [%        [B        5      /U R"                  RF                  l        [%        [&        5      U R"                  RF                  l        [%        [&        5      /U R"                  RH                  l        S U R"                  RH                  l        [K        [L        R"                  S[%        [&        5      [N        [P        [%        [R        5      /[T        5        [        R                  R                  S5      nUc  S	n[!        U5      e[        R                  " U5      U l+        [2        RY                  U RV                  S
5      U l-        [        R                  R                  S5      nUc  Sn[!        U5      e[        R                  " U5      U l.        [2        RY                  U R\                  S5      U l/        [        R                  R                  S5      nUc  Sn[!        U5      e[        R                  " U5      U l0        [2        RY                  U R`                  S5      U l1        [        R                  R                  S5      nUc  Sn[!        U5      e[        R                  " U5      U l2        [2        RY                  U Rd                  S5      U l3         [        R                  " S5      U l4        [%        [&        5      [%        [%        [j        5      5      /U Rh                  Rl                  l        [B        U Rh                  Rl                  l        [%        [j        5      /U Rh                  Rn                  l        S U Rh                  Rn                  l        [%        [j        5      [N        /U Rh                  Rp                  l        [D        U Rh                  Rp                  l        [%        [j        5      [N        [P        /U Rh                  Rr                  l        [D        U Rh                  Rr                  l        [%        [j        5      [N        [%        [D        5      /U Rh                  Rt                  l        [D        U Rh                  Rt                  l        U H
  n	U	" 5         M     SU l        SU l        S S S 5        g ! [v         a
    S U l4         N:f = f! SU l        f = f! , (       d  f       g = f)Nr   )Setupz!Cannot load during initializationTr   zLibrary libxcb.so not foundxcb_intern_atomz	xcb-randrz!Library libxcb-randr.so not foundxcb_randr_idz
xcb-renderz"Library libxcb-render.so not foundxcb_render_idzxcb-shmzLibrary libxcb-shm.so not found
xcb_shm_idz
xcb-xfixesz"Library libxcb-xfixes.so not foundxcb_xfixes_idzlibxcb-errors.so.0F)<mss.linux.xcbgenr   r   r   r   r   r   LoadLibraryr   r   r   r   r   ctypesutilfind_libraryr   r   r   r%   r   r   rC   r   r   r   xcb_get_extension_datar   xcb_prefetch_extension_dataxcb_generate_idr.   xcb_get_setupxcb_connection_has_errorr   r   xcb_connectxcb_disconnectr   ri   r   r   r   rR   r   in_dllr   r   r   shmshm_idr   r   rb   rj   rk   rp   rn   ro   rl   	Exception)
r5   	callbacksr   r   	libxcb_solibxcb_randr_solibxcb_render_solibxcb_shm_solibxcb_xfixes_soxs
             r!   
initializeLibContainer.initialize  s|   *ZZ Z
 !!9"3''l+%)" ))$/(0z$&*#"KK44U;	$7C)#..++I67>z7JJ6W**35<=R5S**27>z7JF6S**359**2<CJ<OQXYeQf;g//8:ABU:V//7AHATV]^jVk@l44=?C44<5<Z5H4I((136((03::3F2G&&/18&&.>Ej>Q=R11:<A1191975>0J$$-/6z/B$$,4;J4G3H''026''/ *GG%Z('8WV_M#	 #)++":":;"G"*=C)#..!--o>
 , 3 3DJJ O#);;#;#;L#I #+>C)#.."../?@!-!4!4T[[/!R & 8 8 C (;C)#..++M:*11$((LI#);;#;#;L#I #+>C)#.."../?@!-!4!4T[[/!RQ/3/?/?@T/UDK
  
+(8 9:CDKK66? BGDKK66>DKL\D]C^DKK77@BFDKK77?OVWgOhjqNrDKKBBKMUDKKBBJ 01 ODKKBBK
 NVDKKBBJ 01)JDKK==F
 IQDKK==E"AC # &+"#Do Zp ! '"&DK': &+"k ZsN   __U0^5?^F-^5_^2/^51^22^55	^>>_
_)r   r   r   rb   r   r   r   r   r   r   r   r   r   r   N)r?   r   )r   zIterable[Callable[[], None]]r?   r   )r(   r)   r*   r+   r[   	frozensetr   rr   r   r   r,   r'   r#   r!   r   r     s5      aN!
( DM; {$ {$r#   r   c                    U " U5      n/ nUR                   S:w  aL  UR                  R                  n[        XR5        UR	                  U5        U" U5        UR                   S:w  a  ML  U$ )Nr   )remdatarh   r"   append)iterator_factory	next_funcparentiteratoritemscurrents         r!   list_from_xcbr  P  s]    'HE
,,!
--((7#W( ,,!
 Lr#   c                    U " U5      nU" U5      nU(       a  U(       d  Sn[        U5      e[        U[        UR                  U-  5      5      nUR                  n[        Xr5        U$ )Nz4XCB returned a NULL pointer for non-zero data length)r   r   r   _type_rh   r"   )pointer_funclength_funcr   pointerrU   r   	array_ptrarrays           r!   array_from_xcbr
  \  s]    6"G FgDc""Wggnnv&=>?IEuLr#   )r   r   r    r   r?   r   )
r   r   r   r   r   listr   r   r?   r   )r   r   r   r   r   Structure | _Pointerr?   r  )r  r   r  r   r   r  r?   r   )5
__future__r   ctypes.utilr   
contextlibr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   	threadingr   typingr   weakrefr   collections.abcr   r   r   mss.exceptionr   r"   r%   r.   rC   rR   rX   r]   r   r   r   r   r   rj   r   r   ri   r  r
  r'   r#   r!   <module>r     s   "       $    2 )D)B	 	 (  I "i j_ B& BJ; ;() )&! j ! H/8:9 :y 
) 
 _$ _$D nH		r#   