diff options
author | Daniel Lange <DLange@git.local> | 2016-04-11 13:00:29 +0200 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2016-04-11 13:00:29 +0200 |
commit | eaf11cc12a1aa4b050a8a1e7ea3770d3d9c81e95 (patch) | |
tree | 833f3fae6e3604a439f909c245a6e35f574997d7 /AffinityPanel.c | |
parent | 283707c5e5bc436b78ea23bf5500cb6b16a01148 (diff) | |
download | debian_htop-eaf11cc12a1aa4b050a8a1e7ea3770d3d9c81e95.tar.gz debian_htop-eaf11cc12a1aa4b050a8a1e7ea3770d3d9c81e95.tar.bz2 debian_htop-eaf11cc12a1aa4b050a8a1e7ea3770d3d9c81e95.zip |
Imported Upstream version 1.0upstream/1.0
Diffstat (limited to 'AffinityPanel.c')
-rw-r--r-- | AffinityPanel.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/AffinityPanel.c b/AffinityPanel.c index bcd99a3..404104a 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -1,6 +1,6 @@ +#include "ProcessList.h" #include "AffinityPanel.h" - #include "Panel.h" #include "CheckItem.h" @@ -8,42 +8,47 @@ #include <assert.h> static HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) { - HandlerResult result = IGNORED; CheckItem* selected = (CheckItem*) Panel_getSelected(this); switch(ch) { case KEY_MOUSE: case ' ': CheckItem_set(selected, ! (CheckItem_get(selected)) ); - result = HANDLED; - break; + return HANDLED; case 0x0a: case 0x0d: case KEY_ENTER: - result = BREAK_LOOP; - break; + return BREAK_LOOP; } - return result; + return IGNORED; } -Panel* AffinityPanel_new(int processorCount, unsigned long mask) { +Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) { 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++) { + int curCpu = 0; + for (int i = 0; i < pl->cpuCount; i++) { char number[10]; - snprintf(number, 9, "%d", i+1); - Panel_add(this, (Object*) CheckItem_new(String_copy(number), NULL, mask & (1 << i))); + snprintf(number, 9, "%d", ProcessList_cpuId(pl, i)); + bool mode; + if (curCpu < affinity->used && affinity->cpus[curCpu] == i) { + mode = true; + curCpu++; + } else { + mode = false; + } + Panel_add(this, (Object*) CheckItem_new(String_copy(number), NULL, mode)); } return this; } -unsigned long AffinityPanel_getAffinity(Panel* this) { +Affinity* AffinityPanel_getAffinity(Panel* this) { + Affinity* affinity = Affinity_new(); int size = Panel_size(this); - unsigned long mask = 0; for (int i = 0; i < size; i++) { if (CheckItem_get((CheckItem*)Panel_get(this, i))) - mask = mask | (1 << i); + Affinity_add(affinity, i); } - return mask; + return affinity; } |