Restore highlighted header of current sorted process column

This commit is contained in:
Christian Göttsche 2020-12-22 17:12:38 +01:00 committed by cgzones
parent 0672be7db1
commit 86d2931255
5 changed files with 23 additions and 19 deletions

View File

@ -102,7 +102,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
MainPanel_updateTreeFunctions(this, this->state->settings->treeView); MainPanel_updateTreeFunctions(this, this->state->settings->treeView);
} }
if (reaction & HTOP_UPDATE_PANELHDR) { if (reaction & HTOP_UPDATE_PANELHDR) {
ProcessList_printHeader(this->state->pl, Panel_getHeader(super)); result |= REDRAW;
} }
if (reaction & HTOP_REFRESH) { if (reaction & HTOP_REFRESH) {
result |= REFRESH; result |= REFRESH;
@ -168,13 +168,19 @@ static void MainPanel_drawFunctionBar(Panel* super) {
} }
} }
static void MainPanel_printHeader(Panel* super) {
MainPanel* this = (MainPanel*) super;
ProcessList_printHeader(this->state->pl, &super->header);
}
const PanelClass MainPanel_class = { const PanelClass MainPanel_class = {
.super = { .super = {
.extends = Class(Panel), .extends = Class(Panel),
.delete = MainPanel_delete .delete = MainPanel_delete
}, },
.eventHandler = MainPanel_eventHandler, .eventHandler = MainPanel_eventHandler,
.drawFunctionBar = MainPanel_drawFunctionBar .drawFunctionBar = MainPanel_drawFunctionBar,
.printHeader = MainPanel_printHeader
}; };
MainPanel* MainPanel_new() { MainPanel* MainPanel_new() {

22
Panel.c
View File

@ -76,13 +76,6 @@ void Panel_setSelectionColor(Panel* this, ColorElements colorId) {
this->selectionColorId = colorId; this->selectionColorId = colorId;
} }
RichString* Panel_getHeader(Panel* this) {
assert (this != NULL);
this->needsRedraw = true;
return &(this->header);
}
inline void Panel_setHeader(Panel* this, const char* header) { inline void Panel_setHeader(Panel* this, const char* header) {
RichString_writeWide(&(this->header), CRT_colors[PANEL_HEADER_FOCUS], header); RichString_writeWide(&(this->header), CRT_colors[PANEL_HEADER_FOCUS], header);
this->needsRedraw = true; this->needsRedraw = true;
@ -228,15 +221,20 @@ void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelect
int x = this->x; int x = this->x;
int h = this->h; int h = this->h;
int headerLen = RichString_sizeVal(this->header); const int header_attr = focus
if (headerLen > 0) {
int attr = focus
? CRT_colors[PANEL_HEADER_FOCUS] ? CRT_colors[PANEL_HEADER_FOCUS]
: CRT_colors[PANEL_HEADER_UNFOCUS]; : CRT_colors[PANEL_HEADER_UNFOCUS];
attrset(attr); if (force_redraw) {
if (Panel_printHeaderFn(this))
Panel_printHeader(this);
else
RichString_setAttr(&this->header, header_attr);
}
int headerLen = RichString_sizeVal(this->header);
if (headerLen > 0) {
attrset(header_attr);
mvhline(y, x, ' ', this->w); mvhline(y, x, ' ', this->w);
if (scrollH < headerLen) { if (scrollH < headerLen) {
RichString_setAttr(&this->header, attr);
RichString_printoffnVal(this->header, y, x, scrollH, RichString_printoffnVal(this->header, y, x, scrollH,
MINIMUM(headerLen - scrollH, this->w)); MINIMUM(headerLen - scrollH, this->w));
} }

View File

@ -37,11 +37,13 @@ typedef enum HandlerResult_ {
typedef HandlerResult (*Panel_EventHandler)(Panel*, int); typedef HandlerResult (*Panel_EventHandler)(Panel*, int);
typedef void (*Panel_DrawFunctionBar)(Panel*); typedef void (*Panel_DrawFunctionBar)(Panel*);
typedef void (*Panel_PrintHeader)(Panel*);
typedef struct PanelClass_ { typedef struct PanelClass_ {
const ObjectClass super; const ObjectClass super;
const Panel_EventHandler eventHandler; const Panel_EventHandler eventHandler;
const Panel_DrawFunctionBar drawFunctionBar; const Panel_DrawFunctionBar drawFunctionBar;
const Panel_PrintHeader printHeader;
} PanelClass; } PanelClass;
#define As_Panel(this_) ((const PanelClass*)((this_)->super.klass)) #define As_Panel(this_) ((const PanelClass*)((this_)->super.klass))
@ -49,6 +51,8 @@ typedef struct PanelClass_ {
#define Panel_eventHandler(this_, ev_) (assert(As_Panel(this_)->eventHandler), As_Panel(this_)->eventHandler((Panel*)(this_), ev_)) #define Panel_eventHandler(this_, ev_) (assert(As_Panel(this_)->eventHandler), As_Panel(this_)->eventHandler((Panel*)(this_), ev_))
#define Panel_drawFunctionBarFn(this_) As_Panel(this_)->drawFunctionBar #define Panel_drawFunctionBarFn(this_) As_Panel(this_)->drawFunctionBar
#define Panel_drawFunctionBar(this_) (assert(As_Panel(this_)->drawFunctionBar), As_Panel(this_)->drawFunctionBar((Panel*)(this_))) #define Panel_drawFunctionBar(this_) (assert(As_Panel(this_)->drawFunctionBar), As_Panel(this_)->drawFunctionBar((Panel*)(this_)))
#define Panel_printHeaderFn(this_) As_Panel(this_)->printHeader
#define Panel_printHeader(this_) (assert(As_Panel(this_)->printHeader), As_Panel(this_)->printHeader((Panel*)(this_)))
struct Panel_ { struct Panel_ {
Object super; Object super;
@ -84,8 +88,6 @@ void Panel_done(Panel* this);
void Panel_setSelectionColor(Panel* this, ColorElements colorId); void Panel_setSelectionColor(Panel* this, ColorElements colorId);
RichString* Panel_getHeader(Panel* this);
void Panel_setHeader(Panel* this, const char* header); void Panel_setHeader(Panel* this, const char* header);
void Panel_move(Panel* this, int x, int y); void Panel_move(Panel* this, int x, int y);

View File

@ -141,7 +141,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
bool timedOut = true; bool timedOut = true;
bool redraw = true; bool redraw = true;
bool force_redraw = false; bool force_redraw = true;
bool rescan = false; bool rescan = false;
int sortTimeout = 0; int sortTimeout = 0;
int resetSortTimeout = 5; int resetSortTimeout = 5;

2
htop.c
View File

@ -313,8 +313,6 @@ int main(int argc, char** argv) {
MainPanel_updateTreeFunctions(panel, settings->treeView); MainPanel_updateTreeFunctions(panel, settings->treeView);
ProcessList_printHeader(pl, Panel_getHeader((Panel*)panel));
State state = { State state = {
.settings = settings, .settings = settings,
.ut = ut, .ut = ut,