1 // SPDX-License-Identifier: GPL-2.0
6 #include <subcmd/pager.h>
7 #include "../util/debug.h"
8 #include "../util/hist.h"
11 struct mutex ui__lock;
12 void *perf_gtk_handle;
15 #define PERF_GTK_DSO "libperf-gtk.so"
17 #ifdef HAVE_GTK2_SUPPORT
19 static int setup_gtk_browser(void)
21 int (*perf_ui_init)(void);
26 perf_gtk_handle = dlopen(PERF_GTK_DSO, RTLD_LAZY);
27 if (perf_gtk_handle == NULL) {
29 scnprintf(buf, sizeof(buf), "%s/%s", LIBDIR, PERF_GTK_DSO);
30 perf_gtk_handle = dlopen(buf, RTLD_LAZY);
32 if (perf_gtk_handle == NULL)
35 perf_ui_init = dlsym(perf_gtk_handle, "perf_gtk__init");
36 if (perf_ui_init == NULL)
39 if (perf_ui_init() == 0)
43 dlclose(perf_gtk_handle);
47 static void exit_gtk_browser(bool wait_for_ok)
49 void (*perf_ui_exit)(bool);
51 if (perf_gtk_handle == NULL)
54 perf_ui_exit = dlsym(perf_gtk_handle, "perf_gtk__exit");
55 if (perf_ui_exit == NULL)
58 perf_ui_exit(wait_for_ok);
61 dlclose(perf_gtk_handle);
63 perf_gtk_handle = NULL;
66 static inline int setup_gtk_browser(void) { return -1; }
67 static inline void exit_gtk_browser(bool wait_for_ok __maybe_unused) {}
70 int stdio__config_color(const struct option *opt __maybe_unused,
71 const char *mode, int unset __maybe_unused)
73 perf_use_color_default = perf_config_colorbool("color.ui", mode, -1);
77 void setup_browser(bool fallback_to_pager)
79 mutex_init(&ui__lock);
80 if (use_browser < 2 && (!isatty(1) || dump_trace))
87 switch (use_browser) {
89 if (setup_gtk_browser() == 0)
91 printf("GTK browser requested but could not find %s\n",
102 if (fallback_to_pager)
108 void exit_browser(bool wait_for_ok)
110 switch (use_browser) {
112 exit_gtk_browser(wait_for_ok);
116 ui__exit(wait_for_ok);
122 mutex_destroy(&ui__lock);
125 void pthread__block_sigwinch(void)
130 sigaddset(&set, SIGWINCH);
131 pthread_sigmask(SIG_BLOCK, &set, NULL);
134 void pthread__unblock_sigwinch(void)
139 sigaddset(&set, SIGWINCH);
140 pthread_sigmask(SIG_UNBLOCK, &set, NULL);