It is currently July 18th, 2019, 8:25 pm

A bang to Focus Skin

Report bugs with the Rainmeter application and suggest features.
User avatar
StArL0rd84
Posts: 336
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

A bang to Focus Skin

StArL0rd84 » June 15th, 2019, 7:49 am

Back in February of 2016 ~Faradey~ released a addon to focus skins so we can use the OnUnfocusAction without having to click on the skin first, in other words: MouseOverAction etc. Source

But it is a external exe file...
And since Rainmeter can do OnUnfocusAction it should also be able to focus it's skins natively, right?
Much like the !Zpos bang is formulated, the focus bang could look similar to that.

[!Focus "illustro\Clock"]
Or just [!Focus] if same skin.

Where i know the focus bang would be beneficial are menu based skins.
So when you open the menu(MouseOverAction), and did not click and item, but rather outside of the skin,
The skin could take the appropriate action.
Which would most likely be to close the menu for you.

In my particullar case i have made a launcher skin which is always hidden until you mouse over one of the menu items.
The skins Zpos is set to 1 so it overlaps other windows, but it also needs focus so when you click away it unfocuses and hides the skin.
ezgif.com-video-to-gif.gif
This following bit of code i found on DisplayFusion which is C#, could be a place to start...
https://www.displayfusion.com/ScriptedFunctions/View/?ID=dd88a3f2-f17d-4cff-9db0-a03a8f9a2064
You do not have the required permissions to view the files attached to this post.
(#WorkTime# = 1 ? #Work# : ([mEnergyLoss:%] > 100 ? #SleepMode# : #Rainmeter#))
User avatar
balala
Rainmeter Sage
Posts: 8376
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: A bang to Focus Skin

balala » June 15th, 2019, 2:34 pm

StArL0rd84 wrote:
June 15th, 2019, 7:49 am
And since Rainmeter can do OnUnfocusAction
I am extremely curious how can be this done. Because I have no idea at all.
However I think you are mistaken. The OnUnfocusAction option is executed when you click outside the skin in which it is used, so
when the skin loses focus in Windows (focus is lost when the mouse is clicked outside the skin).
A similar option do exist. It's the OnFocusAction. This one is executed
when the skin receives focus in Windows (focus is given when the mouse is clicked on the skin).

StArL0rd84 wrote:
June 15th, 2019, 7:49 am
Where i know the focus bang would be beneficial are menu based skins.
So when you open the menu(MouseOverAction), and did not click and item, but rather outside of the skin,
The skin could take the appropriate action.
Which would most likely be to close the menu for you.

In my particullar case i have made a launcher skin which is always hidden until you mouse over one of the menu items.
The skins Zpos is set to 1 so it overlaps other windows, but it also needs focus so when you click away it unfocuses and hides the skin.
Add the following option to the [Rainmeter] section of your skin: OnUnfocusAction=[BANGS TO CLOSE THE MENU].
User avatar
StArL0rd84
Posts: 336
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: A bang to Focus Skin

StArL0rd84 » June 15th, 2019, 4:20 pm

balala wrote:
June 15th, 2019, 2:34 pm
I am extremely curious how can be this done. Because I have no idea at all.
However I think you are mistaken. The OnUnfocusAction option is executed when you click outside the skin in which it is used, so

A similar option do exist. It's the OnFocusAction. This one is executed





Add the following option to the [Rainmeter] section of your skin: OnUnfocusAction=[BANGS TO CLOSE THE MENU].
I did add OnUnfocusAction=[BANGS TO CLOSE THE MENU] to my Rainmeter section:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
OnUnfocusAction=[!SetVariable MenuMode 0][!UpdateMeter *][!Redraw][!Update]
And it works wonderfully.
OnFocusAction and OnUnfocusAction is merely a reaction to focus.
I need something other than the exe file i talked about to actually give focus to my skin without clicking on it.
(( MouseOverAction=[!Focus "MySkin"] ))
(#WorkTime# = 1 ? #Work# : ([mEnergyLoss:%] > 100 ? #SleepMode# : #Rainmeter#))
Cariboudjan
Posts: 9
Joined: May 12th, 2019, 8:55 am

Re: A bang to Focus Skin

Cariboudjan » June 15th, 2019, 4:34 pm

Why don't you just do this?

[!Zpos 2][!Zpos 0]

Zpos 2 will (I think) give the skin focus. And Zpos 0 will bring it back to a normal Zpos, while keeping it above other windows.

You can call [!Zpos 2][!Zpos 0] whenever or however you want, and then the skin's OnFocusAction should also behave normally.

So on MouseOverAction you can use [!Zpos 2][!Zpos 0], giving the dropdown menu focus. Then your OnUnfocusAction for the dropdown menu would hide the dropdown menu.
Last edited by Cariboudjan on June 15th, 2019, 4:41 pm, edited 1 time in total.
User avatar
StArL0rd84
Posts: 336
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: A bang to Focus Skin

StArL0rd84 » June 15th, 2019, 4:38 pm

Cariboudjan wrote:
June 15th, 2019, 4:34 pm
Why don't you just do this?

[!Zpos 2][!Zpos 0]

Zpos 2 will (I think) give the skin focus. And Zpos 0 will bring it back to a normal Zpos, while keeping it above other windows.

You can call [!Zpos 2][!Zpos 0] whenever or however you want, and then the skin's OnFocusAction should also behave normally.
It did not work.
But thank you for your suggestion.
For a second i thought i had overlooked that.
(#WorkTime# = 1 ? #Work# : ([mEnergyLoss:%] > 100 ? #SleepMode# : #Rainmeter#))
Cariboudjan
Posts: 9
Joined: May 12th, 2019, 8:55 am

Re: A bang to Focus Skin

Cariboudjan » June 15th, 2019, 4:42 pm

Pretty sure I've done this before successfully. Weird.
User avatar
balala
Rainmeter Sage
Posts: 8376
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: A bang to Focus Skin

balala » June 15th, 2019, 5:16 pm

StArL0rd84 wrote:
June 15th, 2019, 4:20 pm
I did add OnUnfocusAction=[BANGS TO CLOSE THE MENU] to my Rainmeter section:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
OnUnfocusAction=[!SetVariable MenuMode 0][!UpdateMeter *][!Redraw][!Update]
And it works wonderfully.
Note that there isn't needed to redraw AND update the skin. On every update (doesn't matter if this is done on "normal" update cycle, or through a !Update bang) a redrawn of the skin is also done. That's why the last [!Update] bang is useless. Remove it: OnUnfocusAction=[!SetVariable MenuMode 0][!UpdateMeter *][!Redraw]
StArL0rd84 wrote:
June 15th, 2019, 4:20 pm
I did add OnUnfocusAction=[BANGS TO CLOSE THE MENU] to my Rainmeter section:

OnFocusAction and OnUnfocusAction is merely a reaction to focus.
Right. They are executed when the skin receives / loses the focus. They are not something which could focus the skin.
StArL0rd84 wrote:
June 15th, 2019, 4:20 pm
I need something other than the exe file i talked about to actually give focus to my skin without clicking on it.
(( MouseOverAction=[!Focus "MySkin"] ))
I don't know any other solution excepting Faradey's one. But why isn't that one good enough?
User avatar
StArL0rd84
Posts: 336
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: A bang to Focus Skin

StArL0rd84 » June 15th, 2019, 5:48 pm

balala wrote:
June 15th, 2019, 5:16 pm

I don't know any other solution excepting Faradey's one. But why isn't that one good enough?
When the exe executes a blue spinning wheel appears over the cursor which is a eyesoar.

I posted here because I believe it should be a native bang for Rainmeter.
I can use Faradey's solution, but I don't like it.
(#WorkTime# = 1 ? #Work# : ([mEnergyLoss:%] > 100 ? #SleepMode# : #Rainmeter#))
User avatar
balala
Rainmeter Sage
Posts: 8376
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: A bang to Focus Skin

balala » June 15th, 2019, 5:51 pm

StArL0rd84 wrote:
June 15th, 2019, 5:48 pm
When the exe executes a blue spinning wheel appears over the cursor which is a eyesoar.
Ok, right. Then no other solution from my part. Sorry...
User avatar
Brian
Developer
Posts: 1879
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: A bang to Focus Skin

Brian » June 17th, 2019, 7:04 am

Stealing focus from another application or Windows itself is highly not recommended and we won't pursuing this type of functionality. One of our main goals to give skin authors as much flexibility as possible without crippling user interaction. Window focus should almost always lie with the user.

-Brian