BUGFIX: behavior of 'F' (follow) key was broken, also affecting the

persistence of mouse selections. Closes #3165065.
This commit is contained in:
Hisham Muhammad 2012-02-02 23:45:40 +00:00
parent 58676d7001
commit 1a604a05a5
4 changed files with 12 additions and 11 deletions

View File

@ -7,6 +7,8 @@ What's new in version 1.0.1
* Safer behavior on the kill screen, to make it harder to kill the wrong process. * Safer behavior on the kill screen, to make it harder to kill the wrong process.
* Fix for building in FreeBSD 8.2 * Fix for building in FreeBSD 8.2
(thanks to Trond Endrestol) (thanks to Trond Endrestol)
* BUGFIX: behavior of 'F' (follow) key was broken, also affecting the
persistence of mouse selections.
* BUGFIX: keep main panel up-to-date when running the screen manager, * BUGFIX: keep main panel up-to-date when running the screen manager,
to fix crash when processes die while on the F9/Kill screen. to fix crash when processes die while on the F9/Kill screen.

View File

@ -109,7 +109,7 @@ typedef struct ProcessList_ {
UsersTable* usersTable; UsersTable* usersTable;
Panel* panel; Panel* panel;
bool follow; int following;
bool userOnly; bool userOnly;
uid_t userId; uid_t userId;
bool filtering; bool filtering;
@ -899,15 +899,15 @@ void ProcessList_expandTree(ProcessList* this) {
} }
} }
void ProcessList_rebuildPanel(ProcessList* this, bool flags, bool follow, bool userOnly, uid_t userId, bool filtering, const char* incFilter) { void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool userOnly, uid_t userId, bool filtering, const char* incFilter) {
if (!flags) { if (!flags) {
follow = this->follow; following = this->following;
userOnly = this->userOnly; userOnly = this->userOnly;
userId = this->userId; userId = this->userId;
filtering = this->filtering; filtering = this->filtering;
incFilter = this->incFilter; incFilter = this->incFilter;
} else { } else {
this->follow = follow; this->following = following;
this->userOnly = userOnly; this->userOnly = userOnly;
this->userId = userId; this->userId = userId;
this->filtering = filtering; this->filtering = filtering;
@ -915,10 +915,8 @@ void ProcessList_rebuildPanel(ProcessList* this, bool flags, bool follow, bool u
} }
int currPos = Panel_getSelectedIndex(this->panel); int currPos = Panel_getSelectedIndex(this->panel);
pid_t currPid = 0; pid_t currPid = following ? following : 0;
int currScrollV = this->panel->scrollV; int currScrollV = this->panel->scrollV;
if (follow)
currPid = ProcessList_get(this, currPos)->pid;
Panel_prune(this->panel); Panel_prune(this->panel);
int size = ProcessList_size(this); int size = ProcessList_size(this);
@ -934,7 +932,7 @@ void ProcessList_rebuildPanel(ProcessList* this, bool flags, bool follow, bool u
if (!hidden) { if (!hidden) {
Panel_set(this->panel, idx, (Object*)p); Panel_set(this->panel, idx, (Object*)p);
if ((!follow && idx == currPos) || (follow && p->pid == currPid)) { if ((following == -1 && idx == currPos) || (following != -1 && p->pid == currPid)) {
Panel_setSelected(this->panel, idx); Panel_setSelected(this->panel, idx);
this->panel->scrollV = currScrollV; this->panel->scrollV = currScrollV;
} }

View File

@ -92,7 +92,7 @@ typedef struct ProcessList_ {
UsersTable* usersTable; UsersTable* usersTable;
Panel* panel; Panel* panel;
bool follow; int following;
bool userOnly; bool userOnly;
uid_t userId; uid_t userId;
bool filtering; bool filtering;
@ -183,6 +183,6 @@ ProcessField ProcessList_keyAt(ProcessList* this, int at);
void ProcessList_expandTree(ProcessList* this); void ProcessList_expandTree(ProcessList* this);
void ProcessList_rebuildPanel(ProcessList* this, bool flags, bool follow, bool userOnly, uid_t userId, bool filtering, const char* incFilter); void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool userOnly, uid_t userId, bool filtering, const char* incFilter);
#endif #endif

3
htop.c
View File

@ -440,6 +440,7 @@ int main(int argc, char** argv) {
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000); newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000);
recalculate = (newTime - oldTime > CRT_delay); recalculate = (newTime - oldTime > CRT_delay);
int following = follow ? ((Process*)Panel_getSelected(panel))->pid : -1;
if (recalculate) if (recalculate)
oldTime = newTime; oldTime = newTime;
if (doRefresh) { if (doRefresh) {
@ -451,7 +452,7 @@ int main(int argc, char** argv) {
ProcessList_sort(pl); ProcessList_sort(pl);
refreshTimeout = 1; refreshTimeout = 1;
} }
ProcessList_rebuildPanel(pl, true, follow, userOnly, userId, filtering, incFilter.buffer); ProcessList_rebuildPanel(pl, true, following, userOnly, userId, filtering, incFilter.buffer);
} }
doRefresh = true; doRefresh = true;