From e2b58f0ab81b2aafeb8c29a69abad7829fa21ab3 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 11 Apr 2016 13:00:30 +0200 Subject: Imported Upstream version 1.0.1 --- htop.c | 95 +++++++++++++++++++++++++++++++----------------------------------- 1 file changed, 44 insertions(+), 51 deletions(-) (limited to 'htop.c') diff --git a/htop.c b/htop.c index ff58d20..dd76071 100644 --- a/htop.c +++ b/htop.c @@ -5,16 +5,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include - #include "ProcessList.h" + #include "CRT.h" #include "Panel.h" #include "UsersTable.h" @@ -23,14 +15,25 @@ in the source distribution for its full text. #include "ScreenManager.h" #include "FunctionBar.h" #include "ListItem.h" +#include "String.h" +#include "ColumnsPanel.h" #include "CategoriesPanel.h" #include "SignalsPanel.h" #include "TraceScreen.h" #include "OpenFilesScreen.h" #include "AffinityPanel.h" -#include "config.h" -#include "debug.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include //#link m @@ -199,6 +202,7 @@ static Object* pickFromVector(Panel* panel, Panel* list, int x, int y, const cha if (!list->eventHandler) Panel_setEventHandler(list, Panel_selectByTyping); ScreenManager* scr = ScreenManager_new(0, y, 0, -1, HORIZONTAL, header, false); + scr->allowFocusChange = false; ScreenManager_add(scr, list, FunctionBar_new(keyLabels, fuKeys, fuEvents), x - 1); ScreenManager_add(scr, panel, NULL, -1); Panel* panelFocus; @@ -331,7 +335,6 @@ int main(int argc, char** argv) { exit(1); } - Panel* panel; int quit = 0; int refreshTimeout = 0; int resetRefreshTimeout = 5; @@ -384,10 +387,11 @@ int main(int argc, char** argv) { break; } - CRT_init(settings->delay, settings->colorScheme); + + Panel* panel = Panel_new(0, headerHeight, COLS, LINES - headerHeight - 2, PROCESS_CLASS, false, NULL); + ProcessList_setPanel(pl, panel); - panel = Panel_new(0, headerHeight, COLS, LINES - headerHeight - 2, PROCESS_CLASS, false, NULL); if (sortKey > 0) { pl->sortKey = sortKey; pl->treeView = false; @@ -436,15 +440,10 @@ int main(int argc, char** argv) { gettimeofday(&tv, NULL); newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000); recalculate = (newTime - oldTime > CRT_delay); + int following = follow ? ((Process*)Panel_getSelected(panel))->pid : -1; if (recalculate) oldTime = newTime; if (doRefresh) { - - int currPos = Panel_getSelectedIndex(panel); - pid_t currPid = 0; - int currScrollV = panel->scrollV; - if (follow) - currPid = ProcessList_get(pl, currPos)->pid; if (recalculate || doRecalculate) { ProcessList_scan(pl); doRecalculate = false; @@ -453,27 +452,7 @@ int main(int argc, char** argv) { ProcessList_sort(pl); refreshTimeout = 1; } - Panel_prune(panel); - int size = ProcessList_size(pl); - int idx = 0; - for (int i = 0; i < size; i++) { - bool hidden = false; - Process* p = ProcessList_get(pl, i); - - if ( (!p->show) - || (userOnly && (p->st_uid != userId)) - || (filtering && !(String_contains_i(p->comm, incFilter.buffer))) ) - hidden = true; - - if (!hidden) { - Panel_set(panel, idx, (Object*)p); - if ((!follow && idx == currPos) || (follow && p->pid == currPid)) { - Panel_setSelected(panel, idx); - panel->scrollV = currScrollV; - } - idx++; - } - } + ProcessList_rebuildPanel(pl, true, following, userOnly, userId, filtering, incFilter.buffer); } doRefresh = true; @@ -746,6 +725,19 @@ int main(int argc, char** argv) { if (!killPanel) { killPanel = (Panel*) SignalsPanel_new(0, 0, 0, 0); } + bool anyTagged = false; + pid_t selectedPid; + for (int i = 0; i < Panel_size(panel); i++) { + Process* p = (Process*) Panel_get(panel, i); + if (p->tag) { + anyTagged = true; + break; + } + } + if (!anyTagged) { + Process* p = (Process*) Panel_getSelected(panel); + selectedPid = p->pid; + } SignalsPanel_reset((SignalsPanel*) killPanel); const char* fuFunctions[] = {"Send ", "Cancel ", NULL}; ListItem* sgn = (ListItem*) pickFromVector(panel, killPanel, 15, headerHeight, fuFunctions, defaultBar, header); @@ -754,17 +746,18 @@ int main(int argc, char** argv) { Panel_setHeader(panel, "Sending..."); Panel_draw(panel, true); refresh(); - bool anyTagged = false; - for (int i = 0; i < Panel_size(panel); i++) { - Process* p = (Process*) Panel_get(panel, i); - if (p->tag) { - Process_sendSignal(p, sgn->key); - anyTagged = true; + if (anyTagged) { + for (int i = 0; i < Panel_size(panel); i++) { + Process* p = (Process*) Panel_get(panel, i); + if (p->tag) { + Process_sendSignal(p, sgn->key); + anyTagged = true; + } } - } - if (!anyTagged) { + } else { Process* p = (Process*) Panel_getSelected(panel); - Process_sendSignal(p, sgn->key); + if (p->pid == selectedPid) + Process_sendSignal(p, sgn->key); } napms(500); } @@ -780,6 +773,7 @@ int main(int argc, char** argv) { break; Affinity* affinity = Process_getAffinity((Process*) Panel_getSelected(panel)); + if (!affinity) break; Panel* affinityPanel = AffinityPanel_new(pl, affinity); Affinity_delete(affinity); @@ -921,6 +915,5 @@ int main(int argc, char** argv) { ((Object*)killPanel)->delete((Object*)killPanel); UsersTable_delete(ut); Settings_delete(settings); - debug_done(); return 0; } -- cgit v1.2.3