+
    Ki>  c                   s   R t ^ RIt^ RIt^ RIt^ RIHtHtHt ^ RIt ]P                  ! RR4       ^ RI
Ht Rt ^ RIHt Rt^ R	I
HtHtHtHt ^ R
IHt ^ RIHtHt ^ RIHt ^ RIHtHtH t  ^ RI!H"t" R t#]R 4       t$ ! R R4      t%R t&]&! 4       t' ! R R]PP                  4      t)])PT                  R. R0ORRR. R1OR. R2O/])PV                  R. R3ORRR. R4OR. R5O/])PX                  R. R6ORRR. R7OR. R7O//t-RRR.RRR.RRR.R R/RRR!.RRR!.RR!R.R R/.t.R" R# lt/R$ t0R% R& lt1R' R( lt2. t3]R) 4       t4R R/R* lt5R+ t6R, t7 ! R- R.4      t8R/ t9]9! 4       t:R#   ] d	    RtRt EL-i ; i  ] d    Rt EL4i ; i)8z/Module to deal with various aspects of displaysN)AnyDictOptionalGnomeDesktopz3.0)r   TF)DBusException)GdkGLibGioGtk)cache_single)DEFAULT_RESOLUTION_HEIGHTDEFAULT_RESOLUTION_WIDTH)MutterDisplayManager)LegacyDisplayManagerchange_resolutionget_outputs)loggerc                 s    \         P                  P                  4       p V '       d=   V P                  4       pV'       d%   VP	                  4       p^`V,          p\        V4      # ^`# )zFComputes the DPI to use for the primary monitor
which we pass to WINE.)r   Displayget_defaultZget_primary_monitorZget_scale_factorint)displayZmonitorZscaleZdpi       8/usr/lib/python3.14/site-packages/lutris/util/display.pyget_default_dpir   $   sM     kk%%'G--/,,.Eu*Cs8O    c                 s    \         P                  P                  4       p R\        V 4      P                  P                  4       9   # )zTrue ifZx11)r   r   r   Ztype__name__Zcasefold)r       r   is_display_x11r   1   s4     kk%%'GDM**33555r   c                   sn   a  ] tR t^8t o RtV 3R lR ltR tR tR tR t	]
R 4       t]
R	 4       tR
tV tR# )DisplayManagerz-Get display and resolution using GnomeDesktopc                s4   < V ^8  d   QhRS[ P                  /# )   screen)r   Screen)format__classdict__s   "r   __annotate__ZDisplayManager.__annotate__;   s     & &szz &r   c                s    \         P                  P                  V4      V n        \         P                  P                  V P                  4      V n        V P                  P                  4        R # )N)r   ZRRScreenZnew	rr_screenZRRConfigZnew_current	rr_configZload_current)selfr   s   &&r   __init__ZDisplayManager.__init__;   sF    %..226:%..::4>>J##%r   c                sz    V P                   P                  4        Uu. uF  qP                  4       NK  	  up# u upi )z"Return names of connected displays)r$   r   Zget_display_name)r%   Zoutput_info   & r   get_display_namesZ DisplayManager.get_display_names@   s0    BF..B\B\B^_B^;,,.B^___s   8c                s2   V P                   P                  4        Uu. uF'  qP                  4       : RVP                  4       : 2NK)  	  ppV'       g)   \        P
                  ! R4       \        : R\        : 2.# \        \        V4      R RR7      # u upi )zReturn available resolutionsxz9Failed to generate resolution list from default GdkScreenc                 sD    \        V P                  R 4      ^ ,          4      # r)   )r   Zsplitr*      &r   Z<lambda>Z0DisplayManager.get_resolutions.<locals>.<lambda>J   s    c!''#,q/6Jr   T)ZkeyZreverse)
r#   Z
list_modes	get_width
get_heightr   errorr   r
   Zsortedset)r%   ZmodeZresolutions   &  r   get_resolutionsZDisplayManager.get_resolutionsD   ss    SWSaSaSlSlSnoSn4.."2DOO4EFSnoLLTU79RSTTc+&,JTXYY	 ps   -Bc                s|    V P                   P                  4        F  pVP                  4       '       g   K  Vu # 	  R# )z-Return the RROutput used as a primary displayN)r#   Zlist_outputsZget_is_primary)r%   outputr'   r   _get_primary_outputZ"DisplayManager._get_primary_outputL   s2    nn113F$$&& 4 	r   c                s   V P                  4       pV'       g5   \        P                  ! R4       \        \        4      \        \
        4      3# VP                  4       p\        VP                  4       4      \        VP                  4       4      3# )z5Return the current resolution for the primary displayzFailed to get a default output)	r3   r   r.   strr   r
   Zget_current_moder,   r-   )r%   r2   Zcurrent_moder0   r   get_current_resolutionZ%DisplayManager.get_current_resolutionS   sl    ))+LL9:/0#6O2PPP..0<))+,c,2I2I2K.LLLr   c                s    \        V 4      # )zSet the resolution of one or more displays.
The resolution can either be a string, which will be applied to the
primary display or a list of configurations as returned by `get_config`.
This method uses XrandR and will not work on Wayland.
)r   )Z
resolutionr+   r   set_resolutionZDisplayManager.set_resolution\   s     !,,r   c                 s    \        4       # )zReturn the current display resolution
This method uses XrandR and will not work on wayland
The output can be fed in `set_resolution`
)r    r   r   
get_configZDisplayManager.get_confige   s     }r   )r$   r#   N)r   
__module____qualname____firstlineno____doc__r&   r(   r1   r3   r5   Zstaticmethodr6   r8   __static_attributes____classdictcell__r!      @r   r   r   8   sQ     7& &
`ZM - -  r   r   c                 s   \         '       d    \        4       # \        P                  ! R4       \        '       d>    \        P                  P                  4       pV'       d   \        V4      #  \        4       # \        4       #   \         d"   p \        P                  ! RT 4        Rp ? LzRp ? i\
         d"   p \        P                  ! RT 4        Rp ? LRp ? ii ; i  \        P                   d     \        4       # i ; i)z{Return the appropriate display manager instance.
Defaults to Mutter if available. This is the only one to support Wayland.
z%Mutter DBus service not reachable: %sNzKFailed to instantiate MutterDisplayConfig. Please report with exception: %sz9DBus is not available, Lutris was not properly installed.)DBUS_AVAILABLEr   r   r   debug	ExceptionZ	exceptionr.   LIB_GNOME_DESKTOP_AVAILABLEr   r   r   r   r   Errorr   )exr        r   get_display_managerrH   n   s     ~	p')) 	PQ""	ZZ++-F%f--   !!!!  	FLL@"EE 	pjlnoo	p zz 	!!	s@   	B %C !
C CB((C5C6CCC;:C;c                   s.    ] tR t^tRt^ t^t^t^tRt	Rt
R# )DesktopEnvironmentzEnum of desktop environments.i  r7   N)r   r9   r:   r;   r<   PLASMAMATEXFCEDEEPINUNKNOWNr=   r7   r   r   rI   rI      s    'FDDFGr   rI   checkactive_results   true
stop_compositorstart_compositors
   deepin wm
ZpgrepZpicomZpkill run_in_backgroundZcomptonc                s:    V ^8  d   QhR\         \        ,          /# r   return)r   rI   r       "r   r"   r"      s     & &*<!= &r   c                 s   \         P                  P                  RR4      P                  4       p V '       g   R# V P	                  R4      '       d   \
        P                  # V P	                  R4      '       d   \
        P                  # V P	                  R4      '       d   \
        P                  # RV 9   d   \
        P                  # \
        P                  # )zConverts the value of the DESKTOP_SESSION environment variable
to one of the constants in the DesktopEnvironment class.
Returns None if DESKTOP_SESSION is empty or unset.
ZDESKTOP_SESSIONrS   NZmateZxfceZdeepinZplasma)osZenvirongetZlowerZendswithrI   rK   rL   rM   rJ   rN   )Zdesktop_sessionr   r   get_desktop_environmentr[      s    
 jjnn%6;AACO''!&&&''!&&&))!(((?"!(((%%%r   c                s     \         P                  ! V \         P                  \         P                  RR7      P	                  4       ^ ,          #   \
         d#    \        P                  ! RT ^ ,          4        R# i ; i)zKSome rogue function that gives no shit about residing in the correct moduleT)stdinZstdout	close_fdsz#Unable to run command, %s not foundN)
subprocessPopenDEVNULLZPIPEZcommunicateFileNotFoundErrorr   r.   )commandr+   r   _get_command_outputrc      sc    H:--jooQU

+- 	  H:GAJGHs   A
A )A:9A:c                s$    V ^8  d   QhR\         /# rU   )boolrW   rX   r   r"   r"      s       r   c                 s    \        4       p V \        9   d   \        V ,          p\        V4      # \         F  p\        V4      '       g   K   R# 	  R# )zChecks whether compositing is currently disabled or enabled.
Returns True for enabled, False for disabled or if we didn't recognize
the compositor.
TF)r[   _compositor_commands_by_de_check_compositor_active_non_de_compositor_commands)desktop_environmentcommand_setrG   r   is_compositing_enabledrj      sI     238801DE'442#K00 3
 r   c                sR    V ^8  d   QhR\         \        \        3,          R\        /# )r   ri   rV   )r   r4   r    rd   rW   rX   r   r"   r"     s"     
 
$sCx. 
T 
r   c                sX    V R,          p\        V4      pRV 9   d   W R,          8H  # VR8g  # )zApplies the 'check' command; and returns whether the result
was the desired 'active_result'; if that is omitted, we check for
any result at all.rO   rP   r   )rc   )ri   rb   Zresultr0   r   rf   rf     s8     '"G )F+%_555S=r   c                 s   \        4       p RpV e   \        P                  V 4      pV'       g#   \         F  p\	        V4      '       g   K  Tp M	  V'       d1   VR,          pVR,          p\        VP                  R4      4      pW4V3# R# )zReturns the commands to enable/disable compositing on the current
desktop environment as a 3-tuple: start command, stop-command and
a flag to indicate if we need to run the commands in the background.
NrR   rQ   rT   )NNF)r[   re   rZ   rg   rf   rd   )rh   ri   ZcrR   rQ   rT   s         r   _get_compositor_commandsrk     s     23K&0445HI,A'** -
 &'9:%&78 1D!EF2CCCr   c                s     V '       d   RP                  V4      p\        P                  ! V\        P                  RV V R7      #   \         d    RT3p\
        P                  ! T4        R# i ; i)zYRandom _run_command lost in the middle of the project,
are you lost little _run_command?
Z T)r\   r]   ZshellZstart_new_sessionz'FileNotFoundError when running command:N)Zjoinr^   r_   r`   ra   r   r.   )rT   rb   ZerrorMessages   $* r   _run_commandrl   0  sg    #hhw'G$$#/
 	
  #@'I\"#s   A 9A %A-,A-c                 s    \        4       p \        \        4      '       d   Rp \        P                  V 4       V '       g   R# \	        4       w  rpV'       d   \        VRV/  R# R# )z,Disable compositing if not already disabled.FNrT   )rj   Zany_COMPOSITING_DISABLED_STACKappendrk   rl   )Zcompositing_enabled_rQ   
backgroundr   r   disable_compositingrq   C  sT    02
&''#&&':;%=%?"A
oDD r   c                 s    \         P                  4       p V '       g   R# \        4       w  rpV'       d   \        VRV/  R# R# )zSRe-enable compositing if the corresponding call to disable_compositing
disabled it.NrT   )rm   Zpoprk   rl   )Zcompositing_disabledrR   ro   rp   r   r   enable_compositingrr   P  s=     7::<&>&@#&E*E r   c                   sj   a  ] tR tRt o RtR t]P                  P                  3R lt	R t
R tRtV tR# )	DBusScreenSaverInhibitori\  al  Inhibit and uninhibit the suspend using DBus.

It will use the Gtk.Application's inhibit and uninhibit methods to
prevent the computer from going to sleep.

For enviroments which don't support either org.freedesktop.ScreenSaver or
org.gnome.ScreenSaver interfaces one can declare a DBus interface which
requires the Inhibit() and UnInhibit() methods to be exposed.c                s"    R V n         RV n        R # )NF)proxy_used_gtk_fallback)r%   r+   r   r&   Z!DBusScreenSaverInhibitor.__init__f  s    
"'r   c           	     s    \         P                  P                  V\         P                  P                  RWVR4      V n        R# )zdSets a dbus proxy to be used instead of Gtk.Application methods, this
method can raise an exception.N)r   Z	DBusProxyZnew_for_bus_syncZDBusProxyFlagsZNONErt   )r%   namepath	interfaceZbus_types   &&&&&r   set_dbus_ifaceZ'DBusScreenSaverInhibitor.set_dbus_ifacej  s3     ]]33c((--tTD

r   c                s.   RV,          pRV n         V P                  '       d?    V P                  P                  RRV4      pV'       d   V# \        P                  ! R4       \        P                  P                  4       pVP                  p\        P                  P                  \        P                  P                  ,          pVP                  WgV4      pV^ 8X  d   R# RV n         V#   \
         d"   p\        P                  ! RT4        Rp?LRp?ii ; i)	zInhibit suspend.
Returns a cookie that must be passed to the corresponding uninhibit() call.
If an error occurs, None is returned instead.zRunning game: %sFz(ss)ZLutriszAD-Bus screensaver inhibit returned no cookie, falling back to GTKz@Failed to inhibit screensaver via D-Bus, falling back to GTK: %sNT)ru   rt   ZInhibitr   warningrC   r   Applicationr   windowr   ZApplicationInhibitFlagsZSUSPENDZIDLEinhibit)r%   Z	game_nameZreasoncookierF   appr|   Zflagss   &&      r   r}   Z DBusScreenSaverInhibitor.inhibitq  s     $i/"':::g++FHfE!Mbc
 oo))+++33c6Q6Q6V6VVVF3 Q;"&  gaceffgs#   $C( 	C( C( (D3DDc                s\   V'       g   R# V P                   '       d2   V P                  '       g     V P                   P                  RV4       R# \        P                  P                  4       pVP                  V4       R#   \         d"   p\        P
                  ! RT4        Rp?LXRp?ii ; i)z`Uninhibit suspend.
Takes a cookie as returned by inhibit. If cookie is None, no action is taken.Nz(u)z-Failed to uninhibit screensaver via D-Bus: %s)
rt   ru   Z	UnInhibitrC   r   rz   r   r{   r   	uninhibit)r%   r~   rF   r   s   &&  r   r   Z"DBusScreenSaverInhibitor.uninhibit  s     :::d555T

$$UF3
 oo))+f  TNPRSSTs   A? ?B+
B&&B+)ru   rt   N)r   r9   r:   r;   r<   r&   r   ZBusTypeZSESSIONry   r}   r   r=   r>   r?   r@   r   rs   rs   \  s4     E( >A[[=P=P 
< r   rs   c                 s   \        4       p \        4       p. pV \        P                  J d   VP	                  R4       M6V \        P
                  J d#   VP	                  R4       VP	                  R4       V F2  w  r4p VP                  W4V4       \        P                  ! RV4       Vu # 	  V#   \        P                   d#   p\        P                  ! RY64        Rp?Kj  Rp?ii ; i)zReturn the appropriate suspend inhibitor instance.
If the required interface isn't available, it will default to GTK's
implementation.z%Using D-Bus screensaver interface: %sz$D-Bus interface %s not available: %sN)org.mate.ScreenSaver/r   )org.xfce.ScreenSaverr   r   )org.freedesktop.ScreenSaverz/org/freedesktop/ScreenSaverr   )r[   rs   rI   rK   rn   rL   ry   r   rB   r   rE   )rh   Z	inhibitorZinterfaces_to_tryrv   rw   rx   Zerrs          r   _get_suspend_inhibitorr     s     23(*I 0555  !VW	 2 7 7	7 	  !VW  j	
 "3I	L$$T;LL@$G	 "3 	 zz 	LLL?KK	Ls   <*B--C$CC$)	gsettingsrZ   org.mate.Marco.generalcompositing-manager)r   r/   r   r   Zfalse)r   r/   r   r   Ztrue)xfconf-query--channel=xfwm4#--property=/general/use_compositing)r   r   r   z--set=false)r   r   r   z
--set=true)	dbus-send	--session--dest=com.deepin.WMSwitcher--type=method_callz--print-reply=literal/com/deepin/WMSwitcherzcom.deepin.WMSwitcher.CurrentWM)r   r   r   r   r   z%com.deepin.WMSwitcher.RequestSwitchWM);r<   ZenumrY   r^   Ztypingr    r   r   ZgiZrequire_versionZgi.repositoryr   rD   Z
ValueErrorZdbus.exceptionsr   rA   ZImportErrorr   r   r   r   Zlutris.utilr	   Zlutris.settingsr
   r   Z"lutris.util.graphics.displayconfigr   Zlutris.util.graphics.xrandrr   r   r   Zlutris.util.logr   r   r   r   rH   ZDISPLAY_MANAGERZEnumrI   rK   rL   rM   re   rg   r[   rc   rj   rf   rm   rk   rl   rq   rr   rs   r   ZSCREEN_SAVER_INHIBITORr7   r   r   <module>r      s   5  	  & & 	~u-*"&
-N . - $ O C \ \ "
 6 63 3l"0 &'  Vii	 [tt	  
 	 
 	 
' ) ^ 	'7#GW-WbMT	 	'9%GY/YOT	  &&H&
" !   2#U #&
E	FB BJB 01 e  "'L  Ns"   E E* E'&E'*	E76E7