^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 "../evsel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include "../sort.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include "../hist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include "../helpline.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include "gtk.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) void perf_gtk__signal(int sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) perf_gtk__exit(false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) psignal(sig, "perf");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) void perf_gtk__resize_window(GtkWidget *window)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) GdkRectangle rect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) GdkScreen *screen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) int monitor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) int height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) int width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) screen = gtk_widget_get_screen(window);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) monitor = gdk_screen_get_monitor_at_window(screen, window->window);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) gdk_screen_get_monitor_geometry(screen, monitor, &rect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) width = rect.width * 3 / 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) height = rect.height * 3 / 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) gtk_window_resize(GTK_WINDOW(window), width, height);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) const char *perf_gtk__get_percent_color(double percent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (percent >= MIN_RED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return "<span fgcolor='red'>";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (percent >= MIN_GREEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return "<span fgcolor='dark green'>";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #ifdef HAVE_GTK_INFO_BAR_SUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) GtkWidget *perf_gtk__setup_info_bar(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) GtkWidget *info_bar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) GtkWidget *label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) GtkWidget *content_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) info_bar = gtk_info_bar_new();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) gtk_widget_set_no_show_all(info_bar, TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) label = gtk_label_new("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) gtk_widget_show(label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) content_area = gtk_info_bar_get_content_area(GTK_INFO_BAR(info_bar));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) gtk_container_add(GTK_CONTAINER(content_area), label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) gtk_info_bar_add_button(GTK_INFO_BAR(info_bar), GTK_STOCK_OK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) GTK_RESPONSE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) g_signal_connect(info_bar, "response",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) G_CALLBACK(gtk_widget_hide), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) pgctx->info_bar = info_bar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) pgctx->message_label = label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return info_bar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) GtkWidget *perf_gtk__setup_statusbar(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) GtkWidget *stbar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) unsigned ctxid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) stbar = gtk_statusbar_new();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ctxid = gtk_statusbar_get_context_id(GTK_STATUSBAR(stbar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) "perf report");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) pgctx->statbar = stbar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) pgctx->statbar_ctx_id = ctxid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return stbar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }