Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <stdio.h>
0003 #include <string.h>
0004 #include <linux/kernel.h>
0005 
0006 #include "gtk.h"
0007 #include "../ui.h"
0008 #include "../helpline.h"
0009 
0010 static void gtk_helpline_pop(void)
0011 {
0012     if (!perf_gtk__is_active_context(pgctx))
0013         return;
0014 
0015     gtk_statusbar_pop(GTK_STATUSBAR(pgctx->statbar),
0016               pgctx->statbar_ctx_id);
0017 }
0018 
0019 static void gtk_helpline_push(const char *msg)
0020 {
0021     if (!perf_gtk__is_active_context(pgctx))
0022         return;
0023 
0024     gtk_statusbar_push(GTK_STATUSBAR(pgctx->statbar),
0025                pgctx->statbar_ctx_id, msg);
0026 }
0027 
0028 static int gtk_helpline_show(const char *fmt, va_list ap)
0029 {
0030     int ret;
0031     char *ptr;
0032     static int backlog;
0033 
0034     ret = vscnprintf(ui_helpline__current + backlog,
0035              sizeof(ui_helpline__current) - backlog, fmt, ap);
0036     backlog += ret;
0037 
0038     /* only first line can be displayed */
0039     ptr = strchr(ui_helpline__current, '\n');
0040     if (ptr && (ptr - ui_helpline__current) <= backlog) {
0041         *ptr = '\0';
0042         ui_helpline__puts(ui_helpline__current);
0043         backlog = 0;
0044     }
0045 
0046     return ret;
0047 }
0048 
0049 static struct ui_helpline gtk_helpline_fns = {
0050     .pop    = gtk_helpline_pop,
0051     .push   = gtk_helpline_push,
0052     .show   = gtk_helpline_show,
0053 };
0054 
0055 void perf_gtk__init_helpline(void)
0056 {
0057     helpline_fns = &gtk_helpline_fns;
0058 }