diff options
74 files changed, 713 insertions, 442 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..74d0ece8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build-ubuntu-latest: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build + run: | + sudo apt-get install libncursesw5-dev + ./autogen.sh + ./configure + make + +# build-macos-latest: +# runs-on: macos-latest +# steps: +# - uses: actions/checkout@v2 +# - name: make +# run: | +# ./autogen.sh +# ./configure +# make @@ -62,7 +62,7 @@ typedef struct State_ { }*/ -Object* Action_pickFromVector(State* st, Panel* list, int x) { +Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) { Panel* panel = st->panel; Header* header = st->header; Settings* settings = st->settings; @@ -75,8 +75,8 @@ Object* Action_pickFromVector(State* st, Panel* list, int x) { Panel* panelFocus; int ch; bool unfollow = false; - int pid = MainPanel_selectedPid((MainPanel*)panel); - if (header->pl->following == -1) { + int pid = followProcess ? MainPanel_selectedPid((MainPanel*)panel) : -1; + if (followProcess && header->pl->following == -1) { header->pl->following = pid; unfollow = true; } @@ -88,11 +88,16 @@ Object* Action_pickFromVector(State* st, Panel* list, int x) { Panel_move(panel, 0, y); Panel_resize(panel, COLS, LINES-y-1); if (panelFocus == list && ch == 13) { - Process* selected = (Process*)Panel_getSelected(panel); - if (selected && selected->pid == pid) + if (followProcess) { + Process* selected = (Process*)Panel_getSelected(panel); + if (selected && selected->pid == pid) + return Panel_getSelected(list); + else + beep(); + } else { return Panel_getSelected(list); - else - beep(); + } + } return NULL; } @@ -189,7 +194,7 @@ static Htop_Reaction sortBy(State* st) { Panel_setSelected(sortPanel, i); free(name); } - ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15); + ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15, false); if (field) { reaction |= Action_setSortKey(st->settings, field->key); } @@ -248,10 +253,21 @@ static Htop_Reaction actionIncFilter(State* st) { } static Htop_Reaction actionIncSearch(State* st) { + IncSet_reset(((MainPanel*)st->panel)->inc, INC_SEARCH); IncSet_activate(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel); return HTOP_REFRESH | HTOP_KEEP_FOLLOWING; } +static Htop_Reaction actionIncNext(State* st) { + IncSet_next(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel, (IncMode_GetPanelValue) MainPanel_getValue); + return HTOP_REFRESH | HTOP_KEEP_FOLLOWING; +} + +static Htop_Reaction actionIncPrev(State* st) { + IncSet_prev(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel, (IncMode_GetPanelValue) MainPanel_getValue); + return HTOP_REFRESH | HTOP_KEEP_FOLLOWING; +} + static Htop_Reaction actionHigherPriority(State* st) { bool changed = changePriority((MainPanel*)st->panel, -1); return changed ? HTOP_REFRESH : HTOP_OK; @@ -305,7 +321,7 @@ static Htop_Reaction actionSetAffinity(State* st) { Panel* affinityPanel = AffinityPanel_new(st->pl, affinity); Affinity_delete(affinity); - void* set = Action_pickFromVector(st, affinityPanel, 15); + void* set = Action_pickFromVector(st, affinityPanel, 15, true); if (set) { Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl); bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity }, NULL); @@ -319,7 +335,7 @@ static Htop_Reaction actionSetAffinity(State* st) { static Htop_Reaction actionKill(State* st) { Panel* signalsPanel = (Panel*) SignalsPanel_new(); - ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15); + ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15, true); if (sgn) { if (sgn->key != 0) { Panel_setHeader(st->panel, "Sending..."); @@ -340,7 +356,7 @@ static Htop_Reaction actionFilterByUser(State* st) { Vector_insertionSort(usersPanel->items); ListItem* allUsers = ListItem_new("All users", -1); Panel_insert(usersPanel, 0, (Object*) allUsers); - ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20); + ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20, false); if (picked) { if (picked == allUsers) { st->pl->userId = -1; @@ -559,6 +575,8 @@ void Action_setBindings(Htop_Action* keys) { keys['\\'] = actionIncFilter; keys[KEY_F(3)] = actionIncSearch; keys['/'] = actionIncSearch; + keys['n'] = actionIncNext; + keys['N'] = actionIncPrev; keys[']'] = actionHigherPriority; keys[KEY_F(7)] = actionHigherPriority; @@ -39,20 +39,20 @@ typedef struct State_ { } State; -Object* Action_pickFromVector(State* st, Panel* list, int x); +extern Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess); // ---------------------------------------- -bool Action_setUserOnly(const char* userName, uid_t* userId); +extern bool Action_setUserOnly(const char* userName, uid_t* userId); -Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey); +extern Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey); // ---------------------------------------- -Htop_Reaction Action_follow(State* st); +extern Htop_Reaction Action_follow(State* st); -void Action_setBindings(Htop_Action* keys); +extern void Action_setBindings(Htop_Action* keys); #endif @@ -1,6 +1,7 @@ /* htop - Affinity.c (C) 2004-2011 Hisham H. Muhammad +(C) 2020 Red Hat, Inc. All Rights Reserved. Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -79,7 +80,8 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) { return affinity; } -bool Affinity_set(Process* proc, Affinity* this) { +bool Affinity_set(Process* proc, Arg arg) { + Affinity *this = arg.v; hwloc_cpuset_t cpuset = hwloc_bitmap_alloc(); for (int i = 0; i < this->used; i++) { hwloc_bitmap_set(cpuset, this->cpus[i]); @@ -103,7 +105,8 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) { return affinity; } -bool Affinity_set(Process* proc, Affinity* this) { +bool Affinity_set(Process* proc, Arg arg) { + Affinity *this = arg.v; cpu_set_t cpuset; CPU_ZERO(&cpuset); for (int i = 0; i < this->used; i++) { @@ -5,6 +5,7 @@ /* htop - Affinity.h (C) 2004-2011 Hisham H. Muhammad +(C) 2020 Red Hat, Inc. All Rights Reserved. Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -29,23 +30,23 @@ typedef struct Affinity_ { } Affinity; -Affinity* Affinity_new(ProcessList* pl); +extern Affinity* Affinity_new(ProcessList* pl); -void Affinity_delete(Affinity* this); +extern void Affinity_delete(Affinity* this); -void Affinity_add(Affinity* this, int id); +extern void Affinity_add(Affinity* this, int id); #ifdef HAVE_LIBHWLOC -Affinity* Affinity_get(Process* proc, ProcessList* pl); +extern Affinity* Affinity_get(Process* proc, ProcessList* pl); -bool Affinity_set(Process* proc, Affinity* this); +extern bool Affinity_set(Process* proc, Arg arg); #elif HAVE_LINUX_AFFINITY -Affinity* Affinity_get(Process* proc, ProcessList* pl); +extern Affinity* Affinity_get(Process* proc, ProcessList* pl); -bool Affinity_set(Process* proc, Affinity* this); +extern bool Affinity_set(Process* proc, Arg arg); #endif diff --git a/AffinityPanel.h b/AffinityPanel.h index 2b6059b0..3a9c7807 100644 --- a/AffinityPanel.h +++ b/AffinityPanel.h @@ -16,8 +16,8 @@ in the source distribution for its full text. extern PanelClass AffinityPanel_class; -Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity); +extern Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity); -Affinity* AffinityPanel_getAffinity(Panel* this, ProcessList* pl); +extern Affinity* AffinityPanel_getAffinity(Panel* this, ProcessList* pl); #endif diff --git a/AvailableColumnsPanel.h b/AvailableColumnsPanel.h index 5a8371dd..2d6daf4b 100644 --- a/AvailableColumnsPanel.h +++ b/AvailableColumnsPanel.h @@ -19,6 +19,6 @@ typedef struct AvailableColumnsPanel_ { extern PanelClass AvailableColumnsPanel_class; -AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns); +extern AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns); #endif diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index ddb55367..40534bb7 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -127,7 +127,7 @@ AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* heade Panel_add(super, (Object*) ListItem_new("CPU average", 0)); for (int i = 1; i <= cpus; i++) { char buffer[50]; - xSnprintf(buffer, 50, "%s %d", type->uiName, i); + xSnprintf(buffer, 50, "%s %d", type->uiName, Settings_cpuId(this->settings, i - 1)); Panel_add(super, (Object*) ListItem_new(buffer, i)); } } else { diff --git a/AvailableMetersPanel.h b/AvailableMetersPanel.h index e9b949b0..00e0f596 100644 --- a/AvailableMetersPanel.h +++ b/AvailableMetersPanel.h @@ -27,6 +27,6 @@ typedef struct AvailableMetersPanel_ { extern PanelClass AvailableMetersPanel_class; -AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl); +extern AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl); #endif @@ -131,9 +131,9 @@ typedef enum ColorElements_ { LAST_COLORELEMENT } ColorElements; -void CRT_fatalError(const char* note) __attribute__ ((noreturn)); +extern void CRT_fatalError(const char* note) __attribute__ ((noreturn)); -void CRT_handleSIGSEGV(int sgn); +extern void CRT_handleSIGSEGV(int sgn); #define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A')) @@ -119,9 +119,9 @@ typedef enum ColorElements_ { LAST_COLORELEMENT } ColorElements; -void CRT_fatalError(const char* note) __attribute__ ((noreturn)); +extern void CRT_fatalError(const char* note) __attribute__ ((noreturn)); -void CRT_handleSIGSEGV(int sgn); +extern void CRT_handleSIGSEGV(int sgn); #define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A')) @@ -140,7 +140,7 @@ extern const char **CRT_treeStr; extern int CRT_delay; -int* CRT_colors; +extern int* CRT_colors; extern int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT]; @@ -150,21 +150,21 @@ extern int CRT_scrollHAmount; extern int CRT_scrollWheelVAmount; -char* CRT_termType; +extern char* CRT_termType; // TODO move color scheme to Settings, perhaps? extern int CRT_colorScheme; -void *backtraceArray[128]; +extern void *backtraceArray[128]; #if HAVE_SETUID_ENABLED #define DIE(msg) do { CRT_done(); fprintf(stderr, msg); exit(1); } while(0) -void CRT_dropPrivileges(); +extern void CRT_dropPrivileges(); -void CRT_restorePrivileges(); +extern void CRT_restorePrivileges(); #else @@ -179,18 +179,18 @@ void CRT_restorePrivileges(); // TODO: pass an instance of Settings instead. -void CRT_init(int delay, int colorScheme); +extern void CRT_init(int delay, int colorScheme); -void CRT_done(); +extern void CRT_done(); -void CRT_fatalError(const char* note); +extern void CRT_fatalError(const char* note); -int CRT_readKey(); +extern int CRT_readKey(); -void CRT_disableDelay(); +extern void CRT_disableDelay(); -void CRT_enableDelay(); +extern void CRT_enableDelay(); -void CRT_setColors(int colorScheme); +extern void CRT_setColors(int colorScheme); #endif diff --git a/CategoriesPanel.h b/CategoriesPanel.h index ccef0fae..44c6842a 100644 --- a/CategoriesPanel.h +++ b/CategoriesPanel.h @@ -24,10 +24,10 @@ typedef struct CategoriesPanel_ { } CategoriesPanel; -void CategoriesPanel_makeMetersPage(CategoriesPanel* this); +extern void CategoriesPanel_makeMetersPage(CategoriesPanel* this); extern PanelClass CategoriesPanel_class; -CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl); +extern CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl); #endif diff --git a/CheckItem.h b/CheckItem.h index 5847d4b2..dbd1a039 100644 --- a/CheckItem.h +++ b/CheckItem.h @@ -21,12 +21,12 @@ typedef struct CheckItem_ { extern ObjectClass CheckItem_class; -CheckItem* CheckItem_newByRef(char* text, bool* ref); +extern CheckItem* CheckItem_newByRef(char* text, bool* ref); -CheckItem* CheckItem_newByVal(char* text, bool value); +extern CheckItem* CheckItem_newByVal(char* text, bool value); -void CheckItem_set(CheckItem* this, bool value); +extern void CheckItem_set(CheckItem* this, bool value); -bool CheckItem_get(CheckItem* this); +extern bool CheckItem_get(CheckItem* this); #endif diff --git a/ColorsPanel.h b/ColorsPanel.h index ee3111e0..82b782b8 100644 --- a/ColorsPanel.h +++ b/ColorsPanel.h @@ -29,6 +29,6 @@ typedef struct ColorsPanel_ { extern PanelClass ColorsPanel_class; -ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr); +extern ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr); #endif diff --git a/ColumnsPanel.h b/ColumnsPanel.h index 0da674a8..46d20bbb 100644 --- a/ColumnsPanel.h +++ b/ColumnsPanel.h @@ -22,11 +22,11 @@ typedef struct ColumnsPanel_ { extern PanelClass ColumnsPanel_class; -ColumnsPanel* ColumnsPanel_new(Settings* settings); +extern ColumnsPanel* ColumnsPanel_new(Settings* settings); -int ColumnsPanel_fieldNameToIndex(const char* name); +extern int ColumnsPanel_fieldNameToIndex(const char* name); -void ColumnsPanel_update(Panel* super); +extern void ColumnsPanel_update(Panel* super); #endif diff --git a/DisplayOptionsPanel.h b/DisplayOptionsPanel.h index 2a7509ae..d9de |