
    
3j9                       % S r SSKJr  SSKrSSKrSSKJrJrJrJr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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%J&r&J'r'  Sr(\" \5      r)Sr*Sr+Sr,Sr-Sr.Sr/ " S S\5      r0 " S S\5      r1 " S S\5      r2 " S S\5      r3\" \\\\" \5      \5      r4S S jr5S\\\\\\\\\/	\\54S\/\\54S\\" \15      \\" \5      \\/\\54S\/\\54S\/\\54S\" \5      \\" \35      \/\S4S\\)\4\/\\54S/ \S4S\/\S4S\\" \25      /\\54S\/\\54S\\/\\54S\\/\\54S.r6S\7S'    " S S\5      r8g)!zGDI-based backend for MSS on Microsoft Windows.

Uses user32/gdi32 APIs to capture the desktop and enumerate monitors.
This implementation uses CreateDIBSection for direct memory access to pixel data.
    )annotationsN)POINTERWINFUNCTYPE	StructureWinError_Pointer)BOOLBYTEDWORDHANDLEHBITMAPHDCHGDIOBJHMONITORHWNDINTLONGLPARAMLPRECTLPVOIDRECTUINTWORD)TYPE_CHECKING)MSSImplementation)ScreenShotError)AnyCallable)CFunctionsErrCheckedMonitorMonitors i   @i          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\4S\4S\44rSr	g)BITMAPINFOHEADER5   z;Information about the dimensions and color format of a DIB.biSizebiWidthbiHeightbiPlanes
biBitCountbiCompressionbiSizeImagebiXPelsPerMeterbiYPelsPerMeter	biClrUsedbiClrImportantr"   N)
__name__
__module____qualname____firstlineno____doc__r   r   r   _fields___static_attributes__r"       I/home/wildlama/miniconda3/lib/python3.13/site-packages/mss/windows/gdi.pyr&   r&   5   sf    E 
5	D	T	T	t	% 		D!	D!	e	5!Hr:   r&   c                  .    \ rS rSrSrS\4S\S-  44rSrg)
BITMAPINFOG   zFStructure that defines the dimensions and color information for a DIB.	bmiHeader	bmiColors   r"   N)	r3   r4   r5   r6   r7   r&   r
   r8   r9   r"   r:   r;   r=   r=   G   s     P ./+tax1HIHr:   r=   c                  @    \ rS rSrSrS\4S\4S\4S\4S\\-  44r	Sr
g	)
MONITORINFOEXWO   z~Extended monitor information structure.
https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-monitorinfoexw
cbSize	rcMonitorrcWorkdwFlagsszDevicer"   N)r3   r4   r5   r6   r7   r   r   r   CCHDEVICENAMEr8   r9   r"   r:   r;   rC   rC   O   s=    
 
5	d	4	E	TM)*Hr:   rC   c                  X    \ rS rSrSrS\4S\S-  4S\S-  4S\4S	\S-  4S
\S-  44rSrg)DISPLAY_DEVICEW]   z{Display device information structure.
https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-display_devicew
cb
DeviceNamer#   DeviceString   
StateFlagsDeviceID	DeviceKeyr"   N)	r3   r4   r5   r6   r7   r   r   r8   r9   r"   r:   r;   rL   rL   ]   sO    
 
u	tby!	$	u	TCZ 	dSj!Hr:   rL   c                   U (       d}  [        5       nUR                  UUR                  UR                  S.nUR                  S:X  a  SUR                   3n[	        XTS9eSUR                   SUR                   3n[	        XTS9UeU$ )z*If the result is zero, raise an exception.)funcargs
error_code	error_msgr   z6Windows graphics function failed (no error provided): )detailsz"Windows graphics function failed: z: )r   r3   winerrorstrerrorr   )resultrV   	argumentsr[   rZ   msgs         r;   	_errcheckr`   o   s     :MM"++!**	
 ! K4==/ZC!#7724==/HDUDUCVWc3Ar:   gdi32user32)BitBltCreateCompatibleDCCreateDIBSectionDeleteDCDeleteObjectEnumDisplayDevicesWEnumDisplayMonitorsGdiFlushGetSystemMetricsGetMonitorInfoWGetWindowDC	ReleaseDCSelectObjectr   
CFUNCTIONSc                  t   ^  \ rS rSrSr1 SkrSU 4S 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$ )
MSSImplGdi   a  Multiple ScreenShots implementation for Microsoft Windows (GDI backend).

This implementation uses CreateDIBSection for direct memory access to pixel data,
which eliminates the need for GetDIBits. The DIB pixel data is written directly
to system-managed memory that we can read from.

This backend is selected by ``backend="default"`` and has no Windows-specific
constructor parameters.

.. seealso::

    :py:class:`mss.MSS`
        Lists constructor parameters.
>	   _bmi_dibra   _memdc_srcdcrb   	_dib_bits
_dib_array_region_width_heightc                (  > [         TU ]  5         [        R                  " SSS9U l        [        R                  " SSS9U l        U R                  5         U R                  5         S U l        S U l	        [        5       U l        S U l        U R                  R                  S5      U l        U R
                  R                  U R                  5      U l        [#        5       n[        R$                  " [&        5      UR(                  l        SUR(                  l        SUR(                  l        SUR(                  l        SUR(                  l        SUR(                  l        SUR(                  l        SUR(                  l        SUR(                  l        Xl        g )Nrb   T)use_last_errorra   r   r$   r#   )super__init__ctypesWinDLLrb   ra   _set_cfunctions_set_dpi_awarenessrz   ru   r   rx   ry   rm   rw   rd   rv   r=   sizeofr&   r?   r(   r+   r,   r-   r.   r/   r0   r1   r2   rt   )selfbmi	__class__s     r;   r~   MSSImplGdi.__init__   s     mmHTB]]74@
! =A!$(	!'>Bkk--a0jj33DKK@l%}}-=>!"#% &'#$%!()%()%"#'($	r:   c                v   U R                   (       a,  U R                  R                  U R                   5        S U l         U R                  (       a,  U R                  R	                  U R                  5        S U l        U R
                  (       a.  U R                  R                  SU R
                  5        S U l        g g )Nr   )ru   ra   rg   rv   rf   rw   rb   rn   r   s    r;   closeMSSImplGdi.close   su    99JJ##DII.DI;;JJ,DK;;KK!!!T[[1DK r:   c                    U R                   nU R                  U R                  S.n[        R	                  5        H  u  nu  pEpgU" X$   X5Xg5        M     g)z7Set all ctypes functions and attach them to attributes.)ra   rb   N)	_cfactoryra   rb   rp   items)r   cfactoryattrsrV   attrargtypesrestypeerrchecks           r;   r   MSSImplGdi._set_cfunctions   sO    >>ZZkk
 :D9I9I9K5D547U[$'D :Lr:   c                    [         R                  " 5       SS nUS:  a*  [        R                  R                  R                  S5        gSUs=::  a  S:  a  O  gU R                  R                  5         gg)z<Set DPI awareness to capture full screen on Hi-DPI monitors.N   )      )r   r   )sysgetwindowsversionr   windllshcoreSetProcessDpiAwarenessrb   SetProcessDPIAware)r   versions     r;   r   MSSImplGdi._set_dpi_awareness   s[    '')"1-f MM  77:w''KK**, (r:   c           
     &  ^^^ [         mU R                  mTR                  n/ mTR                  T" U" S5      5      T" U" S5      5      T" U" S5      5      T" U" S5      5      S.5        [        SUUU4S jj5       nTR                  SS US5        T$ )	NL   M   N   rD   )lefttopwidthheightc                  > [        5       n[        R                  " [         5      Ul        TR	                  U [        R
                  " U5      5        UR                  nT" UR                  5      nT" UR                  5      n[        UR                  [        -  5      n[        5       n	[        R                  " [        5      U	l        Sn
TR                  [        R                  " [        R                   " UR"                  5      [%        [&        5      5      S[        R
                  " U	5      S5      (       a4  [        R(                  " [        R                   " U	R*                  5      5      n
SnTR                  [        R                  " [        R                   " UR"                  5      [%        [&        5      5      S[        R
                  " U	5      [,        5      (       a4  [        R(                  " [        R                   " U	R.                  5      5      nUUT" UR0                  5      U-
  T" UR2                  5      U-
  US.nU
b  XS'   Ub  XS'   TR5                  U5        g)zXCallback for monitorenumproc() function, it will return
a RECT with appropriate values.
Nr   )r   r   r   r   
is_primaryname	unique_idT)rC   r   r   rE   rl   byrefcontentsr   r   boolrH   MONITORINFOF_PRIMARYrL   rN   rh   cast	addressofrI   r   r   
wstring_atrP   EDD_GET_DEVICE_INTERFACE_NAMErS   rightbottomappend)hmonitor_datarect_dcinforctr   r   r   display_devicedevice_stringr   mon_dictint_monitorsrb   s                r;   callback%MSSImplGdi.monitors.<locals>.callback  s    "#D --7DK""8V\\$-?@--C>Dsww-Cdll-AABJ,.N &o >N )-M))F,,T]];WT]K^,	  !' 1 1&2B2B>C^C^2_ ` %)I))F,,T]];WT]K^,-	  #--f.>.>~?V?V.WX	 cii4/szz*S0((H (#0 $(1%OOH%r:   r   )
r   r   r   r   r   r   r   r   returnr   )intrb   rk   r   MONITORNUMPROCri   )r   get_system_metricsr   r   r   rb   s      @@@r;   r   MSSImplGdi.monitors  s    #44 	/34.r230451"56		
 
1	 1	 
1	f 	""1dHa8r:   c                  U R                   U R                  p2U R                  nUS   US   peU R                  XV4:w  Ga5  XV4U l        XPR                  R
                  l        U* U R                  R
                  l        U R                  (       a"  UR                  U R                  5        SU l        [        5       U l        UR                  UU R                  [        [        R                  " U R                  5      SS5      U l        UR!                  X0R                  5        XV-  S-  n[        R"                  U-  n[        R$                  " U R                  ['        U5      5      R(                  U l        UR-                  USSXVX!S   US   [.        [0        -  5	        UR3                  5         U R*                  c   e[5        U R*                  5      $ )aw  Retrieve all pixels from a monitor using CreateDIBSection.

CreateDIBSection creates a DIB with system-managed memory backing,
allowing BitBlt to write directly to memory we can read. This eliminates
the need for a separate GetDIBits call.

Note on biHeight: A bottom-up DIB is specified by setting the height to a
positive number, while a top-down DIB is specified by setting the height
to a negative number. We use negative height for top-down orientation.
https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader
https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createdibsection
r   r   Nr   rA   r   r   )rw   rv   ra   rz   rt   r?   r)   r*   ru   rg   r   rx   re   DIB_RGB_COLORSr   r   ro   c_charr   r   r   ry   rc   SRCCOPY
CAPTUREBLTrj   	bytearray)	r   monitorsrcdcmemdcgdir   r   size
array_types	            r;   grabMSSImplGdi.grabO  sq    {{DKKujj('(*;v$$7).D%*/II',27DII(yy  + 	 $XDN,,		T^^,DI UII. >A%D-J$kk$..'*:MNWWDO 	

5!Qufowu~W^akWkl 	 ***))r:   c                    g)z0Retrieve all cursor data. Pixels have to be RGB.Nr"   r   s    r;   cursorMSSImplGdi.cursor  s    r:   )	rt   ru   ry   rx   rv   rz   rw   ra   rb   )r   None)r   r!   )r   r    r   r   )r3   r4   r5   r6   r7   	__slots__r~   r   r   r   r   r   r   r9   __classcell__)r   s   @r;   rr   rr      s;    
I<E-HT5*n r:   rr   )r]   zint | _PointerrV   r   r^   tupler   r   )9r7   
__future__r   r   r   r   r   r   r   r   ctypes.wintypesr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   mss.baser   mss.exceptionr   r   r   
mss.modelsr   r    r!   __all__LPCRECTr   r   r   rJ   r   r   r&   r=   rC   rL   r   r`   rp   __annotations__rr   r"   r:   r;   <module>r      s   #  
 F F    & ! & )$BB
 $-

  * y $J JY i  T8S'$-H: c3S#sCGyY"SE3	: !3
(;T76?TZ\a"bdkmvw3%i0wiy9$wt}eW_=UW\&]_ceij$sG^V&LdT]^ "dD) "C5#t4 8W^-D"EtYWtfc95T3Ki8 sGngyA/$
  6c" cr:   