2011-12-26 21:35:57 +00:00
|
|
|
/*
|
|
|
|
htop - AffinityPanel.c
|
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
|
|
|
Released under the GNU GPL, see the COPYING file
|
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
2007-12-17 05:50:00 +00:00
|
|
|
|
|
|
|
#include "AffinityPanel.h"
|
2015-08-27 21:42:35 +00:00
|
|
|
#include "CRT.h"
|
2007-12-17 05:50:00 +00:00
|
|
|
|
2011-12-26 21:35:57 +00:00
|
|
|
#include "CheckItem.h"
|
|
|
|
|
2007-12-17 05:50:00 +00:00
|
|
|
#include <assert.h>
|
2011-12-26 21:35:57 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/*{
|
|
|
|
#include "Panel.h"
|
|
|
|
#include "Affinity.h"
|
|
|
|
#include "ProcessList.h"
|
|
|
|
#include "ListItem.h"
|
|
|
|
}*/
|
2007-12-17 05:50:00 +00:00
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) {
|
|
|
|
CheckItem* selected = (CheckItem*) Panel_getSelected(this);
|
|
|
|
switch(ch) {
|
2008-05-07 23:01:45 +00:00
|
|
|
case KEY_MOUSE:
|
2015-08-27 21:42:35 +00:00
|
|
|
case KEY_RECLICK:
|
2008-03-09 08:58:38 +00:00
|
|
|
case ' ':
|
|
|
|
CheckItem_set(selected, ! (CheckItem_get(selected)) );
|
2011-11-05 04:42:15 +00:00
|
|
|
return HANDLED;
|
2008-03-09 08:58:38 +00:00
|
|
|
case 0x0a:
|
|
|
|
case 0x0d:
|
|
|
|
case KEY_ENTER:
|
2011-11-05 04:42:15 +00:00
|
|
|
return BREAK_LOOP;
|
2008-03-09 08:58:38 +00:00
|
|
|
}
|
2011-11-05 04:42:15 +00:00
|
|
|
return IGNORED;
|
2008-03-09 08:58:38 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
PanelClass AffinityPanel_class = {
|
|
|
|
.super = {
|
|
|
|
.extends = Class(Panel),
|
|
|
|
.delete = Panel_delete
|
|
|
|
},
|
|
|
|
.eventHandler = AffinityPanel_eventHandler
|
|
|
|
};
|
|
|
|
|
2011-09-24 00:30:47 +00:00
|
|
|
Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) {
|
2015-03-23 22:24:34 +00:00
|
|
|
Panel* this = Panel_new(1, 1, 1, 1, true, Class(CheckItem), FunctionBar_newEnterEsc("Set ", "Cancel "));
|
2012-12-05 15:12:20 +00:00
|
|
|
Object_setClass(this, Class(AffinityPanel));
|
2007-12-17 05:50:00 +00:00
|
|
|
|
|
|
|
Panel_setHeader(this, "Use CPUs:");
|
2011-09-24 00:30:47 +00:00
|
|
|
int curCpu = 0;
|
2011-03-22 20:37:08 +00:00
|
|
|
for (int i = 0; i < pl->cpuCount; i++) {
|
2007-12-17 05:50:00 +00:00
|
|
|
char number[10];
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(number, 9, "%d", Settings_cpuId(pl->settings, i));
|
2011-09-24 00:30:47 +00:00
|
|
|
bool mode;
|
|
|
|
if (curCpu < affinity->used && affinity->cpus[curCpu] == i) {
|
|
|
|
mode = true;
|
|
|
|
curCpu++;
|
|
|
|
} else {
|
|
|
|
mode = false;
|
|
|
|
}
|
2016-02-02 14:53:02 +00:00
|
|
|
Panel_add(this, (Object*) CheckItem_newByVal(xStrdup(number), mode));
|
2007-12-17 05:50:00 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
Affinity* AffinityPanel_getAffinity(Panel* this, ProcessList* pl) {
|
|
|
|
Affinity* affinity = Affinity_new(pl);
|
2009-06-02 04:51:23 +00:00
|
|
|
int size = Panel_size(this);
|
2007-12-17 05:50:00 +00:00
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
if (CheckItem_get((CheckItem*)Panel_get(this, i)))
|
2011-09-24 00:30:47 +00:00
|
|
|
Affinity_add(affinity, i);
|
2007-12-17 05:50:00 +00:00
|
|
|
}
|
2011-09-24 00:30:47 +00:00
|
|
|
return affinity;
|
2007-12-17 05:50:00 +00:00
|
|
|
}
|