It is currently April 20th, 2019, 1:20 pm

RainRez 3.0

Plugins and Addons popular with the Community
User avatar
jsmorley
Developer
Posts: 19178
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: RainRez 3.0

jsmorley » November 28th, 2016, 1:53 pm

Pesoen wrote:am i the only one who gets a trojan warning? and warnings about the program trying to connect to the internet?
The code is included. Take a look for yourself... ;-)
guile
Posts: 1
Joined: September 19th, 2017, 7:36 am

Re: RainRez 3.0

guile » September 19th, 2017, 7:43 am

Hi jsmorley,

I registered on the forum just to say thanks to you, what a useful thing you did!

A million thanks, really, you're awesome.

Thank you, thank you, thank you!


P.D.: Just in case it's a helpful piece of information for you, It couldn't detect my 4K screen resolution (I found a why to trick it though, so it's no problem for me).
radreck
Posts: 1
Joined: October 24th, 2017, 5:09 pm

Re: RainRez 3.0

radreck » October 24th, 2017, 6:37 pm

Hello,

I would also like to thank jsmorley for creating RainRez and giving us such a great tool. Also thanks to ouned and hello2u for their additions!

There is some issue with RainRez looping the Layout change when it detects some resolution changes. I haven't really been able to determine what triggers this looping to try and find a way to prevent it. It seems to happen when connecting/disconnecting an additional display.

I've made a few tweaks to their source in case it can help anyone else. I'm not a coder, just took what they had already provided (or maybe I didn't understand enough to get it to do what I wanted?) and added some settings you can set in RainRez.cfg:


Source:
(Credit to jsmorley, hello2u, and ouned as I just took what I saw in their work and mashed it all into one with some minor tweaks.)

Code: Select all

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=RainRez.ico
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Misc.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include "lib\desktopworkarea.au3"

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",3)
_Singleton("RainRez", 0)

$ResolutionMethod = IniRead("RainRez.cfg", "RainRez", "ResolutionMethod", "" )
If $ResolutionMethod <> "Native" and $ResolutionMethod <> "Virtual" Then
   $ResolutionMethod = "NativeAspect"
EndIf

Local $OldWidth
Local $OldHeight
Local $OldAspect

GetOldResolution($OldWidth, $OldHeight)

$OldAspectValue = $OldWidth/$OldHeight

GetOldAspect($OldAspect)

$WorkingWidth = _GetworkingAreaWidth()
$WorkingHeight = _GetworkingAreaHeight()

$OldWorkingWidth = _GetworkingAreaWidth()
$OldWorkingHeight = _GetworkingAreaHeight()

$SleepCount = 0
$LayoutToLoad = "Unchanged"

$BattStatus = GetBattery()
$BattOld = $BattStatus
$BattWord = "Plugged in"
If ($BattStatus = 0) Then
   $BattWord = "Discharging"
EndIf

$RainmeterPath = IniRead("RainRez.cfg", "RainRez", "RainmeterPath", "")
If StringRight($RainmeterPath, 1) <> "\" Then
   $RainmeterPath = $RainmeterPath & "\"
EndIf

If not FileExists($RainmeterPath & "Rainmeter.exe") Then
   MsgBox(16, "RainRez Error", "Unable to locate " & @CRLF & $RainmeterPath & "Rainmeter.exe" & @CRLF & @CRLF & "Ensure you have set RainmeterPath in RainRez.cfg to the location of your Rainmeter executable files." & @CRLF & @CRLF & "This will normally be C:\Program Files\Rainmeter")
   Exit
EndIf

If Not ProcessExists("Rainmeter.exe") Then
   $DefaultLayout = IniRead("RainRez.cfg", "RainRez", "Default", "" )
   $BattLayout = IniRead("RainRez.cfg", "RainRez", "Battery", "" )
   $ResLayout = IniRead("RainRez.cfg", "RainRez", $OldWidth & "x" & $OldHeight, "" )
    ;DEBUG
    ;MsgBox($MB_SYSTEMMODAL, "DEBUG (Res Layout)", "Defined ResLayout: " &  $ResLayout, 10)
   $AspectLayout = IniRead("RainRez.cfg", "RainRez", $OldAspect, "" )
   $LayoutMethod = IniRead("RainRez.cfg", "RainRez", "LayoutMethod", "" )
   If $LayoutMethod <> "Resolution" and $LayoutMethod <> "Aspect" Then
     $LayoutMethod = "Aspect"
   EndIf


  If $ResLayout = "" Then
     $ResLayout = $DefaultLayout
;    $ResLayout = $AspectLayout ; -- If the resolution isn't found in the .cfg file, then fall back to AspectLayout.
   EndIf

   If $BattLayout <> "" and $BattStatus = 0 Then
     $LayoutToLoad = $BattLayout
   ElseIf $LayoutMethod = "Aspect" Then
     $LayoutToLoad = $AspectLayout
   ElseIf $LayoutMethod = "Resolution" Then
     $LayoutToLoad = $ResLayout
   Else
     $LayoutToLoad = $DefaultLayout
   EndIf

    ;DEBUG
    ;MsgBox($MB_SYSTEMMODAL, "DEBUG (Load Rainmeter, Select Layout)", "Default Layout: " & $DefaultLayout & @CRLF & "Layout Method: " & $LayoutMethod & @CRLF & "Battery Layout: " &$BattLayout & @CRLF & "OldAspect: " & @CRLF & "AspectLayout: " & $AspectLayout & @CRLF & "ResLayout: " & $ResLayout & @CRLF & "LayoutToLoad: " & $LayoutToLoad , 10)

   ShellExecute(chr(34) & $RainmeterPath & "Rainmeter.exe" & chr(34), "!LoadLayout " & chr(34) & $LayoutToLoad & chr(34))

EndIf

$TrayClick = TrayCreateItem("Refresh")
TrayItemSetOnEvent(-1,"Refresh")
;$TrayClick = TrayCreateItem("Manage RM")
;TrayItemSetOnEvent(-1,"OpenSkins")
;$TrayClick = TrayCreateItem("Config")
;TrayItemSetOnEvent(-1,"Openconfig")
$TrayClick = TrayCreateItem("Exit RainRez")
TrayItemSetOnEvent(-1,"ExitRainRez")
$TrayClick = TrayCreateItem("Exit Rainmeter")
TrayItemSetOnEvent(-1,"ExitRainmeter")
TraySetIcon("RainRez.ico")

Local $CurrentWidth
Local $CurrentHeight
Local $CurrentAspect

GetCurrentResolution($CurrentWidth, $CurrentHeight)

$CurrentAspectValue = $CurrentWidth/$CurrentHeight

GetCurrentAspect($CurrentAspect)

$WorkingWidth = _GetworkingAreaWidth()
$WorkingHeight = _GetworkingAreaHeight()

UpdateToolTip()

;
; Re-launch Rainmeter if it isn't running.
;
While 1
   Sleep(5000)

   $BattStatus = GetBattery()
   if ($BattStatus = 0) Then
     $BattWord = "Discharging"
   Else
     $BattWord = "Plugged in"
   EndIf

   GetCurrentResolution($CurrentWidth, $CurrentHeight)

   $CurrentAspectValue = $CurrentWidth/$CurrentHeight

   GetCurrentAspect($CurrentAspect)

   $WorkingWidth = _GetworkingAreaWidth()
   $WorkingHeight = _GetworkingAreaHeight()

    If Not ProcessExists("Rainmeter.exe") Then
      ShellExecute(chr(34) & $RainmeterPath & "Rainmeter.exe" & chr(34))
    EndIf

   If $CurrentWidth <> $OldWidth or $CurrentHeight <> $OldHeight or $BattStatus <> $BattOld Then
     $DefaultLayout = IniRead("RainRez.cfg", "RainRez", "Default", "" )
     $BattLayout = IniRead("RainRez.cfg", "RainRez", "Battery", "" )
     $ResLayout = IniRead("RainRez.cfg", "RainRez", $OldWidth & "x" & $OldHeight, "" )
     $AspectLayout = IniRead("RainRez.cfg", "RainRez", $OldAspect, "" )
     $LayoutMethod = IniRead("RainRez.cfg", "RainRez", "LayoutMethod", "" )
     If $LayoutMethod <> "Resolution" and $LayoutMethod <> "Aspect" Then
       $LayoutMethod = "Aspect"
   EndIf

   If $ResLayout = "" Then
     $ResLayout = $DefaultLayout
   EndIf

   If $BattLayout <> "" and $BattStatus = 0 Then
     $LayoutToLoad = $BattLayout
   ElseIf $LayoutMethod = "Aspect" Then
     $LayoutToLoad = $AspectLayout
   ElseIf $LayoutMethod = "Resolution" Then
     $LayoutToLoad = $ResLayout
   Else
     $LayoutToLoad = $DefaultLayout
   EndIf

     ShellExecute(chr(34) & $RainmeterPath & "Rainmeter.exe" & chr(34), "!LoadLayout " & chr(34) & $LayoutToLoad & chr(34))
     ShellExecute(chr(34) & $RainmeterPath & "Rainmeter.exe" & chr(34), "!RefreshApp")

     $OldHeight = _WinAPI_GetSystemMetrics($SM_CYVIRTUALSCREEN)
     $OldWidth = _WinAPI_GetSystemMetrics($SM_CXVIRTUALSCREEN)

     $OldWorkingWidth = _GetworkingAreaWidth()
     $OldWorkingHeight = _GetworkingAreaHeight()

     $BattOld = GetBattery()

     UpdateToolTip()
   EndIf

    If $WorkingWidth <> $OldWorkingWidth or $WorkingHeight <> $OldWorkingHeight Then
     Refresh()
      $OldWorkingWidth = _GetworkingAreaWidth()
      $OldWorkingHeight = _GetworkingAreaHeight()
     UpdateToolTip()
    EndIf

WEnd

Exit

;Func OpenConfig()
;   ShellExecute(chr(34) & "RainRez.cfg" & chr(34))
; EndFunc

;Func OpenSkins()
;   ShellExecute(chr(34) & $RainmeterPath & "Rainmeter.exe" & chr(34), "!Manage skins")
;EndFunc

;Func OpenLayouts()
;   ShellExecute(chr(34) & $RainmeterPath & "Rainmeter.exe" & chr(34), "!Manage layouts")
;EndFunc

Func Refresh()
   ShellExecute(chr(34) & $RainmeterPath & "Rainmeter.exe" & chr(34), "!RefreshApp")
EndFunc

Func UpdateToolTip()
   TraySetToolTip("RainRez" & @CRLF & "Layout: " & $LayoutToLoad & @CRLF & "Working Area: " & _GetworkingAreaWidth() & "x" & _GetworkingAreaHeight() & @CRLF & "Resolution: " & $CurrentWidth & "x" & $CurrentHeight & @CRLF & "Aspect Ratio: " & $CurrentAspect & @CRLF & "Power/Battery: " & $BattWord)
EndFunc

Func GetBattery()
   ;Thanks to PsaltyDS for the script I used as a reference (http://www.autoitscript.com/forum/index.php?showtopic=10993&view=findpost&p=531988)

   $struct = DllStructCreate("ubyte;ubyte;ubyte;ubyte;ulong;ulong")
   $call = DllCall("kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($struct))

   If @error Then
        Return -1
   EndIf

   If Not $call[0] Then
     Return -1
   EndIf

   Return DllStructGetData($struct, 1)
EndFunc

Func GetOldResolution(ByRef $OldWidth, ByRef $OldHeight)
   If $ResolutionMethod = "Virtual" Then
      $OldWidth = _WinAPI_GetSystemMetrics($SM_CXVIRTUALSCREEN)
      $OldHeight = _WinAPI_GetSystemMetrics($SM_CYVIRTUALSCREEN)
   ElseIf $ResolutionMethod = "Native" Then
      $OldWidth = @DesktopWidth
      $OldHeight = @DesktopHeight
   Else
      $OldWidth = @DesktopWidth
      $OldHeight = @DesktopHeight
   EndIf
EndFunc

Func GetCurrentResolution(ByRef $CurrentWidth, ByRef $CurrentHeight)
   If $ResolutionMethod = "Virtual" Then
     $CurrentWidth = _WinAPI_GetSystemMetrics($SM_CXVIRTUALSCREEN)
     $CurrentHeight = _WinAPI_GetSystemMetrics($SM_CYVIRTUALSCREEN)
    ElseIf $ResolutionMethod = "Native" Then
     $CurrentWidth = @DesktopWidth
     $CurrentHeight = @DesktopHeight
    Else
     $CurrentWidth = @DesktopWidth
     $CurrentHeight = @DesktopHeight
    EndIf
EndFunc

Func GetOldAspect(ByRef $OldAspect)
   If $OldAspectValue > "1.3334" Then
     $OldAspect = "Wide"
   Else
     $OldAspect = "Standard"
   EndIf
EndFunc

Func GetCurrentAspect(ByRef $CurrentAspect)
   If $CurrentAspectValue > "1.3334" Then
     $CurrentAspect = "Wide"
   Else
     $CurrentAspect = "Standard"
   EndIf
EndFunc

Func ExitRainmeter()
   ShellExecute(chr(34) & $RainmeterPath & "Tools\nircmd.exe" & chr(34), "killprocess Rainmeter.exe" & chr(34))
   Exit
EndFunc

Func ExitRainRez()
   Exit
 EndFunc ;StartRainmeter

sample RainRez.cfg:

Code: Select all

[RainRez]
RainmeterPath=C:\Utils\Rainmeter
ResolutionMethod=Native
; ^-- Native / Virtual
; Native/Virtual will determine how the resolution
; is calculated, using either the Native resolution, or the Virtual resolution.

LayoutMethod=Aspect
; Resolution/Aspect will set the layout selection method
; using either the detected resolutions (based on ResolutionMethod),
; or by determining if the aspect ratio is Wide or Standard, then load the
; layout as defined in the .CFG for Wide/Standard aspect settings respectively,
; or load the resolution layout. If a layout for the resolution is not defined
; in the .CFG, we fall back to use the defined Default layout.
; (if the numberator divided by denominator > 1.3334 then
; it's considered a wide aspect ratio)

Default=4.3
Battery=Battery
Wide=16.9
Standard=4.3
10240x4320=16.9
8192x4608=16.9
5120x2880=16.9
5120x2160=16.9
3440x1440=16.9
3200x2400=4.3
3000x2000=4.3
2736x1824=4.3
2560x1600=4.3
2048x1152=16.9
1920x1200=4.3
1920x1080=16.9
1680x1050=16.9
1440x900=16.9
1280x1024=4.3
1280x800=16.9
1280x768=16.9
1024x768=4.3
800x600=4.3
640x480=640x480
Edit:
Added compiled files for convenience. Note that neither myself nor the other authors will be held accountable for issues, support, etc. that you may encounter. You can always (and as a best practice, should) compile the source yourselves. Blah blah. :)
You do not have the required permissions to view the files attached to this post.