1 // SPDX-License-Identifier: GPL-2.0
3 #include "../../util/util.h"
4 #include "../../util/debug.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));
18 ctx->main_window = window;
23 int perf_gtk__deactivate_context(struct perf_gtk_context **ctx)
25 if (!perf_gtk__is_active_context(*ctx))
32 static int perf_gtk__error(const char *format, va_list args)
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");
45 dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(pgctx->main_window),
46 GTK_DIALOG_DESTROY_WITH_PARENT,
49 "<b>Error</b>\n\n%s", msg);
50 gtk_dialog_run(GTK_DIALOG(dialog));
52 gtk_widget_destroy(dialog);
57 #ifdef HAVE_GTK_INFO_BAR_SUPPORT
58 static int perf_gtk__warning_info_bar(const char *format, va_list args)
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");
70 gtk_label_set_text(GTK_LABEL(pgctx->message_label), msg);
71 gtk_info_bar_set_message_type(GTK_INFO_BAR(pgctx->info_bar),
73 gtk_widget_show(pgctx->info_bar);
79 static int perf_gtk__warning_statusbar(const char *format, va_list args)
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");
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');
99 gtk_statusbar_push(GTK_STATUSBAR(pgctx->statbar),
100 pgctx->statbar_ctx_id, msg);
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,
112 .warning = perf_gtk__warning_statusbar,