SignalsPanel.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. htop - SignalsPanel.c
  3. (C) 2004-2011 Hisham H. Muhammad
  4. Released under the GNU GPLv2+, see the COPYING file
  5. in the source distribution for its full text.
  6. */
  7. #include "config.h" // IWYU pragma: keep
  8. #include "SignalsPanel.h"
  9. // the above contains #include <signal.h> so do not add that here again (breaks Solaris build)
  10. #include <stdbool.h>
  11. #include "FunctionBar.h"
  12. #include "ListItem.h"
  13. #include "Object.h"
  14. #include "Panel.h"
  15. #include "Platform.h"
  16. #include "XUtils.h"
  17. Panel* SignalsPanel_new(int preSelectedSignal) {
  18. Panel* this = Panel_new(1, 1, 1, 1, Class(ListItem), true, FunctionBar_newEnterEsc("Send ", "Cancel "));
  19. int defaultPosition = 15;
  20. unsigned int i;
  21. for (i = 0; i < Platform_numberOfSignals; i++) {
  22. Panel_set(this, i, (Object*) ListItem_new(Platform_signals[i].name, Platform_signals[i].number));
  23. // signal 15 is not always the 15th signal in the table
  24. if (Platform_signals[i].number == preSelectedSignal) {
  25. defaultPosition = i;
  26. }
  27. }
  28. #if (defined(SIGRTMIN) && defined(SIGRTMAX))
  29. if (SIGRTMAX - SIGRTMIN <= 100) {
  30. static char buf[16];
  31. for (int sig = SIGRTMIN; sig <= SIGRTMAX; i++, sig++) {
  32. int n = sig - SIGRTMIN;
  33. xSnprintf(buf, sizeof(buf), "%2d SIGRTMIN%-+3d", sig, n);
  34. if (n == 0) {
  35. buf[11] = '\0';
  36. }
  37. Panel_set(this, i, (Object*) ListItem_new(buf, sig));
  38. }
  39. }
  40. #endif
  41. Panel_setHeader(this, "Send signal:");
  42. Panel_setSelected(this, defaultPosition);
  43. return this;
  44. }