timers: Reinitialize per cpu bases on hotplug
[linux/fpc-iii.git] / tools / perf / ui / gtk / util.c
blob7250d8101c8feec896e9cf8733b798b358b98c27
1 // SPDX-License-Identifier: GPL-2.0
2 #include "../util.h"
3 #include "../../util/util.h"
4 #include "../../util/debug.h"
5 #include "gtk.h"
7 #include <string.h>
10 struct perf_gtk_context *pgctx;
12 struct perf_gtk_context *perf_gtk__activate_context(GtkWidget *window)
14 struct perf_gtk_context *ctx;
16 ctx = malloc(sizeof(*pgctx));
17 if (ctx)
18 ctx->main_window = window;
20 return ctx;
23 int perf_gtk__deactivate_context(struct perf_gtk_context **ctx)
25 if (!perf_gtk__is_active_context(*ctx))
26 return -1;
28 zfree(ctx);
29 return 0;
32 static int perf_gtk__error(const char *format, va_list args)
34 char *msg;
35 GtkWidget *dialog;
37 if (!perf_gtk__is_active_context(pgctx) ||
38 vasprintf(&msg, format, args) < 0) {
39 fprintf(stderr, "Error:\n");
40 vfprintf(stderr, format, args);
41 fprintf(stderr, "\n");
42 return -1;
45 dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(pgctx->main_window),
46 GTK_DIALOG_DESTROY_WITH_PARENT,
47 GTK_MESSAGE_ERROR,
48 GTK_BUTTONS_CLOSE,
49 "<b>Error</b>\n\n%s", msg);
50 gtk_dialog_run(GTK_DIALOG(dialog));
52 gtk_widget_destroy(dialog);
53 free(msg);
54 return 0;
57 #ifdef HAVE_GTK_INFO_BAR_SUPPORT
58 static int perf_gtk__warning_info_bar(const char *format, va_list args)
60 char *msg;
62 if (!perf_gtk__is_active_context(pgctx) ||
63 vasprintf(&msg, format, args) < 0) {
64 fprintf(stderr, "Warning:\n");
65 vfprintf(stderr, format, args);
66 fprintf(stderr, "\n");
67 return -1;
70 gtk_label_set_text(GTK_LABEL(pgctx->message_label), msg);
71 gtk_info_bar_set_message_type(GTK_INFO_BAR(pgctx->info_bar),
72 GTK_MESSAGE_WARNING);
73 gtk_widget_show(pgctx->info_bar);
75 free(msg);
76 return 0;
78 #else
79 static int perf_gtk__warning_statusbar(const char *format, va_list args)
81 char *msg, *p;
83 if (!perf_gtk__is_active_context(pgctx) ||
84 vasprintf(&msg, format, args) < 0) {
85 fprintf(stderr, "Warning:\n");
86 vfprintf(stderr, format, args);
87 fprintf(stderr, "\n");
88 return -1;
91 gtk_statusbar_pop(GTK_STATUSBAR(pgctx->statbar),
92 pgctx->statbar_ctx_id);
94 /* Only first line can be displayed */
95 p = strchr(msg, '\n');
96 if (p)
97 *p = '\0';
99 gtk_statusbar_push(GTK_STATUSBAR(pgctx->statbar),
100 pgctx->statbar_ctx_id, msg);
102 free(msg);
103 return 0;
105 #endif
107 struct perf_error_ops perf_gtk_eops = {
108 .error = perf_gtk__error,
109 #ifdef HAVE_GTK_INFO_BAR_SUPPORT
110 .warning = perf_gtk__warning_info_bar,
111 #else
112 .warning = perf_gtk__warning_statusbar,
113 #endif