Page 1 of 9

IsFullScreen 3.0

Posted: April 18th, 2018, 3:25 am
by jsmorley
This demonstrates (and installs) a small plugin that will return a number value of 1 if the application window that currently has focus is running in "full screen" mode, and 0 if not.

New! Thanks to some help from brian (THANKS!), The parent process name of the currently focused window will be returned as the string value.

Important note: This will be unable to detect any process run "As administrator" unless Rainmeter itself is run "As administrator". Otherwise, it should work with any full screen application, such as media players, Youtube in your browser, and games.

Note that this has to do with an application window on the "primary" monitor, the same one Rainmeter is hosted on. Running an application full screen on a second monitor will not trigger this.

Note that if you set the size of a Rainmeter skin to #SCREENAREAWIDTH# and #SCREENAREAHEIGHT#, and the skin is on the primary monitor at a position of 0,0, it will qualify as "full screen" and will cause this plugin to return 1 and Rainmeter.exe.

New: The string value of the measure will now always be the parent process of the currently focused window. If the Desktop has focus, 0 and an empty string will be returned. The number value will still be 1 or 0 depending on whether the window is full screen or not.

So full screen considerations aside, this plugin can also be used to answer the question "does process blah.exe currently have focus?".

Note that the parent process for all Windows 10 "apps", including things like Settings or Windows Update, as well as apps like OneNote or Calculator, is a process called ApplicationFrameHost.exe. That will always be returned in those cases. No, it can't tell you that you are playing Microsoft Solitaire.

Note that the parent process for all Window Explorer elements, like the Taskbar or any File Manager windows, is Explorer.exe. That will always be returned in those cases. No, it can't tell you that you have the folder C:\MyStuff\ open.


The 32bit and 64bit .dll files are also included in @Resources for use in your own .rmskins, and of course if you have the latest 4.2 of Rainmeter or better, installing this will put the plugin in @Vault\Plugins in your Skins folder.
IsFullScreen_3.0.rmskin
Skin:

Code: Select all

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

[Metadata]
Name=IsFullScreen
Author=JSMorley
Version=3.0
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0
Information=Demonstrates IsFullScreen Plugin.
; This plugin will check to see if the "foreground" window, the window that currently has
; "focus", is full screen. The measure will return 1 as the number value if so, and
; 0 as the number value if not. The name of the process for the currently focused window will
; be returned as the string value. An empty string will be returned if the Desktop has focus.

; Note that this is not about "maximized", but rather "full screen".
; Note that this applies to full screen windows on the "primary" monitor only.
; Note that this will be unable to detect any process run "As administrator" unless Rainmeter itself is run "As administrator".

[MeasureIsFullScreen]
Measure=Plugin
Plugin=IsFullScreen
IfCondition=MeasureIsFullScreen=1
IfTrueAction=[!SetOption MeterIsFullScreen Text "Full screen and has focus"][!UpdateMeter *][!Redraw]
IfFalseAction=[!SetOption MeterIsFullScreen Text "Not full screen"][!UpdateMeter *][!Redraw]
IfMatch=^$
IfMatchAction=[!SetOption MeterProcessName Text "Desktop"][!HideMeter MeterIsFullScreen][!UpdateMeter *][!Redraw]
IfNotMatchAction=[!SetOption MeterProcessName Text ""][!ShowMeter MeterIsFullScreen][!UpdateMeter *][!Redraw]

[MeterProcessName]
Meter=String
MeasureName=MeasureIsFullScreen
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1

[MeterIsFullScreen]
Meter=String
Y=30
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
IsFullScreen.dll C++ source code:

Code: Select all

#include <Windows.h>
#include <Psapi.h>
#include <string>
#include "../../API/RainmeterAPI.h"

struct Measure
{
	std::wstring processName;
	Measure() {}
};

PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
	Measure* measure = new Measure;
	*data = measure;
}

PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{
	Measure* measure = (Measure*)data;
}

PLUGIN_EXPORT double Update(void* data)
{
	Measure* measure = (Measure*)data;
	measure->processName.clear();

	double foundFullScreen = 0.0;
	RECT appBounds = { 0 };
	RECT screenBounds = { 0 };
	HWND foregroundHandle = GetForegroundWindow();

	GetWindowRect(GetDesktopWindow(), &screenBounds);

	if (foregroundHandle != GetDesktopWindow() && foregroundHandle != GetShellWindow())
	{
		DWORD processPID;
		GetWindowThreadProcessId(foregroundHandle, &processPID);

		HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processPID);
		if (processHandle)
		{
			WCHAR processName[MAX_PATH];
			if (0 != GetModuleBaseName(processHandle, NULL, processName, MAX_PATH))
			{
				measure->processName = processName;
			}

			CloseHandle(processHandle);
		}

		GetWindowRect(foregroundHandle, &appBounds);
		if (EqualRect(&appBounds, &screenBounds))
		{
			foundFullScreen = 1.0;
		}
	}

	return foundFullScreen;
}

PLUGIN_EXPORT LPCWSTR GetString(void* data)
{
	Measure* measure = (Measure*)data;
	return measure->processName.c_str();
}

//PLUGIN_EXPORT void ExecuteBang(void* data, LPCWSTR args)
//{
//   Measure* measure = (Measure*)data;
//}

PLUGIN_EXPORT void Finalize(void* data)
{
	Measure* measure = (Measure*)data;
	delete measure;
}

Re: IsFullScreen

Posted: April 18th, 2018, 4:05 am
by Active Colors
Sweet plugin. Was looking for this type of thing couple of month before. Thanks jsmorley!
Why is it not posted it the Plugins section by the way?

Re: IsFullScreen

Posted: April 18th, 2018, 4:08 am
by jsmorley
Active Colors wrote:Sweet plugin. Was looking for this type of thing couple of month before. Thanks jsmorley!
Why is it not posted it the Plugins section by the way?
Moved...

Re: IsFullScreen

Posted: April 18th, 2018, 12:59 pm
by eclectic-tech
The rmskin package says the plugin is the same version when installing... I think you forgot to update the version.
I have version 1 installed... and it says the versions are the same. Did the plugin change or only the skin code? :confused:

Re: IsFullScreen

Posted: April 18th, 2018, 1:03 pm
by jsmorley
eclectic-tech wrote:The rmskin package says the plugin is the same version when installing... I think you forgot to update the version.
I have version 1 installed... and it says the versions are the same. Did the plugin change or only the skin code? :confused:
There is something wrong with the way the version is being compared for this plugin, and we are digging into it. So far, it's a mystery.

Just check the box to "force" it to install the newer version.

Re: IsFullScreen

Posted: April 18th, 2018, 1:14 pm
by eclectic-tech
jsmorley wrote:There is something wrong with the way the version is being compared for this plugin, and we are digging into it. So far, it's a mystery.

Just check the box to "force" it to install the newer version.
Did that! Just wanted to let you know... :welcome:

Re: IsFullScreen

Posted: April 18th, 2018, 1:16 pm
by jsmorley
eclectic-tech wrote:Did that! Just wanted to let you know... :welcome:
Yeah, thanks! We are scratching our heads and staring at this intently.

Re: IsFullScreen

Posted: April 18th, 2018, 1:26 pm
by eclectic-tech
jsmorley wrote:Yeah, thanks! We are scratching our heads and staring at this intently.
That's my normal reaction when testing code! :lol:

Re: IsFullScreen

Posted: April 18th, 2018, 1:37 pm
by jsmorley
eclectic-tech wrote:That's my normal reaction when testing code! :lol:
I think I found it. It appears to have been a bug in Microsoft Visual Studio, and updating that seems to have corrected the issue. I have created a 2.1 version, which is in the first post. Can you get that and make sure it says "Replace" for the plugin when you install it? And if you install it again, it should say "Versions are the same".

Re: IsFullScreen

Posted: April 18th, 2018, 2:27 pm
by eclectic-tech
jsmorley wrote:I think I found it. It appears to have been a bug in Microsoft Visual Studio, and updating that seems to have corrected the issue. I have created a 2.1 version, which is in the first post. Can you get that and make sure it says "Replace" for the plugin when you install it? And if you install it again, it should say "Versions are the same".
It works the way you would expect; replaced on first install and said versions were the same on second attempt. :17good