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.
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
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;
}