It is currently May 6th, 2024, 3:16 am

Is OnUnfocusAction behaving properly?

Get help with creating, editing & fixing problems with skins
User avatar
Krainz
Posts: 186
Joined: May 27th, 2012, 5:16 am

Is OnUnfocusAction behaving properly?

Post by Krainz »

I've been testing and it seems that OnUnfocusAction only triggers properly if you click the skin first.

Example:

1. Load the skin through a hotkey (say, F6).

2. Click anywhere outside the skin area.

Result: OnUnfocusAction doesn't fire

1. Load the skin through a hotkey (say, F6).

2. Click anywhere within the skin area.

3. Click anywhere outside the skin area.

Result: OnUnfocusAction properly fires

I think OnUnfocusAction should fire just like in the first example. That way, if you have a skin that is operated through hotkeys, you won't accidentally interact with it after accidentally loading it.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Is OnUnfocusAction behaving properly?

Post by jsmorley »

Krainz wrote: December 21st, 2019, 2:32 pm I've been testing and it seems that OnUnfocusAction only triggers properly if you click the skin first.

Example:

1. Load the skin through a hotkey (say, F6).

2. Click anywhere outside the skin area.

Result: OnUnfocusAction doesn't fire

1. Load the skin through a hotkey (say, F6).

2. Click anywhere within the skin area.

3. Click anywhere outside the skin area.

Result: OnUnfocusAction properly fires

I think OnUnfocusAction should fire just like in the first example. That way, if you have a skin that is operated through hotkeys, you won't accidentally interact with it after accidentally loading it.
OnUnfocusAction is dependent on the skin having focus in the first place. If you simply load a skin, either through Manage, or an !ActivateConfig bang, or any other way, but you never click on it to give it focus, then OnUnfocusAction will never fire. This can't logically be any other way. We have no interest in yanking focus away from something else when you load a skin. Doing that can cause all kinds of other skins to unexpectedly fire their own OnUnfocusAction options, as well as the probably much more common MouseLeaveAction options. Focus is about you purposefully clicking on a skin. There is no other action of any kind that can force the focus anywhere.

https://docs.rainmeter.net/manual/skins/rainmeter-section/#OnFocusAction
https://docs.rainmeter.net/manual/skins/rainmeter-section/#OnUnfocusAction
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Is OnUnfocusAction behaving properly?

Post by eclectic-tech »

jsmorley wrote: December 21st, 2019, 2:38 pm OnUnfocusAction is dependent on the skin having focus in the first place. If you simply load a skin, either through Manage or any other way, but you never click on it to give it focus, then OnUnfocusAction will never fire. This can't logically be any other way.
There is an addon that ~Faradey~ created, RainFocus, which will give a skin focus when hovered by your mouse.
I have used it in several projects and it is the only alternative to clicking the skin to allow UnFocusAction to activate. 8-)
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Is OnUnfocusAction behaving properly?

Post by jsmorley »

It should be noted as well that OnFocusAction is not about a skin "having" focus, but rather "getting" focus. So if you have a skin that has this option on it, and you right click the skin (which gives it focus) and refresh it, the refreshed skin will already have focus, and won't fire any OnFocusAction option until you click away from it and back on it.

Never depend on a skin "having" or "not having" focus to take any action. You simply can't tell if it does or not. It's not about "having", it's about "changing".

OnFocusAction is "skin does not have focus and you click on it."
OnUnfocusAction is "skin has focus and you click away from it."

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
OnFocusAction=[!SetOption MeterOne FontColor 186,255,186][!SetOption MeterOne Text "I've got focus!"][!UpdateMeter *][!Redraw]
OnUnfocusAction=[!SetOption MeterOne FontColor 150,150,150][!SetOption MeterOne Text "No focus here..."][!UpdateMeter *][!Redraw]

[Variables]

[MeterOne]
Meter=String
FontSize=25
FontWeight=400
FontColor=255,69,55,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Do I have focus?#CRLF#I can't tell!
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Is OnUnfocusAction behaving properly?

Post by jsmorley »

eclectic-tech wrote: December 21st, 2019, 2:46 pm There is an addon that ~Faradey~ created, RainFocus, which will give a skin focus when hovered by your mouse.
I have used it in several projects and it is the only alternative to clicking the skin to allow UnFocusAction to activate. 8-)
Also...

https://forum.rainmeter.net/viewtopic.php?f=128&t=33146#p164704

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[MeasureActiveMe]
Measure=Plugin
Plugin=GetActiveTitle
IfMatch=\Q#CURRENTPATH##CURRENTFILE#\E
IfMatchAction=[!SetOption MeterActive Text "I have focus!"][!UpdateMeter *][!Redraw]
IfNotMatchAction=[!SetOption MeterActive Text "I don't have focus!"][!UpdateMeter *][!Redraw]

[MeterActive]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Now this is not a way to "give" or "take" focus to or from anything, but in my view is a much more reliable way to "detect" focus and take any actions you want based on "having" or "not having" focus. The "only fire when it changes between false and true" nature of IfMatch will keep this from getting into an endless loop as long as you don't refresh the skin as part of the "action", and it could be a better way than OnFocusAction / OnUnfocusAction to do something based on clicking on and away from the skin.

This has a different but useful purpose than the built-in bangs do. They are about "getting" and "losing", this is about "having" and "not having".

A bonus with this is that if the skin doesn't have focus, you can actually know, display, or even react to what actually does...

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[MeasureActiveMe]
Measure=Plugin
Plugin=GetActiveTitle
RegExpSubstitute=1
Substitute="^$":"Windows"
IfMatch=\Q#CURRENTPATH##CURRENTFILE#\E
IfMatchAction=[!SetOption MeterActive Text "I have focus!#CRLF##CURRENTCONFIG##CRLF##CURRENTFILE#"][!UpdateMeter *][!Redraw]
IfNotMatchAction=[!SetOption MeterActive Text "I don't have focus!#CRLF#[*MeasureActiveMe*]#CRLF#has focus"][!UpdateMeter *][!Redraw]

[MeterActive]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1

The \Q (begin ignoring reserved characters) and \E (end ignoring reserved characters) pair are needed to deal with the \ characters that will be in the path to the skin .ini file. Technically, you don't need the trailing \E, as the end of the string will be reached before you need to turn this off, but it's a good habit to always treat them as a pair.
User avatar
Krainz
Posts: 186
Joined: May 27th, 2012, 5:16 am

Re: Is OnUnfocusAction behaving properly?

Post by Krainz »

Is there a way to intentionally give focus to a skin in the moment it is loaded?

Example:

If I'm working on an image editor, and I load the hotkey-sensible skin by accident:

1. The skin will gain focus
2. My mouse click will interact with the image editor
3. Therefore clicking in the image editor program area will make the skin lose focus
4. OnUnfocusAction will fire, disabling temporarily the skin's hotkeys

This avoids the skin being interacted with without the user (me in this case) actually wanting it
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Is OnUnfocusAction behaving properly?

Post by jsmorley »

Krainz wrote: December 21st, 2019, 5:43 pm Is there a way to intentionally give focus to a skin in the moment it is loaded?

Example:

If I'm working on an image editor, and I load the hotkey-sensible skin by accident:

1. The skin will gain focus
2. My mouse click will interact with the image editor
3. Therefore clicking in the image editor program area will make the skin lose focus
4. OnUnfocusAction will fire, disabling temporarily the skin's hotkeys

This avoids the skin being interacted with without the user (me in this case) actually wanting it
There is nothing built into Rainmeter, nor anything external that I am aware of right off, that can either "give" or "take" focus from any window. There is likely some external utility that can do this, but I don't know what it is off the top of my head. Perhaps something that can simulate a mouse click.

Loading a skin will not give it focus... Only clicking on it will. We really don't want just loading a skin in the overall context of the Rainmeter application to change what window has focus in Windows.
User avatar
balala
Rainmeter Sage
Posts: 16200
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Is OnUnfocusAction behaving properly?

Post by balala »

Krainz wrote: December 21st, 2019, 5:43 pm Is there a way to intentionally give focus to a skin in the moment it is loaded?
Didn't try this so far, but I suppose RainFocus by ~Faradey~ could do this, as described by eclectic-tech above.
User avatar
Krainz
Posts: 186
Joined: May 27th, 2012, 5:16 am

Re: Is OnUnfocusAction behaving properly?

Post by Krainz »

balala wrote: December 21st, 2019, 6:23 pm Didn't try this so far, but I suppose RainFocus by ~Faradey~ could do this, as described by eclectic-tech above.
Oh snap you are correct, when I first read ecletic-tech's post I thought it would only work with mouseover. It seems to work with pretty much anything.

Thanks!
User avatar
balala
Rainmeter Sage
Posts: 16200
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Is OnUnfocusAction behaving properly?

Post by balala »

Krainz wrote: December 21st, 2019, 6:58 pm Oh snap you are correct, when I first read ecletic-tech's post I thought it would only work with mouseover. It seems to work with pretty much anything.

Thanks!
Thank eclectic-tech not me, he posted the link.