It is currently October 14th, 2024, 8:21 pm

RainRez 3.0

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

Re: RainRez 3.0

Post by jsmorley »

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

Post by guile »

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

Post by radreck »

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.
Fyzler
Posts: 1
Joined: August 7th, 2019, 7:15 pm

Re: RainRez 3.0

Post by Fyzler »

When trying to edit the .cfg file to set the correct path i cannot save it after. Says i need permission from the owner to open it (when trying to save it, i have already opened it), why is this, and how can i fix it?
User avatar
Vx_Lotus
Posts: 34
Joined: July 30th, 2019, 7:37 am

Re: RainRez 3.0

Post by Vx_Lotus »

Try setting permissions of the file to administrator or take ownership of the folder to save it. (Some pc files require system permissions to work) With admin setting you are able to change what you like, but some programs may not work properly after. So when your done, switch permissions back to the default setting. *Merely a security measure*
teiji
Posts: 27
Joined: April 9th, 2021, 5:15 pm

Re: RainRez 3.0

Post by teiji »

Hello,

When trying to run Rainrez.exe from the Task Scheduler, it always gives a "Unable to locate \Rainmeter.exe" error. Yes, I've set the RainmeterPath="C:\Program Files\Rainmeter" in cfg. And when I run Rainrez.exe manually, it works fine with no error. Why is this?
User avatar
SilverAzide
Rainmeter Sage
Posts: 2746
Joined: March 23rd, 2015, 5:26 pm

Re: RainRez 3.0

Post by SilverAzide »

teiji wrote: January 10th, 2023, 12:56 am Hello,

When trying to run Rainrez.exe from the Task Scheduler, it always gives a "Unable to locate \Rainmeter.exe" error. Yes, I've set the RainmeterPath="C:\Program Files\Rainmeter" in cfg. And when I run Rainrez.exe manually, it works fine with no error. Why is this?
I don't mean to answer your question with a question (sorry!), but is there any particular reason why you are using a scheduled task to start RainRez instead of using the suggestion given in the next to last paragraph in the initial post (i.e., run RainRez when you start your machine instead of Rainmeter).
Gadgets Wiki GitHub More Gadgets...
teiji
Posts: 27
Joined: April 9th, 2021, 5:15 pm

Re: RainRez 3.0

Post by teiji »

SilverAzide wrote: January 10th, 2023, 3:05 am I don't mean to answer your question with a question (sorry!), but is there any particular reason why you are using a scheduled task to start RainRez instead of using the suggestion given in the next to last paragraph in the initial post (i.e., run RainRez when you start your machine instead of Rainmeter).
I notice whenever Rainrez/Rainmeter autostart with my PC, some of my skins doesn't work correctly (the ones with plugins and depending on 3rd party software like HWINFO/Afterburner). But if I refresh the skin afterward, it works like normal. So I want to delay Rainrez and Rainmeter from autostart by 1-2min, so those 3rd party software load first and then Rainmeter+Rainrez can run after.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2746
Joined: March 23rd, 2015, 5:26 pm

Re: RainRez 3.0

Post by SilverAzide »

teiji wrote: January 10th, 2023, 3:26 am I notice whenever Rainrez/Rainmeter autostart with my PC, some of my skins doesn't work correctly (the ones with plugins and depending on 3rd party software like HWINFO/Afterburner). But if I refresh the skin afterward, it works like normal. So I want to delay Rainrez and Rainmeter from autostart by 1-2min, so those 3rd party software load first and then Rainmeter+Rainrez can run after.
Ah, I see, that makes sense. (Although the proper fix is the author(s) of the skins you are using should properly handle this situation and not force you to do a refresh once HWiNFO/Afterburner are loaded.)

So it looks like there is a glitch/bug in RainRez where it is not able to find the .cfg file if the current working directory is not the folder where the RainRez executable is installed. When you create a scheduled task, it runs the app without changing the current working directory (which I assume is C:\Windows\System32, but could be anything).

Here's a workaround:
Use File Explorer to navigate to the location where you installed RainRez. Right-click RainRez.exe and from the context menu and select "Create Shortcut". By default, the shortcut you create from doing this should have the "Start in" option set to the folder where the executable is located (you can verify this if you want). Next, edit your scheduled task and change the executable path from "C:\whatever your path is\RainRez.exe" to "C:\whatever your path is\RainRez.lnk". In other words, run the shortcut instead of the executable.

I think this should resolve your issue. Let us know if not. Perhaps jsmorley can release a tweak to fix this glitch someday. Finally, you should know that you can replicate everything that RainRez does by creating a special (and simple) invisible "layout controller" skin that can switch layouts just like RainRez does. You could even add delays for HWiNFO and etc. if you wanted.
Gadgets Wiki GitHub More Gadgets...
teiji
Posts: 27
Joined: April 9th, 2021, 5:15 pm

Re: RainRez 3.0

Post by teiji »

SilverAzide wrote: January 10th, 2023, 5:32 pm Ah, I see, that makes sense. (Although the proper fix is the author(s) of the skins you are using should properly handle this situation and not force you to do a refresh once HWiNFO/Afterburner are loaded.)

So it looks like there is a glitch/bug in RainRez where it is not able to find the .cfg file if the current working directory is not the folder where the RainRez executable is installed. When you create a scheduled task, it runs the app without changing the current working directory (which I assume is C:\Windows\System32, but could be anything).

Here's a workaround:
Use File Explorer to navigate to the location where you installed RainRez. Right-click RainRez.exe and from the context menu and select "Create Shortcut". By default, the shortcut you create from doing this should have the "Start in" option set to the folder where the executable is located (you can verify this if you want). Next, edit your scheduled task and change the executable path from "C:\whatever your path is\RainRez.exe" to "C:\whatever your path is\RainRez.lnk". In other words, run the shortcut instead of the executable.

I think this should resolve your issue. Let us know if not. Perhaps jsmorley can release a tweak to fix this glitch someday. Finally, you should know that you can replicate everything that RainRez does by creating a special (and simple) invisible "layout controller" skin that can switch layouts just like RainRez does. You could even add delays for HWiNFO and etc. if you wanted.
Thanks for the replies. Ashamed to say but I'm the author of the skin actually. (I'm still new to Rainmeter coding.)

The shortcut method didn't work. It still gives the same error when running the shortcut from Task Scheduler. Maybe I'll make a separate topic to solve my skin issue instead. lol