static int scroll_buttons_callback (SsdWidget widget, const char *new_value) { if (!strcmp(widget->name, "scroll_up")) { scroll_page_up(); return 0; } if (!strcmp( widget->name, "scroll_down")) { scroll_page_down(); return 0; } return 1; }
/* Handle a key press. Assumes that a key has been pressed and is * ready to read (will block otherwise). * Return 1 if 'q' (quit). */ static int handle_key() { int c; c = getch(); if (c == 'q') ; /* nothing */ else if (c == 'g') options.debug = 1 - options.debug; else if (c == 'c') options.show_cmdline = 1 - options.show_cmdline; else if ((c == 'd') || (c == 's')) { mvprintw(2, 0, "Change delay from %.2f to: ", options.delay); echo(); nocbreak(); scanw("%f", &options.delay); if (options.delay < 0.01) options.delay = 1.0; tv.tv_sec = options.delay; tv.tv_usec = (options.delay - tv.tv_sec)*1000000.0; cbreak(); noecho(); } else if (c == 'H') { options.show_threads = 1 - options.show_threads; } else if (c == 'i') options.idle = 1 - options.idle; else if (c == 'K') { if (options.show_kernel) { options.show_kernel = 0; message = "Kernel mode Off"; } else { if ((options.euid == 0) || (options.paranoia_level < 2)) { options.show_kernel = 1; message = "Kernel mode On"; } else { message = "Kernel mode not available (not root and paranoia level too high)."; c = ' '; /* do not return the 'K' to the upper level, since it was ignored. */ } } } else if (c == 'k') { /* initialize string to 0s */ char str[10] = { 0 }; int kill_pid, kill_sig, kill_res; mvprintw(2, 0, "PID to kill: "); echo(); nocbreak(); getnstr(str, sizeof(str) - 1); if (!isdigit(str[0])) message = "Not valid"; else { kill_pid = atoi(str); mvprintw(2, 0, "Kill PID %d with signal [15]: ", kill_pid); getnstr(str, sizeof(str) - 1); kill_sig = atoi(str); if (kill_sig == 0) kill_sig = 15; kill_res = kill(kill_pid, kill_sig); if (kill_res == -1) { char tmp_message[100]; snprintf(tmp_message, sizeof(tmp_message), "Kill of PID '%d' with '%d' failed: %s", kill_pid, kill_sig, strerror(errno)); message = tmp_message; } } cbreak(); noecho(); } else if (c == 'p') { char str[100] = { 0 }; /* initialize string to 0s */ mvprintw(2, 0, "Only display process: "); echo(); nocbreak(); getnstr(str, sizeof(str)-1); /* keep final '\0' as string delimiter */ options.only_pid = atoi(str); if (options.only_name) { free(options.only_name); options.only_name = NULL; } if (!options.only_pid && strcmp(str, "")) { options.only_name = strdup(str); } cbreak(); noecho(); } else if (c == 'R') sorting_order = (enum sorting_order) (1 - (int)sorting_order); else if (c == 'S') options.sticky = 1 - options.sticky; else if (c == 'U') options.show_user = 1 - options.show_user; else if (c == 'u') { char str[100] = { 0 }; /* initialize string to 0s */ mvprintw(2, 0, "Which user (blank for all): "); echo(); nocbreak(); getnstr(str, sizeof(str) - 1); /* keep final '\0' as string delimiter */ cbreak(); noecho(); if (str[0] == '\0') /* blank */ options.watch_uid = -1; else if (isdigit(str[0])) options.watch_uid = atoi(str); else { struct passwd* passwd; passwd = getpwnam(str); if (passwd) options.watch_uid = passwd->pw_uid; else message = "User name does not exist."; } } else if (c == 'w') { char str[100] = { 0 }; /* initialize string to 0s */ mvprintw(2, 0, "Watch process: "); echo(); nocbreak(); getnstr(str, sizeof(str)-1); /* keep final '\0' as string delimiter */ options.watch_pid = atoi(str); if (options.watch_name) { free(options.watch_name); options.watch_name = NULL; } if (!options.watch_pid && strcmp(str, "")) { options.watch_name = strdup(str); } cbreak(); noecho(); } else if (c == 'h') options.help = 1 - options.help; else if (c == 'W') { if (export_screens(&options) < 0) message = ".tiptoprc not written: already exists in current directory?"; else message = ".tiptoprc written"; } else if (c == KEY_UP) scroll_up(); else if (c == KEY_PPAGE) scroll_page_up(); else if (c == KEY_DOWN) scroll_down(); else if (c == KEY_NPAGE) scroll_page_down(); else if (c == KEY_HOME) scroll_home(); else if (c == KEY_END) scroll_end(); return c; }