htop/SignalsListBox.c

78 lines
1.8 KiB
C
Raw Normal View History

2006-03-04 18:16:49 +00:00
2006-05-30 13:47:28 +00:00
#include "SignalsPanel.h"
#include "Panel.h"
2006-03-04 18:16:49 +00:00
#include "SignalItem.h"
#include "RichString.h"
#include "debug.h"
#include <assert.h>
#include <ctype.h>
/*{
2006-05-30 13:47:28 +00:00
typedef struct SignalsPanel_ {
Panel super;
2006-03-04 18:16:49 +00:00
int state;
Signal** signals;
2006-05-30 13:47:28 +00:00
} SignalsPanel;
2006-03-04 18:16:49 +00:00
}*/
2006-05-30 13:47:28 +00:00
SignalsPanel* SignalsPanel_new(int x, int y, int w, int h) {
SignalsPanel* this = (SignalsPanel*) malloc(sizeof(SignalsPanel));
Panel* super = (Panel*) this;
Panel_init(super, x, y, w, h, SIGNAL_CLASS, true);
((Object*)this)->delete = SignalsPanel_delete;
2006-03-04 18:16:49 +00:00
this->signals = Signal_getSignalTable();
2006-05-30 13:47:28 +00:00
super->eventHandler = SignalsPanel_EventHandler;
2006-03-04 18:16:49 +00:00
int sigCount = Signal_getSignalCount();
for(int i = 0; i < sigCount; i++)
2006-05-30 13:47:28 +00:00
Panel_set(super, i, (Object*) this->signals[i]);
SignalsPanel_reset(this);
2006-03-04 18:16:49 +00:00
return this;
}
2006-05-30 13:47:28 +00:00
void SignalsPanel_delete(Object* object) {
Panel* super = (Panel*) object;
SignalsPanel* this = (SignalsPanel*) object;
Panel_done(super);
2006-03-04 18:16:49 +00:00
free(this->signals);
free(this);
}
2006-05-30 13:47:28 +00:00
void SignalsPanel_reset(SignalsPanel* this) {
Panel* super = (Panel*) this;
2006-03-04 18:16:49 +00:00
2006-05-30 13:47:28 +00:00
Panel_setHeader(super, "Send signal:");
Panel_setSelected(super, 16); // 16th item is SIGTERM
2006-03-04 18:16:49 +00:00
this->state = 0;
}
2006-05-30 13:47:28 +00:00
HandlerResult SignalsPanel_EventHandler(Panel* super, int ch) {
SignalsPanel* this = (SignalsPanel*) super;
2006-03-04 18:16:49 +00:00
2006-05-30 13:47:28 +00:00
int size = Panel_getSize(super);
2006-03-04 18:16:49 +00:00
if (ch <= 255 && isdigit(ch)) {
int signal = ch-48 + this->state;
for (int i = 0; i < size; i++)
2006-05-30 13:47:28 +00:00
if (((Signal*) Panel_get(super, i))->number == signal) {
Panel_setSelected(super, i);
2006-03-04 18:16:49 +00:00
break;
}
this->state = signal * 10;
if (this->state > 100)
this->state = 0;
return HANDLED;
} else {
this->state = 0;
}
if (ch == 13) {
return BREAK_LOOP;
}
return IGNORED;
}