|
wlmaker
|
#include <cairo.h>#include <dirent.h>#include <inttypes.h>#include <stdarg.h>#include <stdbool.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <primitives/primitives.h>#include <wlclient/wlclient.h>#include <wlclient/icon.h>#include <wlclient/dblbuf.h>#include <libbase/libbase.h>
Classes | |
| struct | wlm_power_supply |
| struct | wlm_power_adapter |
| struct | wlm_battery |
| struct | callback_arg |
Macros | |
| #define | SYSFS_BATTERY_PATH_MAX_LEN 256 |
| #define | VAL_BUF_LEN 64 |
Enumerations | |
| enum | battery_status { BATTERY_STATUS_UNKNOWN = 0 , BATTERY_STATUS_CHARGING , BATTERY_STATUS_DISCHARGING , BATTERY_STATUS_NOT_CHARGING , BATTERY_STATUS_FULL } |
Functions | |
| static struct wlm_power_supply * | wlm_power_supply_create (void) |
| static void | wlm_power_supply_destroy (struct wlm_power_supply *ps) |
| static bool | wlm_power_supply_read (struct wlm_power_supply *ps) |
| static size_t | wlm_power_supply_num_batteries (struct wlm_power_supply *ps) |
| static struct wlm_battery * | wlm_power_supply_battery (struct wlm_power_supply *ps, size_t index) |
| static bool | wlm_power_supply_connected (struct wlm_power_supply *ps) |
| static struct wlm_battery * | wlm_battery_create (const char *name_ptr, const char *power_supply_dir) |
| static void | wlm_battery_destroy (bs_dllist_node_t *dlnode_ptr, void *ud_ptr) |
| static bool | wlm_battery_read (struct wlm_battery *bat) |
| static struct wlm_power_adapter * | wlm_power_adapter_create (const char *name_ptr, const char *power_supply_dir) |
| static void | wlm_power_adapter_destroy (bs_dllist_node_t *dlnode_ptr, void *ud_ptr) |
| static bool | wlm_power_adapter_connected (bs_dllist_node_t *node_ptr, void *ud_ptr) |
| static bool | wlm_power_adapter_read (struct wlm_power_adapter *adapter) |
| static bool | wlm_vread_buffer (char *v, size_t v_size, const char *fmt_ptr, va_list ap) |
| static bool | wlm_read_buffer (char *v, size_t v_size, const char *fmt_ptr,...) |
| static bool | wlm_read_uint64 (uint64_t *u64_ptr, const char *fmt_ptr,...) |
| static enum battery_status | parse_battery_status (const char *status_str) |
| bool | icon_callback (bs_gfxbuf_t *gfxbuf_ptr, void *ud_ptr) |
| void | timer_callback (wlmcl_client_t *client_ptr, void *ud_ptr) |
| static void | _handle_configure (void *ud_ptr, uint32_t width, uint32_t height) |
| int | main (void) |
Variables | |
| static wlmcl_client_t * | wlclient_ptr |
| static wlmcl_dblbuf_t * | dblbuf_ptr |
Displays battery capacity from /sys/class/power_supply in a DockApp.
TODO(kaese.nosp@m.r@gu.nosp@m.bbe.c.nosp@m.h):
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
| #define SYSFS_BATTERY_PATH_MAX_LEN 256 |
Sufficient for the typical paths, although there is no strict maximum.
| #define VAL_BUF_LEN 64 |
Small buffer for reading single values (like capacity).
| enum battery_status |
Internal battery status enum.
|
static |
Handles configure events.
| bool icon_callback | ( | bs_gfxbuf_t * | gfxbuf_ptr, |
| void * | ud_ptr | ||
| ) |
Draws current byttery status into the icon buffer.
| gfxbuf_ptr | |
| ud_ptr |
| int main | ( | void | ) |
EXIT_SUCCESS on success.
|
static |
Maps standard sysfs status string to internal enum.
| status_str | String literal describing the battery status. |
| void timer_callback | ( | wlmcl_client_t * | client_ptr, |
| void * | ud_ptr | ||
| ) |
Called once per second.
|
static |
Creates battery struct spanning the specific name_ptr.
| name_ptr | Null-terminated property name segment (e.g. "BAT0"). |
| power_supply_dir | The root directory where sysfs devices live. |
|
static |
Destroys battery struct.
| dlnode_ptr | |
| ud_ptr |
|
static |
Helper to pull all readings into the structural cache representation.
| bat | Pointer to the target battery object tracking the metric states. |
|
static |
Iterator function to verify whether a power adapter node is connected.
| node_ptr | The doubly-linked list node embedded in a wlm_power_adapter. |
| ud_ptr | Ignored user data. |
|
static |
Creates adapter struct spanning the specific name_ptr.
| name_ptr | Null-terminated property name segment (e.g. "AC0"). |
| power_supply_dir | The root directory where sysfs devices live. |
|
static |
Destroys power adapter struct.
| dlnode_ptr | The list node of the power adapter to destroy. |
| ud_ptr |
|
static |
Reads power adapter properties into the structural cache representation.
| adapter | Pointer to the target power adapter object. |
|
static |
Extract battery handle at specified index linearly.
| ps | Pointer to the structured system state container. |
| index | Index integer for node traversal limit bounding. |
|
static |
Indicates if any of the power adapters is online.
| ps | Pointer to the target power supply. |
|
static |
Iterates through /sys/class/power_supply and creates corresponding battery and adapter items.
|
static |
Destroys the power supply container and internal batteries/adapters.
| ps | Pointer to the target power supply. |
|
static |
Returns the tracked amount of batteries.
| ps | Pointer to the target power supply. |
|
static |
Reads current state of the power supply (batteries and adapters).
| ps |
|
static |
Reads content of file named by the formatted path into the buffer.
| v | Output buffer. |
| v_size | Length boundary for v. |
| fmt_ptr | Format string for the path. |
| ... | Arguments for the format string. |
|
static |
Reads content of file named by the formatted path and parses it as uint64.
| u64_ptr | Output pointer for the parsed integer. |
| fmt_ptr | Format string for the path. |
| ... | Arguments for the format string. |
|
static |
Reads content of file named by the formatted path into a buffer.
| v | Output buffer. |
| v_size | Length boundary for v. |
| fmt_ptr | Format string for the path. |
| ap | Variadic arguments list. |
|
static |
Double buffer pointer.
|
static |
Wayland client state.