1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/zalloc.h>
9 struct perf_gtk_context
*pgctx
;
11 struct perf_gtk_context
*perf_gtk__activate_context(GtkWidget
*window
)
13 struct perf_gtk_context
*ctx
;
15 ctx
= malloc(sizeof(*pgctx
));
17 ctx
->main_window
= window
;
22 int perf_gtk__deactivate_context(struct perf_gtk_context
**ctx
)
24 if (!perf_gtk__is_active_context(*ctx
))
31 static int perf_gtk__error(const char *format
, va_list args
)
36 if (!perf_gtk__is_active_context(pgctx
) ||
37 vasprintf(&msg
, format
, args
) < 0) {
38 fprintf(stderr
, "Error:\n");
39 vfprintf(stderr
, format
, args
);
40 fprintf(stderr
, "\n");
44 dialog
= gtk_message_dialog_new_with_markup(GTK_WINDOW(pgctx
->main_window
),
45 GTK_DIALOG_DESTROY_WITH_PARENT
,
48 "<b>Error</b>\n\n%s", msg
);
49 gtk_dialog_run(GTK_DIALOG(dialog
));
51 gtk_widget_destroy(dialog
);
56 #ifdef HAVE_GTK_INFO_BAR_SUPPORT
57 static int perf_gtk__warning_info_bar(const char *format
, va_list args
)
61 if (!perf_gtk__is_active_context(pgctx
) ||
62 vasprintf(&msg
, format
, args
) < 0) {
63 fprintf(stderr
, "Warning:\n");
64 vfprintf(stderr
, format
, args
);
65 fprintf(stderr
, "\n");
69 gtk_label_set_text(GTK_LABEL(pgctx
->message_label
), msg
);
70 gtk_info_bar_set_message_type(GTK_INFO_BAR(pgctx
->info_bar
),
72 gtk_widget_show(pgctx
->info_bar
);
78 static int perf_gtk__warning_statusbar(const char *format
, va_list args
)
82 if (!perf_gtk__is_active_context(pgctx
) ||
83 vasprintf(&msg
, format
, args
) < 0) {
84 fprintf(stderr
, "Warning:\n");
85 vfprintf(stderr
, format
, args
);
86 fprintf(stderr
, "\n");
90 gtk_statusbar_pop(GTK_STATUSBAR(pgctx
->statbar
),
91 pgctx
->statbar_ctx_id
);
93 /* Only first line can be displayed */
94 p
= strchr(msg
, '\n');
98 gtk_statusbar_push(GTK_STATUSBAR(pgctx
->statbar
),
99 pgctx
->statbar_ctx_id
, msg
);
106 struct perf_error_ops perf_gtk_eops
= {
107 .error
= perf_gtk__error
,
108 #ifdef HAVE_GTK_INFO_BAR_SUPPORT
109 .warning
= perf_gtk__warning_info_bar
,
111 .warning
= perf_gtk__warning_statusbar
,