diff options
| author | Namhyung Kim <namhyung.kim@lge.com> | 2012-04-30 00:55:08 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-05-02 15:17:34 -0400 |
| commit | 281ef544a8476f750b9f378593c42b3e8a0b8788 (patch) | |
| tree | 685e23ed105380b167a36ccac54130c42aaf38c9 /tools/perf/ui/tui | |
| parent | 28e62b90d95a4ed8ae2ba93879003665051581a6 (diff) | |
perf ui: Add gtk2 support into setup_browser()
Now setup_browser can handle gtk2 front-end so split the TUI code to
ui/tui/setup.c in order to remove dependency.
To this end, make ui__init/exit global symbols and take an argument.
Also split gtk code to ui/gtk/setup.c.
Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Acked-by: Pekka Enberg <penberg@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1335761711-31403-5-git-send-email-namhyung.kim@lge.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/ui/tui')
| -rw-r--r-- | tools/perf/ui/tui/setup.c | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c new file mode 100644 index 000000000000..0194cea2ea0e --- /dev/null +++ b/tools/perf/ui/tui/setup.c | |||
| @@ -0,0 +1,140 @@ | |||
| 1 | #include <newt.h> | ||
| 2 | #include <signal.h> | ||
| 3 | #include <stdbool.h> | ||
| 4 | |||
| 5 | #include "../../util/cache.h" | ||
| 6 | #include "../../util/debug.h" | ||
| 7 | #include "../browser.h" | ||
| 8 | #include "../helpline.h" | ||
| 9 | #include "../ui.h" | ||
| 10 | #include "../util.h" | ||
| 11 | #include "../libslang.h" | ||
| 12 | #include "../keysyms.h" | ||
| 13 | |||
| 14 | pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER; | ||
| 15 | |||
| 16 | static volatile int ui__need_resize; | ||
| 17 | |||
| 18 | void ui__refresh_dimensions(bool force) | ||
| 19 | { | ||
| 20 | if (force || ui__need_resize) { | ||
| 21 | ui__need_resize = 0; | ||
| 22 | pthread_mutex_lock(&ui__lock); | ||
| 23 | SLtt_get_screen_size(); | ||
| 24 | SLsmg_reinit_smg(); | ||
| 25 | pthread_mutex_unlock(&ui__lock); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | static void ui__sigwinch(int sig __used) | ||
| 30 | { | ||
| 31 | ui__need_resize = 1; | ||
| 32 | } | ||
| 33 | |||
| 34 | static void ui__setup_sigwinch(void) | ||
| 35 | { | ||
| 36 | static bool done; | ||
| 37 | |||
| 38 | if (done) | ||
| 39 | return; | ||
| 40 | |||
| 41 | done = true; | ||
| 42 | pthread__unblock_sigwinch(); | ||
| 43 | signal(SIGWINCH, ui__sigwinch); | ||
| 44 | } | ||
| 45 | |||
| 46 | int ui__getch(int delay_secs) | ||
| 47 | { | ||
| 48 | struct timeval timeout, *ptimeout = delay_secs ? &timeout : NULL; | ||
| 49 | fd_set read_set; | ||
| 50 | int err, key; | ||
| 51 | |||
| 52 | ui__setup_sigwinch(); | ||
| 53 | |||
| 54 | FD_ZERO(&read_set); | ||
| 55 | FD_SET(0, &read_set); | ||
| 56 | |||
| 57 | if (delay_secs) { | ||
| 58 | timeout.tv_sec = delay_secs; | ||
| 59 | timeout.tv_usec = 0; | ||
| 60 | } | ||
| 61 | |||
| 62 | err = select(1, &read_set, NULL, NULL, ptimeout); | ||
| 63 | |||
| 64 | if (err == 0) | ||
| 65 | return K_TIMER; | ||
| 66 | |||
| 67 | if (err == -1) { | ||
| 68 | if (errno == EINTR) | ||
| 69 | return K_RESIZE; | ||
| 70 | return K_ERROR; | ||
| 71 | } | ||
| 72 | |||
| 73 | key = SLang_getkey(); | ||
| 74 | if (key != K_ESC) | ||
| 75 | return key; | ||
| 76 | |||
| 77 | FD_ZERO(&read_set); | ||
| 78 | FD_SET(0, &read_set); | ||
| 79 | timeout.tv_sec = 0; | ||
| 80 | timeout.tv_usec = 20; | ||
| 81 | err = select(1, &read_set, NULL, NULL, &timeout); | ||
| 82 | if (err == 0) | ||
| 83 | return K_ESC; | ||
| 84 | |||
| 85 | SLang_ungetkey(key); | ||
| 86 | return SLkp_getkey(); | ||
| 87 | } | ||
| 88 | |||
| 89 | static void newt_suspend(void *d __used) | ||
| 90 | { | ||
| 91 | newtSuspend(); | ||
| 92 | raise(SIGTSTP); | ||
| 93 | newtResume(); | ||
| 94 | } | ||
| 95 | |||
| 96 | static void ui__signal(int sig) | ||
| 97 | { | ||
| 98 | ui__exit(false); | ||
| 99 | psignal(sig, "perf"); | ||
| 100 | exit(0); | ||
| 101 | } | ||
| 102 | |||
| 103 | int ui__init(bool fallback_to_pager __used) | ||
| 104 | { | ||
| 105 | int err; | ||
| 106 | |||
| 107 | newtInit(); | ||
| 108 | err = SLkp_init(); | ||
| 109 | if (err < 0) { | ||
| 110 | pr_err("TUI initialization failed.\n"); | ||
| 111 | goto out; | ||
| 112 | } | ||
| 113 | |||
| 114 | SLkp_define_keysym((char *)"^(kB)", SL_KEY_UNTAB); | ||
| 115 | |||
| 116 | newtSetSuspendCallback(newt_suspend, NULL); | ||
| 117 | ui_helpline__init(); | ||
| 118 | ui_browser__init(); | ||
| 119 | |||
| 120 | signal(SIGSEGV, ui__signal); | ||
| 121 | signal(SIGFPE, ui__signal); | ||
| 122 | signal(SIGINT, ui__signal); | ||
| 123 | signal(SIGQUIT, ui__signal); | ||
| 124 | signal(SIGTERM, ui__signal); | ||
| 125 | out: | ||
| 126 | return err; | ||
| 127 | } | ||
| 128 | |||
| 129 | void ui__exit(bool wait_for_ok) | ||
| 130 | { | ||
| 131 | if (wait_for_ok) | ||
| 132 | ui__question_window("Fatal Error", | ||
| 133 | ui_helpline__last_msg, | ||
| 134 | "Press any key...", 0); | ||
| 135 | |||
| 136 | SLtt_set_cursor_visibility(1); | ||
| 137 | SLsmg_refresh(); | ||
| 138 | SLsmg_reset_smg(); | ||
| 139 | SLang_reset_tty(); | ||
| 140 | } | ||
