wallpaper_set_subscriptions

This function subscribes to the given metric(s) from the Companion app. This is used to get real-time system information, and enable mouse input, which is disabled for Live Wallpapers by default.

IMPORTANT See this guide for making a basic Live Wallpaper and (optionally) setting up the Companion app on Windows.

NOTE Graphics drivers must be up-to-date on the target computer for GPU metrics to work correctly.

NOTE Each call to this function cancels any previously active subscriptions, so only those included in the last call remain active.

Arguments

You pass an array into this function, containing one or more of the following strings: "desktop_mouse", "cpu", "gpu", "battery", "ram", "disk", "network", "audio".

"desktop_mouse" enables mouse input for your Live Wallpaper. The other options allow the Wallpaper Subscription Data event to be triggered, where you receive data on the metrics you chose to subscribe to.

Receiving Metrics

Within the Wallpaper Subscription Data event you will receive updates for subscribed metrics, around once every second, except for audio which is ten times a second.

The event will contain a wallpaper_subscription_data variable which is a struct, containing the following members:

wallpaper_subscription_data Structwallpaper_subscription_data Struct

If some information could not be retrieved from the system, its corresponding variable will not be present in this structure. That may cause a crash if you try to access a variable that doesn't exist. To prevent that, use struct_exists to check that a variable exists in a struct, before accessing it.

 

 

Syntax:

wallpaper_set_subscriptions(subscriptions);

ArgumentTypeDescription
subscriptionsArrayAn array containing strings, which are the metrics you want to subscribe to

 

Returns:

N/A

 

Example:

// Create Event
wallpaper_set_subscriptions(["desktop_mouse", "cpu"]);


// Wallpaper Subscription Data Event
var _cpus = wallpaper_subscription_data.cpu;

file = file_text_open_append("sysinfo.txt");
file_text_writeln(file);
file_text_write_string(file, string(date_current_datetime()));
file_text_write_string(file, $"\nCPU count: {array_length(_cpus)}");

array_foreach(_cpus, function(_cpu, _num)
{
    if (!struct_exists(_cpu, "usage_pct")) return;
    var _str = $"\nCPU {_num} load: {_cpu.usage_pct}%";
    file_text_write_string(file, _str);
});

file_text_close(file);

The first line, run in the Create event, enables mouse input and subscribes to CPU metrics.

In the Wallpaper Subscription Data event, it gets the devices array for the CPU, and opens a text file to write metrics to.

In that file, it writes the current datetime, CPU device count (which is the length of the array), and then proceeds to write the load percentage of each CPU device in the array.

This code generates the following text in the sysinfo.txt file, found in the working directory:

45245.33
CPU count: 1
CPU 0 load: 3%
45245.33
CPU count: 1
CPU 0 load: 3%
45245.33
CPU count: 1
CPU 0 load: 3%