diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2021-08-26 02:33:32 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2021-08-26 02:33:32 -0700 |
commit | 9d4d28e099fb8e462a36151551d6a8db1263bdd5 (patch) | |
tree | 1d3963b7c1bf07946f28489f877362b5166be962 | |
parent | 38ea6aa681cd7c0652ffc56f6976d069ef683229 (diff) |
charts: add name to charts overlay
Currently only vmon wires this up to --name, but vwm could get
the window title of the window being overlayed and pass that in
if set...
-rw-r--r-- | src/charts.c | 17 | ||||
-rw-r--r-- | src/charts.h | 2 | ||||
-rw-r--r-- | src/vmon.c | 2 | ||||
-rw-r--r-- | src/xwindow.c | 2 |
4 files changed, 18 insertions, 5 deletions
diff --git a/src/charts.c b/src/charts.c index fddef35..b25f548 100644 --- a/src/charts.c +++ b/src/charts.c @@ -91,6 +91,7 @@ typedef struct _vwm_chart_t { int snowflakes_cnt; /* count of snowflaked rows (reset to zero to truncate snowflakes display) */ int gen_last_composed; /* the last composed vmon generation */ int redraw_needed; /* if a redraw is required (like when the window is resized...) */ + char *name; /* name if provided, included in chart by the \/\/\ */ } vwm_chart_t; /* space we need for every process being monitored */ @@ -852,7 +853,10 @@ static void draw_chart(vwm_charts_t *charts, vwm_chart_t *chart, vmon_proc_t *pr /* only draw the \/\/\ and HZ if necessary */ if (chart->redraw_needed || charts->prev_sampling_interval != charts->sampling_interval) { - str_len = snpf(str, sizeof(str), "\\/\\/\\ %2uHz ", interval_as_hz(charts)); + str_len = snpf(str, sizeof(str), "\\/\\/\\%s%s @ %2uHz ", + chart->name ? " # " : "", + chart->name ? chart->name : "", + interval_as_hz(charts)); XRenderFillRectangle(xserver->display, PictOpSrc, chart->text_picture, &chart_trans_color, 0, 0, /* dst x, y */ chart->visible_width, CHART_ROW_HEIGHT); /* dst w, h */ @@ -1036,7 +1040,7 @@ int vwm_chart_set_visible_size(vwm_charts_t *charts, vwm_chart_t *chart, int wid /* create an chart and start monitoring for the supplied pid */ -vwm_chart_t * vwm_chart_create(vwm_charts_t *charts, int pid, int width, int height) +vwm_chart_t * vwm_chart_create(vwm_charts_t *charts, int pid, int width, int height, const char *name) { vwm_chart_t *chart; @@ -1046,6 +1050,14 @@ vwm_chart_t * vwm_chart_create(vwm_charts_t *charts, int pid, int width, int hei goto _err; } + if (name) { + chart->name = strdup(name); + if (!chart->name) { + VWM_PERROR("Unable to allocate name"); + goto _err_free; + } + } + /* add the client process to the monitoring heirarchy */ /* XXX note libvmon here maintains a unique callback for each unique callback+xwin pair, so multi-window processes work */ chart->monitor = vmon_proc_monitor(&charts->vmon, NULL, pid, VMON_WANT_PROC_INHERIT, (void (*)(vmon_t *, void *, vmon_proc_t *, void *))proc_sample_callback, chart); @@ -1070,6 +1082,7 @@ _err_unmonitor: vmon_proc_unmonitor(&charts->vmon, chart->monitor, (void (*)(vmon_t *, void *, vmon_proc_t *, void *))proc_sample_callback, chart); _err_free: + free(chart->name); free(chart); _err: return NULL; diff --git a/src/charts.h b/src/charts.h index ed71fdd..9e28afa 100644 --- a/src/charts.h +++ b/src/charts.h @@ -16,7 +16,7 @@ void vwm_charts_rate_decrease(vwm_charts_t *charts); void vwm_charts_rate_set(vwm_charts_t *charts, unsigned hertz); int vwm_charts_update(vwm_charts_t *charts, int *desired_delay); -vwm_chart_t * vwm_chart_create(vwm_charts_t *charts, int pid, int width, int height); +vwm_chart_t * vwm_chart_create(vwm_charts_t *charts, int pid, int width, int height, const char *name); void vwm_chart_destroy(vwm_charts_t *charts, vwm_chart_t *chart); void vwm_chart_reset_snowflakes(vwm_charts_t *charts, vwm_chart_t *chart); int vwm_chart_set_visible_size(vwm_charts_t *charts, vwm_chart_t *chart, int width, int height); @@ -389,7 +389,7 @@ static vmon_t * vmon_startup(int argc, char * const argv[]) goto _err_charts; } - vmon->chart = vwm_chart_create(vmon->charts, vmon->pid, vmon->width, vmon->height); + vmon->chart = vwm_chart_create(vmon->charts, vmon->pid, vmon->width, vmon->height, vmon->name); if (!vmon->chart) { VWM_ERROR("unable to create chart"); goto _err_charts; diff --git a/src/xwindow.c b/src/xwindow.c index 1deaf33..18ebf5f 100644 --- a/src/xwindow.c +++ b/src/xwindow.c @@ -105,7 +105,7 @@ void vwm_xwin_setup_chart(vwm_t *vwm, vwm_xwindow_t *xwin) int pid = vwm_xwin_get_pid(vwm, xwin); if (pid != -1) - xwin->chart = vwm_chart_create(vwm->charts, pid, xwin->attrs.width, xwin->attrs.height); + xwin->chart = vwm_chart_create(vwm->charts, pid, xwin->attrs.width, xwin->attrs.height, NULL); /* TODO: windows have names, incorporate it if present. */ } } |