Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 1360

General Discussion • Re: Way to change layout based on program

$
0
0
Ok, here's my first solution.

This will change layouts according to the active process, it will fall back to a default layout if none of the processes are currently in the foreground.


To implement, first create a new skin, e.g. "ChangeLayout.ini"

Then, you need 3 layouts. One will be the "default" which I already coded to the "illustro default" layout. Then you need other 2 layouts of your preference. Once you create the skin, load the skin on each layout and save them to include the new skin on them.

Finally on the skin, set the variables to your desired layouts and processes.

On the process variables, please leave the \ before the .exe. For example: Process1=Notepad\.exe

Now, if you run process 1, layout 1 should be loaded, if you change the active window to any other window, then the layout will change to 'illustro default', or whatever layout you set as default. Make sure the default layout also has the skin loaded.

You need to install isFullScreen Plugin for the skin to work.

Code:

[Rainmeter]Update=1000[Variables]CurrentLayout=defaultLayout=illustro defaultLayout1=MyLayout1Process1=process1\.exeLayout2=MyLayout2Process2=process2\.exe[ActiveProcess]Measure=PluginPlugin=isFullScreen[ChangeLayout]Measure=StringString=#CurrentLayout#;[ActiveProcess]DynamicVariables=1IfMatch=^(?!#Layout1#;).*#Process1#$IfMatchAction=[!WriteKeyValue Variables CurrentLayout "#Layout1#"][!LoadLayout "#Layout1#"]IfMatch2=^(?!#Layout2#;).*#Process2#$IfMatchAction2=[!WriteKeyValue Variables CurrentLayout "#Layout2#"][!LoadLayout "#Layout2#"]IfMatch3=^(?!#defaultLayout#;).*(?<!#Process1#)(?<!#Process2#)$IfMatchAction3=[!WriteKeyValue Variables CurrentLayout "#defaultLayout#"][!LoadLayout "#defaultLayout#"][Meter]Meter=String
Edit just to explain the code a little:

What we are doing here is, we are using the isFullScreen plugin to return the process that is currently in focus, you can see it by right clicking on any skin -> Rainmeter -> About -> Skins tab

Click on the ChangeLayout skin and there you will see the current value on the Active Process measure. It will return the process of whatever program you have in focus.

Now, we have a CurrentLayout variable, this variable helps to avoid infinite loops, it will be set to the name of whatever layout we load.

We use this variable to build a string like SomeLayout;SomeProcess.exe, then we use this string to analyze both the value of CurrentLayout and ActiveProcess.

The we use regex on the IfMatch condition to compare strings.

We check if the current layout is not already loaded (to avoid infinite loops) and if the process we want is in focus. So if true, we load the layout.
For example, let’s say

CurrentLayout= default
Layout1=MyLayout1
Process1=Notepad\.exe

And the string is: default;Notepad.exe
Since CurrentLayout is not MyLayout1 then it is true, it first writes MyLayout1 as the CurrentLayout and loads the layout.

Since now CurrentLayout=MyLayout1
Then when the string is MyLayout1;Notepad.exe
Then it is false, because that layout is already loaded, thus we avoid reloading that layout again.

However, if now the string is: MyLayout1;Explorer.exe
Now we load the default layout, because the third condition is now true.

I apologize for this crude explanation, if you have questions let me know.

Statistics: Posted by RicardoTM — Today, 12:06 am



Viewing all articles
Browse latest Browse all 1360

Latest Images

Trending Articles



Latest Images