^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include "gtk.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include "../ui.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "../helpline.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) static void gtk_helpline_pop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) if (!perf_gtk__is_active_context(pgctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) gtk_statusbar_pop(GTK_STATUSBAR(pgctx->statbar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) pgctx->statbar_ctx_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static void gtk_helpline_push(const char *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) if (!perf_gtk__is_active_context(pgctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) gtk_statusbar_push(GTK_STATUSBAR(pgctx->statbar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) pgctx->statbar_ctx_id, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static int gtk_helpline_show(const char *fmt, va_list ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) char *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static int backlog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ret = vscnprintf(ui_helpline__current + backlog,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) sizeof(ui_helpline__current) - backlog, fmt, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) backlog += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* only first line can be displayed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) ptr = strchr(ui_helpline__current, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (ptr && (ptr - ui_helpline__current) <= backlog) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) *ptr = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) ui_helpline__puts(ui_helpline__current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) backlog = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static struct ui_helpline gtk_helpline_fns = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .pop = gtk_helpline_pop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .push = gtk_helpline_push,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .show = gtk_helpline_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) void perf_gtk__init_helpline(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) helpline_fns = >k_helpline_fns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }