Skip to content

Commit

Permalink
Pre-select the last sent signal in SignalsPanel
Browse files Browse the repository at this point in the history
Instead of pre-selecting SIGTERM every time, select the signal last
send in the same htop session.

Closes: #862
  • Loading branch information
cgzones authored and BenBE committed Dec 5, 2021
1 parent a38f484 commit ff4f44b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Action.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,12 @@ static Htop_Reaction actionKill(State* st) {
if (Settings_isReadonly())
return HTOP_OK;

Panel* signalsPanel = SignalsPanel_new();
static int preSelectedSignal = SIGNALSPANEL_INITSELECTEDSIGNAL;

Panel* signalsPanel = SignalsPanel_new(preSelectedSignal);
const ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 14, true);
if (sgn && sgn->key != 0) {
preSelectedSignal = sgn->key;
Panel_setHeader((Panel*)st->mainPanel, "Sending...");
Panel_draw((Panel*)st->mainPanel, false, true, true, State_hideFunctionBar(st));
refresh();
Expand Down
5 changes: 2 additions & 3 deletions SignalsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ in the source distribution for its full text.
#include "XUtils.h"


Panel* SignalsPanel_new() {
Panel* SignalsPanel_new(int preSelectedSignal) {
Panel* this = Panel_new(1, 1, 1, 1, Class(ListItem), true, FunctionBar_newEnterEsc("Send ", "Cancel "));
const int defaultSignal = SIGTERM;
int defaultPosition = 15;
unsigned int i;
for (i = 0; i < Platform_numberOfSignals; i++) {
Panel_set(this, i, (Object*) ListItem_new(Platform_signals[i].name, Platform_signals[i].number));
// signal 15 is not always the 15th signal in the table
if (Platform_signals[i].number == defaultSignal) {
if (Platform_signals[i].number == preSelectedSignal) {
defaultPosition = i;
}
}
Expand Down
6 changes: 5 additions & 1 deletion SignalsPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

#include <signal.h>

#include "Panel.h"


Expand All @@ -15,6 +17,8 @@ typedef struct SignalItem_ {
int number;
} SignalItem;

Panel* SignalsPanel_new(void);
#define SIGNALSPANEL_INITSELECTEDSIGNAL SIGTERM

Panel* SignalsPanel_new(int preSelectedSignal);

#endif

0 comments on commit ff4f44b

Please sign in to comment.