Commit 9faf4938 authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Refactored key handlers.

Made the logic more modular, hopefully easier to follow,
and removed repeated code.
Plus, some optimization in RichString code.
parent 300af4b8
......@@ -1047,16 +1047,12 @@ void ProcessList_expandTree(ProcessList* this) {
}
}
void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool userOnly, uid_t userId, const char* incFilter) {
void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, const char* incFilter) {
if (!flags) {
following = this->following;
userOnly = this->userOnly;
userId = this->userId;
incFilter = this->incFilter;
} else {
this->following = following;
this->userOnly = userOnly;
this->userId = userId;
this->incFilter = incFilter;
}
......@@ -1072,7 +1068,7 @@ void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool
Process* p = ProcessList_get(this, i);
if ( (!p->show)
|| (userOnly && (p->st_uid != userId))
|| (this->userOnly && (p->st_uid != this->userId))
|| (incFilter && !(String_contains_i(p->comm, incFilter)))
|| (this->pidWhiteList && !Hashtable_get(this->pidWhiteList, p->pid)) )
hidden = true;
......
......@@ -183,6 +183,6 @@ ProcessField ProcessList_keyAt(ProcessList* this, int at);
void ProcessList_expandTree(ProcessList* this);
void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool userOnly, uid_t userId, const char* incFilter);
void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, const char* incFilter);
#endif
......@@ -10,7 +10,7 @@ in the source distribution for its full text.
#include <stdlib.h>
#include <string.h>
#define RICHSTRING_MAXLEN 300
#define RICHSTRING_MAXLEN 350
/*{
#include "config.h"
......@@ -52,8 +52,8 @@ in the source distribution for its full text.
typedef struct RichString_ {
int chlen;
CharType chstr[RICHSTRING_MAXLEN+1];
CharType* chptr;
CharType chstr[RICHSTRING_MAXLEN+1];
} RichString;
}*/
......@@ -64,7 +64,7 @@ typedef struct RichString_ {
#define charBytes(n) (sizeof(CharType) * (n))
static inline void RichString_setLen(RichString* this, int len) {
static void RichString_extendLen(RichString* this, int len) {
if (this->chlen <= RICHSTRING_MAXLEN) {
if (len > RICHSTRING_MAXLEN) {
this->chptr = malloc(charBytes(len+1));
......@@ -83,6 +83,8 @@ static inline void RichString_setLen(RichString* this, int len) {
this->chlen = len;
}
#define RichString_setLen(this, len) do{ if(len < RICHSTRING_MAXLEN) { RichString_setChar(this,len,0); this->chlen=len; } else RichString_extendLen(this,len); }while(0)
#ifdef HAVE_LIBNCURSESW
static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) {
......@@ -92,10 +94,11 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char*
return;
int newLen = from + len;
RichString_setLen(this, newLen);
memset(&this->chptr[from], 0, sizeof(CharType) * (newLen - from));
for (int i = from, j = 0; i < newLen; i++, j++) {
this->chptr[i].chars[0] = data[j];
this->chptr[i].attr = attrs;
CharType* c = &(this->chptr[i]);
c->attr = attrs;
c->chars[0] = data[j];
c->chars[1] = 0;
}
this->chptr[newLen].chars[0] = 0;
}
......@@ -171,4 +174,4 @@ void RichString_appendn(RichString* this, int attrs, const char* data, int len)
void RichString_write(RichString* this, int attrs, const char* data) {
RichString_writeFrom(this, attrs, data, 0, strlen(data));
}
}
\ No newline at end of file
......@@ -9,7 +9,7 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#define RICHSTRING_MAXLEN 300
#define RICHSTRING_MAXLEN 350
#include "config.h"
#include <ctype.h>
......@@ -50,8 +50,8 @@ in the source distribution for its full text.
typedef struct RichString_ {
int chlen;
CharType chstr[RICHSTRING_MAXLEN+1];
CharType* chptr;
CharType chstr[RICHSTRING_MAXLEN+1];
} RichString;
......@@ -61,6 +61,8 @@ typedef struct RichString_ {
#define charBytes(n) (sizeof(CharType) * (n))
#define RichString_setLen(this, len) do{ if(len < RICHSTRING_MAXLEN) { RichString_setChar(this,len,0); this->chlen=len; } else RichString_extendLen(this,len); }while(0)
#ifdef HAVE_LIBNCURSESW
extern void RichString_setAttrn(RichString* this, int attrs, int start, int finish);
......
......@@ -144,7 +144,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
this->lastScan = now;
}
Header_draw(this->header);
ProcessList_rebuildPanel(this->header->pl, false, false, false, false, NULL);
ProcessList_rebuildPanel(this->header->pl, false, false, NULL);
}
for (int i = 0; i < panels; i++) {
Panel* panel = (Panel*) Vector_get(this->panels, i);
......
This diff is collapsed.
......@@ -11,11 +11,36 @@ in the source distribution for its full text.
//#link m
#define COPYRIGHT "(C) 2004-2012 Hisham Muhammad"
#define COPYRIGHT "(C) 2004-2014 Hisham Muhammad"
typedef enum {
HTOP_OK = 0x00,
HTOP_REFRESH = 0x01,
HTOP_RECALCULATE = 0x03, // implies HTOP_REFRESH
HTOP_SAVE_SETTINGS = 0x04,
HTOP_KEEP_FOLLOWING = 0x08,
HTOP_QUIT = 0x10,
HTOP_REDRAW_BAR = 0x20,
HTOP_UPDATE_PANELHDR = 0x41, // implies HTOP_REFRESH
} Htop_Reaction;
typedef Htop_Reaction (*Htop_Action)();
typedef struct State_ {
IncSet* inc;
Settings* settings;
UsersTable* ut;
} State;
typedef bool(*ForeachProcessFn)(Process*, size_t);
void sortBy(Panel* panel, ProcessList* pl, Settings* settings, int headerHeight, FunctionBar* defaultBar, Header* header);
// ----------------------------------------
void setBindings(Htop_Action* keys);
// ----------------------------------------
int main(int argc, char** argv);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment