Merge branch 'resize_bar' of https://github.com/cgzones/htop into cgzones-resize_bar

This commit is contained in:
Nathan Scott 2020-12-22 15:25:08 +11:00
commit 737cd6167a
15 changed files with 97 additions and 93 deletions

View File

@ -341,7 +341,7 @@ static Htop_Reaction actionKill(State* st) {
if (sgn) { if (sgn) {
if (sgn->key != 0) { if (sgn->key != 0) {
Panel_setHeader(st->panel, "Sending..."); Panel_setHeader(st->panel, "Sending...");
Panel_draw(st->panel, true, true); Panel_draw(st->panel, false, true, true);
refresh(); refresh();
MainPanel_foreachProcess((MainPanel*)st->panel, Process_sendSignal, (Arg) { .i = sgn->key }, NULL); MainPanel_foreachProcess((MainPanel*)st->panel, Process_sendSignal, (Arg) { .i = sgn->key }, NULL);
napms(500); napms(500);
@ -372,7 +372,7 @@ static Htop_Reaction actionFilterByUser(State* st) {
Htop_Reaction Action_follow(State* st) { Htop_Reaction Action_follow(State* st) {
st->pl->following = MainPanel_selectedPid((MainPanel*)st->panel); st->pl->following = MainPanel_selectedPid((MainPanel*)st->panel);
Panel_setSelectionColor(st->panel, CRT_colors[PANEL_SELECTION_FOLLOW]); Panel_setSelectionColor(st->panel, PANEL_SELECTION_FOLLOW);
return HTOP_KEEP_FOLLOWING; return HTOP_KEEP_FOLLOWING;
} }

View File

@ -173,7 +173,6 @@ static void AffinityPanel_update(AffinityPanel* this, bool keepSelected) {
Panel* super = (Panel*) this; Panel* super = (Panel*) this;
FunctionBar_setLabel(super->currentBar, KEY_F(3), this->topoView ? "Collapse/Expand" : ""); FunctionBar_setLabel(super->currentBar, KEY_F(3), this->topoView ? "Collapse/Expand" : "");
FunctionBar_draw(super->currentBar);
int oldSelected = Panel_getSelectedIndex(super); int oldSelected = Panel_getSelectedIndex(super);
Panel_prune(super); Panel_prune(super);

View File

@ -35,7 +35,6 @@ static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, c
Panel_add(panel, (Object*) Meter_toListItem(meter, false)); Panel_add(panel, (Object*) Meter_toListItem(meter, false));
Panel_setSelected(panel, Panel_size(panel) - 1); Panel_setSelected(panel, Panel_size(panel) - 1);
MetersPanel_setMoving((MetersPanel*)panel, true); MetersPanel_setMoving((MetersPanel*)panel, true);
FunctionBar_draw(panel->currentBar);
} }
static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) { static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {

View File

@ -60,26 +60,21 @@ static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) {
case KEY_MOUSE: case KEY_MOUSE:
case KEY_RECLICK: case KEY_RECLICK:
case ' ': case ' ':
assert(mark >= 0);
assert(mark < LAST_COLORSCHEME);
for (int i = 0; ColorSchemeNames[i] != NULL; i++) for (int i = 0; ColorSchemeNames[i] != NULL; i++)
CheckItem_set((CheckItem*)Panel_get(super, i), false); CheckItem_set((CheckItem*)Panel_get(super, i), false);
CheckItem_set((CheckItem*)Panel_get(super, mark), true); CheckItem_set((CheckItem*)Panel_get(super, mark), true);
this->settings->colorScheme = mark; this->settings->colorScheme = mark;
result = HANDLED;
}
if (result == HANDLED) {
this->settings->changed = true; this->settings->changed = true;
const Header* header = this->scr->header;
CRT_setColors(mark); CRT_setColors(mark);
clear(); clear();
Panel* menu = (Panel*) Vector_get(this->scr->panels, 0);
Header_draw(header); result = HANDLED | REDRAW;
FunctionBar_draw(super->currentBar);
RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]);
RichString_setAttr(&(menu->header), CRT_colors[PANEL_HEADER_UNFOCUS]);
ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
} }
return result; return result;
} }
@ -100,6 +95,8 @@ ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) {
this->settings = settings; this->settings = settings;
this->scr = scr; this->scr = scr;
assert(ARRAYSIZE(ColorSchemeNames) == LAST_COLORSCHEME + 1);
Panel_setHeader(super, "Colors"); Panel_setHeader(super, "Colors");
for (int i = 0; ColorSchemeNames[i] != NULL; i++) { for (int i = 0; ColorSchemeNames[i] != NULL; i++) {
Panel_add(super, (Object*) CheckItem_newByVal(ColorSchemeNames[i], false)); Panel_add(super, (Object*) CheckItem_newByVal(ColorSchemeNames[i], false));

View File

@ -44,7 +44,7 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
{ {
if (selected < size - 1) { if (selected < size - 1) {
this->moving = !(this->moving); this->moving = !(this->moving);
Panel_setSelectionColor(super, this->moving ? CRT_colors[PANEL_SELECTION_FOLLOW] : CRT_colors[PANEL_SELECTION_FOCUS]); Panel_setSelectionColor(super, this->moving ? PANEL_SELECTION_FOLLOW : PANEL_SELECTION_FOCUS);
ListItem* selectedItem = (ListItem*) Panel_getSelected(super); ListItem* selectedItem = (ListItem*) Panel_getSelected(super);
if (selectedItem) if (selectedItem)
selectedItem->moving = this->moving; selectedItem->moving = this->moving;

View File

@ -17,9 +17,10 @@ static void CommandScreen_scan(InfoScreen* this) {
Panel_prune(panel); Panel_prune(panel);
const char* p = Process_getCommand(this->process); const char* p = Process_getCommand(this->process);
char* line = xMalloc(COLS + 1); char line[COLS + 1];
int line_offset = 0, last_spc = -1, len; int line_offset = 0, last_spc = -1, len;
for (; *p != '\0'; p++, line_offset++) { for (; *p != '\0'; p++, line_offset++) {
assert(line_offset >= 0 && (size_t)line_offset < sizeof(line));
line[line_offset] = *p; line[line_offset] = *p;
if (*p == ' ') { if (*p == ' ') {
last_spc = line_offset; last_spc = line_offset;
@ -41,7 +42,6 @@ static void CommandScreen_scan(InfoScreen* this) {
InfoScreen_addLine(this, line); InfoScreen_addLine(this, line);
} }
free(line);
Panel_setSelected(panel, idx); Panel_setSelected(panel, idx);
} }

View File

@ -112,10 +112,11 @@ void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr
attrset(attr); attrset(attr);
} }
mvaddstr(LINES - 1, x, buffer); mvaddstr(LINES - 1, x, buffer);
attrset(CRT_colors[RESET_COLOR]);
x += strlen(buffer); x += strlen(buffer);
} }
attrset(CRT_colors[RESET_COLOR]);
if (setCursor) { if (setCursor) {
CRT_cursorX = x; CRT_cursorX = x;
curs_set(1); curs_set(1);
@ -132,10 +133,10 @@ void FunctionBar_append(const char* buffer, int attr) {
} else { } else {
attrset(attr); attrset(attr);
} }
mvaddstr(LINES - 1, currentLen, buffer); mvaddstr(LINES - 1, currentLen + 1, buffer);
attrset(CRT_colors[RESET_COLOR]); attrset(CRT_colors[RESET_COLOR]);
currentLen += strlen(buffer); currentLen += strlen(buffer) + 1;
} }
int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos) { int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos) {

View File

@ -54,12 +54,13 @@ static inline void IncMode_done(IncMode* mode) {
} }
IncSet* IncSet_new(FunctionBar* bar) { IncSet* IncSet_new(FunctionBar* bar) {
IncSet* this = xCalloc(1, sizeof(IncSet)); IncSet* this = xMalloc(sizeof(IncSet));
IncMode_initSearch(&(this->modes[INC_SEARCH])); IncMode_initSearch(&(this->modes[INC_SEARCH]));
IncMode_initFilter(&(this->modes[INC_FILTER])); IncMode_initFilter(&(this->modes[INC_FILTER]));
this->active = NULL; this->active = NULL;
this->filtering = false;
this->defaultBar = bar; this->defaultBar = bar;
this->filtering = false;
this->found = false;
return this; return this;
} }
@ -99,20 +100,14 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) {
static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) { static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) {
int size = Panel_size(panel); int size = Panel_size(panel);
bool found = false;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
if (String_contains_i(getPanelValue(panel, i), mode->buffer)) { if (String_contains_i(getPanelValue(panel, i), mode->buffer)) {
Panel_setSelected(panel, i); Panel_setSelected(panel, i);
found = true; return true;
break;
} }
} }
FunctionBar_drawExtra(mode->bar, return false;
mode->buffer,
found ? -1 : CRT_colors[FAILED_SEARCH],
true);
return found;
} }
static bool IncMode_find(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue, int step) { static bool IncMode_find(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue, int step) {
@ -202,7 +197,6 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
} }
this->active = NULL; this->active = NULL;
Panel_setDefaultBar(panel); Panel_setDefaultBar(panel);
FunctionBar_draw(this->defaultBar);
doSearch = false; doSearch = false;
} }
if (doSearch) { if (doSearch) {
@ -221,13 +215,12 @@ const char* IncSet_getListItemValue(Panel* panel, int i) {
void IncSet_activate(IncSet* this, IncType type, Panel* panel) { void IncSet_activate(IncSet* this, IncType type, Panel* panel) {
this->active = &(this->modes[type]); this->active = &(this->modes[type]);
FunctionBar_drawExtra(this->active->bar, this->active->buffer, -1, true);
panel->currentBar = this->active->bar; panel->currentBar = this->active->bar;
} }
void IncSet_drawBar(const IncSet* this) { void IncSet_drawBar(const IncSet* this) {
if (this->active) { if (this->active) {
FunctionBar_drawExtra(this->active->bar, this->active->buffer, -1, true); FunctionBar_drawExtra(this->active->bar, this->active->buffer, (this->active->isFilter || this->found) ? -1 : CRT_colors[FAILED_SEARCH], true);
} else { } else {
FunctionBar_draw(this->defaultBar); FunctionBar_draw(this->defaultBar);
} }

View File

@ -44,8 +44,10 @@ void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
char* title = xMalloc(COLS + 1); char title[COLS + 1];
int len = vsnprintf(title, COLS + 1, fmt, ap); int len = vsnprintf(title, sizeof(title), fmt, ap);
va_end(ap);
if (len > COLS) { if (len > COLS) {
memset(&title[COLS - 3], '.', 3); memset(&title[COLS - 3], '.', 3);
} }
@ -54,11 +56,9 @@ void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...) {
mvhline(0, 0, ' ', COLS); mvhline(0, 0, ' ', COLS);
mvwprintw(stdscr, 0, 0, title); mvwprintw(stdscr, 0, 0, title);
attrset(CRT_colors[DEFAULT_COLOR]); attrset(CRT_colors[DEFAULT_COLOR]);
this->display->needsRedraw = true; Panel_draw(this->display, true, true, true);
Panel_draw(this->display, true, true);
IncSet_drawBar(this->inc); IncSet_drawBar(this->inc);
free(title);
va_end(ap);
} }
void InfoScreen_addLine(InfoScreen* this, const char* line) { void InfoScreen_addLine(InfoScreen* this, const char* line) {
@ -89,7 +89,8 @@ void InfoScreen_run(InfoScreen* this) {
bool looping = true; bool looping = true;
while (looping) { while (looping) {
Panel_draw(panel, true, true); Panel_draw(panel, false, true, true);
IncSet_drawBar(this->inc);
if (this->inc->active) { if (this->inc->active) {
(void) move(LINES - 1, CRT_cursorX); (void) move(LINES - 1, CRT_cursorX);

View File

@ -100,16 +100,12 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
if (reaction & HTOP_REDRAW_BAR) { if (reaction & HTOP_REDRAW_BAR) {
MainPanel_updateTreeFunctions(this, this->state->settings->treeView); MainPanel_updateTreeFunctions(this, this->state->settings->treeView);
IncSet_drawBar(this->inc);
if (this->state->pauseProcessUpdate) {
FunctionBar_append("PAUSED", CRT_colors[PAUSED]);
}
} }
if (reaction & HTOP_UPDATE_PANELHDR) { if (reaction & HTOP_UPDATE_PANELHDR) {
ProcessList_printHeader(this->state->pl, Panel_getHeader(super)); ProcessList_printHeader(this->state->pl, Panel_getHeader(super));
} }
if (reaction & HTOP_REFRESH) { if (reaction & HTOP_REFRESH) {
result |= REDRAW; result |= REFRESH;
} }
if (reaction & HTOP_RECALCULATE) { if (reaction & HTOP_RECALCULATE) {
result |= RESCAN; result |= RESCAN;
@ -122,7 +118,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
} }
if (!(reaction & HTOP_KEEP_FOLLOWING)) { if (!(reaction & HTOP_KEEP_FOLLOWING)) {
this->state->pl->following = -1; this->state->pl->following = -1;
Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOCUS]); Panel_setSelectionColor(super, PANEL_SELECTION_FOCUS);
} }
return result; return result;
} }
@ -164,12 +160,21 @@ bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Ar
return ok; return ok;
} }
static void MainPanel_drawFunctionBar(Panel* super) {
MainPanel* this = (MainPanel*) super;
IncSet_drawBar(this->inc);
if (this->state->pauseProcessUpdate) {
FunctionBar_append("PAUSED", CRT_colors[PAUSED]);
}
}
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
}; };
MainPanel* MainPanel_new() { MainPanel* MainPanel_new() {

View File

@ -20,8 +20,8 @@ in the source distribution for its full text.
// Note: In code the meters are known to have bar/text/graph "Modes", but in UI // Note: In code the meters are known to have bar/text/graph "Modes", but in UI
// we call them "Styles". // we call them "Styles".
static const char* const MetersFunctions[] = {"Style ", "Move ", " ", "Delete", "Done ", NULL}; static const char* const MetersFunctions[] = {"Style ", "Move ", " ", "Delete", "Done ", NULL};
static const char* const MetersKeys[] = {"Space", "Enter", " ", "Del", "F10"}; static const char* const MetersKeys[] = {"Space", "Enter", "", "Del", "F10"};
static const int MetersEvents[] = {' ', 13, ERR, KEY_DC, KEY_F(10)}; static const int MetersEvents[] = {' ', 13, ERR, KEY_DC, KEY_F(10)};
// We avoid UTF-8 arrows ← → here as they might display full-width on Chinese // We avoid UTF-8 arrows ← → here as they might display full-width on Chinese
@ -55,13 +55,12 @@ void MetersPanel_setMoving(MetersPanel* this, bool moving) {
selected->moving = moving; selected->moving = moving;
} }
if (!moving) { if (!moving) {
Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOCUS]); Panel_setSelectionColor(super, PANEL_SELECTION_FOCUS);
Panel_setDefaultBar(super); Panel_setDefaultBar(super);
} else { } else {
Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOLLOW]); Panel_setSelectionColor(super, PANEL_SELECTION_FOLLOW);
super->currentBar = Meters_movingBar; super->currentBar = Meters_movingBar;
} }
FunctionBar_draw(this->super.currentBar);
} }
static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) { static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) {

25
Panel.c
View File

@ -56,10 +56,11 @@ void Panel_init(Panel* this, int x, int y, int w, int h, const ObjectClass* type
this->selected = 0; this->selected = 0;
this->oldSelected = 0; this->oldSelected = 0;
this->needsRedraw = true; this->needsRedraw = true;
this->wasFocus = false;
RichString_beginAllocated(this->header); RichString_beginAllocated(this->header);
this->defaultBar = fuBar; this->defaultBar = fuBar;
this->currentBar = fuBar; this->currentBar = fuBar;
this->selectionColor = CRT_colors[PANEL_SELECTION_FOCUS]; this->selectionColorId = PANEL_SELECTION_FOCUS;
} }
void Panel_done(Panel* this) { void Panel_done(Panel* this) {
@ -70,8 +71,8 @@ void Panel_done(Panel* this) {
RichString_end(this->header); RichString_end(this->header);
} }
void Panel_setSelectionColor(Panel* this, int color) { void Panel_setSelectionColor(Panel* this, ColorElements colorId) {
this->selectionColor = color; this->selectionColorId = colorId;
} }
RichString* Panel_getHeader(Panel* this) { RichString* Panel_getHeader(Panel* this) {
@ -217,7 +218,7 @@ void Panel_splice(Panel* this, Vector* from) {
this->needsRedraw = true; this->needsRedraw = true;
} }
void Panel_draw(Panel* this, bool focus, bool highlightSelected) { void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelected) {
assert (this != NULL); assert (this != NULL);
int size = Vector_size(this->items); int size = Vector_size(this->items);
@ -234,6 +235,7 @@ void Panel_draw(Panel* this, bool focus, bool highlightSelected) {
attrset(attr); attrset(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));
} }
@ -262,10 +264,10 @@ void Panel_draw(Panel* this, bool focus, bool highlightSelected) {
int upTo = MINIMUM(first + h, size); int upTo = MINIMUM(first + h, size);
int selectionColor = focus int selectionColor = focus
? this->selectionColor ? CRT_colors[this->selectionColorId]
: CRT_colors[PANEL_SELECTION_UNFOCUS]; : CRT_colors[PANEL_SELECTION_UNFOCUS];
if (this->needsRedraw) { if (this->needsRedraw || force_redraw) {
int line = 0; int line = 0;
for (int i = first; line < h && i < upTo; i++) { for (int i = first; line < h && i < upTo; i++) {
Object* itemObj = Vector_get(this->items, i); Object* itemObj = Vector_get(this->items, i);
@ -293,7 +295,6 @@ void Panel_draw(Panel* this, bool focus, bool highlightSelected) {
mvhline(y + line, x, ' ', this->w); mvhline(y + line, x, ' ', this->w);
line++; line++;
} }
this->needsRedraw = false;
} else { } else {
Object* oldObj = Vector_get(this->items, this->oldSelected); Object* oldObj = Vector_get(this->items, this->oldSelected);
@ -319,7 +320,17 @@ void Panel_draw(Panel* this, bool focus, bool highlightSelected) {
RichString_end(new); RichString_end(new);
RichString_end(old); RichString_end(old);
} }
if (focus && (this->needsRedraw || force_redraw || !this->wasFocus)) {
if (Panel_drawFunctionBarFn(this))
Panel_drawFunctionBar(this);
else
FunctionBar_draw(this->currentBar);
}
this->oldSelected = this->selected; this->oldSelected = this->selected;
this->wasFocus = focus;
this->needsRedraw = false;
move(0, 0); move(0, 0);
} }

27
Panel.h
View File

@ -9,6 +9,7 @@ in the source distribution for its full text.
#include <stdbool.h> #include <stdbool.h>
#include "CRT.h"
#include "FunctionBar.h" #include "FunctionBar.h"
#include "Object.h" #include "Object.h"
#include "RichString.h" #include "RichString.h"
@ -22,9 +23,10 @@ typedef enum HandlerResult_ {
HANDLED = 0x01, HANDLED = 0x01,
IGNORED = 0x02, IGNORED = 0x02,
BREAK_LOOP = 0x04, BREAK_LOOP = 0x04,
REDRAW = 0x08, REFRESH = 0x08,
RESCAN = 0x10, REDRAW = 0x10,
SYNTH_KEY = 0x20, RESCAN = 0x20,
SYNTH_KEY = 0x40,
} HandlerResult; } HandlerResult;
#define EVENT_SET_SELECTED (-1) #define EVENT_SET_SELECTED (-1)
@ -33,16 +35,20 @@ typedef enum HandlerResult_ {
#define EVENT_IS_HEADER_CLICK(ev_) ((ev_) >= -10000 && (ev_) <= -9000) #define EVENT_IS_HEADER_CLICK(ev_) ((ev_) >= -10000 && (ev_) <= -9000)
#define EVENT_HEADER_CLICK_GET_X(ev_) ((ev_) + 10000) #define EVENT_HEADER_CLICK_GET_X(ev_) ((ev_) + 10000)
typedef HandlerResult(*Panel_EventHandler)(Panel*, int); typedef HandlerResult (*Panel_EventHandler)(Panel*, int);
typedef void (*Panel_DrawFunctionBar)(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;
} PanelClass; } PanelClass;
#define As_Panel(this_) ((const PanelClass*)((this_)->super.klass)) #define As_Panel(this_) ((const PanelClass*)((this_)->super.klass))
#define Panel_eventHandlerFn(this_) As_Panel(this_)->eventHandler #define Panel_eventHandlerFn(this_) As_Panel(this_)->eventHandler
#define Panel_eventHandler(this_, ev_) 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_drawFunctionBar(this_) (assert(As_Panel(this_)->drawFunctionBar), As_Panel(this_)->drawFunctionBar((Panel*)(this_)))
struct Panel_ { struct Panel_ {
Object super; Object super;
@ -55,10 +61,11 @@ struct Panel_ {
int scrollV; int scrollV;
short scrollH; short scrollH;
bool needsRedraw; bool needsRedraw;
bool wasFocus;
FunctionBar* currentBar; FunctionBar* currentBar;
FunctionBar* defaultBar; FunctionBar* defaultBar;
RichString header; RichString header;
int selectionColor; ColorElements selectionColorId;
}; };
#define Panel_setDefaultBar(this_) do { (this_)->currentBar = (this_)->defaultBar; } while (0) #define Panel_setDefaultBar(this_) do { (this_)->currentBar = (this_)->defaultBar; } while (0)
@ -75,7 +82,7 @@ void Panel_init(Panel* this, int x, int y, int w, int h, const ObjectClass* type
void Panel_done(Panel* this); void Panel_done(Panel* this);
void Panel_setSelectionColor(Panel* this, int color); void Panel_setSelectionColor(Panel* this, ColorElements colorId);
RichString* Panel_getHeader(Panel* this); RichString* Panel_getHeader(Panel* this);
@ -109,7 +116,7 @@ int Panel_size(Panel* this);
void Panel_setSelected(Panel* this, int selected); void Panel_setSelected(Panel* this, int selected);
void Panel_draw(Panel* this, bool focus, bool highlightSelected); void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelected);
void Panel_splice(Panel* this, Vector* from); void Panel_splice(Panel* this, Vector* from);

View File

@ -119,29 +119,20 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
*rescan = false; *rescan = false;
} }
static void ScreenManager_drawPanels(ScreenManager* this, int focus) { static void ScreenManager_drawPanels(ScreenManager* this, int focus, bool force_redraw) {
const int nPanels = this->panelCount; const int nPanels = this->panelCount;
for (int i = 0; i < nPanels; i++) { for (int i = 0; i < nPanels; i++) {
Panel* panel = (Panel*) Vector_get(this->panels, i); Panel* panel = (Panel*) Vector_get(this->panels, i);
Panel_draw(panel, i == focus, !((panel == this->state->panel) && this->state->hideProcessSelection)); Panel_draw(panel, force_redraw, i == focus, !((panel == this->state->panel) && this->state->hideProcessSelection));
mvvline(panel->y, panel->x + panel->w, ' ', panel->h + 1); mvvline(panel->y, panel->x + panel->w, ' ', panel->h + 1);
} }
} }
static Panel* setCurrentPanel(const ScreenManager* this, Panel* panel) {
FunctionBar_draw(panel->currentBar);
if (panel == this->state->panel && this->state->pauseProcessUpdate) {
FunctionBar_append("PAUSED", CRT_colors[PAUSED]);
}
return panel;
}
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
bool quit = false; bool quit = false;
int focus = 0; int focus = 0;
Panel* panelFocus = setCurrentPanel(this, (Panel*) Vector_get(this->panels, focus)); Panel* panelFocus = (Panel*) Vector_get(this->panels, focus);
double oldTime = 0.0; double oldTime = 0.0;
@ -150,6 +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 rescan = false; bool rescan = false;
int sortTimeout = 0; int sortTimeout = 0;
int resetSortTimeout = 5; int resetSortTimeout = 5;
@ -159,8 +151,9 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
checkRecalculation(this, &oldTime, &sortTimeout, &redraw, &rescan, &timedOut); checkRecalculation(this, &oldTime, &sortTimeout, &redraw, &rescan, &timedOut);
} }
if (redraw) { if (redraw || force_redraw) {
ScreenManager_drawPanels(this, focus); ScreenManager_drawPanels(this, focus, force_redraw);
force_redraw = false;
} }
int prevCh = ch; int prevCh = ch;
@ -187,7 +180,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
ch = KEY_MOUSE; ch = KEY_MOUSE;
if (panel == panelFocus || this->allowFocusChange) { if (panel == panelFocus || this->allowFocusChange) {
focus = i; focus = i;
panelFocus = setCurrentPanel(this, panel); panelFocus = panel;
Object* oldSelection = Panel_getSelected(panel); Object* oldSelection = Panel_getSelected(panel);
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1); Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
if (Panel_getSelected(panel) == oldSelection) { if (Panel_getSelected(panel) == oldSelection) {
@ -234,9 +227,12 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
if (result & SYNTH_KEY) { if (result & SYNTH_KEY) {
ch = result >> 16; ch = result >> 16;
} }
if (result & REDRAW) { if (result & REFRESH) {
sortTimeout = 0; sortTimeout = 0;
} }
if (result & REDRAW) {
force_redraw = true;
}
if (result & RESCAN) { if (result & RESCAN) {
rescan = true; rescan = true;
sortTimeout = 0; sortTimeout = 0;
@ -269,7 +265,7 @@ tryLeft:
focus--; focus--;
} }
panelFocus = setCurrentPanel(this, (Panel*) Vector_get(this->panels, focus)); panelFocus = (Panel*) Vector_get(this->panels, focus);
if (Panel_size(panelFocus) == 0 && focus > 0) { if (Panel_size(panelFocus) == 0 && focus > 0) {
goto tryLeft; goto tryLeft;
} }
@ -290,7 +286,7 @@ tryRight:
focus++; focus++;
} }
panelFocus = setCurrentPanel(this, (Panel*) Vector_get(this->panels, focus)); panelFocus = (Panel*) Vector_get(this->panels, focus);
if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1) { if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1) {
goto tryRight; goto tryRight;
} }

View File

@ -71,11 +71,7 @@ void TraceScreen_delete(Object* cast) {
} }
void TraceScreen_draw(InfoScreen* this) { void TraceScreen_draw(InfoScreen* this) {
attrset(CRT_colors[PANEL_HEADER_FOCUS]); InfoScreen_drawTitled(this, "Trace of process %d - %s", this->process->pid, Process_getCommand(this->process));
mvhline(0, 0, ' ', COLS);
mvprintw(0, 0, "Trace of process %d - %s", this->process->pid, Process_getCommand(this->process));
attrset(CRT_colors[DEFAULT_COLOR]);
IncSet_drawBar(this->inc);
} }
bool TraceScreen_forkTracer(TraceScreen* this) { bool TraceScreen_forkTracer(TraceScreen* this) {