
    
3j`                       % S r SSKJr  SSKrSSK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JrJr  SSK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)J*r*  Sr+\" 5       r,Sr-Sr.Sr/Sr0\01r1 " S S\5      r2 " S S\5      r3 " S S\5      r4 " S S\
5      r5 " S S\
5      r6 " S S\
5      r7 " S S\
5      r8 " S  S!\
5      r9 " S" S#\
5      r: " S$ S%\
5      r; " S& S'\
5      r< " S( S)\
5      r= " S* S+\
5      r>0 r?\" S,5      r@\" S-5      rA\" S.5      rB " S/ S0\$5      rC\" \\	" \55      \	" \85      5      S;S1 j5       rD        S<S2 jrES3\	" \55      /\4S3\	" \55      /\24S3\	" \:5      /\4S4\	" \55      /\	" \95      4S3\	" \55      \2\\\\\\/\	" \:5      4S3\	" \55      \2\	" \>5      /\34S3\/\	" \55      4S3\	" \55      \\	" \5      \	" \5      \	" \5      /\44S5\	" \55      \	" \5      \	" \5      /\34S5\	" \;5      /S4S5\	" \=5      /S4S5\	" \55      \	" \=5      \2/\	" \;5      4S5\	" \55      \2/\	" \=5      4S5\	" \55      \2/\	" \=5      4S3\/\4S6.rFS7\GS8'    " S9 S:\"5      rHg)=a-  Legacy Xlib-based GNU/Linux backend.

This backend talks to X11 via Xlib and the Xrandr extension, and is retained
as a fallback when XCB backends are unavailable. Cursor capture uses XFixes
when available.

.. versionadded:: 10.2.0 Prior to this version, this was available as
    ``mss.linux.MSS``.
    )annotationsN)suppress)	CFUNCTYPEPOINTER	Structure_Pointerbyrefc_char_pc_intc_shortc_ubytec_uintc_ulongc_ushortc_void_pcastcdllcreate_string_buffer)find_library)Lockcurrent_threadlocal)TYPE_CHECKINGAny)MSSImplementation)ScreenShotError)
ScreenShot)
CFunctionsMonitorMonitors    i        c                      \ rS rSrSrSrg)XID>   zX11 generic resource ID
https://tronche.com/gui/x/xlib/introduction/generic.html
https://gitlab.freedesktop.org/xorg/proto/xorgproto/-/blob/master/include/X11/X.h#L66
r!   N__name__
__module____qualname____firstlineno____doc____static_attributes__r!       H/home/wildlama/miniconda3/lib/python3.13/site-packages/mss/linux/xlib.pyr&   r&   >   s    r/   r&   c                      \ rS rSrSrSrg)XStatusE   a  Xlib common return code type
This is Status in Xlib, but XStatus here to prevent ambiguity.
Zero is an error, non-zero is success.
https://tronche.com/gui/x/xlib/introduction/errors.html
https://gitlab.freedesktop.org/xorg/lib/libx11/-/blob/master/include/X11/Xlib.h#L79
r!   Nr(   r!   r/   r0   r2   r2   E       r/   r2   c                      \ rS rSrSrSrg)XBoolN   zXlib boolean type
This is Bool in Xlib, but XBool here to prevent ambiguity.
0 is False, 1 is True.
https://tronche.com/gui/x/xlib/introduction/generic.html
https://gitlab.freedesktop.org/xorg/lib/libx11/-/blob/master/include/X11/Xlib.h#L78
r!   Nr(   r!   r/   r0   r6   r6   N   r4   r/   r6   c                      \ rS rSrSrSrg)DisplayW   a  Structure that serves as the connection to the X server
and that contains all the information about that X server.
The contents of this structure are implementation dependent.
A Display should be treated as opaque by application code.
https://tronche.com/gui/x/xlib/display/display-macros.html
https://gitlab.freedesktop.org/xorg/lib/libx11/-/blob/master/include/X11/Xlib.h#L477
https://github.com/garrybodsworth/pyxlib-ctypes/blob/master/pyxlib/xlib.py#L831.
r!   Nr(   r!   r/   r0   r9   r9   W   s    r/   r9   c                      \ rS rSrSrSrg)Visuald   a&  Visual structure; contains information about colormapping possible.
https://tronche.com/gui/x/xlib/window/visual-types.html
https://gitlab.freedesktop.org/xorg/lib/libx11/-/blob/master/include/X11/Xlib.hheads#L220
https://github.com/garrybodsworth/pyxlib-ctypes/blob/master/pyxlib/xlib.py#302.
r!   Nr(   r!   r/   r0   r<   r<   d   s    r/   r<   c                      \ rS rSrSrSrg)Screenn   a*  Information about the screen.
The contents of this structure are implementation dependent.  A
Screen should be treated as opaque by application code.
https://tronche.com/gui/x/xlib/display/screen-information.html
https://gitlab.freedesktop.org/xorg/lib/libx11/-/blob/master/include/X11/Xlib.h#L253
r!   Nr(   r!   r/   r0   r?   r?   n   r4   r/   r?   c                  R    \ rS rSrSrS\4S\" \5      4S\4S\	4S\
4S\
4S	\
44rS
rg)XErrorEventy   zXErrorEvent to debug eventual errors.
https://tronche.com/gui/x/xlib/event-handling/protocol-errors/default-handlers.html.
https://gitlab.freedesktop.org/xorg/lib/libx11/-/blob/master/include/X11/Xlib.h#L920
typedisplay
resourceidserial
error_coderequest_code
minor_coder!   N)r)   r*   r+   r,   r-   r   r   r9   r&   r   r   _fields_r.   r!   r/   r0   rB   rB   y   sL     
	GG$%	s	7	w	!	wHr/   rB   c                  d    \ rS rSrSrS\4S\4S\4S\4S\4S\4S	\4S
\" \5      4S\4S\	44
r
Srg)XFixesCursorImage   zCursor structure.
/usr/include/X11/extensions/Xfixes.h
https://github.com/freedesktop/xorg-libXfixes/blob/libXfixes-6.0.0/include/X11/extensions/Xfixes.h#L96.
xywidthheightxhotyhotcursor_serialpixelsatomnamer!   N)r)   r*   r+   r,   r-   r   r   r   r   r
   rK   r.   r!   r/   r0   rM   rM      sc     
g	g	(	8			'"	77#$		Hr/   rM   c                  v    \ rS rSrSrS\4S\4S\4S\4S\4S\4S	\4S
\4S\4S\4S\4S\4S\4S\4S\44rSr	g)XImage   zDescription of an image as it exists in the client's memory.
https://tronche.com/gui/x/xlib/graphics/images.html
https://gitlab.freedesktop.org/xorg/lib/libx11/-/blob/master/include/X11/Xlib.h#L353
rQ   rR   xoffsetformatdata
byte_orderbitmap_unitbitmap_bit_order
bitmap_paddepthbytes_per_linebits_per_pixelred_mask
green_mask	blue_maskr!   N)
r)   r*   r+   r,   r-   r   r   r   rK   r.   r!   r/   r0   rZ   rZ      s     
%	5	E	5		u		U#	u	%	5!	5!	W	w	gHr/   rZ   c                  |    \ rS rSrSrS\4S\4S\4S\4S\4S\4S	\	4S
\4S\
" \5      4S\	4S\4S\
" \5      44rSrg)XRRCrtcInfo   zStructure that contains CRTC information.
https://gitlab.freedesktop.org/xorg/lib/libxrandr/-/blob/master/include/X11/extensions/Xrandr.h#L360.
	timestamprO   rP   rQ   rR   moderotationnoutputoutputs	rotations	npossiblepossibler!   N)r)   r*   r+   r,   r-   r   r   r   r&   r   r   rK   r.   r!   r/   r0   rj   rj      su    
 
g	e	e	&	6		X	E	GCL!	h	e	WS\"Hr/   rj   c                      \ rS rSrSrSrg)XRRModeInfo   zehttps://gitlab.freedesktop.org/xorg/lib/libxrandr/-/blob/master/include/X11/extensions/Xrandr.h#L248.r!   Nr(   r!   r/   r0   ru   ru      s    or/   ru   c                  p    \ rS rSrSrS\4S\4S\4S\" \5      4S\4S\" \5      4S	\4S
\" \	5      44r
Srg)XRRScreenResources   zStructure that contains arrays of XIDs that point to the
available outputs and associated CRTCs.
https://gitlab.freedesktop.org/xorg/lib/libxrandr/-/blob/master/include/X11/extensions/Xrandr.h#L265.
rl   configTimestampncrtccrtcsro   rp   nmodemodesr!   N)r)   r*   r+   r,   r-   r   r   r   r&   ru   rK   r.   r!   r/   r0   rx   rx      s]     
g	G$	%	'#,	E	GCL!	%	'+&'	Hr/   rx   c                      \ rS rSrSrS\4S\4S\4S\4S\4S\4S	\" \5      4S
\4S\4S\4S\4S\4S\	4S\	4S\
4S\4S\
4S\4S\	4S\	4S\	4S\
4S\" \5      44rSrg)XWindowAttributes   zAttributes for the specified window.
https://tronche.com/gui/x/xlib/window-information/XGetWindowAttributes.html
https://gitlab.freedesktop.org/xorg/lib/libx11/-/blob/master/include/X11/Xlib.h#L304
rO   rP   rQ   rR   border_widthrc   visualrootclassbit_gravitywin_gravitybacking_storebacking_planesbacking_pixel
save_undercolormapmapinstalled	map_stateall_event_masksyour_event_maskdo_not_propagate_maskoverride_redirectscreenr!   N)r)   r*   r+   r,   r-   r   r   r<   r&   r   r6   r   r?   rK   r.   r!   r/   r0   r   r      s     
e	e	%	5		%	76?#		%			% 	7#	'"	u	S		f	G$	G$	 '*	e$	76?#/Hr/   r   X11XfixesXrandrc                  ,   ^  \ rS rSrSU 4S jjrSrU =r$ )XErrori  c                h  > [         TU ]  5       nU R                  (       a  USU R                  S    SU R                  S    SU R                  S    S3-  nU R                  S   [        :  a  USU R                  S	    3-  nUS
U R                  S   R                   SU R                  S    3-  nU$ )Nz
X Error of failed request:  errorz$
  Major opcode of failed request:  rI   z (request)z$
  Minor opcode of failed request:  rJ   z#
  Resource id in failed request:  rF   z%
  Serial number of failed request:  rG   )super__str__detailsX_FIRST_EXTENSION_OPCODEvalue)selfmsg	__class__s     r0   r   XError.__str__  s    go <<
 0g1F0G7^8T7UUWX\XdXdenXoWppqsC ||N+/GG>t||L?Y>Z[[6t||L7Q7W7W6X8h9O8PRC 
r/   r!   )returnstr)r)   r*   r+   r,   r   r.   __classcell__r   s   @r0   r   r     s     r/   r   c           
        [         R                  " [        5      nUR                  n[	        [
        5      [        [        [        /Ul        [        Ul
        UR                  n[	        [
        5      [        [        [        [        [        /Ul        [        Ul
        UR                  n[        S5      nU" XR                  U[        U5      5        [        S5      nU" U SSUR                   -  SU[        U5      5        [#        [$        S5      (       a  [$        R&                  " 5       O[$        R(                  " SS9nUR*                  R-                  USS	9UR                  UR.                  UR*                  R-                  USS	9UR                   UR0                  UR2                  UR4                  S
.[6        [9        5       '   g)z/Specifies the program's supplied error handler.i   s   XRequests   %is   Extension-specificgetencodingF)do_setlocalereplace)errors)r   rH   rJ   r   rI   rG   rF   rD   r   )r   LoadLibrary_X11XGetErrorTextr   r9   r   r
   argtypesr   restypeXGetErrorDatabaseTextcontentsr   rH   lenrI   hasattrlocaler   getpreferredencodingr   decoderJ   rG   rF   rD   _ERRORr   )	rE   eventxlib	get_errorget_error_databaseevtr   r   encodings	            r0   _error_handlerr   #  sc    D!D""I!'*E8UCI I33#*7#3XxS[]b"c!&
..C &Eg~~uc%j9"4(GwUS5E5E-EG\^egjkrgst !( > >FD_D_mrDs  ##HY#?nnnn=='''C((**nn	 F> r/   c               h   [        5       nU c  SnOb[        U [        [        [        [
        45      (       a  [        U 5      nO1[        U [        5      (       a  SnOS[        U 5       3n[        U5      eU(       a  U[        ;  a  U$ [        R                  U0 5      nUR                   S3n[        XVS9e)NTz)Internal error: cannot check return type z	() failed)r   )r   
isinstancer   r6   r2   r&   boolintrD   AssertionErrorr   popr)   r   )retvalfuncargsthreadis_okr   r   s          r0   _validate_x11r   J  s     F~	FXugs;	<	< V	FC	 	  9$v,HS!! v%jj$G]]O9
%C

&&r/   r   xfixesxrandr)XCloseDisplayXDefaultRootWindowXDestroyImageXFixesGetCursorImage	XGetImageXGetWindowAttributesXOpenDisplayXQueryExtensionXRRQueryVersionXRRFreeCrtcInfoXRRFreeScreenResourcesXRRGetCrtcInfoXRRGetScreenResourcesXRRGetScreenResourcesCurrentXSetErrorHandlerr   
CFUNCTIONSc                  x   ^  \ rS rSrSr1 SkrSSU 4S jjjrSS jrSS jrSS jr	SS jr
SS	 jrSS
 jrSrU =r$ )MSSImplXlibi  a  Multiple ScreenShots implementation for GNU/Linux.
It uses intensively the Xlib and its Xrandr extension.

:param display: Optional keyword argument.
    Specifies an X11 display string to connect to.  The default is
    taken from the environment variable :envvar:`DISPLAY`.
:type display: str | bytes | None

.. danger::
    The Xlib backend does not have the same multithreading
    guarantees as the rest of MSS.  Specifically, the object may
    only be used on the thread in which it was created.
    Additionally, while rare, using multiple MSS objects in
    different threads simultaneously may still cause problems.

.. seealso::
    :py:class:`mss.MSS`
        Lists other parameters.
>   r   r   r   _handlesc                 > [        UR                  SS5      5      nU=(       a    [        [        5      n[        TU ]  " SSU0UD6  [        5       U l        S U R                  l        S U R                  l        S U R                  l	        S U R                  l
        U(       d#   [        R                  S   R                  S5      n[!        U["        5      (       d  UR                  S5      nSU;  a  SU< S3n[        U5      e[$        (       d  S	n[        U5      e[&        R(                  " [$        5      U l        [,        (       d  S
n[        U5      e[&        R(                  " [,        5      U l        U(       a(  [        b  [&        R(                  " [        5      OS U l        U R3                  5         [4           U R*                  R7                  [8        5      U R                  l	        U R*                  R;                  U5      U R                  l        U R                  R                  (       d  SU< S3n[        U5      eU R*                  R=                  U R                  R                  5      =U R                  l        U R                  l
        S S S 5        U R?                  S5      (       d  Sn[        U5      eg ! [         a    Sn[        U5      S ef = f! , (       d  f       NN= f)Nwith_cursorFDISPLAYzutf-8z$DISPLAY not set.   :zBad display value: .zNo X11 library found.zNo Xrandr extension found.zUnable to open display: RANDRzXrandr not enabled.r!   ) r   r   _XFIXESr   __init__r   r   rE   drawableoriginal_error_handlerr   osenvironencodeKeyErrorr   r   bytesr   r   r   r   _XRANDRr   r   _set_cfunctions_lockr   r   r   r   _is_extension_enabled)r   rE   kwargsrequested_with_cursoreffective_with_cursorr   r   s         r0   r   MSSImplXlib.__init__  s?    $VZZu%E F 5 G$w-E%:EfE  $!%/3,!5**Y/66w?
 '5))nnW-Gw'{!4C!#&&t)C!#&&$$T*	w.C!#&&&&w/  8?7J$**73PTDK 48993M3Mn3]DMM0$(II$:$:7$CDMM!==((01=%c**:>)):V:VW[WdWdWlWl:mmDMM"T]]%7  ))'22'C!#&& 3U  5)%c*45< Us   ""J6 5CK6K
K c                \   U R                   R                  (       aq  [           U R                  R	                  U R                   R                  5        S S S 5        S U R                   l        S U R                   l        S U R                   l        U R                   R                  (       aO  [           U R                  R                  U R                   R                  5        S S S 5        S U R                   l        [        R                  5         g ! , (       d  f       N= f! , (       d  f       NE= f)N)r   rE   r   r   r   r   r   r   r   r   clear)r   s    r0   closeMSSImplXlib.close  s    ==  		''(=(=> $(DMM!%)DMM"!%DMM ==// 		**4==+O+OP 37DMM0 	%  s   0D.0D
D
D+c          
     \   [        5       n[        5       n[        5       n [           U R                  R                  U R                  R
                  UR                  S5      [        U5      [        U5      [        U5      5        SSS5        g! , (       d  f       g= f! [         a     gf = f)z>Return True if the given *extension* is enabled on the server.latin1NFT)	r   r   r   r   r   rE   r   r	   r   )r   rX   major_opcode_returnfirst_event_returnfirst_error_returns        r0   r   !MSSImplXlib._is_extension_enabled  s    #g"W"W
			))MM))KK)-.,-,-      		s/   B ABB 
BB B 
B+*B+c           
     ,   U R                   n[        U SS5      U R                  U R                  S.n[        R                  5        H9  u  nu  pEn[        [        5         US:X  a  SO[        nU" X$   X5XgS9  SSS5        M;     g! , (       d  f       MM  = f)z7Set all ctypes functions and attach them to attributes.r   N)r   r   r   r   )errcheck)		_cfactorygetattrr   r   r   itemsr   AttributeErrorr   )r   cfactoryattrsr   attrr   r   r  s           r0   r   MSSImplXlib._set_cfunctions  s    >>dHd3IIkk

 0:/?/?/A+D+47.)#'+=#=4=dgQ *) 0B))s   B
B	c           
        U R                   R                  n[        nU R                  n/ n[           [        S5      n[        S5      nUR                  XU5        [        5       nU R                  R                  XR                   R                  [        U5      5        UR                  U" UR                  5      U" UR                  5      U" UR                  5      U" UR                   5      S.5        [#        US5      (       aL  UR$                  UR$                  4S:  a0  UR'                  XR                   R(                  5      R*                  nO/UR-                  XR                   R(                  5      R*                  nUR.                  n	[1        UR2                  5       H  n
UR5                  XX   5      R*                  nUR6                  S:X  a  UR9                  U5        MD  UR                  U" UR                  5      U" UR                  5      U" UR                  5      U" UR                   5      S.5        UR9                  U5        M     UR;                  U5        SSS5        U$ ! , (       d  f       U$ = f)zGet positions of monitors.r   lefttoprQ   rR   r   )      N)r   rE   r   r   r   r   r   r   r   r   r   r	   appendrO   rP   rQ   rR   r   r   r   r   r   r   r|   ranger{   r   ro   r   r   )r   rE   int_r   monitorsxrandr_majorxrandr_minorgwamonr|   idxcrtcs               r0   r  MSSImplXlib.monitors  s   --'' 8L 8L""7,G $%CII**7MM4F4Fc
SOOceeT#%%[4		?^bcfcmcm^no v=>>LDVDVXdXjXjCkouCu99'==CYCYZcc227MM<R<RS\\IIESYY',,W5:FOO<<1$**40 $TVV#DFF|!%djj!1"&t{{"3	 &&t, ( ))#.Q T U UT s   H/I**
I9c                   [            U R                  R                  U R                  R                  U R                  R
                  US   US   US   US   [        [        5      nSSS5         WR                  R                  nU[        ;  a  SU S3n[        U5      e[        UR                  R                  [        [        US   -  US   -  S-  5      5      n[!        UR                  5      n[            U R                  R#                  U5        SSS5        U$ ! , (       d  f       N= f! , (       d  f       U$ = f! [            U R                  R#                  W5        SSS5        f ! , (       d  f       f = f= f)	z:Retrieve all pixels from a monitor. Pixels have to be RGB.r  r  rQ   rR   Nz6[XImage] bits per pixel value not (yet?) implemented: r      )r   r   r   r   rE   r   	PLAINMASKZPIXMAPr   re   SUPPORTED_BITS_PER_PIXELSr   r   r^   r   r   	bytearrayr   )r   monitorximagere   r   raw_datar^   s          r0   grabMSSImplXlib.grabD  s;    YY((%%&& !	F 	0#__;;N%>>N~N^^_`%c**$$'("33gg6FFJKH X../D 		''/  9 U2   		''/ s=   AD/BE  7D.
D+.
D= E=E,#	E=,
E:6E=c                   U R                   c  g[           U R                   R                  U R                  R                  5      nSSS5        W(       a  UR
                  (       d  Sn[        U5      eUR
                  nUR                  UR                  -
  UR                  UR                  -
  UR                  UR                  S.n[        UR                  [        [         US   -  US   -  5      5      n[#        UR
                  5      n[#        US   US   -  S-  5      nUSSS2   USSS2'   US	SS2   US	SS2'   US
SS2   US
SS2'   USSS2   USSS2'   [%        Xt5      $ ! , (       d  f       GN'= f)z0Retrieve all cursor data. Pixels have to be RGB.Nz"Cannot read XFixesGetCursorImage()r  rR   rQ   r!  r     r#   r  )r   r   r   r   rE   r   r   rO   rS   rP   rT   rQ   rR   r   rV   r   r   r%  r   )r   r'  r   
cursor_imgregionr(  rawr^   s           r0   cursorMSSImplXlib.cursore  sa   ;; [[55dmm6K6KLF 6??6C!#&&(.
LL:??2<<*//1%% ''	
 
))77VH=M3MPVW^P_3_+`a))*)F7O;a?@AYQTT
AYQTT
AYQTT
!HSqS	$''/ Us   0E%%
E4)r   r   r   r   )r/   )rE   zbytes | strr   r   r   None)r   r2  )rX   r   r   r   )r   r    )r&  r   r   r%  )r   zScreenShot | None)r)   r*   r+   r,   r-   	__slots__r   r   r   r   r  r)  r0  r.   r   r   s   @r0   r   r     s@    ( 9I;' ;'z.&R1fB( (r/   r   )rE   r9   r   rB   r   r   )r   z-_Pointer | None | XBool | XStatus | XID | intr   r   r   tuple[Any, Any]r   r4  )Ir-   
__future__r   r   r   
contextlibr   ctypesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   ctypes.utilr   	threadingr   r   r   typingr   r   mss.baser   mss.exceptionr   mss.screenshotr   
mss.modelsr   r   r    __all__r   r   r"  r#  BITS_PER_PIXELS_32r$  r&   r2   r6   r9   r<   r?   rB   rM   rZ   rj   ru   rx   r   r   r   r   r   r   r   r   r   __annotations__r   r!   r/   r0   <module>rB     s5   #  	     $ % 1 1 % & ) %88
 	 	
  
' e E i Y Y ) "	 (Y 4) *p) p $	 B 
E
x
 
x
 _ . 5''"GK$89# :#L'9'AD'L[''L ww/0%8!GG$4#5s;wv/7%(8'97CT;UV		3uffguM
 $gg&6WEV=W%XZabhZ)9:!18WU^WUZ^]dej]k lnst 77#3WU^WU^"TV]^ 7;#7"8$?''2D*E)FM''"2G<N4OQT!UW^_jWkl&)93(?I[A\]%-0@#/FPbHc$d(X6)
J 0|(# |(r/   