
    
3jP                        S SK Jr  S SKJrJr  S SKJr  S SKJr  S SK	J
r
  S SKJr  S SKJr  S SKJr  S S	KJr  \(       a  S S
KJr  S SKJrJr  SrSS1rSrSrSrSrSr " S S\5      rg)    )annotations)TYPE_CHECKINGAny)	urlencode)MSSImplementation)ScreenShotError)xcb)LIB)
ScreenShot)
parse_edid)Array)MonitorMonitors        i   i      l    c                     ^  \ rS rSrSrSS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S jr\      SS j5       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$ )#MSSImplXCBBase   a  Base class for XCB-based screenshot implementations.

Provides common XCB initialization and monitor detection logic that can be
shared across different XCB screenshot methods (``XGetImage``,
``XShmGetImage``, ``XComposite``, etc.).

: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

.. seealso::
    :py:class:`mss.MSS`
        Lists other parameters.
NF)displaywith_cursorc                 > [         TU ]  US9  U(       d  S nO&[        U[        5      (       a  UR	                  S5      nU   [
        R                  " U5      u  U l        n[
        R                  " U R                  5      n[
        R                  " U5      nXS   U l
        U R                  R                  =U l        U l        S U l        U R                  U R                  :X  d   eU R                  R                  U l        U R                  R                   U l        UR$                  [
        R&                  R(                  :w  a  Sn[+        U5      eU R                  [,        ;  a  SU R                   3n[+        U5      e[
        R.                  " U5       H  nUR0                  U R                  :X  d  M    O   SU R                   S3n[+        U5      eUnUR2                  [4        :w  a  SUR2                   S3n[+        U5      eUR6                  [4        :w  a  S	n[+        U5      e[
        R8                  " U R                  5       H  n	U	R0                  U R                  :X  d  M    O   S
n[+        U5      e[
        R:                  " U	5       H  n
U
R<                  U R"                  :X  d  M    O   Sn[+        U5      eU
R>                  [
        R@                  RB                  [
        R@                  RD                  1;  a  Sn[+        U5      eU
RF                  [H        :w  d(  U
RJ                  [L        :w  d  U
RN                  [P        :w  a  Sn[+        U5      eg )N)r   zutf-8z6Only X11 servers using LSB-First images are supported.z8Only screens of color depth 24 or 32 are supported, not z!Internal error: drawable's depth z( not found in screen's supported formatszFOnly screens at 32 bpp (regardless of color depth) are supported; got z bppz/Screens with scanline padding are not supportedzGInternal error: drawable's depth not found in screen's supported depthszIInternal error: drawable's visual not found in screen's supported visualsz4Only TrueColor and DirectColor visuals are supportedz-Only visuals with BGRx ordering are supported))super__init__
isinstancestrencoder	   connectconn	get_setupsetup_rootspref_screenrootdrawable_xfixes_ready
root_depthdrawable_depthroot_visualdrawable_visual_idimage_byte_order
ImageOrderLSBFirstr   SUPPORTED_DEPTHSsetup_pixmap_formatsdepthbits_per_pixelSUPPORTED_BITS_PER_PIXELscanline_padscreen_allowed_depthsdepth_visuals	visual_idclass_VisualClass	TrueColorDirectColorred_maskSUPPORTED_RED_MASK
green_maskSUPPORTED_GREEN_MASK	blue_maskSUPPORTED_BLUE_MASK)selfr   r   pref_screen_num	xcb_setupscreensmsgformat_drawable_format	xcb_depthvisual_info	__class__s              H/home/wildlama/miniconda3/lib/python3.13/site-packages/mss/linux/base.pyr   MSSImplXCBBase.__init__-   s   [1G%%nnW-G%([[%9"	? MM$)),	//), #3$($4$4$9$99	DM +/ yyDMM)))"..99"&"2"2">">%%)@)@@JC!#&&&66LTM`M`LabC!#&&//	:G}} 3 33 ; 6d6I6I5JJrsC!#&&!))-EE&556d<  "#&&''+CC DC!#&& 2243C3CDI$"5"55 E \C!#&&,,Y7K$$(?(?? 8 ^C!#&&coo&?&?A\A\%]]HC!#&&  $66%%)==$$(;; BC!#&& <    c                l    U R                   b   [        R                  " U R                   5        SU l         g)zClose the XCB connection.N)r    r	   
disconnect)rA   s    rK   closeMSSImplXCBBase.close   s#    99 NN499%	rM   c                R   U R                   c  Sn[        U5      e/ nUR                  U R                  5       5        U R	                  5       nUb  US:  a  U$ U R                  U5      nU R                  5       nUS:  a  X R                  XE5      -  nU$ X R                  X4U5      -  nU$ )zPopulate monitor geometry information.

Detects and returns monitor rectangles. The first entry
represents the entire X11 root screen; subsequent entries,
when available, represent individual monitors reported by
XRandR.
7Cannot identify monitors while the connection is closed)      )rT      )	r    r   append_root_monitor_randr_get_version_randr_get_primary_output_randr_get_edid_atom_monitors_from_randr_monitors_monitors_from_randr_crtcs)rA   rE   monitorsrandr_versionprimary_output	edid_atoms         rK   r^   MSSImplXCBBase.monitors   s     99KC!#&&**,-//1 MF$:O 77F--/	F"::>UUH  77W`aaHrM   c                    U R                   c  Sn[        U5      e[        R                  " U R                   U R                  5      nUR
                  UR                  UR                  UR                  S.$ )NrS   lefttopwidthheight)	r    r   r	   get_geometryr$   xyrg   rh   )rA   rE   	root_geoms      rK   rX   MSSImplXCBBase._root_monitor   s^    99KC!#&&$$TYY		:	KK;;__&&	
 	
rM   c                d   U R                   c  Sn[        U5      e[        R                  " U R                   [        R
                  5      nUR                  (       d  g [        R                  " U R                   [        R                  [        R                  5      nUR                  UR                  4$ )NrS   )r    r   r	   get_extension_datar
   randr_idpresentrandr_query_versionRANDR_MAJOR_VERSIONRANDR_MINOR_VERSIONmajor_versionminor_version)rA   rE   randr_ext_datarandr_version_datas       rK   rY   !MSSImplXCBBase._randr_get_version   s    99KC!#&&//		3<<H%% 44TYY@W@WY\YpYpq"002D2R2RSSrM   c                   U R                   c  Sn[        U5      eUS:  a7  [        R                  " U R                   U R                  5      nUR
                  $ g )NrS   rT      )r    r   r	   randr_get_output_primaryr%   output)rA   r_   rE   primary_output_datas       rK   rZ   (MSSImplXCBBase._randr_get_primary_output   sP    99KC!#&&F""%">">tyy$--"X&--- rM   c                    U R                   c  Sn[        U5      e[        R                  " U R                   SSS9nUb  U$ [        R                  " U R                   SSS9$ )NrS   EDIDT)only_if_existsEdidData)r    r   r	   intern_atom)rA   rE   ra   s      rK   r[   #MSSImplXCBBase._randr_get_edid_atom   sW    99KC!#&&OODIIvdK	  tyy*TJJrM   c          
        U R                   c  Sn[        U5      e[        R                  " U R                   X5      nUR                  S:w  a  Sn[        U5      e0 n[        R
                  " U5      n[        U5      R                  SSS9US'   UGb9  [        R                  " U R                   UU[        R                  SSSS5      nUR                  R                  S:w  a  [        [        R                  " U5      5      n	[        U	5      n
U
R                  S	5      =nb  XS
'   0 nU
R                  S5      =nb  XS'   U
R                  S5      =nb  [        U5      US'   U
R                  S5      =nb(  U
R                  S5      =nb  US SUS 3US'   OUS US'   U
R                  S5      =nb  US US'   U(       a  [!        U5      US'   U$ )NrS   r   z7Display configuration changed while detecting monitors.utf_8replace)errorsr~   i   display_namename	id_legacymodelserial_numberserialmanufacture_yearmanufacture_week04dW02dmfr_date
model_year	unique_id)r    r   r	   randr_get_output_infostatusrandr_get_output_info_namebytesdecoderandr_get_output_propertyXCB_NONEtype_valuerandr_get_output_property_datar   getr   r   )rA   r~   	timestampra   rE   output_inforvoutput_name_arr	edid_prop
edid_block	edid_datar   edid_paramsr   r   r   r   r   s                     rK   _randr_output_ids MSSImplXCBBase._randr_output_ids   s    99KC!#&&//		6M"KC!#&&88E_-44WY4O8 55			I $$)"3#E#Ei#PQ
&z2	$-MM.$AALN!-vJ.0!*{!;;IH+4(%.]]?%CCMP,/,>K)(16H(II$V,5MM:L,MM(Z5Ec4J!L\]`Ka2bJ/5Ec4JJ/"+--"==JJ3=c2BK-&/&<B{O	rM   c               b    [        U 5      S:X  a  Sn[        U5      eUc  U S   $ X;   a  U$ U S   $ )Nr   zNo RandR outputs available)lenr   )outputsr`   rE   s      rK   _choose_randr_output#MSSImplXCBBase._choose_randr_output  sD     w<1.C!#&&!1:!/!:~J
JrM   c               &   U R                   c  Sn[        U5      e/ n[        R                  " U R                   U R                  S5      nUR
                  n[        R                  " U5       H  nUR                  UR                  UR                  UR                  [        UR                  5      S.nUR                  S:  a;  [        R                  " U5      n	U R                  X5      n
XR!                  XU5      -  nUR#                  U5        M     U$ )NrS   rT   )re   rf   rg   rh   
is_primaryr   )r    r   r	   randr_get_monitorsr%   r   randr_get_monitors_monitorsrj   rk   rg   rh   boolprimarynOutputrandr_monitor_info_outputsr   r   rW   )rA   r`   ra   rE   r^   monitors_replyr   randr_monitormonitorr   chosen_outputs              rK   r\   ,MSSImplXCBBase._monitors_from_randr_monitors(  s     99KC!#&&//		4==!L",,	 <<^LM%$&,,'..
 #=#8#89
G $$q(88G $ 9 9' R11-IVVOOG$% M( rM   c               (   U R                   c  Sn[        U5      e/ n[        [        R                  S5      (       aH  US:  aB  [
        R                  " U R                   U R                  5      n[
        R                  " U5      nOA[
        R                  " U R                   U R                  5      n[
        R                  " U5      nUR                  nU H  n	[
        R                  " U R                   X5      n
U
R                  S:X  a  M6  U
R                  U
R                  U
R                   U
R"                  S.n[
        R$                  " U
5      nU R'                  X5      nXR)                  XU5      -  nUb  X:H  US'   UR+                  U5        M     U$ )NrS   &xcb_randr_get_screen_resources_currentr{   r   rd   r   )r    r   hasattrr
   randrr	   "randr_get_screen_resources_currentr%   (randr_get_screen_resources_current_crtcsrandr_get_screen_resources randr_get_screen_resources_crtcsconfig_timestamprandr_get_crtc_infonum_outputsrj   rk   rg   rh   randr_get_crtc_info_outputsr   r   rW   )rA   r_   r`   ra   rE   r^   screen_resourcescrtcsr   crtc	crtc_infor   r   r   s                 rK   r]   )MSSImplXCBBase._monitors_from_randr_crtcsI  sZ    99KC!#&& 399FGGM]cLc"EEdiiQUQ^Q^_@@AQRE"==diiW889IJE$55	D//		4KI$$)! {{"#**	G 55i@G 55gNM--m	RRG )(5(G%OOG$) , rM   c                j   U R                   c  Sn[        U5      e[        R                  " U R                   [        R
                  5      nUR                  (       d  g[        R                  " U R                   [        R                  [        R                  5      nUR                  UR                  4S:  $ )zCheck XFixes availability and version.

:returns: ``True`` if the server provides XFixes with a compatible
    version, otherwise ``False``.
5Cannot take screenshot while the connection is closedF)rU   r   )r    r   r	   ro   r
   	xfixes_idrq   xfixes_query_versionXFIXES_MAJOR_VERSIONXFIXES_MINOR_VERSIONru   rv   )rA   rE   xfixes_ext_datareplys       rK   _cursor_check_xfixes#MSSImplXCBBase._cursor_check_xfixesw  s     99IC!#&&00CMMJ&&((C4L4LcNfNfg ##U%8%89VCCrM   c                   U R                   c  Sn[        U5      eU R                  c  U R                  5       U l        U R                  (       d  Sn[        U5      e[        R
                  " U R                   5      nUR                  UR                  -
  UR                  UR                  -
  UR                  UR                  S.n[        R                  " U5      n[        U5      n[        XS5      $ )zCapture the current cursor image.

Pixels are returned in BGRA ordering.

:returns: A screenshot object containing the cursor image and region.
r   z7Server does not have XFixes, or the version is too old.rd   )r    r   r&   r   r	   xfixes_get_cursor_imagerj   xhotrk   yhotrg   rh   $xfixes_get_cursor_image_cursor_image	bytearrayr   )rA   rE   
cursor_imgregiondata_arrdatas         rK   cursorMSSImplXCBBase.cursor  s     99IC!#&&%!%!:!:!<D!!KC!#&&00;
LL:??2<<*//1%% ''	
 ;;JG" $''rM   c          
     d   U R                   c  Sn[        U5      e[        R                  " U R                   [        R                  R
                  U R                  US   US   US   US   [        5      n[        R                  " U5      n[        U5      nUR                  U R                  :w  d  UR                  U R                  :w  ag  SU R                   S[        U R                  R                  5       SUR                   S[        UR                  R                  5       3n[        U5      eU$ )	a-  Retrieve pixels from a monitor using ``GetImage``.

Used by the XGetImage backend and by the XShmGetImage backend in
fallback mode.

:param monitor: Monitor rectangle specifying ``left``, ``top``,
    ``width``, and ``height`` to capture.
:returns: A screenshot object containing the captured region.
r   re   rf   rg   rh   z_Server returned an image with a depth or visual different than it initially reported: expected ,z, got )r    r   r	   	get_imageImageFormatZPixmapr%   
ALL_PLANESget_image_datar   r0   r(   visualr*   hexr   )rA   r   rE   	img_replyimg_data_arrimg_datas         rK   _grab_xgetimageMSSImplXCBBase._grab_xgetimage  s    99IC!#&&MMIIOO##MMFOENGH	
	 )))4\*??d111Y5E5EI`I`5` //0#d6M6M6S6S2T1U V 'qY-=-=-C-C)D(EG 
 "#&&rM   )r&   r    r%   r(   r*   r#   r$   )r   zstr | bytes | Noner   r   returnNone)r   r   )r   r   )r   r   )r   ztuple[int, int] | None)r_   tuple[int, int]r   xcb.RandrOutput | None)r   xcb.Atom | None)r~   xcb.RandrOutputr   zxcb.Timestampra   r   r   zdict[str, Any])r   zArray[xcb.RandrOutput]r`   r   r   r   )r`   r   ra   r   r   r   )r_   r   r`   r   ra   r   r   r   )r   r   )r   r   )r   r   r   r   )__name__
__module____qualname____firstlineno____doc__r   rP   r^   rX   rY   rZ   r[   r   staticmethodr   r\   r]   r   r   r   __static_attributes____classcell__)rJ   s   @rK   r   r      s      9=RW U' U'n(T

T

K55 !5 #	5 
5n 	K'	K9O	K		K 	K4AP	B,&, /, #	, 
,\D&(B( (rM   r   N) 
__future__r   typingr   r   urllib.parser   mss.baser   mss.exceptionr   	mss.linuxr	   mss.linux.xcbr
   mss.screenshotr   	mss.toolsr   ctypesr   
mss.modelsr   r   __all__r.   r2   r<   r>   r@   r   r   r   rM   rK   <module>r     sd    " % " & )   %  ,
8     
w& wrM   