diff options
author | Daniel Lange <DLange@git.local> | 2016-04-11 13:00:22 +0200 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2016-04-11 13:00:22 +0200 |
commit | 9379132a8234eeedf62d37ef57713e52c12db6ab (patch) | |
tree | 3c1e0d924af0d44be9b14cab8ea1c05a946cdfe3 /AffinityPanel.c | |
parent | 9675cf654d86464344e56705db7a71ea17f76c6f (diff) | |
download | debian_htop-9379132a8234eeedf62d37ef57713e52c12db6ab.tar.gz debian_htop-9379132a8234eeedf62d37ef57713e52c12db6ab.tar.bz2 debian_htop-9379132a8234eeedf62d37ef57713e52c12db6ab.zip |
Imported Upstream version 0.7upstream/0.7
Diffstat (limited to 'AffinityPanel.c')
-rw-r--r-- | AffinityPanel.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/AffinityPanel.c b/AffinityPanel.c new file mode 100644 index 0000000..73cf165 --- /dev/null +++ b/AffinityPanel.c @@ -0,0 +1,45 @@ + +#include "AffinityPanel.h" + +#include "Panel.h" +#include "CheckItem.h" + +#include "debug.h" +#include <assert.h> + +Panel* AffinityPanel_new(int processorCount, unsigned long mask) { + Panel* this = Panel_new(1, 1, 1, 1, CHECKITEM_CLASS, true, ListItem_compare); + this->eventHandler = AffinityPanel_eventHandler; + + Panel_setHeader(this, "Use CPUs:"); + for (int i = 0; i < processorCount; i++) { + char number[10]; + snprintf(number, 9, "%d", i+1); + Panel_add(this, (Object*) CheckItem_new(String_copy(number), NULL, mask & (1 << i))); + } + return this; +} + +unsigned long AffinityPanel_getAffinity(Panel* this) { + int size = Panel_getSize(this); + unsigned long mask = 0; + for (int i = 0; i < size; i++) { + if (CheckItem_get((CheckItem*)Panel_get(this, i))) + mask = mask | (1 << i); + } + return mask; +} + +HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) { + HandlerResult result = IGNORED; + CheckItem* selected = (CheckItem*) Panel_getSelected(this); + switch(ch) { + case 0x0a: + case 0x0d: + case KEY_ENTER: + case ' ': + CheckItem_set(selected, ! (CheckItem_get(selected)) ); + result = HANDLED; + } + return result; +} |