|
wlmaker
|
#include "wlm_graph_shared.h"#include <cairo.h>#include <errno.h>#include <libbase/libbase.h>#include <libwlclient/libwlclient.h>#include <primitives/primitives.h>#include <stdbool.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include "libwlclient/icon.h"
Classes | |
| struct | wlm_graph_sample_t |
| struct | wlm_graph_state_t |
| struct | wlm_graph_font_spec_t |
| struct | wlm_graph_prefs_t |
| struct | wlm_graph_handle_t |
Macros | |
| #define | WLM_GRAPH_BASE_ICON_SIZE 64 |
| #define | WLM_GRAPH_LABEL_FONT_SIZE_BASE 8 |
| #define | WLM_GRAPH_LABEL_COLOR 0xffc4c4c4 |
| #define | WLM_GRAPH_LABEL_FONT_FACE "Monospace" |
| #define | WLM_GRAPH_SOLID_BRIGHTNESS_MIN 32 |
| #define | WLM_GRAPH_SOLID_BRIGHTNESS_MAX 128 |
| #define | WLM_GRAPH_PIXEL_BLACK 0xff000000 |
| #define | WLM_GRAPH_PIXEL_LINE_DEFAULT 0xff008000 |
| #define | WLM_GRAPH_PIXEL_GRAY(b) |
| #define | WLM_GRAPH_FONT_FACE_MAX 64 |
| #define | _str_match_prefix(str_ptr, len_ptr, prefix) |
Typedefs | |
| typedef struct wlm_graph_sample_t | wlm_graph_sample_t |
Enumerations | |
| enum | wlm_graph_color_mode_t { WLM_GRAPH_COLOR_MODE_HEAT , WLM_GRAPH_COLOR_MODE_ALPHA } |
Functions | |
| static void | _wlm_graph_sample_values_free (wlm_graph_sample_t *samples, const uint32_t count) |
| static void | _wlm_graph_samples_init (wlm_graph_sample_t *samples, const uint32_t count) |
| static void | _wlm_graph_sample_compute_peak (wlm_graph_sample_t *sample, const wlm_graph_mode_t accumulate_mode) |
| static uint32_t | _wlm_graph_usage_to_y (const uint8_t usage, const uint32_t height) |
| static uint32_t | _wlm_graph_usage_to_y_with_zero_check (const uint8_t usage, const uint32_t height) |
| static uint32_t | _wlm_graph_column_render (wlm_graph_state_t *graph_state, const wlm_graph_sample_t *sample, const uint32_t column, const wlm_graph_mode_t accumulate_mode) |
| static void | _wlm_graph_peak_connector_draw (uint32_t *graph_pixels, const uint32_t graph_width, const uint32_t pixel_line, const uint32_t x, const uint32_t y_range[2]) |
| static void | _wlm_graph_peak_connector_draw_between (uint32_t *graph_pixels, const uint32_t graph_size[2], const uint32_t pixel_line, const uint8_t usage_curr, const uint8_t usage_prev, const uint32_t column_curr, const uint32_t column_prev) |
| static void | _wlm_graph_fill_columns_black (uint32_t *graph_pixels, const uint32_t graph_size[2], const uint32_t column_end) |
| static void | _wlm_graph_scroll_left (uint32_t *graph_pixels, const uint32_t graph_size[2], const uint32_t y_start) |
| static void | _wlm_graph_rebuild_from_samples (wlm_graph_state_t *graph_state, const wlm_graph_mode_t accumulate_mode) |
| static void | _wlm_graph_update_with_sample (wlm_graph_state_t *graph_state, wlm_graph_sample_t *new_sample, const wlm_graph_mode_t accumulate_mode) |
| static uint64_t | _wlm_graph_time_next_update (const uint64_t interval_usec) |
| static bool | _wlm_graph_icon_render_callback (bs_gfxbuf_t *gfxbuf_ptr, void *ud_ptr) |
| static void | _wlm_graph_sample_update (wlm_graph_handle_t *handle) |
| static void | _wlm_graph_timer_callback (wlclient_t *client_ptr, void *ud_ptr) |
| static bool | _wlm_graph_arg_parse_i32 (const char *opt_name, const char *str, const int32_t val_min, const int32_t val_max, int32_t *result_ptr) |
| static bool | _wlm_graph_arg_parse_f64 (const char *opt_name, const char *str, const double val_min, const double val_max, double *result_ptr) |
| static bool | _str_match_prefix_n (const char **str_ptr, size_t *len_ptr, const char *prefix, const size_t prefix_len) |
| static bool | _wlm_graph_arg_parse_font (const char *opt_name, const char *str, wlm_graph_font_spec_t *font) |
| static void | _wlm_graph_pixel_lut_init (uint32_t pixel_lut[256], uint32_t *pixel_line_ptr, const wlm_graph_color_mode_t color_mode) |
| static bool | _wlm_graph_buffers_resize (wlm_graph_state_t *graph_state, const uint32_t size[2], const uint32_t margin_logical_px) |
| static void | _wlm_graph_y_min_from_samples (wlm_graph_state_t *graph_state, wlm_graph_sample_t *current_sample) |
| static void | _wlm_graph_blit_to_buffer (bs_gfxbuf_t *gfxbuf_ptr, const uint32_t *graph_pixels, const uint32_t graph_size[2], const uint32_t offset[2]) |
| static bool | _wlm_graph_bezel_draw (bs_gfxbuf_t *gfxbuf_ptr, const uint32_t margin_logical_px) |
| static void | _wlm_graph_label_draw (bs_gfxbuf_t *gfxbuf_ptr, const uint32_t margin_px, const char *label, const wlm_graph_prefs_t *prefs) |
| static int | _wlm_graph_args_parse (const int argc, const char **argv, const char *app_name, const char *app_help, const bool has_custom_lut, const bool has_label, wlm_graph_prefs_t *prefs) |
| static void | _wlm_graph_state_free (wlm_graph_state_t *graph_state) |
| int | wlm_graph_app_run (int argc, const char **argv, const wlm_graph_app_config_t *config) |
Shared graph rendering utilities for wlmaker dock-apps.
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 _str_match_prefix | ( | str_ptr, | |
| len_ptr, | |||
| prefix ) |
Wrapper for _str_match_prefix_n using sizeof for string literal prefix.
| #define WLM_GRAPH_BASE_ICON_SIZE 64 |
Base icon size for scaling calculations.
| #define WLM_GRAPH_FONT_FACE_MAX 64 |
Maximum length of font face name.
| #define WLM_GRAPH_LABEL_COLOR 0xffc4c4c4 |
Label text color (light grey).
| #define WLM_GRAPH_LABEL_FONT_FACE "Monospace" |
Label font face.
| #define WLM_GRAPH_LABEL_FONT_SIZE_BASE 8 |
Base font size for label (at 64px icon size).
| #define WLM_GRAPH_PIXEL_BLACK 0xff000000 |
Black pixel (fully opaque).
| #define WLM_GRAPH_PIXEL_GRAY | ( | b | ) |
Constructs a grayscale ARGB pixel from brightness value.
| #define WLM_GRAPH_PIXEL_LINE_DEFAULT 0xff008000 |
Default line pixel color (green).
| #define WLM_GRAPH_SOLID_BRIGHTNESS_MAX 128 |
Maximum brightness for solid area (for WLM_GRAPH_COLOR_MODE_ALPHA).
| #define WLM_GRAPH_SOLID_BRIGHTNESS_MIN 32 |
Minimum brightness for solid area (for WLM_GRAPH_COLOR_MODE_ALPHA).
| typedef struct wlm_graph_sample_t wlm_graph_sample_t |
Single sample in the circular buffer.
|
static |
Checks if string starts with prefix; on match advances string and adjusts length.
| str_ptr | Pointer to string pointer (advanced on match). |
| len_ptr | Pointer to remaining length (decremented on match). |
| prefix | Prefix to match. |
| prefix_len | Length of prefix. |
|
static |
Parses a string as a double within a specified range.
| opt_name | Option name for error messages. |
| str | String to parse. |
| val_min | Minimum allowed value. |
| val_max | Maximum allowed value. |
| result_ptr | Output: parsed value. |
|
static |
Parses XFT-style font specification: "Name:size=N:weight=W:slant=S".
| opt_name | Option name for error messages (e.g., "--font"). |
| str | Font specification string. |
| font | Font spec struct to populate. |
|
static |
Parses a string as a 32-bit integer within a specified range.
| opt_name | Option name for error messages. |
| str | String to parse. |
| val_min | Minimum allowed value. |
| val_max | Maximum allowed value. |
| result_ptr | Output: parsed value. |
|
static |
Parses command-line arguments into preferences.
| argc | Argument count. |
| argv | Argument vector. |
| app_name | Application name for error messages. |
| app_help | Application help string for –help output. |
| has_custom_lut | Whether app supports custom color lookup table. |
| has_label | Whether app supports label display. |
| prefs | Output: parsed preferences. |
|
static |
Draws the bezel frame around the graph area.
| gfxbuf_ptr | Graphics buffer to draw into. |
| margin_logical_px | Margin in logical pixels (at base icon size). |
|
static |
Copies graph pixels to the destination graphics buffer.
| gfxbuf_ptr | Destination graphics buffer. |
| graph_pixels | Source pixel data. |
| graph_size | Graph dimensions [width, height]. |
| offset | Offset in destination buffer [x, y]. |
|
static |
Resizes graph buffers when icon dimensions change.
| graph_state | Graph state to resize. |
| size | New icon dimensions [width, height]. |
| margin_logical_px | Margin in logical pixels (at base icon size). |
|
static |
Renders a single column of the graph from sample data.
| graph_state | Graph state containing pixel buffer and LUT. |
| sample | Sample data for this column. |
| column | Column index to render. |
| accumulate_mode | Sample accumulation mode. |
|
static |
Fills columns with black pixels.
| graph_pixels | Pixel buffer to fill. |
| graph_size | Graph dimensions [width, height]. |
| column_end | Number of columns to fill (0 to column_end-1). |
|
static |
Callback invoked when the icon needs to be rendered.
| gfxbuf_ptr | Graphics buffer to render into. |
| ud_ptr | User data pointer (wlm_graph_handle_t). |
|
static |
Draws the label text in the top-left corner of the graph.
| gfxbuf_ptr | Graphics buffer to draw into. |
| margin_px | Margin in pixels (scaled to current icon size). |
| label | Label text to draw. |
| prefs | Preferences containing font settings. |
|
static |
Draws a vertical connector line between y coordinates.
| graph_pixels | Pixel buffer to draw into. |
| graph_width | Width of the graph in pixels. |
| pixel_line | Color for the connector line. |
| x | X coordinate (column) to draw at. |
| y_range | Y range [start, end) to draw. |
|
static |
Draws a vertical connector between adjacent columns when peaks differ.
| graph_pixels | Pixel buffer to draw into. |
| graph_size | Graph dimensions [width, height]. |
| pixel_line | Color for the connector line. |
| usage_curr | Usage value for current column. |
| usage_prev | Usage value for previous column. |
| column_curr | Current column index. |
| column_prev | Previous column index. |
|
static |
Initializes the pixel lookup table for graph coloring.
| pixel_lut | Output: 256-entry lookup table for value-to-color mapping. |
| pixel_line_ptr | Output: color for the line/peak indicator. |
| color_mode | Color mode (heat map or alpha/grayscale). |
|
static |
Rebuilds the entire graph from stored samples.
Used after resize to re-render all columns from sample history.
| graph_state | Graph state containing samples and pixel buffer. |
| accumulate_mode | Sample accumulation mode. |
|
static |
Computes the peak value for a sample from its values array.
| sample | Sample with values already populated. |
| accumulate_mode | Sample accumulation mode. |
|
static |
Reads stats and updates the graph with a new sample.
| handle | Graph handle containing state and config. |
|
static |
Frees the values arrays within each sample.
| samples | Array of samples to free values from. |
| count | Number of samples in the array. |
|
static |
Initializes sample array as a circular doubly-linked list.
| samples | Array of samples to initialize. |
| count | Number of samples in the array. |
|
static |
Scrolls graph pixels left by one column.
| graph_pixels | Pixel buffer to scroll. |
| graph_size | Graph dimensions [width, height]. |
| y_start | Starting Y coordinate (skip rows above this). |
|
static |
Frees all resources associated with graph state.
| graph_state | Graph state to free, or NULL. |
|
static |
Calculates the timestamp for the next update.
| interval_usec | Update interval in microseconds. |
|
static |
Timer callback for periodic graph updates.
| client_ptr | Wayland client instance. |
| ud_ptr | User data pointer (wlm_graph_handle_t). |
|
static |
Updates the graph with a new sample, scrolling and rendering.
| graph_state | Graph state to update. |
| new_sample | Sample containing the new data. |
| accumulate_mode | Sample accumulation mode. |
|
static |
Maps usage (0-255) to y coordinate: y=0 is top, higher usage = higher on screen.
|
static |
Maps usage (0-255) to y coordinate. Returns height for usage=0 (no bar).
|
static |
Finds sample with highest peak, sets y_min and sample_peak in graph_state.
Iterates newest-to-oldest and uses strict < so the newest sample wins ties. This keeps sample_peak in the buffer longer, reducing rescan frequency.
| int wlm_graph_app_run | ( | int | argc, |
| const char ** | argv, | ||
| const wlm_graph_app_config_t * | config ) |
Runs a graph application.
Handles argument parsing, wlclient setup, icon creation, callback registration, main loop, and cleanup. Apps just need to initialize their state and provide a configuration.
Graph state is managed internally by this function.
| argc | Argument count. |
| argv | Argument vector. |
| config | Application configuration. |