wallpaper_set_subscriptions
此函数从 Companion 应用程序订阅给定的指标。用于获取实时系统信息,并启用鼠标输入,动态壁纸默认禁用鼠标输入。
重要 See this guide for making a basic Live Wallpaper and (optionally) setting up the Companion app on Windows.
注意 目标计算机上的图形驱动程序必须是最新的,GPU 指标才能正常工作。
注意 每次调用此函数都会取消之前所有活动的订阅,因此只有上次调用中包含的订阅仍保持活动状态。
论点
您向该函数传递一个数组,其中包含以下一个或多个字符串:"desktop_mouse"、"cpu"、"gpu"、"battery"、" 内存 "、" 磁盘 "、" 网络 "、" 音频 "。
"desktop_mouse" 为您的动态壁纸启用鼠标输入。其他选项允许触发 壁纸订阅数据 事件,您可以在其中接收有关您选择订阅的指标的数据。
接收指标
在 壁纸订阅数据 事件中,您将收到订阅指标的更新,大约每秒一次,音频除外,每秒十次。
该事件将包含一个 wallpaper_subscription_data 变量,该变量是一个 结构体 ,包含以下成员:
wallpaper_subscription_data 结构 wallpaper_subscription_data 结构
- cpu( 数组 ):CPU 设备数组。该数组中的每个条目都是一个结构体,包含以下成员:
- name(String):CPU 的名称。
- num_logic_cores( 整数 Real):逻辑核心数量。
- num_physical_cores( 整数 Real):物理核心数量。
- usage_pct( 整数 Real):CPU 的负载百分比。
- current_clock_speed_MHz( 整数 Real):当前时钟速度 CPU 的最大时钟速度,以 MHz 为单位。
- max_clock_speed_MHz( 整数 Real):CPU 的最大时钟速度,以 MHz 为单位。
- 电压 _V( 整数 实数 ):CPU 的当前电压 (以伏特为单位)。
- gpu (Array): Array of GPU devices. Each entry in this array is a struct, containing the following members:
- name (String): The name of the GPU.
- usage_pct (Integer Real): The load percentage of the GPU.
- clock_speed_MHz (Integer Real): The current clock speed of the GPU in MHz.
- fan_speed_pct or fan_speed_rpm (Array of Integer Reals): The target speed of each GPU fan. Expressed as a percentage of the maximum speed on NVIDIA GPUs and in RPM on AMD GPUs (AMD will only return one element in the array).
- power_usage_W (Integer Real): The power usage of the GPU in Watt.
- temperature_C (Integer Real): The temperature of the GPU in Celsius.
- memory_used_bytes (String): How much of the GPU memory is used up in bytes.
- memory_available_bytes (String): How much of the GPU memory is available in bytes.
- memory_total_bytes (String): The total GPU memory in bytes.
- battery ( 数组 ):电池设备数组。该数组中的每个条目都是一个结构体,包含以下成员:
- name(String):电池的名称。
- is_charging(Boolean):指示电池是否正在充电。
- remaining_charge_pct(IntegerReal):电池中剩余电量的百分比。
- remaining_time_min( 整数 实数 ):估计电池剩余时间 (以分钟为单位)。
- ram (Array): Array of RAM devices. Each entry in this array is a struct, containing the following members:
- name (String): The name of the RAM.
- available_bytes (String): How much of the RAM memory is available in bytes.
- total_bytes (String): The total RAM memory in bytes.
- used_bytes (String): How much of the GPU memory is used up in bytes.
- disk (Array): Array of disks. Each entry in this array is a struct, containing the following members:
- name (String): The name of the disk.
- available_bytes (String): How much of the disk memory is available in bytes.
- total_bytes (String): The total disk memory in bytes.
- used_bytes (String): How much of the GPU memory is used up in bytes.
- network (Array): Array of network devices. Each entry in this array is a struct, containing the following members:
- bandwidth_bps (String): The bandwidth of the network in bits per second.
- send_bps (Integer Real): The current bytes sent per second on the network.
- received_bps (Integer Real): The current bytes received per second on the network.
- audio (Array): Array of audio devices. Each entry in this array is a struct, containing the following members:
- freq_resolution (Integer Real): The frequency resolution, is always 10.
- spectrum_amplitude (Array): Represents a spectrum analysis of measured sound amplitudes on the system. The frequency will span from 0 Hz up to the Nyquist frequency, i.e half that of the system's sampling rate. If it is, for example, 44.1 kHz (the most common), the frequencies will range from 0 Hz to 22050 Hz. Each bin will always represent a range of freq_resolution. E.g. if it is 10, this array will consist of 2205 data points if the sampling rate is 44.1 kHz, and 2400 if it is 48 kHz (also common).
如果无法从系统检索某些信息,则其相应的变量将不会出现在该结构中。如果您尝试访问不存在的变量,可能会导致崩溃。为了防止这种情况发生,请在访问变量之前使用 struct_exists 检查结构中是否存在变量。
语法:
wallpaper_set_subscriptions(subscriptions);
参数 | 类型 | 描述 |
---|
subscriptions | Array | 包含字符串的数组,这些字符串是您要订阅的指标 |
返回:
N/A
例子:
// 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);
第一行在 Create 事件中运行,启用鼠标输入并订阅 CPU 指标。
在壁纸订阅数据事件中,它获取 CPU 的设备数组,并打开一个文本文件以写入指标。
在该文件中,它写入当前日期时间、CPU 设备计数 (即数组的长度),然后继续写入数组中每个 CPU 设备的负载百分比。
此代码在 工作目录 中的 sysinfo.txt 文件中生成以下文本:
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%