mirror of https://github.com/xzeldon/htop.git
Move responsibility for cursor placement to Panels
This commit is contained in:
parent
df9922a67e
commit
52b5beb4e4
2
CRT.c
2
CRT.c
|
@ -531,8 +531,6 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||
[COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated.
|
||||
};
|
||||
|
||||
int CRT_cursorX = 0;
|
||||
|
||||
int CRT_scrollHAmount = 5;
|
||||
|
||||
int CRT_scrollWheelVAmount = 10;
|
||||
|
|
2
CRT.h
2
CRT.h
|
@ -144,8 +144,6 @@ int* CRT_colors;
|
|||
|
||||
extern int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT];
|
||||
|
||||
extern int CRT_cursorX;
|
||||
|
||||
extern int CRT_scrollHAmount;
|
||||
|
||||
extern int CRT_scrollWheelVAmount;
|
||||
|
|
|
@ -96,11 +96,12 @@ void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) {
|
|||
}
|
||||
}
|
||||
|
||||
void FunctionBar_draw(const FunctionBar* this, char* buffer) {
|
||||
FunctionBar_drawAttr(this, buffer, CRT_colors[FUNCTION_BAR]);
|
||||
int FunctionBar_draw(const FunctionBar* this, char* buffer) {
|
||||
return FunctionBar_drawAttr(this, buffer, CRT_colors[FUNCTION_BAR]);
|
||||
}
|
||||
|
||||
void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) {
|
||||
int FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) {
|
||||
int cursorX = 0;
|
||||
attrset(CRT_colors[FUNCTION_BAR]);
|
||||
mvhline(LINES-1, 0, ' ', COLS);
|
||||
int x = 0;
|
||||
|
@ -115,12 +116,10 @@ void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) {
|
|||
if (buffer) {
|
||||
attrset(attr);
|
||||
mvaddstr(LINES-1, x, buffer);
|
||||
CRT_cursorX = x + strlen(buffer);
|
||||
curs_set(1);
|
||||
} else {
|
||||
curs_set(0);
|
||||
cursorX = x + strlen(buffer);
|
||||
}
|
||||
attrset(CRT_colors[RESET_COLOR]);
|
||||
return cursorX;
|
||||
}
|
||||
|
||||
int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos) {
|
||||
|
|
|
@ -30,9 +30,9 @@ void FunctionBar_delete(FunctionBar* this);
|
|||
|
||||
void FunctionBar_setLabel(FunctionBar* this, int event, const char* text);
|
||||
|
||||
void FunctionBar_draw(const FunctionBar* this, char* buffer);
|
||||
int FunctionBar_draw(const FunctionBar* this, char* buffer);
|
||||
|
||||
void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr);
|
||||
int FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr);
|
||||
|
||||
int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos);
|
||||
|
||||
|
|
43
IncSet.c
43
IncSet.c
|
@ -38,6 +38,7 @@ typedef struct IncMode_ {
|
|||
typedef struct IncSet_ {
|
||||
IncMode modes[2];
|
||||
IncMode* active;
|
||||
Panel* panel;
|
||||
FunctionBar* defaultBar;
|
||||
bool filtering;
|
||||
bool found;
|
||||
|
@ -115,23 +116,35 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) {
|
|||
}
|
||||
}
|
||||
|
||||
static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
||||
static bool search(IncSet* this, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
||||
int size = Panel_size(panel);
|
||||
bool found = false;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (String_contains_i(getPanelValue(panel, i), mode->buffer)) {
|
||||
if (String_contains_i(getPanelValue(panel, i), this->active->buffer)) {
|
||||
Panel_setSelected(panel, i);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
FunctionBar_draw(mode->bar, mode->buffer);
|
||||
else
|
||||
FunctionBar_drawAttr(mode->bar, mode->buffer, CRT_colors[FAILED_SEARCH]);
|
||||
IncSet_drawBar(this, found ? CRT_colors[FUNCTION_BAR] : CRT_colors[FAILED_SEARCH]);
|
||||
return found;
|
||||
}
|
||||
|
||||
void IncSet_activate(IncSet* this, IncType type, Panel* panel) {
|
||||
this->active = &(this->modes[type]);
|
||||
panel->currentBar = this->active->bar;
|
||||
panel->cursorOn = true;
|
||||
this->panel = panel;
|
||||
IncSet_drawBar(this, CRT_colors[FUNCTION_BAR]);
|
||||
}
|
||||
|
||||
static void IncSet_deactivate(IncSet* this, Panel* panel) {
|
||||
this->active = NULL;
|
||||
Panel_setDefaultBar(panel);
|
||||
panel->cursorOn = false;
|
||||
FunctionBar_draw(this->defaultBar, NULL);
|
||||
}
|
||||
|
||||
bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) {
|
||||
if (ch == ERR)
|
||||
return true;
|
||||
|
@ -189,13 +202,11 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
|||
} else {
|
||||
IncMode_reset(mode);
|
||||
}
|
||||
this->active = NULL;
|
||||
Panel_setDefaultBar(panel);
|
||||
FunctionBar_draw(this->defaultBar, NULL);
|
||||
IncSet_deactivate(this, panel);
|
||||
doSearch = false;
|
||||
}
|
||||
if (doSearch) {
|
||||
this->found = search(mode, panel, getPanelValue);
|
||||
this->found = search(this, panel, getPanelValue);
|
||||
}
|
||||
if (filterChanged && lines) {
|
||||
updateWeakPanel(this, panel, lines);
|
||||
|
@ -210,15 +221,11 @@ const char* IncSet_getListItemValue(Panel* panel, int i) {
|
|||
return "";
|
||||
}
|
||||
|
||||
void IncSet_activate(IncSet* this, IncType type, Panel* panel) {
|
||||
this->active = &(this->modes[type]);
|
||||
FunctionBar_draw(this->active->bar, this->active->buffer);
|
||||
panel->currentBar = this->active->bar;
|
||||
}
|
||||
|
||||
void IncSet_drawBar(IncSet* this) {
|
||||
void IncSet_drawBar(IncSet* this, int attr) {
|
||||
if (this->active) {
|
||||
FunctionBar_draw(this->active->bar, this->active->buffer);
|
||||
int cursorX = FunctionBar_drawAttr(this->active->bar, this->active->buffer, attr);
|
||||
this->panel->cursorY = LINES - 1;
|
||||
this->panel->cursorX = cursorX;
|
||||
} else {
|
||||
FunctionBar_draw(this->defaultBar, NULL);
|
||||
}
|
||||
|
|
7
IncSet.h
7
IncSet.h
|
@ -33,6 +33,7 @@ typedef struct IncMode_ {
|
|||
typedef struct IncSet_ {
|
||||
IncMode modes[2];
|
||||
IncMode* active;
|
||||
Panel* panel;
|
||||
FunctionBar* defaultBar;
|
||||
bool filtering;
|
||||
bool found;
|
||||
|
@ -45,13 +46,13 @@ IncSet* IncSet_new(FunctionBar* bar);
|
|||
|
||||
void IncSet_delete(IncSet* this);
|
||||
|
||||
void IncSet_activate(IncSet* this, IncType type, Panel* panel);
|
||||
|
||||
bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines);
|
||||
|
||||
const char* IncSet_getListItemValue(Panel* panel, int i);
|
||||
|
||||
void IncSet_activate(IncSet* this, IncType type, Panel* panel);
|
||||
|
||||
void IncSet_drawBar(IncSet* this);
|
||||
void IncSet_drawBar(IncSet* this, int attr);
|
||||
|
||||
int IncSet_synthesizeEvent(IncSet* this, int x);
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...) {
|
|||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
this->display->needsRedraw = true;
|
||||
Panel_draw(this->display, true);
|
||||
IncSet_drawBar(this->inc);
|
||||
IncSet_drawBar(this->inc, CRT_colors[FUNCTION_BAR]);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
@ -115,10 +115,7 @@ void InfoScreen_run(InfoScreen* this) {
|
|||
|
||||
Panel_draw(panel, true);
|
||||
|
||||
if (this->inc->active)
|
||||
move(LINES-1, CRT_cursorX);
|
||||
set_escdelay(25);
|
||||
int ch = getch();
|
||||
int ch = Panel_getCh(panel);
|
||||
|
||||
if (ch == ERR) {
|
||||
if (As_InfoScreen(this)->onErr) {
|
||||
|
|
22
Panel.c
22
Panel.c
|
@ -57,6 +57,7 @@ typedef struct PanelClass_ {
|
|||
struct Panel_ {
|
||||
Object super;
|
||||
int x, y, w, h;
|
||||
int cursorX, cursorY;
|
||||
WINDOW* window;
|
||||
Vector* items;
|
||||
int selected;
|
||||
|
@ -66,6 +67,7 @@ struct Panel_ {
|
|||
int scrollV;
|
||||
short scrollH;
|
||||
bool needsRedraw;
|
||||
bool cursorOn;
|
||||
FunctionBar* currentBar;
|
||||
FunctionBar* defaultBar;
|
||||
RichString header;
|
||||
|
@ -85,6 +87,11 @@ struct Panel_ {
|
|||
|
||||
#define KEY_CTRL(l) ((l)-'A'+1)
|
||||
|
||||
void Panel_setCursorToSelection(Panel* this) {
|
||||
this->cursorY = this->y + this->selected - this->scrollV + 1;
|
||||
this->cursorX = this->x + this->selectedLen - this->scrollH;
|
||||
}
|
||||
|
||||
PanelClass Panel_class = {
|
||||
.super = {
|
||||
.extends = Class(Object),
|
||||
|
@ -112,6 +119,8 @@ void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool
|
|||
this->y = y;
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
this->cursorX = 0;
|
||||
this->cursorY = 0;
|
||||
this->eventHandlerState = NULL;
|
||||
this->items = Vector_new(type, owner, DEFAULT_SIZE);
|
||||
this->scrollV = 0;
|
||||
|
@ -367,7 +376,6 @@ void Panel_draw(Panel* this, bool focus) {
|
|||
RichString_end(old);
|
||||
}
|
||||
this->oldSelected = this->selected;
|
||||
move(0, 0);
|
||||
}
|
||||
|
||||
bool Panel_onKey(Panel* this, int key) {
|
||||
|
@ -499,3 +507,15 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) {
|
|||
}
|
||||
return IGNORED;
|
||||
}
|
||||
|
||||
int Panel_getCh(Panel* this) {
|
||||
if (this->cursorOn) {
|
||||
move(this->cursorY, this->cursorX);
|
||||
curs_set(1);
|
||||
} else {
|
||||
curs_set(0);
|
||||
}
|
||||
set_escdelay(25);
|
||||
return getch();
|
||||
}
|
||||
|
||||
|
|
7
Panel.h
7
Panel.h
|
@ -46,6 +46,7 @@ typedef struct PanelClass_ {
|
|||
struct Panel_ {
|
||||
Object super;
|
||||
int x, y, w, h;
|
||||
int cursorX, cursorY;
|
||||
WINDOW* window;
|
||||
Vector* items;
|
||||
int selected;
|
||||
|
@ -55,6 +56,7 @@ struct Panel_ {
|
|||
int scrollV;
|
||||
short scrollH;
|
||||
bool needsRedraw;
|
||||
bool cursorOn;
|
||||
FunctionBar* currentBar;
|
||||
FunctionBar* defaultBar;
|
||||
RichString header;
|
||||
|
@ -73,6 +75,8 @@ struct Panel_ {
|
|||
|
||||
#define KEY_CTRL(l) ((l)-'A'+1)
|
||||
|
||||
void Panel_setCursorToSelection(Panel* this);
|
||||
|
||||
extern PanelClass Panel_class;
|
||||
|
||||
Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar);
|
||||
|
@ -123,4 +127,7 @@ bool Panel_onKey(Panel* this, int key);
|
|||
|
||||
HandlerResult Panel_selectByTyping(Panel* this, int ch);
|
||||
|
||||
int Panel_getCh(Panel* this);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -157,7 +157,8 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus) {
|
|||
}
|
||||
}
|
||||
|
||||
static Panel* setCurrentPanel(Panel* panel) {
|
||||
static Panel* setCurrentPanel(ScreenManager* this, int focus) {
|
||||
Panel* panel = (Panel*) Vector_get(this->panels, focus);
|
||||
FunctionBar_draw(panel->currentBar, NULL);
|
||||
return panel;
|
||||
}
|
||||
|
@ -166,7 +167,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||
bool quit = false;
|
||||
int focus = 0;
|
||||
|
||||
Panel* panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
|
||||
Panel* panelFocus = setCurrentPanel(this, focus);
|
||||
|
||||
double oldTime = 0.0;
|
||||
|
||||
|
@ -189,8 +190,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||
}
|
||||
|
||||
int prevCh = ch;
|
||||
set_escdelay(25);
|
||||
ch = getch();
|
||||
ch = Panel_getCh(panelFocus);
|
||||
|
||||
HandlerResult result = IGNORED;
|
||||
if (ch == KEY_MOUSE) {
|
||||
|
@ -212,7 +212,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||
ch = KEY_MOUSE;
|
||||
if (panel == panelFocus || this->allowFocusChange) {
|
||||
focus = i;
|
||||
panelFocus = setCurrentPanel(panel);
|
||||
panelFocus = setCurrentPanel(this, i);
|
||||
Object* oldSelection = Panel_getSelected(panel);
|
||||
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
|
||||
if (Panel_getSelected(panel) == oldSelection) {
|
||||
|
@ -288,7 +288,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||
tryLeft:
|
||||
if (focus > 0)
|
||||
focus--;
|
||||
panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
|
||||
panelFocus = setCurrentPanel(this, focus);
|
||||
if (Panel_size(panelFocus) == 0 && focus > 0)
|
||||
goto tryLeft;
|
||||
break;
|
||||
|
@ -303,7 +303,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||
tryRight:
|
||||
if (focus < this->panelCount - 1)
|
||||
focus++;
|
||||
panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
|
||||
panelFocus = setCurrentPanel(this, focus);
|
||||
if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1)
|
||||
goto tryRight;
|
||||
break;
|
||||
|
|
|
@ -86,7 +86,7 @@ void TraceScreen_draw(InfoScreen* this) {
|
|||
mvhline(0, 0, ' ', COLS);
|
||||
mvprintw(0, 0, "Trace of process %d - %s", this->process->pid, this->process->comm);
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
IncSet_drawBar(this->inc);
|
||||
IncSet_drawBar(this->inc, CRT_colors[FUNCTION_BAR]);
|
||||
}
|
||||
|
||||
bool TraceScreen_forkTracer(TraceScreen* this) {
|
||||
|
|
Loading…
Reference in New Issue